ai-spector 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +173 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/analyze.d.ts +9 -0
  8. package/dist/commands/analyze.d.ts.map +1 -0
  9. package/dist/commands/analyze.js +62 -0
  10. package/dist/commands/analyze.js.map +1 -0
  11. package/dist/commands/bootstrap.d.ts +4 -0
  12. package/dist/commands/bootstrap.d.ts.map +1 -0
  13. package/dist/commands/bootstrap.js +58 -0
  14. package/dist/commands/bootstrap.js.map +1 -0
  15. package/dist/commands/graph-impact.d.ts +10 -0
  16. package/dist/commands/graph-impact.d.ts.map +1 -0
  17. package/dist/commands/graph-impact.js +31 -0
  18. package/dist/commands/graph-impact.js.map +1 -0
  19. package/dist/commands/graph-merge.d.ts +11 -0
  20. package/dist/commands/graph-merge.d.ts.map +1 -0
  21. package/dist/commands/graph-merge.js +88 -0
  22. package/dist/commands/graph-merge.js.map +1 -0
  23. package/dist/commands/graph-query.d.ts +10 -0
  24. package/dist/commands/graph-query.d.ts.map +1 -0
  25. package/dist/commands/graph-query.js +31 -0
  26. package/dist/commands/graph-query.js.map +1 -0
  27. package/dist/commands/graph-visualize.d.ts +10 -0
  28. package/dist/commands/graph-visualize.d.ts.map +1 -0
  29. package/dist/commands/graph-visualize.js +72 -0
  30. package/dist/commands/graph-visualize.js.map +1 -0
  31. package/dist/commands/init.d.ts +6 -0
  32. package/dist/commands/init.d.ts.map +1 -0
  33. package/dist/commands/init.js +47 -0
  34. package/dist/commands/init.js.map +1 -0
  35. package/dist/commands/validate.d.ts +10 -0
  36. package/dist/commands/validate.d.ts.map +1 -0
  37. package/dist/commands/validate.js +89 -0
  38. package/dist/commands/validate.js.map +1 -0
  39. package/dist/config/load.d.ts +21 -0
  40. package/dist/config/load.d.ts.map +1 -0
  41. package/dist/config/load.js +77 -0
  42. package/dist/config/load.js.map +1 -0
  43. package/dist/config/types.d.ts +22 -0
  44. package/dist/config/types.d.ts.map +1 -0
  45. package/dist/config/types.js +2 -0
  46. package/dist/config/types.js.map +1 -0
  47. package/dist/graph/InMemoryGraph.d.ts +20 -0
  48. package/dist/graph/InMemoryGraph.d.ts.map +1 -0
  49. package/dist/graph/InMemoryGraph.js +181 -0
  50. package/dist/graph/InMemoryGraph.js.map +1 -0
  51. package/dist/graph/defaults.d.ts +10 -0
  52. package/dist/graph/defaults.d.ts.map +1 -0
  53. package/dist/graph/defaults.js +10 -0
  54. package/dist/graph/defaults.js.map +1 -0
  55. package/dist/graph/impact.d.ts +32 -0
  56. package/dist/graph/impact.d.ts.map +1 -0
  57. package/dist/graph/impact.js +88 -0
  58. package/dist/graph/impact.js.map +1 -0
  59. package/dist/graph/knowledge.d.ts +53 -0
  60. package/dist/graph/knowledge.d.ts.map +1 -0
  61. package/dist/graph/knowledge.js +79 -0
  62. package/dist/graph/knowledge.js.map +1 -0
  63. package/dist/graph/load.d.ts +4 -0
  64. package/dist/graph/load.d.ts.map +1 -0
  65. package/dist/graph/load.js +12 -0
  66. package/dist/graph/load.js.map +1 -0
  67. package/dist/graph/loadGraph.d.ts +3 -0
  68. package/dist/graph/loadGraph.d.ts.map +1 -0
  69. package/dist/graph/loadGraph.js +7 -0
  70. package/dist/graph/loadGraph.js.map +1 -0
  71. package/dist/graph/merge.d.ts +15 -0
  72. package/dist/graph/merge.d.ts.map +1 -0
  73. package/dist/graph/merge.js +63 -0
  74. package/dist/graph/merge.js.map +1 -0
  75. package/dist/graph/query.d.ts +18 -0
  76. package/dist/graph/query.d.ts.map +1 -0
  77. package/dist/graph/query.js +132 -0
  78. package/dist/graph/query.js.map +1 -0
  79. package/dist/registry/build.d.ts +3 -0
  80. package/dist/registry/build.d.ts.map +1 -0
  81. package/dist/registry/build.js +53 -0
  82. package/dist/registry/build.js.map +1 -0
  83. package/dist/registry/slug.d.ts +4 -0
  84. package/dist/registry/slug.d.ts.map +1 -0
  85. package/dist/registry/slug.js +16 -0
  86. package/dist/registry/slug.js.map +1 -0
  87. package/dist/types.d.ts +45 -0
  88. package/dist/types.d.ts.map +1 -0
  89. package/dist/types.js +2 -0
  90. package/dist/types.js.map +1 -0
  91. package/dist/util/fs.d.ts +6 -0
  92. package/dist/util/fs.d.ts.map +1 -0
  93. package/dist/util/fs.js +24 -0
  94. package/dist/util/fs.js.map +1 -0
  95. package/dist/util/paths.d.ts +16 -0
  96. package/dist/util/paths.d.ts.map +1 -0
  97. package/dist/util/paths.js +19 -0
  98. package/dist/util/paths.js.map +1 -0
  99. package/dist/visualize/html.d.ts +13 -0
  100. package/dist/visualize/html.d.ts.map +1 -0
  101. package/dist/visualize/html.js +374 -0
  102. package/dist/visualize/html.js.map +1 -0
  103. package/dist/visualize/stats.d.ts +21 -0
  104. package/dist/visualize/stats.d.ts.map +1 -0
  105. package/dist/visualize/stats.js +45 -0
  106. package/dist/visualize/stats.js.map +1 -0
  107. package/documents.json +64 -0
  108. package/package.json +65 -0
  109. package/scaffold/.ai-spector/.docflow/config/analyze.graphify.json +40 -0
  110. package/scaffold/.ai-spector/.docflow/config/completeness-rules.basic-design.json +18 -0
  111. package/scaffold/.ai-spector/.docflow/config/completeness-rules.detail-design.json +57 -0
  112. package/scaffold/.ai-spector/.docflow/config/completeness-rules.srs.json +72 -0
  113. package/scaffold/.ai-spector/.docflow/config/dag.basic-design.json +38 -0
  114. package/scaffold/.ai-spector/.docflow/config/dag.detail-design.json +64 -0
  115. package/scaffold/.ai-spector/.docflow/config/dag.srs.json +87 -0
  116. package/scaffold/.ai-spector/.docflow/config/data-source.json +5 -0
  117. package/scaffold/.ai-spector/.docflow/config/index.docs.json +22 -0
  118. package/scaffold/.ai-spector/.docflow/config/workflow.dependencies.json +271 -0
  119. package/scaffold/.ai-spector/.docflow/extract/patch.example.json +20 -0
  120. package/scaffold/.ai-spector/.docflow/state.json +11 -0
  121. package/scaffold/.ai-spector/docflow.config.json +7 -0
  122. package/scaffold/.ai-spector/index/README.md +18 -0
  123. package/scaffold/.ai-spector/index/basic-design.md +5 -0
  124. package/scaffold/.ai-spector/index/srs.md +5 -0
  125. package/scaffold/.cursor/commands/_cli-failures.md +110 -0
  126. package/scaffold/.cursor/commands/_graph.md +48 -0
  127. package/scaffold/.cursor/commands/_prerequisites.md +48 -0
  128. package/scaffold/.cursor/commands/_workflow.md +50 -0
  129. package/scaffold/.cursor/commands/analyze.md +92 -0
  130. package/scaffold/.cursor/commands/generate-basic-design.md +26 -0
  131. package/scaffold/.cursor/commands/generate-detail-design.md +19 -0
  132. package/scaffold/.cursor/commands/generate-srs.md +63 -0
  133. package/scaffold/.cursor/commands/graph-impact.md +45 -0
  134. package/scaffold/.cursor/commands/index-docs.md +36 -0
  135. package/scaffold/.cursor/commands/sync-graph.md +30 -0
  136. package/scaffold/.cursor/commands/validate-graph.md +28 -0
  137. package/scaffold/.cursor/commands/visualize-graph.md +24 -0
  138. package/scaffold/.cursor/skills/ai-spector/SKILL.md +39 -0
  139. package/scaffold/docs/data-source/README.md +7 -0
  140. package/schemas/rules.impact.json +17 -0
  141. package/schemas/rules.traceability.json +30 -0
  142. package/schemas/schema.extract-patch.json +19 -0
  143. package/schemas/schema.graph.json +83 -0
  144. package/schemas/schema.knowledge.json +107 -0
  145. package/templates/basic_design/db-design-template.md +177 -0
  146. package/templates/basic_design/detail-api-template.md +278 -0
  147. package/templates/basic_design/detail-screen-template.md +281 -0
  148. package/templates/basic_design/list-api-template.md +130 -0
  149. package/templates/basic_design/list-screen-template.md +242 -0
  150. package/templates/detail_design/common/architecture-overview-template.md +302 -0
  151. package/templates/detail_design/common/deployment-infrastructure-template.md +461 -0
  152. package/templates/detail_design/common/error-handling-patterns-template.md +460 -0
  153. package/templates/detail_design/common/integration-patterns-template.md +410 -0
  154. package/templates/detail_design/common/performance-standards-template.md +406 -0
  155. package/templates/detail_design/common/security-patterns-template.md +395 -0
  156. package/templates/detail_design/feature-detail-design-template.md +773 -0
  157. package/templates/detail_design/feature-list-template.md +39 -0
  158. package/templates/srs/1-introduction.md +58 -0
  159. package/templates/srs/2-overall-description.md +91 -0
  160. package/templates/srs/3-use-case-detail-template.md +142 -0
  161. package/templates/srs/3-use-cases.md +53 -0
  162. package/templates/srs/4-system-feature-detail-template.md +131 -0
  163. package/templates/srs/4-system-features-list-template.md +39 -0
  164. package/templates/srs/5-data-requirements.md +59 -0
  165. package/templates/srs/6-external-interfaces.md +56 -0
  166. package/templates/srs/7-quality-attributes.md +74 -0
  167. package/templates/srs/8-internationalization.md +36 -0
  168. package/templates/srs/9-other-requirements.md +46 -0
@@ -0,0 +1,5 @@
1
+ # Basic Design Document Index
2
+
3
+ Last indexed: (not yet run — use `/index-docs basic-design`)
4
+
5
+ No entries yet. Source root: `docs/basic-design/`.
@@ -0,0 +1,5 @@
1
+ # SRS Document Index
2
+
3
+ Last indexed: (not yet run — use `/index-docs` or `/index-docs srs`)
4
+
5
+ No entries yet. Source root: `docs/srs/`.
@@ -0,0 +1,110 @@
1
+ # CLI failures (mandatory agent behavior)
2
+
3
+ When any `ai-spector` command **fails** (non-zero exit, throws, or empty/invalid JSON when `--json` was required):
4
+
5
+ 1. **Stop** the current slash command — no templates, no subagents, no writing `docs/srs/**`.
6
+ 2. **Show the user** the failure using the response format below (verbatim CLI output).
7
+ 3. **Explain** what it means in plain language and give **concrete fix steps** the user can take (or approve the agent to apply).
8
+ 4. **Re-run the same CLI** after the fix — do not switch to a manual workaround.
9
+
10
+ ## Forbidden when CLI fails
11
+
12
+ | Do not | Why |
13
+ |--------|-----|
14
+ | Hand-edit `traceability.graph.json` at scale | Bypasses merge/validate; drifts from `knowledge.json` |
15
+ | Implement graph BFS/search in the agent | Duplicates `graph query` / `graph impact` |
16
+ | Glob or read all of `docs/srs/**` because query failed | Hides missing graph or bad seed id |
17
+ | Use `.ai-spector/index/*.md` as primary context when validate/query failed | Index is fallback only after **successful** CLI with empty graph |
18
+ | Skip `graph merge` and “fill SRS from memory” | Breaks traceability |
19
+ | Silently continue after `graph validate` errors | Generation will be wrong or inconsistent |
20
+ | Tell the user “run this CLI yourself” without fixing | User workflow is slash commands; agent owns CLI |
21
+
22
+ **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/**`.
23
+
24
+ ---
25
+
26
+ ## Response format (copy this structure)
27
+
28
+ ```markdown
29
+ ## Blocked: <slash-command> — CLI failed
30
+
31
+ **Command:** `ai-spector <subcommand> …`
32
+ **Exit code:** <n>
33
+
34
+ **CLI output:**
35
+ \`\`\`
36
+ <paste full stdout/stderr>
37
+ \`\`\`
38
+
39
+ **What this means:** <one or two sentences>
40
+
41
+ **How to fix:**
42
+ 1. <step for user or agent>
43
+ 2. <step>
44
+ 3. Re-run **/<slash-command>** (or the step that failed, e.g. `/analyze`)
45
+
46
+ **I will not:** <e.g. generate SRS without a passing validate, or edit the graph by hand>
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Common failures → fixes
52
+
53
+ ### `ai-spector: command not found`
54
+
55
+ - **Means:** Package not installed or not on PATH.
56
+ - **Fix:** `npm install ai-spector` in the project; agent uses `npx ai-spector …` from project root.
57
+
58
+ ### `Could not find project root` / missing `docflow.config.json`
59
+
60
+ - **Means:** `init` not run or wrong working directory.
61
+ - **Fix:** Run `npx ai-spector init` from project root; agent `cd`s to workspace root before CLI.
62
+
63
+ ### `ai-spector analyze` fails
64
+
65
+ - **Means:** Registry/templates or graph bootstrap broke.
66
+ - **Fix:** Show full error; check `.ai-spector/registry/section-registry.json` exists; re-run `init` if config is corrupt; do not proceed to merge.
67
+
68
+ ### `graph merge` — `No domain entries in knowledge.json`
69
+
70
+ - **Means:** `/analyze` extract did not populate staging.
71
+ - **Fix:** Re-run Graphify extract in `/analyze`; ensure `docs/data-source/` has real files; fill `knowledge.json` with at least one `useCase` or `feature`.
72
+
73
+ ### `graph merge` — `Merge edge missing target node` / section id
74
+
75
+ - **Means:** `listedInSection` points to a section id not in the graph.
76
+ - **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.
77
+
78
+ ### `graph validate` — `DOMAIN-ANCHORED` / `SECTION-TREE` / `SCHEMA`
79
+
80
+ - **Means:** Graph inconsistent with rules.
81
+ - **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.
82
+
83
+ ### `graph query <id>` — seed missing or empty subgraph
84
+
85
+ - **Means:** Wrong id, or domain not merged.
86
+ - **Fix:** Run **`/visualize-graph`** or `graph query` with a known id from `knowledge.json`; run **`/analyze`** if no `useCase`/`feature` nodes.
87
+
88
+ ### `graph query` — invalid JSON / parse error
89
+
90
+ - **Means:** CLI crashed or wrong cwd.
91
+ - **Fix:** Re-run from project root; if repeat, report as tool bug with full stderr.
92
+
93
+ ### Graphify MCP unavailable
94
+
95
+ - **Means:** `/analyze` cannot extract.
96
+ - **Fix:** User enables Graphify in Cursor; do not fake `knowledge.json`; stop and document blocker.
97
+
98
+ ---
99
+
100
+ ## Agent may fix without asking (small, local)
101
+
102
+ - Create missing parent dirs under `.ai-spector/` if `init` was incomplete.
103
+ - Correct a **single** typo in `knowledge.json` id or `listedInSection` then re-run `graph merge`.
104
+ - Re-run the **same** failed command once after an obvious fix (e.g. `cd` to project root).
105
+
106
+ ## Agent must ask user before
107
+
108
+ - Deleting `traceability.graph.json` or re-running `init --force`.
109
+ - Large manual edits to graph or generated SRS.
110
+ - Changing bundled templates or `workflow.dependencies.json`.
@@ -0,0 +1,48 @@
1
+ # Graph CLI (for agents)
2
+
3
+ **Users do not run these.** Slash commands invoke CLI. Workflow: [_workflow.md](./_workflow.md). **On failure:** [_cli-failures.md](./_cli-failures.md).
4
+
5
+ Run from project root: `npx ai-spector …` if needed.
6
+
7
+ ## Every CLI invocation
8
+
9
+ 1. Run the command; capture **exit code**, **stdout**, **stderr**.
10
+ 2. If non-zero or `--json` is unparseable → **stop**; report per `_cli-failures.md`.
11
+ 3. On success, use CLI output only — do not re-derive graph state in the agent.
12
+
13
+ ## Commands
14
+
15
+ ```bash
16
+ ai-spector analyze
17
+ ai-spector graph merge --from-knowledge
18
+ ai-spector graph validate
19
+ ai-spector graph visualize [--open]
20
+ ai-spector graph query <nodeId> --json
21
+ ai-spector graph impact <nodeId> --json
22
+ ```
23
+
24
+ ## `graph query`
25
+
26
+ ```bash
27
+ ai-spector graph query <seedId> --direction both --depth 3 --json
28
+ ```
29
+
30
+ Use `projectionPaths`, `nodes`, `edges` from JSON. **If command fails or JSON invalid:** stop — do not glob `docs/srs/**`.
31
+
32
+ **If success but empty domain nodes:** report to user; suggest `/analyze` — still no folder-wide SRS reads.
33
+
34
+ ## `graph impact`
35
+
36
+ ```bash
37
+ ai-spector graph impact <nodeId> --change content_change --json
38
+ ```
39
+
40
+ If this fails, do not guess impact scope — show CLI output and fix.
41
+
42
+ ## `graph merge`
43
+
44
+ Called from `/analyze`. On merge/validate failure, do not patch `traceability.graph.json` by hand at scale — fix `knowledge.json` or section ids and re-run merge.
45
+
46
+ ## Narrow fallback (success only)
47
+
48
+ Only when **validate passed** and **query succeeded** but content is thin: read specific `docs/data-source/**` files. Never because CLI failed.
@@ -0,0 +1,48 @@
1
+ # Workflow prerequisites (shared)
2
+
3
+ User workflow: [**_workflow.md**](./_workflow.md). **CLI failures:** [**_cli-failures.md**](./_cli-failures.md). Agent CLI: [**_graph.md**](./_graph.md).
4
+
5
+ Load `.ai-spector/.docflow/config/workflow.dependencies.json` for the active step.
6
+
7
+ ## When checks fail
8
+
9
+ 1. **Stop immediately** — do not read templates, spawn subagents, or write outputs.
10
+ 2. Reply with the **Blocked** format in [_cli-failures.md](./_cli-failures.md) (include full CLI output).
11
+ 3. Help the user fix the issue; re-run the failed CLI; then continue the slash command.
12
+
13
+ ## Graph context (only after CLI succeeds)
14
+
15
+ 1. **`ai-spector graph validate`** — exit 0 required before generate.
16
+ 2. Per target: **`ai-spector graph query <seedId> --json`** — parse JSON; use `projectionPaths` and `nodes`.
17
+ 3. Open **only** those paths (+ targeted `docs/data-source/**` if still insufficient).
18
+
19
+ **If validate or query fails:** follow [_cli-failures.md](./_cli-failures.md) — do **not** fall back to index or full-tree reads.
20
+
21
+ **If query succeeds but has no domain nodes:** tell the user; suggest **`/analyze`** — still no `docs/srs/**` glob.
22
+
23
+ ## Check types
24
+
25
+ | type | Pass when |
26
+ |------|-----------|
27
+ | `pathExists` | Path exists on disk |
28
+ | `hasFiles` | At least `min` files matching `glob` under `path` |
29
+ | `stateNotNull` | `state.json` field is non-null |
30
+ | `jsonAnyNonEmpty` | JSON file exists; listed keys non-empty |
31
+ | `allPathsExist` | Every path in `paths` exists |
32
+ | `indexPopulated` | Index has `## File:` entries, no placeholder markers |
33
+ | `indexPopulatedIfSourceHasFiles` | Conditional index check |
34
+
35
+ ## Graph checks (generate steps)
36
+
37
+ | id | Pass when |
38
+ |----|-----------|
39
+ | `graph-file` | `.ai-spector/graph/traceability.graph.json` exists |
40
+ | `graph-merged` | `state.json` → `analysis.graphMergedAt` is set |
41
+
42
+ If only section shells (no `useCase`/`feature`): **block** with fix steps → **`/analyze`**, not manual SRS from index.
43
+
44
+ ## Stale warnings (not failures)
45
+
46
+ - Data source newer than `analysis.lastRunAt` → suggest `/analyze`.
47
+ - Projections changed → suggest `/sync-graph` after validate passes.
48
+ - Index stale → warn only; graph query remains primary when domain nodes exist.
@@ -0,0 +1,50 @@
1
+ # AI Spector workflow (Cursor)
2
+
3
+ **You use slash commands.** The agent runs `ai-spector` CLI in the terminal. Do not ask the user to run `analyze`, `graph merge`, or `graph query` manually.
4
+
5
+ If CLI fails: agent **stops**, shows output, and helps you fix — see [**_cli-failures.md**](./_cli-failures.md). No silent fallbacks.
6
+
7
+ ## One-time setup (terminal)
8
+
9
+ ```bash
10
+ npm install ai-spector
11
+ npx ai-spector init
12
+ ```
13
+
14
+ Add source material under `docs/data-source/`, open the project in Cursor, and enable the **ai-spector** skill.
15
+
16
+ ## Day-to-day (slash commands only)
17
+
18
+ | Step | You run | Agent runs (CLI) |
19
+ |------|---------|------------------|
20
+ | 1 | **`/analyze`** | `ai-spector analyze` → Graphify extract → `graph merge --from-knowledge` → `graph validate` → optional `graph visualize --open` |
21
+ | 2 | **`/validate-graph`** | `ai-spector graph validate` |
22
+ | 3 | **`/generate-srs`** | `graph validate` → `graph query <seed> --json` per target → write docs → `graph validate` |
23
+ | 4 | **`/index-docs srs`** (optional) | index update per command |
24
+ | 5 | **`/generate-basic-design`** | same `graph query` pattern |
25
+ | 6 | **`/generate-detail-design`** | same `graph query` pattern |
26
+ | After edits | **`/graph-impact <nodeId>`** | `graph impact <id> --json` |
27
+ | Inspect graph | **`/visualize-graph`** | `graph visualize --open` |
28
+
29
+ **Any step fails?** Agent reports the error and fix steps, then you re-run the **same** slash command. The agent does not bypass CLI with manual graph edits or folder-wide doc reads.
30
+
31
+ ## Typical first run
32
+
33
+ ```text
34
+ npx ai-spector init ← only CLI step you run yourself
35
+ docs/data-source/ ← add files
36
+ /analyze
37
+ /validate-graph
38
+ /generate-srs
39
+ ```
40
+
41
+ ## If something fails
42
+
43
+ | Symptom | What to do |
44
+ |---------|------------|
45
+ | Red error after `/analyze` | Read agent’s **Blocked** message; fix data-source or Graphify; run **`/analyze`** again |
46
+ | Validate errors | **`/validate-graph`** — agent explains each `[ERROR]` and fixes or guides you |
47
+ | Empty SRS / wrong context | **`/analyze`** then **`/generate-srs`** — not “read all docs manually” |
48
+ | Unsure what regen | **`/graph-impact <id>`** |
49
+
50
+ Details: [_cli-failures.md](./_cli-failures.md). CLI reference: [_graph.md](./_graph.md). Prerequisites: [_prerequisites.md](./_prerequisites.md).
@@ -0,0 +1,92 @@
1
+ # /analyze
2
+
3
+ Ingest `docs/data-source/` and commit knowledge into the traceability graph.
4
+
5
+ **User runs this command only.** The agent runs all CLI steps below — see [_workflow.md](./_workflow.md).
6
+
7
+ ## Usage
8
+
9
+ - `/analyze` — default root `docs/data-source`
10
+ - `/analyze <path1> ...` — override inputs
11
+
12
+ ## Prerequisites
13
+
14
+ 1. **`npx ai-spector init`** was run once (project scaffold exists).
15
+ 2. `docs/data-source/` has at least one real input file.
16
+
17
+ **On success, suggest:** `/visualize-graph` (optional) → `/validate-graph` → `/generate-srs`.
18
+
19
+ ## Required Behavior
20
+
21
+ ### 0. Prepare graph structure (CLI — agent runs first)
22
+
23
+ ```bash
24
+ ai-spector analyze
25
+ ```
26
+
27
+ Creates section/document nodes from templates. Do not ask the user to run this separately.
28
+
29
+ ### A. Extract (Graphify MCP)
30
+
31
+ 1. Load `data-source.json`, `analyze.graphify.json`.
32
+ 2. Resolve paths → `scope.json` → `sources`.
33
+ 3. Build/update Graphify index for that scope.
34
+ 4. Query / fallback to extract:
35
+ - actors, useCases, features, functionalRequirements, nfrs, entities, interfaces, constraints, openQuestions
36
+ 5. Persist staging:
37
+ - `.ai-spector/.docflow/analysis/knowledge.json` (see package `schemas/schema.knowledge.json`)
38
+ - `.ai-spector/.docflow/analysis/gaps.json`
39
+ - `.ai-spector/.docflow/analysis/scope.json`
40
+
41
+ ### B. Commit to graph (CLI — agent runs; no hand-edited graph JSON)
42
+
43
+ ```bash
44
+ ai-spector graph merge --from-knowledge
45
+ ai-spector graph validate
46
+ ```
47
+
48
+ Optional for the user:
49
+
50
+ ```bash
51
+ ai-spector graph visualize --open
52
+ ```
53
+
54
+ Or suggest **`/visualize-graph`**.
55
+
56
+ **`knowledge.json` minimum fields:**
57
+
58
+ | Entity | `id` | `title` / `name` | `listedInSection` (optional) | Links |
59
+ |--------|------|------------------|------------------------------|-------|
60
+ | use case | `UC-01` | required | defaults to §3.2 list section | — |
61
+ | feature | `F-01` | required | defaults to §4.2 list section | `satisfies`: `["UC-01"]` |
62
+ | actor | `actor.customer` | `name` or `title` | defaults to §2.2 user classes | — |
63
+ | requirement | `REQ-01` | required | section id | `tracesTo` optional |
64
+ | entity | `ENT-Order` | `name` | defaults to §5.2 logical model | — |
65
+
66
+ ### C. State
67
+
68
+ Update `state.json`: `analysis.lastRunAt`, `analysis.dataSource`, scope hash. Merge sets `analysis.graphMergedAt`.
69
+
70
+ ## Success Criteria
71
+
72
+ - `ai-spector graph validate` passes with domain nodes (`useCase`, `feature`, …) anchored to sections.
73
+ - `knowledge.json` mirrors extract; graph is authoritative for `/generate-srs`.
74
+ - Gaps recorded in `gaps.json`.
75
+
76
+ ## CLI steps — stop on first failure
77
+
78
+ Run in order. If any step fails, **stop** and use [_cli-failures.md](./_cli-failures.md) (show full CLI output + fix steps). Do not skip to merge, validate, or `/generate-srs`.
79
+
80
+ | Step | Command |
81
+ |------|---------|
82
+ | 0 | `ai-spector analyze` |
83
+ | B | `ai-spector graph merge --from-knowledge` |
84
+ | B | `ai-spector graph validate` |
85
+
86
+ Graphify failure counts as blocked — do not invent `knowledge.json`.
87
+
88
+ ## If blocked
89
+
90
+ Use the **Blocked** template in [_cli-failures.md](./_cli-failures.md). Include which step failed, exit code, verbatim CLI output, what it means, and how to fix. Offer to apply small fixes (e.g. one bad `listedInSection`) then re-run the same step.
91
+
92
+ **Do not:** hand-edit the full graph, generate SRS, or read all of `docs/srs/` as a workaround.
@@ -0,0 +1,26 @@
1
+ # /generate-basic-design
2
+
3
+ Basic design from graph-selected SRS context. **User runs this command;** agent runs CLI. On CLI failure: [_cli-failures.md](./_cli-failures.md). [_workflow.md](./_workflow.md), [_graph.md](./_graph.md).
4
+
5
+ ## Prerequisites
6
+
7
+ Graph merged + `ai-spector graph validate`. Minimum SRS on disk.
8
+
9
+ ## Required Behavior
10
+
11
+ 1. `ai-spector graph validate`
12
+ 2. Resolve seed: target **`feature`** id `F-xx` (from file arg or DAG).
13
+ 3. Per seed:
14
+
15
+ ```bash
16
+ ai-spector graph query F-xx --direction both --depth 3 --json
17
+ ```
18
+
19
+ 4. Load only `projectionPaths` + referenced sources from JSON.
20
+ 5. Generate; update graph edges (`tracesTo` / `references`); `ai-spector graph validate`.
21
+
22
+ ## If blocked
23
+
24
+ Any failed `graph validate` or `graph query` → [_cli-failures.md](./_cli-failures.md). No index or SRS folder-wide fallback when CLI failed.
25
+
26
+ Index only if **query succeeded** and subgraph is empty — then suggest `/analyze`.
@@ -0,0 +1,19 @@
1
+ # /generate-detail-design
2
+
3
+ Detail design via graph context. **User runs this command;** agent runs CLI. On CLI failure: [_cli-failures.md](./_cli-failures.md). [_workflow.md](./_workflow.md), [_graph.md](./_graph.md).
4
+
5
+ ## Prerequisites
6
+
7
+ Graph validates; SRS minimum exists.
8
+
9
+ ## Required Behavior
10
+
11
+ 1. `ai-spector graph validate`
12
+ 2. Seed: `feature` id or detail `document` node.
13
+ 3. `ai-spector graph query <seed> --direction both --depth 3 --json`
14
+ 4. Load SRS + basic-design paths from `projectionPaths` only.
15
+ 5. Generate; update graph; `ai-spector graph validate`.
16
+
17
+ ## If blocked
18
+
19
+ Failed validate/query → [_cli-failures.md](./_cli-failures.md). Do not read all of `docs/` manually when CLI failed.
@@ -0,0 +1,63 @@
1
+ # /generate-srs
2
+
3
+ Generate SRS projections. **User runs this command;** agent runs CLI (`graph validate`, `graph query`, …). See [_workflow.md](./_workflow.md).
4
+
5
+ ## Usage
6
+
7
+ - `/generate-srs` | `/generate-srs <file>`
8
+
9
+ ## Prerequisites
10
+
11
+ `workflow.dependencies.json` → `generate-srs`. Block if `analysis.graphMergedAt` missing or **`ai-spector graph validate`** fails.
12
+
13
+ ## Required Behavior
14
+
15
+ ### 1. Gate
16
+
17
+ ```bash
18
+ ai-spector graph validate
19
+ ```
20
+
21
+ ### 2. Plan targets
22
+
23
+ DAG + scan `docs/srs/` (`good` | `missing_content` | `missing_file`). Map each target to graph **seed** id.
24
+
25
+ ### 3. Context per target (CLI — mandatory)
26
+
27
+ ```bash
28
+ ai-spector graph query <seedId> --direction both --depth 3 --json
29
+ ```
30
+
31
+ Parse JSON:
32
+
33
+ - Load **only** `projectionPaths`
34
+ - Use `nodes` / `edges` for UC/F text and relationships
35
+ - Supplement `docs/data-source/**` only when query + graph nodes are insufficient
36
+
37
+ **Forbidden:** manual graph traversal; glob `docs/srs/**` when query failed or validate failed.
38
+
39
+ ### If `graph validate` or `graph query` fails
40
+
41
+ Stop immediately. Report via [_cli-failures.md](./_cli-failures.md). Do not generate SRS from index or folder-wide reads.
42
+
43
+ ### 4. Generate + update graph
44
+
45
+ Fill templates; write files; add `rendersTo` / domain nodes; then:
46
+
47
+ ```bash
48
+ ai-spector graph validate
49
+ ```
50
+
51
+ ### 5. State + logs
52
+
53
+ Update `state.json`, run log, Graphify sync if configured.
54
+
55
+ ## Guardrails
56
+
57
+ - CLI `graph query` for every target seed — on failure, stop and help user fix (see _cli-failures.md).
58
+ - Never overwrite `good` without force.
59
+ - Final `graph validate` must pass; if not, show errors and do not claim success.
60
+
61
+ ## If blocked
62
+
63
+ Use [_cli-failures.md](./_cli-failures.md). User re-runs **`/generate-srs`** after validate/query succeed.
@@ -0,0 +1,45 @@
1
+ # /graph-impact
2
+
3
+ Scope regen after a change. **User runs this command;** agent runs `graph impact` ([_graph.md](./_graph.md), [_workflow.md](./_workflow.md)).
4
+
5
+ ## Usage
6
+
7
+ - `/graph-impact <nodeId>`
8
+ - `/graph-impact <nodeId> --change content_change|delete|id_change|…`
9
+
10
+ ## Prerequisites
11
+
12
+ - `ai-spector graph validate` passes
13
+
14
+ ## Required Behavior
15
+
16
+ 1. Run:
17
+
18
+ ```bash
19
+ ai-spector graph impact <nodeId> --change <type> --json
20
+ ```
21
+
22
+ Optional report file:
23
+
24
+ ```bash
25
+ ai-spector graph impact <nodeId> --json -o .ai-spector/views/impact-<timestamp>.json
26
+ ```
27
+
28
+ 2. Parse JSON buckets: `regenerate`, `review`, `downstream`.
29
+ 3. Present table to user with `projectionPath` per entry.
30
+ 4. For each **regenerate** id, suggest `/generate-srs` or patch using:
31
+
32
+ ```bash
33
+ ai-spector graph query <thatId> --json
34
+ ```
35
+
36
+ **Do not** implement impact BFS in the agent.
37
+
38
+ ## If blocked
39
+
40
+ Use [_cli-failures.md](./_cli-failures.md). If `graph impact` or follow-up `graph query` fails, show output and fix — do not invent regenerate lists.
41
+
42
+ ## Guardrails
43
+
44
+ - No whole-repo regen outside CLI buckets.
45
+ - No regen plan if impact CLI failed.
@@ -0,0 +1,36 @@
1
+ # /index-docs
2
+
3
+ Build **searchable summaries** under `.ai-spector/index/`. This is a **secondary** aid — prefer **`graph_neighbors`** for generation context when the graph has domain nodes.
4
+
5
+ ## Usage
6
+
7
+ - `/index-docs` | `/index-docs srs` | `/index-docs basic-design` | `/index-docs <path>` | `--force`
8
+
9
+ ## Role vs graph
10
+
11
+ | Mechanism | Use for |
12
+ |-----------|---------|
13
+ | **`graph_neighbors`** | **Primary** — relevant sections, UC/F, projection paths |
14
+ | **Index** | Fallback when graph empty; quick human browse; optional metadata cache |
15
+
16
+ After indexing, optionally add **`references`** edges from index entries to `document` nodes (advanced `/sync-graph`).
17
+
18
+ ## Prerequisites
19
+
20
+ Warn if no files to index; do not block. See `workflow.dependencies.json` warn steps.
21
+
22
+ ## Required Behavior
23
+
24
+ 1. Load `index.docs.json`; discover files under `docs/srs/` or `docs/basic-design/`.
25
+ 2. For each file, if graph has matching `document` node by `output` path — include `graphNodeId` in metadata line.
26
+ 3. Write summaries to `.ai-spector/index/srs.md` / `basic-design.md` (format unchanged).
27
+ 4. Update `state.json` index hashes.
28
+
29
+ ## Guardrails
30
+
31
+ - Index does **not** replace graph for `/generate-*` when graph is populated.
32
+ - Never index templates or `node_modules/ai-spector/templates/`.
33
+
34
+ ## Success
35
+
36
+ - Index files updated; user informed that generate commands should still use graph first.
@@ -0,0 +1,30 @@
1
+ # /sync-graph
2
+
3
+ Reconcile **disk projections** (`docs/srs/`, etc.) with **graph nodes** — add missing `document` nodes, `rendersTo` edges, detect orphans.
4
+
5
+ ## Usage
6
+
7
+ - `/sync-graph`
8
+ - `/sync-graph docs/srs`
9
+
10
+ ## When to run
11
+
12
+ - After manual edits to markdown outside `/generate-*`
13
+ - Before `/validate-graph` when files exist but graph lacks `document` nodes
14
+ - After bulk import of SRS files
15
+
16
+ ## Required Behavior
17
+
18
+ 1. Load `traceability.graph.json` + `section-registry.json`.
19
+ 2. Glob projection roots (`docs/srs/**/*.md`, etc.).
20
+ 3. For each file:
21
+ - Match to `document` node by `output` path; if missing, create `document` + link sections from registry where possible.
22
+ - Add **`rendersTo`** from document (or primary section) → file path.
23
+ 4. For each graph `document` with `output` missing on disk → mark orphan in report (do not delete nodes without user confirm).
24
+ 5. Run **`ai-spector graph validate`**.
25
+ 6. Summarize: added nodes, added edges, orphans, stale projections.
26
+
27
+ ## Guardrails
28
+
29
+ - Do not remove domain nodes without explicit user request.
30
+ - Preserve stable ids (`UC-01`, `sec.*`) when linking new files.
@@ -0,0 +1,28 @@
1
+ # /validate-graph
2
+
3
+ Gate before generation. **User runs this command;** agent runs the CLI.
4
+
5
+ ## Usage
6
+
7
+ - `/validate-graph`
8
+
9
+ ## Required Behavior
10
+
11
+ ```bash
12
+ ai-spector graph validate
13
+ ```
14
+
15
+ - **Exit 0** → tell the user OK; if domain nodes exist, suggest `/generate-srs`; if only section shells, explain they need `/analyze` first.
16
+ - **Non-zero** → **stop**. Use [_cli-failures.md](./_cli-failures.md): paste every `[ERROR]` line, explain each, give fix steps (usually re-run `/analyze` or fix one node then re-validate).
17
+
18
+ **Do not:** guess validation in the agent, hand-fix the whole graph without showing the user, or proceed to `/generate-srs`.
19
+
20
+ ## If blocked
21
+
22
+ Follow [_cli-failures.md](./_cli-failures.md). Typical fixes:
23
+
24
+ - `DOMAIN-ANCHORED` → domain node missing `listedIn` / `describedIn` → re-run `/analyze` or fix one node and `graph merge` again.
25
+ - `SECTION-TREE` → structure edge wrong → re-run `ai-spector analyze` (agent), not manual graph surgery at scale.
26
+ - `REGISTRY-COMPLETE` → re-run `/analyze` step 0 (`ai-spector analyze`).
27
+
28
+ After fix, user re-runs **`/validate-graph`**.
@@ -0,0 +1,24 @@
1
+ # /visualize-graph
2
+
3
+ Open an HTML report of the traceability graph and `knowledge.json`.
4
+
5
+ ## Usage
6
+
7
+ - `/visualize-graph`
8
+
9
+ ## Required Behavior
10
+
11
+ ```bash
12
+ ai-spector graph visualize --open
13
+ ```
14
+
15
+ Agent runs from project root. Default: `.ai-spector/views/graph-knowledge.html`
16
+
17
+ ## If blocked
18
+
19
+ Use [_cli-failures.md](./_cli-failures.md). Common fixes:
20
+
21
+ - Missing graph → run **`/analyze`** first (step 0 `ai-spector analyze`).
22
+ - `command not found` → `npm install ai-spector`; use `npx ai-spector graph visualize --open`.
23
+
24
+ Do not tell the user to inspect raw JSON instead of fixing the CLI — offer to fix cwd/install, then re-run **`/visualize-graph`**.