orkeon-code 0.0.0-stage → 1.0.0-rc.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/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +169 -0
- package/README.md +162 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +128 -0
- package/config/appsettings.kev.example.json +130 -0
- package/config/appsettings.liquid.example.json +129 -0
- package/config/appsettings.ollama-whisper.example.json +92 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +31 -0
- package/mcp/whisper/README.md +293 -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 +897 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +837 -0
- package/package.json +57 -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 +562 -0
- package/src/commands/_lib/args.ts +193 -0
- package/src/commands/_lib/dev/dev-batches.ts +368 -0
- package/src/commands/_lib/dev/dev-implement.ts +188 -0
- package/src/commands/_lib/dev/dev-source.ts +65 -0
- package/src/commands/_lib/dev/dev.ts +344 -0
- package/src/commands/_lib/dev-step.ts +142 -0
- package/src/commands/_lib/dispatch.ts +231 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +95 -0
- package/src/commands/_lib/git/commit.ts +94 -0
- package/src/commands/_lib/git/diff.ts +97 -0
- package/src/commands/_lib/git/review.ts +109 -0
- package/src/commands/_lib/memory/memory-admit.ts +150 -0
- package/src/commands/_lib/memory/memory.ts +51 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/session/export.ts +104 -0
- package/src/commands/_lib/session/resume.ts +160 -0
- package/src/commands/_lib/session/tasks.ts +184 -0
- package/src/commands/_lib/settings/advisor.ts +80 -0
- package/src/commands/_lib/settings/agents.ts +147 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/hooks.ts +58 -0
- package/src/commands/_lib/settings/mode.ts +91 -0
- package/src/commands/_lib/settings/model.ts +146 -0
- package/src/commands/_lib/settings/permissions.ts +309 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +51 -0
- package/src/commands/_lib/speech/say.ts +96 -0
- package/src/commands/_lib/speech/transcribe.ts +130 -0
- package/src/commands/_lib/speech/voice.ts +146 -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 +186 -0
- package/src/commands/_lib/status/meta.ts +45 -0
- package/src/commands/_lib/status/status.ts +129 -0
- package/src/commands/_lib/status/usage-tools.ts +49 -0
- package/src/commands/_lib/status/usage.ts +139 -0
- package/src/commands/_lib/view.ts +29 -0
- package/src/commands/dev/dev-batches.cmd.ts +108 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +52 -0
- package/src/commands/dev/dev-spec.cmd.ts +55 -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 +67 -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 +44 -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 +17 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +26 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +44 -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 +17 -0
- package/src/commands/settings/effort.cmd.ts +40 -0
- package/src/commands/settings/fast.cmd.ts +17 -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 +20 -0
- package/src/commands/settings/output-style.cmd.ts +48 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +15 -0
- package/src/commands/settings/skills.cmd.ts +17 -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 +3946 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
- package/src/crews/advisor/application/run-advisor.ts +40 -0
- package/src/crews/advisor/crew.ork.ts +43 -0
- package/src/crews/advisor/domain/advice.ts +135 -0
- package/src/crews/agent-run/application/run-agent-run.ts +42 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/run-analyze.ts +118 -0
- package/src/crews/analyze/crew.ork.ts +40 -0
- package/src/crews/analyze/domain/harvest.ts +301 -0
- package/src/crews/code-review/application/prompts.ts +133 -0
- package/src/crews/code-review/application/review.ts +71 -0
- package/src/crews/code-review/application/run-code-review.ts +123 -0
- package/src/crews/code-review/crew.ork.ts +51 -0
- package/src/crews/code-review/domain/lenses.ts +193 -0
- package/src/crews/code-review/domain/report.ts +59 -0
- package/src/crews/code-review/domain/scope.ts +112 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
- package/src/crews/dev-batches/application/run-wave.ts +450 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
- package/src/crews/dev-batches/crew.ork.ts +143 -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 +54 -0
- package/src/crews/dev-batches/domain/wave-order.ts +43 -0
- package/src/crews/dev-change/application/change-prompt.ts +104 -0
- package/src/crews/dev-change/application/evidence.ts +169 -0
- package/src/crews/dev-change/application/run-dev-change.ts +315 -0
- package/src/crews/dev-change/crew.ork.ts +112 -0
- package/src/crews/dev-change/domain/change-answer.ts +159 -0
- package/src/crews/dev-change/domain/change-render.ts +79 -0
- package/src/crews/dev-implement/application/close.ts +183 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
- package/src/crews/dev-implement/application/observe.ts +50 -0
- package/src/crews/dev-implement/application/report-writes.ts +41 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +118 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +68 -0
- package/src/crews/dev-implement/domain/contracts.ts +256 -0
- package/src/crews/dev-implement/domain/correction.ts +102 -0
- package/src/crews/dev-implement/domain/cycles.ts +35 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/roles.ts +53 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
- package/src/crews/dev-implement/domain/step-checks.ts +136 -0
- package/src/crews/dev-implement/domain/step-section.ts +127 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
- package/src/crews/dev-learn/crew.ork.ts +52 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
- package/src/crews/dev-plan/application/inventory.ts +170 -0
- package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
- package/src/crews/dev-plan/crew.ork.ts +109 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
- package/src/crews/dev-plan/domain/plan-render.ts +307 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
- package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
- package/src/crews/dev-spec/crew.ork.ts +108 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit.ts +259 -0
- package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
- package/src/crews/dev-verify/application/capture.ts +303 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
- package/src/crews/dev-verify/application/run-gate.ts +202 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +126 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +163 -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 +154 -0
- package/src/crews/git-commit/application/run-git-commit.ts +116 -0
- package/src/crews/git-commit/crew.ork.ts +52 -0
- package/src/crews/git-commit/domain/commit.ts +220 -0
- package/src/crews/init-verifiers/application/authoring.ts +89 -0
- package/src/crews/init-verifiers/application/prompts.ts +103 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
- package/src/crews/init-verifiers/crew.ork.ts +34 -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 +77 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/run-main-loop.ts +350 -0
- package/src/crews/main-loop/application/turn-prompt.ts +112 -0
- package/src/crews/main-loop/crew.ork.ts +119 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
- package/src/crews/main-loop/domain/turn-chains.ts +129 -0
- package/src/crews/project-init/application/detect.ts +122 -0
- package/src/crews/project-init/application/prompts.ts +101 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +35 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +63 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/session-compact/crew.ork.ts +55 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
- package/src/crews/speech/application/run-speech.ts +25 -0
- package/src/crews/speech/crew.ork.ts +37 -0
- package/src/shared/application/agents/child-agent.ts +255 -0
- package/src/shared/application/agents/run-sub-agent.ts +96 -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 +237 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -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 +113 -0
- package/src/shared/application/dev/close-batch.ts +83 -0
- package/src/shared/application/dev/find-repo-pack.ts +77 -0
- package/src/shared/application/dev/learn-decision.ts +252 -0
- package/src/shared/application/dev/load-dev-context.ts +266 -0
- package/src/shared/application/dev/measure-access-cost.ts +68 -0
- package/src/shared/application/dev/plan-source.ts +112 -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/question-round.ts +52 -0
- package/src/shared/application/dev/resolve-work-folder.ts +133 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +55 -0
- package/src/shared/application/dev/source-review.ts +63 -0
- package/src/shared/application/dev/source-step.ts +150 -0
- package/src/shared/application/dev/spend.ts +42 -0
- package/src/shared/application/dev/step-precedents.ts +89 -0
- package/src/shared/application/dev/tool-call-policy.ts +89 -0
- package/src/shared/application/dev/tool-callbacks.ts +215 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
- package/src/shared/application/dev/verdict-sources.ts +48 -0
- package/src/shared/application/dev/wrapped-tools.ts +145 -0
- package/src/shared/application/extra-tools.ts +70 -0
- package/src/shared/application/git/batch-worktree.ts +97 -0
- package/src/shared/application/git/commit-files.ts +186 -0
- package/src/shared/application/git/merge-batch.ts +63 -0
- package/src/shared/application/git/open-pull-request.ts +51 -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 +35 -0
- package/src/shared/application/permission-rules.ts +159 -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/files.ts +21 -0
- package/src/shared/application/ports/human.ts +13 -0
- package/src/shared/application/ports/llm.ts +54 -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/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +27 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +84 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +177 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
- package/src/shared/application/shared-memory/memory-files.ts +110 -0
- package/src/shared/application/shared-memory/memory-settings.ts +93 -0
- package/src/shared/application/shared-memory/push-candidate.ts +146 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/workflow-state.ts +135 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -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/permission.ts +623 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
- package/src/shared/domain/agent-policy/tool-access.ts +77 -0
- package/src/shared/domain/agent-registry.ts +142 -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 +61 -0
- package/src/shared/domain/agents/exclusive.ts +24 -0
- package/src/shared/domain/agents/instances.ts +249 -0
- package/src/shared/domain/code-intel-contract.ts +356 -0
- package/src/shared/domain/code-intel-routing.ts +113 -0
- package/src/shared/domain/compact-outcome.ts +44 -0
- package/src/shared/domain/compaction-thresholds.ts +161 -0
- package/src/shared/domain/compaction.ts +379 -0
- package/src/shared/domain/config-schema.ts +421 -0
- package/src/shared/domain/dev/access-cost.ts +226 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +36 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +44 -0
- package/src/shared/domain/dev/call-guard.ts +341 -0
- package/src/shared/domain/dev/carried-text.ts +49 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +175 -0
- package/src/shared/domain/dev/learn-state.ts +93 -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/plan-checks.ts +190 -0
- package/src/shared/domain/dev/plan-format.ts +180 -0
- package/src/shared/domain/dev/project-files.ts +43 -0
- package/src/shared/domain/dev/questions.ts +249 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +237 -0
- package/src/shared/domain/dev/review-answer.ts +150 -0
- package/src/shared/domain/dev/review-prompt.ts +221 -0
- package/src/shared/domain/dev/reviewer-charter.ts +31 -0
- package/src/shared/domain/dev/sheet-facts.ts +83 -0
- package/src/shared/domain/dev/spec-format.ts +183 -0
- package/src/shared/domain/dev/step-budget.ts +72 -0
- package/src/shared/domain/dev/step-rules.ts +110 -0
- package/src/shared/domain/dev/test-commands.ts +90 -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 +64 -0
- package/src/shared/domain/dev/trait-pattern.ts +83 -0
- package/src/shared/domain/dev/verdict-format.ts +169 -0
- package/src/shared/domain/dev/whitespace.ts +34 -0
- package/src/shared/domain/dev/work-folder.ts +67 -0
- package/src/shared/domain/dev/yaml-subset.ts +403 -0
- package/src/shared/domain/git/close.ts +273 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -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 +106 -0
- package/src/shared/domain/llm-profile.ts +25 -0
- package/src/shared/domain/marked-message.ts +33 -0
- package/src/shared/domain/model-catalog.ts +86 -0
- package/src/shared/domain/permission-modes.ts +103 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +83 -0
- package/src/shared/domain/search-routing.ts +85 -0
- package/src/shared/domain/secret-patterns.ts +45 -0
- package/src/shared/domain/session-keys.ts +85 -0
- package/src/shared/domain/session-start.ts +60 -0
- package/src/shared/domain/session-summary.ts +13 -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 +143 -0
- package/src/shared/domain/shared-memory/candidates.ts +41 -0
- package/src/shared/domain/shared-memory/entry.ts +145 -0
- package/src/shared/domain/shared-memory/front-matter.ts +183 -0
- package/src/shared/domain/shared-memory/gate.ts +44 -0
- package/src/shared/domain/shared-memory/harvest.ts +61 -0
- package/src/shared/domain/shared-memory/layout.ts +187 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +93 -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/snip-turns.ts +45 -0
- package/src/shared/domain/speech.ts +20 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +122 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +37 -0
- package/src/shared/domain/vfs.ts +9 -0
- package/src/shared/domain/workflow/state-file.ts +140 -0
- package/src/shared/infrastructure/globals.ts +52 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +127 -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/dev-deps.ts +172 -0
- package/src/shared/infrastructure/orkeon/files.ts +40 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
- package/src/shared/infrastructure/orkeon/llm.ts +109 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -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/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 +134 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +138 -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 +75 -0
- package/src/shared/infrastructure/orkeon/shell.ts +31 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -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 +118 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
// dev-implement F<n>: the steps of one batch sheet, each as RED by the test author then GREEN by
|
|
2
|
+
// the implementer, two acts of the crew's one agent with their own tools and rules. Consecutive
|
|
3
|
+
// steps on one test file are one cycle: every RED first, then one GREEN and one Cost for them all.
|
|
4
|
+
// Code makes each brief from the sheet, observes the tree before and after each act, runs the
|
|
5
|
+
// tests itself, measures the cost of what changed, and ticks a box only once what it stands for was
|
|
6
|
+
// seen. After the last cycle the batch's files are refreshed in the code index, then the build, then
|
|
7
|
+
// the whole suite once per batch (the affected projects after, the sheet's and the graph's), run as
|
|
8
|
+
// shell jobs and write the logs dev-verify reads; a batch all ticked and green hands
|
|
9
|
+
// over to dev-verify (the `next` of its answer, `resume` after a GAPS verdict). A correction
|
|
10
|
+
// (`— correction: <finding>`) is first appended to the sheet as a new step. Any failed check stops
|
|
11
|
+
// the batch with BLOCKED and ticks nothing more.
|
|
12
|
+
//
|
|
13
|
+
// The answer is JSON: `{ lines, next? }`, read by the command's `completed`.
|
|
14
|
+
import type { AffectedTests, Clock, CostIndex, Files, Llm, Logger, Shell, ShellJobs } from "../../../shared/application/ports.ts";
|
|
15
|
+
import { isoDay } from "../../../shared/domain/iso-day.ts";
|
|
16
|
+
import type { ConfigStore } from "../../../shared/application/config-store.ts";
|
|
17
|
+
import type { PullRequestOpener } from "../../../shared/application/git/commit-files.ts";
|
|
18
|
+
import { loadDevContext } from "../../../shared/application/dev/load-dev-context.ts";
|
|
19
|
+
import { createWrappedTools } from "../../../shared/application/dev/wrapped-tools.ts";
|
|
20
|
+
import { measureAccessCost } from "../../../shared/application/dev/measure-access-cost.ts";
|
|
21
|
+
import type { CostFile } from "../../../shared/application/dev/measure-access-cost.ts";
|
|
22
|
+
import { addedLines } from "../../../shared/domain/dev/access-cost.ts";
|
|
23
|
+
import { hasTestLayout, isTestPath } from "../../../shared/domain/dev/test-paths.ts";
|
|
24
|
+
import { auditCommand, closeCommand, gapsRoundsOf, lastVerdict, parseVerdictFile } from "../../../shared/domain/dev/verdict-format.ts";
|
|
25
|
+
import { shellQuote } from "../../../shared/domain/git/close.ts";
|
|
26
|
+
import type { CarriedText } from "../../../shared/domain/dev/carried-text.ts";
|
|
27
|
+
import { tidyWhitespace } from "../../../shared/domain/dev/whitespace.ts";
|
|
28
|
+
import type { WrappedRun, WrappedTools } from "../../../shared/application/dev/wrapped-tools.ts";
|
|
29
|
+
import { stepRules } from "../../../shared/domain/dev/step-rules.ts";
|
|
30
|
+
import { policyFor } from "../../../shared/domain/agent-policy/mode-policy.ts";
|
|
31
|
+
import { parseSessionRules } from "../../../shared/domain/git/pull-request.ts";
|
|
32
|
+
import { shellRuleGuard } from "../../../shared/domain/dev/tool-guards.ts";
|
|
33
|
+
import type { RepoPack, RepoPackLayout } from "../../../shared/domain/dev/repo-pack.ts";
|
|
34
|
+
import { existingStubsOf, testFileOf, greenContract, projectCommandFor, redContract, staleBlock, stubsOf, testCommandFor } from "../domain/contracts.ts";
|
|
35
|
+
import { openSteps, parseImplementSheet } from "../domain/step-section.ts";
|
|
36
|
+
import type { ImplementSheet, ImplementStep } from "../domain/step-section.ts";
|
|
37
|
+
import { addedFailure, changedPaths, failureCount, greenProblem, readCost, redProblem, under } from "../domain/step-checks.ts";
|
|
38
|
+
import { cyclesLine, cyclesOf, stepsLabel } from "../domain/cycles.ts";
|
|
39
|
+
import type { Cycle } from "../domain/cycles.ts";
|
|
40
|
+
import { addCorrection } from "../domain/correction.ts";
|
|
41
|
+
import { addAssumptions, assumptionsOf } from "../domain/sheet-edits.ts";
|
|
42
|
+
import type { ObservedRun } from "../domain/step-checks.ts";
|
|
43
|
+
import { tickBox } from "../domain/sheet-ticks.ts";
|
|
44
|
+
import type { TddBox } from "../domain/sheet-ticks.ts";
|
|
45
|
+
import { IMPLEMENTER, TEST_AUTHOR } from "../domain/roles.ts";
|
|
46
|
+
import type { RoleName } from "../domain/roles.ts";
|
|
47
|
+
import { SLICE_SECONDS, SUITE_LIMIT_SECONDS } from "../domain/implement-budget.ts";
|
|
48
|
+
import { askLine, runRole } from "./run-role.ts";
|
|
49
|
+
import { NOTHING_RECALLED, noPrecedents, precedentsLine, recallQuery, sheetTitle } from "../../../shared/application/dev/step-precedents.ts";
|
|
50
|
+
import type { Recalled, StepPrecedents } from "../../../shared/application/dev/step-precedents.ts";
|
|
51
|
+
import { snapshot } from "./observe.ts";
|
|
52
|
+
import { logText, NO_VERDICT_EXIT, runSuite } from "./suite-job.ts";
|
|
53
|
+
import { locateSheet } from "./locate-sheet.ts";
|
|
54
|
+
import type { LocatedSheet } from "./locate-sheet.ts";
|
|
55
|
+
import { prContextOf, readTouchedRecord, recordTouched, verdictMarkOf } from "./touched.ts";
|
|
56
|
+
import type { PrContext } from "./touched.ts";
|
|
57
|
+
import { closeDevBatch } from "./close.ts";
|
|
58
|
+
import { BATCHES_ACTIVE_RECORD, batchesRunCode } from "../../../shared/domain/dev/batches-state.ts";
|
|
59
|
+
import { WORKSPACE, workspaceRelative } from "../../../shared/domain/vfs.ts";
|
|
60
|
+
|
|
61
|
+
export interface DevImplementInputs {
|
|
62
|
+
batch?: unknown; plan?: unknown; close?: unknown; pr?: unknown; push?: unknown;
|
|
63
|
+
/** The finding of a correction (`— correction: <finding>`): appended to the sheet as a new step first. */
|
|
64
|
+
correction?: unknown;
|
|
65
|
+
/** The `stale: <question> — <evidence>` lines /dev-batches hands a batch's first launch (its review's Major rows):
|
|
66
|
+
* they end the RED and GREEN prompts. */
|
|
67
|
+
stale?: readonly string[];
|
|
68
|
+
/** The session's mode and rules at the launch: a read-only mode is refused, a deny on the push keeps the commit local. */
|
|
69
|
+
permissionMode?: unknown; permissionRules?: unknown;
|
|
70
|
+
/** Whether the github tool is registered (the close opens the pull request itself). */
|
|
71
|
+
githubTool?: unknown;
|
|
72
|
+
/** Carried to the audit the run chains: the /hooks registry, the /effort level, and `memoryRecall: false`. */
|
|
73
|
+
hooks?: unknown; effort?: unknown; memoryRecall?: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const flag = (v: unknown): boolean => v === true || v === "true";
|
|
77
|
+
|
|
78
|
+
/** The crew's inputs as the run reads them. `push: false` is kept: /dev-batches sends it on every batch's close, so
|
|
79
|
+
* that the plan's branch is pushed once, at the run's own close (L-7); any other value pushes, as before. */
|
|
80
|
+
export function implementInputs(args: Record<string, unknown>): DevImplementInputs {
|
|
81
|
+
return {
|
|
82
|
+
batch: args.batch, plan: args.plan, close: flag(args.close), pr: flag(args.pr), correction: args.correction,
|
|
83
|
+
stale: Array.isArray(args.stale) ? args.stale.filter((l): l is string => typeof l === "string") : undefined,
|
|
84
|
+
push: args.push === false || args.push === "false" ? false : undefined,
|
|
85
|
+
permissionMode: args.permissionMode, permissionRules: args.permissionRules, githubTool: args.githubTool,
|
|
86
|
+
hooks: args.hooks, effort: args.effort, memoryRecall: args.memoryRecall,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface DevImplementDeps {
|
|
91
|
+
files: Files; shell: Shell; config: Pick<ConfigStore, "readValue">; jobs: ShellJobs;
|
|
92
|
+
/** A role's Llm, built with that role's callbacks over the pack's layout; `wrote` hears the path of each
|
|
93
|
+
* file_write or edit_file call those callbacks let through; `writable` names the paths the role's own denies
|
|
94
|
+
* leave open (the test author's stubs). */
|
|
95
|
+
roleLlm(role: RoleName, layout: RepoPackLayout, wrote: (path: string) => void, writable: readonly string[]): Pick<Llm, "act">;
|
|
96
|
+
log: Logger;
|
|
97
|
+
/** The slot run_tests and run_build read: bound to this run's wrapped tools. */
|
|
98
|
+
toolSlot?: { bind(tools: WrappedTools): () => void };
|
|
99
|
+
/** The close's pull-request opener, for the context read at the launch; none: the command is handed over. */
|
|
100
|
+
openerFor?(context: PrContext): PullRequestOpener | undefined;
|
|
101
|
+
/** The code index the measured cost reads, refreshed after the batch, and asked for the affected tests; none: the
|
|
102
|
+
* cost is not computed (the stated line decides) and the affected tests are the sheet's. */
|
|
103
|
+
costIndex?: CostIndex;
|
|
104
|
+
/** The time now: the close's done marks carry its UTC day. */
|
|
105
|
+
clock: Clock;
|
|
106
|
+
/** The shared memory's code-triggered recall (T3 before each red act, T5 on a correction); absent, none. */
|
|
107
|
+
precedents?: StepPrecedents;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ImplementAnswer {
|
|
111
|
+
lines: string[];
|
|
112
|
+
next?: { crew: "dev-verify"; input: { batch: string; plan: string; mode: "fast" | "resume"; hooks?: unknown; effort?: unknown; memoryRecall?: false } };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const RESTORE_TIMEOUT_SECONDS = 900;
|
|
116
|
+
const BATCH = /^F\d+$/;
|
|
117
|
+
const GAPS_ROUNDS_WARNED = 2;
|
|
118
|
+
|
|
119
|
+
const answer = (lines: string[], next?: ImplementAnswer["next"]): string =>
|
|
120
|
+
JSON.stringify(next === undefined ? { lines } : { lines, next });
|
|
121
|
+
const blocked = (lines: string[], line: string): string => answer([...lines, `BLOCKED — ${line}`]);
|
|
122
|
+
const reasonOf = (e: unknown): string => String((e as Error)?.message ?? e).split("\n")[0];
|
|
123
|
+
|
|
124
|
+
interface Run {
|
|
125
|
+
deps: DevImplementDeps;
|
|
126
|
+
pack: RepoPack;
|
|
127
|
+
isTest: (path: string) => boolean;
|
|
128
|
+
located: LocatedSheet;
|
|
129
|
+
sheetPath: string;
|
|
130
|
+
sheetText: string;
|
|
131
|
+
sheet: ImplementSheet;
|
|
132
|
+
tools: WrappedTools;
|
|
133
|
+
wrote: (path: string) => void;
|
|
134
|
+
/** Folders whose writes are code's own (the work folder, the plan folder): never a role's change. */
|
|
135
|
+
ownFolders: string[];
|
|
136
|
+
/** The plan folder, relative to /workspace, and its logs folder, the one part of it a role's runs write. */
|
|
137
|
+
planFolder: string;
|
|
138
|
+
planLogs: string;
|
|
139
|
+
logFolder: string;
|
|
140
|
+
/** The paths the running act's write tools named, relative to /workspace. */
|
|
141
|
+
written: Set<string>;
|
|
142
|
+
verdictMark: string;
|
|
143
|
+
touched: Set<string>;
|
|
144
|
+
/** The steps this run ran an act of: the affected projects. */
|
|
145
|
+
ran: ImplementStep[];
|
|
146
|
+
lines: string[];
|
|
147
|
+
/** T5: the mistakes recalled for the correction this run carries, in each role's prompt; every recall, for the end. */
|
|
148
|
+
correction: Recalled;
|
|
149
|
+
recalled: Recalled[];
|
|
150
|
+
/** The stale lines of the launch, as the block that ends each role's prompt ("" without any). */
|
|
151
|
+
stale: Recalled;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A role's prompt with the precedents recalled for it, each block after the contract. */
|
|
155
|
+
function withPrecedents(prompt: string, recalled: readonly Recalled[]): string {
|
|
156
|
+
const blocks = recalled.map((r) => r.block.trimEnd()).filter((b) => b !== "");
|
|
157
|
+
return blocks.length === 0 ? prompt : [prompt.trimEnd(), ...blocks].join("\n\n");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** T3, before a step's red act: the code structures and mistakes recalled from the sheet's title, the step's title
|
|
161
|
+
* and the paths it touches. */
|
|
162
|
+
async function recallForRed(run: Run, step: ImplementStep): Promise<Recalled> {
|
|
163
|
+
const paths = [...(step.anchor?.testFiles ?? []), ...(step.anchor?.production ?? [])].map((a) => a.path);
|
|
164
|
+
const recalled = await (run.deps.precedents ?? noPrecedents)("T3", recallQuery([sheetTitle(run.sheetText), step.title, ...paths]));
|
|
165
|
+
run.recalled.push(recalled);
|
|
166
|
+
return recalled;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function observedRun(run: WrappedRun): ObservedRun {
|
|
170
|
+
return run.ok ? { ran: true, exit: run.exit, timedOut: run.timedOut, log: run.log } : { ran: false, reason: run.refused };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function writeSheet(run: Run, text: string): Promise<string | null> {
|
|
174
|
+
try {
|
|
175
|
+
await run.deps.files.write(run.sheetPath, text);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
return `the sheet could not be written: ${reasonOf(e)}`;
|
|
178
|
+
}
|
|
179
|
+
run.sheetText = text;
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function tick(run: Run, step: ImplementStep, box: TddBox): Promise<string | null> {
|
|
184
|
+
const ticked = tickBox(run.sheetText, step.number, box);
|
|
185
|
+
if (!ticked.ok) return ticked.problem;
|
|
186
|
+
return writeSheet(run, ticked.text);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Ticks `box` on every step, in order; the first problem stops. */
|
|
190
|
+
async function tickAll(run: Run, steps: readonly ImplementStep[], box: TddBox): Promise<string | null> {
|
|
191
|
+
for (const step of steps) {
|
|
192
|
+
const failed = await tick(run, step, box);
|
|
193
|
+
if (failed !== null) return failed;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The `Assumption:` lines of a role's answer, written under `## Assumptions` once each. */
|
|
199
|
+
async function keepAssumptions(run: Run, text: string): Promise<void> {
|
|
200
|
+
const { text: next, added } = addAssumptions(run.sheetText, assumptionsOf(text));
|
|
201
|
+
if (added.length === 0) return;
|
|
202
|
+
const failed = await writeSheet(run, next);
|
|
203
|
+
run.lines.push(failed === null
|
|
204
|
+
? `assumption${added.length === 1 ? "" : "s"} written to ## Assumptions, to be validated by the user: ${added.join("; ")}`
|
|
205
|
+
: `⚠ assumptions not written (${failed}): ${added.join("; ")}`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** A path a write tool named, relative to /workspace. */
|
|
209
|
+
export function workspacePath(path: string): string {
|
|
210
|
+
return workspaceRelative(path.trim()).replace(/^(\.\/)+/, "").replace(/\/+$/, "");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Puts the sheet back as code last wrote it; a problem when it cannot. */
|
|
214
|
+
async function sheetPutBack(run: Run): Promise<string | null> {
|
|
215
|
+
let now: string | null = null;
|
|
216
|
+
try {
|
|
217
|
+
now = await run.deps.files.read(run.sheetPath);
|
|
218
|
+
} catch {
|
|
219
|
+
now = null;
|
|
220
|
+
}
|
|
221
|
+
if (now === run.sheetText) return null;
|
|
222
|
+
try {
|
|
223
|
+
await run.deps.files.write(run.sheetPath, run.sheetText);
|
|
224
|
+
return "the sheet was changed by the role, and put back";
|
|
225
|
+
} catch (e) {
|
|
226
|
+
return `the sheet was changed by the role and could not be put back: ${reasonOf(e)}`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** One act of a role, between two snapshots: the paths it changed, or why not. A path is the role's when its
|
|
231
|
+
* write tools named it and the tree shows it changed (or it is too large to read); what its runs of run_tests
|
|
232
|
+
* or run_build produced is not. Any change to the plan folder but its logs stops the step, the sheet put back. */
|
|
233
|
+
async function act(
|
|
234
|
+
run: Run, role: RoleName, prompt: string, writable: readonly string[] = [],
|
|
235
|
+
): Promise<{ text: string; changed: string[] } | string> {
|
|
236
|
+
const before = await snapshot(run.deps);
|
|
237
|
+
if (!before.ok) return before.problem;
|
|
238
|
+
const spec = role === "test-author" ? TEST_AUTHOR : IMPLEMENTER;
|
|
239
|
+
run.written.clear();
|
|
240
|
+
const said = await runRole(run.deps.roleLlm(role, run.pack.layout, run.wrote, writable), spec, prompt);
|
|
241
|
+
const after = await snapshot(run.deps);
|
|
242
|
+
const seen = after.ok ? new Set(changedPaths(before.snapshot, after.snapshot)) : new Set<string>();
|
|
243
|
+
const planChanges = [...new Set([...seen, ...run.written])]
|
|
244
|
+
.filter((p) => under(p, run.planFolder) && !under(p, run.planLogs)).sort();
|
|
245
|
+
const putBack = await sheetPutBack(run);
|
|
246
|
+
if (planChanges.length > 0 || putBack !== null) {
|
|
247
|
+
return `${role} changed the plan folder (${planChanges.join(", ") || run.located.name}): the sheet and the plan are code's own${putBack === null ? "" : `; ${putBack}`}`;
|
|
248
|
+
}
|
|
249
|
+
if (!said.ok) return said.reason;
|
|
250
|
+
if (!after.ok) return after.problem;
|
|
251
|
+
const unread = (p: string): boolean => after.snapshot.get(p) === null;
|
|
252
|
+
const changed = [...run.written]
|
|
253
|
+
.filter((p) => seen.has(p) || unread(p))
|
|
254
|
+
.filter((p) => !run.ownFolders.some((f) => under(p, f)))
|
|
255
|
+
.sort();
|
|
256
|
+
await keepAssumptions(run, said.text);
|
|
257
|
+
await tidyChanged(run, changed);
|
|
258
|
+
return { text: said.text, changed };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The whitespace `git diff --check` would refuse, put right in the files the role changed: a node insert at the
|
|
262
|
+
* end of a module leaves a blank line after the last member, and the gate would stop the batch for it. */
|
|
263
|
+
async function tidyChanged(run: Run, changed: readonly string[]): Promise<void> {
|
|
264
|
+
for (const path of changed) {
|
|
265
|
+
let text: string;
|
|
266
|
+
try {
|
|
267
|
+
text = await run.deps.files.read(`${WORKSPACE}/${path}`);
|
|
268
|
+
} catch {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const tidy = tidyWhitespace(text);
|
|
272
|
+
if (tidy.fixed.length === 0) continue;
|
|
273
|
+
try {
|
|
274
|
+
await run.deps.files.write(`${WORKSPACE}/${path}`, tidy.text);
|
|
275
|
+
run.lines.push(`whitespace ✓ — ${path}: ${tidy.fixed.join(", ")}`);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
run.lines.push(`⚠ whitespace — ${path}: ${tidy.fixed.join(", ")}, not written (${error instanceof Error ? error.message.split("\n")[0] : String(error)})`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function contractInput(run: Run, step: ImplementStep, testCommand: string, carried: readonly CarriedText[], cycle?: readonly ImplementStep[]) {
|
|
283
|
+
return {
|
|
284
|
+
code: run.located.code, sheetPath: `${run.located.dir}/${run.located.name}`, sheet: run.sheet, step,
|
|
285
|
+
...(cycle === undefined ? {} : { cycle }), layout: run.pack.layout, testCommand, carried,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** What a role's brief carries: the sheet, then each of `paths` that exists (a test file, a production file; one to
|
|
290
|
+
* create is left out). */
|
|
291
|
+
async function carriedFor(run: Run, paths: readonly (string | null)[]): Promise<CarriedText[]> {
|
|
292
|
+
const sheet = `${run.located.dir}/${run.located.name}`;
|
|
293
|
+
const out: CarriedText[] = [{ title: sheet, path: sheet, text: run.sheetText }];
|
|
294
|
+
for (const path of new Set(paths)) {
|
|
295
|
+
if (path === null) continue;
|
|
296
|
+
try {
|
|
297
|
+
out.push({ title: path, path, text: await run.deps.files.read(`${WORKSPACE}/${path}`) });
|
|
298
|
+
} catch {
|
|
299
|
+
// To create, or unreadable: the role's own.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The lines `git diff -U0` adds to each changed production file; an untracked file (no diff), or one whose diff
|
|
306
|
+
* cannot be read, counts whole. */
|
|
307
|
+
async function costFiles(run: Run, paths: readonly string[]): Promise<CostFile[]> {
|
|
308
|
+
const out: CostFile[] = [];
|
|
309
|
+
for (const path of paths) {
|
|
310
|
+
let added: Set<number> | null = null;
|
|
311
|
+
try {
|
|
312
|
+
const r = await run.deps.shell.run(`git diff -U0 HEAD -- ${shellQuote(path)}`);
|
|
313
|
+
if (r.exitCode === 0 && r.stdout.trim() !== "") added = addedLines(r.stdout);
|
|
314
|
+
} catch {
|
|
315
|
+
added = null;
|
|
316
|
+
}
|
|
317
|
+
out.push({ path, added });
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The measured cost of the cycle's production changes, after its stated Cost line passed: a problem when the
|
|
323
|
+
* measure flags a port call or a memory filter on an added line; else the line it adds to the run's. */
|
|
324
|
+
async function measuredCost(run: Run, production: readonly string[]): Promise<{ problem: string } | { line: string }> {
|
|
325
|
+
if (production.length === 0) return { line: "measured: not computed — no production file changed in this run" };
|
|
326
|
+
const cost = await measureAccessCost(run.deps.costIndex, run.pack, [], await costFiles(run, production), run.isTest);
|
|
327
|
+
if (cost.state === "not-computed") return { line: `measured: not computed — ${cost.reason}` };
|
|
328
|
+
if (cost.exit === 2) {
|
|
329
|
+
return { problem: `measured ${cost.costLine}; flagged: ${cost.flagged.join("; ")} — back to /dev-plan (the design names the access, the code cannot move it)` };
|
|
330
|
+
}
|
|
331
|
+
return { line: `measured: ${cost.costLine}` };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** The step's `to create` production paths that are still to create: neither written in this run nor present in the
|
|
335
|
+
* tree. A path an earlier GREEN implemented is never a stub again. */
|
|
336
|
+
async function openStubs(run: Run, step: ImplementStep): Promise<string[]> {
|
|
337
|
+
const out: string[] = [];
|
|
338
|
+
for (const path of stubsOf(step)) {
|
|
339
|
+
if (run.touched.has(path)) continue;
|
|
340
|
+
try {
|
|
341
|
+
await run.deps.files.read(`${WORKSPACE}/${path}`, 1);
|
|
342
|
+
} catch {
|
|
343
|
+
out.push(path);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** The failures each RED-ticked step of the batch left, by step number: a rerun's baseline (`<batch>-red-failures.json`
|
|
350
|
+
* in the logs folder). Unreadable, it is empty. */
|
|
351
|
+
const redCountsPath = (run: Run): string => `${run.logFolder}/${run.sheet.batch}-red-failures.json`;
|
|
352
|
+
|
|
353
|
+
async function readRedCounts(run: Run): Promise<Record<string, number>> {
|
|
354
|
+
try {
|
|
355
|
+
const parsed = JSON.parse(await run.deps.files.read(redCountsPath(run))) as unknown;
|
|
356
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
357
|
+
return Object.fromEntries(Object.entries(parsed).filter((e): e is [string, number] => Number.isInteger(e[1]) && (e[1] as number) >= 0));
|
|
358
|
+
} catch {
|
|
359
|
+
return {};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Records the failures a ticked RED left; a count the tail does not show, or a write that fails, records nothing
|
|
364
|
+
* (a rerun then takes the suite's own run as its baseline). */
|
|
365
|
+
async function recordRedCount(run: Run, step: ImplementStep, count: number | null): Promise<void> {
|
|
366
|
+
if (count === null) return;
|
|
367
|
+
const counts = { ...await readRedCounts(run), [String(step.number)]: count };
|
|
368
|
+
try {
|
|
369
|
+
await run.deps.files.write(redCountsPath(run), `${JSON.stringify(counts)}\n`);
|
|
370
|
+
} catch {
|
|
371
|
+
// the record is a help to a rerun, never a verdict
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function runCycle(run: Run, cycle: Cycle): Promise<string | null> {
|
|
376
|
+
const steps = cycle.steps;
|
|
377
|
+
const label = stepsLabel(steps);
|
|
378
|
+
const command = testCommandFor(run.pack.commands, steps[0]);
|
|
379
|
+
if (!command.ok) return `${label}: ${command.reason}`;
|
|
380
|
+
const production = new Set<string>();
|
|
381
|
+
|
|
382
|
+
const toRed = steps.filter((s) => !s.tdd?.red);
|
|
383
|
+
// A rerun after BLOCKED: a step of the cycle is RED-ticked already and its tests fail. One run before the first new
|
|
384
|
+
// RED is the baseline its tests must add a failure to, as the run of that step would have been. The tests the
|
|
385
|
+
// BLOCKED step wrote before it stopped fail in that run too: the count the last ticked step recorded, when lower,
|
|
386
|
+
// is the baseline.
|
|
387
|
+
let red: WrappedRun | null = null;
|
|
388
|
+
let before: string | number | null = null;
|
|
389
|
+
if (toRed.length > 0 && toRed.length < steps.length) {
|
|
390
|
+
red = await run.tools.runTests({ command: command.command });
|
|
391
|
+
const ticked = steps.filter((s) => s.tdd?.red).at(-1);
|
|
392
|
+
const recorded = ticked === undefined ? undefined : (await readRedCounts(run))[String(ticked.number)];
|
|
393
|
+
const observed = red.ok ? failureCount(red.tail) : null;
|
|
394
|
+
before = recorded !== undefined && observed !== null && recorded < observed ? recorded : red.ok ? red.tail : null;
|
|
395
|
+
}
|
|
396
|
+
// A stub a RED of this cycle wrote stays open to its later REDs, this run's or a rerun's: the cycle's GREEN, the only
|
|
397
|
+
// one that fills it, has not run.
|
|
398
|
+
const stubbed = new Set(steps.filter((s) => s.tdd?.red).flatMap((s) => [...stubsOf(s), ...existingStubsOf(s)]).filter((p) => run.touched.has(p)));
|
|
399
|
+
for (const step of toRed) {
|
|
400
|
+
const stubs = [...new Set([...await openStubs(run, step), ...existingStubsOf(step), ...stubbed])];
|
|
401
|
+
const t3 = await recallForRed(run, step);
|
|
402
|
+
const carried = await carriedFor(run, [testFileOf(step)]);
|
|
403
|
+
const done = await act(run, "test-author", withPrecedents(redContract({ ...contractInput(run, step, command.command, carried), stubs }), [t3, run.correction, run.stale]), stubs);
|
|
404
|
+
if (typeof done === "string") return `step ${step.number} RED: ${done}`;
|
|
405
|
+
run.ran.push(step);
|
|
406
|
+
const earlier = before;
|
|
407
|
+
red = await run.tools.runTests({ command: command.command });
|
|
408
|
+
const problem = redProblem(done.changed, run.isTest, observedRun(red), stubs);
|
|
409
|
+
if (problem !== null) return `step ${step.number} RED: ${problem}${logOf(red)}`;
|
|
410
|
+
// A later step of the cycle: its file failed already, so its own tests must add a failure.
|
|
411
|
+
const added = earlier !== null && red.ok ? addedFailure(earlier, red.tail) : "ok";
|
|
412
|
+
if (typeof added === "object") return `step ${step.number} RED: ${added.problem}${logOf(red)}`;
|
|
413
|
+
done.changed.forEach((p) => { run.touched.add(p); if (!run.isTest(p)) production.add(p); });
|
|
414
|
+
const failed = await tick(run, step, "RED");
|
|
415
|
+
if (failed !== null) return `step ${step.number} RED: ${failed}`;
|
|
416
|
+
before = red.ok ? red.tail : null;
|
|
417
|
+
await recordRedCount(run, step, red.ok ? failureCount(red.tail) : null);
|
|
418
|
+
const wroteStubs = done.changed.filter((p) => !run.isTest(p));
|
|
419
|
+
wroteStubs.forEach((p) => stubbed.add(p));
|
|
420
|
+
const unchecked = added === "unknown" ? " (its own failure not checked: the run's tail shows no failure count)" : "";
|
|
421
|
+
run.lines.push(`step ${step.number} RED ✓ — ${done.changed.filter(run.isTest).join(", ")}${wroteStubs.length === 0 ? "" : ` (stubs: ${wroteStubs.join(", ")})`}${unchecked}`);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
let costText: string | null = null;
|
|
425
|
+
const green = steps.filter((s) => !s.tdd?.green);
|
|
426
|
+
if (green.length > 0) {
|
|
427
|
+
red ??= await run.tools.runTests({ command: command.command });
|
|
428
|
+
const redTail = red.ok ? { tail: red.tail, log: red.log } : { tail: `(not run: ${red.refused})`, log: null };
|
|
429
|
+
const greenLabel = stepsLabel(green);
|
|
430
|
+
// The production files too: a stub RED wrote, an existing module, so that GREEN opens none of them.
|
|
431
|
+
const productionFiles = green.flatMap((s) => (s.anchor?.production ?? []).filter((r) => r.state !== "member").map((r) => r.path));
|
|
432
|
+
const carried = await carriedFor(run, [...green.map(testFileOf), ...productionFiles]);
|
|
433
|
+
const done = await act(run, "implementer", withPrecedents(greenContract(contractInput(run, green[0], command.command, carried, green), redTail), [run.correction, run.stale]));
|
|
434
|
+
if (typeof done === "string") return `${greenLabel} GREEN: ${done}`;
|
|
435
|
+
run.ran.push(...green.filter((s) => !run.ran.includes(s)));
|
|
436
|
+
const after = await run.tools.runTests({ command: command.command });
|
|
437
|
+
const problem = greenProblem(done.changed, run.isTest, observedRun(after), observedRun(red));
|
|
438
|
+
if (problem !== null) return `${greenLabel} GREEN: ${problem}${logOf(after)}`;
|
|
439
|
+
done.changed.forEach((p) => { run.touched.add(p); production.add(p); });
|
|
440
|
+
const failed = await tickAll(run, green, "GREEN");
|
|
441
|
+
if (failed !== null) return `${greenLabel} GREEN: ${failed}`;
|
|
442
|
+
run.lines.push(`${greenLabel} GREEN ✓ — ${done.changed.join(", ") || "no file changed"}`);
|
|
443
|
+
costText = done.text;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const costed = steps.filter((s) => !s.tdd?.cost);
|
|
447
|
+
if (costed.length > 0) {
|
|
448
|
+
const costLabel = stepsLabel(costed);
|
|
449
|
+
let cost = readCost(costText ?? "");
|
|
450
|
+
if (!cost.ok && cost.line === undefined) {
|
|
451
|
+
const asked = await askLine(run.deps.roleLlm("implementer", run.pack.layout, run.wrote, []), IMPLEMENTER,
|
|
452
|
+
`${label[0].toUpperCase()}${label.slice(1)} of ${run.located.code} ${run.sheet.batch}: answer with one line only, ` +
|
|
453
|
+
"`Cost: <reads> reads, <writes> writes; <where a port call sits in a loop, a lambda or a memory filter, or none>`.");
|
|
454
|
+
if (!asked.ok) return `${costLabel} COST: ${asked.reason}`;
|
|
455
|
+
cost = readCost(asked.text);
|
|
456
|
+
}
|
|
457
|
+
if (!cost.ok) return `${costLabel} COST: ${cost.problem}`;
|
|
458
|
+
const measured = await measuredCost(run, [...production].sort());
|
|
459
|
+
if ("problem" in measured) return `${costLabel} COST: ${measured.problem}`;
|
|
460
|
+
const failed = await tickAll(run, costed, "COST");
|
|
461
|
+
if (failed !== null) return `${costLabel} COST: ${failed}`;
|
|
462
|
+
run.lines.push(`${costLabel} COST ✓ — ${cost.line}; ${measured.line}`);
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function logOf(run: WrappedRun): string {
|
|
468
|
+
return run.ok && run.log !== null ? ` (log: ${run.log.replace(`${WORKSPACE}/`, "")})` : "";
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const shownPath = (path: string | null): string => (path === null ? "" : ` (log: ${path.replace(`${WORKSPACE}/`, "")})`);
|
|
472
|
+
|
|
473
|
+
/** The pack's restore, once, before any act: true when it ran green, null when the pack has none. */
|
|
474
|
+
async function restore(
|
|
475
|
+
run: Pick<Run, "deps" | "pack" | "logFolder" | "lines">, batch: string,
|
|
476
|
+
): Promise<{ problem: string } | { restored: boolean }> {
|
|
477
|
+
const command = run.pack.commands.restore?.trim();
|
|
478
|
+
if (!command) return { restored: false };
|
|
479
|
+
const refusal = shellRuleGuard(stepRules("dev-implement"))(command);
|
|
480
|
+
if (refusal !== null) return { problem: `restore: ${refusal}` };
|
|
481
|
+
let r;
|
|
482
|
+
try {
|
|
483
|
+
r = await run.deps.shell.run(command, { timeoutSeconds: RESTORE_TIMEOUT_SECONDS });
|
|
484
|
+
} catch (e) {
|
|
485
|
+
return { problem: `restore: '${command}' could not run: ${reasonOf(e)}` };
|
|
486
|
+
}
|
|
487
|
+
const log = `${run.logFolder}/${batch}-restore.txt`;
|
|
488
|
+
const output = [r.stdout.trimEnd(), r.stderr.trimEnd()].filter((t) => t !== "").join("\n");
|
|
489
|
+
try {
|
|
490
|
+
await run.deps.files.write(log, logText(command, r.timedOut === true ? [`still running after ${RESTORE_TIMEOUT_SECONDS} s: no verdict`] : [], output, r.timedOut === true ? NO_VERDICT_EXIT : r.exitCode));
|
|
491
|
+
} catch {
|
|
492
|
+
// the log is a help, never a verdict
|
|
493
|
+
}
|
|
494
|
+
if (r.timedOut === true) return { problem: `restore: '${command}' still running after ${RESTORE_TIMEOUT_SECONDS} s` };
|
|
495
|
+
if (r.exitCode !== 0) return { problem: `restore: '${command}' exited ${r.exitCode}${shownPath(log)}` };
|
|
496
|
+
run.lines.push(`restored once: ${command}`);
|
|
497
|
+
return { restored: true };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
type SuiteResult = { problem: string } | { ok: true; whole: boolean };
|
|
501
|
+
|
|
502
|
+
async function oneSuite(run: Run, label: string, command: string, log: string | null) {
|
|
503
|
+
return runSuite(
|
|
504
|
+
{ jobs: run.deps.jobs, shell: run.deps.shell, files: run.deps.files },
|
|
505
|
+
{ label, command, log, limitSeconds: SUITE_LIMIT_SECONDS, sliceSeconds: SLICE_SECONDS },
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** The affected tests: `commands.test_project` once per distinct Project cell of the steps this run ran (of every
|
|
510
|
+
* step when it ran none), then once per test project the graph adds, their logs written together to
|
|
511
|
+
* `F<n>-test-affected.txt`. Null when the sheet's cannot be named; a graph project that cannot be is left out, and named. */
|
|
512
|
+
function affectedCommands(
|
|
513
|
+
run: Run, graph: readonly string[] = [],
|
|
514
|
+
): { commands: string[]; fromGraph: string[]; leftOut: string[] } | null {
|
|
515
|
+
if (!run.pack.commands.testProject?.trim()) return null;
|
|
516
|
+
const steps = run.ran.length > 0 ? run.ran : run.sheet.steps.filter((s) => s.tdd !== null);
|
|
517
|
+
const projects = [...new Set(steps.flatMap((s) => s.tests.map((t) => t.project.trim())).filter((p) => p !== ""))];
|
|
518
|
+
const commands: string[] = [];
|
|
519
|
+
for (const project of projects) {
|
|
520
|
+
const c = projectCommandFor(run.pack.commands, project);
|
|
521
|
+
if (!c.ok) return null;
|
|
522
|
+
if (!commands.includes(c.command)) commands.push(c.command);
|
|
523
|
+
}
|
|
524
|
+
if (commands.length === 0) return null;
|
|
525
|
+
const fromGraph: string[] = [];
|
|
526
|
+
const leftOut: string[] = [];
|
|
527
|
+
for (const project of graph) {
|
|
528
|
+
const c = projectCommandFor(run.pack.commands, project.trim());
|
|
529
|
+
if (!c.ok) leftOut.push(`${project.trim()} (${c.reason})`);
|
|
530
|
+
else if (!commands.includes(c.command)) { commands.push(c.command); fromGraph.push(project.trim()); }
|
|
531
|
+
}
|
|
532
|
+
return { commands, fromGraph, leftOut };
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** The batch's touched files refreshed in the code index (incremental_reindex), so that the graph the affected tests,
|
|
536
|
+
* the next batch and the audit read holds the tree as it is now. True when it was; never blocks: a line says what
|
|
537
|
+
* happened, none when no index is wired or nothing was touched. */
|
|
538
|
+
async function refreshIndex(run: Run): Promise<boolean> {
|
|
539
|
+
const index = run.deps.costIndex;
|
|
540
|
+
if (index === undefined || run.touched.size === 0) return false;
|
|
541
|
+
const files = [...run.touched].sort().map((p) => `${WORKSPACE}/${p}`);
|
|
542
|
+
try {
|
|
543
|
+
const roots = (await index.roots()).map((r) => (r.length > 1 ? r.replace(/\/+$/, "") : r));
|
|
544
|
+
if (!roots.includes(WORKSPACE)) {
|
|
545
|
+
run.lines.push(`index: not refreshed — ${WORKSPACE} is not indexed`);
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
const errors = await index.refresh(WORKSPACE, files);
|
|
549
|
+
if (errors.length > 0) {
|
|
550
|
+
run.lines.push(`index: not refreshed — incremental_reindex: ${reasonOf(errors[0])}`);
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
} catch (e) {
|
|
554
|
+
run.lines.push(`index: not refreshed — ${reasonOf(e)}`);
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
run.lines.push(`index: ${files.length} file${files.length === 1 ? "" : "s"} of ${run.sheet.batch} refreshed`);
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** What the graph says the batch's touched files reach (affected_tests), on a refreshed index; null when it cannot be
|
|
562
|
+
* asked or fails, said in a line: the sheet's Project cells then decide alone. */
|
|
563
|
+
async function graphAffected(run: Run): Promise<AffectedTests | null> {
|
|
564
|
+
const index = run.deps.costIndex;
|
|
565
|
+
if (index?.affected === undefined) return null;
|
|
566
|
+
try {
|
|
567
|
+
// Relative to the indexed root: affected_tests looks each file up as `<root>/<file>`, an absolute path never resolves.
|
|
568
|
+
return await index.affected([...run.touched].sort());
|
|
569
|
+
} catch (e) {
|
|
570
|
+
run.lines.push(`affected tests: the graph was not read — ${reasonOf(e)}; the sheet's projects alone`);
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/** The build, then the whole suite (the first time the batch goes green) or its affected projects, as jobs. */
|
|
576
|
+
async function suites(run: Run, suiteGreen: boolean): Promise<SuiteResult> {
|
|
577
|
+
const guard = shellRuleGuard(stepRules("dev-implement"));
|
|
578
|
+
const batch = run.sheet.batch;
|
|
579
|
+
const affectedLog = `${run.logFolder}/${batch}-test-affected.txt`;
|
|
580
|
+
|
|
581
|
+
// The tree changed whatever the build says: the index is refreshed first, so a red build leaves no stale graph.
|
|
582
|
+
const indexed = await refreshIndex(run);
|
|
583
|
+
const build = run.pack.commands.build?.trim();
|
|
584
|
+
if (!build) run.lines.push("build: not run — the pack has no commands.build");
|
|
585
|
+
else {
|
|
586
|
+
const refusal = guard(build);
|
|
587
|
+
if (refusal !== null) return { problem: `build: ${refusal}` };
|
|
588
|
+
const outcome = await oneSuite(run, "build", build, `${run.logFolder}/${batch}-build.txt`);
|
|
589
|
+
if (outcome.status === "not-run") return { problem: outcome.reason };
|
|
590
|
+
if (outcome.status === "running") return { problem: `build still running after ${outcome.seconds} s${shownPath(outcome.log)}` };
|
|
591
|
+
if (outcome.status === "failed") return { problem: `build: '${build}' exited ${outcome.exit}${shownPath(outcome.log)}\n${outcome.tail}` };
|
|
592
|
+
run.lines.push(`build ✓ — ${build}${outcome.how === "blocking" ? " (run blocking)" : ""}${shownPath(outcome.log)}`);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const graph = suiteGreen && indexed ? await graphAffected(run) : null;
|
|
596
|
+
const affected = suiteGreen && graph?.all !== true ? affectedCommands(run, graph?.projects ?? []) : null;
|
|
597
|
+
if (affected !== null && affected.leftOut.length > 0) {
|
|
598
|
+
run.lines.push(`affected tests: the graph's projects left out, no command can be named for them — ${affected.leftOut.join("; ")}`);
|
|
599
|
+
}
|
|
600
|
+
if (affected !== null) {
|
|
601
|
+
const texts: string[] = [];
|
|
602
|
+
let exit = 0;
|
|
603
|
+
for (const command of affected.commands) {
|
|
604
|
+
const refusal = guard(command);
|
|
605
|
+
if (refusal !== null) return { problem: `affected tests: ${refusal}` };
|
|
606
|
+
const outcome = await oneSuite(run, "affected tests", command, null);
|
|
607
|
+
if (outcome.status === "not-run") return { problem: outcome.reason };
|
|
608
|
+
texts.push(outcome.text.trimEnd());
|
|
609
|
+
if (outcome.status === "running") {
|
|
610
|
+
await writeLogQuietly(run, affectedLog, `${texts.join("\n")}\n`);
|
|
611
|
+
return { problem: `affected tests still running after ${outcome.seconds} s${shownPath(affectedLog)}` };
|
|
612
|
+
}
|
|
613
|
+
if (outcome.status === "failed") {
|
|
614
|
+
if (exit === 0) exit = outcome.exit;
|
|
615
|
+
await writeLogQuietly(run, affectedLog, `${texts.join("\n")}\nexit=${exit}\n`);
|
|
616
|
+
return { problem: `affected tests: '${command}' exited ${outcome.exit}${shownPath(affectedLog)}\n${outcome.tail}` };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
await writeLogQuietly(run, affectedLog, `${texts.join("\n")}\nexit=${exit}\n`);
|
|
620
|
+
const byGraph = graph === null ? ""
|
|
621
|
+
: `; the graph added ${affected.fromGraph.length === 0 ? "no project" : affected.fromGraph.join(", ")}${graph.classes.length === 0 ? "" : ` (${graph.classes.length} test class${graph.classes.length === 1 ? "" : "es"} reached)`}`;
|
|
622
|
+
run.lines.push(`affected tests ✓ — ${affected.commands.join("; ")} (the whole suite went green once for ${batch}${byGraph})${shownPath(affectedLog)}`);
|
|
623
|
+
return { ok: true, whole: false };
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const test = run.pack.commands.test?.trim();
|
|
627
|
+
if (!test) {
|
|
628
|
+
run.lines.push("test: not run — the pack has no commands.test");
|
|
629
|
+
return { ok: true, whole: false };
|
|
630
|
+
}
|
|
631
|
+
const refusal = guard(test);
|
|
632
|
+
if (refusal !== null) return { problem: `test: ${refusal}` };
|
|
633
|
+
// A whole-suite run empties the affected log: the audit then reads this one.
|
|
634
|
+
await writeLogQuietly(run, affectedLog, "");
|
|
635
|
+
const outcome = await oneSuite(run, "test", test, `${run.logFolder}/${batch}-test.txt`);
|
|
636
|
+
if (outcome.status === "not-run") return { problem: outcome.reason };
|
|
637
|
+
if (outcome.status === "running") return { problem: `test still running after ${outcome.seconds} s${shownPath(outcome.log)}` };
|
|
638
|
+
if (outcome.status === "failed") return { problem: `test: '${test}' exited ${outcome.exit}${shownPath(outcome.log)}\n${outcome.tail}` };
|
|
639
|
+
const again = !suiteGreen ? ""
|
|
640
|
+
: graph?.all === true && graph.unresolved.length > 0
|
|
641
|
+
? ` (the whole suite again: the graph could not place ${cutList(graph.unresolved)})`
|
|
642
|
+
: graph?.all === true ? " (the whole suite again: the graph reaches every test from these changes)"
|
|
643
|
+
: " (the whole suite again: the pack has no commands.test_project)";
|
|
644
|
+
run.lines.push(`test ✓ — ${test}${outcome.how === "blocking" ? " (run blocking)" : ""}${again}${shownPath(outcome.log)}`);
|
|
645
|
+
return { ok: true, whole: true };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** At most three paths, then how many more. */
|
|
649
|
+
function cutList(paths: readonly string[]): string {
|
|
650
|
+
const shown = paths.slice(0, 3).join(", ");
|
|
651
|
+
return paths.length > 3 ? `${shown} and ${paths.length - 3} more` : shown;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
async function writeLogQuietly(run: Run, path: string, text: string): Promise<void> {
|
|
655
|
+
try {
|
|
656
|
+
await run.deps.files.write(path, text);
|
|
657
|
+
} catch {
|
|
658
|
+
// the log is a help, never a verdict
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** The verdicts of the batch's verdict file: its mark, the last verdict, and the GAPS rounds since the last VALID. */
|
|
663
|
+
async function verdictState(files: Pick<Files, "read">, path: string): Promise<{ mark: string; last: "VALID" | "GAPS" | null; gapsRounds: number }> {
|
|
664
|
+
let text: string | null;
|
|
665
|
+
try {
|
|
666
|
+
text = await files.read(path);
|
|
667
|
+
} catch {
|
|
668
|
+
text = null;
|
|
669
|
+
}
|
|
670
|
+
if (text === null) return { mark: verdictMarkOf(null), last: null, gapsRounds: 0 };
|
|
671
|
+
return { mark: verdictMarkOf(text), last: lastVerdict(parseVerdictFile(text))?.verdict ?? null, gapsRounds: gapsRoundsOf(text) };
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export async function runDevImplement(input: DevImplementInputs, deps: DevImplementDeps): Promise<string> {
|
|
675
|
+
const batch = String(input.batch ?? "").trim();
|
|
676
|
+
if (!BATCH.test(batch)) return blocked([], `the batch is F<n>, e.g. /dev-batches <code> F1: got '${batch}'`);
|
|
677
|
+
const plan = typeof input.plan === "string" && input.plan.trim() !== "" ? input.plan.trim() : null;
|
|
678
|
+
const inputContext = prContextOf(input);
|
|
679
|
+
const mode = typeof input.permissionMode === "string" ? input.permissionMode.trim() : "";
|
|
680
|
+
if (mode !== "" && policyFor(mode).readOnly) {
|
|
681
|
+
return blocked([], `the session mode ${mode} is read-only: /dev-batches writes files and commits (/mode default, then run it again)`);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const context = await loadDevContext({ files: deps.files, shell: deps.shell, config: deps.config });
|
|
685
|
+
const lines = context.warnings.slice(0, 5).map((w) => `⚠ ${w}`);
|
|
686
|
+
if (context.pack === null) return blocked(lines, "no repository pack (.orkeon/repo.yaml): its layout and commands drive the steps");
|
|
687
|
+
if (context.work.vfsPath === null) return blocked(lines, `the work folder ${context.work.folder} is outside the mounts`);
|
|
688
|
+
const pack = context.pack.pack;
|
|
689
|
+
|
|
690
|
+
const located = await locateSheet(deps.files, context.work.folder, batch, plan);
|
|
691
|
+
if (typeof located === "string") return blocked(lines, located);
|
|
692
|
+
const sheetPath = `${WORKSPACE}/${located.dir}/${located.name}`;
|
|
693
|
+
const record = await readTouchedRecord(deps.files, located.code, batch);
|
|
694
|
+
|
|
695
|
+
if (input.close === true) {
|
|
696
|
+
// The chained close carries the session's context read again before its launch (Orkeon #220); a close that
|
|
697
|
+
// names none (a typed --close, a hop whose read failed) takes the one the run saved in the batch record.
|
|
698
|
+
const pr = inputContext ?? record.pr;
|
|
699
|
+
const closeMode = pr?.permissionMode.trim() ?? "";
|
|
700
|
+
if (closeMode !== "" && policyFor(closeMode).readOnly) {
|
|
701
|
+
return blocked(lines, `the session mode ${closeMode} (read at the launch) is read-only: the close commits (/mode default, then ${closeCommand(located.code, batch)})`);
|
|
702
|
+
}
|
|
703
|
+
const opener = pr !== null && pr.githubTool ? deps.openerFor?.(pr) : undefined;
|
|
704
|
+
// A batch of a /dev-batches run in progress is committed, never pushed, even when its close is typed (after a
|
|
705
|
+
// GAPS stop, a refused hop): the run's own close pushes the plan's branch once.
|
|
706
|
+
const inRun = input.push !== false && batchesRunCode(await deps.files.read(BATCHES_ACTIVE_RECORD).catch(() => "")) === located.code;
|
|
707
|
+
if (inRun) lines.push(`not pushed: /dev-batches ${located.code} is in progress, its close pushes the plan's branch once`);
|
|
708
|
+
return answer([...lines, ...await closeDevBatch({ ...deps, opener }, {
|
|
709
|
+
pack, work: context.work, located, batch, touched: record.touched, verdictMark: record.verdictMark,
|
|
710
|
+
openPr: input.pr === true, push: input.push !== false && !inRun, today: isoDay(deps.clock()),
|
|
711
|
+
...(pr === null ? {} : { rules: parseSessionRules(pr.permissionRules) }),
|
|
712
|
+
})]);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (!hasTestLayout(pack.layout)) {
|
|
716
|
+
return blocked(lines, "the pack gives neither layout.tests nor layout.test_files: code cannot tell a test file from a production one");
|
|
717
|
+
}
|
|
718
|
+
let sheetText: string;
|
|
719
|
+
try {
|
|
720
|
+
sheetText = await deps.files.read(sheetPath);
|
|
721
|
+
} catch (e) {
|
|
722
|
+
return blocked(lines, `${located.dir}/${located.name} cannot be read: ${reasonOf(e)}`);
|
|
723
|
+
}
|
|
724
|
+
const verdictPath = `${WORKSPACE}/${located.dir}/${located.prefix}-VERIFY-${batch}.md`;
|
|
725
|
+
const verdicts = await verdictState(deps.files, verdictPath);
|
|
726
|
+
|
|
727
|
+
const finding = typeof input.correction === "string" ? input.correction.trim() : "";
|
|
728
|
+
if (finding !== "") {
|
|
729
|
+
const edit = addCorrection(sheetText, finding);
|
|
730
|
+
if (!edit.ok) return blocked(lines, `correction: ${edit.reason}`);
|
|
731
|
+
if (edit.appended) {
|
|
732
|
+
try {
|
|
733
|
+
await deps.files.write(sheetPath, edit.text);
|
|
734
|
+
} catch (e) {
|
|
735
|
+
return blocked(lines, `correction: the sheet could not be written: ${reasonOf(e)}`);
|
|
736
|
+
}
|
|
737
|
+
lines.push(`correction appended to ${located.name} as step ${edit.step} — ${edit.title}`);
|
|
738
|
+
} else {
|
|
739
|
+
lines.push(`correction still open as step ${edit.step} — ${edit.title}: run again, nothing appended`);
|
|
740
|
+
}
|
|
741
|
+
sheetText = edit.text;
|
|
742
|
+
if (verdicts.gapsRounds >= GAPS_ROUNDS_WARNED) {
|
|
743
|
+
lines.push(`⚠ ${verdicts.gapsRounds} audit rounds in GAPS: the third still GAPS goes to a human`);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const sheet = parseImplementSheet(sheetText);
|
|
747
|
+
if (sheet.problems.length > 0) return blocked(lines, `the sheet is malformed: ${sheet.problems.join("; ")}`);
|
|
748
|
+
|
|
749
|
+
const logFolder = `${context.work.vfsPath}/${located.code}/logs`;
|
|
750
|
+
const written = new Set<string>();
|
|
751
|
+
const wrote = (path: string): void => { if (path.trim() !== "") written.add(workspacePath(path)); };
|
|
752
|
+
const pr = inputContext ?? record.pr;
|
|
753
|
+
const runLines = [...lines, `dev-implement ${batch} (${located.code}): ${located.dir}/${located.name}`];
|
|
754
|
+
const open = openSteps(sheet);
|
|
755
|
+
let restored = false;
|
|
756
|
+
if (open.length > 0) {
|
|
757
|
+
const r = await restore({ deps, pack, logFolder, lines: runLines }, batch);
|
|
758
|
+
if ("problem" in r) return blocked(runLines, r.problem);
|
|
759
|
+
restored = r.restored;
|
|
760
|
+
}
|
|
761
|
+
// Built after the restore, which tells run_build the tree was restored already.
|
|
762
|
+
const tools = createWrappedTools(
|
|
763
|
+
{ shell: deps.shell, files: deps.files },
|
|
764
|
+
{ commands: pack.commands, rules: stepRules("dev-implement"), logFolder, batch, ...(restored ? { restored: true } : {}) },
|
|
765
|
+
);
|
|
766
|
+
const run: Run = {
|
|
767
|
+
deps, pack, isTest: (p) => isTestPath(p, pack.layout), located, sheetPath, sheetText, sheet, tools, wrote,
|
|
768
|
+
ownFolders: [context.work.folder, located.dir], planFolder: located.dir, planLogs: `${context.work.folder}/${located.code}/logs`,
|
|
769
|
+
logFolder, written, verdictMark: verdicts.mark, touched: new Set(record.touched), ran: [], lines: runLines,
|
|
770
|
+
correction: NOTHING_RECALLED, recalled: [],
|
|
771
|
+
stale: { block: staleBlock(Array.isArray(input.stale) ? input.stale : []), ids: [] },
|
|
772
|
+
};
|
|
773
|
+
// T5: a correction run carries the mistakes recalled from its finding to both roles.
|
|
774
|
+
if (finding !== "" && open.length > 0) {
|
|
775
|
+
run.correction = await (deps.precedents ?? noPrecedents)("T5", recallQuery([finding]));
|
|
776
|
+
run.recalled.push(run.correction);
|
|
777
|
+
}
|
|
778
|
+
const save = (suiteGreen: boolean): Promise<void> =>
|
|
779
|
+
recordTouched(deps.files, located.code, batch, [...run.touched], run.verdictMark, { suiteGreen, pr });
|
|
780
|
+
const release = deps.toolSlot?.bind(tools) ?? (() => {});
|
|
781
|
+
try {
|
|
782
|
+
const cycles = cyclesOf(open);
|
|
783
|
+
if (cycles.length > 0) run.lines.push(cyclesLine(cycles));
|
|
784
|
+
for (const cycle of cycles) {
|
|
785
|
+
const problem = await runCycle(run, cycle);
|
|
786
|
+
await save(record.suiteGreen);
|
|
787
|
+
if (problem !== null) return blocked(run.lines, problem);
|
|
788
|
+
}
|
|
789
|
+
const result = await suites(run, record.suiteGreen);
|
|
790
|
+
if ("problem" in result) {
|
|
791
|
+
await save(record.suiteGreen);
|
|
792
|
+
return blocked(run.lines, result.problem);
|
|
793
|
+
}
|
|
794
|
+
await save(record.suiteGreen || result.whole);
|
|
795
|
+
} finally {
|
|
796
|
+
release();
|
|
797
|
+
}
|
|
798
|
+
const recalledLine = precedentsLine(run.recalled);
|
|
799
|
+
if (recalledLine !== "") run.lines.push(recalledLine);
|
|
800
|
+
const planArg = plan ?? located.code;
|
|
801
|
+
const auditMode = verdicts.last === "GAPS" ? "resume" : "fast";
|
|
802
|
+
run.lines.push(`→ Batch ${batch}: every step ticked, the build and the tests green. The audit follows: ${auditCommand(planArg, batch, auditMode)}`);
|
|
803
|
+
return answer(run.lines, {
|
|
804
|
+
crew: "dev-verify",
|
|
805
|
+
input: {
|
|
806
|
+
batch, plan: planArg, mode: auditMode,
|
|
807
|
+
...(input.hooks === undefined ? {} : { hooks: input.hooks }), ...(input.effort === undefined || input.effort === null ? {} : { effort: input.effort }),
|
|
808
|
+
...(input.memoryRecall === false ? { memoryRecall: false as const } : {}),
|
|
809
|
+
},
|
|
810
|
+
});
|
|
811
|
+
}
|