@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,744 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core — Shared utilities, constants, and internal helpers
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
const { getPlanningRoot, PROJECTS_DIR } = require('./paths.cjs');
|
|
9
|
+
|
|
10
|
+
// ─── Path helpers ────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/** Normalize a relative path to always use forward slashes (cross-platform). */
|
|
13
|
+
function toPosixPath(p) {
|
|
14
|
+
return p.split(path.sep).join('/');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ─── Model Profile Table ─────────────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
const MODEL_PROFILES = {
|
|
20
|
+
'dgs-planner': { quality: 'opus', balanced: 'opus', budget: 'sonnet' },
|
|
21
|
+
'dgs-roadmapper': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
|
|
22
|
+
'dgs-executor': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
|
|
23
|
+
'dgs-phase-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
|
|
24
|
+
'dgs-project-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
|
|
25
|
+
'dgs-research-synthesizer': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
|
|
26
|
+
'dgs-debugger': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
|
|
27
|
+
'dgs-codebase-mapper': { quality: 'sonnet', balanced: 'haiku', budget: 'haiku' },
|
|
28
|
+
'dgs-verifier': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
|
|
29
|
+
'dgs-plan-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
|
|
30
|
+
'dgs-integration-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ─── Output helpers ───────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
function output(result, raw, rawValue) {
|
|
36
|
+
if (raw && rawValue !== undefined) {
|
|
37
|
+
process.stdout.write(String(rawValue));
|
|
38
|
+
} else {
|
|
39
|
+
const json = JSON.stringify(result, null, 2);
|
|
40
|
+
// Large payloads exceed Claude Code's Bash tool buffer (~50KB).
|
|
41
|
+
// Write to tmpfile and output the path prefixed with @file: so callers can detect it.
|
|
42
|
+
if (json.length > 50000) {
|
|
43
|
+
const tmpPath = path.join(require('os').tmpdir(), `dgs-${Date.now()}.json`);
|
|
44
|
+
fs.writeFileSync(tmpPath, json, 'utf-8');
|
|
45
|
+
process.stdout.write('@file:' + tmpPath);
|
|
46
|
+
} else {
|
|
47
|
+
process.stdout.write(json);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function error(message) {
|
|
54
|
+
process.stderr.write('Error: ' + message + '\n');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ─── File & Config utilities ──────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
function safeReadFile(filePath) {
|
|
61
|
+
try {
|
|
62
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function loadConfig(cwd) {
|
|
69
|
+
const root = getPlanningRoot(cwd);
|
|
70
|
+
const newConfigPath = path.join(root, 'dgs.config.json');
|
|
71
|
+
const legacyConfigPath = path.join(root, 'config.json');
|
|
72
|
+
const configPath = fs.existsSync(newConfigPath) ? newConfigPath : legacyConfigPath;
|
|
73
|
+
const defaults = {
|
|
74
|
+
model_profile: 'balanced',
|
|
75
|
+
commit_docs: true,
|
|
76
|
+
search_gitignored: false,
|
|
77
|
+
branching_strategy: 'none',
|
|
78
|
+
phase_branch_template: 'dgs/{project}/phase-{phase}-{slug}',
|
|
79
|
+
milestone_branch_template: 'dgs/{project}/{milestone}-{slug}',
|
|
80
|
+
base_branch: 'main',
|
|
81
|
+
research: true,
|
|
82
|
+
plan_checker: true,
|
|
83
|
+
verifier: true,
|
|
84
|
+
parallelization: true,
|
|
85
|
+
brave_search: false,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
90
|
+
const parsed = JSON.parse(raw);
|
|
91
|
+
|
|
92
|
+
// Migrate deprecated "depth" key to "granularity" with value mapping
|
|
93
|
+
if ('depth' in parsed && !('granularity' in parsed)) {
|
|
94
|
+
const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
|
|
95
|
+
parsed.granularity = depthToGranularity[parsed.depth] || parsed.depth;
|
|
96
|
+
delete parsed.depth;
|
|
97
|
+
try { fs.writeFileSync(configPath, JSON.stringify(parsed, null, 2), 'utf-8'); } catch {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const get = (key, nested) => {
|
|
101
|
+
if (parsed[key] !== undefined) return parsed[key];
|
|
102
|
+
if (nested && parsed[nested.section] && parsed[nested.section][nested.field] !== undefined) {
|
|
103
|
+
return parsed[nested.section][nested.field];
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const parallelization = (() => {
|
|
109
|
+
const val = get('parallelization');
|
|
110
|
+
if (typeof val === 'boolean') return val;
|
|
111
|
+
if (typeof val === 'object' && val !== null && 'enabled' in val) return val.enabled;
|
|
112
|
+
return defaults.parallelization;
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
model_profile: get('model_profile') ?? defaults.model_profile,
|
|
117
|
+
commit_docs: get('commit_docs', { section: 'planning', field: 'commit_docs' }) ?? defaults.commit_docs,
|
|
118
|
+
search_gitignored: get('search_gitignored', { section: 'planning', field: 'search_gitignored' }) ?? defaults.search_gitignored,
|
|
119
|
+
branching_strategy: get('branching_strategy', { section: 'git', field: 'branching_strategy' }) ?? defaults.branching_strategy,
|
|
120
|
+
phase_branch_template: get('phase_branch_template', { section: 'git', field: 'phase_branch_template' }) ?? defaults.phase_branch_template,
|
|
121
|
+
milestone_branch_template: get('milestone_branch_template', { section: 'git', field: 'milestone_branch_template' }) ?? defaults.milestone_branch_template,
|
|
122
|
+
base_branch: get('base_branch', { section: 'git', field: 'base_branch' }) ?? defaults.base_branch,
|
|
123
|
+
research: get('research', { section: 'workflow', field: 'research' }) ?? defaults.research,
|
|
124
|
+
plan_checker: get('plan_checker', { section: 'workflow', field: 'plan_check' }) ?? defaults.plan_checker,
|
|
125
|
+
verifier: get('verifier', { section: 'workflow', field: 'verifier' }) ?? defaults.verifier,
|
|
126
|
+
parallelization,
|
|
127
|
+
brave_search: get('brave_search') ?? defaults.brave_search,
|
|
128
|
+
model_overrides: parsed.model_overrides || null,
|
|
129
|
+
// v2 fields — passed through directly from config
|
|
130
|
+
current_project: get('current_project') ?? null,
|
|
131
|
+
v2_hint_shown: get('v2_hint_shown') ?? false,
|
|
132
|
+
};
|
|
133
|
+
} catch {
|
|
134
|
+
return { ...defaults, current_project: null, v2_hint_shown: false };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ─── Git utilities ────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
function isGitIgnored(cwd, targetPath) {
|
|
141
|
+
try {
|
|
142
|
+
// --no-index checks .gitignore rules regardless of whether the file is tracked.
|
|
143
|
+
// Without it, git check-ignore returns "not ignored" for tracked files even when
|
|
144
|
+
// .gitignore explicitly lists them — a common source of confusion when .planning/
|
|
145
|
+
// was committed before being added to .gitignore.
|
|
146
|
+
execSync('git check-ignore -q --no-index -- ' + targetPath.replace(/[^a-zA-Z0-9._\-/]/g, ''), {
|
|
147
|
+
cwd,
|
|
148
|
+
stdio: 'pipe',
|
|
149
|
+
});
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function execGit(cwd, args) {
|
|
157
|
+
try {
|
|
158
|
+
const escaped = args.map(a => {
|
|
159
|
+
if (/^[a-zA-Z0-9._\-/=:@]+$/.test(a)) return a;
|
|
160
|
+
return "'" + a.replace(/'/g, "'\\''") + "'";
|
|
161
|
+
});
|
|
162
|
+
const stdout = execSync('git ' + escaped.join(' '), {
|
|
163
|
+
cwd,
|
|
164
|
+
stdio: 'pipe',
|
|
165
|
+
encoding: 'utf-8',
|
|
166
|
+
});
|
|
167
|
+
return { exitCode: 0, stdout: stdout.trim(), stderr: '' };
|
|
168
|
+
} catch (err) {
|
|
169
|
+
return {
|
|
170
|
+
exitCode: err.status ?? 1,
|
|
171
|
+
stdout: (err.stdout ?? '').toString().trim(),
|
|
172
|
+
stderr: (err.stderr ?? '').toString().trim(),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ─── Phase utilities ──────────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
function escapeRegex(value) {
|
|
180
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function normalizePhaseName(phase) {
|
|
184
|
+
const match = String(phase).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
|
|
185
|
+
if (!match) return phase;
|
|
186
|
+
const padded = match[1].padStart(2, '0');
|
|
187
|
+
const letter = match[2] ? match[2].toUpperCase() : '';
|
|
188
|
+
const decimal = match[3] || '';
|
|
189
|
+
return padded + letter + decimal;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function comparePhaseNum(a, b) {
|
|
193
|
+
const pa = String(a).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
|
|
194
|
+
const pb = String(b).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
|
|
195
|
+
if (!pa || !pb) return String(a).localeCompare(String(b));
|
|
196
|
+
const intDiff = parseInt(pa[1], 10) - parseInt(pb[1], 10);
|
|
197
|
+
if (intDiff !== 0) return intDiff;
|
|
198
|
+
// No letter sorts before letter: 12 < 12A < 12B
|
|
199
|
+
const la = (pa[2] || '').toUpperCase();
|
|
200
|
+
const lb = (pb[2] || '').toUpperCase();
|
|
201
|
+
if (la !== lb) {
|
|
202
|
+
if (!la) return -1;
|
|
203
|
+
if (!lb) return 1;
|
|
204
|
+
return la < lb ? -1 : 1;
|
|
205
|
+
}
|
|
206
|
+
// Segment-by-segment decimal comparison: 12A < 12A.1 < 12A.1.2 < 12A.2
|
|
207
|
+
const aDecParts = pa[3] ? pa[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
|
|
208
|
+
const bDecParts = pb[3] ? pb[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
|
|
209
|
+
const maxLen = Math.max(aDecParts.length, bDecParts.length);
|
|
210
|
+
if (aDecParts.length === 0 && bDecParts.length > 0) return -1;
|
|
211
|
+
if (bDecParts.length === 0 && aDecParts.length > 0) return 1;
|
|
212
|
+
for (let i = 0; i < maxLen; i++) {
|
|
213
|
+
const av = Number.isFinite(aDecParts[i]) ? aDecParts[i] : 0;
|
|
214
|
+
const bv = Number.isFinite(bDecParts[i]) ? bDecParts[i] : 0;
|
|
215
|
+
if (av !== bv) return av - bv;
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function searchPhaseInDir(baseDir, relBase, normalized) {
|
|
221
|
+
try {
|
|
222
|
+
const entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
223
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
|
|
224
|
+
const match = dirs.find(d => d.startsWith(normalized));
|
|
225
|
+
if (!match) return null;
|
|
226
|
+
|
|
227
|
+
const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
|
|
228
|
+
const phaseNumber = dirMatch ? dirMatch[1] : normalized;
|
|
229
|
+
const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
|
|
230
|
+
const phaseDir = path.join(baseDir, match);
|
|
231
|
+
const phaseFiles = fs.readdirSync(phaseDir);
|
|
232
|
+
|
|
233
|
+
const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
|
|
234
|
+
const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
|
|
235
|
+
const hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
|
|
236
|
+
const hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
|
|
237
|
+
const hasVerification = phaseFiles.some(f => f.endsWith('-VERIFICATION.md') || f === 'VERIFICATION.md');
|
|
238
|
+
|
|
239
|
+
const completedPlanIds = new Set(
|
|
240
|
+
summaries.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
|
|
241
|
+
);
|
|
242
|
+
const incompletePlans = plans.filter(p => {
|
|
243
|
+
const planId = p.replace('-PLAN.md', '').replace('PLAN.md', '');
|
|
244
|
+
return !completedPlanIds.has(planId);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
found: true,
|
|
249
|
+
directory: toPosixPath(path.join(relBase, match)),
|
|
250
|
+
phase_number: phaseNumber,
|
|
251
|
+
phase_name: phaseName,
|
|
252
|
+
phase_slug: phaseName ? phaseName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') : null,
|
|
253
|
+
plans,
|
|
254
|
+
summaries,
|
|
255
|
+
incomplete_plans: incompletePlans,
|
|
256
|
+
has_research: hasResearch,
|
|
257
|
+
has_context: hasContext,
|
|
258
|
+
has_verification: hasVerification,
|
|
259
|
+
};
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function findPhaseInternal(cwd, phase) {
|
|
266
|
+
if (!phase) return null;
|
|
267
|
+
|
|
268
|
+
const normalized = normalizePhaseName(phase);
|
|
269
|
+
|
|
270
|
+
// Resolve phases directory: v2 uses .planning/<project>/phases/, v1 uses .planning/phases/
|
|
271
|
+
let projectRoot;
|
|
272
|
+
try {
|
|
273
|
+
projectRoot = getProjectRoot(cwd);
|
|
274
|
+
} catch {
|
|
275
|
+
projectRoot = '.planning';
|
|
276
|
+
}
|
|
277
|
+
const phasesRel = path.join(projectRoot, 'phases');
|
|
278
|
+
const phasesDir = path.join(cwd, phasesRel);
|
|
279
|
+
|
|
280
|
+
// Search current phases first
|
|
281
|
+
const current = searchPhaseInDir(phasesDir, phasesRel, normalized);
|
|
282
|
+
if (current) return current;
|
|
283
|
+
|
|
284
|
+
// Search archived milestone phases (newest first)
|
|
285
|
+
// Archives are product-level, always under the planning root milestones/
|
|
286
|
+
const planRoot = getPlanningRoot(cwd);
|
|
287
|
+
const milestonesDir = path.join(planRoot, 'milestones');
|
|
288
|
+
if (!fs.existsSync(milestonesDir)) return null;
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
|
|
292
|
+
const archiveDirs = milestoneEntries
|
|
293
|
+
.filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
|
|
294
|
+
.map(e => e.name)
|
|
295
|
+
.sort()
|
|
296
|
+
.reverse();
|
|
297
|
+
|
|
298
|
+
const planRootRel = path.relative(cwd, planRoot);
|
|
299
|
+
for (const archiveName of archiveDirs) {
|
|
300
|
+
const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
|
|
301
|
+
const archivePath = path.join(milestonesDir, archiveName);
|
|
302
|
+
const relBase = path.join(planRootRel, 'milestones', archiveName);
|
|
303
|
+
const result = searchPhaseInDir(archivePath, relBase, normalized);
|
|
304
|
+
if (result) {
|
|
305
|
+
result.archived = version;
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
} catch {}
|
|
310
|
+
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function getArchivedPhaseDirs(cwd) {
|
|
315
|
+
const planRoot = getPlanningRoot(cwd);
|
|
316
|
+
const milestonesDir = path.join(planRoot, 'milestones');
|
|
317
|
+
const results = [];
|
|
318
|
+
|
|
319
|
+
if (!fs.existsSync(milestonesDir)) return results;
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
|
|
323
|
+
// Find v*-phases directories, sort newest first
|
|
324
|
+
const phaseDirs = milestoneEntries
|
|
325
|
+
.filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
|
|
326
|
+
.map(e => e.name)
|
|
327
|
+
.sort()
|
|
328
|
+
.reverse();
|
|
329
|
+
|
|
330
|
+
const planRootRel = path.relative(cwd, planRoot);
|
|
331
|
+
for (const archiveName of phaseDirs) {
|
|
332
|
+
const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
|
|
333
|
+
const archivePath = path.join(milestonesDir, archiveName);
|
|
334
|
+
const entries = fs.readdirSync(archivePath, { withFileTypes: true });
|
|
335
|
+
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
|
|
336
|
+
|
|
337
|
+
for (const dir of dirs) {
|
|
338
|
+
results.push({
|
|
339
|
+
name: dir,
|
|
340
|
+
milestone: version,
|
|
341
|
+
basePath: path.join(planRootRel, 'milestones', archiveName),
|
|
342
|
+
fullPath: path.join(archivePath, dir),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch {}
|
|
347
|
+
|
|
348
|
+
return results;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ─── Roadmap & model utilities ────────────────────────────────────────────────
|
|
352
|
+
|
|
353
|
+
function getRoadmapPhaseInternal(cwd, phaseNum) {
|
|
354
|
+
if (!phaseNum) return null;
|
|
355
|
+
// v2: look in project root (.planning/<project>/), v1: .planning/
|
|
356
|
+
let projectRoot;
|
|
357
|
+
try {
|
|
358
|
+
projectRoot = getProjectRoot(cwd);
|
|
359
|
+
} catch {
|
|
360
|
+
projectRoot = path.relative(cwd, getPlanningRoot(cwd)) || '.planning';
|
|
361
|
+
}
|
|
362
|
+
const roadmapPath = path.join(cwd, projectRoot, 'ROADMAP.md');
|
|
363
|
+
if (!fs.existsSync(roadmapPath)) return null;
|
|
364
|
+
|
|
365
|
+
try {
|
|
366
|
+
const content = fs.readFileSync(roadmapPath, 'utf-8');
|
|
367
|
+
const escapedPhase = escapeRegex(phaseNum.toString());
|
|
368
|
+
const phasePattern = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`, 'i');
|
|
369
|
+
const headerMatch = content.match(phasePattern);
|
|
370
|
+
|
|
371
|
+
// Fallback: match bold list-item format (- [ ] **Phase N: Name** - description)
|
|
372
|
+
const listPattern = new RegExp(`\\*\\*Phase\\s+${escapedPhase}:\\s*([^*]+)\\*\\*`, 'i');
|
|
373
|
+
const listMatch = !headerMatch ? content.match(listPattern) : null;
|
|
374
|
+
|
|
375
|
+
if (!headerMatch && !listMatch) return null;
|
|
376
|
+
|
|
377
|
+
let phaseName, section;
|
|
378
|
+
if (headerMatch) {
|
|
379
|
+
phaseName = headerMatch[1].trim();
|
|
380
|
+
const headerIndex = headerMatch.index;
|
|
381
|
+
const restOfContent = content.slice(headerIndex);
|
|
382
|
+
const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
|
|
383
|
+
const sectionEnd = nextHeaderMatch ? headerIndex + nextHeaderMatch.index : content.length;
|
|
384
|
+
section = content.slice(headerIndex, sectionEnd).trim();
|
|
385
|
+
} else {
|
|
386
|
+
phaseName = listMatch[1].trim();
|
|
387
|
+
const listIndex = listMatch.index;
|
|
388
|
+
const restOfContent = content.slice(listIndex);
|
|
389
|
+
const nextListMatch = restOfContent.match(/\n-\s+\[.\]\s+\*\*Phase\s+\d/i);
|
|
390
|
+
const sectionEnd = nextListMatch ? listIndex + nextListMatch.index : content.length;
|
|
391
|
+
section = content.slice(listIndex, sectionEnd).trim();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const goalMatch = section.match(/\*\*Goal:\*\*\s*([^\n]+)/i);
|
|
395
|
+
const goal = goalMatch ? goalMatch[1].trim() : null;
|
|
396
|
+
|
|
397
|
+
return {
|
|
398
|
+
found: true,
|
|
399
|
+
phase_number: phaseNum.toString(),
|
|
400
|
+
phase_name: phaseName,
|
|
401
|
+
goal,
|
|
402
|
+
section,
|
|
403
|
+
};
|
|
404
|
+
} catch {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function resolveModelInternal(cwd, agentType) {
|
|
410
|
+
const config = loadConfig(cwd);
|
|
411
|
+
|
|
412
|
+
// Check per-agent override first
|
|
413
|
+
const override = config.model_overrides?.[agentType];
|
|
414
|
+
if (override) {
|
|
415
|
+
return override === 'opus' ? 'inherit' : override;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Fall back to profile lookup
|
|
419
|
+
const profile = config.model_profile || 'balanced';
|
|
420
|
+
const agentModels = MODEL_PROFILES[agentType];
|
|
421
|
+
if (!agentModels) return 'sonnet';
|
|
422
|
+
const resolved = agentModels[profile] || agentModels['balanced'] || 'sonnet';
|
|
423
|
+
return resolved === 'opus' ? 'inherit' : resolved;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ─── Misc utilities ───────────────────────────────────────────────────────────
|
|
427
|
+
|
|
428
|
+
function pathExistsInternal(cwd, targetPath) {
|
|
429
|
+
const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
|
|
430
|
+
try {
|
|
431
|
+
fs.statSync(fullPath);
|
|
432
|
+
return true;
|
|
433
|
+
} catch {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function generateSlugInternal(text) {
|
|
439
|
+
if (!text) return null;
|
|
440
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function getMilestoneInfo(cwd) {
|
|
444
|
+
try {
|
|
445
|
+
const roadmap = fs.readFileSync(path.join(getPlanningRoot(cwd), 'ROADMAP.md'), 'utf-8');
|
|
446
|
+
|
|
447
|
+
// First: check for list-format roadmaps using 🚧 (in-progress) marker
|
|
448
|
+
// e.g. "- 🚧 **v2.1 Belgium** — Phases 24-28 (in progress)"
|
|
449
|
+
const inProgressMatch = roadmap.match(/🚧\s*\*\*v(\d+\.\d+)\s+([^*]+)\*\*/);
|
|
450
|
+
if (inProgressMatch) {
|
|
451
|
+
return {
|
|
452
|
+
version: 'v' + inProgressMatch[1],
|
|
453
|
+
name: inProgressMatch[2].trim(),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Second: heading-format roadmaps — strip shipped milestones in <details> blocks
|
|
458
|
+
const cleaned = roadmap.replace(/<details>[\s\S]*?<\/details>/gi, '');
|
|
459
|
+
// Extract version and name from the same ## heading for consistency
|
|
460
|
+
const headingMatch = cleaned.match(/## .*v(\d+\.\d+)[:\s]+([^\n(]+)/);
|
|
461
|
+
if (headingMatch) {
|
|
462
|
+
return {
|
|
463
|
+
version: 'v' + headingMatch[1],
|
|
464
|
+
name: headingMatch[2].trim(),
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
// Fallback: try bare version match
|
|
468
|
+
const versionMatch = cleaned.match(/v(\d+\.\d+)/);
|
|
469
|
+
return {
|
|
470
|
+
version: versionMatch ? versionMatch[0] : 'v1.0',
|
|
471
|
+
name: 'milestone',
|
|
472
|
+
};
|
|
473
|
+
} catch {
|
|
474
|
+
return { version: 'v1.0', name: 'milestone' };
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Returns a filter function that checks whether a phase directory belongs
|
|
480
|
+
* to the current milestone based on ROADMAP.md phase headings.
|
|
481
|
+
* If no ROADMAP exists or no phases are listed, returns a pass-all filter.
|
|
482
|
+
*/
|
|
483
|
+
function getMilestonePhaseFilter(cwd) {
|
|
484
|
+
const milestonePhaseNums = new Set();
|
|
485
|
+
try {
|
|
486
|
+
const roadmap = fs.readFileSync(path.join(getPlanningRoot(cwd), 'ROADMAP.md'), 'utf-8');
|
|
487
|
+
const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
|
|
488
|
+
let m;
|
|
489
|
+
while ((m = phasePattern.exec(roadmap)) !== null) {
|
|
490
|
+
milestonePhaseNums.add(m[1]);
|
|
491
|
+
}
|
|
492
|
+
} catch {}
|
|
493
|
+
|
|
494
|
+
if (milestonePhaseNums.size === 0) {
|
|
495
|
+
const passAll = () => true;
|
|
496
|
+
passAll.phaseCount = 0;
|
|
497
|
+
return passAll;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const normalized = new Set(
|
|
501
|
+
[...milestonePhaseNums].map(n => (n.replace(/^0+/, '') || '0').toLowerCase())
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
function isDirInMilestone(dirName) {
|
|
505
|
+
const m = dirName.match(/^0*(\d+[A-Za-z]?(?:\.\d+)*)/);
|
|
506
|
+
if (!m) return false;
|
|
507
|
+
return normalized.has(m[1].toLowerCase());
|
|
508
|
+
}
|
|
509
|
+
isDirInMilestone.phaseCount = milestonePhaseNums.size;
|
|
510
|
+
return isDirInMilestone;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// ─── v2 Path Resolution ──────────────────────────────────────────────────────
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* System directories that live under .planning/ but are NOT project folders.
|
|
517
|
+
* Kept as a safety net — getProjectFolders() now scans .planning/projects/ directly
|
|
518
|
+
* and no longer relies on this set for filtering. The 'projects' entry prevents
|
|
519
|
+
* the projects container directory itself from being mistaken for a project.
|
|
520
|
+
*/
|
|
521
|
+
const SYSTEM_DIRS = new Set([
|
|
522
|
+
'phases', 'codebase', 'archive', 'todos', 'quick',
|
|
523
|
+
'debug', 'milestones', 'research', PROJECTS_DIR,
|
|
524
|
+
]);
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Detect if this is a v2 (multi-project) installation.
|
|
528
|
+
* Requires both file existence AND valid DGS-generated content.
|
|
529
|
+
* PROJECTS.md must start with "# Projects", REPOS.md with "# Repos".
|
|
530
|
+
*
|
|
531
|
+
* @param {string} cwd - Working directory
|
|
532
|
+
* @returns {boolean}
|
|
533
|
+
*/
|
|
534
|
+
function isV2Install(cwd) {
|
|
535
|
+
const checks = [
|
|
536
|
+
{ file: 'PROJECTS.md', header: '# Projects' },
|
|
537
|
+
{ file: 'REPOS.md', header: '# Repos' },
|
|
538
|
+
];
|
|
539
|
+
const planRoot = getPlanningRoot(cwd);
|
|
540
|
+
for (const { file, header } of checks) {
|
|
541
|
+
const filePath = path.join(planRoot, file);
|
|
542
|
+
try {
|
|
543
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
544
|
+
if (content.startsWith(header)) return true;
|
|
545
|
+
} catch {
|
|
546
|
+
// File doesn't exist or unreadable — not a marker
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Construct the absolute path to a project directory.
|
|
554
|
+
*
|
|
555
|
+
* Single centralised helper — all project path construction should flow
|
|
556
|
+
* through this function to keep the 'projects' path segment in one place.
|
|
557
|
+
*
|
|
558
|
+
* @param {string} cwd - Working directory
|
|
559
|
+
* @param {string} slug - Project slug
|
|
560
|
+
* @returns {string} Absolute path to the project directory
|
|
561
|
+
*/
|
|
562
|
+
function getProjectDir(cwd, slug) {
|
|
563
|
+
return path.join(getPlanningRoot(cwd), PROJECTS_DIR, slug);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Get the project root directory (relative path).
|
|
568
|
+
* - v2 with current_project set: returns .planning/projects/<project>
|
|
569
|
+
* - v2 without current_project: throws Error('NO_CURRENT_PROJECT_V2')
|
|
570
|
+
* - v1 (no v2 markers): returns '.planning'
|
|
571
|
+
*
|
|
572
|
+
* @param {string} cwd - Working directory
|
|
573
|
+
* @returns {string} Relative path to project root
|
|
574
|
+
* @throws {Error} NO_CURRENT_PROJECT_V2 | PROJECT_NOT_FOUND | INVALID_PROJECT_NAME
|
|
575
|
+
*/
|
|
576
|
+
function getProjectRoot(cwd) {
|
|
577
|
+
const config = loadConfig(cwd);
|
|
578
|
+
const currentProject = (config.current_project || '').trim();
|
|
579
|
+
|
|
580
|
+
// Determine layout: root layout when planning root equals cwd
|
|
581
|
+
const planRoot = getPlanningRoot(cwd);
|
|
582
|
+
const isRootLayout = (planRoot === path.resolve(cwd));
|
|
583
|
+
const planRootRel = isRootLayout ? '.' : '.planning';
|
|
584
|
+
|
|
585
|
+
if (currentProject) {
|
|
586
|
+
// Validate project name — must be a simple slug, no path traversal
|
|
587
|
+
if (currentProject.includes('..') || currentProject.includes('/') || currentProject.includes('\\')) {
|
|
588
|
+
throw new Error('INVALID_PROJECT_NAME: ' + currentProject);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const projectDir = path.join(planRootRel, PROJECTS_DIR, currentProject);
|
|
592
|
+
|
|
593
|
+
// Validate directory exists on disk
|
|
594
|
+
if (!fs.existsSync(path.join(cwd, projectDir))) {
|
|
595
|
+
throw new Error('PROJECT_NOT_FOUND: ' + currentProject);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Validate project is not completed
|
|
599
|
+
if (isProjectCompleted(cwd, currentProject)) {
|
|
600
|
+
throw new Error('PROJECT_COMPLETED: ' + currentProject);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return projectDir;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// No current_project — check if this is a v2 install
|
|
607
|
+
if (isV2Install(cwd)) {
|
|
608
|
+
throw new Error('NO_CURRENT_PROJECT_V2');
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// v1 fallback — no v2 markers, return planning root relative path
|
|
612
|
+
return planRootRel;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Strict variant of getProjectRoot — signals that the caller MUST have a
|
|
617
|
+
* valid project root or the operation cannot proceed.
|
|
618
|
+
*
|
|
619
|
+
* Currently identical to getProjectRoot(), but exists as a distinct function
|
|
620
|
+
* for two reasons:
|
|
621
|
+
* (a) Call sites that MUST have a project root use requireProjectRoot,
|
|
622
|
+
* making the intent explicit in the code.
|
|
623
|
+
* (b) If getProjectRoot ever gains a silent fallback mode,
|
|
624
|
+
* requireProjectRoot remains strict.
|
|
625
|
+
*
|
|
626
|
+
* @param {string} cwd - Working directory
|
|
627
|
+
* @returns {string} Relative path to project root
|
|
628
|
+
* @throws {Error} NO_CURRENT_PROJECT_V2 | PROJECT_NOT_FOUND | INVALID_PROJECT_NAME
|
|
629
|
+
*/
|
|
630
|
+
function requireProjectRoot(cwd) {
|
|
631
|
+
return getProjectRoot(cwd);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Resolve a project-scoped relative path.
|
|
636
|
+
* e.g., resolveProjectPath(cwd, 'STATE.md') → '.planning/projects/auth-overhaul/STATE.md' (v2)
|
|
637
|
+
* resolveProjectPath(cwd, 'STATE.md') → '.planning/STATE.md' (v1)
|
|
638
|
+
* resolveProjectPath(cwd) → project root
|
|
639
|
+
*
|
|
640
|
+
* @param {string} cwd - Working directory
|
|
641
|
+
* @param {string} [relativePath] - Path relative to project root
|
|
642
|
+
* @returns {string} Resolved relative path
|
|
643
|
+
*/
|
|
644
|
+
function resolveProjectPath(cwd, relativePath) {
|
|
645
|
+
const root = requireProjectRoot(cwd);
|
|
646
|
+
return relativePath ? path.join(root, relativePath) : root;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Check if a project is completed by reading its STATE.md directly.
|
|
651
|
+
*
|
|
652
|
+
* This is intentionally lightweight — reads STATUS line from STATE.md using
|
|
653
|
+
* safeReadFile (already in core.cjs) to avoid circular dependency on projects.cjs.
|
|
654
|
+
* Reads from .planning/projects/<slug>/STATE.md.
|
|
655
|
+
*
|
|
656
|
+
* @param {string} cwd - Working directory
|
|
657
|
+
* @param {string} slug - Project slug
|
|
658
|
+
* @returns {boolean} true if project STATUS is "completed" (case-insensitive)
|
|
659
|
+
*/
|
|
660
|
+
function isProjectCompleted(cwd, slug) {
|
|
661
|
+
const statePath = path.join(getProjectDir(cwd, slug), 'STATE.md');
|
|
662
|
+
const content = safeReadFile(statePath);
|
|
663
|
+
if (!content) return false;
|
|
664
|
+
|
|
665
|
+
const statusMatch = content.match(/Status:\s*(.+)/i);
|
|
666
|
+
if (!statusMatch) return false;
|
|
667
|
+
|
|
668
|
+
return statusMatch[1].trim().toLowerCase() === 'completed';
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* List project folders in a v2 install.
|
|
673
|
+
* Scans .planning/projects/ directly and returns directories that:
|
|
674
|
+
* - Don't start with '.'
|
|
675
|
+
* - Contain a STATE.md file (qualifying marker for project folders)
|
|
676
|
+
*
|
|
677
|
+
* Returns empty array if the projects/ directory does not exist, for v1 installs, or on any error.
|
|
678
|
+
*
|
|
679
|
+
* @param {string} cwd - Working directory
|
|
680
|
+
* @returns {string[]} Sorted array of project folder names
|
|
681
|
+
*/
|
|
682
|
+
function getProjectFolders(cwd) {
|
|
683
|
+
const projectsDir = path.join(getPlanningRoot(cwd), PROJECTS_DIR);
|
|
684
|
+
|
|
685
|
+
try {
|
|
686
|
+
return fs.readdirSync(projectsDir, { withFileTypes: true })
|
|
687
|
+
.filter(e => e.isDirectory())
|
|
688
|
+
.filter(e => !e.name.startsWith('.'))
|
|
689
|
+
.filter(e => {
|
|
690
|
+
// Must contain STATE.md to qualify as a project
|
|
691
|
+
return fs.existsSync(path.join(projectsDir, e.name, 'STATE.md'));
|
|
692
|
+
})
|
|
693
|
+
.map(e => e.name)
|
|
694
|
+
.sort();
|
|
695
|
+
} catch {
|
|
696
|
+
return [];
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Get the one-time v2 availability hint for v1 users.
|
|
702
|
+
* Returns hint text if v2_hint_shown is not set in config.
|
|
703
|
+
* Returns null if hint has already been shown.
|
|
704
|
+
* Note: Caller is responsible for persisting v2_hint_shown: true after displaying.
|
|
705
|
+
*
|
|
706
|
+
* @param {string} _cwd - Working directory (unused, reserved for future)
|
|
707
|
+
* @param {Object} config - Parsed config object
|
|
708
|
+
* @returns {string|null}
|
|
709
|
+
*/
|
|
710
|
+
function getV2Hint(_cwd, config) {
|
|
711
|
+
if (config.v2_hint_shown) return null;
|
|
712
|
+
return 'DGS v2 multi-project support available. Run /dgs:init-product to upgrade.';
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
module.exports = {
|
|
716
|
+
MODEL_PROFILES,
|
|
717
|
+
output,
|
|
718
|
+
error,
|
|
719
|
+
safeReadFile,
|
|
720
|
+
loadConfig,
|
|
721
|
+
isGitIgnored,
|
|
722
|
+
execGit,
|
|
723
|
+
escapeRegex,
|
|
724
|
+
normalizePhaseName,
|
|
725
|
+
comparePhaseNum,
|
|
726
|
+
searchPhaseInDir,
|
|
727
|
+
findPhaseInternal,
|
|
728
|
+
getArchivedPhaseDirs,
|
|
729
|
+
getRoadmapPhaseInternal,
|
|
730
|
+
resolveModelInternal,
|
|
731
|
+
pathExistsInternal,
|
|
732
|
+
generateSlugInternal,
|
|
733
|
+
getMilestoneInfo,
|
|
734
|
+
getMilestonePhaseFilter,
|
|
735
|
+
toPosixPath,
|
|
736
|
+
resolveProjectPath,
|
|
737
|
+
getProjectRoot,
|
|
738
|
+
requireProjectRoot,
|
|
739
|
+
isV2Install,
|
|
740
|
+
getProjectFolders,
|
|
741
|
+
getV2Hint,
|
|
742
|
+
isProjectCompleted,
|
|
743
|
+
getProjectDir,
|
|
744
|
+
};
|