ai-spector 0.4.2 → 0.4.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 (25) hide show
  1. package/package.json +1 -1
  2. package/scaffold/cursor/skills/ai-spector/references/cli-failures.md +43 -167
  3. package/scaffold/cursor/skills/ai-spector/references/context-management.md +157 -0
  4. package/scaffold/cursor/skills/ai-spector/references/generate-graph.md +5 -0
  5. package/scaffold/cursor/skills/ai-spector/references/generate-workflow.md +45 -105
  6. package/scaffold/cursor/skills/ai-spector-generate-basic-design/SKILL.md +17 -15
  7. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/api-detail.md +27 -0
  8. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/api-list.md +26 -0
  9. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/db-design.md +22 -0
  10. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/screen-detail.md +26 -0
  11. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/bd-context/screen-list.md +27 -0
  12. package/scaffold/cursor/skills/ai-spector-generate-basic-design/references/runbook.md +15 -0
  13. package/scaffold/cursor/skills/ai-spector-generate-detail-design/SKILL.md +12 -14
  14. package/scaffold/cursor/skills/ai-spector-generate-prototype/SKILL.md +16 -25
  15. package/scaffold/cursor/skills/ai-spector-generate-prototype/references/prototype-graph-context.md +115 -0
  16. package/scaffold/cursor/skills/ai-spector-generate-prototype/references/runbook.md +27 -0
  17. package/scaffold/cursor/skills/ai-spector-generate-srs/SKILL.md +26 -24
  18. package/scaffold/cursor/skills/ai-spector-generate-srs/references/runbook.md +17 -0
  19. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/data-requirements.md +10 -0
  20. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/external-interfaces.md +10 -0
  21. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/feature-detail.md +20 -0
  22. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/introduction.md +12 -0
  23. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/overall-description.md +11 -0
  24. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/quality-attributes.md +11 -0
  25. package/scaffold/cursor/skills/ai-spector-generate-srs/references/srs-context/use-case-detail.md +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-spector",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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",
@@ -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 |
@@ -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**, apply the layer-specific graph extraction map:
75
+ - SRS targets → [srs-graph-context.md](../../ai-spector-generate-srs/references/srs-graph-context.md)
76
+ - Basic design targets → [basic-design-graph-context.md](../../ai-spector-generate-basic-design/references/basic-design-graph-context.md)
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
 
@@ -1,128 +1,68 @@
1
- # Document generation workflow (shared)
1
+ # Document generation workflow
2
2
 
3
- Used by **SRS**, **basic design**, and **detail design** generation skills.
3
+ Used by SRS, basic design, and detail design skills.
4
4
 
5
- | Topic | Document |
6
- |-------|----------|
7
- | Graph query, merge patch shape, waves algorithm | [generate-graph.md](./generate-graph.md) |
8
- | CLI failure recovery (fix / workaround / pause) | [cli-failures.md](./cli-failures.md) |
9
- | Layer-specific DAG, intent tables, waves | each skill’s `references/runbook.md` |
5
+ **References (load when needed):**
6
+ - Graph queries / merge / ingest → [generate-graph.md](./generate-graph.md)
7
+ - Context compaction / sub-agents [context-management.md](./context-management.md)
8
+ - CLI failures [cli-failures.md](./cli-failures.md)
10
9
 
11
- **Not used by** HTML prototype generation (`ai-spector-generate-prototype` runbook).
10
+ ## Language check (before first write)
12
11
 
13
- ## Language check before any write
12
+ Read `.ai-spector/.docflow/config/language.json`. If `documentLanguage` is empty or missing, load [language-picker.md](./language-picker.md) and run the picker. All content in the chosen language; IDs, paths, code never translated.
14
13
 
15
- **Read [language-picker.md](./language-picker.md) before generating any document content.**
14
+ ## Context hygiene (always)
16
15
 
17
- 1. Check `.ai-spector/.docflow/config/language.json` for `documentLanguage`.
18
- 2. If missing, run the language-picker flow (ask → persist → continue). Do not write until confirmed.
19
- 3. Apply the enforcement rules in language-picker.md to every file written: all content in the target language, IDs/paths/code never translated, no mixing.
16
+ 1. Only read files listed in `projectionPaths` no `docs/**` glob.
17
+ 2. Raw graph JSON stays in the sub-agent, not main context.
18
+ 3. After writing a file, record path + status only; discard content.
19
+ 4. For runs of 5+ files: compact after every wave + every 5 per-domain files. Load [context-management.md](./context-management.md) for the sub-agent pattern.
20
20
 
21
- ## Philosophy
21
+ ## Scope
22
22
 
23
- - **Accuracy over speed** full graph context before every write; ingest before the next wave.
24
- - **Graph in, graph out** — query neighbors + dependencies before; `rendersTo` + `dependsOn` after ([generate-graph.md](./generate-graph.md) § E).
25
- - **Parallel when safe** only targets in the **same DAG wave** with dependencies already merged + validated (and **indexed** when the command doc requires it).
23
+ | Case | User input | Behavior |
24
+ |---|---|---|
25
+ | **1 All** | "generate all SRS" | Every DAG node. Skip `good` files unless user asked to regenerate. |
26
+ | **2 — Explicit** | file paths in chat | Map → DAG nodes → dependency closure. Same wave only. |
27
+ | **3 — Words** | "API list and screens" | Scope table → user confirms → generate. No write before yes. |
26
28
 
27
- ## Scope three ways to choose targets
28
-
29
- Each generate command defines its DAG and intent hints. The pattern is always:
30
-
31
- | Case | User input | Agent behavior |
32
- |------|------------|----------------|
33
- | **1 — All** | “generate all SRS” / full layer | Plan every DAG node (+ per-domain expansions). Respect `good` on disk unless user asked to regenerate. |
34
- | **2 — Explicit paths** | paths in chat (`docs/…/file.md`) | Map paths → DAG nodes → seeds. Include **dependency closure**. Batch only within the same wave. |
35
- | **3 — Words** | “API list and screens” | Proposed scope table → **user confirms** → generate. **Do not write until approved.** |
36
-
37
- Paths are repo-relative. Mixed args: treat paths as case 2, free text as case 3.
38
-
39
- ## Case 3 — confirm before write (mandatory)
40
-
41
- 1. Parse the request against that command’s `dag.*.json`, `dag.*.graph-seeds.json`, and graph domain nodes.
42
- 2. Build a **proposed scope** table (columns: DAG id, output path, seed, reason, prerequisites / deps).
43
- 3. Include **dependency closure** — ancestors that are `missing_file` / `missing_content` run in earlier waves unless the user skips deps.
44
- 4. Ask:
45
-
46
- ```text
47
- I plan to generate the following (N items, waves X–Y). Prerequisites run first.
48
- Reply **yes** to proceed, **no** to cancel, or edit the list.
49
- ```
50
-
51
- 5. **Stop** without explicit **yes**. Do not write on assumption.
52
- 6. If ambiguous (e.g. “features” = list vs all detail files), ask **one** clarifying question before the table.
53
-
54
- Command-specific phrase → DAG mappings live in each `generate-*.md` (not here).
55
-
56
- ## Prerequisites (all DAG generate commands)
57
-
58
- 1. Merged graph — normally after **analyze** (data-source ingest).
59
- 2. Gate:
60
-
61
- ```bash
62
- ai-spector graph validate
63
- ```
64
-
65
- On errors, pause and follow recovery in [cli-failures.md](./cli-failures.md).
66
-
67
- 3. `workflow.dependencies.json` entry for that command (SRS minimum, etc.).
29
+ Case 3: build scope table (DAG id, output path, seed, reason, deps) → ask → stop until confirmed.
68
30
 
69
31
  ## Plan (once per invocation)
70
32
 
71
- 1. **Select targets** (case 1 / 2 / 3; case 3 = confirm first).
72
- 2. Topological sort selected nodes + required dependency ancestors.
73
- 3. Map each node via `dag.*.graph-seeds.json` → query seeds + ingest document ids.
74
- 4. Classify disk per output: `good` | `missing_content` | `missing_file` — do not overwrite `good` without user intent.
75
- 5. Assign **waves** ([generate-graph.md](./generate-graph.md) § Waves). Present wave table (brief for cases 1–2; case 3 table already confirmed).
76
-
77
- ## Per wave, then per target
33
+ 1. Select targets (case 1/2/3).
34
+ 2. Topological sort + dependency closure.
35
+ 3. Map DAG nodes → seeds via `dag.*.graph-seeds.json`.
36
+ 4. Classify disk: `good` | `missing_content` | `missing_file`.
37
+ 5. Assign waves; present wave table.
78
38
 
79
- For **each wave** in order:
80
-
81
- ### Wave checklist
39
+ ## Wave checklist
82
40
 
83
41
  ```
84
- - [ ] All targets in this wave identified (parallel OK within wave only)
85
- - [ ] For each target: graph query deps + target (_generate-graph § C)
42
+ - [ ] Targets for this wave identified (parallel OK within wave only)
43
+ - [ ] Per target: delegate graph queries to sub-agent; receive ≤400-word summary
44
+ - [ ] Load matching srs-context/ or bd-context/ section for this doc type
86
45
  - [ ] Read template from .ai-spector/templates/ — never invent structure
87
- - [ ] Write file(s)
88
- - [ ] Merge projection patch (rendersTo + dependsOn) for this wave
89
- - [ ] ai-spector graph validate — pass before next wave
90
- - [ ] ai-spector index when command doc requires (basic design: every wave; SRS: see generate-srs.md)
46
+ - [ ] Write file from summary + template
47
+ - [ ] Merge projection patch (rendersTo + dependsOn) for the wave
48
+ - [ ] ai-spector graph validate
49
+ - [ ] ai-spector index (basic design: every wave; SRS: see runbook)
50
+ - [ ] /compact with plan summary before next wave
91
51
  ```
92
52
 
93
- ### Per target (summary)
94
-
95
- Details: [generate-graph.md](./generate-graph.md) § C–E.
96
-
97
- 1. **Query** — dependency seeds (depth 2) + target seed (depth 4); `graph impact` when regenerating.
98
- 2. **Read** — `projectionPaths` and cited `docs/data-source/**` only; no glob of entire `docs/`.
99
- 3. **Write** — from DAG template; graph-backed UC/F/API/screen names only.
100
- 4. **Ingest** — merge patch; validate before leaving the wave.
101
-
102
- **Forbidden:** targets from different waves in one batch; next wave before merge + validate; skipping `rendersTo` on generated docs.
103
-
104
- ### Log (optional)
105
-
106
- Append one line per target to `.ai-spector/.docflow/logs/generate-<layer>.log` (create dir if needed): timestamp, seed, path, validate OK.
107
-
108
- ## Finish (end of command)
109
-
110
- 1. `ai-spector graph validate`
111
- 2. `ai-spector index` if not already run after the last wave (required for SRS — see `generate-srs.md`)
112
- 3. Suggest the command doc’s summary command (`/summary srs`, `/summary basic-design`, …) when listed there
113
- 4. Optional: `/visualize-graph` for review
114
-
115
- Index flags: `--skip-doc-semantics` to skip UC/F body parsing; `--graph-only` for structure + merge only.
53
+ Per target: Delegate → Receive summary → Write → Log path/status → Ingest.
116
54
 
117
55
  ## Guardrails
118
56
 
119
- - **Parallel only within a wave** — never across waves; never when A `dependsOn` B in the DAG.
120
- - **Every target** gets its own `graph query` + dependency queries before write.
121
- - **Every wave** ends with merge + validate (and **index** when the command doc says so) before the next wave.
122
- - **Case 3** requires explicit user **yes** before any write.
123
- - On `graph query` / `merge` / `validate` / `index` failure → pause and recover per [cli-failures.md](./cli-failures.md).
124
- - Prefer graph `nodes`/`edges` over stale `knowledge.json` for generation text.
57
+ - Parallel only within a wave.
58
+ - Sub-agent per target never reuse a previous target's summary.
59
+ - No raw graph JSON in main context.
60
+ - No speculative reads projectionPaths only.
61
+ - Case 3 requires explicit yes before any write.
62
+ - On CLI failure load [cli-failures.md](./cli-failures.md).
125
63
 
126
- ## If blocked
64
+ ## Finish
127
65
 
128
- [cli-failures.md](./cli-failures.md). Re-run the same task after fixes. Common upstream fix: **analyze** first, or generate SRS before basic design.
66
+ 1. `ai-spector graph validate`
67
+ 2. `ai-spector index` if not already run after last wave
68
+ 3. Suggest summary command when runbook lists one
@@ -10,25 +10,27 @@ paths:
10
10
  - ".ai-spector/templates/basic_design/**"
11
11
  ---
12
12
 
13
- # AI Spector — Generate basic design
14
-
15
- **Core:** [../ai-spector/SKILL.md](../ai-spector/SKILL.md)
16
-
17
- ## Required reading
13
+ # Generate Basic Design
18
14
 
15
+ ## Load at start
19
16
  1. [references/runbook.md](references/runbook.md)
20
17
  2. [../ai-spector/references/generate-workflow.md](../ai-spector/references/generate-workflow.md)
21
- 3. [../ai-spector/references/generate-graph.md](../ai-spector/references/generate-graph.md) § perEndpoint / perScreen
22
18
 
23
- ## Checklist
19
+ ## Load when needed
24
20
 
25
- ```
26
- - [ ] language confirmed (language-picker.md — check before first write)
27
- - [ ] graph validate; SRS on disk
28
- - [ ] index after every wave (mandatory)
29
- - [ ] one file per endpoint row / Screen Index row — not per F-xx
30
- ```
21
+ | Situation | Load |
22
+ |---|---|
23
+ | Language not set | [../ai-spector/references/language-picker.md](../ai-spector/references/language-picker.md) |
24
+ | Writing DB design | [references/bd-context/db-design.md](references/bd-context/db-design.md) |
25
+ | Writing API list | [references/bd-context/api-list.md](references/bd-context/api-list.md) |
26
+ | Writing API detail (per endpoint) | [references/bd-context/api-detail.md](references/bd-context/api-detail.md) |
27
+ | Writing screen list | [references/bd-context/screen-list.md](references/bd-context/screen-list.md) |
28
+ | Writing screen detail (per screen) | [references/bd-context/screen-detail.md](references/bd-context/screen-detail.md) |
29
+ | Graph queries / merge | [../ai-spector/references/generate-graph.md](../ai-spector/references/generate-graph.md) |
30
+ | CLI fails | [../ai-spector/references/cli-failures.md](../ai-spector/references/cli-failures.md) |
31
+ | Run of 5+ files | [../ai-spector/references/context-management.md](../ai-spector/references/context-management.md) |
31
32
 
32
- ## Natural language
33
+ ## On CLI failure
34
+ Pause. Report full output. Offer fix + retry. Details in cli-failures.md.
33
35
 
34
- basic design”, screen list”, API list”, wireframe for login → this skill.
36
+ "basic design", "screen list", "API list", "wireframe for login" → this skill.