@drafthq/draft 3.0.0 → 3.2.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 (62) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +3 -3
  4. package/bin/README.md +4 -7
  5. package/cli/src/hosts/claude-code.js +4 -1
  6. package/cli/src/installer.js +12 -5
  7. package/core/shared/condensation.md +8 -8
  8. package/core/shared/draft-context-loading.md +5 -9
  9. package/core/shared/graph-query.md +170 -33
  10. package/core/shared/graph-usage-report.md +1 -1
  11. package/core/shared/pattern-learning.md +2 -2
  12. package/core/shared/red-flags.md +3 -3
  13. package/core/templates/ai-context.md +1 -1
  14. package/core/templates/architecture.md +3 -3
  15. package/integrations/agents/AGENTS.md +299 -145
  16. package/integrations/copilot/.github/copilot-instructions.md +299 -145
  17. package/package.json +2 -1
  18. package/scripts/lib.sh +11 -3
  19. package/scripts/tools/_graph_queries.sh +102 -0
  20. package/scripts/tools/adr-index.sh +2 -2
  21. package/scripts/tools/check-scope-conflicts.sh +2 -2
  22. package/scripts/tools/check-skill-line-caps.sh +2 -2
  23. package/scripts/tools/cycle-detect.sh +22 -15
  24. package/scripts/tools/diff-templates-vs-tracks.sh +2 -2
  25. package/scripts/tools/fix-whitespace.sh +15 -9
  26. package/scripts/tools/graph-arch.sh +72 -0
  27. package/scripts/tools/graph-callers.sh +71 -20
  28. package/scripts/tools/graph-deps.sh +76 -0
  29. package/scripts/tools/graph-errors.sh +97 -0
  30. package/scripts/tools/graph-hierarchy.sh +89 -0
  31. package/scripts/tools/graph-impact.sh +1 -0
  32. package/scripts/tools/graph-init.sh +3 -3
  33. package/scripts/tools/graph-query.sh +124 -0
  34. package/scripts/tools/graph-risk.sh +81 -0
  35. package/scripts/tools/graph-search.sh +84 -0
  36. package/scripts/tools/graph-snapshot.sh +63 -50
  37. package/scripts/tools/graph-snippet.sh +92 -0
  38. package/scripts/tools/graph-tests.sh +112 -0
  39. package/scripts/tools/graph-traces.sh +83 -0
  40. package/scripts/tools/hotspot-rank.sh +44 -15
  41. package/scripts/tools/manage-symlinks.sh +1 -1
  42. package/scripts/tools/mermaid-from-graph.sh +31 -10
  43. package/scripts/tools/parse-reports.sh +1 -1
  44. package/scripts/tools/verify-doc-anchors.sh +2 -2
  45. package/scripts/tools/verify-graph-binary.sh +1 -1
  46. package/skills/GRAPH.md +2 -2
  47. package/skills/bughunt/SKILL.md +1 -1
  48. package/skills/debug/SKILL.md +3 -3
  49. package/skills/decompose/SKILL.md +5 -5
  50. package/skills/deep-review/SKILL.md +2 -2
  51. package/skills/deploy-checklist/SKILL.md +2 -2
  52. package/skills/graph/SKILL.md +1 -1
  53. package/skills/implement/SKILL.md +1 -1
  54. package/skills/init/SKILL.md +62 -42
  55. package/skills/init/references/architecture-spec.md +12 -11
  56. package/skills/learn/SKILL.md +5 -5
  57. package/skills/quick-review/SKILL.md +3 -3
  58. package/skills/review/SKILL.md +7 -7
  59. package/skills/tech-debt/SKILL.md +2 -2
  60. package/scripts/tools/okf-bundle.sh +0 -141
  61. package/scripts/tools/okf-check.sh +0 -137
  62. package/scripts/tools/okf-emit.sh +0 -161
@@ -12,7 +12,7 @@
12
12
  "name": "draft",
13
13
  "source": "./",
14
14
  "description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
15
- "version": "3.0.0",
15
+ "version": "3.2.0",
16
16
  "author": {
17
17
  "name": "mayurpise"
18
18
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "draft",
3
3
  "description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
4
- "version": "3.0.0",
4
+ "version": "3.2.0",
5
5
  "author": {
6
6
  "name": "mayurpise"
7
7
  },
package/README.md CHANGED
@@ -129,7 +129,7 @@ curl -o .gemini.md https://raw.githubusercontent.com/drafthq/draft/main/integrat
129
129
  | **`/draft:docs`** | Router for authoring and documentation workflows |
130
130
  | **`/draft:discover`** | Router for discovery, debugging, investigation, and quality |
131
131
  | **`/draft:init`** | Analyze codebase, create context files + state tracking |
132
- | **`/draft:index`** | Aggregate monorepo service contexts |
132
+ | **`/draft:graph`** | Build / refresh the knowledge-graph snapshot |
133
133
  | **`/draft:new-track`** | Collaborative spec + plan with AI |
134
134
  | **`/draft:decompose`** | Module decomposition with dependency mapping |
135
135
  | **`/draft:implement`** | TDD workflow with checkpoints |
@@ -187,7 +187,7 @@ The graph powers `/draft:graph` and `/draft:impact`, enriches `/draft:bughunt` a
187
187
 
188
188
  ### Deterministic helper tools
189
189
 
190
- Skills also call into **34 shell helpers** under `scripts/tools/` for mechanical work — git metadata, file classification, test-framework detection, hotspot ranking, freshness checks, ADR indexing, and Open Knowledge Format emission/validation (`okf-emit.sh`, `okf-bundle.sh`, `okf-check.sh`). All emit JSON or markdown, follow a uniform exit-code contract, and degrade gracefully when their input source is unavailable.
190
+ Skills also call into **shell helpers** under `scripts/tools/` for mechanical work — git metadata, file classification, test-framework detection, hotspot ranking, freshness checks, ADR indexing, and live graph queries (`graph-callers.sh`, `graph-impact.sh`, `hotspot-rank.sh`, `cycle-detect.sh`, `mermaid-from-graph.sh`). All emit JSON or markdown, follow a uniform exit-code contract, and degrade gracefully when their input source is unavailable.
191
191
 
192
192
  ---
193
193
 
@@ -234,7 +234,7 @@ AI tools are fast but unstructured. Draft applies Context-Driven Development to
234
234
  ```
235
235
  product.md → "Build a task manager"
236
236
  tech-stack.md → "React, TypeScript, Tailwind"
237
- architecture.md → Comprehensive: 28 sections + 5 appendices, Mermaid diagrams (source of truth). Mature brownfield projects with strong existing agent docs (CLAUDE.md, INVARIANTS.md, etc.) receive early Context Quality Audit, graph fidelity dashboard, and explicit Relationship + Gaps sections (no blind duplication).
237
+ architecture.md → Comprehensive: 10-section graph-primary engineering reference, Mermaid diagrams (source of truth). Mature brownfield projects with strong existing agent docs (CLAUDE.md, INVARIANTS.md, etc.) receive early Context Quality Audit, graph fidelity dashboard, and explicit Relationship + Gaps sections (no blind duplication).
238
238
  .ai-context.md → 200-400 lines: condensed from architecture.md (token-optimized AI context)
239
239
  .state/ → freshness hashes, signal classification, run memory (incremental refresh)
240
240
  spec.md → "Add drag-and-drop reordering"
package/bin/README.md CHANGED
@@ -46,16 +46,13 @@ and `verify-graph-binary.sh`. The shared wrappers (`memory_cli`,
46
46
 
47
47
  ## Snapshot artifacts
48
48
 
49
- `scripts/tools/graph-snapshot.sh` writes a small, committed, PR-reviewable snapshot under `<repo>/draft/graph/`:
49
+ `draft/graph/` holds a single committed file:
50
50
 
51
51
  | Artifact | Content |
52
52
  |----------|---------|
53
- | `schema.yaml` | Engine + project metadata, node/edge counts, artifact list (gates graph use). |
54
- | `architecture.json` | `get_architecture(all)`: node labels, edge types, languages, packages (fan-in/out), entry points, routes, hotspots. |
55
- | `hotspots.jsonl` | Fan-in-ranked symbols, one JSON object per line. |
56
- | `module-deps.mermaid` | File co-change coupling diagram. |
57
- | `proto-map.mermaid` | Detected service-route diagram. |
58
- | `okf/` | Open Knowledge Format v0.1 bundle (`index.md` + cross-linked `modules/<name>.md`), emitted by default — a portable markdown mirror of the graph. Validate with `okf-check.sh`. |
53
+ | `schema.yaml` | Engine + project metadata, node/edge counts, point-of-index counts (gates graph use). |
54
+
55
+ Structural graph data (architecture, hotspots, module deps, service routes) is queried **live** from the `codebase-memory-mcp` engine — either via the wrapper scripts under `scripts/tools/` (`graph-callers.sh`, `graph-impact.sh`, `hotspot-rank.sh`, `cycle-detect.sh`, `mermaid-from-graph.sh`) or directly with `codebase-memory-mcp cli <tool> '<json>'`.
59
56
 
60
57
  ## Offline / air-gapped distributions
61
58
 
@@ -56,7 +56,10 @@ module.exports = {
56
56
  ],
57
57
  graph: true, // fetch the graph engine at install time (/draft:init also fetches on first use as a fallback)
58
58
  done: 'Installed/updated draft. Restart Claude Code (or start a new session), then run /draft:init.',
59
- fallbackTitle: 'Claude Code CLI not found. Run these in Claude Code instead:',
59
+ // Shown when the `claude` CLI is absent OR a step fails: the in-session
60
+ // /plugin commands work without the terminal CLI on PATH.
61
+ onFailHint: 'If that failed with "unknown command", your Claude Code is too old for the `claude plugin` command — run "claude update" (or upgrade the app), then re-run.',
62
+ fallbackTitle: 'Run these inside a Claude Code session instead (or put the `claude` CLI on your PATH and re-run):',
60
63
  fallback: [
61
64
  '/plugin marketplace add drafthq/draft',
62
65
  '/plugin marketplace update draft-plugins',
@@ -5,9 +5,13 @@ const fsx = require('./lib/fsx');
5
5
  const log = require('./lib/log');
6
6
  const { fetchGraph } = require('./lib/graph');
7
7
 
8
+ // A short ceiling so a wedged `claude --version` can't hang the installer
9
+ // before we even reach the real (separately-timed) install steps.
10
+ const CHECK_TIMEOUT_MS = 10000;
11
+
8
12
  function hasBinary(name) {
9
13
  // ENOENT on the error means the binary is not on PATH.
10
- const r = spawnSync(name, ['--version'], { stdio: 'ignore' });
14
+ const r = spawnSync(name, ['--version'], { stdio: 'ignore', timeout: CHECK_TIMEOUT_MS });
11
15
  return !(r.error && r.error.code === 'ENOENT');
12
16
  }
13
17
 
@@ -59,12 +63,14 @@ function install(host, ctx) {
59
63
  const plan = host.plan(ctx);
60
64
  log.step(`Installing Draft -> ${host.label} [${plan.targetSummary}]${ctx.dryRun ? ' (dry run)' : ''}`);
61
65
 
62
- // A plan may require an external CLI (e.g. claude). If it's missing, print
63
- // the manual fallback and stopbut only when actually installing; a
64
- // dry run still shows the planned commands.
66
+ // A plan may require an external CLI (e.g. claude). If it's missing, say so
67
+ // loudly, print the manual fallback, and exit non-zero a no-op must never
68
+ // read as success. Only enforced on a real install; a dry run still shows the
69
+ // planned commands.
65
70
  if (plan.requires && !ctx.dryRun && !hasBinary(plan.requires)) {
71
+ log.error(`Cannot auto-install: the "${plan.requires}" CLI is not on your PATH. Nothing was installed.`);
66
72
  printFallback(plan);
67
- return 0;
73
+ return 1;
68
74
  }
69
75
 
70
76
  // Pre-flight: for file copies, every bundled source must exist and guarded
@@ -88,6 +94,7 @@ function install(host, ctx) {
88
94
  const code = execAction(act, ctx);
89
95
  if (code !== 0) {
90
96
  log.error(`Step failed (exit ${code}): ${act.label || act.cmd}`);
97
+ if (plan.onFailHint) log.error(plan.onFailHint);
91
98
  if (plan.fallback) printFallback(plan);
92
99
  return code;
93
100
  }
@@ -88,16 +88,16 @@ Transform each `architecture.md` section into machine-optimized format using thi
88
88
 
89
89
  #### Step 3.5: Generate Graph Summary Sections
90
90
 
91
- If `draft/graph/schema.yaml` exists, generate these sections from the snapshot (`draft/graph/architecture.json`, `draft/graph/hotspots.jsonl`) and the live query tools:
91
+ If `draft/graph/schema.yaml` exists, generate these sections via live engine queries.
92
92
 
93
93
  **GRAPH:MODULES** (tier ≥ 2 only):
94
- - Read `draft/graph/architecture.json` `.packages[]` (each has `name`, `node_count`, `fan_in`, `fan_out`)
94
+ - Query: `scripts/tools/graph-arch.sh --repo . | jq '.packages[]'` (each has `name`, `node_count`, `fan_in`, `fan_out`)
95
95
  - Format: `{name}|{node_count} nodes|fan_in:{fan_in} fan_out:{fan_out}`
96
96
  - Order by `node_count` descending
97
97
  - Omit this section entirely for tier-1 codebases (≤5 modules) where Component Graph is sufficient
98
98
 
99
99
  **GRAPH:HOTSPOTS** (all tiers):
100
- - Read `draft/graph/hotspots.jsonl` (already fan-in-ranked), take top 10
100
+ - Query: `scripts/tools/hotspot-rank.sh --repo . --top 10`; take top 10 results
101
101
  - Format: `{name}|fanIn:{fanIn}` (use `id` for disambiguation when names collide)
102
102
  - Always include regardless of tier
103
103
 
@@ -108,20 +108,20 @@ If `draft/graph/schema.yaml` exists, generate these sections from the snapshot (
108
108
  - Always include — absence is positive signal that the call graph is acyclic
109
109
 
110
110
  **GRAPH:MODULE-HOTSPOTS** (tier ≥ 3 only):
111
- - Read `draft/graph/hotspots.jsonl`; group by the package segment of each `id` (the qualified name minus the leaf symbol)
111
+ - Query: `scripts/tools/hotspot-rank.sh --repo .`; group results by the package segment of each `id` (the qualified name minus the leaf symbol)
112
112
  - For each module: take its top 3 symbols by `fanIn`, format as indented lines under the module name
113
113
  - Format: `{module}: {name}|fanIn:{N}` with subsequent symbols indented to align
114
114
  - Order modules by their highest-fanIn symbol, descending
115
115
  - Omit modules with no hotspot entries; omit entire section for tier 1–2 (covered by global GRAPH:HOTSPOTS)
116
116
 
117
117
  **GRAPH:FAN-IN** (tier ≥ 3 only):
118
- - Read `architecture.json` `.packages[]`, use the `fan_in` field per module
118
+ - Query: `scripts/tools/graph-arch.sh --repo . | jq '.packages[]'`, use the `fan_in` field per module
119
119
  - Format: `{name}|fanIn:{fan_in}|fanOut:{fan_out}`
120
120
  - Order by `fan_in` descending; include only modules with `fan_in ≥ 2`; cap at 15 rows
121
121
  - Omit entire section for tier 1–2 (trivially small graph)
122
122
 
123
- **GRAPH:PROTO-MAP** (only when `architecture.json` `.routes` is non-empty):
124
- - Read `architecture.json` `.routes[]` (each has `method`, `path`, `handler`)
123
+ **GRAPH:PROTO-MAP** (only when routes are non-empty):
124
+ - Query: `scripts/tools/graph-arch.sh --repo . | jq '.routes[]'` (each has `method`, `path`, `handler`)
125
125
  - Format: `{method} {path} → {handler}`
126
126
  - One line per route
127
127
  - Omit entire section if `.routes` is empty — do not write an empty section
@@ -168,7 +168,7 @@ Before writing `draft/.ai-context.md`, verify:
168
168
  - [ ] GRAPH:CYCLES present ("None ✓" or cycle list; or note if graph absent)
169
169
  - [ ] GRAPH:MODULE-HOTSPOTS present for tier ≥ 3 (or note if no hotspot data)
170
170
  - [ ] GRAPH:FAN-IN present for tier ≥ 3
171
- - [ ] GRAPH:PROTO-MAP present when `stats.proto_rpcs > 0` (omit entirely if no protos)
171
+ - [ ] GRAPH:PROTO-MAP present when engine reports non-empty routes (omit entirely if no protos)
172
172
  - [ ] YAML frontmatter metadata is present at the top
173
173
 
174
174
  #### Step 7: Write Output
@@ -71,13 +71,9 @@ If `draft/graph/schema.yaml` exists, the project has automated graph analysis da
71
71
 
72
72
  | File | Purpose | Content |
73
73
  |------|---------|---------|
74
- | `draft/graph/schema.yaml` | Snapshot metadata (engine, project, node/edge counts) | YAML, ~15 lines |
75
- | `draft/graph/architecture.json` | Node labels, edge types, languages, packages (fan-in/out), entry points, routes, hotspots | JSON |
76
- | `draft/graph/hotspots.jsonl` | Fan-in-ranked symbols, one object per line: `{id, name, fanIn}` | JSONL |
74
+ | `draft/graph/schema.yaml` | Gate marker (engine + project metadata + point-of-index counts); presence gates graph use | YAML, ~15 lines |
77
75
 
78
- The snapshot also includes `draft/graph/okf/` an Open Knowledge Format v0.1 bundle (`index.md` + `modules/*.md`) emitted by default. It is a portable mirror of the graph, not an always-load target.
79
-
80
- Note: `.ai-context.md` embeds a condensed graph summary (`GRAPH:MODULES`, `GRAPH:HOTSPOTS`, `GRAPH:CYCLES`) for first-pass structural ground truth. `architecture.json` is authoritative for deep structure.
76
+ Note: `.ai-context.md` embeds a condensed graph summary (`GRAPH:MODULES`, `GRAPH:HOTSPOTS`, `GRAPH:CYCLES`) for first-pass structural ground truth. Deep structural data is queried live from the engine (see Live structural queries below).
81
77
 
82
78
  Note: The canonical embedded mermaid diagrams are in architecture.md injection slots (`<!-- GRAPH:module-deps:START/END -->`, `<!-- GRAPH:proto-map:START/END -->`), refreshed by `draft:init`. For current data, regenerate via `scripts/tools/mermaid-from-graph.sh`.
83
79
 
@@ -151,12 +147,12 @@ Do NOT apply relevance scoring for commands that need full context (`/draft:init
151
147
  | `## FILES` | Always (need file locations) |
152
148
  | `## VOCAB` | Domain-specific tasks |
153
149
 
154
- 3. **Score graph files** (if `draft/graph/` exists) against the task concepts:
150
+ 3. **Score graph queries** (if `draft/graph/schema.yaml` exists) against the task concepts:
155
151
 
156
152
  | Graph source | Use When Task Involves... |
157
153
  |------------|--------------------------|
158
- | `architecture.json` | Module boundary changes, cross-module work, architecture analysis, API/route surface |
159
- | `hotspots.jsonl` | Performance work, refactoring, changes to high-fanIn symbols |
154
+ | `scripts/tools/graph-arch.sh --repo .` | Module boundary changes, cross-module work, architecture analysis, API/route surface |
155
+ | `scripts/tools/hotspot-rank.sh --repo .` | Performance work, refactoring, changes to high-fanIn symbols |
160
156
  | `scripts/tools/graph-callers.sh --symbol <name>` | Enumerating callers before a change |
161
157
  | `scripts/tools/graph-impact.sh --file <path>` / `--symbol <name>` | Tracing call paths, root cause analysis, function-level impact |
162
158
  | `scripts/tools/cycle-detect.sh` | Checking for call cycles |
@@ -10,7 +10,7 @@ Referenced by: `/draft:init`, `/draft:implement`, `/draft:bughunt`, `/draft:revi
10
10
 
11
11
  Any code-touching skill that needs to discover files, modules, symbols, callers, or blast-radius **MUST** follow this lookup order whenever `draft/graph/schema.yaml` exists:
12
12
 
13
- 1. **Graph first** — the committed snapshot (`architecture.json`, `hotspots.jsonl`) and the live query tools (`scripts/tools/graph-callers.sh`, `graph-impact.sh`, `cycle-detect.sh`, `hotspot-rank.sh`).
13
+ 1. **Graph first** — live engine queries via the query tools (`scripts/tools/graph-callers.sh`, `graph-impact.sh`, `cycle-detect.sh`, `hotspot-rank.sh`, `mermaid-from-graph.sh`), which drive the local `codebase-memory-mcp` engine on demand. Draft is **engine-only**: there is no committed machine-readable graph to read — `draft/graph/` holds only `schema.yaml` (the gate marker).
14
14
  2. **Generated context second** — `draft/.ai-context.md`, relevant `draft/architecture.md` slices, track-level `hld.md`/`lld.md`.
15
15
  3. **Source file reads third** — narrow via tiers 1–2, then **Read** the candidate files. Reading is **not optional**: see §Ground-Truth Discipline below.
16
16
  4. **Filesystem `grep`/`find`/`rg` last** — only after an explicit graph miss.
@@ -55,10 +55,10 @@ A single "no" / "list" answer is a halt — fix and re-check before output.
55
55
 
56
56
  Use this recipe whenever the user names a concept, feature, or domain term ("in-memory shuffle", "auth flow", "ingest pipeline") and you need to locate the implementing files. **Run it before any filesystem search.**
57
57
 
58
- 1. **Concept → modules** — `grep` the concept token against `draft/graph/architecture.json` (`.packages[].name`) and `draft/.ai-context.md` (module headings). Record the candidate module list.
58
+ 1. **Concept → modules** — query the engine for the package list (`scripts/tools/graph-arch.sh --repo . | jq -r '.packages[].name'`) and cross-reference `draft/.ai-context.md` (module headings). Record the candidate module list. For an **intent/concept** name (not an exact symbol), start with semantic search: `scripts/tools/graph-search.sh --repo . --query "<concept>"` returns ranked candidate symbols directly.
59
59
  2. **Concept → symbols/callers** — for a named function, run `scripts/tools/graph-callers.sh --repo . --symbol <name>` to find call sites, and `scripts/tools/graph-impact.sh --repo . --symbol <name>` for transitive dependents. These are the authoritative structural answers.
60
- 3. **Modules → risk ranking** — cross-reference `draft/graph/hotspots.jsonl` (or `scripts/tools/hotspot-rank.sh`). High-fanIn symbols are the most likely entry points for impact.
61
- 4. **Concept → public API** — for API-shaped concepts, consult `architecture.json` `.routes` (detected HTTP/gRPC/GraphQL routes) for matching service surface.
60
+ 3. **Modules → risk ranking** — rank with `scripts/tools/hotspot-rank.sh --repo . [--top N]`. High-fanIn symbols are the most likely entry points for impact.
61
+ 4. **Concept → public API** — for API-shaped concepts, read the engine's `.routes` (`get_architecture` output, detected HTTP/gRPC/GraphQL routes) for matching service surface.
62
62
  5. **Graph miss → grep fallback** — only if steps 1–4 return nothing relevant, emit the fallback sentence and use `grep`/`find`. Narrow the search by file extension and exclude `node_modules`, `vendor`, `dist`, `build`, `.git`.
63
63
 
64
64
  ## Graph Usage Report (Mandatory Footer)
@@ -68,7 +68,7 @@ Every code-touching skill output MUST end with this footer block. The lint check
68
68
  ```md
69
69
  ## Graph Usage Report
70
70
 
71
- - Graph files queried: <comma-separated list, e.g. `architecture.json, hotspots.jsonl` and/or query tools like `graph-callers.sh` — or `NONE` with justification below>
71
+ - Graph files queried: <comma-separated list of query tools invoked, e.g. `graph-callers.sh, hotspot-rank.sh` — or `NONE` with justification below>
72
72
  - Modules identified via graph: <comma-separated module names, or `none`>
73
73
  - Files identified via graph: <integer count>
74
74
  - Filesystem grep fallbacks: <list of `<pattern>` searches with one-line justification each, or `none`>
@@ -102,11 +102,75 @@ DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
102
102
 
103
103
  | Wrapper | Graph mode | Behavior on missing graph |
104
104
  |---|---|---|
105
- | `bash "$DRAFT_TOOLS/hotspot-rank.sh" [--top N] [--module NAME]` | `--mode hotspots` | Emits `{hotspots:[],source:"unavailable"}` and exits 2 |
106
- | `bash "$DRAFT_TOOLS/cycle-detect.sh"` | `--mode cycles` | Emits `{cycles:[],source:"unavailable"}` and exits 2 |
107
- | `bash "$DRAFT_TOOLS/mermaid-from-graph.sh" [--diagram module-deps\|proto-map]` | `--mode mermaid` | Emits an empty mermaid block and exits 2 |
105
+ | `bash "$DRAFT_TOOLS/hotspot-rank.sh" [--top N]` | complexity-weighted hotspots | Emits `{hotspots:[],source:"unavailable"}` and exits 2 |
106
+ | `bash "$DRAFT_TOOLS/cycle-detect.sh"` | call cycles | Emits `{cycles:[],source:"unavailable"}` and exits 2 |
107
+ | `bash "$DRAFT_TOOLS/mermaid-from-graph.sh" [--diagram module-deps\|co-change\|proto-map]` | diagram text | Emits an empty mermaid block and exits 2 |
108
+ | `bash "$DRAFT_TOOLS/graph-callers.sh" --symbol N [--transitive[=N]] [--prod-only] [--qualified]` | callers | `{callers:[],status:"unavailable",source:"unavailable"}`, exit 2 |
109
+ | `bash "$DRAFT_TOOLS/graph-snippet.sh" --qualified N` | verified source + caller/callee counts | `{status:"unavailable",source:"unavailable"}`, exit 2 |
110
+ | `bash "$DRAFT_TOOLS/graph-search.sh" --query "STR" [--limit N]` | semantic/ranked search | `{results:[],source:"unavailable"}`, exit 2 |
111
+ | `bash "$DRAFT_TOOLS/graph-tests.sh" (--symbol N \| --untested)` | test→symbol coverage | `{tests:[]/untested:[],source:"unavailable"}`, exit 2 |
112
+ | `bash "$DRAFT_TOOLS/graph-deps.sh" [--file PATH]` | real IMPORTS graph | `{imports:[],source:"unavailable"}`, exit 2 |
113
+ | `bash "$DRAFT_TOOLS/graph-hierarchy.sh" [--symbol N \| --derived N]` | INHERITS tree | `{edges:[],source:"unavailable"}`, exit 2 |
114
+ | `bash "$DRAFT_TOOLS/graph-errors.sh" (--symbol N \| --type N)` | RAISES/THROWS | `{raises:[]/raisers:[],source:"unavailable"}`, exit 2 |
115
+ | `bash "$DRAFT_TOOLS/graph-risk.sh" [--min-complexity N]` | pre-computed risk flags | `{risky:[],source:"unavailable"}`, exit 2 |
116
+ | `bash "$DRAFT_TOOLS/graph-query.sh" (--cypher STR \| --tool NAME --json '{...}')` | generic read-only passthrough | `{source:"unavailable"}`, exit 2 |
117
+ | `bash "$DRAFT_TOOLS/graph-traces.sh" ingest --file F --experimental` | runtime traces (experimental write) | `{source:"unavailable"}`, exit 2 |
118
+
119
+ For lower-level modes, call the engine directly: `codebase-memory-mcp cli <tool> '<json>'` (see the tool list in [bin/README.md](../../bin/README.md)).
120
+
121
+ ### Capability wrappers & dialect limits (graph-tooling-v2)
122
+
123
+ All Cypher lives in `scripts/tools/_graph_queries.sh` (the single source of query
124
+ truth). Wrappers are thin arg-parse → builder → fail-loud JSON. Three contracts
125
+ matter when consuming them:
126
+
127
+ **Fail-loud status.** Symbol-scoped wrappers (`graph-callers`, `graph-snippet`,
128
+ `graph-tests --symbol`, `graph-hierarchy --symbol/--derived`, `graph-errors`)
129
+ emit a `status` field that distinguishes the three real outcomes — never read a
130
+ bare `[]` as a confirmed true negative:
131
+
132
+ | `status` | Meaning |
133
+ |---|---|
134
+ | `ok` | node found, edges returned |
135
+ | `no-edges` | node exists but has no matching edge (a *real* negative) |
136
+ | `no-match` | the named symbol was not found at all (check the name / try `--qualified`) |
137
+ | `unavailable` | engine could not be resolved (exit 2) |
138
+
139
+ **Verified engine param shapes** (engine v0.8.x — the runtime source of truth is
140
+ `get_graph_schema`; do not hardcode a property set):
108
141
 
109
- Use the raw `graph` CLI directly for the lower-level modes documented below.
142
+ ```bash
143
+ get_code_snippet '{"project":P,"qualified_name":"pkg.Mod.Class.method"}' # → source + callers/callees counts + transitive_loop_depth
144
+ search_graph '{"project":P,"query":"order submission to broker","limit":5}' # → {results:[{name,qualified_name,label,file_path,rank}]}
145
+ trace_path '{"project":P,"function_name":"submit_order","depth":3,"direction":"both"}' # depth-bounded caller EXPANDER, not an A→B pathfinder
146
+ detect_changes '{"project":P}' # → {changed_files, changed_count, impacted_symbols, depth}
147
+ get_graph_schema '{"project":P}' # → {node_labels:[{label,count,properties}], edge_types:[{type,count}]}
148
+ ```
149
+
150
+ **Cypher dialect — keep queries inside the SAFE set:**
151
+
152
+ - ✅ SAFE: fixed-length patterns, single/multi-hop explicit patterns, `=`, `<`,
153
+ `STARTS WITH`, `NOT x STARTS WITH`, `AND`, `OR`, relationship-type alternation
154
+ `[:A|B]`, simple `count(x)`.
155
+ - ❌ UNSAFE (rejected or silently empty): `coalesce()`, `<>` / `!=` / `<=` / `>=`,
156
+ `NOT EXISTS(...)`, `NOT (pattern)`, `WITH`-grouping aggregation, multi-pattern
157
+ joins. `graph-query.sh --cypher` returns the engine's raw error, not a silent
158
+ empty — but the builders never emit these forms.
159
+
160
+ **Caveats consumers must respect:**
161
+
162
+ - **`--prod-only` is best-effort.** It filters `is_test=false AND NOT file_path
163
+ STARTS WITH 'tests/'`. `is_test` is partially populated by the engine, so test
164
+ helpers/mocks can leak through. Treat it as a heuristic, not a guarantee.
165
+ - **`--transitive` uses the `trace_path` expander** (a depth-bounded caller
166
+ expansion from one symbol), not a from→to pathfinder. "Path between A and B"
167
+ still needs an explicit fixed-length `graph-query.sh --cypher` pattern.
168
+ - **Honest caps.** `cycle-detect`, `graph-deps`, `graph-risk`, `graph-tests
169
+ --untested` cap their output and report `"truncated": true` when the cap is
170
+ hit — results are a sample, not exhaustive.
171
+ - **`graph-tests --untested`** is a set difference (exported symbols minus TESTS
172
+ targets) because the dialect has no anti-join; coverage depends on the engine
173
+ resolving test→symbol links, which varies by language/framework.
110
174
 
111
175
  ## Pre-Check
112
176
 
@@ -118,27 +182,26 @@ ls draft/graph/schema.yaml 2>/dev/null
118
182
 
119
183
  If absent, **skip all graph operations silently**. Graph enriches analysis — it never gates it. All skills must work identically without graph data.
120
184
 
121
- ## Engine + snapshot model
185
+ ## Engine model (engine-only)
122
186
 
123
- The graph is produced by the **codebase-memory-mcp** engine (a single binary; see [bin/README.md](../../bin/README.md)). There are two ways skills consume it:
187
+ The graph is produced by the **codebase-memory-mcp** engine (a single binary; see [bin/README.md](../../bin/README.md)). Draft is **engine-only and opinionated**: the engine is the one structural source of truth, queried live. There is **no committed machine-readable mirror** of the graph — no `architecture.json`, `hotspots.jsonl`, `*.mermaid`, or `okf/`. Those were lossy, went stale on the next commit, and duplicated what the engine serves precisely on demand.
124
188
 
125
- 1. **Live queries** (preferred when the engine is resolvable) — the shell tools under `scripts/tools/` drive the engine on demand (it auto-indexes into its own cache). No committed files required.
126
- 2. **Committed snapshot** (`draft/graph/`) — a small, derived, PR-reviewable snapshot written by `scripts/tools/graph-snapshot.sh`. It exists for reviewability and for the Copilot/Gemini integrations, which cannot run the engine but can read committed files. Git remains the source of truth.
189
+ The only committed file is the gate marker:
127
190
 
128
- When `draft/graph/` exists, the snapshot contains:
191
+ | File | Role |
192
+ |------|------|
193
+ | `draft/graph/schema.yaml` | Engine + project metadata and point-of-index counts (provenance, not authoritative). Carries **no graph data**. Its presence is the **gate** (see Pre-Check) — it signals the engine is wired for this repo. Written by `scripts/tools/graph-snapshot.sh`. |
129
194
 
130
- | File | Load | Content |
131
- |------|------|---------|
132
- | `schema.yaml` | Always | Engine + project metadata, node/edge counts, artifact list. Its presence **gates** graph use (see Pre-Check). |
133
- | `architecture.json` | Always | `get_architecture(all)` output: node labels, edge types, languages, packages (with fan-in/out), entry points, routes, hotspots. |
134
- | `hotspots.jsonl` | Always | Fan-in-ranked symbols, one JSON object per line: `{id, name, fanIn}`. |
135
- | `module-deps.mermaid` | Diagram injection | File co-change coupling diagram (`FILE_CHANGES_WITH`). |
136
- | `proto-map.mermaid` | Diagram injection | Detected service-route diagram (`Route` nodes). |
137
- | `okf/` | On demand | Open Knowledge Format v0.1 bundle (emitted by default): `index.md` (reserved bundle root, no frontmatter) + cross-linked `modules/<name>.md` concept pages. Portable, vendor-neutral mirror of the graph; validate with `okf-check.sh`. |
195
+ All structural data is obtained live by shelling out to the engine — either through the query-tool wrappers under `scripts/tools/` or directly via `codebase-memory-mcp cli <tool> '<json>'`. The shell tools auto-index the repo into the engine's own cache on demand, so no committed files are required.
138
196
 
139
- The engine uses a **unified, language-agnostic** node model — `Function`, `Method`, `Class`, `Module`, `File`, `Folder`, `Route`, `Section`, `Variable` (language is inferred from file extension) — and edges `CALLS`, `DEFINES`, `CONTAINS_FILE`, `IMPORTS`, `HTTP_CALLS`, `FILE_CHANGES_WITH`, `SEMANTICALLY_RELATED`, `SIMILAR_TO`. There are **no** per-language index files and no `ctags-sym` fallback; that detail is served by live queries against the unified model.
197
+ ### How skills query (engine is the interface; jq is optional)
140
198
 
141
- **Always-load files** are compact and should be read during context loading for any task that touches code structure.
199
+ - **The engine is the query.** `codebase-memory-mcp cli <tool> '<json>'` (and the wrappers that call it) is how you ask it takes JSON args and returns JSON. There is no other query surface.
200
+ - **Prefer the wrappers — they resolve the engine for you.** `graph-arch.sh` (architecture view: packages/routes/layers/hotspots), `graph-callers.sh`, `hotspot-rank.sh`, `graph-impact.sh`, `cycle-detect.sh`, `mermaid-from-graph.sh` return already-shaped JSON. The engine binary is usually **not on `$PATH`** (it lives under `~/.cache/draft/bin/`); the wrappers locate it via `_lib.sh:find_memory_bin`, so a skill using a wrapper needs no resolution step.
201
+ - **Raw `codebase-memory-mcp cli` requires resolving the binary first** (it is not on `$PATH`): `CM="${DRAFT_MEMORY_BIN:-$HOME/.cache/draft/bin/codebase-memory-mcp}"; "$CM" cli <tool> '<json>'`. Reach for this only for tools without a wrapper (`search_graph`, `search_code`, `trace_path`).
202
+ - **`jq` is not a query tool — it only trims output.** Reach for it solely to slice a *large* response (chiefly the `get_architecture` blob) down to the field you need, for token economy. The agent can read raw JSON directly; jq is an optimization, not a requirement. Don't pipe wrapper output through jq unless you genuinely need a sub-field.
203
+
204
+ The engine uses a **unified, language-agnostic** node model — `Function`, `Method`, `Class`, `Module`, `File`, `Folder`, `Route`, `Section`, `Variable` (language is inferred from file extension) — and edges `CALLS`, `DEFINES`, `CONTAINS_FILE`, `IMPORTS`, `HTTP_CALLS`, `FILE_CHANGES_WITH`, `SEMANTICALLY_RELATED`, `SIMILAR_TO`. Each node carries `file_path` + `start_line`/`end_line` and rich `properties` (complexity, signature, parent_class), and the engine exposes full-text (`search_code`) and semantic search — none of which a committed snapshot reproduced.
142
205
 
143
206
  ## Query Tools
144
207
 
@@ -179,7 +242,14 @@ Output: `{cycles[[a,b],[a,b,c]], source}` — fixed-length 2- and 3-node `CALLS`
179
242
 
180
243
  ### Modules — dependency overview
181
244
 
182
- Read `draft/graph/architecture.json` (`.packages` for module fan-in/out, `.node_labels`/`.edge_types` for shape, `.routes` for service surface), or regenerate it with `scripts/tools/graph-snapshot.sh --repo .`.
245
+ Query the engine's architecture view live with the `graph-arch.sh` wrapper (it resolves the engine, indexes on demand, and auto-resolves the project):
246
+
247
+ ```bash
248
+ scripts/tools/graph-arch.sh --repo . \
249
+ | jq '{packages, node_labels, edge_types, routes, layers, boundaries}'
250
+ ```
251
+
252
+ `.packages` gives module fan-in/out, `.node_labels`/`.edge_types` the shape, `.routes` the service surface, `.layers`/`.boundaries` the dependency direction.
183
253
 
184
254
  ### Mermaid — diagram text
185
255
 
@@ -188,15 +258,82 @@ scripts/tools/mermaid-from-graph.sh --repo . --diagram module-deps # co-change
188
258
  scripts/tools/mermaid-from-graph.sh --repo . --diagram proto-map # detected routes
189
259
  ```
190
260
 
191
- Emits a ready-to-inject ` ```mermaid ``` ` block, or an empty stub (exit 2) when the engine is unavailable. The committed `draft/graph/*.mermaid` snapshots are written by `graph-snapshot.sh`.
261
+ Emits a ready-to-inject ` ```mermaid ``` ` block on the fly (computed live by the engine), or an empty stub (exit 2) when the engine is unavailable. Diagrams are generated at the moment of use — they are never committed.
262
+
263
+ ### Snippet — verified source + caller/callee counts
264
+
265
+ ```bash
266
+ scripts/tools/graph-snippet.sh --repo . --qualified <pkg.Mod.Class.method>
267
+ ```
268
+
269
+ Output: `{qualified_name, file, start_line, end_line, callers, callees, transitive_loop_depth, complexity, code, status, source}`. Prefer this over grep+Read when you have a qualified name — it returns the engine's attributed source plus pre-computed counts.
270
+
271
+ ### Search — semantic / ranked symbol lookup
272
+
273
+ ```bash
274
+ scripts/tools/graph-search.sh --repo . --query "auth token refresh" [--limit N]
275
+ ```
276
+
277
+ Output: `{query, results[{name, qualified_name, label, file, rank}], total, source}`. Use when the user names an **intent/concept** rather than an exact symbol — this is the first move in the Concept-to-Files recipe.
278
+
279
+ ### Tests — coverage edges and untested surface
280
+
281
+ ```bash
282
+ scripts/tools/graph-tests.sh --repo . --symbol <name> # tests covering a symbol
283
+ scripts/tools/graph-tests.sh --repo . --untested # exported symbols with no TESTS edge
284
+ ```
285
+
286
+ Output: `{symbol, tests[{test,file}], status, source}` or `{untested[{symbol,file}], total, truncated, source}`. Feeds coverage gaps for `init`/`testing-strategy`/`coverage`.
287
+
288
+ ### Deps — real module/file import graph
289
+
290
+ ```bash
291
+ scripts/tools/graph-deps.sh --repo . [--file PATH]
292
+ ```
293
+
294
+ Output: `{imports[{src,dst}], total, truncated, source}` from actual `IMPORTS` edges (self-imports filtered). This is the auto-derived dependency graph behind `mermaid-from-graph.sh --diagram module-deps` and `architecture.md §9`.
295
+
296
+ ### Hierarchy — class inheritance
297
+
298
+ ```bash
299
+ scripts/tools/graph-hierarchy.sh --repo . [--symbol <Class> | --derived <Base>]
300
+ ```
301
+
302
+ Output: `{edges[{child,parent}], status, source}`. `--derived` gives the blast radius of changing a base class.
303
+
304
+ ### Errors — error-propagation paths
305
+
306
+ ```bash
307
+ scripts/tools/graph-errors.sh --repo . --symbol <name> # what it raises/throws
308
+ scripts/tools/graph-errors.sh --repo . --type <ErrType> # who raises/throws that type
309
+ ```
310
+
311
+ Output: `{symbol, raises[...], status, source}` or `{type, raisers[...], status, source}`. `--type` drives fail-closed audits.
312
+
313
+ ### Risk — pre-computed risk hotspots
314
+
315
+ ```bash
316
+ scripts/tools/graph-risk.sh --repo . [--min-complexity N]
317
+ ```
318
+
319
+ Output: `{risky[{symbol, file, complexity, flags}], total, truncated, source}` from the engine's pre-computed flags (`unguarded_recursion`, `recursion_in_loop`, `alloc_in_loop`, `linear_scan_in_loop`). High-signal input for `bughunt`/`deep-review` — the engine already found these.
320
+
321
+ ### Generic — read-only escape hatch (all 20 edges / ~30 properties)
322
+
323
+ ```bash
324
+ scripts/tools/graph-query.sh --repo . --cypher 'MATCH (f)-[:WRITES]->(v) RETURN f.name, v.name LIMIT 50'
325
+ scripts/tools/graph-query.sh --repo . --tool get_graph_schema --json '{}'
326
+ ```
327
+
328
+ Unlocks any edge type or node property without a purpose-built wrapper. Write verbs are rejected; stay inside the SAFE dialect set (above). Emits raw engine JSON.
192
329
 
193
- ### Building / refreshing the snapshot
330
+ ### Indexing / refreshing the gate marker
194
331
 
195
332
  ```bash
196
333
  scripts/tools/graph-snapshot.sh --repo .
197
334
  ```
198
335
 
199
- Writes the committed `draft/graph/` snapshot (`schema.yaml`, `architecture.json`, `hotspots.jsonl`, `*.mermaid`, plus the Open Knowledge Format bundle under `okf/`). Run during `/draft:init` and `/draft:graph`, or whenever the reviewable graph state should be refreshed.
336
+ Indexes the repo into the engine and writes the `draft/graph/schema.yaml` gate marker (now including the `detect_changes` delta: `changed_files`/`impacted_symbols`). It writes **no** graph data. Run during `/draft:init` and `/draft:graph`, or whenever the index should be refreshed.
200
337
 
201
338
  ## Finding the Engine (Resolution + Usage Report)
202
339
 
@@ -220,7 +357,7 @@ ENGINE_INFO="$(scripts/tools/verify-graph-binary.sh --repo . --json 2>/dev/null
220
357
 
221
358
  After successful detection, `draft/.graph-binary-report.json` contains: `detected_at`, `engine_bin`, `source` (`path` | `managed` | `bundled:<arch>` | `override`), `arch`, `status`. It is a derived artifact (safe to prune), regenerated by each graph-using command that calls the verifier.
222
359
 
223
- ## Building the Snapshot
360
+ ## Indexing the Repo
224
361
 
225
362
  Run during `draft:init` / `draft:graph`, or manually:
226
363
 
@@ -228,13 +365,13 @@ Run during `draft:init` / `draft:graph`, or manually:
228
365
  scripts/tools/graph-snapshot.sh --repo .
229
366
  ```
230
367
 
231
- The engine indexes C/C++, Go, Python, TypeScript/JS, and more (tree-sitter, 159 languages) plus LSP-assisted resolution for the major ones, and detects HTTP/gRPC/GraphQL routes. Indexing is incremental in the engine (content-based, git-aware); the snapshot is re-derived on each run.
368
+ The engine indexes C/C++, Go, Python, TypeScript/JS, and more (tree-sitter, 159 languages) plus LSP-assisted resolution for the major ones, and detects HTTP/gRPC/GraphQL routes. Indexing is incremental in the engine (content-based, git-aware). This refreshes the engine index and rewrites the `schema.yaml` gate marker; it produces no committed graph data.
232
369
 
233
370
  ## Graceful Degradation
234
371
 
235
372
  | Scenario | Behavior |
236
373
  |----------|----------|
237
- | No engine resolvable (or `DRAFT_MEMORY_DISABLE=1`) | Skip graph build in init; all skills proceed without graph data; tools emit `source: unavailable` |
374
+ | No engine resolvable (or `DRAFT_MEMORY_DISABLE=1`) | Skip graph indexing in init; all skills proceed without graph data; tools emit `source: unavailable` |
238
375
  | Engine present but a query fails | Warn and proceed; skills work without graph data |
239
- | `draft/graph/` snapshot exists | Load always-load files during context loading; use live query tools as needed |
240
- | Stale snapshot | Still useful structural changes are infrequent. Re-run `graph-snapshot.sh` (or init) to refresh. |
376
+ | `draft/graph/schema.yaml` exists | Engine is wired use live query tools as needed during the run |
377
+ | Engine index out of date | The engine indexes incrementally (content-based, git-aware) on each query, so it self-freshens. Re-run `graph-snapshot.sh` (or init) to force a reindex and refresh the marker. |
@@ -12,7 +12,7 @@ See [graph-query.md](graph-query.md) §Graph Usage Report (Mandatory Footer) for
12
12
  ```md
13
13
  ## Graph Usage Report
14
14
 
15
- - Graph files queried: <comma-separated list, e.g. `architecture.json, hotspots.jsonl` and/or query tools like `graph-callers.sh` — or `NONE` with justification below>
15
+ - Graph files queried: <comma-separated list, e.g. `get_architecture, hotspot-rank.sh` and/or query tools like `graph-callers.sh` — or `NONE` with justification below>
16
16
  - Modules identified via graph: <comma-separated module names, or `none`>
17
17
  - Files identified via graph: <integer count>
18
18
  - Filesystem grep fallbacks: <list of `<pattern>` searches with one-line justification each, or `none`>
@@ -109,11 +109,11 @@ Append under `## Learned Anti-Patterns`:
109
109
  - **Suggested fix:** [Brief description of the correct approach]
110
110
  ```
111
111
 
112
- `graph_severity` derivation rules (from `draft/graph/hotspots.jsonl` fanIn values):
112
+ `graph_severity` derivation rules (from live hotspot query `scripts/tools/hotspot-rank.sh --repo .` fanIn values):
113
113
  - fanIn ≥ 10 in any evidence file → `critical`
114
114
  - fanIn 5–9 → `high`
115
115
  - fanIn 1–4 → `medium`
116
- - fanIn 0 or file not in hotspots.jsonl → `low`
116
+ - fanIn 0 or file not returned by hotspot query → `low`
117
117
  - Graph data absent → `unresolved`
118
118
 
119
119
  When `graph_severity` differs from `severity`, use `graph_severity` as the enforcement priority — it is objective and graph-derived.
@@ -12,7 +12,7 @@ Referenced by: `/draft:decompose`, `/draft:implement`, `/draft:review`, `/draft:
12
12
  ## Universal Red Flags (STOP if any apply)
13
13
 
14
14
  - **Ran `grep`/`find`/`rg` for symbol or file discovery before consulting the graph** (when `draft/graph/schema.yaml` exists).
15
- - **Read more than 50 lines of source before consulting `draft/graph/hotspots.jsonl`** to know whether the file is a hotspot.
15
+ - **Read more than 50 lines of source before querying hotspot rank** (`scripts/tools/hotspot-rank.sh --repo .`) to know whether the file is a hotspot.
16
16
  - **Omitted the Graph Usage Report footer** from the final output (see [graph-query.md](graph-query.md) §Mandatory Lookup Contract).
17
17
  - **Used a `grep` fallback without an explicit graph-miss statement** in the form: `Graph returned no match for <X>; falling back to grep.`
18
18
  - **Loaded full Layer 0.5 guardrails when the command type does not require them** (see selective-loading matrix in [draft-context-loading.md](draft-context-loading.md) §Layer 0.5).
@@ -24,7 +24,7 @@ Referenced by: `/draft:decompose`, `/draft:implement`, `/draft:review`, `/draft:
24
24
  These enforce [graph-query.md](graph-query.md) §Ground-Truth Discipline. Graph identifies candidates; Read confirms them. Shipping unread claims is the dominant correctness failure mode observed in Draft output.
25
25
 
26
26
  - **Wrote a `path:line` / `func()` / `symbol` reference into a deliverable without opening the file in this run.** Graph hit ≠ Read. (G1)
27
- - **Declared something in-scope or out-of-scope without Reading at least one file in that path.** Module names from `architecture.json` are a candidate set, not proof that the candidate contains the named cost. (G2)
27
+ - **Declared something in-scope or out-of-scope without Reading at least one file in that path.** Module names from the live engine (`get_architecture`) are a candidate set, not proof that the candidate contains the named cost. (G2)
28
28
  - **Shipped `Citation: TBD` / `Path: TBD` / `Symbol: TBD` on a row whose Status is `Modified` or `Existing`.** TBD is reserved for `Status: New` rows with a planned path filled in. (G3)
29
29
  - **Claimed code behavior (writes / blocks / loops / fails / is the only path) from graph metadata alone.** Fan-in / fan-out / complexity scores are necessary signal, not sufficient evidence. (G4)
30
30
  - **Promoted a spec / generated an HLD or LLD / closed a review without checking that the in-scope file set covers every cost term in the problem statement.** Silent scope narrowing that excludes the named cost is the highest-impact failure class. (G5)
@@ -34,7 +34,7 @@ When in doubt, prefer "not yet validated against source" over an unbacked assert
34
34
 
35
35
  ## Graph-First Lookup Order (non-negotiable)
36
36
 
37
- 1. **Graph first** — the committed snapshot (`draft/graph/architecture.json`, `draft/graph/hotspots.jsonl`) and the live query tools (`scripts/tools/graph-callers.sh`, `graph-impact.sh`, `cycle-detect.sh`, `hotspot-rank.sh`).
37
+ 1. **Graph first** — wrapper scripts (`scripts/tools/graph-arch.sh`, `graph-callers.sh`, `graph-impact.sh`, `cycle-detect.sh`, `hotspot-rank.sh`) and direct engine queries (`search_graph`, `search_code`). The gate marker `draft/graph/schema.yaml` (present = engine available) is the only committed graph file.
38
38
  2. **Generated context second** — `draft/.ai-context.md`, relevant `draft/architecture.md` slices, track-level `hld.md`/`lld.md`.
39
39
  3. **Source file reads third** — only narrowed targets identified via graph or generated context.
40
40
  4. **Filesystem `grep`/`find` last** — only after a graph miss, with the explicit fallback sentence above.
@@ -49,7 +49,7 @@ generated_at: "{ISO_TIMESTAMP}"
49
49
  ```
50
50
 
51
51
  > Include immediate sub-directories for all major modules (not just top-level).
52
- > Use graph data (`draft/graph/modules/*.jsonl`) for exhaustive sub-module enumeration.
52
+ > Use live engine queries (`get_architecture .packages[]` or `graph-callers.sh`) for exhaustive sub-module enumeration.
53
53
  > Show file counts per sub-module to indicate relative size/importance.
54
54
 
55
55
  ## GRAPH:MODULES
@@ -30,9 +30,9 @@ graph:
30
30
  go: "{approximate | high}"
31
31
  stats:
32
32
  modules: "{N from schema.yaml}"
33
- edges: "{total_edges from architecture.json}"
33
+ edges: "{total_edges from engine: get_architecture .edges}"
34
34
  hotspots: "{N}"
35
- notes: "{explicit fidelity summary from architecture.json languages/packages}"
35
+ notes: "{explicit fidelity summary from engine: get_architecture .languages/.packages}"
36
36
  generation_notes: "{High existing context detected via audit — see §10 Relationship for deference | Standard graph-primary generation}"
37
37
  ---
38
38
 
@@ -114,7 +114,7 @@ Each backed by:
114
114
 
115
115
  ## 4. Module & Dependency Map (Primarily Graph-Derived)
116
116
 
117
- - Module dependency graph rendered from `draft/graph/architecture.json` (`.packages`) + `module-deps.mermaid`
117
+ - Module dependency graph rendered from live engine query `scripts/tools/graph-arch.sh --repo . | jq '.packages'` + `scripts/tools/mermaid-from-graph.sh --repo . --diagram module-deps` (generated live, never committed)
118
118
  - High fan-in / fan-out modules highlighted
119
119
  - Cyclic dependencies called out
120
120
  - Cross-language boundaries (FFI, RPC, shared memory) explicitly surfaced with coverage notes