mindforge-cc 2.1.0 → 2.1.2

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 (236) hide show
  1. package/.agent/bin/lib/commands.cjs +959 -0
  2. package/.agent/bin/lib/config.cjs +421 -0
  3. package/.agent/bin/lib/core.cjs +1166 -0
  4. package/.agent/bin/lib/frontmatter.cjs +307 -0
  5. package/.agent/bin/lib/init.cjs +1336 -0
  6. package/.agent/bin/lib/milestone.cjs +252 -0
  7. package/.agent/bin/lib/model-profiles.cjs +68 -0
  8. package/.agent/bin/lib/phase.cjs +888 -0
  9. package/.agent/bin/lib/profile-output.cjs +952 -0
  10. package/.agent/bin/lib/profile-pipeline.cjs +539 -0
  11. package/.agent/bin/lib/roadmap.cjs +329 -0
  12. package/.agent/bin/lib/security.cjs +356 -0
  13. package/.agent/bin/lib/state.cjs +969 -0
  14. package/.agent/bin/lib/template.cjs +222 -0
  15. package/.agent/bin/lib/uat.cjs +189 -0
  16. package/.agent/bin/lib/verify.cjs +851 -0
  17. package/.agent/bin/lib/workstream.cjs +491 -0
  18. package/.agent/bin/mindforge-tools.cjs +897 -0
  19. package/.agent/file-manifest.json +219 -0
  20. package/.agent/hooks/mindforge-check-update.js +114 -0
  21. package/.agent/hooks/mindforge-context-monitor.js +156 -0
  22. package/.agent/hooks/mindforge-prompt-guard.js +96 -0
  23. package/.agent/hooks/mindforge-statusline.js +119 -0
  24. package/.agent/hooks/mindforge-workflow-guard.js +94 -0
  25. package/.agent/mindforge/discuss-phase.md +1 -1
  26. package/.agent/mindforge/help.md +1 -1
  27. package/.agent/mindforge/learn.md +3 -2
  28. package/.agent/mindforge/research.md +3 -2
  29. package/.agent/mindforge/steer.md +1 -1
  30. package/.agent/settings.json +38 -0
  31. package/.agent/skills/mindforge-add-backlog/SKILL.md +72 -0
  32. package/.agent/skills/mindforge-add-phase/SKILL.md +39 -0
  33. package/.agent/skills/mindforge-add-tests/SKILL.md +28 -0
  34. package/.agent/skills/mindforge-add-todo/SKILL.md +42 -0
  35. package/.agent/skills/mindforge-audit-milestone/SKILL.md +29 -0
  36. package/.agent/skills/mindforge-audit-uat/SKILL.md +20 -0
  37. package/.agent/skills/mindforge-autonomous/SKILL.md +33 -0
  38. package/.agent/skills/mindforge-check-todos/SKILL.md +40 -0
  39. package/.agent/skills/mindforge-cleanup/SKILL.md +19 -0
  40. package/.agent/skills/mindforge-complete-milestone/SKILL.md +131 -0
  41. package/.agent/skills/mindforge-debug/SKILL.md +163 -0
  42. package/.agent/skills/mindforge-discuss-phase/SKILL.md +54 -0
  43. package/.agent/skills/mindforge-do/SKILL.md +26 -0
  44. package/.agent/skills/mindforge-execute-phase/SKILL.md +49 -0
  45. package/.agent/skills/mindforge-fast/SKILL.md +23 -0
  46. package/.agent/skills/mindforge-forensics/SKILL.md +49 -0
  47. package/.agent/skills/mindforge-health/SKILL.md +17 -0
  48. package/.agent/skills/mindforge-help/SKILL.md +23 -0
  49. package/.agent/skills/mindforge-insert-phase/SKILL.md +28 -0
  50. package/.agent/skills/mindforge-join-discord/SKILL.md +19 -0
  51. package/.agent/skills/mindforge-list-phase-assumptions/SKILL.md +41 -0
  52. package/.agent/skills/mindforge-list-workspaces/SKILL.md +17 -0
  53. package/.agent/skills/mindforge-manager/SKILL.md +32 -0
  54. package/.agent/skills/mindforge-map-codebase/SKILL.md +64 -0
  55. package/.agent/skills/mindforge-milestone-summary/SKILL.md +44 -0
  56. package/.agent/skills/mindforge-new-milestone/SKILL.md +38 -0
  57. package/.agent/skills/mindforge-new-project/SKILL.md +36 -0
  58. package/.agent/skills/mindforge-new-workspace/SKILL.md +39 -0
  59. package/.agent/skills/mindforge-next/SKILL.md +19 -0
  60. package/.agent/skills/mindforge-note/SKILL.md +29 -0
  61. package/.agent/skills/mindforge-pause-work/SKILL.md +35 -0
  62. package/.agent/skills/mindforge-plan-milestone-gaps/SKILL.md +28 -0
  63. package/.agent/skills/mindforge-plan-phase/SKILL.md +37 -0
  64. package/.agent/skills/mindforge-plant-seed/SKILL.md +22 -0
  65. package/.agent/skills/mindforge-pr-branch/SKILL.md +21 -0
  66. package/.agent/skills/mindforge-profile-user/SKILL.md +38 -0
  67. package/.agent/skills/mindforge-progress/SKILL.md +19 -0
  68. package/.agent/skills/mindforge-quick/SKILL.md +38 -0
  69. package/.agent/skills/mindforge-reapply-patches/SKILL.md +124 -0
  70. package/.agent/skills/mindforge-remove-phase/SKILL.md +26 -0
  71. package/.agent/skills/mindforge-remove-workspace/SKILL.md +22 -0
  72. package/.agent/skills/mindforge-research-phase/SKILL.md +186 -0
  73. package/.agent/skills/mindforge-resume-work/SKILL.md +35 -0
  74. package/.agent/skills/mindforge-review/SKILL.md +31 -0
  75. package/.agent/skills/mindforge-review-backlog/SKILL.md +58 -0
  76. package/.agent/skills/mindforge-session-report/SKILL.md +16 -0
  77. package/.agent/skills/mindforge-set-profile/SKILL.md +9 -0
  78. package/.agent/skills/mindforge-settings/SKILL.md +32 -0
  79. package/.agent/skills/mindforge-ship/SKILL.md +16 -0
  80. package/.agent/skills/mindforge-stats/SKILL.md +16 -0
  81. package/.agent/skills/mindforge-thread/SKILL.md +123 -0
  82. package/.agent/skills/mindforge-ui-phase/SKILL.md +24 -0
  83. package/.agent/skills/mindforge-ui-review/SKILL.md +24 -0
  84. package/.agent/skills/mindforge-update/SKILL.md +35 -0
  85. package/.agent/skills/mindforge-validate-phase/SKILL.md +26 -0
  86. package/.agent/skills/mindforge-verify-work/SKILL.md +30 -0
  87. package/.agent/skills/mindforge-workstreams/SKILL.md +65 -0
  88. package/.agent/workflows/mindforge-add-phase.md +112 -0
  89. package/.agent/workflows/mindforge-add-tests.md +351 -0
  90. package/.agent/workflows/mindforge-add-todo.md +158 -0
  91. package/.agent/workflows/mindforge-audit-milestone.md +332 -0
  92. package/.agent/workflows/mindforge-audit-uat.md +109 -0
  93. package/.agent/workflows/mindforge-autonomous.md +815 -0
  94. package/.agent/workflows/mindforge-check-todos.md +177 -0
  95. package/.agent/workflows/mindforge-cleanup.md +152 -0
  96. package/.agent/workflows/mindforge-complete-milestone.md +766 -0
  97. package/.agent/workflows/mindforge-diagnose-issues.md +220 -0
  98. package/.agent/workflows/mindforge-discovery-phase.md +289 -0
  99. package/.agent/workflows/mindforge-discuss-phase-assumptions.md +645 -0
  100. package/.agent/workflows/mindforge-discuss-phase.md +1047 -0
  101. package/.agent/workflows/mindforge-do.md +104 -0
  102. package/.agent/workflows/mindforge-execute-phase.md +838 -0
  103. package/.agent/workflows/mindforge-execute-plan.md +509 -0
  104. package/.agent/workflows/mindforge-fast.md +105 -0
  105. package/.agent/workflows/mindforge-forensics.md +265 -0
  106. package/.agent/workflows/mindforge-health.md +181 -0
  107. package/.agent/workflows/mindforge-help.md +606 -0
  108. package/.agent/workflows/mindforge-insert-phase.md +130 -0
  109. package/.agent/workflows/mindforge-list-phase-assumptions.md +178 -0
  110. package/.agent/workflows/mindforge-list-workspaces.md +56 -0
  111. package/.agent/workflows/mindforge-manager.md +360 -0
  112. package/.agent/workflows/mindforge-map-codebase.md +370 -0
  113. package/.agent/workflows/mindforge-milestone-summary.md +223 -0
  114. package/.agent/workflows/mindforge-new-milestone.md +469 -0
  115. package/.agent/workflows/mindforge-new-project.md +1226 -0
  116. package/.agent/workflows/mindforge-new-workspace.md +237 -0
  117. package/.agent/workflows/mindforge-next.md +97 -0
  118. package/.agent/workflows/mindforge-node-repair.md +92 -0
  119. package/.agent/workflows/mindforge-note.md +156 -0
  120. package/.agent/workflows/mindforge-pause-work.md +176 -0
  121. package/.agent/workflows/mindforge-plan-milestone-gaps.md +273 -0
  122. package/.agent/workflows/mindforge-plan-phase.md +848 -0
  123. package/.agent/workflows/mindforge-plant-seed.md +169 -0
  124. package/.agent/workflows/mindforge-pr-branch.md +129 -0
  125. package/.agent/workflows/mindforge-profile-user.md +450 -0
  126. package/.agent/workflows/mindforge-progress.md +507 -0
  127. package/.agent/workflows/mindforge-quick.md +732 -0
  128. package/.agent/workflows/mindforge-remove-phase.md +155 -0
  129. package/.agent/workflows/mindforge-remove-workspace.md +90 -0
  130. package/.agent/workflows/mindforge-research-phase.md +74 -0
  131. package/.agent/workflows/mindforge-resume-project.md +325 -0
  132. package/.agent/workflows/mindforge-review.md +228 -0
  133. package/.agent/workflows/mindforge-session-report.md +146 -0
  134. package/.agent/workflows/mindforge-settings.md +283 -0
  135. package/.agent/workflows/mindforge-ship.md +228 -0
  136. package/.agent/workflows/mindforge-stats.md +60 -0
  137. package/.agent/workflows/mindforge-transition.md +671 -0
  138. package/.agent/workflows/mindforge-ui-phase.md +290 -0
  139. package/.agent/workflows/mindforge-ui-review.md +157 -0
  140. package/.agent/workflows/mindforge-update.md +323 -0
  141. package/.agent/workflows/mindforge-validate-phase.md +167 -0
  142. package/.agent/workflows/mindforge-verify-phase.md +254 -0
  143. package/.agent/workflows/mindforge-verify-work.md +623 -0
  144. package/.mindforge/personas/advisor-researcher.md +3 -3
  145. package/.mindforge/personas/debug-specialist.md +1 -1
  146. package/.mindforge/personas/debugger.md +1 -1
  147. package/.mindforge/personas/developer.md +1 -1
  148. package/.mindforge/personas/phase-researcher.md +4 -4
  149. package/.mindforge/personas/project-researcher.md +3 -3
  150. package/.mindforge/personas/research-agent.md +4 -3
  151. package/.mindforge/personas/tech-writer.md +1 -1
  152. package/.mindforge/personas/ui-researcher.md +1 -1
  153. package/.planning/ROADMAP.md +10 -0
  154. package/CHANGELOG.md +34 -0
  155. package/README.md +70 -45
  156. package/RELEASENOTES.md +26 -26
  157. package/bin/install.js +41 -41
  158. package/bin/installer-core.js +67 -26
  159. package/bin/wizard/setup-wizard.js +11 -24
  160. package/bin/wizard/theme.js +141 -0
  161. package/docs/PERSONAS.md +119 -87
  162. package/docs/References/checkpoints.md +778 -0
  163. package/docs/References/config-reference.md +81 -0
  164. package/docs/References/continuation-format.md +249 -0
  165. package/docs/References/decimal-phase-calculation.md +64 -0
  166. package/docs/References/git-integration.md +295 -0
  167. package/docs/References/git-planning-commit.md +38 -0
  168. package/docs/References/model-profile-resolution.md +36 -0
  169. package/docs/References/model-profiles.md +139 -0
  170. package/docs/References/phase-argument-parsing.md +61 -0
  171. package/docs/References/planning-config.md +202 -0
  172. package/docs/References/questioning.md +162 -0
  173. package/docs/References/tdd.md +263 -0
  174. package/docs/References/ui-brand.md +160 -0
  175. package/docs/References/user-profiling.md +681 -0
  176. package/docs/References/verification-patterns.md +612 -0
  177. package/docs/References/workstream-flag.md +58 -0
  178. package/docs/Templates/Agents/CLAUDE-MD.md +122 -0
  179. package/docs/Templates/Agents/COPILOT-INSTRUCTIONS.md +7 -0
  180. package/docs/Templates/Agents/DEBUGGER-PROMPT.md +91 -0
  181. package/docs/Templates/Agents/PLANNER-PROMPT.md +117 -0
  182. package/docs/Templates/Codebase/architecture.md +255 -0
  183. package/docs/Templates/Codebase/concerns.md +310 -0
  184. package/docs/Templates/Codebase/conventions.md +307 -0
  185. package/docs/Templates/Codebase/integrations.md +280 -0
  186. package/docs/Templates/Codebase/stack.md +186 -0
  187. package/docs/Templates/Codebase/structure.md +285 -0
  188. package/docs/Templates/Codebase/testing.md +480 -0
  189. package/docs/Templates/Execution/CONTINUE-HERE.md +78 -0
  190. package/docs/Templates/Execution/DISCUSSION-LOG.md +63 -0
  191. package/docs/Templates/Execution/PHASE-PROMPT.md +610 -0
  192. package/docs/Templates/Execution/STATE.md +176 -0
  193. package/docs/Templates/Execution/SUMMARY-COMPLEX.md +59 -0
  194. package/docs/Templates/Execution/SUMMARY-MINIMAL.md +41 -0
  195. package/docs/Templates/Execution/SUMMARY-STANDARD.md +48 -0
  196. package/docs/Templates/Execution/SUMMARY.md +248 -0
  197. package/docs/Templates/Profile/DEV-PREFERENCES.md +21 -0
  198. package/docs/Templates/Profile/USER-PROFILE.md +146 -0
  199. package/docs/Templates/Profile/USER-SETUP.md +311 -0
  200. package/docs/Templates/Project/DISCOVERY.md +146 -0
  201. package/docs/Templates/Project/MILESTONE-ARCHIVE.md +123 -0
  202. package/docs/Templates/Project/MILESTONE.md +115 -0
  203. package/docs/Templates/Project/PROJECT.md +206 -0
  204. package/docs/Templates/Project/REQUIREMENTS.md +231 -0
  205. package/docs/Templates/Project/RETROSPECTIVE.md +54 -0
  206. package/docs/Templates/Project/ROADMAP.md +202 -0
  207. package/docs/Templates/Quality/DEBUG.md +164 -0
  208. package/docs/Templates/Quality/UAT.md +280 -0
  209. package/docs/Templates/Quality/UI-SPEC.md +100 -0
  210. package/docs/Templates/Quality/VALIDATION.md +76 -0
  211. package/docs/Templates/Quality/VERIFICATION-REPORT.md +322 -0
  212. package/docs/Templates/Research/ARCHITECTURE.md +204 -0
  213. package/docs/Templates/Research/FEATURES.md +147 -0
  214. package/docs/Templates/Research/PITFALLS.md +200 -0
  215. package/docs/Templates/Research/STACK.md +120 -0
  216. package/docs/Templates/Research/SUMMARY.md +170 -0
  217. package/docs/Templates/System/CONFIG.json +43 -0
  218. package/docs/Templates/System/CONTEXT.md +352 -0
  219. package/docs/architecture/README.md +54 -42
  220. package/docs/commands-reference.md +62 -14
  221. package/docs/getting-started.md +26 -18
  222. package/docs/skills-authoring-guide.md +40 -12
  223. package/docs/tutorial.md +83 -116
  224. package/docs/user-guide.md +72 -198
  225. package/package.json +7 -2
  226. package/.mindforge/memory/knowledge-base.jsonl +0 -7
  227. package/.mindforge/memory/pattern-library.jsonl +0 -1
  228. package/.mindforge/memory/team-preferences.jsonl +0 -4
  229. package/.planning/browser-daemon.log +0 -32
  230. package/docs/mindforge-md-reference.md +0 -57
  231. package/docs/reference/config-reference.md +0 -64
  232. /package/{.mindforge/memory/decision-library.jsonl → .planning/phases/01-migrate-gsd-to-mindforge/.gitkeep} +0 -0
  233. /package/docs/{reference → References}/audit-events.md +0 -0
  234. /package/docs/{reference → References}/commands.md +0 -0
  235. /package/docs/{reference → References}/sdk-api.md +0 -0
  236. /package/docs/{reference → References}/skills-api.md +0 -0
@@ -0,0 +1,307 @@
1
+ /**
2
+ * Frontmatter — YAML frontmatter parsing, serialization, and CRUD commands
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { safeReadFile, normalizeMd, output, error } = require('./core.cjs');
8
+
9
+ // ─── Parsing engine ───────────────────────────────────────────────────────────
10
+
11
+ function extractFrontmatter(content) {
12
+ const frontmatter = {};
13
+ // Find ALL frontmatter blocks at the start of the file.
14
+ // If multiple blocks exist (corruption from CRLF mismatch), use the LAST one
15
+ // since it represents the most recent state sync.
16
+ const allBlocks = [...content.matchAll(/(?:^|\n)\s*---\r?\n([\s\S]+?)\r?\n---/g)];
17
+ const match = allBlocks.length > 0 ? allBlocks[allBlocks.length - 1] : null;
18
+ if (!match) return frontmatter;
19
+
20
+ const yaml = match[1];
21
+ const lines = yaml.split(/\r?\n/);
22
+
23
+ // Stack to track nested objects: [{obj, key, indent}]
24
+ // obj = object to write to, key = current key collecting array items, indent = indentation level
25
+ let stack = [{ obj: frontmatter, key: null, indent: -1 }];
26
+
27
+ for (const line of lines) {
28
+ // Skip empty lines
29
+ if (line.trim() === '') continue;
30
+
31
+ // Calculate indentation (number of leading spaces)
32
+ const indentMatch = line.match(/^(\s*)/);
33
+ const indent = indentMatch ? indentMatch[1].length : 0;
34
+
35
+ // Pop stack back to appropriate level
36
+ while (stack.length > 1 && indent <= stack[stack.length - 1].indent) {
37
+ stack.pop();
38
+ }
39
+
40
+ const current = stack[stack.length - 1];
41
+
42
+ // Check for key: value pattern
43
+ const keyMatch = line.match(/^(\s*)([a-zA-Z0-9_-]+):\s*(.*)/);
44
+ if (keyMatch) {
45
+ const key = keyMatch[2];
46
+ const value = keyMatch[3].trim();
47
+
48
+ if (value === '' || value === '[') {
49
+ // Key with no value or opening bracket — could be nested object or array
50
+ // We'll determine based on next lines, for now create placeholder
51
+ current.obj[key] = value === '[' ? [] : {};
52
+ current.key = null;
53
+ // Push new context for potential nested content
54
+ stack.push({ obj: current.obj[key], key: null, indent });
55
+ } else if (value.startsWith('[') && value.endsWith(']')) {
56
+ // Inline array: key: [a, b, c]
57
+ current.obj[key] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
58
+ current.key = null;
59
+ } else {
60
+ // Simple key: value
61
+ current.obj[key] = value.replace(/^["']|["']$/g, '');
62
+ current.key = null;
63
+ }
64
+ } else if (line.trim().startsWith('- ')) {
65
+ // Array item
66
+ const itemValue = line.trim().slice(2).replace(/^["']|["']$/g, '');
67
+
68
+ // If current context is an empty object, convert to array
69
+ if (typeof current.obj === 'object' && !Array.isArray(current.obj) && Object.keys(current.obj).length === 0) {
70
+ // Find the key in parent that points to this object and convert it
71
+ const parent = stack.length > 1 ? stack[stack.length - 2] : null;
72
+ if (parent) {
73
+ for (const k of Object.keys(parent.obj)) {
74
+ if (parent.obj[k] === current.obj) {
75
+ parent.obj[k] = [itemValue];
76
+ current.obj = parent.obj[k];
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ } else if (Array.isArray(current.obj)) {
82
+ current.obj.push(itemValue);
83
+ }
84
+ }
85
+ }
86
+
87
+ return frontmatter;
88
+ }
89
+
90
+ function reconstructFrontmatter(obj) {
91
+ const lines = [];
92
+ for (const [key, value] of Object.entries(obj)) {
93
+ if (value === null || value === undefined) continue;
94
+ if (Array.isArray(value)) {
95
+ if (value.length === 0) {
96
+ lines.push(`${key}: []`);
97
+ } else if (value.every(v => typeof v === 'string') && value.length <= 3 && value.join(', ').length < 60) {
98
+ lines.push(`${key}: [${value.join(', ')}]`);
99
+ } else {
100
+ lines.push(`${key}:`);
101
+ for (const item of value) {
102
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
103
+ }
104
+ }
105
+ } else if (typeof value === 'object') {
106
+ lines.push(`${key}:`);
107
+ for (const [subkey, subval] of Object.entries(value)) {
108
+ if (subval === null || subval === undefined) continue;
109
+ if (Array.isArray(subval)) {
110
+ if (subval.length === 0) {
111
+ lines.push(` ${subkey}: []`);
112
+ } else if (subval.every(v => typeof v === 'string') && subval.length <= 3 && subval.join(', ').length < 60) {
113
+ lines.push(` ${subkey}: [${subval.join(', ')}]`);
114
+ } else {
115
+ lines.push(` ${subkey}:`);
116
+ for (const item of subval) {
117
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
118
+ }
119
+ }
120
+ } else if (typeof subval === 'object') {
121
+ lines.push(` ${subkey}:`);
122
+ for (const [subsubkey, subsubval] of Object.entries(subval)) {
123
+ if (subsubval === null || subsubval === undefined) continue;
124
+ if (Array.isArray(subsubval)) {
125
+ if (subsubval.length === 0) {
126
+ lines.push(` ${subsubkey}: []`);
127
+ } else {
128
+ lines.push(` ${subsubkey}:`);
129
+ for (const item of subsubval) {
130
+ lines.push(` - ${item}`);
131
+ }
132
+ }
133
+ } else {
134
+ lines.push(` ${subsubkey}: ${subsubval}`);
135
+ }
136
+ }
137
+ } else {
138
+ const sv = String(subval);
139
+ lines.push(` ${subkey}: ${sv.includes(':') || sv.includes('#') ? `"${sv}"` : sv}`);
140
+ }
141
+ }
142
+ } else {
143
+ const sv = String(value);
144
+ if (sv.includes(':') || sv.includes('#') || sv.startsWith('[') || sv.startsWith('{')) {
145
+ lines.push(`${key}: "${sv}"`);
146
+ } else {
147
+ lines.push(`${key}: ${sv}`);
148
+ }
149
+ }
150
+ }
151
+ return lines.join('\n');
152
+ }
153
+
154
+ function spliceFrontmatter(content, newObj) {
155
+ const yamlStr = reconstructFrontmatter(newObj);
156
+ const match = content.match(/^---\r?\n[\s\S]+?\r?\n---/);
157
+ if (match) {
158
+ return `---\n${yamlStr}\n---` + content.slice(match[0].length);
159
+ }
160
+ return `---\n${yamlStr}\n---\n\n` + content;
161
+ }
162
+
163
+ function parseMustHavesBlock(content, blockName) {
164
+ // Extract a specific block from must_haves in raw frontmatter YAML
165
+ // Handles 3-level nesting: must_haves > artifacts/key_links > [{path, provides, ...}]
166
+ const fmMatch = content.match(/^---\r?\n([\s\S]+?)\r?\n---/);
167
+ if (!fmMatch) return [];
168
+
169
+ const yaml = fmMatch[1];
170
+ // Find the block (e.g., "truths:", "artifacts:", "key_links:")
171
+ const blockPattern = new RegExp(`^\\s{4}${blockName}:\\s*$`, 'm');
172
+ const blockStart = yaml.search(blockPattern);
173
+ if (blockStart === -1) return [];
174
+
175
+ const afterBlock = yaml.slice(blockStart);
176
+ const blockLines = afterBlock.split(/\r?\n/).slice(1); // skip the header line
177
+
178
+ const items = [];
179
+ let current = null;
180
+
181
+ for (const line of blockLines) {
182
+ // Stop at same or lower indent level (non-continuation)
183
+ if (line.trim() === '') continue;
184
+ const indent = line.match(/^(\s*)/)[1].length;
185
+ if (indent <= 4 && line.trim() !== '') break; // back to must_haves level or higher
186
+
187
+ if (line.match(/^\s{6}-\s+/)) {
188
+ // New list item at 6-space indent
189
+ if (current) items.push(current);
190
+ current = {};
191
+ // Check if it's a simple string item
192
+ const simpleMatch = line.match(/^\s{6}-\s+"?([^"]+)"?\s*$/);
193
+ if (simpleMatch && !line.includes(':')) {
194
+ current = simpleMatch[1];
195
+ } else {
196
+ // Key-value on same line as dash: "- path: value"
197
+ const kvMatch = line.match(/^\s{6}-\s+(\w+):\s*"?([^"]*)"?\s*$/);
198
+ if (kvMatch) {
199
+ current = {};
200
+ current[kvMatch[1]] = kvMatch[2];
201
+ }
202
+ }
203
+ } else if (current && typeof current === 'object') {
204
+ // Continuation key-value at 8+ space indent
205
+ const kvMatch = line.match(/^\s{8,}(\w+):\s*"?([^"]*)"?\s*$/);
206
+ if (kvMatch) {
207
+ const val = kvMatch[2];
208
+ // Try to parse as number
209
+ current[kvMatch[1]] = /^\d+$/.test(val) ? parseInt(val, 10) : val;
210
+ }
211
+ // Array items under a key
212
+ const arrMatch = line.match(/^\s{10,}-\s+"?([^"]+)"?\s*$/);
213
+ if (arrMatch) {
214
+ // Find the last key added and convert to array
215
+ const keys = Object.keys(current);
216
+ const lastKey = keys[keys.length - 1];
217
+ if (lastKey && !Array.isArray(current[lastKey])) {
218
+ current[lastKey] = current[lastKey] ? [current[lastKey]] : [];
219
+ }
220
+ if (lastKey) current[lastKey].push(arrMatch[1]);
221
+ }
222
+ }
223
+ }
224
+ if (current) items.push(current);
225
+
226
+ return items;
227
+ }
228
+
229
+ // ─── Frontmatter CRUD commands ────────────────────────────────────────────────
230
+
231
+ const FRONTMATTER_SCHEMAS = {
232
+ plan: { required: ['phase', 'plan', 'type', 'wave', 'depends_on', 'files_modified', 'autonomous', 'must_haves'] },
233
+ summary: { required: ['phase', 'plan', 'subsystem', 'tags', 'duration', 'completed'] },
234
+ verification: { required: ['phase', 'verified', 'status', 'score'] },
235
+ };
236
+
237
+ function cmdFrontmatterGet(cwd, filePath, field, raw) {
238
+ if (!filePath) { error('file path required'); }
239
+ // Path traversal guard: reject null bytes
240
+ if (filePath.includes('\0')) { error('file path contains null bytes'); }
241
+ const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
242
+ const content = safeReadFile(fullPath);
243
+ if (!content) { output({ error: 'File not found', path: filePath }, raw); return; }
244
+ const fm = extractFrontmatter(content);
245
+ if (field) {
246
+ const value = fm[field];
247
+ if (value === undefined) { output({ error: 'Field not found', field }, raw); return; }
248
+ output({ [field]: value }, raw, JSON.stringify(value));
249
+ } else {
250
+ output(fm, raw);
251
+ }
252
+ }
253
+
254
+ function cmdFrontmatterSet(cwd, filePath, field, value, raw) {
255
+ if (!filePath || !field || value === undefined) { error('file, field, and value required'); }
256
+ // Path traversal guard: reject null bytes
257
+ if (filePath.includes('\0')) { error('file path contains null bytes'); }
258
+ const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
259
+ if (!fs.existsSync(fullPath)) { output({ error: 'File not found', path: filePath }, raw); return; }
260
+ const content = fs.readFileSync(fullPath, 'utf-8');
261
+ const fm = extractFrontmatter(content);
262
+ let parsedValue;
263
+ try { parsedValue = JSON.parse(value); } catch { parsedValue = value; }
264
+ fm[field] = parsedValue;
265
+ const newContent = spliceFrontmatter(content, fm);
266
+ fs.writeFileSync(fullPath, normalizeMd(newContent), 'utf-8');
267
+ output({ updated: true, field, value: parsedValue }, raw, 'true');
268
+ }
269
+
270
+ function cmdFrontmatterMerge(cwd, filePath, data, raw) {
271
+ if (!filePath || !data) { error('file and data required'); }
272
+ const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
273
+ if (!fs.existsSync(fullPath)) { output({ error: 'File not found', path: filePath }, raw); return; }
274
+ const content = fs.readFileSync(fullPath, 'utf-8');
275
+ const fm = extractFrontmatter(content);
276
+ let mergeData;
277
+ try { mergeData = JSON.parse(data); } catch { error('Invalid JSON for --data'); return; }
278
+ Object.assign(fm, mergeData);
279
+ const newContent = spliceFrontmatter(content, fm);
280
+ fs.writeFileSync(fullPath, normalizeMd(newContent), 'utf-8');
281
+ output({ merged: true, fields: Object.keys(mergeData) }, raw, 'true');
282
+ }
283
+
284
+ function cmdFrontmatterValidate(cwd, filePath, schemaName, raw) {
285
+ if (!filePath || !schemaName) { error('file and schema required'); }
286
+ const schema = FRONTMATTER_SCHEMAS[schemaName];
287
+ if (!schema) { error(`Unknown schema: ${schemaName}. Available: ${Object.keys(FRONTMATTER_SCHEMAS).join(', ')}`); }
288
+ const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
289
+ const content = safeReadFile(fullPath);
290
+ if (!content) { output({ error: 'File not found', path: filePath }, raw); return; }
291
+ const fm = extractFrontmatter(content);
292
+ const missing = schema.required.filter(f => fm[f] === undefined);
293
+ const present = schema.required.filter(f => fm[f] !== undefined);
294
+ output({ valid: missing.length === 0, missing, present, schema: schemaName }, raw, missing.length === 0 ? 'valid' : 'invalid');
295
+ }
296
+
297
+ module.exports = {
298
+ extractFrontmatter,
299
+ reconstructFrontmatter,
300
+ spliceFrontmatter,
301
+ parseMustHavesBlock,
302
+ FRONTMATTER_SCHEMAS,
303
+ cmdFrontmatterGet,
304
+ cmdFrontmatterSet,
305
+ cmdFrontmatterMerge,
306
+ cmdFrontmatterValidate,
307
+ };