mindforge-cc 2.0.0 → 2.1.1
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/.agent/bin/lib/commands.cjs +959 -0
- package/.agent/bin/lib/config.cjs +421 -0
- package/.agent/bin/lib/core.cjs +1166 -0
- package/.agent/bin/lib/frontmatter.cjs +307 -0
- package/.agent/bin/lib/init.cjs +1336 -0
- package/.agent/bin/lib/milestone.cjs +252 -0
- package/.agent/bin/lib/model-profiles.cjs +68 -0
- package/.agent/bin/lib/phase.cjs +888 -0
- package/.agent/bin/lib/profile-output.cjs +952 -0
- package/.agent/bin/lib/profile-pipeline.cjs +539 -0
- package/.agent/bin/lib/roadmap.cjs +329 -0
- package/.agent/bin/lib/security.cjs +356 -0
- package/.agent/bin/lib/state.cjs +969 -0
- package/.agent/bin/lib/template.cjs +222 -0
- package/.agent/bin/lib/uat.cjs +189 -0
- package/.agent/bin/lib/verify.cjs +851 -0
- package/.agent/bin/lib/workstream.cjs +491 -0
- package/.agent/bin/mindforge-tools.cjs +897 -0
- package/.agent/file-manifest.json +219 -0
- package/.agent/hooks/mindforge-check-update.js +114 -0
- package/.agent/hooks/mindforge-context-monitor.js +156 -0
- package/.agent/hooks/mindforge-prompt-guard.js +96 -0
- package/.agent/hooks/mindforge-statusline.js +119 -0
- package/.agent/hooks/mindforge-workflow-guard.js +94 -0
- package/.agent/mindforge/add-backlog.md +32 -0
- package/.agent/mindforge/agent.md +31 -0
- package/.agent/mindforge/discuss-phase.md +1 -1
- package/.agent/mindforge/do.md +31 -0
- package/.agent/mindforge/help.md +1 -1
- package/.agent/mindforge/learn.md +3 -2
- package/.agent/mindforge/note.md +35 -0
- package/.agent/mindforge/plant-seed.md +31 -0
- package/.agent/mindforge/research.md +3 -2
- package/.agent/mindforge/review-backlog.md +34 -0
- package/.agent/mindforge/session-report.md +39 -0
- package/.agent/mindforge/steer.md +1 -1
- package/.agent/mindforge/ui-phase.md +34 -0
- package/.agent/mindforge/ui-review.md +36 -0
- package/.agent/mindforge/validate-phase.md +31 -0
- package/.agent/mindforge/workstreams.md +35 -0
- package/.agent/settings.json +38 -0
- package/.agent/skills/mindforge-add-backlog/SKILL.md +72 -0
- package/.agent/skills/mindforge-add-phase/SKILL.md +39 -0
- package/.agent/skills/mindforge-add-tests/SKILL.md +28 -0
- package/.agent/skills/mindforge-add-todo/SKILL.md +42 -0
- package/.agent/skills/mindforge-audit-milestone/SKILL.md +29 -0
- package/.agent/skills/mindforge-audit-uat/SKILL.md +20 -0
- package/.agent/skills/mindforge-autonomous/SKILL.md +33 -0
- package/.agent/skills/mindforge-check-todos/SKILL.md +40 -0
- package/.agent/skills/mindforge-cleanup/SKILL.md +19 -0
- package/.agent/skills/mindforge-complete-milestone/SKILL.md +131 -0
- package/.agent/skills/mindforge-debug/SKILL.md +163 -0
- package/.agent/skills/mindforge-discuss-phase/SKILL.md +54 -0
- package/.agent/skills/mindforge-do/SKILL.md +26 -0
- package/.agent/skills/mindforge-execute-phase/SKILL.md +49 -0
- package/.agent/skills/mindforge-fast/SKILL.md +23 -0
- package/.agent/skills/mindforge-forensics/SKILL.md +49 -0
- package/.agent/skills/mindforge-health/SKILL.md +17 -0
- package/.agent/skills/mindforge-help/SKILL.md +23 -0
- package/.agent/skills/mindforge-insert-phase/SKILL.md +28 -0
- package/.agent/skills/mindforge-join-discord/SKILL.md +19 -0
- package/.agent/skills/mindforge-list-phase-assumptions/SKILL.md +41 -0
- package/.agent/skills/mindforge-list-workspaces/SKILL.md +17 -0
- package/.agent/skills/mindforge-manager/SKILL.md +32 -0
- package/.agent/skills/mindforge-map-codebase/SKILL.md +64 -0
- package/.agent/skills/mindforge-milestone-summary/SKILL.md +44 -0
- package/.agent/skills/mindforge-new-milestone/SKILL.md +38 -0
- package/.agent/skills/mindforge-new-project/SKILL.md +36 -0
- package/.agent/skills/mindforge-new-workspace/SKILL.md +39 -0
- package/.agent/skills/mindforge-next/SKILL.md +19 -0
- package/.agent/skills/mindforge-note/SKILL.md +29 -0
- package/.agent/skills/mindforge-pause-work/SKILL.md +35 -0
- package/.agent/skills/mindforge-plan-milestone-gaps/SKILL.md +28 -0
- package/.agent/skills/mindforge-plan-phase/SKILL.md +37 -0
- package/.agent/skills/mindforge-plant-seed/SKILL.md +22 -0
- package/.agent/skills/mindforge-pr-branch/SKILL.md +21 -0
- package/.agent/skills/mindforge-profile-user/SKILL.md +38 -0
- package/.agent/skills/mindforge-progress/SKILL.md +19 -0
- package/.agent/skills/mindforge-quick/SKILL.md +38 -0
- package/.agent/skills/mindforge-reapply-patches/SKILL.md +124 -0
- package/.agent/skills/mindforge-remove-phase/SKILL.md +26 -0
- package/.agent/skills/mindforge-remove-workspace/SKILL.md +22 -0
- package/.agent/skills/mindforge-research-phase/SKILL.md +186 -0
- package/.agent/skills/mindforge-resume-work/SKILL.md +35 -0
- package/.agent/skills/mindforge-review/SKILL.md +31 -0
- package/.agent/skills/mindforge-review-backlog/SKILL.md +58 -0
- package/.agent/skills/mindforge-session-report/SKILL.md +16 -0
- package/.agent/skills/mindforge-set-profile/SKILL.md +9 -0
- package/.agent/skills/mindforge-settings/SKILL.md +32 -0
- package/.agent/skills/mindforge-ship/SKILL.md +16 -0
- package/.agent/skills/mindforge-stats/SKILL.md +16 -0
- package/.agent/skills/mindforge-thread/SKILL.md +123 -0
- package/.agent/skills/mindforge-ui-phase/SKILL.md +24 -0
- package/.agent/skills/mindforge-ui-review/SKILL.md +24 -0
- package/.agent/skills/mindforge-update/SKILL.md +35 -0
- package/.agent/skills/mindforge-validate-phase/SKILL.md +26 -0
- package/.agent/skills/mindforge-verify-work/SKILL.md +30 -0
- package/.agent/skills/mindforge-workstreams/SKILL.md +65 -0
- package/.agent/workflows/mindforge-add-phase.md +112 -0
- package/.agent/workflows/mindforge-add-tests.md +351 -0
- package/.agent/workflows/mindforge-add-todo.md +158 -0
- package/.agent/workflows/mindforge-audit-milestone.md +332 -0
- package/.agent/workflows/mindforge-audit-uat.md +109 -0
- package/.agent/workflows/mindforge-autonomous.md +815 -0
- package/.agent/workflows/mindforge-check-todos.md +177 -0
- package/.agent/workflows/mindforge-cleanup.md +152 -0
- package/.agent/workflows/mindforge-complete-milestone.md +766 -0
- package/.agent/workflows/mindforge-diagnose-issues.md +220 -0
- package/.agent/workflows/mindforge-discovery-phase.md +289 -0
- package/.agent/workflows/mindforge-discuss-phase-assumptions.md +645 -0
- package/.agent/workflows/mindforge-discuss-phase.md +1047 -0
- package/.agent/workflows/mindforge-do.md +104 -0
- package/.agent/workflows/mindforge-execute-phase.md +838 -0
- package/.agent/workflows/mindforge-execute-plan.md +509 -0
- package/.agent/workflows/mindforge-fast.md +105 -0
- package/.agent/workflows/mindforge-forensics.md +265 -0
- package/.agent/workflows/mindforge-health.md +181 -0
- package/.agent/workflows/mindforge-help.md +606 -0
- package/.agent/workflows/mindforge-insert-phase.md +130 -0
- package/.agent/workflows/mindforge-list-phase-assumptions.md +178 -0
- package/.agent/workflows/mindforge-list-workspaces.md +56 -0
- package/.agent/workflows/mindforge-manager.md +360 -0
- package/.agent/workflows/mindforge-map-codebase.md +370 -0
- package/.agent/workflows/mindforge-milestone-summary.md +223 -0
- package/.agent/workflows/mindforge-new-milestone.md +469 -0
- package/.agent/workflows/mindforge-new-project.md +1226 -0
- package/.agent/workflows/mindforge-new-workspace.md +237 -0
- package/.agent/workflows/mindforge-next.md +97 -0
- package/.agent/workflows/mindforge-node-repair.md +92 -0
- package/.agent/workflows/mindforge-note.md +156 -0
- package/.agent/workflows/mindforge-pause-work.md +176 -0
- package/.agent/workflows/mindforge-plan-milestone-gaps.md +273 -0
- package/.agent/workflows/mindforge-plan-phase.md +848 -0
- package/.agent/workflows/mindforge-plant-seed.md +169 -0
- package/.agent/workflows/mindforge-pr-branch.md +129 -0
- package/.agent/workflows/mindforge-profile-user.md +450 -0
- package/.agent/workflows/mindforge-progress.md +507 -0
- package/.agent/workflows/mindforge-quick.md +732 -0
- package/.agent/workflows/mindforge-remove-phase.md +155 -0
- package/.agent/workflows/mindforge-remove-workspace.md +90 -0
- package/.agent/workflows/mindforge-research-phase.md +74 -0
- package/.agent/workflows/mindforge-resume-project.md +325 -0
- package/.agent/workflows/mindforge-review.md +228 -0
- package/.agent/workflows/mindforge-session-report.md +146 -0
- package/.agent/workflows/mindforge-settings.md +283 -0
- package/.agent/workflows/mindforge-ship.md +228 -0
- package/.agent/workflows/mindforge-stats.md +60 -0
- package/.agent/workflows/mindforge-transition.md +671 -0
- package/.agent/workflows/mindforge-ui-phase.md +290 -0
- package/.agent/workflows/mindforge-ui-review.md +157 -0
- package/.agent/workflows/mindforge-update.md +323 -0
- package/.agent/workflows/mindforge-validate-phase.md +167 -0
- package/.agent/workflows/mindforge-verify-phase.md +254 -0
- package/.agent/workflows/mindforge-verify-work.md +623 -0
- package/.claude/commands/mindforge/add-backlog.md +32 -0
- package/.claude/commands/mindforge/agent.md +31 -0
- package/.claude/commands/mindforge/approve.md +27 -15
- package/.claude/commands/mindforge/audit.md +30 -26
- package/.claude/commands/mindforge/auto.md +29 -18
- package/.claude/commands/mindforge/benchmark.md +26 -29
- package/.claude/commands/mindforge/browse.md +24 -22
- package/.claude/commands/mindforge/complete-milestone.md +28 -14
- package/.claude/commands/mindforge/costs.md +26 -9
- package/.claude/commands/mindforge/cross-review.md +27 -13
- package/.claude/commands/mindforge/dashboard.md +35 -98
- package/.claude/commands/mindforge/debug.md +34 -126
- package/.claude/commands/mindforge/discuss-phase.md +36 -138
- package/.claude/commands/mindforge/do.md +31 -0
- package/.claude/commands/mindforge/execute-phase.md +37 -190
- package/.claude/commands/mindforge/health.md +27 -17
- package/.claude/commands/mindforge/help.md +25 -19
- package/.claude/commands/mindforge/init-org.md +37 -131
- package/.claude/commands/mindforge/init-project.md +40 -155
- package/.claude/commands/mindforge/install-skill.md +32 -15
- package/.claude/commands/mindforge/learn.md +36 -142
- package/.claude/commands/mindforge/map-codebase.md +36 -298
- package/.claude/commands/mindforge/marketplace.md +33 -120
- package/.claude/commands/mindforge/metrics.md +29 -18
- package/.claude/commands/mindforge/migrate.md +33 -40
- package/.claude/commands/mindforge/milestone.md +35 -12
- package/.claude/commands/mindforge/new-runtime.md +25 -15
- package/.claude/commands/mindforge/next.md +34 -105
- package/.claude/commands/mindforge/note.md +35 -0
- package/.claude/commands/mindforge/plan-phase.md +34 -125
- package/.claude/commands/mindforge/plant-seed.md +31 -0
- package/.claude/commands/mindforge/plugins.md +30 -36
- package/.claude/commands/mindforge/pr-review.md +32 -41
- package/.claude/commands/mindforge/profile-team.md +26 -19
- package/.claude/commands/mindforge/publish-skill.md +28 -17
- package/.claude/commands/mindforge/qa.md +27 -12
- package/.claude/commands/mindforge/quick.md +35 -135
- package/.claude/commands/mindforge/release.md +27 -8
- package/.claude/commands/mindforge/remember.md +25 -10
- package/.claude/commands/mindforge/research.md +27 -9
- package/.claude/commands/mindforge/retrospective.md +28 -22
- package/.claude/commands/mindforge/review-backlog.md +34 -0
- package/.claude/commands/mindforge/review.md +37 -157
- package/.claude/commands/mindforge/security-scan.md +34 -233
- package/.claude/commands/mindforge/session-report.md +39 -0
- package/.claude/commands/mindforge/ship.md +34 -100
- package/.claude/commands/mindforge/skills.md +36 -141
- package/.claude/commands/mindforge/status.md +30 -104
- package/.claude/commands/mindforge/steer.md +25 -10
- package/.claude/commands/mindforge/sync-confluence.md +28 -9
- package/.claude/commands/mindforge/sync-jira.md +32 -12
- package/.claude/commands/mindforge/tokens.md +25 -6
- package/.claude/commands/mindforge/ui-phase.md +34 -0
- package/.claude/commands/mindforge/ui-review.md +36 -0
- package/.claude/commands/mindforge/update.md +33 -42
- package/.claude/commands/mindforge/validate-phase.md +31 -0
- package/.claude/commands/mindforge/verify-phase.md +30 -62
- package/.claude/commands/mindforge/workspace.md +28 -25
- package/.claude/commands/mindforge/workstreams.md +35 -0
- package/.mindforge/memory/decision-library.jsonl +0 -0
- package/.mindforge/memory/knowledge-base.jsonl +7 -0
- package/.mindforge/memory/pattern-library.jsonl +1 -0
- package/.mindforge/memory/team-preferences.jsonl +4 -0
- package/.mindforge/personas/advisor-researcher.md +89 -0
- package/.mindforge/personas/analyst.md +112 -52
- package/.mindforge/personas/architect.md +100 -67
- package/.mindforge/personas/assumptions-analyzer-extend.md +87 -0
- package/.mindforge/personas/assumptions-analyzer.md +109 -0
- package/.mindforge/personas/codebase-mapper-extend.md +93 -0
- package/.mindforge/personas/codebase-mapper.md +770 -0
- package/.mindforge/personas/coverage-specialist.md +104 -0
- package/.mindforge/personas/debug-specialist.md +118 -52
- package/.mindforge/personas/debugger.md +97 -0
- package/.mindforge/personas/decision-architect.md +102 -0
- package/.mindforge/personas/developer.md +97 -85
- package/.mindforge/personas/executor.md +88 -0
- package/.mindforge/personas/integration-checker.md +92 -0
- package/.mindforge/personas/nyquist-auditor.md +84 -0
- package/.mindforge/personas/phase-researcher.md +107 -0
- package/.mindforge/personas/plan-checker.md +92 -0
- package/.mindforge/personas/planner.md +105 -0
- package/.mindforge/personas/project-researcher.md +99 -0
- package/.mindforge/personas/qa-engineer.md +113 -61
- package/.mindforge/personas/release-manager.md +102 -64
- package/.mindforge/personas/research-agent.md +109 -24
- package/.mindforge/personas/research-synthesizer.md +101 -0
- package/.mindforge/personas/roadmapper-extend.md +100 -0
- package/.mindforge/personas/roadmapper.md +103 -0
- package/.mindforge/personas/security-reviewer.md +114 -91
- package/.mindforge/personas/tech-writer.md +118 -51
- package/.mindforge/personas/ui-auditor.md +94 -0
- package/.mindforge/personas/ui-checker.md +89 -0
- package/.mindforge/personas/ui-researcher.md +99 -0
- package/.mindforge/personas/user-profiler.md +93 -0
- package/.mindforge/personas/verifier.md +101 -0
- package/.planning/ROADMAP.md +10 -0
- package/.planning/browser-daemon.log +32 -0
- package/.planning/phases/01-migrate-gsd-to-mindforge/.gitkeep +0 -0
- package/CHANGELOG.md +41 -0
- package/MINDFORGE.md +2 -0
- package/README.md +40 -3
- package/bin/installer-core.js +3 -4
- package/docs/PERSONAS.md +611 -0
- package/docs/commands-reference.md +1 -0
- package/docs/{Context → context}/Master-Context.md +6 -13
- package/docs/references/checkpoints.md +778 -0
- package/docs/{reference → references}/commands.md +53 -43
- package/docs/references/continuation-format.md +249 -0
- package/docs/references/decimal-phase-calculation.md +64 -0
- package/docs/references/git-integration.md +295 -0
- package/docs/references/git-planning-commit.md +38 -0
- package/docs/references/model-profile-resolution.md +36 -0
- package/docs/references/model-profiles.md +139 -0
- package/docs/references/phase-argument-parsing.md +61 -0
- package/docs/references/planning-config.md +202 -0
- package/docs/references/questioning.md +162 -0
- package/docs/references/tdd.md +263 -0
- package/docs/references/ui-brand.md +160 -0
- package/docs/references/user-profiling.md +681 -0
- package/docs/references/verification-patterns.md +612 -0
- package/docs/references/workstream-flag.md +58 -0
- package/docs/skills-authoring-guide.md +1 -1
- package/docs/templates/Agents/CLAUDE-MD.md +122 -0
- package/docs/templates/Agents/COPILOT-INSTRUCTIONS.md +7 -0
- package/docs/templates/Agents/DEBUGGER-PROMPT.md +91 -0
- package/docs/templates/Agents/PLANNER-PROMPT.md +117 -0
- package/docs/templates/Execution/CONTINUE-HERE.md +78 -0
- package/docs/templates/Execution/DISCUSSION-LOG.md +63 -0
- package/docs/templates/Execution/PHASE-PROMPT.md +610 -0
- package/docs/templates/Execution/STATE.md +176 -0
- package/docs/templates/Execution/SUMMARY-COMPLEX.md +59 -0
- package/docs/templates/Execution/SUMMARY-MINIMAL.md +41 -0
- package/docs/templates/Execution/SUMMARY-STANDARD.md +48 -0
- package/docs/templates/Execution/SUMMARY.md +248 -0
- package/docs/templates/Profile/DEV-PREFERENCES.md +21 -0
- package/docs/templates/Profile/USER-PROFILE.md +146 -0
- package/docs/templates/Profile/USER-SETUP.md +311 -0
- package/docs/templates/Project/DISCOVERY.md +146 -0
- package/docs/templates/Project/MILESTONE-ARCHIVE.md +123 -0
- package/docs/templates/Project/MILESTONE.md +115 -0
- package/docs/templates/Project/PROJECT.md +206 -0
- package/docs/templates/Project/REQUIREMENTS.md +231 -0
- package/docs/templates/Project/RETROSPECTIVE.md +54 -0
- package/docs/templates/Project/ROADMAP.md +202 -0
- package/docs/templates/Quality/DEBUG.md +164 -0
- package/docs/templates/Quality/UAT.md +280 -0
- package/docs/templates/Quality/UI-SPEC.md +100 -0
- package/docs/templates/Quality/VALIDATION.md +76 -0
- package/docs/templates/Quality/VERIFICATION-REPORT.md +322 -0
- package/docs/templates/System/CONFIG.json +43 -0
- package/docs/templates/System/CONTEXT.md +352 -0
- package/docs/templates/codebase/architecture.md +255 -0
- package/docs/templates/codebase/concerns.md +310 -0
- package/docs/templates/codebase/conventions.md +307 -0
- package/docs/templates/codebase/integrations.md +280 -0
- package/docs/templates/codebase/stack.md +186 -0
- package/docs/templates/codebase/structure.md +285 -0
- package/docs/templates/codebase/testing.md +480 -0
- package/docs/templates/research/ARCHITECTURE.md +204 -0
- package/docs/templates/research/FEATURES.md +147 -0
- package/docs/templates/research/PITFALLS.md +200 -0
- package/docs/templates/research/STACK.md +120 -0
- package/docs/templates/research/SUMMARY.md +170 -0
- package/docs/user-guide.md +1 -1
- package/package.json +7 -2
- /package/docs/{reference → references}/audit-events.md +0 -0
- /package/docs/{reference → references}/config-reference.md +0 -0
- /package/docs/{reference → references}/sdk-api.md +0 -0
- /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
|
+
};
|