@howlil/ez-agents 3.4.2 → 4.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 (365) hide show
  1. package/README.md +735 -462
  2. package/agents/ez-architect-agent.md +267 -0
  3. package/agents/ez-backend-agent.md +303 -0
  4. package/agents/ez-chief-strategist.md +271 -0
  5. package/agents/ez-codebase-mapper.md +770 -770
  6. package/agents/ez-context-manager.md +319 -0
  7. package/agents/ez-debugger.md +1255 -1255
  8. package/agents/ez-design-expert.md +347 -0
  9. package/agents/ez-devops-agent.md +331 -0
  10. package/agents/ez-executor.md +487 -487
  11. package/agents/ez-frontend-agent.md +322 -0
  12. package/agents/ez-phase-researcher.md +553 -553
  13. package/agents/ez-planner.md +1307 -1307
  14. package/agents/ez-product-engineer.md +435 -0
  15. package/agents/ez-project-researcher.md +629 -629
  16. package/agents/ez-qa-agent.md +320 -0
  17. package/agents/ez-release-agent.md +333 -0
  18. package/agents/ez-requirements-agent.md +377 -0
  19. package/agents/ez-roadmapper.md +650 -650
  20. package/agents/ez-technical-writer.md +551 -0
  21. package/agents/ez-ux-expert.md +393 -0
  22. package/agents/ez-verifier.md +579 -579
  23. package/bin/guards/autonomy-guard.cjs +346 -0
  24. package/bin/guards/context-budget-guard.cjs +278 -0
  25. package/bin/guards/hallucination-guard.cjs +380 -0
  26. package/bin/guards/hidden-state-guard.cjs +182 -0
  27. package/bin/guards/team-overhead-guard.cjs +266 -0
  28. package/bin/guards/tool-sprawl-guard.cjs +271 -0
  29. package/bin/install.js +3221 -3272
  30. package/bin/lib/analytics/analytics-collector.cjs +86 -0
  31. package/bin/lib/analytics/analytics-reporter.cjs +130 -0
  32. package/bin/lib/analytics/cohort-analyzer.cjs +138 -0
  33. package/bin/lib/analytics/funnel-analyzer.cjs +147 -0
  34. package/bin/lib/analytics/nps-tracker.cjs +147 -0
  35. package/bin/lib/archetype-detector.cjs +289 -0
  36. package/bin/lib/assistant-adapter.cjs +361 -0
  37. package/bin/lib/audit-exec.cjs +175 -0
  38. package/bin/lib/auth.cjs +176 -0
  39. package/bin/lib/backup-service.cjs +422 -0
  40. package/bin/lib/bdd-validator.cjs +622 -0
  41. package/bin/lib/business-flow-mapper.cjs +429 -0
  42. package/bin/lib/circuit-breaker.cjs +276 -0
  43. package/bin/lib/code-complexity-analyzer.cjs +360 -0
  44. package/bin/lib/codebase-analyzer.cjs +241 -0
  45. package/bin/lib/commands.cjs +691 -0
  46. package/bin/lib/config.cjs +236 -0
  47. package/bin/lib/constraint-extractor.cjs +526 -0
  48. package/bin/lib/content-scanner.cjs +238 -0
  49. package/bin/lib/context-cache.cjs +154 -0
  50. package/bin/lib/context-compressor.cjs +102 -0
  51. package/bin/lib/context-deduplicator.cjs +105 -0
  52. package/bin/lib/context-errors.cjs +78 -0
  53. package/bin/lib/context-manager.cjs +338 -0
  54. package/bin/lib/context-metadata-tracker.cjs +140 -0
  55. package/bin/lib/context-relevance-scorer.cjs +99 -0
  56. package/bin/lib/core.cjs +507 -0
  57. package/bin/lib/cost-alerts.cjs +174 -0
  58. package/bin/lib/cost-tracker.cjs +275 -0
  59. package/bin/lib/crash-recovery.cjs +220 -0
  60. package/bin/lib/dependency-graph.cjs +319 -0
  61. package/bin/lib/deploy/deploy-audit-log.cjs +76 -0
  62. package/bin/lib/deploy/deploy-detector.cjs +69 -0
  63. package/bin/lib/deploy/deploy-env-manager.cjs +109 -0
  64. package/bin/lib/deploy/deploy-health-check.cjs +88 -0
  65. package/bin/lib/deploy/deploy-pre-flight.cjs +57 -0
  66. package/bin/lib/deploy/deploy-rollback.cjs +72 -0
  67. package/bin/lib/deploy/deploy-runner.cjs +97 -0
  68. package/bin/lib/deploy/deploy-status.cjs +74 -0
  69. package/bin/lib/discussion-synthesizer.cjs +439 -0
  70. package/bin/lib/error-cache.cjs +114 -0
  71. package/bin/lib/error-registry.cjs +177 -0
  72. package/bin/lib/file-access.cjs +207 -0
  73. package/bin/lib/file-lock.cjs +236 -0
  74. package/bin/lib/finops/budget-enforcer.cjs +126 -0
  75. package/bin/lib/finops/cost-reporter.cjs +132 -0
  76. package/bin/lib/finops/finops-analyzer.cjs +112 -0
  77. package/bin/lib/finops/spot-manager.cjs +118 -0
  78. package/bin/lib/framework-detector.cjs +396 -0
  79. package/bin/lib/frontmatter.cjs +313 -0
  80. package/bin/lib/fs-utils.cjs +153 -0
  81. package/bin/lib/gate-executor.cjs +272 -0
  82. package/bin/lib/gates/README.md +374 -0
  83. package/bin/lib/gates/gate-01-requirement.cjs +303 -0
  84. package/bin/lib/gates/gate-02-architecture.cjs +555 -0
  85. package/bin/lib/gates/gate-03-code.cjs +635 -0
  86. package/bin/lib/gates/gate-04-security.cjs +829 -0
  87. package/bin/lib/git-errors.cjs +83 -0
  88. package/bin/lib/git-utils.cjs +321 -0
  89. package/bin/lib/git-workflow-engine.cjs +1157 -0
  90. package/bin/lib/health-check.cjs +227 -0
  91. package/bin/lib/index.cjs +279 -0
  92. package/bin/lib/init.cjs +725 -0
  93. package/bin/lib/lock-logger.cjs +194 -0
  94. package/bin/lib/lock-state.cjs +263 -0
  95. package/bin/lib/lockfile-validator.cjs +227 -0
  96. package/bin/lib/log-rotation.cjs +71 -0
  97. package/bin/lib/logger.cjs +125 -0
  98. package/bin/lib/memory-compression.cjs +256 -0
  99. package/bin/lib/milestone.cjs +247 -0
  100. package/bin/lib/model-provider.cjs +241 -0
  101. package/bin/lib/package-manager-detector.cjs +203 -0
  102. package/bin/lib/package-manager-executor.cjs +385 -0
  103. package/bin/lib/package-manager-service.cjs +216 -0
  104. package/bin/lib/perf/api-monitor.cjs +88 -0
  105. package/bin/lib/perf/db-optimizer.cjs +78 -0
  106. package/bin/lib/perf/frontend-performance.cjs +56 -0
  107. package/bin/lib/perf/perf-analyzer.cjs +77 -0
  108. package/bin/lib/perf/perf-baseline.cjs +102 -0
  109. package/bin/lib/perf/perf-reporter.cjs +117 -0
  110. package/bin/lib/perf/regression-detector.cjs +92 -0
  111. package/bin/lib/phase.cjs +963 -0
  112. package/bin/lib/planning-write.cjs +123 -0
  113. package/bin/lib/project-reporter.cjs +565 -0
  114. package/bin/lib/quality-gate.cjs +332 -0
  115. package/bin/lib/quality-metrics.cjs +324 -0
  116. package/bin/lib/recovery-manager.cjs +98 -0
  117. package/bin/lib/release-validator.cjs +617 -0
  118. package/bin/lib/retry.cjs +119 -0
  119. package/bin/lib/roadmap.cjs +309 -0
  120. package/bin/lib/safe-exec.cjs +173 -0
  121. package/bin/lib/safe-path.cjs +130 -0
  122. package/bin/lib/security-errors.cjs +62 -0
  123. package/bin/lib/session-chain.cjs +304 -0
  124. package/bin/lib/session-errors.cjs +81 -0
  125. package/bin/lib/session-export.cjs +251 -0
  126. package/bin/lib/session-import.cjs +262 -0
  127. package/bin/lib/session-manager.cjs +280 -0
  128. package/bin/lib/skill-context.cjs +148 -0
  129. package/bin/lib/skill-matcher.cjs +236 -0
  130. package/bin/lib/skill-registry.cjs +360 -0
  131. package/bin/lib/skill-resolver.cjs +449 -0
  132. package/bin/lib/skill-triggers.cjs +90 -0
  133. package/bin/lib/skill-validator.cjs +270 -0
  134. package/bin/lib/skill-versioning.cjs +355 -0
  135. package/bin/lib/stack-detector.cjs +399 -0
  136. package/bin/lib/state.cjs +736 -0
  137. package/bin/lib/tech-debt-analyzer.cjs +309 -0
  138. package/bin/lib/temp-file.cjs +239 -0
  139. package/bin/lib/template.cjs +223 -0
  140. package/bin/lib/test-file-lock.cjs +112 -0
  141. package/bin/lib/test-graceful.cjs +93 -0
  142. package/bin/lib/test-logger.cjs +60 -0
  143. package/bin/lib/test-safe-exec.cjs +38 -0
  144. package/bin/lib/test-safe-path.cjs +33 -0
  145. package/bin/lib/test-temp-file.cjs +125 -0
  146. package/bin/lib/tier-manager.cjs +428 -0
  147. package/bin/lib/timeout-exec.cjs +63 -0
  148. package/bin/lib/tradeoff-analyzer.cjs +284 -0
  149. package/bin/lib/url-fetch.cjs +170 -0
  150. package/bin/lib/verify.cjs +863 -0
  151. package/bin/update.js +217 -214
  152. package/commands/deploy.cjs +53 -0
  153. package/commands/ez/add-tests.md +41 -41
  154. package/commands/ez/audit-milestone.md +36 -36
  155. package/commands/ez/complete-milestone.md +136 -136
  156. package/commands/ez/discuss-phase.md +90 -90
  157. package/commands/ez/execute-phase.md +52 -41
  158. package/commands/ez/help.md +22 -22
  159. package/commands/ez/map-codebase.md +71 -71
  160. package/commands/ez/new-milestone.md +44 -44
  161. package/commands/ez/new-project.md +51 -42
  162. package/commands/ez/plan-phase.md +53 -45
  163. package/commands/ez/progress.md +36 -24
  164. package/commands/ez/quick.md +45 -45
  165. package/commands/ez/resume-work.md +40 -40
  166. package/commands/ez/run-phase.md +580 -0
  167. package/commands/ez/settings.md +36 -36
  168. package/commands/ez/update.md +37 -37
  169. package/commands/ez/verify-work.md +402 -38
  170. package/commands/health-check.cjs +44 -0
  171. package/commands/rollback.cjs +47 -0
  172. package/ez-agents/bin/ez-tools.cjs +1692 -716
  173. package/ez-agents/bin/guards/autonomy-guard.cjs +346 -0
  174. package/ez-agents/bin/guards/context-budget-guard.cjs +247 -0
  175. package/ez-agents/bin/guards/hallucination-guard.cjs +271 -0
  176. package/ez-agents/bin/guards/hidden-state-guard.cjs +182 -0
  177. package/ez-agents/bin/guards/team-overhead-guard.cjs +266 -0
  178. package/ez-agents/bin/guards/tool-sprawl-guard.cjs +271 -0
  179. package/ez-agents/bin/lib/analytics/analytics-collector.cjs +86 -0
  180. package/ez-agents/bin/lib/analytics/analytics-reporter.cjs +130 -0
  181. package/ez-agents/bin/lib/analytics/cohort-analyzer.cjs +138 -0
  182. package/ez-agents/bin/lib/analytics/funnel-analyzer.cjs +147 -0
  183. package/ez-agents/bin/lib/analytics/nps-tracker.cjs +147 -0
  184. package/ez-agents/bin/lib/archetype-detector.cjs +289 -0
  185. package/ez-agents/bin/lib/audit-exec.cjs +166 -167
  186. package/ez-agents/bin/lib/auth.cjs +176 -176
  187. package/ez-agents/bin/lib/backup-service.cjs +422 -0
  188. package/ez-agents/bin/lib/bdd-validator.cjs +622 -0
  189. package/ez-agents/bin/lib/business-flow-mapper.cjs +429 -0
  190. package/ez-agents/bin/lib/code-complexity-analyzer.cjs +360 -0
  191. package/ez-agents/bin/lib/codebase-analyzer.cjs +241 -0
  192. package/ez-agents/bin/lib/commands.cjs +685 -685
  193. package/ez-agents/bin/lib/config.cjs +41 -1
  194. package/ez-agents/bin/lib/constraint-extractor.cjs +526 -0
  195. package/ez-agents/bin/lib/content-scanner.cjs +238 -0
  196. package/ez-agents/bin/lib/context-cache.cjs +154 -0
  197. package/ez-agents/bin/lib/context-errors.cjs +71 -0
  198. package/ez-agents/bin/lib/context-manager.cjs +220 -0
  199. package/ez-agents/bin/lib/core.cjs +507 -512
  200. package/ez-agents/bin/lib/cost-tracker.cjs +243 -0
  201. package/ez-agents/bin/lib/crash-recovery.cjs +172 -0
  202. package/ez-agents/bin/lib/dependency-graph.cjs +319 -0
  203. package/ez-agents/bin/lib/deploy/deploy-audit-log.cjs +76 -0
  204. package/ez-agents/bin/lib/deploy/deploy-detector.cjs +69 -0
  205. package/ez-agents/bin/lib/deploy/deploy-env-manager.cjs +109 -0
  206. package/ez-agents/bin/lib/deploy/deploy-health-check.cjs +88 -0
  207. package/ez-agents/bin/lib/deploy/deploy-pre-flight.cjs +57 -0
  208. package/ez-agents/bin/lib/deploy/deploy-rollback.cjs +72 -0
  209. package/ez-agents/bin/lib/deploy/deploy-runner.cjs +97 -0
  210. package/ez-agents/bin/lib/deploy/deploy-status.cjs +74 -0
  211. package/ez-agents/bin/lib/discussion-synthesizer.cjs +458 -0
  212. package/ez-agents/bin/lib/file-access.cjs +207 -0
  213. package/ez-agents/bin/lib/finops/budget-enforcer.cjs +126 -0
  214. package/ez-agents/bin/lib/finops/cost-reporter.cjs +132 -0
  215. package/ez-agents/bin/lib/finops/finops-analyzer.cjs +112 -0
  216. package/ez-agents/bin/lib/finops/spot-manager.cjs +118 -0
  217. package/ez-agents/bin/lib/framework-detector.cjs +396 -0
  218. package/ez-agents/bin/lib/frontmatter.cjs +3 -1
  219. package/ez-agents/bin/lib/gates/README.md +374 -0
  220. package/ez-agents/bin/lib/gates/gate-01-requirement.cjs +303 -0
  221. package/ez-agents/bin/lib/gates/gate-02-architecture.cjs +555 -0
  222. package/ez-agents/bin/lib/gates/gate-03-code.cjs +635 -0
  223. package/ez-agents/bin/lib/gates/gate-04-security.cjs +829 -0
  224. package/ez-agents/bin/lib/git-errors.cjs +83 -0
  225. package/ez-agents/bin/lib/git-utils.cjs +118 -0
  226. package/ez-agents/bin/lib/git-workflow-engine.cjs +1157 -0
  227. package/ez-agents/bin/lib/health-check.cjs +162 -162
  228. package/ez-agents/bin/lib/index.cjs +40 -2
  229. package/ez-agents/bin/lib/init.cjs +0 -2
  230. package/ez-agents/bin/lib/lockfile-validator.cjs +227 -0
  231. package/ez-agents/bin/lib/log-rotation.cjs +71 -0
  232. package/ez-agents/bin/lib/logger.cjs +99 -154
  233. package/ez-agents/bin/lib/memory-compression.cjs +256 -0
  234. package/ez-agents/bin/lib/package-manager-detector.cjs +203 -0
  235. package/ez-agents/bin/lib/package-manager-executor.cjs +385 -0
  236. package/ez-agents/bin/lib/package-manager-service.cjs +216 -0
  237. package/ez-agents/bin/lib/perf/api-monitor.cjs +88 -0
  238. package/ez-agents/bin/lib/perf/db-optimizer.cjs +78 -0
  239. package/ez-agents/bin/lib/perf/frontend-performance.cjs +56 -0
  240. package/ez-agents/bin/lib/perf/perf-analyzer.cjs +77 -0
  241. package/ez-agents/bin/lib/perf/perf-baseline.cjs +102 -0
  242. package/ez-agents/bin/lib/perf/perf-reporter.cjs +117 -0
  243. package/ez-agents/bin/lib/perf/regression-detector.cjs +92 -0
  244. package/ez-agents/bin/lib/project-reporter.cjs +502 -0
  245. package/ez-agents/bin/lib/quality-gate.cjs +332 -0
  246. package/ez-agents/bin/lib/recovery-manager.cjs +98 -0
  247. package/ez-agents/bin/lib/release-validator.cjs +617 -0
  248. package/ez-agents/bin/lib/safe-exec.cjs +128 -214
  249. package/ez-agents/bin/lib/security-errors.cjs +62 -0
  250. package/ez-agents/bin/lib/session-chain.cjs +304 -0
  251. package/ez-agents/bin/lib/session-errors.cjs +81 -0
  252. package/ez-agents/bin/lib/session-export.cjs +251 -0
  253. package/ez-agents/bin/lib/session-import.cjs +262 -0
  254. package/ez-agents/bin/lib/session-manager.cjs +280 -0
  255. package/ez-agents/bin/lib/skill-context.cjs +148 -0
  256. package/ez-agents/bin/lib/skill-matcher.cjs +236 -0
  257. package/ez-agents/bin/lib/skill-registry.cjs +341 -0
  258. package/ez-agents/bin/lib/skill-resolver.cjs +449 -0
  259. package/ez-agents/bin/lib/skill-triggers.cjs +90 -0
  260. package/ez-agents/bin/lib/skill-validator.cjs +270 -0
  261. package/ez-agents/bin/lib/skill-versioning.cjs +355 -0
  262. package/ez-agents/bin/lib/stack-detector.cjs +399 -0
  263. package/ez-agents/bin/lib/tech-debt-analyzer.cjs +309 -0
  264. package/ez-agents/bin/lib/tier-manager.cjs +428 -0
  265. package/ez-agents/bin/lib/tradeoff-analyzer.cjs +284 -0
  266. package/ez-agents/bin/lib/url-fetch.cjs +170 -0
  267. package/ez-agents/bin/lib/verify.cjs +863 -863
  268. package/ez-agents/references/decimal-phase-calculation.md +65 -65
  269. package/ez-agents/references/git-integration.md +248 -248
  270. package/ez-agents/references/git-planning-commit.md +38 -38
  271. package/ez-agents/references/metrics-schema.md +118 -0
  272. package/ez-agents/references/model-profile-resolution.md +34 -34
  273. package/ez-agents/references/model-profiles.md +93 -93
  274. package/ez-agents/references/phase-argument-parsing.md +61 -61
  275. package/ez-agents/references/planning-config.md +340 -200
  276. package/ez-agents/references/tier-strategy.md +103 -0
  277. package/ez-agents/references/ui-brand.md +160 -160
  278. package/ez-agents/references/verification-patterns.md +612 -612
  279. package/ez-agents/templates/DEBUG.md +164 -164
  280. package/ez-agents/templates/UAT.md +247 -247
  281. package/ez-agents/templates/agent-output-format.md +404 -0
  282. package/ez-agents/templates/bdd-feature.md +173 -0
  283. package/ez-agents/templates/codebase/architecture.md +255 -255
  284. package/ez-agents/templates/codebase/structure.md +285 -285
  285. package/ez-agents/templates/copilot-instructions.md +7 -7
  286. package/ez-agents/templates/debug-subagent-prompt.md +91 -91
  287. package/ez-agents/templates/discovery.md +146 -146
  288. package/ez-agents/templates/discussion.md +68 -0
  289. package/ez-agents/templates/handoff-protocol.md +294 -0
  290. package/ez-agents/templates/incident-runbook.md +205 -0
  291. package/ez-agents/templates/mode-workflow-templates.md +301 -0
  292. package/ez-agents/templates/phase-prompt.md +610 -610
  293. package/ez-agents/templates/planner-subagent-prompt.md +117 -117
  294. package/ez-agents/templates/project.md +184 -184
  295. package/ez-agents/templates/release-checklist.md +136 -0
  296. package/ez-agents/templates/research.md +552 -552
  297. package/ez-agents/templates/rollback-plan.md +201 -0
  298. package/ez-agents/templates/security-user-setup.md +244 -0
  299. package/ez-agents/templates/skill-validation-rules.md +476 -0
  300. package/ez-agents/templates/state.md +180 -176
  301. package/ez-agents/templates/summary-complex.md +59 -59
  302. package/ez-agents/tests/gates/gate-01-02.test.cjs +812 -0
  303. package/ez-agents/tests/gates/gate-03-04.test.cjs +762 -0
  304. package/ez-agents/tests/gates/gate-05-validator.test.cjs +145 -0
  305. package/ez-agents/tests/gates/gate-06-docs-validator.test.cjs +244 -0
  306. package/ez-agents/tests/gates/gate-07-release-validator.test.cjs +219 -0
  307. package/ez-agents/tests/guards/context-budget-guard.test.cjs +145 -0
  308. package/ez-agents/tests/guards/edge-case-guards.test.cjs +238 -0
  309. package/ez-agents/tests/guards/hallucination-guard.test.cjs +124 -0
  310. package/ez-agents/workflows/audit-milestone.md +1 -1
  311. package/ez-agents/workflows/autonomous.md +131 -30
  312. package/ez-agents/workflows/complete-milestone.md +1 -1
  313. package/ez-agents/workflows/discuss-phase.md +1 -1
  314. package/ez-agents/workflows/execute-phase.md +169 -3
  315. package/ez-agents/workflows/help.md +86 -133
  316. package/ez-agents/workflows/hotfix.md +291 -0
  317. package/ez-agents/workflows/new-milestone.md +340 -11
  318. package/ez-agents/workflows/new-project.md +294 -318
  319. package/ez-agents/workflows/plan-phase.md +22 -40
  320. package/ez-agents/workflows/progress.md +15 -25
  321. package/ez-agents/workflows/release.md +253 -0
  322. package/ez-agents/workflows/resume-session.md +215 -0
  323. package/ez-agents/workflows/run-phase.md +531 -0
  324. package/ez-agents/workflows/settings.md +2 -35
  325. package/hooks/dist/ez-check-update.js +81 -81
  326. package/hooks/dist/ez-context-monitor.js +148 -141
  327. package/hooks/dist/ez-statusline.js +115 -115
  328. package/package.json +78 -64
  329. package/scripts/fix-qwen-installation.js +144 -144
  330. package/agents/ez-integration-checker.md +0 -443
  331. package/agents/ez-nyquist-auditor.md +0 -176
  332. package/agents/ez-plan-checker.md +0 -706
  333. package/agents/ez-research-synthesizer.md +0 -247
  334. package/agents/ez-ui-auditor.md +0 -439
  335. package/agents/ez-ui-checker.md +0 -300
  336. package/agents/ez-ui-researcher.md +0 -353
  337. package/commands/ez/add-phase.md +0 -43
  338. package/commands/ez/add-todo.md +0 -47
  339. package/commands/ez/auth.md +0 -87
  340. package/commands/ez/autonomous.md +0 -41
  341. package/commands/ez/check-todos.md +0 -45
  342. package/commands/ez/cleanup.md +0 -18
  343. package/commands/ez/debug.md +0 -168
  344. package/commands/ez/health.md +0 -22
  345. package/commands/ez/insert-phase.md +0 -32
  346. package/commands/ez/join-discord.md +0 -18
  347. package/commands/ez/list-phase-assumptions.md +0 -46
  348. package/commands/ez/pause-work.md +0 -38
  349. package/commands/ez/plan-milestone-gaps.md +0 -34
  350. package/commands/ez/reapply-patches.md +0 -124
  351. package/commands/ez/remove-phase.md +0 -31
  352. package/commands/ez/research-phase.md +0 -190
  353. package/commands/ez/set-profile.md +0 -34
  354. package/commands/ez/stats.md +0 -18
  355. package/commands/ez/ui-phase.md +0 -34
  356. package/commands/ez/ui-review.md +0 -32
  357. package/commands/ez/validate-phase.md +0 -35
  358. package/ez-agents/templates/UI-SPEC.md +0 -100
  359. package/ez-agents/templates/VALIDATION.md +0 -76
  360. package/ez-agents/templates/context.md +0 -352
  361. package/ez-agents/templates/verification-report.md +0 -322
  362. package/ez-agents/workflows/research-phase.md +0 -74
  363. package/ez-agents/workflows/ui-phase.md +0 -290
  364. package/ez-agents/workflows/ui-review.md +0 -157
  365. package/ez-agents/workflows/validate-phase.md +0 -167
@@ -1,512 +1,507 @@
1
- /**
2
- * Core — Shared utilities, constants, and internal helpers
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const { safeExec, auditExec } = require('./safe-exec.cjs');
8
- const { defaultLogger: logger } = require('./logger.cjs');
9
-
10
- // ─── Path helpers ────────────────────────────────────────────────────────────
11
-
12
- /** Normalize a relative path to always use forward slashes (cross-platform). */
13
- function toPosixPath(p) {
14
- return p.split(path.sep).join('/');
15
- }
16
-
17
- // ─── Model Profile Table ─────────────────────────────────────────────────────
18
-
19
- const MODEL_PROFILES = {
20
- 'ez-planner': { quality: 'opus', balanced: 'opus', budget: 'sonnet' },
21
- 'ez-roadmapper': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
22
- 'ez-executor': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
23
- 'ez-phase-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
24
- 'ez-project-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
25
- 'ez-research-synthesizer': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
26
- 'ez-debugger': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
27
- 'ez-codebase-mapper': { quality: 'sonnet', balanced: 'haiku', budget: 'haiku' },
28
- 'ez-verifier': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
29
- 'ez-plan-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
30
- 'ez-integration-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
31
- 'ez-nyquist-auditor': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
32
- 'ez-ui-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
33
- 'ez-ui-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
34
- 'ez-ui-auditor': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
35
- };
36
-
37
- // ─── Output helpers ───────────────────────────────────────────────────────────
38
-
39
- function output(result, raw, rawValue) {
40
- if (raw && rawValue !== undefined) {
41
- process.stdout.write(String(rawValue));
42
- } else {
43
- const json = JSON.stringify(result, null, 2);
44
- // Large payloads exceed Claude Code's Bash tool buffer (~50KB).
45
- // Write to tmpfile and output the path prefixed with @file: so callers can detect it.
46
- if (json.length > 50000) {
47
- const tmpPath = path.join(require('os').tmpdir(), `${Date.now()}.json`);
48
- fs.writeFileSync(tmpPath, json, 'utf-8');
49
- process.stdout.write('@file:' + tmpPath);
50
- } else {
51
- process.stdout.write(json);
52
- }
53
- }
54
- process.exit(0);
55
- }
56
-
57
- function error(message) {
58
- process.stderr.write('Error: ' + message + '\n');
59
- process.exit(1);
60
- }
61
-
62
- // ─── File & Config utilities ──────────────────────────────────────────────────
63
-
64
- function safeReadFile(filePath) {
65
- try {
66
- return fs.readFileSync(filePath, 'utf-8');
67
- } catch (err) {
68
- logger.warn('safeReadFile failed', { filePath, error: err.message });
69
- return null;
70
- }
71
- }
72
-
73
- function loadConfig(cwd) {
74
- const configPath = path.join(cwd, '.planning', 'config.json');
75
- const defaults = {
76
- model_profile: 'balanced',
77
- commit_docs: true,
78
- search_gitignored: false,
79
- branching_strategy: 'none',
80
- phase_branch_template: 'ez/phase-{phase}-{slug}',
81
- milestone_branch_template: 'ez/{milestone}-{slug}',
82
- research: true,
83
- plan_checker: true,
84
- verifier: true,
85
- nyquist_validation: true,
86
- parallelization: true,
87
- brave_search: false,
88
- };
89
-
90
- try {
91
- const raw = fs.readFileSync(configPath, 'utf-8');
92
- const parsed = JSON.parse(raw);
93
-
94
- // Migrate deprecated "depth" key to "granularity" with value mapping
95
- if ('depth' in parsed && !('granularity' in parsed)) {
96
- const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
97
- parsed.granularity = depthToGranularity[parsed.depth] || parsed.depth;
98
- delete parsed.depth;
99
- try {
100
- fs.writeFileSync(configPath, JSON.stringify(parsed, null, 2), 'utf-8');
101
- } catch (err) {
102
- logger.warn('Failed to persist migrated config depth->granularity', { configPath, error: err.message });
103
- }
104
- }
105
-
106
- const get = (key, nested) => {
107
- if (parsed[key] !== undefined) return parsed[key];
108
- if (nested && parsed[nested.section] && parsed[nested.section][nested.field] !== undefined) {
109
- return parsed[nested.section][nested.field];
110
- }
111
- return undefined;
112
- };
113
-
114
- const parallelization = (() => {
115
- const val = get('parallelization');
116
- if (typeof val === 'boolean') return val;
117
- if (typeof val === 'object' && val !== null && 'enabled' in val) return val.enabled;
118
- return defaults.parallelization;
119
- })();
120
-
121
- return {
122
- model_profile: get('model_profile') ?? defaults.model_profile,
123
- commit_docs: get('commit_docs', { section: 'planning', field: 'commit_docs' }) ?? defaults.commit_docs,
124
- search_gitignored: get('search_gitignored', { section: 'planning', field: 'search_gitignored' }) ?? defaults.search_gitignored,
125
- branching_strategy: get('branching_strategy', { section: 'git', field: 'branching_strategy' }) ?? defaults.branching_strategy,
126
- phase_branch_template: get('phase_branch_template', { section: 'git', field: 'phase_branch_template' }) ?? defaults.phase_branch_template,
127
- milestone_branch_template: get('milestone_branch_template', { section: 'git', field: 'milestone_branch_template' }) ?? defaults.milestone_branch_template,
128
- research: get('research', { section: 'workflow', field: 'research' }) ?? defaults.research,
129
- plan_checker: get('plan_checker', { section: 'workflow', field: 'plan_check' }) ?? defaults.plan_checker,
130
- verifier: get('verifier', { section: 'workflow', field: 'verifier' }) ?? defaults.verifier,
131
- nyquist_validation: get('nyquist_validation', { section: 'workflow', field: 'nyquist_validation' }) ?? defaults.nyquist_validation,
132
- parallelization,
133
- brave_search: get('brave_search') ?? defaults.brave_search,
134
- model_overrides: parsed.model_overrides || null,
135
- };
136
- } catch (err) {
137
- logger.warn('Failed to load config, using defaults', { configPath, error: err.message });
138
- return defaults;
139
- }
140
- }
141
-
142
- // ─── Git utilities ────────────────────────────────────────────────────────────
143
-
144
- async function isGitIgnored(cwd, targetPath) {
145
- try {
146
- // --no-index checks .gitignore rules regardless of whether the file is tracked.
147
- // Without it, git check-ignore returns "not ignored" for tracked files even when
148
- // .gitignore explicitly lists them — a common source of confusion when .planning/
149
- // was committed before being added to .gitignore.
150
- const safePath = targetPath.replace(/[^a-zA-Z0-9._\-/]/g, '');
151
- await auditExec('git', ['check-ignore', '-q', '--no-index', '--', safePath], {
152
- cwd,
153
- context: 'isGitIgnored',
154
- timeout: 5000
155
- });
156
- return true;
157
- } catch (err) {
158
- logger.warn('git check-ignore failed, assuming not ignored', { targetPath, error: err.message });
159
- return false;
160
- }
161
- }
162
-
163
- async function execGit(cwd, args) {
164
- try {
165
- const stdout = await auditExec('git', args, {
166
- cwd,
167
- context: 'execGit',
168
- timeout: 30000
169
- });
170
- return { exitCode: 0, stdout: stdout.trim(), stderr: '' };
171
- } catch (err) {
172
- logger.warn('execGit failed', { args, error: err.message });
173
- return {
174
- exitCode: err.status ?? 1,
175
- stdout: (err.stdout ?? '').toString().trim(),
176
- stderr: (err.stderr ?? '').toString().trim(),
177
- };
178
- }
179
- }
180
-
181
- // ─── Phase utilities ──────────────────────────────────────────────────────────
182
-
183
- function escapeRegex(value) {
184
- return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
185
- }
186
-
187
- function normalizePhaseName(phase) {
188
- const match = String(phase).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
189
- if (!match) return phase;
190
- const padded = match[1].padStart(2, '0');
191
- const letter = match[2] ? match[2].toUpperCase() : '';
192
- const decimal = match[3] || '';
193
- return padded + letter + decimal;
194
- }
195
-
196
- function comparePhaseNum(a, b) {
197
- const pa = String(a).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
198
- const pb = String(b).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
199
- if (!pa || !pb) return String(a).localeCompare(String(b));
200
- const intDiff = parseInt(pa[1], 10) - parseInt(pb[1], 10);
201
- if (intDiff !== 0) return intDiff;
202
- // No letter sorts before letter: 12 < 12A < 12B
203
- const la = (pa[2] || '').toUpperCase();
204
- const lb = (pb[2] || '').toUpperCase();
205
- if (la !== lb) {
206
- if (!la) return -1;
207
- if (!lb) return 1;
208
- return la < lb ? -1 : 1;
209
- }
210
- // Segment-by-segment decimal comparison: 12A < 12A.1 < 12A.1.2 < 12A.2
211
- const aDecParts = pa[3] ? pa[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
212
- const bDecParts = pb[3] ? pb[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
213
- const maxLen = Math.max(aDecParts.length, bDecParts.length);
214
- if (aDecParts.length === 0 && bDecParts.length > 0) return -1;
215
- if (bDecParts.length === 0 && aDecParts.length > 0) return 1;
216
- for (let i = 0; i < maxLen; i++) {
217
- const av = Number.isFinite(aDecParts[i]) ? aDecParts[i] : 0;
218
- const bv = Number.isFinite(bDecParts[i]) ? bDecParts[i] : 0;
219
- if (av !== bv) return av - bv;
220
- }
221
- return 0;
222
- }
223
-
224
- function searchPhaseInDir(baseDir, relBase, normalized) {
225
- try {
226
- const entries = fs.readdirSync(baseDir, { withFileTypes: true });
227
- const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
228
- const match = dirs.find(d => d.startsWith(normalized));
229
- if (!match) return null;
230
-
231
- const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
232
- const phaseNumber = dirMatch ? dirMatch[1] : normalized;
233
- const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
234
- const phaseDir = path.join(baseDir, match);
235
- const phaseFiles = fs.readdirSync(phaseDir);
236
-
237
- const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
238
- const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
239
- const hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
240
- const hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
241
- const hasVerification = phaseFiles.some(f => f.endsWith('-VERIFICATION.md') || f === 'VERIFICATION.md');
242
-
243
- const completedPlanIds = new Set(
244
- summaries.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
245
- );
246
- const incompletePlans = plans.filter(p => {
247
- const planId = p.replace('-PLAN.md', '').replace('PLAN.md', '');
248
- return !completedPlanIds.has(planId);
249
- });
250
-
251
- return {
252
- found: true,
253
- directory: toPosixPath(path.join(relBase, match)),
254
- phase_number: phaseNumber,
255
- phase_name: phaseName,
256
- phase_slug: phaseName ? phaseName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') : null,
257
- plans,
258
- summaries,
259
- incomplete_plans: incompletePlans,
260
- has_research: hasResearch,
261
- has_context: hasContext,
262
- has_verification: hasVerification,
263
- };
264
- } catch (err) {
265
- logger.warn('Failed to search phase directory', { baseDir, normalized, error: err.message });
266
- return null;
267
- }
268
- }
269
-
270
- function findPhaseInternal(cwd, phase) {
271
- if (!phase) return null;
272
-
273
- const phasesDir = path.join(cwd, '.planning', 'phases');
274
- const normalized = normalizePhaseName(phase);
275
-
276
- // Search current phases first
277
- const current = searchPhaseInDir(phasesDir, '.planning/phases', normalized);
278
- if (current) return current;
279
-
280
- // Search archived milestone phases (newest first)
281
- const milestonesDir = path.join(cwd, '.planning', 'milestones');
282
- if (!fs.existsSync(milestonesDir)) return null;
283
-
284
- try {
285
- const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
286
- const archiveDirs = milestoneEntries
287
- .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
288
- .map(e => e.name)
289
- .sort()
290
- .reverse();
291
-
292
- for (const archiveName of archiveDirs) {
293
- const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
294
- const archivePath = path.join(milestonesDir, archiveName);
295
- const relBase = '.planning/milestones/' + archiveName;
296
- const result = searchPhaseInDir(archivePath, relBase, normalized);
297
- if (result) {
298
- result.archived = version;
299
- return result;
300
- }
301
- }
302
- } catch (err) {
303
- logger.warn('Failed while searching archived milestone phases', { milestonesDir, error: err.message });
304
- }
305
-
306
- return null;
307
- }
308
-
309
- function getArchivedPhaseDirs(cwd) {
310
- const milestonesDir = path.join(cwd, '.planning', 'milestones');
311
- const results = [];
312
-
313
- if (!fs.existsSync(milestonesDir)) return results;
314
-
315
- try {
316
- const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
317
- // Find v*-phases directories, sort newest first
318
- const phaseDirs = milestoneEntries
319
- .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
320
- .map(e => e.name)
321
- .sort()
322
- .reverse();
323
-
324
- for (const archiveName of phaseDirs) {
325
- const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
326
- const archivePath = path.join(milestonesDir, archiveName);
327
- const entries = fs.readdirSync(archivePath, { withFileTypes: true });
328
- const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
329
-
330
- for (const dir of dirs) {
331
- results.push({
332
- name: dir,
333
- milestone: version,
334
- basePath: path.join('.planning', 'milestones', archiveName),
335
- fullPath: path.join(archivePath, dir),
336
- });
337
- }
338
- }
339
- } catch (err) {
340
- logger.warn('Failed to enumerate archived phase directories', { milestonesDir, error: err.message });
341
- }
342
-
343
- return results;
344
- }
345
-
346
- // ─── Roadmap & model utilities ────────────────────────────────────────────────
347
-
348
- function getRoadmapPhaseInternal(cwd, phaseNum) {
349
- if (!phaseNum) return null;
350
- const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
351
- if (!fs.existsSync(roadmapPath)) return null;
352
-
353
- try {
354
- const content = fs.readFileSync(roadmapPath, 'utf-8');
355
- const escapedPhase = escapeRegex(phaseNum.toString());
356
- const phasePattern = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`, 'i');
357
- const headerMatch = content.match(phasePattern);
358
- if (!headerMatch) return null;
359
-
360
- const phaseName = headerMatch[1].trim();
361
- const headerIndex = headerMatch.index;
362
- const restOfContent = content.slice(headerIndex);
363
- const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
364
- const sectionEnd = nextHeaderMatch ? headerIndex + nextHeaderMatch.index : content.length;
365
- const section = content.slice(headerIndex, sectionEnd).trim();
366
-
367
- const goalMatch = section.match(/\*\*Goal:\*\*\s*([^\n]+)/i);
368
- const goal = goalMatch ? goalMatch[1].trim() : null;
369
-
370
- return {
371
- found: true,
372
- phase_number: phaseNum.toString(),
373
- phase_name: phaseName,
374
- goal,
375
- section,
376
- };
377
- } catch (err) {
378
- logger.warn('Failed to read roadmap phase metadata', { roadmapPath, phaseNum, error: err.message });
379
- return null;
380
- }
381
- }
382
-
383
- function resolveModelInternal(cwd, agentType) {
384
- const config = loadConfig(cwd);
385
-
386
- // Check per-agent override first
387
- const override = config.model_overrides?.[agentType];
388
- if (override) {
389
- return override === 'opus' ? 'inherit' : override;
390
- }
391
-
392
- // Fall back to profile lookup
393
- const profile = config.model_profile || 'balanced';
394
- const agentModels = MODEL_PROFILES[agentType];
395
- if (!agentModels) return 'sonnet';
396
- const resolved = agentModels[profile] || agentModels['balanced'] || 'sonnet';
397
- return resolved === 'opus' ? 'inherit' : resolved;
398
- }
399
-
400
- // ─── Misc utilities ───────────────────────────────────────────────────────────
401
-
402
- function pathExistsInternal(cwd, targetPath) {
403
- const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
404
- try {
405
- fs.statSync(fullPath);
406
- return true;
407
- } catch (err) {
408
- logger.warn('Path existence check failed', { fullPath, error: err.message });
409
- return false;
410
- }
411
- }
412
-
413
- function generateSlugInternal(text) {
414
- if (!text) return null;
415
- return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
416
- }
417
-
418
- function getMilestoneInfo(cwd) {
419
- try {
420
- const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
421
-
422
- // First: check for list-format roadmaps using 🚧 (in-progress) marker
423
- // e.g. "- 🚧 **v2.1 Belgium** — Phases 24-28 (in progress)"
424
- const inProgressMatch = roadmap.match(/🚧\s*\*\*v(\d+\.\d+)\s+([^*]+)\*\*/);
425
- if (inProgressMatch) {
426
- return {
427
- version: 'v' + inProgressMatch[1],
428
- name: inProgressMatch[2].trim(),
429
- };
430
- }
431
-
432
- // Second: heading-format roadmaps — strip shipped milestones in <details> blocks
433
- const cleaned = roadmap.replace(/<details>[\s\S]*?<\/details>/gi, '');
434
- // Extract version and name from the same ## heading for consistency
435
- const headingMatch = cleaned.match(/## .*v(\d+\.\d+)[:\s]+([^\n(]+)/);
436
- if (headingMatch) {
437
- return {
438
- version: 'v' + headingMatch[1],
439
- name: headingMatch[2].trim(),
440
- };
441
- }
442
- // Fallback: try bare version match
443
- const versionMatch = cleaned.match(/v(\d+\.\d+)/);
444
- return {
445
- version: versionMatch ? versionMatch[0] : 'v1.0',
446
- name: 'milestone',
447
- };
448
- } catch (err) {
449
- logger.warn('Failed to load milestone info, using fallback', { error: err.message });
450
- return { version: 'v1.0', name: 'milestone' };
451
- }
452
- }
453
-
454
- /**
455
- * Returns a filter function that checks whether a phase directory belongs
456
- * to the current milestone based on ROADMAP.md phase headings.
457
- * If no ROADMAP exists or no phases are listed, returns a pass-all filter.
458
- */
459
- function getMilestonePhaseFilter(cwd) {
460
- const milestonePhaseNums = new Set();
461
- try {
462
- const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
463
- const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
464
- let m;
465
- while ((m = phasePattern.exec(roadmap)) !== null) {
466
- milestonePhaseNums.add(m[1]);
467
- }
468
- } catch (err) {
469
- logger.warn('Failed to parse milestone phases from roadmap', { error: err.message });
470
- }
471
-
472
- if (milestonePhaseNums.size === 0) {
473
- const passAll = () => true;
474
- passAll.phaseCount = 0;
475
- return passAll;
476
- }
477
-
478
- const normalized = new Set(
479
- [...milestonePhaseNums].map(n => (n.replace(/^0+/, '') || '0').toLowerCase())
480
- );
481
-
482
- function isDirInMilestone(dirName) {
483
- const m = dirName.match(/^0*(\d+[A-Za-z]?(?:\.\d+)*)/);
484
- if (!m) return false;
485
- return normalized.has(m[1].toLowerCase());
486
- }
487
- isDirInMilestone.phaseCount = milestonePhaseNums.size;
488
- return isDirInMilestone;
489
- }
490
-
491
- module.exports = {
492
- MODEL_PROFILES,
493
- output,
494
- error,
495
- safeReadFile,
496
- loadConfig,
497
- isGitIgnored,
498
- execGit,
499
- escapeRegex,
500
- normalizePhaseName,
501
- comparePhaseNum,
502
- searchPhaseInDir,
503
- findPhaseInternal,
504
- getArchivedPhaseDirs,
505
- getRoadmapPhaseInternal,
506
- resolveModelInternal,
507
- pathExistsInternal,
508
- generateSlugInternal,
509
- getMilestoneInfo,
510
- getMilestonePhaseFilter,
511
- toPosixPath,
512
- };
1
+ /**
2
+ * Core — Shared utilities, constants, and internal helpers
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { safeExec, auditExec } = require('./safe-exec.cjs');
8
+ const { defaultLogger: logger } = require('./logger.cjs');
9
+
10
+ // ─── Path helpers ────────────────────────────────────────────────────────────
11
+
12
+ /** Normalize a relative path to always use forward slashes (cross-platform). */
13
+ function toPosixPath(p) {
14
+ return p.split(path.sep).join('/');
15
+ }
16
+
17
+ // ─── Model Profile Table ─────────────────────────────────────────────────────
18
+
19
+ const MODEL_PROFILES = {
20
+ 'ez-planner': { quality: 'opus', balanced: 'opus', budget: 'sonnet' },
21
+ 'ez-roadmapper': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
22
+ 'ez-executor': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
23
+ 'ez-phase-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
24
+ 'ez-project-researcher': { quality: 'opus', balanced: 'sonnet', budget: 'haiku' },
25
+ 'ez-debugger': { quality: 'opus', balanced: 'sonnet', budget: 'sonnet' },
26
+ 'ez-codebase-mapper': { quality: 'sonnet', balanced: 'haiku', budget: 'haiku' },
27
+ 'ez-verifier': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
28
+ 'ez-plan-checker': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
29
+ 'ez-ui-auditor': { quality: 'sonnet', balanced: 'sonnet', budget: 'haiku' },
30
+ };
31
+
32
+ // ─── Output helpers ───────────────────────────────────────────────────────────
33
+
34
+ function output(result, raw, rawValue) {
35
+ if (raw && rawValue !== undefined) {
36
+ process.stdout.write(String(rawValue));
37
+ } else {
38
+ const json = JSON.stringify(result, null, 2);
39
+ // Large payloads exceed Claude Code's Bash tool buffer (~50KB).
40
+ // Write to tmpfile and output the path prefixed with @file: so callers can detect it.
41
+ if (json.length > 50000) {
42
+ const tmpPath = path.join(require('os').tmpdir(), `${Date.now()}.json`);
43
+ fs.writeFileSync(tmpPath, json, 'utf-8');
44
+ process.stdout.write('@file:' + tmpPath);
45
+ } else {
46
+ process.stdout.write(json);
47
+ }
48
+ }
49
+ process.exit(0);
50
+ }
51
+
52
+ function error(message) {
53
+ process.stderr.write('Error: ' + message + '\n');
54
+ process.exit(1);
55
+ }
56
+
57
+ // ─── File & Config utilities ──────────────────────────────────────────────────
58
+
59
+ function safeReadFile(filePath) {
60
+ try {
61
+ return fs.readFileSync(filePath, 'utf-8');
62
+ } catch (err) {
63
+ logger.warn('safeReadFile failed', { filePath, error: err.message });
64
+ return null;
65
+ }
66
+ }
67
+
68
+ function loadConfig(cwd) {
69
+ const configPath = path.join(cwd, '.planning', 'config.json');
70
+ const defaults = {
71
+ model_profile: 'balanced',
72
+ commit_docs: true,
73
+ search_gitignored: false,
74
+ branching_strategy: 'none',
75
+ phase_branch_template: 'ez/phase-{phase}-{slug}',
76
+ milestone_branch_template: 'ez/{milestone}-{slug}',
77
+ research: true,
78
+ plan_checker: true,
79
+ verifier: true,
80
+ nyquist_validation: true,
81
+ parallelization: true,
82
+ brave_search: false,
83
+ };
84
+
85
+ try {
86
+ const raw = fs.readFileSync(configPath, 'utf-8');
87
+ const parsed = JSON.parse(raw);
88
+
89
+ // Migrate deprecated "depth" key to "granularity" with value mapping
90
+ if ('depth' in parsed && !('granularity' in parsed)) {
91
+ const depthToGranularity = { quick: 'coarse', standard: 'standard', comprehensive: 'fine' };
92
+ parsed.granularity = depthToGranularity[parsed.depth] || parsed.depth;
93
+ delete parsed.depth;
94
+ try {
95
+ fs.writeFileSync(configPath, JSON.stringify(parsed, null, 2), 'utf-8');
96
+ } catch (err) {
97
+ logger.warn('Failed to persist migrated config depth->granularity', { configPath, error: err.message });
98
+ }
99
+ }
100
+
101
+ const get = (key, nested) => {
102
+ if (parsed[key] !== undefined) return parsed[key];
103
+ if (nested && parsed[nested.section] && parsed[nested.section][nested.field] !== undefined) {
104
+ return parsed[nested.section][nested.field];
105
+ }
106
+ return undefined;
107
+ };
108
+
109
+ const parallelization = (() => {
110
+ const val = get('parallelization');
111
+ if (typeof val === 'boolean') return val;
112
+ if (typeof val === 'object' && val !== null && 'enabled' in val) return val.enabled;
113
+ return defaults.parallelization;
114
+ })();
115
+
116
+ return {
117
+ model_profile: get('model_profile') ?? defaults.model_profile,
118
+ commit_docs: get('commit_docs', { section: 'planning', field: 'commit_docs' }) ?? defaults.commit_docs,
119
+ search_gitignored: get('search_gitignored', { section: 'planning', field: 'search_gitignored' }) ?? defaults.search_gitignored,
120
+ branching_strategy: get('branching_strategy', { section: 'git', field: 'branching_strategy' }) ?? defaults.branching_strategy,
121
+ phase_branch_template: get('phase_branch_template', { section: 'git', field: 'phase_branch_template' }) ?? defaults.phase_branch_template,
122
+ milestone_branch_template: get('milestone_branch_template', { section: 'git', field: 'milestone_branch_template' }) ?? defaults.milestone_branch_template,
123
+ research: get('research', { section: 'workflow', field: 'research' }) ?? defaults.research,
124
+ plan_checker: get('plan_checker', { section: 'workflow', field: 'plan_check' }) ?? defaults.plan_checker,
125
+ verifier: get('verifier', { section: 'workflow', field: 'verifier' }) ?? defaults.verifier,
126
+ nyquist_validation: get('nyquist_validation', { section: 'workflow', field: 'nyquist_validation' }) ?? defaults.nyquist_validation,
127
+ parallelization,
128
+ brave_search: get('brave_search') ?? defaults.brave_search,
129
+ model_overrides: parsed.model_overrides || null,
130
+ };
131
+ } catch (err) {
132
+ logger.warn('Failed to load config, using defaults', { configPath, error: err.message });
133
+ return defaults;
134
+ }
135
+ }
136
+
137
+ // ─── Git utilities ────────────────────────────────────────────────────────────
138
+
139
+ async function isGitIgnored(cwd, targetPath) {
140
+ try {
141
+ // --no-index checks .gitignore rules regardless of whether the file is tracked.
142
+ // Without it, git check-ignore returns "not ignored" for tracked files even when
143
+ // .gitignore explicitly lists them — a common source of confusion when .planning/
144
+ // was committed before being added to .gitignore.
145
+ const safePath = targetPath.replace(/[^a-zA-Z0-9._\-/]/g, '');
146
+ await auditExec('git', ['check-ignore', '-q', '--no-index', '--', safePath], {
147
+ cwd,
148
+ context: 'isGitIgnored',
149
+ timeout: 5000
150
+ });
151
+ return true;
152
+ } catch (err) {
153
+ logger.warn('git check-ignore failed, assuming not ignored', { targetPath, error: err.message });
154
+ return false;
155
+ }
156
+ }
157
+
158
+ async function execGit(cwd, args) {
159
+ try {
160
+ const stdout = await auditExec('git', args, {
161
+ cwd,
162
+ context: 'execGit',
163
+ timeout: 30000
164
+ });
165
+ return { exitCode: 0, stdout: stdout.trim(), stderr: '' };
166
+ } catch (err) {
167
+ logger.warn('execGit failed', { args, error: err.message });
168
+ return {
169
+ exitCode: err.status ?? 1,
170
+ stdout: (err.stdout ?? '').toString().trim(),
171
+ stderr: (err.stderr ?? '').toString().trim(),
172
+ };
173
+ }
174
+ }
175
+
176
+ // ─── Phase utilities ──────────────────────────────────────────────────────────
177
+
178
+ function escapeRegex(value) {
179
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
180
+ }
181
+
182
+ function normalizePhaseName(phase) {
183
+ const match = String(phase).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
184
+ if (!match) return phase;
185
+ const padded = match[1].padStart(2, '0');
186
+ const letter = match[2] ? match[2].toUpperCase() : '';
187
+ const decimal = match[3] || '';
188
+ return padded + letter + decimal;
189
+ }
190
+
191
+ function comparePhaseNum(a, b) {
192
+ const pa = String(a).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
193
+ const pb = String(b).match(/^(\d+)([A-Z])?((?:\.\d+)*)/i);
194
+ if (!pa || !pb) return String(a).localeCompare(String(b));
195
+ const intDiff = parseInt(pa[1], 10) - parseInt(pb[1], 10);
196
+ if (intDiff !== 0) return intDiff;
197
+ // No letter sorts before letter: 12 < 12A < 12B
198
+ const la = (pa[2] || '').toUpperCase();
199
+ const lb = (pb[2] || '').toUpperCase();
200
+ if (la !== lb) {
201
+ if (!la) return -1;
202
+ if (!lb) return 1;
203
+ return la < lb ? -1 : 1;
204
+ }
205
+ // Segment-by-segment decimal comparison: 12A < 12A.1 < 12A.1.2 < 12A.2
206
+ const aDecParts = pa[3] ? pa[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
207
+ const bDecParts = pb[3] ? pb[3].slice(1).split('.').map(p => parseInt(p, 10)) : [];
208
+ const maxLen = Math.max(aDecParts.length, bDecParts.length);
209
+ if (aDecParts.length === 0 && bDecParts.length > 0) return -1;
210
+ if (bDecParts.length === 0 && aDecParts.length > 0) return 1;
211
+ for (let i = 0; i < maxLen; i++) {
212
+ const av = Number.isFinite(aDecParts[i]) ? aDecParts[i] : 0;
213
+ const bv = Number.isFinite(bDecParts[i]) ? bDecParts[i] : 0;
214
+ if (av !== bv) return av - bv;
215
+ }
216
+ return 0;
217
+ }
218
+
219
+ function searchPhaseInDir(baseDir, relBase, normalized) {
220
+ try {
221
+ const entries = fs.readdirSync(baseDir, { withFileTypes: true });
222
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
223
+ const match = dirs.find(d => d.startsWith(normalized));
224
+ if (!match) return null;
225
+
226
+ const dirMatch = match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
227
+ const phaseNumber = dirMatch ? dirMatch[1] : normalized;
228
+ const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
229
+ const phaseDir = path.join(baseDir, match);
230
+ const phaseFiles = fs.readdirSync(phaseDir);
231
+
232
+ const plans = phaseFiles.filter(f => f.endsWith('-PLAN.md') || f === 'PLAN.md').sort();
233
+ const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
234
+ const hasResearch = phaseFiles.some(f => f.endsWith('-RESEARCH.md') || f === 'RESEARCH.md');
235
+ const hasContext = phaseFiles.some(f => f.endsWith('-CONTEXT.md') || f === 'CONTEXT.md');
236
+ const hasVerification = phaseFiles.some(f => f.endsWith('-VERIFICATION.md') || f === 'VERIFICATION.md');
237
+
238
+ const completedPlanIds = new Set(
239
+ summaries.map(s => s.replace('-SUMMARY.md', '').replace('SUMMARY.md', ''))
240
+ );
241
+ const incompletePlans = plans.filter(p => {
242
+ const planId = p.replace('-PLAN.md', '').replace('PLAN.md', '');
243
+ return !completedPlanIds.has(planId);
244
+ });
245
+
246
+ return {
247
+ found: true,
248
+ directory: toPosixPath(path.join(relBase, match)),
249
+ phase_number: phaseNumber,
250
+ phase_name: phaseName,
251
+ phase_slug: phaseName ? phaseName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') : null,
252
+ plans,
253
+ summaries,
254
+ incomplete_plans: incompletePlans,
255
+ has_research: hasResearch,
256
+ has_context: hasContext,
257
+ has_verification: hasVerification,
258
+ };
259
+ } catch (err) {
260
+ logger.warn('Failed to search phase directory', { baseDir, normalized, error: err.message });
261
+ return null;
262
+ }
263
+ }
264
+
265
+ function findPhaseInternal(cwd, phase) {
266
+ if (!phase) return null;
267
+
268
+ const phasesDir = path.join(cwd, '.planning', 'phases');
269
+ const normalized = normalizePhaseName(phase);
270
+
271
+ // Search current phases first
272
+ const current = searchPhaseInDir(phasesDir, '.planning/phases', normalized);
273
+ if (current) return current;
274
+
275
+ // Search archived milestone phases (newest first)
276
+ const milestonesDir = path.join(cwd, '.planning', 'milestones');
277
+ if (!fs.existsSync(milestonesDir)) return null;
278
+
279
+ try {
280
+ const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
281
+ const archiveDirs = milestoneEntries
282
+ .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
283
+ .map(e => e.name)
284
+ .sort()
285
+ .reverse();
286
+
287
+ for (const archiveName of archiveDirs) {
288
+ const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
289
+ const archivePath = path.join(milestonesDir, archiveName);
290
+ const relBase = '.planning/milestones/' + archiveName;
291
+ const result = searchPhaseInDir(archivePath, relBase, normalized);
292
+ if (result) {
293
+ result.archived = version;
294
+ return result;
295
+ }
296
+ }
297
+ } catch (err) {
298
+ logger.warn('Failed while searching archived milestone phases', { milestonesDir, error: err.message });
299
+ }
300
+
301
+ return null;
302
+ }
303
+
304
+ function getArchivedPhaseDirs(cwd) {
305
+ const milestonesDir = path.join(cwd, '.planning', 'milestones');
306
+ const results = [];
307
+
308
+ if (!fs.existsSync(milestonesDir)) return results;
309
+
310
+ try {
311
+ const milestoneEntries = fs.readdirSync(milestonesDir, { withFileTypes: true });
312
+ // Find v*-phases directories, sort newest first
313
+ const phaseDirs = milestoneEntries
314
+ .filter(e => e.isDirectory() && /^v[\d.]+-phases$/.test(e.name))
315
+ .map(e => e.name)
316
+ .sort()
317
+ .reverse();
318
+
319
+ for (const archiveName of phaseDirs) {
320
+ const version = archiveName.match(/^(v[\d.]+)-phases$/)[1];
321
+ const archivePath = path.join(milestonesDir, archiveName);
322
+ const entries = fs.readdirSync(archivePath, { withFileTypes: true });
323
+ const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
324
+
325
+ for (const dir of dirs) {
326
+ results.push({
327
+ name: dir,
328
+ milestone: version,
329
+ basePath: path.join('.planning', 'milestones', archiveName),
330
+ fullPath: path.join(archivePath, dir),
331
+ });
332
+ }
333
+ }
334
+ } catch (err) {
335
+ logger.warn('Failed to enumerate archived phase directories', { milestonesDir, error: err.message });
336
+ }
337
+
338
+ return results;
339
+ }
340
+
341
+ // ─── Roadmap & model utilities ────────────────────────────────────────────────
342
+
343
+ function getRoadmapPhaseInternal(cwd, phaseNum) {
344
+ if (!phaseNum) return null;
345
+ const roadmapPath = path.join(cwd, '.planning', 'ROADMAP.md');
346
+ if (!fs.existsSync(roadmapPath)) return null;
347
+
348
+ try {
349
+ const content = fs.readFileSync(roadmapPath, 'utf-8');
350
+ const escapedPhase = escapeRegex(phaseNum.toString());
351
+ const phasePattern = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}:\\s*([^\\n]+)`, 'i');
352
+ const headerMatch = content.match(phasePattern);
353
+ if (!headerMatch) return null;
354
+
355
+ const phaseName = headerMatch[1].trim();
356
+ const headerIndex = headerMatch.index;
357
+ const restOfContent = content.slice(headerIndex);
358
+ const nextHeaderMatch = restOfContent.match(/\n#{2,4}\s+Phase\s+\d/i);
359
+ const sectionEnd = nextHeaderMatch ? headerIndex + nextHeaderMatch.index : content.length;
360
+ const section = content.slice(headerIndex, sectionEnd).trim();
361
+
362
+ const goalMatch = section.match(/\*\*Goal:\*\*\s*([^\n]+)/i);
363
+ const goal = goalMatch ? goalMatch[1].trim() : null;
364
+
365
+ return {
366
+ found: true,
367
+ phase_number: phaseNum.toString(),
368
+ phase_name: phaseName,
369
+ goal,
370
+ section,
371
+ };
372
+ } catch (err) {
373
+ logger.warn('Failed to read roadmap phase metadata', { roadmapPath, phaseNum, error: err.message });
374
+ return null;
375
+ }
376
+ }
377
+
378
+ function resolveModelInternal(cwd, agentType) {
379
+ const config = loadConfig(cwd);
380
+
381
+ // Check per-agent override first
382
+ const override = config.model_overrides?.[agentType];
383
+ if (override) {
384
+ return override === 'opus' ? 'inherit' : override;
385
+ }
386
+
387
+ // Fall back to profile lookup
388
+ const profile = config.model_profile || 'balanced';
389
+ const agentModels = MODEL_PROFILES[agentType];
390
+ if (!agentModels) return 'sonnet';
391
+ const resolved = agentModels[profile] || agentModels['balanced'] || 'sonnet';
392
+ return resolved === 'opus' ? 'inherit' : resolved;
393
+ }
394
+
395
+ // ─── Misc utilities ───────────────────────────────────────────────────────────
396
+
397
+ function pathExistsInternal(cwd, targetPath) {
398
+ const fullPath = path.isAbsolute(targetPath) ? targetPath : path.join(cwd, targetPath);
399
+ try {
400
+ fs.statSync(fullPath);
401
+ return true;
402
+ } catch (err) {
403
+ logger.warn('Path existence check failed', { fullPath, error: err.message });
404
+ return false;
405
+ }
406
+ }
407
+
408
+ function generateSlugInternal(text) {
409
+ if (!text) return null;
410
+ return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
411
+ }
412
+
413
+ function getMilestoneInfo(cwd) {
414
+ try {
415
+ const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
416
+
417
+ // First: check for list-format roadmaps using 🚧 (in-progress) marker
418
+ // e.g. "- 🚧 **v2.1 Belgium** — Phases 24-28 (in progress)"
419
+ const inProgressMatch = roadmap.match(/🚧\s*\*\*v(\d+\.\d+)\s+([^*]+)\*\*/);
420
+ if (inProgressMatch) {
421
+ return {
422
+ version: 'v' + inProgressMatch[1],
423
+ name: inProgressMatch[2].trim(),
424
+ };
425
+ }
426
+
427
+ // Second: heading-format roadmaps — strip shipped milestones in <details> blocks
428
+ const cleaned = roadmap.replace(/<details>[\s\S]*?<\/details>/gi, '');
429
+ // Extract version and name from the same ## heading for consistency
430
+ const headingMatch = cleaned.match(/## .*v(\d+\.\d+)[:\s]+([^\n(]+)/);
431
+ if (headingMatch) {
432
+ return {
433
+ version: 'v' + headingMatch[1],
434
+ name: headingMatch[2].trim(),
435
+ };
436
+ }
437
+ // Fallback: try bare version match
438
+ const versionMatch = cleaned.match(/v(\d+\.\d+)/);
439
+ return {
440
+ version: versionMatch ? versionMatch[0] : 'v1.0',
441
+ name: 'milestone',
442
+ };
443
+ } catch (err) {
444
+ logger.warn('Failed to load milestone info, using fallback', { error: err.message });
445
+ return { version: 'v1.0', name: 'milestone' };
446
+ }
447
+ }
448
+
449
+ /**
450
+ * Returns a filter function that checks whether a phase directory belongs
451
+ * to the current milestone based on ROADMAP.md phase headings.
452
+ * If no ROADMAP exists or no phases are listed, returns a pass-all filter.
453
+ */
454
+ function getMilestonePhaseFilter(cwd) {
455
+ const milestonePhaseNums = new Set();
456
+ try {
457
+ const roadmap = fs.readFileSync(path.join(cwd, '.planning', 'ROADMAP.md'), 'utf-8');
458
+ const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi;
459
+ let m;
460
+ while ((m = phasePattern.exec(roadmap)) !== null) {
461
+ milestonePhaseNums.add(m[1]);
462
+ }
463
+ } catch (err) {
464
+ logger.warn('Failed to parse milestone phases from roadmap', { error: err.message });
465
+ }
466
+
467
+ if (milestonePhaseNums.size === 0) {
468
+ const passAll = () => true;
469
+ passAll.phaseCount = 0;
470
+ return passAll;
471
+ }
472
+
473
+ const normalized = new Set(
474
+ [...milestonePhaseNums].map(n => (n.replace(/^0+/, '') || '0').toLowerCase())
475
+ );
476
+
477
+ function isDirInMilestone(dirName) {
478
+ const m = dirName.match(/^0*(\d+[A-Za-z]?(?:\.\d+)*)/);
479
+ if (!m) return false;
480
+ return normalized.has(m[1].toLowerCase());
481
+ }
482
+ isDirInMilestone.phaseCount = milestonePhaseNums.size;
483
+ return isDirInMilestone;
484
+ }
485
+
486
+ module.exports = {
487
+ MODEL_PROFILES,
488
+ output,
489
+ error,
490
+ safeReadFile,
491
+ loadConfig,
492
+ isGitIgnored,
493
+ execGit,
494
+ escapeRegex,
495
+ normalizePhaseName,
496
+ comparePhaseNum,
497
+ searchPhaseInDir,
498
+ findPhaseInternal,
499
+ getArchivedPhaseDirs,
500
+ getRoadmapPhaseInternal,
501
+ resolveModelInternal,
502
+ pathExistsInternal,
503
+ generateSlugInternal,
504
+ getMilestoneInfo,
505
+ getMilestonePhaseFilter,
506
+ toPosixPath,
507
+ };