opencastle 1.3.1 → 1.4.1
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 +16 -10
- package/bin/cli.mjs +8 -9
- package/dist/cli/agent-roster.test.js +0 -48
- package/dist/cli/agent-roster.test.js.map +1 -1
- package/dist/cli/boundary.test.js +9 -7
- package/dist/cli/boundary.test.js.map +1 -1
- package/dist/cli/convoy/artifacts.d.ts +9 -2
- package/dist/cli/convoy/artifacts.d.ts.map +1 -1
- package/dist/cli/convoy/artifacts.js +13 -10
- package/dist/cli/convoy/artifacts.js.map +1 -1
- package/dist/cli/convoy/artifacts.test.js +4 -2
- package/dist/cli/convoy/artifacts.test.js.map +1 -1
- package/dist/cli/convoy/engine.d.ts +53 -23
- package/dist/cli/convoy/engine.d.ts.map +1 -1
- package/dist/cli/convoy/engine.git.test.d.ts +2 -0
- package/dist/cli/convoy/engine.git.test.d.ts.map +1 -0
- package/dist/cli/convoy/engine.git.test.js +435 -0
- package/dist/cli/convoy/engine.git.test.js.map +1 -0
- package/dist/cli/convoy/engine.js +1746 -2305
- package/dist/cli/convoy/engine.js.map +1 -1
- package/dist/cli/convoy/engine.test.js +698 -678
- package/dist/cli/convoy/engine.test.js.map +1 -1
- package/dist/cli/convoy/event-schemas.d.ts +2 -0
- package/dist/cli/convoy/event-schemas.d.ts.map +1 -1
- package/dist/cli/convoy/event-schemas.js +59 -57
- package/dist/cli/convoy/event-schemas.js.map +1 -1
- package/dist/cli/convoy/events.d.ts +4 -1
- package/dist/cli/convoy/events.d.ts.map +1 -1
- package/dist/cli/convoy/events.js +69 -84
- package/dist/cli/convoy/events.js.map +1 -1
- package/dist/cli/convoy/events.test.js +50 -9
- package/dist/cli/convoy/events.test.js.map +1 -1
- package/dist/cli/convoy/gates.d.ts +9 -4
- package/dist/cli/convoy/gates.d.ts.map +1 -1
- package/dist/cli/convoy/gates.js +29 -14
- package/dist/cli/convoy/gates.js.map +1 -1
- package/dist/cli/convoy/isolation.d.ts +32 -6
- package/dist/cli/convoy/isolation.d.ts.map +1 -1
- package/dist/cli/convoy/isolation.js +72 -34
- package/dist/cli/convoy/isolation.js.map +1 -1
- package/dist/cli/convoy/isolation.test.js +66 -42
- package/dist/cli/convoy/isolation.test.js.map +1 -1
- package/dist/cli/convoy/lock.d.ts.map +1 -1
- package/dist/cli/convoy/lock.js +25 -10
- package/dist/cli/convoy/lock.js.map +1 -1
- package/dist/cli/convoy/lock.test.js +12 -0
- package/dist/cli/convoy/lock.test.js.map +1 -1
- package/dist/cli/convoy/merge.d.ts +21 -4
- package/dist/cli/convoy/merge.d.ts.map +1 -1
- package/dist/cli/convoy/merge.js +69 -53
- package/dist/cli/convoy/merge.js.map +1 -1
- package/dist/cli/convoy/merge.test.js +23 -1
- package/dist/cli/convoy/merge.test.js.map +1 -1
- package/dist/cli/convoy/progress.d.ts +35 -0
- package/dist/cli/convoy/progress.d.ts.map +1 -0
- package/dist/cli/convoy/progress.js +103 -0
- package/dist/cli/convoy/progress.js.map +1 -0
- package/dist/cli/convoy/progress.test.d.ts +2 -0
- package/dist/cli/convoy/progress.test.d.ts.map +1 -0
- package/dist/cli/convoy/progress.test.js +53 -0
- package/dist/cli/convoy/progress.test.js.map +1 -0
- package/dist/cli/convoy/read-model.d.ts +468 -0
- package/dist/cli/convoy/read-model.d.ts.map +1 -0
- package/dist/cli/convoy/read-model.js +1132 -0
- package/dist/cli/convoy/read-model.js.map +1 -0
- package/dist/cli/convoy/read-model.test.d.ts +2 -0
- package/dist/cli/convoy/read-model.test.d.ts.map +1 -0
- package/dist/cli/convoy/read-model.test.js +609 -0
- package/dist/cli/convoy/read-model.test.js.map +1 -0
- package/dist/cli/convoy/redact.d.ts +34 -0
- package/dist/cli/convoy/redact.d.ts.map +1 -0
- package/dist/cli/convoy/redact.js +66 -0
- package/dist/cli/convoy/redact.js.map +1 -0
- package/dist/cli/convoy/redact.test.d.ts +2 -0
- package/dist/cli/convoy/redact.test.d.ts.map +1 -0
- package/dist/cli/convoy/redact.test.js +43 -0
- package/dist/cli/convoy/redact.test.js.map +1 -0
- package/dist/cli/convoy/reviewer.d.ts +65 -0
- package/dist/cli/convoy/reviewer.d.ts.map +1 -0
- package/dist/cli/convoy/reviewer.js +141 -0
- package/dist/cli/convoy/reviewer.js.map +1 -0
- package/dist/cli/convoy/reviewer.test.d.ts +2 -0
- package/dist/cli/convoy/reviewer.test.d.ts.map +1 -0
- package/dist/cli/convoy/reviewer.test.js +96 -0
- package/dist/cli/convoy/reviewer.test.js.map +1 -0
- package/dist/cli/convoy/schedule.d.ts +30 -0
- package/dist/cli/convoy/schedule.d.ts.map +1 -0
- package/dist/cli/convoy/schedule.js +111 -0
- package/dist/cli/convoy/schedule.js.map +1 -0
- package/dist/cli/convoy/schedule.test.d.ts +2 -0
- package/dist/cli/convoy/schedule.test.d.ts.map +1 -0
- package/dist/cli/convoy/schedule.test.js +45 -0
- package/dist/cli/convoy/schedule.test.js.map +1 -0
- package/dist/cli/convoy/spec-builder.d.ts +120 -30
- package/dist/cli/convoy/spec-builder.d.ts.map +1 -1
- package/dist/cli/convoy/spec-builder.js +438 -114
- package/dist/cli/convoy/spec-builder.js.map +1 -1
- package/dist/cli/convoy/spec-builder.test.js +419 -435
- package/dist/cli/convoy/spec-builder.test.js.map +1 -1
- package/dist/cli/convoy/spec-types.d.ts +46 -92
- package/dist/cli/convoy/spec-types.d.ts.map +1 -1
- package/dist/cli/convoy/store.d.ts +6 -1
- package/dist/cli/convoy/store.d.ts.map +1 -1
- package/dist/cli/convoy/store.js +111 -15
- package/dist/cli/convoy/store.js.map +1 -1
- package/dist/cli/convoy/store.test.js +59 -13
- package/dist/cli/convoy/store.test.js.map +1 -1
- package/dist/cli/convoy/types.d.ts +76 -113
- package/dist/cli/convoy/types.d.ts.map +1 -1
- package/dist/cli/convoy/types.js +6 -13
- package/dist/cli/convoy/types.js.map +1 -1
- package/dist/cli/convoy/worktree.d.ts +88 -3
- package/dist/cli/convoy/worktree.d.ts.map +1 -1
- package/dist/cli/convoy/worktree.js +282 -56
- package/dist/cli/convoy/worktree.js.map +1 -1
- package/dist/cli/convoy/worktree.test.js +132 -1
- package/dist/cli/convoy/worktree.test.js.map +1 -1
- package/dist/cli/convoy-args.test.js +9 -27
- package/dist/cli/convoy-args.test.js.map +1 -1
- package/dist/cli/convoy-cmd.d.ts +31 -6
- package/dist/cli/convoy-cmd.d.ts.map +1 -1
- package/dist/cli/convoy-cmd.js +150 -201
- package/dist/cli/convoy-cmd.js.map +1 -1
- package/dist/cli/convoy-cmd.test.d.ts +2 -0
- package/dist/cli/convoy-cmd.test.d.ts.map +1 -0
- package/dist/cli/convoy-cmd.test.js +144 -0
- package/dist/cli/convoy-cmd.test.js.map +1 -0
- package/dist/cli/dashboard.d.ts +24 -11
- package/dist/cli/dashboard.d.ts.map +1 -1
- package/dist/cli/dashboard.js +241 -303
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/cli/dashboard.test.d.ts +2 -0
- package/dist/cli/dashboard.test.d.ts.map +1 -0
- package/dist/cli/dashboard.test.js +340 -0
- package/dist/cli/dashboard.test.js.map +1 -0
- package/dist/cli/dispatcher.test.js +35 -2
- package/dist/cli/dispatcher.test.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +3 -3
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/log.d.ts +39 -0
- package/dist/cli/log.d.ts.map +1 -1
- package/dist/cli/log.js +267 -93
- package/dist/cli/log.js.map +1 -1
- package/dist/cli/log.test.d.ts +2 -0
- package/dist/cli/log.test.d.ts.map +1 -0
- package/dist/cli/log.test.js +208 -0
- package/dist/cli/log.test.js.map +1 -0
- package/dist/cli/nearest.d.ts +18 -0
- package/dist/cli/nearest.d.ts.map +1 -0
- package/dist/cli/nearest.js +38 -0
- package/dist/cli/nearest.js.map +1 -0
- package/dist/cli/nearest.test.d.ts +2 -0
- package/dist/cli/nearest.test.d.ts.map +1 -0
- package/dist/cli/nearest.test.js +24 -0
- package/dist/cli/nearest.test.js.map +1 -0
- package/dist/cli/pipeline.d.ts +61 -0
- package/dist/cli/pipeline.d.ts.map +1 -1
- package/dist/cli/pipeline.flow.test.d.ts +2 -0
- package/dist/cli/pipeline.flow.test.d.ts.map +1 -0
- package/dist/cli/pipeline.flow.test.js +524 -0
- package/dist/cli/pipeline.flow.test.js.map +1 -0
- package/dist/cli/pipeline.js +471 -690
- package/dist/cli/pipeline.js.map +1 -1
- package/dist/cli/plan.d.ts +82 -31
- package/dist/cli/plan.d.ts.map +1 -1
- package/dist/cli/plan.js +167 -507
- package/dist/cli/plan.js.map +1 -1
- package/dist/cli/plan.test.d.ts +2 -0
- package/dist/cli/plan.test.d.ts.map +1 -0
- package/dist/cli/plan.test.js +158 -0
- package/dist/cli/plan.test.js.map +1 -0
- package/dist/cli/run/adapters/agent-process.d.ts +82 -0
- package/dist/cli/run/adapters/agent-process.d.ts.map +1 -0
- package/dist/cli/run/adapters/agent-process.js +224 -0
- package/dist/cli/run/adapters/agent-process.js.map +1 -0
- package/dist/cli/run/adapters/agent-process.test.d.ts +2 -0
- package/dist/cli/run/adapters/agent-process.test.d.ts.map +1 -0
- package/dist/cli/run/adapters/agent-process.test.js +159 -0
- package/dist/cli/run/adapters/agent-process.test.js.map +1 -0
- package/dist/cli/run/adapters/claude.d.ts +53 -2
- package/dist/cli/run/adapters/claude.d.ts.map +1 -1
- package/dist/cli/run/adapters/claude.js +147 -171
- package/dist/cli/run/adapters/claude.js.map +1 -1
- package/dist/cli/run/adapters/claude.test.js +197 -254
- package/dist/cli/run/adapters/claude.test.js.map +1 -1
- package/dist/cli/run/adapters/codex.d.ts +25 -2
- package/dist/cli/run/adapters/codex.d.ts.map +1 -1
- package/dist/cli/run/adapters/codex.js +113 -81
- package/dist/cli/run/adapters/codex.js.map +1 -1
- package/dist/cli/run/adapters/codex.test.js +116 -95
- package/dist/cli/run/adapters/codex.test.js.map +1 -1
- package/dist/cli/run/adapters/copilot.d.ts +35 -1
- package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
- package/dist/cli/run/adapters/copilot.js +104 -287
- package/dist/cli/run/adapters/copilot.js.map +1 -1
- package/dist/cli/run/adapters/copilot.test.js +122 -282
- package/dist/cli/run/adapters/copilot.test.js.map +1 -1
- package/dist/cli/run/adapters/cursor.d.ts +25 -7
- package/dist/cli/run/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/run/adapters/cursor.js +103 -156
- package/dist/cli/run/adapters/cursor.js.map +1 -1
- package/dist/cli/run/adapters/cursor.test.js +106 -218
- package/dist/cli/run/adapters/cursor.test.js.map +1 -1
- package/dist/cli/run/adapters/index.d.ts +34 -5
- package/dist/cli/run/adapters/index.d.ts.map +1 -1
- package/dist/cli/run/adapters/index.js +147 -21
- package/dist/cli/run/adapters/index.js.map +1 -1
- package/dist/cli/run/adapters/index.test.d.ts +2 -0
- package/dist/cli/run/adapters/index.test.d.ts.map +1 -0
- package/dist/cli/run/adapters/index.test.js +129 -0
- package/dist/cli/run/adapters/index.test.js.map +1 -0
- package/dist/cli/run/adapters/opencode.d.ts +25 -9
- package/dist/cli/run/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/run/adapters/opencode.js +136 -152
- package/dist/cli/run/adapters/opencode.js.map +1 -1
- package/dist/cli/run/adapters/opencode.test.js +99 -218
- package/dist/cli/run/adapters/opencode.test.js.map +1 -1
- package/dist/cli/run/adapters/permission-modes.d.ts +47 -4
- package/dist/cli/run/adapters/permission-modes.d.ts.map +1 -1
- package/dist/cli/run/adapters/permission-modes.js +113 -37
- package/dist/cli/run/adapters/permission-modes.js.map +1 -1
- package/dist/cli/run/adapters/permission-modes.test.js +55 -40
- package/dist/cli/run/adapters/permission-modes.test.js.map +1 -1
- package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +22 -0
- package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -0
- package/dist/cli/run/adapters/stub-cli.test-helper.js +73 -0
- package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -0
- package/dist/cli/run/platform.d.ts +52 -0
- package/dist/cli/run/platform.d.ts.map +1 -0
- package/dist/cli/run/platform.js +207 -0
- package/dist/cli/run/platform.js.map +1 -0
- package/dist/cli/run/platform.test.d.ts +2 -0
- package/dist/cli/run/platform.test.d.ts.map +1 -0
- package/dist/cli/run/platform.test.js +119 -0
- package/dist/cli/run/platform.test.js.map +1 -0
- package/dist/cli/run/schema.d.ts +6 -8
- package/dist/cli/run/schema.d.ts.map +1 -1
- package/dist/cli/run/schema.js +44 -68
- package/dist/cli/run/schema.js.map +1 -1
- package/dist/cli/run/schema.test.js +59 -279
- package/dist/cli/run/schema.test.js.map +1 -1
- package/dist/cli/run.d.ts +34 -56
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +379 -1132
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/run.test.d.ts +2 -0
- package/dist/cli/run.test.d.ts.map +1 -0
- package/dist/cli/run.test.js +318 -0
- package/dist/cli/run.test.js.map +1 -0
- package/dist/cli/team-config.d.ts.map +1 -1
- package/dist/cli/team-config.js +2 -21
- package/dist/cli/team-config.js.map +1 -1
- package/dist/cli/tiers.test.js +4 -13
- package/dist/cli/tiers.test.js.map +1 -1
- package/package.json +3 -10
- package/src/cli/agent-roster.test.ts +0 -55
- package/src/cli/boundary.test.ts +9 -7
- package/src/cli/convoy/TELEMETRY.md +131 -125
- package/src/cli/convoy/artifacts.test.ts +4 -2
- package/src/cli/convoy/artifacts.ts +13 -12
- package/src/cli/convoy/engine.git.test.ts +462 -0
- package/src/cli/convoy/engine.test.ts +817 -850
- package/src/cli/convoy/engine.ts +1864 -2596
- package/src/cli/convoy/event-schemas.ts +63 -59
- package/src/cli/convoy/events.test.ts +58 -9
- package/src/cli/convoy/events.ts +69 -91
- package/src/cli/convoy/gates.ts +31 -12
- package/src/cli/convoy/isolation.test.ts +76 -43
- package/src/cli/convoy/isolation.ts +100 -38
- package/src/cli/convoy/lock.test.ts +16 -0
- package/src/cli/convoy/lock.ts +25 -8
- package/src/cli/convoy/merge.test.ts +25 -1
- package/src/cli/convoy/merge.ts +74 -61
- package/src/cli/convoy/progress.test.ts +59 -0
- package/src/cli/convoy/progress.ts +121 -0
- package/src/cli/convoy/read-model.test.ts +685 -0
- package/src/cli/convoy/read-model.ts +1469 -0
- package/src/cli/convoy/redact.test.ts +49 -0
- package/src/cli/convoy/redact.ts +73 -0
- package/src/cli/convoy/reviewer.test.ts +112 -0
- package/src/cli/convoy/reviewer.ts +196 -0
- package/src/cli/convoy/schedule.test.ts +56 -0
- package/src/cli/convoy/schedule.ts +109 -0
- package/src/cli/convoy/spec-builder.test.ts +460 -464
- package/src/cli/convoy/spec-builder.ts +460 -129
- package/src/cli/convoy/spec-types.ts +46 -108
- package/src/cli/convoy/store.test.ts +64 -13
- package/src/cli/convoy/store.ts +143 -33
- package/src/cli/convoy/types.ts +59 -71
- package/src/cli/convoy/worktree.test.ts +140 -1
- package/src/cli/convoy/worktree.ts +311 -61
- package/src/cli/convoy-args.test.ts +10 -30
- package/src/cli/convoy-cmd.test.ts +163 -0
- package/src/cli/convoy-cmd.ts +173 -216
- package/src/cli/dashboard/dashboard.css +2086 -0
- package/src/cli/dashboard/dashboard.js +1687 -0
- package/src/cli/dashboard/index.html +307 -0
- package/src/cli/dashboard.test.ts +382 -0
- package/src/cli/dashboard.ts +243 -339
- package/src/cli/dispatcher.test.ts +36 -2
- package/src/cli/docs-accuracy.test.ts +3 -3
- package/src/cli/log.test.ts +228 -0
- package/src/cli/log.ts +302 -83
- package/src/cli/nearest.test.ts +27 -0
- package/src/cli/nearest.ts +38 -0
- package/src/cli/pipeline.flow.test.ts +607 -0
- package/src/cli/pipeline.ts +544 -759
- package/src/cli/plan.test.ts +193 -0
- package/src/cli/plan.ts +209 -545
- package/src/cli/run/adapters/agent-process.test.ts +175 -0
- package/src/cli/run/adapters/agent-process.ts +252 -0
- package/src/cli/run/adapters/claude.test.ts +205 -260
- package/src/cli/run/adapters/claude.ts +151 -162
- package/src/cli/run/adapters/codex.test.ts +120 -100
- package/src/cli/run/adapters/codex.ts +115 -91
- package/src/cli/run/adapters/copilot.test.ts +135 -306
- package/src/cli/run/adapters/copilot.ts +105 -274
- package/src/cli/run/adapters/cursor.test.ts +111 -220
- package/src/cli/run/adapters/cursor.ts +105 -156
- package/src/cli/run/adapters/index.test.ts +148 -0
- package/src/cli/run/adapters/index.ts +168 -20
- package/src/cli/run/adapters/opencode.test.ts +106 -227
- package/src/cli/run/adapters/opencode.ts +139 -151
- package/src/cli/run/adapters/permission-modes.test.ts +63 -41
- package/src/cli/run/adapters/permission-modes.ts +118 -37
- package/src/cli/run/adapters/stub-cli.test-helper.ts +88 -0
- package/src/cli/run/platform.test.ts +128 -0
- package/src/cli/run/platform.ts +213 -0
- package/src/cli/run/schema.test.ts +62 -344
- package/src/cli/run/schema.ts +48 -78
- package/src/cli/run.test.ts +351 -0
- package/src/cli/run.ts +366 -1151
- package/src/cli/team-config.ts +2 -21
- package/src/cli/tiers.test.ts +4 -17
- package/src/orchestrator/agents/team-lead.agent.md +1 -1
- package/src/orchestrator/prompts/assess-complexity.prompt.md +43 -26
- package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
- package/src/orchestrator/prompts/bug-fix.prompt.md +2 -2
- package/src/orchestrator/prompts/fix-convoy.prompt.md +43 -29
- package/src/orchestrator/prompts/fix-prd.prompt.md +26 -22
- package/src/orchestrator/prompts/generate-convoy.prompt.md +139 -147
- package/src/orchestrator/prompts/generate-prd.prompt.md +75 -68
- package/src/orchestrator/prompts/implement-feature.prompt.md +2 -2
- package/src/orchestrator/prompts/validate-convoy.prompt.md +29 -28
- package/src/orchestrator/prompts/validate-prd.prompt.md +28 -21
- package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -3
- package/src/orchestrator/skills/agent-hooks/SKILL.md +1 -1
- package/src/orchestrator/skills/fast-review/SKILL.md +3 -1
- package/src/orchestrator/skills/orchestration-protocols/SKILL.md +7 -8
- package/dist/cli/convoy/dag-analysis.d.ts +0 -39
- package/dist/cli/convoy/dag-analysis.d.ts.map +0 -1
- package/dist/cli/convoy/dag-analysis.js +0 -279
- package/dist/cli/convoy/dag-analysis.js.map +0 -1
- package/dist/cli/convoy/dag-analysis.test.d.ts +0 -2
- package/dist/cli/convoy/dag-analysis.test.d.ts.map +0 -1
- package/dist/cli/convoy/dag-analysis.test.js +0 -289
- package/dist/cli/convoy/dag-analysis.test.js.map +0 -1
- package/dist/cli/convoy/formula.d.ts +0 -19
- package/dist/cli/convoy/formula.d.ts.map +0 -1
- package/dist/cli/convoy/formula.js +0 -142
- package/dist/cli/convoy/formula.js.map +0 -1
- package/dist/cli/convoy/formula.test.d.ts +0 -2
- package/dist/cli/convoy/formula.test.d.ts.map +0 -1
- package/dist/cli/convoy/formula.test.js +0 -342
- package/dist/cli/convoy/formula.test.js.map +0 -1
- package/dist/cli/convoy/health.d.ts +0 -34
- package/dist/cli/convoy/health.d.ts.map +0 -1
- package/dist/cli/convoy/health.js +0 -123
- package/dist/cli/convoy/health.js.map +0 -1
- package/dist/cli/convoy/health.test.d.ts +0 -2
- package/dist/cli/convoy/health.test.d.ts.map +0 -1
- package/dist/cli/convoy/health.test.js +0 -448
- package/dist/cli/convoy/health.test.js.map +0 -1
- package/dist/cli/convoy/last-run.d.ts +0 -53
- package/dist/cli/convoy/last-run.d.ts.map +0 -1
- package/dist/cli/convoy/last-run.js +0 -54
- package/dist/cli/convoy/last-run.js.map +0 -1
- package/dist/cli/convoy/last-run.test.d.ts +0 -2
- package/dist/cli/convoy/last-run.test.d.ts.map +0 -1
- package/dist/cli/convoy/last-run.test.js +0 -110
- package/dist/cli/convoy/last-run.test.js.map +0 -1
- package/dist/cli/convoy/pipeline.d.ts +0 -41
- package/dist/cli/convoy/pipeline.d.ts.map +0 -1
- package/dist/cli/convoy/pipeline.js +0 -414
- package/dist/cli/convoy/pipeline.js.map +0 -1
- package/dist/cli/convoy/pipeline.test.d.ts +0 -2
- package/dist/cli/convoy/pipeline.test.d.ts.map +0 -1
- package/dist/cli/convoy/pipeline.test.js +0 -837
- package/dist/cli/convoy/pipeline.test.js.map +0 -1
- package/dist/cli/convoy/review-stages.d.ts +0 -9
- package/dist/cli/convoy/review-stages.d.ts.map +0 -1
- package/dist/cli/convoy/review-stages.js +0 -134
- package/dist/cli/convoy/review-stages.js.map +0 -1
- package/dist/cli/convoy/review-stages.test.d.ts +0 -2
- package/dist/cli/convoy/review-stages.test.d.ts.map +0 -1
- package/dist/cli/convoy/review-stages.test.js +0 -197
- package/dist/cli/convoy/review-stages.test.js.map +0 -1
- package/dist/cli/run/executor.d.ts +0 -15
- package/dist/cli/run/executor.d.ts.map +0 -1
- package/dist/cli/run/executor.js +0 -249
- package/dist/cli/run/executor.js.map +0 -1
- package/dist/cli/run/executor.test.d.ts +0 -2
- package/dist/cli/run/executor.test.d.ts.map +0 -1
- package/dist/cli/run/executor.test.js +0 -297
- package/dist/cli/run/executor.test.js.map +0 -1
- package/dist/cli/run/reporter.d.ts +0 -10
- package/dist/cli/run/reporter.d.ts.map +0 -1
- package/dist/cli/run/reporter.js +0 -142
- package/dist/cli/run/reporter.js.map +0 -1
- package/dist/cli/run-dry-run.test.d.ts +0 -2
- package/dist/cli/run-dry-run.test.d.ts.map +0 -1
- package/dist/cli/run-dry-run.test.js +0 -83
- package/dist/cli/run-dry-run.test.js.map +0 -1
- package/dist/cli/run-executor-flags.test.d.ts +0 -2
- package/dist/cli/run-executor-flags.test.d.ts.map +0 -1
- package/dist/cli/run-executor-flags.test.js +0 -31
- package/dist/cli/run-executor-flags.test.js.map +0 -1
- package/dist/cli/run-finish.test.d.ts +0 -2
- package/dist/cli/run-finish.test.d.ts.map +0 -1
- package/dist/cli/run-finish.test.js +0 -77
- package/dist/cli/run-finish.test.js.map +0 -1
- package/dist/cli/watch.d.ts +0 -15
- package/dist/cli/watch.d.ts.map +0 -1
- package/dist/cli/watch.js +0 -277
- package/dist/cli/watch.js.map +0 -1
- package/dist/dashboard/scripts/etl.d.ts +0 -10
- package/dist/dashboard/scripts/etl.d.ts.map +0 -1
- package/dist/dashboard/scripts/etl.js +0 -141
- package/dist/dashboard/scripts/etl.js.map +0 -1
- package/src/cli/convoy/dag-analysis.test.ts +0 -349
- package/src/cli/convoy/dag-analysis.ts +0 -367
- package/src/cli/convoy/formula.test.ts +0 -404
- package/src/cli/convoy/formula.ts +0 -174
- package/src/cli/convoy/health.test.ts +0 -519
- package/src/cli/convoy/health.ts +0 -189
- package/src/cli/convoy/last-run.test.ts +0 -130
- package/src/cli/convoy/last-run.ts +0 -87
- package/src/cli/convoy/pipeline.test.ts +0 -999
- package/src/cli/convoy/pipeline.ts +0 -492
- package/src/cli/convoy/review-stages.test.ts +0 -235
- package/src/cli/convoy/review-stages.ts +0 -166
- package/src/cli/run/executor.test.ts +0 -338
- package/src/cli/run/executor.ts +0 -292
- package/src/cli/run/reporter.ts +0 -160
- package/src/cli/run-dry-run.test.ts +0 -97
- package/src/cli/run-executor-flags.test.ts +0 -38
- package/src/cli/run-finish.test.ts +0 -91
- package/src/cli/watch.ts +0 -295
- package/src/dashboard/astro.config.mjs +0 -6
- package/src/dashboard/dist/_astro/index.CADNhRPS.css +0 -1
- package/src/dashboard/dist/data/.gitkeep +0 -0
- package/src/dashboard/dist/data/convoy-list.json +0 -1
- package/src/dashboard/dist/data/overall-stats.json +0 -29
- package/src/dashboard/dist/index.html +0 -1963
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +0 -31
- package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js +0 -6776
- package/src/dashboard/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
- package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
- package/src/dashboard/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
- package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js +0 -99
- package/src/dashboard/node_modules/.vite/deps/astro___cssesc.js.map +0 -7
- package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
- package/src/dashboard/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
- package/src/dashboard/node_modules/.vite/deps/package.json +0 -3
- package/src/dashboard/package-lock.json +0 -6
- package/src/dashboard/public/data/.gitkeep +0 -0
- package/src/dashboard/public/data/convoy-list.json +0 -1
- package/src/dashboard/public/data/overall-stats.json +0 -29
- package/src/dashboard/public/icon-192.png +0 -0
- package/src/dashboard/scripts/etl.test.ts +0 -166
- package/src/dashboard/scripts/etl.ts +0 -170
- package/src/dashboard/scripts/generate-demo-db.test.ts +0 -30
- package/src/dashboard/scripts/generate-demo-db.ts +0 -529
- package/src/dashboard/scripts/integration-test.ts +0 -504
- package/src/dashboard/scripts/verify-demo-data.sh +0 -51
- package/src/dashboard/seed-data/delegations.ndjson +0 -35
- package/src/dashboard/seed-data/events.ndjson +0 -104
- package/src/dashboard/seed-data/panels.ndjson +0 -13
- package/src/dashboard/seed-data/reviews.ndjson +0 -6
- package/src/dashboard/seed-data/sessions.ndjson +0 -50
- package/src/dashboard/src/env.d.ts +0 -1
- package/src/dashboard/src/layouts/Layout.astro +0 -25
- package/src/dashboard/src/pages/index.astro +0 -2313
- package/src/dashboard/src/styles/dashboard.css +0 -2943
- package/src/dashboard/tsconfig.json +0 -6
- /package/src/{dashboard/dist → cli/dashboard}/icon-192.png +0 -0
package/src/cli/plan.ts
CHANGED
|
@@ -1,136 +1,63 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
1
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises'
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
|
-
import { resolve, join
|
|
4
|
-
import { mkdir, writeFile } from 'node:fs/promises'
|
|
5
|
-
import { getAdapter, detectAdapter, cleanupAdapters } from './run/adapters/index.js'
|
|
6
|
-
import { parseTaskSpecText } from './run/schema.js'
|
|
3
|
+
import { resolve, join } from 'node:path'
|
|
7
4
|
import { c } from './prompt.js'
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
--file, -f <path> Path to a text file (fills {{goal}} in the template)
|
|
20
|
-
--text, -t <text> Inline text to use as {{goal}} (alternative to --file)
|
|
21
|
-
--template <name> Prompt template name (default: generate-convoy)
|
|
22
|
-
Built-in templates:
|
|
23
|
-
generate-prd — Write a PRD from a feature prompt
|
|
24
|
-
validate-prd — Check a PRD for completeness
|
|
25
|
-
fix-prd — Fix validation errors in a PRD
|
|
26
|
-
assess-complexity — Assess PRD complexity (returns JSON)
|
|
27
|
-
generate-convoy — Generate a convoy spec from a PRD (default)
|
|
28
|
-
validate-convoy — Check a convoy spec for correctness
|
|
29
|
-
fix-convoy — Fix validation errors in a convoy spec
|
|
30
|
-
--context <path> Optional path to an additional context file (fills {{context}})
|
|
31
|
-
--context-text <text> Inline text to fill {{context}} (alternative to --context)
|
|
32
|
-
--output, -o <path> Output path override (skipped for validation output)
|
|
33
|
-
--adapter, -a <name> Override agent runtime adapter
|
|
34
|
-
--verbose Show full agent output
|
|
35
|
-
--dry-run Print the assembled prompt without executing
|
|
36
|
-
--help, -h Show this help
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
interface PlanOptions {
|
|
40
|
-
file: string | null
|
|
41
|
-
text: string | null
|
|
42
|
-
template: string
|
|
43
|
-
context: string | null
|
|
44
|
-
contextText: string | null
|
|
45
|
-
output: string | null
|
|
46
|
-
adapter: string | null
|
|
47
|
-
verbose: boolean
|
|
48
|
-
dryRun: boolean
|
|
49
|
-
help: boolean
|
|
50
|
-
}
|
|
5
|
+
import type { AgentAdapter, Task } from './convoy/spec-types.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One planning step: fill a prompt template, run it through the adapter the
|
|
9
|
+
* caller resolved, and read the answer the way the template's `output:`
|
|
10
|
+
* frontmatter says.
|
|
11
|
+
*
|
|
12
|
+
* This file used to be a command of its own (`--template`, `--context`, …). No
|
|
13
|
+
* route reached it once `convoy plan` went to the pipeline, so only the step
|
|
14
|
+
* runner is left.
|
|
15
|
+
*/
|
|
51
16
|
|
|
52
|
-
|
|
17
|
+
export type PromptOutput = 'prd' | 'validation' | 'json'
|
|
53
18
|
|
|
54
19
|
export interface PromptStepOptions {
|
|
55
|
-
/** Template name without
|
|
56
|
-
template
|
|
57
|
-
/**
|
|
58
|
-
filePath?: string
|
|
59
|
-
/** Inline text that fills {{goal}} — alternative to filePath */
|
|
20
|
+
/** Template name, without `.prompt.md`. */
|
|
21
|
+
template: string
|
|
22
|
+
/** Fills the template's `{{goal}}` line. */
|
|
60
23
|
goalText?: string
|
|
61
|
-
/**
|
|
62
|
-
contextPath?: string
|
|
63
|
-
/** Inline text that fills {{context}} — alternative to contextPath */
|
|
24
|
+
/** Fills the template's `{{context}}` line. */
|
|
64
25
|
contextText?: string
|
|
65
|
-
/**
|
|
26
|
+
/** Where a PRD answer is written. Defaults to a new file in `.opencastle/prds/`. */
|
|
66
27
|
outputPath?: string
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The runtime, resolved once by the caller. Each step used to detect it
|
|
30
|
+
* afresh, so one plan could in principle be written by two different CLIs.
|
|
31
|
+
*/
|
|
32
|
+
adapter: AgentAdapter
|
|
33
|
+
/** Where opencastle is installed; the templates live under it. */
|
|
72
34
|
pkgRoot: string
|
|
73
|
-
/**
|
|
74
|
-
|
|
35
|
+
/** The project the planner reads. Defaults to the current directory. */
|
|
36
|
+
cwd?: string
|
|
37
|
+
verbose?: boolean
|
|
38
|
+
/** How long one session may run before it is stopped. Defaults to 10 minutes. */
|
|
39
|
+
timeoutMs?: number
|
|
75
40
|
}
|
|
76
41
|
|
|
77
42
|
export interface PromptStepResult {
|
|
78
|
-
/**
|
|
43
|
+
/** Where a PRD was written; null for the other outputs. */
|
|
79
44
|
outputPath: string | null
|
|
80
|
-
/**
|
|
45
|
+
/** The answer: for `json`, the JSON text alone when it came fenced. */
|
|
81
46
|
rawOutput: string
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/** Set when outputType === 'validation' */
|
|
47
|
+
outputType: PromptOutput
|
|
48
|
+
/** Set for `validation`. */
|
|
85
49
|
isValid?: boolean
|
|
86
|
-
/** Set
|
|
50
|
+
/** Set for `validation` when the verdict is invalid. */
|
|
87
51
|
errors?: string
|
|
52
|
+
/** What the session spent, as the runtime reported it. */
|
|
53
|
+
tokens?: number
|
|
54
|
+
/** Undefined when the runtime reports no cost. */
|
|
55
|
+
costUsd?: number
|
|
88
56
|
}
|
|
89
57
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (detectionFailed) {
|
|
94
|
-
console.error(
|
|
95
|
-
` ✗ No agent CLI found on your PATH.\n` +
|
|
96
|
-
` Install one of the following adapters:\n` +
|
|
97
|
-
` • copilot — https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli\n` +
|
|
98
|
-
` • claude — npm install -g @anthropic-ai/claude-code\n` +
|
|
99
|
-
` • cursor — https://cursor.com (Cursor > Install CLI)\n` +
|
|
100
|
-
` • opencode — https://opencode.ai\n` +
|
|
101
|
-
` • codex — npm install -g @openai/codex\n` +
|
|
102
|
-
`\n` +
|
|
103
|
-
` Or specify an adapter explicitly: opencastle convoy plan --adapter <name>`
|
|
104
|
-
)
|
|
105
|
-
} else {
|
|
106
|
-
const hints: Record<string, string> = {
|
|
107
|
-
claude:
|
|
108
|
-
' Install: npm install -g @anthropic-ai/claude-code\n' +
|
|
109
|
-
' Docs: https://docs.anthropic.com/en/docs/claude-code',
|
|
110
|
-
copilot:
|
|
111
|
-
' Requires the Copilot CLI installed and authenticated:\n' +
|
|
112
|
-
' https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli\n' +
|
|
113
|
-
' Docs: https://docs.github.com/en/copilot',
|
|
114
|
-
cursor:
|
|
115
|
-
' The Cursor agent CLI ships with the Cursor editor.\n' +
|
|
116
|
-
' Install Cursor from https://cursor.com and ensure the\n' +
|
|
117
|
-
' "agent" command is on your PATH (Cursor > Install CLI).',
|
|
118
|
-
opencode:
|
|
119
|
-
' Install OpenCode from https://opencode.ai\n' +
|
|
120
|
-
' Ensure the "opencode" command is on your PATH.',
|
|
121
|
-
codex:
|
|
122
|
-
' Install: npm install -g @openai/codex\n' +
|
|
123
|
-
' Docs: https://developers.openai.com/codex',
|
|
124
|
-
}
|
|
125
|
-
const cliName = adapterName === 'cursor' ? 'agent' : adapterName
|
|
126
|
-
const hint = hints[adapterName] ?? ''
|
|
127
|
-
console.error(
|
|
128
|
-
` ✗ Adapter "${adapterName}" is not available.\n` +
|
|
129
|
-
` Make sure the "${cliName}" CLI is installed and on your PATH.\n` +
|
|
130
|
-
hint
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
58
|
+
const DEFAULT_STEP_TIMEOUT_MS = 10 * 60_000
|
|
59
|
+
|
|
60
|
+
// ── Templates ───────────────────────────────────────────────────────────────
|
|
134
61
|
|
|
135
62
|
/** Strip YAML frontmatter (everything between first and second --- delimiters). */
|
|
136
63
|
function stripFrontmatter(text: string): string {
|
|
@@ -142,7 +69,7 @@ function stripFrontmatter(text: string): string {
|
|
|
142
69
|
}
|
|
143
70
|
|
|
144
71
|
/** Extract key: value pairs from YAML frontmatter (top-level scalar values only). */
|
|
145
|
-
function parseFrontmatter(text: string): Record<string, string> {
|
|
72
|
+
export function parseFrontmatter(text: string): Record<string, string> {
|
|
146
73
|
const result: Record<string, string> = {}
|
|
147
74
|
const lines = text.split('\n')
|
|
148
75
|
if (lines[0]?.trim() !== '---') return result
|
|
@@ -155,102 +82,94 @@ function parseFrontmatter(text: string): Record<string, string> {
|
|
|
155
82
|
return result
|
|
156
83
|
}
|
|
157
84
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// 1. Prefer explicit yaml/yml fence — greedy to skip backticks inside content
|
|
161
|
-
const yamlFence = text.match(/```ya?ml\s*\n([\s\S]*)```/)
|
|
162
|
-
if (yamlFence) return yamlFence[1].trim()
|
|
163
|
-
|
|
164
|
-
// 2. Fallback: any code fence whose content looks like a convoy spec
|
|
165
|
-
// Must contain at least `name:` AND `tasks:` to avoid false positives
|
|
166
|
-
const genericFences = [...text.matchAll(/```\s*\n([\s\S]*?)```/g)]
|
|
167
|
-
for (const m of genericFences) {
|
|
168
|
-
const content = m[1].trim()
|
|
169
|
-
if (/^name:/m.test(content) && /^tasks:/m.test(content)) return content
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return null
|
|
85
|
+
export function templatePath(pkgRoot: string, name: string): string {
|
|
86
|
+
return join(pkgRoot, 'src', 'orchestrator', 'prompts', `${name}.prompt.md`)
|
|
173
87
|
}
|
|
174
88
|
|
|
175
89
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
90
|
+
* Put the inputs into a template.
|
|
91
|
+
*
|
|
92
|
+
* A placeholder is filled only where it stands on a line of its own. The
|
|
93
|
+
* instructions in generate-convoy mentioned `{{goal}}` and `{{context}}` in
|
|
94
|
+
* passing, and a global replace pasted the whole PRD into those sentences as
|
|
95
|
+
* well, so every plan carried its PRD twice.
|
|
96
|
+
*
|
|
97
|
+
* One pass with a function replacement: the text put in is never scanned again
|
|
98
|
+
* (a PRD that mentions `{{context}}` stays as written), and `$&` or `$'` in it
|
|
99
|
+
* are not read as replacement patterns.
|
|
178
100
|
*/
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const nameMatch = yaml.match(/^name:\s*['"]?([^'"\n]+)['"]?\s*$/m)
|
|
184
|
-
if (nameMatch) {
|
|
185
|
-
const kebab = nameMatch[1].trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
|
|
186
|
-
if (kebab) return `${kebab}.convoy.yml`
|
|
187
|
-
}
|
|
188
|
-
return 'convoy-plan.convoy.yml'
|
|
101
|
+
export function fillTemplate(body: string, goal: string, context: string): string {
|
|
102
|
+
return body.replace(/^[ \t]*\{\{(goal|context)\}\}[ \t]*$/gm, (_line, key: string) =>
|
|
103
|
+
(key === 'goal' ? goal : context).trim(),
|
|
104
|
+
)
|
|
189
105
|
}
|
|
190
106
|
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const kebab = headingMatch[1]
|
|
199
|
-
.trim()
|
|
200
|
-
.toLowerCase()
|
|
201
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
202
|
-
.replace(/^-|-$/g, '')
|
|
203
|
-
if (kebab) return `${kebab}.prd.md`
|
|
204
|
-
}
|
|
205
|
-
return `prd-${Date.now()}.prd.md`
|
|
107
|
+
/** `'Team Lead (OpenCastle)'` → `team-lead`, the agent slug the adapter introduces. */
|
|
108
|
+
function agentSlug(label: string | undefined): string {
|
|
109
|
+
return (label ?? 'team-lead')
|
|
110
|
+
.replace(/\(.*?\)/g, '')
|
|
111
|
+
.trim()
|
|
112
|
+
.toLowerCase()
|
|
113
|
+
.replace(/\s+/g, '-')
|
|
206
114
|
}
|
|
207
115
|
|
|
116
|
+
// ── Answers ─────────────────────────────────────────────────────────────────
|
|
117
|
+
|
|
208
118
|
/**
|
|
209
119
|
* Extract Markdown body from AI output.
|
|
210
120
|
* Strips wrapping ```markdown / ```md fences if present.
|
|
211
121
|
* If a heading is present but prefixed with preamble, trims to the first heading.
|
|
212
122
|
*/
|
|
213
123
|
function extractMarkdownBody(output: string): string {
|
|
214
|
-
// Strip explicit markdown fence
|
|
215
124
|
const mdFenceMatch = output.match(/^```(?:markdown|md)\s*\n([\s\S]*?)```\s*$/m)
|
|
216
125
|
if (mdFenceMatch) return mdFenceMatch[1].trim()
|
|
217
126
|
|
|
218
127
|
const lines = output.trim().split('\n')
|
|
219
|
-
// Strip plain ``` wrapping (first and last line are fences)
|
|
220
128
|
if (lines[0]?.startsWith('```') && lines[lines.length - 1]?.trim() === '```') {
|
|
221
129
|
return lines.slice(1, -1).join('\n').trim()
|
|
222
130
|
}
|
|
223
131
|
|
|
224
|
-
// If there's preamble before the first heading, strip it
|
|
225
132
|
const headingIdx = lines.findIndex((l) => /^#{1,3}\s/.test(l))
|
|
226
133
|
if (headingIdx > 0) return lines.slice(headingIdx).join('\n').trim()
|
|
227
134
|
|
|
228
135
|
return output.trim()
|
|
229
136
|
}
|
|
230
137
|
|
|
138
|
+
/**
|
|
139
|
+
* The JSON in an answer: the last ```json fence if there is one, else the whole
|
|
140
|
+
* answer. A missing fence used to abort the plan outright, before the one
|
|
141
|
+
* retry generate-convoy is allowed; now the parser downstream sees the text and
|
|
142
|
+
* reports why it is not a plan.
|
|
143
|
+
*/
|
|
144
|
+
export function extractJson(output: string): string {
|
|
145
|
+
// Greedy, so a prompt inside the plan that shows a fenced example does not
|
|
146
|
+
// cut the block short.
|
|
147
|
+
const fenced = output.match(/```json\s*\n([\s\S]*)```/)
|
|
148
|
+
return (fenced ? fenced[1] : output).trim()
|
|
149
|
+
}
|
|
150
|
+
|
|
231
151
|
/**
|
|
232
152
|
* Parse a validation AI response for VALID / INVALID verdict.
|
|
233
153
|
* Prefers structured JSON output; falls back to VALID/INVALID keyword matching.
|
|
234
154
|
*/
|
|
235
|
-
function parseValidationResult(output: string): { isValid: boolean; errors: string } {
|
|
155
|
+
export function parseValidationResult(output: string): { isValid: boolean; errors: string } {
|
|
236
156
|
const trimmed = output.trim()
|
|
237
157
|
|
|
238
|
-
// Try structured JSON first (preferred format)
|
|
239
158
|
const jsonFenceMatch = trimmed.match(/```json\s*\n([\s\S]*?)```/)
|
|
240
|
-
|
|
159
|
+
const candidate = jsonFenceMatch ? jsonFenceMatch[1].trim() : trimmed.startsWith('{') ? trimmed : null
|
|
160
|
+
if (candidate) {
|
|
241
161
|
try {
|
|
242
|
-
const parsed = JSON.parse(
|
|
162
|
+
const parsed = JSON.parse(candidate) as { valid?: boolean; issues?: string[] }
|
|
243
163
|
if (typeof parsed.valid === 'boolean') {
|
|
244
164
|
if (parsed.valid) return { isValid: true, errors: '' }
|
|
245
165
|
const errors = Array.isArray(parsed.issues) ? parsed.issues.join('\n') : ''
|
|
246
166
|
return { isValid: false, errors }
|
|
247
167
|
}
|
|
248
168
|
} catch {
|
|
249
|
-
// JSON
|
|
169
|
+
// Not JSON after all — fall through to the keyword check.
|
|
250
170
|
}
|
|
251
171
|
}
|
|
252
172
|
|
|
253
|
-
// Fallback: regex-based parsing for backward compatibility
|
|
254
173
|
const hasInvalid = /\bINVALID\b/.test(trimmed)
|
|
255
174
|
const hasValid = /\bVALID\b/.test(trimmed)
|
|
256
175
|
if (hasValid && !hasInvalid) return { isValid: true, errors: '' }
|
|
@@ -258,437 +177,182 @@ function parseValidationResult(output: string): { isValid: boolean; errors: stri
|
|
|
258
177
|
return { isValid: false, errors: errorsMatch ? errorsMatch[1].trim() : trimmed }
|
|
259
178
|
}
|
|
260
179
|
|
|
180
|
+
/**
|
|
181
|
+
* A path in `dir` that nothing is using yet: `<stem><suffix>`, then
|
|
182
|
+
* `<stem>-2<suffix>` and so on.
|
|
183
|
+
*
|
|
184
|
+
* PRDs and specs were named after their title and overwritten. Two requests
|
|
185
|
+
* that happened to share a title replaced each other's files, hand edits
|
|
186
|
+
* included, and the complexity cache that sat next to the PRD answered for the
|
|
187
|
+
* wrong one.
|
|
188
|
+
*/
|
|
189
|
+
export function freePath(dir: string, stem: string, suffix: string): string {
|
|
190
|
+
let candidate = join(dir, `${stem}${suffix}`)
|
|
191
|
+
for (let n = 2; existsSync(candidate); n++) candidate = join(dir, `${stem}-${n}${suffix}`)
|
|
192
|
+
return candidate
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function prdStem(content: string): string {
|
|
196
|
+
const heading = content.match(/^#\s+(.+?)(?:\s*[-—–]+\s*PRD)?\s*$/m)
|
|
197
|
+
const kebab = heading?.[1]
|
|
198
|
+
.trim()
|
|
199
|
+
.toLowerCase()
|
|
200
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
201
|
+
.replace(/^-|-$/g, '')
|
|
202
|
+
return kebab || `prd-${Date.now()}`
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ── Progress ────────────────────────────────────────────────────────────────
|
|
206
|
+
|
|
261
207
|
const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
262
208
|
|
|
263
209
|
const TEMPLATE_MESSAGES: Record<string, string> = {
|
|
264
|
-
'generate-prd': '
|
|
265
|
-
'
|
|
266
|
-
'
|
|
267
|
-
'
|
|
268
|
-
'
|
|
269
|
-
'
|
|
210
|
+
'generate-prd': 'Writing the PRD',
|
|
211
|
+
'validate-prd': 'Checking the PRD',
|
|
212
|
+
'fix-prd': 'Fixing the PRD',
|
|
213
|
+
'assess-complexity': 'Sizing the work',
|
|
214
|
+
'generate-convoy': 'Breaking it into tasks',
|
|
215
|
+
'validate-convoy': 'Reviewing the plan',
|
|
216
|
+
'fix-convoy': 'Fixing the plan',
|
|
270
217
|
}
|
|
271
218
|
|
|
272
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* One spinner line for however many steps are running.
|
|
221
|
+
*
|
|
222
|
+
* Steps run side by side now (validation beside sizing, one task plan per
|
|
223
|
+
* group), and a spinner each meant several timers overwriting the same line.
|
|
224
|
+
* Off a terminal there is no line to redraw, and the frames only cluttered a
|
|
225
|
+
* log, so nothing is drawn there.
|
|
226
|
+
*/
|
|
227
|
+
const running = new Map<number, string>()
|
|
228
|
+
let nextId = 0
|
|
229
|
+
let ticker: ReturnType<typeof setInterval> | null = null
|
|
230
|
+
let startedAt = 0
|
|
231
|
+
|
|
273
232
|
function startProgress(templateName: string): () => void {
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
233
|
+
if (!process.stdout.isTTY) return () => {}
|
|
234
|
+
const id = nextId++
|
|
235
|
+
running.set(id, TEMPLATE_MESSAGES[templateName] ?? templateName)
|
|
236
|
+
if (!ticker) {
|
|
237
|
+
startedAt = Date.now()
|
|
238
|
+
let frame = 0
|
|
239
|
+
ticker = setInterval(() => {
|
|
240
|
+
const labels = [...new Set(running.values())]
|
|
241
|
+
const elapsed = Math.floor((Date.now() - startedAt) / 1000)
|
|
242
|
+
const spinner = SPINNER_FRAMES[frame++ % SPINNER_FRAMES.length]
|
|
243
|
+
const line = ` ${spinner} ${labels.join(' · ')}… (${elapsed}s)`
|
|
244
|
+
process.stdout.write('\r' + c.dim(line.slice(0, (process.stdout.columns ?? 80) - 1)) + '\x1b[K')
|
|
245
|
+
}, 250)
|
|
246
|
+
}
|
|
283
247
|
return () => {
|
|
284
|
-
|
|
285
|
-
|
|
248
|
+
running.delete(id)
|
|
249
|
+
if (running.size === 0 && ticker) {
|
|
250
|
+
clearInterval(ticker)
|
|
251
|
+
ticker = null
|
|
252
|
+
process.stdout.write('\r\x1b[K')
|
|
253
|
+
}
|
|
286
254
|
}
|
|
287
255
|
}
|
|
288
256
|
|
|
289
|
-
// ──
|
|
257
|
+
// ── The step ────────────────────────────────────────────────────────────────
|
|
290
258
|
|
|
291
259
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
260
|
+
* Writing the PRD and the plan is the work the rest depends on, so it gets the
|
|
261
|
+
* standard tier; checking and sizing them is a short read, so it gets economy.
|
|
262
|
+
*/
|
|
263
|
+
function modelFor(adapter: AgentAdapter, template: string): string | undefined {
|
|
264
|
+
const tier = /^(validate-|assess-)/.test(template) ? 'economy' : 'standard'
|
|
265
|
+
return adapter.tierModels?.[tier]
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Run one planning template through the caller's adapter.
|
|
270
|
+
*
|
|
271
|
+
* Planning sessions run with `permissionMode: 'plan'`: they read the repository
|
|
272
|
+
* to ground the plan in real paths, and they cannot change it. They used to get
|
|
273
|
+
* the workers' `acceptEdits`, so a planner could edit the project it was only
|
|
274
|
+
* meant to describe.
|
|
294
275
|
*/
|
|
295
276
|
export async function runPromptStep(opts: PromptStepOptions): Promise<PromptStepResult> {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
const templatePath = join(
|
|
299
|
-
opts.pkgRoot,
|
|
300
|
-
'src',
|
|
301
|
-
'orchestrator',
|
|
302
|
-
'prompts',
|
|
303
|
-
`${templateName}.prompt.md`
|
|
304
|
-
)
|
|
305
|
-
if (!existsSync(templatePath)) {
|
|
306
|
-
throw new Error(`Prompt template not found: ${templatePath}`)
|
|
307
|
-
}
|
|
277
|
+
const path = templatePath(opts.pkgRoot, opts.template)
|
|
278
|
+
if (!existsSync(path)) throw new Error(`Prompt template not found: ${path}`)
|
|
308
279
|
|
|
309
|
-
const rawTemplate = await readFile(
|
|
280
|
+
const rawTemplate = await readFile(path, 'utf8')
|
|
310
281
|
const frontmatter = parseFrontmatter(rawTemplate)
|
|
311
|
-
const outputType = (frontmatter['output'] ?? '
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
let goalContent = opts.goalText ?? ''
|
|
315
|
-
if (!goalContent && opts.filePath) {
|
|
316
|
-
if (!existsSync(opts.filePath)) throw new Error(`File not found: ${opts.filePath}`)
|
|
317
|
-
goalContent = await readFile(opts.filePath, 'utf8')
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
let contextContent = opts.contextText ?? ''
|
|
321
|
-
if (!contextContent && opts.contextPath) {
|
|
322
|
-
if (!existsSync(opts.contextPath)) throw new Error(`Context file not found: ${opts.contextPath}`)
|
|
323
|
-
contextContent = await readFile(opts.contextPath, 'utf8')
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const assembledPrompt = template
|
|
327
|
-
.replace(/\{\{goal\}\}/g, goalContent.trim())
|
|
328
|
-
.replace(/\{\{context\}\}/g, contextContent.trim())
|
|
282
|
+
const outputType = (frontmatter['output'] ?? 'json') as PromptOutput
|
|
283
|
+
const prompt = fillTemplate(stripFrontmatter(rawTemplate), opts.goalText ?? '', opts.contextText ?? '')
|
|
329
284
|
|
|
330
|
-
if (opts.dryRun) {
|
|
331
|
-
console.log(c.bold(c.cyan(` [${templateName}] Assembled prompt (dry-run):\n`)))
|
|
332
|
-
console.log(assembledPrompt)
|
|
333
|
-
return { outputPath: null, rawOutput: assembledPrompt, outputType }
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
let adapterName = opts.adapterName ?? ''
|
|
337
|
-
if (!adapterName) {
|
|
338
|
-
const detected = await detectAdapter()
|
|
339
|
-
if (!detected) {
|
|
340
|
-
printAdapterError(true, '')
|
|
341
|
-
throw new Error('No adapter available')
|
|
342
|
-
}
|
|
343
|
-
adapterName = detected
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
let adapter
|
|
347
|
-
try {
|
|
348
|
-
adapter = await getAdapter(adapterName)
|
|
349
|
-
} catch {
|
|
350
|
-
printAdapterError(false, adapterName)
|
|
351
|
-
throw new Error(`Adapter "${adapterName}" failed to load`)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (!(await adapter.isAvailable())) {
|
|
355
|
-
printAdapterError(false, adapterName)
|
|
356
|
-
throw new Error(`Adapter "${adapterName}" is not available`)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const agentField = (frontmatter['agent'] ?? 'team-lead').toLowerCase().replace(/\s+/g, '-')
|
|
360
285
|
const task: Task = {
|
|
361
|
-
id:
|
|
362
|
-
prompt
|
|
363
|
-
agent:
|
|
286
|
+
id: opts.template,
|
|
287
|
+
prompt,
|
|
288
|
+
agent: agentSlug(frontmatter['agent']),
|
|
364
289
|
timeout: '10m',
|
|
365
290
|
depends_on: [],
|
|
366
291
|
files: [],
|
|
367
|
-
description: frontmatter['description'] ??
|
|
292
|
+
description: frontmatter['description'] ?? opts.template,
|
|
368
293
|
max_retries: 1,
|
|
369
294
|
}
|
|
370
295
|
|
|
371
296
|
if (opts.verbose) {
|
|
372
|
-
console.log(c.dim(`
|
|
297
|
+
console.log(c.dim(` ${opts.template} · ${opts.adapter.name} · read-only · ${prompt.length} chars`))
|
|
373
298
|
}
|
|
374
299
|
|
|
375
|
-
const
|
|
300
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_STEP_TIMEOUT_MS
|
|
301
|
+
const stop = opts.verbose ? null : startProgress(opts.template)
|
|
302
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
376
303
|
let execResult
|
|
377
304
|
try {
|
|
378
|
-
execResult = await
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
305
|
+
execResult = await Promise.race([
|
|
306
|
+
opts.adapter.execute(task, {
|
|
307
|
+
verbose: opts.verbose ?? false,
|
|
308
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
309
|
+
permissionMode: 'plan',
|
|
310
|
+
...(modelFor(opts.adapter, opts.template) ? { model: modelFor(opts.adapter, opts.template) } : {}),
|
|
311
|
+
}),
|
|
312
|
+
new Promise<never>((_, reject) => {
|
|
313
|
+
timer = setTimeout(() => {
|
|
314
|
+
// A hung session would otherwise hold the whole plan open forever.
|
|
315
|
+
opts.adapter.kill?.(task)
|
|
316
|
+
reject(new Error(`${opts.template} ran longer than ${Math.round(timeoutMs / 60_000)}m and was stopped`))
|
|
317
|
+
}, timeoutMs)
|
|
318
|
+
}),
|
|
319
|
+
])
|
|
382
320
|
} finally {
|
|
321
|
+
if (timer) clearTimeout(timer)
|
|
383
322
|
stop?.()
|
|
384
323
|
}
|
|
385
324
|
|
|
386
325
|
if (!execResult.success) {
|
|
387
326
|
throw new Error(
|
|
388
|
-
|
|
389
|
-
|
|
327
|
+
`${opts.adapter.name} failed on ${opts.template} (exit code ${execResult.exitCode}).\n` +
|
|
328
|
+
execResult.output.slice(0, 2000),
|
|
390
329
|
)
|
|
391
330
|
}
|
|
392
331
|
|
|
393
332
|
const rawOutput = execResult.output
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
333
|
+
const usage = execResult.usage
|
|
334
|
+
const spent: Pick<PromptStepResult, 'tokens' | 'costUsd'> = {
|
|
335
|
+
tokens: usage?.total_tokens ?? ((usage?.prompt_tokens ?? 0) + (usage?.completion_tokens ?? 0)),
|
|
336
|
+
...(execResult.costUsd !== undefined ? { costUsd: execResult.costUsd } : {}),
|
|
397
337
|
}
|
|
398
338
|
|
|
399
339
|
if (outputType === 'validation') {
|
|
400
340
|
const { isValid, errors } = parseValidationResult(rawOutput)
|
|
401
|
-
return { outputPath: null, rawOutput, outputType, isValid, errors }
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (outputType === 'json') {
|
|
405
|
-
// Extract JSON from a ```json fenced block — fail fast if missing
|
|
406
|
-
// Use greedy match (.*) to capture up to the LAST closing fence,
|
|
407
|
-
// since task prompts may contain triple backticks in code examples
|
|
408
|
-
const jsonFenceMatch = rawOutput.match(/```json\s*\n([\s\S]*)```/)
|
|
409
|
-
if (!jsonFenceMatch) {
|
|
410
|
-
throw new Error(
|
|
411
|
-
`Expected a fenced \`\`\`json block in the AI response but found none.\n\n` +
|
|
412
|
-
`Adapter: ${adapterName} | Output length: ${rawOutput.length} chars\n\n` +
|
|
413
|
-
`Raw output:\n${rawOutput}\n\n` +
|
|
414
|
-
`Tip: re-run with --verbose to see the full adapter output.`
|
|
415
|
-
)
|
|
416
|
-
}
|
|
417
|
-
const jsonContent = jsonFenceMatch[1].trim()
|
|
418
|
-
|
|
419
|
-
const outputPath = opts.outputPath ?? null
|
|
420
|
-
if (outputPath) {
|
|
421
|
-
await mkdir(resolve(outputPath, '..'), { recursive: true })
|
|
422
|
-
await writeFile(outputPath, jsonContent + '\n', 'utf8')
|
|
423
|
-
}
|
|
424
|
-
return { outputPath, rawOutput: jsonContent, outputType }
|
|
341
|
+
return { outputPath: null, rawOutput, outputType, isValid, errors, ...spent }
|
|
425
342
|
}
|
|
426
343
|
|
|
427
344
|
if (outputType === 'prd') {
|
|
428
345
|
const content = extractMarkdownBody(rawOutput)
|
|
429
346
|
let outputPath = opts.outputPath ?? null
|
|
430
347
|
if (!outputPath) {
|
|
431
|
-
const prdDir = resolve(process.cwd(), '.opencastle', 'prds')
|
|
348
|
+
const prdDir = resolve(opts.cwd ?? process.cwd(), '.opencastle', 'prds')
|
|
432
349
|
await mkdir(prdDir, { recursive: true })
|
|
433
|
-
outputPath =
|
|
350
|
+
outputPath = freePath(prdDir, prdStem(content), '.prd.md')
|
|
434
351
|
}
|
|
435
352
|
await mkdir(resolve(outputPath, '..'), { recursive: true })
|
|
436
353
|
await writeFile(outputPath, content + '\n', 'utf8')
|
|
437
|
-
return { outputPath, rawOutput, outputType }
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// convoy-spec (default)
|
|
441
|
-
const yamlContent = extractYamlBlock(rawOutput)
|
|
442
|
-
if (!yamlContent) {
|
|
443
|
-
const preview = rawOutput.slice(0, 10_000)
|
|
444
|
-
throw new Error(
|
|
445
|
-
`No YAML code block found in the agent response.\n\nRaw output (truncated):\n${preview}`
|
|
446
|
-
)
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
let schemaValid = true
|
|
450
|
-
try {
|
|
451
|
-
parseTaskSpecText(yamlContent)
|
|
452
|
-
} catch (err) {
|
|
453
|
-
schemaValid = false
|
|
454
|
-
const msg = err instanceof Error ? err.message : String(err)
|
|
455
|
-
console.warn(c.yellow(` ⚠ YAML validation warning: ${msg}`))
|
|
456
|
-
console.warn(c.dim(` The file will still be written — you may need to edit it before running.\n`))
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
let outputPath = opts.outputPath ?? null
|
|
460
|
-
if (!outputPath) {
|
|
461
|
-
const convoyDir = resolve(process.cwd(), '.opencastle', 'convoys')
|
|
462
|
-
await mkdir(convoyDir, { recursive: true })
|
|
463
|
-
outputPath = join(convoyDir, deriveOutputFilename(yamlContent))
|
|
464
|
-
}
|
|
465
|
-
await mkdir(resolve(outputPath, '..'), { recursive: true })
|
|
466
|
-
await writeFile(outputPath, yamlContent + '\n', 'utf8')
|
|
467
|
-
|
|
468
|
-
return { outputPath, rawOutput, outputType, isValid: schemaValid }
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* Read MCP server configurations from the project's MCP config file.
|
|
473
|
-
* Checks in priority order: .vscode/mcp.json, .cursor/mcp.json, .claude/mcp.json, mcp.json
|
|
474
|
-
*/
|
|
475
|
-
export async function readProjectMcpServers(projectRoot: string): Promise<MCPServerConfig[]> {
|
|
476
|
-
const candidates = [
|
|
477
|
-
join(projectRoot, '.vscode', 'mcp.json'),
|
|
478
|
-
join(projectRoot, '.cursor', 'mcp.json'),
|
|
479
|
-
join(projectRoot, '.claude', 'mcp.json'),
|
|
480
|
-
join(projectRoot, 'mcp.json'),
|
|
481
|
-
]
|
|
482
|
-
|
|
483
|
-
for (const filePath of candidates) {
|
|
484
|
-
if (!existsSync(filePath)) continue
|
|
485
|
-
try {
|
|
486
|
-
const raw = await readFile(filePath, 'utf8')
|
|
487
|
-
const parsed = JSON.parse(raw) as Record<string, unknown>
|
|
488
|
-
|
|
489
|
-
// VS Code format: { servers: { name: { type, command, args } } }
|
|
490
|
-
// Cursor/Claude format: { mcpServers: { name: { command, args } } }
|
|
491
|
-
const serversMap =
|
|
492
|
-
(parsed['servers'] as Record<string, unknown> | undefined) ??
|
|
493
|
-
(parsed['mcpServers'] as Record<string, unknown> | undefined)
|
|
494
|
-
|
|
495
|
-
if (!serversMap || typeof serversMap !== 'object') continue
|
|
496
|
-
|
|
497
|
-
return Object.entries(serversMap).map(([name, cfg]) => {
|
|
498
|
-
const c = cfg as Record<string, unknown>
|
|
499
|
-
const server: MCPServerConfig = { name, type: (c['type'] as string) ?? 'stdio' }
|
|
500
|
-
if (typeof c['command'] === 'string') server.command = c['command']
|
|
501
|
-
if (Array.isArray(c['args'])) server.args = c['args'] as string[]
|
|
502
|
-
if (typeof c['url'] === 'string') server.url = c['url']
|
|
503
|
-
return server
|
|
504
|
-
})
|
|
505
|
-
} catch {
|
|
506
|
-
return []
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
return []
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// ── CLI argument parsing ────────────────────────────────────────────────────
|
|
514
|
-
|
|
515
|
-
function parseArgs(args: string[]): PlanOptions {
|
|
516
|
-
const opts: PlanOptions = {
|
|
517
|
-
file: null,
|
|
518
|
-
text: null,
|
|
519
|
-
template: 'generate-convoy',
|
|
520
|
-
context: null,
|
|
521
|
-
contextText: null,
|
|
522
|
-
output: null,
|
|
523
|
-
adapter: null,
|
|
524
|
-
verbose: false,
|
|
525
|
-
dryRun: false,
|
|
526
|
-
help: false,
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
for (let i = 0; i < args.length; i++) {
|
|
530
|
-
const arg = args[i]
|
|
531
|
-
switch (arg) {
|
|
532
|
-
case '--help':
|
|
533
|
-
case '-h':
|
|
534
|
-
opts.help = true
|
|
535
|
-
break
|
|
536
|
-
case '--file':
|
|
537
|
-
case '-f':
|
|
538
|
-
if (i + 1 >= args.length) { console.error(' ✗ --file requires a path'); process.exit(1) }
|
|
539
|
-
opts.file = args[++i]
|
|
540
|
-
if (!opts.file.trim()) { console.error(' ✗ --file cannot be empty'); process.exit(1) }
|
|
541
|
-
break
|
|
542
|
-
case '--text':
|
|
543
|
-
case '-t':
|
|
544
|
-
if (i + 1 >= args.length) { console.error(' ✗ --text requires a value'); process.exit(1) }
|
|
545
|
-
opts.text = args[++i]
|
|
546
|
-
if (!opts.text.trim()) { console.error(' ✗ --text cannot be empty'); process.exit(1) }
|
|
547
|
-
break
|
|
548
|
-
case '--template':
|
|
549
|
-
if (i + 1 >= args.length) { console.error(' ✗ --template requires a name'); process.exit(1) }
|
|
550
|
-
opts.template = args[++i]
|
|
551
|
-
if (!opts.template.trim()) { console.error(' ✗ --template cannot be empty'); process.exit(1) }
|
|
552
|
-
break
|
|
553
|
-
case '--context':
|
|
554
|
-
if (i + 1 >= args.length) { console.error(' ✗ --context requires a path'); process.exit(1) }
|
|
555
|
-
opts.context = args[++i]
|
|
556
|
-
if (!opts.context.trim()) { console.error(' ✗ --context cannot be empty'); process.exit(1) }
|
|
557
|
-
break
|
|
558
|
-
case '--context-text':
|
|
559
|
-
if (i + 1 >= args.length) { console.error(' ✗ --context-text requires a value'); process.exit(1) }
|
|
560
|
-
opts.contextText = args[++i]
|
|
561
|
-
if (!opts.contextText.trim()) { console.error(' ✗ --context-text cannot be empty'); process.exit(1) }
|
|
562
|
-
break
|
|
563
|
-
case '--output':
|
|
564
|
-
case '-o':
|
|
565
|
-
if (i + 1 >= args.length) { console.error(' ✗ --output requires a path'); process.exit(1) }
|
|
566
|
-
opts.output = args[++i]
|
|
567
|
-
if (!opts.output.trim()) { console.error(' ✗ --output cannot be empty'); process.exit(1) }
|
|
568
|
-
break
|
|
569
|
-
case '--adapter':
|
|
570
|
-
case '-a':
|
|
571
|
-
if (i + 1 >= args.length) { console.error(' ✗ --adapter requires a name'); process.exit(1) }
|
|
572
|
-
opts.adapter = args[++i]
|
|
573
|
-
if (!opts.adapter.trim()) { console.error(' ✗ --adapter cannot be empty'); process.exit(1) }
|
|
574
|
-
break
|
|
575
|
-
case '--verbose':
|
|
576
|
-
opts.verbose = true
|
|
577
|
-
break
|
|
578
|
-
case '--dry-run':
|
|
579
|
-
case '--dryRun':
|
|
580
|
-
opts.dryRun = true
|
|
581
|
-
break
|
|
582
|
-
default:
|
|
583
|
-
console.error(` ✗ Unknown option: ${arg}. Run with --help to see available options.`)
|
|
584
|
-
console.log(HELP)
|
|
585
|
-
process.exit(1)
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
return opts
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// ── CLI entrypoint ──────────────────────────────────────────────────────────
|
|
593
|
-
|
|
594
|
-
export default async function plan({ args, pkgRoot }: CliContext): Promise<void> {
|
|
595
|
-
const opts = parseArgs(args)
|
|
596
|
-
|
|
597
|
-
if (opts.help) {
|
|
598
|
-
console.log(HELP)
|
|
599
|
-
return
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (!opts.file && !opts.text) {
|
|
603
|
-
console.error(` ✗ Either --file or --text is required.`)
|
|
604
|
-
console.log(HELP)
|
|
605
|
-
process.exit(1)
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
if (opts.file && opts.text) {
|
|
609
|
-
console.error(` ✗ --file and --text are mutually exclusive.`)
|
|
610
|
-
process.exit(1)
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const filePath = opts.file ? resolve(process.cwd(), opts.file) : undefined
|
|
614
|
-
|
|
615
|
-
if (filePath && !existsSync(filePath)) {
|
|
616
|
-
console.error(` ✗ File not found: ${opts.file}`)
|
|
617
|
-
process.exit(1)
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
const outputPath = opts.output ? resolve(process.cwd(), opts.output) : undefined
|
|
621
|
-
const source = opts.file
|
|
622
|
-
? opts.file
|
|
623
|
-
: `"${(opts.text ?? '').slice(0, 60)}${(opts.text ?? '').length > 60 ? '…' : ''}"`
|
|
624
|
-
|
|
625
|
-
console.log(c.dim(` Template: ${opts.template}`))
|
|
626
|
-
console.log(c.dim(` Input: ${source}\n`))
|
|
627
|
-
|
|
628
|
-
let result: PromptStepResult
|
|
629
|
-
try {
|
|
630
|
-
result = await runPromptStep({
|
|
631
|
-
template: opts.template,
|
|
632
|
-
filePath,
|
|
633
|
-
goalText: opts.text ?? undefined,
|
|
634
|
-
contextPath: opts.context ?? undefined,
|
|
635
|
-
contextText: opts.contextText ?? undefined,
|
|
636
|
-
outputPath,
|
|
637
|
-
adapterName: opts.adapter ?? undefined,
|
|
638
|
-
verbose: opts.verbose,
|
|
639
|
-
dryRun: opts.dryRun,
|
|
640
|
-
pkgRoot,
|
|
641
|
-
})
|
|
642
|
-
} catch (err) {
|
|
643
|
-
console.error(` ✗ ${err instanceof Error ? err.message : String(err)}`)
|
|
644
|
-
process.exit(1)
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (opts.dryRun) return
|
|
648
|
-
|
|
649
|
-
switch (result.outputType) {
|
|
650
|
-
case 'validation': {
|
|
651
|
-
if (result.isValid) {
|
|
652
|
-
console.log(c.green(` ✓ VALID`))
|
|
653
|
-
} else {
|
|
654
|
-
console.log(c.red(` ✗ INVALID\n`))
|
|
655
|
-
console.log(result.errors ?? result.rawOutput)
|
|
656
|
-
process.exit(1)
|
|
657
|
-
}
|
|
658
|
-
break
|
|
659
|
-
}
|
|
660
|
-
case 'prd': {
|
|
661
|
-
const relPath = result.outputPath!.startsWith(process.cwd())
|
|
662
|
-
? result.outputPath!.slice(process.cwd().length + 1)
|
|
663
|
-
: result.outputPath!
|
|
664
|
-
console.log(c.green(` ✓ PRD written to ${relPath}`))
|
|
665
|
-
console.log(`\n ${c.dim('Next step:')} opencastle convoy plan --prd ${relPath}`)
|
|
666
|
-
break
|
|
667
|
-
}
|
|
668
|
-
case 'json': {
|
|
669
|
-
if (result.outputPath) {
|
|
670
|
-
const relP = result.outputPath.startsWith(process.cwd())
|
|
671
|
-
? result.outputPath.slice(process.cwd().length + 1)
|
|
672
|
-
: result.outputPath
|
|
673
|
-
console.log(c.green(` ✓ JSON written to ${relP}`))
|
|
674
|
-
}
|
|
675
|
-
console.log(result.rawOutput)
|
|
676
|
-
break
|
|
677
|
-
}
|
|
678
|
-
default: {
|
|
679
|
-
const relPath = result.outputPath!.startsWith(process.cwd())
|
|
680
|
-
? result.outputPath!.slice(process.cwd().length + 1)
|
|
681
|
-
: result.outputPath!
|
|
682
|
-
console.log(c.green(` ✓ Convoy spec written to ${relPath}`))
|
|
683
|
-
if (result.isValid === false) {
|
|
684
|
-
console.log(c.yellow(` (contains validation warnings — review before running)`))
|
|
685
|
-
}
|
|
686
|
-
console.log(`
|
|
687
|
-
${c.dim('Preview:')} npx opencastle convoy run -f ${relPath} --dry-run
|
|
688
|
-
${c.dim('Execute:')} npx opencastle convoy run -f ${relPath}
|
|
689
|
-
`)
|
|
690
|
-
}
|
|
354
|
+
return { outputPath, rawOutput, outputType, ...spent }
|
|
691
355
|
}
|
|
692
356
|
|
|
693
|
-
|
|
357
|
+
return { outputPath: null, rawOutput: extractJson(rawOutput), outputType: 'json', ...spent }
|
|
694
358
|
}
|