orkeon-code 0.0.0-stage → 1.0.0-rc.2
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/.orkeon-runtime +10 -0
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +163 -0
- package/README.md +156 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +131 -0
- package/config/appsettings.kev.example.json +133 -0
- package/config/appsettings.liquid.example.json +132 -0
- package/config/appsettings.ollama-whisper.example.json +93 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +32 -0
- package/mcp/whisper/README.md +294 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +1092 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +939 -0
- package/package.json +58 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +559 -0
- package/src/commands/_lib/args.ts +194 -0
- package/src/commands/_lib/dev/dev-batches.ts +366 -0
- package/src/commands/_lib/dev/dev-implement.ts +185 -0
- package/src/commands/_lib/dev/dev-source.ts +61 -0
- package/src/commands/_lib/dev/dev.ts +341 -0
- package/src/commands/_lib/dev/markers.ts +7 -0
- package/src/commands/_lib/dev/messages.ts +112 -0
- package/src/commands/_lib/dev-step.ts +145 -0
- package/src/commands/_lib/dispatch.ts +254 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +94 -0
- package/src/commands/_lib/git/commit.ts +90 -0
- package/src/commands/_lib/git/diff.ts +107 -0
- package/src/commands/_lib/git/messages.ts +54 -0
- package/src/commands/_lib/git/review.ts +108 -0
- package/src/commands/_lib/memory/memory-admit.ts +148 -0
- package/src/commands/_lib/memory/memory.ts +52 -0
- package/src/commands/_lib/memory/messages.ts +32 -0
- package/src/commands/_lib/messages.ts +48 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/project/messages.ts +8 -0
- package/src/commands/_lib/session/export.ts +105 -0
- package/src/commands/_lib/session/messages.ts +87 -0
- package/src/commands/_lib/session/prompts.ts +4 -0
- package/src/commands/_lib/session/resume.ts +151 -0
- package/src/commands/_lib/session/tasks.ts +181 -0
- package/src/commands/_lib/settings/advisor.ts +75 -0
- package/src/commands/_lib/settings/agents.ts +137 -0
- package/src/commands/_lib/settings/choices.ts +8 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/effort.ts +147 -0
- package/src/commands/_lib/settings/hooks.ts +50 -0
- package/src/commands/_lib/settings/messages.ts +408 -0
- package/src/commands/_lib/settings/mode.ts +100 -0
- package/src/commands/_lib/settings/model.ts +181 -0
- package/src/commands/_lib/settings/output-style.ts +39 -0
- package/src/commands/_lib/settings/permissions.ts +287 -0
- package/src/commands/_lib/settings/route.ts +63 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +93 -0
- package/src/commands/_lib/settings/theme.ts +42 -0
- package/src/commands/_lib/speech/messages.ts +58 -0
- package/src/commands/_lib/speech/prompts.ts +4 -0
- package/src/commands/_lib/speech/say.ts +95 -0
- package/src/commands/_lib/speech/transcribe.ts +121 -0
- package/src/commands/_lib/speech/voice.ts +142 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +205 -0
- package/src/commands/_lib/status/messages.ts +100 -0
- package/src/commands/_lib/status/meta.ts +24 -0
- package/src/commands/_lib/status/status.ts +128 -0
- package/src/commands/_lib/status/usage-tools.ts +48 -0
- package/src/commands/_lib/status/usage.ts +128 -0
- package/src/commands/_lib/view.ts +34 -0
- package/src/commands/dev/dev-batches.cmd.ts +109 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +51 -0
- package/src/commands/dev/dev-spec.cmd.ts +54 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +62 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +45 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +18 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +25 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +46 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +19 -0
- package/src/commands/settings/effort.cmd.ts +19 -0
- package/src/commands/settings/fast.cmd.ts +18 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +21 -0
- package/src/commands/settings/output-style.cmd.ts +19 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +16 -0
- package/src/commands/settings/route.cmd.ts +16 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/settings/theme.cmd.ts +14 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +4391 -0
- package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +188 -0
- package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +100 -0
- package/src/crews/advisor/application/messages.ts +4 -0
- package/src/crews/advisor/application/prompts.ts +4 -0
- package/src/crews/advisor/application/run-advisor.ts +41 -0
- package/src/crews/advisor/crew.ork.ts +44 -0
- package/src/crews/advisor/domain/advice.ts +119 -0
- package/src/crews/advisor/domain/messages.ts +8 -0
- package/src/crews/advisor/domain/prompts.ts +26 -0
- package/src/crews/agent-run/application/messages.ts +18 -0
- package/src/crews/agent-run/application/run-agent-run.ts +43 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/messages.ts +27 -0
- package/src/crews/analyze/application/prompts.ts +4 -0
- package/src/crews/analyze/application/run-analyze.ts +120 -0
- package/src/crews/analyze/crew.ork.ts +41 -0
- package/src/crews/analyze/domain/harvest.ts +269 -0
- package/src/crews/analyze/domain/prompts.ts +86 -0
- package/src/crews/code-review/application/lens-material.ts +24 -0
- package/src/crews/code-review/application/messages.ts +17 -0
- package/src/crews/code-review/application/prompts.ts +126 -0
- package/src/crews/code-review/application/review.ts +74 -0
- package/src/crews/code-review/application/run-code-review.ts +121 -0
- package/src/crews/code-review/crew.ork.ts +52 -0
- package/src/crews/code-review/domain/lenses.ts +154 -0
- package/src/crews/code-review/domain/messages.ts +25 -0
- package/src/crews/code-review/domain/prompts.ts +58 -0
- package/src/crews/code-review/domain/report.ts +58 -0
- package/src/crews/code-review/domain/scope.ts +106 -0
- package/src/crews/dev-batches/application/messages.ts +127 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/prompts.ts +10 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +676 -0
- package/src/crews/dev-batches/application/run-wave.ts +452 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +163 -0
- package/src/crews/dev-batches/crew.ork.ts +146 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +52 -0
- package/src/crews/dev-batches/domain/markers.ts +5 -0
- package/src/crews/dev-batches/domain/messages.ts +6 -0
- package/src/crews/dev-batches/domain/wave-order.ts +44 -0
- package/src/crews/dev-change/application/change-material.ts +44 -0
- package/src/crews/dev-change/application/evidence.ts +172 -0
- package/src/crews/dev-change/application/messages.ts +81 -0
- package/src/crews/dev-change/application/prompts.ts +101 -0
- package/src/crews/dev-change/application/run-dev-change.ts +324 -0
- package/src/crews/dev-change/crew.ork.ts +114 -0
- package/src/crews/dev-change/domain/change-answer.ts +163 -0
- package/src/crews/dev-change/domain/change-render.ts +77 -0
- package/src/crews/dev-change/domain/markers.ts +28 -0
- package/src/crews/dev-change/domain/messages.ts +16 -0
- package/src/crews/dev-implement/application/close.ts +186 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +82 -0
- package/src/crews/dev-implement/application/messages.ts +161 -0
- package/src/crews/dev-implement/application/observe.ts +52 -0
- package/src/crews/dev-implement/application/prompts.ts +9 -0
- package/src/crews/dev-implement/application/report-writes.ts +46 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +822 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +122 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +69 -0
- package/src/crews/dev-implement/domain/contracts.ts +255 -0
- package/src/crews/dev-implement/domain/correction.ts +103 -0
- package/src/crews/dev-implement/domain/cycles.ts +36 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/markers.ts +23 -0
- package/src/crews/dev-implement/domain/messages.ts +58 -0
- package/src/crews/dev-implement/domain/prompts.ts +93 -0
- package/src/crews/dev-implement/domain/roles.ts +49 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +76 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +23 -0
- package/src/crews/dev-implement/domain/step-checks.ts +137 -0
- package/src/crews/dev-implement/domain/step-section.ts +129 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt-fit.ts +63 -0
- package/src/crews/dev-learn/application/messages.ts +51 -0
- package/src/crews/dev-learn/application/prompts.ts +99 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +558 -0
- package/src/crews/dev-learn/crew.ork.ts +53 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +233 -0
- package/src/crews/dev-learn/domain/messages.ts +65 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +89 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +95 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +113 -0
- package/src/crews/dev-plan/application/inventory.ts +174 -0
- package/src/crews/dev-plan/application/messages.ts +88 -0
- package/src/crews/dev-plan/application/plan-prompt-fit.ts +44 -0
- package/src/crews/dev-plan/application/prompts.ts +141 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +483 -0
- package/src/crews/dev-plan/crew.ork.ts +112 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/markers.ts +18 -0
- package/src/crews/dev-plan/domain/messages.ts +118 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +753 -0
- package/src/crews/dev-plan/domain/plan-render.ts +306 -0
- package/src/crews/dev-plan/domain/prompts.ts +44 -0
- package/src/crews/dev-spec/application/messages.ts +30 -0
- package/src/crews/dev-spec/application/prompts.ts +93 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +237 -0
- package/src/crews/dev-spec/application/spec-material.ts +42 -0
- package/src/crews/dev-spec/crew.ork.ts +110 -0
- package/src/crews/dev-spec/domain/markers.ts +30 -0
- package/src/crews/dev-spec/domain/messages.ts +39 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +252 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit-brief.ts +187 -0
- package/src/crews/dev-verify/application/audit.ts +267 -0
- package/src/crews/dev-verify/application/capture.ts +311 -0
- package/src/crews/dev-verify/application/messages.ts +119 -0
- package/src/crews/dev-verify/application/prompts.ts +209 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +423 -0
- package/src/crews/dev-verify/application/run-gate.ts +204 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +154 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +138 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +131 -0
- package/src/crews/dev-verify/domain/markers.ts +16 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +156 -0
- package/src/crews/dev-verify/domain/messages.ts +92 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +133 -0
- package/src/crews/git-commit/application/messages.ts +15 -0
- package/src/crews/git-commit/application/prompts.ts +47 -0
- package/src/crews/git-commit/application/run-git-commit.ts +117 -0
- package/src/crews/git-commit/crew.ork.ts +53 -0
- package/src/crews/git-commit/domain/commit.ts +200 -0
- package/src/crews/git-commit/domain/markers.ts +4 -0
- package/src/crews/git-commit/domain/messages.ts +48 -0
- package/src/crews/init-verifiers/application/authoring.ts +90 -0
- package/src/crews/init-verifiers/application/messages.ts +13 -0
- package/src/crews/init-verifiers/application/prompts.ts +107 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +26 -0
- package/src/crews/init-verifiers/crew.ork.ts +35 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +78 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/messages.ts +81 -0
- package/src/crews/main-loop/application/prompts.ts +12 -0
- package/src/crews/main-loop/application/run-main-loop.ts +383 -0
- package/src/crews/main-loop/application/turn-context.ts +111 -0
- package/src/crews/main-loop/crew.ork.ts +124 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +338 -0
- package/src/crews/main-loop/domain/prompts.ts +336 -0
- package/src/crews/main-loop/domain/turn-chains.ts +130 -0
- package/src/crews/project-init/application/detect.ts +123 -0
- package/src/crews/project-init/application/messages.ts +15 -0
- package/src/crews/project-init/application/prompts.ts +105 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +36 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +65 -0
- package/src/crews/project-init/domain/messages.ts +13 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/project-init/domain/prompts.ts +10 -0
- package/src/crews/session-compact/application/prompts.ts +5 -0
- package/src/crews/session-compact/crew.ork.ts +56 -0
- package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +49 -0
- package/src/crews/speech/application/messages.ts +3 -0
- package/src/crews/speech/application/prompts.ts +3 -0
- package/src/crews/speech/application/run-speech.ts +26 -0
- package/src/crews/speech/crew.ork.ts +38 -0
- package/src/shared/application/agents/child-agent.ts +259 -0
- package/src/shared/application/agents/messages.ts +35 -0
- package/src/shared/application/agents/route-agent.ts +115 -0
- package/src/shared/application/agents/run-sub-agent.ts +119 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +242 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/messages.ts +20 -0
- package/src/shared/application/compaction/prune-context.ts +94 -0
- package/src/shared/application/compaction/pruned-llm.ts +35 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +115 -0
- package/src/shared/application/dev/close-batch.ts +85 -0
- package/src/shared/application/dev/find-repo-pack.ts +78 -0
- package/src/shared/application/dev/learn-decision.ts +254 -0
- package/src/shared/application/dev/load-dev-context.ts +265 -0
- package/src/shared/application/dev/measure-access-cost.ts +69 -0
- package/src/shared/application/dev/messages.ts +132 -0
- package/src/shared/application/dev/phase-timer.ts +54 -0
- package/src/shared/application/dev/plan-source.ts +116 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/prompts.ts +34 -0
- package/src/shared/application/dev/question-round.ts +60 -0
- package/src/shared/application/dev/resolve-work-folder.ts +134 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +57 -0
- package/src/shared/application/dev/source-review.ts +67 -0
- package/src/shared/application/dev/source-step.ts +152 -0
- package/src/shared/application/dev/spend.ts +55 -0
- package/src/shared/application/dev/step-precedents.ts +90 -0
- package/src/shared/application/dev/tool-call-policy.ts +87 -0
- package/src/shared/application/dev/tool-callbacks.ts +262 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +46 -0
- package/src/shared/application/dev/verdict-sources.ts +50 -0
- package/src/shared/application/dev/wrapped-tools.ts +147 -0
- package/src/shared/application/extra-tools.ts +71 -0
- package/src/shared/application/git/batch-worktree.ts +102 -0
- package/src/shared/application/git/commit-files.ts +191 -0
- package/src/shared/application/git/merge-batch.ts +67 -0
- package/src/shared/application/git/messages.ts +75 -0
- package/src/shared/application/git/open-pull-request.ts +52 -0
- package/src/shared/application/host-context.ts +59 -0
- package/src/shared/application/host-layout-store.ts +45 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +36 -0
- package/src/shared/application/messages.ts +14 -0
- package/src/shared/application/permission-rules.ts +169 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/decision.ts +14 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +38 -0
- package/src/shared/application/ports/llm.ts +83 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/theme.ts +11 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +29 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +85 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +179 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +69 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +45 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +119 -0
- package/src/shared/application/shared-memory/memory-files.ts +111 -0
- package/src/shared/application/shared-memory/memory-settings.ts +94 -0
- package/src/shared/application/shared-memory/messages.ts +63 -0
- package/src/shared/application/shared-memory/push-candidate.ts +149 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +70 -0
- package/src/shared/application/skills/messages.ts +4 -0
- package/src/shared/application/skills/suggest-skills.ts +102 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/messages.ts +8 -0
- package/src/shared/application/workflow/workflow-state.ts +136 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +162 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +67 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/messages.ts +66 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/path-rules.ts +299 -0
- package/src/shared/domain/agent-policy/permission.ts +625 -0
- package/src/shared/domain/agent-policy/prompts.ts +17 -0
- package/src/shared/domain/agent-policy/reasoning.ts +59 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +416 -0
- package/src/shared/domain/agent-policy/tool-access.ts +91 -0
- package/src/shared/domain/agent-registry.ts +143 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +64 -0
- package/src/shared/domain/agents/exclusive.ts +25 -0
- package/src/shared/domain/agents/instances.ts +252 -0
- package/src/shared/domain/agents/messages.ts +39 -0
- package/src/shared/domain/agents/model-route.ts +199 -0
- package/src/shared/domain/agents/prompts.ts +20 -0
- package/src/shared/domain/code-intel-contract.ts +357 -0
- package/src/shared/domain/code-intel-routing.ts +60 -0
- package/src/shared/domain/compact-outcome.ts +46 -0
- package/src/shared/domain/compaction-thresholds.ts +162 -0
- package/src/shared/domain/compaction.ts +288 -0
- package/src/shared/domain/config-schema.ts +434 -0
- package/src/shared/domain/context-prune.ts +176 -0
- package/src/shared/domain/decision/questions.ts +102 -0
- package/src/shared/domain/dev/access-cost.ts +230 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +35 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +45 -0
- package/src/shared/domain/dev/call-guard.ts +342 -0
- package/src/shared/domain/dev/carried-text.ts +47 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +176 -0
- package/src/shared/domain/dev/learn-state.ts +94 -0
- package/src/shared/domain/dev/markers.ts +107 -0
- package/src/shared/domain/dev/messages.ts +259 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/phase-timing.ts +50 -0
- package/src/shared/domain/dev/plan-checks.ts +191 -0
- package/src/shared/domain/dev/plan-format.ts +170 -0
- package/src/shared/domain/dev/project-files.ts +29 -0
- package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
- package/src/shared/domain/dev/prompts.ts +251 -0
- package/src/shared/domain/dev/questions.ts +267 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +240 -0
- package/src/shared/domain/dev/review-answer.ts +173 -0
- package/src/shared/domain/dev/review-brief.ts +54 -0
- package/src/shared/domain/dev/reviewer-charter.ts +35 -0
- package/src/shared/domain/dev/sheet-facts.ts +81 -0
- package/src/shared/domain/dev/spec-format.ts +182 -0
- package/src/shared/domain/dev/step-budget.ts +74 -0
- package/src/shared/domain/dev/step-rules.ts +109 -0
- package/src/shared/domain/dev/test-commands.ts +94 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +65 -0
- package/src/shared/domain/dev/trait-pattern.ts +87 -0
- package/src/shared/domain/dev/verdict-format.ts +162 -0
- package/src/shared/domain/dev/whitespace.ts +35 -0
- package/src/shared/domain/dev/work-folder.ts +68 -0
- package/src/shared/domain/dev/yaml-subset.ts +385 -0
- package/src/shared/domain/error-text.ts +13 -0
- package/src/shared/domain/git/close.ts +274 -0
- package/src/shared/domain/git/messages.ts +20 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/host-layout.ts +147 -0
- package/src/shared/domain/host-paths.ts +399 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +134 -0
- package/src/shared/domain/llm-profile.ts +44 -0
- package/src/shared/domain/marked-message.ts +29 -0
- package/src/shared/domain/markers.ts +30 -0
- package/src/shared/domain/messages.ts +291 -0
- package/src/shared/domain/model-catalog.ts +79 -0
- package/src/shared/domain/permission-modes.ts +99 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +84 -0
- package/src/shared/domain/prompts.ts +233 -0
- package/src/shared/domain/search-routing.ts +77 -0
- package/src/shared/domain/secret-patterns.ts +46 -0
- package/src/shared/domain/session-keys.ts +92 -0
- package/src/shared/domain/session-start.ts +61 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +145 -0
- package/src/shared/domain/shared-memory/candidates.ts +40 -0
- package/src/shared/domain/shared-memory/entry.ts +151 -0
- package/src/shared/domain/shared-memory/front-matter.ts +187 -0
- package/src/shared/domain/shared-memory/gate.ts +45 -0
- package/src/shared/domain/shared-memory/harvest.ts +64 -0
- package/src/shared/domain/shared-memory/layout.ts +190 -0
- package/src/shared/domain/shared-memory/markers.ts +9 -0
- package/src/shared/domain/shared-memory/messages.ts +66 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +82 -0
- package/src/shared/domain/shared-memory/prompts.ts +28 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/skills/prompts.ts +4 -0
- package/src/shared/domain/skills/shortlist.ts +149 -0
- package/src/shared/domain/snip-turns.ts +33 -0
- package/src/shared/domain/speech.ts +21 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +120 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +33 -0
- package/src/shared/domain/vfs.ts +16 -0
- package/src/shared/domain/workflow/prompts.ts +15 -0
- package/src/shared/domain/workflow/state-file.ts +142 -0
- package/src/shared/infrastructure/globals.ts +57 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +122 -0
- package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +179 -0
- package/src/shared/infrastructure/orkeon/files.ts +58 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +30 -0
- package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +55 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +58 -0
- package/src/shared/infrastructure/orkeon/llm.ts +164 -0
- package/src/shared/infrastructure/orkeon/markers.ts +6 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +129 -0
- package/src/shared/infrastructure/orkeon/messages.ts +15 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
- package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +129 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +94 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +81 -0
- package/src/shared/infrastructure/orkeon/shell.ts +39 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +76 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +174 -0
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
// /dev-batches: one run of the driver of a plan's batches (temp/04 L-7). It reads the plan, its sheets, its
|
|
2
|
+
// verdicts and its log, `.orkeon/dev/<code>/batches-state.md`; back from a batch's chain (`after`: the last
|
|
3
|
+
// lines of what dev-implement or dev-verify answered) it logs what came of that batch; then either it
|
|
4
|
+
// stops (a human decides), or it closes the plan (every batch done: one push, one pull request), or it runs
|
|
5
|
+
// the preflight, the review of a batch whose dependencies just closed, and names the next batch for the
|
|
6
|
+
// command to launch: JSON `{ lines, next?: { crew: "dev-implement", input } }`. With `concurrency` n from 2
|
|
7
|
+
// (temp/26 L8P-D1) it runs the next wave itself instead, at most n batches at once, each under its own worktree
|
|
8
|
+
// (run-wave.ts), and names itself next while nothing stopped: `next: { crew: "dev-batches", input }`, one hop a
|
|
9
|
+
// wave. A run that names its code
|
|
10
|
+
// keeps it, with what the command read at its dispatch, in `.orkeon/dev/batches-active.json`; the runs the
|
|
11
|
+
// chain launches name none and read it back. The batch's own work (its steps, its audit, its commit) is
|
|
12
|
+
// dev-implement's: this crew writes only the log, the run record and the pull request's body - and, in a parallel
|
|
13
|
+
// run, the files it seeds and harvests and the merges of the VALID batches.
|
|
14
|
+
import type { Files, Llm, Logger, Shell } from "../../../shared/application/ports.ts";
|
|
15
|
+
import type { ActRoute } from "../../../shared/application/agents/route-agent.ts";
|
|
16
|
+
import type { ConfigStore } from "../../../shared/application/config-store.ts";
|
|
17
|
+
import type { PullRequestOpener } from "../../../shared/application/git/commit-files.ts";
|
|
18
|
+
import { defaultBranch, runGit } from "../../../shared/application/git/commit-files.ts";
|
|
19
|
+
import { loadDevCode, loadDevContext } from "../../../shared/application/dev/load-dev-context.ts";
|
|
20
|
+
import type { DevCode } from "../../../shared/application/dev/load-dev-context.ts";
|
|
21
|
+
import type { WorkFolder } from "../../../shared/application/dev/resolve-work-folder.ts";
|
|
22
|
+
import { preflight } from "../../../shared/application/dev/preflight.ts";
|
|
23
|
+
import { runSubAgent } from "../../../shared/application/agents/run-sub-agent.ts";
|
|
24
|
+
import { isCode } from "../../../shared/domain/dev/artefacts.ts";
|
|
25
|
+
import { checkConcurrency, concurrencyModeRefusal } from "../../../shared/domain/dev/batches-concurrency.ts";
|
|
26
|
+
import { readMemoryDir } from "../../../shared/application/shared-memory/memory-settings.ts";
|
|
27
|
+
import { batchWaves, sheetAnchorPaths } from "../domain/batch-waves.ts";
|
|
28
|
+
import { runWave } from "./run-wave.ts";
|
|
29
|
+
import { batchWorktreeName, worktreePlace } from "../../../shared/domain/git/worktree.ts";
|
|
30
|
+
import type { BatchOutcome, BatchRun } from "./run-wave.ts";
|
|
31
|
+
import { BATCHES_ACTIVE_RECORD, parseBatchesState } from "../../../shared/domain/dev/batches-state.ts";
|
|
32
|
+
import type { BatchesLogEntry } from "../../../shared/domain/dev/batches-state.ts";
|
|
33
|
+
import {
|
|
34
|
+
GAPS_ROUNDS_MAX, closeCommand, correctionCommand, gapsFinding, gapsRoundsOf, isUnfinishedSection, lastVerdict,
|
|
35
|
+
} from "../../../shared/domain/dev/verdict-format.ts";
|
|
36
|
+
import { NEXT_BATCH_REVIEWER_CHARTER } from "../../../shared/domain/dev/reviewer-charter.ts";
|
|
37
|
+
import { charterCatalogue } from "../../../shared/domain/agents/charter.ts";
|
|
38
|
+
import type { CarriedText } from "../../../shared/domain/dev/carried-text.ts";
|
|
39
|
+
import { REVIEW_ANSWER_SCHEMA, reviewChecks } from "../../../shared/domain/dev/review-answer.ts";
|
|
40
|
+
import { reviewSystem } from "../../../shared/domain/dev/prompts.ts";
|
|
41
|
+
import { buildReviewAnswerPrompt, buildReviewBrief } from "../../../shared/domain/dev/review-brief.ts";
|
|
42
|
+
import { parseSessionRules } from "../../../shared/domain/git/pull-request.ts";
|
|
43
|
+
import { GIT_CURRENT_BRANCH_COMMAND, GIT_HEAD_COMMAND, shellQuote, workBranchFromPattern } from "../../../shared/domain/git/close.ts";
|
|
44
|
+
import { policyFor } from "../../../shared/domain/agent-policy/mode-policy.ts";
|
|
45
|
+
import { nextBatch, waveOrder } from "../domain/wave-order.ts";
|
|
46
|
+
import type { BatchNode } from "../domain/wave-order.ts";
|
|
47
|
+
import { appendToLog, batchesLogPath, closedLine, eventLine, lastEntryOf, reviewPending } from "../domain/batches-log.ts";
|
|
48
|
+
import { REVIEW_NOT_RUN } from "../domain/markers.ts";
|
|
49
|
+
import { CLOSE_STOP } from "../../dev-implement/domain/markers.ts";
|
|
50
|
+
import { changedTitle } from "./prompts.ts";
|
|
51
|
+
import { CHAIN_ANSWERED_NOTHING, FILES_NOT_READ, HASH_NOT_READ, NO_REVIEWER, NO_RUN_TO_GO_ON, backOnBranch, closeStop, concurrencyRefused, detachedHead, doneAndCommitted, everyBatchDone, everyBatchDoneArrow, humanDecidesAgain, humanDecidesClose, humanDecidesCorrection, humanDecidesStops, keptByParallelRun, launchLine, logNotWritten, logUnwritableThen, nextWaveFollows, noBranchFromPattern, noPlanUnder, notAWorkCodeBlocked, notMarkedDone, preflightBlocked, blockedReadOnlyMode, recordNotWritten, relaunchedRound, resumeAudit, reviewGaps, batchReviewNotRun, runGoesOn, runInProgress, settleBlocking, validNotCommitted, waitForChain, wavesUnreadable, workOutsideMounts } from "./messages.ts";
|
|
52
|
+
import { branchCreated as workBranchCreated } from "../../../shared/application/git/messages.ts";
|
|
53
|
+
import type { BatchEvent } from "../domain/batches-log.ts";
|
|
54
|
+
import { closePlan } from "./plan-close.ts";
|
|
55
|
+
import type { MergedBatch } from "./plan-close.ts";
|
|
56
|
+
import { WORKSPACE, workspaceRelative } from "../../../shared/domain/vfs.ts";
|
|
57
|
+
import { listProjectFiles } from "../../../shared/application/dev/project-files.ts";
|
|
58
|
+
|
|
59
|
+
export const ACTIVE_RECORD = BATCHES_ACTIVE_RECORD;
|
|
60
|
+
const AFTER_LINES = 20;
|
|
61
|
+
|
|
62
|
+
/** What the dispatch read and a chained run cannot: the session's mode and rules, the github tool, the
|
|
63
|
+
* /hooks registry, the /effort level, and `memoryRecall: false` when a session rule denies it. */
|
|
64
|
+
export interface BatchesContext {
|
|
65
|
+
permissionMode: string; permissionRules: string[]; githubTool: boolean;
|
|
66
|
+
hooks: unknown[]; effort: string | null; memoryRecall?: false;
|
|
67
|
+
/** The batches at once of a parallel run (2 to 4); absent, one. */
|
|
68
|
+
concurrency?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface DevBatchesInputs {
|
|
72
|
+
/** The work code; absent, the run the record names goes on. */
|
|
73
|
+
code?: unknown;
|
|
74
|
+
pr?: unknown;
|
|
75
|
+
/** The last lines of what the batch's chain answered: this run logs what came of it. */
|
|
76
|
+
after?: unknown;
|
|
77
|
+
/** How many batches at once, 1 to 4: 1 (absent) is the sequential run; a chained run reads the record's. */
|
|
78
|
+
concurrency?: unknown;
|
|
79
|
+
permissionMode?: unknown; permissionRules?: unknown; githubTool?: unknown;
|
|
80
|
+
hooks?: unknown; effort?: unknown; memoryRecall?: unknown;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DevBatchesDeps {
|
|
84
|
+
files: Files; shell: Shell; config: Pick<ConfigStore, "readValue">; log: Pick<Logger, "info" | "warn">;
|
|
85
|
+
clock: () => Date;
|
|
86
|
+
/** The reviewer of the next batch (read tools only), under the run's hooks and effort; none: not run, and said. */
|
|
87
|
+
reviewerFor?(context: BatchesContext): Pick<Llm, "act" | "extract">;
|
|
88
|
+
/** The route of the next batch's reviewer's act to a cheaper or stronger profile (shared/application/agents/route-agent.ts actRoute);
|
|
89
|
+
* absent, the act runs on the crew's profile. */
|
|
90
|
+
route?: ActRoute;
|
|
91
|
+
/** The pull-request opener for the context read at the dispatch; none: the command is handed over. */
|
|
92
|
+
openerFor?(context: BatchesContext): PullRequestOpener | undefined;
|
|
93
|
+
/** A parallel run's batch, run by a batch agent under its worktree; none: a parallel run is refused. */
|
|
94
|
+
runBatch?(run: BatchRun, context: BatchesContext): Promise<BatchOutcome>;
|
|
95
|
+
/** git's top as an agent under `root` sees it, before the first wave of a typed run (run-wave.ts). */
|
|
96
|
+
probe?(root: string): Promise<{ exitCode: number; top: string }>;
|
|
97
|
+
/** After a batch's GAPS verdict in a parallel run, over the work folder of its kept worktree (`vfsPath`), where its
|
|
98
|
+
* verdict stays: the mistakes harvested (M-7). */
|
|
99
|
+
afterGaps?(work: Pick<WorkFolder, "folder" | "vfsPath">): Promise<string[]>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface BatchesAnswer {
|
|
103
|
+
lines: string[];
|
|
104
|
+
next?: { crew: "dev-implement" | "dev-batches"; input: Record<string, unknown> };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface ActiveRecord { code: string | null; pr: boolean; context: BatchesContext }
|
|
108
|
+
|
|
109
|
+
const answer = (lines: string[], next?: BatchesAnswer["next"]): string =>
|
|
110
|
+
JSON.stringify(next === undefined ? { lines } : { lines, next });
|
|
111
|
+
const flag = (v: unknown): boolean => v === true || v === "true";
|
|
112
|
+
const reasonOf = (e: unknown): string => String((e as Error)?.message ?? e).split("\n")[0];
|
|
113
|
+
const strings = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []);
|
|
114
|
+
|
|
115
|
+
function contextOf(raw: DevBatchesInputs | Record<string, unknown>): BatchesContext {
|
|
116
|
+
const r = raw as DevBatchesInputs;
|
|
117
|
+
return {
|
|
118
|
+
permissionMode: typeof r.permissionMode === "string" ? r.permissionMode : "",
|
|
119
|
+
permissionRules: strings(r.permissionRules),
|
|
120
|
+
githubTool: flag(r.githubTool),
|
|
121
|
+
hooks: Array.isArray(r.hooks) ? r.hooks : [],
|
|
122
|
+
effort: typeof r.effort === "string" && r.effort !== "" ? r.effort : null,
|
|
123
|
+
...(r.memoryRecall === false ? { memoryRecall: false as const } : {}),
|
|
124
|
+
...(typeof r.concurrency === "number" && r.concurrency > 1 ? { concurrency: r.concurrency } : {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function readRecord(files: Pick<Files, "read">): Promise<ActiveRecord | null> {
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(await files.read(ACTIVE_RECORD)) as { code?: unknown; pr?: unknown; context?: unknown };
|
|
131
|
+
const code = typeof parsed.code === "string" && isCode(parsed.code) ? parsed.code : null;
|
|
132
|
+
const context = parsed.context !== null && typeof parsed.context === "object" ? parsed.context as Record<string, unknown> : {};
|
|
133
|
+
return { code, pr: parsed.pr === true, context: contextOf(context) };
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** True when the log of `code`'s run ends closed: a record left naming it (its last write failed) holds nothing. */
|
|
140
|
+
async function runClosed(files: Pick<Files, "read">, code: string): Promise<boolean> {
|
|
141
|
+
try {
|
|
142
|
+
return parseBatchesState(await files.read(batchesLogPath(code))).closed;
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The log, appended in memory and written once per run. */
|
|
149
|
+
class LogBook {
|
|
150
|
+
readonly path: string;
|
|
151
|
+
readonly code: string;
|
|
152
|
+
text: string | null;
|
|
153
|
+
private readonly added: string[] = [];
|
|
154
|
+
constructor(path: string, code: string, text: string | null) { this.path = path; this.code = code; this.text = text; }
|
|
155
|
+
add(line: string): void { this.added.push(line); }
|
|
156
|
+
entries(): BatchesLogEntry[] { return parseBatchesState(appendToLog(this.text, this.code, this.added)).entries; }
|
|
157
|
+
closed(): boolean { return parseBatchesState(appendToLog(this.text, this.code, this.added)).closed; }
|
|
158
|
+
/** Writes what was added; the line saying it could not, else null. */
|
|
159
|
+
async save(files: Pick<Files, "write">): Promise<string | null> {
|
|
160
|
+
if (this.added.length === 0) return null;
|
|
161
|
+
try {
|
|
162
|
+
await files.write(this.path, appendToLog(this.text, this.code, this.added));
|
|
163
|
+
return null;
|
|
164
|
+
} catch (e) {
|
|
165
|
+
return logNotWritten(workspaceRelative(this.path), reasonOf(e));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const OPENING: ReadonlySet<string> = new Set(["launched", "relaunched"]);
|
|
171
|
+
|
|
172
|
+
/** The batches as the order sees them: their dependencies (the summary row's, else the sheet's) and whether done. */
|
|
173
|
+
export function batchNodes(dev: DevCode): BatchNode[] {
|
|
174
|
+
const plan = dev.plan?.plan;
|
|
175
|
+
if (!plan) return [];
|
|
176
|
+
return plan.batches.map((b) => {
|
|
177
|
+
const row = plan.summary.find((r) => r.id === b.id);
|
|
178
|
+
const sheet = dev.sheets.find((s) => s.batch === b.id)?.sheet;
|
|
179
|
+
return {
|
|
180
|
+
id: b.id,
|
|
181
|
+
dependsOn: row !== undefined ? row.dependsOn : sheet?.dependsOn ?? [],
|
|
182
|
+
done: b.state.kind === "done" || sheet?.doneDate !== undefined,
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** What came of a batch the chain ran and did not close: the event logged, the line said. `launched` is the audits
|
|
188
|
+
* the batch's verdict file held at its launch. */
|
|
189
|
+
function stopOf(dev: DevCode, batch: string, after: readonly string[], launched: number): { event: BatchEvent; detail: string } {
|
|
190
|
+
// An audit the budget stopped since the launch wrote a GAPS verdict and answered BLOCKED: it is a round of GAPS,
|
|
191
|
+
// relaunched without a correction (its resume audits the batch again), counted toward the rounds a human takes.
|
|
192
|
+
const latest = dev.verdicts.filter((v) => v.batch === batch).at(-1)?.file.sections.at(-1);
|
|
193
|
+
if (latest?.verdict === "GAPS" && isUnfinishedSection(latest) && auditsOf(dev, batch) > launched) return { event: "returned", detail: "GAPS" };
|
|
194
|
+
// The audit's own BLOCKED line too, for any other stop it names.
|
|
195
|
+
const blocked = after.map((l) => l.trim().replace(/^dev-verify: (?=BLOCKED)/, "")).find((l) => l.startsWith("BLOCKED"));
|
|
196
|
+
if (blocked !== undefined) return { event: "stopped", detail: `BLOCKED — ${blocked.replace(/^BLOCKED\s*—?\s*/, "")}` };
|
|
197
|
+
const verdicts = dev.verdicts.filter((v) => v.batch === batch);
|
|
198
|
+
const verdict = verdicts.length === 0 ? null : lastVerdict(verdicts[verdicts.length - 1].file);
|
|
199
|
+
if (verdict?.verdict === "GAPS") return { event: "returned", detail: "GAPS" };
|
|
200
|
+
if (verdict?.verdict === "VALID") {
|
|
201
|
+
const failed = after.map((l) => l.trim()).find((l) => l.startsWith("✗"));
|
|
202
|
+
return { event: "stopped", detail: closeStop(failed?.replace(/^✗\s*/, "")) };
|
|
203
|
+
}
|
|
204
|
+
const first = after.map((l) => l.trim()).find((l) => l !== "");
|
|
205
|
+
return { event: "stopped", detail: `BLOCKED — ${first ?? CHAIN_ANSWERED_NOTHING}` };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The verdict of the batch's latest audit section; null while that audit has written none (it may still run). */
|
|
209
|
+
function latestVerdict(dev: DevCode, batch: string): string | null {
|
|
210
|
+
const files = dev.verdicts.filter((v) => v.batch === batch);
|
|
211
|
+
return files.at(-1)?.file.sections.at(-1)?.verdict ?? null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The launch's detail: the audits the batch's verdict file held then, so that a typed run can tell an audit since. */
|
|
215
|
+
const AUDITS_DETAIL = "audits";
|
|
216
|
+
|
|
217
|
+
/** The audits (dated sections) of the batch's verdict file now. */
|
|
218
|
+
function auditsOf(dev: DevCode, batch: string): number {
|
|
219
|
+
return dev.verdicts.filter((v) => v.batch === batch).reduce((n, v) => n + v.file.sections.length, 0);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The audits a launch line recorded; a line without the count (an older log) counts every audit as before it. */
|
|
223
|
+
function auditsAtLaunch(detail: string): number {
|
|
224
|
+
const m = /(?:^|\s)audits (\d+)\b/.exec(detail);
|
|
225
|
+
return m === null ? Number.POSITIVE_INFINITY : Number(m[1]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The text of the batch's verdict file, null when it cannot be read. */
|
|
229
|
+
async function verdictText(files: Pick<Files, "read">, vfsPath: string, dev: DevCode, batch: string): Promise<string | null> {
|
|
230
|
+
const verdict = dev.verdicts.filter((v) => v.batch === batch).at(-1);
|
|
231
|
+
if (verdict === undefined) return null;
|
|
232
|
+
try {
|
|
233
|
+
return await files.read(`${vfsPath}/${dev.code}/${verdict.name}`);
|
|
234
|
+
} catch {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The detail of a relaunch after a GAPS verdict: its round, the audits the verdict file holds (a typed run tells an
|
|
240
|
+
* audit since by them), and the correction it carries. */
|
|
241
|
+
function gapsRelaunchDetail(round: number, audits: number, finding: string | undefined): string {
|
|
242
|
+
return `round ${round}, ${AUDITS_DETAIL} ${audits}${finding === undefined ? "" : ` — correction: ${finding}`}`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** The work branch of a run: the pattern's first alternative before `/`, then the code. */
|
|
246
|
+
export function batchesBranchName(pattern: string, code: string): string | null {
|
|
247
|
+
return workBranchFromPattern(pattern, code);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** On the default branch with `contrib.branch`, the run's work branch is created; the line, or the refusal. */
|
|
251
|
+
async function ensureWorkBranch(
|
|
252
|
+
shell: Pick<Shell, "run">, pattern: string | undefined, code: string,
|
|
253
|
+
): Promise<{ ok: true; line: string | null } | { ok: false; line: string }> {
|
|
254
|
+
const wanted = pattern?.trim();
|
|
255
|
+
if (!wanted) return { ok: true, line: null };
|
|
256
|
+
const current = await runGit(shell, GIT_CURRENT_BRANCH_COMMAND);
|
|
257
|
+
const branch = current.exitCode === 0 ? current.stdout.trim() : "";
|
|
258
|
+
const base = await defaultBranch(shell);
|
|
259
|
+
if (branch === "" || base === null || branch !== base) return { ok: true, line: null };
|
|
260
|
+
const name = batchesBranchName(wanted, code);
|
|
261
|
+
if (name === null) return { ok: false, line: noBranchFromPattern(wanted) };
|
|
262
|
+
const exists = await runGit(shell, `git rev-parse --verify --quiet ${shellQuote(`refs/heads/${name}`)}`);
|
|
263
|
+
const made = await runGit(shell, exists.exitCode === 0 ? `git switch ${shellQuote(name)}` : `git switch -c ${shellQuote(name)}`);
|
|
264
|
+
if (made.exitCode !== 0) {
|
|
265
|
+
return { ok: false, line: `git switch ${exists.exitCode === 0 ? "" : "-c "}${name} failed (${(made.stderr || made.stdout).trim().split("\n")[0] || `exit ${made.exitCode}`})` };
|
|
266
|
+
}
|
|
267
|
+
return { ok: true, line: exists.exitCode === 0 ? backOnBranch(name) : workBranchCreated(name, branch, wanted) };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** The closed batches a review is told about: each one's commit and its files. */
|
|
271
|
+
async function closedInventory(shell: Pick<Shell, "run">, merged: readonly MergedBatch[], deps: readonly string[]): Promise<string> {
|
|
272
|
+
const out: string[] = [];
|
|
273
|
+
for (const m of merged.filter((x) => deps.includes(x.batch))) {
|
|
274
|
+
if (!/^[0-9a-f]{4,40}$/i.test(m.hash)) continue;
|
|
275
|
+
const r = await runGit(shell, `git show --name-only --format= ${shellQuote(m.hash)}`);
|
|
276
|
+
const files = r.exitCode === 0 ? r.stdout.split("\n").map((l) => l.trim()).filter((l) => l !== "") : [];
|
|
277
|
+
out.push(`${m.batch} ${m.hash}: ${files.slice(0, 20).join(", ") || FILES_NOT_READ}${files.length > 20 ? `, and ${files.length - 20} more` : ""}`);
|
|
278
|
+
}
|
|
279
|
+
return out.join("\n");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** What the review's brief carries: the next batch's sheet, what each closed dependency changed (`git show`), then
|
|
283
|
+
* the plan, so the reviewer reads from the brief instead of opening the plan folder and the tree file by file. A
|
|
284
|
+
* text that cannot be read is left out: the brief still names the file, and the reviewer opens it. */
|
|
285
|
+
async function reviewMaterial(
|
|
286
|
+
deps: Pick<DevBatchesDeps, "files" | "shell">, vfsPath: string | null, dev: DevCode, sheetName: string, planName: string,
|
|
287
|
+
merged: readonly MergedBatch[], dependsOn: readonly string[],
|
|
288
|
+
): Promise<CarriedText[]> {
|
|
289
|
+
const out: CarriedText[] = [];
|
|
290
|
+
const planFile = async (name: string): Promise<void> => {
|
|
291
|
+
if (vfsPath === null) return;
|
|
292
|
+
try {
|
|
293
|
+
const shown = `${dev.shown}/${name}`;
|
|
294
|
+
out.push({ title: shown, path: shown, text: await deps.files.read(`${vfsPath}/${dev.code}/${name}`) });
|
|
295
|
+
} catch {
|
|
296
|
+
// Left to read.
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
await planFile(sheetName);
|
|
300
|
+
for (const m of merged.filter((x) => dependsOn.includes(x.batch))) {
|
|
301
|
+
if (!/^[0-9a-f]{4,40}$/i.test(m.hash)) continue;
|
|
302
|
+
const r = await runGit(deps.shell, `git show --format= ${shellQuote(m.hash)}`);
|
|
303
|
+
if (r.exitCode === 0 && r.stdout.trim() !== "") out.push({ title: changedTitle(m.batch, m.hash.slice(0, 7)), text: r.stdout });
|
|
304
|
+
}
|
|
305
|
+
await planFile(planName);
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function mergedOf(entries: readonly BatchesLogEntry[]): MergedBatch[] {
|
|
310
|
+
const out = new Map<string, string>();
|
|
311
|
+
for (const e of entries) if (e.batch !== undefined && e.event === "merged") out.set(e.batch, e.detail.split(" ")[0] ?? "");
|
|
312
|
+
return [...out].map(([batch, hash]) => ({ batch, hash }));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Every batch of the plan in its order, with the commit the log names (none for one closed before the run). */
|
|
316
|
+
function everyDone(order: readonly string[], merged: readonly MergedBatch[]): MergedBatch[] {
|
|
317
|
+
return order.map((batch) => merged.find((m) => m.batch === batch) ?? { batch, hash: "" });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The first wave of the open batches, at most `n`, their anchors read from their sheets; none when it cannot be read. */
|
|
321
|
+
async function nextWave(files: Pick<Files, "read">, dev: DevCode, nodes: readonly BatchNode[], folder: string | null, n: number): Promise<string[]> {
|
|
322
|
+
const batches = [];
|
|
323
|
+
for (const node of nodes) {
|
|
324
|
+
const sheet = dev.sheets.find((s) => s.batch === node.id);
|
|
325
|
+
let anchors: string[] = [];
|
|
326
|
+
if (!node.done && sheet !== undefined && folder !== null) {
|
|
327
|
+
try {
|
|
328
|
+
anchors = sheetAnchorPaths(await files.read(`${folder}/${dev.code}/${sheet.name}`));
|
|
329
|
+
} catch {
|
|
330
|
+
anchors = [];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
batches.push({ id: node.id, dependsOn: node.dependsOn, anchors, done: node.done });
|
|
334
|
+
}
|
|
335
|
+
const waves = batchWaves(batches);
|
|
336
|
+
return waves.ok && waves.waves.length > 0 ? waves.waves[0].slice(0, n) : [];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function listOrNone(files: Pick<Files, "list">, path: string): Promise<string[]> {
|
|
340
|
+
try {
|
|
341
|
+
return (await files.list(path, 200)).map((n) => n.replace(/\/+$/, "").split("/").pop() ?? "");
|
|
342
|
+
} catch {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export async function runDevBatches(input: DevBatchesInputs, deps: DevBatchesDeps): Promise<string> {
|
|
348
|
+
const lines: string[] = [];
|
|
349
|
+
// 0. How many at once: nothing is read or written for a value out of 1..4.
|
|
350
|
+
const concurrency = checkConcurrency(input.concurrency);
|
|
351
|
+
if (!concurrency.ok) return answer([`BLOCKED — ${concurrency.line}`]);
|
|
352
|
+
// 1. The run: the code named, kept with the dispatch's context; else the one the record names.
|
|
353
|
+
let code: string;
|
|
354
|
+
let pr: boolean;
|
|
355
|
+
let context: BatchesContext;
|
|
356
|
+
// A typed /dev-batches (its dispatch passes the session's mode) and a chained run (`after`, its `completed`
|
|
357
|
+
// reading the session again before the hop, Orkeon #220) bring the context as it is now; a chained run whose
|
|
358
|
+
// read failed reads it back. The record is written once the plan is found and the mode allows the run.
|
|
359
|
+
const fresh = typeof input.permissionMode === "string";
|
|
360
|
+
let record: ActiveRecord | null = null;
|
|
361
|
+
// The record of this plan's run in progress, read back by a typed run that names no --concurrency.
|
|
362
|
+
let prior: ActiveRecord | null = null;
|
|
363
|
+
if (typeof input.code === "string" && input.code.trim() !== "") {
|
|
364
|
+
code = input.code.trim();
|
|
365
|
+
if (!isCode(code)) return answer([notAWorkCodeBlocked(code)]);
|
|
366
|
+
// Another plan's run in progress keeps its record: overwritten, a typed close of one of its batches would push.
|
|
367
|
+
const active = await readRecord(deps.files);
|
|
368
|
+
if (active !== null && active.code !== null && active.code !== code && !await runClosed(deps.files, active.code)) {
|
|
369
|
+
return answer([
|
|
370
|
+
runInProgress(active.code, workspaceRelative(ACTIVE_RECORD), code),
|
|
371
|
+
]);
|
|
372
|
+
}
|
|
373
|
+
pr = flag(input.pr);
|
|
374
|
+
context = contextOf(input);
|
|
375
|
+
if (active !== null && active.code === code && !await runClosed(deps.files, code)) prior = active;
|
|
376
|
+
} else {
|
|
377
|
+
record = await readRecord(deps.files);
|
|
378
|
+
if (record === null || record.code === null) {
|
|
379
|
+
return answer([NO_RUN_TO_GO_ON]);
|
|
380
|
+
}
|
|
381
|
+
code = record.code;
|
|
382
|
+
pr = record.pr || flag(input.pr);
|
|
383
|
+
// A typed run without a code brings its whole context (the /effort level, the hooks, as they are now). A chained
|
|
384
|
+
// hop (`after`) brings the mode, rules and github tool its `completed` read again (Orkeon #220) over the hooks,
|
|
385
|
+
// effort, memory rule and concurrency the record kept; a hop whose read failed reads them all back.
|
|
386
|
+
const chained = Array.isArray(input.after);
|
|
387
|
+
const { permissionMode, permissionRules, githubTool } = contextOf(input);
|
|
388
|
+
context = !fresh ? record.context : chained ? { ...record.context, permissionMode, permissionRules, githubTool } : contextOf(input);
|
|
389
|
+
prior = record;
|
|
390
|
+
}
|
|
391
|
+
const mode = context.permissionMode.trim();
|
|
392
|
+
if (mode !== "" && policyFor(mode).readOnly) {
|
|
393
|
+
return answer([...lines, blockedReadOnlyMode(mode, code)]);
|
|
394
|
+
}
|
|
395
|
+
// The value the run names (a typed --concurrency 1 included: back to one at a time); none, the value of the plan's
|
|
396
|
+
// run in progress, typed or chained (a refused hop typed again goes on as it was); else one.
|
|
397
|
+
const parallel = input.concurrency !== undefined ? concurrency.value : prior?.context.concurrency ?? 1;
|
|
398
|
+
if (parallel > 1) {
|
|
399
|
+
context = { ...context, concurrency: parallel };
|
|
400
|
+
// Checked again here: a chained run's mode is the one the record kept (L8P-D14).
|
|
401
|
+
const modeRefused = concurrencyModeRefusal(parallel, mode);
|
|
402
|
+
if (modeRefused !== null) return answer([...lines, `BLOCKED — ${modeRefused}`]);
|
|
403
|
+
if (deps.runBatch === undefined) return answer([...lines, concurrencyRefused(parallel)]);
|
|
404
|
+
} else if (context.concurrency !== undefined) {
|
|
405
|
+
const { concurrency: _, ...one } = context;
|
|
406
|
+
context = one;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// 2. The plan and what was done of it.
|
|
410
|
+
const ctx = await loadDevContext({ files: deps.files, shell: deps.shell, config: deps.config });
|
|
411
|
+
lines.push(...ctx.warnings.slice(0, 5).map((w) => `⚠ ${w}`));
|
|
412
|
+
if (ctx.work.vfsPath === null) return answer([...lines, workOutsideMounts(ctx.work.folder)]);
|
|
413
|
+
const lookup = await loadDevCode({ files: deps.files }, ctx.work, code);
|
|
414
|
+
if (lookup.found === null) {
|
|
415
|
+
const known = lookup.codes.length > 0 ? ` (codes: ${lookup.codes.slice(0, 10).join(", ")})` : "";
|
|
416
|
+
return answer([...lines, noPlanUnder(ctx.work.folder, code, known)]);
|
|
417
|
+
}
|
|
418
|
+
const dev = lookup.found;
|
|
419
|
+
const writeRecord = async (value: object): Promise<void> => {
|
|
420
|
+
try {
|
|
421
|
+
await deps.files.write(ACTIVE_RECORD, `${JSON.stringify(value, null, 2)}\n`);
|
|
422
|
+
} catch (e) {
|
|
423
|
+
lines.push(recordNotWritten(reasonOf(e), code));
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
if (record === null || fresh || flag(input.pr) !== record.pr || record.context.concurrency !== context.concurrency) {
|
|
427
|
+
await writeRecord({ code, pr, context });
|
|
428
|
+
}
|
|
429
|
+
// The crew's budget is sized when it is built, from the concurrency its input names (batches-budget.ts): a run
|
|
430
|
+
// that follows its record's hands itself on, the concurrency named, before any batch.
|
|
431
|
+
if (parallel > 1 && input.concurrency === undefined) {
|
|
432
|
+
return answer([...lines, runGoesOn(code, parallel)], { crew: "dev-batches", input: { concurrency: parallel } });
|
|
433
|
+
}
|
|
434
|
+
const nodes = batchNodes(dev);
|
|
435
|
+
const order = waveOrder(nodes);
|
|
436
|
+
const now = (): Date => deps.clock();
|
|
437
|
+
const logPath = batchesLogPath(code);
|
|
438
|
+
let logText: string | null = null;
|
|
439
|
+
try {
|
|
440
|
+
logText = await deps.files.read(logPath);
|
|
441
|
+
} catch {
|
|
442
|
+
logText = null;
|
|
443
|
+
}
|
|
444
|
+
const book = new LogBook(logPath, code, logText);
|
|
445
|
+
// A batch the log has merged is done, even when its sheet could not be marked: never launched again.
|
|
446
|
+
for (const n of nodes) if (!n.done && lastEntryOf(book.entries(), n.id)?.event === "merged") n.done = true;
|
|
447
|
+
const logShown = workspaceRelative(logPath);
|
|
448
|
+
const finish = async (out: string[], next?: BatchesAnswer["next"]): Promise<string> => {
|
|
449
|
+
const failed = await book.save(deps.files);
|
|
450
|
+
if (failed === null) return answer(out, next);
|
|
451
|
+
// Without its log the run cannot tell a batch it launched: nothing is launched.
|
|
452
|
+
return answer(next === undefined ? [...out, failed] : [...out, failed, logUnwritableThen(code)]);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// What the chain's dev-implement is handed for a batch: the run's context, its open steps, and what is `extra`.
|
|
456
|
+
const launchInput = (batch: string, extra: Record<string, unknown> = {}, added = 0): Record<string, unknown> => {
|
|
457
|
+
const steps = (dev.sheets.find((s) => s.batch === batch)?.sheet.steps ?? [])
|
|
458
|
+
.filter((s) => s.tdd !== null && !(s.tdd.red && s.tdd.green && s.tdd.cost)).length + added;
|
|
459
|
+
return {
|
|
460
|
+
batch, plan: code, hooks: context.hooks, effort: context.effort,
|
|
461
|
+
// No github tool for a batch: its close never opens a pull request (dev.prAuto included); the plan's does.
|
|
462
|
+
permissionMode: context.permissionMode, permissionRules: context.permissionRules, githubTool: false,
|
|
463
|
+
...(context.memoryRecall === false ? { memoryRecall: false } : {}),
|
|
464
|
+
...(steps > 0 ? { steps } : {}),
|
|
465
|
+
...extra,
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// 3. What came of the batches the log leaves launched: a batch done since is logged returned and merged;
|
|
470
|
+
// back from the chain, a batch not done is a stop (a human decides); typed, only a GAPS audit is logged.
|
|
471
|
+
const after = strings(input.after).slice(-AFTER_LINES);
|
|
472
|
+
// A parallel run leaves no launched batch to a chain: its wave picks up what the log leaves open (run-wave.ts).
|
|
473
|
+
for (const node of parallel > 1 ? [] : nodes) {
|
|
474
|
+
const last = lastEntryOf(book.entries(), node.id);
|
|
475
|
+
if (last === undefined || !OPENING.has(last.event)) continue;
|
|
476
|
+
if (node.done) {
|
|
477
|
+
// The close's own line names the batch's commit; a batch closed by hand is read at HEAD.
|
|
478
|
+
const said = after.map((l) => /^✓ committed ([0-9a-f]{4,40}) on /i.exec(l.trim())?.[1]).find((h) => h !== undefined);
|
|
479
|
+
const head = said === undefined ? await runGit(deps.shell, GIT_HEAD_COMMAND) : null;
|
|
480
|
+
const hash = said ?? (head !== null && head.exitCode === 0 ? head.stdout.trim() : HASH_NOT_READ);
|
|
481
|
+
book.add(eventLine(now(), node.id, "returned", "VALID"));
|
|
482
|
+
book.add(eventLine(now(), node.id, "merged", hash));
|
|
483
|
+
lines.push(doneAndCommitted(node.id));
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
// Typed, not back from the chain: a hop refused at the chain's depth (or a killed run) lost the batch's answer.
|
|
487
|
+
// An audit written since the launch says what came of it, as that answer would have; with none, it is relaunched.
|
|
488
|
+
if (input.after === undefined && auditsOf(dev, node.id) <= auditsAtLaunch(last.detail)) continue;
|
|
489
|
+
// Committed, but its sheet or the plan could not be marked done: the commit stands, the marking is the human's.
|
|
490
|
+
const committed = after.map((l) => /^✓ committed ([0-9a-f]{4,40}) on /i.exec(l.trim())?.[1]).find((h) => h !== undefined);
|
|
491
|
+
if (committed !== undefined) {
|
|
492
|
+
book.add(eventLine(now(), node.id, "returned", "VALID"));
|
|
493
|
+
book.add(eventLine(now(), node.id, "merged", committed));
|
|
494
|
+
node.done = true;
|
|
495
|
+
lines.push(`✓ ${node.id} committed (${committed})`, notMarkedDone(node.id));
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
const stop = stopOf(dev, node.id, after, auditsAtLaunch(last.detail));
|
|
499
|
+
// Typed while its chain may still close the batch: an audit since the launch that says VALID is not a stop - the
|
|
500
|
+
// chain's answer, coming back, would find the batch stopped. Nothing is logged; the close is the way out when
|
|
501
|
+
// the chain is gone (its commit then marks the batch done). An audit with no verdict yet is logged as a stop,
|
|
502
|
+
// as before: a dead chain never answers, and the stop is what lets a human decide.
|
|
503
|
+
if (input.after === undefined && latestVerdict(dev, node.id) === "VALID") {
|
|
504
|
+
return finish([
|
|
505
|
+
...lines,
|
|
506
|
+
validNotCommitted(node.id),
|
|
507
|
+
waitForChain(closeCommand(code, node.id), code),
|
|
508
|
+
]);
|
|
509
|
+
}
|
|
510
|
+
book.add(eventLine(now(), node.id, stop.event, stop.detail));
|
|
511
|
+
// A GAPS verdict the audit just wrote relaunches the batch by itself, the Blocking and Major rows of that verdict
|
|
512
|
+
// as the correction (none after an audit the budget stopped: its resume runs), until the third round in GAPS.
|
|
513
|
+
let rounds: number | null = null;
|
|
514
|
+
if (stop.detail === "GAPS" && latestVerdict(dev, node.id) === "GAPS") {
|
|
515
|
+
const text = await verdictText(deps.files, ctx.work.vfsPath, dev, node.id);
|
|
516
|
+
rounds = text === null ? null : gapsRoundsOf(text);
|
|
517
|
+
if (text !== null && rounds !== null && rounds < GAPS_ROUNDS_MAX) {
|
|
518
|
+
const finding = gapsFinding(text);
|
|
519
|
+
book.add(eventLine(now(), node.id, "relaunched", gapsRelaunchDetail(rounds + 1, auditsOf(dev, node.id), finding)));
|
|
520
|
+
return finish(
|
|
521
|
+
[
|
|
522
|
+
...lines, `${node.id} returned GAPS`,
|
|
523
|
+
relaunchedRound(node.id, rounds + 1, GAPS_ROUNDS_MAX) +
|
|
524
|
+
(finding === undefined ? resumeAudit(code, node.id) : correctionCommand(code, node.id, finding)),
|
|
525
|
+
],
|
|
526
|
+
{ crew: "dev-implement", input: launchInput(node.id, finding === undefined ? {} : { correction: finding }, finding === undefined ? 0 : 1) },
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return finish([
|
|
531
|
+
...lines, `${node.id} ${stop.event} ${stop.detail}`,
|
|
532
|
+
stop.detail === "GAPS"
|
|
533
|
+
// The audit's own `/dev-batches <code> <batch> — correction: …` line fixes the batch; its close commits without a
|
|
534
|
+
// push while this run is in progress (run-dev-implement.ts).
|
|
535
|
+
? humanDecidesCorrection(rounds, correctionCommand(code, node.id, "<finding>"), code)
|
|
536
|
+
: stop.detail.startsWith(CLOSE_STOP)
|
|
537
|
+
// The audit said VALID: what is left is the close, not a new run of the batch.
|
|
538
|
+
? humanDecidesClose(closeCommand(code, node.id), code)
|
|
539
|
+
: humanDecidesAgain(code, node.id),
|
|
540
|
+
]);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// 4. Every batch done: the close of the plan, once.
|
|
544
|
+
const next = order.ok ? nextBatch(order.order, nodes) : null;
|
|
545
|
+
if (order.ok && next === null) {
|
|
546
|
+
if (book.closed()) {
|
|
547
|
+
await writeRecord({ code: null });
|
|
548
|
+
return finish([...lines, everyBatchDone(code, logShown)]);
|
|
549
|
+
}
|
|
550
|
+
const opener = context.githubTool ? deps.openerFor?.(context) : undefined;
|
|
551
|
+
const close = await closePlan(
|
|
552
|
+
{ files: deps.files, shell: deps.shell, config: deps.config, opener },
|
|
553
|
+
{ code, dev, pack: ctx.pack?.pack ?? null, work: ctx.work, merged: everyDone(order.order, mergedOf(book.entries())), pr, rules: parseSessionRules(context.permissionRules) },
|
|
554
|
+
);
|
|
555
|
+
lines.push(...close.lines);
|
|
556
|
+
if (close.closed) {
|
|
557
|
+
book.add(closedLine(now()));
|
|
558
|
+
await writeRecord({ code: null });
|
|
559
|
+
lines.push(everyBatchDoneArrow(code, logShown));
|
|
560
|
+
}
|
|
561
|
+
return finish(lines);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// 5. Preflight.
|
|
565
|
+
const plan = dev.plan;
|
|
566
|
+
const sheetOf = (batch: string) => dev.sheets.find((s) => s.batch === batch);
|
|
567
|
+
const pre = await preflight({ shell: deps.shell }, {
|
|
568
|
+
planShown: plan === null ? null : `${dev.shown}/${plan.name}`,
|
|
569
|
+
problems: dev.warnings,
|
|
570
|
+
batches: nodes.length,
|
|
571
|
+
missingSheets: nodes.filter((n) => !n.done && sheetOf(n.id) === undefined).map((n) => n.id),
|
|
572
|
+
order,
|
|
573
|
+
workFolder: ctx.work.folder,
|
|
574
|
+
});
|
|
575
|
+
lines.push(...pre.lines);
|
|
576
|
+
if (!pre.ok || next === null || plan === null) {
|
|
577
|
+
return finish([...lines, preflightBlocked(code)]);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// 6. The review of a batch whose dependencies just closed, before its first launch: the next batch, or each of
|
|
581
|
+
// the wave a parallel run launches.
|
|
582
|
+
const wave = parallel > 1 ? await nextWave(deps.files, dev, nodes, ctx.work.vfsPath, parallel) : [next];
|
|
583
|
+
if (wave.length === 0) return finish([...lines, wavesUnreadable(code)]);
|
|
584
|
+
// The Major rows of each review, handed to that batch's first launch as `stale:` lines.
|
|
585
|
+
const stale: Record<string, string[]> = {};
|
|
586
|
+
for (const id of wave) {
|
|
587
|
+
const node = nodes.find((n) => n.id === id)!;
|
|
588
|
+
if (!reviewPending(book.entries(), id) || node.dependsOn.length === 0) continue;
|
|
589
|
+
const sheet = sheetOf(id)!;
|
|
590
|
+
// A review that cannot run closes the gate: the batch is not launched, and the next run reviews it again.
|
|
591
|
+
const notRun = (reason: string): Promise<string> => {
|
|
592
|
+
book.add(eventLine(now(), id, "stopped", `${REVIEW_NOT_RUN} (${reason})`));
|
|
593
|
+
return finish([...lines, batchReviewNotRun(id, reason, code)]);
|
|
594
|
+
};
|
|
595
|
+
const reviewer = deps.reviewerFor?.(context);
|
|
596
|
+
if (reviewer === undefined) return notRun(NO_REVIEWER);
|
|
597
|
+
const merged = mergedOf(book.entries());
|
|
598
|
+
const outcome = await runSubAgent(reviewer, {
|
|
599
|
+
charter: NEXT_BATCH_REVIEWER_CHARTER,
|
|
600
|
+
tools: charterCatalogue(NEXT_BATCH_REVIEWER_CHARTER),
|
|
601
|
+
system: reviewSystem("next-batch"),
|
|
602
|
+
brief: buildReviewBrief({
|
|
603
|
+
mode: "next-batch", folder: dev.shown, files: [`${dev.shown}/${sheet.name}`], source: `${dev.shown}/${plan.name}`,
|
|
604
|
+
inventory: await closedInventory(deps.shell, merged, node.dependsOn), targets: [id],
|
|
605
|
+
carried: await reviewMaterial(deps, ctx.work.vfsPath, dev, sheet.name, plan.name, merged, node.dependsOn),
|
|
606
|
+
projectFiles: await listProjectFiles(deps.shell, ctx.work.folder),
|
|
607
|
+
}),
|
|
608
|
+
schema: REVIEW_ANSWER_SCHEMA,
|
|
609
|
+
answerPrompt: (reply, problems) => buildReviewAnswerPrompt(reply, problems, [id]),
|
|
610
|
+
...reviewChecks([id]),
|
|
611
|
+
}, deps.route);
|
|
612
|
+
if (!outcome.ok) return notRun(`${outcome.reason}: ${outcome.problems[0] ?? "no detail"}`);
|
|
613
|
+
const rows = outcome.value.rows;
|
|
614
|
+
const blocking = rows.filter((r) => r.severity === "Blocking");
|
|
615
|
+
lines.push(rows.length === 0
|
|
616
|
+
? `review of ${id}: CLEAR`
|
|
617
|
+
: reviewGaps(id, blocking.length, rows.length - blocking.length));
|
|
618
|
+
lines.push(...rows.map((r) => ` ${r.severity} — ${r.question} (${r.evidence})`));
|
|
619
|
+
const majors = rows.filter((r) => r.severity === "Major").map((r) => `stale: ${r.question} — ${r.evidence}`);
|
|
620
|
+
if (majors.length > 0) stale[id] = majors;
|
|
621
|
+
if (blocking.length > 0) {
|
|
622
|
+
book.add(eventLine(now(), id, "stopped", `BLOCKED — review: ${blocking.length} Blocking`));
|
|
623
|
+
return finish([
|
|
624
|
+
...lines,
|
|
625
|
+
settleBlocking(id, `${dev.shown}/${sheet.name}`, code),
|
|
626
|
+
]);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// 7. The work branch, then the launch.
|
|
631
|
+
const branch = await ensureWorkBranch(deps.shell, ctx.pack?.pack.contrib.branch, code);
|
|
632
|
+
if (!branch.ok) return finish([...lines, `BLOCKED — branch: ${branch.line}, then /dev-batches ${code}`]);
|
|
633
|
+
if (branch.line !== null) lines.push(branch.line);
|
|
634
|
+
if (parallel > 1) {
|
|
635
|
+
const current = await runGit(deps.shell, GIT_CURRENT_BRANCH_COMMAND);
|
|
636
|
+
const workBranch = current.exitCode === 0 ? current.stdout.trim() : "";
|
|
637
|
+
if (workBranch === "") return finish([...lines, detachedHead(code)]);
|
|
638
|
+
const memory = await readMemoryDir(deps.config);
|
|
639
|
+
const steps = (id: string): number | undefined => {
|
|
640
|
+
const open = sheetOf(id)?.sheet.steps.filter((s) => s.tdd !== null && !(s.tdd.red && s.tdd.green && s.tdd.cost)).length ?? 0;
|
|
641
|
+
return open > 0 ? open : undefined;
|
|
642
|
+
};
|
|
643
|
+
const ran = await runWave({
|
|
644
|
+
code, concurrency: parallel, wave, workBranch, work: ctx.work.folder, memoryDir: memory.dir, clock: now,
|
|
645
|
+
// The first wave of a typed run proves git works under a worktree root before any batch (L8P-D11).
|
|
646
|
+
probe: typeof input.code === "string",
|
|
647
|
+
sheets: Object.fromEntries(dev.sheets.map((s) => [s.batch, s.name])),
|
|
648
|
+
audits: (id) => auditsOf(dev, id), steps, stale, book: { add: (l) => book.add(l), entries: () => book.entries(), save: () => book.save(deps.files) },
|
|
649
|
+
}, {
|
|
650
|
+
files: deps.files, shell: deps.shell,
|
|
651
|
+
runBatch: (run) => deps.runBatch!(run, context),
|
|
652
|
+
...(deps.probe !== undefined ? { probe: deps.probe } : {}),
|
|
653
|
+
...(deps.afterGaps !== undefined ? { afterGaps: (vfsPath: string) => deps.afterGaps!({ folder: ctx.work.folder, vfsPath }) } : {}),
|
|
654
|
+
});
|
|
655
|
+
lines.push(...ran.lines);
|
|
656
|
+
if (ran.refused) return finish(lines);
|
|
657
|
+
if (ran.stopped) return finish([...lines, humanDecidesStops(code, parallel)]);
|
|
658
|
+
return finish([...lines, nextWaveFollows(code, parallel)], { crew: "dev-batches", input: { concurrency: parallel } });
|
|
659
|
+
}
|
|
660
|
+
// A batch a parallel run stopped keeps its code, sheet and verdict in its worktree: run here, it would start over.
|
|
661
|
+
const kept = worktreePlace(batchWorktreeName(code, next));
|
|
662
|
+
if (kept !== null && (await listOrNone(deps.files, `${WORKSPACE}/.orkeon/worktrees`)).includes(kept.name)) {
|
|
663
|
+
return finish([
|
|
664
|
+
...lines,
|
|
665
|
+
keptByParallelRun(next, kept.path, code),
|
|
666
|
+
]);
|
|
667
|
+
}
|
|
668
|
+
const entry = lastEntryOf(book.entries(), next);
|
|
669
|
+
const relaunch = entry !== undefined;
|
|
670
|
+
book.add(eventLine(now(), next, relaunch ? "relaunched" : "launched", `${AUDITS_DETAIL} ${auditsOf(dev, next)}`));
|
|
671
|
+
const position = order.ok ? order.order.indexOf(next) + 1 : 0;
|
|
672
|
+
return finish(
|
|
673
|
+
[...lines, launchLine(next, relaunch ? "relaunched" : "launched", position, nodes.length, code)],
|
|
674
|
+
{ crew: "dev-implement", input: launchInput(next, (stale[next] ?? []).length > 0 ? { stale: stale[next] } : {}) },
|
|
675
|
+
);
|
|
676
|
+
}
|