orkeon-code 0.0.0-stage → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +169 -0
- package/README.md +162 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +128 -0
- package/config/appsettings.kev.example.json +130 -0
- package/config/appsettings.liquid.example.json +129 -0
- package/config/appsettings.ollama-whisper.example.json +92 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +31 -0
- package/mcp/whisper/README.md +293 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +897 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +837 -0
- package/package.json +57 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
- package/src/commands/_lib/args.ts +193 -0
- package/src/commands/_lib/dev/dev-batches.ts +368 -0
- package/src/commands/_lib/dev/dev-implement.ts +188 -0
- package/src/commands/_lib/dev/dev-source.ts +65 -0
- package/src/commands/_lib/dev/dev.ts +344 -0
- package/src/commands/_lib/dev-step.ts +142 -0
- package/src/commands/_lib/dispatch.ts +231 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +95 -0
- package/src/commands/_lib/git/commit.ts +94 -0
- package/src/commands/_lib/git/diff.ts +97 -0
- package/src/commands/_lib/git/review.ts +109 -0
- package/src/commands/_lib/memory/memory-admit.ts +150 -0
- package/src/commands/_lib/memory/memory.ts +51 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/session/export.ts +104 -0
- package/src/commands/_lib/session/resume.ts +160 -0
- package/src/commands/_lib/session/tasks.ts +184 -0
- package/src/commands/_lib/settings/advisor.ts +80 -0
- package/src/commands/_lib/settings/agents.ts +147 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/hooks.ts +58 -0
- package/src/commands/_lib/settings/mode.ts +91 -0
- package/src/commands/_lib/settings/model.ts +146 -0
- package/src/commands/_lib/settings/permissions.ts +309 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +51 -0
- package/src/commands/_lib/speech/say.ts +96 -0
- package/src/commands/_lib/speech/transcribe.ts +130 -0
- package/src/commands/_lib/speech/voice.ts +146 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +186 -0
- package/src/commands/_lib/status/meta.ts +45 -0
- package/src/commands/_lib/status/status.ts +129 -0
- package/src/commands/_lib/status/usage-tools.ts +49 -0
- package/src/commands/_lib/status/usage.ts +139 -0
- package/src/commands/_lib/view.ts +29 -0
- package/src/commands/dev/dev-batches.cmd.ts +108 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +52 -0
- package/src/commands/dev/dev-spec.cmd.ts +55 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +67 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +44 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +17 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +26 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +44 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +17 -0
- package/src/commands/settings/effort.cmd.ts +40 -0
- package/src/commands/settings/fast.cmd.ts +17 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +20 -0
- package/src/commands/settings/output-style.cmd.ts +48 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +15 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +3946 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
- package/src/crews/advisor/application/run-advisor.ts +40 -0
- package/src/crews/advisor/crew.ork.ts +43 -0
- package/src/crews/advisor/domain/advice.ts +135 -0
- package/src/crews/agent-run/application/run-agent-run.ts +42 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/run-analyze.ts +118 -0
- package/src/crews/analyze/crew.ork.ts +40 -0
- package/src/crews/analyze/domain/harvest.ts +301 -0
- package/src/crews/code-review/application/prompts.ts +133 -0
- package/src/crews/code-review/application/review.ts +71 -0
- package/src/crews/code-review/application/run-code-review.ts +123 -0
- package/src/crews/code-review/crew.ork.ts +51 -0
- package/src/crews/code-review/domain/lenses.ts +193 -0
- package/src/crews/code-review/domain/report.ts +59 -0
- package/src/crews/code-review/domain/scope.ts +112 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
- package/src/crews/dev-batches/application/run-wave.ts +450 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
- package/src/crews/dev-batches/crew.ork.ts +143 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +54 -0
- package/src/crews/dev-batches/domain/wave-order.ts +43 -0
- package/src/crews/dev-change/application/change-prompt.ts +104 -0
- package/src/crews/dev-change/application/evidence.ts +169 -0
- package/src/crews/dev-change/application/run-dev-change.ts +315 -0
- package/src/crews/dev-change/crew.ork.ts +112 -0
- package/src/crews/dev-change/domain/change-answer.ts +159 -0
- package/src/crews/dev-change/domain/change-render.ts +79 -0
- package/src/crews/dev-implement/application/close.ts +183 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
- package/src/crews/dev-implement/application/observe.ts +50 -0
- package/src/crews/dev-implement/application/report-writes.ts +41 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +118 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +68 -0
- package/src/crews/dev-implement/domain/contracts.ts +256 -0
- package/src/crews/dev-implement/domain/correction.ts +102 -0
- package/src/crews/dev-implement/domain/cycles.ts +35 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/roles.ts +53 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
- package/src/crews/dev-implement/domain/step-checks.ts +136 -0
- package/src/crews/dev-implement/domain/step-section.ts +127 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
- package/src/crews/dev-learn/crew.ork.ts +52 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
- package/src/crews/dev-plan/application/inventory.ts +170 -0
- package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
- package/src/crews/dev-plan/crew.ork.ts +109 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
- package/src/crews/dev-plan/domain/plan-render.ts +307 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
- package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
- package/src/crews/dev-spec/crew.ork.ts +108 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit.ts +259 -0
- package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
- package/src/crews/dev-verify/application/capture.ts +303 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
- package/src/crews/dev-verify/application/run-gate.ts +202 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +126 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +154 -0
- package/src/crews/git-commit/application/run-git-commit.ts +116 -0
- package/src/crews/git-commit/crew.ork.ts +52 -0
- package/src/crews/git-commit/domain/commit.ts +220 -0
- package/src/crews/init-verifiers/application/authoring.ts +89 -0
- package/src/crews/init-verifiers/application/prompts.ts +103 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
- package/src/crews/init-verifiers/crew.ork.ts +34 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +77 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/run-main-loop.ts +350 -0
- package/src/crews/main-loop/application/turn-prompt.ts +112 -0
- package/src/crews/main-loop/crew.ork.ts +119 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
- package/src/crews/main-loop/domain/turn-chains.ts +129 -0
- package/src/crews/project-init/application/detect.ts +122 -0
- package/src/crews/project-init/application/prompts.ts +101 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +35 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +63 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/session-compact/crew.ork.ts +55 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
- package/src/crews/speech/application/run-speech.ts +25 -0
- package/src/crews/speech/crew.ork.ts +37 -0
- package/src/shared/application/agents/child-agent.ts +255 -0
- package/src/shared/application/agents/run-sub-agent.ts +96 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +237 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +113 -0
- package/src/shared/application/dev/close-batch.ts +83 -0
- package/src/shared/application/dev/find-repo-pack.ts +77 -0
- package/src/shared/application/dev/learn-decision.ts +252 -0
- package/src/shared/application/dev/load-dev-context.ts +266 -0
- package/src/shared/application/dev/measure-access-cost.ts +68 -0
- package/src/shared/application/dev/plan-source.ts +112 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/question-round.ts +52 -0
- package/src/shared/application/dev/resolve-work-folder.ts +133 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +55 -0
- package/src/shared/application/dev/source-review.ts +63 -0
- package/src/shared/application/dev/source-step.ts +150 -0
- package/src/shared/application/dev/spend.ts +42 -0
- package/src/shared/application/dev/step-precedents.ts +89 -0
- package/src/shared/application/dev/tool-call-policy.ts +89 -0
- package/src/shared/application/dev/tool-callbacks.ts +215 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
- package/src/shared/application/dev/verdict-sources.ts +48 -0
- package/src/shared/application/dev/wrapped-tools.ts +145 -0
- package/src/shared/application/extra-tools.ts +70 -0
- package/src/shared/application/git/batch-worktree.ts +97 -0
- package/src/shared/application/git/commit-files.ts +186 -0
- package/src/shared/application/git/merge-batch.ts +63 -0
- package/src/shared/application/git/open-pull-request.ts +51 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +35 -0
- package/src/shared/application/permission-rules.ts +159 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +13 -0
- package/src/shared/application/ports/llm.ts +54 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +27 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +84 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +177 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
- package/src/shared/application/shared-memory/memory-files.ts +110 -0
- package/src/shared/application/shared-memory/memory-settings.ts +93 -0
- package/src/shared/application/shared-memory/push-candidate.ts +146 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/workflow-state.ts +135 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/permission.ts +623 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
- package/src/shared/domain/agent-policy/tool-access.ts +77 -0
- package/src/shared/domain/agent-registry.ts +142 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +61 -0
- package/src/shared/domain/agents/exclusive.ts +24 -0
- package/src/shared/domain/agents/instances.ts +249 -0
- package/src/shared/domain/code-intel-contract.ts +356 -0
- package/src/shared/domain/code-intel-routing.ts +113 -0
- package/src/shared/domain/compact-outcome.ts +44 -0
- package/src/shared/domain/compaction-thresholds.ts +161 -0
- package/src/shared/domain/compaction.ts +379 -0
- package/src/shared/domain/config-schema.ts +421 -0
- package/src/shared/domain/dev/access-cost.ts +226 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +36 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +44 -0
- package/src/shared/domain/dev/call-guard.ts +341 -0
- package/src/shared/domain/dev/carried-text.ts +49 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +175 -0
- package/src/shared/domain/dev/learn-state.ts +93 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/plan-checks.ts +190 -0
- package/src/shared/domain/dev/plan-format.ts +180 -0
- package/src/shared/domain/dev/project-files.ts +43 -0
- package/src/shared/domain/dev/questions.ts +249 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +237 -0
- package/src/shared/domain/dev/review-answer.ts +150 -0
- package/src/shared/domain/dev/review-prompt.ts +221 -0
- package/src/shared/domain/dev/reviewer-charter.ts +31 -0
- package/src/shared/domain/dev/sheet-facts.ts +83 -0
- package/src/shared/domain/dev/spec-format.ts +183 -0
- package/src/shared/domain/dev/step-budget.ts +72 -0
- package/src/shared/domain/dev/step-rules.ts +110 -0
- package/src/shared/domain/dev/test-commands.ts +90 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +64 -0
- package/src/shared/domain/dev/trait-pattern.ts +83 -0
- package/src/shared/domain/dev/verdict-format.ts +169 -0
- package/src/shared/domain/dev/whitespace.ts +34 -0
- package/src/shared/domain/dev/work-folder.ts +67 -0
- package/src/shared/domain/dev/yaml-subset.ts +403 -0
- package/src/shared/domain/git/close.ts +273 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +106 -0
- package/src/shared/domain/llm-profile.ts +25 -0
- package/src/shared/domain/marked-message.ts +33 -0
- package/src/shared/domain/model-catalog.ts +86 -0
- package/src/shared/domain/permission-modes.ts +103 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +83 -0
- package/src/shared/domain/search-routing.ts +85 -0
- package/src/shared/domain/secret-patterns.ts +45 -0
- package/src/shared/domain/session-keys.ts +85 -0
- package/src/shared/domain/session-start.ts +60 -0
- package/src/shared/domain/session-summary.ts +13 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
- package/src/shared/domain/shared-memory/candidates.ts +41 -0
- package/src/shared/domain/shared-memory/entry.ts +145 -0
- package/src/shared/domain/shared-memory/front-matter.ts +183 -0
- package/src/shared/domain/shared-memory/gate.ts +44 -0
- package/src/shared/domain/shared-memory/harvest.ts +61 -0
- package/src/shared/domain/shared-memory/layout.ts +187 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/snip-turns.ts +45 -0
- package/src/shared/domain/speech.ts +20 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +122 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +37 -0
- package/src/shared/domain/vfs.ts +9 -0
- package/src/shared/domain/workflow/state-file.ts +140 -0
- package/src/shared/infrastructure/globals.ts +52 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
- package/src/shared/infrastructure/orkeon/files.ts +40 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
- package/src/shared/infrastructure/orkeon/llm.ts +109 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
- package/src/shared/infrastructure/orkeon/shell.ts +31 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Context gathering for the main-loop prompt assembly — orchestration + IO.
|
|
2
|
+
// Collects the data the pure ../domain/prompt-assembly renders: the project's
|
|
3
|
+
// instructions file, the memory categories, git context, the budget/cost gauge,
|
|
4
|
+
// the session preferences and registries. Every read is best-effort: a missing
|
|
5
|
+
// tool or file yields an omitted block, never a crash.
|
|
6
|
+
//
|
|
7
|
+
// The body performs ONE act() per crew run, so gathering here, lazily, costs the
|
|
8
|
+
// same as seeding at crew start — the prefix cache plays on the byte-stability of
|
|
9
|
+
// the assembled header, not on avoiding these reads.
|
|
10
|
+
|
|
11
|
+
import type { Files, MemoryStore, SessionStore, Shell, Telemetry } from "../../../shared/application/ports.ts";
|
|
12
|
+
import { readInstructionsFile } from "../../../shared/application/instructions-file.ts";
|
|
13
|
+
import { readLanguage } from "../../../shared/application/answer-language.ts";
|
|
14
|
+
import { readJsonArray } from "../../../shared/application/session-state.ts";
|
|
15
|
+
import {
|
|
16
|
+
OUTPUT_STYLE_STATE_KEY, HOOKS_STATE_KEY,
|
|
17
|
+
EFFORT_STATE_KEY, PASSES_STATE_KEY, FAST_MODE_STATE_KEY,
|
|
18
|
+
PROACTIVE_STATE_KEY, MODEL_PREFERENCE_STATE_KEY,
|
|
19
|
+
} from "../../../shared/domain/session-keys.ts";
|
|
20
|
+
import { MAX_MEMORY_ENTRIES_PER_CATEGORY } from "../domain/prompt-assembly.ts";
|
|
21
|
+
import { MEMORY_CATEGORIES } from "../../../shared/domain/agent-policy/memory-categories.ts";
|
|
22
|
+
import { resolveBehaviorFlags } from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
23
|
+
import type { BehaviorFlags } from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
24
|
+
import { WORKSPACE } from "../../../shared/domain/vfs.ts";
|
|
25
|
+
|
|
26
|
+
/** The project's instructions file (AGENTS.md, then CLAUDE.md), shared with the crews. */
|
|
27
|
+
export { readInstructionsFile };
|
|
28
|
+
|
|
29
|
+
/** The `answer.language` setting, shared with the commands that hand it to a crew. */
|
|
30
|
+
export { readLanguage };
|
|
31
|
+
|
|
32
|
+
/** Memory entries per category, read in one list call (best-effort: a store that cannot list yields none). */
|
|
33
|
+
export async function readMemoryByCategory(memory: MemoryStore): Promise<Record<string, string[]>> {
|
|
34
|
+
let entries: Awaited<ReturnType<MemoryStore["list"]>>;
|
|
35
|
+
try {
|
|
36
|
+
entries = await memory.list();
|
|
37
|
+
} catch {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
const result: Record<string, string[]> = {};
|
|
41
|
+
for (const category of MEMORY_CATEGORIES) {
|
|
42
|
+
result[category] = entries
|
|
43
|
+
.filter((e) => e.category === category)
|
|
44
|
+
.map((e) => e.content)
|
|
45
|
+
.filter((c) => c.length > 0)
|
|
46
|
+
.slice(0, MAX_MEMORY_ENTRIES_PER_CATEGORY);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** cwd + `git status --porcelain=v1 -b` (read-only, legitimate in plan mode too). */
|
|
52
|
+
export async function readGitContext(shell: Shell): Promise<{ cwd: string; gitStatus?: string }> {
|
|
53
|
+
try {
|
|
54
|
+
const r = await shell.run("git status --porcelain=v1 -b");
|
|
55
|
+
return { cwd: WORKSPACE, gitStatus: r.exitCode === 0 ? r.stdout : undefined };
|
|
56
|
+
} catch {
|
|
57
|
+
return { cwd: WORKSPACE };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Budget + cost gauge inputs (token_budget + session_stats). */
|
|
62
|
+
export async function readGauge(session: SessionStore, telemetry: Telemetry): Promise<{
|
|
63
|
+
usedTokens: number;
|
|
64
|
+
contextWindow: number;
|
|
65
|
+
costUsd: number;
|
|
66
|
+
totalTokens: number;
|
|
67
|
+
totalCalls: number;
|
|
68
|
+
}> {
|
|
69
|
+
let usedTokens = 0;
|
|
70
|
+
let contextWindow = 0;
|
|
71
|
+
let costUsd = 0;
|
|
72
|
+
let totalTokens = 0;
|
|
73
|
+
let totalCalls = 0;
|
|
74
|
+
try {
|
|
75
|
+
const b = await session.readBudget();
|
|
76
|
+
usedTokens = b.used;
|
|
77
|
+
contextWindow = b.window;
|
|
78
|
+
} catch { /* gauge degrades to zeros */ }
|
|
79
|
+
try {
|
|
80
|
+
const s = await telemetry.readStats();
|
|
81
|
+
costUsd = s.costUsd ?? 0;
|
|
82
|
+
totalTokens = s.totalTokens ?? 0;
|
|
83
|
+
totalCalls = s.totalCalls ?? 0;
|
|
84
|
+
} catch { /* gauge degrades to zeros */ }
|
|
85
|
+
return { usedTokens, contextWindow, costUsd, totalTokens, totalCalls };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── The session preferences and registries the assembly renders ──
|
|
89
|
+
//
|
|
90
|
+
// These reads are best-effort in the same way as the rest of this module: an
|
|
91
|
+
// unavailable session store yields an omitted block, never a failed turn. The
|
|
92
|
+
// attached skills are read by shared/application/attached-skills.ts, which the
|
|
93
|
+
// compaction shares.
|
|
94
|
+
|
|
95
|
+
// State keys come from shared/domain/session-keys.ts: the writer is a command,
|
|
96
|
+
// the reader is here, and a duplicated literal would let the two desync silently.
|
|
97
|
+
|
|
98
|
+
/** The /output-style session preference; "default" when unset (renders nothing). */
|
|
99
|
+
export async function readOutputStyle(session: SessionStore): Promise<string> {
|
|
100
|
+
try {
|
|
101
|
+
return (await session.readState(OUTPUT_STYLE_STATE_KEY)) ?? "default";
|
|
102
|
+
} catch {
|
|
103
|
+
return "default";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The five behavior flags plus the /model override, in ONE read.
|
|
109
|
+
*
|
|
110
|
+
* Read together and resolved by the pure `resolveBehaviorFlags` so the turn gets
|
|
111
|
+
* a consistent snapshot and every fallback lives in one tested place. A session
|
|
112
|
+
* store that is absent yields the defaults — i.e. exactly the pre-B-9 behaviour.
|
|
113
|
+
*/
|
|
114
|
+
export async function readBehaviorFlags(session: SessionStore): Promise<BehaviorFlags> {
|
|
115
|
+
const read = async (key: string) => {
|
|
116
|
+
try {
|
|
117
|
+
return await session.readState(key);
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const [effort, passes, fast, proactive, model] = await Promise.all([
|
|
123
|
+
read(EFFORT_STATE_KEY), read(PASSES_STATE_KEY), read(FAST_MODE_STATE_KEY),
|
|
124
|
+
read(PROACTIVE_STATE_KEY), read(MODEL_PREFERENCE_STATE_KEY),
|
|
125
|
+
]);
|
|
126
|
+
return resolveBehaviorFlags({ effort, passes, fast, proactive, model });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The declared /hooks registry (rendered with its not-running status). */
|
|
130
|
+
export async function readHooks(session: SessionStore): Promise<Array<{ event?: string; command?: string }>> {
|
|
131
|
+
return (await readJsonArray(session, HOOKS_STATE_KEY))
|
|
132
|
+
.filter((h): h is { event?: string; command?: string } => !!h && typeof h === "object");
|
|
133
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
// MainLoop use case — one turn of the interactive loop: run in the mode the
|
|
2
|
+
// launching command resolved, keep the session buffer, compact around the turn,
|
|
3
|
+
// assemble the prompt (F4) and run the autonomous act() call. The turn's messages are
|
|
4
|
+
// built by ./turn-prompt, the breaker by ./auto-compact; every dependency comes
|
|
5
|
+
// in through the ports.
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
MEMORY_TOOLS, catalogueFor, parseStoredRule, resolvePermissionMode, scriptToolsFor,
|
|
9
|
+
} from "../../../shared/domain/agent-policy/permission.ts";
|
|
10
|
+
import type { CatalogueDecision, ExtraTool } from "../../../shared/domain/agent-policy/permission.ts";
|
|
11
|
+
import { parseExtraTools } from "../../../shared/domain/agent-policy/extra-tools.ts";
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_BEHAVIOR_FLAGS, describeActiveFlags, maxIterationsFor,
|
|
14
|
+
} from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
15
|
+
import type { BehaviorFlags } from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
16
|
+
import type { Llm, Logger, ToolCatalogue } from "../../../shared/application/ports.ts";
|
|
17
|
+
import {
|
|
18
|
+
applyPrelude, epilogueArgs, errorText, parseEpilogue, parsePrelude, toolFailure,
|
|
19
|
+
} from "../../../shared/domain/prelude.ts";
|
|
20
|
+
import type { PreludeCall } from "../../../shared/domain/prelude.ts";
|
|
21
|
+
import { budgetExhaustedAnswerOf, decisionBlockOf, decisionBlockText } from "../../../shared/domain/llm-failure.ts";
|
|
22
|
+
import type { SessionIo } from "../../../shared/application/session-io.ts";
|
|
23
|
+
import { stateSnapshot } from "../../../shared/application/state-snapshot.ts";
|
|
24
|
+
import {
|
|
25
|
+
AUTOCOMPACT_BREAKER_STATE_KEY, EFFORT_STATE_KEY, FAST_MODE_STATE_KEY, HOOKS_STATE_KEY, MODEL_PREFERENCE_STATE_KEY,
|
|
26
|
+
OUTPUT_STYLE_STATE_KEY, PASSES_STATE_KEY, PROACTIVE_STATE_KEY, SKILLS_STATE_KEY,
|
|
27
|
+
} from "../../../shared/domain/session-keys.ts";
|
|
28
|
+
import type { ToolTrace } from "../../../shared/application/dev/tool-trace-recorder.ts";
|
|
29
|
+
import { readBehaviorFlags } from "./context-gather.ts";
|
|
30
|
+
import { autoCompactGuarded } from "./auto-compact.ts";
|
|
31
|
+
import type { AutoCompactDeps } from "./auto-compact.ts";
|
|
32
|
+
import { buildTurnPrompt } from "./turn-prompt.ts";
|
|
33
|
+
import type { TurnContextDeps, TurnPrompt } from "./turn-prompt.ts";
|
|
34
|
+
import {
|
|
35
|
+
STOP_GUARDS, TURN_START_GUARDS, buildStopRetryPrompt, buildTurnContextMessage, readClosingLine, refusedTurnText,
|
|
36
|
+
runChain,
|
|
37
|
+
} from "../domain/turn-chains.ts";
|
|
38
|
+
import type { Guard, StopFacts, TurnStartFacts } from "../domain/turn-chains.ts";
|
|
39
|
+
import { readStartOutput } from "../../../shared/domain/session-start.ts";
|
|
40
|
+
import { llmProfileOf } from "../../../shared/domain/llm-profile.ts";
|
|
41
|
+
|
|
42
|
+
/** The crew's input, as launchMainLoop (/assistant, /summary, /transcribe --then, /voice send and --go) passes it. */
|
|
43
|
+
export interface MainLoopInputs {
|
|
44
|
+
prompt?: unknown;
|
|
45
|
+
/** The mode of the turn, resolved by the launching command: the request's
|
|
46
|
+
* `mode:` prefix, else the session's. Absent, the turn runs in `default`. */
|
|
47
|
+
permissionMode?: unknown;
|
|
48
|
+
/** Where a mode the request did not name came from ("session default via /mode"). */
|
|
49
|
+
permissionModeVia?: unknown;
|
|
50
|
+
/** The session's rules ("deny file_write"), threaded by launchMainLoop, which
|
|
51
|
+
* has handed them to the host gate already. */
|
|
52
|
+
permissionRules?: unknown[];
|
|
53
|
+
/** The extra tools the host registers ("search_issues:write"), filtered by launchMainLoop. */
|
|
54
|
+
extraTools?: unknown[];
|
|
55
|
+
/** The session's `llm.profile`, as launchCrew hands it: every agent of the crew runs on it, and the
|
|
56
|
+
* /model override is not sent under it (the profile names the model). */
|
|
57
|
+
llmProfile?: unknown;
|
|
58
|
+
/** A tool call the launching command asks for before the turn ({ tool, args, label, as? }):
|
|
59
|
+
* /transcribe --then hands over the transcription this way, its result following the
|
|
60
|
+
* request under its label in the message the model reads and the session keeps;
|
|
61
|
+
* /voice --go its dictation, which is the request itself (`as: "request"`). */
|
|
62
|
+
prelude?: unknown;
|
|
63
|
+
/** A tool call the launching command asks for after the turn, with the answer
|
|
64
|
+
* ({ tool, args, textArg, label }): voice.reply reads the answer aloud this way.
|
|
65
|
+
* A failure is a warning; the turn and its answer stand. */
|
|
66
|
+
epilogue?: unknown;
|
|
67
|
+
/** What the session's start script printed ({ script, lines }), on the first free-text
|
|
68
|
+
* turn of a session only: /assistant takes it off the runtime's raw input. */
|
|
69
|
+
sessionStart?: unknown;
|
|
70
|
+
/** The text a line of the answer must start with: an answer without it goes back once. */
|
|
71
|
+
closingLine?: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The tool catalogue the agent is built with, the mode it was built for, and the
|
|
75
|
+
* extra tools it was built with. */
|
|
76
|
+
export interface LoadedCatalogue {
|
|
77
|
+
mode: string;
|
|
78
|
+
extras: ExtraTool[];
|
|
79
|
+
catalogue: CatalogueDecision;
|
|
80
|
+
/** Orkeon Code's own tools the mode offers under the rules (the shared memory's), attached by name. */
|
|
81
|
+
scriptTools: string[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The catalogue, decided at load time — module scope is synchronous — from the
|
|
86
|
+
* inputs alone: the launching command resolved the mode (the session's too) and
|
|
87
|
+
* the extra tools before the crew loads, so the catalogue, the act call and the
|
|
88
|
+
* host gate all run in the same mode. Launched without a mode (scripts/run-crew.sh),
|
|
89
|
+
* the turn runs in `default`. That run is headless: no operator to ask and no
|
|
90
|
+
* session rules, so a gate turned on (the example settings do) REFUSES each call
|
|
91
|
+
* the mode would ask about — every write, every command, every network read — and
|
|
92
|
+
* the model reads `DENIED: …`. A `permissionMode` input lets them run
|
|
93
|
+
* (`--inputs '{"prompt":"…","permissionMode":"bypassPermissions"}'`).
|
|
94
|
+
*
|
|
95
|
+
* The rules are the host gate's to enforce (launchMainLoop handed them over);
|
|
96
|
+
* the catalogue only drops the tools a deny rule covers whole, so the model is
|
|
97
|
+
* not offered a tool whose every call would be refused.
|
|
98
|
+
*/
|
|
99
|
+
export function loadCatalogue(input: MainLoopInputs): LoadedCatalogue {
|
|
100
|
+
const mode = resolvePermissionMode(input.permissionMode);
|
|
101
|
+
const extras = parseExtraTools(input.extraTools ?? []).tools;
|
|
102
|
+
const extraNames = extras.map((t) => t.name);
|
|
103
|
+
const rules = (input.permissionRules ?? [])
|
|
104
|
+
.map((raw) => parseStoredRule(raw, extraNames))
|
|
105
|
+
.filter((r): r is NonNullable<typeof r> => r !== null);
|
|
106
|
+
return { mode, extras, catalogue: catalogueFor(mode, rules, extras), scriptTools: scriptToolsFor(mode, MEMORY_TOOLS, rules) };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Where the mode of the turn came from, when the request did not name it. */
|
|
110
|
+
function modeOrigin(input: MainLoopInputs): string | null {
|
|
111
|
+
if (typeof input.permissionModeVia === "string" && input.permissionModeVia.length > 0) return input.permissionModeVia;
|
|
112
|
+
return input.permissionMode == null ? "no mode given at launch, built-in 'default'" : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Append one turn to the session buffer (best-effort — continuity across runs).
|
|
116
|
+
* Stores the RAW prompt, never the assembled one: the buffer is the conversation
|
|
117
|
+
* thread — embedding assembled prompts would re-nest quadratically and break the
|
|
118
|
+
* byte-stable cache prefix. */
|
|
119
|
+
export async function appendTurn(session: Pick<SessionIo, "appendMessage">, role: string, content: string): Promise<void> {
|
|
120
|
+
try {
|
|
121
|
+
await session.appendMessage(role, content);
|
|
122
|
+
} catch { /* session buffer optional */ }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Run the autonomous tool-use loop and return its text output.
|
|
127
|
+
*
|
|
128
|
+
* `permissionMode` is consumed by the host's per-tool-call gate, which reads the
|
|
129
|
+
* session's rules first and asks the operator when the mode says so. `maxIterations` and, when /effort stored a level,
|
|
130
|
+
* the provider's `effort` come from `/effort` (B-9, A-3), and the optional
|
|
131
|
+
* model from `/model` (B-10) — the latter PATCHES the provider's own
|
|
132
|
+
* configuration, so the boot credentials and endpoint are preserved and only the
|
|
133
|
+
* model name changes for this call.
|
|
134
|
+
*/
|
|
135
|
+
export async function runAct(
|
|
136
|
+
deps: { llm: Pick<Llm, "act">; log: Logger },
|
|
137
|
+
turn: TurnPrompt,
|
|
138
|
+
mode: string,
|
|
139
|
+
flags: BehaviorFlags = DEFAULT_BEHAVIOR_FLAGS,
|
|
140
|
+
): Promise<string> {
|
|
141
|
+
const active = describeActiveFlags(flags);
|
|
142
|
+
// Anything off-default is announced: a turn that stops after 10 iterations, or
|
|
143
|
+
// answers from a different model, must not read as the model being erratic.
|
|
144
|
+
if (active) deps.log.info(`session flags — ${active}`);
|
|
145
|
+
const maxIterations = maxIterationsFor(flags.effort);
|
|
146
|
+
// A level /effort stored reaches the provider (A-3); the line says what this act was given.
|
|
147
|
+
if (flags.thinking !== null) deps.log.info(`act — effort: ${flags.thinking}, maxIterations: ${maxIterations}`);
|
|
148
|
+
|
|
149
|
+
return await deps.llm.act(turn.request, {
|
|
150
|
+
maxIterations,
|
|
151
|
+
...(flags.thinking === null ? {} : { effort: flags.thinking }),
|
|
152
|
+
permissionMode: mode,
|
|
153
|
+
// The static header rides as a REAL system message (ActOptions.system):
|
|
154
|
+
// identity and tool policy outrank user text and tool results, and the
|
|
155
|
+
// provider's native system handling (Anthropic top-level `system`,
|
|
156
|
+
// cache_control) finally applies.
|
|
157
|
+
system: turn.system,
|
|
158
|
+
// The volatile blocks ride as a user message of their own before the request
|
|
159
|
+
// (ActOptions.context, Orkeon #276): a decision guard judges the request alone.
|
|
160
|
+
context: turn.context,
|
|
161
|
+
model: flags.model,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The ports one turn runs on. */
|
|
166
|
+
export interface MainLoopDeps extends TurnContextDeps, Omit<AutoCompactDeps, "session"> {
|
|
167
|
+
session: SessionIo;
|
|
168
|
+
llm: Pick<Llm, "act" | "permissionGateEnabled">;
|
|
169
|
+
/** The calls of a prelude and an epilogue, by the registered name the launching command found. */
|
|
170
|
+
tools: Pick<ToolCatalogue, "callText">;
|
|
171
|
+
/** The recorder of the act's tool calls (dev/tool-trace-recorder); absent, the turn stores no [tools] message. */
|
|
172
|
+
trace?: Pick<ToolTrace, "take">;
|
|
173
|
+
/** The guards of the two chains; absent, the built-in ones (domain/turn-chains). */
|
|
174
|
+
chains?: { turnStart?: ReadonlyArray<Guard<TurnStartFacts>>; stop?: ReadonlyArray<Guard<StopFacts>> };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The request once the prelude's call answered (applyPrelude). */
|
|
178
|
+
async function withPreludeResult(request: string, prelude: PreludeCall, deps: Pick<MainLoopDeps, "tools" | "log">): Promise<string> {
|
|
179
|
+
deps.log.info(`${prelude.label}: ${prelude.tool}, before the turn`);
|
|
180
|
+
const outcome = await deps.tools.callText(prelude.tool, prelude.args);
|
|
181
|
+
if (!outcome.ok) throw toolFailure(prelude.tool, outcome.failure);
|
|
182
|
+
return applyPrelude(request, prelude, outcome.text);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The epilogue the input names, with the answer; a failure is logged, never thrown. */
|
|
186
|
+
async function runEpilogue(value: unknown, answer: string, deps: Pick<MainLoopDeps, "tools" | "log">): Promise<void> {
|
|
187
|
+
const epilogue = parseEpilogue(value);
|
|
188
|
+
if (epilogue === null || answer.trim().length === 0) return;
|
|
189
|
+
const outcome = await deps.tools.callText(epilogue.tool, epilogueArgs(epilogue, answer));
|
|
190
|
+
if (outcome.ok) deps.log.info(`${epilogue.label}: ${outcome.text.trim() || epilogue.tool}`);
|
|
191
|
+
else deps.log.warn(`${epilogue.label}: ${epilogue.tool} failed: ${outcome.failure}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The session state key remembering that the operator was told the gate is off. */
|
|
195
|
+
const GATE_WARNED_KEY = "gate.warned";
|
|
196
|
+
|
|
197
|
+
/** The line the operator reads ONCE per session when the host says its permission gate
|
|
198
|
+
* is off (Orkeon #128): every tool call of the turn runs unchecked, whatever the mode
|
|
199
|
+
* promises. Nothing in bypassPermissions, which promises nothing, nor on a host that
|
|
200
|
+
* cannot say. Shown above the answer, logged, never stored in the transcript. */
|
|
201
|
+
async function gateWarning(mode: string, deps: Pick<MainLoopDeps, "llm" | "session" | "log">): Promise<string | null> {
|
|
202
|
+
if (mode === "bypassPermissions" || deps.llm.permissionGateEnabled() !== false) return null;
|
|
203
|
+
if (await deps.session.readState(GATE_WARNED_KEY) !== null) return null;
|
|
204
|
+
await deps.session.writeState(GATE_WARNED_KEY, "1");
|
|
205
|
+
const text = "⚠ the host's permission gate is off (Orkeon:Security:PermissionGate:Enabled is not true): " +
|
|
206
|
+
`mode '${mode}' and the session's rules check nothing, every tool call runs. /permissions shows it.`;
|
|
207
|
+
deps.log.warn(text);
|
|
208
|
+
return text;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The line shown under an answer the token budget cut short (Orkeon #218, the context counted once since #224):
|
|
212
|
+
* the model's last call, made without tools once the crew's budget was spent. */
|
|
213
|
+
export const BUDGET_EXHAUSTED_LINE =
|
|
214
|
+
"⚠ the turn stopped on its token budget: the answer above is the model's wrap-up, made without tools, and may be cut short";
|
|
215
|
+
|
|
216
|
+
/** The answer of a turn, and whether the token budget cut it short. */
|
|
217
|
+
interface TurnAnswer { answer: string; cut: boolean }
|
|
218
|
+
|
|
219
|
+
/** The answer once the stop chain read it: a refused answer goes back to the model ONCE,
|
|
220
|
+
* with the reason, and the second answer stands whatever the chain would say of it. When that
|
|
221
|
+
* retry throws, a first answer that is not blank stands, with a warning. An act whose token
|
|
222
|
+
* budget ran out (BudgetExhaustedAnswer) gives its wrap-up as the answer, `cut`, and goes
|
|
223
|
+
* through no stop check: a second act would meet the same spent budget. */
|
|
224
|
+
async function stopChecked(
|
|
225
|
+
deps: Pick<MainLoopDeps, "llm" | "log" | "chains">, turn: TurnPrompt, mode: string, flags: BehaviorFlags,
|
|
226
|
+
request: string, closingLine: string | null,
|
|
227
|
+
): Promise<TurnAnswer> {
|
|
228
|
+
let answer: string;
|
|
229
|
+
try {
|
|
230
|
+
answer = await runAct(deps, turn, mode, flags);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
const exhausted = budgetExhaustedAnswerOf(error);
|
|
233
|
+
if (exhausted === null) throw error;
|
|
234
|
+
deps.log.warn(`the token budget ran out: the model's wrap-up is the answer (${errorText(error)})`);
|
|
235
|
+
return { answer: exhausted.answer, cut: true };
|
|
236
|
+
}
|
|
237
|
+
const stop = runChain("stop", deps.chains?.stop ?? STOP_GUARDS, { request, answer, closingLine });
|
|
238
|
+
if (stop.refusedBy === undefined) return { answer, cut: false };
|
|
239
|
+
deps.log.info(`stop check '${stop.refusedBy}': the answer goes back once (${stop.reason})`);
|
|
240
|
+
try {
|
|
241
|
+
return { answer: await runAct(deps, { ...turn, request: buildStopRetryPrompt(turn.request, answer, stop.reason ?? "") }, mode, flags), cut: false };
|
|
242
|
+
} catch (error) {
|
|
243
|
+
// A retry that fails (a provider error) never costs the turn an answer it had: the first one stands, said.
|
|
244
|
+
if (answer.trim().length === 0) throw error;
|
|
245
|
+
deps.log.warn(`stop check '${stop.refusedBy}': the retry failed (${errorText(error)}); the first answer stands`);
|
|
246
|
+
return { answer, cut: false };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The flags of a turn under the session's `llm.profile`: the profile names the model, so a /model override is
|
|
251
|
+
* dropped and said once for the turn. Sent as the per-call model, it would replace the profile's own model, and a
|
|
252
|
+
* decision profile's escalation target with it (the runtime patches the same call configuration onto both). */
|
|
253
|
+
function underProfile(flags: BehaviorFlags, profile: string | null, log: Pick<Logger, "warn">): BehaviorFlags {
|
|
254
|
+
if (profile === null || flags.model === "") return flags;
|
|
255
|
+
log.warn(`/model override '${flags.model}' ignored: llm.profile ${profile} is active`);
|
|
256
|
+
return { ...flags, model: "" };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The state keys a turn reads, in ONE session_store call at its start (Orkeon #263): the behaviour flags, the
|
|
260
|
+
* output style, the hooks, the skills, the compaction breaker (read at the head and the tail) and the gate's
|
|
261
|
+
* warning. A key read and missing here costs its own call, as before. */
|
|
262
|
+
const TURN_STATE_KEYS = [
|
|
263
|
+
EFFORT_STATE_KEY, PASSES_STATE_KEY, FAST_MODE_STATE_KEY, PROACTIVE_STATE_KEY, MODEL_PREFERENCE_STATE_KEY,
|
|
264
|
+
OUTPUT_STYLE_STATE_KEY, HOOKS_STATE_KEY, SKILLS_STATE_KEY, AUTOCOMPACT_BREAKER_STATE_KEY, GATE_WARNED_KEY,
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
/** One turn: the answer, or why there was none. */
|
|
268
|
+
export async function runMainLoop(input: MainLoopInputs, loaded: LoadedCatalogue, given: MainLoopDeps): Promise<string> {
|
|
269
|
+
const request = String(input.prompt ?? "").trim();
|
|
270
|
+
const prelude = parsePrelude(input.prelude);
|
|
271
|
+
if (request.length === 0 && prelude?.as !== "request") return "No prompt provided.";
|
|
272
|
+
// Every reader of the turn reads the state bag through this session: its keys come from one batch read.
|
|
273
|
+
const session: SessionIo = { ...given.session, ...await stateSnapshot(given.session, TURN_STATE_KEYS) };
|
|
274
|
+
const deps: MainLoopDeps = { ...given, session };
|
|
275
|
+
const { log } = deps;
|
|
276
|
+
// The prelude runs first, as the launching command's call (the gate does not ask):
|
|
277
|
+
// a failure fails the run before any message is stored or any model is called.
|
|
278
|
+
const prompt = prelude === null ? request : await withPreludeResult(request, prelude, deps);
|
|
279
|
+
if (prompt.length === 0) return `Nothing to send: ${prelude?.label ?? "the request"} came back empty.`;
|
|
280
|
+
|
|
281
|
+
// The mode the catalogue was built for: the "mode:" prefix, else the session
|
|
282
|
+
// default set by /mode, else the fallback (B-2 — built-in 'default' like the
|
|
283
|
+
// original, or the opt-in 'permissions.fallback'), as the command resolved it.
|
|
284
|
+
const { mode } = loaded;
|
|
285
|
+
// Logged on EVERY turn the request did not name the mode of, not only when
|
|
286
|
+
// /mode set one: a session running the fallback is exactly the case that used
|
|
287
|
+
// to say nothing.
|
|
288
|
+
const origin = modeOrigin(input);
|
|
289
|
+
if (origin) log.info(`permission mode '${mode}' — ${origin}`);
|
|
290
|
+
// A rule that changed the catalogue must announce itself. A catalogue silently
|
|
291
|
+
// short of a tool is indistinguishable from a mode that never had it.
|
|
292
|
+
const { catalogue } = loaded;
|
|
293
|
+
if (catalogue.deniedByRule.length > 0) {
|
|
294
|
+
log.warn(`permission rules removed: ${catalogue.deniedByRule.join(", ")}`);
|
|
295
|
+
}
|
|
296
|
+
for (const r of catalogue.inert) log.warn(`permission rule without effect: ${r.reason}`);
|
|
297
|
+
const warning = await gateWarning(mode, deps);
|
|
298
|
+
|
|
299
|
+
// B-9 / B-10: the persisted behavior flags, read ONCE per turn so prompt
|
|
300
|
+
// assembly and the act() call cannot disagree about them mid-turn.
|
|
301
|
+
const flags = underProfile(await readBehaviorFlags(session), llmProfileOf(input as Record<string, unknown>), log);
|
|
302
|
+
|
|
303
|
+
// turn-start: a refusal ends the turn before anything is stored or any model is
|
|
304
|
+
// called; the context lines are stored just before the request, so this turn and
|
|
305
|
+
// the later ones read them in the history.
|
|
306
|
+
const start = runChain("turn-start", deps.chains?.turnStart ?? TURN_START_GUARDS, {
|
|
307
|
+
request: prompt, sessionStart: readStartOutput(input.sessionStart),
|
|
308
|
+
});
|
|
309
|
+
if (start.refusedBy !== undefined) {
|
|
310
|
+
const text = refusedTurnText(start);
|
|
311
|
+
log.warn(text);
|
|
312
|
+
return text;
|
|
313
|
+
}
|
|
314
|
+
if (start.context.length > 0) await appendTurn(session, "user", buildTurnContextMessage(start.context));
|
|
315
|
+
|
|
316
|
+
await appendTurn(session, "user", prompt);
|
|
317
|
+
// Head-of-turn auto-compaction (F3): act() starts from a healthy buffer.
|
|
318
|
+
await autoCompactGuarded(deps);
|
|
319
|
+
const assembled = await buildTurnPrompt(prompt, mode, flags, deps, loaded.extras, loaded.scriptTools);
|
|
320
|
+
// A turn the provider failed throws (LlmFailure), as any failure of act does:
|
|
321
|
+
// no answer is stored, the tail compaction does not run (the breaker counts
|
|
322
|
+
// compactions, not turns), and the run fails with the provider's error, which
|
|
323
|
+
// /assistant shows. The user's message stays in the buffer.
|
|
324
|
+
// A call a decision stage blocked (DecisionBlockedError) is a decision, not an outage: the turn ends
|
|
325
|
+
// with the block said, nothing stored after the user's message but the [tools] message of the calls that
|
|
326
|
+
// ran before it (an edit made on disk stays on record), the run not failed.
|
|
327
|
+
// The calls of a head-of-turn compaction are not the answer's: the trace starts with the act.
|
|
328
|
+
deps.trace?.take();
|
|
329
|
+
let checked: { answer: string; cut: boolean };
|
|
330
|
+
try {
|
|
331
|
+
checked = await stopChecked(deps, assembled, mode, flags, prompt, readClosingLine(input.closingLine));
|
|
332
|
+
} catch (error) {
|
|
333
|
+
const block = decisionBlockOf(error);
|
|
334
|
+
if (block === null) throw error;
|
|
335
|
+
const ran = deps.trace?.take() ?? null;
|
|
336
|
+
if (ran !== null) await appendTurn(session, "system", ran);
|
|
337
|
+
const text = decisionBlockText(block);
|
|
338
|
+
log.warn(text);
|
|
339
|
+
return [warning, text].filter((part) => part !== null).join("\n\n");
|
|
340
|
+
}
|
|
341
|
+
const { answer, cut } = checked;
|
|
342
|
+
const traced = deps.trace?.take() ?? null;
|
|
343
|
+
if (traced !== null) await appendTurn(session, "system", traced);
|
|
344
|
+
await appendTurn(session, "assistant", answer);
|
|
345
|
+
await runEpilogue(input.epilogue, answer, deps);
|
|
346
|
+
// Tail-of-turn: a verbose act() must not bequeath a saturated buffer.
|
|
347
|
+
await autoCompactGuarded(deps);
|
|
348
|
+
// The budget line is shown, never stored: the transcript keeps what the model said.
|
|
349
|
+
return [warning, answer, cut ? BUDGET_EXHAUSTED_LINE : null].filter((part) => part !== null).join("\n\n");
|
|
350
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// The act() messages of one main-loop turn: the reads of context-gather,
|
|
2
|
+
// rendered by the pure ../domain/prompt-assembly. The permission/toolset logic is
|
|
3
|
+
// pure in shared/domain/agent-policy/permission.
|
|
4
|
+
|
|
5
|
+
import { buildActPrompt, toolsetFor } from "../../../shared/domain/agent-policy/permission.ts";
|
|
6
|
+
import { proactiveSuffix } from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
7
|
+
import type { BehaviorFlags } from "../../../shared/domain/agent-policy/behavior-flags.ts";
|
|
8
|
+
import {
|
|
9
|
+
assembleContext,
|
|
10
|
+
buildGaugeBlock,
|
|
11
|
+
buildHistoryBlock,
|
|
12
|
+
buildMemoryBlock,
|
|
13
|
+
buildStaticHeader,
|
|
14
|
+
buildUserContextBlock,
|
|
15
|
+
windowHistory,
|
|
16
|
+
withoutCurrentRequest,
|
|
17
|
+
buildPreferencesBlock,
|
|
18
|
+
buildSkillsBlock,
|
|
19
|
+
buildHooksBlock,
|
|
20
|
+
} from "../domain/prompt-assembly.ts";
|
|
21
|
+
import {
|
|
22
|
+
readInstructionsFile, readGauge, readGitContext, readLanguage, readMemoryByCategory,
|
|
23
|
+
readOutputStyle, readHooks,
|
|
24
|
+
} from "./context-gather.ts";
|
|
25
|
+
import { readAttachedSkills } from "../../../shared/application/attached-skills.ts";
|
|
26
|
+
import type { AttachedSkill } from "../../../shared/application/attached-skills.ts";
|
|
27
|
+
import type { ConfigStore } from "../../../shared/application/config-store.ts";
|
|
28
|
+
import type { Clock, Files, MemoryStore, SessionStore, Shell, Telemetry } from "../../../shared/application/ports.ts";
|
|
29
|
+
import { isoDay } from "../../../shared/domain/iso-day.ts";
|
|
30
|
+
import type { SessionMsg } from "../../../shared/domain/types.ts";
|
|
31
|
+
import type { ExtraTool } from "../../../shared/domain/agent-policy/permission.ts";
|
|
32
|
+
|
|
33
|
+
/** The ports the prompt of a turn is gathered from. */
|
|
34
|
+
export interface TurnContextDeps {
|
|
35
|
+
shell: Shell;
|
|
36
|
+
session: SessionStore;
|
|
37
|
+
files: Files;
|
|
38
|
+
telemetry: Telemetry;
|
|
39
|
+
memory: MemoryStore;
|
|
40
|
+
/** The layered settings, for the answer language; absent = no language preference. */
|
|
41
|
+
config?: Pick<ConfigStore, "readValue">;
|
|
42
|
+
/** The time now: the environment block carries its UTC day. */
|
|
43
|
+
clock: Clock;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One act() turn's messages: the byte-stable system prompt, the volatile context, the request. */
|
|
47
|
+
export interface TurnPrompt {
|
|
48
|
+
system: string;
|
|
49
|
+
/** The user message before the request (`ActOptions.context`); empty when no block renders. */
|
|
50
|
+
context: string;
|
|
51
|
+
/** The prompt: the request, its permission note, the proactive clause — the last user message. */
|
|
52
|
+
request: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Assemble the act() messages of this turn: the byte-stable static header
|
|
57
|
+
* (behaviour rules + tools + the project's instructions file) is the SYSTEM prompt,
|
|
58
|
+
* the volatile blocks (preferences, skills, memory, hooks, environment, windowed
|
|
59
|
+
* history, budget gauge) are the CONTEXT, and the request is the prompt, alone in the
|
|
60
|
+
* last user message: the message a decision profile's guard judges (Orkeon #276).
|
|
61
|
+
*/
|
|
62
|
+
export async function buildTurnPrompt(
|
|
63
|
+
prompt: string,
|
|
64
|
+
mode: string,
|
|
65
|
+
flags: BehaviorFlags,
|
|
66
|
+
deps: TurnContextDeps,
|
|
67
|
+
extras: readonly ExtraTool[] = [],
|
|
68
|
+
scriptTools: readonly string[] = [],
|
|
69
|
+
): Promise<TurnPrompt> {
|
|
70
|
+
// /fast: skip the two advisory reads entirely, not just their rendering.
|
|
71
|
+
// Rendering-only would keep paying for the memory listing and every skill file
|
|
72
|
+
// read — the latency the flag exists to buy.
|
|
73
|
+
const wantAdvisory = !flags.fast;
|
|
74
|
+
const { shell, session, files, telemetry } = deps;
|
|
75
|
+
const [instructions, memory, git, history, gauge, outputStyle, hooks, skills, language] = await Promise.all([
|
|
76
|
+
readInstructionsFile(files),
|
|
77
|
+
wantAdvisory ? readMemoryByCategory(deps.memory) : Promise.resolve({} as Record<string, string[]>),
|
|
78
|
+
readGitContext(shell),
|
|
79
|
+
session.readMessages().then((read) => read.messages).catch(() => [] as SessionMsg[]),
|
|
80
|
+
readGauge(session, telemetry),
|
|
81
|
+
readOutputStyle(session),
|
|
82
|
+
readHooks(session),
|
|
83
|
+
wantAdvisory ? readAttachedSkills(session, files) : Promise.resolve([] as AttachedSkill[]),
|
|
84
|
+
readLanguage(deps.config),
|
|
85
|
+
]);
|
|
86
|
+
const today = isoDay(deps.clock());
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
system: buildStaticHeader({ toolNames: toolsetFor(mode, extras), scriptTools, instructions }),
|
|
90
|
+
context: assembleContext({
|
|
91
|
+
// All volatile, all in the context. An unconfigured session renders none
|
|
92
|
+
// of the optional blocks.
|
|
93
|
+
preferences: buildPreferencesBlock({ outputStyle, language }),
|
|
94
|
+
skills: buildSkillsBlock(skills),
|
|
95
|
+
memory: buildMemoryBlock(memory),
|
|
96
|
+
hooks: buildHooksBlock(hooks),
|
|
97
|
+
userContext: buildUserContextBlock({ ...git, date: today }),
|
|
98
|
+
// The buffer already ends with this request: the task block carries it.
|
|
99
|
+
history: buildHistoryBlock(windowHistory(withoutCurrentRequest(history, prompt))),
|
|
100
|
+
gauge: buildGaugeBlock(gauge),
|
|
101
|
+
}),
|
|
102
|
+
// /proactive: the clause rides with the request, the last thing the model reads.
|
|
103
|
+
request: "## Request\n" + buildActPrompt(prompt, mode) + proactiveSuffix(flags.proactive),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Freshness note: the loop deliberately has NO post-edit reindex step.
|
|
108
|
+
// Coordination lives host-side — file_write marks the path dirty (the store hook),
|
|
109
|
+
// shell edits are caught by the git working-tree probe, and the search tools
|
|
110
|
+
// reindex the union BEFORE answering (lazy, grouped, single-flight). Adding a loop
|
|
111
|
+
// step here would double the work and re-introduce the "agent must remember"
|
|
112
|
+
// failure mode the lazy design exists to remove.
|