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/run.ts
CHANGED
|
@@ -1,1258 +1,473 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `opencastle convoy run <spec.yml>` and `opencastle convoy resume`.
|
|
3
|
+
*
|
|
4
|
+
* Two things, and only two: start a spec, or continue the newest run that is
|
|
5
|
+
* not done. This file used to be a 1,250-line parser in front of three
|
|
6
|
+
* executors — the convoy engine, a legacy executor and a pipeline orchestrator —
|
|
7
|
+
* with watch mode, formulas, a dead-letter queue and a status report bolted on.
|
|
8
|
+
* Each path finished a run in its own way, so the summary printed twice and a
|
|
9
|
+
* finished run could sit waiting for Ctrl+C. The engine now does the work and
|
|
10
|
+
* prints its own summary; this file picks the runtime, shows the live view,
|
|
11
|
+
* and exits with the engine's code.
|
|
12
|
+
*/
|
|
1
13
|
import { readFile } from 'node:fs/promises'
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
14
|
import { resolve } from 'node:path'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { createExecutor, buildPhases } from './run/executor.js'
|
|
7
|
-
import { getAdapter, detectAdapter } from './run/adapters/index.js'
|
|
15
|
+
import { parseTaskSpecText } from './run/schema.js'
|
|
16
|
+
import { resolveAdapter, cleanupAdapters, type ResolvedAdapter } from './run/adapters/index.js'
|
|
8
17
|
import { permissionModeError } from './run/adapters/permission-modes.js'
|
|
9
|
-
import {
|
|
18
|
+
import { findProjectRoot, isRunAlive, readRun, readRunSpec, readRuns, type RunSummary } from './convoy/read-model.js'
|
|
19
|
+
import { checkConvoyPlan, createConvoyEngine, RESUME_RESET_STATUSES, type ConvoyResult } from './convoy/engine.js'
|
|
20
|
+
import { EngineAlreadyRunningError } from './convoy/lock.js'
|
|
21
|
+
import { startDashboard, type DashboardHandle } from './dashboard.js'
|
|
22
|
+
import { nearest } from './nearest.js'
|
|
10
23
|
import { c } from './prompt.js'
|
|
24
|
+
import type { TaskSpec } from './convoy/spec-types.js'
|
|
11
25
|
import type { CliContext } from './types.js'
|
|
12
|
-
import { PERMISSION_MODES } from './convoy/spec-types.js'
|
|
13
|
-
import type { RunOptions, PermissionMode, TaskSpec } from './convoy/spec-types.js'
|
|
14
|
-
import type { ConvoyResult } from './convoy/engine.js'
|
|
15
|
-
import type { PipelineResult } from './convoy/pipeline.js'
|
|
16
|
-
import { EngineAlreadyRunningError } from './convoy/lock.js'
|
|
17
|
-
|
|
18
|
-
function formatTokens(n: number): string {
|
|
19
|
-
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + 'M'
|
|
20
|
-
if (n >= 1_000) return (n / 1_000).toFixed(1) + 'K'
|
|
21
|
-
return String(n)
|
|
22
|
-
}
|
|
23
26
|
|
|
24
|
-
const
|
|
25
|
-
opencastle convoy run [options]
|
|
27
|
+
const RUN_HELP = `
|
|
28
|
+
opencastle convoy run <spec.yml> [options]
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
Run a convoy spec: one you wrote, or one opencastle convoy "<task>" wrote to
|
|
31
|
+
.opencastle/convoys/. The work lands on a branch of its own (the spec's
|
|
32
|
+
branch, or convoy/<name>-<id>); your checkout is never touched.
|
|
29
33
|
|
|
30
34
|
Options:
|
|
31
|
-
--
|
|
32
|
-
--
|
|
33
|
-
|
|
34
|
-
--
|
|
35
|
-
|
|
36
|
-
--concurrency, -c <n> Override max parallel tasks
|
|
37
|
-
--adapter, -a <name> Override agent runtime adapter
|
|
38
|
-
--report-dir <path> Where to write run reports, for legacy specs only
|
|
39
|
-
(default: .opencastle/runs). Convoy specs record to
|
|
40
|
-
.opencastle/convoy.db and .opencastle/logs instead
|
|
41
|
-
--permission-mode <m> How much a worker may do unattended: default,
|
|
42
|
-
acceptEdits (the default), auto, dontAsk,
|
|
43
|
-
bypassPermissions, plan
|
|
44
|
-
--verbose Show full agent output
|
|
45
|
-
--resume Resume the last interrupted convoy from .opencastle/convoy.db
|
|
46
|
-
--retry-failed [task-id] Retry failed/gate-failed/timed-out tasks from the last convoy
|
|
47
|
-
--status Print the current convoy state from .opencastle/convoy.db
|
|
48
|
-
--dlq-list List dead letter queue entries
|
|
49
|
-
--dlq-resolve <id> Resolve a DLQ entry (requires --resolution)
|
|
50
|
-
--dlq-retry <id> Reset a DLQ task to pending for retry
|
|
51
|
-
--convoy <id> Filter by convoy ID (used with --dlq-list)
|
|
52
|
-
--resolution <text> Resolution text (used with --dlq-resolve)
|
|
53
|
-
--watch Keep running, re-triggering on file changes, cron,
|
|
54
|
-
or git push (convoy specs only)
|
|
55
|
-
--watch-config <p> Path to watch configuration file (overrides spec
|
|
56
|
-
watch config)
|
|
57
|
-
--clear-scratchpad Clear scratchpad data at watch start
|
|
35
|
+
--dry-run Check the spec and show what would run; start nothing
|
|
36
|
+
--adapter, -a <name> Agent runtime: claude, codex, cursor, opencode or copilot
|
|
37
|
+
(default: the spec's, else the one opencastle init set up)
|
|
38
|
+
--concurrency, -c <n> Tasks at once (default: the spec's, else 4)
|
|
39
|
+
--verbose Stream agent output
|
|
58
40
|
--help, -h Show this help
|
|
59
41
|
`
|
|
60
42
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
* Four entry points build a spec — a fresh run, a retry, a convoy resume and a
|
|
65
|
-
* pipeline resume — and each used to repeat this by hand, which is how a flag
|
|
66
|
-
* comes to work on one of them and not the others.
|
|
67
|
-
*/
|
|
68
|
-
function applyCliOverrides(spec: TaskSpec, opts: RunOptions): void {
|
|
69
|
-
if (opts.concurrency !== null) spec.concurrency = opts.concurrency
|
|
70
|
-
if (opts.adapter !== null) spec.adapter = opts.adapter
|
|
71
|
-
if (opts.permissionMode !== null) {
|
|
72
|
-
spec.defaults = { ...spec.defaults, permission_mode: opts.permissionMode }
|
|
73
|
-
}
|
|
74
|
-
if (opts.verbose) spec._verbose = true
|
|
75
|
-
}
|
|
43
|
+
const RESUME_HELP = `
|
|
44
|
+
opencastle convoy resume [options]
|
|
76
45
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
46
|
+
Continue the newest run that is not done. Failed, timed-out and interrupted
|
|
47
|
+
tasks run again, and so do the tasks a failure skipped; finished tasks are
|
|
48
|
+
kept. It runs on the branch and runtime the run started with.
|
|
81
49
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* say so; the dashboard half only registered a SIGINT handler, and four of the
|
|
90
|
-
* five then carried straight on into the next block. With the dashboard running,
|
|
91
|
-
* `convoy run` executed the whole spec on the engine and then ran it a second time
|
|
92
|
-
* on the legacy executor, and `--retry-failed` followed its retry with a full fresh
|
|
93
|
-
* run — every task done twice, and paid for twice, visible only when a dashboard
|
|
94
|
-
* was up.
|
|
95
|
-
*
|
|
96
|
-
* One copy, and it either exits or hands control back for the caller to `return`.
|
|
97
|
-
*/
|
|
98
|
-
export function finishRun(
|
|
99
|
-
dashboard: DashboardHandle | null,
|
|
100
|
-
failed: boolean,
|
|
101
|
-
retryHint?: string,
|
|
102
|
-
): void {
|
|
103
|
-
const exitCode = failed ? 1 : 0
|
|
104
|
-
const printRetryHint = (): void => {
|
|
105
|
-
if (failed && retryHint) console.log(`\n ${c.dim('Retry failed:')} ${retryHint}`)
|
|
106
|
-
}
|
|
50
|
+
Options:
|
|
51
|
+
--dry-run List the tasks that would run; start nothing
|
|
52
|
+
--adapter, -a <name> Run on another agent runtime instead
|
|
53
|
+
--concurrency, -c <n> Tasks at once
|
|
54
|
+
--verbose Stream agent output
|
|
55
|
+
--help, -h Show this help
|
|
56
|
+
`
|
|
107
57
|
|
|
108
|
-
|
|
109
|
-
console.log(`\n ${c.dim('Results saved to .opencastle/convoy.db')}`)
|
|
110
|
-
console.log(` ${c.dim('Dashboard:')} ${dashboard.url}`)
|
|
111
|
-
console.log(`\n Press Ctrl+C to stop`)
|
|
112
|
-
printRetryHint()
|
|
113
|
-
process.on('SIGINT', () => {
|
|
114
|
-
console.log('\n Dashboard stopped.\n')
|
|
115
|
-
dashboard.server.close()
|
|
116
|
-
process.exit(exitCode)
|
|
117
|
-
})
|
|
118
|
-
return
|
|
119
|
-
}
|
|
58
|
+
// ── Arguments ─────────────────────────────────────────────────────────────────
|
|
120
59
|
|
|
121
|
-
|
|
122
|
-
|
|
60
|
+
export interface RunArgs {
|
|
61
|
+
/** The spec path, as typed. Null for resume, or when it is missing. */
|
|
62
|
+
spec: string | null
|
|
63
|
+
dryRun: boolean
|
|
64
|
+
adapter: string | null
|
|
65
|
+
concurrency: number | null
|
|
66
|
+
verbose: boolean
|
|
67
|
+
help: boolean
|
|
123
68
|
}
|
|
124
69
|
|
|
125
|
-
|
|
126
|
-
* The statuses `engine.retryFailed` reopens, and the ones `engine.resume` picks
|
|
127
|
-
* up. Named here so the `--dry-run` preview and the engine cannot drift about
|
|
128
|
-
* which tasks a run would touch.
|
|
129
|
-
*/
|
|
130
|
-
export const RETRYABLE_TASK_STATUSES = [
|
|
131
|
-
'failed',
|
|
132
|
-
'gate-failed',
|
|
133
|
-
'timed-out',
|
|
134
|
-
'review-blocked',
|
|
135
|
-
'disputed',
|
|
136
|
-
] as const
|
|
137
|
-
export const RESUMABLE_TASK_STATUSES = ['pending', 'assigned', 'running'] as const
|
|
70
|
+
const KNOWN_FLAGS = ['--dry-run', '--adapter', '-a', '--concurrency', '-c', '--verbose', '--help', '-h']
|
|
138
71
|
|
|
139
72
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* `--dry-run` was read only on the fresh-run path, so combining it with either
|
|
143
|
-
* of those flags spawned agents against the user's repository for real. The flag
|
|
144
|
-
* a person reaches for to find out what will happen was the one flag that did
|
|
145
|
-
* not change what happened.
|
|
73
|
+
* Flags this command used to take, and what to do instead. Named one by one,
|
|
74
|
+
* because "unknown option" is the wrong answer to a flag our own docs taught.
|
|
146
75
|
*/
|
|
147
|
-
export
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
verb === 'retry'
|
|
162
|
-
? ' No failed tasks to retry.'
|
|
163
|
-
: ' No unfinished tasks — nothing to resume.',
|
|
164
|
-
)
|
|
165
|
-
console.log(c.dim(` (matching: ${statuses.join(', ')})\n`))
|
|
166
|
-
return
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
console.log(
|
|
170
|
-
` Would ${verb === 'retry' ? 're-run' : 'run'} ${selected.length} of ${tasks.length} task(s):`,
|
|
171
|
-
)
|
|
172
|
-
for (const t of selected) {
|
|
173
|
-
console.log(` ${t.id} ${c.dim(`— ${t.agent} [${t.status}]`)}`)
|
|
174
|
-
}
|
|
175
|
-
console.log()
|
|
76
|
+
export const REMOVED_FLAGS: Record<string, string> = {
|
|
77
|
+
'--resume': 'Use: opencastle convoy resume',
|
|
78
|
+
'--retry-failed': 'Use: opencastle convoy resume — it re-runs failed tasks too',
|
|
79
|
+
'--status': 'Use: opencastle convoy — it shows the last run and what to do next',
|
|
80
|
+
'--dlq-list': 'Failed tasks are listed by opencastle convoy, and re-run by opencastle convoy resume',
|
|
81
|
+
'--dlq-resolve': 'Failed tasks are listed by opencastle convoy, and re-run by opencastle convoy resume',
|
|
82
|
+
'--dlq-retry': 'Use: opencastle convoy resume',
|
|
83
|
+
'--formula': 'Formulas are gone: write the spec out, or plan it with opencastle convoy "<task>"',
|
|
84
|
+
'--set': 'Formulas are gone: write the spec out, or plan it with opencastle convoy "<task>"',
|
|
85
|
+
'--watch': 'Watch mode is gone: run the spec again when you want it run',
|
|
86
|
+
'--watch-config': 'Watch mode is gone: run the spec again when you want it run',
|
|
87
|
+
'--clear-scratchpad': 'Watch mode is gone: run the spec again when you want it run',
|
|
88
|
+
'--report-dir': 'Runs are recorded in .opencastle/convoy.db. See them with opencastle convoy dashboard',
|
|
89
|
+
'--permission-mode': 'Set defaults.permission_mode in the spec instead',
|
|
176
90
|
}
|
|
177
91
|
|
|
178
92
|
/**
|
|
179
|
-
*
|
|
93
|
+
* Read `convoy run` or `convoy resume` arguments.
|
|
94
|
+
*
|
|
95
|
+
* The spec is positional; `-f`/`--file` still names it, quietly, because
|
|
96
|
+
* every spec written before this change says `convoy run -f <spec>`.
|
|
180
97
|
*/
|
|
181
|
-
function
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
reportDir: null,
|
|
188
|
-
permissionMode: null,
|
|
189
|
-
verbose: false,
|
|
190
|
-
help: false,
|
|
191
|
-
resume: false,
|
|
192
|
-
status: false,
|
|
193
|
-
retryFailed: false,
|
|
194
|
-
retryFailedTaskIds: undefined,
|
|
195
|
-
dlqList: false,
|
|
196
|
-
dlqResolve: false,
|
|
197
|
-
dlqResolveId: undefined,
|
|
198
|
-
dlqResolveText: undefined,
|
|
199
|
-
dlqRetry: false,
|
|
200
|
-
dlqRetryId: undefined,
|
|
201
|
-
dlqConvoyFilter: undefined,
|
|
202
|
-
formula: null,
|
|
203
|
-
setVars: {},
|
|
204
|
-
watch: false,
|
|
205
|
-
watchConfig: null,
|
|
206
|
-
clearScratchpad: false,
|
|
98
|
+
export function parseRunArgs(args: string[], command: 'run' | 'resume'): RunArgs | { error: string } {
|
|
99
|
+
const out: RunArgs = { spec: null, dryRun: false, adapter: null, concurrency: null, verbose: false, help: false }
|
|
100
|
+
const value = (i: number, flag: string): string | { error: string } => {
|
|
101
|
+
const v = args[i + 1]
|
|
102
|
+
if (v === undefined || v.startsWith('-') || !v.trim()) return { error: `${flag} needs a value` }
|
|
103
|
+
return v
|
|
207
104
|
}
|
|
208
|
-
|
|
209
105
|
for (let i = 0; i < args.length; i++) {
|
|
210
106
|
const arg = args[i]
|
|
211
107
|
switch (arg) {
|
|
212
108
|
case '--help':
|
|
213
109
|
case '-h':
|
|
214
|
-
|
|
110
|
+
out.help = true
|
|
215
111
|
break
|
|
216
|
-
case '--file':
|
|
217
|
-
case '-f':
|
|
218
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --file requires a path'); process.exit(1) }
|
|
219
|
-
opts.file = args[++i]
|
|
220
|
-
if (!opts.file.trim()) { console.error(' ✗ --file cannot be empty'); process.exit(1) }
|
|
221
|
-
break
|
|
222
|
-
case '--dryRun':
|
|
223
112
|
case '--dry-run':
|
|
224
|
-
|
|
113
|
+
out.dryRun = true
|
|
225
114
|
break
|
|
226
|
-
case '--
|
|
227
|
-
|
|
228
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --concurrency requires a number'); process.exit(1) }
|
|
229
|
-
const val = parseInt(args[++i], 10)
|
|
230
|
-
if (!Number.isFinite(val) || val < 1) {
|
|
231
|
-
console.error(` ✗ --concurrency must be an integer >= 1`)
|
|
232
|
-
process.exit(1)
|
|
233
|
-
}
|
|
234
|
-
opts.concurrency = val
|
|
115
|
+
case '--verbose':
|
|
116
|
+
out.verbose = true
|
|
235
117
|
break
|
|
236
|
-
}
|
|
237
118
|
case '--adapter':
|
|
238
|
-
case '-a':
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
break
|
|
243
|
-
case '--report-dir':
|
|
244
|
-
if (i + 1 >= args.length) { console.error(' \u2717 --report-dir requires a path'); process.exit(1) }
|
|
245
|
-
opts.reportDir = args[++i]
|
|
246
|
-
if (!opts.reportDir.trim()) { console.error(' ✗ --report-dir cannot be empty'); process.exit(1) }
|
|
247
|
-
break
|
|
248
|
-
case '--permission-mode': {
|
|
249
|
-
if (i + 1 >= args.length) { console.error(' ✗ --permission-mode requires a mode'); process.exit(1) }
|
|
250
|
-
const mode = args[++i]
|
|
251
|
-
if (!PERMISSION_MODES.includes(mode as PermissionMode)) {
|
|
252
|
-
console.error(` ✗ --permission-mode must be one of: ${PERMISSION_MODES.join(', ')}`)
|
|
253
|
-
process.exit(1)
|
|
254
|
-
}
|
|
255
|
-
opts.permissionMode = mode as PermissionMode
|
|
119
|
+
case '-a': {
|
|
120
|
+
const v = value(i++, arg)
|
|
121
|
+
if (typeof v !== 'string') return v
|
|
122
|
+
out.adapter = v
|
|
256
123
|
break
|
|
257
124
|
}
|
|
258
|
-
case '--
|
|
259
|
-
|
|
125
|
+
case '--concurrency':
|
|
126
|
+
case '-c': {
|
|
127
|
+
const v = value(i++, arg)
|
|
128
|
+
if (typeof v !== 'string') return v
|
|
129
|
+
const n = Number(v)
|
|
130
|
+
if (!/^\d+$/.test(v) || n < 1 || n > 50) return { error: `--concurrency must be a whole number from 1 to 50, not "${v}"` }
|
|
131
|
+
out.concurrency = n
|
|
260
132
|
break
|
|
261
|
-
|
|
262
|
-
|
|
133
|
+
}
|
|
134
|
+
case '--file':
|
|
135
|
+
case '-f': {
|
|
136
|
+
if (command !== 'run') return { error: `${arg} belongs to opencastle convoy run` }
|
|
137
|
+
const v = value(i++, arg)
|
|
138
|
+
if (typeof v !== 'string') return v
|
|
139
|
+
if (out.spec !== null) return { error: `Two specs given: ${out.spec} and ${v}. Run one at a time.` }
|
|
140
|
+
out.spec = v
|
|
263
141
|
break
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
142
|
+
}
|
|
143
|
+
default: {
|
|
144
|
+
if (arg in REMOVED_FLAGS) return { error: `${arg} was removed. ${REMOVED_FLAGS[arg]}.` }
|
|
145
|
+
if (arg.startsWith('-')) {
|
|
146
|
+
const near = nearest(arg, KNOWN_FLAGS)
|
|
147
|
+
return { error: `Unknown option ${arg}. ${near ? `Did you mean ${near}?` : `It accepts ${KNOWN_FLAGS.join(', ')}.`}` }
|
|
268
148
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
opts.status = true
|
|
272
|
-
break
|
|
273
|
-
case '--dlq-list':
|
|
274
|
-
opts.dlqList = true
|
|
275
|
-
break
|
|
276
|
-
case '--dlq-resolve':
|
|
277
|
-
opts.dlqResolve = true
|
|
278
|
-
if (i + 1 < args.length && !args[i + 1].startsWith('--')) opts.dlqResolveId = args[++i]
|
|
279
|
-
break
|
|
280
|
-
case '--dlq-retry':
|
|
281
|
-
opts.dlqRetry = true
|
|
282
|
-
if (i + 1 < args.length && !args[i + 1].startsWith('--')) opts.dlqRetryId = args[++i]
|
|
283
|
-
break
|
|
284
|
-
case '--resolution':
|
|
285
|
-
if (i + 1 >= args.length) { console.error(' ✗ --resolution requires text'); process.exit(1) }
|
|
286
|
-
opts.dlqResolveText = args[++i]
|
|
287
|
-
if (!opts.dlqResolveText.trim()) { console.error(' ✗ --resolution cannot be empty'); process.exit(1) }
|
|
288
|
-
break
|
|
289
|
-
case '--convoy':
|
|
290
|
-
if (i + 1 >= args.length) { console.error(' ✗ --convoy requires an ID'); process.exit(1) }
|
|
291
|
-
opts.dlqConvoyFilter = args[++i]
|
|
292
|
-
if (!opts.dlqConvoyFilter.trim()) { console.error(' ✗ --convoy cannot be empty'); process.exit(1) }
|
|
293
|
-
break
|
|
294
|
-
case '--formula':
|
|
295
|
-
if (i + 1 >= args.length) { console.error(' ✗ --formula requires a path'); process.exit(1) }
|
|
296
|
-
opts.formula = args[++i]
|
|
297
|
-
if (!opts.formula.trim()) { console.error(' ✗ --formula cannot be empty'); process.exit(1) }
|
|
298
|
-
break
|
|
299
|
-
case '--set': {
|
|
300
|
-
if (i + 1 >= args.length) { console.error(' ✗ --set requires key=value'); process.exit(1) }
|
|
301
|
-
const pair = args[++i]
|
|
302
|
-
const eqIdx = pair.indexOf('=')
|
|
303
|
-
if (eqIdx < 1) {
|
|
304
|
-
console.error(` ✗ --set value must be in key=value format, got: ${pair}`)
|
|
305
|
-
process.exit(1)
|
|
149
|
+
if (command === 'resume') {
|
|
150
|
+
return { error: `Unexpected argument "${arg}". resume continues the newest run that is not done, and takes no name.` }
|
|
306
151
|
}
|
|
307
|
-
|
|
308
|
-
|
|
152
|
+
if (out.spec !== null) return { error: `Two specs given: ${out.spec} and ${arg}. Run one at a time.` }
|
|
153
|
+
out.spec = arg
|
|
309
154
|
}
|
|
310
|
-
case '--watch':
|
|
311
|
-
opts.watch = true
|
|
312
|
-
break
|
|
313
|
-
case '--watch-config':
|
|
314
|
-
if (i + 1 >= args.length) { console.error(' ✗ --watch-config requires a path'); process.exit(1) }
|
|
315
|
-
opts.watchConfig = args[++i]
|
|
316
|
-
if (!opts.watchConfig.trim()) { console.error(' ✗ --watch-config cannot be empty'); process.exit(1) }
|
|
317
|
-
break
|
|
318
|
-
case '--clear-scratchpad':
|
|
319
|
-
opts.clearScratchpad = true
|
|
320
|
-
break
|
|
321
|
-
default:
|
|
322
|
-
console.error(` ✗ Unknown option: ${arg}. Run with --help to see available options.`)
|
|
323
|
-
console.log(HELP)
|
|
324
|
-
process.exit(1)
|
|
325
155
|
}
|
|
326
156
|
}
|
|
327
|
-
|
|
328
|
-
return opts
|
|
157
|
+
return out
|
|
329
158
|
}
|
|
330
159
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
* flags are wired into exactly one of them:
|
|
337
|
-
*
|
|
338
|
-
* `--report-dir` is read where `createReporter` is called, which is the legacy
|
|
339
|
-
* path alone. For a `version: 1` spec, which is what every generated spec is,
|
|
340
|
-
* it was parsed, resolved against cwd, and never passed to the engine; the
|
|
341
|
-
* engine writes to SQLite and NDJSON and has no report directory at all. The
|
|
342
|
-
* flag was accepted, documented as "where to write run reports", and did
|
|
343
|
-
* nothing on the path nearly every user is on.
|
|
344
|
-
*
|
|
345
|
-
* `--watch` and its two companions are the mirror image: they live inside the
|
|
346
|
-
* convoy-engine branch, so a legacy or pipeline spec accepted them and ran
|
|
347
|
-
* once.
|
|
348
|
-
*/
|
|
349
|
-
export function specExecutor(spec: TaskSpec): 'pipeline' | 'engine' | 'legacy' {
|
|
350
|
-
if (isPipelineSpec(spec)) return 'pipeline'
|
|
351
|
-
if (isConvoySpec(spec)) return 'engine'
|
|
352
|
-
return 'legacy'
|
|
160
|
+
// ── Shared pieces ─────────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
/** Where `.opencastle/` is: the nearest one at or above the current directory, else here. */
|
|
163
|
+
function projectRootHere(): string {
|
|
164
|
+
return findProjectRoot(process.cwd()) ?? process.cwd()
|
|
353
165
|
}
|
|
354
166
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
set: (_o: RunOptions) => boolean
|
|
360
|
-
why: string
|
|
361
|
-
}> = [
|
|
362
|
-
{
|
|
363
|
-
flag: '--report-dir',
|
|
364
|
-
executor: 'legacy',
|
|
365
|
-
set: (o) => o.reportDir !== null,
|
|
366
|
-
why: 'the convoy engine records runs in .opencastle/convoy.db and .opencastle/logs, not as report files',
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
flag: '--watch',
|
|
370
|
-
executor: 'engine',
|
|
371
|
-
set: (o) => o.watch,
|
|
372
|
-
why: 'only the convoy engine has a watch loop',
|
|
373
|
-
},
|
|
374
|
-
{
|
|
375
|
-
flag: '--watch-config',
|
|
376
|
-
executor: 'engine',
|
|
377
|
-
set: (o) => o.watchConfig !== null,
|
|
378
|
-
why: 'only the convoy engine has a watch loop',
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
flag: '--clear-scratchpad',
|
|
382
|
-
executor: 'engine',
|
|
383
|
-
set: (o) => o.clearScratchpad,
|
|
384
|
-
why: 'only the convoy engine has a watch loop',
|
|
385
|
-
},
|
|
386
|
-
]
|
|
167
|
+
function fail(message: string): number {
|
|
168
|
+
console.error(` ${c.red('✗')} ${message}`)
|
|
169
|
+
return 1
|
|
170
|
+
}
|
|
387
171
|
|
|
388
172
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* never accepted and dropped. Silence here meant `--report-dir ./out` on an
|
|
393
|
-
* ordinary convoy spec exited 0 with `./out` empty.
|
|
173
|
+
* Pick the runtime, once, with the rule `resolveAdapter` owns. On resume the
|
|
174
|
+
* runtime the run recorded comes before the spec's own `adapter:`, so a run
|
|
175
|
+
* that started on the configured runtime continues on it.
|
|
394
176
|
*/
|
|
395
|
-
function
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
: 'a legacy spec (no version)'
|
|
405
|
-
console.error(` ✗ ${entry.flag} does nothing for ${kind}.`)
|
|
406
|
-
console.error(` ${entry.why}.`)
|
|
407
|
-
process.exit(1)
|
|
177
|
+
async function chooseRuntime(projectRoot: string, explicit: string | null, spec: TaskSpec, recorded?: string | null): Promise<ResolvedAdapter> {
|
|
178
|
+
const fromRecord = !explicit && Boolean(recorded)
|
|
179
|
+
const why = (text: string): string =>
|
|
180
|
+
fromRecord ? text.replace(/adapter: \S+ in the spec/, 'the runtime this run started on') : text
|
|
181
|
+
try {
|
|
182
|
+
const resolved = await resolveAdapter({ projectRoot, explicit, specAdapter: recorded || spec.adapter || null })
|
|
183
|
+
return { ...resolved, detail: why(resolved.detail) }
|
|
184
|
+
} catch (err) {
|
|
185
|
+
throw new Error(why((err as Error).message))
|
|
408
186
|
}
|
|
409
187
|
}
|
|
410
188
|
|
|
411
|
-
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
* carried out, and it has to happen here — before a worker starts, while the
|
|
419
|
-
* user can still change the flag.
|
|
420
|
-
*/
|
|
421
|
-
function assertPermissionModeSupported(adapterName: string, spec: TaskSpec): void {
|
|
422
|
-
const mode = spec.defaults?.permission_mode
|
|
423
|
-
if (!mode) return
|
|
424
|
-
const problem = permissionModeError(adapterName, mode)
|
|
425
|
-
if (problem) {
|
|
426
|
-
console.error(` ✗ ${problem}`)
|
|
427
|
-
process.exit(1)
|
|
428
|
-
}
|
|
189
|
+
/** The run's own settings, after the command line has had its say. */
|
|
190
|
+
function applyArgs(spec: TaskSpec, args: RunArgs, runtime: string): void {
|
|
191
|
+
// Written into the spec the engine gets, so the run, its resume and its
|
|
192
|
+
// record all name the same runtime.
|
|
193
|
+
spec.adapter = runtime
|
|
194
|
+
if (args.concurrency !== null) spec.concurrency = args.concurrency
|
|
195
|
+
if (args.verbose) spec._verbose = true
|
|
429
196
|
}
|
|
430
197
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
*/
|
|
434
|
-
function printAdapterError(detectionFailed: boolean, adapterName: string): void {
|
|
435
|
-
if (detectionFailed) {
|
|
436
|
-
console.error(
|
|
437
|
-
` ✗ No agent CLI found on your PATH.\n` +
|
|
438
|
-
` Install one of the following adapters:\n` +
|
|
439
|
-
` • copilot — https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli\n` +
|
|
440
|
-
` • claude — npm install -g @anthropic-ai/claude-code\n` +
|
|
441
|
-
` • cursor — https://cursor.com (Cursor > Install CLI)\n` +
|
|
442
|
-
` • opencode — https://opencode.ai\n` +
|
|
443
|
-
` • codex — npm install -g @openai/codex\n` +
|
|
444
|
-
`\n` +
|
|
445
|
-
` Or specify an adapter explicitly: opencastle convoy run --adapter <name>`
|
|
446
|
-
)
|
|
447
|
-
} else {
|
|
448
|
-
const hints: Record<string, string> = {
|
|
449
|
-
'claude':
|
|
450
|
-
' Install: npm install -g @anthropic-ai/claude-code\n' +
|
|
451
|
-
' Docs: https://docs.anthropic.com/en/docs/claude-code',
|
|
452
|
-
copilot:
|
|
453
|
-
' Requires the Copilot CLI installed and authenticated:\n' +
|
|
454
|
-
' https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli\n' +
|
|
455
|
-
' Docs: https://docs.github.com/en/copilot',
|
|
456
|
-
cursor:
|
|
457
|
-
' The Cursor agent CLI ships with the Cursor editor.\n' +
|
|
458
|
-
' Install Cursor from https://cursor.com and ensure the\n' +
|
|
459
|
-
' "agent" command is on your PATH (Cursor > Install CLI).',
|
|
460
|
-
opencode:
|
|
461
|
-
' Install OpenCode from https://opencode.ai\n' +
|
|
462
|
-
' Ensure the "opencode" command is on your PATH.',
|
|
463
|
-
codex:
|
|
464
|
-
' Install: npm install -g @openai/codex\n' +
|
|
465
|
-
' Docs: https://developers.openai.com/codex',
|
|
466
|
-
}
|
|
467
|
-
const cliName = adapterName === 'cursor' ? 'agent' : adapterName
|
|
468
|
-
const hint = hints[adapterName] ?? ''
|
|
469
|
-
console.error(
|
|
470
|
-
` ✗ Adapter "${adapterName}" is not available.\n` +
|
|
471
|
-
` Make sure the "${cliName}" CLI is installed and on your PATH.\n` +
|
|
472
|
-
hint
|
|
473
|
-
)
|
|
474
|
-
}
|
|
198
|
+
function concurrencyOf(spec: TaskSpec): number {
|
|
199
|
+
return typeof spec.concurrency === 'number' ? spec.concurrency : (spec.defaults?.max_swarm_concurrency ?? 4)
|
|
475
200
|
}
|
|
476
201
|
|
|
477
202
|
/**
|
|
478
|
-
*
|
|
203
|
+
* The live dashboard, on a terminal and outside CI. A run in a pipeline has
|
|
204
|
+
* nobody to look at it, and a port held open there is a port held for nothing.
|
|
479
205
|
*/
|
|
480
|
-
function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
(result.summary.timedOut > 0 ? ` | ${result.summary.timedOut} timed out` : '')
|
|
488
|
-
)
|
|
489
|
-
if (result.gateResults) {
|
|
490
|
-
const gatesPassed = result.gateResults.filter(g => g.passed).length
|
|
491
|
-
const gatesFailed = result.gateResults.filter(g => !g.passed).length
|
|
492
|
-
console.log(` Gates: ${gatesPassed}/${result.gateResults.length} passed${gatesFailed > 0 ? ` | ${gatesFailed} failed` : ''}`)
|
|
493
|
-
for (const g of result.gateResults) {
|
|
494
|
-
console.log(` ${g.passed ? '✓' : '✗'} ${g.command}`)
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if (result.cost) {
|
|
498
|
-
const parts = [`Tokens: ${formatTokens(result.cost.total_tokens)}`]
|
|
499
|
-
if (result.cost.total_cost_usd != null) {
|
|
500
|
-
parts.push(`Cost: $${result.cost.total_cost_usd.toFixed(2)}`)
|
|
501
|
-
}
|
|
502
|
-
console.log(` ${parts.join(' | ')}`)
|
|
206
|
+
async function maybeStartDashboard(projectRoot: string): Promise<DashboardHandle | null> {
|
|
207
|
+
if (!process.stdout.isTTY || process.env.CI) return null
|
|
208
|
+
try {
|
|
209
|
+
return await startDashboard({ projectRoot, port: 4300, open: false })
|
|
210
|
+
} catch {
|
|
211
|
+
// A busy port or a missing page must not stop the run itself.
|
|
212
|
+
return null
|
|
503
213
|
}
|
|
504
214
|
}
|
|
505
215
|
|
|
506
216
|
/**
|
|
507
|
-
*
|
|
217
|
+
* Run the engine, then let go of everything: the dashboard's server, any agent
|
|
218
|
+
* an adapter still holds. Whatever happens, the caller gets an exit code back and
|
|
219
|
+
* nothing is left keeping the process alive.
|
|
508
220
|
*/
|
|
509
|
-
function
|
|
510
|
-
|
|
511
|
-
console.log(`
|
|
512
|
-
console.log(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
(result.
|
|
516
|
-
)
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
parts.push(`Cost: $${result.cost.total_cost_usd.toFixed(2)}`)
|
|
525
|
-
}
|
|
526
|
-
console.log(` ${parts.join(' | ')}`)
|
|
221
|
+
async function drive(work: () => Promise<ConvoyResult>, projectRoot: string): Promise<number> {
|
|
222
|
+
const dashboard = await maybeStartDashboard(projectRoot)
|
|
223
|
+
if (dashboard) console.log(` ${c.dim('Live view:')} ${dashboard.url}`)
|
|
224
|
+
console.log('')
|
|
225
|
+
try {
|
|
226
|
+
const result = await work()
|
|
227
|
+
return result.exitCode ?? (result.status === 'done' ? 0 : 1)
|
|
228
|
+
} catch (err) {
|
|
229
|
+
if (err instanceof EngineAlreadyRunningError) {
|
|
230
|
+
return fail(`${err.message}\n Watch it with: opencastle convoy dashboard`)
|
|
231
|
+
}
|
|
232
|
+
return fail((err as Error).message)
|
|
233
|
+
} finally {
|
|
234
|
+
await dashboard?.close()
|
|
235
|
+
await cleanupAdapters()
|
|
527
236
|
}
|
|
528
237
|
}
|
|
529
238
|
|
|
530
|
-
|
|
531
|
-
* CLI entry point for the `run` command.
|
|
532
|
-
*/
|
|
533
|
-
export default async function run({ args, pkgRoot }: CliContext): Promise<void> {
|
|
534
|
-
const opts = parseArgs(args)
|
|
239
|
+
// ── convoy run <spec.yml> ─────────────────────────────────────────────────────
|
|
535
240
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
241
|
+
function fit(text: string, width: number): string {
|
|
242
|
+
return text.length <= width ? text.padEnd(width) : text.slice(0, Math.max(0, width - 1)) + '…'
|
|
243
|
+
}
|
|
540
244
|
|
|
541
|
-
|
|
245
|
+
/** What a run would do: the tasks and their order, where the work lands, and on what. */
|
|
246
|
+
function describePlan(spec: TaskSpec, runtime: string): string[] {
|
|
247
|
+
const tasks = spec.tasks ?? []
|
|
248
|
+
const rows = tasks.map((t) => ({
|
|
249
|
+
id: t.id,
|
|
250
|
+
agent: t.agent,
|
|
251
|
+
deps: t.depends_on.length ? t.depends_on.join(', ') : '–',
|
|
252
|
+
files: t.files.length ? t.files.join(', ') : '(any)',
|
|
253
|
+
}))
|
|
254
|
+
const width = (pick: (r: (typeof rows)[number]) => string, header: string, cap: number): number =>
|
|
255
|
+
Math.min(cap, Math.max(header.length, ...rows.map((r) => pick(r).length)))
|
|
256
|
+
const idW = width((r) => r.id, 'TASK', 32)
|
|
257
|
+
const agentW = width((r) => r.agent, 'AGENT', 18)
|
|
258
|
+
const depsW = width((r) => r.deps, 'WAITS FOR', 30)
|
|
259
|
+
const line = (a: string, b: string, d: string, f: string): string =>
|
|
260
|
+
` ${fit(a, idW)} ${fit(b, agentW)} ${fit(d, depsW)} ${f}`
|
|
261
|
+
return [
|
|
262
|
+
` ${c.bold(`Convoy: ${spec.name}`)} ${c.dim(`— ${tasks.length} task${tasks.length === 1 ? '' : 's'}, up to ${concurrencyOf(spec)} at once`)}`,
|
|
263
|
+
'',
|
|
264
|
+
c.dim(line('TASK', 'AGENT', 'WAITS FOR', 'FILES')),
|
|
265
|
+
...rows.map((r) => line(r.id, r.agent, r.deps, r.files)),
|
|
266
|
+
'',
|
|
267
|
+
` ${c.dim('Runtime')} ${runtime}`,
|
|
268
|
+
` ${c.dim('Branch')} ${spec.branch ?? 'convoy/<name>-<id>, created when it runs'}`,
|
|
269
|
+
...(spec.gates?.length ? [` ${c.dim('Gates')} ${spec.gates.join(', ')} ${c.dim('(once, after the tasks)')}`] : []),
|
|
270
|
+
]
|
|
271
|
+
}
|
|
542
272
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
console.log(' No DLQ entries found.')
|
|
555
|
-
return
|
|
556
|
-
}
|
|
557
|
-
console.log(`\n Dead Letter Queue (${entries.length} entries):\n`)
|
|
558
|
-
for (const e of entries) {
|
|
559
|
-
const status = e.resolved ? c.green('resolved') : c.red('unresolved')
|
|
560
|
-
console.log(` ${e.id} ${status}`)
|
|
561
|
-
console.log(` Task: ${e.task_id} | Agent: ${e.agent} | Type: ${e.failure_type}`)
|
|
562
|
-
console.log(` Attempts: ${e.attempts} | Created: ${e.created_at}`)
|
|
563
|
-
if (e.resolution) console.log(` Resolution: ${e.resolution}`)
|
|
564
|
-
console.log()
|
|
565
|
-
}
|
|
566
|
-
} finally {
|
|
567
|
-
store.close()
|
|
568
|
-
}
|
|
569
|
-
return
|
|
273
|
+
/**
|
|
274
|
+
* `convoy run <spec>`: the exit code it should end with.
|
|
275
|
+
*
|
|
276
|
+
* `runtime` is for the planner, which has already chosen the runtime and said
|
|
277
|
+
* which; the run uses it rather than choosing, and saying, a second time.
|
|
278
|
+
*/
|
|
279
|
+
export async function runSpec(args: RunArgs, opts: { runtime?: ResolvedAdapter } = {}): Promise<number> {
|
|
280
|
+
if (!args.spec) {
|
|
281
|
+
console.error(` ${c.red('✗')} Name the spec to run: opencastle convoy run <spec.yml>`)
|
|
282
|
+
console.error(` ${c.dim('Specs the planner wrote are in .opencastle/convoys/.')}`)
|
|
283
|
+
return 1
|
|
570
284
|
}
|
|
571
285
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
if (!opts.dlqResolveText) {
|
|
579
|
-
console.error(' \u2717 --dlq-resolve requires --resolution "text"')
|
|
580
|
-
process.exit(1)
|
|
581
|
-
}
|
|
582
|
-
if (!existsSync(dbPath)) {
|
|
583
|
-
console.error(' \u2717 No convoy database found at .opencastle/convoy.db')
|
|
584
|
-
process.exit(1)
|
|
585
|
-
}
|
|
586
|
-
const { createConvoyStore } = await import('./convoy/store.js')
|
|
587
|
-
const store = createConvoyStore(dbPath)
|
|
588
|
-
try {
|
|
589
|
-
store.resolveDlqEntry(opts.dlqResolveId, opts.dlqResolveText)
|
|
590
|
-
console.log(` \u2713 DLQ entry ${opts.dlqResolveId} resolved.`)
|
|
591
|
-
} finally {
|
|
592
|
-
store.close()
|
|
593
|
-
}
|
|
594
|
-
return
|
|
286
|
+
let specText: string
|
|
287
|
+
try {
|
|
288
|
+
specText = await readFile(resolve(process.cwd(), args.spec), 'utf8')
|
|
289
|
+
} catch (err) {
|
|
290
|
+
const e = err as NodeJS.ErrnoException
|
|
291
|
+
return fail(e.code === 'ENOENT' ? `Spec not found: ${args.spec}` : `Cannot read ${args.spec}: ${e.message}`)
|
|
595
292
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
process.exit(1)
|
|
602
|
-
}
|
|
603
|
-
if (!existsSync(dbPath)) {
|
|
604
|
-
console.error(' \u2717 No convoy database found at .opencastle/convoy.db')
|
|
605
|
-
process.exit(1)
|
|
606
|
-
}
|
|
607
|
-
const { createConvoyStore } = await import('./convoy/store.js')
|
|
608
|
-
const store = createConvoyStore(dbPath)
|
|
609
|
-
try {
|
|
610
|
-
const entries = store.listDlqEntries()
|
|
611
|
-
const entry = entries.find(e => e.id === opts.dlqRetryId)
|
|
612
|
-
if (!entry) {
|
|
613
|
-
console.error(` \u2717 DLQ entry "${opts.dlqRetryId}" not found`)
|
|
614
|
-
process.exit(1)
|
|
615
|
-
}
|
|
616
|
-
// Reset the task to pending
|
|
617
|
-
store.updateTaskStatus(entry.task_id, entry.convoy_id, 'pending', {
|
|
618
|
-
worker_id: null,
|
|
619
|
-
worktree: null,
|
|
620
|
-
started_at: null,
|
|
621
|
-
finished_at: null,
|
|
622
|
-
})
|
|
623
|
-
store.resolveDlqEntry(entry.id, 'Retried via CLI')
|
|
624
|
-
// Reset convoy status to running if needed
|
|
625
|
-
const convoy = store.getConvoy(entry.convoy_id)
|
|
626
|
-
if (convoy && (convoy.status === 'failed' || convoy.status === 'done')) {
|
|
627
|
-
store.updateConvoyStatus(entry.convoy_id, 'running', {})
|
|
628
|
-
}
|
|
629
|
-
console.log(` \u2713 Task ${entry.task_id} reset to pending. Run 'opencastle convoy run --resume' to execute.`)
|
|
630
|
-
} finally {
|
|
631
|
-
store.close()
|
|
632
|
-
}
|
|
633
|
-
return
|
|
293
|
+
let spec: TaskSpec
|
|
294
|
+
try {
|
|
295
|
+
spec = parseTaskSpecText(specText)
|
|
296
|
+
} catch (err) {
|
|
297
|
+
return fail(`${args.spec}: ${(err as Error).message}`)
|
|
634
298
|
}
|
|
635
299
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return
|
|
641
|
-
}
|
|
642
|
-
const { createConvoyStore } = await import('./convoy/store.js')
|
|
643
|
-
const store = createConvoyStore(dbPath)
|
|
300
|
+
const projectRoot = projectRootHere()
|
|
301
|
+
let runtime: ResolvedAdapter | null = opts.runtime ?? null
|
|
302
|
+
let runtimeProblem: string | null = null
|
|
303
|
+
if (!runtime) {
|
|
644
304
|
try {
|
|
645
|
-
|
|
646
|
-
if (pipeline) {
|
|
647
|
-
const pipelineConvoys = store.getConvoysByPipeline(pipeline.id)
|
|
648
|
-
console.log(`\n Pipeline: ${pipeline.name}`)
|
|
649
|
-
console.log(` ID: ${pipeline.id}`)
|
|
650
|
-
console.log(` Status: ${pipeline.status}`)
|
|
651
|
-
console.log(` Branch: ${pipeline.branch ?? '(none)'}`)
|
|
652
|
-
console.log(` Created: ${pipeline.created_at}`)
|
|
653
|
-
if (pipeline.started_at) console.log(` Started: ${pipeline.started_at}`)
|
|
654
|
-
if (pipeline.finished_at) console.log(` Finished: ${pipeline.finished_at}`)
|
|
655
|
-
if (pipelineConvoys.length > 0) {
|
|
656
|
-
console.log(`\n Convoys:`)
|
|
657
|
-
let totalTasks = 0
|
|
658
|
-
let totalDone = 0
|
|
659
|
-
let totalFailed = 0
|
|
660
|
-
let totalTokens = 0
|
|
661
|
-
for (const c of pipelineConvoys) {
|
|
662
|
-
const tasks = store.getTasksByConvoy(c.id)
|
|
663
|
-
const done = tasks.filter(t => t.status === 'done').length
|
|
664
|
-
const failed = tasks.filter(t => t.status === 'failed').length
|
|
665
|
-
totalTasks += tasks.length
|
|
666
|
-
totalDone += done
|
|
667
|
-
totalFailed += failed
|
|
668
|
-
totalTokens += tasks.reduce((sum, t) => sum + (t.total_tokens ?? 0), 0)
|
|
669
|
-
console.log(` ${c.name} [${c.status}] — ${done}/${tasks.length} tasks done`)
|
|
670
|
-
}
|
|
671
|
-
console.log(`\n Tasks: ${totalDone} done | ${totalFailed} failed | ${totalTasks} total`)
|
|
672
|
-
if (totalTokens > 0) console.log(` Tokens: ${formatTokens(totalTokens)}`)
|
|
673
|
-
}
|
|
674
|
-
return
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
const convoy = store.getLatestConvoy()
|
|
678
|
-
if (!convoy) {
|
|
679
|
-
console.log(' No convoy records found.')
|
|
680
|
-
return
|
|
681
|
-
}
|
|
682
|
-
const tasks = store.getTasksByConvoy(convoy.id)
|
|
683
|
-
const byStatus = tasks.reduce((acc, t) => {
|
|
684
|
-
acc[t.status] = (acc[t.status] ?? 0) + 1
|
|
685
|
-
return acc
|
|
686
|
-
}, {} as Record<string, number>)
|
|
687
|
-
console.log(`\n Convoy: ${convoy.name}`)
|
|
688
|
-
console.log(` ID: ${convoy.id}`)
|
|
689
|
-
console.log(` Status: ${convoy.status}`)
|
|
690
|
-
console.log(` Branch: ${convoy.branch ?? '(none)'}`)
|
|
691
|
-
console.log(` Created: ${convoy.created_at}`)
|
|
692
|
-
if (convoy.started_at) console.log(` Started: ${convoy.started_at}`)
|
|
693
|
-
if (convoy.finished_at) console.log(` Finished: ${convoy.finished_at}`)
|
|
694
|
-
console.log(`\n Tasks:`)
|
|
695
|
-
for (const [status, count] of Object.entries(byStatus)) {
|
|
696
|
-
console.log(` ${status}: ${count}`)
|
|
697
|
-
}
|
|
698
|
-
console.log(` total: ${tasks.length}`)
|
|
699
|
-
const totalTokens = tasks.reduce((sum, t) => sum + (t.total_tokens ?? 0), 0)
|
|
700
|
-
if (tasks.some(t => t.total_tokens != null)) {
|
|
701
|
-
console.log(`\n Tokens: ${formatTokens(totalTokens)}`)
|
|
702
|
-
const tasksWithTokens = tasks.filter(t => t.total_tokens != null)
|
|
703
|
-
if (tasksWithTokens.length > 0) {
|
|
704
|
-
console.log(`\n Token usage by task:`)
|
|
705
|
-
for (const t of tasksWithTokens) {
|
|
706
|
-
const parts = [formatTokens(t.total_tokens!)]
|
|
707
|
-
if (t.prompt_tokens != null) parts.push(`in: ${formatTokens(t.prompt_tokens)}`)
|
|
708
|
-
if (t.completion_tokens != null) parts.push(`out: ${formatTokens(t.completion_tokens)}`)
|
|
709
|
-
console.log(` ${t.id}: ${parts.join(' | ')}`)
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
} finally {
|
|
714
|
-
store.close()
|
|
715
|
-
}
|
|
716
|
-
return
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// ── --retry-failed flag ───────────────────────────────────────
|
|
720
|
-
if (opts.retryFailed) {
|
|
721
|
-
if (!existsSync(dbPath)) {
|
|
722
|
-
console.error(' ✗ No convoy database found at .opencastle/convoy.db')
|
|
723
|
-
console.error(' Run a convoy spec first: opencastle convoy run -f convoy.yml')
|
|
724
|
-
process.exit(1)
|
|
725
|
-
}
|
|
726
|
-
const { createConvoyStore } = await import('./convoy/store.js')
|
|
727
|
-
const store = createConvoyStore(dbPath)
|
|
728
|
-
const convoy = store.getLatestConvoy()
|
|
729
|
-
const retryTasks = convoy ? store.getTasksByConvoy(convoy.id) : []
|
|
730
|
-
store.close()
|
|
731
|
-
if (!convoy) {
|
|
732
|
-
console.error(' ✗ No convoy records found in .opencastle/convoy.db')
|
|
733
|
-
process.exit(1)
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// Before adapter detection: a preview should not require an agent CLI to be
|
|
737
|
-
// installed, and it must return before anything is executed.
|
|
738
|
-
if (opts.dryRun) {
|
|
739
|
-
printRunDryRun(
|
|
740
|
-
'retry',
|
|
741
|
-
'OpenCastle Convoy (Retry Failed)',
|
|
742
|
-
convoy.name,
|
|
743
|
-
opts.retryFailedTaskIds?.length
|
|
744
|
-
? retryTasks.filter((t) => opts.retryFailedTaskIds!.includes(t.id))
|
|
745
|
-
: retryTasks,
|
|
746
|
-
RETRYABLE_TASK_STATUSES,
|
|
747
|
-
)
|
|
748
|
-
return
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
const retrySpec = parseTaskSpecText(convoy.spec_yaml)
|
|
752
|
-
applyCliOverrides(retrySpec, opts)
|
|
753
|
-
|
|
754
|
-
let retryDetectionFailed = false
|
|
755
|
-
if (!retrySpec.adapter) {
|
|
756
|
-
const detected = await detectAdapter()
|
|
757
|
-
if (detected) {
|
|
758
|
-
retrySpec.adapter = detected
|
|
759
|
-
console.log(` ℹ Auto-detected adapter: ${detected}`)
|
|
760
|
-
} else {
|
|
761
|
-
retryDetectionFailed = true
|
|
762
|
-
retrySpec.adapter = 'claude'
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
const retryAdapter = await getAdapter(retrySpec.adapter)
|
|
767
|
-
const retryAvailable = await retryAdapter.isAvailable()
|
|
768
|
-
if (!retryAvailable) {
|
|
769
|
-
printAdapterError(retryDetectionFailed, retrySpec.adapter)
|
|
770
|
-
process.exit(1)
|
|
771
|
-
}
|
|
772
|
-
assertPermissionModeSupported(retrySpec.adapter, retrySpec)
|
|
773
|
-
|
|
774
|
-
console.log(`\n 🏰 OpenCastle Convoy (Retry Failed): ${convoy.name}`)
|
|
775
|
-
console.log(` Convoy ID: ${convoy.id}`)
|
|
776
|
-
|
|
777
|
-
const { startDashboardServer } = await import('./dashboard.js')
|
|
778
|
-
let retryDashboardResult: { server: import('node:http').Server; port: number; url: string } | null = null
|
|
779
|
-
try {
|
|
780
|
-
retryDashboardResult = await startDashboardServer({
|
|
781
|
-
pkgRoot,
|
|
782
|
-
openBrowser: true,
|
|
783
|
-
convoyId: 'active',
|
|
784
|
-
})
|
|
785
|
-
} catch {
|
|
786
|
-
// Dashboard failure must not block convoy
|
|
787
|
-
}
|
|
788
|
-
if (retryDashboardResult) {
|
|
789
|
-
console.log(` ${c.dim('Dashboard:')} ${retryDashboardResult.url}`)
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
const { createConvoyEngine } = await import('./convoy/engine.js')
|
|
793
|
-
const retryEngine = createConvoyEngine({
|
|
794
|
-
spec: retrySpec,
|
|
795
|
-
specYaml: convoy.spec_yaml,
|
|
796
|
-
adapter: retryAdapter,
|
|
797
|
-
verbose: opts.verbose,
|
|
798
|
-
})
|
|
799
|
-
await retryEngine.retryFailed(convoy.id, opts.retryFailedTaskIds)
|
|
800
|
-
let retryResult: ConvoyResult
|
|
801
|
-
try {
|
|
802
|
-
retryResult = await retryEngine.resume(convoy.id)
|
|
305
|
+
runtime = await chooseRuntime(projectRoot, args.adapter, spec)
|
|
803
306
|
} catch (err) {
|
|
804
|
-
|
|
805
|
-
console.error(` ✗ ${err.message}`)
|
|
806
|
-
process.exit(1)
|
|
807
|
-
}
|
|
808
|
-
throw err
|
|
307
|
+
runtimeProblem = (err as Error).message
|
|
809
308
|
}
|
|
810
|
-
printConvoyResult(retryResult)
|
|
811
|
-
return finishRun(retryDashboardResult, retryResult.status !== 'done')
|
|
812
309
|
}
|
|
813
310
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
console.error(' ✗ No convoy database found at .opencastle/convoy.db')
|
|
818
|
-
console.error(' Run a convoy spec first: opencastle convoy run -f convoy.yml')
|
|
819
|
-
process.exit(1)
|
|
820
|
-
}
|
|
821
|
-
const { createConvoyStore } = await import('./convoy/store.js')
|
|
822
|
-
const store = createConvoyStore(dbPath)
|
|
823
|
-
const { selectResumableRun } = await import('./convoy/last-run.js')
|
|
824
|
-
const selected = selectResumableRun(store)
|
|
825
|
-
|
|
826
|
-
if (!selected) {
|
|
827
|
-
store.close()
|
|
828
|
-
console.error(' ✗ No convoy records found in .opencastle/convoy.db')
|
|
829
|
-
process.exit(1)
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// Whichever run was started most recently, and only if it can be continued.
|
|
833
|
-
// Preferring pipelines unconditionally meant a standalone convoy could never
|
|
834
|
-
// be resumed once the project had run one, and the status screen — which
|
|
835
|
-
// reads the same selector — named a different run than this command resumed.
|
|
836
|
-
if (!selected.resumable) {
|
|
837
|
-
store.close()
|
|
838
|
-
const { kind, record } = selected.run
|
|
839
|
-
console.error(
|
|
840
|
-
` ✗ Last ${kind} "${record.name}" already finished with status: ${record.status}`,
|
|
841
|
-
)
|
|
842
|
-
console.error(
|
|
843
|
-
kind === 'pipeline'
|
|
844
|
-
? ' Only interrupted (running/pending/failed) pipelines can be resumed.'
|
|
845
|
-
: ' Only interrupted (running/pending) convoys can be resumed.',
|
|
846
|
-
)
|
|
847
|
-
if (kind === 'convoy' && record.status === 'failed') {
|
|
848
|
-
console.error(`\n To re-run its failed tasks: opencastle convoy retry`)
|
|
849
|
-
}
|
|
850
|
-
process.exit(1)
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// Before adapter detection, and before either orchestrator is constructed.
|
|
854
|
-
if (opts.dryRun) {
|
|
855
|
-
const previewIds =
|
|
856
|
-
selected.run.kind === 'pipeline'
|
|
857
|
-
? store.getConvoysByPipeline(selected.run.record.id).map((c) => c.id)
|
|
858
|
-
: [selected.run.record.id]
|
|
859
|
-
const previewTasks = previewIds.flatMap((id) => store.getTasksByConvoy(id))
|
|
860
|
-
store.close()
|
|
861
|
-
printRunDryRun(
|
|
862
|
-
'resume',
|
|
863
|
-
selected.run.kind === 'pipeline'
|
|
864
|
-
? 'OpenCastle Pipeline (Resume)'
|
|
865
|
-
: 'OpenCastle Convoy (Resume)',
|
|
866
|
-
selected.run.record.name,
|
|
867
|
-
previewTasks,
|
|
868
|
-
RESUMABLE_TASK_STATUSES,
|
|
869
|
-
)
|
|
870
|
-
return
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
const latestPipeline = selected.run.kind === 'pipeline' ? selected.run.record : null
|
|
874
|
-
|
|
875
|
-
// ── Pipeline resume (pending / running / failed) ────────────
|
|
876
|
-
if (latestPipeline) {
|
|
877
|
-
store.close()
|
|
878
|
-
const resumePipelineSpec = parseTaskSpecText(latestPipeline.spec_yaml)
|
|
879
|
-
applyCliOverrides(resumePipelineSpec, opts)
|
|
880
|
-
|
|
881
|
-
let resumePipelineDetectionFailed = false
|
|
882
|
-
if (!resumePipelineSpec.adapter) {
|
|
883
|
-
const detected = await detectAdapter()
|
|
884
|
-
if (detected) {
|
|
885
|
-
resumePipelineSpec.adapter = detected
|
|
886
|
-
console.log(` ℹ Auto-detected adapter: ${detected}`)
|
|
887
|
-
} else {
|
|
888
|
-
resumePipelineDetectionFailed = true
|
|
889
|
-
resumePipelineSpec.adapter = 'claude'
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
const resumePipelineAdapter = await getAdapter(resumePipelineSpec.adapter)
|
|
894
|
-
const resumePipelineAvailable = await resumePipelineAdapter.isAvailable()
|
|
895
|
-
if (!resumePipelineAvailable) {
|
|
896
|
-
printAdapterError(resumePipelineDetectionFailed, resumePipelineSpec.adapter)
|
|
897
|
-
process.exit(1)
|
|
898
|
-
}
|
|
899
|
-
assertPermissionModeSupported(resumePipelineSpec.adapter, resumePipelineSpec)
|
|
900
|
-
|
|
901
|
-
console.log(`\n 🏰 OpenCastle Pipeline (Resume): ${latestPipeline.name}`)
|
|
902
|
-
console.log(` Pipeline ID: ${latestPipeline.id}`)
|
|
903
|
-
|
|
904
|
-
const { startDashboardServer } = await import('./dashboard.js')
|
|
905
|
-
let resumePipelineDashResult: { server: import('node:http').Server; port: number; url: string } | null = null
|
|
906
|
-
try {
|
|
907
|
-
resumePipelineDashResult = await startDashboardServer({
|
|
908
|
-
pkgRoot,
|
|
909
|
-
openBrowser: true,
|
|
910
|
-
convoyId: 'active',
|
|
911
|
-
})
|
|
912
|
-
} catch {
|
|
913
|
-
// Dashboard failure must not block pipeline
|
|
914
|
-
}
|
|
915
|
-
if (resumePipelineDashResult) {
|
|
916
|
-
console.log(` ${c.dim('Dashboard:')} ${resumePipelineDashResult.url}`)
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
const { createPipelineOrchestrator } = await import('./convoy/pipeline.js')
|
|
920
|
-
const resumePipelineOrchestrator = createPipelineOrchestrator({
|
|
921
|
-
spec: resumePipelineSpec,
|
|
922
|
-
specYaml: latestPipeline.spec_yaml,
|
|
923
|
-
adapter: resumePipelineAdapter,
|
|
924
|
-
verbose: opts.verbose,
|
|
925
|
-
})
|
|
926
|
-
const resumePipelineResult = await resumePipelineOrchestrator.resume(latestPipeline.id)
|
|
927
|
-
printPipelineResult(resumePipelineResult)
|
|
928
|
-
return finishRun(resumePipelineDashResult, resumePipelineResult.status !== 'done')
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// ── Standalone convoy resume ────────────────────────────────
|
|
932
|
-
// Selection and the finished-run refusal both happened above, against the
|
|
933
|
-
// one selector. This branch only executes what was chosen.
|
|
934
|
-
const convoy = selected.run.record as import('./convoy/types.js').ConvoyRecord
|
|
935
|
-
store.close()
|
|
936
|
-
|
|
937
|
-
const resumeSpec = parseTaskSpecText(convoy.spec_yaml)
|
|
938
|
-
applyCliOverrides(resumeSpec, opts)
|
|
939
|
-
|
|
940
|
-
let resumeDetectionFailed = false
|
|
941
|
-
if (!resumeSpec.adapter) {
|
|
942
|
-
const detected = await detectAdapter()
|
|
943
|
-
if (detected) {
|
|
944
|
-
resumeSpec.adapter = detected
|
|
945
|
-
console.log(` ℹ Auto-detected adapter: ${detected}`)
|
|
946
|
-
} else {
|
|
947
|
-
resumeDetectionFailed = true
|
|
948
|
-
resumeSpec.adapter = 'claude'
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
const resumeAdapter = await getAdapter(resumeSpec.adapter)
|
|
953
|
-
const resumeAvailable = await resumeAdapter.isAvailable()
|
|
954
|
-
if (!resumeAvailable) {
|
|
955
|
-
printAdapterError(resumeDetectionFailed, resumeSpec.adapter)
|
|
956
|
-
process.exit(1)
|
|
957
|
-
}
|
|
958
|
-
assertPermissionModeSupported(resumeSpec.adapter, resumeSpec)
|
|
959
|
-
|
|
960
|
-
console.log(`\n \uD83C\uDFF0 OpenCastle Convoy (Resume): ${convoy.name}`)
|
|
961
|
-
console.log(` Convoy ID: ${convoy.id}`)
|
|
962
|
-
|
|
963
|
-
const { startDashboardServer } = await import('./dashboard.js')
|
|
964
|
-
let resumeDashResult: { server: import('node:http').Server; port: number; url: string } | null = null
|
|
311
|
+
if (args.dryRun) {
|
|
312
|
+
// The engine's own check, so a dry run refuses exactly what a run refuses.
|
|
313
|
+
// Nothing is started and nothing is written to the database.
|
|
965
314
|
try {
|
|
966
|
-
|
|
967
|
-
pkgRoot,
|
|
968
|
-
openBrowser: true,
|
|
969
|
-
convoyId: 'active',
|
|
970
|
-
})
|
|
971
|
-
} catch {
|
|
972
|
-
// Dashboard failure must not block convoy
|
|
973
|
-
}
|
|
974
|
-
if (resumeDashResult) {
|
|
975
|
-
console.log(` ${c.dim('Dashboard:')} ${resumeDashResult.url}`)
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
const { createConvoyEngine } = await import('./convoy/engine.js')
|
|
979
|
-
const resumeEngine = createConvoyEngine({
|
|
980
|
-
spec: resumeSpec,
|
|
981
|
-
specYaml: convoy.spec_yaml,
|
|
982
|
-
adapter: resumeAdapter,
|
|
983
|
-
verbose: opts.verbose,
|
|
984
|
-
})
|
|
985
|
-
let resumeResult: ConvoyResult
|
|
986
|
-
try {
|
|
987
|
-
resumeResult = await resumeEngine.resume(convoy.id)
|
|
315
|
+
await checkConvoyPlan(spec, runtime?.name ?? (spec.adapter || 'auto'))
|
|
988
316
|
} catch (err) {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
317
|
+
return fail((err as Error).message)
|
|
318
|
+
}
|
|
319
|
+
if (runtime) applyArgs(spec, args, runtime.name)
|
|
320
|
+
else if (args.concurrency !== null) spec.concurrency = args.concurrency
|
|
321
|
+
console.log('')
|
|
322
|
+
for (const l of describePlan(spec, runtime?.detail ?? c.red('none usable — see below'))) console.log(l)
|
|
323
|
+
console.log('')
|
|
324
|
+
if (runtimeProblem) return fail(runtimeProblem)
|
|
325
|
+
const problem = spec.defaults?.permission_mode ? permissionModeError(runtime!.name, spec.defaults.permission_mode) : null
|
|
326
|
+
if (problem) return fail(problem)
|
|
327
|
+
console.log(` ${c.dim('Dry run — nothing started, nothing recorded. To run it:')} opencastle convoy run ${args.spec}`)
|
|
328
|
+
console.log('')
|
|
329
|
+
return 0
|
|
997
330
|
}
|
|
998
331
|
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
process.exit(1)
|
|
1013
|
-
}
|
|
332
|
+
if (!runtime) return fail(runtimeProblem!)
|
|
333
|
+
const problem = spec.defaults?.permission_mode ? permissionModeError(runtime.name, spec.defaults.permission_mode) : null
|
|
334
|
+
if (problem) return fail(problem)
|
|
335
|
+
applyArgs(spec, args, runtime.name)
|
|
336
|
+
|
|
337
|
+
console.log('')
|
|
338
|
+
console.log(` ${c.bold(`Convoy: ${spec.name}`)} ${c.dim(`— ${spec.tasks?.length ?? 0} tasks`)}`)
|
|
339
|
+
if (!opts.runtime) console.log(` ${c.dim('Runtime:')} ${runtime.detail}`)
|
|
340
|
+
const models = describeModels(spec, runtime)
|
|
341
|
+
if (models) console.log(` ${c.dim('Models:')} ${models}`)
|
|
342
|
+
const engine = createConvoyEngine({ spec, specYaml: specText, adapter: runtime.adapter, verbose: args.verbose, basePath: projectRoot })
|
|
343
|
+
return drive(() => engine.run(), projectRoot)
|
|
344
|
+
}
|
|
1014
345
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Which model the tasks run on, said once before they start: a run that picks
|
|
348
|
+
* models by tier spends far less than one on the runtime's default, and a
|
|
349
|
+
* person should be able to see which happened.
|
|
350
|
+
*/
|
|
351
|
+
function describeModels(spec: TaskSpec, runtime: ResolvedAdapter): string | null {
|
|
352
|
+
if (spec.defaults?.model) return `${spec.defaults.model} for every task (defaults.model)`
|
|
353
|
+
const t = runtime.adapter.tierModels
|
|
354
|
+
if (!t) return null
|
|
355
|
+
return `by agent tier — ${[t.premium && `premium ${t.premium}`, t.standard && `standard ${t.standard}`, t.economy && `economy ${t.economy} (and reviews)`].filter(Boolean).join(', ')}`
|
|
356
|
+
}
|
|
1021
357
|
|
|
1022
|
-
|
|
1023
|
-
console.log(`\n 📋 Formula: ${template.name}`)
|
|
1024
|
-
if (template.description) console.log(` ${template.description}`)
|
|
1025
|
-
console.log(` Variables:`)
|
|
1026
|
-
for (const [key, val] of Object.entries(opts.setVars)) {
|
|
1027
|
-
console.log(` ${key} = ${val}`)
|
|
1028
|
-
}
|
|
1029
|
-
for (const [key, def] of Object.entries(template.variables)) {
|
|
1030
|
-
if (!(key in opts.setVars) && !def.required && def.default) {
|
|
1031
|
-
console.log(` ${key} = ${def.default} (default)`)
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
358
|
+
// ── convoy resume ─────────────────────────────────────────────────────────────
|
|
1035
359
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
console.log(`\n ${c.dim('Resume:')} npx opencastle convoy run --formula ${opts.formula}`)
|
|
1041
|
-
process.exit(1)
|
|
1042
|
-
}
|
|
1043
|
-
specText = yamlStringify(spec)
|
|
1044
|
-
} else {
|
|
1045
|
-
// ── Read and validate spec ──────────────────────────────────
|
|
1046
|
-
const specPath = resolve(process.cwd(), opts.file)
|
|
1047
|
-
try {
|
|
1048
|
-
specText = await readFile(specPath, 'utf8')
|
|
1049
|
-
} catch (err: unknown) {
|
|
1050
|
-
const e = err as Error & { code?: string }
|
|
1051
|
-
if (e.code === 'ENOENT') {
|
|
1052
|
-
console.error(` ✗ Task spec file not found: ${opts.file}`)
|
|
1053
|
-
} else {
|
|
1054
|
-
console.error(` ✗ Cannot read task spec file: ${e.message}`)
|
|
1055
|
-
}
|
|
1056
|
-
console.log(`\n ${c.dim('Resume:')} npx opencastle convoy run -f ${opts.file}`)
|
|
1057
|
-
process.exit(1)
|
|
1058
|
-
}
|
|
360
|
+
/** Not done: a status other than done, or a task that did not finish (older runs ended "done" with tasks skipped). */
|
|
361
|
+
function unfinished(run: RunSummary): boolean {
|
|
362
|
+
return run.status !== 'done' || run.tasks_done < run.tasks_total
|
|
363
|
+
}
|
|
1059
364
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
}
|
|
365
|
+
/** `convoy resume`: the exit code it should end with. */
|
|
366
|
+
export async function resumeLast(args: RunArgs): Promise<number> {
|
|
367
|
+
const projectRoot = projectRootHere()
|
|
368
|
+
const runs = readRuns(projectRoot, 200)
|
|
369
|
+
if (runs.length === 0) {
|
|
370
|
+
console.error(` ${c.red('✗')} No convoy runs in this project yet.`)
|
|
371
|
+
console.error(` ${c.dim('Start one:')} opencastle convoy "<task>"`)
|
|
372
|
+
return 1
|
|
1067
373
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
// ── Auto-detect adapter if not specified ─────────────────────
|
|
1076
|
-
let detectionFailed = false
|
|
1077
|
-
if (!spec.adapter) {
|
|
1078
|
-
const detected = await detectAdapter()
|
|
1079
|
-
if (detected) {
|
|
1080
|
-
spec.adapter = detected
|
|
1081
|
-
console.log(` ℹ Auto-detected adapter: ${detected}`)
|
|
1082
|
-
} else {
|
|
1083
|
-
detectionFailed = true
|
|
1084
|
-
spec.adapter = 'claude' // fallback for availability check below
|
|
1085
|
-
}
|
|
374
|
+
const target = runs.find(unfinished)
|
|
375
|
+
if (!target) {
|
|
376
|
+
const last = runs[0]
|
|
377
|
+
console.log(` Nothing to resume: the last run, ${c.bold(last.name)}, finished with all ${last.tasks_total} tasks done.`)
|
|
378
|
+
console.log(` ${c.dim('Start another:')} opencastle convoy "<task>"`)
|
|
379
|
+
return 0
|
|
1086
380
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
console.log(`\n 🏰 Pipeline Plan: ${spec.name}`)
|
|
1092
|
-
console.log(` Convoy chain: ${(spec.depends_on_convoy as string[]).join(' → ')}`)
|
|
1093
|
-
if (spec.tasks?.length) {
|
|
1094
|
-
console.log(` Plus ${spec.tasks.length} local tasks after chain completes`)
|
|
1095
|
-
}
|
|
1096
|
-
if (spec.branch) console.log(` Branch: ${spec.branch}`)
|
|
1097
|
-
if (spec.gates?.length) console.log(` Gates: ${spec.gates.length} validation commands`)
|
|
1098
|
-
if (!spec.tasks?.length) return
|
|
1099
|
-
} else if (isConvoySpec(spec)) {
|
|
1100
|
-
console.log(`\n \uD83C\uDFF0 Convoy Plan: ${spec.name}`)
|
|
1101
|
-
console.log(
|
|
1102
|
-
` Adapter: ${spec.adapter} | Concurrency: ${spec.concurrency} | Tasks: ${spec.tasks!.length}`
|
|
1103
|
-
)
|
|
1104
|
-
if (spec.branch) console.log(` Branch: ${spec.branch}`)
|
|
1105
|
-
if (spec.gates?.length) console.log(` Gates: ${spec.gates.length} validation commands`)
|
|
1106
|
-
}
|
|
1107
|
-
const phases = buildPhases(spec.tasks!)
|
|
1108
|
-
printExecutionPlan(spec, phases)
|
|
1109
|
-
return
|
|
381
|
+
if (isRunAlive(projectRoot, target.id)) {
|
|
382
|
+
console.error(` ${c.red('✗')} ${target.name} (${target.id}) is still running in another process.`)
|
|
383
|
+
console.error(` ${c.dim('Watch it:')} opencastle convoy dashboard`)
|
|
384
|
+
return 1
|
|
1110
385
|
}
|
|
1111
386
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
387
|
+
const recorded = readRunSpec(projectRoot, target.id)
|
|
388
|
+
if (!recorded) return fail(`The spec ${target.id} was started with is not in .opencastle/convoy.db.`)
|
|
389
|
+
let spec: TaskSpec
|
|
390
|
+
try {
|
|
391
|
+
spec = parseTaskSpecText(recorded.specYaml)
|
|
392
|
+
} catch (err) {
|
|
393
|
+
return fail(`The spec ${target.name} was recorded with no longer reads: ${(err as Error).message}`)
|
|
1119
394
|
}
|
|
1120
|
-
assertPermissionModeSupported(spec.adapter, spec)
|
|
1121
|
-
|
|
1122
|
-
// ── Pipeline orchestrator path (version: 2 specs with depends_on_convoy) ──
|
|
1123
|
-
if (isPipelineSpec(spec)) {
|
|
1124
|
-
const { createPipelineOrchestrator } = await import('./convoy/pipeline.js')
|
|
1125
|
-
console.log(`\n 🏰 OpenCastle Pipeline: ${spec.name}`)
|
|
1126
|
-
console.log(` Convoy chain: ${(spec.depends_on_convoy as string[]).join(' → ')}`)
|
|
1127
|
-
if (spec.branch) console.log(` Branch: ${spec.branch}`)
|
|
1128
|
-
if (spec.gates?.length) console.log(` Gates: ${spec.gates.length} validation commands`)
|
|
1129
395
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
convoyId: 'active',
|
|
1137
|
-
})
|
|
1138
|
-
} catch {
|
|
1139
|
-
// Dashboard failure must not block pipeline
|
|
1140
|
-
}
|
|
1141
|
-
if (pipelineDashboardResult) {
|
|
1142
|
-
console.log(` ${c.dim('Dashboard:')} ${pipelineDashboardResult.url}`)
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
const pipelineOrchestrator = createPipelineOrchestrator({
|
|
1146
|
-
spec,
|
|
1147
|
-
specYaml: specText,
|
|
1148
|
-
adapter,
|
|
1149
|
-
verbose: opts.verbose,
|
|
1150
|
-
})
|
|
396
|
+
const done = `${target.tasks_done}/${target.tasks_total} tasks done`
|
|
397
|
+
console.log('')
|
|
398
|
+
console.log(` ${c.bold(`Resuming ${target.name}`)} ${c.dim(`(${target.id}) — ${target.status}, ${done}`)}`)
|
|
399
|
+
if (target !== runs[0]) {
|
|
400
|
+
console.log(` ${c.dim(`The newest run, ${runs[0].name}, finished; this is the newest one that did not.`)}`)
|
|
401
|
+
}
|
|
1151
402
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
403
|
+
if (args.dryRun) {
|
|
404
|
+
// Read from the read model: a preview opens nothing that could migrate or write.
|
|
405
|
+
const tasks = readRun(projectRoot, target.id)?.tasks ?? []
|
|
406
|
+
const again = new Set<string>(['pending', ...RESUME_RESET_STATUSES])
|
|
407
|
+
const selected = tasks.filter((t) => again.has(t.status))
|
|
408
|
+
console.log('')
|
|
409
|
+
if (selected.length === 0) {
|
|
410
|
+
console.log(' No task would run: every task is done.')
|
|
411
|
+
} else {
|
|
412
|
+
console.log(` Would run ${selected.length} of ${tasks.length} task(s):`)
|
|
413
|
+
for (const t of selected) console.log(` ${t.id} ${c.dim(`— ${t.agent} [${t.status}]`)}`)
|
|
1162
414
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
`npx opencastle convoy run -f ${opts.file} --retry-failed`,
|
|
1168
|
-
)
|
|
415
|
+
console.log('')
|
|
416
|
+
console.log(` ${c.dim('Dry run — nothing started, nothing recorded.')}`)
|
|
417
|
+
console.log('')
|
|
418
|
+
return 0
|
|
1169
419
|
}
|
|
1170
420
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
convoyId: 'active',
|
|
1188
|
-
})
|
|
1189
|
-
} catch {
|
|
1190
|
-
// Dashboard failure must not block convoy
|
|
1191
|
-
}
|
|
1192
|
-
if (dashboardResult) {
|
|
1193
|
-
console.log(` ${c.dim('Dashboard:')} ${dashboardResult.url}`)
|
|
1194
|
-
}
|
|
421
|
+
let runtime: ResolvedAdapter
|
|
422
|
+
try {
|
|
423
|
+
runtime = await chooseRuntime(projectRoot, args.adapter, spec, recorded.adapter)
|
|
424
|
+
} catch (err) {
|
|
425
|
+
return fail((err as Error).message)
|
|
426
|
+
}
|
|
427
|
+
const problem = spec.defaults?.permission_mode ? permissionModeError(runtime.name, spec.defaults.permission_mode) : null
|
|
428
|
+
if (problem) return fail(problem)
|
|
429
|
+
applyArgs(spec, args, runtime.name)
|
|
430
|
+
console.log(` ${c.dim('Runtime:')} ${runtime.detail}`)
|
|
431
|
+
const models = describeModels(spec, runtime)
|
|
432
|
+
if (models) console.log(` ${c.dim('Models:')} ${models}`)
|
|
433
|
+
|
|
434
|
+
const engine = createConvoyEngine({ spec, specYaml: recorded.specYaml, adapter: runtime.adapter, verbose: args.verbose, basePath: projectRoot })
|
|
435
|
+
return drive(() => engine.resume(target.id), projectRoot)
|
|
436
|
+
}
|
|
1195
437
|
|
|
1196
|
-
|
|
1197
|
-
spec,
|
|
1198
|
-
specYaml: specText,
|
|
1199
|
-
adapter,
|
|
1200
|
-
verbose: opts.verbose,
|
|
1201
|
-
})
|
|
438
|
+
// ── Entry points ──────────────────────────────────────────────────────────────
|
|
1202
439
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
pidPath,
|
|
1213
|
-
clearScratchpad: opts.clearScratchpad,
|
|
1214
|
-
watchConfigPath: opts.watchConfig ? resolve(process.cwd(), opts.watchConfig) : null,
|
|
1215
|
-
printResult: printConvoyResult,
|
|
1216
|
-
})
|
|
1217
|
-
return
|
|
1218
|
-
}
|
|
440
|
+
/**
|
|
441
|
+
* Exit once what was written has reached the terminal or the pipe. Exiting is
|
|
442
|
+
* deliberate: a finished run must never sit waiting for Ctrl+C because some
|
|
443
|
+
* handle — a socket, a timer, an agent's pipe — was left open.
|
|
444
|
+
*/
|
|
445
|
+
export function exitWith(code: number): void {
|
|
446
|
+
process.exitCode = code
|
|
447
|
+
process.stdout.write('', () => process.stderr.write('', () => process.exit(code)))
|
|
448
|
+
}
|
|
1219
449
|
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
process.exit(1)
|
|
1228
|
-
}
|
|
1229
|
-
throw err
|
|
1230
|
-
}
|
|
1231
|
-
printConvoyResult(result)
|
|
1232
|
-
return finishRun(
|
|
1233
|
-
dashboardResult,
|
|
1234
|
-
result.status !== 'done',
|
|
1235
|
-
`npx opencastle convoy run -f ${opts.file} --retry-failed`,
|
|
1236
|
-
)
|
|
450
|
+
async function main(args: string[], command: 'run' | 'resume'): Promise<void> {
|
|
451
|
+
const parsed = parseRunArgs(args, command)
|
|
452
|
+
if ('error' in parsed) {
|
|
453
|
+
console.error(` ${c.red('✗')} ${parsed.error}`)
|
|
454
|
+
console.error(` Run "opencastle convoy ${command} --help" for usage.`)
|
|
455
|
+
exitWith(1)
|
|
456
|
+
return
|
|
1237
457
|
}
|
|
458
|
+
if (parsed.help) {
|
|
459
|
+
console.log(command === 'run' ? RUN_HELP : RESUME_HELP)
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
exitWith(command === 'run' ? await runSpec(parsed) : await resumeLast(parsed))
|
|
463
|
+
}
|
|
1238
464
|
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
)
|
|
1244
|
-
|
|
1245
|
-
const reporter = createReporter(spec, {
|
|
1246
|
-
reportDir: opts.reportDir
|
|
1247
|
-
? resolve(process.cwd(), opts.reportDir)
|
|
1248
|
-
: undefined,
|
|
1249
|
-
verbose: opts.verbose,
|
|
1250
|
-
})
|
|
1251
|
-
|
|
1252
|
-
const executor = createExecutor(spec, adapter, reporter)
|
|
1253
|
-
const report = await executor.run()
|
|
465
|
+
/** `opencastle convoy run <spec.yml>`. */
|
|
466
|
+
export default async function run({ args }: CliContext): Promise<void> {
|
|
467
|
+
await main(args, 'run')
|
|
468
|
+
}
|
|
1254
469
|
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
470
|
+
/** `opencastle convoy resume`, and its hidden alias `retry`. */
|
|
471
|
+
export async function resume({ args }: CliContext): Promise<void> {
|
|
472
|
+
await main(args, 'resume')
|
|
1258
473
|
}
|