@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,341 @@
1
+ "use strict";
2
+ /**
3
+ * Frontmatter — YAML frontmatter parsing, serialization, and CRUD commands
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.FRONTMATTER_SCHEMAS = void 0;
10
+ exports.extractFrontmatter = extractFrontmatter;
11
+ exports.reconstructFrontmatter = reconstructFrontmatter;
12
+ exports.spliceFrontmatter = spliceFrontmatter;
13
+ exports.parseMustHavesBlock = parseMustHavesBlock;
14
+ exports.cmdFrontmatterGet = cmdFrontmatterGet;
15
+ exports.cmdFrontmatterSet = cmdFrontmatterSet;
16
+ exports.cmdFrontmatterMerge = cmdFrontmatterMerge;
17
+ exports.cmdFrontmatterValidate = cmdFrontmatterValidate;
18
+ const fs_1 = __importDefault(require("fs"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const core_cjs_1 = require("./core.cjs");
21
+ function extractFrontmatter(content) {
22
+ const frontmatter = {};
23
+ const match = content.match(/^---\n([\s\S]+?)\n---/);
24
+ if (!match)
25
+ return frontmatter;
26
+ const yaml = match[1];
27
+ const lines = yaml.split('\n');
28
+ const stack = [{ obj: frontmatter, key: null, indent: -1 }];
29
+ for (const line of lines) {
30
+ // Skip empty lines
31
+ if (line.trim() === '')
32
+ continue;
33
+ // Calculate indentation (number of leading spaces)
34
+ const indentMatch = line.match(/^(\s*)/);
35
+ const indent = indentMatch ? indentMatch[1].length : 0;
36
+ // Pop stack back to appropriate level
37
+ while (stack.length > 1 && indent <= stack[stack.length - 1].indent) {
38
+ stack.pop();
39
+ }
40
+ const current = stack[stack.length - 1];
41
+ // Check for key: value pattern
42
+ const keyMatch = line.match(/^(\s*)([a-zA-Z0-9_-]+):\s*(.*)/);
43
+ if (keyMatch) {
44
+ const key = keyMatch[2];
45
+ const value = keyMatch[3].trim();
46
+ const currentObj = current.obj;
47
+ if (value === '' || value === '[') {
48
+ // Key with no value or opening bracket — could be nested object or array
49
+ // We'll determine based on next lines, for now create placeholder
50
+ currentObj[key] = value === '[' ? [] : {};
51
+ current.key = null;
52
+ // Push new context for potential nested content
53
+ stack.push({ obj: currentObj[key], key: null, indent });
54
+ }
55
+ else if (value.startsWith('[') && value.endsWith(']')) {
56
+ // Inline array: key: [a, b, c]
57
+ currentObj[key] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
58
+ current.key = null;
59
+ }
60
+ else {
61
+ // Simple key: value
62
+ currentObj[key] = value.replace(/^["']|["']$/g, '');
63
+ current.key = null;
64
+ }
65
+ }
66
+ else if (line.trim().startsWith('- ')) {
67
+ // Array item
68
+ const itemValue = line.trim().slice(2).replace(/^["']|["']$/g, '');
69
+ // If current context is an empty object, convert to array
70
+ if (typeof current.obj === 'object' && !Array.isArray(current.obj) && Object.keys(current.obj).length === 0) {
71
+ // Find the key in parent that points to this object and convert it
72
+ const parent = stack.length > 1 ? stack[stack.length - 2] : null;
73
+ if (parent) {
74
+ const parentObj = parent.obj;
75
+ for (const k of Object.keys(parentObj)) {
76
+ if (parentObj[k] === current.obj) {
77
+ parentObj[k] = [itemValue];
78
+ current.obj = parentObj[k];
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ else if (Array.isArray(current.obj)) {
85
+ current.obj.push(itemValue);
86
+ }
87
+ }
88
+ }
89
+ return frontmatter;
90
+ }
91
+ function reconstructFrontmatter(obj) {
92
+ const lines = [];
93
+ for (const [key, value] of Object.entries(obj)) {
94
+ if (value === null || value === undefined)
95
+ continue;
96
+ if (Array.isArray(value)) {
97
+ if (value.length === 0) {
98
+ lines.push(`${key}: []`);
99
+ }
100
+ else if (value.every(v => typeof v === 'string') && value.length <= 3 && value.join(', ').length < 60) {
101
+ lines.push(`${key}: [${value.join(', ')}]`);
102
+ }
103
+ else {
104
+ lines.push(`${key}:`);
105
+ for (const item of value) {
106
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
107
+ }
108
+ }
109
+ }
110
+ else if (typeof value === 'object') {
111
+ lines.push(`${key}:`);
112
+ for (const [subkey, subval] of Object.entries(value)) {
113
+ if (subval === null || subval === undefined)
114
+ continue;
115
+ if (Array.isArray(subval)) {
116
+ if (subval.length === 0) {
117
+ lines.push(` ${subkey}: []`);
118
+ }
119
+ else if (subval.every(v => typeof v === 'string') && subval.length <= 3 && subval.join(', ').length < 60) {
120
+ lines.push(` ${subkey}: [${subval.join(', ')}]`);
121
+ }
122
+ else {
123
+ lines.push(` ${subkey}:`);
124
+ for (const item of subval) {
125
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
126
+ }
127
+ }
128
+ }
129
+ else if (typeof subval === 'object') {
130
+ lines.push(` ${subkey}:`);
131
+ for (const [subsubkey, subsubval] of Object.entries(subval)) {
132
+ if (subsubval === null || subsubval === undefined)
133
+ continue;
134
+ if (Array.isArray(subsubval)) {
135
+ if (subsubval.length === 0) {
136
+ lines.push(` ${subsubkey}: []`);
137
+ }
138
+ else {
139
+ lines.push(` ${subsubkey}:`);
140
+ for (const item of subsubval) {
141
+ lines.push(` - ${item}`);
142
+ }
143
+ }
144
+ }
145
+ else {
146
+ lines.push(` ${subsubkey}: ${subsubval}`);
147
+ }
148
+ }
149
+ }
150
+ else {
151
+ const sv = String(subval);
152
+ lines.push(` ${subkey}: ${sv.includes(':') || sv.includes('#') ? `"${sv}"` : sv}`);
153
+ }
154
+ }
155
+ }
156
+ else {
157
+ const sv = String(value);
158
+ if (sv.includes(':') || sv.includes('#') || sv.startsWith('[') || sv.startsWith('{')) {
159
+ lines.push(`${key}: "${sv}"`);
160
+ }
161
+ else {
162
+ lines.push(`${key}: ${sv}`);
163
+ }
164
+ }
165
+ }
166
+ return lines.join('\n');
167
+ }
168
+ function spliceFrontmatter(content, newObj) {
169
+ const yamlStr = reconstructFrontmatter(newObj);
170
+ const match = content.match(/^---\n[\s\S]+?\n---/);
171
+ if (match) {
172
+ return `---\n${yamlStr}\n---` + content.slice(match[0].length);
173
+ }
174
+ return `---\n${yamlStr}\n---\n\n` + content;
175
+ }
176
+ function parseMustHavesBlock(content, blockName) {
177
+ // Extract a specific block from must_haves in raw frontmatter YAML
178
+ // Handles 3-level nesting: must_haves > artifacts/key_links > [{path, provides, ...}]
179
+ const fmMatch = content.match(/^---\n([\s\S]+?)\n---/);
180
+ if (!fmMatch)
181
+ return [];
182
+ const yaml = fmMatch[1];
183
+ // Find the block (e.g., "truths:", "artifacts:", "key_links:")
184
+ const blockPattern = new RegExp(`^\\s{4}${blockName}:\\s*$`, 'm');
185
+ const blockStart = yaml.search(blockPattern);
186
+ if (blockStart === -1)
187
+ return [];
188
+ const afterBlock = yaml.slice(blockStart);
189
+ const blockLines = afterBlock.split('\n').slice(1); // skip the header line
190
+ const items = [];
191
+ let current = null;
192
+ for (const line of blockLines) {
193
+ // Stop at same or lower indent level (non-continuation)
194
+ if (line.trim() === '')
195
+ continue;
196
+ const indentMatch = line.match(/^(\s*)/);
197
+ const indent = indentMatch ? indentMatch[1].length : 0;
198
+ if (indent <= 4 && line.trim() !== '')
199
+ break; // back to must_haves level or higher
200
+ if (line.match(/^\s{6}-\s+/)) {
201
+ // New list item at 6-space indent
202
+ if (current)
203
+ items.push(current);
204
+ current = {};
205
+ // Check if it's a simple string item
206
+ const simpleMatch = line.match(/^\s{6}-\s+"?([^"]+)"?\s*$/);
207
+ if (simpleMatch && !line.includes(':')) {
208
+ current = simpleMatch[1];
209
+ }
210
+ else {
211
+ // Key-value on same line as dash: "- path: value"
212
+ const kvMatch = line.match(/^\s{6}-\s+(\w+):\s*"?([^"]*)"?\s*$/);
213
+ if (kvMatch) {
214
+ current = {};
215
+ current[kvMatch[1]] = kvMatch[2];
216
+ }
217
+ }
218
+ }
219
+ else if (current && typeof current === 'object') {
220
+ const currentObj = current;
221
+ // Continuation key-value at 8+ space indent
222
+ const kvMatch = line.match(/^\s{8,}(\w+):\s*"?([^"]*)"?\s*$/);
223
+ if (kvMatch) {
224
+ const val = kvMatch[2];
225
+ // Try to parse as number
226
+ currentObj[kvMatch[1]] = /^\d+$/.test(val) ? parseInt(val, 10) : val;
227
+ }
228
+ // Array items under a key
229
+ const arrMatch = line.match(/^\s{10,}-\s+"?([^"]+)"?\s*$/);
230
+ if (arrMatch) {
231
+ // Find the last key added and convert to array
232
+ const keys = Object.keys(currentObj);
233
+ const lastKey = keys[keys.length - 1];
234
+ if (lastKey && !Array.isArray(currentObj[lastKey])) {
235
+ currentObj[lastKey] = currentObj[lastKey] ? [currentObj[lastKey]] : [];
236
+ }
237
+ if (lastKey)
238
+ currentObj[lastKey].push(arrMatch[1]);
239
+ }
240
+ }
241
+ }
242
+ if (current)
243
+ items.push(current);
244
+ return items;
245
+ }
246
+ // ─── Frontmatter CRUD commands ────────────────────────────────────────────────
247
+ exports.FRONTMATTER_SCHEMAS = {
248
+ plan: { required: ['phase', 'plan', 'type', 'wave', 'depends_on', 'files_modified', 'autonomous', 'must_haves'] },
249
+ summary: { required: ['phase', 'plan', 'subsystem', 'tags', 'duration', 'completed'] },
250
+ verification: { required: ['phase', 'verified', 'status', 'score'] },
251
+ };
252
+ function cmdFrontmatterGet(cwd, filePath, field, raw) {
253
+ if (!filePath) {
254
+ (0, core_cjs_1.error)('file path required');
255
+ }
256
+ const fullPath = path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath);
257
+ const content = (0, core_cjs_1.safeReadFile)(fullPath);
258
+ if (!content) {
259
+ (0, core_cjs_1.output)({ error: 'File not found', path: filePath }, raw);
260
+ return;
261
+ }
262
+ const fm = extractFrontmatter(content);
263
+ if (field) {
264
+ const value = fm[field];
265
+ if (value === undefined) {
266
+ (0, core_cjs_1.output)({ error: 'Field not found', field }, raw);
267
+ return;
268
+ }
269
+ (0, core_cjs_1.output)({ [field]: value }, raw, JSON.stringify(value));
270
+ }
271
+ else {
272
+ (0, core_cjs_1.output)(fm, raw);
273
+ }
274
+ }
275
+ function cmdFrontmatterSet(cwd, filePath, field, value, raw) {
276
+ if (!filePath || !field || value === undefined) {
277
+ (0, core_cjs_1.error)('file, field, and value required');
278
+ }
279
+ const fullPath = path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath);
280
+ if (!fs_1.default.existsSync(fullPath)) {
281
+ (0, core_cjs_1.output)({ error: 'File not found', path: filePath }, raw);
282
+ return;
283
+ }
284
+ const content = fs_1.default.readFileSync(fullPath, 'utf-8');
285
+ const fm = extractFrontmatter(content);
286
+ let parsedValue;
287
+ try {
288
+ parsedValue = JSON.parse(value);
289
+ }
290
+ catch {
291
+ parsedValue = value;
292
+ }
293
+ fm[field] = parsedValue;
294
+ const newContent = spliceFrontmatter(content, fm);
295
+ fs_1.default.writeFileSync(fullPath, newContent, 'utf-8');
296
+ (0, core_cjs_1.output)({ updated: true, field, value: parsedValue }, raw, 'true');
297
+ }
298
+ function cmdFrontmatterMerge(cwd, filePath, data, raw) {
299
+ if (!filePath || !data) {
300
+ (0, core_cjs_1.error)('file and data required');
301
+ }
302
+ const fullPath = path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath);
303
+ if (!fs_1.default.existsSync(fullPath)) {
304
+ (0, core_cjs_1.output)({ error: 'File not found', path: filePath }, raw);
305
+ return;
306
+ }
307
+ const content = fs_1.default.readFileSync(fullPath, 'utf-8');
308
+ const fm = extractFrontmatter(content);
309
+ let mergeData;
310
+ try {
311
+ mergeData = JSON.parse(data);
312
+ }
313
+ catch {
314
+ (0, core_cjs_1.error)('Invalid JSON for --data');
315
+ return;
316
+ }
317
+ Object.assign(fm, mergeData);
318
+ const newContent = spliceFrontmatter(content, fm);
319
+ fs_1.default.writeFileSync(fullPath, newContent, 'utf-8');
320
+ (0, core_cjs_1.output)({ merged: true, fields: Object.keys(mergeData) }, raw, 'true');
321
+ }
322
+ function cmdFrontmatterValidate(cwd, filePath, schemaName, raw) {
323
+ if (!filePath || !schemaName) {
324
+ (0, core_cjs_1.error)('file and schema required');
325
+ }
326
+ const schema = exports.FRONTMATTER_SCHEMAS[schemaName];
327
+ if (!schema) {
328
+ (0, core_cjs_1.error)(`Unknown schema: ${schemaName}. Available: ${Object.keys(exports.FRONTMATTER_SCHEMAS).join(', ')}`);
329
+ }
330
+ const fullPath = path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(cwd, filePath);
331
+ const content = (0, core_cjs_1.safeReadFile)(fullPath);
332
+ if (!content) {
333
+ (0, core_cjs_1.output)({ error: 'File not found', path: filePath }, raw);
334
+ return;
335
+ }
336
+ const fm = extractFrontmatter(content);
337
+ const missing = schema.required.filter(f => fm[f] === undefined);
338
+ const present = schema.required.filter(f => fm[f] !== undefined);
339
+ (0, core_cjs_1.output)({ valid: missing.length === 0, missing, present, schema: schemaName }, raw, missing.length === 0 ? 'valid' : 'invalid');
340
+ }
341
+ //# sourceMappingURL=frontmatter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter.cjs","sourceRoot":"","sources":["frontmatter.cts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAWH,gDA4EC;AAED,wDA8DC;AAED,8CAOC;AAED,kDAkEC;AAUD,8CAaC;AAED,8CAYC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,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjE,IAAA,iBAAM,EAAC,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AACjI,CAAC"}
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Frontmatter — YAML frontmatter parsing, serialization, and CRUD commands
3
+ */
4
+
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { safeReadFile, output, error } from './core.cjs';
8
+
9
+ // ─── Parsing engine ───────────────────────────────────────────────────────────
10
+
11
+ type FrontmatterValue = string | string[] | Record<string, unknown> | boolean | number | null;
12
+ type FrontmatterObject = Record<string, FrontmatterValue>;
13
+
14
+ export function extractFrontmatter(content: string): FrontmatterObject {
15
+ const frontmatter: FrontmatterObject = {};
16
+ const match = content.match(/^---\n([\s\S]+?)\n---/);
17
+ if (!match) return frontmatter;
18
+
19
+ const yaml = match[1];
20
+ const lines = yaml.split('\n');
21
+
22
+ // Stack to track nested objects: [{obj, key, indent}]
23
+ // obj = object to write to, key = current key collecting array items, indent = indentation level
24
+ type StackFrame = { obj: Record<string, unknown> | unknown[]; key: string | null; indent: number };
25
+ const stack: StackFrame[] = [{ obj: frontmatter as Record<string, unknown>, 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
+ const currentObj = current.obj as Record<string, unknown>;
48
+
49
+ if (value === '' || value === '[') {
50
+ // Key with no value or opening bracket — could be nested object or array
51
+ // We'll determine based on next lines, for now create placeholder
52
+ currentObj[key] = value === '[' ? [] : {};
53
+ current.key = null;
54
+ // Push new context for potential nested content
55
+ stack.push({ obj: currentObj[key] as Record<string, unknown> | unknown[], key: null, indent });
56
+ } else if (value.startsWith('[') && value.endsWith(']')) {
57
+ // Inline array: key: [a, b, c]
58
+ currentObj[key] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
59
+ current.key = null;
60
+ } else {
61
+ // Simple key: value
62
+ currentObj[key] = value.replace(/^["']|["']$/g, '');
63
+ current.key = null;
64
+ }
65
+ } else if (line.trim().startsWith('- ')) {
66
+ // Array item
67
+ const itemValue = line.trim().slice(2).replace(/^["']|["']$/g, '');
68
+
69
+ // If current context is an empty object, convert to array
70
+ if (typeof current.obj === 'object' && !Array.isArray(current.obj) && Object.keys(current.obj).length === 0) {
71
+ // Find the key in parent that points to this object and convert it
72
+ const parent = stack.length > 1 ? stack[stack.length - 2] : null;
73
+ if (parent) {
74
+ const parentObj = parent.obj as Record<string, unknown>;
75
+ for (const k of Object.keys(parentObj)) {
76
+ if (parentObj[k] === current.obj) {
77
+ parentObj[k] = [itemValue];
78
+ (current as { obj: unknown[] | Record<string, unknown> }).obj = parentObj[k] as unknown[];
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ } else if (Array.isArray(current.obj)) {
84
+ (current.obj as unknown[]).push(itemValue);
85
+ }
86
+ }
87
+ }
88
+
89
+ return frontmatter;
90
+ }
91
+
92
+ export function reconstructFrontmatter(obj: Record<string, unknown>): string {
93
+ const lines: string[] = [];
94
+ for (const [key, value] of Object.entries(obj)) {
95
+ if (value === null || value === undefined) continue;
96
+ if (Array.isArray(value)) {
97
+ if (value.length === 0) {
98
+ lines.push(`${key}: []`);
99
+ } else if (value.every(v => typeof v === 'string') && value.length <= 3 && (value as string[]).join(', ').length < 60) {
100
+ lines.push(`${key}: [${(value as string[]).join(', ')}]`);
101
+ } else {
102
+ lines.push(`${key}:`);
103
+ for (const item of value) {
104
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
105
+ }
106
+ }
107
+ } else if (typeof value === 'object') {
108
+ lines.push(`${key}:`);
109
+ for (const [subkey, subval] of Object.entries(value as Record<string, unknown>)) {
110
+ if (subval === null || subval === undefined) continue;
111
+ if (Array.isArray(subval)) {
112
+ if (subval.length === 0) {
113
+ lines.push(` ${subkey}: []`);
114
+ } else if (subval.every(v => typeof v === 'string') && subval.length <= 3 && (subval as string[]).join(', ').length < 60) {
115
+ lines.push(` ${subkey}: [${(subval as string[]).join(', ')}]`);
116
+ } else {
117
+ lines.push(` ${subkey}:`);
118
+ for (const item of subval) {
119
+ lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
120
+ }
121
+ }
122
+ } else if (typeof subval === 'object') {
123
+ lines.push(` ${subkey}:`);
124
+ for (const [subsubkey, subsubval] of Object.entries(subval as Record<string, unknown>)) {
125
+ if (subsubval === null || subsubval === undefined) continue;
126
+ if (Array.isArray(subsubval)) {
127
+ if (subsubval.length === 0) {
128
+ lines.push(` ${subsubkey}: []`);
129
+ } else {
130
+ lines.push(` ${subsubkey}:`);
131
+ for (const item of subsubval) {
132
+ lines.push(` - ${item}`);
133
+ }
134
+ }
135
+ } else {
136
+ lines.push(` ${subsubkey}: ${subsubval}`);
137
+ }
138
+ }
139
+ } else {
140
+ const sv = String(subval);
141
+ lines.push(` ${subkey}: ${sv.includes(':') || sv.includes('#') ? `"${sv}"` : sv}`);
142
+ }
143
+ }
144
+ } else {
145
+ const sv = String(value);
146
+ if (sv.includes(':') || sv.includes('#') || sv.startsWith('[') || sv.startsWith('{')) {
147
+ lines.push(`${key}: "${sv}"`);
148
+ } else {
149
+ lines.push(`${key}: ${sv}`);
150
+ }
151
+ }
152
+ }
153
+ return lines.join('\n');
154
+ }
155
+
156
+ export function spliceFrontmatter(content: string, newObj: Record<string, unknown>): string {
157
+ const yamlStr = reconstructFrontmatter(newObj);
158
+ const match = content.match(/^---\n[\s\S]+?\n---/);
159
+ if (match) {
160
+ return `---\n${yamlStr}\n---` + content.slice(match[0].length);
161
+ }
162
+ return `---\n${yamlStr}\n---\n\n` + content;
163
+ }
164
+
165
+ export function parseMustHavesBlock(content: string, blockName: string): unknown[] {
166
+ // Extract a specific block from must_haves in raw frontmatter YAML
167
+ // Handles 3-level nesting: must_haves > artifacts/key_links > [{path, provides, ...}]
168
+ const fmMatch = content.match(/^---\n([\s\S]+?)\n---/);
169
+ if (!fmMatch) return [];
170
+
171
+ const yaml = fmMatch[1];
172
+ // Find the block (e.g., "truths:", "artifacts:", "key_links:")
173
+ const blockPattern = new RegExp(`^\\s{4}${blockName}:\\s*$`, 'm');
174
+ const blockStart = yaml.search(blockPattern);
175
+ if (blockStart === -1) return [];
176
+
177
+ const afterBlock = yaml.slice(blockStart);
178
+ const blockLines = afterBlock.split('\n').slice(1); // skip the header line
179
+
180
+ const items: unknown[] = [];
181
+ let current: Record<string, unknown> | string | null = null;
182
+
183
+ for (const line of blockLines) {
184
+ // Stop at same or lower indent level (non-continuation)
185
+ if (line.trim() === '') continue;
186
+ const indentMatch = line.match(/^(\s*)/);
187
+ const indent = indentMatch ? indentMatch[1].length : 0;
188
+ if (indent <= 4 && line.trim() !== '') break; // back to must_haves level or higher
189
+
190
+ if (line.match(/^\s{6}-\s+/)) {
191
+ // New list item at 6-space indent
192
+ if (current) items.push(current);
193
+ current = {};
194
+ // Check if it's a simple string item
195
+ const simpleMatch = line.match(/^\s{6}-\s+"?([^"]+)"?\s*$/);
196
+ if (simpleMatch && !line.includes(':')) {
197
+ current = simpleMatch[1];
198
+ } else {
199
+ // Key-value on same line as dash: "- path: value"
200
+ const kvMatch = line.match(/^\s{6}-\s+(\w+):\s*"?([^"]*)"?\s*$/);
201
+ if (kvMatch) {
202
+ current = {};
203
+ (current as Record<string, unknown>)[kvMatch[1]] = kvMatch[2];
204
+ }
205
+ }
206
+ } else if (current && typeof current === 'object') {
207
+ const currentObj = current as Record<string, unknown>;
208
+ // Continuation key-value at 8+ space indent
209
+ const kvMatch = line.match(/^\s{8,}(\w+):\s*"?([^"]*)"?\s*$/);
210
+ if (kvMatch) {
211
+ const val = kvMatch[2];
212
+ // Try to parse as number
213
+ currentObj[kvMatch[1]] = /^\d+$/.test(val) ? parseInt(val, 10) : val;
214
+ }
215
+ // Array items under a key
216
+ const arrMatch = line.match(/^\s{10,}-\s+"?([^"]+)"?\s*$/);
217
+ if (arrMatch) {
218
+ // Find the last key added and convert to array
219
+ const keys = Object.keys(currentObj);
220
+ const lastKey = keys[keys.length - 1];
221
+ if (lastKey && !Array.isArray(currentObj[lastKey])) {
222
+ currentObj[lastKey] = currentObj[lastKey] ? [currentObj[lastKey]] : [];
223
+ }
224
+ if (lastKey) (currentObj[lastKey] as unknown[]).push(arrMatch[1]);
225
+ }
226
+ }
227
+ }
228
+ if (current) items.push(current);
229
+
230
+ return items;
231
+ }
232
+
233
+ // ─── Frontmatter CRUD commands ────────────────────────────────────────────────
234
+
235
+ export const FRONTMATTER_SCHEMAS: Record<string, { required: string[] }> = {
236
+ plan: { required: ['phase', 'plan', 'type', 'wave', 'depends_on', 'files_modified', 'autonomous', 'must_haves'] },
237
+ summary: { required: ['phase', 'plan', 'subsystem', 'tags', 'duration', 'completed'] },
238
+ verification: { required: ['phase', 'verified', 'status', 'score'] },
239
+ };
240
+
241
+ export function cmdFrontmatterGet(cwd: string, filePath: string | null, field: string | null, raw: boolean): void {
242
+ if (!filePath) { error('file path required'); }
243
+ const fullPath = path.isAbsolute(filePath!) ? filePath! : path.join(cwd, filePath!);
244
+ const content = safeReadFile(fullPath);
245
+ if (!content) { output({ error: 'File not found', path: filePath }, raw); return; }
246
+ const fm = extractFrontmatter(content);
247
+ if (field) {
248
+ const value = fm[field];
249
+ if (value === undefined) { output({ error: 'Field not found', field }, raw); return; }
250
+ output({ [field]: value }, raw, JSON.stringify(value));
251
+ } else {
252
+ output(fm, raw);
253
+ }
254
+ }
255
+
256
+ export function cmdFrontmatterSet(cwd: string, filePath: string | null, field: string | null, value: string | undefined, raw: boolean): void {
257
+ if (!filePath || !field || value === undefined) { error('file, field, and value required'); }
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: unknown;
263
+ try { parsedValue = JSON.parse(value!); } catch { parsedValue = value; }
264
+ fm[field!] = parsedValue as FrontmatterValue;
265
+ const newContent = spliceFrontmatter(content, fm);
266
+ fs.writeFileSync(fullPath, newContent, 'utf-8');
267
+ output({ updated: true, field, value: parsedValue }, raw, 'true');
268
+ }
269
+
270
+ export function cmdFrontmatterMerge(cwd: string, filePath: string | null, data: string | null, raw: boolean): void {
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: Record<string, unknown>;
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, newContent, 'utf-8');
281
+ output({ merged: true, fields: Object.keys(mergeData) }, raw, 'true');
282
+ }
283
+
284
+ export function cmdFrontmatterValidate(cwd: string, filePath: string | null, schemaName: string | null, raw: boolean): void {
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
+ }