@ktpartners/dgs-platform 2.9.0 → 3.0.4

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 (93) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +26 -1
  3. package/agents/dgs-plan-checker.md +29 -3
  4. package/agents/dgs-planner.md +10 -0
  5. package/commands/dgs/abandon-quick.md +28 -0
  6. package/commands/dgs/add-tests.md +2 -2
  7. package/commands/dgs/audit-milestone.md +2 -2
  8. package/commands/dgs/capture-principle.md +11 -11
  9. package/commands/dgs/cleanup.md +2 -2
  10. package/commands/dgs/complete-milestone.md +11 -11
  11. package/commands/dgs/complete-quick.md +28 -0
  12. package/commands/dgs/create-milestone-job.md +2 -2
  13. package/commands/dgs/debug.md +3 -3
  14. package/commands/dgs/develop-idea.md +1 -1
  15. package/commands/dgs/fast.md +3 -1
  16. package/commands/dgs/health.md +1 -1
  17. package/commands/dgs/map-codebase.md +6 -6
  18. package/commands/dgs/new-milestone.md +5 -5
  19. package/commands/dgs/new-project.md +6 -6
  20. package/commands/dgs/plan-milestone-gaps.md +1 -1
  21. package/commands/dgs/progress.md +3 -3
  22. package/commands/dgs/quick-abandon.md +8 -0
  23. package/commands/dgs/quick-complete.md +8 -0
  24. package/commands/dgs/quick.md +10 -3
  25. package/commands/dgs/research-idea.md +2 -2
  26. package/commands/dgs/research-phase.md +3 -3
  27. package/commands/dgs/switch-project.md +1 -1
  28. package/commands/dgs/write-spec.md +3 -3
  29. package/deliver-great-systems/bin/dgs-tools.cjs +284 -30
  30. package/deliver-great-systems/bin/lib/commands.cjs +316 -31
  31. package/deliver-great-systems/bin/lib/commands.test.cjs +336 -0
  32. package/deliver-great-systems/bin/lib/config.cjs +39 -6
  33. package/deliver-great-systems/bin/lib/context.cjs +120 -0
  34. package/deliver-great-systems/bin/lib/core.cjs +28 -11
  35. package/deliver-great-systems/bin/lib/execution.cjs +49 -17
  36. package/deliver-great-systems/bin/lib/flat-migration.test.cjs +396 -0
  37. package/deliver-great-systems/bin/lib/ideas.cjs +206 -91
  38. package/deliver-great-systems/bin/lib/ideas.test.cjs +244 -1
  39. package/deliver-great-systems/bin/lib/init.cjs +306 -39
  40. package/deliver-great-systems/bin/lib/init.test.cjs +416 -6
  41. package/deliver-great-systems/bin/lib/jobs.cjs +124 -21
  42. package/deliver-great-systems/bin/lib/jobs.test.cjs +193 -74
  43. package/deliver-great-systems/bin/lib/migration.cjs +409 -1
  44. package/deliver-great-systems/bin/lib/migration.test.cjs +158 -1
  45. package/deliver-great-systems/bin/lib/milestone.cjs +54 -29
  46. package/deliver-great-systems/bin/lib/phase.cjs +128 -2
  47. package/deliver-great-systems/bin/lib/phase.test.cjs +420 -0
  48. package/deliver-great-systems/bin/lib/projects.cjs +28 -8
  49. package/deliver-great-systems/bin/lib/projects.test.cjs +86 -0
  50. package/deliver-great-systems/bin/lib/quick.cjs +584 -0
  51. package/deliver-great-systems/bin/lib/quick.test.cjs +596 -0
  52. package/deliver-great-systems/bin/lib/repos.cjs +25 -1
  53. package/deliver-great-systems/bin/lib/roadmap.cjs +34 -13
  54. package/deliver-great-systems/bin/lib/specs.cjs +3 -81
  55. package/deliver-great-systems/bin/lib/state-transition-gate.test.cjs +160 -0
  56. package/deliver-great-systems/bin/lib/state.cjs +142 -54
  57. package/deliver-great-systems/bin/lib/sync.cjs +75 -0
  58. package/deliver-great-systems/bin/lib/verify.cjs +80 -1
  59. package/deliver-great-systems/bin/lib/worktrees.cjs +764 -0
  60. package/deliver-great-systems/bin/lib/worktrees.test.cjs +887 -0
  61. package/deliver-great-systems/templates/claude-md.md +16 -0
  62. package/deliver-great-systems/workflows/abandon-quick.md +89 -0
  63. package/deliver-great-systems/workflows/add-idea.md +3 -3
  64. package/deliver-great-systems/workflows/add-tests.md +14 -0
  65. package/deliver-great-systems/workflows/add-todo.md +1 -0
  66. package/deliver-great-systems/workflows/approve-spec.md +25 -4
  67. package/deliver-great-systems/workflows/audit-phase.md +15 -5
  68. package/deliver-great-systems/workflows/cancel-job.md +1 -1
  69. package/deliver-great-systems/workflows/check-todos.md +2 -3
  70. package/deliver-great-systems/workflows/complete-milestone.md +197 -22
  71. package/deliver-great-systems/workflows/complete-quick.md +68 -0
  72. package/deliver-great-systems/workflows/consolidate-ideas.md +1 -1
  73. package/deliver-great-systems/workflows/create-milestone-job.md +4 -4
  74. package/deliver-great-systems/workflows/develop-idea.md +11 -11
  75. package/deliver-great-systems/workflows/diagnose-issues.md +14 -0
  76. package/deliver-great-systems/workflows/discuss-idea.md +1 -1
  77. package/deliver-great-systems/workflows/execute-phase.md +121 -32
  78. package/deliver-great-systems/workflows/execute-plan.md +12 -21
  79. package/deliver-great-systems/workflows/help.md +2 -2
  80. package/deliver-great-systems/workflows/init-product.md +2 -18
  81. package/deliver-great-systems/workflows/new-milestone.md +30 -24
  82. package/deliver-great-systems/workflows/progress-all.md +133 -0
  83. package/deliver-great-systems/workflows/quick-abandon.md +89 -0
  84. package/deliver-great-systems/workflows/quick-complete.md +68 -0
  85. package/deliver-great-systems/workflows/quick.md +152 -23
  86. package/deliver-great-systems/workflows/refine-spec.md +1 -1
  87. package/deliver-great-systems/workflows/research-idea.md +8 -8
  88. package/deliver-great-systems/workflows/resume-project.md +2 -2
  89. package/deliver-great-systems/workflows/run-job.md +8 -8
  90. package/deliver-great-systems/workflows/validate-phase.md +39 -1
  91. package/deliver-great-systems/workflows/verify-work.md +14 -0
  92. package/deliver-great-systems/workflows/write-spec.md +2 -2
  93. package/package.json +1 -1
@@ -24,7 +24,7 @@ Use `TIER_FILES` JSON `files` array for project context (PROJECT.md, STATE.md, c
24
24
  Parse `$ARGUMENTS` to extract version and flags.
25
25
 
26
26
  - **Version:** First non-flag argument (e.g., `v6`, `v6.0`). If omitted, auto-detection happens in the preview step.
27
- - **--no-check flag:** If present, omit audit-milestone and complete-milestone steps from the generated job.
27
+ - **--no-check flag:** If present, omit the audit-milestone step from the generated job.
28
28
 
29
29
  ```bash
30
30
  # Pseudocode for argument parsing:
@@ -97,7 +97,7 @@ Present in this format:
97
97
  5. execute-phase 52
98
98
  6. verify-work 52
99
99
  ...
100
- N. complete-milestone v6.0
100
+ N. audit-milestone v6.0
101
101
 
102
102
  Create this job? (yes/no)
103
103
  ```
@@ -123,13 +123,13 @@ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs jobs create-milestone VER
123
123
  2. Commit the job file:
124
124
 
125
125
  ```bash
126
- node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs(50): create milestone job {version}" --files jobs/pending/milestone-{version}.md
126
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs(50): create milestone job {version}" --files jobs/milestone-{version}.md
127
127
  ```
128
128
 
129
129
  3. Display success and next steps:
130
130
 
131
131
  ```
132
- Job created: jobs/pending/milestone-{version}.md
132
+ Job created: jobs/milestone-{version}.md
133
133
 
134
134
  ---
135
135
 
@@ -89,7 +89,7 @@ Also check for prior research document:
89
89
  ```bash
90
90
  # Derive slug from filename (strip id prefix and .md suffix)
91
91
  SLUG=$(echo "${filename}" | sed 's/^[0-9]*-//' | sed 's/\.md$//')
92
- RESEARCH_DOC="${project_root}/docs/ideas/pending/${SLUG}-research.md"
92
+ RESEARCH_DOC="${project_root}/docs/ideas/${SLUG}-research.md"
93
93
  ```
94
94
  If the research document file exists, read it for prior research context.
95
95
 
@@ -281,7 +281,7 @@ Per CONTEXT.md: idea body is NOT updated on partial save.
281
281
  <step name="discussion_commit">
282
282
  Commit the updated idea file immediately after discussion:
283
283
  ```bash
284
- node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: discuss idea #${id} — ${title}" --files ${project_root}/ideas/${state}/${filename}
284
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: discuss idea #${id} — ${title}" --files ${project_root}/ideas/${filename}
285
285
  ```
286
286
 
287
287
  **If `partial = true`** (user exited mid-discussion):
@@ -392,10 +392,10 @@ Create (or overwrite) the research document.
392
392
 
393
393
  Ensure directory exists:
394
394
  ```bash
395
- mkdir -p ${project_root}/docs/ideas/pending
395
+ mkdir -p ${project_root}/docs/ideas
396
396
  ```
397
397
 
398
- Write the research document to `${project_root}/docs/ideas/pending/${SLUG}-research.md` using the Write tool.
398
+ Write the research document to `${project_root}/docs/ideas/${SLUG}-research.md` using the Write tool.
399
399
 
400
400
  Document structure:
401
401
  ```markdown
@@ -456,7 +456,7 @@ Build the entry JSON:
456
456
  "summary": "{Actionable summary paragraph}",
457
457
  "keyFindings": "- {finding 1}\n- {finding 2}\n- {finding 3}",
458
458
  "recommendation": "{Strong recommendation or neutral options presentation}",
459
- "documentLink": "${project_root}/docs/ideas/pending/${SLUG}-research.md",
459
+ "documentLink": "${project_root}/docs/ideas/${SLUG}-research.md",
460
460
  "outcome": "{Recommended next step: 'Ready for spec', 'Needs more discussion', 'Not feasible', etc.}"
461
461
  }
462
462
  ```
@@ -472,7 +472,7 @@ Parse the JSON result to confirm success.
472
472
  <step name="research_commit">
473
473
  Commit both the research document and the updated idea file:
474
474
  ```bash
475
- node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: research idea #${id} -- ${title}" --files ${project_root}/docs/ideas/pending/${SLUG}-research.md ${project_root}/ideas/${state}/${filename}
475
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: research idea #${id} -- ${title}" --files ${project_root}/docs/ideas/${SLUG}-research.md ${project_root}/ideas/${filename}
476
476
  ```
477
477
  </step>
478
478
 
@@ -490,8 +490,8 @@ Research: ${recommendation}
490
490
  Next step: ${contextAwareNextStep}
491
491
 
492
492
  Files:
493
- - ${project_root}/ideas/${state}/${filename}
494
- - ${project_root}/docs/ideas/pending/${SLUG}-research.md
493
+ - ${project_root}/ideas/${filename}
494
+ - ${project_root}/docs/ideas/${SLUG}-research.md
495
495
  ```
496
496
 
497
497
  **If only discussion ran** (research skipped by decision routing, user choice, or partial exit):
@@ -503,7 +503,7 @@ Decision: ${decision}
503
503
  Next step: ${contextAwareNextStep}
504
504
 
505
505
  Files:
506
- - ${project_root}/ideas/${state}/${filename}
506
+ - ${project_root}/ideas/${filename}
507
507
  ```
508
508
 
509
509
  **If only research ran** (user chose "Just research" in assess_history):
@@ -516,8 +516,8 @@ Research: ${recommendation}
516
516
  Next step: ${contextAwareNextStep}
517
517
 
518
518
  Files:
519
- - ${project_root}/ideas/${state}/${filename}
520
- - ${project_root}/docs/ideas/pending/${SLUG}-research.md
519
+ - ${project_root}/ideas/${filename}
520
+ - ${project_root}/docs/ideas/${SLUG}-research.md
521
521
  ```
522
522
 
523
523
  **Context-aware next step logic:**
@@ -33,6 +33,20 @@ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" contex
33
33
  ```
34
34
 
35
35
  Store the file list for passing to debug sub-agents in `<files_to_read>` blocks.
36
+
37
+ **Worktree-aware code directory resolution (resolveCodeContext):**
38
+
39
+ For each registered code repo, resolve the correct working directory. When a milestone or quick worktree is active, debug investigation must target the worktree directory, not the main checkout, so the debugger examines the correct code and can reproduce issues in the right context.
40
+
41
+ ```javascript
42
+ // In the agent's execution context, use resolveCodeContext to determine the code directory:
43
+ const { resolveCodeContext } = require('./bin/lib/context.cjs');
44
+ const ctx = resolveCodeContext(planningRoot, repoName);
45
+ // ctx.type: 'main' | 'milestone' | 'quick'
46
+ // ctx.directory: absolute path to the correct working directory
47
+ ```
48
+
49
+ Pass `ctx.directory` to debug sub-agents so they investigate code in the correct location.
36
50
  </step>
37
51
 
38
52
  <step name="parse_gaps">
@@ -86,7 +86,7 @@ IDEA_DOCS_DIR="${IDEA_DIR}/docs"
86
86
  If a flat structure is used (ideas stored as files, not directories), derive from the filename:
87
87
  ```bash
88
88
  IDEA_SLUG=$(echo "${filename}" | sed 's/^[0-9]*-//' | sed 's/\.md$//')
89
- IDEA_DOCS_DIR="$(dirname "$(dirname "${path}")")/docs/ideas/pending/${IDEA_SLUG}"
89
+ IDEA_DOCS_DIR="$(dirname "$(dirname "${path}")")/docs/ideas/${IDEA_SLUG}"
90
90
  ```
91
91
 
92
92
  Check both paths. Use whichever exists.
@@ -9,7 +9,7 @@ Orchestrator coordinates, not executes. Each subagent loads the full execute-pla
9
9
  </core_principle>
10
10
 
11
11
  <hard_boundary>
12
- **CRITICAL SCOPE CONSTRAINT:** You execute ONLY the single phase specified in $ARGUMENTS. After that phase completes (plans executed, verification done, roadmap updated), you MUST STOP. Do NOT read the roadmap to discover subsequent phases. Do NOT execute transition.md unless `--auto` flag is present. Do NOT advance to phase N+1. Violating this boundary causes duplicate work and corrupts job state.
12
+ **CRITICAL SCOPE CONSTRAINT:** You execute ONLY the single phase specified in $ARGUMENTS. After that phase finishes (plans executed, verification done, roadmap updated), you MUST STOP. Do NOT read the roadmap to discover subsequent phases. Do NOT execute transition.md unless `--auto` flag is present. Do NOT advance to phase N+1. Violating this boundary causes duplicate work and corrupts job state.
13
13
  </hard_boundary>
14
14
 
15
15
  <required_reading>
@@ -27,7 +27,7 @@ INIT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" init execute
27
27
  if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
28
28
  ```
29
29
 
30
- Parse JSON for: `executor_model`, `verifier_model`, `commit_docs`, `parallelization`, `branching_strategy`, `branch_name`, `base_branch`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `plans`, `incomplete_plans`, `plan_count`, `incomplete_count`, `state_exists`, `roadmap_exists`, `author`, `phase_req_ids`, `sync_push`, `sync_pull`, `cadence_push`, `cadence_pull`.
30
+ Parse JSON for: `executor_model`, `verifier_model`, `commit_docs`, `parallelization`, `branching_strategy`, `branch_name`, `base_branch`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `plans`, `incomplete_plans`, `plan_count`, `incomplete_count`, `state_exists`, `roadmap_exists`, `author`, `phase_req_ids`, `sync_push`, `sync_pull`, `cadence_push`, `cadence_pull`, `milestone_slug`, `milestone_version`, `milestone_name`.
31
31
 
32
32
  **Load execution tier context:**
33
33
 
@@ -119,34 +119,122 @@ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" sync workflow-pull
119
119
  - If No: skip pull, continue
120
120
  </step>
121
121
 
122
- <step name="handle_branching">
123
- Check `branching_strategy` from init:
122
+ <step name="handle_worktree">
123
+ Check if this phase is part of a milestone with code repos registered in REPOS.md.
124
124
 
125
- **"none":** Skip, continue on current branch.
125
+ **If no REPOS.md or no code repos:** Skip worktree creation entirely. Log: `No code repos registered — skipping worktree setup.` Continue to validate_phase.
126
+
127
+ **If REPOS.md has code repos and `milestone_slug` is present:**
128
+
129
+ Use `milestone_slug` from init JSON (already sanitized).
130
+
131
+ **1. Check for existing worktree:**
126
132
 
127
- **"phase" or "milestone":** Use pre-computed `branch_name` from init for the product folder:
128
133
  ```bash
129
- git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
134
+ WORKTREE_LIST=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees list 2>/dev/null)
130
135
  ```
131
136
 
132
- All subsequent commits go to this branch. User handles merging.
137
+ Parse the JSON array. Look for an entry matching `milestone_slug`.
133
138
 
134
- **Code repo branching (base_branch):**
139
+ **If worktree exists with `setup_complete: true` for all repos:**
140
+ ```
141
+ Using existing milestone worktree for ${MILESTONE_SLUG}
142
+ ```
143
+ Skip to step 3 (set active_context).
135
144
 
136
- The product folder's own branch is always created from the current HEAD (typically `main`). The `base_branch` from init JSON applies only to code repos registered in REPOS.md.
145
+ **If worktree exists but `setup_complete: false` for any repo:**
146
+ ```
147
+ ╔══════════════════════════════════════════════════════════════╗
148
+ ║ ERROR ║
149
+ ╚══════════════════════════════════════════════════════════════╝
137
150
 
138
- When branching is enabled and REPOS.md lists code repos, `createRepoBranches` (via `dgs-tools.cjs`) uses `base_branch` to:
139
- 1. Pre-check all code repos upfront — verify the base branch exists in every registered repo before creating any branches
140
- 2. Fetch the base branch from remote in each repo (`git fetch origin "$BASE_BRANCH"`)
141
- 3. Create feature branches from the base branch (`git checkout "$BASE_BRANCH" && git checkout -b "$BRANCH_NAME"`)
151
+ Worktree setup incomplete for milestone '${MILESTONE_SLUG}'.
152
+ Repo(s) with failed setup need manual intervention.
142
153
 
143
- If the base branch does not exist in any code repo, the operation fails with a clear error before any branches are created:
154
+ **To fix:** dgs-tools worktrees setup ${MILESTONE_SLUG}
155
+ Then re-run: /dgs:execute-phase ${PHASE}
144
156
  ```
145
- Error: Base branch '{base_branch}' does not exist in repo '{repo_name}'.
146
- Create the branch or update git.base_branch in config.
157
+ **STOP.** Do not proceed with phase execution.
158
+
159
+ **If no worktree exists:**
160
+
161
+ **2. Create milestone worktree:**
162
+
163
+ ```bash
164
+ CREATE_RESULT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees create "${MILESTONE_SLUG}" --type milestone)
147
165
  ```
148
166
 
149
- The `base_branch` value is passed from init JSON to `createRepoBranches` automatically — the two-pass validation (verify all repos, then create all branches) is handled by the library function (see Plan 01, Task 3).
167
+ Parse JSON output. Check each repo:
168
+ - If all repos have `setup_complete: true` (or no setup command): continue.
169
+ - If any repo has `setup_complete: false`:
170
+
171
+ ```
172
+ ╔══════════════════════════════════════════════════════════════╗
173
+ ║ ERROR ║
174
+ ╚══════════════════════════════════════════════════════════════╝
175
+
176
+ Setup failed for one or more repos during worktree creation.
177
+ Phase cannot start until setup succeeds.
178
+
179
+ **To fix:** dgs-tools worktrees setup ${MILESTONE_SLUG}
180
+ Then re-run: /dgs:execute-phase ${PHASE}
181
+ ```
182
+ **STOP.** Do not proceed.
183
+
184
+ Note: The worktree directory and branch are kept (not removed) so the user can fix and re-run setup.
185
+
186
+ **3. Set active_context and capture worktree repos:**
187
+
188
+ ```bash
189
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" config-local-set execution.active_context "${MILESTONE_SLUG}"
190
+ ```
191
+
192
+ Read the worktree repos map from config.local.json so it can be passed to executor agents:
193
+
194
+ ```bash
195
+ WORKTREE_REPOS=$(node -e "
196
+ const fs = require('fs');
197
+ const cfg = JSON.parse(fs.readFileSync('config.local.json', 'utf-8'));
198
+ const project = cfg.current_project;
199
+ const repos = (cfg.projects && cfg.projects[project] && cfg.projects[project].worktrees && cfg.projects[project].worktrees['${MILESTONE_SLUG}'] && cfg.projects[project].worktrees['${MILESTONE_SLUG}'].repos) || {};
200
+ process.stdout.write(JSON.stringify(repos));
201
+ ")
202
+ ```
203
+
204
+ Store `$WORKTREE_REPOS` (JSON object mapping repoName -> worktreePath) for use in executor prompts.
205
+
206
+ **4. Verify worktree health:**
207
+
208
+ For each code repo registered in REPOS.md, verify the worktree is healthy:
209
+
210
+ ```bash
211
+ HEALTH=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees health "${MILESTONE_SLUG}" 2>/dev/null || echo '{"healthy":true,"issues":[]}')
212
+ ```
213
+
214
+ If the `worktrees health` subcommand is not available, perform inline checks:
215
+
216
+ For each repo in the worktree:
217
+ ```bash
218
+ # Check branch
219
+ BRANCH=$(git -C "${WORKTREE_PATH}" rev-parse --abbrev-ref HEAD 2>/dev/null)
220
+ # Check clean state
221
+ STATUS=$(git -C "${WORKTREE_PATH}" status --porcelain 2>/dev/null)
222
+ ```
223
+
224
+ If branch is wrong or uncommitted changes exist, **warn** but continue (quick sanity check, not a full health audit):
225
+ ```
226
+ ⚠ Worktree health warning for ${REPO_NAME}:
227
+ - Expected branch: milestone/${MILESTONE_SLUG}, actual: ${BRANCH}
228
+ - Has uncommitted changes
229
+ Continuing anyway — review worktree state after execution.
230
+ ```
231
+
232
+ **5. Do NOT clear active_context after phase completion.**
233
+
234
+ The milestone worktree persists across all phases within the milestone until `complete-milestone` is run. active_context is NOT cleared in the post-execution steps of this workflow.
235
+
236
+ **Note on backward compatibility:**
237
+ The old `branching_strategy` check and `createRepoBranches` code path is removed. If `branching_strategy` is set to "phase" or "milestone" in an older config, the worktree path runs instead.
150
238
  </step>
151
239
 
152
240
  <step name="validate_phase">
@@ -217,6 +305,13 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
217
305
  Commit each task atomically. Create SUMMARY.md. Update STATE.md and ROADMAP.md.
218
306
  </objective>
219
307
 
308
+ ${WORKTREE_REPOS && WORKTREE_REPOS !== '{}' ? `
309
+ <worktree_context>
310
+ This phase is executing in a git worktree. Work in these directories — do NOT use the main checkout paths:
311
+ ${Object.entries(JSON.parse(WORKTREE_REPOS)).map(([name, dir]) => '- ' + name + ': ' + dir).join('\n ')}
312
+ </worktree_context>
313
+ ` : ''}
314
+
220
315
  <execution_context>
221
316
  @~/.claude/deliver-great-systems/workflows/execute-plan.md
222
317
  @~/.claude/deliver-great-systems/templates/summary.md
@@ -292,11 +387,7 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
292
387
 
293
388
  If `CODEREVIEW` is not `true`: skip silently, proceed to next step.
294
389
 
295
- **If `NON_INTERACTIVE` is true:**
296
- Log: `[AUTO-RESOLVE] Code review enabled but skipping in non-interactive mode (codereview requires interactive Task spawning)`
297
- Skip codereview, proceed to next step.
298
-
299
- **If `NON_INTERACTIVE` is false (interactive mode) AND `CODEREVIEW` is `true`:**
390
+ The codereview workflow is non-interactive by design — it auto-fixes low-risk issues and logs CRITICAL/HIGH findings as deviations to SUMMARY.md rather than prompting. It runs in both interactive and job modes.
300
391
 
301
392
  For each plan that completed successfully in this wave:
302
393
 
@@ -570,10 +661,10 @@ Gap closure cycle: `/dgs:plan-phase {X} --gaps` reads VERIFICATION.md → create
570
661
  </step>
571
662
 
572
663
  <step name="update_roadmap">
573
- **Mark phase complete and update all tracking files:**
664
+ **Mark phase done, commit tracking files, and push all atomically:**
574
665
 
575
666
  ```bash
576
- COMPLETION=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" phase complete "${PHASE_NUMBER}")
667
+ FINALIZE=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" phase finalize "${PHASE_NUMBER}" --push)
577
668
  ```
578
669
 
579
670
  The CLI handles:
@@ -582,14 +673,12 @@ The CLI handles:
582
673
  - Updating plan count to final
583
674
  - Advancing STATE.md to next phase
584
675
  - Updating REQUIREMENTS.md traceability
676
+ - **Committing** ROADMAP.md, STATE.md, REQUIREMENTS.md, and `${phase_dir}/*-VERIFICATION.md` in a single atomic commit
677
+ - Pushing (if sync_push=auto) in the same call
585
678
 
586
- Extract from result: `next_phase`, `next_phase_name`, `is_last_phase`.
587
-
588
- ```bash
589
- node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" commit "docs(phase-{X}): complete phase execution" --push --files ${roadmap_path} ${state_path} ${requirements_path} ${phase_dir}/*-VERIFICATION.md
590
- ```
679
+ Extract from result: `next_phase`, `next_phase_name`, `is_last_phase`, `committed`, `hash`, `pushed`.
591
680
 
592
- Parse the commit result JSON. If `needs_push` is true (sync_push is "prompt" mode), handle push prompting via the existing sync_after step. If `pushed` is true, the push already happened atomically with the commit -- skip the sync_after push for this commit (avoid double-push). If `pushed` is false and `push_result` exists, log the push warning but do not halt.
681
+ Parse the result JSON. If `needs_push` is true (sync_push is "prompt" mode), handle push prompting via the existing sync_after step. If `pushed` is true, the push already happened atomically with the commit skip the sync_after push for this commit (avoid double-push). If `pushed` is false and `push_result` exists, log the push warning but do not halt.
593
682
  </step>
594
683
 
595
684
  <step name="sync_after">
@@ -683,7 +772,7 @@ Read and follow `~/.claude/deliver-great-systems/workflows/transition.md`, passi
683
772
 
684
773
  **HARD STOP.** The workflow ends here. Do NOT read transition.md. Do NOT read ROADMAP.md. Do NOT execute any additional phases.
685
774
 
686
- **Use ONLY the `is_last_phase`, `next_phase`, and `next_phase_name` values from the `phase complete` result in the update_roadmap step.** Do NOT read the roadmap or any other file to determine remaining phases — the CLI already computed this.
775
+ **Use ONLY the `is_last_phase`, `next_phase`, and `next_phase_name` values from the `phase finalize` result in the update_roadmap step.** Do NOT read the roadmap or any other file to determine remaining phases — the CLI already computed this.
687
776
 
688
777
  If `is_last_phase` is `false`:
689
778
  ```
@@ -452,25 +452,10 @@ Keep STATE.md under 150 lines.
452
452
  If SUMMARY "Issues Encountered" ≠ "None": yolo → log and continue. Interactive → present issues, wait for acknowledgment.
453
453
  </step>
454
454
 
455
- <step name="update_roadmap">
456
- ```bash
457
- node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" roadmap update-plan-progress "${PHASE}"
458
- ```
459
- Counts PLAN vs SUMMARY files on disk. Updates progress table row with correct count and status (`In Progress` or `Complete` with date).
460
- </step>
461
-
462
- <step name="update_requirements">
463
- Mark completed requirements from the PLAN.md frontmatter `requirements:` field:
464
-
465
- ```bash
466
- node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" requirements mark-complete ${REQ_IDS}
467
- ```
468
-
469
- Extract requirement IDs from the plan's frontmatter (e.g., `requirements: [AUTH-01, AUTH-02]`). If no requirements field, skip.
470
- </step>
455
+ <step name="finalize_plan">
456
+ **Update state/roadmap/requirements and commit plan metadata atomically.**
471
457
 
472
- <step name="git_commit_metadata">
473
- **Multi-repo guard:** If any task used `commit --multi-repo` and returned `success: false`, display a warning before committing planning metadata:
458
+ **Multi-repo guard:** If any task used `commit --multi-repo` and returned `success: false`, display a warning before finalizing:
474
459
 
475
460
  ```
476
461
  Warning: Some repo commits failed. Planning metadata will still be committed to track partial progress.
@@ -479,11 +464,17 @@ Check SUMMARY.md status field for per-repo details.
479
464
 
480
465
  The planning metadata commit proceeds regardless (to track partial progress), but the warning ensures visibility. The SUMMARY.md `status: partial` field records which repos failed.
481
466
 
482
- Task code already committed per-task. Commit plan metadata:
483
-
484
467
  ```bash
485
- node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" commit "docs({phase}-{plan}): complete [plan-name] plan" --files ${phase_dir}/{phase}-{plan}-SUMMARY.md ${state_path} ${roadmap_path} ${requirements_path}
468
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" plan finalize "${PHASE}" "${PLAN}"
486
469
  ```
470
+
471
+ The CLI handles (in one atomic call):
472
+ - `roadmap update-plan-progress` (progress table, status, date, checkbox)
473
+ - `requirements mark-complete` (from PLAN.md `requirements:` frontmatter — auto-extracted)
474
+ - `state update-progress` (global progress bar, idempotent with `record_metrics`)
475
+ - Commits `{phase}-{plan}-PLAN.md`, `{phase}-{plan}-SUMMARY.md`, `STATE.md`, `ROADMAP.md`, `REQUIREMENTS.md` with message `docs({phase}-{plan}): complete {plan-name} plan`
476
+
477
+ The plan name is auto-extracted from the PLAN.md `plan_name` frontmatter field (fallback: "execution"). To override, add `--plan-name "<name>"` to the call.
487
478
  </step>
488
479
 
489
480
  <step name="update_codebase_map">
@@ -384,7 +384,7 @@ Usage: `/dgs:debug` (resume active session)
384
384
  Capture idea or task as todo from current conversation. *(Tier 1: lite)*
385
385
 
386
386
  - Extracts context from conversation (or uses provided description)
387
- - Creates structured todo file in the project's todos/pending/ directory
387
+ - Creates structured todo file in the project's todos/ directory
388
388
  - Infers area from file paths for grouping
389
389
  - Checks for duplicates before creating
390
390
  - Updates STATE.md todo count
@@ -468,7 +468,7 @@ Usage: `/dgs:discuss-idea` (shows picker)
468
468
  Research an idea's feasibility and technical landscape. *(Tier 2: planning)*
469
469
 
470
470
  - Five dimensions: web search, codebase analysis, landscape survey, approaches, feasibility
471
- - Creates research document at `docs/ideas/pending/{slug}-research.md` (relative to planning root)
471
+ - Creates research document at `docs/ideas/{slug}-research.md` (relative to planning root)
472
472
  - Appends Research Log to idea file (Summary, Document link, Key Finding, Recommendation)
473
473
  - Can run multiple times; each run appends a new entry
474
474
 
@@ -206,16 +206,6 @@ AskUserQuestion([
206
206
  { label: "Yes (Recommended)", description: "Planning docs tracked in version control" },
207
207
  { label: "No", description: "Keep planning docs local-only (add to .gitignore)" }
208
208
  ]
209
- },
210
- {
211
- header: "Branching",
212
- question: "Git branching strategy?",
213
- multiSelect: false,
214
- options: [
215
- { label: "None (Recommended)", description: "Commit to current branch (fine for single projects)" },
216
- { label: "Per Phase", description: "Branch per phase, review before merging" },
217
- { label: "Per Milestone", description: "Branch per project, merge all at end (for parallel projects)" }
218
- ]
219
209
  }
220
210
  ])
221
211
  ```
@@ -282,10 +272,9 @@ AskUserQuestion([
282
272
  "discipline": true|false
283
273
  },
284
274
  "git": {
285
- "branching_strategy": "none|phase|milestone",
286
275
  "base_branch": "[from earlier question]",
287
- "sync_push": "prompt",
288
- "sync_pull": "prompt"
276
+ "sync_push": "auto",
277
+ "sync_pull": "auto"
289
278
  }
290
279
  }
291
280
  ```
@@ -300,11 +289,6 @@ Smart defaults (not asked): `parallelization: true`, `auto_advance: false`, `nyq
300
289
  node /Users/adrian/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "chore: add product config" --files ${config_path}
301
290
  ```
302
291
 
303
- **Branch name preview:** If `branching_strategy` is not `"none"`, show:
304
- ```
305
- Branch names will look like: dgs/{project-slug}/phase-03-auth
306
- ```
307
-
308
292
  **b7. Commit initialized files:**
309
293
 
310
294
  Use the `files_created` array from the init response to build the commit file list:
@@ -44,12 +44,28 @@ The spec must have status: final.
44
44
 
45
45
  <process>
46
46
 
47
+ ## 0. Resolve Paths and Models
48
+
49
+ ```bash
50
+ INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init new-milestone)
51
+ ```
52
+
53
+ Extract from init JSON: `researcher_model`, `synthesizer_model`, `roadmapper_model`, `commit_docs`, `research_enabled`, `current_milestone`, `current_milestone_name`, `project_exists`, `roadmap_exists`, `state_exists`, `project_path`, `roadmap_path`, `state_path`, `current_project`, `project_root`.
54
+
55
+ Load planning-tier context files:
56
+
57
+ ```bash
58
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
59
+ ```
60
+
61
+ All subsequent steps use these resolved paths. Never reference PROJECT.md, STATE.md, etc. by bare name — always use `${project_path}`, `${state_path}`, `${project_root}`, etc.
62
+
47
63
  ## 1. Load Context
48
64
 
49
- - Read PROJECT.md (existing project, validated requirements, decisions)
50
- - Read MILESTONES.md (what shipped previously) — if file does not exist, this is the first milestone; skip and use defaults
51
- - Read STATE.md (pending todos, blockers) — if file does not exist, will be created in Step 5
52
- - Check for MILESTONE-CONTEXT.md (from /dgs:discuss-milestone)
65
+ - Read `${project_path}` (existing project, validated requirements, decisions)
66
+ - Read `${project_root}/MILESTONES.md` (what shipped previously) — if file does not exist, this is the first milestone; skip and use defaults
67
+ - Read `${state_path}` (pending todos, blockers) — if file does not exist, will be created in Step 5
68
+ - Check for `${project_root}/MILESTONE-CONTEXT.md` (from /dgs:discuss-milestone)
53
69
 
54
70
  ## 1b. Spec-Driven Milestone (auto mode only)
55
71
 
@@ -67,7 +83,7 @@ Read the spec file and extract:
67
83
 
68
84
  ### Determine Milestone Version
69
85
 
70
- Parse MILESTONES.md for last version. If no MILESTONES.md exists (first milestone): default to v1.0 (auto mode: use v1.0 without asking). Suggest next version automatically (e.g., v1.0 → v1.1, or v2.0 for major). In auto mode, use the minor bump without asking.
86
+ Parse `${project_root}/MILESTONES.md` for last version. If no MILESTONES.md exists (first milestone): default to v1.0 (auto mode: use v1.0 without asking). Suggest next version automatically (e.g., v1.0 → v1.1, or v2.0 for major). In auto mode, use the minor bump without asking.
71
87
 
72
88
  ### Repo Cross-Check (v2 only)
73
89
 
@@ -148,7 +164,7 @@ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "specs: link $SPEC
148
164
 
149
165
  ### Continue to Step 7
150
166
 
151
- Skip Steps 2-6 (questioning, version determination, update, cleanup, context loading) — they're replaced by spec-driven derivation. Proceed to Step 7 (Load Context and Resolve Models), then:
167
+ Skip Steps 2-6 (questioning, version determination, update, cleanup) — they're replaced by spec-driven derivation. Proceed to Step 8 (Research Decision), then:
152
168
 
153
169
  - Step 8 (Research Decision): Default to "Research first" in auto mode
154
170
  - Step 9 (Define Requirements): Generate from spec instead of interactive scoping:
@@ -166,7 +182,7 @@ Skip Steps 2-6 (questioning, version determination, update, cleanup, context loa
166
182
 
167
183
  ## 2. Gather Milestone Goals
168
184
 
169
- **If MILESTONE-CONTEXT.md exists:**
185
+ **If `${project_root}/MILESTONE-CONTEXT.md` exists:**
170
186
  - Use features and scope from discuss-milestone
171
187
  - Present summary for confirmation
172
188
 
@@ -177,7 +193,7 @@ Skip Steps 2-6 (questioning, version determination, update, cleanup, context loa
177
193
 
178
194
  ## 3. Determine Milestone Version
179
195
 
180
- - Parse last version from MILESTONES.md
196
+ - Parse last version from `${project_root}/MILESTONES.md`
181
197
  - If no MILESTONES.md exists (first milestone): default to v1.0 and suggest it to user
182
198
  - Suggest next version (v1.0 → v1.1, or v2.0 for major)
183
199
  - Confirm with user
@@ -201,8 +217,8 @@ Update Active requirements section and "Last updated" footer.
201
217
 
202
218
  ## 5. Update STATE.md
203
219
 
204
- **If STATE.md does not exist (first milestone):** Create it with the structure below.
205
- **If STATE.md exists:** Update the Current Position section.
220
+ **If `${state_path}` does not exist (first milestone):** Create it with the structure below.
221
+ **If it exists:** Update the Current Position section.
206
222
 
207
223
  ```markdown
208
224
  ## Current Position
@@ -217,25 +233,15 @@ Keep Accumulated Context section from previous milestone.
217
233
 
218
234
  ## 6. Cleanup and Commit
219
235
 
220
- Delete MILESTONE-CONTEXT.md if exists (consumed).
236
+ Delete `${project_root}/MILESTONE-CONTEXT.md` if exists (consumed).
221
237
 
222
238
  ```bash
223
239
  node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: start milestone v[X.Y] [Name]" --push --files ${project_path} ${state_path}
224
240
  ```
225
241
 
226
- ## 7. Load Context and Resolve Models
227
-
228
- ```bash
229
- INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init new-milestone)
230
- ```
231
-
232
- Extract from init JSON: `researcher_model`, `synthesizer_model`, `roadmapper_model`, `commit_docs`, `research_enabled`, `current_milestone`, `project_exists`, `roadmap_exists`.
242
+ ## 7. Research Decision Gate
233
243
 
234
- Load planning-tier context files:
235
-
236
- ```bash
237
- TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
238
- ```
244
+ Paths and models already resolved in Step 0.
239
245
 
240
246
  ## 8. Research Decision
241
247
 
@@ -429,7 +435,7 @@ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: define mile
429
435
  ◆ Spawning roadmapper...
430
436
  ```
431
437
 
432
- **Starting phase number:** Read MILESTONES.md for last phase number. Continue from there (v1.0 ended at phase 5 → v1.1 starts at phase 6). If no MILESTONES.md exists (first milestone): start phase numbering at 1.
438
+ **Starting phase number:** Read `${project_root}/MILESTONES.md` for last phase number. Continue from there (v1.0 ended at phase 5 → v1.1 starts at phase 6). If no MILESTONES.md exists (first milestone): start phase numbering at 1.
433
439
 
434
440
  ```
435
441
  Task(prompt="