claude-code-pilot 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +11 -11
  2. package/bin/install.js +19 -1
  3. package/manifest.json +5 -1
  4. package/package.json +2 -2
  5. package/src/agents/a11y-architect.md +141 -0
  6. package/src/agents/code-architect.md +71 -0
  7. package/src/agents/code-explorer.md +69 -0
  8. package/src/agents/code-simplifier.md +47 -0
  9. package/src/agents/comment-analyzer.md +45 -0
  10. package/src/agents/csharp-reviewer.md +101 -0
  11. package/src/agents/dart-build-resolver.md +201 -0
  12. package/src/agents/pr-test-analyzer.md +45 -0
  13. package/src/agents/silent-failure-hunter.md +50 -0
  14. package/src/agents/type-design-analyzer.md +41 -0
  15. package/src/available-rules/README.md +3 -1
  16. package/src/available-rules/dart/coding-style.md +159 -0
  17. package/src/available-rules/dart/hooks.md +66 -0
  18. package/src/available-rules/dart/patterns.md +261 -0
  19. package/src/available-rules/dart/security.md +135 -0
  20. package/src/available-rules/dart/testing.md +215 -0
  21. package/src/available-rules/web/coding-style.md +105 -0
  22. package/src/available-rules/web/design-quality.md +72 -0
  23. package/src/available-rules/web/hooks.md +129 -0
  24. package/src/available-rules/web/patterns.md +88 -0
  25. package/src/available-rules/web/performance.md +73 -0
  26. package/src/available-rules/web/security.md +66 -0
  27. package/src/available-rules/web/testing.md +64 -0
  28. package/src/commands/ccp/ai-integration-phase.md +36 -0
  29. package/src/commands/ccp/audit-fix.md +33 -0
  30. package/src/commands/ccp/code-review-fix.md +52 -0
  31. package/src/commands/ccp/eval-review.md +32 -0
  32. package/src/commands/ccp/extract_learnings.md +22 -0
  33. package/src/commands/ccp/import.md +37 -0
  34. package/src/commands/ccp/ingest-docs.md +42 -0
  35. package/src/commands/ccp/intel.md +179 -0
  36. package/src/commands/ccp/plan-review-convergence.md +58 -0
  37. package/src/commands/ccp/scan.md +26 -0
  38. package/src/commands/ccp/sketch-wrap-up.md +31 -0
  39. package/src/commands/ccp/sketch.md +54 -0
  40. package/src/commands/ccp/spec-phase.md +62 -0
  41. package/src/commands/ccp/spike-wrap-up.md +31 -0
  42. package/src/commands/ccp/spike.md +51 -0
  43. package/src/commands/ccp/ultraplan-phase.md +33 -0
  44. package/src/hooks/ccp-read-injection-scanner.js +152 -0
  45. package/src/hooks/kit-check-update.js +59 -7
  46. package/src/hooks/run-with-flags-shell.sh +1 -0
  47. package/src/hooks/run-with-flags.js +48 -1
  48. package/src/hooks/session-end.js +88 -1
  49. package/src/lib/hook-flags.js +14 -0
  50. package/src/pilot/references/agent-contracts.md +79 -0
  51. package/src/pilot/references/ai-evals.md +156 -0
  52. package/src/pilot/references/ai-frameworks.md +186 -0
  53. package/src/pilot/references/doc-conflict-engine.md +91 -0
  54. package/src/pilot/references/gate-prompts.md +100 -0
  55. package/src/pilot/references/gates.md +70 -0
  56. package/src/pilot/references/mandatory-initial-read.md +2 -0
  57. package/src/pilot/references/project-skills-discovery.md +19 -0
  58. package/src/pilot/references/revision-loop.md +97 -0
  59. package/src/pilot/references/sketch-interactivity.md +41 -0
  60. package/src/pilot/references/sketch-theme-system.md +94 -0
  61. package/src/pilot/references/sketch-tooling.md +45 -0
  62. package/src/pilot/references/sketch-variant-patterns.md +81 -0
  63. package/src/pilot/references/thinking-models-debug.md +44 -0
  64. package/src/pilot/references/thinking-models-execution.md +50 -0
  65. package/src/pilot/references/thinking-models-planning.md +62 -0
  66. package/src/pilot/references/thinking-models-research.md +50 -0
  67. package/src/pilot/references/thinking-models-verification.md +55 -0
  68. package/src/pilot/templates/AI-SPEC.md +246 -0
  69. package/src/pilot/templates/spec.md +307 -0
  70. package/src/pilot/workflows/ai-integration-phase.md +284 -0
  71. package/src/pilot/workflows/audit-fix.md +175 -0
  72. package/src/pilot/workflows/code-review-fix.md +497 -0
  73. package/src/pilot/workflows/eval-review.md +155 -0
  74. package/src/pilot/workflows/extract_learnings.md +242 -0
  75. package/src/pilot/workflows/import.md +246 -0
  76. package/src/pilot/workflows/ingest-docs.md +328 -0
  77. package/src/pilot/workflows/plan-review-convergence.md +329 -0
  78. package/src/pilot/workflows/scan.md +102 -0
  79. package/src/pilot/workflows/sketch-wrap-up.md +285 -0
  80. package/src/pilot/workflows/sketch.md +360 -0
  81. package/src/pilot/workflows/spec-phase.md +262 -0
  82. package/src/pilot/workflows/spike-wrap-up.md +306 -0
  83. package/src/pilot/workflows/spike.md +452 -0
  84. package/src/pilot/workflows/ultraplan-phase.md +189 -0
  85. package/src/skills/accessibility/SKILL.md +146 -0
  86. package/src/skills/agent-eval/SKILL.md +145 -0
  87. package/src/skills/agent-introspection-debugging/SKILL.md +153 -0
  88. package/src/skills/android-clean-architecture/SKILL.md +339 -0
  89. package/src/skills/api-connector-builder/SKILL.md +120 -0
  90. package/src/skills/code-tour/SKILL.md +236 -0
  91. package/src/skills/compose-multiplatform-patterns/SKILL.md +299 -0
  92. package/src/skills/csharp-testing/SKILL.md +321 -0
  93. package/src/skills/dart-flutter-patterns/SKILL.md +563 -0
  94. package/src/skills/dashboard-builder/SKILL.md +108 -0
  95. package/src/skills/dotnet-patterns/SKILL.md +321 -0
  96. package/src/skills/frontend-design/SKILL.md +145 -0
  97. package/src/skills/frontend-slides/SKILL.md +184 -0
  98. package/src/skills/frontend-slides/STYLE_PRESETS.md +330 -0
  99. package/src/skills/gateguard/SKILL.md +121 -0
  100. package/src/skills/github-ops/SKILL.md +144 -0
  101. package/src/skills/hookify-rules/SKILL.md +128 -0
  102. package/src/skills/knowledge-ops/SKILL.md +154 -0
  103. package/src/skills/liquid-glass-design/SKILL.md +279 -0
  104. package/src/skills/nestjs-patterns/SKILL.md +230 -0
  105. package/src/skills/security-bounty-hunter/SKILL.md +99 -0
  106. package/src/skills/swift-actor-persistence/SKILL.md +143 -0
  107. package/src/skills/swift-protocol-di-testing/SKILL.md +190 -0
  108. package/src/skills/swiftui-patterns/SKILL.md +259 -0
  109. package/src/skills/terminal-ops/SKILL.md +109 -0
  110. package/src/skills/ui-demo/SKILL.md +465 -0
@@ -0,0 +1,328 @@
1
+ # Ingest Docs Workflow
2
+
3
+ Scan a repo for mixed planning documents (ADR, PRD, SPEC, DOC), synthesize them into a consolidated context, and bootstrap or merge into `.planning/`.
4
+
5
+ - `[path]` — optional target directory to scan (defaults to repo root)
6
+ - `--mode new|merge` — override auto-detect (defaults: `new` if `.planning/` absent, `merge` if present)
7
+ - `--manifest <file>` — YAML file listing `{path, type, precedence?}` per doc; overrides heuristic classification
8
+ - `--resolve auto|interactive` — conflict resolution (v1: only `auto` is supported; `interactive` is reserved)
9
+
10
+ ---
11
+
12
+ <step name="banner">
13
+
14
+ Display the stage banner:
15
+
16
+ ```
17
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18
+ GSD ► INGEST DOCS
19
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
20
+ ```
21
+
22
+ </step>
23
+
24
+ <step name="parse_arguments">
25
+
26
+ Parse `$ARGUMENTS`:
27
+
28
+ - First positional token (if not a flag) → `SCAN_PATH` (default: `.`)
29
+ - `--mode new|merge` → `MODE` (default: auto-detect)
30
+ - `--manifest <file>` → `MANIFEST_PATH` (optional)
31
+ - `--resolve auto|interactive` → `RESOLVE_MODE` (default: `auto`; reject `interactive` in v1 with message "interactive resolution is planned for a future release")
32
+
33
+ **Validate paths:**
34
+
35
+ ```bash
36
+ case "{SCAN_PATH}" in *..*) echo "SECURITY_ERROR: path contains traversal sequence"; exit 1 ;; esac
37
+ test -d "{SCAN_PATH}" || echo "PATH_NOT_FOUND"
38
+ if [ -n "{MANIFEST_PATH}" ]; then
39
+ case "{MANIFEST_PATH}" in *..*) echo "SECURITY_ERROR: manifest path contains traversal"; exit 1 ;; esac
40
+ test -f "{MANIFEST_PATH}" || echo "MANIFEST_NOT_FOUND"
41
+ fi
42
+ ```
43
+
44
+ **Containment (required):** After resolving `SCAN_PATH` and `MANIFEST_PATH` relative to the repo root, canonicalize each with `realpath` (or platform equivalent) and assert the result is under `realpath("$REPO_ROOT")`. Reject absolute paths outside the repo (e.g. `/tmp`, `C:\Windows`) even when they do not contain `..`.
45
+
46
+ If `PATH_NOT_FOUND` or `MANIFEST_NOT_FOUND`: display error and exit.
47
+
48
+ </step>
49
+
50
+ <step name="init_and_mode_detect">
51
+
52
+ Run the init query:
53
+
54
+ ```bash
55
+ INIT=$(gsd-sdk query init.ingest-docs)
56
+ ```
57
+
58
+ Parse `project_exists`, `planning_exists`, `has_git`, `project_path` from INIT.
59
+
60
+ **Auto-detect MODE** if not set:
61
+ - `planning_exists: true` → `MODE=merge`
62
+ - `planning_exists: false` → `MODE=new`
63
+
64
+ If user passed `--mode new` but `.planning/` already exists: display warning and require explicit confirm via `AskUserQuestion` (approve-revise-abort from `references/gate-prompts.md`) before overwriting.
65
+
66
+ If `has_git: false` and `MODE=new`: initialize git:
67
+ ```bash
68
+ git init
69
+ ```
70
+
71
+ **Detect runtime** using the same pattern as `new-project.md`:
72
+ - execution_context path `/.codex/` → `RUNTIME=codex`
73
+ - `/.gemini/` → `RUNTIME=gemini`
74
+ - `/.opencode/` or `/.config/opencode/` → `RUNTIME=opencode`
75
+ - else → `RUNTIME=claude`
76
+
77
+ Fall back to env vars (`CODEX_HOME`, `GEMINI_CONFIG_DIR`, `OPENCODE_CONFIG_DIR`) if execution_context is unavailable.
78
+
79
+ </step>
80
+
81
+ <step name="discover_docs">
82
+
83
+ Build the doc list from three sources, in order:
84
+
85
+ **1. Manifest (if provided)** — authoritative:
86
+
87
+ Read `MANIFEST_PATH`. Expected YAML shape:
88
+
89
+ ```yaml
90
+ docs:
91
+ - path: docs/adr/0001-db.md
92
+ type: ADR
93
+ precedence: 0 # optional, lower = higher precedence
94
+ - path: docs/prd/auth.md
95
+ type: PRD
96
+ ```
97
+
98
+ Each entry provides `path` (required, relative to repo root) + `type` (required, one of ADR|PRD|SPEC|DOC) + `precedence` (optional integer).
99
+
100
+ **2. Directory conventions** (skipped when manifest is provided):
101
+
102
+ ```bash
103
+ # ADRs
104
+ find {SCAN_PATH} -type f \( -path '*/adr/*' -o -path '*/adrs/*' -o -name 'ADR-*.md' -o -regex '.*/[0-9]\{4\}-.*\.md' \) 2>/dev/null
105
+
106
+ # PRDs
107
+ find {SCAN_PATH} -type f \( -path '*/prd/*' -o -path '*/prds/*' -o -name 'PRD-*.md' \) 2>/dev/null
108
+
109
+ # SPECs / RFCs
110
+ find {SCAN_PATH} -type f \( -path '*/spec/*' -o -path '*/specs/*' -o -path '*/rfc/*' -o -path '*/rfcs/*' -o -name 'SPEC-*.md' -o -name 'RFC-*.md' \) 2>/dev/null
111
+
112
+ # Generic docs (fall-through candidates)
113
+ find {SCAN_PATH} -type f -path '*/docs/*' -name '*.md' 2>/dev/null
114
+ ```
115
+
116
+ De-duplicate the union (a file matched by multiple patterns is one doc).
117
+
118
+ **3. Content heuristics** (run during classification, not here) — the classifier handles frontmatter `type:` and H1 inspection for docs that didn't match a convention.
119
+
120
+ **Cap:** hard limit of 50 docs per invocation (documented v1 constraint). If the discovered set exceeds 50:
121
+
122
+ ```
123
+ GSD > Discovered {N} docs, which exceeds the v1 cap of 50.
124
+ Use --manifest to narrow the set to ≤ 50 files, or run
125
+ /ccp:ingest-docs again with a narrower <path>.
126
+ ```
127
+
128
+ Exit without proceeding.
129
+
130
+ **Display discovered set** and request approval (see `references/gate-prompts.md` — `yes-no-pick` pattern works; or `approve-revise-abort`):
131
+
132
+ ```
133
+ Discovered {N} documents:
134
+ {N} ADR | {N} PRD | {N} SPEC | {N} DOC | {N} unclassified
135
+
136
+ docs/adr/0001-architecture.md [ADR] (from manifest|directory|heuristic)
137
+ docs/adr/0002-database.md [ADR] (directory)
138
+ docs/prd/auth.md [PRD] (manifest)
139
+ ...
140
+ ```
141
+
142
+ **Text mode:** apply the same `--text`/`text_mode` rule as other workflows — replace `AskUserQuestion` with a numbered list.
143
+
144
+ Use `AskUserQuestion` (approve-revise-abort):
145
+ - question: "Proceed with classification of these {N} documents?"
146
+ - header: "Approve?"
147
+ - options: Approve | Revise | Abort
148
+
149
+ On Abort: exit cleanly with "Ingest cancelled."
150
+ On Revise: exit with guidance to re-run with `--manifest` or a narrower path.
151
+
152
+ </step>
153
+
154
+ <step name="classify_parallel">
155
+
156
+ Create staging directory:
157
+
158
+ ```bash
159
+ mkdir -p .planning/intel/classifications/
160
+ ```
161
+
162
+ For each discovered doc, spawn `gsd-doc-classifier` in parallel. In Claude Code, issue all Task calls in a single message with multiple tool uses so the harness runs them concurrently. For Copilot / sequential runtimes, fall back to sequential dispatch.
163
+
164
+ Per-spawn prompt fields:
165
+ - `FILEPATH` — absolute path to the doc
166
+ - `OUTPUT_DIR` — `.planning/intel/classifications/`
167
+ - `MANIFEST_TYPE` — the type from the manifest if present, else omit
168
+ - `MANIFEST_PRECEDENCE` — the precedence integer from the manifest if present, else omit
169
+ - `<required_reading>` — `agents/ccp:doc-classifier.md` (the agent definition itself)
170
+
171
+ Collect the one-line confirmations from each classifier. If any classifier errors out, surface the error and abort without touching `.planning/` further.
172
+
173
+ </step>
174
+
175
+ <step name="synthesize">
176
+
177
+ Spawn `gsd-doc-synthesizer` once:
178
+
179
+ ```
180
+ Task({
181
+ subagent_type: "gsd-doc-synthesizer",
182
+ prompt: "
183
+ CLASSIFICATIONS_DIR: .planning/intel/classifications/
184
+ INTEL_DIR: .planning/intel/
185
+ CONFLICTS_PATH: .planning/INGEST-CONFLICTS.md
186
+ MODE: {MODE}
187
+ EXISTING_CONTEXT: {paths to existing .planning files if MODE=merge, else empty}
188
+ PRECEDENCE: {array from manifest defaults or default ['ADR','SPEC','PRD','DOC']}
189
+
190
+ <required_reading>
191
+ - agents/ccp:doc-synthesizer.md
192
+ - get-shit-done/references/doc-conflict-engine.md
193
+ </required_reading>
194
+ "
195
+ })
196
+ ```
197
+
198
+ The synthesizer writes:
199
+ - `.planning/intel/decisions.md`, `.planning/intel/requirements.md`, `.planning/intel/constraints.md`, `.planning/intel/context.md`
200
+ - `.planning/intel/SYNTHESIS.md`
201
+ - `.planning/INGEST-CONFLICTS.md`
202
+
203
+ </step>
204
+
205
+ <step name="conflict_gate">
206
+
207
+ Read `.planning/INGEST-CONFLICTS.md`. Count entries in each bucket (the synthesizer always writes the three-bucket header; parse the `### BLOCKERS ({N})`, `### WARNINGS ({N})`, `### INFO ({N})` lines).
208
+
209
+ Apply the safety semantics from `references/doc-conflict-engine.md`. Operation noun: `ingest`.
210
+
211
+ **If BLOCKERS > 0:**
212
+
213
+ Render the report to the user, then display:
214
+
215
+ ```
216
+ GSD > BLOCKED: {N} blockers must be resolved before ingest can proceed.
217
+ ```
218
+
219
+ Exit WITHOUT writing PROJECT.md, REQUIREMENTS.md, ROADMAP.md, or STATE.md. The staging intel files remain for inspection. The safety gate holds — no destination files are written when blockers exist.
220
+
221
+ **If WARNINGS > 0 and BLOCKERS = 0:**
222
+
223
+ Render the report, then ask via AskUserQuestion (approve-revise-abort):
224
+ - question: "Review the competing variants above. Resolve manually and proceed, or abort?"
225
+ - header: "Approve?"
226
+ - options: Approve | Abort
227
+
228
+ On Abort: exit cleanly with "Ingest cancelled. Staged intel preserved at `.planning/intel/`."
229
+
230
+ **If BLOCKERS = 0 and WARNINGS = 0:**
231
+
232
+ Proceed to routing silently, or optionally display `GSD > No conflicts. Auto-resolved: {N}.`
233
+
234
+ </step>
235
+
236
+ <step name="route_new_mode">
237
+
238
+ **Applies only when MODE=new.**
239
+
240
+ Audit PROJECT.md field requirements that `gsd-roadmapper` expects. For fields derivable from `.planning/intel/SYNTHESIS.md` (project scope, goals/non-goals, constraints, locked decisions), synthesize from the intel. For fields NOT derivable (project name, developer-facing success metric, target runtime), prompt via `AskUserQuestion` one at a time — minimal question set, no interrogation.
241
+
242
+ Delegate to `gsd-roadmapper`:
243
+
244
+ ```
245
+ Task({
246
+ subagent_type: "gsd-roadmapper",
247
+ prompt: "
248
+ Mode: new-project-from-ingest
249
+ Intel: .planning/intel/SYNTHESIS.md (entry point)
250
+ Per-type intel: .planning/intel/{decisions,requirements,constraints,context}.md
251
+ User-supplied fields: {collected in previous step}
252
+
253
+ Produce:
254
+ - .planning/PROJECT.md
255
+ - .planning/REQUIREMENTS.md
256
+ - .planning/ROADMAP.md
257
+ - .planning/STATE.md
258
+
259
+ Treat ADR-locked decisions as locked in PROJECT.md <decisions> blocks.
260
+ "
261
+ })
262
+ ```
263
+
264
+ </step>
265
+
266
+ <step name="route_merge_mode">
267
+
268
+ **Applies only when MODE=merge.**
269
+
270
+ Load existing `.planning/ROADMAP.md`, `.planning/PROJECT.md`, `.planning/REQUIREMENTS.md`, all `CONTEXT.md` files under `.planning/phases/`.
271
+
272
+ The synthesizer has already hard-blocked on any LOCKED-in-ingest vs LOCKED-in-existing contradiction; if we reach this step, no such blockers remain.
273
+
274
+ Plan the merge:
275
+ - **New requirements** from synthesized `.planning/intel/requirements.md` that do not overlap existing REQUIREMENTS.md entries → append to REQUIREMENTS.md
276
+ - **New decisions** from synthesized `.planning/intel/decisions.md` that do not overlap existing CONTEXT.md `<decisions>` blocks → write to a new phase's CONTEXT.md or append to the next milestone's requirements
277
+ - **New scope** → derive phase additions following the `new-milestone.md` pattern; append phases to `.planning/ROADMAP.md`
278
+
279
+ Preview the merge diff to the user and gate via approve-revise-abort before writing.
280
+
281
+ </step>
282
+
283
+ <step name="finalize">
284
+
285
+ Commit the ingest results:
286
+
287
+ ```bash
288
+ gsd-sdk query commit "docs: ingest {N} docs from {SCAN_PATH} (#2387)" \
289
+ .planning/PROJECT.md \
290
+ .planning/REQUIREMENTS.md \
291
+ .planning/ROADMAP.md \
292
+ .planning/STATE.md \
293
+ .planning/intel/ \
294
+ .planning/INGEST-CONFLICTS.md
295
+ ```
296
+
297
+ (For merge mode, substitute the actual set of modified files.)
298
+
299
+ Display completion:
300
+
301
+ ```
302
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
303
+ GSD ► INGEST DOCS COMPLETE
304
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
305
+ ```
306
+
307
+ Show:
308
+ - Mode ran (new or merge)
309
+ - Docs ingested (count + type breakdown)
310
+ - Decisions locked, requirements created, constraints captured
311
+ - Conflict report path (`.planning/INGEST-CONFLICTS.md`)
312
+ - Next step: `/ccp:plan-phase 1` (new mode) or `/ccp:plan-phase N` (merge, pointing at the first newly-added phase)
313
+
314
+ </step>
315
+
316
+ ---
317
+
318
+ ## Anti-Patterns
319
+
320
+ Do NOT:
321
+ - Violate the shared conflict-engine contract in `references/doc-conflict-engine.md` (no markdown tables, no new severity labels, no bypass of the BLOCKER gate)
322
+ - Write PROJECT.md, REQUIREMENTS.md, ROADMAP.md, or STATE.md when BLOCKERs exist in the conflict report
323
+ - Skip the 50-doc cap — larger sets must use `--manifest` to narrow the scope
324
+ - Auto-resolve LOCKED-vs-LOCKED ADR contradictions — those are BLOCKERs in both modes
325
+ - Merge competing PRD acceptance variants into a combined criterion — preserve all variants for user resolution
326
+ - Bypass the discovery approval gate — users must see the classified doc list before classifiers spawn
327
+ - Skip path validation on `SCAN_PATH` or `MANIFEST_PATH`
328
+ - Implement `--resolve interactive` in this v1 — the flag is reserved; reject with a future-release message
@@ -0,0 +1,329 @@
1
+ <purpose>
2
+ Cross-AI plan convergence loop — automates the manual chain:
3
+ gsd-plan-phase N → gsd-review N --codex → gsd-plan-phase N --reviews → gsd-review N --codex → ...
4
+ Each step runs inside an isolated Agent that calls the corresponding Skill.
5
+ Orchestrator only does: init, loop control, parse CYCLE_SUMMARY for HIGH count, stall detection, escalation.
6
+ </purpose>
7
+
8
+ <required_reading>
9
+ Read all files referenced by the invoking prompt's execution_context before starting.
10
+
11
+ @$HOME/.claude/pilot/references/revision-loop.md
12
+ @$HOME/.claude/pilot/references/gates.md
13
+ @$HOME/.claude/pilot/references/agent-contracts.md
14
+ </required_reading>
15
+
16
+ <process>
17
+
18
+ ## 1. Parse and Normalize Arguments
19
+
20
+ Extract from $ARGUMENTS: phase number, reviewer flags (`--codex`, `--gemini`, `--claude`, `--opencode`, `--ollama`, `--lm-studio`, `--llama-cpp`, `--all`), `--max-cycles N`, `--text`, `--ws`.
21
+
22
+ ```bash
23
+ PHASE=$(echo "$ARGUMENTS" | grep -oE '[0-9]+\.?[0-9]*' | head -1)
24
+
25
+ REVIEWER_FLAGS=""
26
+ echo "$ARGUMENTS" | grep -q '\-\-codex' && REVIEWER_FLAGS="$REVIEWER_FLAGS --codex"
27
+ echo "$ARGUMENTS" | grep -q '\-\-gemini' && REVIEWER_FLAGS="$REVIEWER_FLAGS --gemini"
28
+ echo "$ARGUMENTS" | grep -q '\-\-claude' && REVIEWER_FLAGS="$REVIEWER_FLAGS --claude"
29
+ echo "$ARGUMENTS" | grep -q '\-\-opencode' && REVIEWER_FLAGS="$REVIEWER_FLAGS --opencode"
30
+ echo "$ARGUMENTS" | grep -q '\-\-ollama' && REVIEWER_FLAGS="$REVIEWER_FLAGS --ollama"
31
+ echo "$ARGUMENTS" | grep -q '\-\-lm-studio' && REVIEWER_FLAGS="$REVIEWER_FLAGS --lm-studio"
32
+ echo "$ARGUMENTS" | grep -q '\-\-llama-cpp' && REVIEWER_FLAGS="$REVIEWER_FLAGS --llama-cpp"
33
+ echo "$ARGUMENTS" | grep -q '\-\-all' && REVIEWER_FLAGS="$REVIEWER_FLAGS --all"
34
+ if [ -z "$REVIEWER_FLAGS" ]; then REVIEWER_FLAGS="--codex"; fi
35
+
36
+ MAX_CYCLES=$(echo "$ARGUMENTS" | grep -oE '\-\-max-cycles\s+[0-9]+' | awk '{print $2}')
37
+ if [ -z "$MAX_CYCLES" ]; then MAX_CYCLES=3; fi
38
+
39
+ GSD_WS=""
40
+ echo "$ARGUMENTS" | grep -qE '\-\-ws\s+\S+' && GSD_WS=$(echo "$ARGUMENTS" | grep -oE '\-\-ws\s+\S+')
41
+ ```
42
+
43
+ ## 1.5. Config Gate (feature disabled by default)
44
+
45
+ ```bash
46
+ CONVERGENCE_ENABLED=$(gsd-sdk query config-get workflow.plan_review_convergence 2>/dev/null || echo "false")
47
+ ```
48
+
49
+ **If `CONVERGENCE_ENABLED` is not `"true"`:** Display and exit:
50
+
51
+ ```text
52
+ gsd-plan-review-convergence is disabled (workflow.plan_review_convergence=false).
53
+
54
+ This feature automates the plan→review→replan loop using external AI reviewers.
55
+ Enable it with:
56
+
57
+ gsd config-set workflow.plan_review_convergence true
58
+
59
+ Then re-run: /ccp:plan-review-convergence {PHASE}
60
+ ```
61
+
62
+ ## 2. Initialize
63
+
64
+ ```bash
65
+ INIT=$(node "$HOME/.claude/pilot/bin/ccp:tools.cjs" init plan-phase "$PHASE")
66
+ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
67
+ ```
68
+
69
+ Parse JSON for: `phase_dir`, `phase_number`, `padded_phase`, `phase_name`, `has_plans`, `plan_count`, `commit_docs`, `text_mode`, `response_language`.
70
+
71
+ **If `response_language` is set:** All user-facing output should be in `{response_language}`.
72
+
73
+ Set `TEXT_MODE=true` if `--text` is present in $ARGUMENTS OR `text_mode` from init JSON is `true`. When `TEXT_MODE` is active, replace every `AskUserQuestion` call with a plain-text numbered list and ask the user to type their choice number.
74
+
75
+ ## 3. Validate Phase + Pre-flight Gate
76
+
77
+ ```bash
78
+ PHASE_INFO=$(node "$HOME/.claude/pilot/bin/ccp:tools.cjs" roadmap get-phase "${PHASE}")
79
+ ```
80
+
81
+ **If `found` is false:** Error with available phases. Exit.
82
+
83
+ Display startup banner:
84
+
85
+ ```text
86
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
87
+ GSD ► PLAN CONVERGENCE — Phase {phase_number}
88
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
89
+
90
+ Reviewers: {REVIEWER_FLAGS}
91
+ Max cycles: {MAX_CYCLES}
92
+ ```
93
+
94
+ ## 4. Initial Planning (if no plans exist)
95
+
96
+ **If `has_plans` is true:** Skip to step 5. Display: `Plans found: {plan_count} PLAN.md files — skipping initial planning.`
97
+
98
+ **If `has_plans` is false:**
99
+
100
+ Display: `◆ No plans found — spawning initial planning agent...`
101
+
102
+ ```text
103
+ Agent(
104
+ description="Initial planning Phase {PHASE}",
105
+ prompt="Run /ccp:plan-phase for Phase {PHASE}.
106
+
107
+ Execute: Skill(skill='gsd-plan-phase', args='{PHASE} {GSD_WS}')
108
+
109
+ Complete the full planning workflow. Do NOT return until planning is complete and PLAN.md files are committed.",
110
+ mode="auto"
111
+ )
112
+ ```
113
+
114
+ After agent returns, verify plans were created:
115
+ ```bash
116
+ PLAN_COUNT=$(ls ${phase_dir}/${padded_phase}-*-PLAN.md 2>/dev/null | wc -l)
117
+ ```
118
+
119
+ If PLAN_COUNT == 0: Error — initial planning failed. Exit.
120
+
121
+ Display: `Initial planning complete: ${PLAN_COUNT} PLAN.md files created.`
122
+
123
+ ## 5. Convergence Loop
124
+
125
+ Initialize loop variables:
126
+
127
+ ```text
128
+ cycle = 0
129
+ prev_high_count = Infinity
130
+ ```
131
+
132
+ ### 5a. Review (Spawn Agent)
133
+
134
+ Increment `cycle`.
135
+
136
+ Display: `◆ Cycle {cycle}/{MAX_CYCLES} — spawning review agent...`
137
+
138
+ ```text
139
+ Agent(
140
+ description="Cross-AI review Phase {PHASE} cycle {cycle}",
141
+ prompt="Run /ccp:review for Phase {PHASE}.
142
+
143
+ Execute: Skill(skill='gsd-review', args='--phase {PHASE} {REVIEWER_FLAGS} {GSD_WS}')
144
+
145
+ Complete the full review workflow. Do NOT return until REVIEWS.md is committed.
146
+
147
+ IMPORTANT — CYCLE_SUMMARY contract (required):
148
+ Your final response MUST include a machine-readable line of exactly this form:
149
+
150
+ CYCLE_SUMMARY: current_high=<N>
151
+
152
+ Where <N> is the integer count of HIGH-severity concerns that REMAIN UNRESOLVED in this cycle's findings.
153
+
154
+ Counting rules:
155
+ INCLUDE in the count:
156
+ - Newly raised HIGHs in this cycle
157
+ - PARTIALLY RESOLVED HIGHs: concern acknowledged and a mitigation is in progress, but not yet verified/completed
158
+ - Previously raised HIGHs that are still unresolved
159
+
160
+ EXCLUDE from the count:
161
+ - FULLY RESOLVED HIGHs: concern addressed with verification complete (closed ticket, verification log, or reviewer sign-off)
162
+ - HIGH mentions in retrospective/summary tables comparing cycles
163
+ - Quoted excerpts from prior reviews referencing past HIGH items
164
+
165
+ Definitions:
166
+ PARTIALLY RESOLVED — concern acknowledged and mitigation is in progress but not yet verified/completed (e.g., open ticket exists but fix not landed).
167
+ FULLY RESOLVED — concern addressed with verification complete (closed ticket, verification log, or explicit reviewer sign-off confirming closure).
168
+
169
+ Your final response MUST also include this section immediately after the CYCLE_SUMMARY line:
170
+
171
+ ## Current HIGH Concerns
172
+ [List each unresolved HIGH with a brief description, one per bullet]
173
+ [If none: write exactly 'None.']",
174
+ mode="auto"
175
+ )
176
+ ```
177
+
178
+ After agent returns, verify REVIEWS.md exists:
179
+ ```bash
180
+ REVIEWS_FILE=$(ls ${phase_dir}/${padded_phase}-REVIEWS.md 2>/dev/null)
181
+ ```
182
+
183
+ If REVIEWS_FILE is empty: Error — review agent did not produce REVIEWS.md. Exit.
184
+
185
+ ### 5b. Extract HIGH Count from CYCLE_SUMMARY Contract
186
+
187
+ **Do NOT grep REVIEWS.md for HIGH count.** REVIEWS.md accumulates history across cycles — resolved HIGHs from prior cycles remain in the file as audit trail, inflating a raw grep count and causing false stall detection.
188
+
189
+ Parse HIGH_COUNT from the review agent's return message via the CYCLE_SUMMARY contract:
190
+
191
+ ```bash
192
+ # Extract the integer from "CYCLE_SUMMARY: current_high=N" in the agent's return message
193
+ HIGH_COUNT=$(echo "$REVIEW_AGENT_RETURN" | grep -oE 'CYCLE_SUMMARY:\s*current_high=[0-9]+' | head -1 | grep -oE '[0-9]+$')
194
+
195
+ if [ -z "$HIGH_COUNT" ]; then
196
+ # Distinguish malformed contract from completely absent contract
197
+ if echo "$REVIEW_AGENT_RETURN" | grep -q 'CYCLE_SUMMARY:'; then
198
+ echo "CYCLE_SUMMARY present but current_high is malformed — expected integer, got non-numeric value. Retry or switch reviewer."
199
+ else
200
+ echo "Review agent did not honor the CYCLE_SUMMARY contract — cannot determine HIGH count. Retry or switch reviewer."
201
+ fi
202
+ exit 1
203
+ fi
204
+
205
+ # Extract the ## Current HIGH Concerns section from the agent's return message
206
+ HIGH_LINES=$(echo "$REVIEW_AGENT_RETURN" | awk '/^## Current HIGH Concerns/{found=1; next} found && /^##/{exit} found{print}')
207
+
208
+ if [ "${HIGH_COUNT}" -gt 0 ] && [ -z "${HIGH_LINES}" ]; then
209
+ echo "⚠ Review agent's CYCLE_SUMMARY reports ${HIGH_COUNT} HIGHs but did not provide ## Current HIGH Concerns section — continuing with incomplete escalation details."
210
+ fi
211
+ ```
212
+
213
+ **If HIGH_COUNT == 0 (converged):**
214
+
215
+ ```bash
216
+ node "$HOME/.claude/pilot/bin/ccp:tools.cjs" state planned-phase --phase "${PHASE}" --name "${phase_name}" --plans "${PLAN_COUNT}"
217
+ ```
218
+
219
+ Display:
220
+ ```text
221
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
222
+ GSD ► CONVERGENCE COMPLETE ✓
223
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
224
+
225
+ Phase {phase_number} converged in {cycle} cycle(s).
226
+ No HIGH concerns remaining.
227
+
228
+ REVIEWS.md: {REVIEWS_FILE}
229
+ Next: /ccp:execute-phase {PHASE}
230
+ ```
231
+
232
+ Exit — convergence achieved.
233
+
234
+ **If HIGH_COUNT > 0:** Continue to 5c.
235
+
236
+ ### 5c. Stall Detection + Escalation Check
237
+
238
+ Display: `◆ Cycle {cycle}/{MAX_CYCLES} — {HIGH_COUNT} HIGH concerns found`
239
+
240
+ **Stall detection:** If `HIGH_COUNT >= prev_high_count`:
241
+ ```text
242
+ ⚠ Convergence stalled — HIGH concern count not decreasing
243
+ ({HIGH_COUNT} HIGH concerns, previous cycle had {prev_high_count})
244
+ ```
245
+
246
+ **Max cycles check:** If `cycle >= MAX_CYCLES`:
247
+
248
+ If `TEXT_MODE` is true, present as plain-text numbered list:
249
+ ```text
250
+ Plan convergence did not complete after {MAX_CYCLES} cycles.
251
+ {HIGH_COUNT} HIGH concerns remain:
252
+
253
+ {HIGH_LINES}
254
+
255
+ How would you like to proceed?
256
+
257
+ 1. Proceed anyway — Accept plans with remaining HIGH concerns and move to execution
258
+ 2. Manual review — Stop here, review REVIEWS.md and address concerns manually
259
+
260
+ Enter number:
261
+ ```
262
+
263
+ Otherwise use AskUserQuestion:
264
+ ```js
265
+ AskUserQuestion([
266
+ {
267
+ question: "Plan convergence did not complete after {MAX_CYCLES} cycles. {HIGH_COUNT} HIGH concerns remain:\n\n{HIGH_LINES}\n\nHow would you like to proceed?",
268
+ header: "Convergence",
269
+ multiSelect: false,
270
+ options: [
271
+ { label: "Proceed anyway", description: "Accept plans with remaining HIGH concerns and move to execution" },
272
+ { label: "Manual review", description: "Stop here — review REVIEWS.md and address concerns manually" }
273
+ ]
274
+ }
275
+ ])
276
+ ```
277
+
278
+ If "Proceed anyway": Display final status and exit.
279
+ If "Manual review":
280
+ ```text
281
+ Review the concerns in: {REVIEWS_FILE}
282
+
283
+ To replan manually: /ccp:plan-phase {PHASE} --reviews
284
+ To restart loop: /ccp:plan-review-convergence {PHASE} {REVIEWER_FLAGS}
285
+ ```
286
+ Exit workflow.
287
+
288
+ ### 5d. Replan (Spawn Agent)
289
+
290
+ **If under max cycles:**
291
+
292
+ Update `prev_high_count = HIGH_COUNT`.
293
+
294
+ Display: `◆ Spawning replan agent with review feedback...`
295
+
296
+ ```text
297
+ Agent(
298
+ description="Replan Phase {PHASE} with review feedback cycle {cycle}",
299
+ prompt="Run /ccp:plan-phase with --reviews for Phase {PHASE}.
300
+
301
+ Execute: Skill(skill='gsd-plan-phase', args='{PHASE} --reviews --skip-research {GSD_WS}')
302
+
303
+ This will replan incorporating cross-AI review feedback from REVIEWS.md.
304
+ Do NOT return until replanning is complete and updated PLAN.md files are committed.
305
+
306
+ IMPORTANT: When gsd-plan-phase outputs '## PLANNING COMPLETE', that means replanning is done. Return at that point.",
307
+ mode="auto"
308
+ )
309
+ ```
310
+
311
+ After agent returns → go back to **step 5a** (review again).
312
+
313
+ </process>
314
+
315
+ <success_criteria>
316
+ - [ ] Config gate checked before running — exits with enable instructions if workflow.plan_review_convergence is false
317
+ - [ ] Initial planning via Agent → Skill("gsd-plan-phase") if no plans exist
318
+ - [ ] Review via Agent → Skill("gsd-review") — isolated, not inline; {GSD_WS} forwarded
319
+ - [ ] Replan via Agent → Skill("gsd-plan-phase --reviews") — isolated, not inline
320
+ - [ ] Orchestrator only does: init, config gate, loop control, parse CYCLE_SUMMARY for HIGH count, stall detection, escalation
321
+ - [ ] HIGH count extracted from review agent's CYCLE_SUMMARY return message (not by grepping REVIEWS.md)
322
+ - [ ] Review agent prompt defines CYCLE_SUMMARY: current_high=<N> contract with PARTIALLY/FULLY RESOLVED definitions
323
+ - [ ] Abort with clear error if CYCLE_SUMMARY is absent; distinguish malformed from absent
324
+ - [ ] Warn if HIGH_COUNT > 0 but ## Current HIGH Concerns section is absent from return message
325
+ - [ ] Each Agent fully completes its Skill before returning
326
+ - [ ] Loop exits on: no HIGH concerns (converged) OR max cycles (escalation)
327
+ - [ ] Stall detection reported when HIGH count not decreasing
328
+ - [ ] STATE.md updated on convergence completion
329
+ </success_criteria>