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,50 @@
|
|
|
1
|
+
// Dev workflow artefacts: what a file of a work folder is, read from its name alone.
|
|
2
|
+
// Pure, no IO. The prefix group follows the harness's own `[A-Za-z0-9][\w.-]*`.
|
|
3
|
+
|
|
4
|
+
export type ArtefactKind = "spec" | "change" | "plan" | "sheet" | "verdict" | "batches-state";
|
|
5
|
+
export interface ArtefactName { kind: ArtefactKind; name: string; prefix: string; batch?: string }
|
|
6
|
+
|
|
7
|
+
/** A work code: a plain folder name, never a path. */
|
|
8
|
+
export const CODE_PATTERN: RegExp = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
9
|
+
|
|
10
|
+
export function isCode(value: string): boolean {
|
|
11
|
+
return CODE_PATTERN.test(value) && !value.includes("..");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const PREFIX = "([A-Za-z0-9][\\w.-]*)";
|
|
15
|
+
|
|
16
|
+
// Order matters: a sheet (`-PLAN-F1.md`) is tried before a plan so it never reads as one.
|
|
17
|
+
const PATTERNS: Array<{ kind: ArtefactKind; re: RegExp; batch: boolean }> = [
|
|
18
|
+
{ kind: "spec", re: /^SPEC-(.+)\.md$/, batch: false },
|
|
19
|
+
{ kind: "change", re: /^CHANGE-(.+)\.md$/, batch: false },
|
|
20
|
+
{ kind: "sheet", re: new RegExp(`^${PREFIX}-PLAN-(F\\d+)\\.md$`), batch: true },
|
|
21
|
+
{ kind: "plan", re: new RegExp(`^${PREFIX}-PLAN\\.md$`), batch: false },
|
|
22
|
+
{ kind: "verdict", re: new RegExp(`^${PREFIX}-VERIFY-(F\\d+)\\.md$`), batch: true },
|
|
23
|
+
{ kind: "batches-state", re: new RegExp(`^${PREFIX}-BATCHES-STATE\\.md$`), batch: false },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export function classifyArtefact(fileName: string): ArtefactName | null {
|
|
27
|
+
for (const p of PATTERNS) {
|
|
28
|
+
const m = p.re.exec(fileName);
|
|
29
|
+
if (!m) continue;
|
|
30
|
+
const out: ArtefactName = { kind: p.kind, name: fileName, prefix: m[1] };
|
|
31
|
+
if (p.batch) out.batch = m[2];
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const BATCH_ID = /^F(\d+)$/;
|
|
38
|
+
|
|
39
|
+
/** F2 before F10; non-F ids last, by text. */
|
|
40
|
+
export function compareBatchIds(a: string, b: string): number {
|
|
41
|
+
const ma = BATCH_ID.exec(a);
|
|
42
|
+
const mb = BATCH_ID.exec(b);
|
|
43
|
+
if (ma && mb) {
|
|
44
|
+
const d = Number(ma[1]) - Number(mb[1]);
|
|
45
|
+
return d !== 0 ? d : a < b ? -1 : a > b ? 1 : 0;
|
|
46
|
+
}
|
|
47
|
+
if (ma) return -1;
|
|
48
|
+
if (mb) return 1;
|
|
49
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
50
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// How many batches /dev-batches runs at once: 1 unless asked, a whole number from 1 to 4 (the crew's default child
|
|
2
|
+
// gate, and four suites at once on one machine). Above 1, each batch runs under its own worktree as a working
|
|
3
|
+
// root (crews/dev-batches/application/run-wave.ts), and only in a session mode that never asks before a shell
|
|
4
|
+
// command: two batches asking at once could not both be answered. That is bypassPermissions alone: acceptEdits still
|
|
5
|
+
// asks for shell_command, and dontAsk is read-only here (mode-policy.ts), which /dev-batches refuses at any
|
|
6
|
+
// concurrency. Read by the command's arguments and by the crew's input. Pure.
|
|
7
|
+
|
|
8
|
+
export const MAX_CONCURRENCY = 4;
|
|
9
|
+
|
|
10
|
+
/** The writing modes in which no shell command is asked about (call-guard.ts: acceptEdits still asks for shell_command). */
|
|
11
|
+
const SILENT_MODES: readonly string[] = ["bypassPermissions"];
|
|
12
|
+
|
|
13
|
+
export type Concurrency = { ok: true; value: number } | { ok: false; line: string };
|
|
14
|
+
|
|
15
|
+
/** `concurrency` as given (absent, a number or a digit string): 1 to 4, or the one line refusing it. */
|
|
16
|
+
export function checkConcurrency(raw: unknown): Concurrency {
|
|
17
|
+
if (raw === undefined || raw === null) return { ok: true, value: 1 };
|
|
18
|
+
const n = typeof raw === "number" ? raw : typeof raw === "string" && /^\s*\d+\s*$/.test(raw) ? Number(raw.trim()) : NaN;
|
|
19
|
+
if (!Number.isSafeInteger(n) || n < 1) return { ok: false, line: `concurrency must be a whole number from 1, not '${String(raw)}'` };
|
|
20
|
+
if (n > MAX_CONCURRENCY) return { ok: false, line: `concurrency ${n} refused: at most ${MAX_CONCURRENCY} batches at once` };
|
|
21
|
+
return { ok: true, value: n };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Above 1, the line refusing a session mode that asks before shell commands; null when the mode lets it run. */
|
|
25
|
+
export function concurrencyModeRefusal(n: number, mode: string): string | null {
|
|
26
|
+
if (n <= 1 || SILENT_MODES.includes(mode.trim())) return null;
|
|
27
|
+
return `concurrency ${n} refused: the session mode ${mode.trim() || "default"} asks before shell commands, and two batches would ask at once: ` +
|
|
28
|
+
"/mode bypassPermissions, or run with --concurrency 1";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The line refusing a parallel run when git fails in a batch's worktree: a runtime older than the one binding a
|
|
32
|
+
* linked worktree's git dir under its shell confinement. */
|
|
33
|
+
export function concurrencyGitRefusal(n: number): string {
|
|
34
|
+
return `concurrency ${n} refused: git does not work inside a worktree under this shell confinement (Tools:Shell:Confinement:Mode)` +
|
|
35
|
+
"; a runtime from Orkeon/orkeon#191 on binds a linked worktree's git dir: update it, or run with --concurrency 1";
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The log of a `/dev-batches` run, `<CODE>-BATCHES-STATE.md`, read only. Pure, no IO.
|
|
2
|
+
// A batch is open when its last entry is `launched`, `relaunched` or `stall` and no
|
|
3
|
+
// `closed` line follows it; any other line (a table, prose) is ignored.
|
|
4
|
+
import { WORKSPACE } from "../vfs.ts";
|
|
5
|
+
|
|
6
|
+
/** The record of the /dev-batches run in progress (its `code`), cleared when the run closes. A close of one of its
|
|
7
|
+
* batches, typed or chained, commits without pushing: the run's close pushes the plan's branch once. */
|
|
8
|
+
export const BATCHES_ACTIVE_RECORD = `${WORKSPACE}/.orkeon/dev/batches-active.json`;
|
|
9
|
+
|
|
10
|
+
/** The code the record names, or null (no record, unreadable). Pure: the record's text. */
|
|
11
|
+
export function batchesRunCode(text: string): string | null {
|
|
12
|
+
try {
|
|
13
|
+
const code = (JSON.parse(text) as { code?: unknown } | null)?.code;
|
|
14
|
+
return typeof code === "string" && code !== "" ? code : null;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BatchesLogEntry { date: string; time: string; batch?: string; event: string; detail: string; line: number }
|
|
21
|
+
export interface BatchesState { entries: BatchesLogEntry[]; closed: boolean; open: string[] }
|
|
22
|
+
|
|
23
|
+
const EVENT = /^- (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) (F\d+) (launched|relaunched|returned|merged|stopped|stall)( .*)?$/;
|
|
24
|
+
const CLOSE = /^- (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) closed$/;
|
|
25
|
+
const OPENING: ReadonlySet<string> = new Set(["launched", "relaunched", "stall"]);
|
|
26
|
+
|
|
27
|
+
export function parseBatchesState(text: string): BatchesState {
|
|
28
|
+
const entries: BatchesLogEntry[] = [];
|
|
29
|
+
text.split(/\r?\n/).forEach((raw, i) => {
|
|
30
|
+
const t = raw.trimEnd();
|
|
31
|
+
const e = EVENT.exec(t);
|
|
32
|
+
if (e) {
|
|
33
|
+
entries.push({ date: e[1], time: e[2], batch: e[3], event: e[4], detail: (e[5] ?? "").trim(), line: i + 1 });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const c = CLOSE.exec(t);
|
|
37
|
+
if (c) entries.push({ date: c[1], time: c[2], event: "closed", detail: "", line: i + 1 });
|
|
38
|
+
});
|
|
39
|
+
const last = new Map<string, number>();
|
|
40
|
+
let lastClose = -1;
|
|
41
|
+
entries.forEach((e, i) => {
|
|
42
|
+
if (e.batch === undefined) lastClose = i;
|
|
43
|
+
else last.set(e.batch, i);
|
|
44
|
+
});
|
|
45
|
+
const open: string[] = [];
|
|
46
|
+
for (const [batch, i] of last) if (OPENING.has(entries[i].event) && i > lastClose) open.push(batch);
|
|
47
|
+
const closed = entries.length > 0 && entries[entries.length - 1].event === "closed";
|
|
48
|
+
return { entries, closed, open };
|
|
49
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The build run_build may run, and the one case it restores: pure. The pack's commands carry the
|
|
2
|
+
// restore rule themselves (`build: … --no-restore`, `build_test: … --no-restore`; repo.yaml): the
|
|
3
|
+
// tool runs them as written, never a restore of its own, but once, when a red build says the tree
|
|
4
|
+
// was never restored (a cold checkout or worktree), where the flag cannot succeed.
|
|
5
|
+
import type { RepoPackCommands } from "./repo-pack.ts";
|
|
6
|
+
import { PLACEHOLDER, plainWords, valueProblem } from "./test-commands.ts";
|
|
7
|
+
|
|
8
|
+
export type BuildCommand = { ok: true; command: string; key: "commands.build" | "commands.build_test" } | { ok: false; reason: string };
|
|
9
|
+
|
|
10
|
+
/** `commands.build` without a project; `commands.build_test` with its one placeholder filled by `project`. */
|
|
11
|
+
export function buildCommandFor(commands: RepoPackCommands, project?: string): BuildCommand {
|
|
12
|
+
if (project === undefined) {
|
|
13
|
+
const build = commands.build?.trim();
|
|
14
|
+
return build ? { ok: true, command: build, key: "commands.build" } : { ok: false, reason: "the pack has no commands.build" };
|
|
15
|
+
}
|
|
16
|
+
const template = commands.buildTest?.trim();
|
|
17
|
+
if (!template) return { ok: false, reason: "the pack has no commands.build_test to build one project" };
|
|
18
|
+
const holes = template.match(PLACEHOLDER) ?? [];
|
|
19
|
+
if (holes.length !== 1) {
|
|
20
|
+
return { ok: false, reason: `commands.build_test has ${holes.length} placeholders, not one: '${template}'` };
|
|
21
|
+
}
|
|
22
|
+
const problem = valueProblem(project);
|
|
23
|
+
if (problem !== null) return { ok: false, reason: problem };
|
|
24
|
+
const command = template.replace(PLACEHOLDER, project);
|
|
25
|
+
return plainWords(command)
|
|
26
|
+
? { ok: true, command, key: "commands.build_test" }
|
|
27
|
+
: { ok: false, reason: "a shell operator outside double quotes" };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether `command` is the pack's restore, or a restore by its verb (`dotnet restore`, `npm ci`, `npm install`). */
|
|
31
|
+
export function isRestore(command: string, commands: RepoPackCommands): boolean {
|
|
32
|
+
const c = command.trim();
|
|
33
|
+
const restore = commands.restore?.trim();
|
|
34
|
+
if (restore && c === restore) return true;
|
|
35
|
+
return /(^|\s)(dotnet\s+restore|npm\s+(ci|install)|pnpm\s+install|yarn\s+install)(\s|$)/.test(c);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What a red build prints when its project was never restored: .NET's NETSDK1004 and its assets file. */
|
|
39
|
+
const COLD_TREE = [/NETSDK1004/, /project\.assets\.json'? not found/i, /run a NuGet package restore/i];
|
|
40
|
+
|
|
41
|
+
/** Whether a red build's output says the tree was never restored. */
|
|
42
|
+
export function coldTree(output: string): boolean {
|
|
43
|
+
return COLD_TREE.some((pattern) => pattern.test(output));
|
|
44
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// What a dev crew's onToolCall checks after the host's gate allowed a call, and the /hooks declarations it runs
|
|
2
|
+
// around the call — pure, no IO. The host gate runs first and keeps the session's rules; this guard can only
|
|
3
|
+
// refuse: the step's rule sets again (the only check of them under `orkeon run`, which keeps no session rules), the
|
|
4
|
+
// role's roots and its rewrite rule, the whole input of the folder readers, each operation of an edit_batch as the
|
|
5
|
+
// editor it stands for, and the act's mode when the host has no gate. The callbacks
|
|
6
|
+
// themselves, and the hooks' shell commands, are shared/application/dev/tool-callbacks.ts's.
|
|
7
|
+
import { ACT_TOOLS, READ_TOOLS, formatRule, matchesRule, sameToolName, shellCommandForms } from "../agent-policy/permission.ts";
|
|
8
|
+
import type { PermissionRule } from "../agent-policy/permission.ts";
|
|
9
|
+
import { declaredAccess } from "../agent-policy/tool-access.ts";
|
|
10
|
+
import {
|
|
11
|
+
GIT_CONFIG_SET_RULE, OPERATION_TOOLS, OPERATIONS_TOOL, PATH_WRITE_TOOLS, RULE_SETS, UNSCOPED_WRITE_TOOLS, gitConfigSets,
|
|
12
|
+
} from "../agent-policy/rule-sets.ts";
|
|
13
|
+
import type { RuleSetId } from "../agent-policy/rule-sets.ts";
|
|
14
|
+
import { STEP_RULE_SETS, roleRules, stepCommand } from "./step-rules.ts";
|
|
15
|
+
import type { DevRole, DevStep, LayoutRootKey } from "./step-rules.ts";
|
|
16
|
+
import type { RepoPackLayout } from "./repo-pack.ts";
|
|
17
|
+
import { matchesAny, relativePath } from "./test-paths.ts";
|
|
18
|
+
import { EDIT_BATCH_SHAPE } from "./reading-rule.ts";
|
|
19
|
+
import { WORKSPACE } from "../vfs.ts";
|
|
20
|
+
|
|
21
|
+
/** One /hooks declaration the callbacks run; `n` is its number in /hooks list. */
|
|
22
|
+
export interface ToolHook { n: number; event: "pre-tool" | "post-tool"; command: string }
|
|
23
|
+
|
|
24
|
+
/** What a crew builds its guard from: its step, and for a role of a batch the role and the pack's roots. */
|
|
25
|
+
export interface CallGuardSpec {
|
|
26
|
+
step: DevStep;
|
|
27
|
+
role?: DevRole;
|
|
28
|
+
layout?: Pick<RepoPackLayout, LayoutRootKey | "testFiles">;
|
|
29
|
+
/** Exact paths the test author's own root denies leave writable (the signature stubs a RED step names): no
|
|
30
|
+
* pattern, no other role, never a rule set's deny, never the host's gate: nothing widens. */
|
|
31
|
+
writable?: readonly string[];
|
|
32
|
+
/** The crew's `hooks` input: the /hooks registry as the command read it. */
|
|
33
|
+
hooks?: unknown;
|
|
34
|
+
/** Tools beyond READ_TOOLS that only read (a crew's autonomous tools declared `read`): let through by every
|
|
35
|
+
* mode when the host has no gate. */
|
|
36
|
+
readTools?: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A deny rule of the guard and where it comes from: a step's set, a role's roots, or a writing role's rewrite rule
|
|
40
|
+
* (no whole write of an existing source file, step-rules.ts roleRules). */
|
|
41
|
+
export interface GuardRule {
|
|
42
|
+
rule: PermissionRule;
|
|
43
|
+
origin: { kind: "set"; id: RuleSetId } | { kind: "role"; role: DevRole; access: "read" | "write" } | { kind: "rewrite"; role: DevRole };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CallGuard {
|
|
47
|
+
step: DevStep;
|
|
48
|
+
role?: DevRole;
|
|
49
|
+
rules: GuardRule[];
|
|
50
|
+
/** Why a root of the role got no rule, and the pack keys it lacks. */
|
|
51
|
+
problems: string[];
|
|
52
|
+
hooks: ToolHook[];
|
|
53
|
+
readTools: readonly string[];
|
|
54
|
+
/** What the role's write denies leave open: the pack's test file patterns, for the test author only. */
|
|
55
|
+
writable: readonly string[];
|
|
56
|
+
/** The exact paths the test author's write denies leave open: its stubs, compared as paths, never as patterns. */
|
|
57
|
+
stubs: readonly string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type CallVerdict = { allow: true } | { allow: false; reason: string; context: string };
|
|
61
|
+
|
|
62
|
+
const ALLOW: CallVerdict = { allow: true };
|
|
63
|
+
|
|
64
|
+
export function buildCallGuard(spec: CallGuardSpec): CallGuard {
|
|
65
|
+
const rules: GuardRule[] = [];
|
|
66
|
+
for (const id of STEP_RULE_SETS[spec.step]) {
|
|
67
|
+
for (const rule of RULE_SETS[id].rules) {
|
|
68
|
+
if (rule.effect === "deny") rules.push({ rule, origin: { kind: "set", id } });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const problems: string[] = [];
|
|
72
|
+
const writable: string[] = [];
|
|
73
|
+
const stubs: string[] = [];
|
|
74
|
+
if (spec.role !== undefined) {
|
|
75
|
+
const role = spec.role;
|
|
76
|
+
const access = role === "pilot" ? "read" : "write";
|
|
77
|
+
const own = roleRules(role, spec.layout ?? {});
|
|
78
|
+
for (const rule of own.rules) rules.push({ rule, origin: { kind: "role", role, access } });
|
|
79
|
+
for (const rule of own.rewrite) rules.push({ rule, origin: { kind: "rewrite", role } });
|
|
80
|
+
problems.push(...own.problems, ...own.missing.map((key) => `the pack gives no ${key}: no rule on it`));
|
|
81
|
+
if (access === "write") writable.push(...own.writable);
|
|
82
|
+
if (role === "test-author") stubs.push(...(spec.writable ?? []).map(relativePath).filter((p) => p !== ""));
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
step: spec.step, role: spec.role, rules, problems, hooks: toolHooks(spec.hooks), readTools: spec.readTools ?? [], writable, stubs,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The pre-tool and post-tool declarations of a raw registry, numbered by their place in it; a malformed entry,
|
|
90
|
+
* another event or an empty command is skipped (it keeps its number). */
|
|
91
|
+
export function toolHooks(raw: unknown): ToolHook[] {
|
|
92
|
+
if (!Array.isArray(raw)) return [];
|
|
93
|
+
const out: ToolHook[] = [];
|
|
94
|
+
raw.forEach((entry, i) => {
|
|
95
|
+
const event = (entry as { event?: unknown } | null)?.event;
|
|
96
|
+
const command = (entry as { command?: unknown } | null)?.command;
|
|
97
|
+
if ((event === "pre-tool" || event === "post-tool") && typeof command === "string" && command.trim() !== "") {
|
|
98
|
+
out.push({ n: i + 1, event, command: command.trim() });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The operators the host's shell tool refuses in a command (ShellCommandTool's forbidden list): a hook is one
|
|
105
|
+
* program and its arguments. */
|
|
106
|
+
export const SHELL_OPERATORS: readonly string[] = [";", "&&", "||", "|", "$(", "`", "\n", "\r", "&", "<", ">>", ">"];
|
|
107
|
+
|
|
108
|
+
/** The first operator of `command` the shell tool would refuse, or undefined. */
|
|
109
|
+
export function shellOperatorIn(command: string): string | undefined {
|
|
110
|
+
return SHELL_OPERATORS.find((op) => command.includes(op));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** A path the hook may receive as one word: letters, digits and `._/@+=,:-`. */
|
|
114
|
+
const PLAIN = /^[A-Za-z0-9._/@+=,:-]+$/;
|
|
115
|
+
|
|
116
|
+
/** The hook's command with `{tool}`, `{event}` and `{path}` replaced: `{path}` is the input's `path` when it is
|
|
117
|
+
* plain and does not start with `-` (never read as an option by the hook), else `-`. */
|
|
118
|
+
export function hookCommand(hook: ToolHook, tool: string, input: unknown): string {
|
|
119
|
+
const raw = (input as { path?: unknown } | null)?.path;
|
|
120
|
+
const path = typeof raw === "string" && PLAIN.test(raw) && !raw.startsWith("-") ? raw : "-";
|
|
121
|
+
const name = PLAIN.test(tool) ? tool : "-";
|
|
122
|
+
return hook.command.replaceAll("{tool}", name).replaceAll("{event}", hook.event).replaceAll("{path}", path);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The tools `acceptEdits` runs without asking beside the reads: the file editors, rag_ingest, rag_eval (an edit
|
|
126
|
+
* since Orkeon #223) and spawn_agent. A `github` write (`create_pr`, `create_issue`) and an `http_api` write
|
|
127
|
+
* (`POST`…) declare an execute (Orkeon #219): the host asks them there too. */
|
|
128
|
+
const ACCEPT_EDITS_TOOLS: readonly string[] = [...PATH_WRITE_TOOLS, OPERATIONS_TOOL, ...UNSCOPED_WRITE_TOOLS, "rag_ingest", "rag_eval", ...ACT_TOOLS];
|
|
129
|
+
|
|
130
|
+
/** What the act's mode lets through when the host has no gate, by the gate's own reading of the classes. A call
|
|
131
|
+
* that declares a read per call (a `github` read action, an `http_api` GET without a body nor a method-override
|
|
132
|
+
* header: agent-policy/tool-access.ts, Orkeon #219 and #223) runs in `default` and `acceptEdits` as the gate would
|
|
133
|
+
* run it; `rag_eval` declares an edit, asked about in `default`. `plan` and `dontAsk` stay stricter,
|
|
134
|
+
* the local reads alone: their catalogue withholds `github` and `http_api` whatever the call, since an outbound
|
|
135
|
+
* request is observable elsewhere (mode-policy.ts), and a fallback must not widen what the catalogue promised. */
|
|
136
|
+
function modeVerdict(guard: CallGuard, tool: string, input: unknown, mode: string): CallVerdict {
|
|
137
|
+
if (mode === "bypassPermissions") return ALLOW;
|
|
138
|
+
const reads = [...READ_TOOLS, ...guard.readTools];
|
|
139
|
+
const allowed = mode === "acceptEdits" ? [...reads, ...ACCEPT_EDITS_TOOLS] : reads;
|
|
140
|
+
if (allowed.includes(tool)) return ALLOW;
|
|
141
|
+
if ((mode === "default" || mode === "acceptEdits") && declaredAccess(tool, input) === "read") return ALLOW;
|
|
142
|
+
const known = ["default", "acceptEdits", "plan", "dontAsk"].includes(mode) ? mode : "default";
|
|
143
|
+
return {
|
|
144
|
+
allow: false,
|
|
145
|
+
reason: `${guard.step}: '${tool}' is not run in mode '${known}': the host has no permission gate, so the crew's ` +
|
|
146
|
+
`callback applies the mode itself`,
|
|
147
|
+
context: known === "acceptEdits"
|
|
148
|
+
? "Use the read tools and the file editors only."
|
|
149
|
+
: "Use the read tools only.",
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function plainText(value: unknown): string | undefined {
|
|
154
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A path with its `//` collapsed and its `.` and `..` segments resolved by their text: `/workspace/./src//x`
|
|
158
|
+
* and `/workspace/tests/../src/x` read `/workspace/src/x`, `./src/x` reads `src/x`. A `..` that climbs above the
|
|
159
|
+
* path's start is kept. */
|
|
160
|
+
export function normalisePath(path: string): string {
|
|
161
|
+
const absolute = path.startsWith("/");
|
|
162
|
+
const out: string[] = [];
|
|
163
|
+
for (const part of path.split("/")) {
|
|
164
|
+
if (part === "" || part === ".") continue;
|
|
165
|
+
if (part === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
|
|
166
|
+
else if (part === ".." && absolute) continue;
|
|
167
|
+
else out.push(part);
|
|
168
|
+
}
|
|
169
|
+
const text = out.join("/");
|
|
170
|
+
return absolute ? `/${text}` : text === "" ? "." : text;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The forms a path is matched in: as written, normalised, and for a relative path the absolute one the host
|
|
174
|
+
* resolves it to under the project, where a leading `..` cannot climb above the root
|
|
175
|
+
* (`../workspace/tests/a.test.ts` reads `/workspace/tests/a.test.ts`). Each form once. */
|
|
176
|
+
function pathForms(path: string): string[] {
|
|
177
|
+
const forms = [path, normalisePath(path)];
|
|
178
|
+
if (!path.startsWith("/")) forms.push(normalisePath(`${WORKSPACE}/${path}`));
|
|
179
|
+
return [...new Set(forms)];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function joinPath(base: string | undefined, tail: string): string {
|
|
183
|
+
if (base === undefined) return tail;
|
|
184
|
+
const head = base.endsWith("/") ? base.slice(0, -1) : base;
|
|
185
|
+
return tail.startsWith("/") ? tail : `${head}/${tail}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The paths a folder reader reaches beyond its `path`: glob's pattern under it, grep's glob under it (or the
|
|
189
|
+
* whole folder), count_pattern's and directory_search's whole folder. */
|
|
190
|
+
function reachedPaths(tool: string, input: Readonly<Record<string, unknown>>): string[] {
|
|
191
|
+
const base = plainText(input.path);
|
|
192
|
+
if (tool === "glob") {
|
|
193
|
+
const pattern = plainText(input.pattern);
|
|
194
|
+
return pattern === undefined ? [] : [joinPath(base, pattern)];
|
|
195
|
+
}
|
|
196
|
+
if (tool === "grep") return [joinPath(base, plainText(input.glob) ?? "**")];
|
|
197
|
+
if (tool === "count_pattern" || tool === "directory_search") return [joinPath(base, "**")];
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The text of `path` up to its first wildcard of a glob (`*`, `?`, `[`, `{`). */
|
|
202
|
+
function literalHead(path: string): string {
|
|
203
|
+
const at = path.search(/[*?[{]/);
|
|
204
|
+
return at < 0 ? path : path.slice(0, at);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Whether a joined path with a wildcard whose literal head starts the rule's folder can reach below it
|
|
208
|
+
* (`/workspace/**` and `/workspace/s*` reach `/workspace/src/*`). The rule's pattern is `<root>/*`. */
|
|
209
|
+
function reachesBelow(rule: PermissionRule, joined: string): boolean {
|
|
210
|
+
const pattern = rule.pattern ?? "";
|
|
211
|
+
if (!pattern.endsWith("/*") || pattern.slice(0, -2).includes("*")) return false;
|
|
212
|
+
const folder = pattern.slice(0, -1);
|
|
213
|
+
const head = literalHead(joined);
|
|
214
|
+
return head !== joined && folder.startsWith(head);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function originText(origin: GuardRule["origin"]): string {
|
|
218
|
+
if (origin.kind === "set") return `the rule set ${origin.id}`;
|
|
219
|
+
return origin.kind === "rewrite" ? `the ${origin.role}'s rewrite rule` : `the ${origin.role}'s roots`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function contextOf(guard: CallGuard, origin: GuardRule["origin"]): string {
|
|
223
|
+
if (origin.kind === "set") return `${RULE_SETS[origin.id].title} are refused during /${stepCommand(guard.step)}: do without this call.`;
|
|
224
|
+
if (origin.kind === "rewrite") {
|
|
225
|
+
return "This source file exists: change it by node (node_read for its sha256, then node_replace, node_insert or " +
|
|
226
|
+
"node_ensure) or with edit_file, never by writing it whole; file_write only creates a file.";
|
|
227
|
+
}
|
|
228
|
+
return origin.access === "read"
|
|
229
|
+
? `The ${origin.role} opens no source or test file by its path: work from the batch sheet and the plan.`
|
|
230
|
+
: `The ${origin.role} writes outside these roots only: ${origin.role === "implementer" ? "leave the tests as they are" : "write the tests, no source file"}.`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function ruleVerdict(guard: CallGuard, entry: GuardRule, how: string): CallVerdict {
|
|
234
|
+
return {
|
|
235
|
+
allow: false,
|
|
236
|
+
reason: `${guard.step}: refused by '${formatRule(entry.rule)}' of ${originText(entry.origin)}${how}`,
|
|
237
|
+
context: contextOf(guard, entry.origin),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* One call, after the host's gate allowed it: refused when the host has no gate and the act's mode does not let
|
|
243
|
+
* it through, when a deny rule of the guard covers its input, or when it reaches below a covered folder through
|
|
244
|
+
* a pattern of a folder reader; otherwise allowed. Allow rules are never read: the guard cannot widen the gate.
|
|
245
|
+
* The hooks are not run here (the callbacks run them after an allow).
|
|
246
|
+
*/
|
|
247
|
+
export function checkToolCall(
|
|
248
|
+
guard: CallGuard, tool: string, input: unknown, act: ActFacts,
|
|
249
|
+
): CallVerdict {
|
|
250
|
+
if (act.gateEnabled === false) {
|
|
251
|
+
const verdict = modeVerdict(guard, tool, input, act.mode);
|
|
252
|
+
if (!verdict.allow) return verdict;
|
|
253
|
+
}
|
|
254
|
+
const args = input !== null && typeof input === "object" && !Array.isArray(input)
|
|
255
|
+
? input as Readonly<Record<string, unknown>>
|
|
256
|
+
: {};
|
|
257
|
+
const given = typeof args.path === "string" ? pathForms(args.path) : [undefined];
|
|
258
|
+
for (const path of given) {
|
|
259
|
+
const asked = path === undefined || path === args.path ? args : { ...args, path };
|
|
260
|
+
for (const entry of guard.rules) {
|
|
261
|
+
if (leftWritable(guard, entry, path) || (entry.origin.kind === "rewrite" && act.newFile === true)) continue;
|
|
262
|
+
if (matchesRule(entry.rule, tool, asked)) return ruleVerdict(guard, entry, path === args.path ? "" : `, which '${path}' is`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// The command as the program receives it: a pattern on the raw text misses `git "push"` or `python3 -Ic`.
|
|
266
|
+
const command = sameToolName(tool, "shell_command") && typeof args.command === "string" ? args.command : undefined;
|
|
267
|
+
for (const form of command === undefined ? [] : shellCommandForms(command).slice(1)) {
|
|
268
|
+
for (const entry of guard.rules) {
|
|
269
|
+
if (matchesRule(entry.rule, tool, { ...args, command: form })) return ruleVerdict(guard, entry, `, which '${form}' runs`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// A git config that sets a value, which no glob of git-readonly can tell from a read (rule-sets gitConfigSets).
|
|
273
|
+
if (command !== undefined && gitConfigSets(command)) {
|
|
274
|
+
const held = guard.rules.find((e) => e.origin.kind === "set" && e.origin.id === "git-readonly");
|
|
275
|
+
if (held !== undefined) return ruleVerdict(guard, { rule: GIT_CONFIG_SET_RULE, origin: held.origin }, "");
|
|
276
|
+
}
|
|
277
|
+
const reached = reachedPaths(tool, args).flatMap(pathForms);
|
|
278
|
+
for (const joined of reached) {
|
|
279
|
+
for (const entry of guard.rules) {
|
|
280
|
+
if (entry.rule.argument !== "path" || leftWritable(guard, entry, joined)) continue;
|
|
281
|
+
if (matchesRule(entry.rule, tool, { ...args, path: joined })) {
|
|
282
|
+
return ruleVerdict(guard, entry, `, which '${joined}' reaches`);
|
|
283
|
+
}
|
|
284
|
+
if (entry.origin.kind === "role" && entry.origin.access === "read" && sameToolName(entry.rule.tool, tool)
|
|
285
|
+
&& reachesBelow(entry.rule, joined)) {
|
|
286
|
+
return ruleVerdict(guard, entry, `, which '${joined}' can reach`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return sameToolName(tool, OPERATIONS_TOOL) ? checkOperations(guard, args, act) : ALLOW;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** What the act's callbacks tell the guard of one call: the act's mode, the host's gate, and for a file_write
|
|
294
|
+
* whether its path names no file yet (read by the callbacks; undefined when not known, and the rewrite rule holds). */
|
|
295
|
+
export interface ActFacts { mode: string; gateEnabled: boolean | undefined; newFile?: boolean }
|
|
296
|
+
|
|
297
|
+
const BATCH_SHAPE = `Give ${EDIT_BATCH_SHAPE}.`;
|
|
298
|
+
|
|
299
|
+
function batchRefusal(guard: CallGuard, why: string, context = BATCH_SHAPE): CallVerdict {
|
|
300
|
+
return { allow: false, reason: `${guard.step}: edit_batch refused: ${why}`, context };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** An edit_batch, operation by operation: each is checked as the editor its `kind` stands for (OPERATION_TOOLS), with
|
|
304
|
+
* its own path and text, so every rule of the guard holds on it; the first refusal refuses the whole batch. A batch
|
|
305
|
+
* whose operations cannot be read is refused, and so is `validate: "build"`, the tool's own build rather than the
|
|
306
|
+
* pack's (run_build). An operation never creates a file: the rewrite rule's lift does not apply. */
|
|
307
|
+
function checkOperations(guard: CallGuard, args: Readonly<Record<string, unknown>>, act: ActFacts): CallVerdict {
|
|
308
|
+
const validate = args.validate;
|
|
309
|
+
if (validate !== undefined && validate !== null && String(validate).trim().toLowerCase() !== "parse") {
|
|
310
|
+
return batchRefusal(guard, `validate '${String(validate)}' is not run in a dev step`,
|
|
311
|
+
"Use validate \"parse\" (the default); the build is run_build's, with the pack's command.");
|
|
312
|
+
}
|
|
313
|
+
const operations = args.operations;
|
|
314
|
+
if (!Array.isArray(operations) || operations.length === 0) return batchRefusal(guard, "no list of operations");
|
|
315
|
+
for (const [i, raw] of operations.entries()) {
|
|
316
|
+
const op = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw as Readonly<Record<string, unknown>> : null;
|
|
317
|
+
const kind = typeof op?.kind === "string" ? op.kind.trim() : "";
|
|
318
|
+
const editor = Object.entries(OPERATION_TOOLS).find(([k]) => sameToolName(k, kind))?.[1];
|
|
319
|
+
if (op === null || typeof op.path !== "string" || op.path.trim() === "") {
|
|
320
|
+
return batchRefusal(guard, `operation ${i + 1} names no path`);
|
|
321
|
+
}
|
|
322
|
+
if (editor === undefined) return batchRefusal(guard, `operation ${i + 1} has the unknown kind '${kind}'`);
|
|
323
|
+
const verdict = checkToolCall(guard, editor, op, { mode: act.mode, gateEnabled: act.gateEnabled });
|
|
324
|
+
if (!verdict.allow) {
|
|
325
|
+
return { allow: false, reason: `${verdict.reason} (edit_batch operation ${i + 1}, ${kind} on '${op.path}')`, context: verdict.context };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return ALLOW;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** A role's own write deny does not hold on a path its guard leaves writable. */
|
|
332
|
+
function leftWritable(guard: CallGuard, entry: GuardRule, path: string | undefined): boolean {
|
|
333
|
+
return path !== undefined && entry.origin.kind === "role" && entry.origin.access === "write"
|
|
334
|
+
&& entry.rule.argument === "path"
|
|
335
|
+
&& (matchesAny(path, guard.writable) || guard.stubs.includes(relativePath(path)));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** The refusal the model reads: the reason, then the line saying what to do instead. */
|
|
339
|
+
export function denyText(verdict: Extract<CallVerdict, { allow: false }>): string {
|
|
340
|
+
return `${verdict.reason}\n${verdict.context}`;
|
|
341
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A text a brief carries so that the agent opens no file for it: a sheet, a test file, a diff.
|
|
2
|
+
// Each one goes under its title in a fenced block; past the room given, a text is cut and says
|
|
3
|
+
// so, the ones after it are left out and named, so the agent knows what it did not get. Pure.
|
|
4
|
+
|
|
5
|
+
export interface CarriedText {
|
|
6
|
+
/** What the text is: a path, or a sentence ("what F1 changed (git show ab700a7)"). */
|
|
7
|
+
title: string;
|
|
8
|
+
text: string;
|
|
9
|
+
/** The file the text is, when it is one: what `Carried.whole` names. */
|
|
10
|
+
path?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The blocks a brief carries, and the files among them it carries whole (neither cut nor left out). */
|
|
14
|
+
export interface Carried {
|
|
15
|
+
blocks: string[];
|
|
16
|
+
whole: ReadonlySet<string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The line a cut block ends with. */
|
|
20
|
+
const CUT = (left: number): string => `… (cut: ${left} more characters)`;
|
|
21
|
+
|
|
22
|
+
/** The fenced blocks of `texts`, in order, within `room` characters in all: a text past the room is cut with a
|
|
23
|
+
* note, the ones after it are listed as not carried. Empty when nothing fits. */
|
|
24
|
+
export function carriedBlocks(texts: readonly CarriedText[], room: number): string[] {
|
|
25
|
+
return carry(texts, room).blocks;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `carriedBlocks`, with the paths of the texts carried whole: a brief says a file is in it only when it is whole. */
|
|
29
|
+
export function carry(texts: readonly CarriedText[], room: number): Carried {
|
|
30
|
+
const out: string[] = [];
|
|
31
|
+
const skipped: string[] = [];
|
|
32
|
+
const whole = new Set<string>();
|
|
33
|
+
let left = room;
|
|
34
|
+
for (const { title, text, path } of texts) {
|
|
35
|
+
const body = text.replace(/\s+$/u, "");
|
|
36
|
+
const frame = `### ${title}\n\`\`\`text\n\n\`\`\``.length + 1;
|
|
37
|
+
if (left - frame < 200) {
|
|
38
|
+
skipped.push(title);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const fits = body.length <= left - frame;
|
|
42
|
+
if (fits && path !== undefined) whole.add(path);
|
|
43
|
+
const kept = fits ? body : `${body.slice(0, left - frame - 40)}\n${CUT(body.length - (left - frame - 40))}`;
|
|
44
|
+
out.push(`### ${title}\n\`\`\`text\n${kept}\n\`\`\``);
|
|
45
|
+
left -= frame + kept.length;
|
|
46
|
+
}
|
|
47
|
+
if (skipped.length > 0) out.push(`Not carried (no room left): ${skipped.join(", ")}.`);
|
|
48
|
+
return { blocks: out, whole };
|
|
49
|
+
}
|