@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,399 +1,506 @@
1
- # GSD-T: Debug — Systematic Debugging with Contract Awareness
2
-
3
- You are debugging an issue in a contract-driven project. Your approach should identify whether the bug is within a domain or at a contract boundary.
4
-
5
- ## Step 0: Launch via Subagent
6
-
7
- To give this debug session a fresh context window and prevent compaction, always execute via a Task subagent.
8
-
9
- **If you are the orchestrating agent** (you received the slash command directly):
10
-
11
- **Stack Rules Detection (before spawning subagent):**
12
-
13
- Run via Bash to detect project stack and collect matching rules. Local overrides in `.gsd-t/stacks/` take precedence over global templates.
14
-
15
- ```bash
16
- GSD_T_DIR=$(npm root -g 2>/dev/null)/@tekyzinc/gsd-t
17
- STACKS_DIR="$GSD_T_DIR/templates/stacks"
18
- LOCAL_STACKS=".gsd-t/stacks"
19
- STACK_RULES=""
20
- _sf() { local n=$(basename "$1"); [ -f "$LOCAL_STACKS/$n" ] && cat "$LOCAL_STACKS/$n" || cat "$1"; }
21
- _add() { [ -f "$STACKS_DIR/$1" ] && STACK_RULES="${STACK_RULES}$(_sf "$STACKS_DIR/$1")"$'\n\n'; }
22
- if [ -d "$STACKS_DIR" ]; then
23
- for f in "$STACKS_DIR"/_*.md; do [ -f "$f" ] && STACK_RULES="${STACK_RULES}$(_sf "$f")"$'\n\n'; done
24
- if [ -f "package.json" ]; then
25
- grep -q '"react-native"' package.json 2>/dev/null && _add react-native.md
26
- grep -q '"react"' package.json 2>/dev/null && ! grep -q '"react-native"' package.json 2>/dev/null && _add react.md
27
- grep -q '"next"' package.json 2>/dev/null && _add nextjs.md
28
- grep -q '"vue"' package.json 2>/dev/null && _add vue.md
29
- (grep -q '"typescript"' package.json 2>/dev/null || [ -f "tsconfig.json" ]) && _add typescript.md
30
- grep -qE '"(express|fastify|hono|koa)"' package.json 2>/dev/null && _add node-api.md && _add rest-api.md
31
- grep -q '"tailwindcss"' package.json 2>/dev/null && _add tailwind.md
32
- grep -q '"vite"' package.json 2>/dev/null && _add vite.md
33
- grep -q '"@supabase/supabase-js"' package.json 2>/dev/null && _add supabase.md
34
- grep -q '"firebase"' package.json 2>/dev/null && _add firebase.md
35
- grep -qE '"(graphql|@apollo/client|urql)"' package.json 2>/dev/null && _add graphql.md
36
- grep -q '"zustand"' package.json 2>/dev/null && _add zustand.md
37
- grep -q '"@reduxjs/toolkit"' package.json 2>/dev/null && _add redux.md
38
- grep -q '"neo4j-driver"' package.json 2>/dev/null && _add neo4j.md
39
- grep -qE '"(pg|prisma|drizzle-orm|knex)"' package.json 2>/dev/null && _add postgresql.md
40
- grep -qE '"(prisma|@prisma/client)"' package.json 2>/dev/null && _add prisma.md
41
- grep -qE '"(bullmq|bull|amqplib|@aws-sdk/client-sqs|bee-queue|agenda)"' package.json 2>/dev/null && _add queues.md
42
- grep -qE '"(openai|anthropic|@anthropic-ai/sdk|langchain|llama-index|@google/generative-ai)"' package.json 2>/dev/null && _add llm.md
43
- fi
44
- ([ -f "requirements.txt" ] || [ -f "pyproject.toml" ] || [ -f "Pipfile" ]) && _add python.md
45
- ([ -f "requirements.txt" ] && grep -q "psycopg" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -q "psycopg" pyproject.toml 2>/dev/null) && _add postgresql.md
46
- ([ -f "requirements.txt" ] && grep -q "neo4j" requirements.txt 2>/dev/null) && _add neo4j.md
47
- ([ -f "requirements.txt" ] && grep -q "fastapi" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -q "fastapi" pyproject.toml 2>/dev/null) && _add fastapi.md
48
- ([ -f "requirements.txt" ] && grep -qE "(celery|dramatiq|rq|arq)" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -qE "(celery|dramatiq|rq|arq)" pyproject.toml 2>/dev/null) && _add queues.md
49
- ([ -f "requirements.txt" ] && grep -qE "(openai|anthropic|langchain|llama.index)" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -qE "(openai|anthropic|langchain|llama.index)" pyproject.toml 2>/dev/null) && _add llm.md
50
- [ -f "pubspec.yaml" ] && _add flutter.md
51
- [ -f "Dockerfile" ] && _add docker.md
52
- [ -d ".github/workflows" ] && _add github-actions.md
53
- ([ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]) && _add playwright.md
54
- [ -f "go.mod" ] && _add go.md
55
- [ -f "Cargo.toml" ] && _add rust.md
56
- fi
57
- ```
58
-
59
- If STACK_RULES is non-empty, append to the subagent prompt:
60
- ```
61
- ## Stack Rules (MANDATORY — violations fail this task)
62
-
63
- {STACK_RULES}
64
-
65
- These standards have the same enforcement weight as contract compliance.
66
- Violations are task failures, not warnings.
67
- ```
68
-
69
- If STACK_RULES is empty (no templates/stacks/ dir or no matches), skip silently.
70
-
71
- **OBSERVABILITY LOGGING (MANDATORY):**
72
- Before spawning — run via Bash:
73
- `T_START=$(date +%s) && DT_START=$(date +"%Y-%m-%d %H:%M") && TOK_START=${CLAUDE_CONTEXT_TOKENS_USED:-0} && TOK_MAX=${CLAUDE_CONTEXT_TOKENS_MAX:-200000}`
74
-
75
- Spawn a fresh subagent using the Task tool:
76
- ```
77
- subagent_type: general-purpose
78
- prompt: "You are running gsd-t-debug for this issue: {$ARGUMENTS}
79
- Working directory: {current project root}
80
- Read CLAUDE.md and .gsd-t/progress.md for project context, then execute gsd-t-debug starting at Step 1."
81
- ```
82
-
83
- After subagent returns — run via Bash:
84
- `T_END=$(date +%s) && DT_END=$(date +"%Y-%m-%d %H:%M") && TOK_END=${CLAUDE_CONTEXT_TOKENS_USED:-0} && DURATION=$((T_END-T_START))`
85
- Compute tokens and compaction:
86
- - No compaction (TOK_END >= TOK_START): `TOKENS=$((TOK_END-TOK_START))`, COMPACTED=null
87
- - Compaction detected (TOK_END < TOK_START): `TOKENS=$(((TOK_MAX-TOK_START)+TOK_END))`, COMPACTED=$DT_END
88
- Append to `.gsd-t/token-log.md` (create with header `| Datetime-start | Datetime-end | Command | Step | Model | Duration(s) | Notes | Tokens | Compacted |` if missing):
89
- `| {DT_START} | {DT_END} | gsd-t-debug | Step 0 | sonnet | {DURATION}s | debug: {issue summary} | {TOKENS} | {COMPACTED} |`
90
-
91
- Relay the subagent's summary to the user. **Do not execute Steps 1–5 yourself.**
92
-
93
- **If you are the spawned subagent** (your prompt says "starting at Step 1"):
94
- Continue to Step 1 below.
95
-
96
- ## Step 1: Load Context
97
-
98
- Read:
99
- 1. `CLAUDE.md`
100
- 2. `.gsd-t/progress.md`
101
- 3. `.gsd-t/contracts/` — all contracts
102
- 4. `.gsd-t/domains/*/scope.md` — domain boundaries
103
-
104
- ## Step 1.5: Debug Loop Detection (MANDATORY)
105
-
106
- Before attempting any fix, check whether this issue has been through multiple failed debug sessions. This prevents the 10–20 attempt death spiral that happens when the same approach is retried repeatedly.
107
-
108
- **Detection:**
109
- 1. Scan `.gsd-t/progress.md` Decision Log for `[debug]` entries related to this issue (match by keyword, error name, or component)
110
- 2. Count distinct debug sessions that attempted to fix this issue
111
- 3. Check `.gsd-t/deferred-items.md` for any entries matching this issue
112
-
113
- **If 3 or more prior sessions found → Enter Deep Research Mode (below). Do NOT attempt another fix with the same approach.**
114
-
115
- **If fewer than 3 sessions → Proceed to Step 2 normally.**
116
-
117
- ---
118
-
119
- ### Deep Research Mode (triggered when debug loop detected)
120
-
121
- The current approach has failed 3+ times. This means the root cause is not yet understood. A different strategy — possibly a fundamentally different technical approach — is required.
122
-
123
- **OBSERVABILITY LOGGING (MANDATORY):**
124
- Before spawning — run via Bash:
125
- `T_START=$(date +%s) && DT_START=$(date +"%Y-%m-%d %H:%M") && TOK_START=${CLAUDE_CONTEXT_TOKENS_USED:-0} && TOK_MAX=${CLAUDE_CONTEXT_TOKENS_MAX:-200000}`
126
-
127
- ```
128
- Spawn a deep research team (run all three in parallel):
129
-
130
- - Teammate "researcher-root-cause": Take the broadest possible look at
131
- the problem. Ignore prior fix attempts. Read the full component,
132
- its dependencies, contracts, and all error traces from scratch.
133
- What is the actual root cause — not the symptom? Consider that the
134
- real issue may be architectural, not in the code being patched.
135
-
136
- - Teammate "researcher-alternatives": Enumerate 3–5 fundamentally
137
- different ways to solve this problem. Include approaches that would
138
- require refactoring or changing the technical direction entirely.
139
- For each: what are the trade-offs, effort, and risk?
140
-
141
- - Teammate "researcher-prior-art": Search external sources, docs,
142
- GitHub issues, and known patterns for this class of bug. Has this
143
- problem been documented elsewhere? What did others find? Are there
144
- framework-specific pitfalls or known workarounds?
145
-
146
- Lead: Wait for all three researchers to complete. Then synthesize:
147
- 1. What is the true root cause based on full investigation?
148
- 2. What are the viable solution paths (ranked by confidence)?
149
- 3. Does any path require a different technical approach than what has been tried?
150
- 4. What is the recommended path and why?
151
- ```
152
-
153
- After team completes — run via Bash:
154
- `T_END=$(date +%s) && DT_END=$(date +"%Y-%m-%d %H:%M") && TOK_END=${CLAUDE_CONTEXT_TOKENS_USED:-0} && DURATION=$((T_END-T_START))`
155
- Compute tokens and compaction:
156
- - No compaction (TOK_END >= TOK_START): `TOKENS=$((TOK_END-TOK_START))`, COMPACTED=null
157
- - Compaction detected (TOK_END < TOK_START): `TOKENS=$(((TOK_MAX-TOK_START)+TOK_END))`, COMPACTED=$DT_END
158
- Append to `.gsd-t/token-log.md`:
159
- `| {DT_START} | {DT_END} | gsd-t-debug | Step 1.5 | sonnet | {DURATION}s | deep research loop break: {issue summary} | {TOKENS} | {COMPACTED} |`
160
-
161
- **STOP. Present findings to the user before making any changes:**
162
-
163
- ```
164
- ## Debug Loop Break — Research Findings
165
-
166
- **Issue**: {issue summary}
167
- **Prior sessions**: {count} failed attempts
168
-
169
- **Root Cause (revised)**: {finding from researcher-root-cause}
170
-
171
- **Solution Options**:
172
- | # | Approach | Effort | Risk | Notes |
173
- |---|----------|--------|------|-------|
174
- | 1 | {option} | {effort} | {risk} | {notes} |
175
- | 2 | {option} | {effort} | {risk} | {notes} |
176
- | 3 | {option} | {effort} | {risk} | {notes} |
177
-
178
- **Recommendation**: {recommended option and rationale}
179
-
180
- **Does this require a different technical direction?** {Yes/No — explain}
181
-
182
- Please select an option (or provide your own direction) before I proceed.
183
- ```
184
-
185
- **Wait for explicit user selection/approval.** Do NOT proceed with any fix until the user confirms the chosen approach. If the recommendation requires refactoring or changing technical direction, the Destructive Action Guard applies — present the full migration path and wait for approval.
186
-
187
- ---
188
-
189
- ## Step 1.7: Experience Retrieval
190
-
191
- Before proceeding to classification and fix, retrieve relevant past failures from the Decision Log.
192
-
193
- Run via Bash:
194
- `grep -i "\[failure\]\|\[learning\]" .gsd-t/progress.md | tail -10`
195
-
196
- If results found:
197
- - Display a `## ⚠️ Relevant Past Failures` block showing matching entries (max 5 lines)
198
- - Pass this block as context to any debug subagent spawned in Step 3
199
- - Write event via Bash: `node ~/.claude/scripts/gsd-t-event-writer.js --type experience_retrieval --command gsd-t-debug --reasoning "{N entries found}" --outcome null || true`
200
-
201
- If no results found: proceed normally to Step 2.
202
-
203
- ---
204
-
205
- ## Step 1.7: Graph-Enhanced Root Cause Tracing (if available)
206
-
207
- If `.gsd-t/graph/meta.json` exists, use the graph to accelerate root cause identification:
208
-
209
- 1. **Call chain from error**: `query('getCallers', { entity: '{error_function}' })` → trace backward from the error location
210
- 2. **Transitive callers**: `query('getTransitiveCallers', { entity: '{name}', depth: 5 })` → find the full path from entry point to error
211
- 3. **Domain ownership**: `query('getDomainOwner', { entity: '{name}' })` → immediately classify as within-domain or boundary bug
212
- 4. **Contract check**: `query('getContractFor', { entity: '{name}' })` → determine if the bug is at a contract boundary
213
- 5. **Related tests**: `query('getTestsFor', { entity: '{name}' })` → find existing tests that should have caught this
214
-
215
- Graph results replace the manual "classify the bug" analysis in Step 2 — the call chain tells you exactly where the bug type is (within-domain vs boundary) based on whether the caller and callee are in the same domain.
216
-
217
- ## Step 2: Classify the Bug
218
-
219
- Based on the user's description ($ARGUMENTS) and graph analysis (if available), determine:
220
-
221
- ### A) Within-Domain Bug
222
- The issue is entirely inside one domain's scope. Symptoms:
223
- - Error occurs in files owned by a single domain
224
- - No cross-domain data flow involved
225
- - Logic error, typo, missing validation within one area
226
-
227
- → Debug within that domain's files. Fix and verify against domain's acceptance criteria.
228
-
229
- ### B) Contract Boundary Bug
230
- The issue occurs where domains interact. Symptoms:
231
- - Data shape mismatch between producer and consumer
232
- - API returns unexpected format
233
- - UI sends wrong payload to backend
234
- - Auth middleware doesn't integrate correctly with routes
235
-
236
- → Check the relevant contract first. Is the contract correct? Does the implementation match?
237
-
238
- ### C) Contract Gap
239
- The contract didn't specify something it should have. Symptoms:
240
- - Edge case not covered in contract
241
- - Error handling not specified
242
- - Race condition at boundary
243
- - Missing contract entirely
244
-
245
- → Update the contract, then fix implementations on both sides.
246
-
247
- ## Step 2.5: Reproduce First (MANDATORY — Category 5)
248
-
249
- **A fix attempt without a reproduction script is a guess, not a fix.**
250
-
251
- Before touching any code:
252
-
253
- 1. **Write a reproduction script** that demonstrates the bug. Automate as much as possible:
254
- - Unit/integration bug → write a failing test that proves the bug exists
255
- - UI/audio/GPU/worker bug (not fully automatable) → write the closest possible script: a headless probe, a log-based trigger, a mock that replicates the failure path. Document the manual remainder explicitly.
256
- - If you cannot write any form of reproduction → you do not yet understand the bug. Keep investigating until you can.
257
-
258
- 2. **Run the reproduction** and confirm it fails before attempting any fix.
259
-
260
- 3. **Never close a debug session with "ready for testing."** A session closes only when the reproduction script passes. If manual steps remain, document them explicitly and confirm they passed.
261
-
262
- 4. **Log the reproduction script path** in `.gsd-t/progress.md` Decision Log: what it tests, how to run it, what passing looks like.
263
-
264
- > This rule exists because code review cannot detect silent runtime failures (GPU compute shaders, audio context state, worker message drops). Only execution proves correctness.
265
-
266
- ---
267
-
268
- ## Step 3: Debug (Solo or Team)
269
-
270
- ### Deviation Rules
271
-
272
- When you encounter unexpected situations during the fix:
273
- 1. **Related bug found while tracing** → Fix it immediately (up to 3 attempts). Log to `.gsd-t/deferred-items.md` if it recurs.
274
- 2. **Missing functionality required for the fix** → Add minimum needed. Note in commit message.
275
- 3. **Blocker (missing file, wrong API response)** → Fix blocker and continue. Log if non-trivial.
276
- 4. **Architectural change required to fix correctly** → STOP. Explain what exists, what needs to change, what breaks, and a migration path. Wait for user approval. Never self-approve.
277
-
278
- **3-attempt limit**: If your fix doesn't work after 3 attempts within this session, treat it as a loop. Do NOT keep trying the same approach. Before entering Deep Research Mode, first try the headless debug-loop:
279
- 1. Write current failure context to `.gsd-t/debug-state.jsonl` via appendEntry
280
- 2. Log: "Delegating to headless debug-loop (3 in-context attempts exhausted)"
281
- 3. Run: `gsd-t headless --debug-loop --max-iterations 10`
282
- 4. Check exit code:
283
- - 0: Tests pass, continue
284
- - 1/4: Log to `.gsd-t/deferred-items.md`, then enter Deep Research Mode
285
- - 3: Report error, stop
286
-
287
- If the debug-loop also fails (exit 1/4), log the attempt to `.gsd-t/progress.md` Decision Log with a `[failure]` prefix, return to Step 1.5 and run Deep Research Mode before any further attempts. Present findings and options to the user before proceeding.
288
-
289
- ### Solo Mode
290
- 1. Reproduce the issue — **reproduction script must exist before step 2** (see Step 2.5)
291
- 2. Trace through the relevant domain(s)
292
- 3. Check contract compliance at each boundary
293
- 4. Identify root cause
294
- 5. **Destructive Action Guard**: If the fix requires destructive or structural changes (dropping tables, removing columns, changing schema, replacing architecture patterns, removing working modules) → STOP and present the change to the user with what exists, what will change, what will break, and a safe migration path. Wait for explicit approval.
295
- 6. Fix and test — **adapt the fix to existing structures**, not the other way around
296
- 7. Update contracts if needed
297
- 8. **Category 6 — Bug Isolation Check**: After applying the fix, run the FULL test suite and all smoke tests — not just the reproduction script. Do not assume the bug was isolated. A fix that resolves one failure frequently uncovers adjacent failures. Every test must pass before the session closes.
298
-
299
- ### Team Mode (for complex cross-domain bugs)
300
- ```
301
- Create an agent team to debug:
302
- - Teammate 1: Investigate in {domain-1} — check implementation
303
- against contracts, trace data flow
304
- - Teammate 2: Investigate in {domain-2} — check implementation
305
- against contracts, trace data flow
306
- - Teammate 3: Check all contracts for gaps or ambiguities
307
- related to the failing scenario
308
-
309
- First to find root cause: message the lead with findings.
310
- ```
311
-
312
- ## Step 4: Document Ripple
313
-
314
- After fixing, assess what documentation was affected by the change and update ALL relevant files:
315
-
316
- ### Always check:
317
- 1. **`.gsd-t/progress.md`** — Add to Decision Log: what broke, why, and the fix. Prefix the entry with an outcome tag:
318
- - Debug session start → prefix `[debug]`
319
- - Fix succeeded → prefix `[success]`
320
- - Fix failed → prefix `[failure]`
321
- - Issue deferred → prefix `[deferred]`
322
- 2. **`.gsd-t/contracts/`** — Update any contract if the fix changed an interface, schema, or API shape
323
- 3. **Domain `constraints.md`** — Add a "must not" rule if the bug was caused by a pattern that should be avoided
324
-
325
- ### Check if affected:
326
- 4. **`docs/requirements.md`** — Did the fix reveal a missing or incorrect requirement? Update it
327
- 5. **`docs/architecture.md`** — Did the fix change architectural patterns, data flow, or component relationships? Update it
328
- 6. **`docs/schema.md`** — Did the fix modify the database schema? Update it
329
- 7. **`.gsd-t/techdebt.md`** — Did the fix reveal related debt? Add a new TD item. Did it resolve an existing one? Mark it complete
330
- 8. **Domain `scope.md`** — Did the fix add new files or change ownership? Update it
331
- 9. **Domain `tasks.md`** — If the bug was in an active milestone, update task status or add a remediation task
332
- 10. **`CLAUDE.md`** — Did the fix establish a new convention or pattern that future work should follow? Add it
333
-
334
- ### Scan Doc Micro-Update (if `.gsd-t/scan/` exists):
335
- Patch structural metadata in scan docs so they stay fresh between full scans. Near-zero cost — no LLM re-analysis.
336
-
337
- For each scan doc that exists, apply only the relevant patches:
338
- - **`.gsd-t/scan/architecture.md`** — Update file/directory counts if the fix added/removed files
339
- - **`.gsd-t/scan/quality.md`** — Mark resolved TODOs/FIXMEs, update test counts if tests were added
340
- - **`.gsd-t/scan/security.md`** — If the bug was a security issue, mark the finding `[RESOLVED]`
341
- - **`.gsd-t/scan/business-rules.md`** — If the fix changed validation/auth/workflow logic, update the rule
342
- - **`.gsd-t/scan/contract-drift.md`** — If contracts were updated as part of the fix, mark resolved drift items
343
-
344
- Skip scan docs not affected by this fix. Skip analytical sections — those require a full scan.
345
-
346
- ### Skip what's not affected — don't update docs for the sake of updating them.
347
-
348
- ## Step 5: Test Verification (run tests confirming fix)
349
-
350
- Before committing, ensure the fix is solid:
351
-
352
- 1. **Update tests**: If the bug reveals a missing test case, add one that would have caught it
353
- 2. **Run ALL configured test suites** — this is NOT optional:
354
- a. Detect all runners: check for vitest/jest config, playwright.config.*, cypress.config.*
355
- b. Run EVERY detected suite. Unit tests alone are NEVER sufficient when E2E exists.
356
- c. If `playwright.config.*` exists → run `npx playwright test` (full suite)
357
- d. Report ALL results: "Unit: X/Y pass | E2E: X/Y pass"
358
- 3. **Verify passing**: All tests must pass. If any fail, fix before proceeding (up to 2 attempts)
359
- 4. **If the project has a UI but no E2E specs cover the fixed area**: WRITE THEM.
360
- 5. **Functional test quality**: Every E2E assertion must verify an action produced the correct outcome (state changed, data loaded, content updated) — not just that elements exist. Tests that only check `isVisible`/`toBeEnabled` are shallow layout tests and don't catch real bugs. If a test would pass on an empty HTML page with the right IDs, rewrite it.
361
- 6. **Regression check**: Confirm the fix doesn't break any adjacent functionality
362
-
363
- Commit: `[debug] Fix {description} root cause: {explanation}`
364
-
365
- ## Step 5.5: Emit Task Metrics
366
-
367
- After committing, emit a task-metrics record for this debug session run via Bash:
368
- `node bin/metrics-collector.js --milestone {current-milestone-or-none} --domain {domain-or-debug} --task debug-{timestamp} --command debug --duration_s {elapsed} --tokens_used {estimated} --context_pct ${CTX_PCT:-0} --pass {true|false} --fix_cycles {attempts} --signal_type debug-invoked --notes "[debug] {description}" 2>/dev/null || true`
369
-
370
- Signal type is always `debug-invoked` for debug sessions.
371
-
372
- Emit task_complete event run via Bash:
373
- `node ~/.claude/scripts/gsd-t-event-writer.js --type task_complete --command gsd-t-debug --reasoning "signal_type=debug-invoked, domain={domain}" --outcome {success|failure} || true`
374
-
375
- ## Step 6: Doc-Ripple (Automated)
376
-
377
- After all work is committed but before reporting completion:
378
-
379
- 1. Run threshold check read `git diff --name-only HEAD~1` and evaluate against doc-ripple-contract.md trigger conditions
380
- 2. If SKIP: log "Doc-ripple: SKIP — {reason}" and proceed to completion
381
- 3. If FIRE: spawn doc-ripple agent:
382
-
383
- [{model}] gsd-t-doc-ripple → blast radius analysis + parallel updates
384
-
385
- Task subagent (general-purpose, model: sonnet):
386
- "Execute the doc-ripple workflow per commands/gsd-t-doc-ripple.md.
387
- Git diff context: {files changed list}
388
- Command that triggered: debug
389
- Produce manifest at .gsd-t/doc-ripple-manifest.md.
390
- Update all affected documents.
391
- Report: 'Doc-ripple: {N} checked, {N} updated, {N} skipped'"
392
-
393
- 4. After doc-ripple returns, verify manifest exists and report summary inline
394
-
395
- $ARGUMENTS
396
-
397
- ## Auto-Clear
398
-
399
- All work is committed to project files. Execute `/clear` to free the context window for the next command.
1
+ # GSD-T: Debug — Systematic Debugging with Contract Awareness
2
+
3
+ You are debugging an issue in a contract-driven project. Your approach should identify whether the bug is within a domain or at a contract boundary.
4
+
5
+ ## Step 0: Launch via Subagent
6
+
7
+ To give this debug session a fresh context window and prevent compaction, always execute via a Task subagent.
8
+
9
+ **If you are the orchestrating agent** (you received the slash command directly):
10
+
11
+ **Stack Rules Detection (before spawning subagent):**
12
+
13
+ Run via Bash to detect project stack and collect matching rules. Local overrides in `.gsd-t/stacks/` take precedence over global templates.
14
+
15
+ ```bash
16
+ GSD_T_DIR=$(npm root -g 2>/dev/null)/@tekyzinc/gsd-t
17
+ STACKS_DIR="$GSD_T_DIR/templates/stacks"
18
+ LOCAL_STACKS=".gsd-t/stacks"
19
+ STACK_RULES=""
20
+ _sf() { local n=$(basename "$1"); [ -f "$LOCAL_STACKS/$n" ] && cat "$LOCAL_STACKS/$n" || cat "$1"; }
21
+ _add() { [ -f "$STACKS_DIR/$1" ] && STACK_RULES="${STACK_RULES}$(_sf "$STACKS_DIR/$1")"$'\n\n'; }
22
+ if [ -d "$STACKS_DIR" ]; then
23
+ for f in "$STACKS_DIR"/_*.md; do [ -f "$f" ] && STACK_RULES="${STACK_RULES}$(_sf "$f")"$'\n\n'; done
24
+ if [ -f "package.json" ]; then
25
+ grep -q '"react-native"' package.json 2>/dev/null && _add react-native.md
26
+ grep -q '"react"' package.json 2>/dev/null && ! grep -q '"react-native"' package.json 2>/dev/null && _add react.md
27
+ grep -q '"next"' package.json 2>/dev/null && _add nextjs.md
28
+ grep -q '"vue"' package.json 2>/dev/null && _add vue.md
29
+ (grep -q '"typescript"' package.json 2>/dev/null || [ -f "tsconfig.json" ]) && _add typescript.md
30
+ grep -qE '"(express|fastify|hono|koa)"' package.json 2>/dev/null && _add node-api.md && _add rest-api.md
31
+ grep -q '"tailwindcss"' package.json 2>/dev/null && _add tailwind.md
32
+ grep -q '"vite"' package.json 2>/dev/null && _add vite.md
33
+ grep -q '"@supabase/supabase-js"' package.json 2>/dev/null && _add supabase.md
34
+ grep -q '"firebase"' package.json 2>/dev/null && _add firebase.md
35
+ grep -qE '"(graphql|@apollo/client|urql)"' package.json 2>/dev/null && _add graphql.md
36
+ grep -q '"zustand"' package.json 2>/dev/null && _add zustand.md
37
+ grep -q '"@reduxjs/toolkit"' package.json 2>/dev/null && _add redux.md
38
+ grep -q '"neo4j-driver"' package.json 2>/dev/null && _add neo4j.md
39
+ grep -qE '"(pg|prisma|drizzle-orm|knex)"' package.json 2>/dev/null && _add postgresql.md
40
+ grep -qE '"(prisma|@prisma/client)"' package.json 2>/dev/null && _add prisma.md
41
+ grep -qE '"(bullmq|bull|amqplib|@aws-sdk/client-sqs|bee-queue|agenda)"' package.json 2>/dev/null && _add queues.md
42
+ grep -qE '"(openai|anthropic|@anthropic-ai/sdk|langchain|llama-index|@google/generative-ai)"' package.json 2>/dev/null && _add llm.md
43
+ fi
44
+ ([ -f "requirements.txt" ] || [ -f "pyproject.toml" ] || [ -f "Pipfile" ]) && _add python.md
45
+ ([ -f "requirements.txt" ] && grep -q "psycopg" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -q "psycopg" pyproject.toml 2>/dev/null) && _add postgresql.md
46
+ ([ -f "requirements.txt" ] && grep -q "neo4j" requirements.txt 2>/dev/null) && _add neo4j.md
47
+ ([ -f "requirements.txt" ] && grep -q "fastapi" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -q "fastapi" pyproject.toml 2>/dev/null) && _add fastapi.md
48
+ ([ -f "requirements.txt" ] && grep -qE "(celery|dramatiq|rq|arq)" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -qE "(celery|dramatiq|rq|arq)" pyproject.toml 2>/dev/null) && _add queues.md
49
+ ([ -f "requirements.txt" ] && grep -qE "(openai|anthropic|langchain|llama.index)" requirements.txt 2>/dev/null || [ -f "pyproject.toml" ] && grep -qE "(openai|anthropic|langchain|llama.index)" pyproject.toml 2>/dev/null) && _add llm.md
50
+ [ -f "pubspec.yaml" ] && _add flutter.md
51
+ [ -f "Dockerfile" ] && _add docker.md
52
+ [ -d ".github/workflows" ] && _add github-actions.md
53
+ ([ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]) && _add playwright.md
54
+ [ -f "go.mod" ] && _add go.md
55
+ [ -f "Cargo.toml" ] && _add rust.md
56
+ fi
57
+ ```
58
+
59
+ If STACK_RULES is non-empty, append to the subagent prompt:
60
+ ```
61
+ ## Stack Rules (MANDATORY — violations fail this task)
62
+
63
+ {STACK_RULES}
64
+
65
+ These standards have the same enforcement weight as contract compliance.
66
+ Violations are task failures, not warnings.
67
+ ```
68
+
69
+ If STACK_RULES is empty (no templates/stacks/ dir or no matches), skip silently.
70
+
71
+ **OBSERVABILITY LOGGING (MANDATORY):**
72
+ Before spawning — run via Bash:
73
+ `T_START=$(date +%s) && DT_START=$(date +"%Y-%m-%d %H:%M") && TOK_START=${CLAUDE_CONTEXT_TOKENS_USED:-0} && TOK_MAX=${CLAUDE_CONTEXT_TOKENS_MAX:-200000}`
74
+
75
+ Spawn a fresh subagent using the Task tool:
76
+ ```
77
+ subagent_type: general-purpose
78
+ prompt: "You are running gsd-t-debug for this issue: {$ARGUMENTS}
79
+ Working directory: {current project root}
80
+ Read CLAUDE.md and .gsd-t/progress.md for project context, then execute gsd-t-debug starting at Step 1."
81
+ ```
82
+
83
+ After subagent returns — run via Bash:
84
+ `T_END=$(date +%s) && DT_END=$(date +"%Y-%m-%d %H:%M") && TOK_END=${CLAUDE_CONTEXT_TOKENS_USED:-0} && DURATION=$((T_END-T_START))`
85
+ Compute tokens and compaction:
86
+ - No compaction (TOK_END >= TOK_START): `TOKENS=$((TOK_END-TOK_START))`, COMPACTED=null
87
+ - Compaction detected (TOK_END < TOK_START): `TOKENS=$(((TOK_MAX-TOK_START)+TOK_END))`, COMPACTED=$DT_END
88
+ Append to `.gsd-t/token-log.md` (create with header `| Datetime-start | Datetime-end | Command | Step | Model | Duration(s) | Notes | Tokens | Compacted |` if missing):
89
+ `| {DT_START} | {DT_END} | gsd-t-debug | Step 0 | sonnet | {DURATION}s | debug: {issue summary} | {TOKENS} | {COMPACTED} |`
90
+
91
+ Relay the subagent's summary to the user. **Do not execute Steps 1–5 yourself.**
92
+
93
+ **If you are the spawned subagent** (your prompt says "starting at Step 1"):
94
+ Continue to Step 1 below.
95
+
96
+ ## Step 1: Load Context
97
+
98
+ Read:
99
+ 1. `CLAUDE.md`
100
+ 2. `.gsd-t/progress.md`
101
+ 3. `.gsd-t/contracts/` — all contracts
102
+ 4. `.gsd-t/domains/*/scope.md` — domain boundaries
103
+
104
+ ## Step 1.5: Debug Loop Detection (MANDATORY)
105
+
106
+ Before attempting any fix, check whether this issue has been through multiple failed debug sessions. This prevents the 10–20 attempt death spiral that happens when the same approach is retried repeatedly.
107
+
108
+ **Detection:**
109
+ 1. Scan `.gsd-t/progress.md` Decision Log for `[debug]` entries related to this issue (match by keyword, error name, or component)
110
+ 2. Count distinct debug sessions that attempted to fix this issue
111
+ 3. Check `.gsd-t/deferred-items.md` for any entries matching this issue
112
+
113
+ **If 3 or more prior sessions found → Enter Deep Research Mode (below). Do NOT attempt another fix with the same approach.**
114
+
115
+ **If fewer than 3 sessions → Proceed to Step 2 normally.**
116
+
117
+ ---
118
+
119
+ ### Deep Research Mode (triggered when debug loop detected)
120
+
121
+ The current approach has failed 3+ times. This means the root cause is not yet understood. A different strategy — possibly a fundamentally different technical approach — is required.
122
+
123
+ **OBSERVABILITY LOGGING (MANDATORY):**
124
+ Before spawning — run via Bash:
125
+ `T_START=$(date +%s) && DT_START=$(date +"%Y-%m-%d %H:%M") && TOK_START=${CLAUDE_CONTEXT_TOKENS_USED:-0} && TOK_MAX=${CLAUDE_CONTEXT_TOKENS_MAX:-200000}`
126
+
127
+ ```
128
+ Spawn a deep research team (run all three in parallel):
129
+
130
+ - Teammate "researcher-root-cause": Take the broadest possible look at
131
+ the problem. Ignore prior fix attempts. Read the full component,
132
+ its dependencies, contracts, and all error traces from scratch.
133
+ What is the actual root cause — not the symptom? Consider that the
134
+ real issue may be architectural, not in the code being patched.
135
+
136
+ - Teammate "researcher-alternatives": Enumerate 3–5 fundamentally
137
+ different ways to solve this problem. Include approaches that would
138
+ require refactoring or changing the technical direction entirely.
139
+ For each: what are the trade-offs, effort, and risk?
140
+
141
+ - Teammate "researcher-prior-art": Search external sources, docs,
142
+ GitHub issues, and known patterns for this class of bug. Has this
143
+ problem been documented elsewhere? What did others find? Are there
144
+ framework-specific pitfalls or known workarounds?
145
+
146
+ Lead: Wait for all three researchers to complete. Then synthesize:
147
+ 1. What is the true root cause based on full investigation?
148
+ 2. What are the viable solution paths (ranked by confidence)?
149
+ 3. Does any path require a different technical approach than what has been tried?
150
+ 4. What is the recommended path and why?
151
+ ```
152
+
153
+ After team completes — run via Bash:
154
+ `T_END=$(date +%s) && DT_END=$(date +"%Y-%m-%d %H:%M") && TOK_END=${CLAUDE_CONTEXT_TOKENS_USED:-0} && DURATION=$((T_END-T_START))`
155
+ Compute tokens and compaction:
156
+ - No compaction (TOK_END >= TOK_START): `TOKENS=$((TOK_END-TOK_START))`, COMPACTED=null
157
+ - Compaction detected (TOK_END < TOK_START): `TOKENS=$(((TOK_MAX-TOK_START)+TOK_END))`, COMPACTED=$DT_END
158
+ Append to `.gsd-t/token-log.md`:
159
+ `| {DT_START} | {DT_END} | gsd-t-debug | Step 1.5 | sonnet | {DURATION}s | deep research loop break: {issue summary} | {TOKENS} | {COMPACTED} |`
160
+
161
+ **STOP. Present findings to the user before making any changes:**
162
+
163
+ ```
164
+ ## Debug Loop Break — Research Findings
165
+
166
+ **Issue**: {issue summary}
167
+ **Prior sessions**: {count} failed attempts
168
+
169
+ **Root Cause (revised)**: {finding from researcher-root-cause}
170
+
171
+ **Solution Options**:
172
+ | # | Approach | Effort | Risk | Notes |
173
+ |---|----------|--------|------|-------|
174
+ | 1 | {option} | {effort} | {risk} | {notes} |
175
+ | 2 | {option} | {effort} | {risk} | {notes} |
176
+ | 3 | {option} | {effort} | {risk} | {notes} |
177
+
178
+ **Recommendation**: {recommended option and rationale}
179
+
180
+ **Does this require a different technical direction?** {Yes/No — explain}
181
+
182
+ Please select an option (or provide your own direction) before I proceed.
183
+ ```
184
+
185
+ **Wait for explicit user selection/approval.** Do NOT proceed with any fix until the user confirms the chosen approach. If the recommendation requires refactoring or changing technical direction, the Destructive Action Guard applies — present the full migration path and wait for approval.
186
+
187
+ ---
188
+
189
+ ## Step 1.7: Experience Retrieval
190
+
191
+ Before proceeding to classification and fix, retrieve relevant past failures from the Decision Log.
192
+
193
+ Run via Bash:
194
+ `grep -i "\[failure\]\|\[learning\]" .gsd-t/progress.md | tail -10`
195
+
196
+ If results found:
197
+ - Display a `## ⚠️ Relevant Past Failures` block showing matching entries (max 5 lines)
198
+ - Pass this block as context to any debug subagent spawned in Step 3
199
+ - Write event via Bash: `node ~/.claude/scripts/gsd-t-event-writer.js --type experience_retrieval --command gsd-t-debug --reasoning "{N entries found}" --outcome null || true`
200
+
201
+ If no results found: proceed normally to Step 2.
202
+
203
+ ---
204
+
205
+ ## Step 1.7: Graph-Enhanced Root Cause Tracing (if available)
206
+
207
+ If `.gsd-t/graph/meta.json` exists, use the graph to accelerate root cause identification:
208
+
209
+ 1. **Call chain from error**: `query('getCallers', { entity: '{error_function}' })` → trace backward from the error location
210
+ 2. **Transitive callers**: `query('getTransitiveCallers', { entity: '{name}', depth: 5 })` → find the full path from entry point to error
211
+ 3. **Domain ownership**: `query('getDomainOwner', { entity: '{name}' })` → immediately classify as within-domain or boundary bug
212
+ 4. **Contract check**: `query('getContractFor', { entity: '{name}' })` → determine if the bug is at a contract boundary
213
+ 5. **Related tests**: `query('getTestsFor', { entity: '{name}' })` → find existing tests that should have caught this
214
+
215
+ Graph results replace the manual "classify the bug" analysis in Step 2 — the call chain tells you exactly where the bug type is (within-domain vs boundary) based on whether the caller and callee are in the same domain.
216
+
217
+ ## Step 2: Classify the Bug
218
+
219
+ Based on the user's description ($ARGUMENTS) and graph analysis (if available), determine:
220
+
221
+ ### A) Within-Domain Bug
222
+ The issue is entirely inside one domain's scope. Symptoms:
223
+ - Error occurs in files owned by a single domain
224
+ - No cross-domain data flow involved
225
+ - Logic error, typo, missing validation within one area
226
+
227
+ → Debug within that domain's files. Fix and verify against domain's acceptance criteria.
228
+
229
+ ### B) Contract Boundary Bug
230
+ The issue occurs where domains interact. Symptoms:
231
+ - Data shape mismatch between producer and consumer
232
+ - API returns unexpected format
233
+ - UI sends wrong payload to backend
234
+ - Auth middleware doesn't integrate correctly with routes
235
+
236
+ → Check the relevant contract first. Is the contract correct? Does the implementation match?
237
+
238
+ ### C) Contract Gap
239
+ The contract didn't specify something it should have. Symptoms:
240
+ - Edge case not covered in contract
241
+ - Error handling not specified
242
+ - Race condition at boundary
243
+ - Missing contract entirely
244
+
245
+ → Update the contract, then fix implementations on both sides.
246
+
247
+ ## Step 2.5: Reproduce First (MANDATORY — Category 5)
248
+
249
+ **A fix attempt without a reproduction script is a guess, not a fix.**
250
+
251
+ Before touching any code:
252
+
253
+ 1. **Write a reproduction script** that demonstrates the bug. Automate as much as possible:
254
+ - Unit/integration bug → write a failing test that proves the bug exists
255
+ - UI/audio/GPU/worker bug (not fully automatable) → write the closest possible script: a headless probe, a log-based trigger, a mock that replicates the failure path. Document the manual remainder explicitly.
256
+ - If you cannot write any form of reproduction → you do not yet understand the bug. Keep investigating until you can.
257
+
258
+ 2. **Run the reproduction** and confirm it fails before attempting any fix.
259
+
260
+ 3. **Never close a debug session with "ready for testing."** A session closes only when the reproduction script passes. If manual steps remain, document them explicitly and confirm they passed.
261
+
262
+ 4. **Log the reproduction script path** in `.gsd-t/progress.md` Decision Log: what it tests, how to run it, what passing looks like.
263
+
264
+ > This rule exists because code review cannot detect silent runtime failures (GPU compute shaders, audio context state, worker message drops). Only execution proves correctness.
265
+
266
+ ---
267
+
268
+ ## Step 3: Debug (Solo or Team)
269
+
270
+ ### Deviation Rules
271
+
272
+ When you encounter unexpected situations during the fix:
273
+ 1. **Related bug found while tracing** → Fix it immediately (up to 3 attempts). Log to `.gsd-t/deferred-items.md` if it recurs.
274
+ 2. **Missing functionality required for the fix** → Add minimum needed. Note in commit message.
275
+ 3. **Blocker (missing file, wrong API response)** → Fix blocker and continue. Log if non-trivial.
276
+ 4. **Architectural change required to fix correctly** → STOP. Explain what exists, what needs to change, what breaks, and a migration path. Wait for user approval. Never self-approve.
277
+
278
+ **3-attempt limit**: If your fix doesn't work after 3 attempts within this session, treat it as a loop. Do NOT keep trying the same approach. Before entering Deep Research Mode, first try the headless debug-loop:
279
+ 1. Write current failure context to `.gsd-t/debug-state.jsonl` via appendEntry
280
+ 2. Log: "Delegating to headless debug-loop (3 in-context attempts exhausted)"
281
+ 3. Run: `gsd-t headless --debug-loop --max-iterations 10`
282
+ 4. Check exit code:
283
+ - 0: Tests pass, continue
284
+ - 1/4: Log to `.gsd-t/deferred-items.md`, then enter Deep Research Mode
285
+ - 3: Report error, stop
286
+
287
+ If the debug-loop also fails (exit 1/4), log the attempt to `.gsd-t/progress.md` Decision Log with a `[failure]` prefix, return to Step 1.5 and run Deep Research Mode before any further attempts. Present findings and options to the user before proceeding.
288
+
289
+ ### Solo Mode
290
+ 1. Reproduce the issue — **reproduction script must exist before step 2** (see Step 2.5)
291
+ 2. Trace through the relevant domain(s)
292
+ 3. Check contract compliance at each boundary
293
+ 4. Identify root cause
294
+ 5. **Destructive Action Guard**: If the fix requires destructive or structural changes (dropping tables, removing columns, changing schema, replacing architecture patterns, removing working modules) → STOP and present the change to the user with what exists, what will change, what will break, and a safe migration path. Wait for explicit approval.
295
+ 6. Fix and test — **adapt the fix to existing structures**, not the other way around
296
+ 7. Update contracts if needed
297
+ 8. **Category 6 — Bug Isolation Check**: After applying the fix, run the FULL test suite and all smoke tests — not just the reproduction script. Do not assume the bug was isolated. A fix that resolves one failure frequently uncovers adjacent failures. Every test must pass before the session closes.
298
+
299
+ ### Team Mode (for complex cross-domain bugs)
300
+ ```
301
+ Create an agent team to debug:
302
+ - Teammate 1: Investigate in {domain-1} — check implementation
303
+ against contracts, trace data flow
304
+ - Teammate 2: Investigate in {domain-2} — check implementation
305
+ against contracts, trace data flow
306
+ - Teammate 3: Check all contracts for gaps or ambiguities
307
+ related to the failing scenario
308
+
309
+ First to find root cause: message the lead with findings.
310
+ ```
311
+
312
+ ## Step 4: Document Ripple
313
+
314
+ After fixing, assess what documentation was affected by the change and update ALL relevant files:
315
+
316
+ ### Always check:
317
+ 1. **`.gsd-t/progress.md`** — Add to Decision Log: what broke, why, and the fix. Prefix the entry with an outcome tag:
318
+ - Debug session start → prefix `[debug]`
319
+ - Fix succeeded → prefix `[success]`
320
+ - Fix failed → prefix `[failure]`
321
+ - Issue deferred → prefix `[deferred]`
322
+ 2. **`.gsd-t/contracts/`** — Update any contract if the fix changed an interface, schema, or API shape
323
+ 3. **Domain `constraints.md`** — Add a "must not" rule if the bug was caused by a pattern that should be avoided
324
+
325
+ ### Check if affected:
326
+ 4. **`docs/requirements.md`** — Did the fix reveal a missing or incorrect requirement? Update it
327
+ 5. **`docs/architecture.md`** — Did the fix change architectural patterns, data flow, or component relationships? Update it
328
+ 6. **`docs/schema.md`** — Did the fix modify the database schema? Update it
329
+ 7. **`.gsd-t/techdebt.md`** — Did the fix reveal related debt? Add a new TD item. Did it resolve an existing one? Mark it complete
330
+ 8. **Domain `scope.md`** — Did the fix add new files or change ownership? Update it
331
+ 9. **Domain `tasks.md`** — If the bug was in an active milestone, update task status or add a remediation task
332
+ 10. **`CLAUDE.md`** — Did the fix establish a new convention or pattern that future work should follow? Add it
333
+
334
+ ### Scan Doc Micro-Update (if `.gsd-t/scan/` exists):
335
+ Patch structural metadata in scan docs so they stay fresh between full scans. Near-zero cost — no LLM re-analysis.
336
+
337
+ For each scan doc that exists, apply only the relevant patches:
338
+ - **`.gsd-t/scan/architecture.md`** — Update file/directory counts if the fix added/removed files
339
+ - **`.gsd-t/scan/quality.md`** — Mark resolved TODOs/FIXMEs, update test counts if tests were added
340
+ - **`.gsd-t/scan/security.md`** — If the bug was a security issue, mark the finding `[RESOLVED]`
341
+ - **`.gsd-t/scan/business-rules.md`** — If the fix changed validation/auth/workflow logic, update the rule
342
+ - **`.gsd-t/scan/contract-drift.md`** — If contracts were updated as part of the fix, mark resolved drift items
343
+
344
+ Skip scan docs not affected by this fix. Skip analytical sections — those require a full scan.
345
+
346
+ ### Skip what's not affected — don't update docs for the sake of updating them.
347
+
348
+ ## Step 5: Test Verification (run tests confirming fix)
349
+
350
+ Before committing, ensure the fix is solid:
351
+
352
+ 1. **Update tests**: If the bug reveals a missing test case, add one that would have caught it
353
+ 2. **Run ALL configured test suites** — this is NOT optional:
354
+ a. Detect all runners: check for vitest/jest config, playwright.config.*, cypress.config.*
355
+ b. Run EVERY detected suite. Unit tests alone are NEVER sufficient when E2E exists.
356
+ c. If `playwright.config.*` exists → run `npx playwright test` (full suite)
357
+ d. Report ALL results: "Unit: X/Y pass | E2E: X/Y pass"
358
+ 3. **Verify passing**: All tests must pass. If any fail, fix before proceeding (up to 2 attempts)
359
+ 4. **If the project has a UI but no E2E specs cover the fixed area**: WRITE THEM.
360
+ 5. **Functional test quality**: Every E2E assertion must verify an action produced the correct outcome (state changed, data loaded, content updated) — not just that elements exist. Tests that only check `isVisible`/`toBeEnabled` are shallow layout tests and don't catch real bugs. If a test would pass on an empty HTML page with the right IDs, rewrite it.
361
+ 6. **Regression check**: Confirm the fix doesn't break any adjacent functionality
362
+
363
+ ### Exploratory Testing (if Playwright MCP available)
364
+
365
+ After all scripted tests pass:
366
+ 1. Check if Playwright MCP is registered in Claude Code settings (look for "playwright" in mcpServers)
367
+ 2. If available: spend 3 minutes on interactive exploration using Playwright MCP
368
+ - Specifically probe the area around the bug fix related flows, boundary conditions
369
+ - Try variations that might expose similar bugs nearby
370
+ - Test the fix path under edge input conditions
371
+ 3. Tag all findings [EXPLORATORY] in reports and append to .gsd-t/qa-issues.md
372
+ 4. If Playwright MCP is not available: skip this section silently
373
+ Note: Exploratory findings do NOT count against the scripted test pass/fail ratio.
374
+
375
+ Commit: `[debug] Fix {description} — root cause: {explanation}`
376
+
377
+ ## Step 5.3: Red Team Adversarial QA (MANDATORY)
378
+
379
+ After the fix passes all tests, spawn an adversarial Red Team agent. This agent's sole purpose is to BREAK the fix and find regressions. Its success is measured by bugs found, not tests passed.
380
+
381
+ [{model}] Red Team adversarial validation of debug fix
382
+
383
+ **OBSERVABILITY LOGGING (MANDATORY):**
384
+ Before spawning — run via Bash:
385
+ `T_START=$(date +%s) && DT_START=$(date +"%Y-%m-%d %H:%M") && TOK_START=${CLAUDE_CONTEXT_TOKENS_USED:-0} && TOK_MAX=${CLAUDE_CONTEXT_TOKENS_MAX:-200000}`
386
+
387
+ ```
388
+ Task subagent (general-purpose, model: opus):
389
+ "You are a Red Team QA adversary. Your job is to BREAK the fix that was just applied.
390
+
391
+ Your value is measured by REAL bugs found. More bugs = more value.
392
+ If you find zero bugs, you must prove you were thorough — list every
393
+ attack vector you tried and why it didn't break. A short list means
394
+ you didn't try hard enough.
395
+
396
+ Rules:
397
+ - False positives DESTROY your credibility. If you report something
398
+ as a bug and it's actually correct behavior, that's worse than
399
+ missing a real bug. Never report something you haven't reproduced.
400
+ - Style opinions are not bugs. Theoretical concerns are not bugs.
401
+ A bug is: 'I did X, expected Y, got Z.' With proof.
402
+ - You are done ONLY when you have exhausted every category below
403
+ and either found a bug or documented exactly what you tried.
404
+
405
+ ## Attack Categories (exhaust ALL of these)
406
+
407
+ 1. **Contract Violations**: Read .gsd-t/contracts/. Does the code EXACTLY
408
+ match every contract? Test each endpoint/interface/schema shape.
409
+ 2. **Boundary Inputs**: Empty strings, null, undefined, huge payloads,
410
+ special characters, SQL injection attempts, XSS payloads, path traversal.
411
+ 3. **State Transitions**: What happens when actions are performed out of
412
+ order? Double-submit? Concurrent access? Refresh mid-flow?
413
+ 4. **Error Paths**: Remove env vars. Kill the database. Send malformed
414
+ requests. Does the code handle failures gracefully or crash?
415
+ 5. **Regression Around the Fix**: The fix changed specific code. Test
416
+ every adjacent code path. Fixes frequently break neighboring functionality.
417
+ 6. **Original Bug Variants**: The original bug was found. Are there SIMILAR
418
+ bugs in related code? Same pattern, different location?
419
+ 7. **Full Suite**: Run the FULL test suite. Did the fix break anything else?
420
+ 8. **E2E Functional Gaps**: Review ALL Playwright specs. Do they test actual
421
+ behavior (state changes, data loaded, navigation works) or just check
422
+ that elements exist? Flag and rewrite any shallow/layout tests.
423
+
424
+ ## Exploratory Testing (if Playwright MCP available)
425
+
426
+ After all scripted tests pass:
427
+ 1. Check if Playwright MCP is registered in Claude Code settings (look for "playwright" in mcpServers)
428
+ 2. If available: spend 5 minutes on adversarial interactive exploration using Playwright MCP
429
+ - Focus on the fixed area and adjacent code — regressions often lurk nearby
430
+ - Try the original bug reproduction path to confirm it is truly fixed
431
+ - Probe for variant bugs: same pattern in related code paths
432
+ 3. Tag all findings [EXPLORATORY] in your report
433
+ 4. If Playwright MCP is not available: skip this section silently
434
+ Note: Exploratory findings are additive — they do not replace scripted test results.
435
+
436
+ ## Report Format
437
+
438
+ For each bug found:
439
+ - **BUG-{N}**: {severity: CRITICAL/HIGH/MEDIUM/LOW}
440
+ - **Reproduction**: {exact steps to reproduce}
441
+ - **Expected**: {what should happen}
442
+ - **Actual**: {what actually happens}
443
+ - **Proof**: {test file or command that demonstrates the bug}
444
+
445
+ Summary:
446
+ - BUGS FOUND: {count} (with severity breakdown)
447
+ - COVERAGE GAPS: {untested flows from requirements}
448
+ - SHALLOW TESTS REWRITTEN: {count}
449
+ - CONTRACTS VERIFIED: {N}/{total}
450
+ - ATTACK VECTORS TRIED: {list every category attempted and results}
451
+ - VERDICT: FAIL ({N} bugs found) | GRUDGING PASS (exhaustive search, nothing found)
452
+
453
+ Write all findings to .gsd-t/red-team-report.md.
454
+ If bugs found, also append to .gsd-t/qa-issues.md."
455
+ ```
456
+
457
+ After subagent returns — run via Bash:
458
+ `T_END=$(date +%s) && DT_END=$(date +"%Y-%m-%d %H:%M") && TOK_END=${CLAUDE_CONTEXT_TOKENS_USED:-0} && DURATION=$((T_END-T_START))`
459
+ Compute tokens and compaction:
460
+ - No compaction (TOK_END >= TOK_START): `TOKENS=$((TOK_END-TOK_START))`, COMPACTED=null
461
+ - Compaction detected (TOK_END < TOK_START): `TOKENS=$(((TOK_MAX-TOK_START)+TOK_END))`, COMPACTED=$DT_END
462
+ Append to `.gsd-t/token-log.md`:
463
+ `| {DT_START} | {DT_END} | gsd-t-debug | Red Team | sonnet | {DURATION}s | {VERDICT} — {N} bugs found | {TOKENS} | {COMPACTED} | | | {CTX_PCT} |`
464
+
465
+ **If Red Team VERDICT is FAIL:**
466
+ 1. Fix all CRITICAL and HIGH bugs immediately (up to 2 fix attempts per bug)
467
+ 2. Re-run Red Team after fixes
468
+ 3. If bugs persist after 2 fix cycles, log to `.gsd-t/deferred-items.md` and present to user
469
+
470
+ **If Red Team VERDICT is GRUDGING PASS:** Proceed to metrics and doc-ripple.
471
+
472
+ ## Step 5.5: Emit Task Metrics
473
+
474
+ After committing, emit a task-metrics record for this debug session — run via Bash:
475
+ `node bin/metrics-collector.js --milestone {current-milestone-or-none} --domain {domain-or-debug} --task debug-{timestamp} --command debug --duration_s {elapsed} --tokens_used {estimated} --context_pct ${CTX_PCT:-0} --pass {true|false} --fix_cycles {attempts} --signal_type debug-invoked --notes "[debug] {description}" 2>/dev/null || true`
476
+
477
+ Signal type is always `debug-invoked` for debug sessions.
478
+
479
+ Emit task_complete event — run via Bash:
480
+ `node ~/.claude/scripts/gsd-t-event-writer.js --type task_complete --command gsd-t-debug --reasoning "signal_type=debug-invoked, domain={domain}" --outcome {success|failure} || true`
481
+
482
+ ## Step 6: Doc-Ripple (Automated)
483
+
484
+ After all work is committed but before reporting completion:
485
+
486
+ 1. Run threshold check — read `git diff --name-only HEAD~1` and evaluate against doc-ripple-contract.md trigger conditions
487
+ 2. If SKIP: log "Doc-ripple: SKIP — {reason}" and proceed to completion
488
+ 3. If FIRE: spawn doc-ripple agent:
489
+
490
+ ⚙ [{model}] gsd-t-doc-ripple → blast radius analysis + parallel updates
491
+
492
+ Task subagent (general-purpose, model: sonnet):
493
+ "Execute the doc-ripple workflow per commands/gsd-t-doc-ripple.md.
494
+ Git diff context: {files changed list}
495
+ Command that triggered: debug
496
+ Produce manifest at .gsd-t/doc-ripple-manifest.md.
497
+ Update all affected documents.
498
+ Report: 'Doc-ripple: {N} checked, {N} updated, {N} skipped'"
499
+
500
+ 4. After doc-ripple returns, verify manifest exists and report summary inline
501
+
502
+ $ARGUMENTS
503
+
504
+ ## Auto-Clear
505
+
506
+ All work is committed to project files. Execute `/clear` to free the context window for the next command.