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,27 @@
|
|
|
1
|
+
// One act of a role of the batch: its brief, its own tools (a subset of the crew agent's), its
|
|
2
|
+
// mode and the Llm built with its own callbacks (the role's deny rules). A failure of the act is
|
|
3
|
+
// a result, never thrown: the step stops on it with its reason.
|
|
4
|
+
import type { Llm } from "../../../shared/application/ports.ts";
|
|
5
|
+
import type { RoleSpec } from "../domain/roles.ts";
|
|
6
|
+
|
|
7
|
+
export type RoleAnswer = { ok: true; text: string } | { ok: false; reason: string };
|
|
8
|
+
|
|
9
|
+
export async function runRole(llm: Pick<Llm, "act">, role: RoleSpec, prompt: string): Promise<RoleAnswer> {
|
|
10
|
+
try {
|
|
11
|
+
const text = await llm.act(prompt, {
|
|
12
|
+
system: role.system, maxIterations: role.maxIterations, tools: role.tools, permissionMode: "acceptEdits",
|
|
13
|
+
});
|
|
14
|
+
return { ok: true, text };
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return { ok: false, reason: `${role.name}: ${String((e as Error)?.message ?? e).split("\n")[0]}` };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One short question, no tool: the line a role left out of its answer. */
|
|
21
|
+
export async function askLine(llm: Pick<Llm, "act">, role: RoleSpec, question: string): Promise<RoleAnswer> {
|
|
22
|
+
try {
|
|
23
|
+
return { ok: true, text: await llm.act(question, { system: role.system, maxIterations: 1, tools: [], permissionMode: "acceptEdits" }) };
|
|
24
|
+
} catch (e) {
|
|
25
|
+
return { ok: false, reason: `${role.name}: ${String((e as Error)?.message ?? e).split("\n")[0]}` };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// The build or the whole suite at the end of a batch, run as a shell job so that no shell timeout
|
|
2
|
+
// cuts it: started, looked at after 1 s, then a wait twice as long each time up to SLICE_SECONDS (a
|
|
3
|
+
// suite of a second is seen ended in a second or two, not a slice later), up to the suite's limit,
|
|
4
|
+
// then the tail of its log (500 lines) written to the batch's log and 15 lines passed on. Where code cannot wait (no node,
|
|
5
|
+
// interpreters off), the job cannot start or its first look fails, the suite runs blocking with the same
|
|
6
|
+
// limit. A suite past its limit gives no verdict: it is left to the end of the run, which stops it.
|
|
7
|
+
//
|
|
8
|
+
// The log is what dev-verify's capture reads (`<work>/<code>/logs/F<n>-build.txt`, `F<n>-test.txt`,
|
|
9
|
+
// `F<n>-test-affected.txt`): a `#` header, the output, then a last line `exit=<n>`, the harness's shape.
|
|
10
|
+
import type { Files, Shell, ShellJobs } from "../../../shared/application/ports.ts";
|
|
11
|
+
import {
|
|
12
|
+
CODE_CANNOT_WAIT, jobCannotBeRead, jobCouldNotBeRead, jobDidNotStart, jobLogHeader, jobStillRunning, lostWaitOnJob, noVerdict,
|
|
13
|
+
runBlocking, stillRunningNoVerdict, tailNotRead,
|
|
14
|
+
} from "./messages.ts";
|
|
15
|
+
|
|
16
|
+
export const TAIL_LINES = 500;
|
|
17
|
+
export const SHOWN_LINES = 15;
|
|
18
|
+
|
|
19
|
+
export interface SuiteRequest {
|
|
20
|
+
label: string;
|
|
21
|
+
command: string;
|
|
22
|
+
/** Virtual path of the log this run writes; null: the caller writes the text itself. */
|
|
23
|
+
log: string | null;
|
|
24
|
+
limitSeconds: number;
|
|
25
|
+
sliceSeconds: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type SuiteOutcome =
|
|
29
|
+
| { status: "passed" | "failed"; exit: number; tail: string; log: string | null; how: "job" | "blocking"; text: string }
|
|
30
|
+
| { status: "running"; seconds: number; log: string | null; text: string }
|
|
31
|
+
| { status: "not-run"; reason: string };
|
|
32
|
+
|
|
33
|
+
const reasonOf = (e: unknown): string => String((e as Error)?.message ?? e).split("\n")[0];
|
|
34
|
+
const lastLines = (text: string, n: number): string => text.trimEnd().split("\n").slice(-n).join("\n");
|
|
35
|
+
|
|
36
|
+
/** The last line of a log that holds no verdict (past the limit, or the job lost): the timeout's own code, so that
|
|
37
|
+
* no reader takes a log without an end for a green one. */
|
|
38
|
+
export const NO_VERDICT_EXIT = 124;
|
|
39
|
+
|
|
40
|
+
/** The log's text: the command and the header lines as comments, the output, then `exit=<n>` when it ended. */
|
|
41
|
+
export function logText(command: string, header: readonly string[], output: string, exit: number | null): string {
|
|
42
|
+
const body = output.trimEnd();
|
|
43
|
+
return [`# $ ${command}`, ...header.map((h) => `# ${h}`), ...(body === "" ? [] : [body]), ...(exit === null ? [] : [`exit=${exit}`])].join("\n") + "\n";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function writeLog(files: Pick<Files, "write">, path: string | null, text: string): Promise<string | null> {
|
|
47
|
+
if (path === null) return null;
|
|
48
|
+
try {
|
|
49
|
+
await files.write(path, text);
|
|
50
|
+
return path;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A job lost after it started: no verdict, and a log saying so, so that an earlier log is never read for this run. */
|
|
57
|
+
async function lost(deps: { files: Pick<Files, "write"> }, req: SuiteRequest, why: string): Promise<SuiteOutcome> {
|
|
58
|
+
await writeLog(deps.files, req.log, logText(req.command, [noVerdict(why, NO_VERDICT_EXIT)], "", NO_VERDICT_EXIT));
|
|
59
|
+
return { status: "not-run", reason: `${req.label}: ${why}` };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function blocking(deps: { shell: Pick<Shell, "run">; files: Pick<Files, "write"> }, req: SuiteRequest, why: string): Promise<SuiteOutcome> {
|
|
63
|
+
let r;
|
|
64
|
+
try {
|
|
65
|
+
r = await deps.shell.run(req.command, { timeoutSeconds: req.limitSeconds });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return { status: "not-run", reason: `${req.label}: ${reasonOf(e)}` };
|
|
68
|
+
}
|
|
69
|
+
const output = [r.stdout.trimEnd(), r.stderr.trimEnd()].filter((t) => t !== "").join("\n");
|
|
70
|
+
const header = [runBlocking(why)];
|
|
71
|
+
if (r.timedOut === true) {
|
|
72
|
+
const text = logText(req.command, [...header, stillRunningNoVerdict(req.limitSeconds, NO_VERDICT_EXIT)], output, NO_VERDICT_EXIT);
|
|
73
|
+
return { status: "running", seconds: req.limitSeconds, log: await writeLog(deps.files, req.log, text), text };
|
|
74
|
+
}
|
|
75
|
+
const text = logText(req.command, header, output, r.exitCode);
|
|
76
|
+
const log = await writeLog(deps.files, req.log, text);
|
|
77
|
+
return { status: r.exitCode === 0 ? "passed" : "failed", exit: r.exitCode, tail: lastLines(output, SHOWN_LINES), log, how: "blocking", text };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function runSuite(
|
|
81
|
+
deps: { jobs: ShellJobs; shell: Pick<Shell, "run">; files: Pick<Files, "write"> }, req: SuiteRequest,
|
|
82
|
+
): Promise<SuiteOutcome> {
|
|
83
|
+
if (!(await deps.jobs.wait(1))) return blocking(deps, req, CODE_CANNOT_WAIT);
|
|
84
|
+
let job;
|
|
85
|
+
try {
|
|
86
|
+
job = await deps.jobs.start(req.command);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return blocking(deps, req, jobDidNotStart(reasonOf(e)));
|
|
89
|
+
}
|
|
90
|
+
let seconds = 0;
|
|
91
|
+
for (let looks = 0; ; looks++) {
|
|
92
|
+
let status;
|
|
93
|
+
try {
|
|
94
|
+
status = await deps.jobs.status(job.id);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
// A job never seen running may not run at all: once, the suite runs blocking (the job, if it runs, dies
|
|
97
|
+
// with the run). A job seen before and lost now gives no verdict.
|
|
98
|
+
if (looks === 0) return blocking(deps, req, jobCouldNotBeRead(job.id, reasonOf(e)));
|
|
99
|
+
return lost(deps, req, jobCannotBeRead(job.id, reasonOf(e)));
|
|
100
|
+
}
|
|
101
|
+
if (!status.running) {
|
|
102
|
+
let tail = "";
|
|
103
|
+
try {
|
|
104
|
+
tail = await deps.jobs.tail(job.id, TAIL_LINES);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
tail = tailNotRead(reasonOf(e));
|
|
107
|
+
}
|
|
108
|
+
const text = logText(req.command, [jobLogHeader(job.id, job.log, TAIL_LINES)], tail, status.exitCode);
|
|
109
|
+
const log = await writeLog(deps.files, req.log, text);
|
|
110
|
+
return { status: status.exitCode === 0 ? "passed" : "failed", exit: status.exitCode, tail: lastLines(tail, SHOWN_LINES), log, how: "job", text };
|
|
111
|
+
}
|
|
112
|
+
if (seconds >= req.limitSeconds) {
|
|
113
|
+
const text = logText(req.command, [jobStillRunning(job.id, seconds, NO_VERDICT_EXIT, job.log)], "", NO_VERDICT_EXIT);
|
|
114
|
+
return { status: "running", seconds, log: await writeLog(deps.files, req.log, text), text };
|
|
115
|
+
}
|
|
116
|
+
const slice = Math.min(req.sliceSeconds, 2 ** looks, req.limitSeconds - seconds);
|
|
117
|
+
if (!(await deps.jobs.wait(slice))) {
|
|
118
|
+
return lost(deps, req, lostWaitOnJob(job.id));
|
|
119
|
+
}
|
|
120
|
+
seconds += slice;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// The files a batch's roles changed, as code observed them, kept beside Orkeon's own state
|
|
2
|
+
// (`.orkeon/dev/<code>/implement-F<n>.json`, outside git) so that the close commits these files
|
|
3
|
+
// and no other, whichever run of the batch made them. The record also says whether the whole suite
|
|
4
|
+
// went green once for the batch (later runs run the affected tests only), and carries the pull-request
|
|
5
|
+
// context read at the launch, which the chained close reads back: the chain keeps no state of its own.
|
|
6
|
+
import type { Files } from "../../../shared/application/ports.ts";
|
|
7
|
+
import { contentHash } from "./observe.ts";
|
|
8
|
+
import { WORKSPACE } from "../../../shared/domain/vfs.ts";
|
|
9
|
+
|
|
10
|
+
/** The mark of a verdict file's text: its hash, or "none" when there is no verdict file. */
|
|
11
|
+
export function verdictMarkOf(text: string | null): string {
|
|
12
|
+
return text === null ? "none" : contentHash(text);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function touchedPath(code: string, batch: string): string {
|
|
16
|
+
return `${WORKSPACE}/.orkeon/dev/${code}/implement-${batch}.json`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** What the close needs to open the pull request itself, as the command read it at the launch. */
|
|
20
|
+
export interface PrContext { githubTool: boolean; permissionMode: string; permissionRules: string[] }
|
|
21
|
+
|
|
22
|
+
export interface TouchedRecord {
|
|
23
|
+
touched: string[];
|
|
24
|
+
/** The whole suite went green once for this batch. */
|
|
25
|
+
suiteGreen: boolean;
|
|
26
|
+
pr: PrContext | null;
|
|
27
|
+
/** The hash of the batch's verdict file when the list was last written ("none" without one): the close
|
|
28
|
+
* wants a verdict written since, so an audit older than the last change never commits it. */
|
|
29
|
+
verdictMark: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function readTouchedRecord(files: Pick<Files, "read">, code: string, batch: string): Promise<TouchedRecord> {
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(await files.read(touchedPath(code, batch))) as {
|
|
35
|
+
touched?: unknown; verdictMark?: unknown; suiteGreen?: unknown; pr?: unknown;
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
touched: Array.isArray(parsed.touched) ? parsed.touched.filter((p): p is string => typeof p === "string") : [],
|
|
39
|
+
verdictMark: typeof parsed.verdictMark === "string" ? parsed.verdictMark : null,
|
|
40
|
+
suiteGreen: parsed.suiteGreen === true,
|
|
41
|
+
pr: prContextOf(parsed.pr),
|
|
42
|
+
};
|
|
43
|
+
} catch {
|
|
44
|
+
return { touched: [], verdictMark: null, suiteGreen: false, pr: null };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A pull-request context from a record or a crew's input; null when it names none. */
|
|
49
|
+
export function prContextOf(raw: unknown): PrContext | null {
|
|
50
|
+
if (raw === null || typeof raw !== "object") return null;
|
|
51
|
+
const r = raw as { githubTool?: unknown; permissionMode?: unknown; permissionRules?: unknown };
|
|
52
|
+
if (r.githubTool === undefined && r.permissionMode === undefined && r.permissionRules === undefined) return null;
|
|
53
|
+
return {
|
|
54
|
+
githubTool: r.githubTool === true || r.githubTool === "true",
|
|
55
|
+
permissionMode: typeof r.permissionMode === "string" ? r.permissionMode : "",
|
|
56
|
+
permissionRules: Array.isArray(r.permissionRules) ? r.permissionRules.filter((x): x is string => typeof x === "string") : [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Writes the record, the list sorted; a write that fails is said by the close, which then finds none. */
|
|
61
|
+
export async function recordTouched(
|
|
62
|
+
files: Pick<Files, "write">, code: string, batch: string, touched: readonly string[], verdictMark: string,
|
|
63
|
+
more: { suiteGreen?: boolean; pr?: PrContext | null } = {},
|
|
64
|
+
): Promise<void> {
|
|
65
|
+
const record = {
|
|
66
|
+
batch, touched: [...new Set(touched)].sort(), verdictMark,
|
|
67
|
+
...(more.suiteGreen === true ? { suiteGreen: true } : {}), ...(more.pr ? { pr: more.pr } : {}),
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
await files.write(touchedPath(code, batch), `${JSON.stringify(record, null, 2)}\n`);
|
|
71
|
+
} catch {
|
|
72
|
+
// the close says it found no list
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @orkeon-script 1.0
|
|
2
|
+
/// <reference path="../.orkeon/orkeon.d.ts" />
|
|
3
|
+
//
|
|
4
|
+
// DevImplement crew (dev-implement). Composition root: one agent holds the tools of the two
|
|
5
|
+
// writing roles of a batch step (the test author, the implementer) and the autonomous run_tests
|
|
6
|
+
// and run_build; application/run-dev-implement runs each step as two acts of it, each act with
|
|
7
|
+
// its own tools and its own callbacks (the role's deny rules over the pack's layout), observes
|
|
8
|
+
// the tree and the tests itself and ticks the sheet. The build and the whole suite then run as
|
|
9
|
+
// shell jobs. With close: true it commits the batch's files once dev-verify found it VALID.
|
|
10
|
+
//
|
|
11
|
+
// Input (globalThis.inputs): { batch: "F<n>", plan?: string | null, close?: boolean, pr?: boolean, push?: false,
|
|
12
|
+
// correction?: string (the finding of an audit's gap), steps?: number,
|
|
13
|
+
// stale?: string[] (/dev-batches' `stale:` lines: they end the RED and GREEN prompts),
|
|
14
|
+
// hooks?: the /hooks registry, effort?: "low" | "medium" | "high" | "xhigh" | "max" | null,
|
|
15
|
+
// memoryRecall?: false (a session rule denies it: the agent gets none),
|
|
16
|
+
// permissionMode?, permissionRules?, githubTool? (the close's pull request;
|
|
17
|
+
// the run saves them in the batch record, the chained close reads them back) }
|
|
18
|
+
// Answer: JSON { lines: string[], next?: { crew: "dev-verify", input } }, read by the command's completed.
|
|
19
|
+
//
|
|
20
|
+
// Budget (G-29): sized to the steps of the run, implement-budget.ts; the close has its own.
|
|
21
|
+
|
|
22
|
+
import { CrewBuilder, publishCrew, inputs, ToolBuilder } from "../../shared/infrastructure/globals.ts";
|
|
23
|
+
import { orkeonAgent } from "../../shared/infrastructure/orkeon/wiring.ts";
|
|
24
|
+
import { runBuildTool, runTestsTool, scriptToolSlot } from "../../shared/infrastructure/orkeon/script-tools.ts";
|
|
25
|
+
import type { WrappedTools } from "../../shared/application/dev/wrapped-tools.ts";
|
|
26
|
+
import { memoryRecallOn, memoryRecallTools } from "../../shared/infrastructure/orkeon/memory-tools.ts";
|
|
27
|
+
import { agentTools, implementDeps } from "../../shared/infrastructure/orkeon/dev-deps.ts";
|
|
28
|
+
import { providerEffort } from "../../shared/domain/agent-policy/behavior-flags.ts";
|
|
29
|
+
import { implementBudget } from "./domain/implement-budget.ts";
|
|
30
|
+
import { CREW_TOOLS } from "./domain/roles.ts";
|
|
31
|
+
import { implementInputs, runDevImplement } from "./application/run-dev-implement.ts";
|
|
32
|
+
import { DEV_IMPLEMENT_GOAL } from "./application/prompts.ts";
|
|
33
|
+
|
|
34
|
+
// run_tests and run_build: built here, bound by the body to the run's wrapped tools (its pack, its rules, its logs).
|
|
35
|
+
const toolSlot = scriptToolSlot<WrappedTools>();
|
|
36
|
+
// memory_recall's ports: over the tools of the body that runs (dev-deps.ts), never the global's.
|
|
37
|
+
const bodyTools = agentTools();
|
|
38
|
+
const flag = (v: unknown): boolean => v === true || v === "true";
|
|
39
|
+
const effort = providerEffort(inputs().effort);
|
|
40
|
+
// memory_recall is attached unless a session rule denies every call of it (the gate would refuse each one).
|
|
41
|
+
const memoryOn = memoryRecallOn(inputs());
|
|
42
|
+
|
|
43
|
+
const builder = orkeonAgent()
|
|
44
|
+
.name("dev-implement")
|
|
45
|
+
.role("Batch implementer")
|
|
46
|
+
.goal(DEV_IMPLEMENT_GOAL)
|
|
47
|
+
.tools([...CREW_TOOLS])
|
|
48
|
+
.withAutonomousTool(runTestsTool(ToolBuilder, toolSlot))
|
|
49
|
+
.withAutonomousTool(runBuildTool(ToolBuilder, toolSlot))
|
|
50
|
+
.withAutonomousTools(memoryRecallTools(ToolBuilder, bodyTools.memoryPorts(), memoryOn))
|
|
51
|
+
.maxIterations(60)
|
|
52
|
+
.body(async (_input: any, ctx: any) => {
|
|
53
|
+
const args = inputs();
|
|
54
|
+
bodyTools.bind(ctx.tools);
|
|
55
|
+
// implementInputs keeps a `push: false` (/dev-batches' closes: the plan's branch is pushed once, at its end).
|
|
56
|
+
// The ports, each role's Llm under its callbacks and the close's opener: dev-deps.ts, over this body's tools.
|
|
57
|
+
return await runDevImplement(implementInputs(args), implementDeps(ctx, { hooks: args.hooks, effort, memoryOn, toolSlot }));
|
|
58
|
+
});
|
|
59
|
+
const implementer = (effort === undefined ? builder : builder.effort(effort)).build();
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
publishCrew(
|
|
63
|
+
CrewBuilder()
|
|
64
|
+
.name("dev-implement")
|
|
65
|
+
.process("sequential")
|
|
66
|
+
.budget(implementBudget({ steps: inputs().steps, close: flag(inputs().close) }))
|
|
67
|
+
.withAgent(implementer)
|
|
68
|
+
.build(),
|
|
69
|
+
);
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// The two briefs of a step, made by code from the sheet and the pack (never by a model): the RED
|
|
2
|
+
// contract the test author works from and the GREEN contract the implementer works from. Each
|
|
3
|
+
// names the batch, the ids, the behaviour, the files, the narrow test command code runs after the
|
|
4
|
+
// act, and the reading and editing rules: by node. A contract never asks to read a file whole. Pure.
|
|
5
|
+
import { carry } from "../../../shared/domain/dev/carried-text.ts";
|
|
6
|
+
import type { CarriedText } from "../../../shared/domain/dev/carried-text.ts";
|
|
7
|
+
import type { RepoPackCommands, RepoPackLayout } from "../../../shared/domain/dev/repo-pack.ts";
|
|
8
|
+
import { PLACEHOLDER, plainWords, valueProblem } from "../../../shared/domain/dev/test-commands.ts";
|
|
9
|
+
import { BOUNDED_READ_RULE, NODE_EDIT_RULE, NODE_READ_RULE } from "../../../shared/domain/dev/reading-rule.ts";
|
|
10
|
+
import type { AnchorRef, ImplementSheet, ImplementStep } from "./step-section.ts";
|
|
11
|
+
import { CORRECTION_LABEL as CORRECTION, STALE_HEADING } from "./markers.ts";
|
|
12
|
+
import { PACK_HAS_NO_CLASS_OR_PROJECT_TEST, PACK_HAS_NO_TEST_PROJECT, stepNamesNoTestFile } from "./messages.ts";
|
|
13
|
+
import { SHELL_OPERATOR_OUTSIDE_QUOTES } from "../../../shared/domain/dev/messages.ts";
|
|
14
|
+
import {
|
|
15
|
+
ANY_LEVEL_RULE, ASSUMPTION_RULE, CODE_ELEMENTS_LINE, FILES_HEADING, GREEN_ANSWER, IN_THIS_BRIEF_HEADING, INTEGRATION_LEVEL_RULE,
|
|
16
|
+
LEAST_CODE_RULE, NO_ID, NONE_LISTED, NONE_NAMED, ONE_TEST_PER_ROW_RULE, PRODUCTION_HEADING, READ_ONLY_NEVER_WRITE, RED_ANSWER,
|
|
17
|
+
RED_TESTS_HEADING, RULES_HEADING, SIGNATURE_STUB_AT_MOST, STUB_EXISTING, STUB_IMPORT_RULE, STUB_OF_EARLIER_RED, STUBBED_AT_RED,
|
|
18
|
+
TEST_FILE_EXISTING, TEST_FILE_IN_BRIEF, TEST_FILE_TO_CREATE, TESTS_TO_WRITE_HEADING, THE_TEST_FILES, UNIT_LEVEL_RULE,
|
|
19
|
+
WRITE_FAILING_TESTS_FOR_FINDING, appliedRulesLine, briefTitle, correctionOfFinding, doublesLine, greenRunRule, inThisBrief,
|
|
20
|
+
lastRedRun, memberRefLine, neverWriteTestRule, oneStep, productionLine, redRunRule, sheetLine, stepLabel, stepsOfOneBehaviour,
|
|
21
|
+
stubsRule, testFileLine, testFilesOnlyRule, testRow,
|
|
22
|
+
} from "./prompts.ts";
|
|
23
|
+
|
|
24
|
+
export type TestCommand = { ok: true; command: string } | { ok: false; reason: string };
|
|
25
|
+
|
|
26
|
+
/** What the placeholder `<Class>` stands for: a C# file's base name, else the test file's path. */
|
|
27
|
+
export function classOf(testFile: string): string {
|
|
28
|
+
const name = testFile.split("/").pop() ?? testFile;
|
|
29
|
+
return name.endsWith(".cs") ? name.slice(0, -3) : testFile;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The step's test file: the first path of its Anchors test cell; null when it names none. */
|
|
33
|
+
export function testFileOf(step: ImplementStep): string | null {
|
|
34
|
+
return step.anchor?.testFiles[0]?.path ?? null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function fill(template: string, values: { project: string; klass: string }): TestCommand {
|
|
38
|
+
const holes = template.match(PLACEHOLDER) ?? [];
|
|
39
|
+
for (const hole of holes) {
|
|
40
|
+
const value = /project/i.test(hole) ? values.project : values.klass;
|
|
41
|
+
const problem = valueProblem(value);
|
|
42
|
+
if (problem !== null) return { ok: false, reason: `${hole}: ${problem}` };
|
|
43
|
+
}
|
|
44
|
+
const command = template.replace(PLACEHOLDER, (hole) => (/project/i.test(hole) ? values.project : values.klass));
|
|
45
|
+
return plainWords(command) ? { ok: true, command } : { ok: false, reason: SHELL_OPERATOR_OUTSIDE_QUOTES };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The narrow command that runs the step's tests: `test_class`, else `test_project`; never the whole suite. */
|
|
49
|
+
export function testCommandFor(commands: RepoPackCommands, step: ImplementStep): TestCommand {
|
|
50
|
+
const file = testFileOf(step);
|
|
51
|
+
if (file === null) return { ok: false, reason: stepNamesNoTestFile(step.number) };
|
|
52
|
+
const values = { project: step.tests[0]?.project ?? "", klass: classOf(file) };
|
|
53
|
+
const byClass = commands.testClass?.trim();
|
|
54
|
+
if (byClass) return fill(byClass, values);
|
|
55
|
+
const byProject = commands.testProject?.trim();
|
|
56
|
+
if (byProject) return fill(byProject, values);
|
|
57
|
+
return { ok: false, reason: PACK_HAS_NO_CLASS_OR_PROJECT_TEST };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** `test_project` for one Project cell: the affected tests of a later run. */
|
|
61
|
+
export function projectCommandFor(commands: RepoPackCommands, project: string): TestCommand {
|
|
62
|
+
const byProject = commands.testProject?.trim();
|
|
63
|
+
if (!byProject) return { ok: false, reason: PACK_HAS_NO_TEST_PROJECT };
|
|
64
|
+
return fill(byProject, { project, klass: project });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ContractInput {
|
|
68
|
+
code: string;
|
|
69
|
+
sheetPath: string;
|
|
70
|
+
sheet: ImplementSheet;
|
|
71
|
+
step: ImplementStep;
|
|
72
|
+
/** Every step of the cycle, `step` first: one GREEN turns them all green. */
|
|
73
|
+
cycle?: readonly ImplementStep[];
|
|
74
|
+
layout: RepoPackLayout;
|
|
75
|
+
testCommand: string;
|
|
76
|
+
/** Texts carried in the brief (the sheet, the test file), so the role opens no file for them. */
|
|
77
|
+
carried?: readonly CarriedText[];
|
|
78
|
+
/** The files open to RED as signature stubs: `stubsOf(step)`, and the stubs an earlier RED of the cycle wrote. */
|
|
79
|
+
stubs?: readonly string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The production files a RED step may write as signature stubs: its Anchors' `to create` production paths. */
|
|
83
|
+
export function stubsOf(step: ImplementStep): string[] {
|
|
84
|
+
return (step.anchor?.production ?? []).filter((r) => r.state === "to create").map((r) => r.path);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The existing production files a RED step may add a signature stub to: its Anchors' `existing` production paths. A
|
|
88
|
+
* declaration the new tests import and the module lacks is stubbed there, so that the import fails no other test (an
|
|
89
|
+
* ES module's missing export fails its whole test file). */
|
|
90
|
+
export function existingStubsOf(step: ImplementStep): string[] {
|
|
91
|
+
return (step.anchor?.production ?? []).filter((r) => r.state === "existing").map((r) => r.path);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** What a stub path is to the test author: a file to create, an existing one, or an earlier RED's stub. */
|
|
95
|
+
function stubKind(step: ImplementStep, path: string): string {
|
|
96
|
+
if (stubsOf(step).includes(path)) return "to create";
|
|
97
|
+
if (existingStubsOf(step).includes(path)) return STUB_EXISTING;
|
|
98
|
+
return STUB_OF_EARLIER_RED;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Where the tests live, as the pack says: its test folder, and its test file patterns. */
|
|
102
|
+
function testsWhere(layout: RepoPackLayout): string {
|
|
103
|
+
const parts = [
|
|
104
|
+
...(layout.tests?.trim() ? [`under \`${layout.tests.trim()}\``] : []),
|
|
105
|
+
...(layout.testFiles ?? []).filter((p) => p.trim() !== "").map((p) => `\`${p.trim()}\``),
|
|
106
|
+
];
|
|
107
|
+
return parts.length === 0 ? THE_TEST_FILES : parts.join(" or ");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** One anchor as a brief line; `shown` overrides the state it says (a file the sheet says to create, stubbed since). */
|
|
111
|
+
function refLine(ref: AnchorRef, shown: string = ref.state): string {
|
|
112
|
+
const at = ref.line === undefined ? ref.path : `${ref.path}:${ref.line}`;
|
|
113
|
+
if (ref.state === "member") return memberRefLine(at, ref.member);
|
|
114
|
+
return `\`${at}\` — ${shown}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** How the test author works on its test file: creates it whole when it is to create, else adds to it by node; one
|
|
118
|
+
* carried in the brief is not read again. */
|
|
119
|
+
function testFileRule(state: string, inBrief: boolean): string {
|
|
120
|
+
if (inBrief) return TEST_FILE_IN_BRIEF;
|
|
121
|
+
return state === "to create" ? TEST_FILE_TO_CREATE : TEST_FILE_EXISTING;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ids(step: ImplementStep): string {
|
|
125
|
+
return [...new Set(step.tests.flatMap((t) => t.ids))].join(", ") || NONE_NAMED;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function levelRule(step: ImplementStep): string {
|
|
129
|
+
const levels = new Set(step.tests.map((t) => t.level.toLowerCase()));
|
|
130
|
+
const lines: string[] = [];
|
|
131
|
+
if (levels.has("unit")) lines.push(UNIT_LEVEL_RULE);
|
|
132
|
+
if (levels.has("integration")) lines.push(INTEGRATION_LEVEL_RULE);
|
|
133
|
+
return lines.length === 0 ? ANY_LEVEL_RULE : lines.join("\n");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function header(input: ContractInput, role: string, steps: readonly ImplementStep[] = [input.step]): string[] {
|
|
137
|
+
const { sheet } = input;
|
|
138
|
+
const what = steps.length === 1
|
|
139
|
+
? oneStep(steps[0].number, steps[0].title)
|
|
140
|
+
: stepsOfOneBehaviour(steps.map((s) => s.number).join(", "), steps.map((s) => s.title).join("; "));
|
|
141
|
+
const allIds = [...new Set(steps.flatMap((s) => s.tests.flatMap((t) => t.ids)))].join(", ") || NONE_NAMED;
|
|
142
|
+
return [
|
|
143
|
+
briefTitle(role, input.code, sheet.batch ?? "?", what),
|
|
144
|
+
"",
|
|
145
|
+
sheetLine(input.sheetPath, steps.length === 1 ? ids(steps[0]) : allIds),
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function testsTable(step: ImplementStep): string[] {
|
|
150
|
+
return step.tests.map((t, i) => testRow(i + 1, t.name, t.level, t.project, t.ids.join(", ") || NO_ID));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The test author's brief: write the step's tests, all red, test files only. */
|
|
154
|
+
/** The most carried text a role's brief holds, in characters. */
|
|
155
|
+
export const CARRIED_CONTRACT_CHARS = 12_000;
|
|
156
|
+
|
|
157
|
+
/** The carried texts as a section of the brief (or nothing), and the files it holds whole. */
|
|
158
|
+
function carriedSection(input: ContractInput): { lines: string[]; whole: ReadonlySet<string> } {
|
|
159
|
+
const { blocks, whole } = carry(input.carried ?? [], CARRIED_CONTRACT_CHARS);
|
|
160
|
+
return { lines: blocks.length === 0 ? [] : ["", IN_THIS_BRIEF_HEADING, ...blocks], whole };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function redContract(input: ContractInput): string {
|
|
164
|
+
const { step, layout } = input;
|
|
165
|
+
const file = testFileOf(step) ?? "(none)";
|
|
166
|
+
const doubles = step.anchor?.doubles ?? "";
|
|
167
|
+
const stubs = input.stubs ?? [...stubsOf(step), ...existingStubsOf(step)];
|
|
168
|
+
const correction = CORRECTION.exec(step.title);
|
|
169
|
+
const testRef: AnchorRef = step.anchor?.testFiles[0] ?? { path: file, state: "to create" };
|
|
170
|
+
const carried = carriedSection(input);
|
|
171
|
+
const testInBrief = carried.whole.has(testRef.path);
|
|
172
|
+
// A file the sheet says is to create exists once an earlier step wrote it: the brief carries it and says so.
|
|
173
|
+
const shownRef: AnchorRef = testInBrief && testRef.state === "to create" ? { ...testRef, state: "existing" } : testRef;
|
|
174
|
+
return [
|
|
175
|
+
...header(input, "RED"),
|
|
176
|
+
"",
|
|
177
|
+
TESTS_TO_WRITE_HEADING,
|
|
178
|
+
...(correction === null
|
|
179
|
+
? testsTable(step)
|
|
180
|
+
: [correctionOfFinding(correction[1], correction[2]), WRITE_FAILING_TESTS_FOR_FINDING]),
|
|
181
|
+
...(step.note.length > 0 ? ["", ...step.note] : []),
|
|
182
|
+
"",
|
|
183
|
+
FILES_HEADING,
|
|
184
|
+
testFileLine(refLine(shownRef), testFileRule(testRef.state, testInBrief)),
|
|
185
|
+
doublesLine(doubles === "" ? NONE_NAMED : doubles),
|
|
186
|
+
...(step.anchor?.production ?? []).map((r) => productionLine(stubs.includes(r.path) ? SIGNATURE_STUB_AT_MOST : READ_ONLY_NEVER_WRITE, refLine(r))),
|
|
187
|
+
...carried.lines,
|
|
188
|
+
"",
|
|
189
|
+
RULES_HEADING,
|
|
190
|
+
testFilesOnlyRule(testsWhere(layout)),
|
|
191
|
+
...(stubs.length === 0 ? [] : [
|
|
192
|
+
stubsRule(stubs.map((p) => `\`${p}\` (${stubKind(step, p)})`).join(", ")),
|
|
193
|
+
STUB_IMPORT_RULE,
|
|
194
|
+
]),
|
|
195
|
+
ONE_TEST_PER_ROW_RULE,
|
|
196
|
+
levelRule(step),
|
|
197
|
+
redRunRule(input.testCommand),
|
|
198
|
+
`- ${NODE_READ_RULE}`,
|
|
199
|
+
`- ${BOUNDED_READ_RULE}`,
|
|
200
|
+
`- ${NODE_EDIT_RULE}`,
|
|
201
|
+
`- ${ASSUMPTION_RULE}`,
|
|
202
|
+
"",
|
|
203
|
+
RED_ANSWER,
|
|
204
|
+
].join("\n");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The implementer's brief: the least production code that turns the red tests green, tests read-only. */
|
|
208
|
+
export function greenContract(input: ContractInput, red: { tail: string; log: string | null }): string {
|
|
209
|
+
const { sheet, layout } = input;
|
|
210
|
+
const steps = input.cycle !== undefined && input.cycle.length > 0 ? input.cycle : [input.step];
|
|
211
|
+
const elements = sheet.codeElements.length === 0 ? [NONE_LISTED] : sheet.codeElements;
|
|
212
|
+
const testFiles = [...new Set(steps.map((s) => testFileOf(s) ?? "(none)"))];
|
|
213
|
+
const production = steps.flatMap((s) => s.anchor?.production ?? []);
|
|
214
|
+
const carried = carriedSection(input);
|
|
215
|
+
// A production file to create exists once RED stubbed it: the brief carries it and says so.
|
|
216
|
+
const shown = (r: AnchorRef): string => carried.whole.has(r.path)
|
|
217
|
+
? inThisBrief(refLine(r, r.state === "to create" ? STUBBED_AT_RED : r.state))
|
|
218
|
+
: refLine(r);
|
|
219
|
+
const seen = new Set<string>();
|
|
220
|
+
return [
|
|
221
|
+
...header(input, "GREEN", steps),
|
|
222
|
+
"",
|
|
223
|
+
RED_TESTS_HEADING,
|
|
224
|
+
...steps.flatMap((s) => [...(steps.length > 1 ? [stepLabel(s.number, s.title)] : []), ...testsTable(s)]),
|
|
225
|
+
lastRedRun(testFiles.every((f) => carried.whole.has(f)), testFiles.map((f) => `\`${f}\``).join(", "), red.log),
|
|
226
|
+
"```",
|
|
227
|
+
red.tail,
|
|
228
|
+
"```",
|
|
229
|
+
"",
|
|
230
|
+
PRODUCTION_HEADING,
|
|
231
|
+
...production.filter((r) => !seen.has(refLine(r)) && seen.add(refLine(r)) !== undefined).map((r) => `- ${shown(r)}`),
|
|
232
|
+
CODE_ELEMENTS_LINE,
|
|
233
|
+
...elements,
|
|
234
|
+
appliedRulesLine(sheet.appliedRules, sheet.accessCost),
|
|
235
|
+
...carried.lines,
|
|
236
|
+
"",
|
|
237
|
+
RULES_HEADING,
|
|
238
|
+
neverWriteTestRule(testsWhere(layout)),
|
|
239
|
+
LEAST_CODE_RULE,
|
|
240
|
+
greenRunRule(input.testCommand),
|
|
241
|
+
`- ${NODE_READ_RULE}`,
|
|
242
|
+
`- ${BOUNDED_READ_RULE}`,
|
|
243
|
+
`- ${NODE_EDIT_RULE}`,
|
|
244
|
+
`- ${ASSUMPTION_RULE}`,
|
|
245
|
+
"",
|
|
246
|
+
GREEN_ANSWER,
|
|
247
|
+
].join("\n");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The block that ends a role's prompt with the `stale:` lines the next batch's review handed the launch (its Major
|
|
251
|
+
* rows); "" without any. */
|
|
252
|
+
export function staleBlock(lines: readonly string[]): string {
|
|
253
|
+
const kept = lines.map((l) => l.replace(/\s+/g, " ").trim()).filter((l) => l !== "");
|
|
254
|
+
return kept.length === 0 ? "" : [STALE_HEADING, ...kept].join("\n");
|
|
255
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// A correction of a batch (`/dev-batches <code> F<n> — correction: <finding>`, an audit's gap): a new step of the
|
|
2
|
+
// sheet, `### Step <last+1> — Correction C<k> — <finding>`, with one test row and its own TDD line, and an
|
|
3
|
+
// `## Anchors` row copied from the step it corrects, so that it runs as any step, RED first. The earlier steps
|
|
4
|
+
// and their evidence stay as they are. A finding naming an id the sheet does not carry changes the scope: it is
|
|
5
|
+
// refused and routed. Pure, never throws.
|
|
6
|
+
import { OPEN_TDD_LINE, STEP_TESTS_TABLE_HEAD } from "../../../shared/domain/dev/markers.ts";
|
|
7
|
+
import { unfencedLines } from "../../../shared/domain/dev/plan-format.ts";
|
|
8
|
+
import { parseImplementSheet } from "./step-section.ts";
|
|
9
|
+
import type { ImplementSheet, ImplementStep } from "./step-section.ts";
|
|
10
|
+
import { CORRECTION_TITLE, correctionTitle } from "./markers.ts";
|
|
11
|
+
import {
|
|
12
|
+
ANCHORS_HAVE_NO_ROW, CORRECTION_NAMES_NO_FINDING, NO_STEP_TO_CORRECT, SHEET_LACKS_TDD_OR_ANCHORS, correctionTestRow, correctsStep,
|
|
13
|
+
findingNamesUnknownIds,
|
|
14
|
+
} from "./messages.ts";
|
|
15
|
+
|
|
16
|
+
export type CorrectionEdit =
|
|
17
|
+
| { ok: true; text: string; step: number; title: string; appended: boolean }
|
|
18
|
+
| { ok: false; reason: string };
|
|
19
|
+
|
|
20
|
+
const IDS = /\b[A-Z][A-Z0-9]*-[0-9]+\b/g;
|
|
21
|
+
const MAX_FINDING = 200;
|
|
22
|
+
|
|
23
|
+
/** The finding on one line, without the table's pipe, cut at 200 characters. */
|
|
24
|
+
export function cleanFinding(finding: string): string {
|
|
25
|
+
const one = finding.replace(/\s+/g, " ").replace(/\|/g, "/").trim();
|
|
26
|
+
return one.length <= MAX_FINDING ? one : `${one.slice(0, MAX_FINDING - 1)}…`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The step a finding corrects: the one it names (`step <m>`), else the one whose Anchors paths it names, else the
|
|
30
|
+
* last step with a TDD line and a test file. */
|
|
31
|
+
export function targetStep(sheet: ImplementSheet, finding: string): ImplementStep | null {
|
|
32
|
+
const runnable = sheet.steps.filter((s) => s.tdd !== null && (s.anchor?.testFiles.length ?? 0) > 0);
|
|
33
|
+
const named = /\bstep (\d+)\b/i.exec(finding);
|
|
34
|
+
if (named !== null) {
|
|
35
|
+
const step = runnable.find((s) => s.number === Number(named[1]));
|
|
36
|
+
if (step !== undefined) return step;
|
|
37
|
+
}
|
|
38
|
+
const byPath = runnable.find((s) => [...(s.anchor?.testFiles ?? []), ...(s.anchor?.production ?? [])]
|
|
39
|
+
.some((r) => r.path !== "" && finding.includes(r.path)));
|
|
40
|
+
return byPath ?? runnable[runnable.length - 1] ?? null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sectionEnd(lines: ReturnType<typeof unfencedLines>, heading: string, total: number): { start: number; end: number } | null {
|
|
44
|
+
const at = lines.findIndex((l) => l.text.trim() === heading);
|
|
45
|
+
if (at < 0) return null;
|
|
46
|
+
const next = lines.slice(at + 1).find((l) => l.text.startsWith("## "));
|
|
47
|
+
return { start: lines[at].line, end: next === undefined ? total + 1 : next.line };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const idPrefix = (id: string): string => id.replace(/-[0-9]+$/, "");
|
|
51
|
+
|
|
52
|
+
/** The sheet with the correction appended; an open correction with the same finding is kept, not appended again. */
|
|
53
|
+
export function addCorrection(text: string, findingRaw: string): CorrectionEdit {
|
|
54
|
+
const finding = cleanFinding(findingRaw);
|
|
55
|
+
if (finding === "") return { ok: false, reason: CORRECTION_NAMES_NO_FINDING };
|
|
56
|
+
// The ids the steps carry; a token of the same prefix they do not carry is a new id (`UTF-8`, `SHA-256` are not).
|
|
57
|
+
const carried = new Set(parseImplementSheet(text).steps.flatMap((s) => s.tests.flatMap((t) => t.ids)));
|
|
58
|
+
const prefixes = new Set([...carried].map(idPrefix));
|
|
59
|
+
const unknown = [...new Set(finding.match(IDS) ?? [])].filter((id) => prefixes.has(idPrefix(id)) && !carried.has(id));
|
|
60
|
+
if (unknown.length > 0) {
|
|
61
|
+
return { ok: false, reason: findingNamesUnknownIds(unknown) };
|
|
62
|
+
}
|
|
63
|
+
const sheet = parseImplementSheet(text);
|
|
64
|
+
const corrections = sheet.steps.map((s) => CORRECTION_TITLE.exec(s.title)).filter((m): m is RegExpExecArray => m !== null);
|
|
65
|
+
const same = sheet.steps.find((s) => CORRECTION_TITLE.exec(s.title)?.[2] === finding
|
|
66
|
+
&& !(s.tdd?.red && s.tdd.green && s.tdd.cost));
|
|
67
|
+
if (same !== undefined) return { ok: true, text, step: same.number, title: same.title, appended: false };
|
|
68
|
+
|
|
69
|
+
const target = targetStep(sheet, finding);
|
|
70
|
+
if (target === null || target.anchor === null) return { ok: false, reason: NO_STEP_TO_CORRECT };
|
|
71
|
+
const k = corrections.reduce((max, m) => Math.max(max, Number(m[1])), 0) + 1;
|
|
72
|
+
const number = sheet.steps.reduce((max, s) => Math.max(max, s.number), 0) + 1;
|
|
73
|
+
const title = correctionTitle(k, finding);
|
|
74
|
+
const base = target.tests[0];
|
|
75
|
+
const ids = [...new Set(target.tests.flatMap((t) => t.ids))].join(", ") || "—";
|
|
76
|
+
|
|
77
|
+
const raw = text.split("\n");
|
|
78
|
+
const lines = unfencedLines(text);
|
|
79
|
+
const tdd = sectionEnd(lines, "## TDD sequence", raw.length);
|
|
80
|
+
const anchors = sectionEnd(lines, "## Anchors", raw.length);
|
|
81
|
+
if (tdd === null || anchors === null) return { ok: false, reason: SHEET_LACKS_TDD_OR_ANCHORS };
|
|
82
|
+
const lastRow = lines.filter((l) => l.line > anchors.start && l.line < anchors.end && l.text.startsWith("|")).pop();
|
|
83
|
+
if (lastRow === undefined) return { ok: false, reason: ANCHORS_HAVE_NO_ROW };
|
|
84
|
+
|
|
85
|
+
const cell = (refs: NonNullable<ImplementStep["anchor"]>["testFiles"]): string => refs.length === 0 ? "—"
|
|
86
|
+
: refs.map((r) => `\`${r.line === undefined ? r.path : `${r.path}:${r.line}`}\` — ${r.state === "member" ? `\`${r.member}\`` : "existing"}`).join("; ");
|
|
87
|
+
const anchorRow = `| ${number} — Correction C${k} | ${cell(target.anchor.testFiles)} | ${target.anchor.doubles || "—"} | ${cell(target.anchor.production)} |`;
|
|
88
|
+
const stepBlock = [
|
|
89
|
+
`### Step ${number} — ${title}`,
|
|
90
|
+
correctsStep(target.number, target.title),
|
|
91
|
+
...STEP_TESTS_TABLE_HEAD,
|
|
92
|
+
correctionTestRow(k, base?.level ?? "unit", base?.project ?? "", ids),
|
|
93
|
+
OPEN_TDD_LINE, "",
|
|
94
|
+
];
|
|
95
|
+
// Anchors first (it may lie after the TDD sequence), so the TDD insertion point keeps its index.
|
|
96
|
+
const out = [...raw];
|
|
97
|
+
const insertAt = (index: number, add: string[]): void => { out.splice(index, 0, ...add); };
|
|
98
|
+
const tddAt = tdd.end - 1;
|
|
99
|
+
const rowAt = lastRow.line;
|
|
100
|
+
if (rowAt > tddAt) { insertAt(rowAt, [anchorRow]); insertAt(tddAt, stepBlock); }
|
|
101
|
+
else { insertAt(tddAt, stepBlock); insertAt(rowAt, [anchorRow]); }
|
|
102
|
+
return { ok: true, text: out.join("\n"), step: number, title, appended: true };
|
|
103
|
+
}
|