# Porting kuizer v1 into the Rust kuizer Status: plan. Nothing in this document is implemented yet. kuizer v1 is a TypeScript dead-code finder (Bun, ts-morph). It lives on the `v1-typescript` branch of `github.com/remcostoeten/kuizer` at `44fc149`. `master` now holds the Rust disk cleanup tool that was called sweep until October 2026 and took over the kuizer name and repository. This plan rebuilds v1 inside it as a `kuizer code` command: kuizer already removes generated folders that a tool can rebuild, and v1 removes source that nothing imports. Both answer "what on this disk can go", with different evidence. The port is a rewrite, not a translation. ts-morph gives kuizer v1 a full TypeScript program and the type checker; Rust has no equivalent. The replacement is the oxc toolchain, which oxlint, the linter in the TypeScript repos, is built on: a parser, a semantic pass with scopes and references, and a module resolver that reads `tsconfig.json`. That covers everything v1 actually uses from the checker, which is symbol references and module resolution, not types. ## 1. Audit: kuizer v1 ### What it does | Area | Files | Behaviour | | --- | --- | --- | | Engine | `src/engine/index.ts` (417 lines) | Loads the ts-morph project from `tsconfig.json`, adds every `*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}` under the root plus test files, builds an import graph from `import`, `export ... from` and literal `import()` calls, finds entry points, and runs a BFS for production reachability and a second one for test-only reachability. Non-literal `import()` calls are recorded as analysis boundaries. | | Cache | `src/engine/cache.ts` | Per-file `size-mtime` key in `node_modules/.cache/kuizer/analyze-cache.json`, storing adjacency, boundaries and consumer keys. | | Detectors | `src/detectors/` | `unusedFiles`: files not reachable from an entry. `unusedImports`: imported bindings with no local reference. `unusedExports`: exported declarations with zero production consumers, split by kind into `unusedFunctions`, `unusedTypes`, `unusedClasses`, `unusedComponents` (PascalCase function or class in `.tsx`/`.jsx`), `unusedConstants`, `unusedEnums`, `unusedDefaults`, `unusedOthers`. Each export finding is flagged `testOnly` or `internalOnly` where that applies. | | Framework rules | `unused-exports.ts`, `config/presets.ts` | Presets `nextjs-app`, `nextjs-pages`, `vite`, `none` add entry globs and allowed exports. Next.js route files keep `default`, `metadata`, `generateMetadata`, route handlers (`GET`, `POST`...), segment config and OG image exports. Root `*.config.*` default exports count as consumed. | | Fix planning | `src/fixers/planners/` | Unused file: delete it (`destructive`). Unused export used locally: strip the `export` keyword (`safe`). Unused export that is the file's only statement: delete the file (`destructive`). Otherwise delete the declaration (`cautious`). Refuses default exports, re-export declarations, grouped `export const a, b`, and anything when a dynamic-import boundary exists. | | Fix apply | `src/fixers/apply.ts` | Line-range edits, applied bottom-up per file. `remove-export-keyword` regex-strips a leading `export` on every line in the range. `delete-declaration` drops the lines and collapses blank runs. | | Snapshots | `src/backup/` | Copies every touched file to `.kuizer/snapshots/-fix-/files/` with a `manifest.json`. `restore` and `revert` both copy the files back. | | Config | `src/config/` | cosmiconfig lookup: `--config`, then `kuizer.config.{json,ts,js}`, `.kuizerrc*`, the `kuizer` key in `package.json`, then `~/.kuizerrc`. Keys: `tsconfig`, `entrypoints`, `framework`, `countTestsAsConsumers`, `allowedExports`, `ignore.{files,symbols,paths}`, `detectors..{enabled,severity}`, `outputDir`, `dryRunByDefault`. | | CLI | `src/cli/index.ts` (984 lines), `help.ts` (567) | `detect` (`--only`, `--skip`, `--filter` by detector or kind, `--exclude-pattern` regex on symbol names, `--json`, `--reporter`, `--interactive`), `fix` (`-w`, `--dry-run`, `--no-backup`, `--interactive`), `restore`, `revert`, `init`. Exit code 1 when any finding has severity `error`. | | TUI | `src/cli/interactive.ts` (1195 lines) | Hand-rolled ANSI two-pane browser with detector and kind toggles, selection and a fix hand-off. | | JSON | `src/reporters/json.ts` | `{ meta: { version, durationMs, total, analysisBoundaryCount }, findings, analysisBoundaries }`. | | Tests | `__tests__/` | Bun tests per module plus `e2e.test.ts` over `__tests__/fixtures/sample`. | ### Defects to fix in the port, not copy 1. **`unusedFiles` reports almost nothing by default.** With no configured entry points, `inferEntries` makes every file that nothing imports an entry, so it is reachable by definition. Only files inside import cycles that nothing outside imports are ever reported. The port reads real entry points from `package.json` (`main`, `module`, `bin`, `exports`, `scripts` that name a file) and framework conventions, and reports unreachable files only when at least one real entry exists. Otherwise it says so in the report. 2. **The cache gives stale results.** A consumer key is `::`, and it is cached under the consuming file. Editing the declaring file shifts the offset, but the consumer's `size-mtime` stays the same, so its cached keys point at the old offset and the export shows as unused. Adjacency is cached the same way, though it depends on which other files exist. The port starts with no cache (section 4.6). 3. **`ignore.symbols` is documented as a regex (`"^_"` in `CONFIG.md`) but matched as an exact string.** The port takes globs and says so. 4. **`ignore.files` is compared against absolute paths in `unusedFiles` and against root-relative paths in the engine.** A relative entry only works in one of the two places. The port resolves every ignore path once, at config load. 5. **`node_modules`, `.next` and `dist` are hard-coded skips.** In kuizer they come from the existing artifact rules, so `target`, `.turbo`, `build` with a marker and the rest are skipped too. 6. **Every split detector recomputes everything.** `detectById` runs `collectUnusedExportFindings` and the full consumer count once per detector, which is nine times with defaults. The port computes it once and filters. 7. **`hasInternalConsumer` matches identifier text across the whole file.** A shadowing local with the same name counts as a use. oxc's semantic pass resolves references to the declaring symbol, so this case is correct by construction. 8. **`remove-export-keyword` edits by line and regex.** Any line in the statement's range that starts with `export`, such as a line in a template literal, gets rewritten too. The port edits byte spans from the AST. 9. **Restore never checks whether files changed after the snapshot.** It overwrites later work without asking. The port stores a BLAKE3 hash per file and refuses or asks when the current content differs. 10. **The `vite` preset lists `index.html` as an entry.** It is never in the file set, so it never matches, and `