ts-reviewer 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,16 +14,17 @@ Three modes, one skill:
14
14
  | **fix** | Reads the report and applies fixes file-by-file with tsc/lint/test verification |
15
15
  | **auto** | Runs scan, asks you to confirm, fixes everything, deletes the report if clean |
16
16
 
17
- The review covers six domains, each with its own detailed checklist:
18
-
19
- | Domain | Examples |
20
- |---|---|
21
- | **Type Safety** | `any` abuse, unsafe casts, non-null assertions, missing exhaustive checks |
22
- | **Security** | Injection, prototype pollution, ReDoS, path traversal, hardcoded secrets |
23
- | **Async Patterns** | Floating promises, race conditions, missing error propagation, `forEach(async...)` |
24
- | **Modernization** | `enum` → `as const`, missing `satisfies`, `using` keyword, `import type` |
25
- | **Code Quality** | Dead code, complexity, duplication, hacky patterns, error handling |
26
- | **Config** | tsconfig.json strict flags, module resolution, deprecated options |
17
+ The review covers six domains by default, each with its own detailed checklist. Add `--arch` or `--full` to include architecture analysis:
18
+
19
+ | Domain | Examples | Default |
20
+ |---|---|---|
21
+ | **Type Safety** | `any` abuse, unsafe casts, non-null assertions, missing exhaustive checks | ✓ |
22
+ | **Security** | Injection, prototype pollution, ReDoS, path traversal, hardcoded secrets | ✓ |
23
+ | **Async Patterns** | Floating promises, race conditions, missing error propagation, `forEach(async...)` | ✓ |
24
+ | **Modernization** | `enum` → `as const`, missing `satisfies`, `using` keyword, `import type` | ✓ |
25
+ | **Code Quality** | Dead code, complexity, duplication, hacky patterns, error handling | ✓ |
26
+ | **Config** | tsconfig.json strict flags, module resolution, deprecated options | ✓ |
27
+ | **Architecture** | Shallow modules, scattered concepts, tight coupling, dependency seams, testability | `--arch` / `--full` |
27
28
 
28
29
  ## Installation
29
30
 
@@ -75,7 +76,29 @@ Find issues in this project
75
76
  Audit the codebase for security and type safety problems
76
77
  ```
77
78
 
78
- Claude will analyze the project and write a report to `code-smells.md` in the project root (or `.claude/code-smells.md` if that directory exists).
79
+ Claude will analyze the project and write a report to `code-smells.md` in the project root.
80
+
81
+ #### Domain flags
82
+
83
+ By default, only the six core domains run. Use flags to control which domains are active:
84
+
85
+ | Flag | What runs |
86
+ |---|---|
87
+ | *(none)* | Type Safety, Security, Async, Modernization, Code Quality, Config |
88
+ | `--arch` | Architecture only (shallow modules, coupling, dependency seams) |
89
+ | `--full` | All seven domains |
90
+
91
+ Examples:
92
+
93
+ ```
94
+ Review my TypeScript code --arch
95
+ ```
96
+ ```
97
+ Full audit --full
98
+ ```
99
+ ```
100
+ Review architecture of this project
101
+ ```
79
102
 
80
103
  ### Fix — apply fixes from the report
81
104
 
@@ -136,6 +159,14 @@ Issues on unchanged lines are listed separately as pre-existing tech debt — in
136
159
  | **Medium** | Tech debt — clean up when you're already editing that file |
137
160
  | **Low** | Style and conventions — improve when convenient |
138
161
 
162
+ Architecture findings use the same scale. Each candidate also carries a **Fixability** tag:
163
+
164
+ | Fixability | Meaning |
165
+ |---|---|
166
+ | `auto` | Applied automatically during fix mode |
167
+ | `needs-confirm` | Shown to you first — only applied after explicit approval |
168
+ | `report-only` | Left as documentation — never auto-applied |
169
+
139
170
  ## Project Structure
140
171
 
141
172
  ```
@@ -153,21 +184,22 @@ ts-reviewer/
153
184
  ├── modernization.md # Checklist: TS 5.9+ idioms, satisfies, using, as const
154
185
  ├── code-quality.md # Checklist: complexity, dead code, naming, duplication
155
186
  ├── tsconfig.md # Checklist: strict flags, module resolution, deprecated
187
+ ├── architecture.md # Checklist: shallow modules, coupling, seams, deepening
156
188
  └── fix-workflow.md # Complete fix protocol: tests, verification, rollback
157
189
  ```
158
190
 
159
- **SKILL.md** (349 lines) is the orchestrator — it routes between scan/fix/auto modes, defines scope detection, severity scale, and report format. It stays under the 500-line recommended limit for Claude skills.
191
+ **SKILL.md** is the orchestrator — it routes between scan/fix/auto modes, detects domain flags (`--arch`, `--full`), defines scope detection, severity scale, and report format.
160
192
 
161
- **Reference files** contain the detailed checklists and protocols. Each analysis agent reads only the reference file relevant to its domain, keeping context focused. The fix workflow is in its own reference file because it's a complex multi-step protocol.
193
+ **Reference files** contain the detailed checklists and protocols. Each analysis agent reads only the reference file relevant to its domain, keeping context focused. Architecture analysis is opt-in and loaded only when the domain is active.
162
194
 
163
195
  ## How It Works Under the Hood
164
196
 
165
197
  ### Scan mode
166
198
 
167
- 1. **Discovery** — maps the project, reads tsconfig.json, detects linter and test runner
199
+ 1. **Discovery** — detects domain flags, maps the project, reads tsconfig.json, detects linter and test runner. If architecture is active, also maps module relationships and checks for `docs/adr/`.
168
200
  2. **Diagnostics** — runs `tsc --noEmit`, linter, and LSP diagnostics (if available)
169
- 3. **Analysis** — six specialized passes (sub-agents in Claude Code, sequential in Claude.ai), each with its own checklist
170
- 4. **Report** — deduplicates, applies severity boost (scoped modes), consolidates recurring patterns, writes `code-smells.md`
201
+ 3. **Analysis** — specialized passes for each active domain (sub-agents in Claude Code, sequential in Claude.ai), each with its own checklist
202
+ 4. **Report** — deduplicates, applies severity boost (scoped modes), consolidates recurring patterns, writes `code-smells.md`. Architecture findings appear in a separate `## Architecture Opportunities` section at the end.
171
203
 
172
204
  ### Fix mode
173
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-reviewer",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Install the TypeScript Code Reviewer skill for Claude Code, Codex, or Antigravity",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,18 +1,12 @@
1
1
  ---
2
2
  name: ts-reviewer
3
3
  description: >
4
- Deep TypeScript code review and auto-fix tool. Three modes: scan (find issues),
5
- fix (apply fixes from scan report), auto (scan + fix + verify in one pass).
6
- Supports scoped review: full codebase, uncommitted changes, branch diff (PR review),
7
- or last N commits. Outputs a prioritized report and can auto-fix issues with
8
- regression tests and verification.
9
- Use this skill whenever the user asks to "review", "audit", "check", "lint", "find issues",
10
- "find problems", "find bugs", "fix issues", "fix code smells", "auto-fix",
11
- "review and fix", "clean up code", or "review code quality" in a TypeScript project.
12
- Also trigger when the user mentions "tech debt", "code health", "refactor candidates",
13
- "security audit", "modernize", "review my changes", "review my PR", "check what I changed",
14
- "review last commit", or "review uncommitted" in a TypeScript context. Works with pure
15
- TypeScript 5.9+ codebases — no framework-specific checks (React, Vue, Angular, etc.).
4
+ TypeScript code review and auto-fix. Modes: scan, fix, auto. Scopes: full codebase,
5
+ uncommitted, branch diff, last N commits. Trigger on: review, audit, check, lint,
6
+ find issues, find bugs, fix issues, fix code smells, auto-fix, review and fix,
7
+ clean up code, tech debt, code health, security audit, modernize, review my changes,
8
+ review my PR, review last commit. Architecture review: --arch, --full, review architecture,
9
+ find refactoring opportunities, full audit. Pure TypeScript 5.9+ only.
16
10
  ---
17
11
 
18
12
  # TypeScript Code Reviewer
@@ -33,6 +27,22 @@ This skill operates in three modes. Detect the mode from the user's request:
33
27
  **`fix`** — Read `code-smells.md` and apply fixes with verification.
34
28
  **`auto`** — Run scan, then fix, then re-scan to verify. Delete report if clean.
35
29
 
30
+ ## Domain Set
31
+
32
+ Controls which review domains are active. Detected from flags first, then natural-language phrases.
33
+
34
+ | Flag / phrase | Active domains |
35
+ |---|---|
36
+ | (none / default) | Type Safety, Security, Async Patterns, Modernization, Code Quality, Config |
37
+ | `--arch` / "review architecture" / "find refactoring opportunities" / "deepening review" | Architecture only |
38
+ | `--full` / "full audit" / "full review" / "review everything" | All 7 domains (default 6 + Architecture) |
39
+
40
+ Parse order: check for explicit `--arch` / `--full` / `--no-arch` flags in the user's message first.
41
+ Fall back to phrase detection. If no flag or phrase matches → default domain set (no architecture).
42
+
43
+ Architecture domain is **off** in default scans. It loads `references/architecture.md` and adds
44
+ an `## Architecture Opportunities` section to `code-smells.md` only when active.
45
+
36
46
  ## Report File Location
37
47
 
38
48
  - Always write to `code-smells.md` in the project root (not in `.claude/`)
@@ -145,21 +155,28 @@ git diff -U0 [appropriate range] -- '*.ts' | grep '^@@'
145
155
 
146
156
  ## Phase 1 — Discovery (scan mode)
147
157
 
148
- 1. **Detect scope mode** from user's request. Build file list.
158
+ 1. **Detect domain set** from flags and phrases (see Domain Set section above).
159
+
160
+ 2. **Detect scope mode** from user's request. Build file list.
149
161
  If scoped mode yields 0 files, ask whether to fall back to full.
150
162
 
151
- 2. **Map project tree** — full structure regardless of scope.
163
+ 3. **Map project tree** — full structure regardless of scope.
152
164
 
153
- 3. **Read `tsconfig.json`**. Load `references/tsconfig.md` and audit config flags.
165
+ 4. **Read `tsconfig.json`**. Load `references/tsconfig.md` and audit config flags.
154
166
  In scoped modes: only flag config if `tsconfig.json` is in diff or if full review.
155
167
 
156
- 4. **Check for linter configs** — `eslint.config.*`, `.eslintrc.*`, `biome.json`, `deno.json`.
168
+ 5. **Check for linter configs** — `eslint.config.*`, `.eslintrc.*`, `biome.json`, `deno.json`.
169
+
170
+ 6. **Read `package.json`** — TS version, dependencies, module type.
157
171
 
158
- 5. **Read `package.json`** — TS version, dependencies, module type.
172
+ 7. **Identify entry points** — `index.ts`, `main.ts`, exports in `package.json`.
159
173
 
160
- 6. **Identify entry points** — `index.ts`, `main.ts`, exports in `package.json`.
174
+ 8. **Collect context files** (scoped modes only).
161
175
 
162
- 7. **Collect context files** (scoped modes only).
176
+ 9. **Architecture discovery** (only if Architecture is in active domain set):
177
+ - Map module relationships: note circular imports, deep relative imports, barrel-file cycles, feature slices, public entry points.
178
+ - Check if `docs/adr/` exists — if so, scan it for architectural decisions before proposing changes. Skip silently if absent.
179
+ - Do NOT require `CONTEXT.md` or any domain-doc files.
163
180
 
164
181
  Discovery summary:
165
182
  ```
@@ -203,6 +220,8 @@ Query TypeScript LSP via MCP if accessible. Merge with compiler output, deduplic
203
220
 
204
221
  Read the corresponding reference file before each analysis pass.
205
222
 
223
+ Run only the agents whose domain is in the active domain set (see Domain Set section).
224
+
206
225
  | Agent | Reference file | Focus |
207
226
  |---|---|---|
208
227
  | Type Safety | `references/type-safety.md` | `any`, casts, `!`, exhaustiveness, generics |
@@ -211,6 +230,7 @@ Read the corresponding reference file before each analysis pass.
211
230
  | Modernization | `references/modernization.md` | Outdated patterns vs TS 5.9+ idioms |
212
231
  | Code Quality | `references/code-quality.md` | Complexity, duplication, naming, dead code |
213
232
  | Config | `references/tsconfig.md` | tsconfig.json flags and module setup |
233
+ | Architecture | `references/architecture.md` | Shallow modules, scattered concepts, coupling, dependency seams, testability |
214
234
 
215
235
  ### Sub-agent template (Claude Code)
216
236
 
@@ -297,6 +317,23 @@ Write to `code-smells.md`:
297
317
  ## Recurring Patterns
298
318
  ## Config Issues
299
319
  ## Pre-existing Issues (scoped modes only)
320
+
321
+ ## Architecture Opportunities
322
+ (only when Architecture is in active domain set AND at least one candidate found — omit entirely otherwise)
323
+
324
+ ### TITLE — Severity
325
+
326
+ - **Files:** relative/path/a.ts, relative/path/b.ts
327
+ - **Problem:** why this causes friction now
328
+ - **Proposed deepening:** what would change
329
+ - **Interface shape:** rough sketch of new interface
330
+ - **Dependency category:** in-process | local-substitutable | remote-owned | true-external
331
+ - **Test strategy:** how tests improve
332
+ - **Benefits:** locality, leverage, test impact
333
+ - **Trade-offs:** what gets harder
334
+ - **Fixability:** auto | needs-confirm | report-only
335
+
336
+ ---
300
337
  ````
301
338
 
302
339
  ### Sorting
@@ -337,6 +374,9 @@ Key principles:
337
374
 
338
375
  In scoped modes: these are base severities before diff-aware boost.
339
376
 
377
+ Architecture findings use the same severity scale with domain-specific criteria.
378
+ See `references/architecture.md` → Severity Mapping for Architecture.
379
+
340
380
  ---
341
381
 
342
382
  ## Important Guidelines
@@ -0,0 +1,118 @@
1
+ # Architecture Review Checklist
2
+
3
+ Loaded only when architecture review is active (`--arch` or `--full` flag).
4
+
5
+ ## Glossary
6
+
7
+ Use these terms in all architecture findings. Don't substitute "component", "service", "API", "boundary".
8
+
9
+ - **Module** — anything with an interface and an implementation: function, class, package, feature slice.
10
+ - **Interface** — everything a caller must know: types, invariants, error modes, ordering, config. Not just the TypeScript `interface` keyword.
11
+ - **Implementation** — the code inside the module.
12
+ - **Depth** — leverage at the interface. Deep = large behaviour behind small interface. Shallow = interface nearly as complex as implementation.
13
+ - **Seam** — where the interface lives; a place behaviour can be altered without editing in place. Prefer over "boundary".
14
+ - **Adapter** — a concrete thing satisfying an interface at a seam.
15
+ - **Leverage** — what callers get from depth: more capability per unit of interface they must learn.
16
+ - **Locality** — what maintainers get from depth: change, bugs, and knowledge concentrated in one place.
17
+
18
+ ## Principles
19
+
20
+ - **Depth is a property of the interface, not the implementation.** A deep module can be internally complex — what matters is how small its interface is relative to what it hides.
21
+ - **Deletion test.** Imagine deleting the module. If complexity vanishes → it was a pass-through. If complexity reappears across callers → it was earning its keep.
22
+ - **The interface is the test surface.** Callers and tests cross the same seam. If tests must reach past the interface into internals, the module is the wrong shape.
23
+ - **One adapter = hypothetical seam. Two adapters = real seam.** Don't introduce a port unless at least two adapters are justified (production + test at minimum). Single-adapter seams are just indirection.
24
+
25
+ ## Smell Checklist
26
+
27
+ ### Shallow Modules
28
+
29
+ - Understanding one concept requires bouncing across many tiny modules. Severity: **Medium**.
30
+ - Module interface is nearly as complex as its implementation (shallow). Severity: **Medium**.
31
+ - Pass-through wrapper / manager / helper / service that adds no hidden complexity. Severity: **Medium**. Apply deletion test.
32
+ - Pure functions extracted only for testability, but real bugs hide in orchestration — no locality. Severity: **Medium**.
33
+
34
+ ### Coupling and Boundaries
35
+
36
+ - Tight coupling leaks across module interfaces (callers must know implementation details). Severity: **High**.
37
+ - Tests must reach into module internals or mock too many neighbors to test one thing. Severity: **High**.
38
+ - Public API exports implementation details, config, ordering constraints, or internal error modes that callers should not need to know. Severity: **Medium**.
39
+
40
+ ### Import and Module Structure
41
+
42
+ *Note: circular imports and deep relative imports are also flagged by the Code Quality domain in all scan modes. Architecture domain provides deeper refactoring guidance when Code Quality flags them.*
43
+
44
+ - Barrel-file cycles or circular import chains that can't be resolved by reordering. Severity: **High**.
45
+ - Deep relative imports (`../../../`) indicating modules not co-located with what they depend on. Severity: **Low**. Suggest path aliases or co-location.
46
+
47
+ ### Locality
48
+
49
+ - Shared utility module mixes unrelated domain concepts (a grab-bag util). Severity: **Medium**.
50
+ - Feature logic split by technical layer (e.g. controller / service / repo per feature) in a way that destroys locality — change to one feature requires touching 4+ files. Severity: **Medium**.
51
+
52
+ ## Dependency Classification
53
+
54
+ When proposing a deepening fix, classify the dependency to determine test strategy:
55
+
56
+ **1. In-process** — pure computation or in-memory state, no I/O.
57
+ - Strategy: merge modules, test through the deepened interface directly. No adapter needed.
58
+
59
+ **2. Local-substitutable** — DB, filesystem, etc. with usable local stand-ins (PGLite, in-memory filesystem).
60
+ - Strategy: deepen using the stand-in in tests. The seam is internal; no port at the external interface.
61
+
62
+ **3. Remote but owned** — internal services across a network boundary.
63
+ - Strategy: define a port (TypeScript interface) at the seam. Production adapter + in-memory adapter for tests.
64
+ - The deep module owns the logic; only the transport is injected.
65
+
66
+ **4. True external** — third-party services (Stripe, Twilio, etc.) you don't control.
67
+ - Strategy: inject a port; provide a mock adapter for tests.
68
+
69
+ **Rule:** don't introduce a port unless at least two adapters are justified. A single-adapter seam is indirection without benefit.
70
+
71
+ ## Candidate Report Format
72
+
73
+ Each architecture finding uses this format in the `## Architecture Opportunities` section:
74
+
75
+ ```md
76
+ ### TITLE — Severity
77
+
78
+ - **Files:** relative/path/a.ts, relative/path/b.ts
79
+ - **Problem:** why this causes friction now (not just a pattern name)
80
+ - **Proposed deepening:** plain-English description of what would change
81
+ - **Interface shape:** rough sketch of the new interface (types, methods, key invariants)
82
+ - **Dependency category:** in-process | local-substitutable | remote-owned | true-external
83
+ - **Test strategy:** how tests would improve (what tests survive, what gets deleted, what's new)
84
+ - **Benefits:** locality gained, leverage gained, test impact
85
+ - **Trade-offs:** what gets harder, what is genuinely uncertain
86
+ - **Fixability:** auto | needs-confirm | report-only
87
+ ```
88
+
89
+ ## Severity Mapping for Architecture
90
+
91
+ | Level | Architecture criteria |
92
+ |---|---|
93
+ | **Highest** | Architecture issue directly causing a security vulnerability, data loss, or production correctness bug |
94
+ | **High** | Circular imports or cross-module coupling that blocks reliable tests or causes recurring defects |
95
+ | **Medium** | Shallow modules, scattered domain logic, pass-through abstractions, hard-to-test orchestration |
96
+ | **Low** | Small interface leaks, minor naming drift between module interface and what it exposes |
97
+
98
+ ## Fixability Mapping
99
+
100
+ | Fixability | Meaning | Fix mode behavior |
101
+ |---|---|---|
102
+ | `auto` | Local change: import path cleanup, narrow circular-import break, local module merge with co-located tests | Applied in normal fix loop |
103
+ | `needs-confirm` | Interface change, dependency inversion, test replacement, feature-slice reorganization | Shown to user, NOT applied automatically |
104
+ | `report-only` | Broad migration, ambiguous domain model, change requiring product/domain decision | Never applied, left as documentation |
105
+
106
+ ## Naming Guidance
107
+
108
+ Use names that already exist in the codebase (function names, type names, file names, package names). Don't invent domain terms. If a deepened module needs a name, prefer a name already used in adjacent code.
109
+
110
+ ## Architecture Fix Rules
111
+
112
+ When applying `auto` fixability architecture findings:
113
+
114
+ - Write new tests at the deepened module's interface. Old unit tests on shallow modules that are now merged become redundant — delete them.
115
+ - Tests assert observable behavior through the interface, not internal state.
116
+ - Don't expose internal seams through the interface just because tests need them.
117
+ - Tests that have to change when the implementation changes are testing past the interface.
118
+ - For large architecture changes classified `needs-confirm`, show a diff/migration plan and wait for explicit go-ahead before touching code.
@@ -67,6 +67,9 @@
67
67
  - Circular imports. Severity: **High**.
68
68
  - Deep relative imports (`../../../`). Severity: **Low**. Fix: path aliases.
69
69
 
70
+ For deeper architectural refactors (shallow modules, dependency seams, module deepening, coupling),
71
+ load `references/architecture.md` — available only when architecture review is enabled (`--arch` or `--full`).
72
+
70
73
  ## Comments
71
74
 
72
75
  - JSDoc repeating the type info. Severity: **Low**.
@@ -298,6 +298,34 @@ After fix completes:
298
298
 
299
299
  ---
300
300
 
301
+ ## Architecture Fixes
302
+
303
+ Architecture findings in the `## Architecture Opportunities` section carry a `Fixability:` field.
304
+ Fix mode behavior is determined by that field:
305
+
306
+ | Fixability | Fix mode behavior |
307
+ |---|---|
308
+ | `auto` | Apply in normal fix loop. Run `tsc --noEmit` after each file as usual. |
309
+ | `needs-confirm` | Surface to user with a diff/migration plan. Do NOT apply automatically. Wait for explicit go-ahead. |
310
+ | `report-only` | Never apply. Leave in report as documentation. Mark `[SKIPPED: report-only]`. |
311
+
312
+ ### Testing strategy for architecture fixes
313
+
314
+ When applying an `auto` architecture fix (module merge, import path cleanup, narrow circular-import break):
315
+
316
+ 1. Write new tests at the **deepened module's interface** — test observable behavior, not internal state.
317
+ 2. Delete old unit tests that tested the shallow modules being merged — they become redundant once the deeper module's interface tests cover the same behavior.
318
+ 3. Tests must survive internal refactors. If a test must change when implementation changes, it's testing past the interface.
319
+ 4. Don't expose internal seams through the module interface just to make tests easier to write.
320
+
321
+ ### `needs-confirm` flow
322
+
323
+ 1. Show the user what would change (describe the reorganization or interface change).
324
+ 2. If the user approves, apply the fix using the same file-by-file + `tsc` verification loop.
325
+ 3. If the user rejects, mark the finding `[SKIPPED: user rejected]` in the report and move on.
326
+
327
+ ---
328
+
301
329
  ## Fix Safety Rules
302
330
 
303
331
  1. **NEVER commit or stage.** The user reviews and decides.