octocode-cli 1.2.9 → 1.2.10

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.
@@ -1,499 +1,413 @@
1
1
  ---
2
2
  name: octocode-engineer
3
- description: "Codebase-aware engineering: analysis, planning, implementation. For code understanding, bug fixes, refactors, audits, architecture/security/test-quality reviews. AST/graph/LSP scanning + AI validation. Use when checking code or architecture, understanding before/after any code change, validating bugs and flows, reviewing docs/plans/RFCs against code, or doing smart implementation with blast-radius awareness."
3
+ description: "System-aware engineering skill for code understanding, safe implementation, refactoring, architecture review, and quality analysis. Use this before planning and for general task support when an agent must start with local Octocode tools, use AST search/tree-search to prove structure, and combine those checks with LSP and scanner results to understand structure, flows, blast radius, contracts, documentation gaps, and architectural risk instead of looking only at one file. Aims to improve any system, and is especially effective for Node-based applications."
4
4
  ---
5
5
 
6
- # Octocode Code Engineer
7
-
8
- Detectors produce hypotheses. AI validates, reasons, and prioritizes. Never present raw findings as facts. Always tell user what you found with evidence, ask before acting on M/L changes.
9
-
10
- `<SKILL_DIR>` = directory containing this SKILL.md.
11
-
12
- ## Core Principle: Multi-Angle Investigation
13
-
14
- Every question about code MUST be investigated from multiple angles. No single tool gives a complete answer. Cross-validate using **at least 2 tool families** before presenting findings.
15
-
16
- ```mermaid
17
- flowchart TD
18
- Q([User Question]) --> D[Discovery Layer]
19
-
20
- D -->|"layout, files, search"| Local["Local Tools\n(search, structure, files)"]
21
- D -->|"lineHint"| LSP["LSP\n(definition, refs, calls)"]
22
- D -->|"presets, patterns"| AST["AST Scripts\n(structural proof)"]
23
- D -->|"full scan"| Scanner["Scanner\n(94 detectors, 5 pillars)"]
24
-
25
- Local -->|text patterns\nfile locations| V{AI Validation}
26
- LSP -->|blast radius\ncall chains| V
27
- AST -->|structural facts\npattern matches| V
28
- Scanner -->|hypotheses\n94 categories| V
29
-
30
- V -->|"2+ layers agree"| C([Confirmed Finding])
31
- V -->|"1 layer only"| U([Uncertain needs more evidence])
32
- V -->|"code contradicts"| X([Dismissed])
33
- ```
34
-
35
- | Tool Family | What it proves | Unique strength |
36
- |-------------|---------------|-----------------|
37
- | **Local tools** (search, structure, files, content) | Where things are, what the code says | Scope, layout, text patterns, `lineHint` for LSP |
38
- | **LSP** (definition, references, call hierarchy) | Semantic relationships between symbols | Blast radius, call chains, dead code proof |
39
- | **AST** (search.js, tree-search.js) | Structural code patterns | Empty catches, `any` types, nested ternaries — things regex can't prove |
40
- | **Scanner** (run.js) | Cross-cutting analysis across 5 pillars | 94 finding categories, dependency graph, per-function metrics |
41
-
42
- **Confidence levels:**
43
- - `confirmed` 2+ tool families agree
44
- - `uncertain` — partial evidence from 1 family
45
- - `dismissed` code contradicts the finding
46
-
47
- ### Why Cross-Validated Investigation Matters
48
-
49
- Most regressions come from hidden context: complex control flow, high fan-in, dependency cycles, duplicated logic, and weak test coverage. Multi-angle checks prevent local optimizations from causing system-level failures.
50
-
51
- Use one source for each claim type: Local tools for scope/text evidence, LSP for semantic blast radius, AST for structural proof, and scanner findings for codebase-wide prioritization.
52
-
53
- ## Tools
54
-
55
- ### Local Tools (Octocode MCP)
56
-
57
- MCP check: run `localSearchCode`. If unavailable CLI-only mode (AST scripts only), reduce confidence on semantic claims.
58
-
59
- **`localViewStructure`** Maps codebase shape: directories, file counts, extensions, nesting. Tells you *where to look* — large folders, test gaps, naming patterns. Use `directoriesOnly=true` for layout, `filesOnly=true` + `extension` for source spread.
60
-
61
- **`localFindFiles`** — Finds files by size, modification time, name pattern. Surfaces god files (`sortBy=size`), recent churn (`modifiedWithin=7d`), naming anomalies. Feeds candidate lists to every other tool.
62
-
63
- **`localSearchCode`** — Text search across the codebase. Critical output: `lineHint` — the exact line number that **every LSP tool requires**. Without this, LSP tools cannot be called. Also reveals how symbols spread across files. Use `filesOnly=true` for fast file-level discovery first.
64
-
65
- **`localGetFileContent`** — Reads actual source code. The final verification step: after other tools identify *where* and *what*, this lets AI *read and reason about* the real code. Use `matchString` to jump to the right section in large files.
66
-
67
- ### LSP Tools (Semantic Analysis)
68
-
69
- All LSP tools REQUIRE `lineHint` from `localSearchCode`. Never guess it.
70
-
71
- **`lspGotoDefinition(lineHint=N)`** — Jumps from usage to definition. Answers "what is this symbol actually?" Resolves ambiguity when search returns multiple candidates.
72
-
73
- **`lspFindReferences(lineHint=N)`** — Counts all consumers of a symbol (types, vars, exports, functions). This is **blast radius** — the most important metric for risk. 0 refs = dead code. 50 refs = plan carefully. Use `includeDeclaration=false` for clean consumer counts.
74
-
75
- **`lspCallHierarchy(lineHint=N, direction)`** — Traces function call chains. `incoming` = who calls this? `outgoing` = what does it call? **Functions only** — do NOT use on types/vars/constants.
76
-
77
- | Symbol type | Use this | NOT this |
78
- |-------------|----------|----------|
79
- | Function/method | `lspCallHierarchy` | — |
80
- | Type/interface/class | `lspFindReferences` | `lspCallHierarchy` (will fail) |
81
- | Variable/constant/export | `lspFindReferences` | `lspCallHierarchy` (will fail) |
82
-
83
- ### AST Scripts (Structural Proof)
84
-
85
- Text search finds strings. AST search proves **structure**. AST matches are facts.
86
-
87
- **`ast/search.js`** — Parses live source files. Matches structural patterns that regex cannot reliably detect.
88
-
89
- ```bash
90
- node <SKILL_DIR>/scripts/ast/search.js --preset empty-catch --root <target> --json
91
- node <SKILL_DIR>/scripts/ast/search.js -p 'console.$METHOD($$$ARGS)' --root <target> --json
92
- node <SKILL_DIR>/scripts/ast/search.js --kind function_declaration --root <target> --json
93
- ```
94
-
95
- 22 presets: `empty-catch`, `console-log`, `console-any`, `debugger`, `todo-fixme`, `any-type`, `type-assertion`, `non-null-assertion`, `fat-arrow-body`, `nested-ternary`, `throw-string`, `switch-no-default`, `class-declaration`, `async-function`, `export-default`, `import-star`, `catch-rethrow` (catch blocks containing a throw — simplification candidates), `promise-all`, `boolean-param` (boolean type annotations in function signatures), `magic-number`, `deep-callback`, `unused-var`.
96
-
97
- **TypeScript pattern best practices** — patterns must match the full AST structure including type annotations:
98
-
99
- | Goal | Wrong (misses TS types) | Right |
100
- |------|------------------------|-------|
101
- | Find all functions | `-p 'function $NAME($$$P)'` | `-k function_declaration` or `--preset async-function` |
102
- | Find specific calls | (works fine) | `-p 'JSON.parse($X)'` or `-p 'console.$M($$$A)'` |
103
- | Match typed params | `-p 'function $N($P)'` | `-p 'function $N($P: string): string { $$$B }'` |
104
- | Structural smells | (use presets) | `--preset empty-catch`, `--preset any-type`, etc. |
105
-
106
- **Rule of thumb:** Use `--kind` or `--preset` for declarations (functions, classes, exports). Use `-p` pattern for call expressions and specific code shapes where types aren't involved.
107
-
108
- See [AST reference](./references/ast-reference.md) for pattern wildcards (`$X`, `$$$X`), kind matching, and rule mode.
109
-
110
- **`ast/tree-search.js`** Queries cached `ast-trees.txt` from a prior scan. Fast triage to narrow targets before deeper investigation.
111
-
112
- ```bash
113
- node <SKILL_DIR>/scripts/ast/tree-search.js -i .octocode/scan -k function_declaration --limit 25
114
- node <SKILL_DIR>/scripts/ast/tree-search.js -i .octocode/scan -p 'async' --json
115
- node <SKILL_DIR>/scripts/ast/tree-search.js -i .octocode/scan -k arrow_function --file src/utils.ts --section functions
116
- ```
117
-
118
- Additional options: `-p <pattern>` (text pattern), `--json` (JSON output), `--file <path>` (filter by file), `--section <name>` (filter by tree section), `-C N` (context lines), `--ignore-case`.
119
-
120
- **Triage** with `tree-search.js` (fast, cached). **Prove** with `search.js` (live source, authoritative).
121
-
122
- ### Scanner (`run.js`) Full Deterministic Analysis
123
-
124
- Heaviest tool. Runs TypeScript Compiler + tree-sitter across the codebase. Produces hypotheses across 5 analysis pillars with 94 finding categories.
125
-
126
- ```bash
127
- node <SKILL_DIR>/scripts/run.js [flags]
128
- ```
129
-
130
- **5 pillars:**
131
- - **Architecture** (28 categories): dependency cycles, coupling, god modules, SDP violations, chokepoints, critical paths, layer violations, barrel explosions
132
- - **Code quality** (34 categories): complexity, duplicates, halstead effort, maintainability, unsafe `any`, empty catch, promise misuse, memory leaks, god functions, deep nesting, multiple returns, catch-rethrow, magic strings, boolean param clusters, unhandled promise combinators, export surface density, change risk
133
- - **Dead code** (12 categories): dead exports/files, unused deps, barrel explosions, orphan implementations
134
- - **Security** (12 categories): secrets, eval, injection, XSS, prototype pollution, path traversal, command injection
135
- - **Test quality** (8 categories): assertion density, excessive mocking, cleanup, focused tests
136
-
137
- **Additional capabilities:**
138
- - `--semantic`: 12 of the 94 finding categories require this flag — TypeChecker-powered analysis (over-abstraction, shotgun surgery, unused params, circular types, and more)
139
- - `--graph` / `--graph-advanced`: dependency graph with Mermaid, chokepoints, SCC clusters
140
- - `--flow`: flow enrichment for richer evidence metadata
141
- - `--scope=path` or `--scope=file:functionName`: focus on specific areas
142
- - `--parser auto|typescript|tree-sitter`: engine selection (`auto` = TypeScript primary + tree-sitter for node-count metadata; `tree-sitter` = tree-sitter primary + TypeScript for dependencies)
143
- - `--layer-order ui,service,repository`: automatic layer violation detection
144
- - `--similarity-threshold 0.8`: near-clone / duplicate function detection
145
- - `--features` / `--exclude`: select or skip pillars and individual categories (mutually exclusive)
146
- - `--findings-limit N`: cap total findings; `--no-diversify` for pure severity ordering (default interleaves categories)
147
- - `--all`: enable everything (`--include-tests --semantic`)
148
- - Incremental caching (use `--no-cache` to force full re-scan, `--clear-cache` to wipe)
149
- - `--affected [revision]`: scope to git-changed files + their transitive dependents (default: HEAD)
150
- - `--save-baseline` / `--ignore-known [file]`: progressive adoption — save current findings, suppress known ones
151
- - `--reporter default|compact|github-actions`: CI-friendly output (one-line or `::warning`/`::error` annotations)
152
- - `--focus <module>` + `--focus-depth N`: graph neighborhood exploration (show module + N hops)
153
- - `--collapse N`: fold graph nodes to folder depth for high-level architecture view
154
- - `--at-least N`: fail if gate score below threshold (CI quality gate; uses count-based `100/(1+(findings/files)/10)`, distinct from severity-weighted feature scores in `summary.md`)
155
- - `--config <file>`: explicit config; auto-discovers `.octocode-scan.json`, `.octocode-scan.jsonc`, or `package.json#octocode`
156
- - Additional flags (`--root`, `--out`, `--json`, `--emit-tree`/`--no-tree`, `--deep-link-topn`, `--tree-depth`): see `node <SKILL_DIR>/scripts/run.js --help`
157
-
158
- **Key thresholds** (tune for stricter or looser analysis):
159
-
160
- | Area | Flag | Default | What it controls |
161
- |------|------|---------|-----------------|
162
- | Complexity | `--critical-complexity-threshold` | 30 | Cyclomatic complexity for HIGH findings |
163
- | Complexity | `--cognitive-complexity-threshold` | 15 | Cognitive complexity threshold |
164
- | Coupling | `--coupling-threshold` | 15 | Ca+Ce for high-coupling |
165
- | Coupling | `--fan-in-threshold` / `--fan-out-threshold` | 20/15 | God-module coupling |
166
- | Type safety | `--any-threshold` | 5 | Max `any` usages per file |
167
- | Maintainability | `--maintainability-index-threshold` | 20 | MI below this = high-risk |
168
- | God module | `--god-module-statements` / `--god-module-exports` | 500/20 | Size thresholds |
169
- | God function | `--god-function-statements` | 100 | Statement count threshold |
170
- | God function | `--god-function-mi-threshold` | 10 | MI threshold (fires when MI < N and LOC > 30) |
171
- | Parameters | `--parameter-threshold` | 5 | Max function parameters before flagging |
172
- | Halstead | `--halstead-effort-threshold` | 500000 | Halstead effort threshold |
173
- | Duplicates | `--similarity-threshold` | 0.85 | Jaccard similarity for near-clones |
174
- | Duplicates | `--min-function-statements` | 6 | Min function body statements for duplicate matching |
175
- | Duplicates | `--min-flow-statements` | 6 | Min control-flow statements for duplicate matching |
176
- | Duplicates | `--flow-dup-threshold` | 3 | Min occurrences for a repeated flow to become a finding |
177
- | Nesting | `--deep-nesting-threshold` | 5 | Max branch/loop nesting depth |
178
- | Returns | `--multiple-return-threshold` | 6 | Max return/throw paths per function |
179
- | Magic strings | `--magic-string-min-occurrences` | 3 | Min repetitions to flag a string literal |
180
- | Boolean params | `--boolean-param-threshold` | 3 | Min boolean params to flag a function |
181
- | Architecture | `--barrel-symbol-threshold` | 30 | Re-export count for barrel-explosion |
182
- | Architecture | `--sdp-min-delta` | 0.15 | Min instability delta for SDP violations |
183
- | Architecture | `--sdp-max-source-instability` | 0.6 | Max source instability to report SDP |
184
- | Semantic | `--override-chain-threshold` | 3 | Max method override depth (requires `--semantic`) |
185
- | Semantic | `--shotgun-threshold` | 8 | Unique-file threshold for shotgun-surgery (requires `--semantic`) |
186
- | Security | `--secret-entropy-threshold` | 4.5 | Shannon entropy for secret detection |
187
- | Security | `--secret-min-length` | 20 | Min string length for entropy-based secret detection |
188
- | Tests | `--mock-threshold` | 10 | Max mock/spy calls per test file |
189
-
190
- **Common profiles:**
191
-
192
- | Goal | Flags |
193
- |------|-------|
194
- | General audit | `--graph --flow` |
195
- | Architecture deep-dive | `--features=architecture --graph --graph-advanced` |
196
- | Code quality | `--features=code-quality --flow` |
197
- | Dead code cleanup | `--features=dead-code` |
198
- | Security audit | `--features=security --flow` |
199
- | Test quality | `--features=test-quality --include-tests` |
200
- | Focused deep-dive | `--scope=<path> --graph --flow --semantic` |
201
- | Full everything | `--all --graph --graph-advanced --flow` |
202
- | Post-change verify | `--scope=<changed-paths> --no-cache` |
203
- | Strict type safety | `--any-threshold 0` |
204
- | Layer enforcement | `--layer-order ui,service,repository --features=architecture` |
205
- | Detect near-clones | `--similarity-threshold 0.8 --features=code-quality` |
206
- | CI gate | `--reporter github-actions --at-least 60` |
207
- | PR diff check | `--affected HEAD~1 --reporter compact` |
208
- | Progressive adoption | `--save-baseline` then `--ignore-known --at-least 60` |
209
- | Module zoom | `--graph --focus=src/session.ts --focus-depth 2` |
210
- | High-level arch | `--graph --collapse 2` |
211
-
212
- **Drill-down workflow** progressive narrowing from broad to surgical:
213
-
214
- ```
215
- 1. Full scan → identify hotspots from summary.md
216
- 2. --scope=critical/area → deep-dive into the worst package/directory
217
- 3. --scope=file.ts → investigate a single file's findings
218
- 4. --scope=file.ts:functionName → drill into a specific function
219
- 5. Fix → re-scan with scope → verify finding count drops
220
- ```
221
-
222
- **Scope sanity checks** low/zero findings may mean clean code OR a bad scope:
223
- - Confirm the scope has `.ts`/`.js` files `--scope=docs/` yields 0 findings
224
- - `--features=test-quality` without `--include-tests` yields 0 findings test files are excluded by default
225
- - Scoped scans affect `ast-trees.txt` — `tree-search.js` picks the latest scan, which may be the narrow one. Point to a full-scan timestamp explicitly if needed.
226
- - When in doubt, compare against a broad baseline: `run.js --graph --flow` with no scope
227
-
228
- Output: `.octocode/scan/<timestamp>/` — `summary.json`, `summary.md`, `findings.json`, `architecture.json`, `code-quality.json`, `dead-code.json`, `file-inventory.json`. Conditional: `security.json` and `test-quality.json` (only when findings exist), `ast-trees.txt` (unless `--no-tree`), `graph.md` (requires `--graph`).
229
-
230
- See [CLI reference](./references/cli-reference.md) for all flags and thresholds. See [output files](./references/output-files.md) for JSON schemas and read order.
231
-
232
- ## How to Investigate
233
-
234
- For any user request, reason beyond the literal question and check adjacent risk areas.
235
-
236
- ### 21 Investigation Workflows
237
-
238
- The skill includes ready-made workflows for every common scenario. Pick the right one based on the task:
239
-
240
- | # | Workflow | When to use |
241
- |---|---------|-------------|
242
- | 1 | **Full Scan → Triage → Validate** | New codebase or broad audit |
243
- | 2 | **Symbol Deep Dive** | Trace a function: definition → callers → callees |
244
- | 3 | **Impact Analysis (Pre-Refactor)** | Assess blast radius before changing a symbol |
245
- | 4 | **Dead Export Validation** | Confirm/dismiss dead code findings |
246
- | 5 | **Code Smell Sweep** | Batch AST preset checks for structural smells |
247
- | 6 | **Dependency Cycle Tracing** | Validate and trace cycles from architecture.json |
248
- | 7 | **Security Sink Validation** | Taint-trace data flow from source to sink |
249
- | 8 | **Scoped Deep-Dive** | Drill into a specific flagged file or function |
250
- | 9 | **Coupling Hotspot Analysis** | Quantify coupling for architecture findings |
251
- | 10 | **Fix Verification Loop** | Confirm fixes reduced finding count after every batch |
252
- | 11 | **Pre-Implementation Check** | Where should new code live? Avoid hotspots |
253
- | 12 | **Refactoring Plan** | Multi-file refactor with full blast radius awareness |
254
- | 13 | **Codebase Exploration** | New repo orientation — layout, scale, conventions |
255
- | 14 | **Test Strategy Analysis** | Map test coverage gaps and test quality issues |
256
- | 15 | **Code Review Support** | Assess architectural impact of changed files |
257
- | 16 | **Code Quality Review** | Focused quality review of a module or file |
258
- | 17 | **Full Architecture Analysis** | Complete architecture health assessment |
259
- | 18 | **Smart Coding** | Impact-aware before/during/after code changes |
260
- | 19 | **CLI Change Safety** | Safe changes to commands, flags, output, exit behavior |
261
- | 20 | **API Contract Safety** | Safe changes to endpoints, schemas, DTOs, responses |
262
- | 21 | **Docs & Rollout Sync** | Post-change docs, migration notes, rollback plan |
263
-
264
- Full step-by-step details: [tool workflows](./references/tool-workflows.md).
265
-
266
- ### Smart Coding Workflow (Before / During / After)
267
-
268
- The most important workflow for any code change. Ensures blast-radius awareness and post-change verification.
269
-
270
- **BEFORE coding:**
271
- 1. Define behavior contract current behavior, desired behavior, invariants, non-goals
272
- 2. Understand the target area explore module layout, read current code, jump to definitions
273
- 3. Check blast radius `localSearchCode` `lspFindReferences` (total, production-only, test-only) → `lspCallHierarchy(incoming)`
274
- 4. Check architecture safety scoped scan with architecture + graph check if change creates new cycles
275
- 5. Follow existing patterns AST search for similar patterns nearby, text search for analogous implementations
276
-
277
- **MAKE the change:**
278
- 6. Implement edits
279
-
280
- **AFTER coding:**
281
- 7. Run project tests
282
- 8. Verify no new issues — scoped scan of changed files + AST preset sweep (`any-type`, `empty-catch`)
283
- 9. Verify references intact `lspFindReferences` for moved/renamed symbols, `lspCallHierarchy(incoming)` for callers
284
- 10. Run project toolchain lint (with auto-fix), build
285
-
286
- **Decision gates:**
287
- - Step 3: >20 production consumers = high-risk consider feature flag or incremental migration
288
- - Step 4: change touches cycle member or hotfile = extra caution → re-scan after
289
- - Step 8: new findings = fix before committing
290
- - Step 10: any failure = investigate before proceeding
291
-
292
- ### Decision: What tool(s) to reach for?
293
-
294
- | I need to know... | Use these (parallel when possible) |
295
- |-------------------|------------------------------------|
296
- | Codebase layout / where to look | `localViewStructure` + `localFindFiles` |
297
- | Where a symbol lives | `localSearchCode` `lspGotoDefinition(lineHint)` |
298
- | Who uses a symbol | `localSearchCode` `lspFindReferences(lineHint)` |
299
- | Who calls a function | `localSearchCode` `lspCallHierarchy(incoming, lineHint)` |
300
- | What a function calls | `localSearchCode` `lspCallHierarchy(outgoing, lineHint)` |
301
- | If a structural pattern exists | `ast/search.js --preset` or `-p` pattern |
302
- | If an export is dead | `lspFindReferences` (0 refs?) + `ast/search.js` (import check) + `localSearchCode` (dynamic refs?) |
303
- | Module/file health | `run.js --scope=<path>` + `ast/search.js` presets + `lspFindReferences` per export |
304
- | Full codebase health | `run.js --graph --flow` validate top findings with LSP + AST |
305
- | If a fix worked | `run.js --scope=<changed> --no-cache` + `ast/search.js` on changed dirs + lint/test/build |
306
-
307
- ### Think broader than the question
308
-
309
- | User asks about... | Also investigate... |
310
- |--------------------|---------------------|
311
- | A function | Callers, tests, sibling functions, error handling |
312
- | A module | Dependency cycles, consumers, barrel re-exports, test coverage |
313
- | Security | Input sources, data flows, output sinks, guard functions |
314
- | Tests | Untested production code, mock quality, assertion density |
315
- | A bug fix | Blast radius, related callers, regression risk |
316
- | A refactor | Fan-in, cycles, test coverage of affected symbols |
317
- | Architecture | Hotspots, coupling, critical paths, layer violations |
318
-
319
- ### Cross-validate findings
320
-
321
- Every finding should be checked from multiple angles:
322
-
323
- **"Is this catch block a problem?"**
324
- 1. `ast/search.js --preset empty-catch` → proves the catch IS empty (structural fact)
325
- 2. `localSearchCode` for the function → get `lineHint`
326
- 3. `lspFindReferences(lineHint)` 15 callers (high blast radius)
327
- 4. `localGetFileContent` read the actual code, understand context
328
- 5. AI: "confirmed silent error swallowing in high-traffic function"
329
-
330
- **"Is this export dead?"**
331
- 1. `localSearchCode` for the export get `lineHint` + see file spread
332
- 2. `lspFindReferences(lineHint, includeDeclaration=false)` 0 refs
333
- 3. `ast/search.js -p 'import { exportName }'` 0 structural imports
334
- 4. AI: "confirmed dead zero consumers across semantic + structural checks"
335
-
336
- **"Is this function too complex?"**
337
- 1. `run.js --scope=file:functionName` complexity metrics
338
- 2. `ast/tree-search.js` function span and nesting depth
339
- 3. `lspCallHierarchy(outgoing)` how many things it orchestrates
340
- 4. `lspCallHierarchy(incoming)` how many callers depend on it
341
- 5. `localGetFileContent` read the body, count concerns
342
- 6. AI: "uncertain high complexity but may be intentional orchestration. Flag for review."
343
-
344
- **Per-category validation quick-reference:**
345
-
346
- | Category | How to validate | Typical fix |
347
- |----------|----------------|-------------|
348
- | Dead export | `lspFindReferences(includeDeclaration=false)` 0 refs = dead | Remove export or wire real usage |
349
- | Coupling hotspot | Fan-in (`lspFindReferences`) + fan-out (`lspCallHierarchy(outgoing)`) | Split module by responsibility/consumer group |
350
- | Dependency cycle | Trace imports through cycle path from `architecture.json` | Break edge via shared contract/inversion |
351
- | Security sink | Trace data sources via `lspCallHierarchy(incoming)` → check for guards | Add/centralize validation before sink |
352
- | God function | Read body + map outgoing calls count concerns and side effects | Extract focused helpers, keep orchestration thin |
353
- | Performance (await-in-loop) | Check if iterations are independent (no data dependency between N and N-1) | Collect with `Promise.all()`; keep sequential only when dependent |
354
- | Test gap | `lspFindReferences` filtered to test dirs 0 test refs = gap | Add tests around public contract and edge paths |
355
-
356
- Use TDD for behavioral fixes when practical: failing test → fix → pass → full suite.
357
-
358
- More cross-validation patterns: [validation playbooks](./references/validation-playbooks.md).
359
-
360
- ### External tools — ask user before running
361
-
362
- `npx` only. Scanner already covers duplicates, unused deps, dead exports — no external tool needed for those.
363
-
364
- | Tool | When | Command |
365
- |------|------|---------|
366
- | eslint | Lint & auto-fix | `npx eslint --fix <path>` |
367
- | tsc | Type check | `npx tsc --noEmit` |
368
- | stylelint | CSS/SCSS | `npx stylelint "**/*.css"` |
369
- | knip | Framework-aware dead code | `npx knip --exports` |
370
- | type-coverage | Type safety % | `npx type-coverage --strict --detail` |
371
- | dep-cruiser | Custom arch rules | `npx depcruise --no-config -T err <path>` |
372
-
373
- Details: [external tools](./references/externals.md).
374
-
375
- ### Architecture interpretation signals
376
-
377
- When raw architecture findings are noisy, use these structural signals to prioritize:
378
-
379
- | Signal | What it means | Action |
380
- |--------|--------------|--------|
381
- | **SCC cluster** | Overlapping dependency cycles forming a strongly connected component | Treat entire cluster as one refactor unit — breaking one edge may not help |
382
- | **Broker/chokepoint** | High fan-in + high fan-out — dependency pressure node | Decompose by splitting read vs write consumers, or extract interface |
383
- | **Bridge module** | Articulation-style file connecting two subsystems | Fragile — breaking it disconnects the graph. Stabilize or duplicate at boundary |
384
- | **Package chatter** | Excessive cross-package imports | Boundary erosion — consolidate shared types or redraw package lines |
385
-
386
- Prioritize fixes where **hotspots and critical paths overlap** — those are the highest-leverage changes.
387
-
388
- ### Metrics reference
389
-
390
- | Metric | Formula / Scale | What it means | Threshold signal |
391
- |--------|----------------|---------------|------------------|
392
- | Instability | `I = Ce / (Ca + Ce)` | How change-prone vs depended-on (0 = stable, 1 = unstable) | Stable module depending on unstable one = SDP violation |
393
- | Cognitive complexity | Incremental per branch/nesting | Mental load to understand a function | >15 = decomposition candidate |
394
- | Maintainability index | 0-100 composite (volume, complexity, LOC) | Overall maintainability score | <20 = high-risk |
395
- | Halstead effort | Operators × operands formula | Estimated comprehension effort | Very high = split or refactor |
396
- | Fan-in | Count of incoming dependencies | How many modules depend on this | >20 = god module risk |
397
- | Fan-out | Count of outgoing dependencies | How many modules this depends on | >15 = coupling risk |
398
-
399
- Use thresholds as heuristics, not absolute truth. Context matters — a config module with fan-in=45 may be fine if it's read-only.
400
-
401
- ### Working with scanner output
402
-
403
- Read scan results in this order:
404
- 1. `summary.md` → health scores, severity breakdown, top recommendations
405
- 2. `summary.json` → `featureScores[]`, `investigationPrompts[]`, `recommendedValidation`
406
- 3. `findings.json` → per-finding detail with `evidence.location`, `correlatedSignals[]`, `lspHints[]`
407
- 4. Pillar files as needed
408
-
409
- Per finding, use:
410
- - `recommendedValidation.tools[]` → which tools to run for confirmation
411
- - `evidence.location` → exact `file:line` to inspect
412
- - `correlatedSignals[]` → related findings to check together
413
- - `suggestedFix.strategy` + `suggestedFix.steps` → actionable fix path
414
-
415
- Follow `investigationPrompts[]` from `summary.json` — ready-made next steps.
416
-
417
- **Scoring model** — the scanner produces two complementary scores:
418
-
419
- *Feature scores* (`featureScores[]`): per-category scores using severity weights (`critical=25, high=10, medium=3, low=1`). Formula: `100 / (1 + (weightedFindingsPerFile / 10))`. Guardrails: critical findings cap at 95, high at 98. Hotspot overlap applies context penalties.
420
-
421
- *Quality rating* (`qualityRating`): hybrid AI + structural rating across 6 weighted aspects:
422
- - Architecture & Structure (30%) — dependency health, modularity, coupling
423
- - Folder Topology (15%) — directory depth, naming coherence, layout clarity
424
- - Naming Quality (15%) — consistent conventions, descriptive identifiers
425
- - Common/Shared Layer Health (15%) — utility modules, shared abstractions
426
- - Maintainability & Evolvability (15%) — change readiness, encapsulation
427
- - Codebase Consistency (10%) — uniform patterns across modules
428
-
429
- Use `featureScores[]` to rank worst categories. Use `qualityRating.aspects[]` for soft-signal scoring.
430
-
431
- **Finding correlation patterns** — findings that appear together often signal deeper issues:
432
-
433
- | Combination | Likely root cause |
434
- |-------------|-------------------|
435
- | `feature-envy` + `low-cohesion` | Boundary error — logic in the wrong module |
436
- | `layer-violation` + `feature-envy` | Dependency leak across architecture layers |
437
- | `import-side-effect-risk` + hotspot tags | Startup risk — initialization on import |
438
- | `dependency-critical-path` + complexity tags | Change chokepoint — high-risk modification path |
439
-
440
- **File inventory deep fields** (`file-inventory.json`) — per-file AST lens for targeted investigation:
441
- - `functions[]` — shape, complexity, span per function
442
- - `flows[]` — repeated control-flow structures
443
- - `dependencyProfile` — exports, imports, re-exports, internal/external deps
444
- - `topLevelEffects[]` — hidden initialization / import-time side effects
445
- - `effectProfile` — summarized import-time risk
446
- - `symbolUsageSummary` — compact import/export shape for boundary follow-up
447
- - `boundaryRoleHints[]` — lightweight role inference (entrypoint, utility, config, etc.)
448
- - `cfgFlags` — flow clues for validation, cleanup, exit behavior, async boundaries (with `--flow`)
449
-
450
- If `architecture.json` names a hotspot, use `file-inventory.json` to explain *why* it's structurally hard to change.
451
-
452
- ## Task Sizing & Planning
453
-
454
- | Size | Scope | Approach |
455
- |------|-------|----------|
456
- | S | Single-file, low-risk | Investigate → implement → verify (lint + tests) |
457
- | M | Multi-file with consumers | Multi-angle investigation → present plan → implement → verify (lint + tests + build) |
458
- | L | Cross-cutting / architectural | Full investigation → present improvement plan → implement → verify (lint + tests + build + re-scan) |
459
-
460
- Upgrade to L if: fan-in >20, cycle/hotspot involvement, or unclear contract risk.
461
-
462
- **M/L improvement plan** — per item:
463
- - **Target**: file:symbol
464
- - **Issue**: what's wrong + evidence (tool + file:line)
465
- - **Impact**: consumer count, severity
466
- - **Fix**: strategy + steps
467
- - **Test**: what to add/update
468
- - **Risk**: low/medium/high + mitigation
469
- - **Order**: dependency-aware (foundations first)
470
-
471
- Present plan to user. Ask before proceeding.
6
+ # Octocode Engineer
7
+
8
+ This skill helps an agent investigate, change, and verify a codebase with system awareness.
9
+
10
+ Use this skill before writing a plan. First build system understanding, then switch to plan mode once structure, flows, blast radius, and architectural risks are clear.
11
+ Use it as an organizer for agents: pick the right lens, choose the right tools, understand the system, then move into planning or implementation.
12
+ Use it with a senior-architect review posture: check whether the system is clear, modular, extensible, efficient, documented, and safe to evolve.
13
+ Start with local Octocode tools whenever they are available. Use AST to check and prove structural claims instead of trusting text search alone.
14
+
15
+ Most agents naturally zoom into the file in front of them. This skill pushes the opposite direction first:
16
+ - start with local Octocode discovery before deep reading
17
+ - use AST to check structural patterns and confirm smells
18
+ - understand the structure before editing the line
19
+ - trace flows before changing behavior
20
+ - check architecture before trusting a local fix
21
+ - validate important claims from more than one angle
22
+
23
+ ## What This Skill Does
24
+
25
+ Use this skill to:
26
+ - help with almost any engineering task, especially before planning, by organizing investigation and decision-making
27
+ - understand how a feature, bug, or module really works
28
+ - trace definitions, callers, callees, imports, and shared contracts
29
+ - find architectural issues such as cycles, chokepoints, coupling, hotspots, and layer violations
30
+ - validate structural code smells with AST tools instead of weak text guesses
31
+ - push toward clean code, clean modular architecture, strong contracts, and low duplication
32
+ - check efficiency problems such as avoidable `O(n^2)` work, repeated scans, repeated queries, and wasteful flows
33
+ - flag rigid, naive, brittle, or clearly unnecessary code paths before they spread
34
+ - prevent patchy fixes that work locally but make the system harder to extend later
35
+ - improve both delivery velocity and long-term quality through smarter flows and better structure
36
+ - plan safer refactors with blast-radius awareness
37
+ - check that important critical aspects are documented when behavior, contracts, architecture, or operations depend on them
38
+ - verify that a change did not create new code-quality, architecture, or test-quality problems
39
+
40
+ This is not only a code-editing skill.
41
+ It is a structure, architecture, and flow-analysis skill that also supports coding.
42
+ It aims to make systems easier to extend, safer to evolve, and smarter to work in over time.
43
+ It applies to any system, but is especially effective for Node and TypeScript applications where module boundaries, async flows, contracts, package dependencies, and runtime edges must stay clean.
44
+
45
+ ## When To Use It
46
+
47
+ Use this skill when the user asks to:
48
+ - help with almost any code or architecture task that benefits from better system understanding first
49
+ - understand code before changing it
50
+ - fix a bug in shared or unclear code
51
+ - refactor a module, package, or cross-file flow
52
+ - review code quality, architecture, or technical debt
53
+ - improve maintainability, modularity, contracts, or extensibility
54
+ - validate docs, plans, or RFCs against the real implementation
55
+ - check dead code, test gaps, security risks, or design problems
56
+ - implement a change safely in a non-trivial area
57
+ - prepare for planning by understanding the real system before switching to plan mode
58
+
59
+ ## Core Mindset
60
+
61
+ 1. System first, file second.
62
+ 2. Root causes often live in boundaries, flows, ownership, coupling, or missing tests, not just in the visible line of code.
63
+ 3. Important findings should be validated with at least 2 approaches when possible.
64
+ 4. Prefer local Octocode tools first for discovery, scope, and evidence.
65
+ 5. Use AST to check structural claims whenever text search may be misleading.
66
+ 6. Report confidence clearly: `confirmed`, `likely`, or `uncertain`.
67
+ 7. Prefer clean, modular, contract-driven solutions over local patches.
68
+ 8. For medium or large changes, understand blast radius and architecture before editing.
69
+ 9. Track meaningful work with tasks or todos when the runtime supports it.
70
+ 10. Ask the user at the right checkpoint when scope, risk, or tradeoffs are genuinely unclear.
71
+
72
+ ## The Main Problem This Skill Solves
73
+
74
+ A local code read is often not enough.
75
+ A function may look wrong, but the real issue may be:
76
+ - too many callers
77
+ - circular dependencies
78
+ - a shared module doing too much
79
+ - a weak boundary between layers
80
+ - weak or implicit contracts between modules, APIs, or types
81
+ - inefficient loops, repeated work, or avoidable `O(n^2)` logic
82
+ - rigid or brittle code that is hard to extend without patching around it
83
+ - duplicate logic spread across packages
84
+ - a hidden flow through re-exports, side effects, or orchestration code
85
+ - poor tests around a high-risk path
86
+ - a quick patch that solves today but blocks safe extension tomorrow
87
+
88
+ Because of that, always look at:
89
+ - structure: where code lives and how modules are grouped
90
+ - architecture: dependencies, boundaries, cycles, hotspots, and ownership
91
+ - contracts: TypeScript types, interfaces, DTOs, schemas, and public module boundaries
92
+ - flows: entry points, call chains, data movement, and side effects
93
+ - quality: clean code, low duplication, CSS hygiene, and maintainable module responsibilities
94
+ - efficiency: algorithmic complexity, repeated work, repeated queries, N+1 patterns, and unnecessary orchestration
95
+ - rigidity: brittle logic, over-coupled decisions, and code that is harder than necessary to extend
96
+ - docs: whether critical setup, contracts, flows, constraints, migrations, and caveats are documented
97
+ - code: the actual implementation details
98
+
99
+ The target is not just "working code".
100
+ The target is a system that stays extendable, understandable, and fast to change.
101
+
102
+ ## Investigation Lenses
103
+
104
+ | Lens | Main question | Best tools |
105
+ |------|---------------|------------|
106
+ | Layout | Where does this behavior live? | `localViewStructure`, `localFindFiles`, `localSearchCode` |
107
+ | Semantics | What symbol is this and who uses it? | `localSearchCode` -> LSP tools |
108
+ | Persistence | How is state stored and mutated? | schema files, SQL/Prisma/Mongoose definitions, migration files, repository/storage modules |
109
+ | Efficiency | Is the implementation doing avoidable work or unnecessary complexity? | scanner complexity findings, code read, query/storage access paths, tests/benchmarks when available |
110
+ | Docs | Are critical behaviors, contracts, flows, and operational constraints documented? | docs/readmes, API docs, config docs, migration notes, code comments near boundaries |
111
+ | Structure | Does this pattern really exist? | `scripts/ast/search.js`, `scripts/ast/tree-search.js` |
112
+ | Architecture | Is this area hard or risky to change? | `scripts/run.js`, graph and flow modes |
113
+ | Behavior | What does the code actually do? | `localGetFileContent`, tests |
114
+
115
+ ## Tool Families And Their Jobs
116
+
117
+ ### 1. Local Octocode tools
118
+
119
+ Use local tools first to map the workspace.
120
+ These are the default first tools for this skill, not a fallback.
121
+
122
+ | Tool | Use it for |
123
+ |------|------------|
124
+ | `localViewStructure` | Package/module layout, folder depth, source spread |
125
+ | `localFindFiles` | Large files, recent churn, suspicious filenames, likely hotspots |
126
+ | `localSearchCode` | Fast discovery, symbol search, text patterns, and `lineHint` for LSP |
127
+ | `localGetFileContent` | Final code reading after you know what you are looking at |
128
+
129
+ Rule: do not start with a random full-file read if discovery tools can narrow the target first.
130
+
131
+ ### 2. LSP tools
132
+
133
+ Use LSP tools to understand real semantic relationships.
134
+
135
+ Critical rule: every LSP tool needs `lineHint` from `localSearchCode`.
136
+ Never guess it.
137
+
138
+ | Tool | Use it for |
139
+ |------|------------|
140
+ | `lspGotoDefinition` | What symbol is this really? |
141
+ | `lspFindReferences` | Blast radius, all usages, dead-code checks |
142
+ | `lspCallHierarchy` | Function call flow only: incoming callers and outgoing callees |
143
+
144
+ LSP is the main way to answer:
145
+ - who depends on this?
146
+ - what will break if we change it?
147
+ - what path does execution follow?
148
+
149
+ ### 3. AST tools
150
+
151
+ Use AST tools when text search is too weak and you need structural proof.
152
+ AST is a primary checking tool in this skill, especially for validating smells, redundancy, and code-shape claims.
153
+
154
+ | Tool | Use it for |
155
+ |------|------------|
156
+ | `scripts/ast/search.js` | Live source analysis and structural pattern matching |
157
+ | `scripts/ast/tree-search.js` | Fast triage over cached AST trees from a previous scan |
158
+
159
+ Use AST tools for things like:
160
+ - empty catch blocks
161
+ - `any` usage
162
+ - nested ternaries
163
+ - broad exports
164
+ - repeated structural patterns
165
+ - verifying whether a smell is real or just a text coincidence
166
+
167
+ Rule: `tree-search.js` is for fast narrowing. `search.js` is the authoritative proof on live code.
168
+ Rule: if a structural claim matters, check it with AST before presenting it as fact.
169
+
170
+ ### 4. Scanner
171
+
172
+ Use `scripts/run.js` when the question is bigger than one symbol or one file.
173
+
174
+ The scanner is especially important for this skill because it surfaces the issues agents often miss when they focus too narrowly on code:
175
+ - dependency cycles
176
+ - chokepoints and broker modules
177
+ - coupling and fan-in/fan-out pressure
178
+ - layer violations
179
+ - dead code clusters
180
+ - security sinks and risky flows
181
+ - test-quality gaps
182
+ - hotspots and critical paths
183
+
184
+ Use scanner output to reason about:
185
+ - where change risk is concentrated
186
+ - whether a module is structurally unhealthy
187
+ - whether a local fix ignores a broader architectural problem
188
+ - which area should be refactored first
189
+ - where duplication, weak contracts, or poor boundaries are slowing future velocity
190
+ - where complexity, repeated work, or inefficient flows are wasting performance or developer time
191
+
192
+ ### 5. Quality and hygiene checks
193
+
194
+ Use supporting quality checks when the task touches the relevant surface area.
195
+
196
+ | Check | Use it for |
197
+ |------|------------|
198
+ | clean code review | naming, cohesion, responsibility split, readability |
199
+ | contract review | TypeScript types, interfaces, DTOs, schemas, return shapes |
200
+ | duplication review | repeated logic, near-clones, copy-pasted flows, repeated CSS patterns, general redundancy |
201
+ | efficiency review | avoidable `O(n^2)` work, repeated scans, N+1 calls, wasteful transforms, unnecessary recomputation |
202
+ | rigidity review | brittle condition trees, hard-coded branching, patchy glue code, over-coupled modules, naive solutions |
203
+ | docs review | whether critical assumptions, contracts, flows, setup, migrations, and risks are documented where they should be |
204
+ | clean CSS review | selector scope, token reuse, naming clarity, dead styles, layout consistency |
205
+ | `knip` | unused exports, unused files, unused dependencies, dead integration edges |
206
+
207
+ These checks matter because quality and velocity support each other.
208
+ Messy structure slows teams down. Clear structure speeds them up.
209
+
210
+ ### 6. Task and user checkpoints
211
+
212
+ Use task or todo tracking when the work has multiple steps, risks, or follow-ups.
213
+ Track at least:
214
+ - investigation
215
+ - decision or plan
216
+ - implementation
217
+ - verification
218
+ - docs follow-up when needed
219
+
220
+ Ask the user when needed at a real checkpoint, especially if:
221
+ - requirements are ambiguous
222
+ - multiple reasonable architectures exist
223
+ - a public contract or persistence model may change
224
+ - the safest fix conflicts with the smallest fix
225
+ - the work may have migration, rollout, or compatibility impact
226
+
227
+ When asking, be concise and specific. Ask only what is needed to move forward safely.
228
+
229
+ ## Default Working Order
230
+
231
+ For any non-trivial task, follow this order:
232
+
233
+ 1. Clarify the behavior or question.
234
+ 2. Create or update tasks/todos if the work is multi-step.
235
+ 3. Map the package/module area with local tools.
236
+ 4. Trace important symbols with LSP.
237
+ 5. Validate and check structural claims with AST tools.
238
+ 6. Check architecture, docs, and flow risk with the scanner and relevant docs.
239
+ 7. Read the actual code with context.
240
+ 8. Pause and ask the user if a real decision checkpoint appears.
241
+ 9. Only then decide whether to explain, plan, or edit.
242
+
243
+ Short form:
244
+ `clarify -> track -> layout -> symbols -> structure -> architecture/docs -> code -> checkpoint -> action`
245
+
246
+ ## How To Use This Skill
247
+
248
+ ### For code understanding
249
+
250
+ 1. Start with `localViewStructure` or `localFindFiles` to see the area.
251
+ 2. Use `localSearchCode` to find the symbol or flow.
252
+ 3. Use LSP to trace definitions, references, callers, and callees.
253
+ 4. Read the relevant code only after the surrounding context is clear.
254
+ 5. Check whether important contracts or critical flows are documented.
255
+ 6. If the area is shared, central, or suspicious, run a scoped scanner pass.
256
+
257
+ ### For bug fixing
258
+
259
+ 1. Identify the failing behavior and likely entry point.
260
+ 2. Trace incoming callers and outgoing callees.
261
+ 3. Check adjacent risk areas: error handling, retries, side effects, tests, shared consumers, and contract mismatches.
262
+ 4. Use AST tools if the bug may involve a structural smell.
263
+ 5. Use the scanner if the bug points to a hotspot, cycle, or orchestration problem.
264
+ 6. Fix the smallest layer that solves the root cause, not just the symptom.
265
+ 7. Prefer a clean boundary or contract fix over a narrow patch if the issue is systemic.
266
+ 8. Check whether the bug is caused by redundant work, inefficient flow, or rigid branching.
267
+ 9. Check whether the risky behavior and fix assumptions should be documented.
268
+
269
+ ### For refactors
270
+
271
+ 1. Measure blast radius with `lspFindReferences` and `lspCallHierarchy`.
272
+ 2. Check architecture health in the target area with `scripts/run.js --scope=...`.
273
+ 3. Look for similar patterns nearby with AST or local search.
274
+ 4. Check whether duplication, weak contracts, or bad boundaries are the real refactor driver.
275
+ 5. Plan the change if multiple files, packages, or shared symbols are involved.
276
+ 6. Prefer extracting modules, clarifying contracts, simplifying flows, and removing redundant work over cosmetic reshuffling.
277
+ 7. Implement incrementally.
278
+ 8. Re-run verification after each batch.
279
+ 9. Update or propose docs when the refactor changes important usage, contracts, or constraints.
280
+
281
+ ### For architecture review
282
+
283
+ 1. Start broad with the scanner, especially graph and flow output.
284
+ 2. Identify hotspots, cycles, chokepoints, and suspicious shared modules.
285
+ 3. Use local tools to understand the folder and package layout.
286
+ 4. Use LSP to verify the real dependency pressure around candidate modules.
287
+ 5. Read representative files to explain why the structure is problematic.
288
+ 6. Check whether contracts, duplication, and module boundaries support extensibility.
289
+ 7. Check whether critical architectural constraints are documented.
290
+ 8. Report both local code issues and system-level causes.
291
+
292
+ ## Recommended Tool Combos
293
+
294
+ | Question | Recommended approach |
295
+ |----------|----------------------|
296
+ | Where should I start? | `localViewStructure` + `localFindFiles` |
297
+ | What is this symbol? | `localSearchCode` -> `lspGotoDefinition` |
298
+ | Who uses this shared function/type/export? | `localSearchCode` -> `lspFindReferences` |
299
+ | What is the runtime path? | `localSearchCode` -> `lspCallHierarchy` |
300
+ | Is this smell real? | AST search + targeted code read |
301
+ | Can I prove this structural claim? | AST search/tree-search + targeted code read |
302
+ | Are contracts weak or inconsistent? | LSP on public symbols + code read + scanner/AST signals |
303
+ | Is this implementation inefficient? | scanner complexity signals + code read + persistence/query path review |
304
+ | Is this dead code? | `lspFindReferences` + AST import/export check + scanner dead-code signals |
305
+ | Is this module risky to change? | scanner scope + LSP references/call flow + code read |
306
+ | Is the problem architectural? | scanner graph/flow + local structure + LSP on chokepoints |
307
+ | Are important critical aspects documented? | docs/readmes + code boundaries + config/schema/migration docs |
308
+ | Is the codebase losing velocity? | scanner hotspots + duplication/redundancy checks + boundary/contract review |
309
+ | Did the fix actually improve things? | tests + lint/build + scoped scanner + targeted LSP re-check |
310
+
311
+ ## Before / During / After A Change
312
+
313
+ ### Before
314
+ - understand current behavior and invariants
315
+ - find consumers and callers
316
+ - inspect tests around the changed path
317
+ - check whether the area is a hotspot, cycle member, or shared boundary
318
+ - check contracts: types, inputs, outputs, schemas, and public APIs
319
+ - check whether critical behavior and constraints are documented
320
+ - check for duplication before adding another branch or helper
321
+ - check for unnecessary complexity or repeated work before accepting the current shape
322
+ - look for an existing local pattern before inventing a new one
323
+
324
+ ### During
325
+ - keep edits focused
326
+ - preserve boundaries unless the plan intentionally changes them
327
+ - prefer the smallest change that fixes the real issue
328
+ - prefer the cleanest modular fix that keeps the system extendable
329
+ - maintain clear contracts, especially in TypeScript-heavy code
330
+ - reduce redundancy and avoid layering new logic on top of rigid or naive code when a cleaner simplification is possible
331
+ - improve inefficient flows when they are part of the real problem
332
+ - keep CSS clean and scoped if the task touches frontend styling
333
+ - update or flag docs when critical behavior, contracts, setup, migration, or architecture understanding changed
334
+ - if the root cause is structural, say so instead of hiding it behind a cosmetic patch
335
+
336
+ ### After
337
+ - run the relevant tests
338
+ - run lint and build or type-check as appropriate
339
+ - run CSS checks when styles changed
340
+ - run `knip` when refactors may have left dead exports, files, or deps behind
341
+ - re-check changed symbols with LSP after renames or moves
342
+ - run a scoped scanner pass for non-trivial changes
343
+ - verify important critical aspects are documented if the task changed them
344
+ - mention any remaining architectural risk even if the code now works
345
+
346
+ ## Confidence Rules
347
+
348
+ Use these confidence levels in your reasoning and user-facing output:
349
+
350
+ | Level | Meaning |
351
+ |-------|---------|
352
+ | `confirmed` | 2 or more approaches agree, or one source is clearly authoritative |
353
+ | `likely` | good evidence exists, but one important angle is still missing |
354
+ | `uncertain` | signals conflict, context is incomplete, or only one weak source exists |
355
+
356
+ Examples:
357
+ - `confirmed`: AST proves an empty catch, and LSP shows the function is widely used
358
+ - `likely`: scanner reports a hotspot and code shape agrees, but blast radius is still unverified
359
+ - `uncertain`: text search suggests dead code, but LSP is unavailable
472
360
 
473
361
  ## Hard Rules
474
362
 
475
- - Never present unvalidated findings as facts
476
- - Never guess `lineHint` — always get it from `localSearchCode`
477
- - Never use `lspCallHierarchy` on non-function symbols
478
- - Never skip blast-radius checks on shared symbols (M/L)
479
- - Never implement M/L changes without presenting plan to user first
480
- - Always cross-validate with 2+ tool families before confirming a finding
481
-
482
- ## Error Recovery
483
-
484
- | Problem | Recovery |
485
- |---------|----------|
486
- | 0 findings from scan | Relax scope/features; check `parseErrors` in `summary.json`; verify scope has `.ts`/`.js` files |
487
- | LSP unavailable | CLI-only mode (AST scripts); reduce confidence claims |
488
- | AST no matches | Widen `--root`/pattern or switch kind/preset |
489
- | Scan vs LSP mismatch | Report both; treat as uncertain |
490
- | Huge findings count | Triage via `featureScores[]` grades first, filter by severity |
363
+ - Never present raw detector output as unquestioned fact.
364
+ - Never guess `lineHint`; get it from `localSearchCode`.
365
+ - Never use `lspCallHierarchy` on non-function symbols.
366
+ - Never judge a shared module by one file read alone.
367
+ - Never skip local Octocode discovery when those tools are available.
368
+ - Never present an important structural claim without checking it with AST when AST can prove it.
369
+ - Never stop at code style if the deeper issue is structure or flow.
370
+ - Never prefer a quick patch when the real issue is contracts, boundaries, duplication, or architecture.
371
+ - Never ignore obvious inefficiency, redundancy, or rigid code if it materially hurts extensibility or clarity.
372
+ - Never add new duplication if an existing abstraction or module should be improved instead.
373
+ - Never leave critical contract, flow, setup, or migration changes undocumented when documentation is needed.
374
+ - Always check blast radius before changing shared symbols.
375
+ - Always mention architecture, flow, or boundary impact when it matters.
376
+ - Always consider whether the change improves or hurts extensibility and team velocity.
377
+ - Always use task tracking for meaningful multi-step work when the runtime supports it.
378
+ - Always ask the user when a real decision or ambiguity checkpoint blocks safe progress.
379
+ - For medium or large changes, present a plan before making the edit.
380
+
381
+ ## Fallback Mode
382
+
383
+ If local Octocode tools or LSP are unavailable:
384
+ - continue with AST tools and the scanner
385
+ - rely more on local search and direct code reading
386
+ - reduce confidence on semantic claims
387
+ - say clearly which parts were proven and which parts were inferred
388
+
389
+ ## Outcome Standard
390
+
391
+ A good result from this skill should answer all of these:
392
+ - What is happening?
393
+ - Where is the real ownership or boundary?
394
+ - What is the blast radius?
395
+ - Are the contracts clear and safe?
396
+ - Is the problem local, structural, or architectural?
397
+ - Is the implementation efficient enough, or is avoidable complexity hurting it?
398
+ - Is the system becoming cleaner, more modular, and easier to extend?
399
+ - Are important critical aspects documented?
400
+ - What is the safest next move?
401
+
402
+ If the answer only explains one file, it is usually incomplete.
491
403
 
492
404
  ## References
493
- - [Tool workflows](./references/tool-workflows.md) — 21 scenario-specific workflows
494
- - [CLI reference](./references/cli-reference.md) all flags, thresholds, scope details
495
- - [Output files](./references/output-files.md) — JSON schemas, read order, key reference
496
- - [AST reference](./references/ast-reference.md) — presets, patterns, tree-search
497
- - [Validation playbooks](./references/validation-playbooks.md) — per-category validation with worked examples
498
- - [External Tools](./references/externals.md) — `npx` cross-validation: eslint, tsc, stylelint, knip, type-coverage, dep-cruiser
499
- - [Quality Indicators](./references/quality-indicators.md) — complete catalog of 34 code quality detectors, 22 AST presets, metrics, algorithms, thresholds
405
+
406
+ Use these only when needed:
407
+ - [Tool workflows](./references/tool-workflows.md)
408
+ - [CLI reference](./references/cli-reference.md)
409
+ - [Output files](./references/output-files.md)
410
+ - [AST reference](./references/ast-reference.md)
411
+ - [Validation playbooks](./references/validation-playbooks.md)
412
+ - [Quality indicators](./references/quality-indicators.md)
413
+ - [External tools](./references/externals.md)