gsd-code-first 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja-JP.md +834 -0
- package/README.ko-KR.md +823 -0
- package/README.md +937 -0
- package/README.pt-BR.md +452 -0
- package/README.zh-CN.md +800 -0
- package/agents/gsd-advisor-researcher.md +104 -0
- package/agents/gsd-annotator.md +148 -0
- package/agents/gsd-arc-executor.md +537 -0
- package/agents/gsd-arc-planner.md +374 -0
- package/agents/gsd-assumptions-analyzer.md +105 -0
- package/agents/gsd-code-planner.md +155 -0
- package/agents/gsd-codebase-mapper.md +770 -0
- package/agents/gsd-debugger.md +1373 -0
- package/agents/gsd-executor.md +509 -0
- package/agents/gsd-integration-checker.md +443 -0
- package/agents/gsd-nyquist-auditor.md +176 -0
- package/agents/gsd-phase-researcher.md +698 -0
- package/agents/gsd-plan-checker.md +773 -0
- package/agents/gsd-planner.md +1354 -0
- package/agents/gsd-project-researcher.md +654 -0
- package/agents/gsd-prototyper.md +161 -0
- package/agents/gsd-research-synthesizer.md +247 -0
- package/agents/gsd-roadmapper.md +679 -0
- package/agents/gsd-ui-auditor.md +439 -0
- package/agents/gsd-ui-checker.md +300 -0
- package/agents/gsd-ui-researcher.md +357 -0
- package/agents/gsd-user-profiler.md +171 -0
- package/agents/gsd-verifier.md +700 -0
- package/bin/install.js +5009 -0
- package/commands/gsd/add-backlog.md +76 -0
- package/commands/gsd/add-phase.md +43 -0
- package/commands/gsd/add-tests.md +41 -0
- package/commands/gsd/add-todo.md +47 -0
- package/commands/gsd/annotate.md +54 -0
- package/commands/gsd/audit-milestone.md +36 -0
- package/commands/gsd/audit-uat.md +24 -0
- package/commands/gsd/autonomous.md +41 -0
- package/commands/gsd/check-todos.md +45 -0
- package/commands/gsd/cleanup.md +18 -0
- package/commands/gsd/complete-milestone.md +136 -0
- package/commands/gsd/debug.md +173 -0
- package/commands/gsd/deep-plan.md +52 -0
- package/commands/gsd/discuss-phase.md +64 -0
- package/commands/gsd/do.md +30 -0
- package/commands/gsd/execute-phase.md +59 -0
- package/commands/gsd/extract-plan.md +35 -0
- package/commands/gsd/fast.md +30 -0
- package/commands/gsd/forensics.md +56 -0
- package/commands/gsd/health.md +22 -0
- package/commands/gsd/help.md +22 -0
- package/commands/gsd/insert-phase.md +32 -0
- package/commands/gsd/iterate.md +124 -0
- package/commands/gsd/join-discord.md +18 -0
- package/commands/gsd/list-phase-assumptions.md +46 -0
- package/commands/gsd/list-workspaces.md +19 -0
- package/commands/gsd/manager.md +39 -0
- package/commands/gsd/map-codebase.md +71 -0
- package/commands/gsd/milestone-summary.md +51 -0
- package/commands/gsd/new-milestone.md +44 -0
- package/commands/gsd/new-project.md +42 -0
- package/commands/gsd/new-workspace.md +44 -0
- package/commands/gsd/next.md +24 -0
- package/commands/gsd/note.md +34 -0
- package/commands/gsd/pause-work.md +38 -0
- package/commands/gsd/plan-milestone-gaps.md +34 -0
- package/commands/gsd/plan-phase.md +47 -0
- package/commands/gsd/plant-seed.md +28 -0
- package/commands/gsd/pr-branch.md +25 -0
- package/commands/gsd/profile-user.md +46 -0
- package/commands/gsd/progress.md +24 -0
- package/commands/gsd/prototype.md +56 -0
- package/commands/gsd/quick.md +47 -0
- package/commands/gsd/reapply-patches.md +123 -0
- package/commands/gsd/remove-phase.md +31 -0
- package/commands/gsd/remove-workspace.md +26 -0
- package/commands/gsd/research-phase.md +195 -0
- package/commands/gsd/resume-work.md +40 -0
- package/commands/gsd/review-backlog.md +61 -0
- package/commands/gsd/review.md +37 -0
- package/commands/gsd/session-report.md +19 -0
- package/commands/gsd/set-mode.md +41 -0
- package/commands/gsd/set-profile.md +12 -0
- package/commands/gsd/settings.md +36 -0
- package/commands/gsd/ship.md +23 -0
- package/commands/gsd/stats.md +18 -0
- package/commands/gsd/thread.md +127 -0
- package/commands/gsd/ui-phase.md +34 -0
- package/commands/gsd/ui-review.md +32 -0
- package/commands/gsd/update.md +37 -0
- package/commands/gsd/validate-phase.md +35 -0
- package/commands/gsd/verify-work.md +38 -0
- package/commands/gsd/workstreams.md +63 -0
- package/get-shit-done/bin/gsd-tools.cjs +946 -0
- package/get-shit-done/bin/lib/arc-scanner.cjs +341 -0
- package/get-shit-done/bin/lib/commands.cjs +959 -0
- package/get-shit-done/bin/lib/config.cjs +466 -0
- package/get-shit-done/bin/lib/core.cjs +1230 -0
- package/get-shit-done/bin/lib/frontmatter.cjs +336 -0
- package/get-shit-done/bin/lib/init.cjs +1442 -0
- package/get-shit-done/bin/lib/milestone.cjs +252 -0
- package/get-shit-done/bin/lib/model-profiles.cjs +68 -0
- package/get-shit-done/bin/lib/phase.cjs +888 -0
- package/get-shit-done/bin/lib/profile-output.cjs +952 -0
- package/get-shit-done/bin/lib/profile-pipeline.cjs +539 -0
- package/get-shit-done/bin/lib/roadmap.cjs +329 -0
- package/get-shit-done/bin/lib/security.cjs +382 -0
- package/get-shit-done/bin/lib/state.cjs +1031 -0
- package/get-shit-done/bin/lib/template.cjs +222 -0
- package/get-shit-done/bin/lib/uat.cjs +282 -0
- package/get-shit-done/bin/lib/verify.cjs +888 -0
- package/get-shit-done/bin/lib/workstream.cjs +491 -0
- package/get-shit-done/commands/gsd/workstreams.md +63 -0
- package/get-shit-done/references/arc-standard.md +315 -0
- package/get-shit-done/references/checkpoints.md +778 -0
- package/get-shit-done/references/continuation-format.md +249 -0
- package/get-shit-done/references/decimal-phase-calculation.md +64 -0
- package/get-shit-done/references/git-integration.md +295 -0
- package/get-shit-done/references/git-planning-commit.md +38 -0
- package/get-shit-done/references/model-profile-resolution.md +36 -0
- package/get-shit-done/references/model-profiles.md +139 -0
- package/get-shit-done/references/phase-argument-parsing.md +61 -0
- package/get-shit-done/references/planning-config.md +202 -0
- package/get-shit-done/references/questioning.md +162 -0
- package/get-shit-done/references/tdd.md +263 -0
- package/get-shit-done/references/ui-brand.md +160 -0
- package/get-shit-done/references/user-profiling.md +681 -0
- package/get-shit-done/references/verification-patterns.md +612 -0
- package/get-shit-done/references/workstream-flag.md +58 -0
- package/get-shit-done/templates/DEBUG.md +164 -0
- package/get-shit-done/templates/UAT.md +265 -0
- package/get-shit-done/templates/UI-SPEC.md +100 -0
- package/get-shit-done/templates/VALIDATION.md +76 -0
- package/get-shit-done/templates/claude-md.md +122 -0
- package/get-shit-done/templates/codebase/architecture.md +255 -0
- package/get-shit-done/templates/codebase/concerns.md +310 -0
- package/get-shit-done/templates/codebase/conventions.md +307 -0
- package/get-shit-done/templates/codebase/integrations.md +280 -0
- package/get-shit-done/templates/codebase/stack.md +186 -0
- package/get-shit-done/templates/codebase/structure.md +285 -0
- package/get-shit-done/templates/codebase/testing.md +480 -0
- package/get-shit-done/templates/config.json +44 -0
- package/get-shit-done/templates/context.md +352 -0
- package/get-shit-done/templates/continue-here.md +78 -0
- package/get-shit-done/templates/copilot-instructions.md +7 -0
- package/get-shit-done/templates/debug-subagent-prompt.md +91 -0
- package/get-shit-done/templates/dev-preferences.md +21 -0
- package/get-shit-done/templates/discovery.md +146 -0
- package/get-shit-done/templates/discussion-log.md +63 -0
- package/get-shit-done/templates/milestone-archive.md +123 -0
- package/get-shit-done/templates/milestone.md +115 -0
- package/get-shit-done/templates/phase-prompt.md +610 -0
- package/get-shit-done/templates/planner-subagent-prompt.md +117 -0
- package/get-shit-done/templates/project.md +186 -0
- package/get-shit-done/templates/requirements.md +231 -0
- package/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
- package/get-shit-done/templates/research-project/FEATURES.md +147 -0
- package/get-shit-done/templates/research-project/PITFALLS.md +200 -0
- package/get-shit-done/templates/research-project/STACK.md +120 -0
- package/get-shit-done/templates/research-project/SUMMARY.md +170 -0
- package/get-shit-done/templates/research.md +552 -0
- package/get-shit-done/templates/retrospective.md +54 -0
- package/get-shit-done/templates/roadmap.md +202 -0
- package/get-shit-done/templates/state.md +176 -0
- package/get-shit-done/templates/summary-complex.md +59 -0
- package/get-shit-done/templates/summary-minimal.md +41 -0
- package/get-shit-done/templates/summary-standard.md +48 -0
- package/get-shit-done/templates/summary.md +248 -0
- package/get-shit-done/templates/user-profile.md +146 -0
- package/get-shit-done/templates/user-setup.md +311 -0
- package/get-shit-done/templates/verification-report.md +322 -0
- package/get-shit-done/workflows/add-phase.md +112 -0
- package/get-shit-done/workflows/add-tests.md +351 -0
- package/get-shit-done/workflows/add-todo.md +158 -0
- package/get-shit-done/workflows/audit-milestone.md +340 -0
- package/get-shit-done/workflows/audit-uat.md +109 -0
- package/get-shit-done/workflows/autonomous.md +891 -0
- package/get-shit-done/workflows/check-todos.md +177 -0
- package/get-shit-done/workflows/cleanup.md +152 -0
- package/get-shit-done/workflows/complete-milestone.md +767 -0
- package/get-shit-done/workflows/diagnose-issues.md +231 -0
- package/get-shit-done/workflows/discovery-phase.md +289 -0
- package/get-shit-done/workflows/discuss-phase-assumptions.md +653 -0
- package/get-shit-done/workflows/discuss-phase.md +1049 -0
- package/get-shit-done/workflows/do.md +104 -0
- package/get-shit-done/workflows/execute-phase.md +846 -0
- package/get-shit-done/workflows/execute-plan.md +514 -0
- package/get-shit-done/workflows/fast.md +105 -0
- package/get-shit-done/workflows/forensics.md +265 -0
- package/get-shit-done/workflows/health.md +181 -0
- package/get-shit-done/workflows/help.md +634 -0
- package/get-shit-done/workflows/insert-phase.md +130 -0
- package/get-shit-done/workflows/list-phase-assumptions.md +178 -0
- package/get-shit-done/workflows/list-workspaces.md +56 -0
- package/get-shit-done/workflows/manager.md +362 -0
- package/get-shit-done/workflows/map-codebase.md +377 -0
- package/get-shit-done/workflows/milestone-summary.md +223 -0
- package/get-shit-done/workflows/new-milestone.md +486 -0
- package/get-shit-done/workflows/new-project.md +1250 -0
- package/get-shit-done/workflows/new-workspace.md +237 -0
- package/get-shit-done/workflows/next.md +97 -0
- package/get-shit-done/workflows/node-repair.md +92 -0
- package/get-shit-done/workflows/note.md +156 -0
- package/get-shit-done/workflows/pause-work.md +176 -0
- package/get-shit-done/workflows/plan-milestone-gaps.md +273 -0
- package/get-shit-done/workflows/plan-phase.md +859 -0
- package/get-shit-done/workflows/plant-seed.md +169 -0
- package/get-shit-done/workflows/pr-branch.md +129 -0
- package/get-shit-done/workflows/profile-user.md +450 -0
- package/get-shit-done/workflows/progress.md +507 -0
- package/get-shit-done/workflows/quick.md +757 -0
- package/get-shit-done/workflows/remove-phase.md +155 -0
- package/get-shit-done/workflows/remove-workspace.md +90 -0
- package/get-shit-done/workflows/research-phase.md +82 -0
- package/get-shit-done/workflows/resume-project.md +326 -0
- package/get-shit-done/workflows/review.md +228 -0
- package/get-shit-done/workflows/session-report.md +146 -0
- package/get-shit-done/workflows/settings.md +283 -0
- package/get-shit-done/workflows/ship.md +228 -0
- package/get-shit-done/workflows/stats.md +60 -0
- package/get-shit-done/workflows/transition.md +671 -0
- package/get-shit-done/workflows/ui-phase.md +302 -0
- package/get-shit-done/workflows/ui-review.md +165 -0
- package/get-shit-done/workflows/update.md +323 -0
- package/get-shit-done/workflows/validate-phase.md +174 -0
- package/get-shit-done/workflows/verify-phase.md +254 -0
- package/get-shit-done/workflows/verify-work.md +637 -0
- package/hooks/dist/gsd-check-update.js +114 -0
- package/hooks/dist/gsd-context-monitor.js +156 -0
- package/hooks/dist/gsd-prompt-guard.js +96 -0
- package/hooks/dist/gsd-statusline.js +119 -0
- package/hooks/dist/gsd-workflow-guard.js +94 -0
- package/package.json +52 -0
- package/scripts/base64-scan.sh +262 -0
- package/scripts/build-hooks.js +82 -0
- package/scripts/prompt-injection-scan.sh +198 -0
- package/scripts/run-tests.cjs +29 -0
- package/scripts/secret-scan.sh +227 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config — Planning config CRUD operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { output, error, planningRoot } = require('./core.cjs');
|
|
8
|
+
const {
|
|
9
|
+
VALID_PROFILES,
|
|
10
|
+
getAgentToModelMapForProfile,
|
|
11
|
+
formatAgentToModelMapAsTable,
|
|
12
|
+
} = require('./model-profiles.cjs');
|
|
13
|
+
|
|
14
|
+
const VALID_CONFIG_KEYS = new Set([
|
|
15
|
+
'mode', 'granularity', 'parallelization', 'commit_docs', 'model_profile',
|
|
16
|
+
'search_gitignored', 'brave_search', 'firecrawl', 'exa_search',
|
|
17
|
+
'workflow.research', 'workflow.plan_check', 'workflow.verifier',
|
|
18
|
+
'workflow.nyquist_validation', 'workflow.ui_phase', 'workflow.ui_safety_gate',
|
|
19
|
+
'workflow.auto_advance', 'workflow.node_repair', 'workflow.node_repair_budget',
|
|
20
|
+
'workflow.text_mode',
|
|
21
|
+
'workflow.research_before_questions',
|
|
22
|
+
'workflow.discuss_mode',
|
|
23
|
+
'workflow.skip_discuss',
|
|
24
|
+
'workflow._auto_chain_active',
|
|
25
|
+
'git.branching_strategy', 'git.phase_branch_template', 'git.milestone_branch_template', 'git.quick_branch_template',
|
|
26
|
+
'planning.commit_docs', 'planning.search_gitignored',
|
|
27
|
+
'hooks.context_warnings',
|
|
28
|
+
'arc.enabled', 'arc.tag_prefix', 'arc.comment_anchors',
|
|
29
|
+
'phase_modes.default', 'default_phase_mode',
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Check whether a config key path is valid.
|
|
34
|
+
* Supports exact matches from VALID_CONFIG_KEYS plus dynamic patterns
|
|
35
|
+
* like `agent_skills.<agent-type>` where the sub-key is freeform.
|
|
36
|
+
*/
|
|
37
|
+
function isValidConfigKey(keyPath) {
|
|
38
|
+
if (VALID_CONFIG_KEYS.has(keyPath)) return true;
|
|
39
|
+
// Allow agent_skills.<agent-type> with any agent type string
|
|
40
|
+
if (/^agent_skills\.[a-zA-Z0-9_-]+$/.test(keyPath)) return true;
|
|
41
|
+
// Allow phase_modes.<number> for per-phase mode overrides
|
|
42
|
+
if (/^phase_modes\.\d+$/.test(keyPath)) return true;
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const CONFIG_KEY_SUGGESTIONS = {
|
|
47
|
+
'workflow.nyquist_validation_enabled': 'workflow.nyquist_validation',
|
|
48
|
+
'agents.nyquist_validation_enabled': 'workflow.nyquist_validation',
|
|
49
|
+
'nyquist.validation_enabled': 'workflow.nyquist_validation',
|
|
50
|
+
'hooks.research_questions': 'workflow.research_before_questions',
|
|
51
|
+
'workflow.research_questions': 'workflow.research_before_questions',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function validateKnownConfigKeyPath(keyPath) {
|
|
55
|
+
const suggested = CONFIG_KEY_SUGGESTIONS[keyPath];
|
|
56
|
+
if (suggested) {
|
|
57
|
+
error(`Unknown config key: ${keyPath}. Did you mean ${suggested}?`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build a fully-materialized config object for a new project.
|
|
63
|
+
*
|
|
64
|
+
* Merges (increasing priority):
|
|
65
|
+
* 1. Hardcoded defaults — every key that loadConfig() resolves, plus mode/granularity
|
|
66
|
+
* 2. User-level defaults from ~/.gsd/defaults.json (if present)
|
|
67
|
+
* 3. userChoices — the settings the user explicitly selected during /gsd:new-project
|
|
68
|
+
*
|
|
69
|
+
* Uses the canonical `git` namespace for branching keys (consistent with VALID_CONFIG_KEYS
|
|
70
|
+
* and the settings workflow). loadConfig() handles both flat and nested formats, so this
|
|
71
|
+
* is backward-compatible with existing projects that have flat keys.
|
|
72
|
+
*
|
|
73
|
+
* Returns a plain object — does NOT write any files.
|
|
74
|
+
*/
|
|
75
|
+
function buildNewProjectConfig(userChoices) {
|
|
76
|
+
const choices = userChoices || {};
|
|
77
|
+
const homedir = require('os').homedir();
|
|
78
|
+
|
|
79
|
+
// Detect API key availability
|
|
80
|
+
const braveKeyFile = path.join(homedir, '.gsd', 'brave_api_key');
|
|
81
|
+
const hasBraveSearch = !!(process.env.BRAVE_API_KEY || fs.existsSync(braveKeyFile));
|
|
82
|
+
const firecrawlKeyFile = path.join(homedir, '.gsd', 'firecrawl_api_key');
|
|
83
|
+
const hasFirecrawl = !!(process.env.FIRECRAWL_API_KEY || fs.existsSync(firecrawlKeyFile));
|
|
84
|
+
const exaKeyFile = path.join(homedir, '.gsd', 'exa_api_key');
|
|
85
|
+
const hasExaSearch = !!(process.env.EXA_API_KEY || fs.existsSync(exaKeyFile));
|
|
86
|
+
|
|
87
|
+
// Load user-level defaults from ~/.gsd/defaults.json if available
|
|
88
|
+
const globalDefaultsPath = path.join(homedir, '.gsd', 'defaults.json');
|
|
89
|
+
let userDefaults = {};
|
|
90
|
+
try {
|
|
91
|
+
if (fs.existsSync(globalDefaultsPath)) {
|
|
92
|
+
userDefaults = JSON.parse(fs.readFileSync(globalDefaultsPath, 'utf-8'));
|
|
93
|
+
// Migrate deprecated "depth" key to "granularity"
|
|
94
|
+
if ('depth' in userDefaults && !('granularity' in userDefaults)) {
|
|
95
|
+
const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
|
|
96
|
+
userDefaults.granularity = depthToGranularity[userDefaults.depth] || userDefaults.depth;
|
|
97
|
+
delete userDefaults.depth;
|
|
98
|
+
try {
|
|
99
|
+
fs.writeFileSync(globalDefaultsPath, JSON.stringify(userDefaults, null, 2), 'utf-8');
|
|
100
|
+
} catch { /* intentionally empty */ }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
// Ignore malformed global defaults
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const hardcoded = {
|
|
108
|
+
model_profile: 'balanced',
|
|
109
|
+
commit_docs: true,
|
|
110
|
+
parallelization: true,
|
|
111
|
+
search_gitignored: false,
|
|
112
|
+
brave_search: hasBraveSearch,
|
|
113
|
+
firecrawl: hasFirecrawl,
|
|
114
|
+
exa_search: hasExaSearch,
|
|
115
|
+
git: {
|
|
116
|
+
branching_strategy: 'none',
|
|
117
|
+
phase_branch_template: 'gsd/phase-{phase}-{slug}',
|
|
118
|
+
milestone_branch_template: 'gsd/{milestone}-{slug}',
|
|
119
|
+
quick_branch_template: null,
|
|
120
|
+
},
|
|
121
|
+
workflow: {
|
|
122
|
+
research: true,
|
|
123
|
+
plan_check: true,
|
|
124
|
+
verifier: true,
|
|
125
|
+
nyquist_validation: true,
|
|
126
|
+
auto_advance: false,
|
|
127
|
+
node_repair: true,
|
|
128
|
+
node_repair_budget: 2,
|
|
129
|
+
ui_phase: true,
|
|
130
|
+
ui_safety_gate: true,
|
|
131
|
+
text_mode: false,
|
|
132
|
+
research_before_questions: false,
|
|
133
|
+
discuss_mode: 'discuss',
|
|
134
|
+
skip_discuss: false,
|
|
135
|
+
},
|
|
136
|
+
hooks: {
|
|
137
|
+
context_warnings: true,
|
|
138
|
+
},
|
|
139
|
+
agent_skills: {},
|
|
140
|
+
arc: {
|
|
141
|
+
enabled: true,
|
|
142
|
+
tag_prefix: '@gsd-',
|
|
143
|
+
comment_anchors: ['//', '#', '/*', '--'],
|
|
144
|
+
},
|
|
145
|
+
phase_modes: {},
|
|
146
|
+
default_phase_mode: 'plan-first',
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Three-level deep merge: hardcoded <- userDefaults <- choices
|
|
150
|
+
return {
|
|
151
|
+
...hardcoded,
|
|
152
|
+
...userDefaults,
|
|
153
|
+
...choices,
|
|
154
|
+
git: {
|
|
155
|
+
...hardcoded.git,
|
|
156
|
+
...(userDefaults.git || {}),
|
|
157
|
+
...(choices.git || {}),
|
|
158
|
+
},
|
|
159
|
+
workflow: {
|
|
160
|
+
...hardcoded.workflow,
|
|
161
|
+
...(userDefaults.workflow || {}),
|
|
162
|
+
...(choices.workflow || {}),
|
|
163
|
+
},
|
|
164
|
+
hooks: {
|
|
165
|
+
...hardcoded.hooks,
|
|
166
|
+
...(userDefaults.hooks || {}),
|
|
167
|
+
...(choices.hooks || {}),
|
|
168
|
+
},
|
|
169
|
+
agent_skills: {
|
|
170
|
+
...hardcoded.agent_skills,
|
|
171
|
+
...(userDefaults.agent_skills || {}),
|
|
172
|
+
...(choices.agent_skills || {}),
|
|
173
|
+
},
|
|
174
|
+
arc: {
|
|
175
|
+
...hardcoded.arc,
|
|
176
|
+
...(userDefaults.arc || {}),
|
|
177
|
+
...(choices.arc || {}),
|
|
178
|
+
},
|
|
179
|
+
phase_modes: {
|
|
180
|
+
...hardcoded.phase_modes,
|
|
181
|
+
...(userDefaults.phase_modes || {}),
|
|
182
|
+
...(choices.phase_modes || {}),
|
|
183
|
+
},
|
|
184
|
+
default_phase_mode: choices.default_phase_mode || userDefaults.default_phase_mode || hardcoded.default_phase_mode,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Command: create a fully-materialized .planning/config.json for a new project.
|
|
190
|
+
*
|
|
191
|
+
* Accepts user-chosen settings as a JSON string (the keys the user explicitly
|
|
192
|
+
* configured during /gsd:new-project). All remaining keys are filled from
|
|
193
|
+
* hardcoded defaults and optional ~/.gsd/defaults.json.
|
|
194
|
+
*
|
|
195
|
+
* Idempotent: if config.json already exists, returns { created: false }.
|
|
196
|
+
*/
|
|
197
|
+
function cmdConfigNewProject(cwd, choicesJson, raw) {
|
|
198
|
+
const planningBase = planningRoot(cwd);
|
|
199
|
+
const configPath = path.join(planningBase, 'config.json');
|
|
200
|
+
|
|
201
|
+
// Idempotent: don't overwrite existing config
|
|
202
|
+
if (fs.existsSync(configPath)) {
|
|
203
|
+
output({ created: false, reason: 'already_exists' }, raw, 'exists');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Parse user choices
|
|
208
|
+
let userChoices = {};
|
|
209
|
+
if (choicesJson && choicesJson.trim() !== '') {
|
|
210
|
+
try {
|
|
211
|
+
userChoices = JSON.parse(choicesJson);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
error('Invalid JSON for config-new-project: ' + err.message);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Ensure .planning directory exists
|
|
218
|
+
try {
|
|
219
|
+
if (!fs.existsSync(planningBase)) {
|
|
220
|
+
fs.mkdirSync(planningBase, { recursive: true });
|
|
221
|
+
}
|
|
222
|
+
} catch (err) {
|
|
223
|
+
error('Failed to create .planning directory: ' + err.message);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const config = buildNewProjectConfig(userChoices);
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
230
|
+
output({ created: true, path: '.planning/config.json' }, raw, 'created');
|
|
231
|
+
} catch (err) {
|
|
232
|
+
error('Failed to write config.json: ' + err.message);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Ensures the config file exists (creates it if needed).
|
|
238
|
+
*
|
|
239
|
+
* Does not call `output()`, so can be used as one step in a command without triggering `exit(0)` in
|
|
240
|
+
* the happy path. But note that `error()` will still `exit(1)` out of the process.
|
|
241
|
+
*/
|
|
242
|
+
function ensureConfigFile(cwd) {
|
|
243
|
+
const planningBase = planningRoot(cwd);
|
|
244
|
+
const configPath = path.join(planningBase, 'config.json');
|
|
245
|
+
|
|
246
|
+
// Ensure .planning directory exists
|
|
247
|
+
try {
|
|
248
|
+
if (!fs.existsSync(planningBase)) {
|
|
249
|
+
fs.mkdirSync(planningBase, { recursive: true });
|
|
250
|
+
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
error('Failed to create .planning directory: ' + err.message);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Check if config already exists
|
|
256
|
+
if (fs.existsSync(configPath)) {
|
|
257
|
+
return { created: false, reason: 'already_exists' };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const config = buildNewProjectConfig({});
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
264
|
+
return { created: true, path: '.planning/config.json' };
|
|
265
|
+
} catch (err) {
|
|
266
|
+
error('Failed to create config.json: ' + err.message);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Command to ensure the config file exists (creates it if needed).
|
|
272
|
+
*
|
|
273
|
+
* Note that this exits the process (via `output()`) even in the happy path; use
|
|
274
|
+
* `ensureConfigFile()` directly if you need to avoid this.
|
|
275
|
+
*/
|
|
276
|
+
function cmdConfigEnsureSection(cwd, raw) {
|
|
277
|
+
const ensureConfigFileResult = ensureConfigFile(cwd);
|
|
278
|
+
if (ensureConfigFileResult.created) {
|
|
279
|
+
output(ensureConfigFileResult, raw, 'created');
|
|
280
|
+
} else {
|
|
281
|
+
output(ensureConfigFileResult, raw, 'exists');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Sets a value in the config file, allowing nested values via dot notation (e.g.,
|
|
287
|
+
* "workflow.research").
|
|
288
|
+
*
|
|
289
|
+
* Does not call `output()`, so can be used as one step in a command without triggering `exit(0)` in
|
|
290
|
+
* the happy path. But note that `error()` will still `exit(1)` out of the process.
|
|
291
|
+
*/
|
|
292
|
+
function setConfigValue(cwd, keyPath, parsedValue) {
|
|
293
|
+
const configPath = path.join(planningRoot(cwd), 'config.json');
|
|
294
|
+
|
|
295
|
+
// Load existing config or start with empty object
|
|
296
|
+
let config = {};
|
|
297
|
+
try {
|
|
298
|
+
if (fs.existsSync(configPath)) {
|
|
299
|
+
config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
error('Failed to read config.json: ' + err.message);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Set nested value using dot notation (e.g., "workflow.research")
|
|
306
|
+
const keys = keyPath.split('.');
|
|
307
|
+
let current = config;
|
|
308
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
309
|
+
const key = keys[i];
|
|
310
|
+
if (current[key] === undefined || typeof current[key] !== 'object') {
|
|
311
|
+
current[key] = {};
|
|
312
|
+
}
|
|
313
|
+
current = current[key];
|
|
314
|
+
}
|
|
315
|
+
const previousValue = current[keys[keys.length - 1]]; // Capture previous value before overwriting
|
|
316
|
+
current[keys[keys.length - 1]] = parsedValue;
|
|
317
|
+
|
|
318
|
+
// Write back
|
|
319
|
+
try {
|
|
320
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
321
|
+
return { updated: true, key: keyPath, value: parsedValue, previousValue };
|
|
322
|
+
} catch (err) {
|
|
323
|
+
error('Failed to write config.json: ' + err.message);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Command to set a value in the config file, allowing nested values via dot notation (e.g.,
|
|
329
|
+
* "workflow.research").
|
|
330
|
+
*
|
|
331
|
+
* Note that this exits the process (via `output()`) even in the happy path; use `setConfigValue()`
|
|
332
|
+
* directly if you need to avoid this.
|
|
333
|
+
*/
|
|
334
|
+
function cmdConfigSet(cwd, keyPath, value, raw) {
|
|
335
|
+
if (!keyPath) {
|
|
336
|
+
error('Usage: config-set <key.path> <value>');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
validateKnownConfigKeyPath(keyPath);
|
|
340
|
+
|
|
341
|
+
if (!isValidConfigKey(keyPath)) {
|
|
342
|
+
error(`Unknown config key: "${keyPath}". Valid keys: ${[...VALID_CONFIG_KEYS].sort().join(', ')}, agent_skills.<agent-type>`);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Parse value (handle booleans, numbers, and JSON arrays/objects)
|
|
346
|
+
let parsedValue = value;
|
|
347
|
+
if (value === 'true') parsedValue = true;
|
|
348
|
+
else if (value === 'false') parsedValue = false;
|
|
349
|
+
else if (!isNaN(value) && value !== '') parsedValue = Number(value);
|
|
350
|
+
else if (typeof value === 'string' && (value.startsWith('[') || value.startsWith('{'))) {
|
|
351
|
+
try { parsedValue = JSON.parse(value); } catch { /* keep as string */ }
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const setConfigValueResult = setConfigValue(cwd, keyPath, parsedValue);
|
|
355
|
+
output(setConfigValueResult, raw, `${keyPath}=${parsedValue}`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function cmdConfigGet(cwd, keyPath, raw) {
|
|
359
|
+
const configPath = path.join(planningRoot(cwd), 'config.json');
|
|
360
|
+
|
|
361
|
+
if (!keyPath) {
|
|
362
|
+
error('Usage: config-get <key.path>');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
let config = {};
|
|
366
|
+
try {
|
|
367
|
+
if (fs.existsSync(configPath)) {
|
|
368
|
+
config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
369
|
+
} else {
|
|
370
|
+
error('No config.json found at ' + configPath);
|
|
371
|
+
}
|
|
372
|
+
} catch (err) {
|
|
373
|
+
if (err.message.startsWith('No config.json')) throw err;
|
|
374
|
+
error('Failed to read config.json: ' + err.message);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Traverse dot-notation path (e.g., "workflow.auto_advance")
|
|
378
|
+
const keys = keyPath.split('.');
|
|
379
|
+
let current = config;
|
|
380
|
+
for (const key of keys) {
|
|
381
|
+
if (current === undefined || current === null || typeof current !== 'object') {
|
|
382
|
+
error(`Key not found: ${keyPath}`);
|
|
383
|
+
}
|
|
384
|
+
current = current[key];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (current === undefined) {
|
|
388
|
+
error(`Key not found: ${keyPath}`);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
output(current, raw, String(current));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Command to set the model profile in the config file.
|
|
396
|
+
*
|
|
397
|
+
* Note that this exits the process (via `output()`) even in the happy path.
|
|
398
|
+
*/
|
|
399
|
+
function cmdConfigSetModelProfile(cwd, profile, raw) {
|
|
400
|
+
if (!profile) {
|
|
401
|
+
error(`Usage: config-set-model-profile <${VALID_PROFILES.join('|')}>`);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const normalizedProfile = profile.toLowerCase().trim();
|
|
405
|
+
if (!VALID_PROFILES.includes(normalizedProfile)) {
|
|
406
|
+
error(`Invalid profile '${profile}'. Valid profiles: ${VALID_PROFILES.join(', ')}`);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Ensure config exists (create if needed)
|
|
410
|
+
ensureConfigFile(cwd);
|
|
411
|
+
|
|
412
|
+
// Set the model profile in the config
|
|
413
|
+
const { previousValue } = setConfigValue(cwd, 'model_profile', normalizedProfile, raw);
|
|
414
|
+
const previousProfile = previousValue || 'balanced';
|
|
415
|
+
|
|
416
|
+
// Build result value / message and return
|
|
417
|
+
const agentToModelMap = getAgentToModelMapForProfile(normalizedProfile);
|
|
418
|
+
const result = {
|
|
419
|
+
updated: true,
|
|
420
|
+
profile: normalizedProfile,
|
|
421
|
+
previousProfile,
|
|
422
|
+
agentToModelMap,
|
|
423
|
+
};
|
|
424
|
+
const rawValue = getCmdConfigSetModelProfileResultMessage(
|
|
425
|
+
normalizedProfile,
|
|
426
|
+
previousProfile,
|
|
427
|
+
agentToModelMap
|
|
428
|
+
);
|
|
429
|
+
output(result, raw, rawValue);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Returns the message to display for the result of the `config-set-model-profile` command when
|
|
434
|
+
* displaying raw output.
|
|
435
|
+
*/
|
|
436
|
+
function getCmdConfigSetModelProfileResultMessage(
|
|
437
|
+
normalizedProfile,
|
|
438
|
+
previousProfile,
|
|
439
|
+
agentToModelMap
|
|
440
|
+
) {
|
|
441
|
+
const agentToModelTable = formatAgentToModelMapAsTable(agentToModelMap);
|
|
442
|
+
const didChange = previousProfile !== normalizedProfile;
|
|
443
|
+
const paragraphs = didChange
|
|
444
|
+
? [
|
|
445
|
+
`✓ Model profile set to: ${normalizedProfile} (was: ${previousProfile})`,
|
|
446
|
+
'Agents will now use:',
|
|
447
|
+
agentToModelTable,
|
|
448
|
+
'Next spawned agents will use the new profile.',
|
|
449
|
+
]
|
|
450
|
+
: [
|
|
451
|
+
`✓ Model profile is already set to: ${normalizedProfile}`,
|
|
452
|
+
'Agents are using:',
|
|
453
|
+
agentToModelTable,
|
|
454
|
+
];
|
|
455
|
+
return paragraphs.join('\n\n');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
module.exports = {
|
|
459
|
+
buildNewProjectConfig,
|
|
460
|
+
cmdConfigEnsureSection,
|
|
461
|
+
cmdConfigSet,
|
|
462
|
+
cmdConfigGet,
|
|
463
|
+
cmdConfigSetModelProfile,
|
|
464
|
+
cmdConfigNewProject,
|
|
465
|
+
setConfigValue,
|
|
466
|
+
};
|