ai-spector 0.4.2 → 0.4.4

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 (33) hide show
  1. package/package.json +1 -1
  2. package/scaffold/cursor/skills/README.md +0 -1
  3. package/scaffold/cursor/skills/_skill-router.md +2 -4
  4. package/scaffold/cursor/skills/ai-spector/SKILL.md +1 -2
  5. package/scaffold/cursor/skills/ai-spector/references/cli-failures.md +43 -167
  6. package/scaffold/cursor/skills/ai-spector/references/context-management.md +157 -0
  7. package/scaffold/cursor/skills/ai-spector/references/generate-graph.md +6 -1
  8. package/scaffold/cursor/skills/ai-spector/references/generate-workflow.md +45 -105
  9. package/scaffold/cursor/skills/ai-spector/references/project-conventions.md +0 -1
  10. package/scaffold/cursor/skills/ai-spector-generate/SKILL.md +3 -7
  11. package/scaffold/cursor/skills/ai-spector-generate-basic-design/SKILL.md +18 -16
  12. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/api-detail.md +27 -0
  13. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/api-list.md +26 -0
  14. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/db-design.md +22 -0
  15. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/screen-detail.md +26 -0
  16. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/screen-list.md +27 -0
  17. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/runbook.md +16 -1
  18. package/scaffold/cursor/skills/ai-spector-generate-prototype/SKILL.md +17 -26
  19. package/scaffold/cursor/skills/ai-spector-generate-prototype/references/prototype-graph-context.md +115 -0
  20. package/scaffold/cursor/skills/ai-spector-generate-prototype/references/runbook.md +31 -2
  21. package/scaffold/cursor/skills/ai-spector-generate-prototype/references/theme-picker.md +2 -0
  22. package/scaffold/cursor/skills/ai-spector-generate-srs/SKILL.md +22 -20
  23. package/scaffold/cursor/skills/ai-spector-generate-srs/references/runbook.md +17 -0
  24. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/data-requirements.md +10 -0
  25. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/external-interfaces.md +10 -0
  26. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/feature-detail.md +20 -0
  27. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/introduction.md +12 -0
  28. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/overall-description.md +11 -0
  29. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/quality-attributes.md +11 -0
  30. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/use-case-detail.md +26 -0
  31. package/scaffold/cursor/skills/ai-spector-graph/SKILL.md +1 -2
  32. package/scaffold/cursor/skills/ai-spector-generate-detail-design/SKILL.md +0 -33
  33. package/scaffold/cursor/skills/ai-spector-generate-detail-design/references/runbook.md +0 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-spector",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Cursor-first documentation workflow: traceability graph, SRS/basic/detail design templates, and ai-spector CLI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,7 +14,6 @@ Enable **every** folder under `.cursor/skills/` in Cursor (Settings → Rules
14
14
  | Analyze, index, validate graph, impact, visualize | `ai-spector-graph` |
15
15
  | SRS / requirements | `ai-spector-generate-srs` |
16
16
  | Screens, APIs, DB basic design | `ai-spector-generate-basic-design` |
17
- | Detail / implementation design | `ai-spector-generate-detail-design` |
18
17
  | HTML prototype | `ai-spector-generate-prototype` |
19
18
  | Review comments | `ai-spector-resolve-comments` |
20
19
  | Unsure | `ai-spector` (core) |
@@ -6,7 +6,7 @@ Agents use this when intent is ambiguous.
6
6
 
7
7
  1. **File context** — `paths` in skill frontmatter (e.g. `prototype/**` → prototype skill).
8
8
  2. **Natural language** — match skill `description`; then read that skill’s `references/` runbook.
9
- 3. **Still unclear** — `ai-spector` core + one question (graph vs SRS vs basic design vs detail vs prototype vs comments).
9
+ 3. **Still unclear** — `ai-spector` core + one question (graph vs SRS vs basic design vs prototype vs comments).
10
10
 
11
11
  ## Task → skill → runbook
12
12
 
@@ -22,8 +22,7 @@ Agents use this when intent is ambiguous.
22
22
  | doc summaries | `ai-spector-graph` | `references/summary.md` |
23
23
  | SRS, use cases, features, requirements | `ai-spector-generate-srs` | `references/runbook.md` |
24
24
  | screens, APIs, wireframes, basic design | `ai-spector-generate-basic-design` | `references/runbook.md` |
25
- | detail design, implementation spec | `ai-spector-generate-detail-design` | `references/runbook.md` |
26
- | HTML prototype | “HTML prototype”, “mockup screens”, “prototype with stripe theme” | `ai-spector-generate-prototype` | `references/runbook.md`, `references/theme-picker.md` |
25
+ | HTML prototype | `ai-spector-generate-prototype` | `references/runbook.md` |
27
26
  | review comments, C-001, inbox | `ai-spector-resolve-comments` | `references/runbook.md` |
28
27
  | “generate docs” (no layer named) | `ai-spector-generate` | route to one skill above |
29
28
 
@@ -34,7 +33,6 @@ Shared: [ai-spector/references/cli-failures.md](./ai-spector/references/cli-fail
34
33
  ```text
35
34
  analyze → validate graph → generate SRS → index
36
35
  → generate basic design → index
37
- → generate detail design
38
36
  → prototype setup → generate HTML screens
39
37
  ```
40
38
 
@@ -4,7 +4,7 @@ description: >-
4
4
  Provides shared rules for AI Spector docflow projects: CLI failure handling, traceability graph path,
5
5
  and routing to task skills. Use when the user mentions ai-spector, docflow, or .ai-spector but the
6
6
  task is unclear, or for init and project layout. Do not use when the user clearly wants SRS,
7
- basic design, detail design, HTML prototype, graph operations, or comment resolution — use the
7
+ basic design, HTML prototype, graph operations, or comment resolution — use the
8
8
  matching task skill instead.
9
9
  ---
10
10
 
@@ -36,7 +36,6 @@ When `ai-spector` exits non-zero, required `--json` is invalid, or a required MC
36
36
  | Analyze, index, validate, impact, visualize | `ai-spector-graph` |
37
37
  | SRS | `ai-spector-generate-srs` |
38
38
  | Basic design | `ai-spector-generate-basic-design` |
39
- | Detail design | `ai-spector-generate-detail-design` |
40
39
  | Prototype | `ai-spector-generate-prototype` |
41
40
  | Comments | `ai-spector-resolve-comments` |
42
41
  | “Generate docs” (vague) | `ai-spector-generate` |
@@ -1,185 +1,61 @@
1
- # CLI and tool failures (mandatory agent behavior)
1
+ # CLI failures
2
2
 
3
- When any `ai-spector` command **fails** (non-zero exit, throws, or empty/invalid JSON when `--json` was required), or a **required tool** fails unexpectedly (MCP, terminal, network):
3
+ **Load this file only when a CLI command fails.** Do not pre-load.
4
4
 
5
- 1. **Pause** the current step no templates, no subagents, no writing `docs/srs/**`, no silent fallbacks.
6
- 2. **Report** using the response format below (verbatim CLI/tool output).
7
- 3. **Offer recovery** — always present **fix and retry** (recommended) and, when safe, a **bounded workaround** the agent can execute if the user approves.
8
- 4. **Wait for the user** (or apply [auto-fix without asking](#agent-may-fix-without-asking-small-local) only for trivial local fixes).
9
- 5. After fix or approved workaround, **continue the same task** from the failed step (re-run the same CLI when possible).
5
+ When any `ai-spector` command exits non-zero or returns invalid JSON:
10
6
 
11
- **Default:** fix and retry. **Workarounds** are allowed only with explicit user approval and the guardrails in [Workaround catalog](#workaround-catalog-user-approval-required).
7
+ 1. **Pause** no writing, no silent fallbacks.
8
+ 2. **Report** with the format below.
9
+ 3. **Offer recovery** — fix + retry (default), or bounded workaround if approved.
10
+ 4. **Wait** — then continue the same task from the failed step.
12
11
 
13
- ---
14
-
15
- ## Recovery flow
16
-
17
- ```text
18
- Tool/CLI fails
19
- → pause + report (Blocked format)
20
- → propose Option 1 (fix & retry) + Option 2 (workaround, if any) + Option 3 (pause)
21
- → user picks (or auto-fix for trivial cases)
22
- → execute choice → re-run same CLI at next checkpoint when possible
23
- ```
24
-
25
- | User says | Agent does |
26
- |-----------|------------|
27
- | **1**, “fix”, “retry”, “yes fix” | Apply fix steps (or ask for one missing input), re-run **the same** failed command/step |
28
- | **2**, “workaround”, “continue anyway” | Follow [Workaround catalog](#workaround-catalog-user-approval-required); state trade-offs; merge/validate when writing docs |
29
- | **3**, “pause”, “stop”, no reply yet | Stop; do not generate or bulk-read docs; user re-runs the task later |
30
- | “you figure it out” / “use your judgment” | Prefer **fix and retry** first; if blocked after one retry, propose the **smallest** approved workaround and ask once |
31
-
32
- Do **not** leave the user stuck with only “run `/analyze` again” when you can propose a concrete fix **or** a bounded workaround.
12
+ Auto-fix without asking: typo in seed id, missing parent dir, wrong cwd — fix and retry once.
13
+ Must ask user: deleting graph files, large manual edits, any workaround not listed below.
33
14
 
34
15
  ---
35
16
 
36
- ## Forbidden (unless user explicitly approves a workaround)
37
-
38
- | Do not | Why |
39
- |--------|-----|
40
- | Hand-edit `traceability.graph.json` at scale | Bypasses merge/validate; drifts from `knowledge.json` |
41
- | Implement graph BFS/search in the agent | Duplicates `graph query` / `graph impact` |
42
- | Glob or read all of `docs/srs/**` because query failed | Hides missing graph or bad seed id |
43
- | Use `.ai-spector/index/*.md` as **primary** context when validate/query failed | Index is fallback only after **successful** CLI with thin graph |
44
- | Skip `graph merge` and “fill SRS from memory” | Breaks traceability |
45
- | Silently continue after `graph validate` errors | Generation will be wrong or inconsistent |
46
- | Tell the user “run this CLI yourself” without offering to run it | Agent owns CLI in this workflow |
47
- | Continue generation after CLI failure **without** user choosing fix, workaround, or pause | User must not be blocked silently or bypassed silently |
48
-
49
- **Allowed after successful CLI:** If `graph query --json` succeeds but `nodes` has no domain entries, say so and suggest **analyze** — still do not bulk-read `docs/srs/**`.
50
-
51
- ---
52
-
53
- ## Response format (copy this structure)
54
-
55
- ```markdown
56
- ## Blocked: <task or slash-command> — <CLI | tool> failed
57
-
58
- **Command / tool:** `ai-spector <subcommand> …` or `<MCP tool name>`
59
- **Exit code:** <n> (if applicable)
17
+ ## Report format
60
18
 
61
- **Output:**
62
- \`\`\`
63
- <paste full stdout/stderr or tool error>
64
- \`\`\`
65
-
66
- **What this means:** <one or two sentences>
67
-
68
- **How to fix (recommended):**
69
- 1. <step agent or user can take>
70
- 2. <step>
71
- 3. Re-run the same step: `<exact command>` or **/<slash-command>**
72
-
73
- **Workaround (optional):** <only if bounded and useful — e.g. “read these 2 projection paths and draft section X; merge after index recovers”>
74
- **Trade-off if workaround:** <traceability / staleness risk in plain language>
75
-
76
- **What would you like to do?**
77
- 1. **Fix and retry** (recommended) — <one-line summary of fix path>
78
- 2. **Workaround** — <one-line summary; skip only if none applies>
79
- 3. **Pause** — stop here; you fix environment and say “retry” or re-run the task
80
-
81
- Reply with **1**, **2**, **3**, or tell me your preference.
82
19
  ```
83
-
84
- For **optional** steps (e.g. `graph visualize --open`), you may use a shorter **Interrupted** header but still offer fix vs skip.
85
-
86
- ---
87
-
88
- ## Workaround catalog (user approval required)
89
-
90
- Use only when the user chooses **2** or explicitly accepts the trade-off. Prefer the **smallest** scope that unblocks the task; return to CLI as soon as it works.
91
-
92
- | Situation | Workaround | Guardrails | Restore traceability |
93
- |-----------|------------|------------|----------------------|
94
- | `graph query` fails once (cwd, typo) | Fix cwd/seed id; one retry | No doc writes until query succeeds | Re-run query before write |
95
- | `graph query` OK but thin `nodes` | Read only `projectionPaths` + cited `docs/data-source/**` | Named paths only; no `docs/srs/**` glob | `graph merge` + `validate` after draft |
96
- | `graph validate` — one bad id/edge | Patch **single** node/edge; re-validate | No mass graph surgery | `validate` must pass before next wave |
97
- | `graph merge` — one bad `listedInSection` | Fix id in `knowledge.json`; re-merge | No hand-merge of full graph | Same |
98
- | `index` fails on one path | Skip that path if command allows; fix path and re-index | Do not skip required wave index without user OK | Re-run **index** for skipped paths |
99
- | Optional visualize fails | Skip open; continue pipeline | User chose workaround | None |
100
- | Terminal/env (not git, missing `uv`) | Agent runs install/init steps user approves | No destructive deletes without ask | Re-run failed CLI |
101
- | Generation blocked only by **upstream** missing SRS | User approves generating prerequisite layer first | Run prerequisite wave with normal merge/validate | Full pipeline order |
102
-
103
- After any workaround that wrote docs or graph patches: **`graph validate`** (and **`index`** when the command doc requires) before the next wave.
20
+ ## Blocked: <command> failed
21
+ **Command:** `ai-spector <subcommand>` **Exit:** <n>
22
+ **Output:** <paste stdout/stderr>
23
+ **Means:** <one sentence>
24
+ **Fix:** <steps> then re-run `<same command>`
25
+ **Workaround (if any):** <bounded scope + trade-off>
26
+
27
+ Reply: 1 Fix & retry 2 Workaround 3 Pause
28
+ ```
104
29
 
105
30
  ---
106
31
 
107
- ## Common failures → fixes
108
-
109
- ### `ai-spector: command not found`
110
-
111
- - **Means:** Package not installed or not on PATH.
112
- - **Fix:** `npm install ai-spector` in the project; agent uses `npx ai-spector …` from project root.
113
-
114
- ### `Could not find project root` / missing `docflow.config.json`
115
-
116
- - **Means:** `init` not run or wrong working directory.
117
- - **Fix:** Run `npx ai-spector init` from project root; agent `cd`s to workspace root before CLI.
118
-
119
- ### `ai-spector analyze` fails
120
-
121
- - **Means:** Registry/templates or graph bootstrap broke.
122
- - **Fix:** Show full error; check `.ai-spector/registry/section-registry.json` exists; re-run `init` if config is corrupt; do not proceed to merge.
123
-
124
- ### `graph merge` — `No domain entries in knowledge.json`
125
-
126
- - **Means:** Analyze extract did not populate staging.
127
- - **Fix:** Re-run `/analyze`; ensure `docs/data-source/` has real markdown files with UC/F/actor content; fill `knowledge.json` with at least one `useCase` or `feature`.
128
- - **Workaround (user OK):** Manually add minimal entries to `knowledge.json` then re-merge.
129
-
130
- ### `graph merge` — `Merge edge missing target node` / section id
131
-
132
- - **Means:** `listedInSection` points to a section id not in the graph.
133
- - **Fix:** Use a section id from `section-registry.json` (e.g. `sec.srs.3-use-cases.l3.3.32-list-use-case`) or omit `listedInSection` for defaults; re-run merge.
134
-
135
- ### `graph validate` — `DOC-SECTION-COVERAGE` on `doc.bd.list-api` / `doc.bd.list-screen` / `doc.bd.db-design`
136
-
137
- - **Means:** Basic-design **list chapter** documents exist in the graph without child `section` nodes (common after a projection-only `graph merge` before bootstrap/index).
138
- - **Fix:** From project root run **`npx ai-spector index`** (or ask to **refresh index**). Ensure `.ai-spector/templates/basic_design/` exists (`npx ai-spector init`). Then re-run **`graph merge`** for your patch and **`graph validate`**.
139
-
140
- ### `graph validate` — `DOMAIN-ANCHORED` / `SECTION-TREE` / `SCHEMA`
141
-
142
- - **Means:** Graph inconsistent with rules.
143
- - **Fix:** Paste each `[ERROR]` line; prefer re-run **analyze** (merge) over manual JSON surgery; for one bad id, agent may patch **only** that node/edge then re-validate.
144
-
145
- ### `graph query <id>` — seed missing or empty subgraph
146
-
147
- - **Means:** Wrong id, or domain not merged.
148
- - **Fix:** Run **visualize-graph** or `graph query` with a known id from `knowledge.json`; run **analyze** if no `useCase`/`feature` nodes.
149
-
150
- ### `graph query` — invalid JSON / parse error
151
-
152
- - **Means:** CLI crashed or wrong cwd.
153
- - **Fix:** Re-run from project root; if repeat, report as tool bug with full stderr.
154
-
155
- ### `graph impact --git` — not a git repository / no changes
156
-
157
- - **Means:** `--git` needs a git working tree with staged or unstaged diffs.
158
- - **Fix:** Initialize git (`git init`) and make edits, or use **impact** with a short description, editor selection, or `--file` / `--heading` instead of `--git`.
159
-
160
- ### `graph impact --git` — could not map diff to graph seeds
161
-
162
- - **Means:** Changed paths are not linked to `document` / `section` nodes (e.g. only `README.md` or `src/`).
163
- - **Fix:** Run impact on doc paths under `docs/` or `.ai-spector/`; or **impact** with a short description of the traceability change.
164
-
165
- ### Stale graph or indexes after manual edits or generate SRS
166
-
167
- - **Means:** User changed `docs/data-source/`, SRS outputs, or templates without re-running ingest; graph still shows template-only domain nodes.
168
- - **Fix:** Run **`ai-spector index`**. For fully stale domain detail, re-run **`/analyze`** → fresh `knowledge.json`.
32
+ ## Common fixes
33
+
34
+ | Error | Fix |
35
+ |---|---|
36
+ | `command not found` | `npm install ai-spector`; use `npx ai-spector` |
37
+ | `Could not find project root` | Run `npx ai-spector init`; check cwd |
38
+ | `analyze` fails | Show full error; check registry exists; re-run init if corrupt |
39
+ | `merge` no domain entries | Re-run `/analyze`; ensure data-source has UC/F/actor content |
40
+ | `merge` — missing target node | Fix section id from `section-registry.json`; re-merge |
41
+ | `validate` — DOC-SECTION-COVERAGE | Run `ai-spector index` then re-merge and re-validate |
42
+ | `validate` DOMAIN-ANCHORED / SCHEMA | Re-run analyze; patch only the single bad node/edge |
43
+ | `graph query` — empty subgraph | Wrong id or domain not merged; run analyze first |
44
+ | `graph query` — invalid JSON | Re-run from project root; report as bug if repeats |
45
+ | `index` fails on one path | Fix the path; re-index; do not skip required wave index without user OK |
46
+ | Stale graph after manual edits | `ai-spector index`; re-run `/analyze` for fully stale domain |
169
47
 
170
48
  ---
171
49
 
172
- ## Agent may fix without asking (small, local)
50
+ ## Workarounds (user approval required)
173
51
 
174
- - Create missing parent dirs under `.ai-spector/` if `init` was incomplete.
175
- - Correct a **single** typo in `knowledge.json` id or `listedInSection` then re-run `graph merge`.
176
- - Re-run the **same** failed command once after an obvious fix (e.g. `cd` to project root).
177
- - Wrong CLI flags the agent introduced fix and retry immediately.
52
+ | Situation | Workaround | Restore |
53
+ |---|---|---|
54
+ | `graph query` thin nodes | Read `projectionPaths` + cited data-source files only (no `docs/srs/**` glob) | `graph merge` + validate after draft |
55
+ | `validate` one bad id/edge | Patch single node/edge; re-validate | Must pass before next wave |
56
+ | `index` fails one path | Skip that path if allowed; re-index after fix | Re-run index |
57
+ | Upstream SRS missing | Generate SRS prerequisite first (user approves) | Full pipeline order |
178
58
 
179
- ## Agent must ask user before
59
+ After any workaround that wrote docs: `graph validate` (+ `index` if required) before next wave.
180
60
 
181
- - Deleting `traceability.graph.json` or re-running `init --force`.
182
- - Large manual edits to graph or generated SRS.
183
- - Changing bundled templates or `workflow.dependencies.json`.
184
- - Any [workaround](#workaround-catalog-user-approval-required) not listed above or that skips **validate** before the next generation wave.
185
- - Bulk reads under `docs/srs/**` or `docs/basic-design/**` as primary context.
61
+ **Forbidden without user approval:** hand-edit graph at scale · glob `docs/srs/**` as primary context · skip `graph merge` · continue generation after validate errors.
@@ -0,0 +1,157 @@
1
+ # Context management during generation
2
+
3
+ Long generation runs (full SRS, full basic design) accumulate raw graph JSON, template content, data-source files, and previous wave outputs in the context window. Past a certain size, this degrades accuracy — the model starts blending data from earlier targets into the current one.
4
+
5
+ Two tools prevent this: **compaction checkpoints** and **sub-agent delegation**.
6
+
7
+ ---
8
+
9
+ ## Rule 1 — Compact at wave boundaries (mandatory)
10
+
11
+ After every wave completes (merge + validate pass), compact the context **before starting the next wave**:
12
+
13
+ ```
14
+ /compact
15
+ ```
16
+
17
+ What to retain across the compaction (summarise into the compact prompt if the tool asks):
18
+ - The generation plan: wave table, remaining targets, current wave number
19
+ - Completed outputs: list of written file paths + validate OK (not their content)
20
+ - Language setting and theme (if prototype)
21
+ - Any open blockers or deferred items
22
+
23
+ What to discard (do not try to retain):
24
+ - Raw graph query JSON from completed targets
25
+ - File content of already-written docs
26
+ - Template content (re-read from `.ai-spector/templates/` when needed)
27
+ - Data-source file content read in earlier waves
28
+
29
+ **Trigger compact also when:**
30
+ - Writing more than 5 per-domain files in a single wave (compact after every 5th file)
31
+ - Switching document types mid-wave (e.g., UC files → feature files)
32
+ - Context feels noisy — re-reads of the same data, earlier target data bleeding in
33
+
34
+ ---
35
+
36
+ ## Rule 2 — Sub-agent for graph context gathering
37
+
38
+ Do **not** run graph queries + file reads + synthesis all inline in the main agent turn. This fills the context with raw data that is only useful for 30 seconds.
39
+
40
+ Instead, delegate context gathering to a sub-task and receive only the distilled result.
41
+
42
+ ### Sub-agent pattern
43
+
44
+ **Delegate:** "Gather context for `<target>`"
45
+
46
+ **Prompt to sub-agent (adapt per target type):**
47
+
48
+ ```
49
+ Query the graph and read relevant files for <target id / type>.
50
+ Return ONLY a structured summary — do not return raw JSON or full file content.
51
+
52
+ Required output shape:
53
+ - Target: <id>, <name>
54
+ - Actors: list of actor names and roles
55
+ - Flow steps: numbered main flow (max 10 steps); exception flows (list conditions only)
56
+ - Data fields: input fields (name, type, required, validation); output fields (name, type)
57
+ - Related nodes: UC/F/API/screen ids that this target depends on or satisfies
58
+ - Gaps: any required graph node that is missing or empty
59
+
60
+ Queries to run:
61
+ ai-spector graph query <seedId> --direction both --depth 4 --edges CONTEXT --json
62
+ ai-spector graph query <depId> --direction both --depth 2 --edges DEPS --json
63
+ [read projectionPaths files listed in query result]
64
+
65
+ Max summary length: 400 words. No raw JSON in the response.
66
+ ```
67
+
68
+ **Main agent receives:** The 400-word summary — not the raw query output.
69
+
70
+ **Main agent writes:** The document file using the summary + template.
71
+
72
+ ### When to use sub-agents
73
+
74
+ | Task | Use sub-agent? |
75
+ |---|---|
76
+ | Graph query + extraction for a single UC/F/screen | **Yes** |
77
+ | Reading multiple data-source files to find relevant domain info | **Yes** |
78
+ | Impact analysis before regenerating a file | **Yes** |
79
+ | Checking whether a UC node exists | No — simple CLI call inline |
80
+ | Writing the file itself | No — main agent writes |
81
+ | Running `graph validate` / `graph merge` | No — CLI inline |
82
+
83
+ ---
84
+
85
+ ## Rule 3 — Read discipline (no speculative reads)
86
+
87
+ Only read a file if the graph query result references it in `projectionPaths` or the DAG explicitly lists it as a dependency. Never read:
88
+
89
+ - `docs/**` as a glob
90
+ - The entire `docs/data-source/` directory upfront
91
+ - Previously generated docs "for context" unless they are a direct DAG dependency of the current target
92
+
93
+ After a file is read and its relevant data extracted, treat it as consumed. Do not re-read it for a later target unless that target also has it in `projectionPaths`.
94
+
95
+ ---
96
+
97
+ ## Rule 4 — Context budget per target
98
+
99
+ Before writing each target, the context should hold **only**:
100
+
101
+ | Item | Max size |
102
+ |---|---|
103
+ | Generation plan (wave table, remaining targets) | ~200 tokens |
104
+ | Extracted context for current target (from sub-agent or compact summary) | ~400 tokens |
105
+ | Template structure (section headings only, not full template) | ~200 tokens |
106
+ | Language setting | 1 line |
107
+ | Current target output (while writing) | as needed |
108
+
109
+ If the active context clearly exceeds this (raw JSON visible, previous target data visible, multiple template files loaded), compact before writing.
110
+
111
+ ---
112
+
113
+ ## Rule 5 — After writing, let it go
114
+
115
+ Once a file is written and `rendersTo` is logged for the wave-end merge:
116
+ - Do not re-read the file
117
+ - Do not summarise its content into memory
118
+ - Record only: path + validate status
119
+
120
+ The graph is the persistent record. The context window is scratch space per target.
121
+
122
+ ---
123
+
124
+ ## Compaction prompt template
125
+
126
+ When compacting mid-run, include this summary so the next turn has enough to continue:
127
+
128
+ ```
129
+ Continuing generation of <layer> (e.g., SRS / basic design).
130
+
131
+ Plan:
132
+ - Wave <N> of <total> — COMPLETED
133
+ - Wave <N+1> targets: <list of DAG ids and output paths>
134
+ - Remaining waves: <list>
135
+
136
+ Completed files:
137
+ <path> — validate OK
138
+ <path> — validate OK
139
+
140
+ Settings:
141
+ - Language: <language>
142
+ - Graph validated: YES
143
+
144
+ Resume at: wave <N+1>, target <first target id>.
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Summary
150
+
151
+ | Checkpoint | Action |
152
+ |---|---|
153
+ | End of every wave | `/compact` with plan summary |
154
+ | Every 5 per-domain files | `/compact` with plan summary |
155
+ | Before each target | Delegate graph query + extraction to sub-agent |
156
+ | After reading data-source files | Extract what's needed; discard the raw read |
157
+ | After writing a file | Record path + status only; discard file content |
@@ -1,6 +1,6 @@
1
1
  # Graph-first generation (shared)
2
2
 
3
- Used by **SRS**, **basic design**, and **detail design** generation skills.
3
+ Used by **SRS** and **basic design** generation skills.
4
4
 
5
5
  | Orchestration (scope, confirm, wave checklist, finish) | [generate-workflow.md](./generate-workflow.md) |
6
6
  | Per-command DAG + intent tables | each skill's `references/runbook.md` |
@@ -71,9 +71,14 @@ ai-spector graph impact <targetSeedId> --change content_change --json
71
71
  ### D. Write
72
72
 
73
73
  - Read template from `.ai-spector/templates/` (DAG `template` field). If missing → stop and ask user to run `npx ai-spector init`.
74
+ - **Before filling the template**, load the matching context section for this doc type:
75
+ - SRS targets → `srs-context/<section>.md` (see SRS runbook for the table)
76
+ - Basic design targets → `bd-context/<doc-type>.md` (see BD runbook for the table)
77
+ - Prototype screens → [prototype-graph-context.md](../../ai-spector-generate-prototype/references/prototype-graph-context.md)
74
78
  - Fill for this target only; keep all required headings; replace placeholders with graph-backed content.
75
79
  - Cross-check every UC/F reference against `nodes` from query JSON.
76
80
  - Add section anchors `<!-- section:sec.... -->` where templates expect them.
81
+ - **Never invent** field names, endpoint paths, table names, actor roles, or business rules not present in the query results.
77
82
 
78
83
  ### E. Ingest (once per wave — not per file)
79
84