@ktpartners/dgs-platform 2.6.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.
- package/LICENSE +38 -0
- package/README.md +851 -0
- package/agents/dgs-codebase-cross-analyzer.md +183 -0
- package/agents/dgs-codebase-mapper.md +782 -0
- package/agents/dgs-codebase-synthesizer.md +156 -0
- package/agents/dgs-debugger.md +1256 -0
- package/agents/dgs-executor.md +550 -0
- package/agents/dgs-integration-checker.md +481 -0
- package/agents/dgs-nyquist-auditor.md +178 -0
- package/agents/dgs-phase-researcher.md +563 -0
- package/agents/dgs-phase-verifier.md +450 -0
- package/agents/dgs-plan-checker.md +708 -0
- package/agents/dgs-planner.md +1324 -0
- package/agents/dgs-project-researcher.md +631 -0
- package/agents/dgs-research-synthesizer.md +249 -0
- package/agents/dgs-roadmapper.md +652 -0
- package/agents/dgs-verifier.md +607 -0
- package/bin/install.js +2073 -0
- package/commands/dgs/add-doc.md +45 -0
- package/commands/dgs/add-idea.md +38 -0
- package/commands/dgs/add-phase.md +43 -0
- package/commands/dgs/add-repo.md +54 -0
- package/commands/dgs/add-tests.md +41 -0
- package/commands/dgs/add-todo.md +47 -0
- package/commands/dgs/approve-spec.md +38 -0
- package/commands/dgs/audit-milestone.md +36 -0
- package/commands/dgs/audit-phase.md +37 -0
- package/commands/dgs/cancel-job.md +23 -0
- package/commands/dgs/capture-principle.md +143 -0
- package/commands/dgs/check-todos.md +45 -0
- package/commands/dgs/cleanup.md +18 -0
- package/commands/dgs/complete-milestone.md +136 -0
- package/commands/dgs/complete-project.md +70 -0
- package/commands/dgs/consolidate-ideas.md +50 -0
- package/commands/dgs/create-milestone-job.md +37 -0
- package/commands/dgs/debug.md +164 -0
- package/commands/dgs/develop-idea.md +53 -0
- package/commands/dgs/discuss-idea.md +41 -0
- package/commands/dgs/discuss-phase.md +83 -0
- package/commands/dgs/execute-phase.md +41 -0
- package/commands/dgs/fast.md +38 -0
- package/commands/dgs/find-related-ideas.md +43 -0
- package/commands/dgs/health.md +28 -0
- package/commands/dgs/help.md +22 -0
- package/commands/dgs/import-spec.md +36 -0
- package/commands/dgs/init-product.md +28 -0
- package/commands/dgs/insert-phase.md +32 -0
- package/commands/dgs/join-discord.md +18 -0
- package/commands/dgs/list-docs.md +40 -0
- package/commands/dgs/list-ideas.md +42 -0
- package/commands/dgs/list-jobs.md +22 -0
- package/commands/dgs/list-phase-assumptions.md +46 -0
- package/commands/dgs/list-projects.md +57 -0
- package/commands/dgs/list-specs.md +40 -0
- package/commands/dgs/map-codebase.md +92 -0
- package/commands/dgs/new-milestone.md +44 -0
- package/commands/dgs/new-project.md +42 -0
- package/commands/dgs/node-repair.md +26 -0
- package/commands/dgs/overlap-check.md +20 -0
- package/commands/dgs/pause-work.md +38 -0
- package/commands/dgs/plan-milestone-gaps.md +34 -0
- package/commands/dgs/plan-phase.md +44 -0
- package/commands/dgs/progress.md +24 -0
- package/commands/dgs/quick.md +41 -0
- package/commands/dgs/reactivate-project.md +70 -0
- package/commands/dgs/reapply-patches.md +110 -0
- package/commands/dgs/refine-spec.md +38 -0
- package/commands/dgs/reject-idea.md +43 -0
- package/commands/dgs/remove-doc.md +44 -0
- package/commands/dgs/remove-phase.md +31 -0
- package/commands/dgs/remove-repo.md +69 -0
- package/commands/dgs/research-idea.md +43 -0
- package/commands/dgs/research-phase.md +189 -0
- package/commands/dgs/restore-idea.md +45 -0
- package/commands/dgs/resume-work.md +40 -0
- package/commands/dgs/rollback-job.md +24 -0
- package/commands/dgs/run-job.md +35 -0
- package/commands/dgs/search.md +40 -0
- package/commands/dgs/set-profile.md +34 -0
- package/commands/dgs/settings.md +38 -0
- package/commands/dgs/switch-project.md +58 -0
- package/commands/dgs/undo-consolidation.md +42 -0
- package/commands/dgs/update-idea.md +44 -0
- package/commands/dgs/update.md +37 -0
- package/commands/dgs/validate-phase.md +35 -0
- package/commands/dgs/verify-work.md +39 -0
- package/commands/dgs/write-spec.md +49 -0
- package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-01-SUMMARY.md +84 -0
- package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-02-SUMMARY.md +86 -0
- package/deliver-great-systems/.planning/phases/10-v1-to-v2-migration-flow/10-01-SUMMARY.md +85 -0
- package/deliver-great-systems/bin/dgs-tools.cjs +1444 -0
- package/deliver-great-systems/bin/lib/auto-test.cjs +1365 -0
- package/deliver-great-systems/bin/lib/commands.cjs +570 -0
- package/deliver-great-systems/bin/lib/config.cjs +417 -0
- package/deliver-great-systems/bin/lib/conflict-agent.cjs +1063 -0
- package/deliver-great-systems/bin/lib/conflict-agent.test.cjs +554 -0
- package/deliver-great-systems/bin/lib/context.cjs +929 -0
- package/deliver-great-systems/bin/lib/context.test.cjs +693 -0
- package/deliver-great-systems/bin/lib/core.cjs +744 -0
- package/deliver-great-systems/bin/lib/core.test.cjs +822 -0
- package/deliver-great-systems/bin/lib/docs.cjs +919 -0
- package/deliver-great-systems/bin/lib/docs.test.cjs +211 -0
- package/deliver-great-systems/bin/lib/execution.cjs +705 -0
- package/deliver-great-systems/bin/lib/execution.test.cjs +1472 -0
- package/deliver-great-systems/bin/lib/frontmatter.cjs +324 -0
- package/deliver-great-systems/bin/lib/ideas.cjs +1406 -0
- package/deliver-great-systems/bin/lib/ideas.test.cjs +1417 -0
- package/deliver-great-systems/bin/lib/identity.cjs +125 -0
- package/deliver-great-systems/bin/lib/init.cjs +1114 -0
- package/deliver-great-systems/bin/lib/init.test.cjs +1271 -0
- package/deliver-great-systems/bin/lib/jobs.cjs +2015 -0
- package/deliver-great-systems/bin/lib/jobs.test.cjs +2619 -0
- package/deliver-great-systems/bin/lib/merge-conflicts.cjs +654 -0
- package/deliver-great-systems/bin/lib/merge-conflicts.test.cjs +370 -0
- package/deliver-great-systems/bin/lib/migration.cjs +352 -0
- package/deliver-great-systems/bin/lib/migration.test.cjs +582 -0
- package/deliver-great-systems/bin/lib/milestone.cjs +243 -0
- package/deliver-great-systems/bin/lib/overlap.cjs +437 -0
- package/deliver-great-systems/bin/lib/overlap.test.cjs +747 -0
- package/deliver-great-systems/bin/lib/path-audit.test.cjs +384 -0
- package/deliver-great-systems/bin/lib/paths.cjs +144 -0
- package/deliver-great-systems/bin/lib/paths.test.cjs +486 -0
- package/deliver-great-systems/bin/lib/phase.cjs +910 -0
- package/deliver-great-systems/bin/lib/projects.cjs +691 -0
- package/deliver-great-systems/bin/lib/projects.test.cjs +871 -0
- package/deliver-great-systems/bin/lib/repos.cjs +1432 -0
- package/deliver-great-systems/bin/lib/repos.test.cjs +1882 -0
- package/deliver-great-systems/bin/lib/roadmap.cjs +305 -0
- package/deliver-great-systems/bin/lib/search.cjs +570 -0
- package/deliver-great-systems/bin/lib/specs.cjs +1303 -0
- package/deliver-great-systems/bin/lib/state.cjs +893 -0
- package/deliver-great-systems/bin/lib/template.cjs +228 -0
- package/deliver-great-systems/bin/lib/test-helpers.cjs +291 -0
- package/deliver-great-systems/bin/lib/verify.cjs +796 -0
- package/deliver-great-systems/references/checkpoints.md +776 -0
- package/deliver-great-systems/references/conflict-resolution.md +66 -0
- package/deliver-great-systems/references/context-tiers.md +166 -0
- package/deliver-great-systems/references/continuation-format.md +249 -0
- package/deliver-great-systems/references/decimal-phase-calculation.md +67 -0
- package/deliver-great-systems/references/git-integration.md +250 -0
- package/deliver-great-systems/references/git-planning-commit.md +40 -0
- package/deliver-great-systems/references/model-profile-resolution.md +36 -0
- package/deliver-great-systems/references/model-profiles.md +95 -0
- package/deliver-great-systems/references/phase-argument-parsing.md +61 -0
- package/deliver-great-systems/references/planning-config.md +224 -0
- package/deliver-great-systems/references/questioning.md +162 -0
- package/deliver-great-systems/references/spec-review-loop.md +177 -0
- package/deliver-great-systems/references/tdd.md +265 -0
- package/deliver-great-systems/references/ui-brand.md +160 -0
- package/deliver-great-systems/references/verification-patterns.md +612 -0
- package/deliver-great-systems/templates/DEBUG.md +166 -0
- package/deliver-great-systems/templates/UAT.md +251 -0
- package/deliver-great-systems/templates/VALIDATION.md +95 -0
- package/deliver-great-systems/templates/claude-md.md +74 -0
- package/deliver-great-systems/templates/codebase/architecture.md +257 -0
- package/deliver-great-systems/templates/codebase/concerns.md +312 -0
- package/deliver-great-systems/templates/codebase/conventions.md +309 -0
- package/deliver-great-systems/templates/codebase/integrations.md +282 -0
- package/deliver-great-systems/templates/codebase/stack.md +188 -0
- package/deliver-great-systems/templates/codebase/structure.md +287 -0
- package/deliver-great-systems/templates/codebase/testing.md +482 -0
- package/deliver-great-systems/templates/config.json +38 -0
- package/deliver-great-systems/templates/context.md +354 -0
- package/deliver-great-systems/templates/continue-here.md +80 -0
- package/deliver-great-systems/templates/debug-subagent-prompt.md +93 -0
- package/deliver-great-systems/templates/discovery.md +148 -0
- package/deliver-great-systems/templates/milestone-archive.md +125 -0
- package/deliver-great-systems/templates/milestone.md +117 -0
- package/deliver-great-systems/templates/phase-prompt.md +615 -0
- package/deliver-great-systems/templates/planner-subagent-prompt.md +119 -0
- package/deliver-great-systems/templates/project.md +186 -0
- package/deliver-great-systems/templates/requirements.md +233 -0
- package/deliver-great-systems/templates/research-project/ARCHITECTURE.md +206 -0
- package/deliver-great-systems/templates/research-project/FEATURES.md +149 -0
- package/deliver-great-systems/templates/research-project/PITFALLS.md +202 -0
- package/deliver-great-systems/templates/research-project/STACK.md +122 -0
- package/deliver-great-systems/templates/research-project/SUMMARY.md +172 -0
- package/deliver-great-systems/templates/research.md +554 -0
- package/deliver-great-systems/templates/retrospective.md +54 -0
- package/deliver-great-systems/templates/roadmap.md +204 -0
- package/deliver-great-systems/templates/state.md +178 -0
- package/deliver-great-systems/templates/summary-complex.md +59 -0
- package/deliver-great-systems/templates/summary-minimal.md +41 -0
- package/deliver-great-systems/templates/summary-standard.md +48 -0
- package/deliver-great-systems/templates/summary.md +253 -0
- package/deliver-great-systems/templates/user-setup.md +313 -0
- package/deliver-great-systems/templates/verification-report.md +324 -0
- package/deliver-great-systems/workflows/add-doc.md +151 -0
- package/deliver-great-systems/workflows/add-idea.md +96 -0
- package/deliver-great-systems/workflows/add-phase.md +120 -0
- package/deliver-great-systems/workflows/add-tests.md +359 -0
- package/deliver-great-systems/workflows/add-todo.md +162 -0
- package/deliver-great-systems/workflows/approve-spec.md +194 -0
- package/deliver-great-systems/workflows/audit-milestone.md +364 -0
- package/deliver-great-systems/workflows/audit-phase.md +462 -0
- package/deliver-great-systems/workflows/cancel-job.md +108 -0
- package/deliver-great-systems/workflows/check-todos.md +181 -0
- package/deliver-great-systems/workflows/cleanup.md +247 -0
- package/deliver-great-systems/workflows/codereview.md +526 -0
- package/deliver-great-systems/workflows/complete-milestone.md +1298 -0
- package/deliver-great-systems/workflows/consolidate-ideas.md +365 -0
- package/deliver-great-systems/workflows/create-milestone-job.md +177 -0
- package/deliver-great-systems/workflows/develop-idea.md +544 -0
- package/deliver-great-systems/workflows/diagnose-issues.md +231 -0
- package/deliver-great-systems/workflows/discovery-phase.md +301 -0
- package/deliver-great-systems/workflows/discuss-idea.md +263 -0
- package/deliver-great-systems/workflows/discuss-phase.md +733 -0
- package/deliver-great-systems/workflows/execute-phase.md +571 -0
- package/deliver-great-systems/workflows/execute-plan.md +592 -0
- package/deliver-great-systems/workflows/find-related-ideas.md +271 -0
- package/deliver-great-systems/workflows/health.md +173 -0
- package/deliver-great-systems/workflows/help.md +997 -0
- package/deliver-great-systems/workflows/import-spec.md +381 -0
- package/deliver-great-systems/workflows/init-product.md +767 -0
- package/deliver-great-systems/workflows/insert-phase.md +138 -0
- package/deliver-great-systems/workflows/list-docs.md +119 -0
- package/deliver-great-systems/workflows/list-ideas.md +154 -0
- package/deliver-great-systems/workflows/list-jobs.md +89 -0
- package/deliver-great-systems/workflows/list-phase-assumptions.md +192 -0
- package/deliver-great-systems/workflows/list-specs.md +101 -0
- package/deliver-great-systems/workflows/map-codebase.md +621 -0
- package/deliver-great-systems/workflows/new-milestone.md +591 -0
- package/deliver-great-systems/workflows/new-project.md +1113 -0
- package/deliver-great-systems/workflows/node-repair.md +94 -0
- package/deliver-great-systems/workflows/overlap-check.md +86 -0
- package/deliver-great-systems/workflows/pause-work.md +134 -0
- package/deliver-great-systems/workflows/plan-milestone-gaps.md +306 -0
- package/deliver-great-systems/workflows/plan-phase.md +698 -0
- package/deliver-great-systems/workflows/progress.md +386 -0
- package/deliver-great-systems/workflows/quick.md +845 -0
- package/deliver-great-systems/workflows/refine-spec.md +275 -0
- package/deliver-great-systems/workflows/reject-idea.md +109 -0
- package/deliver-great-systems/workflows/remove-doc.md +117 -0
- package/deliver-great-systems/workflows/remove-phase.md +163 -0
- package/deliver-great-systems/workflows/research-idea.md +325 -0
- package/deliver-great-systems/workflows/research-phase.md +81 -0
- package/deliver-great-systems/workflows/restore-idea.md +101 -0
- package/deliver-great-systems/workflows/resume-project.md +311 -0
- package/deliver-great-systems/workflows/rollback-job.md +130 -0
- package/deliver-great-systems/workflows/run-job.md +498 -0
- package/deliver-great-systems/workflows/search.md +130 -0
- package/deliver-great-systems/workflows/set-profile.md +83 -0
- package/deliver-great-systems/workflows/settings.md +470 -0
- package/deliver-great-systems/workflows/transition.md +563 -0
- package/deliver-great-systems/workflows/undo-consolidation.md +155 -0
- package/deliver-great-systems/workflows/update-idea.md +157 -0
- package/deliver-great-systems/workflows/update.md +242 -0
- package/deliver-great-systems/workflows/validate-phase.md +177 -0
- package/deliver-great-systems/workflows/verify-phase.md +253 -0
- package/deliver-great-systems/workflows/verify-work.md +671 -0
- package/deliver-great-systems/workflows/write-spec.md +450 -0
- package/hooks/dist/dgs-check-update.js +62 -0
- package/hooks/dist/dgs-context-monitor.js +141 -0
- package/hooks/dist/dgs-statusline.js +115 -0
- package/package.json +60 -0
- package/scripts/build-hooks.js +43 -0
|
@@ -0,0 +1,324 @@
|
|
|
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, output, error } = require('./core.cjs');
|
|
8
|
+
|
|
9
|
+
// ─── Parsing engine ───────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
function extractFrontmatter(content) {
|
|
12
|
+
const frontmatter = {};
|
|
13
|
+
// Support files with an HTML comment block before the frontmatter
|
|
14
|
+
// (e.g., <!-- DGS metadata ... --> preceding the --- delimiter)
|
|
15
|
+
const match = content.match(/(?:^|-->\n)---\n([\s\S]+?)\n---/);
|
|
16
|
+
if (!match) return frontmatter;
|
|
17
|
+
|
|
18
|
+
const yaml = match[1];
|
|
19
|
+
const lines = yaml.split('\n');
|
|
20
|
+
|
|
21
|
+
// Stack to track nested objects: [{obj, key, indent}]
|
|
22
|
+
// obj = object to write to, key = current key collecting array items, indent = indentation level
|
|
23
|
+
let stack = [{ obj: frontmatter, key: null, indent: -1 }];
|
|
24
|
+
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
// Skip empty lines
|
|
27
|
+
if (line.trim() === '') continue;
|
|
28
|
+
|
|
29
|
+
// Calculate indentation (number of leading spaces)
|
|
30
|
+
const indentMatch = line.match(/^(\s*)/);
|
|
31
|
+
const indent = indentMatch ? indentMatch[1].length : 0;
|
|
32
|
+
|
|
33
|
+
// Pop stack back to appropriate level
|
|
34
|
+
while (stack.length > 1 && indent <= stack[stack.length - 1].indent) {
|
|
35
|
+
stack.pop();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const current = stack[stack.length - 1];
|
|
39
|
+
|
|
40
|
+
// Check for key: value pattern
|
|
41
|
+
const keyMatch = line.match(/^(\s*)([a-zA-Z0-9_-]+):\s*(.*)/);
|
|
42
|
+
if (keyMatch) {
|
|
43
|
+
const key = keyMatch[2];
|
|
44
|
+
const value = keyMatch[3].trim();
|
|
45
|
+
|
|
46
|
+
if (value === '' || value === '[') {
|
|
47
|
+
// Key with no value or opening bracket — could be nested object or array
|
|
48
|
+
// We'll determine based on next lines, for now create placeholder
|
|
49
|
+
current.obj[key] = value === '[' ? [] : {};
|
|
50
|
+
current.key = null;
|
|
51
|
+
// Push new context for potential nested content
|
|
52
|
+
stack.push({ obj: current.obj[key], key: null, indent });
|
|
53
|
+
} else if (value.startsWith('[') && value.endsWith(']')) {
|
|
54
|
+
// Inline array: key: [a, b, c]
|
|
55
|
+
current.obj[key] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
|
|
56
|
+
current.key = null;
|
|
57
|
+
} else {
|
|
58
|
+
// Simple key: value
|
|
59
|
+
current.obj[key] = value.replace(/^["']|["']$/g, '');
|
|
60
|
+
current.key = null;
|
|
61
|
+
}
|
|
62
|
+
} else if (line.trim().startsWith('- ')) {
|
|
63
|
+
// Array item
|
|
64
|
+
const itemValue = line.trim().slice(2).replace(/^["']|["']$/g, '');
|
|
65
|
+
|
|
66
|
+
// If current context is an empty object, convert to array
|
|
67
|
+
if (typeof current.obj === 'object' && !Array.isArray(current.obj) && Object.keys(current.obj).length === 0) {
|
|
68
|
+
// Find the key in parent that points to this object and convert it
|
|
69
|
+
const parent = stack.length > 1 ? stack[stack.length - 2] : null;
|
|
70
|
+
if (parent) {
|
|
71
|
+
for (const k of Object.keys(parent.obj)) {
|
|
72
|
+
if (parent.obj[k] === current.obj) {
|
|
73
|
+
parent.obj[k] = [itemValue];
|
|
74
|
+
current.obj = parent.obj[k];
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else if (Array.isArray(current.obj)) {
|
|
80
|
+
current.obj.push(itemValue);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return frontmatter;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function reconstructFrontmatter(obj) {
|
|
89
|
+
const lines = [];
|
|
90
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
91
|
+
if (value === null || value === undefined) continue;
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
if (value.length === 0) {
|
|
94
|
+
lines.push(`${key}: []`);
|
|
95
|
+
} else if (value.every(v => typeof v === 'string') && value.length <= 3 && value.join(', ').length < 60) {
|
|
96
|
+
lines.push(`${key}: [${value.join(', ')}]`);
|
|
97
|
+
} else {
|
|
98
|
+
lines.push(`${key}:`);
|
|
99
|
+
for (const item of value) {
|
|
100
|
+
lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} else if (typeof value === 'object') {
|
|
104
|
+
lines.push(`${key}:`);
|
|
105
|
+
for (const [subkey, subval] of Object.entries(value)) {
|
|
106
|
+
if (subval === null || subval === undefined) continue;
|
|
107
|
+
if (Array.isArray(subval)) {
|
|
108
|
+
if (subval.length === 0) {
|
|
109
|
+
lines.push(` ${subkey}: []`);
|
|
110
|
+
} else if (subval.every(v => typeof v === 'string') && subval.length <= 3 && subval.join(', ').length < 60) {
|
|
111
|
+
lines.push(` ${subkey}: [${subval.join(', ')}]`);
|
|
112
|
+
} else {
|
|
113
|
+
lines.push(` ${subkey}:`);
|
|
114
|
+
for (const item of subval) {
|
|
115
|
+
lines.push(` - ${typeof item === 'string' && (item.includes(':') || item.includes('#')) ? `"${item}"` : item}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else if (typeof subval === 'object') {
|
|
119
|
+
lines.push(` ${subkey}:`);
|
|
120
|
+
for (const [subsubkey, subsubval] of Object.entries(subval)) {
|
|
121
|
+
if (subsubval === null || subsubval === undefined) continue;
|
|
122
|
+
if (Array.isArray(subsubval)) {
|
|
123
|
+
if (subsubval.length === 0) {
|
|
124
|
+
lines.push(` ${subsubkey}: []`);
|
|
125
|
+
} else {
|
|
126
|
+
lines.push(` ${subsubkey}:`);
|
|
127
|
+
for (const item of subsubval) {
|
|
128
|
+
lines.push(` - ${item}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
lines.push(` ${subsubkey}: ${subsubval}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const sv = String(subval);
|
|
137
|
+
lines.push(` ${subkey}: ${sv.includes(':') || sv.includes('#') ? `"${sv}"` : sv}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
const sv = String(value);
|
|
142
|
+
if (sv.includes(':') || sv.includes('#') || sv.startsWith('[') || sv.startsWith('{')) {
|
|
143
|
+
lines.push(`${key}: "${sv}"`);
|
|
144
|
+
} else {
|
|
145
|
+
lines.push(`${key}: ${sv}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return lines.join('\n');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function spliceFrontmatter(content, newObj) {
|
|
153
|
+
const yamlStr = reconstructFrontmatter(newObj);
|
|
154
|
+
// Support files with an HTML comment block before the frontmatter
|
|
155
|
+
const match = content.match(/((?:^|-->\n))---\n[\s\S]+?\n---/);
|
|
156
|
+
if (match) {
|
|
157
|
+
const prefix = match[1]; // either '' or '-->\n'
|
|
158
|
+
const fullMatch = match[0];
|
|
159
|
+
const startIdx = content.indexOf(fullMatch);
|
|
160
|
+
return content.slice(0, startIdx) + `${prefix}---\n${yamlStr}\n---` + content.slice(startIdx + fullMatch.length);
|
|
161
|
+
}
|
|
162
|
+
return `---\n${yamlStr}\n---\n\n` + content;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function parseMustHavesBlock(content, blockName) {
|
|
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
|
+
// Supports both 2-space and 4-space indent styles
|
|
169
|
+
const fmMatch = content.match(/(?:^|-->\n)---\n([\s\S]+?)\n---/);
|
|
170
|
+
if (!fmMatch) return [];
|
|
171
|
+
|
|
172
|
+
const yaml = fmMatch[1];
|
|
173
|
+
|
|
174
|
+
// Detect indent style: find must_haves line and measure child indent
|
|
175
|
+
const mustHavesMatch = yaml.match(/^(\s*)must_haves:\s*$/m);
|
|
176
|
+
if (!mustHavesMatch) return [];
|
|
177
|
+
const baseIndent = mustHavesMatch[1].length; // 0 for top-level must_haves
|
|
178
|
+
|
|
179
|
+
// Find the block (e.g., "truths:", "artifacts:", "key_links:")
|
|
180
|
+
// Block header is one indent level deeper than must_haves
|
|
181
|
+
const blockPattern = new RegExp(`^\\s+${blockName}:\\s*$`, 'm');
|
|
182
|
+
const blockStart = yaml.search(blockPattern);
|
|
183
|
+
if (blockStart === -1) return [];
|
|
184
|
+
|
|
185
|
+
// Detect the block header's indent level
|
|
186
|
+
const blockHeaderMatch = yaml.slice(blockStart).match(/^(\s+)/);
|
|
187
|
+
const blockIndent = blockHeaderMatch ? blockHeaderMatch[1].length : baseIndent + 2;
|
|
188
|
+
const itemIndent = blockIndent + 2; // list items are one level deeper (- path: ...)
|
|
189
|
+
const contIndent = itemIndent + 2; // continuation keys are two levels deeper
|
|
190
|
+
|
|
191
|
+
const afterBlock = yaml.slice(blockStart);
|
|
192
|
+
const blockLines = afterBlock.split('\n').slice(1); // skip the header line
|
|
193
|
+
|
|
194
|
+
const items = [];
|
|
195
|
+
let current = null;
|
|
196
|
+
|
|
197
|
+
for (const line of blockLines) {
|
|
198
|
+
// Stop at same or lower indent level (non-continuation)
|
|
199
|
+
if (line.trim() === '') continue;
|
|
200
|
+
const indent = line.match(/^(\s*)/)[1].length;
|
|
201
|
+
if (indent <= blockIndent && line.trim() !== '') break; // back to block level or higher
|
|
202
|
+
|
|
203
|
+
// New list item at item indent level
|
|
204
|
+
const itemPattern = new RegExp(`^\\s{${itemIndent}}-\\s+`);
|
|
205
|
+
if (itemPattern.test(line)) {
|
|
206
|
+
if (current) items.push(current);
|
|
207
|
+
current = {};
|
|
208
|
+
// Check if it's a simple string item
|
|
209
|
+
const simplePattern = new RegExp(`^\\s{${itemIndent}}-\\s+"?([^"]+)"?\\s*$`);
|
|
210
|
+
const simpleMatch = line.match(simplePattern);
|
|
211
|
+
if (simpleMatch && !line.includes(':')) {
|
|
212
|
+
current = simpleMatch[1];
|
|
213
|
+
} else {
|
|
214
|
+
// Key-value on same line as dash: "- path: value"
|
|
215
|
+
const kvPattern = new RegExp(`^\\s{${itemIndent}}-\\s+(\\w+):\\s*"?([^"]*)"?\\s*$`);
|
|
216
|
+
const kvMatch = line.match(kvPattern);
|
|
217
|
+
if (kvMatch) {
|
|
218
|
+
current = {};
|
|
219
|
+
current[kvMatch[1]] = kvMatch[2];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} else if (current && typeof current === 'object') {
|
|
223
|
+
// Continuation key-value at continuation indent or deeper
|
|
224
|
+
const kvPattern = new RegExp(`^\\s{${contIndent},}(\\w+):\\s*"?([^"]*)"?\\s*$`);
|
|
225
|
+
const kvMatch = line.match(kvPattern);
|
|
226
|
+
if (kvMatch) {
|
|
227
|
+
const val = kvMatch[2];
|
|
228
|
+
// Try to parse as number
|
|
229
|
+
current[kvMatch[1]] = /^\d+$/.test(val) ? parseInt(val, 10) : val;
|
|
230
|
+
}
|
|
231
|
+
// Array items under a key (two more levels deep)
|
|
232
|
+
const arrPattern = new RegExp(`^\\s{${contIndent + 2},}-\\s+"?([^"]+)"?\\s*$`);
|
|
233
|
+
const arrMatch = line.match(arrPattern);
|
|
234
|
+
if (arrMatch) {
|
|
235
|
+
// Find the last key added and convert to array
|
|
236
|
+
const keys = Object.keys(current);
|
|
237
|
+
const lastKey = keys[keys.length - 1];
|
|
238
|
+
if (lastKey && !Array.isArray(current[lastKey])) {
|
|
239
|
+
current[lastKey] = current[lastKey] ? [current[lastKey]] : [];
|
|
240
|
+
}
|
|
241
|
+
if (lastKey) current[lastKey].push(arrMatch[1]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (current) items.push(current);
|
|
246
|
+
|
|
247
|
+
return items;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ─── Frontmatter CRUD commands ────────────────────────────────────────────────
|
|
251
|
+
|
|
252
|
+
const FRONTMATTER_SCHEMAS = {
|
|
253
|
+
plan: { required: ['phase', 'plan', 'type', 'wave', 'depends_on', 'files_modified', 'autonomous', 'must_haves'] },
|
|
254
|
+
summary: { required: ['phase', 'plan', 'subsystem', 'tags', 'duration', 'completed', 'requirements-completed'] },
|
|
255
|
+
verification: { required: ['phase', 'verified', 'status', 'score'] },
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
function cmdFrontmatterGet(cwd, filePath, field, raw) {
|
|
259
|
+
if (!filePath) { error('file path required'); }
|
|
260
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
|
|
261
|
+
const content = safeReadFile(fullPath);
|
|
262
|
+
if (!content) { output({ error: 'File not found', path: filePath }, raw); return; }
|
|
263
|
+
const fm = extractFrontmatter(content);
|
|
264
|
+
if (field) {
|
|
265
|
+
const value = fm[field];
|
|
266
|
+
if (value === undefined) { output({ error: 'Field not found', field }, raw); return; }
|
|
267
|
+
output({ [field]: value }, raw, JSON.stringify(value));
|
|
268
|
+
} else {
|
|
269
|
+
output(fm, raw);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cmdFrontmatterSet(cwd, filePath, field, value, raw) {
|
|
274
|
+
if (!filePath || !field || value === undefined) { error('file, field, and value required'); }
|
|
275
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
|
|
276
|
+
if (!fs.existsSync(fullPath)) { output({ error: 'File not found', path: filePath }, raw); return; }
|
|
277
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
278
|
+
const fm = extractFrontmatter(content);
|
|
279
|
+
let parsedValue;
|
|
280
|
+
try { parsedValue = JSON.parse(value); } catch { parsedValue = value; }
|
|
281
|
+
fm[field] = parsedValue;
|
|
282
|
+
const newContent = spliceFrontmatter(content, fm);
|
|
283
|
+
fs.writeFileSync(fullPath, newContent, 'utf-8');
|
|
284
|
+
output({ updated: true, field, value: parsedValue }, raw, 'true');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function cmdFrontmatterMerge(cwd, filePath, data, raw) {
|
|
288
|
+
if (!filePath || !data) { error('file and data required'); }
|
|
289
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
|
|
290
|
+
if (!fs.existsSync(fullPath)) { output({ error: 'File not found', path: filePath }, raw); return; }
|
|
291
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
292
|
+
const fm = extractFrontmatter(content);
|
|
293
|
+
let mergeData;
|
|
294
|
+
try { mergeData = JSON.parse(data); } catch { error('Invalid JSON for --data'); return; }
|
|
295
|
+
Object.assign(fm, mergeData);
|
|
296
|
+
const newContent = spliceFrontmatter(content, fm);
|
|
297
|
+
fs.writeFileSync(fullPath, newContent, 'utf-8');
|
|
298
|
+
output({ merged: true, fields: Object.keys(mergeData) }, raw, 'true');
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function cmdFrontmatterValidate(cwd, filePath, schemaName, raw) {
|
|
302
|
+
if (!filePath || !schemaName) { error('file and schema required'); }
|
|
303
|
+
const schema = FRONTMATTER_SCHEMAS[schemaName];
|
|
304
|
+
if (!schema) { error(`Unknown schema: ${schemaName}. Available: ${Object.keys(FRONTMATTER_SCHEMAS).join(', ')}`); }
|
|
305
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(cwd, filePath);
|
|
306
|
+
const content = safeReadFile(fullPath);
|
|
307
|
+
if (!content) { output({ error: 'File not found', path: filePath }, raw); return; }
|
|
308
|
+
const fm = extractFrontmatter(content);
|
|
309
|
+
const missing = schema.required.filter(f => fm[f] === undefined);
|
|
310
|
+
const present = schema.required.filter(f => fm[f] !== undefined);
|
|
311
|
+
output({ valid: missing.length === 0, missing, present, schema: schemaName }, raw, missing.length === 0 ? 'valid' : 'invalid');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
module.exports = {
|
|
315
|
+
extractFrontmatter,
|
|
316
|
+
reconstructFrontmatter,
|
|
317
|
+
spliceFrontmatter,
|
|
318
|
+
parseMustHavesBlock,
|
|
319
|
+
FRONTMATTER_SCHEMAS,
|
|
320
|
+
cmdFrontmatterGet,
|
|
321
|
+
cmdFrontmatterSet,
|
|
322
|
+
cmdFrontmatterMerge,
|
|
323
|
+
cmdFrontmatterValidate,
|
|
324
|
+
};
|