@tekyzinc/gsd-t 2.50.12 → 2.53.10

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 (99) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +379 -372
  3. package/bin/component-registry.js +250 -0
  4. package/bin/graph-cgc.js +510 -510
  5. package/bin/graph-indexer.js +147 -147
  6. package/bin/graph-overlay.js +195 -195
  7. package/bin/graph-parsers.js +327 -327
  8. package/bin/graph-query.js +453 -452
  9. package/bin/graph-store.js +154 -154
  10. package/bin/qa-calibrator.js +194 -0
  11. package/bin/scan-data-collector.js +153 -153
  12. package/bin/scan-diagrams-generators.js +187 -187
  13. package/bin/scan-diagrams.js +79 -79
  14. package/bin/scan-renderer.js +92 -92
  15. package/bin/scan-report-sections.js +121 -121
  16. package/bin/scan-report.js +184 -184
  17. package/bin/scan-schema-parsers.js +199 -199
  18. package/bin/scan-schema.js +103 -103
  19. package/bin/token-budget.js +246 -0
  20. package/commands/Claude-md.md +10 -10
  21. package/commands/branch.md +15 -15
  22. package/commands/checkin.md +45 -45
  23. package/commands/global-change.md +209 -209
  24. package/commands/gsd-t-audit.md +199 -0
  25. package/commands/gsd-t-backlog-add.md +94 -94
  26. package/commands/gsd-t-backlog-edit.md +111 -111
  27. package/commands/gsd-t-backlog-list.md +63 -63
  28. package/commands/gsd-t-backlog-move.md +94 -94
  29. package/commands/gsd-t-backlog-promote.md +123 -123
  30. package/commands/gsd-t-backlog-remove.md +86 -86
  31. package/commands/gsd-t-backlog-settings.md +158 -158
  32. package/commands/gsd-t-complete-milestone.md +528 -515
  33. package/commands/gsd-t-debug.md +506 -399
  34. package/commands/gsd-t-discuss.md +174 -174
  35. package/commands/gsd-t-execute.md +758 -634
  36. package/commands/gsd-t-feature.md +276 -276
  37. package/commands/gsd-t-health.md +142 -142
  38. package/commands/gsd-t-help.md +465 -457
  39. package/commands/gsd-t-impact.md +302 -302
  40. package/commands/gsd-t-init.md +320 -280
  41. package/commands/gsd-t-integrate.md +365 -249
  42. package/commands/gsd-t-milestone.md +87 -87
  43. package/commands/gsd-t-partition.md +442 -361
  44. package/commands/gsd-t-pause.md +82 -82
  45. package/commands/gsd-t-plan.md +345 -344
  46. package/commands/gsd-t-populate.md +111 -111
  47. package/commands/gsd-t-prd.md +326 -326
  48. package/commands/gsd-t-project.md +211 -211
  49. package/commands/gsd-t-promote-debt.md +123 -123
  50. package/commands/gsd-t-prompt.md +137 -137
  51. package/commands/gsd-t-qa.md +266 -266
  52. package/commands/gsd-t-quick.md +357 -234
  53. package/commands/gsd-t-reflect.md +134 -134
  54. package/commands/gsd-t-resume.md +72 -72
  55. package/commands/gsd-t-scan.md +615 -615
  56. package/commands/gsd-t-setup.md +76 -0
  57. package/commands/gsd-t-status.md +192 -166
  58. package/commands/gsd-t-test-sync.md +381 -381
  59. package/commands/gsd-t-triage-and-merge.md +171 -171
  60. package/commands/gsd-t-verify.md +382 -382
  61. package/commands/gsd-t-visualize.md +118 -118
  62. package/commands/gsd-t-wave.md +401 -378
  63. package/docs/GSD-T-README.md +425 -422
  64. package/docs/architecture.md +385 -369
  65. package/docs/harness-design-analysis.md +371 -0
  66. package/docs/infrastructure.md +205 -205
  67. package/docs/prd-graph-engine.md +398 -398
  68. package/docs/prd-gsd2-hybrid.md +559 -559
  69. package/docs/prd-harness-evolution.md +583 -0
  70. package/docs/requirements.md +14 -0
  71. package/docs/workflows.md +226 -226
  72. package/examples/.gsd-t/domains/example-domain/scope.md +13 -13
  73. package/package.json +40 -40
  74. package/scripts/gsd-t-auto-route.js +39 -39
  75. package/scripts/gsd-t-dashboard-mockup.html +1143 -1143
  76. package/scripts/gsd-t-dashboard-server.js +171 -171
  77. package/scripts/gsd-t-dashboard.html +262 -262
  78. package/scripts/gsd-t-event-writer.js +128 -128
  79. package/scripts/gsd-t-statusline.js +94 -94
  80. package/scripts/gsd-t-tools.js +175 -175
  81. package/templates/CLAUDE-global.md +639 -614
  82. package/templates/CLAUDE-project.md +24 -0
  83. package/templates/backlog-settings.md +18 -18
  84. package/templates/backlog.md +1 -1
  85. package/templates/progress.md +40 -40
  86. package/templates/shared-services-contract.md +60 -60
  87. package/templates/stacks/desktop.ini +2 -2
  88. package/bin/desktop.ini +0 -2
  89. package/commands/desktop.ini +0 -2
  90. package/docs/ci-examples/desktop.ini +0 -2
  91. package/docs/desktop.ini +0 -2
  92. package/examples/.gsd-t/contracts/desktop.ini +0 -2
  93. package/examples/.gsd-t/desktop.ini +0 -2
  94. package/examples/.gsd-t/domains/desktop.ini +0 -2
  95. package/examples/.gsd-t/domains/example-domain/desktop.ini +0 -2
  96. package/examples/desktop.ini +0 -2
  97. package/examples/rules/desktop.ini +0 -2
  98. package/scripts/desktop.ini +0 -2
  99. package/templates/desktop.ini +0 -2
@@ -1,398 +1,398 @@
1
- # PRD: Graph Engine — Native Indexer + CGC Integration
2
-
3
- ## Document Info
4
- | Field | Value |
5
- |-------|-------|
6
- | **PRD ID** | PRD-GRAPH-001 |
7
- | **Date** | 2026-03-18 |
8
- | **Author** | GSD-T Team |
9
- | **Status** | DELIVERED (M20 + M21 complete — 2026-03-20) |
10
- | **Milestones** | M20 (Graph Abstraction + Indexer + CGC), M21 (Graph-Powered Commands) |
11
- | **Version Target** | 2.37.10 (M20), 2.38.10 (M21) |
12
- | **Priority** | P0 — foundational for all future enhancements |
13
- | **Predecessor** | M19 (Shared Service Detection v2.35.10) |
14
- | **Successor** | GSD 2 milestones (M22 COMPLETE, M23-M24 queued) |
15
-
16
- ---
17
-
18
- ## 1. Problem Statement
19
-
20
- GSD-T currently uses grep-based analysis (`grep -r "import.*{module}"`) for all code structure understanding. This approach:
21
-
22
- 1. **Cannot trace transitive call chains** — grep finds direct imports but not "A calls B which calls C which modifies D"
23
- 2. **Cannot distinguish same-named functions** in different contexts — `getUser()` in auth-service vs `getUser()` in user-service
24
- 3. **Cannot persist relationships across commands** — each command re-discovers the same code relationships from scratch
25
- 4. **Cannot detect semantic duplication** — copy-paste-rename code escapes text-matching entirely
26
- 5. **Cannot map code entities to GSD-T concepts** — grep doesn't know which domain owns a function, which contract it implements, or which requirement it satisfies
27
-
28
- This limits the quality of 21 commands that analyze or reason about code structure.
29
-
30
- ---
31
-
32
- ## 2. Objective
33
-
34
- Build a **graph abstraction layer** with two pluggable providers:
35
-
36
- 1. **Native Indexer** (zero-dependency, always available) — lightweight JS parser that extracts function/class/import entities and relationships, enriched with GSD-T context (domains, contracts, requirements, tests, tech debt)
37
- 2. **CGC Integration** (automatic when available) — CodeGraphContext MCP server providing deeper analysis (AST comparison, cross-language type flow, transitive call chains via Tree-sitter)
38
-
39
- Commands query the abstraction layer. They never know which provider answered. The fallback chain is automatic and invisible:
40
-
41
- ```
42
- CGC MCP → Native Graph → Grep (always works)
43
- ```
44
-
45
- ---
46
-
47
- ## 3. User Stories
48
-
49
- ### US-1: Developer runs scan on a large project
50
- **Today**: 5 grep-based agents find text-pattern duplicates. Misses semantic duplication (same logic, different names). Reports ~60% of actual issues.
51
- **With graph**: Scan queries the graph for structural duplication (AST comparison via CGC), circular dependency cycles (transitive call chains), dead code (unreachable from any entry point), and domain boundary violations. Reports ~95% of actual issues.
52
-
53
- ### US-2: Developer runs impact before changing a shared function
54
- **Today**: `grep -r "import.*processPayment"` finds direct importers. Misses transitive callers (checkout calls paymentHandler which calls processPayment). Developer changes processPayment, checkout breaks in production.
55
- **With graph**: Impact traces the full call chain: processPayment ← paymentHandler ← checkout ← [web-frontend, mobile-app]. Shows all 4 affected files, 2 affected surfaces, 1 contract violation. Developer knows the full blast radius before writing code.
56
-
57
- ### US-3: Debug session for a production failure
58
- **Today**: Developer describes the error. Debug command greps for related functions, guesses at call paths. Takes 3-4 iterations to find root cause.
59
- **With graph**: Debug traces the call chain from the error location backward through the graph. Shows the exact path: `webhookHandler.stripeEvent → processPayment → stripeClient.charge → [rate limit error]`. Root cause identified in one pass. Prior failure/learning entries from Decision Log attached to relevant graph nodes.
60
-
61
- ### US-4: Partition auto-detects domain boundaries
62
- **Today**: Partition uses file paths and import patterns to suggest domains. Misses shared backend functions that serve multiple surfaces.
63
- **With graph**: Partition queries the graph for operation-to-surface mapping. Identifies that `processPayment`, `validateCart`, and `applyDiscount` are all called by both web-frontend and mobile-app. Auto-creates SharedCore domain with these functions. Correct boundaries from the start.
64
-
65
- ### US-5: Execute verifies domain isolation during task execution
66
- **Today**: QA subagent runs tests after execution. Domain boundary violations only caught if a test happens to cover them.
67
- **With graph**: Execute queries the graph before and after each task. If a task in the payments domain modified a function owned by the auth domain, the violation is caught immediately — before tests even run.
68
-
69
- ### US-6: Visualize renders actual code architecture
70
- **Today**: Dashboard shows agent hierarchy and event stream. No code structure visualization.
71
- **With graph**: Dashboard can render domain-to-function ownership graphs, call chain diagrams, contract-to-code mapping, and cross-surface dependency trees. The graph IS the data source for architectural visualization.
72
-
73
- ---
74
-
75
- ## 4. Command Impact Matrix (Complete Audit)
76
-
77
- ### TIER 1 — Transformative (fundamentally changes how the command works)
78
-
79
- | Command | Current Approach | With Graph |
80
- |---------|-----------------|------------|
81
- | **scan** | 5 grep agents | Graph queries: dead code, circular deps, AST duplication, domain violations |
82
- | **impact** | `grep -r "import.*{module}"` | Transitive caller/callee traversal + contract violation detection |
83
- | **partition** | File path + import pattern heuristics | Operation-to-surface graph for SharedCore auto-detection |
84
- | **debug** | Grep for related functions, guess call paths | Call-chain tracing from error → root cause in one pass |
85
- | **execute** | QA validates after the fact | Domain isolation verification during execution, not just after |
86
- | **visualize** | Agent hierarchy + event stream only | Code architecture graphs, domain maps, contract-to-code diagrams |
87
-
88
- ### TIER 2 — High Impact (significantly improves quality/speed)
89
-
90
- | Command | Improvement |
91
- |---------|-------------|
92
- | **qa** | Gap detection: contracts without tests via contract-to-call-chain mapping |
93
- | **wave** | Cross-phase consistency: partition boundaries match actual code ownership before execute |
94
- | **integrate** | Automatic cross-domain boundary violation detection during wiring |
95
- | **verify** | Automated requirement traceability chain verification |
96
- | **gap-analysis** | Requirement-to-code mapping via entity relationships |
97
-
98
- ### TIER 3 — Moderate Impact
99
-
100
- | Command | Improvement |
101
- |---------|-------------|
102
- | **quick** | Instant domain-boundary violation check before writing code |
103
- | **plan** | Deterministic cross-domain duplicate detection, implicit task dependency ordering |
104
- | **test-sync** | Transitive test dependency mapping, stale test detection |
105
- | **complete-milestone** | Validate delivered components against milestone scope |
106
- | **status** | Richer progress metrics: % functions implemented, dependency bottlenecks |
107
- | **feature** | Unified blast radius calculation across all surfaces |
108
-
109
- ### TIER 4 — Light Impact
110
-
111
- | Command | Improvement |
112
- |---------|-------------|
113
- | **promote-debt** | Impact radius for prioritization (how many downstream functions affected) |
114
- | **populate** | More accurate architecture docs from actual component relationships |
115
- | **init-scan-setup** | Graph-assisted scan phase auto-populates architecture findings |
116
-
117
- ### No Impact (15 commands)
118
-
119
- milestone, project, prd, discuss, setup, triage-and-merge, reflect, brainstorm, prompt, health, log, resume, pause, help, all backlog commands (6), branch, checkin, Claude-md, global-change, version-update, version-update-all
120
-
121
- ---
122
-
123
- ## 5. Architecture
124
-
125
- ### 5.1 Graph Abstraction Layer
126
-
127
- ```
128
- ┌─────────────────────────────────────────────────┐
129
- │ GSD-T Commands │
130
- │ (scan, impact, debug, partition, execute...) │
131
- └──────────────────────┬──────────────────────────┘
132
- │ query(type, params)
133
-
134
- ┌─────────────────────────────────────────────────┐
135
- │ Graph Abstraction Layer │
136
- │ │
137
- │ Unified query interface: │
138
- │ - getCallers(entity) │
139
- │ - getCallees(entity) │
140
- │ - getTransitiveCallers(entity, depth) │
141
- │ - getDomainOwner(entity) │
142
- │ - getContractFor(entity) │
143
- │ - getRequirementFor(entity) │
144
- │ - getTestsFor(entity) │
145
- │ - findDuplicates(threshold) │
146
- │ - getDomainBoundaryViolations() │
147
- │ - getSurfaceConsumers(entity) │
148
- │ │
149
- │ Provider selection (automatic): │
150
- │ 1. CGC MCP available? → use CGC + overlay │
151
- │ 2. Native graph indexed? → use native │
152
- │ 3. Fallback → grep patterns │
153
- └───────┬─────────────────────────┬───────────────┘
154
- │ │
155
- ▼ ▼
156
- ┌───────────────┐ ┌─────────────────────────┐
157
- │ Native Indexer │ │ CGC MCP Provider │
158
- │ │ │ │
159
- │ JS parser │ │ MCP client → CGC server │
160
- │ .gsd-t/graph/ │ │ Tree-sitter + graph DB │
161
- │ JSON store │ │ AST comparison │
162
- │ GSD-T overlay │ │ Cross-language type flow │
163
- │ │ │ + GSD-T overlay │
164
- └───────────────┘ └─────────────────────────┘
165
- ```
166
-
167
- ### 5.2 Native Indexer
168
-
169
- **Location**: `bin/graph-indexer.js` (new file)
170
-
171
- **Capabilities**:
172
- - Parse JS/TS/Python files for function, class, and import declarations
173
- - Build direct call relationship map
174
- - Map entities to GSD-T domains (via `.gsd-t/domains/*/scope.md` file ownership)
175
- - Map entities to contracts (via `.gsd-t/contracts/*.md` pattern matching)
176
- - Map entities to requirements (via `docs/requirements.md` REQ-ID references)
177
- - Map entities to tests (via test file naming conventions + import analysis)
178
- - Map entities to tech debt items (via `.gsd-t/techdebt.md` references)
179
-
180
- **Storage**: `.gsd-t/graph/` directory
181
- ```
182
- .gsd-t/graph/
183
- index.json ← entity registry (id, name, type, file, line, domain)
184
- calls.json ← caller → callee edges
185
- imports.json ← import relationships
186
- contracts.json ← entity → contract mapping
187
- requirements.json ← entity → REQ-ID mapping
188
- tests.json ← entity → test file mapping
189
- surfaces.json ← entity → consumer surface mapping
190
- meta.json ← last indexed timestamp, file hashes for incremental
191
- ```
192
-
193
- **Indexing trigger**: Commands that query the graph auto-trigger indexing if `meta.json` is stale (file hashes changed). Indexing is incremental — only re-parses changed files.
194
-
195
- **Zero external dependencies**: Uses regex-based parsing (not Tree-sitter). Sufficient for direct entity extraction and call-chain mapping in JS/TS/Python. Does NOT attempt AST comparison or type flow — that's CGC's domain.
196
-
197
- ### 5.3 CGC MCP Provider
198
-
199
- **Detection**: Check if CGC MCP server is responding (health endpoint or MCP handshake).
200
-
201
- **Integration**: Query CGC via MCP protocol for:
202
- - Transitive call chains (depth > 1)
203
- - AST comparison for semantic duplication
204
- - Cross-language type flow analysis
205
- - Full Tree-sitter parsed entity data
206
-
207
- **GSD-T Overlay**: CGC entities are enriched with GSD-T context from the native graph's mapping files (domain, contract, requirement, test, debt). CGC provides the code topology; the overlay provides the methodology context.
208
-
209
- ### 5.4 Grep Fallback
210
-
211
- When neither graph provider is available, commands fall back to current grep-based analysis. This ensures GSD-T works in any environment — the graph is an enhancement, not a requirement.
212
-
213
- ---
214
-
215
- ## 6. Milestone Breakdown
216
-
217
- ### M20: Graph Abstraction Layer + Native Indexer + CGC Integration
218
-
219
- **Scope**: Build the foundation — abstraction layer, native indexer, CGC provider, storage format, incremental indexing.
220
-
221
- | Domain | Deliverables |
222
- |--------|-------------|
223
- | **graph-abstraction** | Unified query interface, provider selection logic, query routing |
224
- | **native-indexer** | JS/TS/Python parser, entity extraction, call-chain mapping, GSD-T overlay (domain/contract/requirement/test/debt mapping) |
225
- | **cgc-provider** | MCP client, CGC query translation, health detection, auto-fallback |
226
- | **graph-storage** | `.gsd-t/graph/` JSON format, incremental indexing, file hash tracking |
227
- | **cli-integration** | `gsd-t graph index` CLI subcommand, `gsd-t graph status`, `gsd-t graph query` |
228
-
229
- **Exit Criteria**:
230
- - Native indexer parses a JS/TS project and produces correct entity/call-chain data
231
- - CGC provider connects to running CGC MCP server and returns enriched results
232
- - Fallback chain works: CGC unavailable → native → grep
233
- - Incremental indexing only re-parses changed files
234
- - CLI subcommands functional
235
-
236
- ### M21: Graph-Powered Commands
237
-
238
- **Scope**: Wire the graph into all 21 impacted commands. Each command checks graph availability and uses the best available provider.
239
-
240
- | Domain | Commands | Changes |
241
- |--------|----------|---------|
242
- | **tier-1-commands** | scan, impact, partition, debug, execute, visualize | Major rewrites of analysis logic to use graph queries |
243
- | **tier-2-commands** | qa, wave, integrate, verify, gap-analysis | Add graph-enhanced validation steps |
244
- | **tier-3-commands** | quick, plan, test-sync, complete-milestone, status, feature | Add graph checks where beneficial |
245
- | **tier-4-commands** | promote-debt, populate, init-scan-setup | Light graph enrichment |
246
-
247
- **Exit Criteria**:
248
- - All 21 commands use graph when available, fall back gracefully when not
249
- - Scan on GSD-T itself produces higher-quality findings than grep-only scan
250
- - No command breaks when graph is unavailable (grep fallback works)
251
- - Pre-Commit Gate updated with graph-related checks
252
- - All 4 reference docs updated (README, GSD-T-README, CLAUDE-global, gsd-t-help)
253
-
254
- **Validation Gate**: After M21 completes, run `gsd-t-scan` on GSD-T itself. Compare findings to prior scan results. Graph-powered scan must find issues that grep-only scan missed.
255
-
256
- ---
257
-
258
- ## 7. Real-World Scenario: Option B vs Option C per Command
259
-
260
- For each impacted command, here's how **Option B (native only)** compares to **Option C (native + CGC)**.
261
-
262
- ### scan
263
- - **Option B**: Detects direct circular imports, dead exports, naming-convention duplicates. Catches ~80% of structural issues.
264
- - **Option C**: Adds AST comparison — finds semantically identical functions with different names (copy-paste-rename debt). Catches ~95% of structural issues. Example: `canUserEdit()` in auth-service and `hasEditPermission()` in user-service have identical ASTs. Option B misses this. Option C flags it as a duplication candidate.
265
-
266
- ### impact
267
- - **Option B**: Traces 1-level callers and callees. Shows direct consumers of a function. "processPayment is called by paymentHandler and webhookHandler."
268
- - **Option C**: Traces N-level transitive callers with type flow. Shows full blast radius. "processPayment ← paymentHandler ← checkout ← [web-frontend route /checkout, mobile-app PaymentScreen]. The return type PaymentResult flows through all 4 callers — changing its shape breaks 4 consumers across 2 surfaces." Option C shows WHERE the type changes propagate, not just WHO calls the function.
269
-
270
- ### partition
271
- - **Option B**: Maps file ownership to domains based on directory structure and import patterns. Good for most cases.
272
- - **Option C**: Adds cross-language analysis. In a project with a Python backend and JS frontend, Option C maps the REST contract between them. Option B can only see one language at a time.
273
-
274
- ### debug
275
- - **Option B**: Traces direct call chain from error location. "Error in stripeClient.charge, called by processPayment."
276
- - **Option C**: Traces full transitive chain with type flow. "Error in stripeClient.charge. The `amount` parameter is typed as `number` in processPayment but arrives as `string` from webhookHandler.parseBody — type coercion at the boundary caused the Stripe API rejection." Option C identifies the type mismatch root cause, not just the call path.
277
-
278
- ### execute
279
- - **Option B**: Checks domain file ownership. "This task modified auth-service/getUser.ts which belongs to the auth domain, not the payments domain."
280
- - **Option C**: Also checks for indirect boundary violations via shared imports. "This task didn't modify auth-service files directly, but it changed the type signature of SharedTypes.UserRole which is imported by 3 auth-service functions." Option C catches ripple effects through shared types.
281
-
282
- ### visualize
283
- - **Option B**: Renders domain-to-function ownership graphs and direct call chains. Useful for understanding "what's in each domain."
284
- - **Option C**: Renders full transitive dependency trees with type flow annotations and cross-language edges. Useful for understanding "how does data flow through the entire system."
285
-
286
- ### qa
287
- - **Option B**: Maps contracts to test files by naming convention and direct imports. Finds contracts without test coverage.
288
- - **Option C**: Maps contracts to test files through transitive call chains. Finds contracts that have tests but those tests don't exercise the actual contract path — they test a helper function that happens to be in the same file. False coverage detection.
289
-
290
- ### wave
291
- - **Option B**: Validates partition boundaries against file ownership between phases.
292
- - **Option C**: Also validates that no transitive dependencies cross partition boundaries. A function might be in the right domain folder but import a utility that imports a function from another domain — indirect boundary violation.
293
-
294
- ### integrate
295
- - **Option B**: Checks that cross-domain calls match contract specs at the direct call level.
296
- - **Option C**: Checks type compatibility across the integration boundary. "Domain A's `createOrder()` returns `OrderResponse` but domain B's consumer expects `OrderResult` — structurally similar but field `totalAmount` is named `total` in domain B's type. Integration will fail at runtime."
297
-
298
- ### verify
299
- - **Option B**: Maps requirements to code entities. "REQ-012 is implemented by processPayment."
300
- - **Option C**: Maps requirements through the full call chain. "REQ-012 (Payment Processing) is implemented by processPayment → stripeClient.charge → [external API]. The requirement says 'retry on failure' but the call chain has no retry logic — requirement partially implemented."
301
-
302
- ### gap-analysis
303
- - **Option B**: Matches REQ-IDs to function names and file paths. Finds unmapped requirements.
304
- - **Option C**: Traces requirement implementation depth. "REQ-015 (Notification Delivery) maps to sendNotification(), but sendNotification() calls emailProvider.send() which has a TODO comment and returns a hardcoded `true`. The requirement is mapped but not meaningfully implemented."
305
-
306
- ### quick
307
- - **Option B**: Checks if the task's target file belongs to the expected domain.
308
- - **Option C**: Also checks if the change would affect functions consumed by other domains via shared imports. "This quick fix changes `formatCurrency()` in utils/ — 7 functions across 3 domains import it. Run impact first."
309
-
310
- ### plan
311
- - **Option B**: Detects when two tasks in different domains create functions with the same name.
312
- - **Option C**: Detects when two tasks create functions with the same AST structure (semantic duplication across domains, not just name collision).
313
-
314
- ### test-sync
315
- - **Option B**: Maps test files to source files by naming convention. Finds tests for deleted/renamed functions.
316
- - **Option C**: Maps tests through transitive imports. Finds tests that import a helper that imports the tested function — when the tested function changes, these indirect tests may also need updating. Option B only catches direct test-to-source mapping.
317
-
318
- ### complete-milestone
319
- - **Option B**: Lists functions created/modified during the milestone based on git diff + domain scope.
320
- - **Option C**: Validates that all functions listed in the milestone scope are reachable from at least one entry point. Catches "implemented but unwired" functions that pass all tests individually but are never called in the actual application.
321
-
322
- ### status
323
- - **Option B**: Shows domain progress as % of tasks complete.
324
- - **Option C**: Adds code coverage depth: "payments domain: 8/10 tasks complete, 23 functions implemented, 3 unreachable from any entry point, 2 with no test coverage."
325
-
326
- ### feature
327
- - **Option B**: Calculates blast radius based on file count per domain.
328
- - **Option C**: Calculates blast radius based on transitive call chains across surfaces. "Adding recurring payments affects 12 functions across 3 domains, consumed by 2 surfaces. Estimated 6 contract updates needed."
329
-
330
- ### promote-debt
331
- - **Option B**: Shows debt item and its file location.
332
- - **Option C**: Shows debt item's impact radius. "TD-042 (no error handling in stripeClient.charge) is called by 4 functions, consumed by 2 surfaces, affects 3 contracts. High priority — promotes to milestone."
333
-
334
- ### populate
335
- - **Option B**: Auto-fills architecture.md with domain structure and file listings.
336
- - **Option C**: Auto-fills architecture.md with actual component relationships, call chains, and data flow diagrams generated from the graph.
337
-
338
- ### init-scan-setup
339
- - **Option B**: Scan phase uses native graph for initial analysis.
340
- - **Option C**: Scan phase uses full CGC analysis for comprehensive initial codebase assessment.
341
-
342
- ---
343
-
344
- ## 8. Non-Goals
345
-
346
- - **Replacing grep entirely** — grep remains the universal fallback
347
- - **Building a Tree-sitter parser** — that's CGC's job; the native indexer uses regex
348
- - **Supporting all programming languages** — M20 targets JS/TS/Python; others added by demand
349
- - **Real-time indexing** — indexing is triggered on-demand by commands, not via file watchers
350
- - **Graph visualization in terminal** — visualization is via the existing dashboard (gsd-t-visualize)
351
- - **LLM-powered code analysis** — the graph is deterministic; LLM interprets graph results
352
-
353
- ---
354
-
355
- ## 9. Risks and Mitigations
356
-
357
- | Risk | Likelihood | Impact | Mitigation |
358
- |------|-----------|--------|------------|
359
- | Regex parser misses edge cases in complex JS/TS | Medium | Medium | Fallback to CGC for complex analysis; native parser covers common patterns |
360
- | CGC project abandoned (single maintainer, alpha) | Medium | Low | Graph abstraction layer means CGC is swappable; native graph covers 80% |
361
- | Graph storage grows large on big projects | Low | Medium | Incremental indexing + file hash deduplication; graph files are git-ignored |
362
- | Performance impact on command startup | Medium | Medium | Lazy loading — graph only queried when command needs it; index check is O(1) via meta.json |
363
- | Breaking change in CGC MCP protocol | Medium | Low | Provider adapter isolates protocol changes; only cgc-provider.js needs updating |
364
-
365
- ---
366
-
367
- ## 10. Success Metrics
368
-
369
- | Metric | Target |
370
- |--------|--------|
371
- | Commands using graph | 21 of 46 |
372
- | Scan finding improvement vs grep-only | ≥30% more issues found |
373
- | Impact blast radius accuracy | 100% of transitive callers identified (vs ~40% with grep) |
374
- | Indexing time for 10K-line project | < 5 seconds (native), < 15 seconds (CGC) |
375
- | Zero-dep principle maintained | Native indexer: 0 external deps. CGC: optional external dep. |
376
- | Fallback reliability | 100% — every command works without graph |
377
-
378
- ---
379
-
380
- ## 11. Dependencies
381
-
382
- | Dependency | Type | Risk |
383
- |-----------|------|------|
384
- | CodeGraphContext MCP server | Optional external | Alpha maturity; mitigated by abstraction layer |
385
- | Node.js >= 16 | Required (existing) | Already a GSD-T requirement |
386
- | `.gsd-t/` directory structure | Required (existing) | Already established |
387
- | Claude Code slash command system | Required (existing) | Already established |
388
-
389
- ---
390
-
391
- ## 12. Timeline
392
-
393
- | Milestone | Estimated Effort | Sequence |
394
- |-----------|-----------------|----------|
395
- | M20: Graph Abstraction + Indexer + CGC | 3-4 domains, medium complexity | First |
396
- | M21: Graph-Powered Commands | 4 domains (by tier), high complexity | Second |
397
- | Validation: Scan GSD-T itself | 1 scan run + comparison | After M21 |
398
- | Then → GSD 2 milestones (M22+) | See PRD-GSD2-001 | After validation |
1
+ # PRD: Graph Engine — Native Indexer + CGC Integration
2
+
3
+ ## Document Info
4
+ | Field | Value |
5
+ |-------|-------|
6
+ | **PRD ID** | PRD-GRAPH-001 |
7
+ | **Date** | 2026-03-18 |
8
+ | **Author** | GSD-T Team |
9
+ | **Status** | DELIVERED (M20 + M21 complete — 2026-03-20) |
10
+ | **Milestones** | M20 (Graph Abstraction + Indexer + CGC), M21 (Graph-Powered Commands) |
11
+ | **Version Target** | 2.37.10 (M20), 2.38.10 (M21) |
12
+ | **Priority** | P0 — foundational for all future enhancements |
13
+ | **Predecessor** | M19 (Shared Service Detection v2.35.10) |
14
+ | **Successor** | GSD 2 milestones (M22 COMPLETE, M23-M24 queued) |
15
+
16
+ ---
17
+
18
+ ## 1. Problem Statement
19
+
20
+ GSD-T currently uses grep-based analysis (`grep -r "import.*{module}"`) for all code structure understanding. This approach:
21
+
22
+ 1. **Cannot trace transitive call chains** — grep finds direct imports but not "A calls B which calls C which modifies D"
23
+ 2. **Cannot distinguish same-named functions** in different contexts — `getUser()` in auth-service vs `getUser()` in user-service
24
+ 3. **Cannot persist relationships across commands** — each command re-discovers the same code relationships from scratch
25
+ 4. **Cannot detect semantic duplication** — copy-paste-rename code escapes text-matching entirely
26
+ 5. **Cannot map code entities to GSD-T concepts** — grep doesn't know which domain owns a function, which contract it implements, or which requirement it satisfies
27
+
28
+ This limits the quality of 21 commands that analyze or reason about code structure.
29
+
30
+ ---
31
+
32
+ ## 2. Objective
33
+
34
+ Build a **graph abstraction layer** with two pluggable providers:
35
+
36
+ 1. **Native Indexer** (zero-dependency, always available) — lightweight JS parser that extracts function/class/import entities and relationships, enriched with GSD-T context (domains, contracts, requirements, tests, tech debt)
37
+ 2. **CGC Integration** (automatic when available) — CodeGraphContext MCP server providing deeper analysis (AST comparison, cross-language type flow, transitive call chains via Tree-sitter)
38
+
39
+ Commands query the abstraction layer. They never know which provider answered. The fallback chain is automatic and invisible:
40
+
41
+ ```
42
+ CGC MCP → Native Graph → Grep (always works)
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 3. User Stories
48
+
49
+ ### US-1: Developer runs scan on a large project
50
+ **Today**: 5 grep-based agents find text-pattern duplicates. Misses semantic duplication (same logic, different names). Reports ~60% of actual issues.
51
+ **With graph**: Scan queries the graph for structural duplication (AST comparison via CGC), circular dependency cycles (transitive call chains), dead code (unreachable from any entry point), and domain boundary violations. Reports ~95% of actual issues.
52
+
53
+ ### US-2: Developer runs impact before changing a shared function
54
+ **Today**: `grep -r "import.*processPayment"` finds direct importers. Misses transitive callers (checkout calls paymentHandler which calls processPayment). Developer changes processPayment, checkout breaks in production.
55
+ **With graph**: Impact traces the full call chain: processPayment ← paymentHandler ← checkout ← [web-frontend, mobile-app]. Shows all 4 affected files, 2 affected surfaces, 1 contract violation. Developer knows the full blast radius before writing code.
56
+
57
+ ### US-3: Debug session for a production failure
58
+ **Today**: Developer describes the error. Debug command greps for related functions, guesses at call paths. Takes 3-4 iterations to find root cause.
59
+ **With graph**: Debug traces the call chain from the error location backward through the graph. Shows the exact path: `webhookHandler.stripeEvent → processPayment → stripeClient.charge → [rate limit error]`. Root cause identified in one pass. Prior failure/learning entries from Decision Log attached to relevant graph nodes.
60
+
61
+ ### US-4: Partition auto-detects domain boundaries
62
+ **Today**: Partition uses file paths and import patterns to suggest domains. Misses shared backend functions that serve multiple surfaces.
63
+ **With graph**: Partition queries the graph for operation-to-surface mapping. Identifies that `processPayment`, `validateCart`, and `applyDiscount` are all called by both web-frontend and mobile-app. Auto-creates SharedCore domain with these functions. Correct boundaries from the start.
64
+
65
+ ### US-5: Execute verifies domain isolation during task execution
66
+ **Today**: QA subagent runs tests after execution. Domain boundary violations only caught if a test happens to cover them.
67
+ **With graph**: Execute queries the graph before and after each task. If a task in the payments domain modified a function owned by the auth domain, the violation is caught immediately — before tests even run.
68
+
69
+ ### US-6: Visualize renders actual code architecture
70
+ **Today**: Dashboard shows agent hierarchy and event stream. No code structure visualization.
71
+ **With graph**: Dashboard can render domain-to-function ownership graphs, call chain diagrams, contract-to-code mapping, and cross-surface dependency trees. The graph IS the data source for architectural visualization.
72
+
73
+ ---
74
+
75
+ ## 4. Command Impact Matrix (Complete Audit)
76
+
77
+ ### TIER 1 — Transformative (fundamentally changes how the command works)
78
+
79
+ | Command | Current Approach | With Graph |
80
+ |---------|-----------------|------------|
81
+ | **scan** | 5 grep agents | Graph queries: dead code, circular deps, AST duplication, domain violations |
82
+ | **impact** | `grep -r "import.*{module}"` | Transitive caller/callee traversal + contract violation detection |
83
+ | **partition** | File path + import pattern heuristics | Operation-to-surface graph for SharedCore auto-detection |
84
+ | **debug** | Grep for related functions, guess call paths | Call-chain tracing from error → root cause in one pass |
85
+ | **execute** | QA validates after the fact | Domain isolation verification during execution, not just after |
86
+ | **visualize** | Agent hierarchy + event stream only | Code architecture graphs, domain maps, contract-to-code diagrams |
87
+
88
+ ### TIER 2 — High Impact (significantly improves quality/speed)
89
+
90
+ | Command | Improvement |
91
+ |---------|-------------|
92
+ | **qa** | Gap detection: contracts without tests via contract-to-call-chain mapping |
93
+ | **wave** | Cross-phase consistency: partition boundaries match actual code ownership before execute |
94
+ | **integrate** | Automatic cross-domain boundary violation detection during wiring |
95
+ | **verify** | Automated requirement traceability chain verification |
96
+ | **gap-analysis** | Requirement-to-code mapping via entity relationships |
97
+
98
+ ### TIER 3 — Moderate Impact
99
+
100
+ | Command | Improvement |
101
+ |---------|-------------|
102
+ | **quick** | Instant domain-boundary violation check before writing code |
103
+ | **plan** | Deterministic cross-domain duplicate detection, implicit task dependency ordering |
104
+ | **test-sync** | Transitive test dependency mapping, stale test detection |
105
+ | **complete-milestone** | Validate delivered components against milestone scope |
106
+ | **status** | Richer progress metrics: % functions implemented, dependency bottlenecks |
107
+ | **feature** | Unified blast radius calculation across all surfaces |
108
+
109
+ ### TIER 4 — Light Impact
110
+
111
+ | Command | Improvement |
112
+ |---------|-------------|
113
+ | **promote-debt** | Impact radius for prioritization (how many downstream functions affected) |
114
+ | **populate** | More accurate architecture docs from actual component relationships |
115
+ | **init-scan-setup** | Graph-assisted scan phase auto-populates architecture findings |
116
+
117
+ ### No Impact (15 commands)
118
+
119
+ milestone, project, prd, discuss, setup, triage-and-merge, reflect, brainstorm, prompt, health, log, resume, pause, help, all backlog commands (6), branch, checkin, Claude-md, global-change, version-update, version-update-all
120
+
121
+ ---
122
+
123
+ ## 5. Architecture
124
+
125
+ ### 5.1 Graph Abstraction Layer
126
+
127
+ ```
128
+ ┌─────────────────────────────────────────────────┐
129
+ │ GSD-T Commands │
130
+ │ (scan, impact, debug, partition, execute...) │
131
+ └──────────────────────┬──────────────────────────┘
132
+ │ query(type, params)
133
+
134
+ ┌─────────────────────────────────────────────────┐
135
+ │ Graph Abstraction Layer │
136
+ │ │
137
+ │ Unified query interface: │
138
+ │ - getCallers(entity) │
139
+ │ - getCallees(entity) │
140
+ │ - getTransitiveCallers(entity, depth) │
141
+ │ - getDomainOwner(entity) │
142
+ │ - getContractFor(entity) │
143
+ │ - getRequirementFor(entity) │
144
+ │ - getTestsFor(entity) │
145
+ │ - findDuplicates(threshold) │
146
+ │ - getDomainBoundaryViolations() │
147
+ │ - getSurfaceConsumers(entity) │
148
+ │ │
149
+ │ Provider selection (automatic): │
150
+ │ 1. CGC MCP available? → use CGC + overlay │
151
+ │ 2. Native graph indexed? → use native │
152
+ │ 3. Fallback → grep patterns │
153
+ └───────┬─────────────────────────┬───────────────┘
154
+ │ │
155
+ ▼ ▼
156
+ ┌───────────────┐ ┌─────────────────────────┐
157
+ │ Native Indexer │ │ CGC MCP Provider │
158
+ │ │ │ │
159
+ │ JS parser │ │ MCP client → CGC server │
160
+ │ .gsd-t/graph/ │ │ Tree-sitter + graph DB │
161
+ │ JSON store │ │ AST comparison │
162
+ │ GSD-T overlay │ │ Cross-language type flow │
163
+ │ │ │ + GSD-T overlay │
164
+ └───────────────┘ └─────────────────────────┘
165
+ ```
166
+
167
+ ### 5.2 Native Indexer
168
+
169
+ **Location**: `bin/graph-indexer.js` (new file)
170
+
171
+ **Capabilities**:
172
+ - Parse JS/TS/Python files for function, class, and import declarations
173
+ - Build direct call relationship map
174
+ - Map entities to GSD-T domains (via `.gsd-t/domains/*/scope.md` file ownership)
175
+ - Map entities to contracts (via `.gsd-t/contracts/*.md` pattern matching)
176
+ - Map entities to requirements (via `docs/requirements.md` REQ-ID references)
177
+ - Map entities to tests (via test file naming conventions + import analysis)
178
+ - Map entities to tech debt items (via `.gsd-t/techdebt.md` references)
179
+
180
+ **Storage**: `.gsd-t/graph/` directory
181
+ ```
182
+ .gsd-t/graph/
183
+ index.json ← entity registry (id, name, type, file, line, domain)
184
+ calls.json ← caller → callee edges
185
+ imports.json ← import relationships
186
+ contracts.json ← entity → contract mapping
187
+ requirements.json ← entity → REQ-ID mapping
188
+ tests.json ← entity → test file mapping
189
+ surfaces.json ← entity → consumer surface mapping
190
+ meta.json ← last indexed timestamp, file hashes for incremental
191
+ ```
192
+
193
+ **Indexing trigger**: Commands that query the graph auto-trigger indexing if `meta.json` is stale (file hashes changed). Indexing is incremental — only re-parses changed files.
194
+
195
+ **Zero external dependencies**: Uses regex-based parsing (not Tree-sitter). Sufficient for direct entity extraction and call-chain mapping in JS/TS/Python. Does NOT attempt AST comparison or type flow — that's CGC's domain.
196
+
197
+ ### 5.3 CGC MCP Provider
198
+
199
+ **Detection**: Check if CGC MCP server is responding (health endpoint or MCP handshake).
200
+
201
+ **Integration**: Query CGC via MCP protocol for:
202
+ - Transitive call chains (depth > 1)
203
+ - AST comparison for semantic duplication
204
+ - Cross-language type flow analysis
205
+ - Full Tree-sitter parsed entity data
206
+
207
+ **GSD-T Overlay**: CGC entities are enriched with GSD-T context from the native graph's mapping files (domain, contract, requirement, test, debt). CGC provides the code topology; the overlay provides the methodology context.
208
+
209
+ ### 5.4 Grep Fallback
210
+
211
+ When neither graph provider is available, commands fall back to current grep-based analysis. This ensures GSD-T works in any environment — the graph is an enhancement, not a requirement.
212
+
213
+ ---
214
+
215
+ ## 6. Milestone Breakdown
216
+
217
+ ### M20: Graph Abstraction Layer + Native Indexer + CGC Integration
218
+
219
+ **Scope**: Build the foundation — abstraction layer, native indexer, CGC provider, storage format, incremental indexing.
220
+
221
+ | Domain | Deliverables |
222
+ |--------|-------------|
223
+ | **graph-abstraction** | Unified query interface, provider selection logic, query routing |
224
+ | **native-indexer** | JS/TS/Python parser, entity extraction, call-chain mapping, GSD-T overlay (domain/contract/requirement/test/debt mapping) |
225
+ | **cgc-provider** | MCP client, CGC query translation, health detection, auto-fallback |
226
+ | **graph-storage** | `.gsd-t/graph/` JSON format, incremental indexing, file hash tracking |
227
+ | **cli-integration** | `gsd-t graph index` CLI subcommand, `gsd-t graph status`, `gsd-t graph query` |
228
+
229
+ **Exit Criteria**:
230
+ - Native indexer parses a JS/TS project and produces correct entity/call-chain data
231
+ - CGC provider connects to running CGC MCP server and returns enriched results
232
+ - Fallback chain works: CGC unavailable → native → grep
233
+ - Incremental indexing only re-parses changed files
234
+ - CLI subcommands functional
235
+
236
+ ### M21: Graph-Powered Commands
237
+
238
+ **Scope**: Wire the graph into all 21 impacted commands. Each command checks graph availability and uses the best available provider.
239
+
240
+ | Domain | Commands | Changes |
241
+ |--------|----------|---------|
242
+ | **tier-1-commands** | scan, impact, partition, debug, execute, visualize | Major rewrites of analysis logic to use graph queries |
243
+ | **tier-2-commands** | qa, wave, integrate, verify, gap-analysis | Add graph-enhanced validation steps |
244
+ | **tier-3-commands** | quick, plan, test-sync, complete-milestone, status, feature | Add graph checks where beneficial |
245
+ | **tier-4-commands** | promote-debt, populate, init-scan-setup | Light graph enrichment |
246
+
247
+ **Exit Criteria**:
248
+ - All 21 commands use graph when available, fall back gracefully when not
249
+ - Scan on GSD-T itself produces higher-quality findings than grep-only scan
250
+ - No command breaks when graph is unavailable (grep fallback works)
251
+ - Pre-Commit Gate updated with graph-related checks
252
+ - All 4 reference docs updated (README, GSD-T-README, CLAUDE-global, gsd-t-help)
253
+
254
+ **Validation Gate**: After M21 completes, run `gsd-t-scan` on GSD-T itself. Compare findings to prior scan results. Graph-powered scan must find issues that grep-only scan missed.
255
+
256
+ ---
257
+
258
+ ## 7. Real-World Scenario: Option B vs Option C per Command
259
+
260
+ For each impacted command, here's how **Option B (native only)** compares to **Option C (native + CGC)**.
261
+
262
+ ### scan
263
+ - **Option B**: Detects direct circular imports, dead exports, naming-convention duplicates. Catches ~80% of structural issues.
264
+ - **Option C**: Adds AST comparison — finds semantically identical functions with different names (copy-paste-rename debt). Catches ~95% of structural issues. Example: `canUserEdit()` in auth-service and `hasEditPermission()` in user-service have identical ASTs. Option B misses this. Option C flags it as a duplication candidate.
265
+
266
+ ### impact
267
+ - **Option B**: Traces 1-level callers and callees. Shows direct consumers of a function. "processPayment is called by paymentHandler and webhookHandler."
268
+ - **Option C**: Traces N-level transitive callers with type flow. Shows full blast radius. "processPayment ← paymentHandler ← checkout ← [web-frontend route /checkout, mobile-app PaymentScreen]. The return type PaymentResult flows through all 4 callers — changing its shape breaks 4 consumers across 2 surfaces." Option C shows WHERE the type changes propagate, not just WHO calls the function.
269
+
270
+ ### partition
271
+ - **Option B**: Maps file ownership to domains based on directory structure and import patterns. Good for most cases.
272
+ - **Option C**: Adds cross-language analysis. In a project with a Python backend and JS frontend, Option C maps the REST contract between them. Option B can only see one language at a time.
273
+
274
+ ### debug
275
+ - **Option B**: Traces direct call chain from error location. "Error in stripeClient.charge, called by processPayment."
276
+ - **Option C**: Traces full transitive chain with type flow. "Error in stripeClient.charge. The `amount` parameter is typed as `number` in processPayment but arrives as `string` from webhookHandler.parseBody — type coercion at the boundary caused the Stripe API rejection." Option C identifies the type mismatch root cause, not just the call path.
277
+
278
+ ### execute
279
+ - **Option B**: Checks domain file ownership. "This task modified auth-service/getUser.ts which belongs to the auth domain, not the payments domain."
280
+ - **Option C**: Also checks for indirect boundary violations via shared imports. "This task didn't modify auth-service files directly, but it changed the type signature of SharedTypes.UserRole which is imported by 3 auth-service functions." Option C catches ripple effects through shared types.
281
+
282
+ ### visualize
283
+ - **Option B**: Renders domain-to-function ownership graphs and direct call chains. Useful for understanding "what's in each domain."
284
+ - **Option C**: Renders full transitive dependency trees with type flow annotations and cross-language edges. Useful for understanding "how does data flow through the entire system."
285
+
286
+ ### qa
287
+ - **Option B**: Maps contracts to test files by naming convention and direct imports. Finds contracts without test coverage.
288
+ - **Option C**: Maps contracts to test files through transitive call chains. Finds contracts that have tests but those tests don't exercise the actual contract path — they test a helper function that happens to be in the same file. False coverage detection.
289
+
290
+ ### wave
291
+ - **Option B**: Validates partition boundaries against file ownership between phases.
292
+ - **Option C**: Also validates that no transitive dependencies cross partition boundaries. A function might be in the right domain folder but import a utility that imports a function from another domain — indirect boundary violation.
293
+
294
+ ### integrate
295
+ - **Option B**: Checks that cross-domain calls match contract specs at the direct call level.
296
+ - **Option C**: Checks type compatibility across the integration boundary. "Domain A's `createOrder()` returns `OrderResponse` but domain B's consumer expects `OrderResult` — structurally similar but field `totalAmount` is named `total` in domain B's type. Integration will fail at runtime."
297
+
298
+ ### verify
299
+ - **Option B**: Maps requirements to code entities. "REQ-012 is implemented by processPayment."
300
+ - **Option C**: Maps requirements through the full call chain. "REQ-012 (Payment Processing) is implemented by processPayment → stripeClient.charge → [external API]. The requirement says 'retry on failure' but the call chain has no retry logic — requirement partially implemented."
301
+
302
+ ### gap-analysis
303
+ - **Option B**: Matches REQ-IDs to function names and file paths. Finds unmapped requirements.
304
+ - **Option C**: Traces requirement implementation depth. "REQ-015 (Notification Delivery) maps to sendNotification(), but sendNotification() calls emailProvider.send() which has a TODO comment and returns a hardcoded `true`. The requirement is mapped but not meaningfully implemented."
305
+
306
+ ### quick
307
+ - **Option B**: Checks if the task's target file belongs to the expected domain.
308
+ - **Option C**: Also checks if the change would affect functions consumed by other domains via shared imports. "This quick fix changes `formatCurrency()` in utils/ — 7 functions across 3 domains import it. Run impact first."
309
+
310
+ ### plan
311
+ - **Option B**: Detects when two tasks in different domains create functions with the same name.
312
+ - **Option C**: Detects when two tasks create functions with the same AST structure (semantic duplication across domains, not just name collision).
313
+
314
+ ### test-sync
315
+ - **Option B**: Maps test files to source files by naming convention. Finds tests for deleted/renamed functions.
316
+ - **Option C**: Maps tests through transitive imports. Finds tests that import a helper that imports the tested function — when the tested function changes, these indirect tests may also need updating. Option B only catches direct test-to-source mapping.
317
+
318
+ ### complete-milestone
319
+ - **Option B**: Lists functions created/modified during the milestone based on git diff + domain scope.
320
+ - **Option C**: Validates that all functions listed in the milestone scope are reachable from at least one entry point. Catches "implemented but unwired" functions that pass all tests individually but are never called in the actual application.
321
+
322
+ ### status
323
+ - **Option B**: Shows domain progress as % of tasks complete.
324
+ - **Option C**: Adds code coverage depth: "payments domain: 8/10 tasks complete, 23 functions implemented, 3 unreachable from any entry point, 2 with no test coverage."
325
+
326
+ ### feature
327
+ - **Option B**: Calculates blast radius based on file count per domain.
328
+ - **Option C**: Calculates blast radius based on transitive call chains across surfaces. "Adding recurring payments affects 12 functions across 3 domains, consumed by 2 surfaces. Estimated 6 contract updates needed."
329
+
330
+ ### promote-debt
331
+ - **Option B**: Shows debt item and its file location.
332
+ - **Option C**: Shows debt item's impact radius. "TD-042 (no error handling in stripeClient.charge) is called by 4 functions, consumed by 2 surfaces, affects 3 contracts. High priority — promotes to milestone."
333
+
334
+ ### populate
335
+ - **Option B**: Auto-fills architecture.md with domain structure and file listings.
336
+ - **Option C**: Auto-fills architecture.md with actual component relationships, call chains, and data flow diagrams generated from the graph.
337
+
338
+ ### init-scan-setup
339
+ - **Option B**: Scan phase uses native graph for initial analysis.
340
+ - **Option C**: Scan phase uses full CGC analysis for comprehensive initial codebase assessment.
341
+
342
+ ---
343
+
344
+ ## 8. Non-Goals
345
+
346
+ - **Replacing grep entirely** — grep remains the universal fallback
347
+ - **Building a Tree-sitter parser** — that's CGC's job; the native indexer uses regex
348
+ - **Supporting all programming languages** — M20 targets JS/TS/Python; others added by demand
349
+ - **Real-time indexing** — indexing is triggered on-demand by commands, not via file watchers
350
+ - **Graph visualization in terminal** — visualization is via the existing dashboard (gsd-t-visualize)
351
+ - **LLM-powered code analysis** — the graph is deterministic; LLM interprets graph results
352
+
353
+ ---
354
+
355
+ ## 9. Risks and Mitigations
356
+
357
+ | Risk | Likelihood | Impact | Mitigation |
358
+ |------|-----------|--------|------------|
359
+ | Regex parser misses edge cases in complex JS/TS | Medium | Medium | Fallback to CGC for complex analysis; native parser covers common patterns |
360
+ | CGC project abandoned (single maintainer, alpha) | Medium | Low | Graph abstraction layer means CGC is swappable; native graph covers 80% |
361
+ | Graph storage grows large on big projects | Low | Medium | Incremental indexing + file hash deduplication; graph files are git-ignored |
362
+ | Performance impact on command startup | Medium | Medium | Lazy loading — graph only queried when command needs it; index check is O(1) via meta.json |
363
+ | Breaking change in CGC MCP protocol | Medium | Low | Provider adapter isolates protocol changes; only cgc-provider.js needs updating |
364
+
365
+ ---
366
+
367
+ ## 10. Success Metrics
368
+
369
+ | Metric | Target |
370
+ |--------|--------|
371
+ | Commands using graph | 21 of 46 |
372
+ | Scan finding improvement vs grep-only | ≥30% more issues found |
373
+ | Impact blast radius accuracy | 100% of transitive callers identified (vs ~40% with grep) |
374
+ | Indexing time for 10K-line project | < 5 seconds (native), < 15 seconds (CGC) |
375
+ | Zero-dep principle maintained | Native indexer: 0 external deps. CGC: optional external dep. |
376
+ | Fallback reliability | 100% — every command works without graph |
377
+
378
+ ---
379
+
380
+ ## 11. Dependencies
381
+
382
+ | Dependency | Type | Risk |
383
+ |-----------|------|------|
384
+ | CodeGraphContext MCP server | Optional external | Alpha maturity; mitigated by abstraction layer |
385
+ | Node.js >= 16 | Required (existing) | Already a GSD-T requirement |
386
+ | `.gsd-t/` directory structure | Required (existing) | Already established |
387
+ | Claude Code slash command system | Required (existing) | Already established |
388
+
389
+ ---
390
+
391
+ ## 12. Timeline
392
+
393
+ | Milestone | Estimated Effort | Sequence |
394
+ |-----------|-----------------|----------|
395
+ | M20: Graph Abstraction + Indexer + CGC | 3-4 domains, medium complexity | First |
396
+ | M21: Graph-Powered Commands | 4 domains (by tier), high complexity | Second |
397
+ | Validation: Scan GSD-T itself | 1 scan run + comparison | After M21 |
398
+ | Then → GSD 2 milestones (M22+) | See PRD-GSD2-001 | After validation |