opencastle 1.3.1 → 1.4.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 +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/dist/cli/pipeline.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { readFile, writeFile, mkdir
|
|
1
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { resolve, relative, basename } from 'node:path';
|
|
5
5
|
import { c, confirm, closePrompts } from './prompt.js';
|
|
6
|
-
import { runPromptStep,
|
|
7
|
-
import { cleanupAdapters } from './run/adapters/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { buildConvoyYaml,
|
|
6
|
+
import { runPromptStep, freePath } from './plan.js';
|
|
7
|
+
import { resolveAdapter, cleanupAdapters } from './run/adapters/index.js';
|
|
8
|
+
import { findProjectRoot } from './convoy/read-model.js';
|
|
9
|
+
import { foldTestOnlyTasks, applyPatches, buildConvoyYaml, checkPlan, detectGates, mergeGroupPlans, normalizePlanFiles, parsePatches, parseTaskPlanWithReason, planConcurrency, sequenceConflicts, slugify, } from './convoy/spec-builder.js';
|
|
10
10
|
function appendTaskComplexity(base, taskComplexity) {
|
|
11
11
|
if (!taskComplexity?.length)
|
|
12
12
|
return base;
|
|
@@ -233,43 +233,375 @@ export function topologicalSortGroups(groups) {
|
|
|
233
233
|
}
|
|
234
234
|
return sorted;
|
|
235
235
|
}
|
|
236
|
+
/** The SHA-256 of a PRD's text: the complexity cache's key. */
|
|
237
|
+
export function hashPrd(content) {
|
|
238
|
+
return createHash('sha256').update(content).digest('hex');
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The cached assessment of exactly this PRD, or null.
|
|
242
|
+
*
|
|
243
|
+
* The cache sits next to the PRD and records the hash of the text it assessed;
|
|
244
|
+
* it is used only when that hash matches. It used to be trusted by path alone,
|
|
245
|
+
* and PRDs were overwritten by title, so a different request that produced the
|
|
246
|
+
* same title was planned with the previous request's assessment.
|
|
247
|
+
*/
|
|
248
|
+
export async function readCachedComplexity(prdPath, prdContent) {
|
|
249
|
+
const path = deriveComplexityPath(prdPath);
|
|
250
|
+
if (!existsSync(path))
|
|
251
|
+
return null;
|
|
252
|
+
try {
|
|
253
|
+
const raw = JSON.parse(await readFile(path, 'utf8'));
|
|
254
|
+
if (raw.prd_sha256 !== hashPrd(prdContent))
|
|
255
|
+
return null;
|
|
256
|
+
return parseComplexityAssessment(JSON.stringify(raw));
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function writeCachedComplexity(prdPath, prdContent, assessment) {
|
|
263
|
+
const record = { prd_sha256: hashPrd(prdContent), ...assessment };
|
|
264
|
+
await writeFile(deriveComplexityPath(prdPath), JSON.stringify(record, null, 2) + '\n', 'utf8');
|
|
265
|
+
}
|
|
266
|
+
// ── Planning ────────────────────────────────────────────────────────────────
|
|
267
|
+
/** Rounds of fix-prd, and of fix-convoy, before the planner stops asking. */
|
|
268
|
+
const MAX_FIX_ROUNDS = 2;
|
|
269
|
+
function done(text, detail = '') {
|
|
270
|
+
console.log(` ${c.green('✓')} ${text}${detail ? ` ${c.dim(detail)}` : ''}`);
|
|
271
|
+
}
|
|
272
|
+
function warn(text) {
|
|
273
|
+
console.log(` ${c.yellow('⚠')} ${text}`);
|
|
274
|
+
}
|
|
275
|
+
/** Agent-written text, indented under the line that introduced it. */
|
|
276
|
+
function indented(text) {
|
|
277
|
+
return c.dim(text.trim().split('\n').map((line) => ` ${line}`).join('\n'));
|
|
278
|
+
}
|
|
279
|
+
function relPath(abs) {
|
|
280
|
+
const rel = relative(process.cwd(), abs);
|
|
281
|
+
return rel && !rel.startsWith('..') ? rel : abs;
|
|
282
|
+
}
|
|
283
|
+
function message(err) {
|
|
284
|
+
return err instanceof Error ? err.message : String(err);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Like Promise.all, but waits for every step before reporting the first failure,
|
|
288
|
+
* so a failed step never leaves its siblings' sessions running unwatched.
|
|
289
|
+
*/
|
|
290
|
+
async function settleAll(work) {
|
|
291
|
+
const settled = await Promise.allSettled(work);
|
|
292
|
+
const failed = settled.find((s) => s.status === 'rejected');
|
|
293
|
+
if (failed)
|
|
294
|
+
throw failed.reason;
|
|
295
|
+
return settled.map((s) => s.value);
|
|
296
|
+
}
|
|
297
|
+
/** generate-convoy, with the one retry an unreadable answer gets. */
|
|
298
|
+
async function generatePlan(step, goal, context, label, convoyDir) {
|
|
299
|
+
let raw = '';
|
|
300
|
+
let reason = '';
|
|
301
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
302
|
+
raw = (await step('generate-convoy', { goalText: goal, contextText: context })).rawOutput;
|
|
303
|
+
const parsed = parseTaskPlanWithReason(raw);
|
|
304
|
+
if (parsed.plan)
|
|
305
|
+
return parsed.plan;
|
|
306
|
+
reason = parsed.reason ?? 'unreadable';
|
|
307
|
+
if (attempt === 1)
|
|
308
|
+
warn(`The ${label} plan could not be read (${reason}) — asking once more`);
|
|
309
|
+
}
|
|
310
|
+
await mkdir(convoyDir, { recursive: true });
|
|
311
|
+
const kept = freePath(convoyDir, `${slugify(label) || 'plan'}.task-plan`, '.json');
|
|
312
|
+
await writeFile(kept, raw + '\n', 'utf8');
|
|
313
|
+
throw new Error(`The ${label} plan could not be read after a retry: ${reason}. The answer is in ${relPath(kept)}.`);
|
|
314
|
+
}
|
|
315
|
+
/** One fix-convoy round: patches applied to the plan, globs reduced again. */
|
|
316
|
+
async function fixPlan(step, plan, problems) {
|
|
317
|
+
const answer = await step('fix-convoy', { goalText: JSON.stringify(plan, null, 2), contextText: problems });
|
|
318
|
+
const patches = parsePatches(answer.rawOutput);
|
|
319
|
+
if (!patches?.length) {
|
|
320
|
+
warn('No usable patches came back');
|
|
321
|
+
return plan;
|
|
322
|
+
}
|
|
323
|
+
return normalizePlanFiles(applyPatches(plan, patches)).plan;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* From a request (or an edited PRD) to a checked spec on disk.
|
|
327
|
+
*
|
|
328
|
+
* Sessions, all read-only, on the one adapter the caller resolved:
|
|
329
|
+
* - generate-prd, unless a PRD was given;
|
|
330
|
+
* - validate-prd beside assess-complexity, which is skipped when this exact
|
|
331
|
+
* PRD was assessed before; up to two fix-prd + validate-prd rounds;
|
|
332
|
+
* - generate-convoy, once, or once per group at the same time for a large
|
|
333
|
+
* feature; one retry when an answer cannot be read;
|
|
334
|
+
* - fix-convoy only when the code's checks fail, at most twice;
|
|
335
|
+
* - validate-convoy only as the reviewer for `--yes`.
|
|
336
|
+
*
|
|
337
|
+
* The semantic validate-convoy pass that followed every plan is gone: the
|
|
338
|
+
* checks it was there for are done in code, and a person reads the plan
|
|
339
|
+
* before it runs.
|
|
340
|
+
*/
|
|
341
|
+
/** Where a PRD would go, for a change small enough to plan from the request alone. */
|
|
342
|
+
const NO_PRD = 'There is no PRD: this is a small change, planned straight from the request. Read the code it touches before you plan.';
|
|
343
|
+
export async function planConvoy(req) {
|
|
344
|
+
const root = req.projectRoot ?? process.cwd();
|
|
345
|
+
const convoyDir = resolve(root, '.opencastle', 'convoys');
|
|
346
|
+
// Planning is agent sessions too, and the run's own total never counted them.
|
|
347
|
+
const started = Date.now();
|
|
348
|
+
const spend = { sessions: 0, ms: 0, tokens: 0, costUsd: 0, costComplete: true };
|
|
349
|
+
const step = async (template, inputs) => {
|
|
350
|
+
const r = await runPromptStep({ template, adapter: req.adapter, pkgRoot: req.pkgRoot, cwd: root, verbose: req.verbose, ...inputs });
|
|
351
|
+
spend.sessions++;
|
|
352
|
+
spend.tokens += r.tokens ?? 0;
|
|
353
|
+
if (r.costUsd === undefined)
|
|
354
|
+
spend.costComplete = false;
|
|
355
|
+
else
|
|
356
|
+
spend.costUsd += r.costUsd;
|
|
357
|
+
spend.ms = Date.now() - started;
|
|
358
|
+
return r;
|
|
359
|
+
};
|
|
360
|
+
// ── A small change: no PRD ────────────────────────────────────────────────
|
|
361
|
+
// Sizing the request first is one short economy session. When it is small,
|
|
362
|
+
// the plan is written straight from it: a PRD, its review and its fixes were
|
|
363
|
+
// four or five sessions and most of the planning time — 7m 25s in a real
|
|
364
|
+
// run — for a change the request already described.
|
|
365
|
+
let prdPath = null;
|
|
366
|
+
let plan = null;
|
|
367
|
+
let quick = null;
|
|
368
|
+
if (!req.prdPath && req.task) {
|
|
369
|
+
quick = await step('assess-complexity', { goalText: req.task, contextText: req.task })
|
|
370
|
+
.then((r) => parseComplexityAssessment(r.rawOutput))
|
|
371
|
+
.catch(() => null);
|
|
372
|
+
if (quick?.complexity === 'low' && quick.recommended_strategy !== 'chain') {
|
|
373
|
+
done('Sized', 'low — planned straight from the request, without a PRD');
|
|
374
|
+
plan = await generatePlan(step, req.task, appendTaskComplexity(NO_PRD, quick.task_complexity), 'task', convoyDir);
|
|
375
|
+
done(`${plan.tasks.length} tasks planned`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (!plan) {
|
|
379
|
+
// ── The PRD ───────────────────────────────────────────────────────────────
|
|
380
|
+
if (req.prdPath) {
|
|
381
|
+
prdPath = resolve(root, req.prdPath);
|
|
382
|
+
done('PRD', relPath(prdPath));
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
const written = await step('generate-prd', { goalText: req.task ?? '' });
|
|
386
|
+
prdPath = written.outputPath;
|
|
387
|
+
done('PRD written', relPath(prdPath));
|
|
388
|
+
}
|
|
389
|
+
let prd = await readFile(prdPath, 'utf8');
|
|
390
|
+
// Both only read the PRD, so they run side by side. fix-prd is told to keep
|
|
391
|
+
// the PRD's phases, so the assessment of this draft still fits a fixed one;
|
|
392
|
+
// it is cached under this draft's text, which is the text it describes.
|
|
393
|
+
const cached = await readCachedComplexity(prdPath, prd);
|
|
394
|
+
const assessedFrom = prd;
|
|
395
|
+
const [verdict, complexity] = await settleAll([
|
|
396
|
+
step('validate-prd', { goalText: `<!-- validation-pass: 1 -->\n${prd}` }),
|
|
397
|
+
// The request was sized already. Only groups need sizing against the
|
|
398
|
+
// PRD, whose phases they name.
|
|
399
|
+
cached || (quick && quick.recommended_strategy !== 'chain')
|
|
400
|
+
? Promise.resolve(cached ?? quick)
|
|
401
|
+
: step('assess-complexity', { goalText: prd, contextText: req.task ?? '' })
|
|
402
|
+
.then((r) => parseComplexityAssessment(r.rawOutput))
|
|
403
|
+
.catch((err) => {
|
|
404
|
+
warn(`Could not size the work (${message(err)}) — planning it as one`);
|
|
405
|
+
return null;
|
|
406
|
+
}),
|
|
407
|
+
]);
|
|
408
|
+
if (complexity && !cached && complexity !== quick)
|
|
409
|
+
await writeCachedComplexity(prdPath, assessedFrom, complexity);
|
|
410
|
+
if (verdict.isValid) {
|
|
411
|
+
done('PRD checked');
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
let issues = verdict.errors || verdict.rawOutput;
|
|
415
|
+
let fixed = false;
|
|
416
|
+
for (let round = 1; round <= MAX_FIX_ROUNDS && !fixed; round++) {
|
|
417
|
+
warn(`The PRD has issues — fixing (${round}/${MAX_FIX_ROUNDS})`);
|
|
418
|
+
console.log(indented(issues));
|
|
419
|
+
await step('fix-prd', { goalText: prd, contextText: issues, outputPath: prdPath });
|
|
420
|
+
prd = await readFile(prdPath, 'utf8');
|
|
421
|
+
const again = await step('validate-prd', { goalText: `<!-- validation-pass: ${round + 1} -->\n${prd}` });
|
|
422
|
+
fixed = again.isValid === true;
|
|
423
|
+
if (!fixed)
|
|
424
|
+
issues = again.errors || again.rawOutput;
|
|
425
|
+
}
|
|
426
|
+
if (fixed)
|
|
427
|
+
done('PRD fixed and checked');
|
|
428
|
+
else
|
|
429
|
+
warn(`The PRD still has issues after ${MAX_FIX_ROUNDS} fixes — planning from it anyway:\n${indented(issues)}`);
|
|
430
|
+
}
|
|
431
|
+
if (complexity) {
|
|
432
|
+
done(cached ? 'Sized (cached for this PRD)' : 'Sized', `${complexity.complexity}, ${complexity.total_tasks} workstreams`);
|
|
433
|
+
}
|
|
434
|
+
// ── The tasks ─────────────────────────────────────────────────────────────
|
|
435
|
+
let groups = null;
|
|
436
|
+
if (complexity?.recommended_strategy === 'chain' && complexity.convoy_groups.length > 1) {
|
|
437
|
+
const check = validateComplexityGroups(complexity);
|
|
438
|
+
if (check.valid)
|
|
439
|
+
groups = topologicalSortGroups(complexity.convoy_groups);
|
|
440
|
+
else
|
|
441
|
+
warn(`Ignoring the suggested groups (${check.reason}) — planning it as one`);
|
|
442
|
+
}
|
|
443
|
+
if (groups) {
|
|
444
|
+
const featureName = prd.match(/^# (.+?)\s*(?:—|-)?\s*PRD/m)?.[1].trim() ?? complexity?.original_prompt ?? 'Feature';
|
|
445
|
+
const request = req.task ?? complexity?.original_prompt ?? '';
|
|
446
|
+
const all = groups;
|
|
447
|
+
const plans = await settleAll(all.map((group) => {
|
|
448
|
+
const goal = [
|
|
449
|
+
request,
|
|
450
|
+
'',
|
|
451
|
+
'## Convoy Group Scope',
|
|
452
|
+
'',
|
|
453
|
+
`This is one of ${all.length} groups, all planned at the same time. Plan ONLY the phases listed here.`,
|
|
454
|
+
'The planner joins the group plans into one spec: tasks of the groups this one depends on are',
|
|
455
|
+
'finished before this group\'s first tasks start.',
|
|
456
|
+
'',
|
|
457
|
+
`- **Group name:** ${group.name}`,
|
|
458
|
+
`- **Description:** ${group.description}`,
|
|
459
|
+
`- **Phases to include:** ${group.phases.join(', ')}`,
|
|
460
|
+
group.depends_on.length ? `- **Depends on groups:** ${group.depends_on.join(', ')}` : '',
|
|
461
|
+
].filter((line, i, lines) => line !== '' || lines[i - 1] !== '').join('\n');
|
|
462
|
+
const context = appendTaskComplexity(extractRelevantPrdSections(prd, group.phases), filterTaskComplexityByPhases(complexity?.task_complexity, group.phases));
|
|
463
|
+
return generatePlan(step, goal, context, group.name, convoyDir);
|
|
464
|
+
}));
|
|
465
|
+
plan = mergeGroupPlans(featureName, all.map((g, i) => ({ name: g.name, depends_on: g.depends_on, plan: plans[i] })));
|
|
466
|
+
done(`${plan.tasks.length} tasks planned`, `${all.length} groups, planned side by side`);
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
const goal = req.task ?? complexity?.original_prompt ?? 'Implement the PRD.';
|
|
470
|
+
plan = await generatePlan(step, goal, appendTaskComplexity(prd, complexity?.task_complexity), 'task', convoyDir);
|
|
471
|
+
done(`${plan.tasks.length} tasks planned`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const normalized = normalizePlanFiles(plan);
|
|
475
|
+
plan = normalized.plan;
|
|
476
|
+
for (const note of normalized.notes)
|
|
477
|
+
console.log(c.dim(` files: ${note}`));
|
|
478
|
+
const tests = foldTestOnlyTasks(plan);
|
|
479
|
+
plan = tests.plan;
|
|
480
|
+
for (const [from, into] of tests.folded)
|
|
481
|
+
console.log(c.dim(` ${from} folded into ${into}: the agent that writes the code writes its tests`));
|
|
482
|
+
// ── The spec ──────────────────────────────────────────────────────────────
|
|
483
|
+
await mkdir(convoyDir, { recursive: true });
|
|
484
|
+
const specPath = freePath(convoyDir, slugify(plan.name) || 'convoy', '.convoy.yml');
|
|
485
|
+
const settings = {
|
|
486
|
+
adapter: req.adapterName,
|
|
487
|
+
branch: `convoy/${basename(specPath, '.convoy.yml')}`,
|
|
488
|
+
gates: detectGates(root),
|
|
489
|
+
};
|
|
490
|
+
let problems = checkPlan(plan, settings);
|
|
491
|
+
for (let round = 1; round <= MAX_FIX_ROUNDS && problems.length > 0; round++) {
|
|
492
|
+
warn(`The plan fails ${problems.length} check${problems.length === 1 ? '' : 's'} — fixing (${round}/${MAX_FIX_ROUNDS})`);
|
|
493
|
+
console.log(indented(problems.join('\n')));
|
|
494
|
+
plan = await fixPlan(step, plan, problems.map((p) => `- ${p}`).join('\n'));
|
|
495
|
+
problems = checkPlan(plan, settings);
|
|
496
|
+
}
|
|
497
|
+
if (problems.length > 0) {
|
|
498
|
+
const sequenced = sequenceConflicts(plan);
|
|
499
|
+
if (sequenced.added.length > 0) {
|
|
500
|
+
plan = sequenced.plan;
|
|
501
|
+
problems = checkPlan(plan, settings);
|
|
502
|
+
for (const [later, earlier] of sequenced.added) {
|
|
503
|
+
console.log(c.dim(` ${later} now waits for ${earlier}: they claim the same files`));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (problems.length === 0)
|
|
508
|
+
done('Plan checked');
|
|
509
|
+
if (req.critic && problems.length === 0) {
|
|
510
|
+
const review = await step('validate-convoy', { goalText: buildConvoyYaml(plan, settings) });
|
|
511
|
+
if (review.isValid) {
|
|
512
|
+
done('Plan reviewed');
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
const issues = review.errors || review.rawOutput;
|
|
516
|
+
warn('The review found issues — fixing once');
|
|
517
|
+
console.log(indented(issues));
|
|
518
|
+
const revised = await fixPlan(step, plan, issues);
|
|
519
|
+
if (checkPlan(revised, settings).length === 0) {
|
|
520
|
+
plan = revised;
|
|
521
|
+
done('Plan revised after review');
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
warn('The revision fails the checks — keeping the plan as it was');
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
await writeFile(specPath, buildConvoyYaml(plan, settings), 'utf8');
|
|
529
|
+
return { prdPath, specPath, plan, settings, problems, planning: spend };
|
|
530
|
+
}
|
|
531
|
+
// ── Showing the plan ────────────────────────────────────────────────────────
|
|
532
|
+
function fit(text, width) {
|
|
533
|
+
if (text.length <= width)
|
|
534
|
+
return text.padEnd(width);
|
|
535
|
+
return text.slice(0, Math.max(0, width - 1)) + '…';
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The plan as a few lines a person can check before saying yes: who does what,
|
|
539
|
+
* after what, touching which files.
|
|
540
|
+
*/
|
|
541
|
+
export function renderPlan(outcome, columns = 100) {
|
|
542
|
+
const { plan, settings } = outcome;
|
|
543
|
+
const rows = plan.tasks.map((t) => ({
|
|
544
|
+
id: t.id,
|
|
545
|
+
agent: t.agent ?? 'developer',
|
|
546
|
+
deps: t.depends_on?.length ? t.depends_on.join(', ') : '–',
|
|
547
|
+
files: t.files?.length ? t.files.join(', ') : '(any)',
|
|
548
|
+
}));
|
|
549
|
+
const width = (pick, header, cap) => Math.min(cap, Math.max(header.length, ...rows.map((r) => pick(r).length)));
|
|
550
|
+
const idW = width((r) => r.id, 'TASK', 32);
|
|
551
|
+
const agentW = width((r) => r.agent, 'AGENT', 18);
|
|
552
|
+
const depsW = width((r) => r.deps, 'DEPENDS ON', 30);
|
|
553
|
+
const filesW = Math.max(20, columns - 4 - idW - agentW - depsW - 6);
|
|
554
|
+
const line = (a, b, d, f) => ` ${fit(a, idW)} ${fit(b, agentW)} ${fit(d, depsW)} ${fit(f, filesW).trimEnd()}`;
|
|
555
|
+
const at = planConcurrency(plan);
|
|
556
|
+
const out = [
|
|
557
|
+
'',
|
|
558
|
+
` ${c.bold(`Plan: ${plan.name}`)} ${c.dim(`— ${plan.tasks.length} task${plan.tasks.length === 1 ? '' : 's'}, up to ${at} at a time`)}`,
|
|
559
|
+
'',
|
|
560
|
+
c.dim(line('TASK', 'AGENT', 'DEPENDS ON', 'FILES')),
|
|
561
|
+
...rows.map((r) => line(r.id, r.agent, r.deps, r.files)),
|
|
562
|
+
'',
|
|
563
|
+
` ${c.dim('Branch')} ${settings.branch} ${c.dim('· runtime')} ${settings.adapter}` +
|
|
564
|
+
(settings.gates.length ? ` ${c.dim('· then once:')} ${settings.gates.join(', ')}` : ''),
|
|
565
|
+
` ${c.dim('Spec')} ${relPath(outcome.specPath)}`,
|
|
566
|
+
...(outcome.planning ? [` ${c.dim('Planned')} ${describeSpend(outcome.planning)}`] : []),
|
|
567
|
+
'',
|
|
568
|
+
];
|
|
569
|
+
return out;
|
|
570
|
+
}
|
|
571
|
+
function describeSpend(s) {
|
|
572
|
+
const secs = Math.round(s.ms / 1000);
|
|
573
|
+
const time = secs >= 60 ? `${Math.floor(secs / 60)}m ${secs % 60}s` : `${secs}s`;
|
|
574
|
+
const tokens = s.tokens >= 1_000_000 ? `${(s.tokens / 1_000_000).toFixed(1)}M` : s.tokens >= 1000 ? `${Math.round(s.tokens / 1000)}K` : String(s.tokens);
|
|
575
|
+
const cost = s.costUsd > 0 || s.costComplete ? ` · $${s.costUsd.toFixed(2)}${s.costComplete ? '' : '+ (not every session reported a cost)'}` : '';
|
|
576
|
+
return `in ${time} · ${s.sessions} session${s.sessions === 1 ? '' : 's'} · ${tokens} tokens${cost}`;
|
|
577
|
+
}
|
|
578
|
+
// ── The command ─────────────────────────────────────────────────────────────
|
|
236
579
|
const HELP = `
|
|
237
|
-
opencastle convoy plan [options]
|
|
238
|
-
|
|
239
|
-
Run the full convoy generation pipeline from a feature prompt:
|
|
580
|
+
opencastle convoy plan --prd <file> [options]
|
|
240
581
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
Step 3 — Fix PRD (fix-prd, up to 2 retries if invalid)
|
|
244
|
-
Step 4 — Assess complexity (assess-complexity, determines single vs chain)
|
|
245
|
-
Step 5 — Generate task plan (generate-convoy outputs JSON, code builds YAML)
|
|
246
|
-
Step 6 — Validate convoy spec (programmatic + semantic validation)
|
|
247
|
-
Step 7 — Fix convoy spec (patch-based fixing, up to 2 retries)
|
|
582
|
+
Plan again from a PRD you edited. The PRD is checked, broken into tasks and
|
|
583
|
+
written as a spec; you see the plan and are asked before it runs.
|
|
248
584
|
|
|
249
585
|
Options:
|
|
250
|
-
--
|
|
251
|
-
|
|
252
|
-
--
|
|
253
|
-
--
|
|
254
|
-
--adapter, -a <name>
|
|
255
|
-
--
|
|
256
|
-
--
|
|
257
|
-
--complexity <path> Skip complexity assessment — use an existing complexity file
|
|
258
|
-
--skip-validation Skip PRD and convoy validation (steps 2, 3, 6, 7)
|
|
586
|
+
--prd <file> The PRD to plan from (opencastle convoy "<task>" writes
|
|
587
|
+
them to .opencastle/prds/)
|
|
588
|
+
--yes, -y Run the plan without asking
|
|
589
|
+
--dry-run Plan and write the spec, but do not run it
|
|
590
|
+
--adapter, -a <name> Agent runtime to plan and run with
|
|
591
|
+
--concurrency, -c <n> Tasks at once when it runs
|
|
592
|
+
--verbose Show each planning session's output
|
|
259
593
|
--help, -h Show this help
|
|
260
594
|
`;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
skipValidation: false,
|
|
272
|
-
help: false,
|
|
595
|
+
/** Flags `convoy "<task>"` and `convoy plan` share; `--prd` is plan's alone. */
|
|
596
|
+
function parseArgs(args, allowPrd) {
|
|
597
|
+
const opts = { prd: null, yes: false, dryRun: false, adapter: null, concurrency: null, verbose: false, help: false };
|
|
598
|
+
const value = (i, flag) => {
|
|
599
|
+
const v = args[i + 1];
|
|
600
|
+
if (v === undefined || !v.trim() || v.startsWith('-')) {
|
|
601
|
+
console.error(` ✗ ${flag} needs a value`);
|
|
602
|
+
process.exit(1);
|
|
603
|
+
}
|
|
604
|
+
return v;
|
|
273
605
|
};
|
|
274
606
|
for (let i = 0; i < args.length; i++) {
|
|
275
607
|
const arg = args[i];
|
|
@@ -278,696 +610,145 @@ function parseArgs(args) {
|
|
|
278
610
|
case '-h':
|
|
279
611
|
opts.help = true;
|
|
280
612
|
break;
|
|
281
|
-
case '--text':
|
|
282
|
-
case '-t':
|
|
283
|
-
if (i + 1 >= args.length) {
|
|
284
|
-
console.error(' ✗ --text requires a value');
|
|
285
|
-
process.exit(1);
|
|
286
|
-
}
|
|
287
|
-
opts.text = args[++i];
|
|
288
|
-
if (!opts.text.trim()) {
|
|
289
|
-
console.error(' ✗ --text cannot be empty');
|
|
290
|
-
process.exit(1);
|
|
291
|
-
}
|
|
292
|
-
break;
|
|
293
613
|
case '--prd':
|
|
294
|
-
if (
|
|
295
|
-
console.error(
|
|
614
|
+
if (!allowPrd) {
|
|
615
|
+
console.error(` ✗ --prd belongs to \`opencastle convoy plan\`: plan from a task or from a PRD, not both.`);
|
|
296
616
|
process.exit(1);
|
|
297
617
|
}
|
|
298
|
-
opts.prd =
|
|
618
|
+
opts.prd = value(i++, arg);
|
|
299
619
|
break;
|
|
300
|
-
case '--
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
process.exit(1);
|
|
304
|
-
}
|
|
305
|
-
opts.complexity = args[++i];
|
|
620
|
+
case '--yes':
|
|
621
|
+
case '-y':
|
|
622
|
+
opts.yes = true;
|
|
306
623
|
break;
|
|
307
|
-
case '--
|
|
308
|
-
|
|
309
|
-
console.error(' ✗ --output-prd requires a path');
|
|
310
|
-
process.exit(1);
|
|
311
|
-
}
|
|
312
|
-
opts.outputPrd = args[++i];
|
|
313
|
-
break;
|
|
314
|
-
case '--output-spec':
|
|
315
|
-
if (i + 1 >= args.length) {
|
|
316
|
-
console.error(' ✗ --output-spec requires a path');
|
|
317
|
-
process.exit(1);
|
|
318
|
-
}
|
|
319
|
-
opts.outputSpec = args[++i];
|
|
624
|
+
case '--dry-run':
|
|
625
|
+
opts.dryRun = true;
|
|
320
626
|
break;
|
|
321
627
|
case '--adapter':
|
|
322
628
|
case '-a':
|
|
323
|
-
|
|
324
|
-
|
|
629
|
+
opts.adapter = value(i++, arg);
|
|
630
|
+
break;
|
|
631
|
+
case '--concurrency':
|
|
632
|
+
case '-c': {
|
|
633
|
+
const raw = value(i++, arg);
|
|
634
|
+
const n = Number(raw);
|
|
635
|
+
if (!/^\d+$/.test(raw) || n < 1 || n > 50) {
|
|
636
|
+
console.error(` ✗ --concurrency must be a whole number from 1 to 50, not "${raw}"`);
|
|
325
637
|
process.exit(1);
|
|
326
638
|
}
|
|
327
|
-
opts.
|
|
639
|
+
opts.concurrency = n;
|
|
328
640
|
break;
|
|
641
|
+
}
|
|
329
642
|
case '--verbose':
|
|
330
643
|
opts.verbose = true;
|
|
331
644
|
break;
|
|
332
|
-
case '--dry-run':
|
|
333
|
-
case '--dryRun':
|
|
334
|
-
opts.dryRun = true;
|
|
335
|
-
break;
|
|
336
|
-
case '--skip-validation':
|
|
337
|
-
opts.skipValidation = true;
|
|
338
|
-
break;
|
|
339
645
|
default:
|
|
340
|
-
console.error(` ✗ Unknown option: ${arg}
|
|
646
|
+
console.error(` ✗ Unknown option: ${arg}`);
|
|
647
|
+
console.error(` ${c.dim('Accepts:')} --yes --dry-run --adapter --concurrency --verbose --help${allowPrd ? ' --prd' : ''}`);
|
|
341
648
|
process.exit(1);
|
|
342
649
|
}
|
|
343
650
|
}
|
|
344
651
|
return opts;
|
|
345
652
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const MAX_PRD_FIX_RETRIES = 2;
|
|
355
|
-
let fixedPrdContent = prdContent;
|
|
356
|
-
let prdValidationErrors = initialErrors;
|
|
357
|
-
let prdFixed = false;
|
|
358
|
-
for (let attempt = 1; attempt <= MAX_PRD_FIX_RETRIES; attempt++) {
|
|
359
|
-
const label = `Fix PRD attempt ${attempt}/${MAX_PRD_FIX_RETRIES}…`;
|
|
360
|
-
console.log(stepLabel(3, totalSteps, label));
|
|
361
|
-
try {
|
|
362
|
-
await runPromptStep({
|
|
363
|
-
...sharedOpts,
|
|
364
|
-
template: 'fix-prd',
|
|
365
|
-
goalText: fixedPrdContent,
|
|
366
|
-
contextText: prdValidationErrors,
|
|
367
|
-
outputPath: prdPath,
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
catch (err) {
|
|
371
|
-
console.error(`\n ✗ Step 3 (attempt ${attempt}) failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
372
|
-
process.exit(1);
|
|
373
|
-
}
|
|
374
|
-
console.log(c.dim(` Re-validating after fix…`));
|
|
375
|
-
fixedPrdContent = await readFile(prdPath, 'utf8');
|
|
376
|
-
let revalidation;
|
|
377
|
-
try {
|
|
378
|
-
revalidation = await runPromptStep({
|
|
379
|
-
...sharedOpts,
|
|
380
|
-
template: 'validate-prd',
|
|
381
|
-
goalText: `<!-- validation-pass: ${attempt + 1} -->\n${fixedPrdContent}`,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
catch (err) {
|
|
385
|
-
console.error(`\n ✗ Re-validation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
386
|
-
process.exit(1);
|
|
387
|
-
}
|
|
388
|
-
if (revalidation.isValid) {
|
|
389
|
-
console.log(c.green(` ✓ PRD fixed and validated\n`));
|
|
390
|
-
prdFixed = true;
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
prdValidationErrors = revalidation.errors ?? revalidation.rawOutput;
|
|
394
|
-
if (attempt < MAX_PRD_FIX_RETRIES) {
|
|
395
|
-
console.log(c.yellow(` ⚠ Still has issues after fix attempt ${attempt} — retrying…\n`));
|
|
396
|
-
console.log(c.dim(prdValidationErrors));
|
|
397
|
-
console.log();
|
|
398
|
-
}
|
|
653
|
+
/**
|
|
654
|
+
* The runtime for the whole plan, and the run after it, chosen once by the
|
|
655
|
+
* rule `resolveAdapter` owns: `--adapter`, else what `opencastle init` set up,
|
|
656
|
+
* else what is on PATH.
|
|
657
|
+
*/
|
|
658
|
+
async function chooseRuntime(projectRoot, explicit) {
|
|
659
|
+
try {
|
|
660
|
+
return await resolveAdapter({ projectRoot, explicit });
|
|
399
661
|
}
|
|
400
|
-
|
|
401
|
-
console.
|
|
402
|
-
|
|
403
|
-
console.log(c.dim(prdValidationErrors));
|
|
404
|
-
console.log(c.dim(`\n PRD saved to ${relPath(prdPath)} with best available fixes.`) +
|
|
405
|
-
c.dim(`\n You can re-validate later with:\n`) +
|
|
406
|
-
` opencastle convoy plan --prd ${relPath(prdPath)}${adapterFlag ? ` --adapter ${adapterFlag}` : ''}\n`);
|
|
662
|
+
catch (err) {
|
|
663
|
+
console.error(` ${c.red('✗')} ${message(err)}`);
|
|
664
|
+
process.exit(1);
|
|
407
665
|
}
|
|
408
666
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
667
|
+
/**
|
|
668
|
+
* Plan, show the plan once, ask once, run.
|
|
669
|
+
*
|
|
670
|
+
* Nothing runs without a yes. A closed stdin is not one: piped into a script,
|
|
671
|
+
* the old prompt's default-yes started a full convoy nobody had agreed to.
|
|
672
|
+
*/
|
|
673
|
+
async function planThenRun(source, opts, pkgRoot) {
|
|
674
|
+
const projectRoot = process.cwd();
|
|
675
|
+
const runtime = await chooseRuntime(findProjectRoot(projectRoot) ?? projectRoot, opts.adapter);
|
|
676
|
+
console.log(`\n ${c.bold('opencastle convoy')} ${c.dim('— planning, read-only')}`);
|
|
677
|
+
console.log(` ${c.dim('Runtime:')} ${runtime.detail}\n`);
|
|
678
|
+
let outcome;
|
|
679
|
+
try {
|
|
680
|
+
outcome = await planConvoy({
|
|
681
|
+
task: 'task' in source ? source.task : undefined,
|
|
682
|
+
prdPath: 'prd' in source ? source.prd : undefined,
|
|
683
|
+
adapter: runtime.adapter,
|
|
684
|
+
adapterName: runtime.name,
|
|
685
|
+
pkgRoot,
|
|
686
|
+
verbose: opts.verbose,
|
|
687
|
+
critic: opts.yes && !opts.dryRun,
|
|
688
|
+
});
|
|
414
689
|
}
|
|
415
|
-
|
|
416
|
-
console.error(
|
|
417
|
-
|
|
690
|
+
catch (err) {
|
|
691
|
+
console.error(`\n ${c.red('✗')} Planning stopped: ${message(err)}`);
|
|
692
|
+
await cleanupAdapters();
|
|
418
693
|
process.exit(1);
|
|
419
694
|
}
|
|
420
|
-
|
|
421
|
-
console.
|
|
695
|
+
for (const row of renderPlan(outcome, process.stdout.columns ?? 100))
|
|
696
|
+
console.log(row);
|
|
697
|
+
const later = `opencastle convoy run ${relPath(outcome.specPath)}`;
|
|
698
|
+
if (outcome.problems.length > 0) {
|
|
699
|
+
console.error(` ${c.red('✗')} The plan still fails these checks, so it was not started:`);
|
|
700
|
+
for (const p of outcome.problems)
|
|
701
|
+
console.error(` • ${p}`);
|
|
702
|
+
console.error(`\n Edit the spec, then: ${later}\n`);
|
|
703
|
+
await cleanupAdapters();
|
|
422
704
|
process.exit(1);
|
|
423
705
|
}
|
|
424
|
-
if (opts.
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
console.error(` ✗ PRD file not found: ${opts.prd}`);
|
|
428
|
-
process.exit(1);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
const totalSteps = opts.skipValidation ? 4 : 7;
|
|
432
|
-
const mcpServers = await readProjectMcpServers(process.cwd());
|
|
433
|
-
const sharedOpts = {
|
|
434
|
-
adapterName: opts.adapter ?? undefined,
|
|
435
|
-
verbose: opts.verbose,
|
|
436
|
-
pkgRoot,
|
|
437
|
-
...(mcpServers.length ? { mcpServers } : {}),
|
|
438
|
-
};
|
|
439
|
-
console.log(c.bold('\n opencastle convoy\n'));
|
|
440
|
-
// ── Step 1: Generate PRD ──────────────────────────────────────────────────
|
|
441
|
-
let prdPath;
|
|
442
|
-
if (opts.prd) {
|
|
443
|
-
prdPath = resolve(process.cwd(), opts.prd);
|
|
444
|
-
console.log(c.dim(` [−] Skipping PRD generation — using: ${relPath(prdPath)}`));
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
console.log(stepLabel(1, totalSteps, 'Generating PRD…'));
|
|
448
|
-
let result;
|
|
449
|
-
try {
|
|
450
|
-
result = await runPromptStep({
|
|
451
|
-
...sharedOpts,
|
|
452
|
-
template: 'generate-prd',
|
|
453
|
-
goalText: opts.text,
|
|
454
|
-
outputPath: opts.outputPrd ? resolve(process.cwd(), opts.outputPrd) : undefined,
|
|
455
|
-
dryRun: opts.dryRun,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
catch (err) {
|
|
459
|
-
console.error(`\n ✗ Step 1 failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
460
|
-
process.exit(1);
|
|
461
|
-
}
|
|
462
|
-
if (opts.dryRun) {
|
|
463
|
-
console.log(c.dim('\n [dry-run] Stopping after step 1. Remove --dry-run to run the full pipeline.'));
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
prdPath = result.outputPath;
|
|
467
|
-
console.log(c.green(` ✓ PRD written to ${relPath(prdPath)}\n`));
|
|
468
|
-
}
|
|
469
|
-
// Handle --dry-run when PRD was provided externally (not generated)
|
|
470
|
-
if (opts.dryRun && opts.prd) {
|
|
471
|
-
console.log(c.dim('\n [dry-run] Nothing to preview — PRD already provided via --prd. Remove --dry-run to continue.'));
|
|
706
|
+
if (opts.dryRun) {
|
|
707
|
+
console.log(` ${c.dim('Dry run — not started. To run it:')} ${later}\n`);
|
|
708
|
+
await cleanupAdapters();
|
|
472
709
|
return;
|
|
473
710
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const complexityFilePath = opts.complexity
|
|
481
|
-
? resolve(process.cwd(), opts.complexity)
|
|
482
|
-
: deriveComplexityPath(prdPath);
|
|
483
|
-
// Check for cached / provided complexity before launching LLM calls
|
|
484
|
-
if (opts.complexity) {
|
|
485
|
-
if (!existsSync(complexityFilePath)) {
|
|
486
|
-
console.error(` ✗ Complexity file not found: ${opts.complexity}`);
|
|
487
|
-
process.exit(1);
|
|
488
|
-
}
|
|
489
|
-
try {
|
|
490
|
-
const raw = await readFile(complexityFilePath, 'utf8');
|
|
491
|
-
complexity = parseComplexityAssessment(raw);
|
|
492
|
-
if (complexity) {
|
|
493
|
-
console.log(c.dim(` [−] Using existing complexity assessment: ${relPath(complexityFilePath)}`));
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
console.error(` ✗ Invalid complexity file: ${opts.complexity}`);
|
|
497
|
-
process.exit(1);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
catch (err) {
|
|
501
|
-
console.error(` ✗ Failed to read complexity file: ${err instanceof Error ? err.message : String(err)}`);
|
|
502
|
-
process.exit(1);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
else if (existsSync(complexityFilePath)) {
|
|
506
|
-
try {
|
|
507
|
-
const raw = await readFile(complexityFilePath, 'utf8');
|
|
508
|
-
const cached = parseComplexityAssessment(raw);
|
|
509
|
-
if (cached) {
|
|
510
|
-
complexity = cached;
|
|
511
|
-
console.log(c.dim(` [−] Using existing complexity assessment: ${relPath(complexityFilePath)}`));
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
catch {
|
|
515
|
-
// ignore — fall through to LLM assessment
|
|
516
|
-
}
|
|
711
|
+
const go = opts.yes || (await confirm('Run it?', true, 'refuse'));
|
|
712
|
+
closePrompts();
|
|
713
|
+
if (!go) {
|
|
714
|
+
console.log(`\n ${c.dim('Not started. To run it later:')} ${later}\n`);
|
|
715
|
+
await cleanupAdapters();
|
|
716
|
+
return;
|
|
517
717
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
console.log(stepLabel(2, totalSteps, 'Validating PRD…'));
|
|
525
|
-
console.log(stepLabel(complexityStep, totalSteps, 'Assessing complexity…'));
|
|
526
|
-
console.log(c.dim(` (running in parallel)\n`));
|
|
527
|
-
const [validationResult, complexityResult] = await Promise.all([
|
|
528
|
-
runPromptStep({
|
|
529
|
-
...sharedOpts,
|
|
530
|
-
template: 'validate-prd',
|
|
531
|
-
goalText: `<!-- validation-pass: 1 -->\n${prdContent}`,
|
|
532
|
-
}).catch((err) => {
|
|
533
|
-
console.error(`\n ✗ Validation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
534
|
-
return null;
|
|
535
|
-
}),
|
|
536
|
-
runPromptStep({
|
|
537
|
-
...sharedOpts,
|
|
538
|
-
template: 'assess-complexity',
|
|
539
|
-
filePath: prdPath,
|
|
540
|
-
contextText: opts.text ?? undefined,
|
|
541
|
-
}).catch((err) => {
|
|
542
|
-
console.warn(c.yellow(` ⚠ Complexity assessment failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
543
|
-
return null;
|
|
544
|
-
}),
|
|
545
|
-
]);
|
|
546
|
-
// Process complexity result
|
|
547
|
-
if (complexityResult) {
|
|
548
|
-
complexity = parseComplexityAssessment(complexityResult.rawOutput);
|
|
549
|
-
if (complexity) {
|
|
550
|
-
await writeFile(complexityFilePath, JSON.stringify(complexity, null, 2), 'utf8');
|
|
551
|
-
console.log(c.green(` ✓ Complexity assessment saved to ${relPath(complexityFilePath)}`));
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
// Process validation result
|
|
555
|
-
if (!validationResult) {
|
|
556
|
-
process.exit(1);
|
|
557
|
-
}
|
|
558
|
-
if (!validationResult.isValid) {
|
|
559
|
-
let prdValidationErrors = validationResult.errors ?? validationResult.rawOutput;
|
|
560
|
-
console.log(c.yellow(` ⚠ PRD has validation issues — attempting auto-fix…\n`));
|
|
561
|
-
console.log(c.dim(prdValidationErrors));
|
|
562
|
-
console.log();
|
|
563
|
-
await fixPrd(sharedOpts, prdPath, prdContent, prdValidationErrors, totalSteps, opts.adapter);
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
console.log(c.green(` ✓ PRD is valid\n`));
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
else if (needsValidation) {
|
|
570
|
-
// Only validation needed (complexity was cached)
|
|
571
|
-
console.log(stepLabel(2, totalSteps, 'Validating PRD…'));
|
|
572
|
-
let result;
|
|
573
|
-
try {
|
|
574
|
-
result = await runPromptStep({
|
|
575
|
-
...sharedOpts,
|
|
576
|
-
template: 'validate-prd',
|
|
577
|
-
goalText: `<!-- validation-pass: 1 -->\n${prdContent}`,
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
catch (err) {
|
|
581
|
-
console.error(`\n ✗ Step 2 failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
582
|
-
process.exit(1);
|
|
583
|
-
}
|
|
584
|
-
if (!result.isValid) {
|
|
585
|
-
let prdValidationErrors = result.errors ?? result.rawOutput;
|
|
586
|
-
console.log(c.yellow(` ⚠ PRD has validation issues — attempting auto-fix…\n`));
|
|
587
|
-
console.log(c.dim(prdValidationErrors));
|
|
588
|
-
console.log();
|
|
589
|
-
await fixPrd(sharedOpts, prdPath, prdContent, prdValidationErrors, totalSteps, opts.adapter);
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
console.log(c.green(` ✓ PRD is valid\n`));
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
else {
|
|
596
|
-
// Only complexity needed (validation skipped)
|
|
597
|
-
console.log(stepLabel(complexityStep, totalSteps, 'Assessing complexity…'));
|
|
598
|
-
try {
|
|
599
|
-
const complexityResult = await runPromptStep({
|
|
600
|
-
...sharedOpts,
|
|
601
|
-
template: 'assess-complexity',
|
|
602
|
-
filePath: prdPath,
|
|
603
|
-
contextText: opts.text ?? undefined,
|
|
604
|
-
});
|
|
605
|
-
complexity = parseComplexityAssessment(complexityResult.rawOutput);
|
|
606
|
-
if (complexity) {
|
|
607
|
-
await writeFile(complexityFilePath, JSON.stringify(complexity, null, 2), 'utf8');
|
|
608
|
-
console.log(c.green(` ✓ Complexity assessment saved to ${relPath(complexityFilePath)}\n`));
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
catch (err) {
|
|
612
|
-
console.warn(c.yellow(` ⚠ Complexity assessment failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
613
|
-
console.warn(c.dim(` Falling back to single convoy strategy.\n`));
|
|
614
|
-
}
|
|
615
|
-
}
|
|
718
|
+
// The run takes the spec by its path, as `convoy run <spec>` does, on the
|
|
719
|
+
// runtime already chosen and printed above.
|
|
720
|
+
const { runSpec, exitWith } = await import('./run.js');
|
|
721
|
+
let code = 1;
|
|
722
|
+
try {
|
|
723
|
+
code = await runSpec({ spec: outcome.specPath, dryRun: false, adapter: opts.adapter, concurrency: opts.concurrency, verbose: opts.verbose, help: false }, { runtime });
|
|
616
724
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
if (complexity) {
|
|
621
|
-
if (complexity.recommended_strategy === 'chain' && complexity.convoy_groups.length > 1) {
|
|
622
|
-
// Validate complexity groups before chain generation
|
|
623
|
-
const groupValidation = validateComplexityGroups(complexity);
|
|
624
|
-
if (!groupValidation.valid) {
|
|
625
|
-
console.log(c.yellow(` ⚠ Complexity groups failed validation: ${groupValidation.reason}`));
|
|
626
|
-
console.log(c.yellow(` Falling back to single convoy strategy.\n`));
|
|
627
|
-
// Fall through to single-spec generation below
|
|
628
|
-
}
|
|
629
|
-
else {
|
|
630
|
-
// Sort groups in dependency order
|
|
631
|
-
complexity.convoy_groups = topologicalSortGroups(complexity.convoy_groups);
|
|
632
|
-
console.log(c.cyan(` ℹ`) +
|
|
633
|
-
` Complexity: ${complexity.complexity} | Strategy: chain | ${complexity.convoy_groups.length} convoy groups\n`);
|
|
634
|
-
console.log(` Chain plan:`);
|
|
635
|
-
for (let i = 0; i < complexity.convoy_groups.length; i++) {
|
|
636
|
-
const g = complexity.convoy_groups[i];
|
|
637
|
-
const depStr = g.depends_on.length > 0 ? ` → depends on: ${g.depends_on.join(', ')}` : '';
|
|
638
|
-
console.log(` ${i + 1}. ${g.name.padEnd(20)} (phases: ${g.phases.join(', ')})${depStr}`);
|
|
639
|
-
}
|
|
640
|
-
console.log();
|
|
641
|
-
const convoyDir = resolve(process.cwd(), '.opencastle', 'convoys');
|
|
642
|
-
await mkdir(convoyDir, { recursive: true });
|
|
643
|
-
// Extract feature name early for convoy naming
|
|
644
|
-
const chainPrdContent = await readFile(prdPath, 'utf8');
|
|
645
|
-
const featureNameMatch = chainPrdContent.match(/^# (.+?)\s*(?:—|-)?\s*PRD/m);
|
|
646
|
-
const featureName = featureNameMatch
|
|
647
|
-
? featureNameMatch[1].trim().toLowerCase().replace(/[^a-z0-9]+/g, '-')
|
|
648
|
-
: 'feature';
|
|
649
|
-
const groupSpecPaths = [];
|
|
650
|
-
for (let i = 0; i < complexity.convoy_groups.length; i++) {
|
|
651
|
-
const group = complexity.convoy_groups[i];
|
|
652
|
-
console.log(c.cyan(` [${i + 1}/${complexity.convoy_groups.length}] Generating convoy: ${group.name}`) + c.dim(` (phases: ${group.phases.join(', ')})`));
|
|
653
|
-
const chainGoal = [
|
|
654
|
-
complexity.original_prompt,
|
|
655
|
-
'',
|
|
656
|
-
'## Convoy Group Scope',
|
|
657
|
-
'',
|
|
658
|
-
`This is group **${i + 1} of ${complexity.convoy_groups.length}** in a convoy chain.`,
|
|
659
|
-
`Generate a convoy spec covering ONLY the phases listed below.`,
|
|
660
|
-
'',
|
|
661
|
-
`- **Group name:** ${group.name}`,
|
|
662
|
-
`- **Description:** ${group.description}`,
|
|
663
|
-
`- **Phases to include:** ${group.phases.join(', ')}`,
|
|
664
|
-
group.depends_on.length ? `- **Depends on groups:** ${group.depends_on.join(', ')}` : '',
|
|
665
|
-
].filter(Boolean).join('\n');
|
|
666
|
-
const prdContent = await readFile(prdPath, 'utf8');
|
|
667
|
-
const relevantPrd = extractRelevantPrdSections(prdContent, group.phases);
|
|
668
|
-
const relevantComplexity = filterTaskComplexityByPhases(complexity?.task_complexity, group.phases);
|
|
669
|
-
const contextForSpec = appendTaskComplexity(relevantPrd, relevantComplexity);
|
|
670
|
-
const groupSpecPath = resolve(convoyDir, `${featureName}-${group.name}.convoy.yml`);
|
|
671
|
-
const { specPath: resolvedGroupSpecPath } = await generateAndValidateSpec({
|
|
672
|
-
sharedOpts,
|
|
673
|
-
goalText: chainGoal,
|
|
674
|
-
contextText: contextForSpec,
|
|
675
|
-
specPath: groupSpecPath,
|
|
676
|
-
skipValidation: opts.skipValidation,
|
|
677
|
-
groupName: group.name,
|
|
678
|
-
featureName,
|
|
679
|
-
enrichment: complexity ? deriveSpecEnrichment(complexity) : undefined,
|
|
680
|
-
});
|
|
681
|
-
groupSpecPaths.push(resolvedGroupSpecPath);
|
|
682
|
-
}
|
|
683
|
-
// Build master pipeline spec (version 2)
|
|
684
|
-
const branchMatch = chainPrdContent.match(/`feat\/([^`]+)`/);
|
|
685
|
-
const branch = branchMatch ? `feat/${branchMatch[1]}` : `feat/${featureName}`;
|
|
686
|
-
const masterSpec = {
|
|
687
|
-
name: featureNameMatch ? featureNameMatch[1].trim() : 'Feature Pipeline',
|
|
688
|
-
version: 2,
|
|
689
|
-
branch,
|
|
690
|
-
on_failure: 'stop',
|
|
691
|
-
depends_on_convoy: groupSpecPaths.map(p => relPath(p)),
|
|
692
|
-
};
|
|
693
|
-
const masterSpecPath = resolve(convoyDir, `${featureName}-pipeline.convoy.yml`);
|
|
694
|
-
await writeFile(masterSpecPath, stringify(masterSpec), 'utf8');
|
|
695
|
-
console.log(c.green(` ✓ Generated convoy chain:\n`));
|
|
696
|
-
for (const p of groupSpecPaths) {
|
|
697
|
-
console.log(` ${relPath(p)}`);
|
|
698
|
-
}
|
|
699
|
-
console.log(` ${relPath(masterSpecPath)} ${c.dim('(master)')}`);
|
|
700
|
-
console.log();
|
|
701
|
-
console.log(` ${c.dim('Preview:')} npx opencastle convoy run -f ${relPath(masterSpecPath)} --dry-run\n` +
|
|
702
|
-
` ${c.dim('Execute:')} npx opencastle convoy run -f ${relPath(masterSpecPath)}\n`);
|
|
703
|
-
try {
|
|
704
|
-
const shouldRun = await confirm('Run the convoy chain now?', true);
|
|
705
|
-
if (shouldRun) {
|
|
706
|
-
closePrompts();
|
|
707
|
-
const runModule = await import('./run.js');
|
|
708
|
-
const runArgs = ['-f', masterSpecPath];
|
|
709
|
-
if (opts.adapter)
|
|
710
|
-
runArgs.push('-a', opts.adapter);
|
|
711
|
-
if (opts.verbose)
|
|
712
|
-
runArgs.push('--verbose');
|
|
713
|
-
await runModule.default({ args: runArgs, pkgRoot });
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
finally {
|
|
717
|
-
closePrompts();
|
|
718
|
-
await cleanupAdapters();
|
|
719
|
-
}
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
console.log(c.cyan(` ℹ`) + ` Complexity: ${complexity.complexity} | Strategy: single\n`);
|
|
725
|
-
}
|
|
725
|
+
finally {
|
|
726
|
+
closePrompts();
|
|
727
|
+
await cleanupAdapters();
|
|
726
728
|
}
|
|
727
|
-
|
|
728
|
-
const singlePrdContent = await readFile(prdPath, 'utf8');
|
|
729
|
-
const singleContextForSpec = appendTaskComplexity(singlePrdContent, complexity?.task_complexity);
|
|
730
|
-
const singleGoal = complexity?.original_prompt ?? opts.text ?? '';
|
|
731
|
-
const specResult = await generateAndValidateSpec({
|
|
732
|
-
sharedOpts,
|
|
733
|
-
goalText: singleGoal,
|
|
734
|
-
contextText: singleContextForSpec,
|
|
735
|
-
specPath: opts.outputSpec ? resolve(process.cwd(), opts.outputSpec) : undefined,
|
|
736
|
-
skipValidation: opts.skipValidation,
|
|
737
|
-
enrichment: complexity ? deriveSpecEnrichment(complexity) : undefined,
|
|
738
|
-
});
|
|
739
|
-
await printFinalSummary(prdPath, specResult.specPath, opts, pkgRoot);
|
|
729
|
+
exitWith(code);
|
|
740
730
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
console.log(c.dim(` Fix attempt ${attempt}/${MAX_FIX_RETRIES}…`));
|
|
746
|
-
let fixResult;
|
|
747
|
-
try {
|
|
748
|
-
fixResult = await runPromptStep({
|
|
749
|
-
...sharedOpts,
|
|
750
|
-
template: 'fix-convoy',
|
|
751
|
-
goalText: JSON.stringify(currentPlan, null, 2),
|
|
752
|
-
contextText: currentErrors,
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
catch (err) {
|
|
756
|
-
console.error(`\n ✗ Fix attempt ${attempt} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
757
|
-
process.exit(1);
|
|
758
|
-
}
|
|
759
|
-
const patches = parsePatches(fixResult.rawOutput);
|
|
760
|
-
if (!patches || patches.length === 0) {
|
|
761
|
-
console.warn(c.yellow(` ⚠ No valid patches returned`));
|
|
762
|
-
if (attempt >= MAX_FIX_RETRIES)
|
|
763
|
-
break;
|
|
764
|
-
continue;
|
|
765
|
-
}
|
|
766
|
-
console.log(c.dim(` Applied ${patches.length} patches`));
|
|
767
|
-
currentPlan = applyPatches(currentPlan, patches);
|
|
768
|
-
// Rebuild YAML and re-validate
|
|
769
|
-
const yaml = buildConvoyYaml(currentPlan, enrichment);
|
|
770
|
-
try {
|
|
771
|
-
const parsed = parseYaml(yaml);
|
|
772
|
-
const { valid, errors: schemaErrors } = validateSpec(parsed);
|
|
773
|
-
if (!valid) {
|
|
774
|
-
currentErrors = schemaErrors.map(e => `- Schema: ${e}`).join('\n');
|
|
775
|
-
if (attempt < MAX_FIX_RETRIES) {
|
|
776
|
-
console.log(c.yellow(` ⚠ Still has schema issues — retrying…\n`));
|
|
777
|
-
console.log(c.dim(currentErrors));
|
|
778
|
-
}
|
|
779
|
-
continue;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
catch (err) {
|
|
783
|
-
currentErrors = `YAML error: ${err instanceof Error ? err.message : String(err)}`;
|
|
784
|
-
continue;
|
|
785
|
-
}
|
|
786
|
-
await writeFile(specPath, yaml, 'utf8');
|
|
787
|
-
console.log(c.dim(` Re-validating after fix…`));
|
|
788
|
-
let revalidation;
|
|
789
|
-
try {
|
|
790
|
-
revalidation = await runPromptStep({
|
|
791
|
-
...sharedOpts,
|
|
792
|
-
template: 'validate-convoy',
|
|
793
|
-
goalText: `<!-- validation-pass: ${attempt + 1} -->\n${yaml}`,
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
catch (err) {
|
|
797
|
-
console.error(`\n ✗ Re-validation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
798
|
-
process.exit(1);
|
|
799
|
-
}
|
|
800
|
-
if (revalidation.isValid) {
|
|
801
|
-
console.log(c.green(` ✓ Fixed and validated\n`));
|
|
802
|
-
return currentPlan;
|
|
803
|
-
}
|
|
804
|
-
currentErrors = revalidation.errors ?? revalidation.rawOutput;
|
|
805
|
-
if (attempt < MAX_FIX_RETRIES) {
|
|
806
|
-
console.log(c.yellow(` ⚠ Still has issues — retrying…\n`));
|
|
807
|
-
console.log(c.dim(currentErrors));
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
// Exhausted retries — save best effort and continue with warning
|
|
811
|
-
await writeFile(specPath, buildConvoyYaml(currentPlan, enrichment), 'utf8');
|
|
812
|
-
console.log(c.yellow(`\n ⚠ Could not fully auto-fix after ${MAX_FIX_RETRIES} attempts — continuing with best-effort spec.\n`));
|
|
813
|
-
console.log(c.dim(` Remaining issues:\n`));
|
|
814
|
-
console.log(c.dim(currentErrors));
|
|
815
|
-
console.log(c.dim(`\n Spec saved to ${relPath(specPath)} with best available fixes.`) +
|
|
816
|
-
c.dim(`\n You can re-validate later with:\n`) +
|
|
817
|
-
` opencastle convoy run --file ${relPath(specPath)} --dry-run\n`);
|
|
818
|
-
return currentPlan;
|
|
731
|
+
/** `opencastle convoy "<task>"`: the task comes from the words typed, the flags from `args`. */
|
|
732
|
+
export async function planTask({ args, pkgRoot }, task) {
|
|
733
|
+
const opts = parseArgs(args, false);
|
|
734
|
+
await planThenRun({ task }, opts, pkgRoot);
|
|
819
735
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const convoyDir = resolve(process.cwd(), '.opencastle', 'convoys');
|
|
827
|
-
await mkdir(convoyDir, { recursive: true });
|
|
828
|
-
const tempJsonName = params.groupName
|
|
829
|
-
? `${params.featureName ? `${params.featureName}-` : ''}${params.groupName}.task-plan.json`
|
|
830
|
-
: `${params.featureName ?? 'task-plan'}.task-plan.json`;
|
|
831
|
-
const tempJsonPath = resolve(convoyDir, tempJsonName);
|
|
832
|
-
let taskPlanResult;
|
|
833
|
-
try {
|
|
834
|
-
taskPlanResult = await runPromptStep({
|
|
835
|
-
...params.sharedOpts,
|
|
836
|
-
template: 'generate-convoy',
|
|
837
|
-
goalText: params.goalText,
|
|
838
|
-
contextText: params.contextText,
|
|
839
|
-
});
|
|
736
|
+
/** `opencastle convoy plan --prd <file>`. */
|
|
737
|
+
export default async function pipeline({ args, pkgRoot }) {
|
|
738
|
+
const opts = parseArgs(args, true);
|
|
739
|
+
if (opts.help) {
|
|
740
|
+
console.log(HELP);
|
|
741
|
+
return;
|
|
840
742
|
}
|
|
841
|
-
|
|
842
|
-
console.error(
|
|
743
|
+
if (opts.prd === null) {
|
|
744
|
+
console.error(' ✗ Name the PRD to plan from: opencastle convoy plan --prd <file>');
|
|
745
|
+
console.log(HELP);
|
|
843
746
|
process.exit(1);
|
|
844
747
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (!result.plan) {
|
|
849
|
-
console.log(c.yellow(` ⚠ Failed to parse task plan JSON: ${result.reason}`));
|
|
850
|
-
console.log(c.dim(` Output length: ${taskPlanResult.rawOutput.length} chars`));
|
|
851
|
-
console.log(c.dim(` Temp file: ${relPath(tempJsonPath)}`));
|
|
852
|
-
console.log(c.yellow(` Retrying generation…\n`));
|
|
853
|
-
let retryResult;
|
|
854
|
-
try {
|
|
855
|
-
retryResult = await runPromptStep({
|
|
856
|
-
...params.sharedOpts,
|
|
857
|
-
template: 'generate-convoy',
|
|
858
|
-
goalText: params.goalText,
|
|
859
|
-
contextText: params.contextText,
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
catch (err) {
|
|
863
|
-
console.error(`\n ✗ Retry failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
864
|
-
process.exit(1);
|
|
865
|
-
}
|
|
866
|
-
// Overwrite temp file with retry output
|
|
867
|
-
await writeFile(tempJsonPath, retryResult.rawOutput + '\n', 'utf8');
|
|
868
|
-
result = parseTaskPlanWithReason(retryResult.rawOutput);
|
|
869
|
-
if (!result.plan) {
|
|
870
|
-
console.error(` ✗ Failed to parse task plan JSON after retry: ${result.reason}`);
|
|
871
|
-
console.error(c.dim(` Output length: ${retryResult.rawOutput.length} chars`));
|
|
872
|
-
console.error(c.dim(` Raw JSON saved to ${relPath(tempJsonPath)} for inspection.`));
|
|
873
|
-
console.error(c.dim(`\n${retryResult.rawOutput}`));
|
|
874
|
-
process.exit(1);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
let taskPlan = result.plan;
|
|
878
|
-
// Success — clean up temp file
|
|
879
|
-
await unlink(tempJsonPath).catch(() => { });
|
|
880
|
-
console.log(c.green(` ✓ Task plan generated (${taskPlan.tasks.length} tasks)`));
|
|
881
|
-
// Derive spec path from plan name if not provided
|
|
882
|
-
let resolvedSpecPath = params.specPath;
|
|
883
|
-
if (!resolvedSpecPath) {
|
|
884
|
-
const convoyDir = resolve(process.cwd(), '.opencastle', 'convoys');
|
|
885
|
-
await mkdir(convoyDir, { recursive: true });
|
|
886
|
-
const kebab = taskPlan.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
887
|
-
resolvedSpecPath = resolve(convoyDir, `${kebab}.convoy.yml`);
|
|
888
|
-
}
|
|
889
|
-
// Build YAML from JSON task plan
|
|
890
|
-
let yamlContent = buildConvoyYaml(taskPlan, params.enrichment);
|
|
891
|
-
await mkdir(resolve(resolvedSpecPath, '..'), { recursive: true });
|
|
892
|
-
await writeFile(resolvedSpecPath, yamlContent, 'utf8');
|
|
893
|
-
console.log(c.green(` ✓ Convoy spec written to ${relPath(resolvedSpecPath)}\n`));
|
|
894
|
-
if (!params.skipValidation) {
|
|
895
|
-
// Programmatic validation first
|
|
896
|
-
try {
|
|
897
|
-
const parsed = parseYaml(yamlContent);
|
|
898
|
-
const { valid, errors: schemaErrors } = validateSpec(parsed);
|
|
899
|
-
if (!valid) {
|
|
900
|
-
console.log(c.yellow(` ⚠ Schema validation issues — auto-fixing…\n`));
|
|
901
|
-
const errorText = schemaErrors.map(e => `- Schema: ${e}`).join('\n');
|
|
902
|
-
console.log(c.dim(errorText));
|
|
903
|
-
console.log();
|
|
904
|
-
taskPlan = await fixViaPatch(taskPlan, errorText, params.sharedOpts, resolvedSpecPath, params.enrichment);
|
|
905
|
-
yamlContent = buildConvoyYaml(taskPlan, params.enrichment);
|
|
906
|
-
await writeFile(resolvedSpecPath, yamlContent, 'utf8');
|
|
907
|
-
}
|
|
908
|
-
else {
|
|
909
|
-
console.log(c.dim(` ✓ Schema validation passed`));
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
catch (err) {
|
|
913
|
-
console.warn(c.yellow(` ⚠ YAML warning: ${err instanceof Error ? err.message : String(err)}`));
|
|
914
|
-
}
|
|
915
|
-
// Semantic validation (LLM)
|
|
916
|
-
const valLabel = params.groupName
|
|
917
|
-
? `Validating spec: ${params.groupName}…`
|
|
918
|
-
: 'Validating convoy spec…';
|
|
919
|
-
console.log(c.cyan(` ${valLabel}`));
|
|
920
|
-
let semanticResult;
|
|
921
|
-
try {
|
|
922
|
-
semanticResult = await runPromptStep({
|
|
923
|
-
...params.sharedOpts,
|
|
924
|
-
template: 'validate-convoy',
|
|
925
|
-
goalText: `<!-- validation-pass: 1 -->\n${await readFile(resolvedSpecPath, 'utf8')}`,
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
catch (err) {
|
|
929
|
-
console.error(`\n ✗ Semantic validation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
930
|
-
process.exit(1);
|
|
931
|
-
}
|
|
932
|
-
if (semanticResult.isValid) {
|
|
933
|
-
console.log(c.green(` ✓ Spec is valid\n`));
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
const semanticErrors = semanticResult.errors ?? semanticResult.rawOutput;
|
|
937
|
-
console.log(c.yellow(` ⚠ Semantic issues — auto-fixing…\n`));
|
|
938
|
-
console.log(c.dim(semanticErrors));
|
|
939
|
-
console.log();
|
|
940
|
-
taskPlan = await fixViaPatch(taskPlan, semanticErrors, params.sharedOpts, resolvedSpecPath, params.enrichment);
|
|
941
|
-
yamlContent = buildConvoyYaml(taskPlan, params.enrichment);
|
|
942
|
-
await writeFile(resolvedSpecPath, yamlContent, 'utf8');
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return { specPath: resolvedSpecPath, taskPlan };
|
|
946
|
-
}
|
|
947
|
-
async function printFinalSummary(prdPath, specPath, opts, pkgRoot) {
|
|
948
|
-
const prd = relPath(prdPath);
|
|
949
|
-
const spec = relPath(specPath);
|
|
950
|
-
console.log(c.bold(c.green(' Pipeline complete!\n')));
|
|
951
|
-
console.log(` PRD: ${prd}`);
|
|
952
|
-
console.log(` Convoy spec: ${spec}\n`);
|
|
953
|
-
console.log(` ${c.dim('Preview:')} npx opencastle convoy run -f ${spec} --dry-run\n` +
|
|
954
|
-
` ${c.dim('Execute:')} npx opencastle convoy run -f ${spec}\n`);
|
|
955
|
-
try {
|
|
956
|
-
const shouldRun = await confirm('Run the convoy now?', true);
|
|
957
|
-
if (shouldRun) {
|
|
958
|
-
closePrompts();
|
|
959
|
-
const runModule = await import('./run.js');
|
|
960
|
-
const runArgs = ['-f', specPath];
|
|
961
|
-
if (opts.adapter)
|
|
962
|
-
runArgs.push('-a', opts.adapter);
|
|
963
|
-
if (opts.verbose)
|
|
964
|
-
runArgs.push('--verbose');
|
|
965
|
-
await runModule.default({ args: runArgs, pkgRoot });
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
finally {
|
|
969
|
-
closePrompts();
|
|
970
|
-
await cleanupAdapters();
|
|
748
|
+
if (!existsSync(resolve(process.cwd(), opts.prd))) {
|
|
749
|
+
console.error(` ✗ PRD not found: ${opts.prd}`);
|
|
750
|
+
process.exit(1);
|
|
971
751
|
}
|
|
752
|
+
await planThenRun({ prd: opts.prd }, opts, pkgRoot);
|
|
972
753
|
}
|
|
973
754
|
//# sourceMappingURL=pipeline.js.map
|