@howlil/ez-agents 2.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.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +845 -0
  3. package/README.zh-CN.md +702 -0
  4. package/agents/ez-codebase-mapper.md +770 -0
  5. package/agents/ez-debugger.md +1255 -0
  6. package/agents/ez-executor.md +487 -0
  7. package/agents/ez-integration-checker.md +443 -0
  8. package/agents/ez-nyquist-auditor.md +176 -0
  9. package/agents/ez-phase-researcher.md +553 -0
  10. package/agents/ez-plan-checker.md +706 -0
  11. package/agents/ez-planner.md +1307 -0
  12. package/agents/ez-project-researcher.md +629 -0
  13. package/agents/ez-research-synthesizer.md +247 -0
  14. package/agents/ez-roadmapper.md +650 -0
  15. package/agents/ez-ui-auditor.md +441 -0
  16. package/agents/ez-ui-checker.md +302 -0
  17. package/agents/ez-ui-researcher.md +355 -0
  18. package/agents/ez-verifier.md +579 -0
  19. package/bin/install.js +2862 -0
  20. package/bin/update.js +214 -0
  21. package/commands/ez/add-phase.md +43 -0
  22. package/commands/ez/add-tests.md +41 -0
  23. package/commands/ez/add-todo.md +47 -0
  24. package/commands/ez/audit-milestone.md +36 -0
  25. package/commands/ez/autonomous.md +41 -0
  26. package/commands/ez/check-todos.md +45 -0
  27. package/commands/ez/cleanup.md +18 -0
  28. package/commands/ez/complete-milestone.md +136 -0
  29. package/commands/ez/debug.md +168 -0
  30. package/commands/ez/discuss-phase.md +90 -0
  31. package/commands/ez/execute-phase.md +41 -0
  32. package/commands/ez/health.md +22 -0
  33. package/commands/ez/help.md +22 -0
  34. package/commands/ez/insert-phase.md +32 -0
  35. package/commands/ez/join-discord.md +18 -0
  36. package/commands/ez/list-phase-assumptions.md +46 -0
  37. package/commands/ez/map-codebase.md +71 -0
  38. package/commands/ez/new-milestone.md +44 -0
  39. package/commands/ez/new-project.md +42 -0
  40. package/commands/ez/pause-work.md +38 -0
  41. package/commands/ez/plan-milestone-gaps.md +34 -0
  42. package/commands/ez/plan-phase.md +45 -0
  43. package/commands/ez/progress.md +24 -0
  44. package/commands/ez/quick.md +45 -0
  45. package/commands/ez/reapply-patches.md +124 -0
  46. package/commands/ez/remove-phase.md +31 -0
  47. package/commands/ez/research-phase.md +190 -0
  48. package/commands/ez/resume-work.md +40 -0
  49. package/commands/ez/set-profile.md +34 -0
  50. package/commands/ez/settings.md +36 -0
  51. package/commands/ez/stats.md +18 -0
  52. package/commands/ez/ui-phase.md +34 -0
  53. package/commands/ez/ui-review.md +32 -0
  54. package/commands/ez/update.md +37 -0
  55. package/commands/ez/validate-phase.md +35 -0
  56. package/commands/ez/verify-work.md +38 -0
  57. package/get-shit-done/bin/ez-tools.cjs +598 -0
  58. package/get-shit-done/bin/lib/assistant-adapter.cjs +205 -0
  59. package/get-shit-done/bin/lib/audit-exec.cjs +150 -0
  60. package/get-shit-done/bin/lib/auth.cjs +175 -0
  61. package/get-shit-done/bin/lib/circuit-breaker.cjs +118 -0
  62. package/get-shit-done/bin/lib/commands.cjs +666 -0
  63. package/get-shit-done/bin/lib/config.cjs +183 -0
  64. package/get-shit-done/bin/lib/core.cjs +495 -0
  65. package/get-shit-done/bin/lib/file-lock.cjs +236 -0
  66. package/get-shit-done/bin/lib/frontmatter.cjs +299 -0
  67. package/get-shit-done/bin/lib/fs-utils.cjs +153 -0
  68. package/get-shit-done/bin/lib/git-utils.cjs +203 -0
  69. package/get-shit-done/bin/lib/health-check.cjs +163 -0
  70. package/get-shit-done/bin/lib/index.cjs +113 -0
  71. package/get-shit-done/bin/lib/init.cjs +710 -0
  72. package/get-shit-done/bin/lib/logger.cjs +117 -0
  73. package/get-shit-done/bin/lib/milestone.cjs +241 -0
  74. package/get-shit-done/bin/lib/model-provider.cjs +146 -0
  75. package/get-shit-done/bin/lib/phase.cjs +908 -0
  76. package/get-shit-done/bin/lib/retry.cjs +119 -0
  77. package/get-shit-done/bin/lib/roadmap.cjs +305 -0
  78. package/get-shit-done/bin/lib/safe-exec.cjs +128 -0
  79. package/get-shit-done/bin/lib/safe-path.cjs +130 -0
  80. package/get-shit-done/bin/lib/state.cjs +721 -0
  81. package/get-shit-done/bin/lib/temp-file.cjs +239 -0
  82. package/get-shit-done/bin/lib/template.cjs +222 -0
  83. package/get-shit-done/bin/lib/test-file-lock.cjs +112 -0
  84. package/get-shit-done/bin/lib/test-graceful.cjs +93 -0
  85. package/get-shit-done/bin/lib/test-logger.cjs +60 -0
  86. package/get-shit-done/bin/lib/test-safe-exec.cjs +38 -0
  87. package/get-shit-done/bin/lib/test-safe-path.cjs +33 -0
  88. package/get-shit-done/bin/lib/test-temp-file.cjs +125 -0
  89. package/get-shit-done/bin/lib/timeout-exec.cjs +62 -0
  90. package/get-shit-done/bin/lib/verify.cjs +820 -0
  91. package/get-shit-done/references/checkpoints.md +776 -0
  92. package/get-shit-done/references/continuation-format.md +249 -0
  93. package/get-shit-done/references/decimal-phase-calculation.md +65 -0
  94. package/get-shit-done/references/git-integration.md +248 -0
  95. package/get-shit-done/references/git-planning-commit.md +38 -0
  96. package/get-shit-done/references/model-profile-resolution.md +34 -0
  97. package/get-shit-done/references/model-profiles.md +93 -0
  98. package/get-shit-done/references/phase-argument-parsing.md +61 -0
  99. package/get-shit-done/references/planning-config.md +200 -0
  100. package/get-shit-done/references/questioning.md +162 -0
  101. package/get-shit-done/references/tdd.md +263 -0
  102. package/get-shit-done/references/ui-brand.md +160 -0
  103. package/get-shit-done/references/verification-patterns.md +612 -0
  104. package/get-shit-done/templates/DEBUG.md +164 -0
  105. package/get-shit-done/templates/UAT.md +247 -0
  106. package/get-shit-done/templates/UI-SPEC.md +100 -0
  107. package/get-shit-done/templates/VALIDATION.md +76 -0
  108. package/get-shit-done/templates/codebase/architecture.md +255 -0
  109. package/get-shit-done/templates/codebase/concerns.md +310 -0
  110. package/get-shit-done/templates/codebase/conventions.md +307 -0
  111. package/get-shit-done/templates/codebase/integrations.md +280 -0
  112. package/get-shit-done/templates/codebase/stack.md +186 -0
  113. package/get-shit-done/templates/codebase/structure.md +285 -0
  114. package/get-shit-done/templates/codebase/testing.md +480 -0
  115. package/get-shit-done/templates/config.json +37 -0
  116. package/get-shit-done/templates/context.md +352 -0
  117. package/get-shit-done/templates/continue-here.md +78 -0
  118. package/get-shit-done/templates/copilot-instructions.md +7 -0
  119. package/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  120. package/get-shit-done/templates/discovery.md +146 -0
  121. package/get-shit-done/templates/milestone-archive.md +123 -0
  122. package/get-shit-done/templates/milestone.md +115 -0
  123. package/get-shit-done/templates/phase-prompt.md +610 -0
  124. package/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  125. package/get-shit-done/templates/project.md +184 -0
  126. package/get-shit-done/templates/requirements.md +231 -0
  127. package/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  128. package/get-shit-done/templates/research-project/FEATURES.md +147 -0
  129. package/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  130. package/get-shit-done/templates/research-project/STACK.md +120 -0
  131. package/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  132. package/get-shit-done/templates/research.md +552 -0
  133. package/get-shit-done/templates/retrospective.md +54 -0
  134. package/get-shit-done/templates/roadmap.md +202 -0
  135. package/get-shit-done/templates/state.md +176 -0
  136. package/get-shit-done/templates/summary-complex.md +59 -0
  137. package/get-shit-done/templates/summary-minimal.md +41 -0
  138. package/get-shit-done/templates/summary-standard.md +48 -0
  139. package/get-shit-done/templates/summary.md +248 -0
  140. package/get-shit-done/templates/user-setup.md +311 -0
  141. package/get-shit-done/templates/verification-report.md +322 -0
  142. package/get-shit-done/workflows/add-phase.md +112 -0
  143. package/get-shit-done/workflows/add-tests.md +351 -0
  144. package/get-shit-done/workflows/add-todo.md +158 -0
  145. package/get-shit-done/workflows/audit-milestone.md +332 -0
  146. package/get-shit-done/workflows/autonomous.md +743 -0
  147. package/get-shit-done/workflows/check-todos.md +177 -0
  148. package/get-shit-done/workflows/cleanup.md +152 -0
  149. package/get-shit-done/workflows/complete-milestone.md +766 -0
  150. package/get-shit-done/workflows/diagnose-issues.md +219 -0
  151. package/get-shit-done/workflows/discovery-phase.md +289 -0
  152. package/get-shit-done/workflows/discuss-phase.md +762 -0
  153. package/get-shit-done/workflows/execute-phase.md +468 -0
  154. package/get-shit-done/workflows/execute-plan.md +483 -0
  155. package/get-shit-done/workflows/health.md +159 -0
  156. package/get-shit-done/workflows/help.md +492 -0
  157. package/get-shit-done/workflows/insert-phase.md +130 -0
  158. package/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  159. package/get-shit-done/workflows/map-codebase.md +316 -0
  160. package/get-shit-done/workflows/new-milestone.md +384 -0
  161. package/get-shit-done/workflows/new-project.md +1111 -0
  162. package/get-shit-done/workflows/node-repair.md +92 -0
  163. package/get-shit-done/workflows/pause-work.md +122 -0
  164. package/get-shit-done/workflows/plan-milestone-gaps.md +274 -0
  165. package/get-shit-done/workflows/plan-phase.md +651 -0
  166. package/get-shit-done/workflows/progress.md +382 -0
  167. package/get-shit-done/workflows/quick.md +610 -0
  168. package/get-shit-done/workflows/remove-phase.md +155 -0
  169. package/get-shit-done/workflows/research-phase.md +74 -0
  170. package/get-shit-done/workflows/resume-project.md +307 -0
  171. package/get-shit-done/workflows/set-profile.md +81 -0
  172. package/get-shit-done/workflows/settings.md +242 -0
  173. package/get-shit-done/workflows/stats.md +57 -0
  174. package/get-shit-done/workflows/transition.md +544 -0
  175. package/get-shit-done/workflows/ui-phase.md +290 -0
  176. package/get-shit-done/workflows/ui-review.md +157 -0
  177. package/get-shit-done/workflows/update.md +320 -0
  178. package/get-shit-done/workflows/validate-phase.md +167 -0
  179. package/get-shit-done/workflows/verify-phase.md +243 -0
  180. package/get-shit-done/workflows/verify-work.md +584 -0
  181. package/package.json +55 -0
  182. package/scripts/build-hooks.js +43 -0
  183. package/scripts/run-tests.cjs +29 -0
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Config — Planning config CRUD operations
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { output, error } = require('./core.cjs');
8
+
9
+ const VALID_CONFIG_KEYS = new Set([
10
+ 'mode', 'granularity', 'parallelization', 'commit_docs', 'model_profile',
11
+ 'search_gitignored', 'brave_search',
12
+ 'workflow.research', 'workflow.plan_check', 'workflow.verifier',
13
+ 'workflow.nyquist_validation', 'workflow.ui_phase', 'workflow.ui_safety_gate',
14
+ 'workflow._auto_chain_active',
15
+ 'git.branching_strategy', 'git.phase_branch_template', 'git.milestone_branch_template',
16
+ 'planning.commit_docs', 'planning.search_gitignored',
17
+ ]);
18
+
19
+ function cmdConfigEnsureSection(cwd, raw) {
20
+ const configPath = path.join(cwd, '.planning', 'config.json');
21
+ const planningDir = path.join(cwd, '.planning');
22
+
23
+ // Ensure .planning directory exists
24
+ try {
25
+ if (!fs.existsSync(planningDir)) {
26
+ fs.mkdirSync(planningDir, { recursive: true });
27
+ }
28
+ } catch (err) {
29
+ error('Failed to create .planning directory: ' + err.message);
30
+ }
31
+
32
+ // Check if config already exists
33
+ if (fs.existsSync(configPath)) {
34
+ const result = { created: false, reason: 'already_exists' };
35
+ output(result, raw, 'exists');
36
+ return;
37
+ }
38
+
39
+ // Detect Brave Search API key availability
40
+ const homedir = require('os').homedir();
41
+ const braveKeyFile = path.join(homedir, '.gsd', 'brave_api_key');
42
+ const hasBraveSearch = !!(process.env.BRAVE_API_KEY || fs.existsSync(braveKeyFile));
43
+
44
+ // Load user-level defaults from ~/.gsd/defaults.json if available
45
+ const globalDefaultsPath = path.join(homedir, '.gsd', 'defaults.json');
46
+ let userDefaults = {};
47
+ try {
48
+ if (fs.existsSync(globalDefaultsPath)) {
49
+ userDefaults = JSON.parse(fs.readFileSync(globalDefaultsPath, 'utf-8'));
50
+ // Migrate deprecated "depth" key to "granularity"
51
+ if ('depth' in userDefaults && !('granularity' in userDefaults)) {
52
+ const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
53
+ userDefaults.granularity = depthToGranularity[userDefaults.depth] || userDefaults.depth;
54
+ delete userDefaults.depth;
55
+ try { fs.writeFileSync(globalDefaultsPath, JSON.stringify(userDefaults, null, 2), 'utf-8'); } catch {}
56
+ }
57
+ }
58
+ } catch (err) {
59
+ // Ignore malformed global defaults, fall back to hardcoded
60
+ }
61
+
62
+ // Create default config (user-level defaults override hardcoded defaults)
63
+ const hardcoded = {
64
+ model_profile: 'balanced',
65
+ commit_docs: true,
66
+ search_gitignored: false,
67
+ branching_strategy: 'none',
68
+ phase_branch_template: 'gsd/phase-{phase}-{slug}',
69
+ milestone_branch_template: 'gsd/{milestone}-{slug}',
70
+ workflow: {
71
+ research: true,
72
+ plan_check: true,
73
+ verifier: true,
74
+ nyquist_validation: true,
75
+ },
76
+ parallelization: true,
77
+ brave_search: hasBraveSearch,
78
+ };
79
+ const defaults = {
80
+ ...hardcoded,
81
+ ...userDefaults,
82
+ workflow: { ...hardcoded.workflow, ...(userDefaults.workflow || {}) },
83
+ };
84
+
85
+ try {
86
+ fs.writeFileSync(configPath, JSON.stringify(defaults, null, 2), 'utf-8');
87
+ const result = { created: true, path: '.planning/config.json' };
88
+ output(result, raw, 'created');
89
+ } catch (err) {
90
+ error('Failed to create config.json: ' + err.message);
91
+ }
92
+ }
93
+
94
+ function cmdConfigSet(cwd, keyPath, value, raw) {
95
+ const configPath = path.join(cwd, '.planning', 'config.json');
96
+
97
+ if (!keyPath) {
98
+ error('Usage: config-set <key.path> <value>');
99
+ }
100
+
101
+ if (!VALID_CONFIG_KEYS.has(keyPath)) {
102
+ error(`Unknown config key: "${keyPath}". Valid keys: ${[...VALID_CONFIG_KEYS].sort().join(', ')}`);
103
+ }
104
+
105
+ // Parse value (handle booleans and numbers)
106
+ let parsedValue = value;
107
+ if (value === 'true') parsedValue = true;
108
+ else if (value === 'false') parsedValue = false;
109
+ else if (!isNaN(value) && value !== '') parsedValue = Number(value);
110
+
111
+ // Load existing config or start with empty object
112
+ let config = {};
113
+ try {
114
+ if (fs.existsSync(configPath)) {
115
+ config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
116
+ }
117
+ } catch (err) {
118
+ error('Failed to read config.json: ' + err.message);
119
+ }
120
+
121
+ // Set nested value using dot notation (e.g., "workflow.research")
122
+ const keys = keyPath.split('.');
123
+ let current = config;
124
+ for (let i = 0; i < keys.length - 1; i++) {
125
+ const key = keys[i];
126
+ if (current[key] === undefined || typeof current[key] !== 'object') {
127
+ current[key] = {};
128
+ }
129
+ current = current[key];
130
+ }
131
+ current[keys[keys.length - 1]] = parsedValue;
132
+
133
+ // Write back
134
+ try {
135
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
136
+ const result = { updated: true, key: keyPath, value: parsedValue };
137
+ output(result, raw, `${keyPath}=${parsedValue}`);
138
+ } catch (err) {
139
+ error('Failed to write config.json: ' + err.message);
140
+ }
141
+ }
142
+
143
+ function cmdConfigGet(cwd, keyPath, raw) {
144
+ const configPath = path.join(cwd, '.planning', 'config.json');
145
+
146
+ if (!keyPath) {
147
+ error('Usage: config-get <key.path>');
148
+ }
149
+
150
+ let config = {};
151
+ try {
152
+ if (fs.existsSync(configPath)) {
153
+ config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
154
+ } else {
155
+ error('No config.json found at ' + configPath);
156
+ }
157
+ } catch (err) {
158
+ if (err.message.startsWith('No config.json')) throw err;
159
+ error('Failed to read config.json: ' + err.message);
160
+ }
161
+
162
+ // Traverse dot-notation path (e.g., "workflow.auto_advance")
163
+ const keys = keyPath.split('.');
164
+ let current = config;
165
+ for (const key of keys) {
166
+ if (current === undefined || current === null || typeof current !== 'object') {
167
+ error(`Key not found: ${keyPath}`);
168
+ }
169
+ current = current[key];
170
+ }
171
+
172
+ if (current === undefined) {
173
+ error(`Key not found: ${keyPath}`);
174
+ }
175
+
176
+ output(current, raw, String(current));
177
+ }
178
+
179
+ module.exports = {
180
+ cmdConfigEnsureSection,
181
+ cmdConfigSet,
182
+ cmdConfigGet,
183
+ };
@@ -0,0 +1,495 @@
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
+
9
+ // ─── Path helpers ────────────────────────────────────────────────────────────
10
+
11
+ /** Normalize a relative path to always use forward slashes (cross-platform). */
12
+ function toPosixPath(p) {
13
+ return p.split(path.sep).join('/');
14
+ }
15
+
16
+ // ─── Model Profile Table ─────────────────────────────────────────────────────
17
+
18
+ const MODEL_PROFILES = {
19
+ 'gsd-planner': { quality: 'opus', balanced: 'opus', budget: 'sonnet' },
20
+ 'gsd-roadmapper': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
21
+ 'gsd-executor': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
22
+ 'gsd-phase-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
23
+ 'gsd-project-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
24
+ 'gsd-research-synthesizer': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
25
+ 'gsd-debugger': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
26
+ 'gsd-codebase-mapper': { quality: 'sonnet', balanced: 'haiku', budget: 'haiku' },
27
+ 'gsd-verifier': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
28
+ 'gsd-plan-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
29
+ 'gsd-integration-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
30
+ 'gsd-nyquist-auditor': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
31
+ 'gsd-ui-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
32
+ 'gsd-ui-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
33
+ 'gsd-ui-auditor': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
34
+ };
35
+
36
+ // ─── Output helpers ───────────────────────────────────────────────────────────
37
+
38
+ function output(result, raw, rawValue) {
39
+ if (raw && rawValue !== undefined) {
40
+ process.stdout.write(String(rawValue));
41
+ } else {
42
+ const json = JSON.stringify(result, null, 2);
43
+ // Large payloads exceed Claude Code's Bash tool buffer (~50KB).
44
+ // Write to tmpfile and output the path prefixed with @file: so callers can detect it.
45
+ if (json.length > 50000) {
46
+ const tmpPath = path.join(require('os').tmpdir(), `gsd-${Date.now()}.json`);
47
+ fs.writeFileSync(tmpPath, json, 'utf-8');
48
+ process.stdout.write('@file:' + tmpPath);
49
+ } else {
50
+ process.stdout.write(json);
51
+ }
52
+ }
53
+ process.exit(0);
54
+ }
55
+
56
+ function error(message) {
57
+ process.stderr.write('Error: ' + message + '\n');
58
+ process.exit(1);
59
+ }
60
+
61
+ // ─── File & Config utilities ──────────────────────────────────────────────────
62
+
63
+ function safeReadFile(filePath) {
64
+ try {
65
+ return fs.readFileSync(filePath, 'utf-8');
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+
71
+ function loadConfig(cwd) {
72
+ const configPath = path.join(cwd, '.planning', 'config.json');
73
+ const defaults = {
74
+ model_profile: 'balanced',
75
+ commit_docs: true,
76
+ search_gitignored: false,
77
+ branching_strategy: 'none',
78
+ phase_branch_template: 'gsd/phase-{phase}-{slug}',
79
+ milestone_branch_template: 'gsd/{milestone}-{slug}',
80
+ research: true,
81
+ plan_checker: true,
82
+ verifier: true,
83
+ nyquist_validation: 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
+ research: get('research', { section: 'workflow', field: 'research' }) ?? defaults.research,
123
+ plan_checker: get('plan_checker', { section: 'workflow', field: 'plan_check' }) ?? defaults.plan_checker,
124
+ verifier: get('verifier', { section: 'workflow', field: 'verifier' }) ?? defaults.verifier,
125
+ nyquist_validation: get('nyquist_validation', { section: 'workflow', field: 'nyquist_validation' }) ?? defaults.nyquist_validation,
126
+ parallelization,
127
+ brave_search: get('brave_search') ?? defaults.brave_search,
128
+ model_overrides: parsed.model_overrides || null,
129
+ };
130
+ } catch {
131
+ return defaults;
132
+ }
133
+ }
134
+
135
+ // ─── Git utilities ────────────────────────────────────────────────────────────
136
+
137
+ function isGitIgnored(cwd, targetPath) {
138
+ try {
139
+ // --no-index checks .gitignore rules regardless of whether the file is tracked.
140
+ // Without it, git check-ignore returns "not ignored" for tracked files even when
141
+ // .gitignore explicitly lists them — a common source of confusion when .planning/
142
+ // was committed before being added to .gitignore.
143
+ execSync('git check-ignore -q --no-index -- ' + targetPath.replace(/[^a-zA-Z0-9._\-/]/g, ''), {
144
+ cwd,
145
+ stdio: 'pipe',
146
+ });
147
+ return true;
148
+ } catch {
149
+ return false;
150
+ }
151
+ }
152
+
153
+ function execGit(cwd, args) {
154
+ try {
155
+ const escaped = args.map(a => {
156
+ if (/^[a-zA-Z0-9._\-/=:@]+$/.test(a)) return a;
157
+ return "'" + a.replace(/'/g, "'\\''") + "'";
158
+ });
159
+ const stdout = execSync('git ' + escaped.join(' '), {
160
+ cwd,
161
+ stdio: 'pipe',
162
+ encoding: 'utf-8',
163
+ });
164
+ return { exitCode: 0, stdout: stdout.trim(), stderr: '' };
165
+ } catch (err) {
166
+ return {
167
+ exitCode: err.status ?? 1,
168
+ stdout: (err.stdout ?? '').toString().trim(),
169
+ stderr: (err.stderr ?? '').toString().trim(),
170
+ };
171
+ }
172
+ }
173
+
174
+ // ─── Phase utilities ──────────────────────────────────────────────────────────
175
+
176
+ function escapeRegex(value) {
177
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
178
+ }
179
+
180
+ function normalizePhaseName(phase) {
181
+ const match = String(phase).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
182
+ if (!match) return phase;
183
+ const padded = match[1].padStart(2, '0');
184
+ const letter = match[2] ? match[2].toUpperCase() : '';
185
+ const decimal = match[3] || '';
186
+ return padded + letter + decimal;
187
+ }
188
+
189
+ function comparePhaseNum(a, b) {
190
+ const pa = String(a).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
191
+ const pb = String(b).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
192
+ if (!pa || !pb) return String(a).localeCompare(String(b));
193
+ const intDiff = parseInt(pa[1], 10) - parseInt(pb[1], 10);
194
+ if (intDiff !== 0) return intDiff;
195
+ // No letter sorts before letter: 12 < 12A < 12B
196
+ const la = (pa[2] || '').toUpperCase();
197
+ const lb = (pb[2] || '').toUpperCase();
198
+ if (la !== lb) {
199
+ if (!la) return -1;
200
+ if (!lb) return 1;
201
+ return la < lb ? -1 : 1;
202
+ }
203
+ // Segment-by-segment decimal comparison: 12A < 12A.1 < 12A.1.2 < 12A.2
204
+ const aDecParts = pa[3] ? pa[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
205
+ const bDecParts = pb[3] ? pb[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
206
+ const maxLen = Math.max(aDecParts.length, bDecParts.length);
207
+ if (aDecParts.length === 0 && bDecParts.length > 0) return -1;
208
+ if (bDecParts.length === 0 && aDecParts.length > 0) return 1;
209
+ for (let i = 0; i < maxLen; i++) {
210
+ const av = Number.isFinite(aDecParts[i]) ? aDecParts[i] : 0;
211
+ const bv = Number.isFinite(bDecParts[i]) ? bDecParts[i] : 0;
212
+ if (av !== bv) return av - bv;
213
+ }
214
+ return 0;
215
+ }
216
+
217
+ function searchPhaseInDir(baseDir, relBase, normalized) {
218
+ try {
219
+ const entries = fs.readdirSync(baseDir, { withFileTypes: true });
220
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
221
+ const match = dirs.find(d => d.startsWith(normalized));
222
+ if (!match) return null;
223
+
224
+ const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
225
+ const phaseNumber = dirMatch ? dirMatch[1] : normalized;
226
+ const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
227
+ const phaseDir = path.join(baseDir, match);
228
+ const phaseFiles = fs.readdirSync(phaseDir);
229
+
230
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
231
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
232
+ const hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
233
+ const hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
234
+ const hasVerification = phaseFiles.some(f => f.endsWith('-VERIFICATION.md') || f === 'VERIFICATION.md');
235
+
236
+ const completedPlanIds = new Set(
237
+ summaries.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
238
+ );
239
+ const incompletePlans = plans.filter(p => {
240
+ const planId = p.replace('-PLAN.md', '').replace('PLAN.md', '');
241
+ return !completedPlanIds.has(planId);
242
+ });
243
+
244
+ return {
245
+ found: true,
246
+ directory: toPosixPath(path.join(relBase, match)),
247
+ phase_number: phaseNumber,
248
+ phase_name: phaseName,
249
+ phase_slug: phaseName ? phaseName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') : null,
250
+ plans,
251
+ summaries,
252
+ incomplete_plans: incompletePlans,
253
+ has_research: hasResearch,
254
+ has_context: hasContext,
255
+ has_verification: hasVerification,
256
+ };
257
+ } catch {
258
+ return null;
259
+ }
260
+ }
261
+
262
+ function findPhaseInternal(cwd, phase) {
263
+ if (!phase) return null;
264
+
265
+ const phasesDir = path.join(cwd, '.planning', 'phases');
266
+ const normalized = normalizePhaseName(phase);
267
+
268
+ // Search current phases first
269
+ const current = searchPhaseInDir(phasesDir, '.planning/phases', normalized);
270
+ if (current) return current;
271
+
272
+ // Search archived milestone phases (newest first)
273
+ const milestonesDir = path.join(cwd, '.planning', 'milestones');
274
+ if (!fs.existsSync(milestonesDir)) return null;
275
+
276
+ try {
277
+ const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
278
+ const archiveDirs = milestoneEntries
279
+ .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
280
+ .map(e => e.name)
281
+ .sort()
282
+ .reverse();
283
+
284
+ for (const archiveName of archiveDirs) {
285
+ const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
286
+ const archivePath = path.join(milestonesDir, archiveName);
287
+ const relBase = '.planning/milestones/' + archiveName;
288
+ const result = searchPhaseInDir(archivePath, relBase, normalized);
289
+ if (result) {
290
+ result.archived = version;
291
+ return result;
292
+ }
293
+ }
294
+ } catch {}
295
+
296
+ return null;
297
+ }
298
+
299
+ function getArchivedPhaseDirs(cwd) {
300
+ const milestonesDir = path.join(cwd, '.planning', 'milestones');
301
+ const results = [];
302
+
303
+ if (!fs.existsSync(milestonesDir)) return results;
304
+
305
+ try {
306
+ const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
307
+ // Find v*-phases directories, sort newest first
308
+ const phaseDirs = milestoneEntries
309
+ .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
310
+ .map(e => e.name)
311
+ .sort()
312
+ .reverse();
313
+
314
+ for (const archiveName of phaseDirs) {
315
+ const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
316
+ const archivePath = path.join(milestonesDir, archiveName);
317
+ const entries = fs.readdirSync(archivePath, { withFileTypes: true });
318
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
319
+
320
+ for (const dir of dirs) {
321
+ results.push({
322
+ name: dir,
323
+ milestone: version,
324
+ basePath: path.join('.planning', 'milestones', archiveName),
325
+ fullPath: path.join(archivePath, dir),
326
+ });
327
+ }
328
+ }
329
+ } catch {}
330
+
331
+ return results;
332
+ }
333
+
334
+ // ─── Roadmap & model utilities ────────────────────────────────────────────────
335
+
336
+ function getRoadmapPhaseInternal(cwd, phaseNum) {
337
+ if (!phaseNum) return null;
338
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
339
+ if (!fs.existsSync(roadmapPath)) return null;
340
+
341
+ try {
342
+ const content = fs.readFileSync(roadmapPath, 'utf-8');
343
+ const escapedPhase = escapeRegex(phaseNum.toString());
344
+ const phasePattern = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`, 'i');
345
+ const headerMatch = content.match(phasePattern);
346
+ if (!headerMatch) return null;
347
+
348
+ const phaseName = headerMatch[1].trim();
349
+ const headerIndex = headerMatch.index;
350
+ const restOfContent = content.slice(headerIndex);
351
+ const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
352
+ const sectionEnd = nextHeaderMatch ? headerIndex + nextHeaderMatch.index : content.length;
353
+ const section = content.slice(headerIndex, sectionEnd).trim();
354
+
355
+ const goalMatch = section.match(/\*\*Goal:\*\*\s*([^\n]+)/i);
356
+ const goal = goalMatch ? goalMatch[1].trim() : null;
357
+
358
+ return {
359
+ found: true,
360
+ phase_number: phaseNum.toString(),
361
+ phase_name: phaseName,
362
+ goal,
363
+ section,
364
+ };
365
+ } catch {
366
+ return null;
367
+ }
368
+ }
369
+
370
+ function resolveModelInternal(cwd, agentType) {
371
+ const config = loadConfig(cwd);
372
+
373
+ // Check per-agent override first
374
+ const override = config.model_overrides?.[agentType];
375
+ if (override) {
376
+ return override === 'opus' ? 'inherit' : override;
377
+ }
378
+
379
+ // Fall back to profile lookup
380
+ const profile = config.model_profile || 'balanced';
381
+ const agentModels = MODEL_PROFILES[agentType];
382
+ if (!agentModels) return 'sonnet';
383
+ const resolved = agentModels[profile] || agentModels['balanced'] || 'sonnet';
384
+ return resolved === 'opus' ? 'inherit' : resolved;
385
+ }
386
+
387
+ // ─── Misc utilities ───────────────────────────────────────────────────────────
388
+
389
+ function pathExistsInternal(cwd, targetPath) {
390
+ const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
391
+ try {
392
+ fs.statSync(fullPath);
393
+ return true;
394
+ } catch {
395
+ return false;
396
+ }
397
+ }
398
+
399
+ function generateSlugInternal(text) {
400
+ if (!text) return null;
401
+ return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
402
+ }
403
+
404
+ function getMilestoneInfo(cwd) {
405
+ try {
406
+ const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
407
+
408
+ // First: check for list-format roadmaps using 🚧 (in-progress) marker
409
+ // e.g. "- 🚧 **v2.1 Belgium** — Phases 24-28 (in progress)"
410
+ const inProgressMatch = roadmap.match(/🚧\s*\*\*v(\d+\.\d+)\s+([^*]+)\*\*/);
411
+ if (inProgressMatch) {
412
+ return {
413
+ version: 'v' + inProgressMatch[1],
414
+ name: inProgressMatch[2].trim(),
415
+ };
416
+ }
417
+
418
+ // Second: heading-format roadmaps — strip shipped milestones in <details> blocks
419
+ const cleaned = roadmap.replace(/<details>[\s\S]*?<\/details>/gi, '');
420
+ // Extract version and name from the same ## heading for consistency
421
+ const headingMatch = cleaned.match(/## .*v(\d+\.\d+)[:\s]+([^\n(]+)/);
422
+ if (headingMatch) {
423
+ return {
424
+ version: 'v' + headingMatch[1],
425
+ name: headingMatch[2].trim(),
426
+ };
427
+ }
428
+ // Fallback: try bare version match
429
+ const versionMatch = cleaned.match(/v(\d+\.\d+)/);
430
+ return {
431
+ version: versionMatch ? versionMatch[0] : 'v1.0',
432
+ name: 'milestone',
433
+ };
434
+ } catch {
435
+ return { version: 'v1.0', name: 'milestone' };
436
+ }
437
+ }
438
+
439
+ /**
440
+ * Returns a filter function that checks whether a phase directory belongs
441
+ * to the current milestone based on ROADMAP.md phase headings.
442
+ * If no ROADMAP exists or no phases are listed, returns a pass-all filter.
443
+ */
444
+ function getMilestonePhaseFilter(cwd) {
445
+ const milestonePhaseNums = new Set();
446
+ try {
447
+ const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
448
+ const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
449
+ let m;
450
+ while ((m = phasePattern.exec(roadmap)) !== null) {
451
+ milestonePhaseNums.add(m[1]);
452
+ }
453
+ } catch {}
454
+
455
+ if (milestonePhaseNums.size === 0) {
456
+ const passAll = () => true;
457
+ passAll.phaseCount = 0;
458
+ return passAll;
459
+ }
460
+
461
+ const normalized = new Set(
462
+ [...milestonePhaseNums].map(n => (n.replace(/^0+/, '') || '0').toLowerCase())
463
+ );
464
+
465
+ function isDirInMilestone(dirName) {
466
+ const m = dirName.match(/^0*(\d+[A-Za-z]?(?:\.\d+)*)/);
467
+ if (!m) return false;
468
+ return normalized.has(m[1].toLowerCase());
469
+ }
470
+ isDirInMilestone.phaseCount = milestonePhaseNums.size;
471
+ return isDirInMilestone;
472
+ }
473
+
474
+ module.exports = {
475
+ MODEL_PROFILES,
476
+ output,
477
+ error,
478
+ safeReadFile,
479
+ loadConfig,
480
+ isGitIgnored,
481
+ execGit,
482
+ escapeRegex,
483
+ normalizePhaseName,
484
+ comparePhaseNum,
485
+ searchPhaseInDir,
486
+ findPhaseInternal,
487
+ getArchivedPhaseDirs,
488
+ getRoadmapPhaseInternal,
489
+ resolveModelInternal,
490
+ pathExistsInternal,
491
+ generateSlugInternal,
492
+ getMilestoneInfo,
493
+ getMilestonePhaseFilter,
494
+ toPosixPath,
495
+ };