orkeon-code 0.0.0-stage → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.orkeon-version +1 -0
- package/LICENSE.md +21 -0
- package/NOTICE.md +17 -0
- package/README.fr.md +169 -0
- package/README.md +162 -2
- package/config/appsettings.anthropic.example.json +77 -0
- package/config/appsettings.example.json +71 -0
- package/config/appsettings.jev.example.json +128 -0
- package/config/appsettings.kev.example.json +130 -0
- package/config/appsettings.liquid.example.json +129 -0
- package/config/appsettings.ollama-whisper.example.json +92 -0
- package/config/appsettings.ollama.example.json +70 -0
- package/config/appsettings.whisper.example.json +31 -0
- package/mcp/whisper/README.md +293 -0
- package/mcp/whisper/pyproject.toml +32 -0
- package/mcp/whisper/uv.lock +1641 -0
- package/mcp/whisper/whisper_mcp.py +1053 -0
- package/orkeon-code +897 -0
- package/orkeon-code.mjs +71 -0
- package/orkeon-code.ps1 +837 -0
- package/package.json +57 -4
- package/scripts/install.ps1 +156 -0
- package/scripts/install.sh +148 -0
- package/scripts/session-start.ork.ts +90 -0
- package/scripts/session-start.sh +74 -0
- package/scripts/setup-fixture.sh +88 -0
- package/src/commands/.orkeon/orkeon-cli.d.ts +562 -0
- package/src/commands/_lib/args.ts +193 -0
- package/src/commands/_lib/dev/dev-batches.ts +368 -0
- package/src/commands/_lib/dev/dev-implement.ts +188 -0
- package/src/commands/_lib/dev/dev-source.ts +65 -0
- package/src/commands/_lib/dev/dev.ts +344 -0
- package/src/commands/_lib/dev-step.ts +142 -0
- package/src/commands/_lib/dispatch.ts +231 -0
- package/src/commands/_lib/effort.ts +15 -0
- package/src/commands/_lib/git/branch.ts +95 -0
- package/src/commands/_lib/git/commit.ts +94 -0
- package/src/commands/_lib/git/diff.ts +97 -0
- package/src/commands/_lib/git/review.ts +109 -0
- package/src/commands/_lib/memory/memory-admit.ts +150 -0
- package/src/commands/_lib/memory/memory.ts +51 -0
- package/src/commands/_lib/pr-context.ts +32 -0
- package/src/commands/_lib/project/analyze.ts +24 -0
- package/src/commands/_lib/session/export.ts +104 -0
- package/src/commands/_lib/session/resume.ts +160 -0
- package/src/commands/_lib/session/tasks.ts +184 -0
- package/src/commands/_lib/settings/advisor.ts +80 -0
- package/src/commands/_lib/settings/agents.ts +147 -0
- package/src/commands/_lib/settings/config.ts +141 -0
- package/src/commands/_lib/settings/hooks.ts +58 -0
- package/src/commands/_lib/settings/mode.ts +91 -0
- package/src/commands/_lib/settings/model.ts +146 -0
- package/src/commands/_lib/settings/permissions.ts +309 -0
- package/src/commands/_lib/settings/session-config.ts +49 -0
- package/src/commands/_lib/settings/skills.ts +51 -0
- package/src/commands/_lib/speech/say.ts +96 -0
- package/src/commands/_lib/speech/transcribe.ts +130 -0
- package/src/commands/_lib/speech/voice.ts +146 -0
- package/src/commands/_lib/status/cache.ts +31 -0
- package/src/commands/_lib/status/context.ts +57 -0
- package/src/commands/_lib/status/doctor.ts +186 -0
- package/src/commands/_lib/status/meta.ts +45 -0
- package/src/commands/_lib/status/status.ts +129 -0
- package/src/commands/_lib/status/usage-tools.ts +49 -0
- package/src/commands/_lib/status/usage.ts +139 -0
- package/src/commands/_lib/view.ts +29 -0
- package/src/commands/dev/dev-batches.cmd.ts +108 -0
- package/src/commands/dev/dev-learn.cmd.ts +29 -0
- package/src/commands/dev/dev-plan.cmd.ts +52 -0
- package/src/commands/dev/dev-spec.cmd.ts +55 -0
- package/src/commands/dev/dev-status.cmd.ts +16 -0
- package/src/commands/git/branch.cmd.ts +27 -0
- package/src/commands/git/commit.cmd.ts +48 -0
- package/src/commands/git/diff.cmd.ts +26 -0
- package/src/commands/git/review.cmd.ts +36 -0
- package/src/commands/memory/memory.cmd.ts +48 -0
- package/src/commands/project/analyze.cmd.ts +32 -0
- package/src/commands/project/debug-tool-call.cmd.ts +67 -0
- package/src/commands/project/files.cmd.ts +22 -0
- package/src/commands/project/init-verifiers.cmd.ts +14 -0
- package/src/commands/project/init.cmd.ts +14 -0
- package/src/commands/project/verify.cmd.ts +27 -0
- package/src/commands/session/assistant.cmd.ts +40 -0
- package/src/commands/session/btw.cmd.ts +18 -0
- package/src/commands/session/clear.cmd.ts +19 -0
- package/src/commands/session/compact.cmd.ts +16 -0
- package/src/commands/session/copy.cmd.ts +44 -0
- package/src/commands/session/exit.cmd.ts +9 -0
- package/src/commands/session/export.cmd.ts +28 -0
- package/src/commands/session/rename.cmd.ts +17 -0
- package/src/commands/session/resume.cmd.ts +19 -0
- package/src/commands/session/rewind.cmd.ts +26 -0
- package/src/commands/session/summary.cmd.ts +27 -0
- package/src/commands/session/tasks.cmd.ts +44 -0
- package/src/commands/settings/advisor.cmd.ts +38 -0
- package/src/commands/settings/agents.cmd.ts +19 -0
- package/src/commands/settings/config.cmd.ts +17 -0
- package/src/commands/settings/effort.cmd.ts +40 -0
- package/src/commands/settings/fast.cmd.ts +17 -0
- package/src/commands/settings/hooks.cmd.ts +17 -0
- package/src/commands/settings/mode.cmd.ts +20 -0
- package/src/commands/settings/model.cmd.ts +20 -0
- package/src/commands/settings/output-style.cmd.ts +48 -0
- package/src/commands/settings/permissions.cmd.ts +25 -0
- package/src/commands/settings/proactive.cmd.ts +15 -0
- package/src/commands/settings/skills.cmd.ts +17 -0
- package/src/commands/speech/say.cmd.ts +24 -0
- package/src/commands/speech/transcribe.cmd.ts +29 -0
- package/src/commands/speech/voice.cmd.ts +30 -0
- package/src/commands/status/context.cmd.ts +18 -0
- package/src/commands/status/doctor.cmd.ts +27 -0
- package/src/commands/status/release-notes.cmd.ts +9 -0
- package/src/commands/status/status.cmd.ts +25 -0
- package/src/commands/status/usage.cmd.ts +21 -0
- package/src/crews/.orkeon/orkeon.d.ts +3946 -0
- package/src/crews/_probe-shared-memory/domain/probe-verdict.ts +183 -0
- package/src/crews/_probe-shared-memory/probe.ork.ts +98 -0
- package/src/crews/advisor/application/run-advisor.ts +40 -0
- package/src/crews/advisor/crew.ork.ts +43 -0
- package/src/crews/advisor/domain/advice.ts +135 -0
- package/src/crews/agent-run/application/run-agent-run.ts +42 -0
- package/src/crews/agent-run/crew.ork.ts +67 -0
- package/src/crews/analyze/application/run-analyze.ts +118 -0
- package/src/crews/analyze/crew.ork.ts +40 -0
- package/src/crews/analyze/domain/harvest.ts +301 -0
- package/src/crews/code-review/application/prompts.ts +133 -0
- package/src/crews/code-review/application/review.ts +71 -0
- package/src/crews/code-review/application/run-code-review.ts +123 -0
- package/src/crews/code-review/crew.ork.ts +51 -0
- package/src/crews/code-review/domain/lenses.ts +193 -0
- package/src/crews/code-review/domain/report.ts +59 -0
- package/src/crews/code-review/domain/scope.ts +112 -0
- package/src/crews/dev-batches/application/plan-close.ts +181 -0
- package/src/crews/dev-batches/application/run-dev-batches.ts +669 -0
- package/src/crews/dev-batches/application/run-wave.ts +450 -0
- package/src/crews/dev-batches/application/seed-harvest.ts +162 -0
- package/src/crews/dev-batches/crew.ork.ts +143 -0
- package/src/crews/dev-batches/domain/batch-waves.ts +70 -0
- package/src/crews/dev-batches/domain/batches-budget.ts +52 -0
- package/src/crews/dev-batches/domain/batches-log.ts +54 -0
- package/src/crews/dev-batches/domain/wave-order.ts +43 -0
- package/src/crews/dev-change/application/change-prompt.ts +104 -0
- package/src/crews/dev-change/application/evidence.ts +169 -0
- package/src/crews/dev-change/application/run-dev-change.ts +315 -0
- package/src/crews/dev-change/crew.ork.ts +112 -0
- package/src/crews/dev-change/domain/change-answer.ts +159 -0
- package/src/crews/dev-change/domain/change-render.ts +79 -0
- package/src/crews/dev-implement/application/close.ts +183 -0
- package/src/crews/dev-implement/application/count-open-steps.ts +24 -0
- package/src/crews/dev-implement/application/locate-sheet.ts +80 -0
- package/src/crews/dev-implement/application/observe.ts +50 -0
- package/src/crews/dev-implement/application/report-writes.ts +41 -0
- package/src/crews/dev-implement/application/run-dev-implement.ts +811 -0
- package/src/crews/dev-implement/application/run-role.ts +27 -0
- package/src/crews/dev-implement/application/suite-job.ts +118 -0
- package/src/crews/dev-implement/application/touched.ts +74 -0
- package/src/crews/dev-implement/crew.ork.ts +68 -0
- package/src/crews/dev-implement/domain/contracts.ts +256 -0
- package/src/crews/dev-implement/domain/correction.ts +102 -0
- package/src/crews/dev-implement/domain/cycles.ts +35 -0
- package/src/crews/dev-implement/domain/implement-budget.ts +29 -0
- package/src/crews/dev-implement/domain/roles.ts +53 -0
- package/src/crews/dev-implement/domain/sheet-edits.ts +75 -0
- package/src/crews/dev-implement/domain/sheet-ticks.ts +22 -0
- package/src/crews/dev-implement/domain/step-checks.ts +136 -0
- package/src/crews/dev-implement/domain/step-section.ts +127 -0
- package/src/crews/dev-learn/application/learn-backlog.ts +58 -0
- package/src/crews/dev-learn/application/learn-prompt.ts +140 -0
- package/src/crews/dev-learn/application/run-dev-learn.ts +553 -0
- package/src/crews/dev-learn/crew.ork.ts +52 -0
- package/src/crews/dev-learn/domain/learn-answer.ts +235 -0
- package/src/crews/dev-learn/domain/owner-lines.ts +86 -0
- package/src/crews/dev-learn/domain/proposals-render.ts +96 -0
- package/src/crews/dev-plan/application/anchor-paths.ts +76 -0
- package/src/crews/dev-plan/application/inventory.ts +170 -0
- package/src/crews/dev-plan/application/plan-prompt.ts +159 -0
- package/src/crews/dev-plan/application/run-dev-plan.ts +455 -0
- package/src/crews/dev-plan/crew.ork.ts +109 -0
- package/src/crews/dev-plan/domain/inventory-model.ts +95 -0
- package/src/crews/dev-plan/domain/plan-answer.ts +738 -0
- package/src/crews/dev-plan/domain/plan-render.ts +307 -0
- package/src/crews/dev-spec/application/run-dev-spec.ts +206 -0
- package/src/crews/dev-spec/application/spec-prompt.ts +98 -0
- package/src/crews/dev-spec/crew.ork.ts +108 -0
- package/src/crews/dev-spec/domain/spec-answer.ts +253 -0
- package/src/crews/dev-spec/domain/spec-render.ts +76 -0
- package/src/crews/dev-verify/application/audit.ts +259 -0
- package/src/crews/dev-verify/application/auditor-prompt.ts +323 -0
- package/src/crews/dev-verify/application/capture.ts +303 -0
- package/src/crews/dev-verify/application/run-dev-verify.ts +409 -0
- package/src/crews/dev-verify/application/run-gate.ts +202 -0
- package/src/crews/dev-verify/crew.ork.ts +103 -0
- package/src/crews/dev-verify/domain/audit-answer.ts +150 -0
- package/src/crews/dev-verify/domain/auditor-charter.ts +21 -0
- package/src/crews/dev-verify/domain/capture-sections.ts +137 -0
- package/src/crews/dev-verify/domain/commands.ts +103 -0
- package/src/crews/dev-verify/domain/gate.ts +126 -0
- package/src/crews/dev-verify/domain/mechanical-table.ts +163 -0
- package/src/crews/dev-verify/domain/runtime-cut.ts +13 -0
- package/src/crews/dev-verify/domain/sheet-facts.ts +4 -0
- package/src/crews/dev-verify/domain/text.ts +20 -0
- package/src/crews/dev-verify/domain/verdict.ts +127 -0
- package/src/crews/git-commit/application/draft.ts +154 -0
- package/src/crews/git-commit/application/run-git-commit.ts +116 -0
- package/src/crews/git-commit/crew.ork.ts +52 -0
- package/src/crews/git-commit/domain/commit.ts +220 -0
- package/src/crews/init-verifiers/application/authoring.ts +89 -0
- package/src/crews/init-verifiers/application/prompts.ts +103 -0
- package/src/crews/init-verifiers/application/run-init-verifiers.ts +25 -0
- package/src/crews/init-verifiers/crew.ork.ts +34 -0
- package/src/crews/init-verifiers/domain/commands-section.ts +36 -0
- package/src/crews/init-verifiers/domain/readiness.ts +23 -0
- package/src/crews/main-loop/application/auto-compact.ts +77 -0
- package/src/crews/main-loop/application/context-gather.ts +133 -0
- package/src/crews/main-loop/application/run-main-loop.ts +350 -0
- package/src/crews/main-loop/application/turn-prompt.ts +112 -0
- package/src/crews/main-loop/crew.ork.ts +119 -0
- package/src/crews/main-loop/domain/autocompact.ts +27 -0
- package/src/crews/main-loop/domain/prompt-assembly.ts +521 -0
- package/src/crews/main-loop/domain/turn-chains.ts +129 -0
- package/src/crews/project-init/application/detect.ts +122 -0
- package/src/crews/project-init/application/prompts.ts +101 -0
- package/src/crews/project-init/application/run-project-init.ts +31 -0
- package/src/crews/project-init/crew.ork.ts +35 -0
- package/src/crews/project-init/domain/conventions.ts +36 -0
- package/src/crews/project-init/domain/existing-files.ts +63 -0
- package/src/crews/project-init/domain/package-map.ts +73 -0
- package/src/crews/session-compact/crew.ork.ts +55 -0
- package/src/crews/shared-memory-admit/crew.ork.ts +48 -0
- package/src/crews/speech/application/run-speech.ts +25 -0
- package/src/crews/speech/crew.ork.ts +37 -0
- package/src/shared/application/agents/child-agent.ts +255 -0
- package/src/shared/application/agents/run-sub-agent.ts +96 -0
- package/src/shared/application/answer-language.ts +14 -0
- package/src/shared/application/attached-skills.ts +36 -0
- package/src/shared/application/compaction/compact-session.ts +237 -0
- package/src/shared/application/compaction/extract-memories.ts +38 -0
- package/src/shared/application/compaction/restore-context.ts +78 -0
- package/src/shared/application/config-store.ts +123 -0
- package/src/shared/application/dev/brief-inventory.ts +113 -0
- package/src/shared/application/dev/close-batch.ts +83 -0
- package/src/shared/application/dev/find-repo-pack.ts +77 -0
- package/src/shared/application/dev/learn-decision.ts +252 -0
- package/src/shared/application/dev/load-dev-context.ts +266 -0
- package/src/shared/application/dev/measure-access-cost.ts +68 -0
- package/src/shared/application/dev/plan-source.ts +112 -0
- package/src/shared/application/dev/preflight.ts +71 -0
- package/src/shared/application/dev/project-files.ts +17 -0
- package/src/shared/application/dev/question-round.ts +52 -0
- package/src/shared/application/dev/resolve-work-folder.ts +133 -0
- package/src/shared/application/dev/script-tool-slot.ts +27 -0
- package/src/shared/application/dev/settle-questions.ts +55 -0
- package/src/shared/application/dev/source-review.ts +63 -0
- package/src/shared/application/dev/source-step.ts +150 -0
- package/src/shared/application/dev/spend.ts +42 -0
- package/src/shared/application/dev/step-precedents.ts +89 -0
- package/src/shared/application/dev/tool-call-policy.ts +89 -0
- package/src/shared/application/dev/tool-callbacks.ts +215 -0
- package/src/shared/application/dev/tool-trace-recorder.ts +45 -0
- package/src/shared/application/dev/verdict-sources.ts +48 -0
- package/src/shared/application/dev/wrapped-tools.ts +145 -0
- package/src/shared/application/extra-tools.ts +70 -0
- package/src/shared/application/git/batch-worktree.ts +97 -0
- package/src/shared/application/git/commit-files.ts +186 -0
- package/src/shared/application/git/merge-batch.ts +63 -0
- package/src/shared/application/git/open-pull-request.ts +51 -0
- package/src/shared/application/instructions-file.ts +19 -0
- package/src/shared/application/json-file.ts +34 -0
- package/src/shared/application/llm-profile.ts +35 -0
- package/src/shared/application/permission-rules.ts +159 -0
- package/src/shared/application/ports/approvals.ts +20 -0
- package/src/shared/application/ports/clock.ts +5 -0
- package/src/shared/application/ports/code-index.ts +93 -0
- package/src/shared/application/ports/crew.ts +60 -0
- package/src/shared/application/ports/files.ts +21 -0
- package/src/shared/application/ports/human.ts +13 -0
- package/src/shared/application/ports/llm.ts +54 -0
- package/src/shared/application/ports/memory.ts +30 -0
- package/src/shared/application/ports/progress.ts +23 -0
- package/src/shared/application/ports/runtime.ts +15 -0
- package/src/shared/application/ports/session.ts +74 -0
- package/src/shared/application/ports/shared-memory.ts +26 -0
- package/src/shared/application/ports/shell.ts +40 -0
- package/src/shared/application/ports/telemetry.ts +45 -0
- package/src/shared/application/ports/tools.ts +46 -0
- package/src/shared/application/ports/usage.ts +45 -0
- package/src/shared/application/ports.ts +27 -0
- package/src/shared/application/project-manifests.ts +106 -0
- package/src/shared/application/session-io.ts +84 -0
- package/src/shared/application/session-state.ts +36 -0
- package/src/shared/application/shared-memory/admit-entries.ts +177 -0
- package/src/shared/application/shared-memory/harvest-after-gaps.ts +72 -0
- package/src/shared/application/shared-memory/harvest-mistakes.ts +44 -0
- package/src/shared/application/shared-memory/import-agent-memory.ts +117 -0
- package/src/shared/application/shared-memory/memory-files.ts +110 -0
- package/src/shared/application/shared-memory/memory-settings.ts +93 -0
- package/src/shared/application/shared-memory/push-candidate.ts +146 -0
- package/src/shared/application/shared-memory/recall-precedents.ts +69 -0
- package/src/shared/application/state-snapshot.ts +38 -0
- package/src/shared/application/workflow/workflow-state.ts +135 -0
- package/src/shared/domain/agent-policy/behavior-flags.ts +168 -0
- package/src/shared/domain/agent-policy/extra-tools.ts +69 -0
- package/src/shared/domain/agent-policy/memory-categories.ts +6 -0
- package/src/shared/domain/agent-policy/mode-policy.ts +51 -0
- package/src/shared/domain/agent-policy/output-styles.ts +11 -0
- package/src/shared/domain/agent-policy/permission.ts +623 -0
- package/src/shared/domain/agent-policy/rule-sets.ts +412 -0
- package/src/shared/domain/agent-policy/tool-access.ts +77 -0
- package/src/shared/domain/agent-registry.ts +142 -0
- package/src/shared/domain/agents/built-in-charters.ts +43 -0
- package/src/shared/domain/agents/chain.ts +30 -0
- package/src/shared/domain/agents/charter.ts +61 -0
- package/src/shared/domain/agents/exclusive.ts +24 -0
- package/src/shared/domain/agents/instances.ts +249 -0
- package/src/shared/domain/code-intel-contract.ts +356 -0
- package/src/shared/domain/code-intel-routing.ts +113 -0
- package/src/shared/domain/compact-outcome.ts +44 -0
- package/src/shared/domain/compaction-thresholds.ts +161 -0
- package/src/shared/domain/compaction.ts +379 -0
- package/src/shared/domain/config-schema.ts +421 -0
- package/src/shared/domain/dev/access-cost.ts +226 -0
- package/src/shared/domain/dev/artefacts.ts +50 -0
- package/src/shared/domain/dev/batches-concurrency.ts +36 -0
- package/src/shared/domain/dev/batches-state.ts +49 -0
- package/src/shared/domain/dev/build-commands.ts +44 -0
- package/src/shared/domain/dev/call-guard.ts +341 -0
- package/src/shared/domain/dev/carried-text.ts +49 -0
- package/src/shared/domain/dev/design-rules.ts +100 -0
- package/src/shared/domain/dev/learn-proposals.ts +175 -0
- package/src/shared/domain/dev/learn-state.ts +93 -0
- package/src/shared/domain/dev/path-args.ts +42 -0
- package/src/shared/domain/dev/path-rebase.ts +93 -0
- package/src/shared/domain/dev/plan-checks.ts +190 -0
- package/src/shared/domain/dev/plan-format.ts +180 -0
- package/src/shared/domain/dev/project-files.ts +43 -0
- package/src/shared/domain/dev/questions.ts +249 -0
- package/src/shared/domain/dev/reading-rule.ts +41 -0
- package/src/shared/domain/dev/repo-pack.ts +237 -0
- package/src/shared/domain/dev/review-answer.ts +150 -0
- package/src/shared/domain/dev/review-prompt.ts +221 -0
- package/src/shared/domain/dev/reviewer-charter.ts +31 -0
- package/src/shared/domain/dev/sheet-facts.ts +83 -0
- package/src/shared/domain/dev/spec-format.ts +183 -0
- package/src/shared/domain/dev/step-budget.ts +72 -0
- package/src/shared/domain/dev/step-rules.ts +110 -0
- package/src/shared/domain/dev/test-commands.ts +90 -0
- package/src/shared/domain/dev/test-output.ts +33 -0
- package/src/shared/domain/dev/test-paths.ts +40 -0
- package/src/shared/domain/dev/tool-guards.ts +64 -0
- package/src/shared/domain/dev/trait-pattern.ts +83 -0
- package/src/shared/domain/dev/verdict-format.ts +169 -0
- package/src/shared/domain/dev/whitespace.ts +34 -0
- package/src/shared/domain/dev/work-folder.ts +67 -0
- package/src/shared/domain/dev/yaml-subset.ts +403 -0
- package/src/shared/domain/git/close.ts +273 -0
- package/src/shared/domain/git/pull-request.ts +96 -0
- package/src/shared/domain/git/worktree.ts +46 -0
- package/src/shared/domain/index-languages.ts +16 -0
- package/src/shared/domain/instructions-file.ts +18 -0
- package/src/shared/domain/iso-day.ts +4 -0
- package/src/shared/domain/llm-failure.ts +106 -0
- package/src/shared/domain/llm-profile.ts +25 -0
- package/src/shared/domain/marked-message.ts +33 -0
- package/src/shared/domain/model-catalog.ts +86 -0
- package/src/shared/domain/permission-modes.ts +103 -0
- package/src/shared/domain/prelude.ts +92 -0
- package/src/shared/domain/project-manifests.ts +83 -0
- package/src/shared/domain/search-routing.ts +85 -0
- package/src/shared/domain/secret-patterns.ts +45 -0
- package/src/shared/domain/session-keys.ts +85 -0
- package/src/shared/domain/session-start.ts +60 -0
- package/src/shared/domain/session-summary.ts +13 -0
- package/src/shared/domain/severity.ts +72 -0
- package/src/shared/domain/sha1.ts +61 -0
- package/src/shared/domain/shared-memory/agent-memory-import.ts +143 -0
- package/src/shared/domain/shared-memory/candidates.ts +41 -0
- package/src/shared/domain/shared-memory/entry.ts +145 -0
- package/src/shared/domain/shared-memory/front-matter.ts +183 -0
- package/src/shared/domain/shared-memory/gate.ts +44 -0
- package/src/shared/domain/shared-memory/harvest.ts +61 -0
- package/src/shared/domain/shared-memory/layout.ts +187 -0
- package/src/shared/domain/shared-memory/precedents-block.ts +93 -0
- package/src/shared/domain/shared-memory/refused.ts +84 -0
- package/src/shared/domain/shared-memory/verdict-rows.ts +134 -0
- package/src/shared/domain/snip-turns.ts +45 -0
- package/src/shared/domain/speech.ts +20 -0
- package/src/shared/domain/strip.ts +88 -0
- package/src/shared/domain/tool-trace.ts +122 -0
- package/src/shared/domain/types.ts +67 -0
- package/src/shared/domain/verifiers.ts +37 -0
- package/src/shared/domain/vfs.ts +9 -0
- package/src/shared/domain/workflow/state-file.ts +140 -0
- package/src/shared/infrastructure/globals.ts +52 -0
- package/src/shared/infrastructure/orkeon/approvals.ts +24 -0
- package/src/shared/infrastructure/orkeon/child-agents.ts +127 -0
- package/src/shared/infrastructure/orkeon/code-index.ts +120 -0
- package/src/shared/infrastructure/orkeon/crew-host.ts +27 -0
- package/src/shared/infrastructure/orkeon/crew-memory.ts +12 -0
- package/src/shared/infrastructure/orkeon/dev-deps.ts +172 -0
- package/src/shared/infrastructure/orkeon/files.ts +40 -0
- package/src/shared/infrastructure/orkeon/github-pull-requests.ts +29 -0
- package/src/shared/infrastructure/orkeon/host-provider.ts +22 -0
- package/src/shared/infrastructure/orkeon/human-input.ts +59 -0
- package/src/shared/infrastructure/orkeon/llm-profile.ts +38 -0
- package/src/shared/infrastructure/orkeon/llm.ts +109 -0
- package/src/shared/infrastructure/orkeon/memory-store.ts +41 -0
- package/src/shared/infrastructure/orkeon/memory-tools.ts +131 -0
- package/src/shared/infrastructure/orkeon/permission-rules.ts +42 -0
- package/src/shared/infrastructure/orkeon/progress.ts +24 -0
- package/src/shared/infrastructure/orkeon/run-state.ts +17 -0
- package/src/shared/infrastructure/orkeon/runtime-info.ts +30 -0
- package/src/shared/infrastructure/orkeon/runtime-tools.ts +60 -0
- package/src/shared/infrastructure/orkeon/script-tools.ts +134 -0
- package/src/shared/infrastructure/orkeon/session-store.ts +138 -0
- package/src/shared/infrastructure/orkeon/session-switch.ts +23 -0
- package/src/shared/infrastructure/orkeon/shared-memory.ts +61 -0
- package/src/shared/infrastructure/orkeon/shell-jobs.ts +75 -0
- package/src/shared/infrastructure/orkeon/shell.ts +31 -0
- package/src/shared/infrastructure/orkeon/telemetry.ts +63 -0
- package/src/shared/infrastructure/orkeon/tool-catalogue.ts +75 -0
- package/src/shared/infrastructure/orkeon/tool-results.ts +120 -0
- package/src/shared/infrastructure/orkeon/usage.ts +74 -0
- package/src/shared/infrastructure/orkeon/wiring.ts +118 -0
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
// The main loop's TOOL CATALOGUE and the session's permission rules — pure, no
|
|
2
|
+
// IO. Which tool classes a mode offers is the table of mode-policy.ts; this
|
|
3
|
+
// module names the tools of each class, adds the extra tools the user configured
|
|
4
|
+
// (extra-tools.ts), builds the catalogue, and parses and formats the rules that
|
|
5
|
+
// /permissions keeps and the host's permission gate enforces. `plan` and
|
|
6
|
+
// `dontAsk` offer no mutating tool, so no write or shell call can even be
|
|
7
|
+
// attempted in them.
|
|
8
|
+
|
|
9
|
+
import { policyFor } from "./mode-policy.ts";
|
|
10
|
+
import type { ToolClass } from "./mode-policy.ts";
|
|
11
|
+
|
|
12
|
+
/** Read-side tools (inspection + the read-only RaggableTree index queries). */
|
|
13
|
+
export const READ_TOOLS = [
|
|
14
|
+
"file_read", "directory_read", "directory_search",
|
|
15
|
+
// index_codebase builds a derived graph+cache (no source mutation) so it
|
|
16
|
+
// stays read-side; the rest query it.
|
|
17
|
+
"index_codebase", "index_status",
|
|
18
|
+
"codebase_map", "codebase_search", "symbol_source", "flow_trace",
|
|
19
|
+
// The analysis five (all ToolAccess.Read, probed live 2026-08-06, 14/14):
|
|
20
|
+
// without them the model reconstructs a dependency view one flow_trace at a
|
|
21
|
+
// time — dependency_graph/impact_analysis answer it in one call.
|
|
22
|
+
"dependency_graph", "impact_analysis", "package_summary", "sub_graph", "symbol_detail",
|
|
23
|
+
// Every edge of one kind across the index or under a root, paged (Orkeon #280, ToolAccess.Read like sub_graph).
|
|
24
|
+
"edge_list",
|
|
25
|
+
// RAG (host wired since the hybrid-search work): rag_search reads. rag_ingest is
|
|
26
|
+
// an EDIT (the class below): it writes the knowledge index, never the workspace,
|
|
27
|
+
// and the host gate classifies it so since Orkeon #126 — refused in plan and
|
|
28
|
+
// dontAsk, asked in default — so a read-only turn must not be offered it. Names
|
|
29
|
+
// verified live (/debug-tool-call list, 60 registered) — an act call whose agent
|
|
30
|
+
// names an unknown tool fails.
|
|
31
|
+
"rag_search",
|
|
32
|
+
// Since Orkeon #180 (each declares ToolAccess.Read): files, mounts, the node readers and the graph queries.
|
|
33
|
+
"glob", "grep", "list_mounts", "node_outline", "node_read", "count_pattern",
|
|
34
|
+
"access_cost", "affected_tests", "batch_anchors", "documented_in", "documents_of",
|
|
35
|
+
"structural_search", "incremental_reindex", "statement_query", "complexity_report",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* B-8 — network-read tools: they mutate nothing locally, but they reach OUT.
|
|
40
|
+
*
|
|
41
|
+
* Every name here was verified against the running host (`Object.keys(tools)` in
|
|
42
|
+
* the REPL, 57 registered tools) rather than against the DI source, because
|
|
43
|
+
* `.tools([...])` resolves by name: a name the host does not register fails the
|
|
44
|
+
* agent's act call (UnknownToolError) before the model is asked anything.
|
|
45
|
+
*
|
|
46
|
+
* Two tools the backlog expected are deliberately absent, and their absence is
|
|
47
|
+
* pinned by a test rather than left to be rediscovered:
|
|
48
|
+
* - `search_tool` — the registered names are `web_search` (needs
|
|
49
|
+
* AddOrkeonWebSearchTool) and `semantic_search` (needs AddSemanticSearchTool);
|
|
50
|
+
* the REPL host (Orkeon.ConsoleApp) calls neither, so no search tool exists to
|
|
51
|
+
* hand over.
|
|
52
|
+
* - `delegate_work` — NOT registered as IBaseTool anywhere. DelegateWorkTool is
|
|
53
|
+
* constructed per-agent by AgentDelegationToolsProvider and attached to that
|
|
54
|
+
* agent's own list; it never enters the DI catalogue the scripting bridge draws
|
|
55
|
+
* from. "Framework-registered and auto-bridged" holds for http_api, not for it.
|
|
56
|
+
*
|
|
57
|
+
* `spawn_agent` is the script host's own tool, appended to every act whatever
|
|
58
|
+
* `.tools([...])` names (naming it there fails the act): it is ruleable
|
|
59
|
+
* (ACT_TOOLS) and never named in a catalogue.
|
|
60
|
+
*/
|
|
61
|
+
export const NETWORK_READ_TOOLS = ["http_api", "web_scrape", "scrape_element"];
|
|
62
|
+
|
|
63
|
+
/** The built-in tools of each class a mode policy grants: each tool is named
|
|
64
|
+
* once, here or in the lists above, and every other list derives from this table. */
|
|
65
|
+
const TOOLS_BY_CLASS: Readonly<Record<ToolClass, readonly string[]>> = {
|
|
66
|
+
read: READ_TOOLS,
|
|
67
|
+
network: NETWORK_READ_TOOLS,
|
|
68
|
+
edit: [
|
|
69
|
+
"file_write", "rag_ingest",
|
|
70
|
+
"edit_file", "node_replace", "node_insert", "node_ensure", "edit_batch", "structural_rewrite",
|
|
71
|
+
// `github` writes with `create_pr` and `create_issue` (its read actions declare a read, Orkeon #219): a tool
|
|
72
|
+
// that can open a pull request belongs to the writing modes. `rag_eval` declares an edit to the gate (Orkeon
|
|
73
|
+
// #223): it re-ingests a corpus into a collection of the knowledge index and writes its reports, so it stays
|
|
74
|
+
// out of the modes that promise nothing changes (tool-access.ts).
|
|
75
|
+
"github", "rag_eval",
|
|
76
|
+
],
|
|
77
|
+
shell: ["shell_command"],
|
|
78
|
+
extra: [],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** Mutating tools — added for every mode except the read-only ones. */
|
|
82
|
+
export const WRITE_TOOLS: readonly string[] = [...TOOLS_BY_CLASS.edit, ...TOOLS_BY_CLASS.shell];
|
|
83
|
+
|
|
84
|
+
/** What an extra tool may do, as the user declares it in `tools.extra`. */
|
|
85
|
+
export type ExtraToolAccess = "read" | "write";
|
|
86
|
+
|
|
87
|
+
/** A tool the host registers beyond the built-in lists (an MCP server's, a plugin's). */
|
|
88
|
+
export interface ExtraTool {
|
|
89
|
+
name: string;
|
|
90
|
+
access: ExtraToolAccess;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The class an extra tool joins: a `read` one is offered with the local reads,
|
|
94
|
+
* a `write` one only by the modes whose policy grants `extra`. */
|
|
95
|
+
const EXTRA_TOOL_CLASS: Readonly<Record<ExtraToolAccess, ToolClass>> = { read: "read", write: "extra" };
|
|
96
|
+
|
|
97
|
+
/** Normalise the raw permissionMode input to a string (default "default"). */
|
|
98
|
+
export function resolvePermissionMode(raw: any): string {
|
|
99
|
+
return String(raw ?? "default");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `plan` inspects only; `dontAsk` denies writes without asking (E-3). */
|
|
103
|
+
export function isReadOnly(mode: string): boolean {
|
|
104
|
+
return policyFor(mode).readOnly;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The tool catalogue for a mode: the tools of the classes its policy grants, in
|
|
109
|
+
* order, each class's built-in tools then the extra tools that join it.
|
|
110
|
+
*/
|
|
111
|
+
export function toolsetFor(mode: string, extras: readonly ExtraTool[] = []): string[] {
|
|
112
|
+
return policyFor(mode).toolClasses.flatMap((c) => [
|
|
113
|
+
...TOOLS_BY_CLASS[c],
|
|
114
|
+
...extras.filter((t) => EXTRA_TOOL_CLASS[t.access] === c).map((t) => t.name),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The permission clause appended to the act() prompt. */
|
|
119
|
+
export function permissionNote(mode: string): string {
|
|
120
|
+
const clause = isReadOnly(mode)
|
|
121
|
+
? "Read-only: read and search the project, but MUST NOT modify files, run commands or fetch anything over the " +
|
|
122
|
+
"network; answer with an assessment or a plan."
|
|
123
|
+
: "You may edit files, run shell commands and fetch over the network; the host may ask the user before a call.";
|
|
124
|
+
return `(Permission mode: ${mode}. ${clause})`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The full prompt handed to ctx.llm.act: the user request + permission note. */
|
|
128
|
+
export function buildActPrompt(prompt: string, mode: string): string {
|
|
129
|
+
return `${prompt}\n\n${permissionNote(mode)}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ── The session's rules: enforced by the host gate, read by the catalogue ──
|
|
133
|
+
//
|
|
134
|
+
// The host's permission gate (Orkeon's ModePermissionGate) reads the session's
|
|
135
|
+
// rules before the mode, at every tool call of the model (act; a command's own
|
|
136
|
+
// `tools.*` call is not checked): a deny rule refuses a matching call
|
|
137
|
+
// in every mode; an allow rule lets it run without asking in every mode but
|
|
138
|
+
// `plan`. A rule covers every call of a tool, or the calls whose argument matches
|
|
139
|
+
// a pattern whole, `*` standing for any run of characters. /permissions keeps the
|
|
140
|
+
// rules in the session state bag and hands them to the gate
|
|
141
|
+
// (shared/application/permission-rules.ts).
|
|
142
|
+
//
|
|
143
|
+
// The catalogue reads one kind of rule only: a deny that covers EVERY call of a
|
|
144
|
+
// tool removes the tool, so the model is not offered a tool whose every call the
|
|
145
|
+
// gate would refuse. An argument-scoped deny leaves the tool offered (its other
|
|
146
|
+
// calls run), and an allow spares a question, it never hands over a tool the mode
|
|
147
|
+
// does not offer: the read-only promise of `plan` and `dontAsk` rests on that.
|
|
148
|
+
|
|
149
|
+
export type RuleEffect = "deny" | "allow";
|
|
150
|
+
|
|
151
|
+
export interface PermissionRule {
|
|
152
|
+
effect: RuleEffect;
|
|
153
|
+
/** Tool name, e.g. "shell_command". */
|
|
154
|
+
tool: string;
|
|
155
|
+
/** The argument the pattern is read against, e.g. "command"; absent, the rule
|
|
156
|
+
* covers every call of the tool. Set together with `pattern`. */
|
|
157
|
+
argument?: string;
|
|
158
|
+
/** The text the argument must match whole, `*` for any run of characters, e.g. "npm test*". */
|
|
159
|
+
pattern?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Tools the host offers to every act whatever `.tools([...])` names (naming one there fails the act):
|
|
163
|
+
* ruleable, never in a catalogue. */
|
|
164
|
+
export const ACT_TOOLS: readonly string[] = ["spawn_agent"];
|
|
165
|
+
|
|
166
|
+
/** The access a tool Orkeon Code defines declares to the gate (`toolBuilder().access`): `read` runs in every
|
|
167
|
+
* mode, `execute` is gated as a write (refused in plan and dontAsk, asked in default and acceptEdits). */
|
|
168
|
+
export type ScriptToolAccess = "read" | "edit" | "execute";
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The tools Orkeon Code defines itself (shared/infrastructure/orkeon/script-tools.ts), attached to an agent with
|
|
172
|
+
* `withAutonomousTool`, never named in `.tools([...])`: the gate reads their declared access, and a session rule
|
|
173
|
+
* matches them by name like a built-in, so they are ruleable and in no catalogue. Their own shell calls are not
|
|
174
|
+
* gated by the host: each applies the rules it is given (matchesRule) before it runs one.
|
|
175
|
+
*/
|
|
176
|
+
export const SCRIPT_TOOLS: ReadonlyArray<{ name: string; access: ScriptToolAccess }> = [
|
|
177
|
+
{ name: "run_validation", access: "read" },
|
|
178
|
+
{ name: "run_tests", access: "execute" },
|
|
179
|
+
{ name: "run_build", access: "execute" },
|
|
180
|
+
// The shared memory's (M-5): the recall reads, the push writes a candidate file (an edit).
|
|
181
|
+
{ name: "memory_recall", access: "read" },
|
|
182
|
+
{ name: "memory_push", access: "edit" },
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
/** The shared memory's tools, offered to the main loop by mode (scriptToolsFor). */
|
|
186
|
+
export const MEMORY_TOOLS: readonly string[] = ["memory_recall", "memory_push"];
|
|
187
|
+
|
|
188
|
+
/** The tool class whose grant lets a script tool of this access be offered (mode-policy.ts toolClasses). */
|
|
189
|
+
const SCRIPT_TOOL_CLASS: Readonly<Record<ScriptToolAccess, ToolClass>> = { read: "read", edit: "edit", execute: "shell" };
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Which of `names` (script tools a crew builds) the mode offers under the session's rules: those whose declared
|
|
193
|
+
* access the mode's policy grants (`read` always, `edit` with the edit class, `execute` with the shell class), less
|
|
194
|
+
* those a deny rule covers whole. A name that is no script tool is left out. The gate still checks every call.
|
|
195
|
+
*/
|
|
196
|
+
export function scriptToolsFor(mode: string, names: readonly string[], rules: readonly PermissionRule[] = []): string[] {
|
|
197
|
+
const classes = policyFor(mode).toolClasses;
|
|
198
|
+
const denied = rules.filter((r) => r.effect === "deny" && coversEveryCall(r)).map((r) => r.tool);
|
|
199
|
+
return names.filter((name) => {
|
|
200
|
+
const access = scriptToolAccess(name);
|
|
201
|
+
return access !== undefined && classes.includes(SCRIPT_TOOL_CLASS[access]) && !denied.some((t) => sameToolName(t, name));
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** The access `name` declares, when it is one of SCRIPT_TOOLS; undefined otherwise. */
|
|
206
|
+
export function scriptToolAccess(name: string): ScriptToolAccess | undefined {
|
|
207
|
+
return SCRIPT_TOOLS.find((tool) => tool.name.toLowerCase() === name.toLowerCase())?.access;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Every built-in tool a rule may name, and Orkeon Code's own (SCRIPT_TOOLS); the configured extra tools come on top
|
|
212
|
+
* (ruleableTool). The gate matches any name, so a rule on a tool the host does not
|
|
213
|
+
* register would never match anything: naming it is refused instead.
|
|
214
|
+
*/
|
|
215
|
+
export const RULEABLE_TOOLS: readonly string[] = [
|
|
216
|
+
...Object.values(TOOLS_BY_CLASS).flat(), ...ACT_TOOLS, ...SCRIPT_TOOLS.map((tool) => tool.name),
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The arguments each built-in tool takes, as Orkeon binds them: the properties of
|
|
221
|
+
* its request record in snake_case (ShellCommandRequest.WorkingDirectory →
|
|
222
|
+
* `working_directory`), or the parameters it declares (rag_search, rag_ingest). The
|
|
223
|
+
* gate reads a rule's argument by that exact name, so a rule on any other never
|
|
224
|
+
* matches a call: /permissions refuses it.
|
|
225
|
+
*/
|
|
226
|
+
export const TOOL_ARGUMENTS: Readonly<Record<string, readonly string[]>> = {
|
|
227
|
+
file_read: ["path", "encoding", "max_length", "use_raggable_cache", "offset", "limit"],
|
|
228
|
+
directory_read: ["path", "recursive", "pattern", "max_results"],
|
|
229
|
+
directory_search: [
|
|
230
|
+
"path", "query", "file_patterns", "recursive", "top_k", "threshold", "chunk_size", "max_file_size_kb",
|
|
231
|
+
],
|
|
232
|
+
index_codebase: [
|
|
233
|
+
"root_path", "languages", "exclude", "enrich_with_llm", "embedding_model", "root_alias", "respect_gitignore",
|
|
234
|
+
"max_parallelism", "use_cache",
|
|
235
|
+
],
|
|
236
|
+
index_status: [],
|
|
237
|
+
codebase_map: ["level", "include_metrics", "root_fqn", "max_entries"],
|
|
238
|
+
codebase_search: [
|
|
239
|
+
"query", "levels", "top_k", "filter_kinds", "filter_packages", "filter_languages", "min_score",
|
|
240
|
+
"include_signature", "mode",
|
|
241
|
+
],
|
|
242
|
+
symbol_source: ["fqn", "mode", "max_lines", "statement_id"],
|
|
243
|
+
flow_trace: ["from", "to", "direction", "max_depth", "edge_kinds", "include_all_paths", "max_paths"],
|
|
244
|
+
dependency_graph: [
|
|
245
|
+
"scope", "edge_kinds", "include_external", "root_fqn", "max_nodes", "include_mermaid", "include_dot",
|
|
246
|
+
"node_kinds", "max_cycles", "max_cycle_members",
|
|
247
|
+
],
|
|
248
|
+
impact_analysis: ["target", "direction", "max_depth", "max_nodes"],
|
|
249
|
+
package_summary: ["fqn", "include_public_exports", "include_dependencies", "max_exports"],
|
|
250
|
+
sub_graph: ["seeds", "edge_kinds", "depth", "direction", "max_nodes", "include_mermaid", "node_kinds"],
|
|
251
|
+
symbol_detail: ["fqn", "expand", "include_signature", "include_doc", "include_body_metrics", "max_children"],
|
|
252
|
+
edge_list: ["cursor", "edge_kinds", "page_size", "root_fqn"],
|
|
253
|
+
rag_search: ["question", "top_k", "collection"],
|
|
254
|
+
rag_ingest: ["collection", "sources", "chunking_strategy", "reindex", "prune"],
|
|
255
|
+
http_api: ["url", "method", "headers", "body", "content_type"],
|
|
256
|
+
web_scrape: ["url", "selector", "cached", "chunk_size"],
|
|
257
|
+
scrape_element: ["url", "css_selector", "extract_attributes", "include_html", "max_elements"],
|
|
258
|
+
file_write: ["path", "content", "encoding", "append", "create_backup"],
|
|
259
|
+
shell_command: ["command", "working_directory", "timeout_seconds", "action", "job_id", "tail_lines"],
|
|
260
|
+
// The tools of Orkeon #180, each with the depth-1 keys of its input (orkeon.d.ts, OrkeonBuiltInTools).
|
|
261
|
+
// Nested arguments, which no rule reaches (the gate reads a top-level argument's text, and an array or
|
|
262
|
+
// an object reads as its type name):
|
|
263
|
+
// - edit_batch.operations[]: expected_hash?, index?, kind, level?, module?, name?, path, position?,
|
|
264
|
+
// selector, text; `kind` names the operation (node_replace, node_insert, ensure_*, the Markdown
|
|
265
|
+
// intents) where node_ensure takes `op`; `expected_hash` (node_read's sha256) is required on a
|
|
266
|
+
// node_replace operation as on node_replace itself; `validate` is "parse" (default) or "build".
|
|
267
|
+
// - structural_rewrite is a dry run unless `dry_run` is false; `rule` is an object, `paths` an array.
|
|
268
|
+
// - github, per action: list_issues {owner, repo}, create_issue {owner, repo, title, body?},
|
|
269
|
+
// create_pr {owner, repo, base, head, title, body?}, get_pr {owner, repo, number}, search_repos
|
|
270
|
+
// {query}, get_repo {owner, repo}; the tool reads the action case-insensitively, a rule does not.
|
|
271
|
+
// - batch_anchors.a and .b are {fqns, files}, for action "overlap"; "closure" takes fqns or files.
|
|
272
|
+
// - arrays or objects: rag_ingest.sources, access_cost.*, affected_tests.changed_files,
|
|
273
|
+
// sub_graph.seeds|edge_kinds|node_kinds, edge_list.edge_kinds, structural_search.paths|rule,
|
|
274
|
+
// count_pattern.patterns, statement_query.kinds|parent_fqns, incremental_reindex.changed_files|languages.
|
|
275
|
+
glob: ["max_results", "path", "pattern"],
|
|
276
|
+
grep: ["case_insensitive", "glob", "max_files", "max_results", "output_mode", "path", "pattern"],
|
|
277
|
+
list_mounts: [],
|
|
278
|
+
node_outline: ["path"],
|
|
279
|
+
node_read: ["path", "selector"],
|
|
280
|
+
access_cost: ["changed_files", "fqns", "receivers", "roots"],
|
|
281
|
+
affected_tests: ["base", "changed_files"],
|
|
282
|
+
batch_anchors: ["a", "action", "b", "files", "fqns"],
|
|
283
|
+
documented_in: ["fqn"],
|
|
284
|
+
documents_of: ["path"],
|
|
285
|
+
structural_search: ["glob", "language", "max_files", "max_results", "paths", "pattern", "rule", "rule_file"],
|
|
286
|
+
incremental_reindex: ["changed_files", "enrich_with_llm", "from_commit", "languages", "root_path", "to_commit"],
|
|
287
|
+
count_pattern: ["distinct_matches", "include_matches", "max_matches_returned", "multiline", "path", "patterns"],
|
|
288
|
+
statement_query: ["kinds", "parent_fqns", "semantic_query", "top_k"],
|
|
289
|
+
complexity_report: ["metric", "root_fqn", "top_n"],
|
|
290
|
+
edit_file: ["create_backup", "new_string", "old_string", "path", "replace_all"],
|
|
291
|
+
node_replace: ["expected_hash", "path", "selector", "text"],
|
|
292
|
+
node_insert: ["path", "position", "selector", "text"],
|
|
293
|
+
node_ensure: ["index", "level", "module", "name", "op", "path", "selector", "text"],
|
|
294
|
+
edit_batch: ["operations", "validate"],
|
|
295
|
+
structural_rewrite: ["dry_run", "fix", "glob", "language", "max_files", "paths", "pattern", "rule", "rule_file"],
|
|
296
|
+
github: ["action", "base", "body", "head", "number", "owner", "query", "repo", "title"],
|
|
297
|
+
rag_eval: ["collection", "compare", "dataset", "k", "profile", "reindex", "use_llm_judge"],
|
|
298
|
+
// Offered by the script host to every act, not a built-in of orkeon.d.ts (SpawnAgentScriptRequest).
|
|
299
|
+
spawn_agent: ["agent", "input"],
|
|
300
|
+
// Orkeon Code's own tools (SCRIPT_TOOLS), the keys of their schemas.
|
|
301
|
+
run_validation: ["command"],
|
|
302
|
+
run_tests: ["command"],
|
|
303
|
+
run_build: ["project"],
|
|
304
|
+
memory_recall: ["query", "types", "top_k"],
|
|
305
|
+
memory_push: [
|
|
306
|
+
"type", "title", "topic", "applies_when", "rationale", "correction", "detection_signal", "evidence", "tags",
|
|
307
|
+
],
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/** Whether two tool names designate the same tool: Orkeon compares them case-insensitively. */
|
|
311
|
+
export function sameToolName(a: string, b: string): boolean {
|
|
312
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The built-in tool `name` designates, in its own spelling; undefined when it is none. */
|
|
316
|
+
export function builtInTool(name: string): string | undefined {
|
|
317
|
+
return RULEABLE_TOOLS.find((tool) => sameToolName(tool, name));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The tool a rule's name designates, a built-in one or one of `extraNames` (the
|
|
321
|
+
* configured extra tools), in its own spelling; undefined when it is neither. */
|
|
322
|
+
export function ruleableTool(name: string, extraNames: readonly string[] = []): string | undefined {
|
|
323
|
+
return builtInTool(name) ?? extraNames.find((tool) => sameToolName(tool, name));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface CatalogueDecision {
|
|
327
|
+
/** The effective catalogue after the rules. */
|
|
328
|
+
tools: string[];
|
|
329
|
+
/** Tools the mode offers and a whole-tool deny rule removed. */
|
|
330
|
+
deniedByRule: string[];
|
|
331
|
+
/** Allow rules that cannot take effect in this mode, with the reason — never silently dropped. */
|
|
332
|
+
inert: Array<{ rule: PermissionRule; reason: string }>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** True when the rule covers every call of its tool, not only the calls an argument pattern matches. */
|
|
336
|
+
export function coversEveryCall(rule: PermissionRule): boolean {
|
|
337
|
+
return rule.argument === undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Whether a deny rule covers every call of `tool` (an agent offered it would be refused at each call). */
|
|
341
|
+
export function deniesEveryCall(rules: readonly PermissionRule[], tool: string): boolean {
|
|
342
|
+
return rules.some((r) => r.effect === "deny" && coversEveryCall(r) && sameToolName(r.tool, tool));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Whether the host offers `tool` to every act (ACT_TOOLS), whatever the catalogue. */
|
|
346
|
+
function isActTool(tool: string): boolean {
|
|
347
|
+
return ACT_TOOLS.some((name) => sameToolName(name, tool));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Why an allow rule does nothing in `mode`, or undefined when it can spare a question there. */
|
|
351
|
+
function inertReason(mode: string, rule: PermissionRule, offered: readonly string[]): string | undefined {
|
|
352
|
+
// The gate reads no allow rule in plan (ModePermissionGate): plan's promise of a
|
|
353
|
+
// turn that changes nothing outranks the session's rules.
|
|
354
|
+
if (mode === "plan") {
|
|
355
|
+
return "mode 'plan' ignores every allow rule: the gate decides each call from the mode, which runs reads " +
|
|
356
|
+
"and refuses the rest. Switch mode instead.";
|
|
357
|
+
}
|
|
358
|
+
// An ACT_TOOLS tool reaches the gate from every act whatever the catalogue: the gate reads an allow
|
|
359
|
+
// rule on it in every other mode, dontAsk included.
|
|
360
|
+
if (!offered.includes(rule.tool) && !isActTool(rule.tool)) {
|
|
361
|
+
return `mode '${mode}' does not offer '${rule.tool}': an allow rule spares a question, ` +
|
|
362
|
+
"it does not hand a tool over. Switch mode instead.";
|
|
363
|
+
}
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The catalogue of a mode under the session's rules: the tools the mode offers,
|
|
369
|
+
* the extra tools of the classes it grants included, less those a deny rule
|
|
370
|
+
* covers whole. The rules themselves are the gate's to
|
|
371
|
+
* enforce; this only spares the model a tool it could never call.
|
|
372
|
+
*
|
|
373
|
+
* An allow rule is reported as inert in `plan`, where the gate ignores every allow,
|
|
374
|
+
* and wherever the mode does not offer its tool: no call of the tool can reach the gate.
|
|
375
|
+
*/
|
|
376
|
+
export function catalogueFor(
|
|
377
|
+
mode: string,
|
|
378
|
+
rules: readonly PermissionRule[],
|
|
379
|
+
extras: readonly ExtraTool[] = [],
|
|
380
|
+
): CatalogueDecision {
|
|
381
|
+
const offered = toolsetFor(mode, extras);
|
|
382
|
+
const denied = new Set(rules.filter((r) => r.effect === "deny" && coversEveryCall(r)).map((r) => r.tool));
|
|
383
|
+
const inert = rules
|
|
384
|
+
.filter((r) => r.effect === "allow")
|
|
385
|
+
.flatMap((rule) => {
|
|
386
|
+
const reason = inertReason(mode, rule, offered);
|
|
387
|
+
return reason === undefined ? [] : [{ rule, reason }];
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
tools: offered.filter((t) => !denied.has(t)),
|
|
391
|
+
deniedByRule: offered.filter((t) => denied.has(t)),
|
|
392
|
+
inert,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** An argument name as tools declare them (`command`, `path`). */
|
|
397
|
+
const ARGUMENT_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
398
|
+
|
|
399
|
+
/** What a rule must look like, for messages. */
|
|
400
|
+
export const RULE_SYNTAX = "<deny|allow> <tool> [<argument>=<pattern>]";
|
|
401
|
+
|
|
402
|
+
/** The pattern without one pair of matching quotes around it: `"npm test*"` → `npm test*`. */
|
|
403
|
+
function unquote(pattern: string): string {
|
|
404
|
+
const quote = pattern.charAt(0);
|
|
405
|
+
return pattern.length >= 2 && (quote === '"' || quote === "'") && pattern.endsWith(quote)
|
|
406
|
+
? pattern.slice(1, -1)
|
|
407
|
+
: pattern;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Whether the pattern starts and ends with the same quote, which reading it would take off. */
|
|
411
|
+
function looksQuoted(pattern: string): boolean {
|
|
412
|
+
return unquote(pattern) !== pattern;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Reads a rule's text by the grammar alone, `<deny|allow> <tool> [<argument>=<pattern>]`
|
|
417
|
+
* (the /permissions grammar, the stored form, the line the host gate lists, e.g.
|
|
418
|
+
* `allow shell_command command=npm test*`), or the `effect:tool` form stored before
|
|
419
|
+
* rules took patterns. The pattern is the rest of the text after `=`, spaces
|
|
420
|
+
* included, less one pair of matching quotes around it (`command="npm test*"`).
|
|
421
|
+
* The tool is not checked: a stored rule may name a tool the session no longer
|
|
422
|
+
* knows, and is still that rule. Null when the text is not the grammar.
|
|
423
|
+
*/
|
|
424
|
+
export function readRule(text: unknown): PermissionRule | null {
|
|
425
|
+
const trimmed = String(text ?? "").trim();
|
|
426
|
+
const legacy = /^([^:\s]+):([^:\s]+)$/.exec(trimmed);
|
|
427
|
+
const m = /^(\S+)\s+(\S+)(?:\s+(.+))?$/.exec(legacy ? `${legacy[1]} ${legacy[2]}` : trimmed);
|
|
428
|
+
if (!m) return null;
|
|
429
|
+
const effect = m[1].toLowerCase();
|
|
430
|
+
const tool = m[2];
|
|
431
|
+
if (effect !== "deny" && effect !== "allow") return null;
|
|
432
|
+
if (m[3] === undefined) return { effect, tool };
|
|
433
|
+
const eq = m[3].indexOf("=");
|
|
434
|
+
const argument = m[3].slice(0, Math.max(eq, 0));
|
|
435
|
+
const pattern = unquote(m[3].slice(eq + 1));
|
|
436
|
+
if (eq < 0 || !ARGUMENT_NAME.test(argument) || pattern.length === 0) return null;
|
|
437
|
+
return { effect, tool, argument, pattern };
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* A stored rule, as the session holds it: the rule its text reads as, its tool in
|
|
442
|
+
* the spelling of the built-in or configured extra tool it designates. Null when
|
|
443
|
+
* the text is not a rule or its tool is neither: such a rule is kept as written
|
|
444
|
+
* (shared/application/permission-rules.ts), never enforced.
|
|
445
|
+
*/
|
|
446
|
+
export function parseStoredRule(raw: unknown, extraNames: readonly string[] = []): PermissionRule | null {
|
|
447
|
+
const rule = readRule(raw);
|
|
448
|
+
const tool = rule === null ? undefined : ruleableTool(rule.tool, extraNames);
|
|
449
|
+
return rule === null || tool === undefined ? null : { ...rule, tool };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** A rule /permissions may add, with what to say about it, or why it may not. */
|
|
453
|
+
export type RuleCheck =
|
|
454
|
+
| { ok: true; rule: PermissionRule; warning?: string }
|
|
455
|
+
| { ok: false; reason: string };
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Checks a rule to add: the grammar (readRule); a tool built in or among
|
|
459
|
+
* `extraNames`, taken in its own spelling; and, for a built-in tool, an argument it
|
|
460
|
+
* takes (TOOL_ARGUMENTS). The arguments of an extra tool are not known here: one is
|
|
461
|
+
* accepted with a warning.
|
|
462
|
+
*/
|
|
463
|
+
export function checkRule(text: unknown, extraNames: readonly string[] = []): RuleCheck {
|
|
464
|
+
const read = readRule(text);
|
|
465
|
+
if (read === null) return { ok: false, reason: `expected ${RULE_SYNTAX}` };
|
|
466
|
+
const tool = ruleableTool(read.tool, extraNames);
|
|
467
|
+
if (tool === undefined) {
|
|
468
|
+
const tools = [...RULEABLE_TOOLS, ...extraNames].join(", ");
|
|
469
|
+
return { ok: false, reason: `'${read.tool}' is no tool a rule may name: one of ${tools}` };
|
|
470
|
+
}
|
|
471
|
+
const rule = { ...read, tool };
|
|
472
|
+
// The gate reads an allow rule on an ACT_TOOLS tool in every mode but plan: say so, refuse nothing.
|
|
473
|
+
const accepted: RuleCheck = rule.effect === "allow" && isActTool(tool)
|
|
474
|
+
? {
|
|
475
|
+
ok: true,
|
|
476
|
+
rule,
|
|
477
|
+
warning: `'${tool}' is offered to every act whatever the mode: an allow rule lets it run without asking in ` +
|
|
478
|
+
"dontAsk too.",
|
|
479
|
+
}
|
|
480
|
+
: { ok: true, rule };
|
|
481
|
+
if (rule.argument === undefined) return accepted;
|
|
482
|
+
const known = TOOL_ARGUMENTS[tool];
|
|
483
|
+
if (known === undefined) {
|
|
484
|
+
return {
|
|
485
|
+
ok: true,
|
|
486
|
+
rule,
|
|
487
|
+
warning: `the arguments of '${tool}' are not known here (its MCP server or plugin declares them): the rule ` +
|
|
488
|
+
`matches a call only if '${tool}' takes an argument named exactly '${rule.argument}'.`,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
if (known.includes(rule.argument)) return accepted;
|
|
492
|
+
return {
|
|
493
|
+
ok: false,
|
|
494
|
+
reason: known.length === 0
|
|
495
|
+
? `'${tool}' takes no argument: a rule on it covers every call`
|
|
496
|
+
: `'${tool}' has no argument '${rule.argument}': it takes ${known.join(", ")}`,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** The rule as one line, as stored and shown: the host gate's spelling
|
|
501
|
+
* (gateLine), with a pattern that starts and ends with the same quote quoted
|
|
502
|
+
* once more, so that the line reads back as this rule. */
|
|
503
|
+
export function formatRule(rule: PermissionRule): string {
|
|
504
|
+
if (coversEveryCall(rule) || !looksQuoted(rule.pattern ?? "")) return gateLine(rule);
|
|
505
|
+
return `${rule.effect} ${rule.tool} ${rule.argument}="${rule.pattern}"`;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** The rule as the host gate lists it: `deny file_write`, `allow shell_command command=npm test*`. */
|
|
509
|
+
export function gateLine(rule: PermissionRule): string {
|
|
510
|
+
const head = `${rule.effect} ${rule.tool}`;
|
|
511
|
+
return coversEveryCall(rule) ? head : `${head} ${rule.argument}=${rule.pattern}`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** Whether two rules cover the same calls (same tool, same argument and pattern), whatever their effect. */
|
|
515
|
+
export function sameCalls(a: PermissionRule, b: PermissionRule): boolean {
|
|
516
|
+
return sameToolName(a.tool, b.tool) && a.argument === b.argument && a.pattern === b.pattern;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Whether `text` matches `pattern` whole, as the host gate reads a rule's pattern: `*` stands for any run of
|
|
521
|
+
* characters (none, or many, line breaks included); every other character stands for itself, case counting.
|
|
522
|
+
* No other wildcard exists: `?`, `[`, `.`, `(` are literal.
|
|
523
|
+
*/
|
|
524
|
+
export function globMatches(pattern: string, text: string): boolean {
|
|
525
|
+
const parts = pattern.split("*");
|
|
526
|
+
if (parts.length === 1) return pattern === text;
|
|
527
|
+
const first = parts[0];
|
|
528
|
+
const last = parts[parts.length - 1];
|
|
529
|
+
if (text.length < first.length + last.length) return false;
|
|
530
|
+
if (!text.startsWith(first) || !text.endsWith(last)) return false;
|
|
531
|
+
// The middle parts, in order and without overlap, between the first part and the last.
|
|
532
|
+
const end = text.length - last.length;
|
|
533
|
+
let at = first.length;
|
|
534
|
+
for (const part of parts.slice(1, -1)) {
|
|
535
|
+
const found = text.indexOf(part, at);
|
|
536
|
+
if (found < 0 || found + part.length > end) return false;
|
|
537
|
+
at = found + part.length;
|
|
538
|
+
}
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Whether `rule` covers this call, by the gate's own reading (docs/permissions.md, "Rules"): the tool by
|
|
544
|
+
* sameToolName; a rule without argument covers every call; otherwise the argument named exactly
|
|
545
|
+
* `rule.argument` (own property of `args`) must be present and its text match `rule.pattern` whole.
|
|
546
|
+
* A string argument is its text; a number or a boolean its String(); anything else (absent, null, object,
|
|
547
|
+
* array) matches nothing. The effect is not read: this says "covered", not "refused".
|
|
548
|
+
* It mirrors the gate and is NOT the gate: the gate enforces the session's rules on the model's calls;
|
|
549
|
+
* this function serves the tests and the tools Orkeon Code wraps around built-ins (W1), whose own
|
|
550
|
+
* calls the gate does not see.
|
|
551
|
+
*/
|
|
552
|
+
export function matchesRule(rule: PermissionRule, tool: string, args: Readonly<Record<string, unknown>>): boolean {
|
|
553
|
+
if (!sameToolName(rule.tool, tool)) return false;
|
|
554
|
+
if (coversEveryCall(rule)) return true;
|
|
555
|
+
const name = rule.argument as string;
|
|
556
|
+
if (!Object.prototype.hasOwnProperty.call(args, name)) return false;
|
|
557
|
+
const value = args[name];
|
|
558
|
+
const text = typeof value === "string"
|
|
559
|
+
? value
|
|
560
|
+
: typeof value === "number" || typeof value === "boolean" ? String(value) : undefined;
|
|
561
|
+
return text !== undefined && globMatches(rule.pattern ?? "", text);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** The words of a shell command as the host's shell tool splits them (ShellCommandTool.TokenizeCommand): on
|
|
565
|
+
* whitespace outside quotes, the quotes themselves dropped, nothing expanded. */
|
|
566
|
+
export function shellWords(command: string): string[] {
|
|
567
|
+
const words: string[] = [];
|
|
568
|
+
let current = "";
|
|
569
|
+
let single = false;
|
|
570
|
+
let double = false;
|
|
571
|
+
for (const c of command) {
|
|
572
|
+
if (c === "'" && !double) { single = !single; continue; }
|
|
573
|
+
if (c === "\"" && !single) { double = !double; continue; }
|
|
574
|
+
if (/\s/.test(c) && !single && !double) {
|
|
575
|
+
if (current !== "") words.push(current);
|
|
576
|
+
current = "";
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
current += c;
|
|
580
|
+
}
|
|
581
|
+
if (current !== "") words.push(current);
|
|
582
|
+
return words;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* A cluster of short options read as separate flags: `-Ic` as `-I -c`, `-we` as `-w -e`; code attached to the
|
|
587
|
+
* cluster after its first `c`, `e` or `E` stands apart (`-Icprint(1)` read `-I -c print(1)`). A long option, or a
|
|
588
|
+
* word that is not a cluster, is kept whole.
|
|
589
|
+
*/
|
|
590
|
+
function splitCluster(word: string): string[] {
|
|
591
|
+
const match = /^-([A-Za-z]+)(.*)$/s.exec(word);
|
|
592
|
+
if (match === null) return [word];
|
|
593
|
+
const [, letters, rest] = match;
|
|
594
|
+
const at = letters.search(/[ceE]/);
|
|
595
|
+
if (at < 0) return rest === "" && letters.length > 1 ? [...letters].map((letter) => `-${letter}`) : [word];
|
|
596
|
+
const flags = [...letters.slice(0, at + 1)].map((letter) => `-${letter}`);
|
|
597
|
+
const tail = letters.slice(at + 1) + rest;
|
|
598
|
+
return tail === "" ? flags : [...flags, tail];
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The texts a shell command is matched in by a deny rule: as written, then as the program receives it, which a
|
|
603
|
+
* pattern on the raw text misses. The words rejoined by one space (`git "push"`, `git<TAB>push`, `bash -c`); the
|
|
604
|
+
* same with each backslash escape resolved, as `/bin/sh` reads it under a sandbox (`git pu\sh`); and with each
|
|
605
|
+
* cluster of short options split (`python3 -Ic x` read `python3 -I -c x`, `perl -we"p 1"` read `perl -w -e p 1`), so the
|
|
606
|
+
* patterns on a flag before `-c` or `-e` hold. Each form once, the raw one first.
|
|
607
|
+
*/
|
|
608
|
+
export function shellCommandForms(command: string): string[] {
|
|
609
|
+
const words = shellWords(command);
|
|
610
|
+
const unescaped = words.map((w) => w.replace(/\\(.)/g, "$1"));
|
|
611
|
+
const split = unescaped.flatMap(splitCluster);
|
|
612
|
+
return [...new Set([command, words.join(" "), unescaped.join(" "), split.join(" ")])];
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** What `rules` decide for this call: "deny" when a deny rule covers it (deny wins in every mode),
|
|
616
|
+
* else "allow" when an allow rule does, else undefined (the mode decides). */
|
|
617
|
+
export function ruleDecision(
|
|
618
|
+
rules: readonly PermissionRule[], tool: string, args: Readonly<Record<string, unknown>>,
|
|
619
|
+
): RuleEffect | undefined {
|
|
620
|
+
const covering = rules.filter((rule) => matchesRule(rule, tool, args));
|
|
621
|
+
if (covering.some((rule) => rule.effect === "deny")) return "deny";
|
|
622
|
+
return covering.length > 0 ? "allow" : undefined;
|
|
623
|
+
}
|