@mobiman/vector 1.1.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 (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/agents/vector-codebase-mapper.md +770 -0
  4. package/agents/vector-debugger.md +1338 -0
  5. package/agents/vector-executor.md +487 -0
  6. package/agents/vector-integration-checker.md +443 -0
  7. package/agents/vector-nyquist-auditor.md +176 -0
  8. package/agents/vector-phase-researcher.md +553 -0
  9. package/agents/vector-plan-checker.md +706 -0
  10. package/agents/vector-planner.md +1307 -0
  11. package/agents/vector-project-researcher.md +629 -0
  12. package/agents/vector-research-synthesizer.md +247 -0
  13. package/agents/vector-roadmapper.md +650 -0
  14. package/agents/vector-ui-auditor.md +439 -0
  15. package/agents/vector-ui-checker.md +300 -0
  16. package/agents/vector-ui-researcher.md +353 -0
  17. package/agents/vector-verifier.md +579 -0
  18. package/bin/install.cjs +2907 -0
  19. package/bin/install.cjs.map +1 -0
  20. package/bin/install.cts +3103 -0
  21. package/bin/install.d.cts +3 -0
  22. package/bin/install.d.cts.map +1 -0
  23. package/commands/vector/add-phase.md +43 -0
  24. package/commands/vector/add-tests.md +41 -0
  25. package/commands/vector/add-todo.md +47 -0
  26. package/commands/vector/audit-milestone.md +36 -0
  27. package/commands/vector/autonomous.md +41 -0
  28. package/commands/vector/check-todos.md +45 -0
  29. package/commands/vector/cleanup.md +18 -0
  30. package/commands/vector/complete-milestone.md +136 -0
  31. package/commands/vector/debug.md +168 -0
  32. package/commands/vector/discuss-phase.md +90 -0
  33. package/commands/vector/do.md +30 -0
  34. package/commands/vector/execute-phase.md +41 -0
  35. package/commands/vector/health.md +22 -0
  36. package/commands/vector/help.md +22 -0
  37. package/commands/vector/insert-phase.md +32 -0
  38. package/commands/vector/join-discord.md +18 -0
  39. package/commands/vector/list-phase-assumptions.md +46 -0
  40. package/commands/vector/map-codebase.md +71 -0
  41. package/commands/vector/new-milestone.md +44 -0
  42. package/commands/vector/new-project.md +42 -0
  43. package/commands/vector/pause-work.md +38 -0
  44. package/commands/vector/plan-milestone-gaps.md +34 -0
  45. package/commands/vector/plan-phase.md +45 -0
  46. package/commands/vector/progress.md +24 -0
  47. package/commands/vector/quick.md +47 -0
  48. package/commands/vector/reapply-patches.md +123 -0
  49. package/commands/vector/remove-phase.md +31 -0
  50. package/commands/vector/research-phase.md +190 -0
  51. package/commands/vector/resume-work.md +40 -0
  52. package/commands/vector/set-profile.md +12 -0
  53. package/commands/vector/settings.md +36 -0
  54. package/commands/vector/stats.md +18 -0
  55. package/commands/vector/ui-phase.md +34 -0
  56. package/commands/vector/ui-review.md +32 -0
  57. package/commands/vector/update.md +37 -0
  58. package/commands/vector/validate-phase.md +35 -0
  59. package/commands/vector/verify-work.md +38 -0
  60. package/core/bin/lib/commands.cjs +641 -0
  61. package/core/bin/lib/commands.cjs.map +1 -0
  62. package/core/bin/lib/commands.cts +712 -0
  63. package/core/bin/lib/commands.d.cts +23 -0
  64. package/core/bin/lib/commands.d.cts.map +1 -0
  65. package/core/bin/lib/config.cjs +281 -0
  66. package/core/bin/lib/config.cjs.map +1 -0
  67. package/core/bin/lib/config.cts +301 -0
  68. package/core/bin/lib/config.d.cts +50 -0
  69. package/core/bin/lib/config.d.cts.map +1 -0
  70. package/core/bin/lib/core.cjs +483 -0
  71. package/core/bin/lib/core.cjs.map +1 -0
  72. package/core/bin/lib/core.cts +544 -0
  73. package/core/bin/lib/core.d.cts +96 -0
  74. package/core/bin/lib/core.d.cts.map +1 -0
  75. package/core/bin/lib/frontmatter.cjs +341 -0
  76. package/core/bin/lib/frontmatter.cjs.map +1 -0
  77. package/core/bin/lib/frontmatter.cts +295 -0
  78. package/core/bin/lib/frontmatter.d.cts +18 -0
  79. package/core/bin/lib/frontmatter.d.cts.map +1 -0
  80. package/core/bin/lib/init.cjs +674 -0
  81. package/core/bin/lib/init.cjs.map +1 -0
  82. package/core/bin/lib/init.cts +775 -0
  83. package/core/bin/lib/init.d.cts +16 -0
  84. package/core/bin/lib/init.d.cts.map +1 -0
  85. package/core/bin/lib/milestone.cjs +210 -0
  86. package/core/bin/lib/milestone.cjs.map +1 -0
  87. package/core/bin/lib/milestone.cts +241 -0
  88. package/core/bin/lib/milestone.d.cts +11 -0
  89. package/core/bin/lib/milestone.d.cts.map +1 -0
  90. package/core/bin/lib/model-profiles.cjs +62 -0
  91. package/core/bin/lib/model-profiles.cjs.map +1 -0
  92. package/core/bin/lib/model-profiles.cts +66 -0
  93. package/core/bin/lib/model-profiles.d.cts +33 -0
  94. package/core/bin/lib/model-profiles.d.cts.map +1 -0
  95. package/core/bin/lib/phase.cjs +713 -0
  96. package/core/bin/lib/phase.cjs.map +1 -0
  97. package/core/bin/lib/phase.cts +914 -0
  98. package/core/bin/lib/phase.d.cts +21 -0
  99. package/core/bin/lib/phase.d.cts.map +1 -0
  100. package/core/bin/lib/roadmap.cjs +246 -0
  101. package/core/bin/lib/roadmap.cjs.map +1 -0
  102. package/core/bin/lib/roadmap.cts +311 -0
  103. package/core/bin/lib/roadmap.d.cts +7 -0
  104. package/core/bin/lib/roadmap.d.cts.map +1 -0
  105. package/core/bin/lib/state.cjs +709 -0
  106. package/core/bin/lib/state.cjs.map +1 -0
  107. package/core/bin/lib/state.cts +718 -0
  108. package/core/bin/lib/state.d.cts +47 -0
  109. package/core/bin/lib/state.d.cts.map +1 -0
  110. package/core/bin/lib/template.cjs +220 -0
  111. package/core/bin/lib/template.cjs.map +1 -0
  112. package/core/bin/lib/template.cts +229 -0
  113. package/core/bin/lib/template.d.cts +15 -0
  114. package/core/bin/lib/template.d.cts.map +1 -0
  115. package/core/bin/lib/verify.cjs +824 -0
  116. package/core/bin/lib/verify.cjs.map +1 -0
  117. package/core/bin/lib/verify.cts +829 -0
  118. package/core/bin/lib/verify.d.cts +17 -0
  119. package/core/bin/lib/verify.d.cts.map +1 -0
  120. package/core/bin/vector-tools.cjs +641 -0
  121. package/core/bin/vector-tools.cjs.map +1 -0
  122. package/core/bin/vector-tools.cts +603 -0
  123. package/core/bin/vector-tools.d.cts +128 -0
  124. package/core/bin/vector-tools.d.cts.map +1 -0
  125. package/core/references/checkpoints.md +776 -0
  126. package/core/references/continuation-format.md +249 -0
  127. package/core/references/decimal-phase-calculation.md +65 -0
  128. package/core/references/git-integration.md +248 -0
  129. package/core/references/git-planning-commit.md +38 -0
  130. package/core/references/model-profile-resolution.md +36 -0
  131. package/core/references/model-profiles.md +101 -0
  132. package/core/references/phase-argument-parsing.md +61 -0
  133. package/core/references/planning-config.md +200 -0
  134. package/core/references/questioning.md +162 -0
  135. package/core/references/tdd.md +263 -0
  136. package/core/references/ui-brand.md +160 -0
  137. package/core/references/verification-patterns.md +612 -0
  138. package/core/templates/DEBUG.md +164 -0
  139. package/core/templates/UAT.md +247 -0
  140. package/core/templates/UI-SPEC.md +100 -0
  141. package/core/templates/VALIDATION.md +76 -0
  142. package/core/templates/codebase/architecture.md +255 -0
  143. package/core/templates/codebase/concerns.md +310 -0
  144. package/core/templates/codebase/conventions.md +307 -0
  145. package/core/templates/codebase/integrations.md +280 -0
  146. package/core/templates/codebase/stack.md +186 -0
  147. package/core/templates/codebase/structure.md +285 -0
  148. package/core/templates/codebase/testing.md +480 -0
  149. package/core/templates/config.json +37 -0
  150. package/core/templates/context.md +352 -0
  151. package/core/templates/continue-here.md +78 -0
  152. package/core/templates/copilot-instructions.md +7 -0
  153. package/core/templates/debug-subagent-prompt.md +91 -0
  154. package/core/templates/discovery.md +146 -0
  155. package/core/templates/milestone-archive.md +123 -0
  156. package/core/templates/milestone.md +115 -0
  157. package/core/templates/phase-prompt.md +610 -0
  158. package/core/templates/planner-subagent-prompt.md +117 -0
  159. package/core/templates/project.md +184 -0
  160. package/core/templates/requirements.md +231 -0
  161. package/core/templates/research-project/ARCHITECTURE.md +204 -0
  162. package/core/templates/research-project/FEATURES.md +147 -0
  163. package/core/templates/research-project/PITFALLS.md +200 -0
  164. package/core/templates/research-project/STACK.md +120 -0
  165. package/core/templates/research-project/SUMMARY.md +170 -0
  166. package/core/templates/research.md +552 -0
  167. package/core/templates/retrospective.md +54 -0
  168. package/core/templates/roadmap.md +202 -0
  169. package/core/templates/state.md +176 -0
  170. package/core/templates/summary-complex.md +59 -0
  171. package/core/templates/summary-minimal.md +41 -0
  172. package/core/templates/summary-standard.md +48 -0
  173. package/core/templates/summary.md +248 -0
  174. package/core/templates/user-setup.md +311 -0
  175. package/core/templates/verification-report.md +322 -0
  176. package/core/workflows/add-phase.md +112 -0
  177. package/core/workflows/add-tests.md +351 -0
  178. package/core/workflows/add-todo.md +158 -0
  179. package/core/workflows/audit-milestone.md +332 -0
  180. package/core/workflows/autonomous.md +743 -0
  181. package/core/workflows/check-todos.md +177 -0
  182. package/core/workflows/cleanup.md +152 -0
  183. package/core/workflows/complete-milestone.md +766 -0
  184. package/core/workflows/diagnose-issues.md +219 -0
  185. package/core/workflows/discovery-phase.md +289 -0
  186. package/core/workflows/discuss-phase.md +762 -0
  187. package/core/workflows/do.md +104 -0
  188. package/core/workflows/execute-phase.md +468 -0
  189. package/core/workflows/execute-plan.md +483 -0
  190. package/core/workflows/health.md +159 -0
  191. package/core/workflows/help.md +513 -0
  192. package/core/workflows/insert-phase.md +130 -0
  193. package/core/workflows/list-phase-assumptions.md +178 -0
  194. package/core/workflows/map-codebase.md +316 -0
  195. package/core/workflows/new-milestone.md +386 -0
  196. package/core/workflows/new-project.md +1113 -0
  197. package/core/workflows/node-repair.md +92 -0
  198. package/core/workflows/pause-work.md +122 -0
  199. package/core/workflows/plan-milestone-gaps.md +274 -0
  200. package/core/workflows/plan-phase.md +666 -0
  201. package/core/workflows/progress.md +382 -0
  202. package/core/workflows/quick.md +717 -0
  203. package/core/workflows/remove-phase.md +155 -0
  204. package/core/workflows/research-phase.md +74 -0
  205. package/core/workflows/resume-project.md +307 -0
  206. package/core/workflows/settings.md +243 -0
  207. package/core/workflows/stats.md +60 -0
  208. package/core/workflows/transition.md +544 -0
  209. package/core/workflows/ui-phase.md +290 -0
  210. package/core/workflows/ui-review.md +157 -0
  211. package/core/workflows/update.md +320 -0
  212. package/core/workflows/validate-phase.md +167 -0
  213. package/core/workflows/verify-phase.md +243 -0
  214. package/core/workflows/verify-work.md +584 -0
  215. package/package.json +55 -0
  216. package/scripts/build-hooks.cjs +38 -0
  217. package/scripts/build-hooks.cjs.map +1 -0
  218. package/scripts/build-hooks.cts +41 -0
  219. package/scripts/build-hooks.d.cts +6 -0
  220. package/scripts/build-hooks.d.cts.map +1 -0
  221. package/scripts/run-tests.cjs +28 -0
  222. package/scripts/run-tests.cjs.map +1 -0
  223. package/scripts/run-tests.cts +28 -0
  224. package/scripts/run-tests.d.cts +3 -0
  225. package/scripts/run-tests.d.cts.map +1 -0
@@ -0,0 +1,713 @@
1
+ "use strict";
2
+ /**
3
+ * Phase — Phase CRUD, query, and lifecycle operations
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.cmdPhasesList = cmdPhasesList;
10
+ exports.cmdPhaseNextDecimal = cmdPhaseNextDecimal;
11
+ exports.cmdFindPhase = cmdFindPhase;
12
+ exports.cmdPhasePlanIndex = cmdPhasePlanIndex;
13
+ exports.cmdPhaseAdd = cmdPhaseAdd;
14
+ exports.cmdPhaseInsert = cmdPhaseInsert;
15
+ exports.cmdPhaseRemove = cmdPhaseRemove;
16
+ exports.cmdPhaseComplete = cmdPhaseComplete;
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const path_1 = __importDefault(require("path"));
19
+ const core_cjs_1 = require("./core.cjs");
20
+ const frontmatter_cjs_1 = require("./frontmatter.cjs");
21
+ const state_cjs_1 = require("./state.cjs");
22
+ function cmdPhasesList(cwd, options, raw) {
23
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
24
+ const { type, phase, includeArchived } = options;
25
+ // If no phases directory, return empty
26
+ if (!fs_1.default.existsSync(phasesDir)) {
27
+ if (type) {
28
+ (0, core_cjs_1.output)({ files: [], count: 0 }, raw, '');
29
+ }
30
+ else {
31
+ (0, core_cjs_1.output)({ directories: [], count: 0 }, raw, '');
32
+ }
33
+ return;
34
+ }
35
+ try {
36
+ // Get all phase directories
37
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
38
+ let dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
39
+ // Include archived phases if requested
40
+ if (includeArchived) {
41
+ const archived = (0, core_cjs_1.getArchivedPhaseDirs)(cwd);
42
+ for (const a of archived) {
43
+ dirs.push(`${a.name} [${a.milestone}]`);
44
+ }
45
+ }
46
+ // Sort numerically (handles integers, decimals, letter-suffix, hybrids)
47
+ dirs.sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
48
+ // If filtering by phase number
49
+ if (phase) {
50
+ const normalized = (0, core_cjs_1.normalizePhaseName)(phase);
51
+ const match = dirs.find(d => d.startsWith(normalized));
52
+ if (!match) {
53
+ (0, core_cjs_1.output)({ files: [], count: 0, phase_dir: null, error: 'Phase not found' }, raw, '');
54
+ return;
55
+ }
56
+ dirs = [match];
57
+ }
58
+ // If listing files of a specific type
59
+ if (type) {
60
+ const files = [];
61
+ for (const dir of dirs) {
62
+ const dirPath = path_1.default.join(phasesDir, dir);
63
+ const dirFiles = fs_1.default.readdirSync(dirPath);
64
+ let filtered;
65
+ if (type === 'plans') {
66
+ filtered = dirFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md');
67
+ }
68
+ else if (type === 'summaries') {
69
+ filtered = dirFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
70
+ }
71
+ else {
72
+ filtered = dirFiles;
73
+ }
74
+ files.push(...filtered.sort());
75
+ }
76
+ const result = {
77
+ files,
78
+ count: files.length,
79
+ phase_dir: phase ? dirs[0].replace(/^\d+(?:\.\d+)*-?/, '') : null,
80
+ };
81
+ (0, core_cjs_1.output)(result, raw, files.join('\n'));
82
+ return;
83
+ }
84
+ // Default: list directories
85
+ (0, core_cjs_1.output)({ directories: dirs, count: dirs.length }, raw, dirs.join('\n'));
86
+ }
87
+ catch (e) {
88
+ (0, core_cjs_1.error)('Failed to list phases: ' + e.message);
89
+ }
90
+ }
91
+ function cmdPhaseNextDecimal(cwd, basePhase, raw) {
92
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
93
+ const normalized = (0, core_cjs_1.normalizePhaseName)(basePhase);
94
+ // Check if phases directory exists
95
+ if (!fs_1.default.existsSync(phasesDir)) {
96
+ (0, core_cjs_1.output)({
97
+ found: false,
98
+ base_phase: normalized,
99
+ next: `${normalized}.1`,
100
+ existing: [],
101
+ }, raw, `${normalized}.1`);
102
+ return;
103
+ }
104
+ try {
105
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
106
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
107
+ // Check if base phase exists
108
+ const baseExists = dirs.some(d => d.startsWith(normalized + '-') || d === normalized);
109
+ // Find existing decimal phases for this base
110
+ const decimalPattern = new RegExp(`^${normalized}\\.(\\d+)`);
111
+ const existingDecimals = [];
112
+ for (const dir of dirs) {
113
+ const match = dir.match(decimalPattern);
114
+ if (match) {
115
+ existingDecimals.push(`${normalized}.${match[1]}`);
116
+ }
117
+ }
118
+ // Sort numerically
119
+ existingDecimals.sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
120
+ // Calculate next decimal
121
+ let nextDecimal;
122
+ if (existingDecimals.length === 0) {
123
+ nextDecimal = `${normalized}.1`;
124
+ }
125
+ else {
126
+ const lastDecimal = existingDecimals[existingDecimals.length - 1];
127
+ const lastNum = parseInt(lastDecimal.split('.')[1], 10);
128
+ nextDecimal = `${normalized}.${lastNum + 1}`;
129
+ }
130
+ (0, core_cjs_1.output)({
131
+ found: baseExists,
132
+ base_phase: normalized,
133
+ next: nextDecimal,
134
+ existing: existingDecimals,
135
+ }, raw, nextDecimal);
136
+ }
137
+ catch (e) {
138
+ (0, core_cjs_1.error)('Failed to calculate next decimal phase: ' + e.message);
139
+ }
140
+ }
141
+ function cmdFindPhase(cwd, phase, raw) {
142
+ if (!phase) {
143
+ (0, core_cjs_1.error)('phase identifier required');
144
+ }
145
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
146
+ const normalized = (0, core_cjs_1.normalizePhaseName)(phase);
147
+ const notFound = { found: false, directory: null, phase_number: null, phase_name: null, plans: [], summaries: [] };
148
+ try {
149
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
150
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
151
+ const match = dirs.find(d => d.startsWith(normalized));
152
+ if (!match) {
153
+ (0, core_cjs_1.output)(notFound, raw, '');
154
+ return;
155
+ }
156
+ const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
157
+ const phaseNumber = dirMatch ? dirMatch[1] : normalized;
158
+ const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
159
+ const phaseDir = path_1.default.join(phasesDir, match);
160
+ const phaseFiles = fs_1.default.readdirSync(phaseDir);
161
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
162
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
163
+ const result = {
164
+ found: true,
165
+ directory: (0, core_cjs_1.toPosixPath)(path_1.default.join('.planning', 'phases', match)),
166
+ phase_number: phaseNumber,
167
+ phase_name: phaseName,
168
+ plans,
169
+ summaries,
170
+ };
171
+ (0, core_cjs_1.output)(result, raw, result.directory);
172
+ }
173
+ catch {
174
+ (0, core_cjs_1.output)(notFound, raw, '');
175
+ }
176
+ }
177
+ function extractObjective(content) {
178
+ const m = content.match(/<objective>\s*\n?\s*(.+)/);
179
+ return m ? m[1].trim() : null;
180
+ }
181
+ function cmdPhasePlanIndex(cwd, phase, raw) {
182
+ if (!phase) {
183
+ (0, core_cjs_1.error)('phase required for phase-plan-index');
184
+ }
185
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
186
+ const normalized = (0, core_cjs_1.normalizePhaseName)(phase);
187
+ // Find phase directory
188
+ let phaseDir = null;
189
+ try {
190
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
191
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
192
+ const match = dirs.find(d => d.startsWith(normalized));
193
+ if (match) {
194
+ phaseDir = path_1.default.join(phasesDir, match);
195
+ }
196
+ }
197
+ catch {
198
+ // phases dir doesn't exist
199
+ }
200
+ if (!phaseDir) {
201
+ (0, core_cjs_1.output)({ phase: normalized, error: 'Phase not found', plans: [], waves: {}, incomplete: [], has_checkpoints: false }, raw);
202
+ return;
203
+ }
204
+ // Get all files in phase directory
205
+ const phaseFiles = fs_1.default.readdirSync(phaseDir);
206
+ const planFiles = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
207
+ const summaryFiles = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
208
+ // Build set of plan IDs with summaries
209
+ const completedPlanIds = new Set(summaryFiles.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', '')));
210
+ const plans = [];
211
+ const waves = {};
212
+ const incomplete = [];
213
+ let hasCheckpoints = false;
214
+ for (const planFile of planFiles) {
215
+ const planId = planFile.replace('-PLAN.md', '').replace('PLAN.md', '');
216
+ const planPath = path_1.default.join(phaseDir, planFile);
217
+ const content = fs_1.default.readFileSync(planPath, 'utf-8');
218
+ const fm = (0, frontmatter_cjs_1.extractFrontmatter)(content);
219
+ // Count tasks: XML <task> tags (canonical) or ## Task N markdown (legacy)
220
+ const xmlTasks = content.match(/<task[\s>]/gi) || [];
221
+ const mdTasks = content.match(/##\s*Task\s*\d+/gi) || [];
222
+ const taskCount = xmlTasks.length || mdTasks.length;
223
+ // Parse wave as integer
224
+ const wave = parseInt(fm.wave, 10) || 1;
225
+ // Parse autonomous (default true if not specified)
226
+ let autonomous = true;
227
+ if (fm.autonomous !== undefined) {
228
+ autonomous = fm.autonomous === 'true' || fm.autonomous === true;
229
+ }
230
+ if (!autonomous) {
231
+ hasCheckpoints = true;
232
+ }
233
+ // Parse files_modified (underscore is canonical; also accept hyphenated for compat)
234
+ let filesModified = [];
235
+ const fmFiles = fm['files_modified'] || fm['files-modified'];
236
+ if (fmFiles) {
237
+ filesModified = Array.isArray(fmFiles) ? fmFiles : [fmFiles];
238
+ }
239
+ const hasSummary = completedPlanIds.has(planId);
240
+ if (!hasSummary) {
241
+ incomplete.push(planId);
242
+ }
243
+ const plan = {
244
+ id: planId,
245
+ wave,
246
+ autonomous,
247
+ objective: extractObjective(content) || fm.objective || null,
248
+ files_modified: filesModified,
249
+ task_count: taskCount,
250
+ has_summary: hasSummary,
251
+ };
252
+ plans.push(plan);
253
+ // Group by wave
254
+ const waveKey = String(wave);
255
+ if (!waves[waveKey]) {
256
+ waves[waveKey] = [];
257
+ }
258
+ waves[waveKey].push(planId);
259
+ }
260
+ const result = {
261
+ phase: normalized,
262
+ plans,
263
+ waves,
264
+ incomplete,
265
+ has_checkpoints: hasCheckpoints,
266
+ };
267
+ (0, core_cjs_1.output)(result, raw);
268
+ }
269
+ function cmdPhaseAdd(cwd, description, raw) {
270
+ if (!description) {
271
+ (0, core_cjs_1.error)('description required for phase add');
272
+ }
273
+ const roadmapPath = path_1.default.join(cwd, '.planning', 'ROADMAP.md');
274
+ if (!fs_1.default.existsSync(roadmapPath)) {
275
+ (0, core_cjs_1.error)('ROADMAP.md not found');
276
+ }
277
+ const rawContent = fs_1.default.readFileSync(roadmapPath, 'utf-8');
278
+ const content = (0, core_cjs_1.stripShippedMilestones)(rawContent);
279
+ const slug = (0, core_cjs_1.generateSlugInternal)(description);
280
+ // Find highest integer phase number (in current milestone only)
281
+ const phasePattern = /#{2,4}\s*Phase\s+(\d+)[A-Z]?(?:\.\d+)*:/gi;
282
+ let maxPhase = 0;
283
+ let m;
284
+ while ((m = phasePattern.exec(content)) !== null) {
285
+ const num = parseInt(m[1], 10);
286
+ if (num > maxPhase)
287
+ maxPhase = num;
288
+ }
289
+ const newPhaseNum = maxPhase + 1;
290
+ const paddedNum = String(newPhaseNum).padStart(2, '0');
291
+ const dirName = `${paddedNum}-${slug}`;
292
+ const dirPath = path_1.default.join(cwd, '.planning', 'phases', dirName);
293
+ // Create directory with .gitkeep so git tracks empty folders
294
+ fs_1.default.mkdirSync(dirPath, { recursive: true });
295
+ fs_1.default.writeFileSync(path_1.default.join(dirPath, '.gitkeep'), '');
296
+ // Build phase entry
297
+ const phaseEntry = `\n### Phase ${newPhaseNum}: ${description}\n\n**Goal:** [To be planned]\n**Requirements**: TBD\n**Depends on:** Phase ${maxPhase}\n**Plans:** 0 plans\n\nPlans:\n- [ ] TBD (run /vector:plan-phase ${newPhaseNum} to break down)\n`;
298
+ // Find insertion point: before last "---" or at end
299
+ let updatedContent;
300
+ const lastSeparator = rawContent.lastIndexOf('\n---');
301
+ if (lastSeparator > 0) {
302
+ updatedContent = rawContent.slice(0, lastSeparator) + phaseEntry + rawContent.slice(lastSeparator);
303
+ }
304
+ else {
305
+ updatedContent = rawContent + phaseEntry;
306
+ }
307
+ fs_1.default.writeFileSync(roadmapPath, updatedContent, 'utf-8');
308
+ const result = {
309
+ phase_number: newPhaseNum,
310
+ padded: paddedNum,
311
+ name: description,
312
+ slug,
313
+ directory: `.planning/phases/${dirName}`,
314
+ };
315
+ (0, core_cjs_1.output)(result, raw, paddedNum);
316
+ }
317
+ function cmdPhaseInsert(cwd, afterPhase, description, raw) {
318
+ if (!afterPhase || !description) {
319
+ (0, core_cjs_1.error)('after-phase and description required for phase insert');
320
+ }
321
+ const roadmapPath = path_1.default.join(cwd, '.planning', 'ROADMAP.md');
322
+ if (!fs_1.default.existsSync(roadmapPath)) {
323
+ (0, core_cjs_1.error)('ROADMAP.md not found');
324
+ }
325
+ const rawContent = fs_1.default.readFileSync(roadmapPath, 'utf-8');
326
+ const content = (0, core_cjs_1.stripShippedMilestones)(rawContent);
327
+ const slug = (0, core_cjs_1.generateSlugInternal)(description);
328
+ // Normalize input then strip leading zeros for flexible matching
329
+ const normalizedAfter = (0, core_cjs_1.normalizePhaseName)(afterPhase);
330
+ const unpadded = normalizedAfter.replace(/^0+/, '');
331
+ const afterPhaseEscaped = unpadded.replace(/\./g, '\\.');
332
+ const targetPattern = new RegExp(`#{2,4}\\s*Phase\\s+0*${afterPhaseEscaped}:`, 'i');
333
+ if (!targetPattern.test(content)) {
334
+ (0, core_cjs_1.error)(`Phase ${afterPhase} not found in ROADMAP.md`);
335
+ }
336
+ // Calculate next decimal using existing logic
337
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
338
+ const normalizedBase = (0, core_cjs_1.normalizePhaseName)(afterPhase);
339
+ const existingDecimals = [];
340
+ try {
341
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
342
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
343
+ const decimalPattern = new RegExp(`^${normalizedBase}\\.(\\d+)`);
344
+ for (const dir of dirs) {
345
+ const dm = dir.match(decimalPattern);
346
+ if (dm)
347
+ existingDecimals.push(parseInt(dm[1], 10));
348
+ }
349
+ }
350
+ catch { }
351
+ const nextDecimal = existingDecimals.length === 0 ? 1 : Math.max(...existingDecimals) + 1;
352
+ const decimalPhase = `${normalizedBase}.${nextDecimal}`;
353
+ const dirName = `${decimalPhase}-${slug}`;
354
+ const dirPath = path_1.default.join(cwd, '.planning', 'phases', dirName);
355
+ // Create directory with .gitkeep so git tracks empty folders
356
+ fs_1.default.mkdirSync(dirPath, { recursive: true });
357
+ fs_1.default.writeFileSync(path_1.default.join(dirPath, '.gitkeep'), '');
358
+ // Build phase entry
359
+ const phaseEntry = `\n### Phase ${decimalPhase}: ${description} (INSERTED)\n\n**Goal:** [Urgent work - to be planned]\n**Requirements**: TBD\n**Depends on:** Phase ${afterPhase}\n**Plans:** 0 plans\n\nPlans:\n- [ ] TBD (run /vector:plan-phase ${decimalPhase} to break down)\n`;
360
+ // Insert after the target phase section
361
+ const headerPattern = new RegExp(`(#{2,4}\\s*Phase\\s+0*${afterPhaseEscaped}:[^\\n]*\\n)`, 'i');
362
+ const headerMatch = rawContent.match(headerPattern);
363
+ if (!headerMatch) {
364
+ (0, core_cjs_1.error)(`Could not find Phase ${afterPhase} header`);
365
+ }
366
+ const headerIdx = rawContent.indexOf(headerMatch[0]);
367
+ const afterHeader = rawContent.slice(headerIdx + headerMatch[0].length);
368
+ const nextPhaseMatch = afterHeader.match(/\n#{2,4}\s+Phase\s+\d/i);
369
+ let insertIdx;
370
+ if (nextPhaseMatch) {
371
+ insertIdx = headerIdx + headerMatch[0].length + nextPhaseMatch.index;
372
+ }
373
+ else {
374
+ insertIdx = rawContent.length;
375
+ }
376
+ const updatedContent = rawContent.slice(0, insertIdx) + phaseEntry + rawContent.slice(insertIdx);
377
+ fs_1.default.writeFileSync(roadmapPath, updatedContent, 'utf-8');
378
+ const result = {
379
+ phase_number: decimalPhase,
380
+ after_phase: afterPhase,
381
+ name: description,
382
+ slug,
383
+ directory: `.planning/phases/${dirName}`,
384
+ };
385
+ (0, core_cjs_1.output)(result, raw, decimalPhase);
386
+ }
387
+ function cmdPhaseRemove(cwd, targetPhase, options, raw) {
388
+ if (!targetPhase) {
389
+ (0, core_cjs_1.error)('phase number required for phase remove');
390
+ }
391
+ const roadmapPath = path_1.default.join(cwd, '.planning', 'ROADMAP.md');
392
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
393
+ const force = options.force || false;
394
+ if (!fs_1.default.existsSync(roadmapPath)) {
395
+ (0, core_cjs_1.error)('ROADMAP.md not found');
396
+ }
397
+ // Normalize the target
398
+ const normalized = (0, core_cjs_1.normalizePhaseName)(targetPhase);
399
+ const isDecimal = targetPhase.includes('.');
400
+ // Find and validate target directory
401
+ let targetDir = null;
402
+ try {
403
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
404
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
405
+ targetDir = dirs.find(d => d.startsWith(normalized + '-') || d === normalized) || null;
406
+ }
407
+ catch { }
408
+ // Check for executed work (SUMMARY.md files)
409
+ if (targetDir && !force) {
410
+ const targetPath = path_1.default.join(phasesDir, targetDir);
411
+ const files = fs_1.default.readdirSync(targetPath);
412
+ const summaries = files.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
413
+ if (summaries.length > 0) {
414
+ (0, core_cjs_1.error)(`Phase ${targetPhase} has ${summaries.length} executed plan(s). Use --force to remove anyway.`);
415
+ }
416
+ }
417
+ // Delete target directory
418
+ if (targetDir) {
419
+ fs_1.default.rmSync(path_1.default.join(phasesDir, targetDir), { recursive: true, force: true });
420
+ }
421
+ // Renumber subsequent phases
422
+ const renamedDirs = [];
423
+ const renamedFiles = [];
424
+ if (isDecimal) {
425
+ // Decimal removal: renumber sibling decimals (e.g., removing 06.2 → 06.3 becomes 06.2)
426
+ const baseParts = normalized.split('.');
427
+ const baseInt = baseParts[0];
428
+ const removedDecimal = parseInt(baseParts[1], 10);
429
+ try {
430
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
431
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
432
+ // Find sibling decimals with higher numbers
433
+ const decPattern = new RegExp(`^${baseInt}\\.(\\d+)-(.+)$`);
434
+ const toRename = [];
435
+ for (const dir of dirs) {
436
+ const dm = dir.match(decPattern);
437
+ if (dm && parseInt(dm[1], 10) > removedDecimal) {
438
+ toRename.push({ dir, oldDecimal: parseInt(dm[1], 10), slug: dm[2] });
439
+ }
440
+ }
441
+ // Sort descending to avoid conflicts
442
+ toRename.sort((a, b) => b.oldDecimal - a.oldDecimal);
443
+ for (const item of toRename) {
444
+ const newDecimal = item.oldDecimal - 1;
445
+ const oldPhaseId = `${baseInt}.${item.oldDecimal}`;
446
+ const newPhaseId = `${baseInt}.${newDecimal}`;
447
+ const newDirName = `${baseInt}.${newDecimal}-${item.slug}`;
448
+ // Rename directory
449
+ fs_1.default.renameSync(path_1.default.join(phasesDir, item.dir), path_1.default.join(phasesDir, newDirName));
450
+ renamedDirs.push({ from: item.dir, to: newDirName });
451
+ // Rename files inside
452
+ const dirFiles = fs_1.default.readdirSync(path_1.default.join(phasesDir, newDirName));
453
+ for (const f of dirFiles) {
454
+ // Files may have phase prefix like "06.2-01-PLAN.md"
455
+ if (f.includes(oldPhaseId)) {
456
+ const newFileName = f.replace(oldPhaseId, newPhaseId);
457
+ fs_1.default.renameSync(path_1.default.join(phasesDir, newDirName, f), path_1.default.join(phasesDir, newDirName, newFileName));
458
+ renamedFiles.push({ from: f, to: newFileName });
459
+ }
460
+ }
461
+ }
462
+ }
463
+ catch { }
464
+ }
465
+ else {
466
+ // Integer removal: renumber all subsequent integer phases
467
+ const removedInt = parseInt(normalized, 10);
468
+ try {
469
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
470
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
471
+ // Collect directories that need renumbering (integer phases > removed, and their decimals/letters)
472
+ const toRename = [];
473
+ for (const dir of dirs) {
474
+ const dm = dir.match(/^(\d+)([A-Z])?(?:\.(\d+))?-(.+)$/i);
475
+ if (!dm)
476
+ continue;
477
+ const dirInt = parseInt(dm[1], 10);
478
+ if (dirInt > removedInt) {
479
+ toRename.push({
480
+ dir,
481
+ oldInt: dirInt,
482
+ letter: dm[2] ? dm[2].toUpperCase() : '',
483
+ decimal: dm[3] ? parseInt(dm[3], 10) : null,
484
+ slug: dm[4],
485
+ });
486
+ }
487
+ }
488
+ // Sort descending to avoid conflicts
489
+ toRename.sort((a, b) => {
490
+ if (a.oldInt !== b.oldInt)
491
+ return b.oldInt - a.oldInt;
492
+ return (b.decimal || 0) - (a.decimal || 0);
493
+ });
494
+ for (const item of toRename) {
495
+ const newInt = item.oldInt - 1;
496
+ const newPadded = String(newInt).padStart(2, '0');
497
+ const oldPadded = String(item.oldInt).padStart(2, '0');
498
+ const letterSuffix = item.letter || '';
499
+ const decimalSuffix = item.decimal !== null ? `.${item.decimal}` : '';
500
+ const oldPrefix = `${oldPadded}${letterSuffix}${decimalSuffix}`;
501
+ const newPrefix = `${newPadded}${letterSuffix}${decimalSuffix}`;
502
+ const newDirName = `${newPrefix}-${item.slug}`;
503
+ // Rename directory
504
+ fs_1.default.renameSync(path_1.default.join(phasesDir, item.dir), path_1.default.join(phasesDir, newDirName));
505
+ renamedDirs.push({ from: item.dir, to: newDirName });
506
+ // Rename files inside
507
+ const dirFiles = fs_1.default.readdirSync(path_1.default.join(phasesDir, newDirName));
508
+ for (const f of dirFiles) {
509
+ if (f.startsWith(oldPrefix)) {
510
+ const newFileName = newPrefix + f.slice(oldPrefix.length);
511
+ fs_1.default.renameSync(path_1.default.join(phasesDir, newDirName, f), path_1.default.join(phasesDir, newDirName, newFileName));
512
+ renamedFiles.push({ from: f, to: newFileName });
513
+ }
514
+ }
515
+ }
516
+ }
517
+ catch { }
518
+ }
519
+ // Update ROADMAP.md
520
+ let roadmapContent = fs_1.default.readFileSync(roadmapPath, 'utf-8');
521
+ // Remove the target phase section
522
+ const targetEscaped = (0, core_cjs_1.escapeRegex)(targetPhase);
523
+ const sectionPattern = new RegExp(`\\n?#{2,4}\\s*Phase\\s+${targetEscaped}\\s*:[\\s\\S]*?(?=\\n#{2,4}\\s+Phase\\s+\\d|$)`, 'i');
524
+ roadmapContent = roadmapContent.replace(sectionPattern, '');
525
+ // Remove from phase list (checkbox)
526
+ const checkboxPattern = new RegExp(`\\n?-\\s*\\[[ x]\\]\\s*.*Phase\\s+${targetEscaped}[:\\s][^\\n]*`, 'gi');
527
+ roadmapContent = roadmapContent.replace(checkboxPattern, '');
528
+ // Remove from progress table
529
+ const tableRowPattern = new RegExp(`\\n?\\|\\s*${targetEscaped}\\.?\\s[^|]*\\|[^\\n]*`, 'gi');
530
+ roadmapContent = roadmapContent.replace(tableRowPattern, '');
531
+ // Renumber references in ROADMAP for subsequent phases
532
+ if (!isDecimal) {
533
+ const removedInt = parseInt(normalized, 10);
534
+ // Collect all integer phases > removedInt
535
+ const maxPhase = 99; // reasonable upper bound
536
+ for (let oldNum = maxPhase; oldNum > removedInt; oldNum--) {
537
+ const newNum = oldNum - 1;
538
+ const oldStr = String(oldNum);
539
+ const newStr = String(newNum);
540
+ const oldPad = oldStr.padStart(2, '0');
541
+ const newPad = newStr.padStart(2, '0');
542
+ // Phase headings: ## Phase 18: or ### Phase 18: → ## Phase 17: or ### Phase 17:
543
+ roadmapContent = roadmapContent.replace(new RegExp(`(#{2,4}\\s*Phase\\s+)${oldStr}(\\s*:)`, 'gi'), `$1${newStr}$2`);
544
+ // Checkbox items: - [ ] **Phase 18:** → - [ ] **Phase 17:**
545
+ roadmapContent = roadmapContent.replace(new RegExp(`(Phase\\s+)${oldStr}([:\\s])`, 'g'), `$1${newStr}$2`);
546
+ // Plan references: 18-01 → 17-01
547
+ roadmapContent = roadmapContent.replace(new RegExp(`${oldPad}-(\\d{2})`, 'g'), `${newPad}-$1`);
548
+ // Table rows: | 18. → | 17.
549
+ roadmapContent = roadmapContent.replace(new RegExp(`(\\|\\s*)${oldStr}\\.\\s`, 'g'), `$1${newStr}. `);
550
+ // Depends on references
551
+ roadmapContent = roadmapContent.replace(new RegExp(`(Depends on:\\*\\*\\s*Phase\\s+)${oldStr}\\b`, 'gi'), `$1${newStr}`);
552
+ }
553
+ }
554
+ fs_1.default.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
555
+ // Update STATE.md phase count
556
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
557
+ if (fs_1.default.existsSync(statePath)) {
558
+ let stateContent = fs_1.default.readFileSync(statePath, 'utf-8');
559
+ // Update "Total Phases" field
560
+ const totalPattern = /(\*\*Total Phases:\*\*\s*)(\d+)/;
561
+ const totalMatch = stateContent.match(totalPattern);
562
+ if (totalMatch) {
563
+ const oldTotal = parseInt(totalMatch[2], 10);
564
+ stateContent = stateContent.replace(totalPattern, `$1${oldTotal - 1}`);
565
+ }
566
+ // Update "Phase: X of Y" pattern
567
+ const ofPattern = /(\bof\s+)(\d+)(\s*(?:\(|phases?))/i;
568
+ const ofMatch = stateContent.match(ofPattern);
569
+ if (ofMatch) {
570
+ const oldTotal = parseInt(ofMatch[2], 10);
571
+ stateContent = stateContent.replace(ofPattern, `$1${oldTotal - 1}$3`);
572
+ }
573
+ (0, state_cjs_1.writeStateMd)(statePath, stateContent, cwd);
574
+ }
575
+ const result = {
576
+ removed: targetPhase,
577
+ directory_deleted: targetDir || null,
578
+ renamed_directories: renamedDirs,
579
+ renamed_files: renamedFiles,
580
+ roadmap_updated: true,
581
+ state_updated: fs_1.default.existsSync(statePath),
582
+ };
583
+ (0, core_cjs_1.output)(result, raw);
584
+ }
585
+ function cmdPhaseComplete(cwd, phaseNum, raw) {
586
+ if (!phaseNum) {
587
+ (0, core_cjs_1.error)('phase number required for phase complete');
588
+ }
589
+ const roadmapPath = path_1.default.join(cwd, '.planning', 'ROADMAP.md');
590
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
591
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
592
+ const today = new Date().toISOString().split('T')[0];
593
+ // Verify phase info
594
+ const phaseInfo = (0, core_cjs_1.findPhaseInternal)(cwd, phaseNum);
595
+ if (!phaseInfo) {
596
+ (0, core_cjs_1.error)(`Phase ${phaseNum} not found`);
597
+ }
598
+ const planCount = phaseInfo.plans.length;
599
+ const summaryCount = phaseInfo.summaries.length;
600
+ let requirementsUpdated = false;
601
+ // Update ROADMAP.md: mark phase complete
602
+ if (fs_1.default.existsSync(roadmapPath)) {
603
+ let roadmapContent = fs_1.default.readFileSync(roadmapPath, 'utf-8');
604
+ // Checkbox: - [ ] Phase N: → - [x] Phase N: (...completed DATE)
605
+ const checkboxPattern = new RegExp(`(-\\s*\\[)[ ](\\]\\s*.*Phase\\s+${(0, core_cjs_1.escapeRegex)(phaseNum)}[:\\s][^\\n]*)`, 'i');
606
+ roadmapContent = (0, core_cjs_1.replaceInCurrentMilestone)(roadmapContent, checkboxPattern, `$1x$2 (completed ${today})`);
607
+ // Progress table: update Status to Complete, add date
608
+ const phaseEscaped = (0, core_cjs_1.escapeRegex)(phaseNum);
609
+ const tablePattern = new RegExp(`(\\|\\s*${phaseEscaped}\\.?\\s[^|]*\\|[^|]*\\|)\\s*[^|]*(\\|)\\s*[^|]*(\\|)`, 'i');
610
+ roadmapContent = (0, core_cjs_1.replaceInCurrentMilestone)(roadmapContent, tablePattern, `$1 Complete $2 ${today} $3`);
611
+ // Update plan count in phase section
612
+ const planCountPattern = new RegExp(`(#{2,4}\\s*Phase\\s+${phaseEscaped}[\\s\\S]*?\\*\\*Plans:\\*\\*\\s*)[^\\n]+`, 'i');
613
+ roadmapContent = (0, core_cjs_1.replaceInCurrentMilestone)(roadmapContent, planCountPattern, `$1${summaryCount}/${planCount} plans complete`);
614
+ fs_1.default.writeFileSync(roadmapPath, roadmapContent, 'utf-8');
615
+ // Update REQUIREMENTS.md traceability for this phase's requirements
616
+ const reqPath = path_1.default.join(cwd, '.planning', 'REQUIREMENTS.md');
617
+ if (fs_1.default.existsSync(reqPath)) {
618
+ // Extract the current phase section from roadmap (scoped to avoid cross-phase matching)
619
+ const phaseEsc = (0, core_cjs_1.escapeRegex)(phaseNum);
620
+ const currentMilestoneRoadmap = (0, core_cjs_1.stripShippedMilestones)(roadmapContent);
621
+ const phaseSectionMatch = currentMilestoneRoadmap.match(new RegExp(`(#{2,4}\\s*Phase\\s+${phaseEsc}[:\\s][\\s\\S]*?)(?=#{2,4}\\s*Phase\\s+|$)`, 'i'));
622
+ const sectionText = phaseSectionMatch ? phaseSectionMatch[1] : '';
623
+ const reqMatch = sectionText.match(/\*\*Requirements:\*\*\s*([^\n]+)/i);
624
+ if (reqMatch) {
625
+ const reqIds = reqMatch[1].replace(/[\[\]]/g, '').split(/[,\s]+/).map(r => r.trim()).filter(Boolean);
626
+ let reqContent = fs_1.default.readFileSync(reqPath, 'utf-8');
627
+ for (const reqId of reqIds) {
628
+ const reqEscaped = (0, core_cjs_1.escapeRegex)(reqId);
629
+ // Update checkbox: - [ ] **REQ-ID** → - [x] **REQ-ID**
630
+ reqContent = reqContent.replace(new RegExp(`(-\\s*\\[)[ ](\\]\\s*\\*\\*${reqEscaped}\\*\\*)`, 'gi'), '$1x$2');
631
+ // Update traceability table: | REQ-ID | Phase N | Pending/In Progress | → | REQ-ID | Phase N | Complete |
632
+ reqContent = reqContent.replace(new RegExp(`(\\|\\s*${reqEscaped}\\s*\\|[^|]+\\|)\\s*(?:Pending|In Progress)\\s*(\\|)`, 'gi'), '$1 Complete $2');
633
+ }
634
+ fs_1.default.writeFileSync(reqPath, reqContent, 'utf-8');
635
+ requirementsUpdated = true;
636
+ }
637
+ }
638
+ }
639
+ // Find next phase — check both filesystem AND roadmap
640
+ let nextPhaseNum = null;
641
+ let nextPhaseName = null;
642
+ let isLastPhase = true;
643
+ try {
644
+ const isDirInMilestone = (0, core_cjs_1.getMilestonePhaseFilter)(cwd);
645
+ const entries = fs_1.default.readdirSync(phasesDir, { withFileTypes: true });
646
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name)
647
+ .filter(isDirInMilestone)
648
+ .sort((a, b) => (0, core_cjs_1.comparePhaseNum)(a, b));
649
+ // Find the next phase directory after current
650
+ for (const dir of dirs) {
651
+ const dm = dir.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
652
+ if (dm) {
653
+ if ((0, core_cjs_1.comparePhaseNum)(dm[1], phaseNum) > 0) {
654
+ nextPhaseNum = dm[1];
655
+ nextPhaseName = dm[2] || null;
656
+ isLastPhase = false;
657
+ break;
658
+ }
659
+ }
660
+ }
661
+ }
662
+ catch { }
663
+ // Fallback: if filesystem found no next phase, check ROADMAP.md
664
+ if (isLastPhase && fs_1.default.existsSync(roadmapPath)) {
665
+ try {
666
+ const roadmapForPhases = (0, core_cjs_1.stripShippedMilestones)(fs_1.default.readFileSync(roadmapPath, 'utf-8'));
667
+ const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:\s*([^\n]+)/gi;
668
+ let pm;
669
+ while ((pm = phasePattern.exec(roadmapForPhases)) !== null) {
670
+ if ((0, core_cjs_1.comparePhaseNum)(pm[1], phaseNum) > 0) {
671
+ nextPhaseNum = pm[1];
672
+ nextPhaseName = pm[2].replace(/\(INSERTED\)/i, '').trim().toLowerCase().replace(/\s+/g, '-');
673
+ isLastPhase = false;
674
+ break;
675
+ }
676
+ }
677
+ }
678
+ catch { }
679
+ }
680
+ // Update STATE.md
681
+ if (fs_1.default.existsSync(statePath)) {
682
+ let stateContent = fs_1.default.readFileSync(statePath, 'utf-8');
683
+ // Update Current Phase
684
+ stateContent = stateContent.replace(/(\*\*Current Phase:\*\*\s*).*/, `$1${nextPhaseNum || phaseNum}`);
685
+ // Update Current Phase Name
686
+ if (nextPhaseName) {
687
+ stateContent = stateContent.replace(/(\*\*Current Phase Name:\*\*\s*).*/, `$1${nextPhaseName.replace(/-/g, ' ')}`);
688
+ }
689
+ // Update Status
690
+ stateContent = stateContent.replace(/(\*\*Status:\*\*\s*).*/, `$1${isLastPhase ? 'Milestone complete' : 'Ready to plan'}`);
691
+ // Update Current Plan
692
+ stateContent = stateContent.replace(/(\*\*Current Plan:\*\*\s*).*/, `$1Not started`);
693
+ // Update Last Activity
694
+ stateContent = stateContent.replace(/(\*\*Last Activity:\*\*\s*).*/, `$1${today}`);
695
+ // Update Last Activity Description
696
+ stateContent = stateContent.replace(/(\*\*Last Activity Description:\*\*\s*).*/, `$1Phase ${phaseNum} complete${nextPhaseNum ? `, transitioned to Phase ${nextPhaseNum}` : ''}`);
697
+ (0, state_cjs_1.writeStateMd)(statePath, stateContent, cwd);
698
+ }
699
+ const result = {
700
+ completed_phase: phaseNum,
701
+ phase_name: phaseInfo.phase_name,
702
+ plans_executed: `${summaryCount}/${planCount}`,
703
+ next_phase: nextPhaseNum,
704
+ next_phase_name: nextPhaseName,
705
+ is_last_phase: isLastPhase,
706
+ date: today,
707
+ roadmap_updated: fs_1.default.existsSync(roadmapPath),
708
+ state_updated: fs_1.default.existsSync(statePath),
709
+ requirements_updated: requirementsUpdated,
710
+ };
711
+ (0, core_cjs_1.output)(result, raw);
712
+ }
713
+ //# sourceMappingURL=phase.cjs.map