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,399 @@
|
|
|
1
|
+
// One path, many spellings. The runtime maps a virtual path (`/workspace/src/a.ts`) to the disk, but the disk's own
|
|
2
|
+
// spellings come back to the code and to the model in what a program prints, in what the user types and in what the
|
|
3
|
+
// model writes: `C:\ici est\mon repertoire\src\a.ts` on Windows, `/mnt/c/ici est/mon repertoire/src/a.ts` under WSL,
|
|
4
|
+
// `\\wsl.localhost\Ubuntu\home\me\x` for a Linux folder seen from Windows, `C:/…` from git for Windows. These functions
|
|
5
|
+
// bring every such spelling back to the one canonical spelling, the virtual path with `/` and no trailing separator,
|
|
6
|
+
// from the bases a HostLayout holds (docs/architecture.md, "The VFS and the host platform"). They never produce a
|
|
7
|
+
// physical spelling for the runtime: a command leaves the code with virtual paths, which the runtime checks against the
|
|
8
|
+
// VFS rights before it spells them for the process (ADR 0022). On IDENTITY_HOST every function is the identity. Pure.
|
|
9
|
+
import { sameToolName } from "./agent-policy/permission.ts";
|
|
10
|
+
import { type HostLayout, type MountBase, isIdentityHost } from "./host-layout.ts";
|
|
11
|
+
|
|
12
|
+
/** One spelling read into its parts: the segments after a drive, a UNC share or the posix root. */
|
|
13
|
+
type Parsed =
|
|
14
|
+
| { kind: "drive"; drive: string; segments: string[] }
|
|
15
|
+
| { kind: "unc"; server: string; share: string; segments: string[] }
|
|
16
|
+
| { kind: "posix"; segments: string[] };
|
|
17
|
+
|
|
18
|
+
/** A base of a mount, parsed, with the spelling it came from. */
|
|
19
|
+
interface Base { virtual: string; raw: string; spelling: "posix" | "windows"; parsed: Parsed }
|
|
20
|
+
|
|
21
|
+
/** A character that continues a path segment (as path-rebase.ts reads it). */
|
|
22
|
+
const SEGMENT = /[\w.-]/;
|
|
23
|
+
|
|
24
|
+
/** What ends an unquoted path in free text: whitespace, a quote, brackets, a comma, a colon, a semicolon, a pipe. */
|
|
25
|
+
const DELIMITER = /[\s"'`()<>\[\]{},:;|]/;
|
|
26
|
+
|
|
27
|
+
const WSL_SERVERS: readonly string[] = ["wsl$", "wsl.localhost"];
|
|
28
|
+
|
|
29
|
+
// ---- reading one spelling ----
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One whole path in any spelling, or null when it is not an absolute path (relative, `.` or `..` inside, an empty
|
|
33
|
+
* segment, `C:foo`). `/mnt/<d>/…` is a drive under WSL; `\\wsl$\<distro>\…` and `\\wsl.localhost\<distro>\…` are the
|
|
34
|
+
* posix form when `<distro>` is the layout's; on the posix flavour a `\` is a character of a name, elsewhere a separator.
|
|
35
|
+
*/
|
|
36
|
+
function parsePhysical(text: string, layout: HostLayout): Parsed | null {
|
|
37
|
+
let rest: string;
|
|
38
|
+
let kind: Parsed;
|
|
39
|
+
const extended = /^\\\\\?\\(.*)$/s.exec(text);
|
|
40
|
+
const body = extended === null ? text : extended[1];
|
|
41
|
+
const uncLong = extended !== null ? /^UNC\\(.*)$/is.exec(body) : null;
|
|
42
|
+
const unc = uncLong !== null ? /^([^\\/]+)[\\/]([^\\/]+)(.*)$/s.exec(uncLong[1]) : /^(?:\\\\|\/\/)([^\\/]+)[\\/]([^\\/]+)(.*)$/s.exec(body);
|
|
43
|
+
const drive = unc === null ? /^([A-Za-z]):(?:([\\/].*)|)$/s.exec(body) : null;
|
|
44
|
+
if (unc !== null) {
|
|
45
|
+
const [, server, share, tail] = unc;
|
|
46
|
+
rest = tail;
|
|
47
|
+
const alias = WSL_SERVERS.includes(server.toLowerCase()) && layout.distro !== undefined && share.toLowerCase() === layout.distro.toLowerCase();
|
|
48
|
+
kind = alias ? { kind: "posix", segments: [] } : { kind: "unc", server: server.toLowerCase(), share: share.toLowerCase(), segments: [] };
|
|
49
|
+
} else if (drive !== null) {
|
|
50
|
+
kind = { kind: "drive", drive: drive[1].toUpperCase(), segments: [] };
|
|
51
|
+
rest = drive[2] ?? "";
|
|
52
|
+
} else if (body.startsWith("/")) {
|
|
53
|
+
if (extended !== null) return null;
|
|
54
|
+
const automount = automountDrive(body, layout);
|
|
55
|
+
if (automount !== null) return automount;
|
|
56
|
+
kind = { kind: "posix", segments: [] };
|
|
57
|
+
rest = body;
|
|
58
|
+
} else {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const separators = kind.kind === "posix" && layout.flavour === "posix" && unc === null ? /\/+/ : /[\\/]+/;
|
|
62
|
+
const segments = rest.split(separators);
|
|
63
|
+
if (segments[0] === "") segments.shift();
|
|
64
|
+
if (segments.length > 0 && segments[segments.length - 1] === "") segments.pop();
|
|
65
|
+
if (segments.some((s) => s === "" || s === "." || s === "..")) return null;
|
|
66
|
+
kind.segments = segments;
|
|
67
|
+
return kind;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `/mnt/c/…` under WSL as the drive `C:`; null when the path is not under the automount root with a drive letter. */
|
|
71
|
+
function automountDrive(path: string, layout: HostLayout): Parsed | null {
|
|
72
|
+
if (layout.flavour !== "wsl") return null;
|
|
73
|
+
const root = layout.automountRoot === "/" ? "" : layout.automountRoot;
|
|
74
|
+
if (!path.startsWith(`${root}/`)) return null;
|
|
75
|
+
const match = /^([A-Za-z])(?:\/(.*)|)$/s.exec(path.slice(root.length + 1));
|
|
76
|
+
if (match === null) return null;
|
|
77
|
+
const segments = (match[2] ?? "").split(/[\\/]+/).filter((s, i, all) => !(s === "" && i === all.length - 1));
|
|
78
|
+
if (segments.some((s) => s === "" || s === "." || s === "..")) return null;
|
|
79
|
+
return { kind: "drive", drive: match[1].toUpperCase(), segments };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---- the bases of a layout ----
|
|
83
|
+
|
|
84
|
+
function basesOf(layout: HostLayout): Base[] {
|
|
85
|
+
const bases: Base[] = [];
|
|
86
|
+
for (const mount of layout.mounts) {
|
|
87
|
+
for (const spelling of ["posix", "windows"] as const) {
|
|
88
|
+
const raw = mount[spelling];
|
|
89
|
+
if (raw === undefined) continue;
|
|
90
|
+
const parsed = parsePhysical(raw, layout);
|
|
91
|
+
if (parsed !== null) bases.push({ virtual: mount.virtual, raw, spelling, parsed });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// The longest base first: a mount whose base lies under another's wins the paths under it.
|
|
95
|
+
return bases.sort((a, b) => b.parsed.segments.length - a.parsed.segments.length);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Case counts for a posix name, never for a drive or a share (Windows names): the segments of `path` under `base`. */
|
|
99
|
+
function under(path: Parsed, base: Parsed): string[] | null {
|
|
100
|
+
if (path.kind !== base.kind) return null;
|
|
101
|
+
if (path.kind === "drive" && base.kind === "drive" && path.drive !== base.drive) return null;
|
|
102
|
+
if (path.kind === "unc" && base.kind === "unc" && (path.server !== base.server || path.share !== base.share)) return null;
|
|
103
|
+
if (path.segments.length < base.segments.length) return null;
|
|
104
|
+
const fold = path.kind !== "posix";
|
|
105
|
+
for (let i = 0; i < base.segments.length; i++) {
|
|
106
|
+
const same = fold ? path.segments[i].toLowerCase() === base.segments[i].toLowerCase() : path.segments[i] === base.segments[i];
|
|
107
|
+
if (!same) return null;
|
|
108
|
+
}
|
|
109
|
+
return path.segments.slice(base.segments.length);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const virtualOf = (mount: string, rest: readonly string[]): string => rest.length === 0 ? mount : `${mount}/${rest.join("/")}`;
|
|
113
|
+
|
|
114
|
+
// ---- one path ----
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One whole path in any spelling of a mount's base, as its canonical virtual path (`/workspace/un dossier/f.txt`: `/`,
|
|
118
|
+
* no trailing separator). A virtual path spelled with `\` after its mount is normalised on a WSL or Windows host.
|
|
119
|
+
* Anything else (a relative path, a path under no mount, a path with `.` or `..`) is returned as given.
|
|
120
|
+
*/
|
|
121
|
+
export function toVirtual(path: string, layout: HostLayout): string {
|
|
122
|
+
if (isIdentityHost(layout)) return path;
|
|
123
|
+
const parsed = parsePhysical(path, layout);
|
|
124
|
+
if (parsed === null) return path;
|
|
125
|
+
for (const base of basesOf(layout)) {
|
|
126
|
+
const rest = under(parsed, base.parsed);
|
|
127
|
+
if (rest !== null) return virtualOf(base.virtual, rest);
|
|
128
|
+
}
|
|
129
|
+
if (parsed.kind === "posix" && layout.flavour !== "posix" && parsed.segments.length > 0) {
|
|
130
|
+
const mount = `/${parsed.segments[0]}`;
|
|
131
|
+
if (layout.mounts.some((m) => m.virtual === mount)) return virtualOf(mount, parsed.segments.slice(1));
|
|
132
|
+
}
|
|
133
|
+
return path;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A canonical virtual path in the physical spelling asked for, from the mount's base in that spelling; null when the
|
|
138
|
+
* path is under no mount, or the mount has no base in that spelling. For the round trip and the diagnostics: never
|
|
139
|
+
* for a command (ADR 0022).
|
|
140
|
+
*/
|
|
141
|
+
export function fromVirtual(path: string, layout: HostLayout, spelling: "posix" | "windows"): string | null {
|
|
142
|
+
const segments = path.split("/");
|
|
143
|
+
if (segments[0] !== "" || segments.length < 2) return null;
|
|
144
|
+
const mount = layout.mounts.find((m) => m.virtual === `/${segments[1]}`);
|
|
145
|
+
const raw = mount?.[spelling];
|
|
146
|
+
if (raw === undefined) return null;
|
|
147
|
+
const sep = spelling === "windows" ? "\\" : "/";
|
|
148
|
+
const rest = segments.slice(2).join(sep);
|
|
149
|
+
if (rest === "") return raw;
|
|
150
|
+
return raw.endsWith(sep) ? raw + rest : raw + sep + rest;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---- free text ----
|
|
154
|
+
|
|
155
|
+
/** The literal spellings of a base a text may hold, each with whether case counts. */
|
|
156
|
+
interface Literal { text: string; fold: boolean; backslashed: boolean; virtual: string }
|
|
157
|
+
|
|
158
|
+
function literalsOf(layout: HostLayout): Literal[] {
|
|
159
|
+
const literals: Literal[] = [];
|
|
160
|
+
const add = (text: string, fold: boolean, backslashed: boolean, virtual: string) => {
|
|
161
|
+
if (!literals.some((l) => l.text === text && l.fold === fold)) literals.push({ text, fold, backslashed, virtual });
|
|
162
|
+
};
|
|
163
|
+
for (const mount of layout.mounts) {
|
|
164
|
+
// On a WSL or Windows host the runtime's own rewrite may leave `/workspace/un dossier\f.txt`: the mount is a literal too.
|
|
165
|
+
if (layout.flavour !== "posix") add(mount.virtual, false, true, mount.virtual);
|
|
166
|
+
if (mount.windows !== undefined) {
|
|
167
|
+
add(mount.windows, true, true, mount.virtual);
|
|
168
|
+
add(mount.windows.replace(/\\/g, "/"), true, false, mount.virtual);
|
|
169
|
+
if (/^[A-Za-z]:/.test(mount.windows)) add(`\\\\?\\${mount.windows}`, true, true, mount.virtual);
|
|
170
|
+
}
|
|
171
|
+
if (mount.posix !== undefined) {
|
|
172
|
+
add(mount.posix, layout.flavour !== "posix" && automountDrive(mount.posix, layout) !== null, false, mount.virtual);
|
|
173
|
+
if (layout.distro !== undefined) {
|
|
174
|
+
const tail = mount.posix.replace(/\//g, "\\");
|
|
175
|
+
for (const server of WSL_SERVERS) add(`\\\\${server}\\${layout.distro}${tail}`, true, true, mount.virtual);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return literals.sort((a, b) => b.text.length - a.text.length);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** True when a literal found at `at` starts a path there: nothing of a name right before it. */
|
|
183
|
+
const startsPath = (text: string, at: number): boolean => at === 0 || !/[\w./\\-]/.test(text[at - 1]);
|
|
184
|
+
|
|
185
|
+
/** True when a base ending at `at` ends there as a name: the end, a separator or a delimiter follows. */
|
|
186
|
+
const endsBase = (text: string, at: number): boolean => at >= text.length || text[at] === "/" || text[at] === "\\" || !SEGMENT.test(text[at]);
|
|
187
|
+
|
|
188
|
+
/** Where a word starting at `from` ends: the first delimiter, or a dot that ends a sentence. */
|
|
189
|
+
function wordEnd(line: string, from: number): number {
|
|
190
|
+
let at = from;
|
|
191
|
+
while (at < line.length && !DELIMITER.test(line[at]) && !(line[at] === "." && sentenceDot(line, at))) at++;
|
|
192
|
+
return at;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Where an unquoted path starting at `from` ends. A Windows path with a space in a name goes on over the spaces: the
|
|
197
|
+
* path runs to the next word that holds a `\`, unless a word before it starts another path (`C:`, `\\`, `/`).
|
|
198
|
+
*/
|
|
199
|
+
function unquotedEnd(line: string, from: number, backslashed: boolean): number {
|
|
200
|
+
let at = wordEnd(line, from);
|
|
201
|
+
if (!backslashed) return at;
|
|
202
|
+
for (;;) {
|
|
203
|
+
let probe = at;
|
|
204
|
+
let found = -1;
|
|
205
|
+
while (line[probe] === " ") {
|
|
206
|
+
const end = wordEnd(line, probe + 1);
|
|
207
|
+
const word = line.slice(probe + 1, end);
|
|
208
|
+
if (word === "" || word.startsWith("\\") || word.startsWith("/") || (word.length === 1 && line[end] === ":")) break;
|
|
209
|
+
probe = end;
|
|
210
|
+
if (word.includes("\\")) { found = end; break; }
|
|
211
|
+
}
|
|
212
|
+
if (found < 0) return at;
|
|
213
|
+
at = found;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const sentenceDot = (line: string, at: number): boolean => at + 1 >= line.length || /[\s"'`)\]]/.test(line[at + 1]);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Every physical spelling of a mount's base in a text (a command's output, a tool's result, a prompt) replaced by the
|
|
221
|
+
* canonical virtual path. A base is found literally (a space inside it counts); after an opening quote the path runs to
|
|
222
|
+
* the closing quote on the line, else to the first delimiter (whitespace, quotes, brackets, `,` `:` `;` `|`, or a dot
|
|
223
|
+
* that ends a sentence), a Windows path going on over a space when the next word still holds a `\`. With `keepFenced`,
|
|
224
|
+
* the lines inside a ``` or ~~~ block are left as they are (a prompt that quotes code).
|
|
225
|
+
*/
|
|
226
|
+
export function textToVirtual(text: string, layout: HostLayout, options: { keepFenced?: boolean } = {}): string {
|
|
227
|
+
if (isIdentityHost(layout) || text === "") return text;
|
|
228
|
+
const literals = literalsOf(layout);
|
|
229
|
+
if (literals.length === 0) return text;
|
|
230
|
+
let fence: string | null = null;
|
|
231
|
+
return text.split("\n").map((line) => {
|
|
232
|
+
if (options.keepFenced) {
|
|
233
|
+
const mark = /^\s*(```|~~~)/.exec(line)?.[1];
|
|
234
|
+
if (mark !== undefined) {
|
|
235
|
+
if (fence === null) fence = mark;
|
|
236
|
+
else if (fence === mark) fence = null;
|
|
237
|
+
return line;
|
|
238
|
+
}
|
|
239
|
+
if (fence !== null) return line;
|
|
240
|
+
}
|
|
241
|
+
return lineToVirtual(line, literals, layout);
|
|
242
|
+
}).join("\n");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function lineToVirtual(line: string, literals: readonly Literal[], layout: HostLayout): string {
|
|
246
|
+
const lower = line.toLowerCase();
|
|
247
|
+
let out = "";
|
|
248
|
+
let from = 0;
|
|
249
|
+
for (let at = 0; at < line.length;) {
|
|
250
|
+
const hit = literalAt(line, lower, at, literals);
|
|
251
|
+
if (hit === null) { at++; continue; }
|
|
252
|
+
const quote = at > 0 && (line[at - 1] === '"' || line[at - 1] === "'") ? line[at - 1] : null;
|
|
253
|
+
const closing = quote === null ? -1 : line.indexOf(quote, at + hit.text.length);
|
|
254
|
+
const end = closing >= 0 ? closing : unquotedEnd(line, at + hit.text.length, hit.backslashed);
|
|
255
|
+
const candidate = line.slice(at, end);
|
|
256
|
+
const virtual = toVirtual(candidate, layout);
|
|
257
|
+
if (virtual === candidate) { at++; continue; }
|
|
258
|
+
out += line.slice(from, at) + virtual;
|
|
259
|
+
from = end;
|
|
260
|
+
at = end;
|
|
261
|
+
}
|
|
262
|
+
return out + line.slice(from);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The longest literal starting a path at `at`, or null. */
|
|
266
|
+
function literalAt(line: string, lower: string, at: number, literals: readonly Literal[]): Literal | null {
|
|
267
|
+
if (!startsPath(line, at)) return null;
|
|
268
|
+
for (const literal of literals) {
|
|
269
|
+
const found = literal.fold ? lower.startsWith(literal.text.toLowerCase(), at) : line.startsWith(literal.text, at);
|
|
270
|
+
if (found && endsBase(line, at + literal.text.length)) return literal;
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---- a shell command ----
|
|
276
|
+
|
|
277
|
+
/** One word of a shell command with its span in the text (quotes included) and the quote it opened with, if any. */
|
|
278
|
+
export interface CommandToken { start: number; end: number; value: string; quote: '"' | "'" | null }
|
|
279
|
+
|
|
280
|
+
/** The words of a command as shellWords splits them (agent-policy/permission.ts), each with where it stands. */
|
|
281
|
+
export function commandTokens(command: string): CommandToken[] {
|
|
282
|
+
const tokens: CommandToken[] = [];
|
|
283
|
+
let current = "";
|
|
284
|
+
let start = -1;
|
|
285
|
+
let quote: '"' | "'" | null = null;
|
|
286
|
+
let single = false;
|
|
287
|
+
let double = false;
|
|
288
|
+
const flush = (end: number) => {
|
|
289
|
+
if (start >= 0) tokens.push({ start, end, value: current, quote });
|
|
290
|
+
current = "";
|
|
291
|
+
start = -1;
|
|
292
|
+
quote = null;
|
|
293
|
+
};
|
|
294
|
+
for (let i = 0; i < command.length; i++) {
|
|
295
|
+
const c = command[i];
|
|
296
|
+
if (c === "'" && !double) {
|
|
297
|
+
if (start < 0) start = i;
|
|
298
|
+
if (quote === null) quote = "'";
|
|
299
|
+
single = !single;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (c === '"' && !single) {
|
|
303
|
+
if (start < 0) start = i;
|
|
304
|
+
if (quote === null) quote = '"';
|
|
305
|
+
double = !double;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (/\s/.test(c) && !single && !double) {
|
|
309
|
+
flush(i);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (start < 0) start = i;
|
|
313
|
+
current += c;
|
|
314
|
+
}
|
|
315
|
+
flush(command.length);
|
|
316
|
+
return tokens;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* A command with each word that is a path in a physical spelling, whole or after its first `=`, in the canonical
|
|
321
|
+
* virtual spelling; the quotes of a word are kept around the new value. What is not a whole word (a path inside a
|
|
322
|
+
* script) stays as written.
|
|
323
|
+
*/
|
|
324
|
+
export function commandToVirtual(command: string, layout: HostLayout): string {
|
|
325
|
+
if (isIdentityHost(layout) || command === "") return command;
|
|
326
|
+
let out = "";
|
|
327
|
+
let from = 0;
|
|
328
|
+
for (const token of commandTokens(command)) {
|
|
329
|
+
const value = valueToVirtual(token.value, layout);
|
|
330
|
+
if (value === token.value) continue;
|
|
331
|
+
const spelled = token.quote === null ? (/[\s'"]/.test(value) ? `"${value}"` : value) : `${token.quote}${value}${token.quote}`;
|
|
332
|
+
out += command.slice(from, token.start) + spelled;
|
|
333
|
+
from = token.end;
|
|
334
|
+
}
|
|
335
|
+
return out + command.slice(from);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** A word as a path, or a `key=path`, in the canonical spelling; the word itself otherwise. */
|
|
339
|
+
function valueToVirtual(value: string, layout: HostLayout): string {
|
|
340
|
+
const whole = toVirtual(value, layout);
|
|
341
|
+
if (whole !== value) return whole;
|
|
342
|
+
const eq = value.indexOf("=");
|
|
343
|
+
if (eq <= 0 || eq === value.length - 1) return value;
|
|
344
|
+
const right = toVirtual(value.slice(eq + 1), layout);
|
|
345
|
+
return right === value.slice(eq + 1) ? value : value.slice(0, eq + 1) + right;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ---- a tool call ----
|
|
349
|
+
|
|
350
|
+
/** The fields of a call that name a path or a folder, whatever the tool. */
|
|
351
|
+
const PATH_FIELDS: readonly string[] = ["path", "root_path", "working_directory"];
|
|
352
|
+
/** The fields that list paths. */
|
|
353
|
+
const PATHS_FIELDS: readonly string[] = ["paths"];
|
|
354
|
+
/** The field that holds the operations of an edit batch, each with its `path`. */
|
|
355
|
+
const OPERATIONS_FIELD = "operations";
|
|
356
|
+
const SHELL_TOOL = "shell_command";
|
|
357
|
+
const COMMAND_FIELD = "command";
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The input of a tool call with its path fields in the canonical spelling: `path`, `root_path`, `working_directory`,
|
|
361
|
+
* the strings of `paths`, the `path` of each operation, and for the shell tool the words of `command`. Nothing else
|
|
362
|
+
* is touched (a file's content, an edit's strings, a pattern). Null when nothing changed; the same again on its own
|
|
363
|
+
* result (idempotent).
|
|
364
|
+
*/
|
|
365
|
+
export function callToVirtual(tool: string, input: unknown, layout: HostLayout): Record<string, unknown> | null {
|
|
366
|
+
if (isIdentityHost(layout) || input === null || typeof input !== "object" || Array.isArray(input)) return null;
|
|
367
|
+
const given = input as Record<string, unknown>;
|
|
368
|
+
const out: Record<string, unknown> = { ...given };
|
|
369
|
+
let changed = false;
|
|
370
|
+
const set = (key: string, value: unknown) => {
|
|
371
|
+
if (value !== given[key]) { out[key] = value; changed = true; }
|
|
372
|
+
};
|
|
373
|
+
for (const key of PATH_FIELDS) {
|
|
374
|
+
if (typeof given[key] === "string") set(key, toVirtual(given[key] as string, layout));
|
|
375
|
+
}
|
|
376
|
+
for (const key of PATHS_FIELDS) {
|
|
377
|
+
const list = given[key];
|
|
378
|
+
if (Array.isArray(list)) {
|
|
379
|
+
const mapped = list.map((p) => (typeof p === "string" ? toVirtual(p, layout) : p));
|
|
380
|
+
if (mapped.some((p, i) => p !== list[i])) set(key, mapped);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const operations = given[OPERATIONS_FIELD];
|
|
384
|
+
if (Array.isArray(operations)) {
|
|
385
|
+
let any = false;
|
|
386
|
+
const mapped = operations.map((op) => {
|
|
387
|
+
if (op === null || typeof op !== "object" || typeof (op as Record<string, unknown>).path !== "string") return op;
|
|
388
|
+
const path = toVirtual((op as Record<string, unknown>).path as string, layout);
|
|
389
|
+
if (path === (op as Record<string, unknown>).path) return op;
|
|
390
|
+
any = true;
|
|
391
|
+
return { ...(op as Record<string, unknown>), path };
|
|
392
|
+
});
|
|
393
|
+
if (any) set(OPERATIONS_FIELD, mapped);
|
|
394
|
+
}
|
|
395
|
+
if (sameToolName(tool, SHELL_TOOL) && typeof given[COMMAND_FIELD] === "string") {
|
|
396
|
+
set(COMMAND_FIELD, commandToVirtual(given[COMMAND_FIELD] as string, layout));
|
|
397
|
+
}
|
|
398
|
+
return changed ? out : null;
|
|
399
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The languages index_codebase is asked for: every grammar of the runtime's registry
|
|
2
|
+
// (src/analysis/Orkeon.Analysis/TreeSitter/LanguageRegistry.cs, twenty-five since Orkeon #195). The discovery keeps
|
|
3
|
+
// every file of a known grammar, then opens it to hash it; since Orkeon #215 the path validator lets a plain read
|
|
4
|
+
// of a shell script through (.sh, .bash, .ps1, .bat, .cmd, .vbs, .wsf) and the discovery skips a file the VFS still refuses
|
|
5
|
+
// instead of failing the whole index, so no grammar is held back any more. A grammar added framework-side must be
|
|
6
|
+
// mirrored here, as search-routing.ts does for the extensions. Pure.
|
|
7
|
+
|
|
8
|
+
/** The grammars of the runtime's registry, in its order. */
|
|
9
|
+
export const TREE_LANGUAGES: readonly string[] = [
|
|
10
|
+
"typescript", "python", "csharp", "go", "rust", "javascript", "java", "c", "cpp", "php", "ruby", "bash",
|
|
11
|
+
"markdown", "tsx", "agda", "css", "embedded-template", "haskell", "html", "json", "julia", "ql", "razor",
|
|
12
|
+
"scala", "verilog",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/** What index_codebase is asked for: every grammar of the registry. */
|
|
16
|
+
export const INDEXED_LANGUAGES: readonly string[] = TREE_LANGUAGES;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The project's instructions file — which file the agent reads and /init writes.
|
|
2
|
+
// Pure, no IO.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The instructions files of a project, in order of preference: the loop reads the
|
|
6
|
+
* first one present and /init writes the first. AGENTS.md is the name several
|
|
7
|
+
* assistants share; CLAUDE.md stays readable for projects that already have one.
|
|
8
|
+
*/
|
|
9
|
+
export const INSTRUCTIONS_FILES = ["AGENTS.md", "CLAUDE.md"] as const;
|
|
10
|
+
|
|
11
|
+
/** The file /init writes. */
|
|
12
|
+
export const INSTRUCTIONS_FILE_WRITTEN = INSTRUCTIONS_FILES[0];
|
|
13
|
+
|
|
14
|
+
/** The instructions file as the loop read it: which file, and its text. */
|
|
15
|
+
export interface InstructionsFile {
|
|
16
|
+
file: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// A model call the host's provider failed. Orkeon does not throw then: `act`
|
|
2
|
+
// resolves its `output`, and `complete` its text, to the marker
|
|
3
|
+
// `<undefined-llm:<the provider's error>>` (also what a host without a provider
|
|
4
|
+
// echoes). Read as an answer, the marker would be stored, summarised, written or
|
|
5
|
+
// committed as if the model had said it, so the Llm adapter throws this failure
|
|
6
|
+
// instead. The same adapter throws a BudgetExhaustedAnswer when an act resolves
|
|
7
|
+
// with `budgetExhausted` (Orkeon #218: the token budget ran out, the act made one
|
|
8
|
+
// last call without tools and resolved with that answer): the answer rides on the
|
|
9
|
+
// error, so no caller reads a cut-short wrap-up as a finished answer, and the
|
|
10
|
+
// readers of a spent budget (shared/domain/dev/step-budget.ts) see the `tokens`
|
|
11
|
+
// dimension as they did when the runtime rejected. An act that resolves with
|
|
12
|
+
// `exhausted` (its `maxIterations` reached, no final answer: its output is the
|
|
13
|
+
// runtime's own notice, not the model's words) is thrown as an IterationsExhausted,
|
|
14
|
+
// so that no caller parses that notice as an answer - a review read as CLEAR, an
|
|
15
|
+
// audit as a verdict. A call a decision stage of
|
|
16
|
+
// the host blocked is no failure of the provider: the runtime rejects it with a
|
|
17
|
+
// DecisionBlockedError (Orkeon #269), which decisionBlockOf reads. Pure, no IO.
|
|
18
|
+
import {
|
|
19
|
+
BUDGET_EXHAUSTED_MESSAGE, blockedByDecisionProfile, iterationsExhaustedMessage, matchesTheRisk, modelCallFailed,
|
|
20
|
+
} from "./messages.ts";
|
|
21
|
+
|
|
22
|
+
const MARKER = /^<undefined-llm:([\s\S]*)>$/;
|
|
23
|
+
|
|
24
|
+
/** The longest provider error a failure carries: a host without a provider echoes the whole prompt. */
|
|
25
|
+
const MAX_DETAIL = 300;
|
|
26
|
+
|
|
27
|
+
/** The error a failed model call throws, told apart by its `name`. */
|
|
28
|
+
export interface LlmFailure extends Error {
|
|
29
|
+
name: "LlmFailure";
|
|
30
|
+
/** The provider's error, as the marker carried it (cut at MAX_DETAIL characters). */
|
|
31
|
+
detail: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The failure a model's text stands for, or null when the text is an answer. */
|
|
35
|
+
export function llmFailureOf(text: unknown): LlmFailure | null {
|
|
36
|
+
const m = typeof text === "string" ? MARKER.exec(text) : null;
|
|
37
|
+
if (!m) return null;
|
|
38
|
+
const detail = m[1].length > MAX_DETAIL ? `${m[1].slice(0, MAX_DETAIL)}…` : m[1];
|
|
39
|
+
// A plain Error with a name rather than a subclass: subclassing Error is not
|
|
40
|
+
// something the bundles rely on anywhere else, in Jint or in Node.
|
|
41
|
+
const failure = new Error(modelCallFailed(detail)) as LlmFailure;
|
|
42
|
+
failure.name = "LlmFailure";
|
|
43
|
+
failure.detail = detail;
|
|
44
|
+
return failure;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A call a decision stage of the host blocked (a decision profile, `llm.profile`): which stage, of which profile,
|
|
48
|
+
* the risk a guard matched, why. */
|
|
49
|
+
export interface DecisionBlock {
|
|
50
|
+
readonly stage: string;
|
|
51
|
+
readonly profile: string;
|
|
52
|
+
/** The risk a guard matched (`prompt_injection`); null for another stage. */
|
|
53
|
+
readonly risk: string | null;
|
|
54
|
+
/** Why the stage blocked the call; null when the stage gave no reason. */
|
|
55
|
+
readonly reason: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The `errorType` of the runtime's DecisionBlockedError (Orkeon #269): `complete`, `chat`, `extract`, `decide`, `act`
|
|
59
|
+
* and a `stream` iteration reject with it when a stage blocks the call, a fail-closed stage that failed included. */
|
|
60
|
+
const DECISION_BLOCKED = "DecisionBlocked";
|
|
61
|
+
|
|
62
|
+
function textField(value: unknown): string | null {
|
|
63
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The block a DecisionBlockedError carries; null for any other error (an LlmFailure, a rate limit) or value. */
|
|
67
|
+
export function decisionBlockOf(error: unknown): DecisionBlock | null {
|
|
68
|
+
if (typeof error !== "object" || error === null) return null;
|
|
69
|
+
const e = error as { errorType?: unknown; profile?: unknown; stage?: unknown; risk?: unknown; reason?: unknown };
|
|
70
|
+
if (e.errorType !== DECISION_BLOCKED) return null;
|
|
71
|
+
return {
|
|
72
|
+
stage: textField(e.stage) ?? "unknown",
|
|
73
|
+
profile: textField(e.profile) ?? "unknown",
|
|
74
|
+
risk: textField(e.risk),
|
|
75
|
+
reason: textField(e.reason),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** What the user reads for a blocked request: a decision, not an outage, and what to do about it. */
|
|
80
|
+
export function decisionBlockText(block: DecisionBlock): string {
|
|
81
|
+
const why = block.reason ?? (block.risk === null ? null : matchesTheRisk(block.risk));
|
|
82
|
+
return blockedByDecisionProfile(block.profile, block.stage, why);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The error an act whose token budget ran out throws: the wrap-up answer the model gave in its last call, and the
|
|
86
|
+
* `tokens` dimension, as readBudgetExhausted reads it off a BudgetExhaustedError of the runtime. */
|
|
87
|
+
export interface BudgetExhaustedAnswer extends Error {
|
|
88
|
+
name: "BudgetExhaustedError";
|
|
89
|
+
dimension: "tokens";
|
|
90
|
+
/** The model's last answer, made without tools once the budget was spent: cut short, never parsed as an answer. */
|
|
91
|
+
answer: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/** The error carrying the wrap-up `answer` of an act that resolved with `budgetExhausted`. */
|
|
96
|
+
export function budgetExhaustedAnswer(answer: string): BudgetExhaustedAnswer {
|
|
97
|
+
const failure = new Error(BUDGET_EXHAUSTED_MESSAGE) as BudgetExhaustedAnswer;
|
|
98
|
+
failure.name = "BudgetExhaustedError";
|
|
99
|
+
failure.dimension = "tokens";
|
|
100
|
+
failure.answer = answer;
|
|
101
|
+
return failure;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The failure as a BudgetExhaustedAnswer, or null for any other value: a BudgetExhaustedError of the runtime's own
|
|
105
|
+
* carries no answer and is not one. */
|
|
106
|
+
export function budgetExhaustedAnswerOf(failure: unknown): BudgetExhaustedAnswer | null {
|
|
107
|
+
if (!(failure instanceof Error) || failure.name !== "BudgetExhaustedError") return null;
|
|
108
|
+
const answer = (failure as { answer?: unknown }).answer;
|
|
109
|
+
return typeof answer === "string" ? failure as BudgetExhaustedAnswer : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The error an act stopped at its iteration cap throws: the model never gave a final answer. */
|
|
113
|
+
export interface IterationsExhausted extends Error {
|
|
114
|
+
name: "IterationsExhausted";
|
|
115
|
+
/** The tool-call turns the act ran; null when the runtime did not say. */
|
|
116
|
+
iterations: number | null;
|
|
117
|
+
/** What the runtime resolved with in place of an answer: its notice, never the model's words. */
|
|
118
|
+
notice: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The error of an act that resolved with `exhausted` after `iterations` turns, `notice` its output. */
|
|
122
|
+
export function iterationsExhausted(iterations: unknown, notice: string): IterationsExhausted {
|
|
123
|
+
const turns = typeof iterations === "number" && Number.isInteger(iterations) && iterations > 0 ? iterations : null;
|
|
124
|
+
const failure = new Error(iterationsExhaustedMessage(turns)) as IterationsExhausted;
|
|
125
|
+
failure.name = "IterationsExhausted";
|
|
126
|
+
failure.iterations = turns;
|
|
127
|
+
failure.notice = notice;
|
|
128
|
+
return failure;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The failure as an IterationsExhausted, or null for any other value. */
|
|
132
|
+
export function iterationsExhaustedOf(failure: unknown): IterationsExhausted | null {
|
|
133
|
+
return failure instanceof Error && failure.name === "IterationsExhausted" ? failure as IterationsExhausted : null;
|
|
134
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The host profile the agents of the commands run on (`llm.profile`): one of the host's LLM profiles
|
|
2
|
+
// (`Llm:Profiles:<name>`) or decision profiles (`Orkeon:Decision:Profiles:<name>`, a decision model such
|
|
3
|
+
// as Jev in front of an LLM profile). The command reads the session key and hands the name to the crew
|
|
4
|
+
// in its input, under `llmProfile`; the crew's composition root builds every agent on it
|
|
5
|
+
// (shared/infrastructure/orkeon/llm-profile.ts). Omitted, the agents run on the host's default model,
|
|
6
|
+
// as they always did.
|
|
7
|
+
import { PROFILE_NAME_EXPECTED, profileHoldsColon, profileHoldsSpace } from "./messages.ts";
|
|
8
|
+
|
|
9
|
+
export const LLM_PROFILE_CONFIG_KEY = "llm.profile";
|
|
10
|
+
/** The field of a crew input that carries the profile's name. */
|
|
11
|
+
export const LLM_PROFILE_INPUT_KEY = "llmProfile";
|
|
12
|
+
/** The field of a crew input that marks `llmProfile` as picked by the routing, and carries the session's own profile
|
|
13
|
+
* ("" for the host's default model): what the crew runs on when the host declares no profile of the routed name. */
|
|
14
|
+
export const LLM_PROFILE_FALLBACK_INPUT_KEY = "llmProfileFallback";
|
|
15
|
+
|
|
16
|
+
/** The session's profile a routed crew input falls back on: undefined when the input was not routed, null for the
|
|
17
|
+
* host's default model. */
|
|
18
|
+
export function llmProfileFallbackOf(input: Readonly<Record<string, unknown>>): string | null | undefined {
|
|
19
|
+
const value = input[LLM_PROFILE_FALLBACK_INPUT_KEY];
|
|
20
|
+
if (typeof value !== "string") return undefined;
|
|
21
|
+
return value.trim() === "" || llmProfileProblem(value) !== undefined ? null : value.trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The session's own profile a crew input carries: its `llmProfileFallback` when the launch was routed, else its
|
|
25
|
+
* `llmProfile`; null for the host's default model. */
|
|
26
|
+
export function llmSessionProfileOf(input: Readonly<Record<string, unknown>>): string | null {
|
|
27
|
+
const fallback = llmProfileFallbackOf(input);
|
|
28
|
+
return fallback === undefined ? llmProfileOf(input) : fallback;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Why a value is refused for `llm.profile`; undefined when it is a profile name. */
|
|
32
|
+
export function llmProfileProblem(value: string): string | undefined {
|
|
33
|
+
const name = value.trim();
|
|
34
|
+
if (name === "") return PROFILE_NAME_EXPECTED;
|
|
35
|
+
if (/\s/.test(name)) return profileHoldsSpace(value);
|
|
36
|
+
if (name.includes(":")) return profileHoldsColon(value);
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The profile a crew input names, or null when it names none or the name is not one. */
|
|
41
|
+
export function llmProfileOf(input: Readonly<Record<string, unknown>>): string | null {
|
|
42
|
+
const value = input[LLM_PROFILE_INPUT_KEY];
|
|
43
|
+
return typeof value === "string" && llmProfileProblem(value) === undefined ? value.trim() : null;
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The messages the harness stores in the session with a marker opening them: a turn's context lines, the summary of
|
|
2
|
+
// compacted turns, a turn's tool trace. They are material, never a request the user typed, even one that opens with
|
|
3
|
+
// a bracket ("[bug] why does it fail?").
|
|
4
|
+
import { COMPACTED_HEADER, TOOL_TRACE_MARKER, TURN_CONTEXT_MARKER } from "./markers.ts";
|
|
5
|
+
import type { SessionMsg } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
/** The marker that opens the summary of compacted turns. */
|
|
8
|
+
export const COMPACTED_MARKER = COMPACTED_HEADER.slice(0, COMPACTED_HEADER.indexOf("]") + 1);
|
|
9
|
+
|
|
10
|
+
const MARKERS: readonly string[] = [TURN_CONTEXT_MARKER, COMPACTED_MARKER, TOOL_TRACE_MARKER];
|
|
11
|
+
|
|
12
|
+
/** Whether a stored message opens with one of the harness's markers. */
|
|
13
|
+
export function isMarkedMessage(content: string): boolean {
|
|
14
|
+
return MARKERS.some((m) => content.startsWith(m));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** How many messages at the end of `messages` are the request still waiting for its answer: the last one when the
|
|
18
|
+
* user typed it (a user message no marker opens), with the [turn-context] stored just before it; none when the buffer
|
|
19
|
+
* ends on an answer or on a message of the harness. The first message, the head of the buffer, is never counted. */
|
|
20
|
+
export function pendingRequestLength(messages: readonly SessionMsg[]): number {
|
|
21
|
+
const last = messages.length - 1;
|
|
22
|
+
if (last < 1 || !isTypedRequest(messages[last])) return 0;
|
|
23
|
+
const before = messages[last - 1];
|
|
24
|
+
return last >= 2 && before.role === "user" && String(before.content).startsWith(TURN_CONTEXT_MARKER) ? 2 : 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isTypedRequest(message: SessionMsg): boolean {
|
|
28
|
+
return message.role === "user" && !isMarkedMessage(String(message.content));
|
|
29
|
+
}
|