orkeon-code 1.0.0-rc.1 → 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 -1
- package/NOTICE.md +1 -1
- package/README.fr.md +16 -22
- package/README.md +16 -22
- package/config/appsettings.jev.example.json +4 -1
- package/config/appsettings.kev.example.json +4 -1
- package/config/appsettings.liquid.example.json +4 -1
- package/config/appsettings.ollama-whisper.example.json +1 -0
- package/config/appsettings.whisper.example.json +1 -0
- package/mcp/whisper/README.md +2 -1
- package/orkeon-code +206 -11
- package/orkeon-code.ps1 +109 -7
- package/package.json +2 -1
- package/src/commands/.orkeon/orkeon-cli.d.ts +1 -4
- package/src/commands/_lib/args.ts +5 -4
- package/src/commands/_lib/dev/dev-batches.ts +34 -36
- package/src/commands/_lib/dev/dev-implement.ts +11 -14
- package/src/commands/_lib/dev/dev-source.ts +7 -11
- package/src/commands/_lib/dev/dev.ts +34 -37
- 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 +16 -13
- package/src/commands/_lib/dispatch.ts +62 -39
- package/src/commands/_lib/git/branch.ts +9 -10
- package/src/commands/_lib/git/commit.ts +9 -13
- package/src/commands/_lib/git/diff.ts +22 -12
- package/src/commands/_lib/git/messages.ts +54 -0
- package/src/commands/_lib/git/review.ts +9 -10
- package/src/commands/_lib/memory/memory-admit.ts +19 -21
- package/src/commands/_lib/memory/memory.ts +3 -2
- package/src/commands/_lib/memory/messages.ts +32 -0
- package/src/commands/_lib/messages.ts +48 -0
- package/src/commands/_lib/project/messages.ts +8 -0
- package/src/commands/_lib/session/export.ts +3 -2
- 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 +15 -24
- package/src/commands/_lib/session/tasks.ts +20 -23
- package/src/commands/_lib/settings/advisor.ts +11 -16
- package/src/commands/_lib/settings/agents.ts +18 -28
- package/src/commands/_lib/settings/choices.ts +8 -0
- package/src/commands/_lib/settings/config.ts +43 -43
- package/src/commands/_lib/settings/effort.ts +147 -0
- package/src/commands/_lib/settings/hooks.ts +12 -20
- package/src/commands/_lib/settings/messages.ts +408 -0
- package/src/commands/_lib/settings/mode.ts +33 -24
- package/src/commands/_lib/settings/model.ts +71 -36
- package/src/commands/_lib/settings/output-style.ts +39 -0
- package/src/commands/_lib/settings/permissions.ts +71 -93
- package/src/commands/_lib/settings/route.ts +63 -0
- package/src/commands/_lib/settings/skills.ts +53 -11
- 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 +9 -10
- package/src/commands/_lib/speech/transcribe.ts +14 -23
- package/src/commands/_lib/speech/voice.ts +14 -18
- package/src/commands/_lib/status/doctor.ts +47 -28
- package/src/commands/_lib/status/messages.ts +100 -0
- package/src/commands/_lib/status/meta.ts +3 -24
- package/src/commands/_lib/status/status.ts +10 -11
- package/src/commands/_lib/status/usage-tools.ts +2 -3
- package/src/commands/_lib/status/usage.ts +7 -18
- package/src/commands/_lib/view.ts +6 -1
- package/src/commands/dev/dev-batches.cmd.ts +4 -3
- package/src/commands/dev/dev-learn.cmd.ts +3 -3
- package/src/commands/dev/dev-plan.cmd.ts +6 -7
- package/src/commands/dev/dev-spec.cmd.ts +6 -7
- package/src/commands/git/commit.cmd.ts +3 -3
- package/src/commands/git/review.cmd.ts +3 -3
- package/src/commands/memory/memory.cmd.ts +2 -2
- package/src/commands/project/analyze.cmd.ts +3 -3
- package/src/commands/project/debug-tool-call.cmd.ts +4 -9
- package/src/commands/project/init-verifiers.cmd.ts +3 -3
- package/src/commands/project/init.cmd.ts +3 -3
- package/src/commands/project/verify.cmd.ts +2 -2
- package/src/commands/session/assistant.cmd.ts +2 -2
- package/src/commands/session/compact.cmd.ts +1 -1
- package/src/commands/session/copy.cmd.ts +8 -7
- package/src/commands/session/rename.cmd.ts +3 -2
- package/src/commands/session/rewind.cmd.ts +3 -4
- package/src/commands/session/summary.cmd.ts +3 -3
- package/src/commands/session/tasks.cmd.ts +4 -2
- package/src/commands/settings/config.cmd.ts +4 -2
- package/src/commands/settings/effort.cmd.ts +10 -31
- package/src/commands/settings/fast.cmd.ts +2 -1
- package/src/commands/settings/mode.cmd.ts +3 -3
- package/src/commands/settings/model.cmd.ts +3 -2
- package/src/commands/settings/output-style.cmd.ts +9 -38
- package/src/commands/settings/permissions.cmd.ts +2 -2
- package/src/commands/settings/proactive.cmd.ts +2 -1
- package/src/commands/settings/route.cmd.ts +16 -0
- package/src/commands/settings/skills.cmd.ts +3 -3
- package/src/commands/settings/theme.cmd.ts +14 -0
- package/src/commands/speech/say.cmd.ts +2 -2
- package/src/commands/speech/transcribe.cmd.ts +2 -2
- package/src/commands/status/release-notes.cmd.ts +1 -1
- package/src/crews/.orkeon/orkeon.d.ts +538 -93
- package/src/crews/_probe-shared-memory/domain/messages.ts +54 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +17 -12
- package/src/crews/_probe-shared-memory/domain/prompts.ts +5 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +5 -3
- 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 +2 -1
- package/src/crews/advisor/crew.ork.ts +5 -4
- package/src/crews/advisor/domain/advice.ts +7 -23
- 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 +5 -4
- package/src/crews/agent-run/crew.ork.ts +3 -3
- 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 +16 -14
- package/src/crews/analyze/crew.ork.ts +5 -4
- package/src/crews/analyze/domain/harvest.ts +33 -65
- 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 +10 -17
- package/src/crews/code-review/application/review.ts +4 -1
- package/src/crews/code-review/application/run-code-review.ts +13 -15
- package/src/crews/code-review/crew.ork.ts +5 -4
- package/src/crews/code-review/domain/lenses.ts +6 -45
- 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 +5 -6
- package/src/crews/code-review/domain/scope.ts +6 -12
- package/src/crews/dev-batches/application/messages.ts +127 -0
- package/src/crews/dev-batches/application/plan-close.ts +12 -12
- package/src/crews/dev-batches/application/prompts.ts +10 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +57 -50
- package/src/crews/dev-batches/application/run-wave.ts +24 -22
- package/src/crews/dev-batches/application/seed-harvest.ts +8 -7
- package/src/crews/dev-batches/crew.ork.ts +12 -9
- package/src/crews/dev-batches/domain/batches-log.ts +1 -3
- 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 +3 -2
- package/src/crews/dev-change/application/change-material.ts +44 -0
- package/src/crews/dev-change/application/evidence.ts +25 -22
- package/src/crews/dev-change/application/messages.ts +81 -0
- package/src/crews/dev-change/application/{change-prompt.ts → prompts.ts} +40 -43
- package/src/crews/dev-change/application/run-dev-change.ts +43 -34
- package/src/crews/dev-change/crew.ork.ts +11 -9
- package/src/crews/dev-change/domain/change-answer.ts +24 -20
- package/src/crews/dev-change/domain/change-render.ts +13 -15
- 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 +21 -18
- package/src/crews/dev-implement/application/locate-sheet.ts +7 -5
- package/src/crews/dev-implement/application/messages.ts +161 -0
- package/src/crews/dev-implement/application/observe.ts +4 -2
- package/src/crews/dev-implement/application/prompts.ts +9 -0
- package/src/crews/dev-implement/application/report-writes.ts +14 -9
- package/src/crews/dev-implement/application/run-dev-implement.ts +84 -73
- package/src/crews/dev-implement/application/suite-job.ts +15 -11
- package/src/crews/dev-implement/crew.ork.ts +2 -1
- package/src/crews/dev-implement/domain/contracts.ts +59 -60
- package/src/crews/dev-implement/domain/correction.ts +16 -15
- package/src/crews/dev-implement/domain/cycles.ts +2 -1
- 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 +3 -7
- package/src/crews/dev-implement/domain/sheet-edits.ts +6 -5
- package/src/crews/dev-implement/domain/sheet-ticks.ts +5 -4
- package/src/crews/dev-implement/domain/step-checks.ts +17 -16
- package/src/crews/dev-implement/domain/step-section.ts +6 -4
- 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/{learn-prompt.ts → prompts.ts} +24 -65
- package/src/crews/dev-learn/application/run-dev-learn.ts +37 -32
- package/src/crews/dev-learn/crew.ork.ts +4 -3
- package/src/crews/dev-learn/domain/learn-answer.ts +25 -27
- package/src/crews/dev-learn/domain/messages.ts +65 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +12 -9
- package/src/crews/dev-learn/domain/proposals-render.ts +8 -9
- package/src/crews/dev-plan/application/anchor-paths.ts +57 -20
- package/src/crews/dev-plan/application/inventory.ts +17 -13
- 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/{plan-prompt.ts → prompts.ts} +37 -55
- package/src/crews/dev-plan/application/run-dev-plan.ts +103 -75
- package/src/crews/dev-plan/crew.ork.ts +11 -8
- package/src/crews/dev-plan/domain/inventory-model.ts +3 -3
- 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 +118 -103
- package/src/crews/dev-plan/domain/plan-render.ts +30 -31
- 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/{spec-prompt.ts → prompts.ts} +42 -47
- package/src/crews/dev-spec/application/run-dev-spec.ts +67 -36
- package/src/crews/dev-spec/application/spec-material.ts +42 -0
- package/src/crews/dev-spec/crew.ork.ts +11 -9
- 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 +46 -47
- package/src/crews/dev-spec/domain/spec-render.ts +18 -18
- package/src/crews/dev-verify/application/audit-brief.ts +187 -0
- package/src/crews/dev-verify/application/audit.ts +38 -30
- package/src/crews/dev-verify/application/capture.ts +34 -26
- 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 +60 -46
- package/src/crews/dev-verify/application/run-gate.ts +11 -9
- package/src/crews/dev-verify/crew.ork.ts +6 -6
- package/src/crews/dev-verify/domain/audit-answer.ts +16 -12
- package/src/crews/dev-verify/domain/capture-sections.ts +5 -4
- package/src/crews/dev-verify/domain/commands.ts +3 -3
- package/src/crews/dev-verify/domain/gate.ts +21 -16
- package/src/crews/dev-verify/domain/markers.ts +16 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +37 -44
- package/src/crews/dev-verify/domain/messages.ts +92 -0
- package/src/crews/dev-verify/domain/verdict.ts +4 -4
- package/src/crews/git-commit/application/draft.ts +16 -37
- 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 +13 -12
- package/src/crews/git-commit/crew.ork.ts +5 -4
- package/src/crews/git-commit/domain/commit.ts +15 -35
- 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 +2 -1
- package/src/crews/init-verifiers/application/messages.ts +13 -0
- package/src/crews/init-verifiers/application/prompts.ts +5 -1
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +3 -2
- package/src/crews/init-verifiers/crew.ork.ts +5 -4
- package/src/crews/main-loop/application/auto-compact.ts +2 -1
- 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 +63 -30
- package/src/crews/main-loop/application/{turn-prompt.ts → turn-context.ts} +7 -8
- package/src/crews/main-loop/crew.ork.ts +12 -7
- package/src/crews/main-loop/domain/prompt-assembly.ts +45 -228
- package/src/crews/main-loop/domain/prompts.ts +336 -0
- package/src/crews/main-loop/domain/turn-chains.ts +10 -9
- package/src/crews/project-init/application/detect.ts +5 -4
- package/src/crews/project-init/application/messages.ts +15 -0
- package/src/crews/project-init/application/prompts.ts +11 -7
- package/src/crews/project-init/crew.ork.ts +5 -4
- package/src/crews/project-init/domain/existing-files.ts +6 -4
- package/src/crews/project-init/domain/messages.ts +13 -0
- package/src/crews/project-init/domain/package-map.ts +3 -3
- 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 +5 -4
- package/src/crews/shared-memory-admit/application/prompts.ts +5 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +3 -2
- 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 +2 -1
- package/src/crews/speech/crew.ork.ts +2 -1
- package/src/shared/application/agents/child-agent.ts +11 -7
- 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 +31 -8
- package/src/shared/application/compaction/compact-session.ts +19 -14
- 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/dev/brief-inventory.ts +6 -4
- package/src/shared/application/dev/close-batch.ts +9 -7
- package/src/shared/application/dev/find-repo-pack.ts +4 -3
- package/src/shared/application/dev/learn-decision.ts +20 -18
- package/src/shared/application/dev/load-dev-context.ts +7 -8
- package/src/shared/application/dev/measure-access-cost.ts +5 -4
- 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 +12 -8
- package/src/shared/application/dev/preflight.ts +8 -8
- package/src/shared/application/dev/prompts.ts +34 -0
- package/src/shared/application/dev/question-round.ts +25 -17
- package/src/shared/application/dev/resolve-work-folder.ts +4 -3
- package/src/shared/application/dev/settle-questions.ts +4 -2
- package/src/shared/application/dev/source-review.ts +12 -8
- package/src/shared/application/dev/source-step.ts +12 -10
- package/src/shared/application/dev/spend.ts +17 -4
- package/src/shared/application/dev/step-precedents.ts +2 -1
- package/src/shared/application/dev/tool-call-policy.ts +9 -11
- package/src/shared/application/dev/tool-callbacks.ts +52 -5
- package/src/shared/application/dev/tool-trace-recorder.ts +2 -1
- package/src/shared/application/dev/verdict-sources.ts +5 -3
- package/src/shared/application/dev/wrapped-tools.ts +4 -2
- package/src/shared/application/extra-tools.ts +2 -1
- package/src/shared/application/git/batch-worktree.ts +22 -17
- package/src/shared/application/git/commit-files.ts +24 -19
- package/src/shared/application/git/merge-batch.ts +11 -7
- package/src/shared/application/git/messages.ts +75 -0
- package/src/shared/application/git/open-pull-request.ts +4 -3
- package/src/shared/application/host-context.ts +59 -0
- package/src/shared/application/host-layout-store.ts +45 -0
- package/src/shared/application/llm-profile.ts +4 -3
- package/src/shared/application/messages.ts +14 -0
- package/src/shared/application/permission-rules.ts +10 -0
- package/src/shared/application/ports/decision.ts +14 -0
- package/src/shared/application/ports/human.ts +25 -0
- package/src/shared/application/ports/llm.ts +32 -3
- package/src/shared/application/ports/memory.ts +1 -1
- package/src/shared/application/ports/theme.ts +11 -0
- package/src/shared/application/ports.ts +4 -2
- package/src/shared/application/session-io.ts +2 -1
- package/src/shared/application/shared-memory/admit-entries.ts +16 -14
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +5 -8
- package/src/shared/application/shared-memory/harvest-mistakes.ts +3 -2
- package/src/shared/application/shared-memory/import-agent-memory.ts +9 -7
- package/src/shared/application/shared-memory/memory-files.ts +2 -1
- package/src/shared/application/shared-memory/memory-settings.ts +2 -1
- package/src/shared/application/shared-memory/messages.ts +63 -0
- package/src/shared/application/shared-memory/push-candidate.ts +14 -11
- package/src/shared/application/shared-memory/recall-precedents.ts +2 -1
- package/src/shared/application/skills/messages.ts +4 -0
- package/src/shared/application/skills/suggest-skills.ts +102 -0
- package/src/shared/application/workflow/messages.ts +8 -0
- package/src/shared/application/workflow/workflow-state.ts +7 -6
- package/src/shared/domain/agent-policy/behavior-flags.ts +4 -10
- package/src/shared/domain/agent-policy/extra-tools.ts +2 -4
- package/src/shared/domain/agent-policy/messages.ts +66 -0
- package/src/shared/domain/agent-policy/path-rules.ts +299 -0
- package/src/shared/domain/agent-policy/permission.ts +20 -18
- 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 +18 -14
- package/src/shared/domain/agent-policy/tool-access.ts +17 -3
- package/src/shared/domain/agent-registry.ts +6 -5
- package/src/shared/domain/agents/chain.ts +2 -2
- package/src/shared/domain/agents/charter.ts +8 -5
- package/src/shared/domain/agents/exclusive.ts +2 -1
- package/src/shared/domain/agents/instances.ts +18 -15
- 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 +5 -4
- package/src/shared/domain/code-intel-routing.ts +8 -61
- package/src/shared/domain/compact-outcome.ts +5 -3
- package/src/shared/domain/compaction-thresholds.ts +2 -1
- package/src/shared/domain/compaction.ts +22 -113
- package/src/shared/domain/config-schema.ts +94 -81
- 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 +19 -15
- package/src/shared/domain/dev/batches-concurrency.ts +5 -6
- package/src/shared/domain/dev/build-commands.ts +5 -4
- package/src/shared/domain/dev/call-guard.ts +29 -28
- package/src/shared/domain/dev/carried-text.ts +3 -5
- package/src/shared/domain/dev/learn-proposals.ts +5 -4
- package/src/shared/domain/dev/learn-state.ts +3 -2
- package/src/shared/domain/dev/markers.ts +107 -0
- package/src/shared/domain/dev/messages.ts +259 -0
- package/src/shared/domain/dev/phase-timing.ts +50 -0
- package/src/shared/domain/dev/plan-checks.ts +24 -23
- package/src/shared/domain/dev/plan-format.ts +14 -24
- package/src/shared/domain/dev/project-files.ts +1 -15
- package/src/shared/domain/dev/prompts/brief-blocks.ts +20 -0
- package/src/shared/domain/dev/{review-prompt.ts → prompts.ts} +91 -61
- package/src/shared/domain/dev/questions.ts +33 -15
- package/src/shared/domain/dev/repo-pack.ts +12 -9
- package/src/shared/domain/dev/review-answer.ts +40 -17
- package/src/shared/domain/dev/review-brief.ts +54 -0
- package/src/shared/domain/dev/reviewer-charter.ts +4 -0
- package/src/shared/domain/dev/sheet-facts.ts +2 -4
- package/src/shared/domain/dev/spec-format.ts +13 -14
- package/src/shared/domain/dev/step-budget.ts +4 -2
- package/src/shared/domain/dev/step-rules.ts +3 -4
- package/src/shared/domain/dev/test-commands.ts +14 -10
- package/src/shared/domain/dev/tool-guards.ts +4 -3
- package/src/shared/domain/dev/trait-pattern.ts +14 -10
- package/src/shared/domain/dev/verdict-format.ts +14 -21
- package/src/shared/domain/dev/whitespace.ts +3 -2
- package/src/shared/domain/dev/work-folder.ts +4 -3
- package/src/shared/domain/dev/yaml-subset.ts +8 -26
- package/src/shared/domain/error-text.ts +13 -0
- package/src/shared/domain/git/close.ts +5 -4
- package/src/shared/domain/git/messages.ts +20 -0
- package/src/shared/domain/git/pull-request.ts +5 -5
- package/src/shared/domain/host-layout.ts +147 -0
- package/src/shared/domain/host-paths.ts +399 -0
- package/src/shared/domain/llm-failure.ts +35 -7
- package/src/shared/domain/llm-profile.ts +22 -3
- package/src/shared/domain/marked-message.ts +1 -5
- package/src/shared/domain/markers.ts +30 -0
- package/src/shared/domain/messages.ts +291 -0
- package/src/shared/domain/model-catalog.ts +2 -9
- package/src/shared/domain/permission-modes.ts +4 -8
- package/src/shared/domain/prelude.ts +2 -2
- package/src/shared/domain/project-manifests.ts +3 -2
- package/src/shared/domain/prompts.ts +233 -0
- package/src/shared/domain/search-routing.ts +3 -11
- package/src/shared/domain/secret-patterns.ts +3 -2
- package/src/shared/domain/session-keys.ts +7 -0
- package/src/shared/domain/session-start.ts +3 -2
- package/src/shared/domain/shared-memory/agent-memory-import.ts +4 -2
- package/src/shared/domain/shared-memory/candidates.ts +3 -4
- package/src/shared/domain/shared-memory/entry.ts +26 -20
- package/src/shared/domain/shared-memory/front-matter.ts +17 -13
- package/src/shared/domain/shared-memory/gate.ts +4 -3
- package/src/shared/domain/shared-memory/harvest.ts +9 -6
- package/src/shared/domain/shared-memory/layout.ts +11 -8
- 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 +4 -15
- package/src/shared/domain/shared-memory/prompts.ts +28 -0
- package/src/shared/domain/shared-memory/refused.ts +3 -3
- 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 +2 -14
- package/src/shared/domain/speech.ts +2 -1
- package/src/shared/domain/tool-trace.ts +5 -7
- package/src/shared/domain/verifiers.ts +7 -11
- package/src/shared/domain/vfs.ts +8 -1
- package/src/shared/domain/workflow/prompts.ts +15 -0
- package/src/shared/domain/workflow/state-file.ts +14 -12
- package/src/shared/infrastructure/globals.ts +7 -2
- package/src/shared/infrastructure/orkeon/child-agents.ts +11 -16
- package/src/shared/infrastructure/orkeon/chooser.ts +32 -0
- package/src/shared/infrastructure/orkeon/decision-model.ts +31 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +21 -14
- package/src/shared/infrastructure/orkeon/files.ts +24 -6
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +3 -2
- package/src/shared/infrastructure/orkeon/host-context.ts +36 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +1 -5
- package/src/shared/infrastructure/orkeon/llm-profile.ts +36 -16
- package/src/shared/infrastructure/orkeon/llm.ts +85 -30
- package/src/shared/infrastructure/orkeon/markers.ts +6 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +1 -1
- package/src/shared/infrastructure/orkeon/memory-tools.ts +18 -20
- package/src/shared/infrastructure/orkeon/messages.ts +15 -0
- package/src/shared/infrastructure/orkeon/prompts.ts +47 -0
- package/src/shared/infrastructure/orkeon/reasoning.ts +40 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +14 -19
- package/src/shared/infrastructure/orkeon/session-store.ts +7 -51
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +13 -7
- package/src/shared/infrastructure/orkeon/shell.ts +13 -5
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +3 -2
- package/src/shared/infrastructure/orkeon/wiring.ts +68 -12
- package/src/crews/dev-verify/application/auditor-prompt.ts +0 -323
- package/src/shared/domain/session-summary.ts +0 -13
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The host Orkeon Code was started on, as the launcher wrote it to /user-config/launch.json (docs/architecture.md,
|
|
2
|
+
// "The VFS and the host platform"): its flavour (a posix system, WSL, native Windows) and the physical base of each
|
|
3
|
+
// VFS mount, in the spellings the launcher knows. The code never learns these bases from the runtime, which hides
|
|
4
|
+
// them (list_mounts answers virtual paths only): the launcher is the one holder. Without the file, or with one it
|
|
5
|
+
// cannot read, the layout is IDENTITY_HOST and every conversion of host-paths.ts is the identity. Pure.
|
|
6
|
+
import {
|
|
7
|
+
LAUNCH_MOUNTS_NOT_AN_OBJECT, LAUNCH_NOT_AN_OBJECT, launchFlavourIsNot, launchVersionIsNot, mountHasNoBases,
|
|
8
|
+
mountNoUsableBase, noMountBase, notAMountPoint, posixBaseNotAbsolute, windowsBaseNotADrive, wslWhere,
|
|
9
|
+
} from "./messages.ts";
|
|
10
|
+
|
|
11
|
+
export type HostFlavour = "posix" | "wsl" | "windows";
|
|
12
|
+
|
|
13
|
+
/** One mount and its physical base as the launcher passed it to `--mount`, in each spelling it knows. */
|
|
14
|
+
export interface MountBase {
|
|
15
|
+
/** The virtual path, `/workspace`. */
|
|
16
|
+
virtual: string;
|
|
17
|
+
/** The base as the posix side spells it (`/mnt/c/ici est/mon repertoire`, `/home/me/x`): absent on native Windows. */
|
|
18
|
+
posix?: string;
|
|
19
|
+
/** The base as Windows spells it (`C:\ici est\mon repertoire`, `\\wsl.localhost\Ubuntu\home\me\x`): absent on a
|
|
20
|
+
* plain posix host, and under WSL when the launcher had no `wslpath`. */
|
|
21
|
+
windows?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface HostLayout {
|
|
25
|
+
flavour: HostFlavour;
|
|
26
|
+
/** The WSL distribution (`Ubuntu`), for the `\\wsl$\<distro>\` and `\\wsl.localhost\<distro>\` spellings. */
|
|
27
|
+
distro?: string;
|
|
28
|
+
/** Where WSL mounts the Windows drives: `/mnt` (then `C:` is `/mnt/c`). */
|
|
29
|
+
automountRoot: string;
|
|
30
|
+
mounts: MountBase[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** No host facts: a posix host whose bases are unknown, every conversion the identity. */
|
|
34
|
+
export const IDENTITY_HOST: HostLayout = Object.freeze({ flavour: "posix", automountRoot: "/mnt", mounts: [] }) as HostLayout;
|
|
35
|
+
|
|
36
|
+
/** The version of launch.json this code reads. */
|
|
37
|
+
export const HOST_LAYOUT_VERSION = 1;
|
|
38
|
+
|
|
39
|
+
const FLAVOURS: readonly HostFlavour[] = ["posix", "wsl", "windows"];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The layout a launch.json holds. Anything unusable (not an object, another version, an unknown flavour) is
|
|
43
|
+
* IDENTITY_HOST with the reason in `problems`; a mount entry that is not usable is dropped and named there, the
|
|
44
|
+
* others kept. Each base is normalised: no trailing separator (a drive root keeps `C:\`), the drive letter
|
|
45
|
+
* upper-cased in a Windows spelling and lower-cased under the automount root, `/` for `\` in a Windows spelling.
|
|
46
|
+
*/
|
|
47
|
+
export function parseHostLayout(raw: unknown): { layout: HostLayout; problems: string[] } {
|
|
48
|
+
const problems: string[] = [];
|
|
49
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
50
|
+
return { layout: IDENTITY_HOST, problems: [LAUNCH_NOT_AN_OBJECT] };
|
|
51
|
+
}
|
|
52
|
+
const o = raw as Record<string, unknown>;
|
|
53
|
+
if (o.version !== HOST_LAYOUT_VERSION) {
|
|
54
|
+
return { layout: IDENTITY_HOST, problems: [launchVersionIsNot(String(o.version), HOST_LAYOUT_VERSION)] };
|
|
55
|
+
}
|
|
56
|
+
if (typeof o.flavour !== "string" || !FLAVOURS.includes(o.flavour as HostFlavour)) {
|
|
57
|
+
return { layout: IDENTITY_HOST, problems: [launchFlavourIsNot(String(o.flavour))] };
|
|
58
|
+
}
|
|
59
|
+
const flavour = o.flavour as HostFlavour;
|
|
60
|
+
const wsl = flavour === "wsl" && o.wsl !== null && typeof o.wsl === "object" ? (o.wsl as Record<string, unknown>) : {};
|
|
61
|
+
const distro = typeof wsl.distro === "string" && wsl.distro !== "" ? wsl.distro : undefined;
|
|
62
|
+
const automountRoot = typeof wsl.automountRoot === "string" && wsl.automountRoot.startsWith("/")
|
|
63
|
+
? trimTrailing(wsl.automountRoot, "/") || "/"
|
|
64
|
+
: "/mnt";
|
|
65
|
+
const mounts: MountBase[] = [];
|
|
66
|
+
const plain = o.mounts !== null && typeof o.mounts === "object" && !Array.isArray(o.mounts);
|
|
67
|
+
if (o.mounts !== undefined && !plain) problems.push(LAUNCH_MOUNTS_NOT_AN_OBJECT);
|
|
68
|
+
const entries = plain ? Object.entries(o.mounts as Record<string, unknown>) : [];
|
|
69
|
+
for (const [virtual, bases] of entries) {
|
|
70
|
+
const mount = parseMount(virtual, bases, automountRoot, problems);
|
|
71
|
+
if (mount !== null) mounts.push(mount);
|
|
72
|
+
}
|
|
73
|
+
return { layout: { flavour, ...(distro === undefined ? {} : { distro }), automountRoot, mounts }, problems };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseMount(virtual: string, bases: unknown, automountRoot: string, problems: string[]): MountBase | null {
|
|
77
|
+
if (!/^\/[^/\\]+$/.test(virtual)) {
|
|
78
|
+
problems.push(notAMountPoint(virtual));
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (bases === null || typeof bases !== "object" || Array.isArray(bases)) {
|
|
82
|
+
problems.push(mountHasNoBases(virtual));
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const b = bases as Record<string, unknown>;
|
|
86
|
+
const posix = typeof b.posix === "string" ? normalisePosixBase(b.posix, automountRoot) : undefined;
|
|
87
|
+
const windows = typeof b.windows === "string" ? normaliseWindowsBase(b.windows) : undefined;
|
|
88
|
+
if (typeof b.posix === "string" && posix === undefined) problems.push(posixBaseNotAbsolute(virtual, b.posix));
|
|
89
|
+
if (typeof b.windows === "string" && windows === undefined) problems.push(windowsBaseNotADrive(virtual, b.windows));
|
|
90
|
+
if (posix === undefined && windows === undefined) {
|
|
91
|
+
if (typeof b.posix !== "string" && typeof b.windows !== "string") problems.push(mountNoUsableBase(virtual));
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return { virtual, ...(posix === undefined ? {} : { posix }), ...(windows === undefined ? {} : { windows }) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** An absolute posix base without its trailing `/`; the drive letter lower-cased under the automount root. */
|
|
98
|
+
function normalisePosixBase(base: string, automountRoot: string): string | undefined {
|
|
99
|
+
if (!base.startsWith("/")) return undefined;
|
|
100
|
+
const trimmed = trimTrailing(base, "/");
|
|
101
|
+
if (trimmed === "") return undefined;
|
|
102
|
+
const root = automountRoot === "/" ? "" : automountRoot;
|
|
103
|
+
const drive = new RegExp(`^${escapeRegExp(root)}/([A-Za-z])(/|$)`).exec(trimmed);
|
|
104
|
+
return drive === null ? trimmed : `${root}/${drive[1].toLowerCase()}${trimmed.slice(root.length + 2)}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A Windows base with `\`, no trailing separator (a drive root keeps `C:\`), its drive letter upper-cased. */
|
|
108
|
+
function normaliseWindowsBase(base: string): string | undefined {
|
|
109
|
+
const backslashed = base.replace(/\//g, "\\");
|
|
110
|
+
const drive = /^([A-Za-z]):(\\|$)/.exec(backslashed);
|
|
111
|
+
if (drive !== null) {
|
|
112
|
+
const rest = trimTrailing(backslashed.slice(2), "\\");
|
|
113
|
+
return `${drive[1].toUpperCase()}:${rest === "" ? "\\" : rest}`;
|
|
114
|
+
}
|
|
115
|
+
if (/^\\\\[^\\]+\\[^\\]+/.test(backslashed)) return trimTrailing(backslashed, "\\");
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function trimTrailing(text: string, char: string): string {
|
|
120
|
+
let end = text.length;
|
|
121
|
+
while (end > 0 && text[end - 1] === char) end--;
|
|
122
|
+
return text.slice(0, end);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function escapeRegExp(text: string): string {
|
|
126
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** True when `layout` carries no host fact: a posix flavour and no mount. */
|
|
130
|
+
export function isIdentityHost(layout: HostLayout): boolean {
|
|
131
|
+
return layout.flavour === "posix" && layout.mounts.length === 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The layout in a line, for /doctor: the flavour, under WSL the distribution and the automount root, then each mount
|
|
135
|
+
* with its base as the host spells it, the Windows spelling in parentheses under WSL when the launcher knew it. */
|
|
136
|
+
export function describeHostLayout(layout: HostLayout): string {
|
|
137
|
+
const where = layout.flavour === "wsl"
|
|
138
|
+
? wslWhere(layout.distro ?? "distribution unknown", layout.automountRoot)
|
|
139
|
+
: layout.flavour;
|
|
140
|
+
if (layout.mounts.length === 0) return noMountBase(where);
|
|
141
|
+
const bases = layout.mounts.map((m) => {
|
|
142
|
+
const base = layout.flavour === "windows" ? (m.windows ?? m.posix) : (m.posix ?? m.windows);
|
|
143
|
+
const other = layout.flavour === "wsl" && m.posix !== undefined && m.windows !== undefined ? ` (${m.windows})` : "";
|
|
144
|
+
return `${m.virtual} = ${base ?? "?"}${other}`;
|
|
145
|
+
});
|
|
146
|
+
return `${where}: ${bases.join(", ")}`;
|
|
147
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
// last call without tools and resolved with that answer): the answer rides on the
|
|
9
9
|
// error, so no caller reads a cut-short wrap-up as a finished answer, and the
|
|
10
10
|
// readers of a spent budget (shared/domain/dev/step-budget.ts) see the `tokens`
|
|
11
|
-
// dimension as they did when the runtime rejected.
|
|
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
|
|
12
16
|
// the host blocked is no failure of the provider: the runtime rejects it with a
|
|
13
17
|
// DecisionBlockedError (Orkeon #269), which decisionBlockOf reads. Pure, no IO.
|
|
18
|
+
import {
|
|
19
|
+
BUDGET_EXHAUSTED_MESSAGE, blockedByDecisionProfile, iterationsExhaustedMessage, matchesTheRisk, modelCallFailed,
|
|
20
|
+
} from "./messages.ts";
|
|
14
21
|
|
|
15
22
|
const MARKER = /^<undefined-llm:([\s\S]*)>$/;
|
|
16
23
|
|
|
@@ -31,7 +38,7 @@ export function llmFailureOf(text: unknown): LlmFailure | null {
|
|
|
31
38
|
const detail = m[1].length > MAX_DETAIL ? `${m[1].slice(0, MAX_DETAIL)}…` : m[1];
|
|
32
39
|
// A plain Error with a name rather than a subclass: subclassing Error is not
|
|
33
40
|
// something the bundles rely on anywhere else, in Jint or in Node.
|
|
34
|
-
const failure = new Error(
|
|
41
|
+
const failure = new Error(modelCallFailed(detail)) as LlmFailure;
|
|
35
42
|
failure.name = "LlmFailure";
|
|
36
43
|
failure.detail = detail;
|
|
37
44
|
return failure;
|
|
@@ -71,9 +78,8 @@ export function decisionBlockOf(error: unknown): DecisionBlock | null {
|
|
|
71
78
|
|
|
72
79
|
/** What the user reads for a blocked request: a decision, not an outage, and what to do about it. */
|
|
73
80
|
export function decisionBlockText(block: DecisionBlock): string {
|
|
74
|
-
const why = block.reason ?? (block.risk === null ? null :
|
|
75
|
-
return
|
|
76
|
-
"The model gave no answer; rephrase the request, or choose another profile with /config set llm.profile.";
|
|
81
|
+
const why = block.reason ?? (block.risk === null ? null : matchesTheRisk(block.risk));
|
|
82
|
+
return blockedByDecisionProfile(block.profile, block.stage, why);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/** The error an act whose token budget ran out throws: the wrap-up answer the model gave in its last call, and the
|
|
@@ -85,8 +91,6 @@ export interface BudgetExhaustedAnswer extends Error {
|
|
|
85
91
|
answer: string;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
/** What the error says: the runtime's words, so a reader of the message sees the dimension. */
|
|
89
|
-
export const BUDGET_EXHAUSTED_MESSAGE = "Token budget exhausted: the model made its last call without tools, and its answer is cut short";
|
|
90
94
|
|
|
91
95
|
/** The error carrying the wrap-up `answer` of an act that resolved with `budgetExhausted`. */
|
|
92
96
|
export function budgetExhaustedAnswer(answer: string): BudgetExhaustedAnswer {
|
|
@@ -104,3 +108,27 @@ export function budgetExhaustedAnswerOf(failure: unknown): BudgetExhaustedAnswer
|
|
|
104
108
|
const answer = (failure as { answer?: unknown }).answer;
|
|
105
109
|
return typeof answer === "string" ? failure as BudgetExhaustedAnswer : null;
|
|
106
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
|
+
}
|
|
@@ -4,17 +4,36 @@
|
|
|
4
4
|
// in its input, under `llmProfile`; the crew's composition root builds every agent on it
|
|
5
5
|
// (shared/infrastructure/orkeon/llm-profile.ts). Omitted, the agents run on the host's default model,
|
|
6
6
|
// as they always did.
|
|
7
|
+
import { PROFILE_NAME_EXPECTED, profileHoldsColon, profileHoldsSpace } from "./messages.ts";
|
|
7
8
|
|
|
8
9
|
export const LLM_PROFILE_CONFIG_KEY = "llm.profile";
|
|
9
10
|
/** The field of a crew input that carries the profile's name. */
|
|
10
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
|
+
}
|
|
11
30
|
|
|
12
31
|
/** Why a value is refused for `llm.profile`; undefined when it is a profile name. */
|
|
13
32
|
export function llmProfileProblem(value: string): string | undefined {
|
|
14
33
|
const name = value.trim();
|
|
15
|
-
if (name === "") return
|
|
16
|
-
if (/\s/.test(name)) return
|
|
17
|
-
if (name.includes(":")) return
|
|
34
|
+
if (name === "") return PROFILE_NAME_EXPECTED;
|
|
35
|
+
if (/\s/.test(name)) return profileHoldsSpace(value);
|
|
36
|
+
if (name.includes(":")) return profileHoldsColon(value);
|
|
18
37
|
return undefined;
|
|
19
38
|
}
|
|
20
39
|
|