gsd-opencode 1.22.1 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/agents/gsd-advisor-researcher.md +112 -0
  2. package/agents/gsd-assumptions-analyzer.md +110 -0
  3. package/agents/gsd-codebase-mapper.md +0 -2
  4. package/agents/gsd-debugger.md +117 -2
  5. package/agents/gsd-doc-verifier.md +207 -0
  6. package/agents/gsd-doc-writer.md +608 -0
  7. package/agents/gsd-executor.md +45 -4
  8. package/agents/gsd-integration-checker.md +0 -2
  9. package/agents/gsd-nyquist-auditor.md +0 -2
  10. package/agents/gsd-phase-researcher.md +191 -5
  11. package/agents/gsd-plan-checker.md +152 -5
  12. package/agents/gsd-planner.md +131 -157
  13. package/agents/gsd-project-researcher.md +28 -3
  14. package/agents/gsd-research-synthesizer.md +0 -2
  15. package/agents/gsd-roadmapper.md +29 -2
  16. package/agents/gsd-security-auditor.md +129 -0
  17. package/agents/gsd-ui-auditor.md +485 -0
  18. package/agents/gsd-ui-checker.md +305 -0
  19. package/agents/gsd-ui-researcher.md +368 -0
  20. package/agents/gsd-user-profiler.md +173 -0
  21. package/agents/gsd-verifier.md +207 -22
  22. package/commands/gsd/gsd-add-backlog.md +76 -0
  23. package/commands/gsd/gsd-analyze-dependencies.md +34 -0
  24. package/commands/gsd/gsd-audit-uat.md +24 -0
  25. package/commands/gsd/gsd-autonomous.md +45 -0
  26. package/commands/gsd/gsd-cleanup.md +5 -0
  27. package/commands/gsd/gsd-debug.md +29 -21
  28. package/commands/gsd/gsd-discuss-phase.md +15 -36
  29. package/commands/gsd/gsd-do.md +30 -0
  30. package/commands/gsd/gsd-docs-update.md +48 -0
  31. package/commands/gsd/gsd-execute-phase.md +24 -2
  32. package/commands/gsd/gsd-fast.md +30 -0
  33. package/commands/gsd/gsd-forensics.md +56 -0
  34. package/commands/gsd/gsd-help.md +2 -0
  35. package/commands/gsd/gsd-join-discord.md +2 -1
  36. package/commands/gsd/gsd-list-workspaces.md +19 -0
  37. package/commands/gsd/gsd-manager.md +40 -0
  38. package/commands/gsd/gsd-milestone-summary.md +51 -0
  39. package/commands/gsd/gsd-new-project.md +4 -0
  40. package/commands/gsd/gsd-new-workspace.md +44 -0
  41. package/commands/gsd/gsd-next.md +24 -0
  42. package/commands/gsd/gsd-note.md +34 -0
  43. package/commands/gsd/gsd-plan-phase.md +8 -1
  44. package/commands/gsd/gsd-plant-seed.md +28 -0
  45. package/commands/gsd/gsd-pr-branch.md +25 -0
  46. package/commands/gsd/gsd-profile-user.md +46 -0
  47. package/commands/gsd/gsd-quick.md +7 -3
  48. package/commands/gsd/gsd-reapply-patches.md +178 -45
  49. package/commands/gsd/gsd-remove-workspace.md +26 -0
  50. package/commands/gsd/gsd-research-phase.md +7 -12
  51. package/commands/gsd/gsd-review-backlog.md +62 -0
  52. package/commands/gsd/gsd-review.md +38 -0
  53. package/commands/gsd/gsd-secure-phase.md +35 -0
  54. package/commands/gsd/gsd-session-report.md +19 -0
  55. package/commands/gsd/gsd-set-profile.md +24 -23
  56. package/commands/gsd/gsd-ship.md +23 -0
  57. package/commands/gsd/gsd-stats.md +18 -0
  58. package/commands/gsd/gsd-thread.md +127 -0
  59. package/commands/gsd/gsd-ui-phase.md +34 -0
  60. package/commands/gsd/gsd-ui-review.md +32 -0
  61. package/commands/gsd/gsd-workstreams.md +71 -0
  62. package/get-shit-done/bin/gsd-tools.cjs +450 -90
  63. package/get-shit-done/bin/lib/commands.cjs +489 -24
  64. package/get-shit-done/bin/lib/config.cjs +329 -48
  65. package/get-shit-done/bin/lib/core.cjs +1143 -102
  66. package/get-shit-done/bin/lib/docs.cjs +267 -0
  67. package/get-shit-done/bin/lib/frontmatter.cjs +125 -43
  68. package/get-shit-done/bin/lib/init.cjs +918 -106
  69. package/get-shit-done/bin/lib/milestone.cjs +65 -33
  70. package/get-shit-done/bin/lib/model-profiles.cjs +70 -0
  71. package/get-shit-done/bin/lib/phase.cjs +434 -404
  72. package/get-shit-done/bin/lib/profile-output.cjs +1048 -0
  73. package/get-shit-done/bin/lib/profile-pipeline.cjs +539 -0
  74. package/get-shit-done/bin/lib/roadmap.cjs +156 -101
  75. package/get-shit-done/bin/lib/schema-detect.cjs +238 -0
  76. package/get-shit-done/bin/lib/security.cjs +384 -0
  77. package/get-shit-done/bin/lib/state.cjs +711 -79
  78. package/get-shit-done/bin/lib/template.cjs +2 -2
  79. package/get-shit-done/bin/lib/uat.cjs +282 -0
  80. package/get-shit-done/bin/lib/verify.cjs +254 -42
  81. package/get-shit-done/bin/lib/workstream.cjs +495 -0
  82. package/get-shit-done/references/agent-contracts.md +79 -0
  83. package/get-shit-done/references/artifact-types.md +113 -0
  84. package/get-shit-done/references/checkpoints.md +12 -10
  85. package/get-shit-done/references/context-budget.md +49 -0
  86. package/get-shit-done/references/continuation-format.md +15 -15
  87. package/get-shit-done/references/decimal-phase-calculation.md +2 -3
  88. package/get-shit-done/references/domain-probes.md +125 -0
  89. package/get-shit-done/references/gate-prompts.md +100 -0
  90. package/get-shit-done/references/git-integration.md +47 -0
  91. package/get-shit-done/references/model-profile-resolution.md +2 -0
  92. package/get-shit-done/references/model-profiles.md +62 -16
  93. package/get-shit-done/references/phase-argument-parsing.md +2 -2
  94. package/get-shit-done/references/planner-gap-closure.md +62 -0
  95. package/get-shit-done/references/planner-reviews.md +39 -0
  96. package/get-shit-done/references/planner-revision.md +87 -0
  97. package/get-shit-done/references/planning-config.md +18 -1
  98. package/get-shit-done/references/revision-loop.md +97 -0
  99. package/get-shit-done/references/ui-brand.md +2 -2
  100. package/get-shit-done/references/universal-anti-patterns.md +58 -0
  101. package/get-shit-done/references/user-profiling.md +681 -0
  102. package/get-shit-done/references/workstream-flag.md +111 -0
  103. package/get-shit-done/templates/SECURITY.md +61 -0
  104. package/get-shit-done/templates/UAT.md +21 -3
  105. package/get-shit-done/templates/UI-SPEC.md +100 -0
  106. package/get-shit-done/templates/VALIDATION.md +3 -3
  107. package/get-shit-done/templates/claude-md.md +145 -0
  108. package/get-shit-done/templates/config.json +14 -3
  109. package/get-shit-done/templates/context.md +61 -6
  110. package/get-shit-done/templates/debug-subagent-prompt.md +2 -6
  111. package/get-shit-done/templates/dev-preferences.md +21 -0
  112. package/get-shit-done/templates/discussion-log.md +63 -0
  113. package/get-shit-done/templates/phase-prompt.md +46 -5
  114. package/get-shit-done/templates/planner-subagent-prompt.md +2 -10
  115. package/get-shit-done/templates/project.md +2 -0
  116. package/get-shit-done/templates/state.md +2 -2
  117. package/get-shit-done/templates/user-profile.md +146 -0
  118. package/get-shit-done/workflows/add-phase.md +4 -4
  119. package/get-shit-done/workflows/add-tests.md +4 -4
  120. package/get-shit-done/workflows/add-todo.md +4 -4
  121. package/get-shit-done/workflows/analyze-dependencies.md +96 -0
  122. package/get-shit-done/workflows/audit-milestone.md +20 -16
  123. package/get-shit-done/workflows/audit-uat.md +109 -0
  124. package/get-shit-done/workflows/autonomous.md +1036 -0
  125. package/get-shit-done/workflows/check-todos.md +4 -4
  126. package/get-shit-done/workflows/cleanup.md +4 -4
  127. package/get-shit-done/workflows/complete-milestone.md +22 -10
  128. package/get-shit-done/workflows/diagnose-issues.md +21 -7
  129. package/get-shit-done/workflows/discovery-phase.md +2 -2
  130. package/get-shit-done/workflows/discuss-phase-assumptions.md +671 -0
  131. package/get-shit-done/workflows/discuss-phase-power.md +291 -0
  132. package/get-shit-done/workflows/discuss-phase.md +558 -47
  133. package/get-shit-done/workflows/do.md +104 -0
  134. package/get-shit-done/workflows/docs-update.md +1093 -0
  135. package/get-shit-done/workflows/execute-phase.md +741 -58
  136. package/get-shit-done/workflows/execute-plan.md +77 -12
  137. package/get-shit-done/workflows/fast.md +105 -0
  138. package/get-shit-done/workflows/forensics.md +265 -0
  139. package/get-shit-done/workflows/health.md +28 -6
  140. package/get-shit-done/workflows/help.md +127 -7
  141. package/get-shit-done/workflows/insert-phase.md +4 -4
  142. package/get-shit-done/workflows/list-phase-assumptions.md +2 -2
  143. package/get-shit-done/workflows/list-workspaces.md +56 -0
  144. package/get-shit-done/workflows/manager.md +363 -0
  145. package/get-shit-done/workflows/map-codebase.md +83 -44
  146. package/get-shit-done/workflows/milestone-summary.md +223 -0
  147. package/get-shit-done/workflows/new-milestone.md +133 -25
  148. package/get-shit-done/workflows/new-project.md +216 -54
  149. package/get-shit-done/workflows/new-workspace.md +237 -0
  150. package/get-shit-done/workflows/next.md +97 -0
  151. package/get-shit-done/workflows/node-repair.md +92 -0
  152. package/get-shit-done/workflows/note.md +156 -0
  153. package/get-shit-done/workflows/pause-work.md +132 -15
  154. package/get-shit-done/workflows/plan-milestone-gaps.md +6 -7
  155. package/get-shit-done/workflows/plan-phase.md +513 -62
  156. package/get-shit-done/workflows/plant-seed.md +169 -0
  157. package/get-shit-done/workflows/pr-branch.md +129 -0
  158. package/get-shit-done/workflows/profile-user.md +450 -0
  159. package/get-shit-done/workflows/progress.md +154 -29
  160. package/get-shit-done/workflows/quick.md +285 -111
  161. package/get-shit-done/workflows/remove-phase.md +2 -2
  162. package/get-shit-done/workflows/remove-workspace.md +90 -0
  163. package/get-shit-done/workflows/research-phase.md +13 -9
  164. package/get-shit-done/workflows/resume-project.md +37 -18
  165. package/get-shit-done/workflows/review.md +281 -0
  166. package/get-shit-done/workflows/secure-phase.md +154 -0
  167. package/get-shit-done/workflows/session-report.md +146 -0
  168. package/get-shit-done/workflows/set-profile.md +2 -2
  169. package/get-shit-done/workflows/settings.md +91 -11
  170. package/get-shit-done/workflows/ship.md +237 -0
  171. package/get-shit-done/workflows/stats.md +60 -0
  172. package/get-shit-done/workflows/transition.md +150 -23
  173. package/get-shit-done/workflows/ui-phase.md +292 -0
  174. package/get-shit-done/workflows/ui-review.md +183 -0
  175. package/get-shit-done/workflows/update.md +262 -30
  176. package/get-shit-done/workflows/validate-phase.md +14 -17
  177. package/get-shit-done/workflows/verify-phase.md +143 -11
  178. package/get-shit-done/workflows/verify-work.md +141 -39
  179. package/package.json +1 -1
  180. package/skills/gsd-audit-milestone/SKILL.md +29 -0
  181. package/skills/gsd-cleanup/SKILL.md +19 -0
  182. package/skills/gsd-complete-milestone/SKILL.md +131 -0
  183. package/skills/gsd-discuss-phase/SKILL.md +54 -0
  184. package/skills/gsd-execute-phase/SKILL.md +49 -0
  185. package/skills/gsd-plan-phase/SKILL.md +37 -0
  186. package/skills/gsd-ui-phase/SKILL.md +24 -0
  187. package/skills/gsd-ui-review/SKILL.md +24 -0
  188. package/skills/gsd-verify-work/SKILL.md +30 -0
@@ -4,32 +4,86 @@
4
4
 
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
- const { output, error } = require('./core.cjs');
7
+ const { output, error, planningRoot, CONFIG_DEFAULTS } = require('./core.cjs');
8
+ const {
9
+ VALID_PROFILES,
10
+ getAgentToModelMapForProfile,
11
+ formatAgentToModelMapAsTable,
12
+ } = require('./model-profiles.cjs');
8
13
 
9
- function cmdConfigEnsureSection(cwd, raw) {
10
- const configPath = path.join(cwd, '.planning', 'config.json');
11
- const planningDir = path.join(cwd, '.planning');
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
+ 'workflow.use_worktrees',
26
+ 'git.branching_strategy', 'git.base_branch', 'git.phase_branch_template', 'git.milestone_branch_template', 'git.quick_branch_template',
27
+ 'planning.commit_docs', 'planning.search_gitignored',
28
+ 'workflow.subagent_timeout',
29
+ 'hooks.context_warnings',
30
+ 'project_code', 'phase_naming',
31
+ 'manager.flags.discuss', 'manager.flags.plan', 'manager.flags.execute',
32
+ 'response_language',
33
+ ]);
12
34
 
13
- // Ensure .planning directory exists
14
- try {
15
- if (!fs.existsSync(planningDir)) {
16
- fs.mkdirSync(planningDir, { recursive: true });
17
- }
18
- } catch (err) {
19
- error('Failed to create .planning directory: ' + err.message);
20
- }
35
+ /**
36
+ * Check whether a config key path is valid.
37
+ * Supports exact matches from VALID_CONFIG_KEYS plus dynamic patterns
38
+ * like `agent_skills.<agent-type>` where the sub-key is freeform.
39
+ */
40
+ function isValidConfigKey(keyPath) {
41
+ if (VALID_CONFIG_KEYS.has(keyPath)) return true;
42
+ // Allow agent_skills.<agent-type> with any agent type string
43
+ if (/^agent_skills\.[a-zA-Z0-9_-]+$/.test(keyPath)) return true;
44
+ return false;
45
+ }
21
46
 
22
- // Check if config already exists
23
- if (fs.existsSync(configPath)) {
24
- const result = { created: false, reason: 'already_exists' };
25
- output(result, raw, 'exists');
26
- return;
47
+ const CONFIG_KEY_SUGGESTIONS = {
48
+ 'workflow.nyquist_validation_enabled': 'workflow.nyquist_validation',
49
+ 'agents.nyquist_validation_enabled': 'workflow.nyquist_validation',
50
+ 'nyquist.validation_enabled': 'workflow.nyquist_validation',
51
+ 'hooks.research_questions': 'workflow.research_before_questions',
52
+ 'workflow.research_questions': 'workflow.research_before_questions',
53
+ };
54
+
55
+ function validateKnownConfigKeyPath(keyPath) {
56
+ const suggested = CONFIG_KEY_SUGGESTIONS[keyPath];
57
+ if (suggested) {
58
+ error(`Unknown config key: ${keyPath}. Did you mean ${suggested}?`);
27
59
  }
60
+ }
28
61
 
29
- // Detect Brave Search API key availability
62
+ /**
63
+ * Build a fully-materialized config object for a new project.
64
+ *
65
+ * Merges (increasing priority):
66
+ * 1. Hardcoded defaults — every key that loadConfig() resolves, plus mode/granularity
67
+ * 2. User-level defaults from ~/.gsd/defaults.json (if present)
68
+ * 3. userChoices — the settings the user explicitly selected during /gsd-new-project
69
+ *
70
+ * Uses the canonical `git` namespace for branching keys (consistent with VALID_CONFIG_KEYS
71
+ * and the settings workflow). loadConfig() handles both flat and nested formats, so this
72
+ * is backward-compatible with existing projects that have flat keys.
73
+ *
74
+ * Returns a plain object — does NOT write any files.
75
+ */
76
+ function buildNewProjectConfig(userChoices) {
77
+ const choices = userChoices || {};
30
78
  const homedir = require('os').homedir();
79
+
80
+ // Detect API key availability
31
81
  const braveKeyFile = path.join(homedir, '.gsd', 'brave_api_key');
32
82
  const hasBraveSearch = !!(process.env.BRAVE_API_KEY || fs.existsSync(braveKeyFile));
83
+ const firecrawlKeyFile = path.join(homedir, '.gsd', 'firecrawl_api_key');
84
+ const hasFirecrawl = !!(process.env.FIRECRAWL_API_KEY || fs.existsSync(firecrawlKeyFile));
85
+ const exaKeyFile = path.join(homedir, '.gsd', 'exa_api_key');
86
+ const hasExaSearch = !!(process.env.EXA_API_KEY || fs.existsSync(exaKeyFile));
33
87
 
34
88
  // Load user-level defaults from ~/.gsd/defaults.json if available
35
89
  const globalDefaultsPath = path.join(homedir, '.gsd', 'defaults.json');
@@ -42,57 +96,186 @@ function cmdConfigEnsureSection(cwd, raw) {
42
96
  const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
43
97
  userDefaults.granularity = depthToGranularity[userDefaults.depth] || userDefaults.depth;
44
98
  delete userDefaults.depth;
45
- try { fs.writeFileSync(globalDefaultsPath, JSON.stringify(userDefaults, null, 2), 'utf-8'); } catch {}
99
+ try {
100
+ fs.writeFileSync(globalDefaultsPath, JSON.stringify(userDefaults, null, 2), 'utf-8');
101
+ } catch { /* intentionally empty */ }
46
102
  }
47
103
  }
48
- } catch (err) {
49
- // Ignore malformed global defaults, fall back to hardcoded
104
+ } catch {
105
+ // Ignore malformed global defaults
50
106
  }
51
107
 
52
- // Create default config (user-level defaults override hardcoded defaults)
53
108
  const hardcoded = {
54
- model_profile: 'balanced',
55
- commit_docs: true,
56
- search_gitignored: false,
57
- branching_strategy: 'none',
58
- phase_branch_template: 'gsd/phase-{phase}-{slug}',
59
- milestone_branch_template: 'gsd/{milestone}-{slug}',
109
+ model_profile: CONFIG_DEFAULTS.model_profile,
110
+ commit_docs: CONFIG_DEFAULTS.commit_docs,
111
+ parallelization: CONFIG_DEFAULTS.parallelization,
112
+ search_gitignored: CONFIG_DEFAULTS.search_gitignored,
113
+ brave_search: hasBraveSearch,
114
+ firecrawl: hasFirecrawl,
115
+ exa_search: hasExaSearch,
116
+ git: {
117
+ branching_strategy: CONFIG_DEFAULTS.branching_strategy,
118
+ phase_branch_template: CONFIG_DEFAULTS.phase_branch_template,
119
+ milestone_branch_template: CONFIG_DEFAULTS.milestone_branch_template,
120
+ quick_branch_template: CONFIG_DEFAULTS.quick_branch_template,
121
+ },
60
122
  workflow: {
61
123
  research: true,
62
124
  plan_check: true,
63
125
  verifier: true,
64
126
  nyquist_validation: true,
127
+ auto_advance: false,
128
+ node_repair: true,
129
+ node_repair_budget: 2,
130
+ ui_phase: true,
131
+ ui_safety_gate: true,
132
+ text_mode: false,
133
+ research_before_questions: false,
134
+ discuss_mode: 'discuss',
135
+ skip_discuss: false,
65
136
  },
66
- parallelization: true,
67
- brave_search: hasBraveSearch,
137
+ hooks: {
138
+ context_warnings: true,
139
+ },
140
+ project_code: null,
141
+ phase_naming: 'sequential',
142
+ agent_skills: {},
68
143
  };
69
- const defaults = {
144
+
145
+ // Three-level deep merge: hardcoded <- userDefaults <- choices
146
+ return {
70
147
  ...hardcoded,
71
148
  ...userDefaults,
72
- workflow: { ...hardcoded.workflow, ...(userDefaults.workflow || {}) },
149
+ ...choices,
150
+ git: {
151
+ ...hardcoded.git,
152
+ ...(userDefaults.git || {}),
153
+ ...(choices.git || {}),
154
+ },
155
+ workflow: {
156
+ ...hardcoded.workflow,
157
+ ...(userDefaults.workflow || {}),
158
+ ...(choices.workflow || {}),
159
+ },
160
+ hooks: {
161
+ ...hardcoded.hooks,
162
+ ...(userDefaults.hooks || {}),
163
+ ...(choices.hooks || {}),
164
+ },
165
+ agent_skills: {
166
+ ...hardcoded.agent_skills,
167
+ ...(userDefaults.agent_skills || {}),
168
+ ...(choices.agent_skills || {}),
169
+ },
73
170
  };
171
+ }
172
+
173
+ /**
174
+ * Command: create a fully-materialized .planning/config.json for a new project.
175
+ *
176
+ * Accepts user-chosen settings as a JSON string (the keys the user explicitly
177
+ * configured during /gsd-new-project). All remaining keys are filled from
178
+ * hardcoded defaults and optional ~/.gsd/defaults.json.
179
+ *
180
+ * Idempotent: if config.json already exists, returns { created: false }.
181
+ */
182
+ function cmdConfigNewProject(cwd, choicesJson, raw) {
183
+ const planningBase = planningRoot(cwd);
184
+ const configPath = path.join(planningBase, 'config.json');
185
+
186
+ // Idempotent: don't overwrite existing config
187
+ if (fs.existsSync(configPath)) {
188
+ output({ created: false, reason: 'already_exists' }, raw, 'exists');
189
+ return;
190
+ }
74
191
 
192
+ // Parse user choices
193
+ let userChoices = {};
194
+ if (choicesJson && choicesJson.trim() !== '') {
195
+ try {
196
+ userChoices = JSON.parse(choicesJson);
197
+ } catch (err) {
198
+ error('Invalid JSON for config-new-project: ' + err.message);
199
+ }
200
+ }
201
+
202
+ // Ensure .planning directory exists
75
203
  try {
76
- fs.writeFileSync(configPath, JSON.stringify(defaults, null, 2), 'utf-8');
77
- const result = { created: true, path: '.planning/config.json' };
78
- output(result, raw, 'created');
204
+ if (!fs.existsSync(planningBase)) {
205
+ fs.mkdirSync(planningBase, { recursive: true });
206
+ }
79
207
  } catch (err) {
80
- error('Failed to create config.json: ' + err.message);
208
+ error('Failed to create .planning directory: ' + err.message);
209
+ }
210
+
211
+ const config = buildNewProjectConfig(userChoices);
212
+
213
+ try {
214
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
215
+ output({ created: true, path: '.planning/config.json' }, raw, 'created');
216
+ } catch (err) {
217
+ error('Failed to write config.json: ' + err.message);
81
218
  }
82
219
  }
83
220
 
84
- function cmdConfigSet(cwd, keyPath, value, raw) {
85
- const configPath = path.join(cwd, '.planning', 'config.json');
221
+ /**
222
+ * Ensures the config file exists (creates it if needed).
223
+ *
224
+ * Does not call `output()`, so can be used as one step in a command without triggering `exit(0)` in
225
+ * the happy path. But note that `error()` will still `exit(1)` out of the process.
226
+ */
227
+ function ensureConfigFile(cwd) {
228
+ const planningBase = planningRoot(cwd);
229
+ const configPath = path.join(planningBase, 'config.json');
86
230
 
87
- if (!keyPath) {
88
- error('Usage: config-set <key.path> <value>');
231
+ // Ensure .planning directory exists
232
+ try {
233
+ if (!fs.existsSync(planningBase)) {
234
+ fs.mkdirSync(planningBase, { recursive: true });
235
+ }
236
+ } catch (err) {
237
+ error('Failed to create .planning directory: ' + err.message);
89
238
  }
90
239
 
91
- // Parse value (handle booleans and numbers)
92
- let parsedValue = value;
93
- if (value === 'true') parsedValue = true;
94
- else if (value === 'false') parsedValue = false;
95
- else if (!isNaN(value) && value !== '') parsedValue = Number(value);
240
+ // Check if config already exists
241
+ if (fs.existsSync(configPath)) {
242
+ return { created: false, reason: 'already_exists' };
243
+ }
244
+
245
+ const config = buildNewProjectConfig({});
246
+
247
+ try {
248
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
249
+ return { created: true, path: '.planning/config.json' };
250
+ } catch (err) {
251
+ error('Failed to create config.json: ' + err.message);
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Command to ensure the config file exists (creates it if needed).
257
+ *
258
+ * Note that this exits the process (via `output()`) even in the happy path; use
259
+ * `ensureConfigFile()` directly if you need to avoid this.
260
+ */
261
+ function cmdConfigEnsureSection(cwd, raw) {
262
+ const ensureConfigFileResult = ensureConfigFile(cwd);
263
+ if (ensureConfigFileResult.created) {
264
+ output(ensureConfigFileResult, raw, 'created');
265
+ } else {
266
+ output(ensureConfigFileResult, raw, 'exists');
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Sets a value in the config file, allowing nested values via dot notation (e.g.,
272
+ * "workflow.research").
273
+ *
274
+ * Does not call `output()`, so can be used as one step in a command without triggering `exit(0)` in
275
+ * the happy path. But note that `error()` will still `exit(1)` out of the process.
276
+ */
277
+ function setConfigValue(cwd, keyPath, parsedValue) {
278
+ const configPath = path.join(planningRoot(cwd), 'config.json');
96
279
 
97
280
  // Load existing config or start with empty object
98
281
  let config = {};
@@ -114,20 +297,51 @@ function cmdConfigSet(cwd, keyPath, value, raw) {
114
297
  }
115
298
  current = current[key];
116
299
  }
300
+ const previousValue = current[keys[keys.length - 1]]; // Capture previous value before overwriting
117
301
  current[keys[keys.length - 1]] = parsedValue;
118
302
 
119
303
  // write back
120
304
  try {
121
305
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
122
- const result = { updated: true, key: keyPath, value: parsedValue };
123
- output(result, raw, `${keyPath}=${parsedValue}`);
306
+ return { updated: true, key: keyPath, value: parsedValue, previousValue };
124
307
  } catch (err) {
125
308
  error('Failed to write config.json: ' + err.message);
126
309
  }
127
310
  }
128
311
 
312
+ /**
313
+ * Command to set a value in the config file, allowing nested values via dot notation (e.g.,
314
+ * "workflow.research").
315
+ *
316
+ * Note that this exits the process (via `output()`) even in the happy path; use `setConfigValue()`
317
+ * directly if you need to avoid this.
318
+ */
319
+ function cmdConfigSet(cwd, keyPath, value, raw) {
320
+ if (!keyPath) {
321
+ error('Usage: config-set <key.path> <value>');
322
+ }
323
+
324
+ validateKnownConfigKeyPath(keyPath);
325
+
326
+ if (!isValidConfigKey(keyPath)) {
327
+ error(`Unknown config key: "${keyPath}". Valid keys: ${[...VALID_CONFIG_KEYS].sort().join(', ')}, agent_skills.<agent-type>`);
328
+ }
329
+
330
+ // Parse value (handle booleans, numbers, and JSON arrays/objects)
331
+ let parsedValue = value;
332
+ if (value === 'true') parsedValue = true;
333
+ else if (value === 'false') parsedValue = false;
334
+ else if (!isNaN(value) && value !== '') parsedValue = Number(value);
335
+ else if (typeof value === 'string' && (value.startsWith('[') || value.startsWith('{'))) {
336
+ try { parsedValue = JSON.parse(value); } catch { /* keep as string */ }
337
+ }
338
+
339
+ const setConfigValueResult = setConfigValue(cwd, keyPath, parsedValue);
340
+ output(setConfigValueResult, raw, `${keyPath}=${parsedValue}`);
341
+ }
342
+
129
343
  function cmdConfigGet(cwd, keyPath, raw) {
130
- const configPath = path.join(cwd, '.planning', 'config.json');
344
+ const configPath = path.join(planningRoot(cwd), 'config.json');
131
345
 
132
346
  if (!keyPath) {
133
347
  error('Usage: config-get <key.path>');
@@ -162,8 +376,75 @@ function cmdConfigGet(cwd, keyPath, raw) {
162
376
  output(current, raw, String(current));
163
377
  }
164
378
 
379
+ /**
380
+ * Command to set the model profile in the config file.
381
+ *
382
+ * Note that this exits the process (via `output()`) even in the happy path.
383
+ */
384
+ function cmdConfigSetModelProfile(cwd, profile, raw) {
385
+ if (!profile) {
386
+ error(`Usage: config-set-model-profile <${VALID_PROFILES.join('|')}>`);
387
+ }
388
+
389
+ const normalizedProfile = profile.toLowerCase().trim();
390
+ if (!VALID_PROFILES.includes(normalizedProfile)) {
391
+ error(`Invalid profile '${profile}'. Valid profiles: ${VALID_PROFILES.join(', ')}`);
392
+ }
393
+
394
+ // Ensure config exists (create if needed)
395
+ ensureConfigFile(cwd);
396
+
397
+ // Set the model profile in the config
398
+ const { previousValue } = setConfigValue(cwd, 'model_profile', normalizedProfile, raw);
399
+ const previousProfile = previousValue || 'balanced';
400
+
401
+ // Build result value / message and return
402
+ const agentToModelMap = getAgentToModelMapForProfile(normalizedProfile);
403
+ const result = {
404
+ updated: true,
405
+ profile: normalizedProfile,
406
+ previousProfile,
407
+ agentToModelMap,
408
+ };
409
+ const rawValue = getCmdConfigSetModelProfileResultMessage(
410
+ normalizedProfile,
411
+ previousProfile,
412
+ agentToModelMap
413
+ );
414
+ output(result, raw, rawValue);
415
+ }
416
+
417
+ /**
418
+ * Returns the message to display for the result of the `config-set-model-profile` command when
419
+ * displaying raw output.
420
+ */
421
+ function getCmdConfigSetModelProfileResultMessage(
422
+ normalizedProfile,
423
+ previousProfile,
424
+ agentToModelMap
425
+ ) {
426
+ const agentToModelTable = formatAgentToModelMapAsTable(agentToModelMap);
427
+ const didChange = previousProfile !== normalizedProfile;
428
+ const paragraphs = didChange
429
+ ? [
430
+ `✓ Model profile set to: ${normalizedProfile} (was: ${previousProfile})`,
431
+ 'Agents will now use:',
432
+ agentToModelTable,
433
+ 'Next spawned agents will use the new profile.',
434
+ ]
435
+ : [
436
+ `✓ Model profile is already set to: ${normalizedProfile}`,
437
+ 'Agents are using:',
438
+ agentToModelTable,
439
+ ];
440
+ return paragraphs.join('\n\n');
441
+ }
442
+
165
443
  module.exports = {
444
+ VALID_CONFIG_KEYS,
166
445
  cmdConfigEnsureSection,
167
446
  cmdConfigSet,
168
447
  cmdConfigGet,
448
+ cmdConfigSetModelProfile,
449
+ cmdConfigNewProject,
169
450
  };