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,179 @@
|
|
|
1
|
+
/// <reference path="../../../crews/.orkeon/orkeon.d.ts" />
|
|
2
|
+
// The ports of dev-implement's and dev-verify's use cases, built from the agent body that runs them: its own
|
|
3
|
+
// `ctx.tools`, `ctx.llm` and `ctx.log`. The crews' bodies use them, and so does a parallel /dev-batches' batch
|
|
4
|
+
// agent, beside others under their own working roots - where the global `tools` refuses a call from code
|
|
5
|
+
// (temp/26 L8P-D3). Given a root (the batch's worktree), the ports keep naming the checkout `/workspace` and map
|
|
6
|
+
// it onto the root (path-rebase.ts): the files, the shell and its jobs, the config, the act's callbacks (a call's
|
|
7
|
+
// paths back to `/workspace` before the rules see them) and the model's briefs (prompts and system texts out with
|
|
8
|
+
// the root's paths). The cost index is left out under a root: it indexes the main checkout. A spend, given, bounds
|
|
9
|
+
// the batch's tool calls: the runtime gives a delegated agent no budget (L8P-D12).
|
|
10
|
+
|
|
11
|
+
import type { ActRequest, CompleteRequest, Llm, Logger } from "../../application/ports.ts";
|
|
12
|
+
import type { WorkFolder } from "../../application/dev/resolve-work-folder.ts";
|
|
13
|
+
import { stepPrecedents } from "../../application/dev/step-precedents.ts";
|
|
14
|
+
import { harvestAfterGaps } from "../../application/shared-memory/harvest-after-gaps.ts";
|
|
15
|
+
import { memoryDirOf } from "../../application/shared-memory/memory-settings.ts";
|
|
16
|
+
import { briefToRoot, mapStrings } from "../../domain/dev/path-rebase.ts";
|
|
17
|
+
import { toVirtual } from "../../domain/host-paths.ts";
|
|
18
|
+
import type { HostSource } from "../../application/host-context.ts";
|
|
19
|
+
import { parseSessionRules } from "../../domain/git/pull-request.ts";
|
|
20
|
+
import type { DevImplementDeps } from "../../../crews/dev-implement/application/run-dev-implement.ts";
|
|
21
|
+
import type { DevVerifyDeps } from "../../../crews/dev-verify/application/run-dev-verify.ts";
|
|
22
|
+
import { reportingWrites } from "../../../crews/dev-implement/application/report-writes.ts";
|
|
23
|
+
import { AUDITOR_CHARTER } from "../../../crews/dev-verify/domain/auditor-charter.ts";
|
|
24
|
+
import { charterCatalogue } from "../../domain/agents/charter.ts";
|
|
25
|
+
import { agentLlm } from "./llm.ts";
|
|
26
|
+
import { memoryReadTools, memoryRecallTools } from "./memory-tools.ts";
|
|
27
|
+
import type { MemoryToolPorts } from "./memory-tools.ts";
|
|
28
|
+
import { RUN_VALIDATION, runBuildTool, runTestsTool, runValidationTool, scriptToolSlot } from "./script-tools.ts";
|
|
29
|
+
import type { ScriptToolSlot, ToolBuilderFactory, ValidationCalls } from "./script-tools.ts";
|
|
30
|
+
import type { WrappedTools } from "../../application/dev/wrapped-tools.ts";
|
|
31
|
+
import { shCode, shOut } from "./tool-results.ts";
|
|
32
|
+
import { devToolCallbacks, rootedCallbacks } from "../../application/dev/tool-callbacks.ts";
|
|
33
|
+
import type { ToolCallbacks } from "../../application/dev/tool-callbacks.ts";
|
|
34
|
+
import { createSpend, spendGuard } from "../../application/dev/spend.ts";
|
|
35
|
+
import type { Spend } from "../../application/dev/spend.ts";
|
|
36
|
+
import {
|
|
37
|
+
orkeonClock, orkeonConfigStore, orkeonCostIndex, orkeonFiles, orkeonHostContext, orkeonMemoryToolPorts,
|
|
38
|
+
orkeonPrunedLlm, orkeonPullRequestOpener, orkeonSharedMemory, orkeonShell, orkeonShellJobs,
|
|
39
|
+
} from "./wiring.ts";
|
|
40
|
+
|
|
41
|
+
/** What an agent body hands its deps: its own tools, model, file-system section and log. */
|
|
42
|
+
export interface BodyContext {
|
|
43
|
+
tools: OrkeonTools;
|
|
44
|
+
llm: Pick<LlmFacade, "act" | "complete" | "extract" | "chat"> & Partial<Pick<LlmFacade, "permissionGate">>;
|
|
45
|
+
fileSystem: Pick<AgentFileSystem, "prompt">;
|
|
46
|
+
log: Logger;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `llm` with the `/workspace` paths its prompts and system texts name on the root; `llm` itself without one. */
|
|
50
|
+
export function rootedLlm(llm: Llm, root: string | undefined): Llm {
|
|
51
|
+
if (root === undefined || root === "") return llm;
|
|
52
|
+
// A brief's own paths only: what it quotes of the files (a constant, a fenced diff) stays as the files hold it.
|
|
53
|
+
const out = (text: string) => briefToRoot(text, root);
|
|
54
|
+
return {
|
|
55
|
+
...llm,
|
|
56
|
+
act: (prompt: string, request: ActRequest) => llm.act(out(prompt), mapStrings(request, out)),
|
|
57
|
+
complete: (prompt: string, request?: CompleteRequest) => llm.complete(out(prompt), request === undefined ? request : mapStrings(request, out)),
|
|
58
|
+
extract: (prompt: string, schema: object) => llm.extract(out(prompt), schema),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The tools of the agent body that runs, for the script tools built with its agent before any body runs. */
|
|
63
|
+
export function agentTools(): { bind(tools: OrkeonTools): void; memoryPorts(root?: string): () => MemoryToolPorts } {
|
|
64
|
+
let bound: OrkeonTools | undefined;
|
|
65
|
+
return {
|
|
66
|
+
bind: (tools) => { bound = tools; },
|
|
67
|
+
// Unbound (a host that calls the tool before the body), the global: the crews' own single agent.
|
|
68
|
+
memoryPorts: (root) => () => orkeonMemoryToolPorts(bound, root),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** What one batch agent of a parallel /dev-batches is built with: its own script-tool slots, spend and body tools,
|
|
73
|
+
* never shared with another batch agent, and the script tools bound to them (rooted on its worktree). */
|
|
74
|
+
export interface BatchAgentParts {
|
|
75
|
+
spend: Spend;
|
|
76
|
+
toolSlot: ScriptToolSlot<WrappedTools>;
|
|
77
|
+
validationSlot: ScriptToolSlot<ValidationCalls>;
|
|
78
|
+
bodyTools: ReturnType<typeof agentTools>;
|
|
79
|
+
tools: Array<Tool<unknown, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function batchAgentParts(builder: ToolBuilderFactory, opts: { root: string; toolCalls: number; memoryOn: boolean }): BatchAgentParts {
|
|
83
|
+
const spend = createSpend(opts.toolCalls);
|
|
84
|
+
const toolSlot = scriptToolSlot<WrappedTools>();
|
|
85
|
+
const validationSlot = scriptToolSlot<ValidationCalls>();
|
|
86
|
+
const bodyTools = agentTools();
|
|
87
|
+
const tools = [
|
|
88
|
+
runTestsTool(builder, toolSlot, opts.root), runBuildTool(builder, toolSlot, opts.root), runValidationTool(builder, validationSlot, opts.root),
|
|
89
|
+
...memoryRecallTools(builder, bodyTools.memoryPorts(opts.root), opts.memoryOn, opts.root),
|
|
90
|
+
];
|
|
91
|
+
return { spend, toolSlot, validationSlot, bodyTools, tools };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** git's top as an agent under `root` sees it: the raw output, never mapped back to `/workspace`, so that a
|
|
95
|
+
* top other than the root shows (a parallel /dev-batches' probe, L8P-D11); a top git spells as the disk does (git
|
|
96
|
+
* for Windows prints `C:/...`, which the runtime's own rewrite misses) comes back to the VFS. A refused call throws. */
|
|
97
|
+
export async function gitTopUnder(
|
|
98
|
+
tools: Pick<OrkeonTools, "shellCommand">, root: string, host: HostSource = orkeonHostContext,
|
|
99
|
+
): Promise<{ exitCode: number; top: string }> {
|
|
100
|
+
const r = await tools.shellCommand({ command: "git rev-parse --show-toplevel", working_directory: root });
|
|
101
|
+
return { exitCode: shCode(r), top: toVirtual(shOut(r).trim(), (await host()).layout) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface DevOptions {
|
|
105
|
+
/** The /hooks registry the command passed. */
|
|
106
|
+
hooks: unknown;
|
|
107
|
+
effort: ActRequest["effort"] | undefined;
|
|
108
|
+
/** memory_recall is attached (no session rule denies it). */
|
|
109
|
+
memoryOn: boolean;
|
|
110
|
+
/** The batch's worktree, a parallel /dev-batches' working root; none: the checkout itself. */
|
|
111
|
+
root?: string;
|
|
112
|
+
spend?: Spend;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function portsOf(ctx: Pick<BodyContext, "tools">, root: string | undefined) {
|
|
116
|
+
return {
|
|
117
|
+
shell: orkeonShell(ctx.tools, root), files: orkeonFiles(ctx.tools, root), config: orkeonConfigStore(ctx.tools, root),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** dev-implement's deps over the body's context. */
|
|
122
|
+
export function implementDeps(
|
|
123
|
+
ctx: BodyContext, opts: DevOptions & { toolSlot: DevImplementDeps["toolSlot"] },
|
|
124
|
+
): DevImplementDeps {
|
|
125
|
+
const ports = portsOf(ctx, opts.root);
|
|
126
|
+
const callbacks = (spec: Parameters<typeof devToolCallbacks>[0], wrote: (path: string) => void) =>
|
|
127
|
+
spendGuard(rootedCallbacks(reportingWrites(devToolCallbacks(spec, { shell: ports.shell, log: ctx.log, files: ports.files, memoryDir: memoryDirOf(ports.config) }), wrote), opts.root), opts.spend);
|
|
128
|
+
return {
|
|
129
|
+
...ports, jobs: orkeonShellJobs(ctx.tools, opts.root), log: ctx.log, clock: orkeonClock(),
|
|
130
|
+
...(opts.toolSlot !== undefined ? { toolSlot: opts.toolSlot } : {}),
|
|
131
|
+
...(opts.root === undefined ? { costIndex: orkeonCostIndex(ctx.tools) } : {}),
|
|
132
|
+
precedents: stepPrecedents({ ...ports, memory: orkeonSharedMemory(ctx.tools), log: ctx.log }, { on: opts.memoryOn }),
|
|
133
|
+
// The close's opener, for the context read at the launch (the chained close reads it from the batch record).
|
|
134
|
+
openerFor: (pr) => orkeonPullRequestOpener({ mode: pr.permissionMode, rules: parseSessionRules(pr.permissionRules), asked: false }, ctx.tools),
|
|
135
|
+
// Each role's act runs under its own callbacks, then the host's gate: the step's rule sets, the role's
|
|
136
|
+
// roots and the /hooks the command passed. `wrote` hears each write that ran, from its result; `writable`:
|
|
137
|
+
// the test author's stubs, which its own root denies leave open; `files`: the rewrite rule reads a write's path.
|
|
138
|
+
// Under the rebase of the paths, the pruning of the act's tool loop (compaction.prune): nothing added when off.
|
|
139
|
+
roleLlm: (role, layout, wrote, writable) => rootedLlm(orkeonPrunedLlm(agentLlm(ctx, callbacks(
|
|
140
|
+
{ step: "dev-implement", role, layout, writable, hooks: opts.hooks, readTools: memoryReadTools(opts.memoryOn) }, wrote,
|
|
141
|
+
), { effort: opts.effort }), ctx.log, ctx.tools, opts.root), opts.root),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** dev-verify's callbacks over the body's context: the step's rule sets again and the /hooks the command passed;
|
|
146
|
+
* run_validation and memory_recall, declared `read`, let through on a host without a gate. */
|
|
147
|
+
export function verifyCallbacks(ctx: Pick<BodyContext, "tools" | "log">, opts: DevOptions): ToolCallbacks {
|
|
148
|
+
const ports = portsOf(ctx, opts.root);
|
|
149
|
+
return spendGuard(rootedCallbacks(devToolCallbacks(
|
|
150
|
+
{ step: "dev-verify", hooks: opts.hooks, readTools: [RUN_VALIDATION.name, ...memoryReadTools(opts.memoryOn)] },
|
|
151
|
+
{ shell: ports.shell, log: ctx.log, memoryDir: memoryDirOf(ports.config) },
|
|
152
|
+
), opts.root), opts.spend);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** dev-verify's deps over the body's context. The audit acts on the plain Llm (inline) unless `wrapLlm` hands it
|
|
156
|
+
* to a background child (the crew's); the harvest after GAPS runs only when asked (never in a batch: the driver's). */
|
|
157
|
+
export function verifyDeps(
|
|
158
|
+
ctx: BodyContext,
|
|
159
|
+
opts: DevOptions & { validationSlot: DevVerifyDeps["validationSlot"]; wrapLlm?: (llm: Llm) => Llm; harvest?: boolean },
|
|
160
|
+
): DevVerifyDeps {
|
|
161
|
+
const ports = portsOf(ctx, opts.root);
|
|
162
|
+
const clock = orkeonClock();
|
|
163
|
+
// The audit's act is offered the auditor's tools alone: a batch agent also holds the implementer's, which an act
|
|
164
|
+
// without a subset would offer too - write tools to a read-only auditor, their schemas resent at every turn.
|
|
165
|
+
const auditorTools = [...charterCatalogue(AUDITOR_CHARTER), RUN_VALIDATION.name, ...memoryReadTools(opts.memoryOn)];
|
|
166
|
+
const rooted = rootedLlm(orkeonPrunedLlm(agentLlm(ctx, verifyCallbacks(ctx, opts), { effort: opts.effort }), ctx.log, ctx.tools, opts.root), opts.root);
|
|
167
|
+
const plain: Llm = { ...rooted, act: (prompt, request = {}) => rooted.act(prompt, request.tools === undefined ? { ...request, tools: auditorTools } : request) };
|
|
168
|
+
return {
|
|
169
|
+
...ports, log: ctx.log, clock, llm: opts.wrapLlm === undefined ? plain : opts.wrapLlm(plain),
|
|
170
|
+
...(opts.validationSlot !== undefined ? { validationSlot: opts.validationSlot } : {}),
|
|
171
|
+
...(opts.root === undefined ? { costIndex: orkeonCostIndex(ctx.tools) } : {}),
|
|
172
|
+
// T4: the shared memory's precedents in the auditor's brief, unless memory_recall is denied.
|
|
173
|
+
precedents: stepPrecedents({ ...ports, memory: orkeonSharedMemory(ctx.tools), log: ctx.log }, { on: opts.memoryOn }),
|
|
174
|
+
// M-7: after a GAPS verdict, the mistakes that recur become candidates.
|
|
175
|
+
...(opts.harvest === true
|
|
176
|
+
? { harvest: (work: Pick<WorkFolder, "folder" | "vfsPath">) => harvestAfterGaps({ ...ports, clock, log: ctx.log }, work) }
|
|
177
|
+
: {}),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Files adapter over file_read, file_write, directory_read and list_mounts. A
|
|
2
|
+
// failed read is rethrown with the tool's own message, the runtime's wrapping gone
|
|
3
|
+
// (withToolMessage): callers tell an absent file from an unreadable one by it. Given a batch's working root, each
|
|
4
|
+
// `/workspace` path is read and written under it (shared/domain/dev/path-rebase.ts). Given the host's context, a path
|
|
5
|
+
// spelled as the disk does comes back to the VFS first, and a failure's message comes back with the VFS spellings
|
|
6
|
+
// (shared/domain/host-paths.ts).
|
|
7
|
+
|
|
8
|
+
import type { Files } from "../../application/ports.ts";
|
|
9
|
+
import type { HostSource } from "../../application/host-context.ts";
|
|
10
|
+
import { toRoot } from "../../domain/dev/path-rebase.ts";
|
|
11
|
+
import { textToVirtual, toVirtual } from "../../domain/host-paths.ts";
|
|
12
|
+
import type { HostLayout } from "../../domain/host-layout.ts";
|
|
13
|
+
import { layoutOf } from "./host-context.ts";
|
|
14
|
+
import { entryNames, fileContent, pick, withToolMessage } from "./tool-results.ts";
|
|
15
|
+
|
|
16
|
+
/** The tool's own message (withToolMessage), its disk spellings brought back to the VFS. */
|
|
17
|
+
async function withHostMessage<T>(layout: HostLayout, call: () => Promise<T>): Promise<T> {
|
|
18
|
+
try {
|
|
19
|
+
return await withToolMessage(call);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error(textToVirtual(error instanceof Error ? error.message : String(error), layout));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createFiles(
|
|
26
|
+
tools: Pick<OrkeonTools, "fileRead" | "fileWrite" | "directoryRead" | "listMounts">,
|
|
27
|
+
root?: string,
|
|
28
|
+
host?: HostSource,
|
|
29
|
+
): Files {
|
|
30
|
+
const pathOf = async (logical: string) => toRoot(toVirtual(logical, await layoutOf(host)), root);
|
|
31
|
+
return {
|
|
32
|
+
async read(logical, maxLength) {
|
|
33
|
+
const layout = await layoutOf(host);
|
|
34
|
+
const path = toRoot(toVirtual(logical, layout), root);
|
|
35
|
+
const input = maxLength === undefined ? { path } : { path, max_length: maxLength };
|
|
36
|
+
return fileContent(await withHostMessage(layout, () => tools.fileRead(input)));
|
|
37
|
+
},
|
|
38
|
+
async write(logical, content) {
|
|
39
|
+
await tools.fileWrite({ path: await pathOf(logical), content });
|
|
40
|
+
},
|
|
41
|
+
async list(logical, maxEntries) {
|
|
42
|
+
const path = await pathOf(logical);
|
|
43
|
+
// DirectoryReadRequest.MaxResults, bound through the tools' snake_case naming
|
|
44
|
+
// (as file_read's MaxLength is `max_length`); an unknown field is ignored.
|
|
45
|
+
return entryNames(await tools.directoryRead({ path, max_results: maxEntries }));
|
|
46
|
+
},
|
|
47
|
+
async mounts() {
|
|
48
|
+
const list: any[] = pick(await tools.listMounts(), "mounts") ?? [];
|
|
49
|
+
// `{ mounts: [{ virtual_path, access, overrides }] }`, as the typings of the
|
|
50
|
+
// runtime declare it (tools.generated.d.ts, `listMounts`); `access` is `ro`, `rw`
|
|
51
|
+
// or `rwnd`, else the rights enum's own name.
|
|
52
|
+
return list.map((m) => ({
|
|
53
|
+
path: String(m.virtual_path ?? ""),
|
|
54
|
+
rights: m.access == null ? undefined : String(m.access),
|
|
55
|
+
}));
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// GitHubPullRequests adapter over the runtime's `github` tool, action
|
|
2
|
+
// `create_pr`. The tool answers a failure as `success: false` with `error`
|
|
3
|
+
// (an HTTP refusal included), not a throw: this turns it into one, GitHub's
|
|
4
|
+
// first line as its message. The url is the pull request's page (`html_url`,
|
|
5
|
+
// read as `url`); without one, its number.
|
|
6
|
+
|
|
7
|
+
import type { GitHubPullRequests } from "../../application/git/open-pull-request.ts";
|
|
8
|
+
import { asArray, pick } from "./tool-results.ts";
|
|
9
|
+
import { GITHUB_FAILED_WITHOUT_REASON, GITHUB_SUCCESS_WITHOUT_PULL_REQUEST } from "./messages.ts";
|
|
10
|
+
|
|
11
|
+
function firstLine(text: unknown): string {
|
|
12
|
+
return String(text ?? "").split("\n").map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createGitHubPullRequests(tools: Pick<OrkeonTools, "github">): GitHubPullRequests {
|
|
16
|
+
return {
|
|
17
|
+
async create(args) {
|
|
18
|
+
const r = await tools.github(args);
|
|
19
|
+
if (pick(r, "success", "Success") !== true) {
|
|
20
|
+
throw new Error(firstLine(pick(r, "error", "Error")) || GITHUB_FAILED_WITHOUT_REASON);
|
|
21
|
+
}
|
|
22
|
+
const item = asArray(pick(r, "items", "Items"))[0];
|
|
23
|
+
const url = String(pick(item, "url", "Url") ?? "").trim();
|
|
24
|
+
if (url.length > 0) return { url };
|
|
25
|
+
const number = pick(item, "number", "Number");
|
|
26
|
+
if (number == null) throw new Error(GITHUB_SUCCESS_WITHOUT_PULL_REQUEST);
|
|
27
|
+
return { url: `#${number}` };
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The host context of this run (shared/application/host-context.ts: the layout of launch.json and the path lists of
|
|
2
|
+
// the settings), read once and shared by every act (llm.ts) and every operation of the file, shell and job adapters.
|
|
3
|
+
// wiring.ts, the module every entry point loads, binds the reader over the global tools; an adapter or the Llm
|
|
4
|
+
// adapter loaded alone, in a test, finds nothing bound and reads the identity: the spellings pass as they are. The
|
|
5
|
+
// read runs at the first call, never at load, and a read that fails (the runtime refusing a call from code while
|
|
6
|
+
// agents under other roots run) leaves the identity as well.
|
|
7
|
+
|
|
8
|
+
import { IDENTITY_CONTEXT } from "../../application/host-context.ts";
|
|
9
|
+
import type { HostContext, HostSource } from "../../application/host-context.ts";
|
|
10
|
+
import { IDENTITY_HOST } from "../../domain/host-layout.ts";
|
|
11
|
+
import type { HostLayout } from "../../domain/host-layout.ts";
|
|
12
|
+
|
|
13
|
+
/** The host's layout, the identity for an adapter given no context. */
|
|
14
|
+
export async function layoutOf(host: HostSource | undefined): Promise<HostLayout> {
|
|
15
|
+
return host === undefined ? IDENTITY_HOST : (await host()).layout;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let reader: HostSource | undefined;
|
|
19
|
+
let memo: Promise<HostContext> | undefined;
|
|
20
|
+
|
|
21
|
+
/** Binds the reader of this run's context, or none: the next call reads it again. */
|
|
22
|
+
export function bindHostContext(read: HostSource | undefined): void {
|
|
23
|
+
reader = read;
|
|
24
|
+
memo = undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** This run's context: the bound reader's, read once; the identity unbound or when the read fails. */
|
|
28
|
+
export const orkeonHostContext: HostSource = () => {
|
|
29
|
+
if (memo === undefined) {
|
|
30
|
+
const read = reader;
|
|
31
|
+
memo = read === undefined
|
|
32
|
+
? Promise.resolve(IDENTITY_CONTEXT)
|
|
33
|
+
: Promise.resolve().then(() => read()).catch(() => IDENTITY_CONTEXT);
|
|
34
|
+
}
|
|
35
|
+
return memo;
|
|
36
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The name of the host's LLM provider, read from the command context's `llm`
|
|
2
|
+
// service (the host's ILlmProvider, optional: a host may wire none). Jint keeps
|
|
3
|
+
// the CLR member names, so the name is `Name`; `name` is read too. Like the
|
|
4
|
+
// script-host, the service comes from the context each command receives, so the
|
|
5
|
+
// reader takes the service locator as a parameter. Nothing here is offered to
|
|
6
|
+
// the model.
|
|
7
|
+
|
|
8
|
+
import type { ServiceLocator } from "../../../commands/.orkeon/orkeon-cli.d.ts";
|
|
9
|
+
import { pick } from "./tool-results.ts";
|
|
10
|
+
|
|
11
|
+
const LLM = "llm";
|
|
12
|
+
|
|
13
|
+
/** The provider's name (`deepseek`, `anthropic`, `OpenAI`...), undefined when the host wires none or the read fails. */
|
|
14
|
+
export function readHostProvider(services: Pick<ServiceLocator, "get" | "has">): string | undefined {
|
|
15
|
+
try {
|
|
16
|
+
if (!services.has(LLM)) return undefined;
|
|
17
|
+
const name = String(pick(services.get<unknown>(LLM), "Name", "name") ?? "").trim();
|
|
18
|
+
return name.length > 0 ? name : undefined;
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// HumanInput adapter: human_input (RT-08) as the dev steps ask it. No answer is ever made on the person's behalf:
|
|
2
|
+
// every `choice` and `text` carries a default value no option holds, so whichever unattended provider answers (the
|
|
3
|
+
// auto-approver returns the default, the observed runner returns it when nobody replies) is read as "nobody
|
|
4
|
+
// answered", `was_default` or not; a `multi` gets no recommended option and a first option meaning "decide later",
|
|
5
|
+
// which the auto-approver picks and nobody else needs to. A host without the tool, or a call that throws, is
|
|
6
|
+
// nobody answering too. In the REPL an empty answer to a `choice` takes the recommended option (the person pressed
|
|
7
|
+
// Enter); an empty `text` is no answer.
|
|
8
|
+
import type { HumanInput } from "../../application/ports.ts";
|
|
9
|
+
import { pick } from "./tool-results.ts";
|
|
10
|
+
import { DECIDE_LATER, NO_ANSWER } from "./markers.ts";
|
|
11
|
+
|
|
12
|
+
type HumanInputTools = Partial<Pick<OrkeonTools, "humanInput">>;
|
|
13
|
+
const NOBODY = { answered: false } as const;
|
|
14
|
+
|
|
15
|
+
function textOf(value: unknown): string {
|
|
16
|
+
return typeof value === "string" ? value : "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function valuesOf(value: unknown): string[] {
|
|
20
|
+
return Array.isArray(value) ? value.filter((v): v is string => typeof v === "string") : [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createHumanInput(tools: HumanInputTools): HumanInput {
|
|
24
|
+
const ask = async (input: Parameters<OrkeonTools["humanInput"]>[0]): Promise<unknown> => {
|
|
25
|
+
if (typeof tools.humanInput !== "function") return null;
|
|
26
|
+
try {
|
|
27
|
+
return await tools.humanInput(input);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
async choice(prompt, options) {
|
|
34
|
+
const r = await ask({ prompt, input_type: "choice", choices: [...options], recommended: 0, default_value: NO_ANSWER });
|
|
35
|
+
if (r === null) return NOBODY;
|
|
36
|
+
const value = textOf(pick(r, "response", "Response"));
|
|
37
|
+
if (pick(r, "was_default", "WasDefault") === true || value === NO_ANSWER || !options.includes(value)) return NOBODY;
|
|
38
|
+
return { answered: true, value };
|
|
39
|
+
},
|
|
40
|
+
async text(prompt) {
|
|
41
|
+
const r = await ask({ prompt, input_type: "text", default_value: NO_ANSWER });
|
|
42
|
+
if (r === null) return NOBODY;
|
|
43
|
+
const value = textOf(pick(r, "response", "Response")).trim();
|
|
44
|
+
if (pick(r, "was_default", "WasDefault") === true || value === NO_ANSWER || value === "") return NOBODY;
|
|
45
|
+
return { answered: true, value };
|
|
46
|
+
},
|
|
47
|
+
async multi(prompt, options) {
|
|
48
|
+
const r = await ask({ prompt, input_type: "multi", choices: [DECIDE_LATER, ...options] });
|
|
49
|
+
if (r === null) return NOBODY;
|
|
50
|
+
const picked = valuesOf(pick(r, "values", "Values"));
|
|
51
|
+
if (picked.length === 0 || picked.includes(DECIDE_LATER)) return NOBODY;
|
|
52
|
+
return { answered: true, values: options.filter((o) => picked.includes(o)) };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// An agent builder on the host profile the crew input names: `llmProfile`, the session's `llm.profile` the
|
|
2
|
+
// command read (shared/domain/llm-profile.ts). Every composition root starts its agents at wiring.ts
|
|
3
|
+
// orkeonAgent(), which hands this the runtime's factories, child agents included: one session key moves every
|
|
4
|
+
// agent of every crew onto a decision profile (Jev in front of an LLM profile) or another LLM profile. An input
|
|
5
|
+
// naming none gives the plain builder, on the host's default model. A name the host does not declare throws at
|
|
6
|
+
// the crew's load, as `llm.profile` does, listing the profiles the host knows. Every agent asks the provider to cache
|
|
7
|
+
// its system prompt and its tool definitions (Orkeon #254): the prompts are assembled so that this prefix stays
|
|
8
|
+
// byte-identical turn after turn. Only a provider whose cache is explicit (Anthropic) needs the request; the others
|
|
9
|
+
// cache by their own rules. A sub-agent's act routed to a rung the host does not declare stays on the crew's profile
|
|
10
|
+
// (declaredRoute), as a crew launched on one does: the runtime throws on an unknown profile name an
|
|
11
|
+
// `InvalidScriptError` (Orkeon #364, #366), which `refusal` recognises. Any other failure of `llm.profile` is no
|
|
12
|
+
// undeclared name: it is thrown as it came.
|
|
13
|
+
|
|
14
|
+
import { llmProfileFallbackOf, llmProfileOf } from "../../domain/llm-profile.ts";
|
|
15
|
+
import { noLlmNamespace } from "./messages.ts";
|
|
16
|
+
import type { ActRoute } from "../../application/agents/route-agent.ts";
|
|
17
|
+
|
|
18
|
+
/** What building a profiled agent needs of the runtime: the agent builder, `llm.profile`, absent where the host
|
|
19
|
+
* declares no `llm`, and `refusal`, whether an error is the runtime refusing what the script asked. */
|
|
20
|
+
export interface AgentFactories {
|
|
21
|
+
agent: () => any;
|
|
22
|
+
profile: ((name: string) => LlmConfig) | undefined;
|
|
23
|
+
refusal: (error: unknown) => boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The prompt cache every agent requests: the system prompt and the tools, for the vendor's default lifetime. */
|
|
27
|
+
export const PROMPT_CACHE: LlmCacheOptions = { systemPrompt: true, tools: true };
|
|
28
|
+
|
|
29
|
+
export function profiledAgent(input: Readonly<Record<string, unknown>>, factories: AgentFactories): any {
|
|
30
|
+
const builder = factories.agent().cache(PROMPT_CACHE);
|
|
31
|
+
const name = llmProfileOf(input);
|
|
32
|
+
if (name === null) return builder;
|
|
33
|
+
if (factories.profile === undefined) throw new Error(noLlmNamespace(name));
|
|
34
|
+
const fallback = llmProfileFallbackOf(input);
|
|
35
|
+
if (fallback === undefined) return builder.llm(factories.profile(name));
|
|
36
|
+
// A routed name the host does not declare: the crew runs as it would have without the routing.
|
|
37
|
+
try {
|
|
38
|
+
return builder.llm(factories.profile(name));
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (!factories.refusal(error)) throw error;
|
|
41
|
+
return fallback === null ? builder : builder.llm(factories.profile(fallback));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `route`, answering null for a profile the host does not declare (or on a host without `llm`). */
|
|
46
|
+
export function declaredRoute(route: ActRoute, { profile, refusal }: Pick<AgentFactories, "profile" | "refusal">): ActRoute {
|
|
47
|
+
return async (task) => {
|
|
48
|
+
const name = await route(task);
|
|
49
|
+
if (name === null || profile === undefined) return null;
|
|
50
|
+
try {
|
|
51
|
+
profile(name);
|
|
52
|
+
return name;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!refusal(error)) throw error;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/// <reference path="../../../crews/.orkeon/orkeon.d.ts" />
|
|
2
|
+
// Llm adapter over the running agent's `ctx.llm` facade. The facade belongs to
|
|
3
|
+
// the context the runtime hands each agent body, not to a global, so the entry
|
|
4
|
+
// point passes its context in (`agentLlm(ctx)`) rather than wiring.ts binding it.
|
|
5
|
+
// This is the one place that turns the port's settings into the runtime's call
|
|
6
|
+
// options, and the one place that reads an act() result. A call the provider
|
|
7
|
+
// failed comes back as the host's failure marker: it is thrown as an LlmFailure,
|
|
8
|
+
// never returned as an answer. An act whose token budget ran out resolves with
|
|
9
|
+
// `budgetExhausted: true` and the wrap-up the model made without tools (Orkeon #218):
|
|
10
|
+
// it is thrown as a BudgetExhaustedAnswer carrying that answer, never returned, so the
|
|
11
|
+
// port's `act` keeps resolving to a finished answer alone, every caller that reads a
|
|
12
|
+
// spent budget off a rejection (runSubAgent, the dev roles, the auditor) keeps doing
|
|
13
|
+
// so under the `tokens` dimension, and the one caller that shows the wrap-up (the
|
|
14
|
+
// main loop) reads it off the error. An act stopped at its `maxIterations` resolves with
|
|
15
|
+
// `exhausted: true` and the runtime's notice as output: it is thrown as an IterationsExhausted,
|
|
16
|
+
// so a reviewer or an auditor that never concluded is a failure of its act, never an answer to
|
|
17
|
+
// parse; the main loop shows the notice. A crew that guards its tool calls hands its callbacks
|
|
18
|
+
// (shared/application/dev/tool-callbacks.ts) as the second argument: each act then carries the
|
|
19
|
+
// onToolCall/onToolResult built for its own mode. The request's `effort` is the runtime's
|
|
20
|
+
// `act({effort})` as it is; the crew's own level, when it has one, fills a request that names none.
|
|
21
|
+
// `effortSent` asks the facade what such an act sends for its effort (`ctx.llm.reasoning`, Orkeon #360), without a call.
|
|
22
|
+
// The request's `context` is the runtime's `act({context})` (Orkeon #276), a blank one left out.
|
|
23
|
+
// Every act's callbacks, the crew's or none, sit inside the host's (hostCallbacks): under a host whose paths have
|
|
24
|
+
// another spelling, or with path lists, a call's paths come back to the VFS and are judged before the crew's
|
|
25
|
+
// callbacks see them, and every result's disk spellings come back before the model reads them. The host's context
|
|
26
|
+
// is this run's (orkeon/host-context.ts), read at the first act; a test hands its own in the defaults.
|
|
27
|
+
// An act that carries a system prompt ends it with the runtime's `## File system` section (`ctx.fileSystem.prompt`,
|
|
28
|
+
// Orkeon #378): the paths this agent may touch, their rights and where relative paths resolve, read at each act and
|
|
29
|
+
// left out when the runtime gives none. The entry points build the adapter from the agent's context (`agentLlm(ctx)`).
|
|
30
|
+
|
|
31
|
+
import type { ActRequest, CompleteRequest, Llm, ModelOverride } from "../../application/ports.ts";
|
|
32
|
+
import type { PermissionMode } from "../../domain/permission-modes.ts";
|
|
33
|
+
import { budgetExhaustedAnswer, iterationsExhausted, llmFailureOf } from "../../domain/llm-failure.ts";
|
|
34
|
+
import { effortReportOf } from "../../domain/agent-policy/reasoning.ts";
|
|
35
|
+
import { hostCallbacks } from "../../application/dev/tool-callbacks.ts";
|
|
36
|
+
import type { ActCallbacks, ToolCallbacks } from "../../application/dev/tool-callbacks.ts";
|
|
37
|
+
import type { HostSource } from "../../application/host-context.ts";
|
|
38
|
+
import { orkeonHostContext } from "./host-context.ts";
|
|
39
|
+
|
|
40
|
+
/** The request as the callers fill it: its mode is one of PERMISSION_MODES, the
|
|
41
|
+
* five modes ActOptions names. */
|
|
42
|
+
type ModeActRequest = Omit<ActRequest, "permissionMode"> & { permissionMode?: PermissionMode };
|
|
43
|
+
|
|
44
|
+
/** The runtime's `llm` patch of one call: its profile and its model, each when set; none when neither is. */
|
|
45
|
+
function llmPatch(profile: string | undefined, model: string | undefined): { profile?: string; model?: string } | undefined {
|
|
46
|
+
if (!profile && !model) return undefined;
|
|
47
|
+
return { ...(profile ? { profile } : {}), ...(model ? { model } : {}) };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The runtime's per-call options for a model override; none without one. */
|
|
51
|
+
function callOptions(override: ModelOverride | undefined): LlmCallOptions | undefined {
|
|
52
|
+
const llm = llmPatch(override?.profile, override?.model);
|
|
53
|
+
return llm === undefined ? undefined : { llm };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The runtime's act() options: the request as given (its `tools` subset copied), its profile and model as the `llm`
|
|
57
|
+
* patch, and the act's callbacks, when it has any. */
|
|
58
|
+
function actOptions(request: ActRequest, callbacks: ActCallbacks | undefined): ActOptions {
|
|
59
|
+
const { model, profile, tools, ...given } = request as ModeActRequest;
|
|
60
|
+
const rest = tools === undefined ? given : { ...given, tools: [...tools] };
|
|
61
|
+
const llm = llmPatch(profile, model);
|
|
62
|
+
const options: ActOptions = llm === undefined ? rest : { ...rest, llm };
|
|
63
|
+
return callbacks === undefined ? options : { ...options, ...callbacks };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The answer text of an act() result: its `output`; the result itself when it
|
|
67
|
+
* carries none (a host resolving to a bare string); empty when nothing came back.
|
|
68
|
+
* A result flagged `budgetExhausted` is thrown with its output as a BudgetExhaustedAnswer, one flagged `exhausted`
|
|
69
|
+
* (the iteration cap reached, its output the runtime's notice) as an IterationsExhausted. */
|
|
70
|
+
function answerOf(result: unknown): string {
|
|
71
|
+
const r = result as { output?: unknown; budgetExhausted?: unknown; exhausted?: unknown; iterations?: unknown } | null | undefined;
|
|
72
|
+
const text = String(r?.output ?? r ?? "");
|
|
73
|
+
if (r?.budgetExhausted === true) throw budgetExhaustedAnswer(text);
|
|
74
|
+
if (r?.exhausted === true) throw iterationsExhausted(r.iterations, text);
|
|
75
|
+
return text;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The model's text; the failure it stands for, thrown, when it is the host's marker. */
|
|
79
|
+
function answerOrThrow(text: string): string {
|
|
80
|
+
const failure = llmFailureOf(text);
|
|
81
|
+
if (failure) throw failure;
|
|
82
|
+
return text;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** What the adapter adds to every act: the crew's effort, the host's context (this run's when none is given), and
|
|
86
|
+
* the agent's file-system section, read from the runtime at each act. */
|
|
87
|
+
export type LlmDefaults = Pick<ActRequest, "effort"> & { host?: HostSource; fileSystem?: Pick<AgentFileSystem, "prompt"> };
|
|
88
|
+
|
|
89
|
+
/** The request with the runtime's file-system section closing its system prompt; as given without a system prompt
|
|
90
|
+
* or when the runtime gives no section (no path visible, no file-system tool, `announceMounts(false)`). */
|
|
91
|
+
function withFileSystem(request: ActRequest, fileSystem: Pick<AgentFileSystem, "prompt"> | undefined): ActRequest {
|
|
92
|
+
if (request.system === undefined || fileSystem === undefined) return request;
|
|
93
|
+
const section = fileSystem.prompt.trim();
|
|
94
|
+
return section.length === 0 ? request : { ...request, system: `${request.system.trimEnd()}\n\n${section}` };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The request the runtime receives: as given, a blank context left out. */
|
|
98
|
+
function withContext(request: ActRequest): ActRequest {
|
|
99
|
+
const { context, ...rest } = request;
|
|
100
|
+
return context === undefined || context.trim().length === 0 ? rest : request;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The part of the runtime's `ctx.llm` the adapter reads; a test's facade may lack the gate and the reasoning. */
|
|
104
|
+
type Facade = Pick<LlmFacade, "act" | "complete" | "extract" | "chat"> & Partial<Pick<LlmFacade, "permissionGate" | "reasoning">>;
|
|
105
|
+
|
|
106
|
+
export function createLlm(
|
|
107
|
+
llm: Facade,
|
|
108
|
+
callbacks?: Pick<ToolCallbacks, "forAct">,
|
|
109
|
+
defaults: LlmDefaults = {},
|
|
110
|
+
): Llm {
|
|
111
|
+
const permissionGateEnabled = (): boolean | undefined => {
|
|
112
|
+
// The runtime always sets it; a facade without it (a test's) cannot say.
|
|
113
|
+
const on = llm.permissionGate?.enabled;
|
|
114
|
+
return on === true || on === false ? on : undefined;
|
|
115
|
+
};
|
|
116
|
+
const host = defaults.host ?? orkeonHostContext;
|
|
117
|
+
return {
|
|
118
|
+
permissionGateEnabled,
|
|
119
|
+
effortSent(request) {
|
|
120
|
+
const effort = request.effort ?? defaults.effort;
|
|
121
|
+
// A facade without it (a test's, a runtime before #360) cannot say. With no effort asked, the runtime reports
|
|
122
|
+
// what the host's own configuration sends, or nothing.
|
|
123
|
+
if (llm.reasoning === undefined) return null;
|
|
124
|
+
try {
|
|
125
|
+
return effortReportOf(llm.reasoning({ ...(effort === undefined ? {} : { effort }), ...callOptions(request) }));
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
async act(prompt, request) {
|
|
131
|
+
// The crew's effort (/effort, handed as an input) when the request names none.
|
|
132
|
+
const effort = request.effort ?? defaults.effort;
|
|
133
|
+
const withEffort = effort === undefined ? request : { ...request, effort };
|
|
134
|
+
// The crew's callbacks for the act's mode (`default` when the request names none, as the runtime reads it),
|
|
135
|
+
// inside the host's.
|
|
136
|
+
const own = callbacks?.forAct(request.permissionMode ?? "default", permissionGateEnabled());
|
|
137
|
+
const acts = hostCallbacks(own, await host());
|
|
138
|
+
const sent = withFileSystem(withContext(withEffort), defaults.fileSystem);
|
|
139
|
+
return answerOrThrow(answerOf(await llm.act(prompt, actOptions(sent, acts))));
|
|
140
|
+
},
|
|
141
|
+
async complete(prompt, request?: CompleteRequest) {
|
|
142
|
+
// A system message needs the message-array call: `complete` takes a prompt only.
|
|
143
|
+
if (request?.system) {
|
|
144
|
+
const reply = await llm.chat(
|
|
145
|
+
[{ role: "system", content: request.system }, { role: "user", content: prompt }],
|
|
146
|
+
callOptions(request),
|
|
147
|
+
);
|
|
148
|
+
return answerOrThrow(String(reply?.content ?? ""));
|
|
149
|
+
}
|
|
150
|
+
return answerOrThrow(await llm.complete(prompt, callOptions(request)));
|
|
151
|
+
},
|
|
152
|
+
extract: (prompt, schema) => llm.extract<unknown>(prompt, schema as JsonSchema),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The Llm of a running agent, from the context the runtime hands its body: its `llm` facade, and its file-system
|
|
157
|
+
* section for every act's system prompt. */
|
|
158
|
+
export function agentLlm(
|
|
159
|
+
ctx: { llm: Facade; fileSystem: Pick<AgentFileSystem, "prompt"> },
|
|
160
|
+
callbacks?: Pick<ToolCallbacks, "forAct">,
|
|
161
|
+
defaults: Omit<LlmDefaults, "fileSystem"> = {},
|
|
162
|
+
): Llm {
|
|
163
|
+
return createLlm(ctx.llm, callbacks, { ...defaults, fileSystem: ctx.fileSystem });
|
|
164
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The values the Orkeon adapters write and read back: the human_input answers that came from no person.
|
|
2
|
+
|
|
3
|
+
/** The default value no option holds: an answer equal to it came from no person. */
|
|
4
|
+
export const NO_ANSWER = "(no answer)";
|
|
5
|
+
/** The first option of a `multi`: picked by the auto-approver, it decides nothing. */
|
|
6
|
+
export const DECIDE_LATER = "Decide later";
|