@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,709 @@
1
+ "use strict";
2
+ /**
3
+ * State — STATE.md operations and progression engine
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.stateExtractField = stateExtractField;
10
+ exports.cmdStateLoad = cmdStateLoad;
11
+ exports.cmdStateGet = cmdStateGet;
12
+ exports.cmdStatePatch = cmdStatePatch;
13
+ exports.cmdStateUpdate = cmdStateUpdate;
14
+ exports.stateReplaceField = stateReplaceField;
15
+ exports.cmdStateAdvancePlan = cmdStateAdvancePlan;
16
+ exports.cmdStateRecordMetric = cmdStateRecordMetric;
17
+ exports.cmdStateUpdateProgress = cmdStateUpdateProgress;
18
+ exports.cmdStateAddDecision = cmdStateAddDecision;
19
+ exports.cmdStateAddBlocker = cmdStateAddBlocker;
20
+ exports.cmdStateResolveBlocker = cmdStateResolveBlocker;
21
+ exports.cmdStateRecordSession = cmdStateRecordSession;
22
+ exports.cmdStateSnapshot = cmdStateSnapshot;
23
+ exports.writeStateMd = writeStateMd;
24
+ exports.cmdStateJson = cmdStateJson;
25
+ const fs_1 = __importDefault(require("fs"));
26
+ const path_1 = __importDefault(require("path"));
27
+ const core_cjs_1 = require("./core.cjs");
28
+ const frontmatter_cjs_1 = require("./frontmatter.cjs");
29
+ // Shared helper: extract a field value from STATE.md content.
30
+ // Supports both **Field:** bold and plain Field: format.
31
+ function stateExtractField(content, fieldName) {
32
+ const escaped = (0, core_cjs_1.escapeRegex)(fieldName);
33
+ const boldPattern = new RegExp(`\\*\\*${escaped}:\\*\\*\\s*(.+)`, 'i');
34
+ const boldMatch = content.match(boldPattern);
35
+ if (boldMatch)
36
+ return boldMatch[1].trim();
37
+ const plainPattern = new RegExp(`^${escaped}:\\s*(.+)`, 'im');
38
+ const plainMatch = content.match(plainPattern);
39
+ return plainMatch ? plainMatch[1].trim() : null;
40
+ }
41
+ function cmdStateLoad(cwd, raw) {
42
+ const config = (0, core_cjs_1.loadConfig)(cwd);
43
+ const planningDir = path_1.default.join(cwd, '.planning');
44
+ let stateRaw = '';
45
+ try {
46
+ stateRaw = fs_1.default.readFileSync(path_1.default.join(planningDir, 'STATE.md'), 'utf-8');
47
+ }
48
+ catch { }
49
+ const configExists = fs_1.default.existsSync(path_1.default.join(planningDir, 'config.json'));
50
+ const roadmapExists = fs_1.default.existsSync(path_1.default.join(planningDir, 'ROADMAP.md'));
51
+ const stateExists = stateRaw.length > 0;
52
+ const result = {
53
+ config,
54
+ state_raw: stateRaw,
55
+ state_exists: stateExists,
56
+ roadmap_exists: roadmapExists,
57
+ config_exists: configExists,
58
+ };
59
+ // For --raw, output a condensed key=value format
60
+ if (raw) {
61
+ const c = config;
62
+ const lines = [
63
+ `model_profile=${c.model_profile}`,
64
+ `commit_docs=${c.commit_docs}`,
65
+ `branching_strategy=${c.branching_strategy}`,
66
+ `phase_branch_template=${c.phase_branch_template}`,
67
+ `milestone_branch_template=${c.milestone_branch_template}`,
68
+ `parallelization=${c.parallelization}`,
69
+ `research=${c.research}`,
70
+ `plan_checker=${c.plan_checker}`,
71
+ `verifier=${c.verifier}`,
72
+ `config_exists=${configExists}`,
73
+ `roadmap_exists=${roadmapExists}`,
74
+ `state_exists=${stateExists}`,
75
+ ];
76
+ process.stdout.write(lines.join('\n'));
77
+ process.exit(0);
78
+ }
79
+ (0, core_cjs_1.output)(result);
80
+ }
81
+ function cmdStateGet(cwd, section, raw) {
82
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
83
+ try {
84
+ const content = fs_1.default.readFileSync(statePath, 'utf-8');
85
+ if (!section) {
86
+ (0, core_cjs_1.output)({ content }, raw, content);
87
+ return;
88
+ }
89
+ // Try to find markdown section or field
90
+ const fieldEscaped = section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
91
+ // Check for **field:** value (bold format)
92
+ const boldPattern = new RegExp(`\\*\\*${fieldEscaped}:\\*\\*\\s*(.*)`, 'i');
93
+ const boldMatch = content.match(boldPattern);
94
+ if (boldMatch) {
95
+ (0, core_cjs_1.output)({ [section]: boldMatch[1].trim() }, raw, boldMatch[1].trim());
96
+ return;
97
+ }
98
+ // Check for field: value (plain format)
99
+ const plainPattern = new RegExp(`^${fieldEscaped}:\\s*(.*)`, 'im');
100
+ const plainMatch = content.match(plainPattern);
101
+ if (plainMatch) {
102
+ (0, core_cjs_1.output)({ [section]: plainMatch[1].trim() }, raw, plainMatch[1].trim());
103
+ return;
104
+ }
105
+ // Check for ## Section
106
+ const sectionPattern = new RegExp(`##\\s*${fieldEscaped}\\s*\n([\\s\\S]*?)(?=\\n##|$)`, 'i');
107
+ const sectionMatch = content.match(sectionPattern);
108
+ if (sectionMatch) {
109
+ (0, core_cjs_1.output)({ [section]: sectionMatch[1].trim() }, raw, sectionMatch[1].trim());
110
+ return;
111
+ }
112
+ (0, core_cjs_1.output)({ error: `Section or field "${section}" not found` }, raw, '');
113
+ }
114
+ catch {
115
+ (0, core_cjs_1.error)('STATE.md not found');
116
+ }
117
+ }
118
+ function readTextArgOrFile(cwd, value, filePath, label) {
119
+ if (!filePath)
120
+ return value ?? null;
121
+ const resolvedPath = path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath);
122
+ try {
123
+ return fs_1.default.readFileSync(resolvedPath, 'utf-8').trimEnd();
124
+ }
125
+ catch {
126
+ throw new Error(`${label} file not found: ${filePath}`);
127
+ }
128
+ }
129
+ function cmdStatePatch(cwd, patches, raw) {
130
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
131
+ try {
132
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
133
+ const results = { updated: [], failed: [] };
134
+ for (const [field, value] of Object.entries(patches)) {
135
+ const fieldEscaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
136
+ // Try **Field:** bold format first, then plain Field: format
137
+ const boldPattern = new RegExp(`(\\*\\*${fieldEscaped}:\\*\\*\\s*)(.*)`, 'i');
138
+ const plainPattern = new RegExp(`(^${fieldEscaped}:\\s*)(.*)`, 'im');
139
+ if (boldPattern.test(content)) {
140
+ content = content.replace(boldPattern, (_match, prefix) => `${prefix}${value}`);
141
+ results.updated.push(field);
142
+ }
143
+ else if (plainPattern.test(content)) {
144
+ content = content.replace(plainPattern, (_match, prefix) => `${prefix}${value}`);
145
+ results.updated.push(field);
146
+ }
147
+ else {
148
+ results.failed.push(field);
149
+ }
150
+ }
151
+ if (results.updated.length > 0) {
152
+ writeStateMd(statePath, content, cwd);
153
+ }
154
+ (0, core_cjs_1.output)(results, raw, results.updated.length > 0 ? 'true' : 'false');
155
+ }
156
+ catch {
157
+ (0, core_cjs_1.error)('STATE.md not found');
158
+ }
159
+ }
160
+ function cmdStateUpdate(cwd, field, value) {
161
+ if (!field || value === undefined) {
162
+ (0, core_cjs_1.error)('field and value required for state update');
163
+ }
164
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
165
+ try {
166
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
167
+ const fieldEscaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
168
+ // Try **Field:** bold format first, then plain Field: format
169
+ const boldPattern = new RegExp(`(\\*\\*${fieldEscaped}:\\*\\*\\s*)(.*)`, 'i');
170
+ const plainPattern = new RegExp(`(^${fieldEscaped}:\\s*)(.*)`, 'im');
171
+ if (boldPattern.test(content)) {
172
+ content = content.replace(boldPattern, (_match, prefix) => `${prefix}${value}`);
173
+ writeStateMd(statePath, content, cwd);
174
+ (0, core_cjs_1.output)({ updated: true });
175
+ }
176
+ else if (plainPattern.test(content)) {
177
+ content = content.replace(plainPattern, (_match, prefix) => `${prefix}${value}`);
178
+ writeStateMd(statePath, content, cwd);
179
+ (0, core_cjs_1.output)({ updated: true });
180
+ }
181
+ else {
182
+ (0, core_cjs_1.output)({ updated: false, reason: `Field "${field}" not found in STATE.md` });
183
+ }
184
+ }
185
+ catch {
186
+ (0, core_cjs_1.output)({ updated: false, reason: 'STATE.md not found' });
187
+ }
188
+ }
189
+ // ─── State Progression Engine ────────────────────────────────────────────────
190
+ function stateReplaceField(content, fieldName, newValue) {
191
+ const escaped = fieldName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
192
+ // Try **Field:** bold format first, then plain Field: format
193
+ const boldPattern = new RegExp(`(\\*\\*${escaped}:\\*\\*\\s*)(.*)`, 'i');
194
+ if (boldPattern.test(content)) {
195
+ return content.replace(boldPattern, (_match, prefix) => `${prefix}${newValue}`);
196
+ }
197
+ const plainPattern = new RegExp(`(^${escaped}:\\s*)(.*)`, 'im');
198
+ if (plainPattern.test(content)) {
199
+ return content.replace(plainPattern, (_match, prefix) => `${prefix}${newValue}`);
200
+ }
201
+ return null;
202
+ }
203
+ function cmdStateAdvancePlan(cwd, raw) {
204
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
205
+ if (!fs_1.default.existsSync(statePath)) {
206
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
207
+ return;
208
+ }
209
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
210
+ const currentPlan = parseInt(stateExtractField(content, 'Current Plan') ?? '', 10);
211
+ const totalPlans = parseInt(stateExtractField(content, 'Total Plans in Phase') ?? '', 10);
212
+ const today = new Date().toISOString().split('T')[0];
213
+ if (isNaN(currentPlan) || isNaN(totalPlans)) {
214
+ (0, core_cjs_1.output)({ error: 'Cannot parse Current Plan or Total Plans in Phase from STATE.md' }, raw);
215
+ return;
216
+ }
217
+ if (currentPlan >= totalPlans) {
218
+ content = stateReplaceField(content, 'Status', 'Phase complete — ready for verification') || content;
219
+ content = stateReplaceField(content, 'Last Activity', today) || content;
220
+ writeStateMd(statePath, content, cwd);
221
+ (0, core_cjs_1.output)({ advanced: false, reason: 'last_plan', current_plan: currentPlan, total_plans: totalPlans, status: 'ready_for_verification' }, raw, 'false');
222
+ }
223
+ else {
224
+ const newPlan = currentPlan + 1;
225
+ content = stateReplaceField(content, 'Current Plan', String(newPlan)) || content;
226
+ content = stateReplaceField(content, 'Status', 'Ready to execute') || content;
227
+ content = stateReplaceField(content, 'Last Activity', today) || content;
228
+ writeStateMd(statePath, content, cwd);
229
+ (0, core_cjs_1.output)({ advanced: true, previous_plan: currentPlan, current_plan: newPlan, total_plans: totalPlans }, raw, 'true');
230
+ }
231
+ }
232
+ function cmdStateRecordMetric(cwd, options, raw) {
233
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
234
+ if (!fs_1.default.existsSync(statePath)) {
235
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
236
+ return;
237
+ }
238
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
239
+ const { phase, plan, duration, tasks, files } = options;
240
+ if (!phase || !plan || !duration) {
241
+ (0, core_cjs_1.output)({ error: 'phase, plan, and duration required' }, raw);
242
+ return;
243
+ }
244
+ // Find Performance Metrics section and its table
245
+ const metricsPattern = /(##\s*Performance Metrics[\s\S]*?\n\|[^\n]+\n\|[-|\s]+\n)([\s\S]*?)(?=\n##|\n$|$)/i;
246
+ const metricsMatch = content.match(metricsPattern);
247
+ if (metricsMatch) {
248
+ let tableBody = metricsMatch[2].trimEnd();
249
+ const newRow = `| Phase ${phase} P${plan} | ${duration} | ${tasks || '-'} tasks | ${files || '-'} files |`;
250
+ if (tableBody.trim() === '' || tableBody.includes('None yet')) {
251
+ tableBody = newRow;
252
+ }
253
+ else {
254
+ tableBody = tableBody + '\n' + newRow;
255
+ }
256
+ content = content.replace(metricsPattern, (_match, header) => `${header}${tableBody}\n`);
257
+ writeStateMd(statePath, content, cwd);
258
+ (0, core_cjs_1.output)({ recorded: true, phase, plan, duration }, raw, 'true');
259
+ }
260
+ else {
261
+ (0, core_cjs_1.output)({ recorded: false, reason: 'Performance Metrics section not found in STATE.md' }, raw, 'false');
262
+ }
263
+ }
264
+ function cmdStateUpdateProgress(cwd, raw) {
265
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
266
+ if (!fs_1.default.existsSync(statePath)) {
267
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
268
+ return;
269
+ }
270
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
271
+ // Count summaries across current milestone phases only
272
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
273
+ let totalPlans = 0;
274
+ let totalSummaries = 0;
275
+ if (fs_1.default.existsSync(phasesDir)) {
276
+ const isDirInMilestone = (0, core_cjs_1.getMilestonePhaseFilter)(cwd);
277
+ const phaseDirs = fs_1.default.readdirSync(phasesDir, { withFileTypes: true })
278
+ .filter(e => e.isDirectory()).map(e => e.name)
279
+ .filter(isDirInMilestone);
280
+ for (const dir of phaseDirs) {
281
+ const files = fs_1.default.readdirSync(path_1.default.join(phasesDir, dir));
282
+ totalPlans += files.filter(f => f.match(/-PLAN\.md$/i)).length;
283
+ totalSummaries += files.filter(f => f.match(/-SUMMARY\.md$/i)).length;
284
+ }
285
+ }
286
+ const percent = totalPlans > 0 ? Math.min(100, Math.round(totalSummaries / totalPlans * 100)) : 0;
287
+ const barWidth = 10;
288
+ const filled = Math.round(percent / 100 * barWidth);
289
+ const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
290
+ const progressStr = `[${bar}] ${percent}%`;
291
+ // Try **Progress:** bold format first, then plain Progress: format
292
+ const boldProgressPattern = /(\*\*Progress:\*\*\s*).*/i;
293
+ const plainProgressPattern = /^(Progress:\s*).*/im;
294
+ if (boldProgressPattern.test(content)) {
295
+ content = content.replace(boldProgressPattern, (_match, prefix) => `${prefix}${progressStr}`);
296
+ writeStateMd(statePath, content, cwd);
297
+ (0, core_cjs_1.output)({ updated: true, percent, completed: totalSummaries, total: totalPlans, bar: progressStr }, raw, progressStr);
298
+ }
299
+ else if (plainProgressPattern.test(content)) {
300
+ content = content.replace(plainProgressPattern, (_match, prefix) => `${prefix}${progressStr}`);
301
+ writeStateMd(statePath, content, cwd);
302
+ (0, core_cjs_1.output)({ updated: true, percent, completed: totalSummaries, total: totalPlans, bar: progressStr }, raw, progressStr);
303
+ }
304
+ else {
305
+ (0, core_cjs_1.output)({ updated: false, reason: 'Progress field not found in STATE.md' }, raw, 'false');
306
+ }
307
+ }
308
+ function cmdStateAddDecision(cwd, options, raw) {
309
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
310
+ if (!fs_1.default.existsSync(statePath)) {
311
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
312
+ return;
313
+ }
314
+ const { phase, summary, summary_file, rationale, rationale_file } = options;
315
+ let summaryText = null;
316
+ let rationaleText = '';
317
+ try {
318
+ summaryText = readTextArgOrFile(cwd, summary, summary_file, 'summary');
319
+ rationaleText = readTextArgOrFile(cwd, rationale || '', rationale_file, 'rationale') || '';
320
+ }
321
+ catch (err) {
322
+ (0, core_cjs_1.output)({ added: false, reason: err.message }, raw, 'false');
323
+ return;
324
+ }
325
+ if (!summaryText) {
326
+ (0, core_cjs_1.output)({ error: 'summary required' }, raw);
327
+ return;
328
+ }
329
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
330
+ const entry = `- [Phase ${phase || '?'}]: ${summaryText}${rationaleText ? ` — ${rationaleText}` : ''}`;
331
+ // Find Decisions section (various heading patterns)
332
+ const sectionPattern = /(###?\s*(?:Decisions|Decisions Made|Accumulated.*Decisions)\s*\n)([\s\S]*?)(?=\n###?|\n##[^#]|$)/i;
333
+ const match = content.match(sectionPattern);
334
+ if (match) {
335
+ let sectionBody = match[2];
336
+ // Remove placeholders
337
+ sectionBody = sectionBody.replace(/None yet\.?\s*\n?/gi, '').replace(/No decisions yet\.?\s*\n?/gi, '');
338
+ sectionBody = sectionBody.trimEnd() + '\n' + entry + '\n';
339
+ content = content.replace(sectionPattern, (_match, header) => `${header}${sectionBody}`);
340
+ writeStateMd(statePath, content, cwd);
341
+ (0, core_cjs_1.output)({ added: true, decision: entry }, raw, 'true');
342
+ }
343
+ else {
344
+ (0, core_cjs_1.output)({ added: false, reason: 'Decisions section not found in STATE.md' }, raw, 'false');
345
+ }
346
+ }
347
+ function cmdStateAddBlocker(cwd, text, raw) {
348
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
349
+ if (!fs_1.default.existsSync(statePath)) {
350
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
351
+ return;
352
+ }
353
+ const blockerOptions = typeof text === 'object' && text !== null ? text : { text: text };
354
+ let blockerText = null;
355
+ try {
356
+ blockerText = readTextArgOrFile(cwd, blockerOptions.text, blockerOptions.text_file, 'blocker');
357
+ }
358
+ catch (err) {
359
+ (0, core_cjs_1.output)({ added: false, reason: err.message }, raw, 'false');
360
+ return;
361
+ }
362
+ if (!blockerText) {
363
+ (0, core_cjs_1.output)({ error: 'text required' }, raw);
364
+ return;
365
+ }
366
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
367
+ const entry = `- ${blockerText}`;
368
+ const sectionPattern = /(###?\s*(?:Blockers|Blockers\/Concerns|Concerns)\s*\n)([\s\S]*?)(?=\n###?|\n##[^#]|$)/i;
369
+ const match = content.match(sectionPattern);
370
+ if (match) {
371
+ let sectionBody = match[2];
372
+ sectionBody = sectionBody.replace(/None\.?\s*\n?/gi, '').replace(/None yet\.?\s*\n?/gi, '');
373
+ sectionBody = sectionBody.trimEnd() + '\n' + entry + '\n';
374
+ content = content.replace(sectionPattern, (_match, header) => `${header}${sectionBody}`);
375
+ writeStateMd(statePath, content, cwd);
376
+ (0, core_cjs_1.output)({ added: true, blocker: blockerText }, raw, 'true');
377
+ }
378
+ else {
379
+ (0, core_cjs_1.output)({ added: false, reason: 'Blockers section not found in STATE.md' }, raw, 'false');
380
+ }
381
+ }
382
+ function cmdStateResolveBlocker(cwd, text, raw) {
383
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
384
+ if (!fs_1.default.existsSync(statePath)) {
385
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
386
+ return;
387
+ }
388
+ if (!text) {
389
+ (0, core_cjs_1.output)({ error: 'text required' }, raw);
390
+ return;
391
+ }
392
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
393
+ const sectionPattern = /(###?\s*(?:Blockers|Blockers\/Concerns|Concerns)\s*\n)([\s\S]*?)(?=\n###?|\n##[^#]|$)/i;
394
+ const match = content.match(sectionPattern);
395
+ if (match) {
396
+ const sectionBody = match[2];
397
+ const lines = sectionBody.split('\n');
398
+ const filtered = lines.filter(line => {
399
+ if (!line.startsWith('- '))
400
+ return true;
401
+ return !line.toLowerCase().includes(text.toLowerCase());
402
+ });
403
+ let newBody = filtered.join('\n');
404
+ // If section is now empty, add placeholder
405
+ if (!newBody.trim() || !newBody.includes('- ')) {
406
+ newBody = 'None\n';
407
+ }
408
+ content = content.replace(sectionPattern, (_match, header) => `${header}${newBody}`);
409
+ writeStateMd(statePath, content, cwd);
410
+ (0, core_cjs_1.output)({ resolved: true, blocker: text }, raw, 'true');
411
+ }
412
+ else {
413
+ (0, core_cjs_1.output)({ resolved: false, reason: 'Blockers section not found in STATE.md' }, raw, 'false');
414
+ }
415
+ }
416
+ function cmdStateRecordSession(cwd, options, raw) {
417
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
418
+ if (!fs_1.default.existsSync(statePath)) {
419
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
420
+ return;
421
+ }
422
+ let content = fs_1.default.readFileSync(statePath, 'utf-8');
423
+ const now = new Date().toISOString();
424
+ const updated = [];
425
+ // Update Last session / Last Date
426
+ let result = stateReplaceField(content, 'Last session', now);
427
+ if (result) {
428
+ content = result;
429
+ updated.push('Last session');
430
+ }
431
+ result = stateReplaceField(content, 'Last Date', now);
432
+ if (result) {
433
+ content = result;
434
+ updated.push('Last Date');
435
+ }
436
+ // Update Stopped at
437
+ if (options.stopped_at) {
438
+ result = stateReplaceField(content, 'Stopped At', options.stopped_at);
439
+ if (!result)
440
+ result = stateReplaceField(content, 'Stopped at', options.stopped_at);
441
+ if (result) {
442
+ content = result;
443
+ updated.push('Stopped At');
444
+ }
445
+ }
446
+ // Update Resume file
447
+ const resumeFile = options.resume_file || 'None';
448
+ result = stateReplaceField(content, 'Resume File', resumeFile);
449
+ if (!result)
450
+ result = stateReplaceField(content, 'Resume file', resumeFile);
451
+ if (result) {
452
+ content = result;
453
+ updated.push('Resume File');
454
+ }
455
+ if (updated.length > 0) {
456
+ writeStateMd(statePath, content, cwd);
457
+ (0, core_cjs_1.output)({ recorded: true, updated }, raw, 'true');
458
+ }
459
+ else {
460
+ (0, core_cjs_1.output)({ recorded: false, reason: 'No session fields found in STATE.md' }, raw, 'false');
461
+ }
462
+ }
463
+ function cmdStateSnapshot(cwd, raw) {
464
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
465
+ if (!fs_1.default.existsSync(statePath)) {
466
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw);
467
+ return;
468
+ }
469
+ const content = fs_1.default.readFileSync(statePath, 'utf-8');
470
+ // Extract basic fields
471
+ const currentPhase = stateExtractField(content, 'Current Phase');
472
+ const currentPhaseName = stateExtractField(content, 'Current Phase Name');
473
+ const totalPhasesRaw = stateExtractField(content, 'Total Phases');
474
+ const currentPlan = stateExtractField(content, 'Current Plan');
475
+ const totalPlansRaw = stateExtractField(content, 'Total Plans in Phase');
476
+ const status = stateExtractField(content, 'Status');
477
+ const progressRaw = stateExtractField(content, 'Progress');
478
+ const lastActivity = stateExtractField(content, 'Last Activity');
479
+ const lastActivityDesc = stateExtractField(content, 'Last Activity Description');
480
+ const pausedAt = stateExtractField(content, 'Paused At');
481
+ // Parse numeric fields
482
+ const totalPhases = totalPhasesRaw ? parseInt(totalPhasesRaw, 10) : null;
483
+ const totalPlansInPhase = totalPlansRaw ? parseInt(totalPlansRaw, 10) : null;
484
+ const progressPercent = progressRaw ? parseInt(progressRaw.replace('%', ''), 10) : null;
485
+ // Extract decisions table
486
+ const decisions = [];
487
+ const decisionsMatch = content.match(/##\s*Decisions Made[\s\S]*?\n\|[^\n]+\n\|[-|\s]+\n([\s\S]*?)(?=\n##|\n$|$)/i);
488
+ if (decisionsMatch) {
489
+ const tableBody = decisionsMatch[1];
490
+ const rows = tableBody.trim().split('\n').filter(r => r.includes('|'));
491
+ for (const row of rows) {
492
+ const cells = row.split('|').map(c => c.trim()).filter(Boolean);
493
+ if (cells.length >= 3) {
494
+ decisions.push({
495
+ phase: cells[0],
496
+ summary: cells[1],
497
+ rationale: cells[2],
498
+ });
499
+ }
500
+ }
501
+ }
502
+ // Extract blockers list
503
+ const blockers = [];
504
+ const blockersMatch = content.match(/##\s*Blockers\s*\n([\s\S]*?)(?=\n##|$)/i);
505
+ if (blockersMatch) {
506
+ const blockersSection = blockersMatch[1];
507
+ const items = blockersSection.match(/^-\s+(.+)$/gm) || [];
508
+ for (const item of items) {
509
+ blockers.push(item.replace(/^-\s+/, '').trim());
510
+ }
511
+ }
512
+ // Extract session info
513
+ const session = {
514
+ last_date: null,
515
+ stopped_at: null,
516
+ resume_file: null,
517
+ };
518
+ const sessionMatch = content.match(/##\s*Session\s*\n([\s\S]*?)(?=\n##|$)/i);
519
+ if (sessionMatch) {
520
+ const sessionSection = sessionMatch[1];
521
+ const lastDateMatch = sessionSection.match(/\*\*Last Date:\*\*\s*(.+)/i)
522
+ || sessionSection.match(/^Last Date:\s*(.+)/im);
523
+ const stoppedAtMatch = sessionSection.match(/\*\*Stopped At:\*\*\s*(.+)/i)
524
+ || sessionSection.match(/^Stopped At:\s*(.+)/im);
525
+ const resumeFileMatch = sessionSection.match(/\*\*Resume File:\*\*\s*(.+)/i)
526
+ || sessionSection.match(/^Resume File:\s*(.+)/im);
527
+ if (lastDateMatch)
528
+ session.last_date = lastDateMatch[1].trim();
529
+ if (stoppedAtMatch)
530
+ session.stopped_at = stoppedAtMatch[1].trim();
531
+ if (resumeFileMatch)
532
+ session.resume_file = resumeFileMatch[1].trim();
533
+ }
534
+ const result = {
535
+ current_phase: currentPhase,
536
+ current_phase_name: currentPhaseName,
537
+ total_phases: totalPhases,
538
+ current_plan: currentPlan,
539
+ total_plans_in_phase: totalPlansInPhase,
540
+ status,
541
+ progress_percent: progressPercent,
542
+ last_activity: lastActivity,
543
+ last_activity_desc: lastActivityDesc,
544
+ decisions,
545
+ blockers,
546
+ paused_at: pausedAt,
547
+ session,
548
+ };
549
+ (0, core_cjs_1.output)(result, raw);
550
+ }
551
+ // ─── State Frontmatter Sync ──────────────────────────────────────────────────
552
+ /**
553
+ * Extract machine-readable fields from STATE.md markdown body and build
554
+ * a YAML frontmatter object. Allows hooks and scripts to read state
555
+ * reliably via `state json` instead of fragile regex parsing.
556
+ */
557
+ function buildStateFrontmatter(bodyContent, cwd) {
558
+ const currentPhase = stateExtractField(bodyContent, 'Current Phase');
559
+ const currentPhaseName = stateExtractField(bodyContent, 'Current Phase Name');
560
+ const currentPlan = stateExtractField(bodyContent, 'Current Plan');
561
+ const totalPhasesRaw = stateExtractField(bodyContent, 'Total Phases');
562
+ const totalPlansRaw = stateExtractField(bodyContent, 'Total Plans in Phase');
563
+ const status = stateExtractField(bodyContent, 'Status');
564
+ const progressRaw = stateExtractField(bodyContent, 'Progress');
565
+ const lastActivity = stateExtractField(bodyContent, 'Last Activity');
566
+ const stoppedAt = stateExtractField(bodyContent, 'Stopped At') || stateExtractField(bodyContent, 'Stopped at');
567
+ const pausedAt = stateExtractField(bodyContent, 'Paused At');
568
+ let milestone = null;
569
+ let milestoneName = null;
570
+ if (cwd) {
571
+ try {
572
+ const info = (0, core_cjs_1.getMilestoneInfo)(cwd);
573
+ milestone = info.version;
574
+ milestoneName = info.name;
575
+ }
576
+ catch { }
577
+ }
578
+ let totalPhases = totalPhasesRaw ? parseInt(totalPhasesRaw, 10) : null;
579
+ let completedPhases = null;
580
+ let totalPlans = totalPlansRaw ? parseInt(totalPlansRaw, 10) : null;
581
+ let completedPlans = null;
582
+ if (cwd) {
583
+ try {
584
+ const phasesDir = path_1.default.join(cwd, '.planning', 'phases');
585
+ if (fs_1.default.existsSync(phasesDir)) {
586
+ const isDirInMilestone = (0, core_cjs_1.getMilestonePhaseFilter)(cwd);
587
+ const phaseDirs = fs_1.default.readdirSync(phasesDir, { withFileTypes: true })
588
+ .filter(e => e.isDirectory()).map(e => e.name)
589
+ .filter(isDirInMilestone);
590
+ let diskTotalPlans = 0;
591
+ let diskTotalSummaries = 0;
592
+ let diskCompletedPhases = 0;
593
+ for (const dir of phaseDirs) {
594
+ const files = fs_1.default.readdirSync(path_1.default.join(phasesDir, dir));
595
+ const plans = files.filter(f => f.match(/-PLAN\.md$/i)).length;
596
+ const summaries = files.filter(f => f.match(/-SUMMARY\.md$/i)).length;
597
+ diskTotalPlans += plans;
598
+ diskTotalSummaries += summaries;
599
+ if (plans > 0 && summaries >= plans)
600
+ diskCompletedPhases++;
601
+ }
602
+ totalPhases = isDirInMilestone.phaseCount > 0
603
+ ? Math.max(phaseDirs.length, isDirInMilestone.phaseCount)
604
+ : phaseDirs.length;
605
+ completedPhases = diskCompletedPhases;
606
+ totalPlans = diskTotalPlans;
607
+ completedPlans = diskTotalSummaries;
608
+ }
609
+ }
610
+ catch { }
611
+ }
612
+ let progressPercent = null;
613
+ if (progressRaw) {
614
+ const pctMatch = progressRaw.match(/(\d+)%/);
615
+ if (pctMatch)
616
+ progressPercent = parseInt(pctMatch[1], 10);
617
+ }
618
+ // Normalize status to one of: planning, discussing, executing, verifying, paused, completed, unknown
619
+ let normalizedStatus = status || 'unknown';
620
+ const statusLower = (status || '').toLowerCase();
621
+ if (statusLower.includes('paused') || statusLower.includes('stopped') || pausedAt) {
622
+ normalizedStatus = 'paused';
623
+ }
624
+ else if (statusLower.includes('executing') || statusLower.includes('in progress')) {
625
+ normalizedStatus = 'executing';
626
+ }
627
+ else if (statusLower.includes('planning') || statusLower.includes('ready to plan')) {
628
+ normalizedStatus = 'planning';
629
+ }
630
+ else if (statusLower.includes('discussing')) {
631
+ normalizedStatus = 'discussing';
632
+ }
633
+ else if (statusLower.includes('verif')) {
634
+ normalizedStatus = 'verifying';
635
+ }
636
+ else if (statusLower.includes('complete') || statusLower.includes('done')) {
637
+ normalizedStatus = 'completed';
638
+ }
639
+ else if (statusLower.includes('ready to execute')) {
640
+ normalizedStatus = 'executing';
641
+ }
642
+ const fm = { vector_state_version: '1.0' };
643
+ if (milestone)
644
+ fm.milestone = milestone;
645
+ if (milestoneName)
646
+ fm.milestone_name = milestoneName;
647
+ if (currentPhase)
648
+ fm.current_phase = currentPhase;
649
+ if (currentPhaseName)
650
+ fm.current_phase_name = currentPhaseName;
651
+ if (currentPlan)
652
+ fm.current_plan = currentPlan;
653
+ fm.status = normalizedStatus;
654
+ if (stoppedAt)
655
+ fm.stopped_at = stoppedAt;
656
+ if (pausedAt)
657
+ fm.paused_at = pausedAt;
658
+ fm.last_updated = new Date().toISOString();
659
+ if (lastActivity)
660
+ fm.last_activity = lastActivity;
661
+ const progress = {};
662
+ if (totalPhases !== null)
663
+ progress.total_phases = totalPhases;
664
+ if (completedPhases !== null)
665
+ progress.completed_phases = completedPhases;
666
+ if (totalPlans !== null)
667
+ progress.total_plans = totalPlans;
668
+ if (completedPlans !== null)
669
+ progress.completed_plans = completedPlans;
670
+ if (progressPercent !== null)
671
+ progress.percent = progressPercent;
672
+ if (Object.keys(progress).length > 0)
673
+ fm.progress = progress;
674
+ return fm;
675
+ }
676
+ function stripFrontmatter(content) {
677
+ return content.replace(/^---\n[\s\S]*?\n---\n*/, '');
678
+ }
679
+ function syncStateFrontmatter(content, cwd) {
680
+ const body = stripFrontmatter(content);
681
+ const fm = buildStateFrontmatter(body, cwd);
682
+ const yamlStr = (0, frontmatter_cjs_1.reconstructFrontmatter)(fm);
683
+ return `---\n${yamlStr}\n---\n\n${body}`;
684
+ }
685
+ /**
686
+ * Write STATE.md with synchronized YAML frontmatter.
687
+ * All STATE.md writes should use this instead of raw writeFileSync.
688
+ */
689
+ function writeStateMd(statePath, content, cwd) {
690
+ const synced = syncStateFrontmatter(content, cwd);
691
+ fs_1.default.writeFileSync(statePath, synced, 'utf-8');
692
+ }
693
+ function cmdStateJson(cwd, raw) {
694
+ const statePath = path_1.default.join(cwd, '.planning', 'STATE.md');
695
+ if (!fs_1.default.existsSync(statePath)) {
696
+ (0, core_cjs_1.output)({ error: 'STATE.md not found' }, raw, 'STATE.md not found');
697
+ return;
698
+ }
699
+ const content = fs_1.default.readFileSync(statePath, 'utf-8');
700
+ const fm = (0, frontmatter_cjs_1.extractFrontmatter)(content);
701
+ if (!fm || Object.keys(fm).length === 0) {
702
+ const body = stripFrontmatter(content);
703
+ const built = buildStateFrontmatter(body, cwd);
704
+ (0, core_cjs_1.output)(built, raw, JSON.stringify(built, null, 2));
705
+ return;
706
+ }
707
+ (0, core_cjs_1.output)(fm, raw, JSON.stringify(fm, null, 2));
708
+ }
709
+ //# sourceMappingURL=state.cjs.map