@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.
- package/README.md +735 -462
- package/agents/ez-architect-agent.md +267 -0
- package/agents/ez-backend-agent.md +303 -0
- package/agents/ez-chief-strategist.md +271 -0
- package/agents/ez-codebase-mapper.md +770 -770
- package/agents/ez-context-manager.md +319 -0
- package/agents/ez-debugger.md +1255 -1255
- package/agents/ez-design-expert.md +347 -0
- package/agents/ez-devops-agent.md +331 -0
- package/agents/ez-executor.md +487 -487
- package/agents/ez-frontend-agent.md +322 -0
- package/agents/ez-phase-researcher.md +553 -553
- package/agents/ez-planner.md +1307 -1307
- package/agents/ez-product-engineer.md +435 -0
- package/agents/ez-project-researcher.md +629 -629
- package/agents/ez-qa-agent.md +320 -0
- package/agents/ez-release-agent.md +333 -0
- package/agents/ez-requirements-agent.md +377 -0
- package/agents/ez-roadmapper.md +650 -650
- package/agents/ez-technical-writer.md +551 -0
- package/agents/ez-ux-expert.md +393 -0
- package/agents/ez-verifier.md +579 -579
- package/bin/guards/autonomy-guard.cjs +346 -0
- package/bin/guards/context-budget-guard.cjs +278 -0
- package/bin/guards/hallucination-guard.cjs +380 -0
- package/bin/guards/hidden-state-guard.cjs +182 -0
- package/bin/guards/team-overhead-guard.cjs +266 -0
- package/bin/guards/tool-sprawl-guard.cjs +271 -0
- package/bin/install.js +3221 -3272
- package/bin/lib/analytics/analytics-collector.cjs +86 -0
- package/bin/lib/analytics/analytics-reporter.cjs +130 -0
- package/bin/lib/analytics/cohort-analyzer.cjs +138 -0
- package/bin/lib/analytics/funnel-analyzer.cjs +147 -0
- package/bin/lib/analytics/nps-tracker.cjs +147 -0
- package/bin/lib/archetype-detector.cjs +289 -0
- package/bin/lib/assistant-adapter.cjs +361 -0
- package/bin/lib/audit-exec.cjs +175 -0
- package/bin/lib/auth.cjs +176 -0
- package/bin/lib/backup-service.cjs +422 -0
- package/bin/lib/bdd-validator.cjs +622 -0
- package/bin/lib/business-flow-mapper.cjs +429 -0
- package/bin/lib/circuit-breaker.cjs +276 -0
- package/bin/lib/code-complexity-analyzer.cjs +360 -0
- package/bin/lib/codebase-analyzer.cjs +241 -0
- package/bin/lib/commands.cjs +691 -0
- package/bin/lib/config.cjs +236 -0
- package/bin/lib/constraint-extractor.cjs +526 -0
- package/bin/lib/content-scanner.cjs +238 -0
- package/bin/lib/context-cache.cjs +154 -0
- package/bin/lib/context-compressor.cjs +102 -0
- package/bin/lib/context-deduplicator.cjs +105 -0
- package/bin/lib/context-errors.cjs +78 -0
- package/bin/lib/context-manager.cjs +338 -0
- package/bin/lib/context-metadata-tracker.cjs +140 -0
- package/bin/lib/context-relevance-scorer.cjs +99 -0
- package/bin/lib/core.cjs +507 -0
- package/bin/lib/cost-alerts.cjs +174 -0
- package/bin/lib/cost-tracker.cjs +275 -0
- package/bin/lib/crash-recovery.cjs +220 -0
- package/bin/lib/dependency-graph.cjs +319 -0
- package/bin/lib/deploy/deploy-audit-log.cjs +76 -0
- package/bin/lib/deploy/deploy-detector.cjs +69 -0
- package/bin/lib/deploy/deploy-env-manager.cjs +109 -0
- package/bin/lib/deploy/deploy-health-check.cjs +88 -0
- package/bin/lib/deploy/deploy-pre-flight.cjs +57 -0
- package/bin/lib/deploy/deploy-rollback.cjs +72 -0
- package/bin/lib/deploy/deploy-runner.cjs +97 -0
- package/bin/lib/deploy/deploy-status.cjs +74 -0
- package/bin/lib/discussion-synthesizer.cjs +439 -0
- package/bin/lib/error-cache.cjs +114 -0
- package/bin/lib/error-registry.cjs +177 -0
- package/bin/lib/file-access.cjs +207 -0
- package/bin/lib/file-lock.cjs +236 -0
- package/bin/lib/finops/budget-enforcer.cjs +126 -0
- package/bin/lib/finops/cost-reporter.cjs +132 -0
- package/bin/lib/finops/finops-analyzer.cjs +112 -0
- package/bin/lib/finops/spot-manager.cjs +118 -0
- package/bin/lib/framework-detector.cjs +396 -0
- package/bin/lib/frontmatter.cjs +313 -0
- package/bin/lib/fs-utils.cjs +153 -0
- package/bin/lib/gate-executor.cjs +272 -0
- package/bin/lib/gates/README.md +374 -0
- package/bin/lib/gates/gate-01-requirement.cjs +303 -0
- package/bin/lib/gates/gate-02-architecture.cjs +555 -0
- package/bin/lib/gates/gate-03-code.cjs +635 -0
- package/bin/lib/gates/gate-04-security.cjs +829 -0
- package/bin/lib/git-errors.cjs +83 -0
- package/bin/lib/git-utils.cjs +321 -0
- package/bin/lib/git-workflow-engine.cjs +1157 -0
- package/bin/lib/health-check.cjs +227 -0
- package/bin/lib/index.cjs +279 -0
- package/bin/lib/init.cjs +725 -0
- package/bin/lib/lock-logger.cjs +194 -0
- package/bin/lib/lock-state.cjs +263 -0
- package/bin/lib/lockfile-validator.cjs +227 -0
- package/bin/lib/log-rotation.cjs +71 -0
- package/bin/lib/logger.cjs +125 -0
- package/bin/lib/memory-compression.cjs +256 -0
- package/bin/lib/milestone.cjs +247 -0
- package/bin/lib/model-provider.cjs +241 -0
- package/bin/lib/package-manager-detector.cjs +203 -0
- package/bin/lib/package-manager-executor.cjs +385 -0
- package/bin/lib/package-manager-service.cjs +216 -0
- package/bin/lib/perf/api-monitor.cjs +88 -0
- package/bin/lib/perf/db-optimizer.cjs +78 -0
- package/bin/lib/perf/frontend-performance.cjs +56 -0
- package/bin/lib/perf/perf-analyzer.cjs +77 -0
- package/bin/lib/perf/perf-baseline.cjs +102 -0
- package/bin/lib/perf/perf-reporter.cjs +117 -0
- package/bin/lib/perf/regression-detector.cjs +92 -0
- package/bin/lib/phase.cjs +963 -0
- package/bin/lib/planning-write.cjs +123 -0
- package/bin/lib/project-reporter.cjs +565 -0
- package/bin/lib/quality-gate.cjs +332 -0
- package/bin/lib/quality-metrics.cjs +324 -0
- package/bin/lib/recovery-manager.cjs +98 -0
- package/bin/lib/release-validator.cjs +617 -0
- package/bin/lib/retry.cjs +119 -0
- package/bin/lib/roadmap.cjs +309 -0
- package/bin/lib/safe-exec.cjs +173 -0
- package/bin/lib/safe-path.cjs +130 -0
- package/bin/lib/security-errors.cjs +62 -0
- package/bin/lib/session-chain.cjs +304 -0
- package/bin/lib/session-errors.cjs +81 -0
- package/bin/lib/session-export.cjs +251 -0
- package/bin/lib/session-import.cjs +262 -0
- package/bin/lib/session-manager.cjs +280 -0
- package/bin/lib/skill-context.cjs +148 -0
- package/bin/lib/skill-matcher.cjs +236 -0
- package/bin/lib/skill-registry.cjs +360 -0
- package/bin/lib/skill-resolver.cjs +449 -0
- package/bin/lib/skill-triggers.cjs +90 -0
- package/bin/lib/skill-validator.cjs +270 -0
- package/bin/lib/skill-versioning.cjs +355 -0
- package/bin/lib/stack-detector.cjs +399 -0
- package/bin/lib/state.cjs +736 -0
- package/bin/lib/tech-debt-analyzer.cjs +309 -0
- package/bin/lib/temp-file.cjs +239 -0
- package/bin/lib/template.cjs +223 -0
- package/bin/lib/test-file-lock.cjs +112 -0
- package/bin/lib/test-graceful.cjs +93 -0
- package/bin/lib/test-logger.cjs +60 -0
- package/bin/lib/test-safe-exec.cjs +38 -0
- package/bin/lib/test-safe-path.cjs +33 -0
- package/bin/lib/test-temp-file.cjs +125 -0
- package/bin/lib/tier-manager.cjs +428 -0
- package/bin/lib/timeout-exec.cjs +63 -0
- package/bin/lib/tradeoff-analyzer.cjs +284 -0
- package/bin/lib/url-fetch.cjs +170 -0
- package/bin/lib/verify.cjs +863 -0
- package/bin/update.js +217 -214
- package/commands/deploy.cjs +53 -0
- package/commands/ez/add-tests.md +41 -41
- package/commands/ez/audit-milestone.md +36 -36
- package/commands/ez/complete-milestone.md +136 -136
- package/commands/ez/discuss-phase.md +90 -90
- package/commands/ez/execute-phase.md +52 -41
- package/commands/ez/help.md +22 -22
- package/commands/ez/map-codebase.md +71 -71
- package/commands/ez/new-milestone.md +44 -44
- package/commands/ez/new-project.md +51 -42
- package/commands/ez/plan-phase.md +53 -45
- package/commands/ez/progress.md +36 -24
- package/commands/ez/quick.md +45 -45
- package/commands/ez/resume-work.md +40 -40
- package/commands/ez/run-phase.md +580 -0
- package/commands/ez/settings.md +36 -36
- package/commands/ez/update.md +37 -37
- package/commands/ez/verify-work.md +402 -38
- package/commands/health-check.cjs +44 -0
- package/commands/rollback.cjs +47 -0
- package/ez-agents/bin/ez-tools.cjs +1692 -716
- package/ez-agents/bin/guards/autonomy-guard.cjs +346 -0
- package/ez-agents/bin/guards/context-budget-guard.cjs +247 -0
- package/ez-agents/bin/guards/hallucination-guard.cjs +271 -0
- package/ez-agents/bin/guards/hidden-state-guard.cjs +182 -0
- package/ez-agents/bin/guards/team-overhead-guard.cjs +266 -0
- package/ez-agents/bin/guards/tool-sprawl-guard.cjs +271 -0
- package/ez-agents/bin/lib/analytics/analytics-collector.cjs +86 -0
- package/ez-agents/bin/lib/analytics/analytics-reporter.cjs +130 -0
- package/ez-agents/bin/lib/analytics/cohort-analyzer.cjs +138 -0
- package/ez-agents/bin/lib/analytics/funnel-analyzer.cjs +147 -0
- package/ez-agents/bin/lib/analytics/nps-tracker.cjs +147 -0
- package/ez-agents/bin/lib/archetype-detector.cjs +289 -0
- package/ez-agents/bin/lib/audit-exec.cjs +166 -167
- package/ez-agents/bin/lib/auth.cjs +176 -176
- package/ez-agents/bin/lib/backup-service.cjs +422 -0
- package/ez-agents/bin/lib/bdd-validator.cjs +622 -0
- package/ez-agents/bin/lib/business-flow-mapper.cjs +429 -0
- package/ez-agents/bin/lib/code-complexity-analyzer.cjs +360 -0
- package/ez-agents/bin/lib/codebase-analyzer.cjs +241 -0
- package/ez-agents/bin/lib/commands.cjs +685 -685
- package/ez-agents/bin/lib/config.cjs +41 -1
- package/ez-agents/bin/lib/constraint-extractor.cjs +526 -0
- package/ez-agents/bin/lib/content-scanner.cjs +238 -0
- package/ez-agents/bin/lib/context-cache.cjs +154 -0
- package/ez-agents/bin/lib/context-errors.cjs +71 -0
- package/ez-agents/bin/lib/context-manager.cjs +220 -0
- package/ez-agents/bin/lib/core.cjs +507 -512
- package/ez-agents/bin/lib/cost-tracker.cjs +243 -0
- package/ez-agents/bin/lib/crash-recovery.cjs +172 -0
- package/ez-agents/bin/lib/dependency-graph.cjs +319 -0
- package/ez-agents/bin/lib/deploy/deploy-audit-log.cjs +76 -0
- package/ez-agents/bin/lib/deploy/deploy-detector.cjs +69 -0
- package/ez-agents/bin/lib/deploy/deploy-env-manager.cjs +109 -0
- package/ez-agents/bin/lib/deploy/deploy-health-check.cjs +88 -0
- package/ez-agents/bin/lib/deploy/deploy-pre-flight.cjs +57 -0
- package/ez-agents/bin/lib/deploy/deploy-rollback.cjs +72 -0
- package/ez-agents/bin/lib/deploy/deploy-runner.cjs +97 -0
- package/ez-agents/bin/lib/deploy/deploy-status.cjs +74 -0
- package/ez-agents/bin/lib/discussion-synthesizer.cjs +458 -0
- package/ez-agents/bin/lib/file-access.cjs +207 -0
- package/ez-agents/bin/lib/finops/budget-enforcer.cjs +126 -0
- package/ez-agents/bin/lib/finops/cost-reporter.cjs +132 -0
- package/ez-agents/bin/lib/finops/finops-analyzer.cjs +112 -0
- package/ez-agents/bin/lib/finops/spot-manager.cjs +118 -0
- package/ez-agents/bin/lib/framework-detector.cjs +396 -0
- package/ez-agents/bin/lib/frontmatter.cjs +3 -1
- package/ez-agents/bin/lib/gates/README.md +374 -0
- package/ez-agents/bin/lib/gates/gate-01-requirement.cjs +303 -0
- package/ez-agents/bin/lib/gates/gate-02-architecture.cjs +555 -0
- package/ez-agents/bin/lib/gates/gate-03-code.cjs +635 -0
- package/ez-agents/bin/lib/gates/gate-04-security.cjs +829 -0
- package/ez-agents/bin/lib/git-errors.cjs +83 -0
- package/ez-agents/bin/lib/git-utils.cjs +118 -0
- package/ez-agents/bin/lib/git-workflow-engine.cjs +1157 -0
- package/ez-agents/bin/lib/health-check.cjs +162 -162
- package/ez-agents/bin/lib/index.cjs +40 -2
- package/ez-agents/bin/lib/init.cjs +0 -2
- package/ez-agents/bin/lib/lockfile-validator.cjs +227 -0
- package/ez-agents/bin/lib/log-rotation.cjs +71 -0
- package/ez-agents/bin/lib/logger.cjs +99 -154
- package/ez-agents/bin/lib/memory-compression.cjs +256 -0
- package/ez-agents/bin/lib/package-manager-detector.cjs +203 -0
- package/ez-agents/bin/lib/package-manager-executor.cjs +385 -0
- package/ez-agents/bin/lib/package-manager-service.cjs +216 -0
- package/ez-agents/bin/lib/perf/api-monitor.cjs +88 -0
- package/ez-agents/bin/lib/perf/db-optimizer.cjs +78 -0
- package/ez-agents/bin/lib/perf/frontend-performance.cjs +56 -0
- package/ez-agents/bin/lib/perf/perf-analyzer.cjs +77 -0
- package/ez-agents/bin/lib/perf/perf-baseline.cjs +102 -0
- package/ez-agents/bin/lib/perf/perf-reporter.cjs +117 -0
- package/ez-agents/bin/lib/perf/regression-detector.cjs +92 -0
- package/ez-agents/bin/lib/project-reporter.cjs +502 -0
- package/ez-agents/bin/lib/quality-gate.cjs +332 -0
- package/ez-agents/bin/lib/recovery-manager.cjs +98 -0
- package/ez-agents/bin/lib/release-validator.cjs +617 -0
- package/ez-agents/bin/lib/safe-exec.cjs +128 -214
- package/ez-agents/bin/lib/security-errors.cjs +62 -0
- package/ez-agents/bin/lib/session-chain.cjs +304 -0
- package/ez-agents/bin/lib/session-errors.cjs +81 -0
- package/ez-agents/bin/lib/session-export.cjs +251 -0
- package/ez-agents/bin/lib/session-import.cjs +262 -0
- package/ez-agents/bin/lib/session-manager.cjs +280 -0
- package/ez-agents/bin/lib/skill-context.cjs +148 -0
- package/ez-agents/bin/lib/skill-matcher.cjs +236 -0
- package/ez-agents/bin/lib/skill-registry.cjs +341 -0
- package/ez-agents/bin/lib/skill-resolver.cjs +449 -0
- package/ez-agents/bin/lib/skill-triggers.cjs +90 -0
- package/ez-agents/bin/lib/skill-validator.cjs +270 -0
- package/ez-agents/bin/lib/skill-versioning.cjs +355 -0
- package/ez-agents/bin/lib/stack-detector.cjs +399 -0
- package/ez-agents/bin/lib/tech-debt-analyzer.cjs +309 -0
- package/ez-agents/bin/lib/tier-manager.cjs +428 -0
- package/ez-agents/bin/lib/tradeoff-analyzer.cjs +284 -0
- package/ez-agents/bin/lib/url-fetch.cjs +170 -0
- package/ez-agents/bin/lib/verify.cjs +863 -863
- package/ez-agents/references/decimal-phase-calculation.md +65 -65
- package/ez-agents/references/git-integration.md +248 -248
- package/ez-agents/references/git-planning-commit.md +38 -38
- package/ez-agents/references/metrics-schema.md +118 -0
- package/ez-agents/references/model-profile-resolution.md +34 -34
- package/ez-agents/references/model-profiles.md +93 -93
- package/ez-agents/references/phase-argument-parsing.md +61 -61
- package/ez-agents/references/planning-config.md +340 -200
- package/ez-agents/references/tier-strategy.md +103 -0
- package/ez-agents/references/ui-brand.md +160 -160
- package/ez-agents/references/verification-patterns.md +612 -612
- package/ez-agents/templates/DEBUG.md +164 -164
- package/ez-agents/templates/UAT.md +247 -247
- package/ez-agents/templates/agent-output-format.md +404 -0
- package/ez-agents/templates/bdd-feature.md +173 -0
- package/ez-agents/templates/codebase/architecture.md +255 -255
- package/ez-agents/templates/codebase/structure.md +285 -285
- package/ez-agents/templates/copilot-instructions.md +7 -7
- package/ez-agents/templates/debug-subagent-prompt.md +91 -91
- package/ez-agents/templates/discovery.md +146 -146
- package/ez-agents/templates/discussion.md +68 -0
- package/ez-agents/templates/handoff-protocol.md +294 -0
- package/ez-agents/templates/incident-runbook.md +205 -0
- package/ez-agents/templates/mode-workflow-templates.md +301 -0
- package/ez-agents/templates/phase-prompt.md +610 -610
- package/ez-agents/templates/planner-subagent-prompt.md +117 -117
- package/ez-agents/templates/project.md +184 -184
- package/ez-agents/templates/release-checklist.md +136 -0
- package/ez-agents/templates/research.md +552 -552
- package/ez-agents/templates/rollback-plan.md +201 -0
- package/ez-agents/templates/security-user-setup.md +244 -0
- package/ez-agents/templates/skill-validation-rules.md +476 -0
- package/ez-agents/templates/state.md +180 -176
- package/ez-agents/templates/summary-complex.md +59 -59
- package/ez-agents/tests/gates/gate-01-02.test.cjs +812 -0
- package/ez-agents/tests/gates/gate-03-04.test.cjs +762 -0
- package/ez-agents/tests/gates/gate-05-validator.test.cjs +145 -0
- package/ez-agents/tests/gates/gate-06-docs-validator.test.cjs +244 -0
- package/ez-agents/tests/gates/gate-07-release-validator.test.cjs +219 -0
- package/ez-agents/tests/guards/context-budget-guard.test.cjs +145 -0
- package/ez-agents/tests/guards/edge-case-guards.test.cjs +238 -0
- package/ez-agents/tests/guards/hallucination-guard.test.cjs +124 -0
- package/ez-agents/workflows/audit-milestone.md +1 -1
- package/ez-agents/workflows/autonomous.md +131 -30
- package/ez-agents/workflows/complete-milestone.md +1 -1
- package/ez-agents/workflows/discuss-phase.md +1 -1
- package/ez-agents/workflows/execute-phase.md +169 -3
- package/ez-agents/workflows/help.md +86 -133
- package/ez-agents/workflows/hotfix.md +291 -0
- package/ez-agents/workflows/new-milestone.md +340 -11
- package/ez-agents/workflows/new-project.md +294 -318
- package/ez-agents/workflows/plan-phase.md +22 -40
- package/ez-agents/workflows/progress.md +15 -25
- package/ez-agents/workflows/release.md +253 -0
- package/ez-agents/workflows/resume-session.md +215 -0
- package/ez-agents/workflows/run-phase.md +531 -0
- package/ez-agents/workflows/settings.md +2 -35
- package/hooks/dist/ez-check-update.js +81 -81
- package/hooks/dist/ez-context-monitor.js +148 -141
- package/hooks/dist/ez-statusline.js +115 -115
- package/package.json +78 -64
- package/scripts/fix-qwen-installation.js +144 -144
- package/agents/ez-integration-checker.md +0 -443
- package/agents/ez-nyquist-auditor.md +0 -176
- package/agents/ez-plan-checker.md +0 -706
- package/agents/ez-research-synthesizer.md +0 -247
- package/agents/ez-ui-auditor.md +0 -439
- package/agents/ez-ui-checker.md +0 -300
- package/agents/ez-ui-researcher.md +0 -353
- package/commands/ez/add-phase.md +0 -43
- package/commands/ez/add-todo.md +0 -47
- package/commands/ez/auth.md +0 -87
- package/commands/ez/autonomous.md +0 -41
- package/commands/ez/check-todos.md +0 -45
- package/commands/ez/cleanup.md +0 -18
- package/commands/ez/debug.md +0 -168
- package/commands/ez/health.md +0 -22
- package/commands/ez/insert-phase.md +0 -32
- package/commands/ez/join-discord.md +0 -18
- package/commands/ez/list-phase-assumptions.md +0 -46
- package/commands/ez/pause-work.md +0 -38
- package/commands/ez/plan-milestone-gaps.md +0 -34
- package/commands/ez/reapply-patches.md +0 -124
- package/commands/ez/remove-phase.md +0 -31
- package/commands/ez/research-phase.md +0 -190
- package/commands/ez/set-profile.md +0 -34
- package/commands/ez/stats.md +0 -18
- package/commands/ez/ui-phase.md +0 -34
- package/commands/ez/ui-review.md +0 -32
- package/commands/ez/validate-phase.md +0 -35
- package/ez-agents/templates/UI-SPEC.md +0 -100
- package/ez-agents/templates/VALIDATION.md +0 -76
- package/ez-agents/templates/context.md +0 -352
- package/ez-agents/templates/verification-report.md +0 -322
- package/ez-agents/workflows/research-phase.md +0 -74
- package/ez-agents/workflows/ui-phase.md +0 -290
- package/ez-agents/workflows/ui-review.md +0 -157
- package/ez-agents/workflows/validate-phase.md +0 -167
package/bin/lib/core.cjs
ADDED
|
@@ -0,0 +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-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
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* EZ Cost Alerts — Multi-threshold budget alert system
|
|
4
|
+
* Triggers alerts at 50%, 75%, and 90% budget usage
|
|
5
|
+
* With duplicate prevention (24h window)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Alert threshold percentages
|
|
13
|
+
*/
|
|
14
|
+
const THRESHOLDS = {
|
|
15
|
+
INFO: 50,
|
|
16
|
+
WARNING: 75,
|
|
17
|
+
CRITICAL: 90
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Duplicate prevention window in milliseconds (24 hours)
|
|
22
|
+
*/
|
|
23
|
+
const DUPLICATE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
24
|
+
|
|
25
|
+
class CostAlerts {
|
|
26
|
+
constructor(cwd) {
|
|
27
|
+
this.cwd = cwd || process.cwd();
|
|
28
|
+
this.planningDir = path.join(this.cwd, '.planning');
|
|
29
|
+
this.alertsFile = path.join(this.planningDir, 'alerts.json');
|
|
30
|
+
this._ensurePlanningDir();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Ensure .planning directory exists
|
|
35
|
+
*/
|
|
36
|
+
_ensurePlanningDir() {
|
|
37
|
+
if (!fs.existsSync(this.planningDir)) {
|
|
38
|
+
fs.mkdirSync(this.planningDir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Load existing alerts from file
|
|
44
|
+
* @returns {Array} Existing alerts
|
|
45
|
+
*/
|
|
46
|
+
_loadAlerts() {
|
|
47
|
+
try {
|
|
48
|
+
if (fs.existsSync(this.alertsFile)) {
|
|
49
|
+
const data = JSON.parse(fs.readFileSync(this.alertsFile, 'utf8'));
|
|
50
|
+
return data.alerts || [];
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// File corrupted or unreadable, start fresh
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Save alerts to file
|
|
60
|
+
* @param {Array} alerts - Alerts to save
|
|
61
|
+
*/
|
|
62
|
+
_saveAlerts(alerts) {
|
|
63
|
+
const data = {
|
|
64
|
+
alerts,
|
|
65
|
+
lastUpdated: new Date().toISOString()
|
|
66
|
+
};
|
|
67
|
+
fs.writeFileSync(this.alertsFile, JSON.stringify(data, null, 2), 'utf8');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Check if alert is duplicate within 24h window
|
|
72
|
+
* @param {Array} existingAlerts - Existing alerts
|
|
73
|
+
* @param {object} newAlert - New alert to check
|
|
74
|
+
* @returns {boolean} True if duplicate
|
|
75
|
+
*/
|
|
76
|
+
_isDuplicate(existingAlerts, newAlert) {
|
|
77
|
+
const now = new Date().getTime();
|
|
78
|
+
return existingAlerts.some(alert => {
|
|
79
|
+
if (alert.threshold !== newAlert.threshold || alert.level !== newAlert.level) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const alertTime = new Date(alert.timestamp).getTime();
|
|
83
|
+
return (now - alertTime) < DUPLICATE_WINDOW_MS;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Check thresholds and return triggered alerts
|
|
89
|
+
* @param {object} opts - Alert options
|
|
90
|
+
* @param {number} opts.percentUsed - Current budget usage percentage
|
|
91
|
+
* @param {number} opts.totalSpent - Total amount spent
|
|
92
|
+
* @param {number} opts.budget - Total budget
|
|
93
|
+
* @returns {Array} Array of triggered alerts
|
|
94
|
+
*/
|
|
95
|
+
checkThresholds(opts) {
|
|
96
|
+
const { percentUsed, totalSpent, budget } = opts;
|
|
97
|
+
const triggered = [];
|
|
98
|
+
|
|
99
|
+
const thresholds = [
|
|
100
|
+
{ level: 'info', threshold: THRESHOLDS.INFO },
|
|
101
|
+
{ level: 'warning', threshold: THRESHOLDS.WARNING },
|
|
102
|
+
{ level: 'critical', threshold: THRESHOLDS.CRITICAL }
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
for (const { level, threshold } of thresholds) {
|
|
106
|
+
if (percentUsed >= threshold) {
|
|
107
|
+
triggered.push({
|
|
108
|
+
threshold,
|
|
109
|
+
level,
|
|
110
|
+
percentUsed,
|
|
111
|
+
totalSpent,
|
|
112
|
+
budget,
|
|
113
|
+
message: this._buildMessage(level, threshold, percentUsed, totalSpent, budget),
|
|
114
|
+
timestamp: new Date().toISOString()
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return triggered;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Build alert message
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
_buildMessage(level, threshold, percentUsed, totalSpent, budget) {
|
|
127
|
+
const levelMessages = {
|
|
128
|
+
info: 'Budget usage has reached',
|
|
129
|
+
warning: 'Budget usage is getting high at',
|
|
130
|
+
critical: 'CRITICAL: Budget usage is very high at'
|
|
131
|
+
};
|
|
132
|
+
return `${levelMessages[level]} ${percentUsed.toFixed(1)}% (${totalSpent.toFixed(2)}/${budget.toFixed(2)})`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Log alert to alerts.json with duplicate prevention
|
|
137
|
+
* @param {object} alert - Alert object to log
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*/
|
|
140
|
+
async logAlert(alert) {
|
|
141
|
+
const existingAlerts = this._loadAlerts();
|
|
142
|
+
|
|
143
|
+
// Check for duplicates
|
|
144
|
+
if (this._isDuplicate(existingAlerts, alert)) {
|
|
145
|
+
return; // Skip duplicate
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
existingAlerts.push(alert);
|
|
149
|
+
this._saveAlerts(existingAlerts);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get all alerts
|
|
154
|
+
* @returns {Array} All alerts
|
|
155
|
+
*/
|
|
156
|
+
getAlerts() {
|
|
157
|
+
return this._loadAlerts();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get alerts by level
|
|
162
|
+
* @param {string} level - Alert level (info, warning, critical)
|
|
163
|
+
* @returns {Array} Filtered alerts
|
|
164
|
+
*/
|
|
165
|
+
getAlertsByLevel(level) {
|
|
166
|
+
const alerts = this._loadAlerts();
|
|
167
|
+
return alerts.filter(alert => alert.level === level);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Export thresholds as static property
|
|
172
|
+
CostAlerts.THRESHOLDS = THRESHOLDS;
|
|
173
|
+
|
|
174
|
+
module.exports = CostAlerts;
|