sequant 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +125 -163
  4. package/dist/bin/cli.js +13 -0
  5. package/dist/dashboard/server.js +1 -0
  6. package/dist/marketplace/external_plugins/sequant/.claude-plugin/plugin.json +2 -2
  7. package/dist/marketplace/external_plugins/sequant/README.md +6 -3
  8. package/dist/marketplace/external_plugins/sequant/hooks/post-tool.sh +92 -0
  9. package/dist/marketplace/external_plugins/sequant/hooks/pre-tool.sh +18 -9
  10. package/dist/marketplace/external_plugins/sequant/hooks/relay-check.sh +107 -0
  11. package/dist/marketplace/external_plugins/sequant/skills/_shared/references/behavior-rule-detection.md +205 -0
  12. package/dist/marketplace/external_plugins/sequant/skills/_shared/references/subagent-types.md +21 -8
  13. package/dist/marketplace/external_plugins/sequant/skills/assess/SKILL.md +302 -86
  14. package/dist/marketplace/external_plugins/sequant/skills/assess/references/predicted-collision-detection.md +109 -0
  15. package/dist/marketplace/external_plugins/sequant/skills/docs/SKILL.md +141 -22
  16. package/dist/marketplace/external_plugins/sequant/skills/exec/SKILL.md +83 -78
  17. package/dist/marketplace/external_plugins/sequant/skills/fullsolve/SKILL.md +377 -137
  18. package/dist/marketplace/external_plugins/sequant/skills/loop/SKILL.md +28 -0
  19. package/dist/marketplace/external_plugins/sequant/skills/merger/SKILL.md +621 -0
  20. package/dist/marketplace/external_plugins/sequant/skills/qa/SKILL.md +741 -232
  21. package/dist/marketplace/external_plugins/sequant/skills/qa/scripts/quality-checks.sh +47 -1
  22. package/dist/marketplace/external_plugins/sequant/skills/setup/SKILL.md +12 -6
  23. package/dist/marketplace/external_plugins/sequant/skills/spec/SKILL.md +217 -964
  24. package/dist/marketplace/external_plugins/sequant/skills/spec/references/parallel-groups.md +7 -0
  25. package/dist/marketplace/external_plugins/sequant/skills/spec/references/quality-checklist.md +75 -0
  26. package/dist/marketplace/external_plugins/sequant/skills/spec/references/recommended-workflow.md +4 -2
  27. package/dist/marketplace/external_plugins/sequant/skills/test/SKILL.md +0 -27
  28. package/dist/marketplace/external_plugins/sequant/skills/testgen/SKILL.md +24 -44
  29. package/dist/src/commands/ready-tui-adapter.d.ts +59 -0
  30. package/dist/src/commands/ready-tui-adapter.js +130 -0
  31. package/dist/src/commands/ready.d.ts +49 -0
  32. package/dist/src/commands/ready.js +243 -0
  33. package/dist/src/commands/status.js +4 -0
  34. package/dist/src/lib/cli-ui/run-renderer.d.ts +7 -1
  35. package/dist/src/lib/cli-ui/run-renderer.js +28 -28
  36. package/dist/src/lib/settings.d.ts +34 -0
  37. package/dist/src/lib/settings.js +23 -1
  38. package/dist/src/lib/workflow/phase-executor.js +17 -2
  39. package/dist/src/lib/workflow/platforms/github.d.ts +6 -0
  40. package/dist/src/lib/workflow/platforms/github.js +17 -0
  41. package/dist/src/lib/workflow/ready-gate.d.ts +155 -0
  42. package/dist/src/lib/workflow/ready-gate.js +374 -0
  43. package/dist/src/lib/workflow/reconcile.js +6 -0
  44. package/dist/src/lib/workflow/state-schema.d.ts +3 -0
  45. package/dist/src/lib/workflow/state-schema.js +1 -0
  46. package/dist/src/lib/workflow/types.d.ts +9 -0
  47. package/dist/src/ui/tui/App.js +8 -2
  48. package/dist/src/ui/tui/IssueBox.js +3 -4
  49. package/dist/src/ui/tui/index.d.ts +13 -4
  50. package/dist/src/ui/tui/index.js +19 -5
  51. package/dist/src/ui/tui/row-cap.d.ts +51 -0
  52. package/dist/src/ui/tui/row-cap.js +76 -0
  53. package/dist/src/ui/tui/teardown.d.ts +20 -0
  54. package/dist/src/ui/tui/teardown.js +29 -0
  55. package/dist/src/ui/tui/theme.d.ts +3 -0
  56. package/dist/src/ui/tui/theme.js +3 -0
  57. package/package.json +19 -8
  58. package/templates/skills/qa/SKILL.md +5 -2
@@ -22,14 +22,21 @@ allowed-tools:
22
22
  - Bash(gh issue comment:*)
23
23
  - Bash(gh issue edit:*)
24
24
  - Bash(gh pr create:*)
25
+ - Bash(gh pr list:*)
26
+ - Bash(gh pr merge:*)
25
27
  - Bash(npm test:*)
26
28
  - Bash(npm run build:*)
27
29
  - Bash(git diff:*)
28
30
  - Bash(git status:*)
31
+ - Bash(git log:*)
29
32
  - Bash(git add:*)
30
33
  - Bash(git commit:*)
31
34
  - Bash(git push:*)
32
35
  - Bash(git worktree:*)
36
+ - Bash(./scripts/dev/*:*)
37
+ - Bash(./scripts/cleanup-worktree.sh:*)
38
+ - Bash(./scripts/new-feature.sh:*)
39
+ - Bash(./scripts/list-worktrees.sh:*)
33
40
  ---
34
41
 
35
42
  # Full Solve Command
@@ -40,6 +47,26 @@ You are the "Full Solve Agent" for the current repository.
40
47
 
41
48
  When invoked as `/fullsolve <issue-number>`, execute the complete issue resolution workflow with integrated quality loops. This command orchestrates all phases and automatically iterates until quality gates pass.
42
49
 
50
+ ## CRITICAL: Auto-Progression Between Phases
51
+
52
+ **DO NOT wait for user confirmation between phases.** This is an autonomous workflow.
53
+
54
+ After each phase completes successfully, **immediately proceed** to the next phase:
55
+ 1. `/spec` completes → **immediately** invoke `/exec`
56
+ 2. `/exec` completes → **immediately** invoke `/test` (if UI) or `/qa`
57
+ 3. `/test` completes → **immediately** invoke `/qa`
58
+ 4. `/qa` completes → **immediately** create PR
59
+
60
+ **The user invoked `/fullsolve` expecting end-to-end automation.** Only stop for:
61
+ - Unrecoverable errors (after retry attempts exhausted)
62
+ - Final summary after PR creation
63
+ - Explicit user interruption
64
+
65
+ ```
66
+ WRONG: "Spec complete. Ready for exec phase." [waits]
67
+ RIGHT: "Spec complete. Proceeding to exec..." [invokes /exec immediately]
68
+ ```
69
+
43
70
  ## Workflow Overview
44
71
 
45
72
  ```
@@ -88,8 +115,59 @@ When invoked as `/fullsolve <issue-number>`, execute the complete issue resoluti
88
115
  /fullsolve 218 # Standard full solve
89
116
  /fullsolve 218 --skip-test # Skip testing phase (backend issues)
90
117
  /fullsolve 218 --max-iterations 5 # Override max fix iterations
118
+ /fullsolve 218 --parallel # Force parallel agent execution (faster, higher token usage)
119
+ /fullsolve 218 --sequential # Force sequential agent execution (slower, lower token usage)
91
120
  ```
92
121
 
122
+ ## Agent Execution Mode
123
+
124
+ When spawning sub-agents for quality checks, determine the execution mode:
125
+
126
+ 1. **Check for CLI flag override:**
127
+ - `--parallel` → Run sub-agents in parallel
128
+ - `--sequential` → Run sub-agents one at a time
129
+
130
+ 2. **If no flag, read project settings:**
131
+ Use the Read tool to check project settings:
132
+ ```
133
+ Read(file_path=".sequant/settings.json")
134
+ # Parse JSON and extract agents.parallel (default: false)
135
+ ```
136
+
137
+ 3. **Default:** Sequential (cost-optimized)
138
+
139
+ | Mode | Token Usage | Speed | Best For |
140
+ |------|-------------|-------|----------|
141
+ | Sequential | 1x (baseline) | Slower | Limited API plans, single issues |
142
+ | Parallel | ~2-3x | ~50% faster | Unlimited plans, batch operations |
143
+
144
+ **Pass execution mode to child skills:** When invoking `/qa` or other skills that spawn agents, pass the `--parallel` or `--sequential` flag to maintain consistency.
145
+
146
+ ## Orchestration Context
147
+
148
+ This skill acts as an **orchestrator** and sets environment variables for child skills to optimize their behavior:
149
+
150
+ | Environment Variable | Description | Example Value |
151
+ |---------------------|-------------|---------------|
152
+ | `SEQUANT_ORCHESTRATOR` | Identifies the orchestrator | `sequant-run` |
153
+ | `SEQUANT_PHASE` | Current phase being executed | `spec`, `exec`, `test`, `qa`, `loop` |
154
+ | `SEQUANT_ISSUE` | Issue number being processed | `218` |
155
+ | `SEQUANT_WORKTREE` | Path to the feature worktree | `/path/to/worktrees/feature/218-...` |
156
+
157
+ **Benefits of orchestration context:**
158
+
159
+ 1. **Faster execution** - Child skills skip redundant pre-flight checks
160
+ 2. **Cleaner GitHub comments** - Only orchestrator posts progress updates
161
+ 3. **Better coordination** - Skills can trust worktree and issue context
162
+ 4. **Reduced API calls** - Issue fetch happens once, not per-phase
163
+
164
+ **Child skills detect orchestration via `SEQUANT_ORCHESTRATOR` and adjust behavior:**
165
+ - `/spec`: Runs normally (first phase, no prior context)
166
+ - `/exec`: Skips worktree creation, uses provided path
167
+ - `/test`: Skips issue fetch, trusts orchestrator context
168
+ - `/qa`: Skips pre-flight sync, defers GitHub updates
169
+ - `/loop`: Uses provided worktree, defers GitHub updates
170
+
93
171
  ## Phase Detection (Smart Resumption)
94
172
 
95
173
  **Before starting any phase**, detect the current workflow state from GitHub issue comments to enable smart resumption:
@@ -169,144 +247,189 @@ Before creating any files, check if they already exist:
169
247
 
170
248
  **If work already exists:** Skip to the appropriate phase (e.g., if implementation is done, go to Phase 3 or 4).
171
249
 
172
- ## Phase 1: Planning (SPEC)
173
-
174
- Execute the planning phase inline (not as separate command):
250
+ ### 0.3 Acquire Concurrency Lock (#625)
175
251
 
176
- ### 1.1 Fetch Issue Context
252
+ **Before invoking `/spec`**, claim the per-issue concurrency lock. This prevents a second session (another `/fullsolve`, an `npx sequant run`, or another `/fullsolve` in a different window) from racing on the same issue and producing zero-diff exec failures.
177
253
 
178
254
  ```bash
179
- gh issue view <issue-number> --json title,body,labels
180
- gh issue view <issue-number> --comments
255
+ # Acquire lock for this issue. --skip-pid-check is required: the shell that
256
+ # runs this command exits immediately, so the lock's PID is dead by the time
257
+ # the next check runs. Stale recovery falls back to age-only (2h).
258
+ if ! npx sequant locks acquire <issue-number> \
259
+ --command="/fullsolve <issue-number>" \
260
+ --skip-pid-check; then
261
+ echo "❌ Another session is working on #<issue-number>. Run 'npx sequant locks list' for details."
262
+ echo " If you're sure the holder is dead, run: npx sequant locks clear <issue-number>"
263
+ exit 1
264
+ fi
181
265
  ```
182
266
 
183
- ### 1.2 Extract Acceptance Criteria
267
+ **Release contract:** Phase 5.5 releases the lock on the happy path. On ANY halt/abort branch (spec failure, exec exhausted, qa loop exhausted with AC_NOT_MET, unrecoverable error, stagnation halt), you MUST run `npx sequant locks release <issue-number> || true` **before** printing the halt message. The explicit release calls below cover the known branches; if you add a new abort path, add a release call there too.
268
+
269
+ **Backstop:** If a release is somehow missed, stale recovery clears the lock after 6h on the same host (`SEQUANT_SKILL_LOCK_TTL_MS` overrides). The user can also force-clear via `npx sequant locks clear <issue-number>`.
184
270
 
185
- Parse issue body and comments to build AC checklist:
186
- - AC-1, AC-2, etc.
187
- - Identify blockers, dependencies
188
- - Note open questions
271
+ **Orchestrator/MCP mode:** When `SEQUANT_ORCHESTRATOR` is set, `locks acquire` and `locks release` are no-ops (exit 0, no file touched). Safe to call unconditionally.
189
272
 
190
- ### 1.3 Create Implementation Plan
273
+ ## Phase 1: Planning (SPEC)
191
274
 
192
- - Break down into 3-7 implementation steps
193
- - Identify complexity and risks
194
- - Post plan comment to issue
275
+ **Invoke the `/spec` skill** to plan implementation and extract acceptance criteria.
195
276
 
196
- **Use Sequential Thinking for Complex Planning:**
277
+ ### 1.1 Invoke Spec Skill
197
278
 
198
- If the issue involves architectural decisions or multiple valid approaches, use Sequential Thinking MCP:
279
+ Use the `Skill` tool to invoke `/spec`:
199
280
 
200
- ```javascript
201
- // For complex issues with multiple implementation paths
202
- mcp__sequential-thinking__sequentialthinking({
203
- thought: "Analyzing implementation approaches for [feature]. Options: 1) [Approach A] - pros/cons. 2) [Approach B] - pros/cons. 3) [Approach C] - pros/cons...",
204
- thoughtNumber: 1,
205
- totalThoughts: 4,
206
- nextThoughtNeeded: true
207
- })
208
281
  ```
282
+ Skill(skill: "spec", args: "<issue-number>")
283
+ ```
284
+
285
+ The `/spec` skill will:
286
+ - Fetch issue context from GitHub
287
+ - Extract acceptance criteria (AC-1, AC-2, etc.)
288
+ - Create implementation plan (3-7 steps)
289
+ - Post plan comment to the issue
290
+ - Create feature worktree
291
+
292
+ ### 1.2 Capture Spec Output
209
293
 
210
- **When to use Sequential Thinking in planning:**
211
- - Issue labeled `complex`, `refactor`, or `architecture`
212
- - 3+ valid implementation approaches exist
213
- - Unclear trade-offs between options
214
- - Previous implementation attempt failed
294
+ After `/spec` completes, extract and store:
295
+ - **AC Checklist:** List of acceptance criteria for tracking
296
+ - **Worktree Path:** Location for subsequent phases
297
+ - **Recommended Phases:** Whether `/test` is needed (UI features)
215
298
 
216
- **Fallback:** If Sequential Thinking unavailable, document pros/cons explicitly in the plan comment.
299
+ ```markdown
300
+ ## Spec Output Captured
301
+
302
+ **Issue:** #<N>
303
+ **Worktree:** ../worktrees/feature/<issue-number>-*/
304
+ **AC Count:** <N> items
305
+ **Needs Testing:** Yes/No (based on labels)
306
+ ```
217
307
 
218
- ### 1.4 Create Feature Worktree
308
+ ### 1.3 Handle Spec Failures
309
+
310
+ If `/spec` fails:
311
+ - Check if issue exists and is readable
312
+ - Verify GitHub CLI authentication
313
+ - **Release the lock acquired in Phase 0.3** (so the user can retry without hitting the orphan window)
314
+ - Report failure and exit workflow
219
315
 
220
316
  ```bash
221
- ./scripts/dev/new-feature.sh <issue-number>
317
+ # Release before halting — see Phase 0.3 release contract.
318
+ npx sequant locks release <issue-number> || true
319
+ ```
320
+
321
+ ```markdown
322
+ ## Spec Failed
323
+
324
+ **Error:** [error message]
325
+ **Action Required:** [what the user needs to do]
326
+
327
+ Workflow halted. Fix the issue and re-run `/fullsolve <issue-number>`.
222
328
  ```
223
329
 
224
330
  **State after Phase 1:**
225
331
  - AC checklist defined
226
- - Implementation plan created
332
+ - Implementation plan created (and posted to GitHub)
227
333
  - Feature worktree ready
228
334
 
335
+ **→ IMMEDIATELY proceed to Phase 2 (do not wait for user input)**
336
+
229
337
  ## Phase 2: Implementation (EXEC)
230
338
 
231
- ### 2.1 Navigate to Worktree
339
+ **Invoke the `/exec` skill** to implement all acceptance criteria.
232
340
 
233
- ```bash
234
- cd ../worktrees/feature/<issue-number>-*/
341
+ ### 2.1 Invoke Exec Skill
342
+
343
+ Use the `Skill` tool to invoke `/exec`:
344
+
345
+ ```
346
+ Skill(skill: "exec", args: "<issue-number>")
235
347
  ```
236
348
 
237
- ### 2.2 MCP Availability Check (Optional Enhancement)
349
+ The `/exec` skill will:
350
+ - Navigate to the feature worktree
351
+ - Implement each AC item
352
+ - Run tests and build after changes
353
+ - Verify quality gates pass
238
354
 
239
- Before implementation, check MCP tool availability for enhanced workflow:
355
+ ### 2.2 Pass Orchestration Context
240
356
 
241
- ```markdown
242
- **Available MCPs:**
243
- - [ ] Context7 (`mcp__context7__*`) - For external library documentation
244
- - [ ] Sequential Thinking (`mcp__sequential-thinking__*`) - For complex decisions
245
- - [ ] Chrome DevTools (`mcp__chrome-devtools__*`) - For browser testing in Phase 3
246
- ```
357
+ Set environment variables before invoking `/exec` so it can optimize its behavior:
247
358
 
248
- **If MCPs unavailable:** Continue with standard implementation - fallback strategies documented in `/exec` skill.
359
+ ```bash
360
+ export SEQUANT_ORCHESTRATOR=fullsolve
361
+ export SEQUANT_PHASE=exec
362
+ export SEQUANT_ISSUE=<issue-number>
363
+ export SEQUANT_WORKTREE=../worktrees/feature/<issue-number>-*/
364
+ ```
249
365
 
250
- ### 2.3 Implement Each AC Item
366
+ When `/exec` detects `SEQUANT_ORCHESTRATOR`, it:
367
+ - Skips worktree creation (already done by `/spec`)
368
+ - Uses the provided worktree path
369
+ - Defers GitHub comment updates to orchestrator
251
370
 
252
- For each AC item:
253
- 1. Understand requirement
254
- 2. Find similar patterns in codebase (use Glob/Grep first)
255
- 3. **If using unfamiliar library:** Use Context7 for documentation lookup
256
- 4. **If facing complex decision:** Use Sequential Thinking to analyze approaches
257
- 5. Implement minimal solution
258
- 6. Run tests and build
259
- 7. Mark AC as complete
371
+ ### 2.3 Handle Exec Failures
260
372
 
261
- **MCP Usage in Implementation Loop:**
373
+ If `/exec` fails (tests or build):
262
374
 
375
+ **Attempt fix (max 3 iterations):**
263
376
  ```
264
- For each AC item:
265
-
266
- ├─ Need external library API? → Use Context7 (if available)
267
- │ └─ Fallback: WebSearch for documentation
268
-
269
- ├─ Multiple valid approaches? → Use Sequential Thinking (if available)
270
- │ └─ Fallback: Explicit pros/cons analysis in response
271
-
272
- └─ Standard implementation → Use Glob/Grep for patterns
273
- ```
377
+ exec_iteration = 0
378
+ while exec_iteration < MAX_EXEC_ITERATIONS:
379
+ result = Skill(skill: "exec", args: "<issue-number>")
274
380
 
275
- ### 2.4 Quality Gates
381
+ if result.success:
382
+ break
276
383
 
277
- After implementation:
278
- - `npm test` - All tests pass
279
- - `npm run build` - Build succeeds
280
- - `git diff` - Changes are proportional
384
+ # Parse and log failure
385
+ log_failure(result.error)
386
+ exec_iteration += 1
387
+ ```
281
388
 
282
- ### 2.5 Final Verification (CRITICAL)
389
+ **If all iterations exhausted:**
390
+ ```bash
391
+ # Release before halting — see Phase 0.3 release contract.
392
+ npx sequant locks release <issue-number> || true
393
+ ```
283
394
 
284
- **After ALL implementation changes are complete**, run verification one more time:
395
+ ```markdown
396
+ ## Exec Failed
285
397
 
286
- ```bash
287
- # Run full test suite AFTER all changes
288
- npm test
398
+ **Iterations:** 3/3 exhausted
399
+ **Last Error:** [error message]
289
400
 
290
- # Verify build still works
291
- npm run build
401
+ Workflow halted. Manual intervention required.
292
402
  ```
293
403
 
294
- **Why this matters:** Tests run during implementation may pass before file conversions or final changes are made. Always verify after the LAST change, not just after each intermediate step.
404
+ ### 2.4 Capture Exec Output
295
405
 
296
- **If tests fail at this stage:**
297
- 1. Fix the failing tests (update paths, content checks, etc.)
298
- 2. Re-run `npm test` until all pass
299
- 3. Do NOT proceed to Phase 3 until tests pass
406
+ After successful `/exec`:
407
+ - Verify tests passed
408
+ - Verify build succeeded
409
+ - Record files changed
410
+
411
+ ```markdown
412
+ ## Exec Complete
413
+
414
+ **Tests:** ✅ All passing
415
+ **Build:** ✅ Succeeded
416
+ **Files Changed:** <N>
417
+ ```
300
418
 
301
419
  **State after Phase 2:**
302
420
  - All AC items implemented
303
421
  - Tests passing (verified AFTER final changes)
304
422
  - Build succeeding
305
423
 
424
+ **→ IMMEDIATELY proceed to Phase 3 or 4 (do not wait for user input)**
425
+ - If UI labels (`ui`, `frontend`, `admin`) present AND no `no-browser-test` label → invoke `/test`
426
+ - If `no-browser-test` label present → skip to `/qa` (explicit opt-out)
427
+ - Otherwise → skip to `/qa`
428
+
306
429
  ## Phase 3: Testing (TEST)
307
430
 
308
431
  **Skip if:**
309
- - Issue doesn't have `admin`, `ui`, or `frontend` labels, OR
432
+ - Issue doesn't have `admin`, `ui`, or `frontend` labels (determined from `/spec` output), OR
310
433
  - Issue has `no-browser-test` label (explicit opt-out, overrides UI labels)
311
434
 
312
435
  ### Browser Testing Label Reference
@@ -317,105 +440,182 @@ npm run build
317
440
  | `no-browser-test` | Always skips `/test` phase (explicit opt-out) |
318
441
  | Neither | Auto-detection in `/spec` may suggest adding `ui` label |
319
442
 
320
- ### 3.1 Start Dev Server
443
+ **Invoke the `/test` skill** for browser-based UI testing.
321
444
 
322
- ```bash
323
- npm run dev &
324
- ```
445
+ ### 3.1 Invoke Test Skill
446
+
447
+ Use the `Skill` tool to invoke `/test`:
325
448
 
326
- ### 3.2 Execute Test Cases
449
+ ```
450
+ Skill(skill: "test", args: "<issue-number>")
451
+ ```
327
452
 
328
- Using Chrome DevTools MCP:
329
- - Navigate to feature
453
+ The `/test` skill will:
454
+ - Start development server
455
+ - Navigate to feature in browser (Chrome DevTools MCP)
330
456
  - Execute each test case
331
- - Record PASS/FAIL/BLOCKED
457
+ - Record PASS/FAIL/BLOCKED results
458
+
459
+ ### 3.2 Pass Orchestration Context
460
+
461
+ ```bash
462
+ export SEQUANT_ORCHESTRATOR=fullsolve
463
+ export SEQUANT_PHASE=test
464
+ export SEQUANT_ISSUE=<issue-number>
465
+ export SEQUANT_WORKTREE=../worktrees/feature/<issue-number>-*/
466
+ ```
467
+
468
+ When `/test` detects `SEQUANT_ORCHESTRATOR`, it:
469
+ - Skips issue fetch (trusts orchestrator context)
470
+ - Uses provided AC checklist
471
+ - Defers GitHub updates to orchestrator
332
472
 
333
473
  ### 3.3 Test Loop (Max 3 iterations)
334
474
 
475
+ If tests fail, invoke `/loop` to fix and re-test:
476
+
335
477
  ```
336
478
  test_iteration = 0
337
- while test_iteration < 3:
338
- run_tests()
479
+ while test_iteration < MAX_TEST_ITERATIONS:
480
+ result = Skill(skill: "test", args: "<issue-number>")
339
481
 
340
- if all_tests_pass:
482
+ if result.all_tests_pass:
341
483
  break
342
484
 
343
- # Parse failures
344
- failed_tests = parse_failed_tests()
485
+ # Use /loop to fix failures
486
+ Skill(skill: "sequant:loop", args: "<issue-number> --phase test")
487
+ test_iteration += 1
488
+ ```
345
489
 
346
- # Fix each failure
347
- for test in failed_tests:
348
- understand_failure()
349
- implement_fix()
350
- verify_fix()
490
+ ### 3.4 Handle Test Exhaustion
351
491
 
352
- test_iteration += 1
492
+ If max iterations reached:
493
+
494
+ ```markdown
495
+ ## Test Loop Exhausted
496
+
497
+ **Iterations:** 3/3
498
+ **Remaining Failures:** [list]
499
+
500
+ Proceeding to QA phase. Failures will be documented.
353
501
  ```
354
502
 
355
503
  **State after Phase 3:**
356
504
  - All tests passing (or max iterations reached)
357
505
  - Bugs documented and fixed
358
506
 
507
+ **→ IMMEDIATELY proceed to Phase 4 (do not wait for user input)**
508
+
359
509
  ## Phase 4: Quality Assurance (QA)
360
510
 
361
- ### 4.1 Automated Quality Checks
511
+ **Invoke the `/qa` skill** for code review and AC validation.
362
512
 
363
- ```bash
364
- # Type safety
365
- git diff main...HEAD | grep -E ":\s*any[,)]|as any" || true
513
+ ### 4.1 Invoke QA Skill
366
514
 
367
- # Deleted tests
368
- git diff main...HEAD --diff-filter=D --name-only | grep -E "\.test\." || true
515
+ Use the `Skill` tool to invoke `/qa`:
369
516
 
370
- # Scope check
371
- git diff main...HEAD --name-only | wc -l
372
-
373
- # Size check
374
- git diff main...HEAD --numstat
375
517
  ```
518
+ Skill(skill: "qa", args: "<issue-number>")
519
+ ```
520
+
521
+ The `/qa` skill will:
522
+ - Run automated quality checks (type safety, deleted tests, scope)
523
+ - Review AC coverage (MET/PARTIALLY_MET/NOT_MET/PENDING)
524
+ - Generate review comment draft
525
+ - Return verdict: READY_FOR_MERGE, AC_MET_BUT_NOT_A_PLUS, NEEDS_VERIFICATION,
526
+ or AC_NOT_MET
376
527
 
377
- ### 4.2 AC Coverage Review
528
+ ### 4.2 Pass Orchestration Context
378
529
 
379
- For each AC item, mark:
380
- - `MET` - Fully implemented
381
- - `PARTIALLY_MET` - Needs more work
382
- - `NOT_MET` - Not implemented
530
+ ```bash
531
+ export SEQUANT_ORCHESTRATOR=fullsolve
532
+ export SEQUANT_PHASE=qa
533
+ export SEQUANT_ISSUE=<issue-number>
534
+ export SEQUANT_WORKTREE=../worktrees/feature/<issue-number>-*/
535
+ ```
536
+
537
+ When `/qa` detects `SEQUANT_ORCHESTRATOR`, it:
538
+ - Skips pre-flight sync
539
+ - Defers GitHub comment posting to orchestrator
540
+ - Returns structured verdict for orchestrator to process
383
541
 
384
542
  ### 4.3 QA Loop (Max 2 iterations)
385
543
 
544
+ If verdict is not `READY_FOR_MERGE`, invoke `/loop` to fix and re-run QA.
545
+
546
+ **Stagnation gate (issue #581):** Before each `/qa` re-invocation after iteration 1, run the stagnation detector. If it reports `stagnant: true` with reason `SAME_SHA_NO_PROGRESS`, the prior `/loop` made no commit and produced no diff — re-running `/qa` would yield the same verdict. Halt the loop and surface a hard blocker instead of wasting another cycle.
547
+
548
+ ```bash
549
+ # Run before each /qa call after iteration 0 (skip on first call):
550
+ npx tsx scripts/qa-stagnation.ts detect <issue-number>
551
+ # Output (JSON): {"stagnant": true|false, "reason"?: "SAME_SHA_NO_PROGRESS", "message": "...", ...}
552
+ # When stagnant === true: record telemetry, then halt — do NOT call /qa again.
553
+ npx tsx scripts/qa-stagnation.ts record <issue-number> <iteration> SAME_SHA_NO_PROGRESS --verdict=AC_NOT_MET
386
554
  ```
387
- qa_iteration = 0
388
- while qa_iteration < 2:
389
- run_qa_checks()
390
555
 
391
- if verdict == "READY_FOR_MERGE":
556
+ ```
557
+ qa_iteration = 0
558
+ while qa_iteration < MAX_QA_ITERATIONS:
559
+ if qa_iteration > 0:
560
+ # Stagnation gate — same-SHA same-verdict cycles are wasted.
561
+ decision = `npx tsx scripts/qa-stagnation.ts detect <issue-number>`
562
+ if decision.stagnant == true:
563
+ `npx tsx scripts/qa-stagnation.ts record <issue-number> {qa_iteration} SAME_SHA_NO_PROGRESS --verdict=AC_NOT_MET`
564
+ # Halt — no progress since last QA. Skip to 4.4 with stagnation note.
565
+ break
566
+
567
+ result = Skill(skill: "qa", args: "<issue-number>")
568
+
569
+ if result.verdict == "READY_FOR_MERGE":
392
570
  break
393
571
 
394
- if verdict == "AC_MET_BUT_NOT_A_PLUS":
572
+ if result.verdict == "AC_MET_BUT_NOT_A_PLUS":
395
573
  # Good enough, proceed with notes
396
574
  break
397
575
 
398
- if verdict == "NEEDS_VERIFICATION":
576
+ if result.verdict == "NEEDS_VERIFICATION":
399
577
  # ACs are met but pending external verification
400
578
  # Proceed to PR - verification can happen post-PR
401
579
  break
402
580
 
403
- # Parse issues (AC_NOT_MET)
404
- issues = parse_qa_issues()
581
+ # Use /loop to fix issues (AC_NOT_MET)
582
+ Skill(skill: "sequant:loop", args: "<issue-number> --phase qa")
583
+ qa_iteration += 1
584
+ ```
405
585
 
406
- # Fix each issue
407
- for issue in issues:
408
- understand_issue()
409
- implement_fix()
410
- verify_fix()
586
+ ### 4.4 Handle QA Exhaustion
411
587
 
412
- qa_iteration += 1
588
+ If max iterations reached with `AC_NOT_MET`:
589
+
590
+ ```markdown
591
+ ## QA Loop Exhausted
592
+
593
+ **Iterations:** 2/2
594
+ **Verdict:** AC_NOT_MET
595
+ **Remaining Issues:** [list]
596
+
597
+ Creating PR with notes for human review.
413
598
  ```
414
599
 
415
600
  **State after Phase 4:**
416
- - AC fully met
601
+ - AC fully met (or documented as partial)
417
602
  - Code quality validated
418
- - Ready for merge
603
+ - Ready for merge (or flagged for human review)
604
+
605
+ **→ IMMEDIATELY proceed to Phase 5 after self-evaluation (do not wait for user input)**
606
+
607
+ ### 4.5 Risk Assessment
608
+
609
+ Risk assessment is performed during the QA phase — see QA output above. If QA was skipped or incomplete, state risks here using the same format:
610
+
611
+ ```markdown
612
+ ### Risk Assessment
613
+
614
+ - **Likely failure mode:** [How would this break in production?]
615
+ - **Not tested:** [What gaps exist in test coverage?]
616
+ ```
617
+
618
+ ---
419
619
 
420
620
  ## Phase 5: Pull Request (PR)
421
621
 
@@ -470,7 +670,7 @@ Post completion comment to issue with:
470
670
  gh pr merge <N> --squash
471
671
 
472
672
  # 2. Clean up worktree (removes local worktree + branch)
473
- ./scripts/dev/cleanup-worktree.sh feature/<issue-number>-*
673
+ ./scripts/cleanup-worktree.sh feature/<issue-number>-*
474
674
 
475
675
  # 3. Issue auto-closes if commit message contains "Fixes #N"
476
676
  ```
@@ -494,6 +694,16 @@ npx sequant doctor
494
694
 
495
695
  If any command fails, fix immediately on main before continuing. This catches issues like ESM compatibility bugs that unit tests may miss.
496
696
 
697
+ ### 5.5 Release Concurrency Lock (#625)
698
+
699
+ After the PR is created (or earlier if the workflow exits gracefully), release the lock so other sessions can claim it:
700
+
701
+ ```bash
702
+ npx sequant locks release <issue-number> || true
703
+ ```
704
+
705
+ `|| true` is intentional — release is idempotent; the lock may already have been cleared (orchestrator mode, age-based recovery, or manual `locks clear`). The exit code is informational only.
706
+
497
707
  ## Iteration Tracking
498
708
 
499
709
  Track iterations to prevent infinite loops:
@@ -592,15 +802,24 @@ Ready for human review and merge.
592
802
 
593
803
  ## Error Recovery
594
804
 
805
+ **Concurrency lock cleanup (#625, applies to every abort path below):**
806
+
807
+ ```bash
808
+ npx sequant locks release <issue-number> || true
809
+ ```
810
+
811
+ Run this BEFORE printing the halt/exit message in any of the branches below. The release call is idempotent (no-op when nothing is held, no-op in orchestrator mode), so calling it unconditionally on every error path is safe.
812
+
595
813
  **If spec fails:**
596
814
  - Check issue exists and is readable
597
815
  - Verify GitHub CLI authentication
816
+ - Release lock (see top of section)
598
817
  - Exit with clear error
599
818
 
600
819
  **If exec fails (build/test):**
601
820
  - Check error logs
602
821
  - Attempt targeted fix
603
- - If persistent, document and exit
822
+ - If persistent: release lock, document, and exit
604
823
 
605
824
  **If test loop exhausted:**
606
825
  - Document remaining failures
@@ -693,10 +912,31 @@ sequant merge --check # Verify no cross-issue conflicts
693
912
 
694
913
  ---
695
914
 
915
+ ## State Tracking
916
+
917
+ **IMPORTANT:** `/fullsolve` is an orchestrator and manages state for child skills.
918
+
919
+ ### Orchestrator Responsibilities
920
+
921
+ As an orchestrator, `/fullsolve` must:
922
+
923
+ 1. **Set orchestration context** for child skills:
924
+ ```bash
925
+ export SEQUANT_ORCHESTRATOR=fullsolve
926
+ export SEQUANT_PHASE=<current-phase>
927
+ export SEQUANT_ISSUE=<issue-number>
928
+ export SEQUANT_WORKTREE=<worktree-path>
929
+ ```
930
+
931
+ 2. **State tracking** is handled automatically by the orchestrator runtime when `SEQUANT_ORCHESTRATOR` is set. Child skills defer state management to the orchestrator to avoid duplicate updates.
932
+
933
+ ---
934
+
696
935
  ## Output Verification
697
936
 
698
937
  **Before responding, verify your output includes ALL of these:**
699
938
 
939
+ - [ ] **Risk Assessment (from QA)** - Likely failure mode and coverage gaps stated
700
940
  - [ ] **Progress Table** - Phase, iterations, and status for each phase
701
941
  - [ ] **AC Coverage** - Each AC marked MET/PARTIALLY_MET/NOT_MET
702
942
  - [ ] **Quality Metrics** - Tests passed, build status, type issues