@opencodehub/cli 0.2.1 → 0.2.3

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.
Files changed (52) hide show
  1. package/dist/commands/ci-templates/github-nightly.yml +35 -0
  2. package/dist/commands/ci-templates/github-rescan.yml +52 -0
  3. package/dist/commands/ci-templates/github-verdict.yml +24 -0
  4. package/dist/commands/ci-templates/github-weekly.yml +49 -0
  5. package/dist/commands/ci-templates/gitlab-ci.yml +56 -0
  6. package/dist/index.js +9 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/plugin-assets/agents/code-analyst.md +18 -0
  9. package/dist/plugin-assets/commands/audit-deps.md +29 -0
  10. package/dist/plugin-assets/commands/owners.md +20 -0
  11. package/dist/plugin-assets/commands/probe.md +21 -0
  12. package/dist/plugin-assets/commands/rename.md +20 -0
  13. package/dist/plugin-assets/commands/verdict.md +18 -0
  14. package/dist/plugin-assets/hooks/augment.sh +128 -0
  15. package/dist/plugin-assets/hooks/docs-staleness.sh +45 -0
  16. package/dist/plugin-assets/hooks.json +34 -0
  17. package/dist/plugin-assets/skills/codehub-code-pack/SKILL.md +181 -0
  18. package/dist/plugin-assets/skills/codehub-code-pack/references/determinism-contract.md +150 -0
  19. package/dist/plugin-assets/skills/codehub-contract-map/SKILL.md +144 -0
  20. package/dist/plugin-assets/skills/codehub-document/SKILL.md +152 -0
  21. package/dist/plugin-assets/skills/codehub-document/references/cross-reference-spec.md +142 -0
  22. package/dist/plugin-assets/skills/codehub-document/references/data-source-map.md +139 -0
  23. package/dist/plugin-assets/skills/codehub-document/references/document-templates.md +347 -0
  24. package/dist/plugin-assets/skills/codehub-document/references/mermaid-patterns.md +181 -0
  25. package/dist/plugin-assets/skills/codehub-document/templates/agents/README.md +64 -0
  26. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-analysis-dead-code.md +104 -0
  27. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-analysis-ownership.md +101 -0
  28. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-analysis-risk-hotspots.md +105 -0
  29. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-architecture-data-flow.md +103 -0
  30. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-architecture-module-map.md +102 -0
  31. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-architecture-system-overview.md +100 -0
  32. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-behavior-processes.md +103 -0
  33. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-behavior-state-machines.md +101 -0
  34. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-cross-repo-contracts-matrix.md +104 -0
  35. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-cross-repo-dependency-flow.md +111 -0
  36. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-cross-repo-portfolio-map.md +106 -0
  37. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-diagrams-components.md +99 -0
  38. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-diagrams-dependency-graph.md +104 -0
  39. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-diagrams-sequences.md +103 -0
  40. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-reference-cli.md +110 -0
  41. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-reference-mcp-tools.md +100 -0
  42. package/dist/plugin-assets/skills/codehub-document/templates/agents/doc-reference-public-api.md +111 -0
  43. package/dist/plugin-assets/skills/codehub-document/templates/orchestrator-prompt.md +110 -0
  44. package/dist/plugin-assets/skills/codehub-onboarding/SKILL.md +111 -0
  45. package/dist/plugin-assets/skills/codehub-pr-description/SKILL.md +122 -0
  46. package/dist/plugin-assets/skills/opencodehub-debugging/SKILL.md +144 -0
  47. package/dist/plugin-assets/skills/opencodehub-exploring/SKILL.md +120 -0
  48. package/dist/plugin-assets/skills/opencodehub-guide/SKILL.md +180 -0
  49. package/dist/plugin-assets/skills/opencodehub-impact-analysis/SKILL.md +151 -0
  50. package/dist/plugin-assets/skills/opencodehub-pr-review/SKILL.md +246 -0
  51. package/dist/plugin-assets/skills/opencodehub-refactoring/SKILL.md +180 -0
  52. package/package.json +16 -14
@@ -0,0 +1,347 @@
1
+ # document-templates — per-file structural templates
2
+
3
+ One template per file the artifact factory emits. Subagents consult this reference when drafting; the skill orchestrator uses it to validate Phase E output.
4
+
5
+ ## Conventions
6
+
7
+ - H1 = identifier (repo name, module name, API section). No decorative titles.
8
+ - No YAML frontmatter on any generated doc.
9
+ - Every factual claim has a backtick citation (`path:LOC` or `repo:path:LOC`).
10
+ - Mermaid only for diagrams; fenced with ```mermaid.
11
+ - "See also" footer is written by Phase E, not by subagents.
12
+
13
+ ## architecture/system-overview.md
14
+
15
+ ```markdown
16
+ # <repo> · System overview
17
+
18
+ 2-paragraph narrative of what the repo does and how the pieces fit.
19
+ Cites `packages/foo/src/index.ts` (200 LOC) style file references.
20
+
21
+ ## Stack
22
+
23
+ | Layer | Technology | Source |
24
+ |---|---|---|
25
+ | Runtime | Node 22 | `package.json:7` |
26
+ | Storage | DuckDB + hnsw_acorn | `packages/storage/src/index.ts:12` |
27
+ | ... | ... | ... |
28
+
29
+ ## Module map
30
+
31
+ ```mermaid
32
+ flowchart LR
33
+ cli[CLI]
34
+ mcp[MCP server]
35
+ analysis[Analysis]
36
+ cli --> mcp
37
+ mcp --> analysis
38
+ ```
39
+
40
+ One Mermaid `flowchart LR`, ≤ 20 nodes.
41
+ ```
42
+
43
+ ## architecture/module-map.md
44
+
45
+ ```markdown
46
+ # <repo> · Module map
47
+
48
+ ## <module-1 name>
49
+
50
+ One-paragraph description. Cites `path:LOC`.
51
+
52
+ - `packages/module-1/src/index.ts` (320 LOC)
53
+ - `packages/module-1/src/types.ts` (88 LOC)
54
+ - ... top 8 files ...
55
+
56
+ ## <module-2 name>
57
+
58
+ (same pattern)
59
+
60
+ ## Supporting code
61
+
62
+ Everything that didn't fit into a named module.
63
+ ```
64
+
65
+ ## architecture/data-flow.md
66
+
67
+ ```markdown
68
+ # <repo> · Data flow
69
+
70
+ ## Flow 1: <process-name>
71
+
72
+ 1. Entry point at `packages/cli/src/commands/analyze.ts:14`.
73
+ 2. Dispatches to `packages/ingestion/src/phases/*.ts`.
74
+ 3. ... numbered steps, each with a backtick citation ...
75
+
76
+ ```mermaid
77
+ sequenceDiagram
78
+ participant CLI
79
+ participant Ingestion
80
+ participant Storage
81
+ CLI->>Ingestion: run(analyze)
82
+ Ingestion->>Storage: writeGraph()
83
+ ```
84
+
85
+ ## Flow 2: <process-name>
86
+ (same pattern, max 3 flows total)
87
+ ```
88
+
89
+ ## reference/public-api.md
90
+
91
+ ```markdown
92
+ # <repo> · Public API
93
+
94
+ ## <exported-symbol-1>
95
+
96
+ ```ts
97
+ export function doThing(input: InputShape): OutputShape
98
+ ```
99
+
100
+ One-sentence description. `packages/foo/src/index.ts:42`.
101
+
102
+ ## <exported-symbol-2>
103
+ (same pattern, top 30 exports)
104
+ ```
105
+
106
+ ## reference/cli.md (conditional)
107
+
108
+ ```markdown
109
+ # <repo> · CLI
110
+
111
+ The `codehub` CLI has the following subcommands.
112
+
113
+ ## analyze
114
+
115
+ ```
116
+ codehub analyze [--incremental] [--quiet]
117
+ ```
118
+
119
+ Runs the ingestion pipeline. `packages/cli/src/commands/analyze.ts:1`.
120
+
121
+ Flags:
122
+ - `--incremental` — skip unchanged files. `packages/cli/src/commands/analyze.ts:22`.
123
+ - `--quiet` — suppress progress output.
124
+
125
+ ## status
126
+ (same pattern)
127
+ ```
128
+
129
+ ## reference/mcp-tools.md (conditional)
130
+
131
+ ```markdown
132
+ # <repo> · MCP tools
133
+
134
+ ## list_repos
135
+
136
+ Enumerates indexed repos on this machine. No inputs.
137
+
138
+ Returns `{ repos: [{ name, graph_hash, indexed_at }] }`.
139
+
140
+ Source: `packages/mcp/src/tools/list-repos.ts:1`.
141
+
142
+ ## query
143
+ (same pattern, one H2 per tool)
144
+ ```
145
+
146
+ ## behavior/processes.md
147
+
148
+ ```markdown
149
+ # <repo> · Processes
150
+
151
+ ## <process-1 name>
152
+
153
+ Entry point: `packages/foo/src/entry.ts:10`.
154
+
155
+ 1. Step 1. `path:LOC`
156
+ 2. Step 2. `path:LOC`
157
+ 3. Step 3. `path:LOC`
158
+
159
+ ### Related
160
+
161
+ - `packages/foo/src/helper-1.ts`
162
+ - `packages/foo/src/helper-2.ts`
163
+
164
+ ## <process-2 name>
165
+ (same pattern, max 8 processes)
166
+ ```
167
+
168
+ ## behavior/state-machines.md (conditional)
169
+
170
+ ```markdown
171
+ # <repo> · State machines
172
+
173
+ ## <machine-1 name>
174
+
175
+ ```mermaid
176
+ stateDiagram-v2
177
+ [*] --> Pending
178
+ Pending --> Running: start()
179
+ Running --> Done: complete()
180
+ Running --> Failed: error()
181
+ ```
182
+
183
+ Defined at `packages/foo/src/state.ts:15`.
184
+ ```
185
+
186
+ ## analysis/risk-hotspots.md
187
+
188
+ ```markdown
189
+ # <repo> · Risk hotspots
190
+
191
+ Top 12 files by combined risk score (30-day window).
192
+
193
+ | File | Trend | Open findings | Top owner | Citation |
194
+ |---|---|---|---|---|
195
+ | packages/foo/src/bar.ts | ↑ rising | 3 warn, 1 error | alice@ | `packages/foo/src/bar.ts` (245 LOC) |
196
+ | ... | ... | ... | ... | ... |
197
+
198
+ ## Per-file drill-down
199
+
200
+ ### packages/foo/src/bar.ts
201
+
202
+ What's there: (2-sentence summary).
203
+ Recent activity: (from risk_trends).
204
+ Owners: alice@ (68%), bob@ (22%).
205
+ Findings: 3 warn, 1 error — see `list_findings` output.
206
+ ```
207
+
208
+ ## analysis/ownership.md
209
+
210
+ ```markdown
211
+ # <repo> · Ownership
212
+
213
+ | Folder | Top owner | Share | Total contributors |
214
+ |---|---|---|---|
215
+ | packages/mcp | ... | 72% | 4 |
216
+ | ... | ... | ... | ... |
217
+
218
+ ## Single points of failure
219
+
220
+ Paths where the top owner has > 70% of commits.
221
+
222
+ - `packages/mcp/src/resources/` — alice@ (82%). No secondary reviewer.
223
+ - ... (each with a 1-sentence mitigation suggestion)
224
+ ```
225
+
226
+ ## analysis/dead-code.md
227
+
228
+ ```markdown
229
+ # <repo> · Dead code
230
+
231
+ ## Unreferenced exports
232
+
233
+ | Symbol | Path | Last modified |
234
+ |---|---|---|
235
+ | oldHelper | packages/foo/src/helpers.ts:120 | 2024-11-03 |
236
+ | ... | ... | ... |
237
+
238
+ ## Unreferenced files
239
+
240
+ | File | Lines | Last modified |
241
+ |---|---|---|
242
+ | packages/legacy/src/deprecated.ts | 88 | 2024-08-12 |
243
+
244
+ ## Dead imports
245
+
246
+ | Path | Symbol | Imported from |
247
+ |---|---|---|
248
+ | packages/foo/src/index.ts:3 | legacy | packages/legacy |
249
+ ```
250
+
251
+ ## diagrams/ — three files
252
+
253
+ Each has exactly one Mermaid diagram (plus optional Legend table when node count was truncated). See `mermaid-patterns.md` for idioms.
254
+
255
+ - `diagrams/architecture/components.md` — `classDiagram`.
256
+ - `diagrams/behavioral/sequences.md` — up to 3 `sequenceDiagram` blocks.
257
+ - `diagrams/structural/dependency-graph.md` — `flowchart LR`.
258
+
259
+ ## cross-repo/ — group mode only
260
+
261
+ ### cross-repo/portfolio-map.md
262
+
263
+ ```markdown
264
+ # <group> · Portfolio map
265
+
266
+ 2-paragraph narrative of the group's shape (domain, member purposes, shared contracts).
267
+
268
+ ## Member repos
269
+
270
+ ```mermaid
271
+ flowchart LR
272
+ billing --> core
273
+ web --> core
274
+ web --> billing
275
+ ```
276
+
277
+ ## Repos
278
+
279
+ ### billing — <one-line description>
280
+
281
+ Citations: `billing:packages/api/src/index.ts:1` (120 LOC).
282
+ [See billing docs →](../../billing/.codehub/docs/README.md)
283
+
284
+ ### core — <one-line description>
285
+ (same pattern)
286
+ ```
287
+
288
+ ### cross-repo/contracts-matrix.md
289
+
290
+ ```markdown
291
+ # <group> · Contracts matrix
292
+
293
+ Rows = producers; columns = consumers. Cell = number of contracts.
294
+
295
+ | | billing | core | web |
296
+ |-------|---------|------|-----|
297
+ | billing | — | 3 | 5 |
298
+ | core | — | — | 12 |
299
+ | web | — | — | — |
300
+
301
+ ## Notable contracts
302
+
303
+ - `billing:packages/api/src/handlers/invoice.ts:45` ← consumed by `web:packages/checkout/src/api.ts:22`.
304
+ - ... (top 10 with direction + path + both-ends citations)
305
+ ```
306
+
307
+ ### cross-repo/dependency-flow.md
308
+
309
+ ```markdown
310
+ # <group> · Dependency flow
311
+
312
+ ```mermaid
313
+ flowchart TB
314
+ web["web"]
315
+ billing["billing"]
316
+ core["core"]
317
+ web -->|POST /invoices| billing
318
+ web -->|GET /user| core
319
+ billing -->|publishes| events[(events.stream)]
320
+ core -.->|consumes| events
321
+ ```
322
+ ```
323
+
324
+ ## README.md (Phase E output)
325
+
326
+ ```markdown
327
+ # <repo-or-group> · Generated documentation
328
+
329
+ *Prose is LLM-generated; structure is graph-derived. Phase E cross-references are deterministic.*
330
+
331
+ Generated at: 2026-04-27T18:12:04Z
332
+ Graph hash: sha256:…
333
+
334
+ ## Structure
335
+
336
+ - [Architecture](architecture/system-overview.md)
337
+ - [Reference](reference/public-api.md)
338
+ - [Behavior](behavior/processes.md)
339
+ - [Analysis](analysis/risk-hotspots.md)
340
+ - [Diagrams](diagrams/architecture/components.md)
341
+ - [Cross-repo](cross-repo/portfolio-map.md) ← group mode only
342
+
343
+ ## Refreshing
344
+
345
+ Run `/codehub-document --refresh` to regenerate stale sections only.
346
+ Run `/codehub-document` without flags for a full regen.
347
+ ```
@@ -0,0 +1,181 @@
1
+ # mermaid-patterns — diagram idioms
2
+
3
+ One diagram type per artifact. Diagrams capped at 20 nodes; overflow goes into a Legend table, never into the diagram. All Mermaid fenced with ```mermaid.
4
+
5
+ No SVG or PNG generation. Ever.
6
+
7
+ ## Dependency graph — `flowchart LR`
8
+
9
+ For `diagrams/structural/dependency-graph.md`. Internal communities as filled nodes; external deps as leaf nodes with a distinct style.
10
+
11
+ ```mermaid
12
+ flowchart LR
13
+ mcp[MCP server]
14
+ core[Core types]
15
+ ingestion[Ingestion DAG]
16
+ storage[Storage]
17
+ duckdb[(DuckDB)]:::external
18
+ mcp --> core
19
+ ingestion --> core
20
+ ingestion --> storage
21
+ storage --> duckdb
22
+ classDef external stroke-dasharray: 3 3
23
+ ```
24
+
25
+ **Rules:**
26
+ - Max 20 nodes.
27
+ - Internal communities: plain rectangles with brackets.
28
+ - External deps: parenthesized shape `node[(name)]:::external` + dashed stroke class.
29
+ - Overflow nodes go into a Legend table below the fenced block.
30
+
31
+ ## Component view — `classDiagram`
32
+
33
+ For `diagrams/architecture/components.md`. Shows has-a and uses relationships between top components.
34
+
35
+ ```mermaid
36
+ classDiagram
37
+ class CLI {
38
+ +analyze()
39
+ +status()
40
+ +verdict()
41
+ }
42
+ class MCPServer {
43
+ +registerTools()
44
+ }
45
+ class IngestionDAG {
46
+ +runPhases()
47
+ }
48
+ CLI --> MCPServer : invokes
49
+ CLI --> IngestionDAG : triggers
50
+ MCPServer --> IngestionDAG : depends
51
+ ```
52
+
53
+ **Rules:**
54
+ - Max 8 components.
55
+ - 3–5 methods per class, chosen by call-count from the graph.
56
+ - Relationships labeled with a one-word verb.
57
+
58
+ ## Top process — `sequenceDiagram`
59
+
60
+ For `diagrams/behavioral/sequences.md`. One diagram per top process, up to 3.
61
+
62
+ ```mermaid
63
+ sequenceDiagram
64
+ participant User
65
+ participant CLI
66
+ participant MCP
67
+ participant Storage
68
+ User->>CLI: codehub analyze
69
+ CLI->>MCP: register(tools)
70
+ MCP->>Storage: write(graph)
71
+ Storage-->>MCP: graph_hash
72
+ MCP-->>CLI: ready
73
+ CLI-->>User: analyzed N files
74
+ ```
75
+
76
+ **Rules:**
77
+ - 4–8 participants per diagram.
78
+ - Lifelines in dispatch order.
79
+ - Solid arrows for calls, dashed for returns.
80
+
81
+ ## State machine — `stateDiagram-v2`
82
+
83
+ For `behavior/state-machines.md` (conditional).
84
+
85
+ ```mermaid
86
+ stateDiagram-v2
87
+ [*] --> Pending
88
+ Pending --> Running: start()
89
+ Running --> Done: complete()
90
+ Running --> Failed: error()
91
+ Failed --> Pending: retry()
92
+ Done --> [*]
93
+ ```
94
+
95
+ **Rules:**
96
+ - Every transition labeled with the triggering event.
97
+ - `[*]` entry/exit always present.
98
+
99
+ ## Data flow — `flowchart TB`
100
+
101
+ For `architecture/data-flow.md`.
102
+
103
+ ```mermaid
104
+ flowchart TB
105
+ source[Repo files]
106
+ parse[tree-sitter parser]
107
+ graph[DuckDB graph]
108
+ embed[ONNX embedder]
109
+ query[MCP query]
110
+ source --> parse
111
+ parse --> graph
112
+ parse --> embed
113
+ embed --> graph
114
+ query --> graph
115
+ ```
116
+
117
+ **Rules:**
118
+ - Top-to-bottom flow (`TB`).
119
+ - Stores as rectangular bracket nodes; processes as simple bracket nodes; external interfaces as parenthesized nodes.
120
+
121
+ ## Cross-repo portfolio — `flowchart LR`
122
+
123
+ For `cross-repo/portfolio-map.md` (group mode).
124
+
125
+ ```mermaid
126
+ flowchart LR
127
+ billing["billing<br/>payment domain"]
128
+ core["core<br/>shared types + auth"]
129
+ web["web<br/>customer-facing UI"]
130
+ web -->|contracts: 5| billing
131
+ web -->|contracts: 12| core
132
+ billing -->|contracts: 3| core
133
+ ```
134
+
135
+ **Rules:**
136
+ - Node labels include a one-line domain description (use `<br/>` for the second line).
137
+ - Edge labels include the contract count from `group_contracts`.
138
+
139
+ ## Cross-repo dependency flow — `flowchart TB`
140
+
141
+ For `cross-repo/dependency-flow.md` (group mode).
142
+
143
+ ```mermaid
144
+ flowchart TB
145
+ web["web"]
146
+ billing["billing"]
147
+ core["core"]
148
+ events[(events.stream)]
149
+ web -->|POST /invoices| billing
150
+ web -->|GET /user| core
151
+ billing -->|publishes| events
152
+ core -.->|consumes| events
153
+ ```
154
+
155
+ **Rules:**
156
+ - Nodes are repos; events/queues are parenthesized shape.
157
+ - Edge labels are the HTTP verb + path (for routes) or the event type (for streams).
158
+ - Dashed edges for async/pub-sub; solid for synchronous calls.
159
+
160
+ ## Legend tables
161
+
162
+ When a diagram exceeds 20 nodes, keep the top-20-by-edge-count in the diagram and add a Legend table immediately below:
163
+
164
+ ```markdown
165
+ ## Legend (overflow)
166
+
167
+ These nodes were elided from the diagram above for readability:
168
+
169
+ | Node | Edges | Reason for elision |
170
+ |---|---|---|
171
+ | peripheral-module-1 | 3 | Too few edges |
172
+ | deprecated-thing | 2 | Slated for removal |
173
+ ```
174
+
175
+ ## Diagram label length rules
176
+
177
+ Mermaid breaks on long labels. Keep them short:
178
+
179
+ - Node labels: ≤ 20 characters (excluding explicit `<br/>`).
180
+ - Edge labels: ≤ 15 characters.
181
+ - Use abbreviations liberally; spell the full name in a Legend table.
@@ -0,0 +1,64 @@
1
+ # templates/agents — per-file packet skeletons
2
+
3
+ Each `.md` file here is a **packet skeleton** for one output document produced by `codehub-document`. The skill orchestrator seeds one packet per output file by copying a skeleton to `<docs-root>/.packets/<file-role>.md`, substituting placeholders, and spawning a `general-purpose` subagent with a short prompt that points at the packet path.
4
+
5
+ ## Contract
6
+
7
+ Every skeleton follows the same shape, ported from `erpaval/templates/session/task-skeleton.md` and adapted for doc-writing:
8
+
9
+ ```yaml
10
+ ---
11
+ role: <file-role> # doc-architecture-system-overview, doc-reference-public-api, ...
12
+ model: sonnet # overridable by the orchestrator
13
+ output: "{{ docs_root }}/<path>.md" # exactly one file per packet
14
+ depends_on:
15
+ - "{{ context_path }}" # .codehub/docs/.context.md (or equivalent)
16
+ - "{{ prefetch_path }}" # .codehub/docs/.prefetch.md
17
+ status: IN_PROGRESS
18
+ ---
19
+ ```
20
+
21
+ Then ten numbered sections, in order, using the ERPAVal `<write_protocol>` discipline:
22
+
23
+ 1. **Objective** — one sentence: the single file this packet produces and why it exists.
24
+ 2. **Scope** — the exact output path; any other paths the subagent is *not* allowed to touch.
25
+ 3. **Input specification** — source MCP tools / files, each marked `cached` (read from `.prefetch.md`) or `mid-run` (subagent may call).
26
+ 4. **Process** — numbered steps from read-shared-context → draft → write.
27
+ 5. **Document format rules** — H1 shape, citation grammar, diagram rules, "no YAML frontmatter on outputs".
28
+ 6. **Tool usage guide** — a short table mapping need → tool → why.
29
+ 7. **Fallback paths** — what to do when a tool returns empty / errors / is stale.
30
+ 8. **Success criteria** — mechanical checks the subagent validates before flipping `status: COMPLETE`.
31
+ 9. **Anti-goals** — common failure modes to avoid (re-calling cached tools, inventing edges, hallucinating symbol names).
32
+ 10. **Work log / Validation / Summary** — three trailing sections the subagent edits during execution per the write protocol.
33
+
34
+ ## Placeholders
35
+
36
+ Filled by the orchestrator at seed time. Common to every skeleton:
37
+
38
+ | Placeholder | Example value (single-repo) | Example value (group mode) |
39
+ |---|---|---|
40
+ | `{{ docs_root }}` | `.codehub/docs` | `.codehub/groups/<group>/docs` |
41
+ | `{{ repo }}` | `opencodehub` | member repo name |
42
+ | `{{ context_path }}` | `.codehub/docs/.context.md` | `.codehub/groups/<group>/docs/.context.md` |
43
+ | `{{ prefetch_path }}` | `.codehub/docs/.prefetch.md` | `.codehub/groups/<group>/docs/.prefetch.md` |
44
+ | `{{ packet_path }}` | `.codehub/docs/.packets/doc-architecture-system-overview.md` | `.codehub/groups/<group>/docs/.packets/...` |
45
+ | `{{ graph_hash }}` | `sha256:a1b2c3…` | (same) |
46
+
47
+ Cross-repo skeletons add:
48
+
49
+ | Placeholder | Example |
50
+ |---|---|
51
+ | `{{ group }}` | `platform` |
52
+ | `{{ group_docs_root }}` | `.codehub/groups/platform/docs` |
53
+
54
+ ## Spawn prompt
55
+
56
+ The orchestrator spawns each subagent with the prompt in `../orchestrator-prompt.md`. That prompt is deliberately short — all role-specific instructions live in the packet itself.
57
+
58
+ ## Write protocol
59
+
60
+ Every skeleton embeds the doc-variant `<write_protocol>` block verbatim. The rhythm is "read tool output → Write output file → edit packet section with the outcome" (vs. ERPAVal's "read code → edit code → run check → edit packet").
61
+
62
+ ## Why file-level, not role-level
63
+
64
+ One packet = one output file. Blast radius of a failing subagent is one file. `--refresh` and `--section` become trivial 1-subagent dispatches. `.docmeta.json.sections[i].agent` still records the role for auditability.
@@ -0,0 +1,104 @@
1
+ ---
2
+ role: doc-analysis-dead-code
3
+ model: sonnet
4
+ output: "{{ docs_root }}/analysis/dead-code.md"
5
+ depends_on:
6
+ - "{{ context_path }}"
7
+ - "{{ prefetch_path }}"
8
+ status: IN_PROGRESS
9
+ ---
10
+
11
+ # Packet · {{ repo }} · analysis/dead-code.md
12
+
13
+ ## 1. Objective
14
+
15
+ Produce `{{ docs_root }}/analysis/dead-code.md`: three tables enumerating unreferenced exports, unreferenced files, and dead imports in `{{ repo }}`. The file is always emitted — when the graph reports no dead code, emit a `No unreferenced symbols detected.` banner plus a timestamp so Phase E cross-references have a stable target.
16
+
17
+ ## 2. Scope
18
+
19
+ - Create: `{{ docs_root }}/analysis/dead-code.md`
20
+ - Do not touch: `{{ docs_root }}/analysis/risk-hotspots.md`, `{{ docs_root }}/analysis/ownership.md`, any other file under `{{ docs_root }}/`, any source file in the repo, `.context.md`, `.prefetch.md`, or any `.packets/*.md` other than this one.
21
+
22
+ ## 3. Input specification
23
+
24
+ | Source | Read how | Cache state |
25
+ |---|---|---|
26
+ | Shared context | `Read {{ context_path }}` | always first |
27
+ | Prefetch ledger | `Read {{ prefetch_path }}` | always first |
28
+ | Dead-code inventory | `mcp__opencodehub__list_dead_code({repo: "{{ repo }}"})` | mid-run (rarely cached; the tool is cheap) |
29
+ | Last-modified per path | from `list_dead_code` response fields when present, else `git log -1 --format=%cs -- <path>` via shell | mid-run |
30
+ | Graph hash | `{{ graph_hash }}` for the empty-state banner timestamp anchor | cached |
31
+
32
+ ## 4. Process
33
+
34
+ 1. `Read {{ context_path }}` and `Read {{ prefetch_path }}`. Confirm graph hash and any cached dead-code digest.
35
+ 2. Call `mcp__opencodehub__list_dead_code({repo: "{{ repo }}"})`. Partition the response into three buckets: `Unreferenced exports`, `Unreferenced files`, `Dead imports`.
36
+ 3. If all three buckets are empty: skip to step 7 (empty-state banner).
37
+ 4. For `Unreferenced exports`: draft a table with columns `Symbol | Path | Last modified`. Path is a backtick `path:LOC`. Last modified is an ISO date.
38
+ 5. For `Unreferenced files`: draft a table with columns `File | Lines | Last modified`. File is a backtick `path`. Lines is an integer LOC count.
39
+ 6. For `Dead imports`: draft a table with columns `Path | Symbol | Imported from`. Path is a backtick `path:LOC` at the import site; Imported from is a backtick `path` (module/package).
40
+ 7. Empty-state handling: if `list_dead_code` returns no rows in any bucket, emit the banner `No unreferenced symbols detected.` on its own line, followed by `Graph hash: {{ graph_hash }}` and a UTC timestamp line. Still emit the three H2 headings (`## Unreferenced exports`, `## Unreferenced files`, `## Dead imports`) each with a single `_none_` line under them, so Phase E cross-references resolve.
41
+ 8. `Write {{ docs_root }}/analysis/dead-code.md` with H1 = `{{ repo }} · Dead code`.
42
+
43
+ ## 5. Document format rules
44
+
45
+ - H1 = `{{ repo }} · Dead code`. No decorative titles.
46
+ - No YAML frontmatter on the output file.
47
+ - Three H2s in this fixed order: `## Unreferenced exports`, `## Unreferenced files`, `## Dead imports`.
48
+ - `Unreferenced exports` table columns: `Symbol | Path | Last modified`.
49
+ - `Unreferenced files` table columns: `File | Lines | Last modified`.
50
+ - `Dead imports` table columns: `Path | Symbol | Imported from`.
51
+ - Every Path / File / Imported from cell is a backtick `path` or `path:LOC`.
52
+ - Empty-state banner is a single line `No unreferenced symbols detected.` followed by `Graph hash: {{ graph_hash }}` and a UTC timestamp.
53
+ - Under the empty state, each of the three H2 sections contains a single `_none_` line.
54
+ - No emojis. No filler adverbs.
55
+
56
+ ## 6. Tool usage guide
57
+
58
+ | Need | Tool | Why |
59
+ |---|---|---|
60
+ | Unreferenced symbols + files | `mcp__opencodehub__list_dead_code` | graph-aware; deletes are safe |
61
+ | Last-modified per path | `list_dead_code` fields, else `git log -1` shell | graph does not always carry mtime |
62
+ | LOC per unreferenced file | `Read` then line count | graph stores node spans, not file LOC |
63
+ | Cross-check at import site | `Read` at `path:LOC` | verify import survives before listing as dead |
64
+
65
+ ## 7. Fallback paths
66
+
67
+ - If `list_dead_code` errors or times out: write the failure to the Work log, retry once, and on a second failure emit the empty-state banner with an added line `*list_dead_code unavailable — re-run after codehub analyze*`. The file must still exist.
68
+ - If `list_dead_code` returns an `Unreferenced exports` row whose symbol is actually re-exported from a barrel (false positive): `Read` the barrel and drop the row, citing the removal in the Work log.
69
+ - If a `Last modified` field is missing from the response: run `git log -1 --format=%cs -- <path>` via the shell; if that also fails, use `—` in the cell and note in the Work log.
70
+ - If all three buckets are empty, always follow the step-7 empty-state flow; do not skip the Write step.
71
+
72
+ ## 8. Success criteria
73
+
74
+ - [ ] `{{ docs_root }}/analysis/dead-code.md` exists on disk (even when empty).
75
+ - [ ] H1 line reads `# {{ repo }} · Dead code`.
76
+ - [ ] All three H2 headings exist in the fixed order `Unreferenced exports`, `Unreferenced files`, `Dead imports`.
77
+ - [ ] Every populated table row has a backtick path citation in its Path/File/Imported-from column.
78
+ - [ ] When all three buckets are empty: the banner `No unreferenced symbols detected.` appears once, the graph hash is cited, and each H2 contains `_none_`.
79
+ - [ ] When tables have rows: column headers match the fixed schema in Section 5.
80
+ - [ ] No YAML frontmatter on the output.
81
+ - [ ] No row cites a symbol absent from `list_dead_code` output (spot-check 3).
82
+
83
+ ## 9. Anti-goals
84
+
85
+ - Do not re-call `list_dead_code` inside the same packet run — one call, then cache in the Work log.
86
+ - Do not invent unreferenced symbols, files, or imports — every row must map to a `list_dead_code` response entry.
87
+ - Do not omit the three H2 headings when buckets are empty; the skeleton must stay consistent for Phase E.
88
+ - Do not delete the file or skip the Write step when buckets are empty — the banner is the product in that case.
89
+ - Do not write YAML frontmatter on the output file.
90
+ - Do not emit emojis.
91
+
92
+ ---
93
+
94
+ ## Work log
95
+
96
+ {{ subagent fills this section per the write protocol }}
97
+
98
+ ## Validation
99
+
100
+ {{ checks run, outputs pasted, any fixes applied }}
101
+
102
+ ## Summary
103
+
104
+ {{ one paragraph — what shipped, row counts per bucket, whether the empty-state path was taken }}