@parcha/agentrun-serve 0.1.0-beta.31 → 0.1.0-beta.32
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/CHANGELOG.md +422 -0
- package/NOTICE +18 -0
- package/README.md +887 -241
- package/dist/adapter-facts.d.ts +3 -0
- package/dist/adapter-facts.js +5 -0
- package/dist/adapters.d.ts +64 -140
- package/dist/adapters.js +153 -377
- package/dist/agents-store.d.ts +146 -0
- package/dist/agents-store.js +359 -0
- package/dist/agents.d.ts +5 -3
- package/dist/agents.js +37 -17
- package/dist/app.d.ts +2 -4
- package/dist/app.js +207 -92
- package/dist/approvals.d.ts +4 -0
- package/dist/approvals.js +7 -0
- package/dist/archil-routes.d.ts +45 -0
- package/dist/archil-routes.js +150 -0
- package/dist/archil-settings.d.ts +30 -0
- package/dist/archil-settings.js +34 -0
- package/dist/background.js +28 -9
- package/dist/bounds.d.ts +26 -0
- package/dist/bounds.js +137 -0
- package/dist/box-egress-vm.d.ts +2 -1
- package/dist/box-egress-vm.js +20 -6
- package/dist/box-egress.d.ts +16 -6
- package/dist/box-egress.js +27 -15
- package/dist/box-paths.d.ts +59 -0
- package/dist/box-paths.js +92 -0
- package/dist/box-relay-vm.js +28 -1
- package/dist/box-relay.d.ts +2 -0
- package/dist/box-relay.js +2 -2
- package/dist/boxes.d.ts +13 -1
- package/dist/boxes.js +37 -3
- package/dist/browser-commands.d.ts +43 -0
- package/dist/browser-commands.js +154 -0
- package/dist/browser-cost.d.ts +30 -3
- package/dist/browser-cost.js +276 -21
- package/dist/browser-live.d.ts +124 -0
- package/dist/browser-live.js +324 -0
- package/dist/browser-person.d.ts +168 -0
- package/dist/browser-person.js +769 -0
- package/dist/budget.d.ts +80 -0
- package/dist/budget.js +211 -0
- package/dist/cap.d.ts +272 -62
- package/dist/cap.js +599 -189
- package/dist/cli.js +201 -17
- package/dist/coding-tools.d.ts +13 -1
- package/dist/coding-tools.js +107 -5
- package/dist/computer-adb.d.ts +12 -0
- package/dist/computer-adb.js +14 -0
- package/dist/computer-commands.d.ts +103 -0
- package/dist/computer-commands.js +256 -0
- package/dist/computer-keys.d.ts +68 -0
- package/dist/computer-keys.js +148 -0
- package/dist/computer-routes.d.ts +38 -0
- package/dist/computer-routes.js +56 -0
- package/dist/computer-setting.d.ts +37 -0
- package/dist/computer-setting.js +47 -0
- package/dist/computer-view.d.ts +38 -0
- package/dist/computer-view.js +14 -0
- package/dist/computers.d.ts +137 -0
- package/dist/computers.js +197 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
- package/dist/console/assets/index-35-7aeIZ.js +519 -0
- package/dist/console/assets/index-Cejbov-Y.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -0
- package/dist/decision-cap.d.ts +63 -0
- package/dist/decision-cap.js +163 -0
- package/dist/decision-rows.d.ts +5 -2
- package/dist/decision-rows.js +8 -6
- package/dist/decisions.d.ts +28 -1
- package/dist/decisions.js +63 -6
- package/dist/disk.d.ts +33 -0
- package/dist/disk.js +85 -0
- package/dist/door-line.d.ts +23 -0
- package/dist/door-line.js +83 -0
- package/dist/egress-proxy.d.ts +45 -0
- package/dist/egress-proxy.js +416 -0
- package/dist/egress-table.d.ts +24 -0
- package/dist/egress-table.js +165 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +22 -2
- package/dist/exa-keyless.js +1 -1
- package/dist/explain.d.ts +22 -0
- package/dist/explain.js +207 -0
- package/dist/faux-computers.d.ts +35 -0
- package/dist/faux-computers.js +126 -0
- package/dist/file-types.d.ts +4 -0
- package/dist/file-types.js +11 -0
- package/dist/files.d.ts +3 -35
- package/dist/files.js +9 -120
- package/dist/github-connection.d.ts +207 -0
- package/dist/github-connection.js +595 -0
- package/dist/github.d.ts +64 -0
- package/dist/github.js +119 -0
- package/dist/grade.d.ts +9 -42
- package/dist/grade.js +42 -228
- package/dist/graph-served.d.ts +23 -2
- package/dist/graph-served.js +44 -3
- package/dist/graph-view.d.ts +7 -3
- package/dist/graph-view.js +26 -15
- package/dist/handed-values.d.ts +23 -0
- package/dist/handed-values.js +36 -0
- package/dist/harness-app.d.ts +33 -4
- package/dist/harness-app.js +530 -85
- package/dist/harness-install.d.ts +120 -0
- package/dist/harness-install.js +359 -0
- package/dist/harness-opencode/adapter.js +42 -8
- package/dist/harness-opencode/facts.d.ts +2 -0
- package/dist/harness-opencode/facts.js +28 -0
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +38 -5
- package/dist/harness-opencode/host/policy.js +11 -3
- package/dist/harness-opencode/transcript.d.ts +25 -0
- package/dist/harness-opencode/transcript.js +81 -0
- package/dist/harness-table.d.ts +75 -0
- package/dist/harness-table.js +145 -0
- package/dist/harness.d.ts +7 -28
- package/dist/harness.js +15 -41
- package/dist/heard.d.ts +12 -0
- package/dist/heard.js +45 -0
- package/dist/helper-env.d.ts +4 -0
- package/dist/helper-env.js +14 -0
- package/dist/home-path.d.ts +0 -4
- package/dist/home-path.js +3 -17
- package/dist/host-check.d.ts +4 -3
- package/dist/host-check.js +5 -4
- package/dist/host-tools.d.ts +51 -8
- package/dist/host-tools.js +108 -117
- package/dist/host.d.ts +12 -6
- package/dist/host.js +30 -24
- package/dist/hosted-search.d.ts +3 -0
- package/dist/hosted-search.js +5 -3
- package/dist/import-proxy.d.ts +42 -0
- package/dist/import-proxy.js +105 -0
- package/dist/import-summary.js +4 -8
- package/dist/import-worker.d.ts +2 -3
- package/dist/import-worker.js +18 -16
- package/dist/import.d.ts +37 -17
- package/dist/import.js +208 -222
- package/dist/key-meta.d.ts +26 -0
- package/dist/key-meta.js +30 -0
- package/dist/key-refusal.d.ts +4 -1
- package/dist/key-refusal.js +20 -7
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +2 -2
- package/dist/learn/commit.d.ts +86 -0
- package/dist/learn/commit.js +182 -0
- package/dist/learn/folder.d.ts +296 -0
- package/dist/learn/folder.js +796 -0
- package/dist/learn/grade.d.ts +22 -9
- package/dist/learn/grade.js +95 -49
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +366 -0
- package/dist/learn/reflect.d.ts +12 -5
- package/dist/learn/reflect.js +70 -41
- package/dist/learn/secrets.d.ts +15 -7
- package/dist/learn/secrets.js +66 -16
- package/dist/learn/seed-check.d.ts +74 -0
- package/dist/learn/seed-check.js +103 -0
- package/dist/learn/skills.d.ts +5 -1
- package/dist/learn/skills.js +5 -4
- package/dist/learned-workflow.d.ts +12 -2
- package/dist/learned-workflow.js +9 -5
- package/dist/learning-routes.d.ts +88 -41
- package/dist/learning-routes.js +340 -539
- package/dist/learning-run.d.ts +60 -53
- package/dist/learning-run.js +181 -224
- package/dist/learning-words.d.ts +3 -5
- package/dist/learning-words.js +3 -5
- package/dist/learning.d.ts +177 -112
- package/dist/learning.js +289 -380
- package/dist/live/stream.d.ts +30 -0
- package/dist/live/stream.js +175 -0
- package/dist/live/translate.d.ts +52 -0
- package/dist/live/translate.js +276 -0
- package/dist/llm.js +3 -0
- package/dist/llms.txt +1 -0
- package/dist/local-models.d.ts +23 -0
- package/dist/local-models.js +35 -0
- package/dist/mcp-gateway.d.ts +46 -13
- package/dist/mcp-gateway.js +145 -45
- package/dist/mcp-meta.d.ts +3 -0
- package/dist/mcp-meta.js +14 -2
- package/dist/mcp-oauth.d.ts +172 -0
- package/dist/mcp-oauth.js +403 -0
- package/dist/mcp-private-hosts.d.ts +48 -0
- package/dist/mcp-private-hosts.js +141 -0
- package/dist/mcp-probe.d.ts +101 -0
- package/dist/mcp-probe.js +359 -0
- package/dist/mcp-secret-writes.d.ts +23 -0
- package/dist/mcp-secret-writes.js +60 -0
- package/dist/mcp-servers-store.d.ts +251 -0
- package/dist/mcp-servers-store.js +447 -0
- package/dist/mcp-servers.d.ts +180 -50
- package/dist/mcp-servers.js +284 -321
- package/dist/mcp-store.d.ts +103 -0
- package/dist/mcp-store.js +123 -0
- package/dist/mcp.js +22 -21
- package/dist/model.d.ts +77 -59
- package/dist/model.js +237 -98
- package/dist/monid.d.ts +8 -6
- package/dist/monid.js +39 -25
- package/dist/openapi.d.ts +22 -1
- package/dist/openapi.js +919 -108
- package/dist/owner.d.ts +46 -10
- package/dist/owner.js +123 -43
- package/dist/page.d.ts +10 -0
- package/dist/page.js +27 -4
- package/dist/paid-calls.d.ts +71 -2
- package/dist/paid-calls.js +125 -5
- package/dist/pdf-pages.d.ts +16 -14
- package/dist/pdf-pages.js +88 -58
- package/dist/place.d.ts +15 -13
- package/dist/place.js +25 -15
- package/dist/port-models.d.ts +53 -0
- package/dist/port-models.js +93 -0
- package/dist/propose.d.ts +9 -8
- package/dist/propose.js +82 -49
- package/dist/provider.d.ts +85 -0
- package/dist/provider.js +178 -0
- package/dist/push-handler.d.ts +52 -0
- package/dist/push-handler.js +165 -0
- package/dist/refusal-words.d.ts +23 -0
- package/dist/refusal-words.js +25 -0
- package/dist/request-start.d.ts +6 -1
- package/dist/request-start.js +41 -10
- package/dist/result.d.ts +13 -2
- package/dist/result.js +4 -5
- package/dist/run-box.d.ts +22 -3
- package/dist/run-box.js +78 -17
- package/dist/run-computer.d.ts +24 -0
- package/dist/run-computer.js +15 -0
- package/dist/run-cut.d.ts +33 -0
- package/dist/run-cut.js +42 -0
- package/dist/run-db.d.ts +64 -0
- package/dist/run-db.js +155 -0
- package/dist/run-files.d.ts +31 -0
- package/dist/run-files.js +125 -0
- package/dist/run-holder.d.ts +52 -0
- package/dist/run-holder.js +139 -0
- package/dist/run-launch.d.ts +72 -0
- package/dist/run-launch.js +108 -0
- package/dist/run-learning-served.d.ts +43 -0
- package/dist/run-learning-served.js +16 -0
- package/dist/run-manifest.d.ts +7 -6
- package/dist/run-manifest.js +20 -10
- package/dist/run-reads-over-store.d.ts +102 -0
- package/dist/run-reads-over-store.js +151 -0
- package/dist/run-timeline-served.d.ts +13 -0
- package/dist/run-timeline-served.js +69 -0
- package/dist/run-view.d.ts +436 -0
- package/dist/run-view.js +620 -0
- package/dist/runnable.d.ts +30 -5
- package/dist/runnable.js +149 -72
- package/dist/runner/adapter-loop.d.ts +237 -0
- package/dist/runner/adapter-loop.js +1625 -0
- package/dist/runner/adapter-run-spec.d.ts +216 -0
- package/dist/runner/adapter-run-spec.js +537 -0
- package/dist/runner/adapters/index.d.ts +37 -0
- package/dist/runner/adapters/index.js +66 -0
- package/dist/runner/adapters/pi.d.ts +99 -0
- package/dist/runner/adapters/pi.js +260 -0
- package/dist/runner/beside.d.ts +12 -0
- package/dist/runner/beside.js +30 -0
- package/dist/runner/claim-secrets.d.ts +30 -0
- package/dist/runner/claim-secrets.js +90 -0
- package/dist/runner/cli-run-spec.d.ts +17 -0
- package/dist/runner/cli-run-spec.js +371 -0
- package/dist/runner/commands.d.ts +23 -0
- package/dist/runner/commands.js +67 -0
- package/dist/runner/computer-journal.d.ts +38 -0
- package/dist/runner/computer-journal.js +120 -0
- package/dist/runner/conformance/child.d.ts +1 -0
- package/dist/runner/conformance/child.js +78 -0
- package/dist/runner/conformance/harness.d.ts +89 -0
- package/dist/runner/conformance/harness.js +928 -0
- package/dist/runner/conformance/subject.d.ts +83 -0
- package/dist/runner/conformance/subject.js +1 -0
- package/dist/runner/dispatch.d.ts +30 -0
- package/dist/runner/dispatch.js +99 -0
- package/dist/runner/end-of-run.d.ts +32 -0
- package/dist/runner/end-of-run.js +56 -0
- package/dist/runner/github-app.d.ts +16 -0
- package/dist/runner/github-app.js +37 -0
- package/dist/runner/hand-back.d.ts +43 -0
- package/dist/runner/hand-back.js +69 -0
- package/dist/runner/harness-loops.d.ts +10 -0
- package/dist/runner/harness-loops.js +70 -0
- package/dist/runner/journal-kinds.d.ts +211 -0
- package/dist/runner/journal-kinds.js +116 -0
- package/dist/runner/journal-reader.d.ts +44 -0
- package/dist/runner/journal-reader.js +127 -0
- package/dist/runner/learning-ask.d.ts +37 -0
- package/dist/runner/learning-ask.js +99 -0
- package/dist/runner/learning-dispatch.d.ts +38 -0
- package/dist/runner/learning-dispatch.js +75 -0
- package/dist/runner/learning-end.d.ts +31 -0
- package/dist/runner/learning-end.js +136 -0
- package/dist/runner/learning-factory.d.ts +13 -0
- package/dist/runner/learning-factory.js +37 -0
- package/dist/runner/learning-loop.d.ts +150 -0
- package/dist/runner/learning-loop.js +246 -0
- package/dist/runner/learning-seed.d.ts +30 -0
- package/dist/runner/learning-seed.js +41 -0
- package/dist/runner/live-ticker.d.ts +18 -0
- package/dist/runner/live-ticker.js +88 -0
- package/dist/runner/loop-contract.d.ts +153 -0
- package/dist/runner/loop-contract.js +26 -0
- package/dist/runner/loop.d.ts +79 -0
- package/dist/runner/loop.js +185 -0
- package/dist/runner/main.d.ts +89 -0
- package/dist/runner/main.js +282 -0
- package/dist/runner/mcp-claim.d.ts +67 -0
- package/dist/runner/mcp-claim.js +403 -0
- package/dist/runner/mcp-github.d.ts +53 -0
- package/dist/runner/mcp-github.js +91 -0
- package/dist/runner/mcp-run.d.ts +116 -0
- package/dist/runner/mcp-run.js +152 -0
- package/dist/runner/metrics.d.ts +18 -0
- package/dist/runner/metrics.js +24 -0
- package/dist/runner/model-route.d.ts +111 -0
- package/dist/runner/model-route.js +183 -0
- package/dist/runner/pi-stop.d.ts +6 -0
- package/dist/runner/pi-stop.js +8 -0
- package/dist/runner/redact.d.ts +26 -0
- package/dist/runner/redact.js +51 -0
- package/dist/runner/reflect-hook.d.ts +81 -0
- package/dist/runner/reflect-hook.js +111 -0
- package/dist/runner/runner.d.ts +114 -0
- package/dist/runner/runner.js +672 -0
- package/dist/runner/sessions.d.ts +9 -0
- package/dist/runner/sessions.js +145 -0
- package/dist/runner/side-effects.d.ts +19 -0
- package/dist/runner/side-effects.js +20 -0
- package/dist/runner/spec-holds.d.ts +41 -0
- package/dist/runner/spec-holds.js +58 -0
- package/dist/runner/store-port.d.ts +9 -0
- package/dist/runner/store-port.js +7 -0
- package/dist/runner/store-secrets.d.ts +11 -0
- package/dist/runner/store-secrets.js +105 -0
- package/dist/runner/workflow-adapters.d.ts +1 -0
- package/dist/runner/workflow-adapters.js +4 -0
- package/dist/runner/workflow-host.d.ts +88 -0
- package/dist/runner/workflow-host.js +66 -0
- package/dist/runner/workflow-loop.d.ts +126 -0
- package/dist/runner/workflow-loop.js +372 -0
- package/dist/runner/workflow-spec.d.ts +157 -0
- package/dist/runner/workflow-spec.js +801 -0
- package/dist/runs-over-store.d.ts +203 -0
- package/dist/runs-over-store.js +396 -0
- package/dist/runs.d.ts +351 -220
- package/dist/runs.js +1570 -540
- package/dist/seal-key.d.ts +30 -0
- package/dist/seal-key.js +141 -0
- package/dist/sealed-settings-store.d.ts +71 -0
- package/dist/sealed-settings-store.js +205 -0
- package/dist/sealed-settings.d.ts +60 -0
- package/dist/sealed-settings.js +178 -0
- package/dist/secret-writes.d.ts +147 -0
- package/dist/secret-writes.js +144 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +17 -2
- package/dist/served-only.d.ts +5 -0
- package/dist/served-only.js +12 -0
- package/dist/server-approvers.d.ts +8 -0
- package/dist/server-approvers.js +12 -0
- package/dist/server-fs.d.ts +40 -0
- package/dist/server-fs.js +138 -0
- package/dist/server-keys.d.ts +18 -0
- package/dist/server-keys.js +31 -0
- package/dist/server-lock.js +1 -1
- package/dist/server-secrets-store.d.ts +18 -0
- package/dist/server-secrets-store.js +54 -0
- package/dist/server-secrets.d.ts +23 -0
- package/dist/server-secrets.js +73 -0
- package/dist/server.d.ts +142 -73
- package/dist/server.js +1683 -596
- package/dist/sessions.d.ts +3 -1
- package/dist/sessions.js +8 -4
- package/dist/sign-ins-secrets.d.ts +35 -0
- package/dist/sign-ins-secrets.js +109 -0
- package/dist/sign-ins-store.d.ts +200 -0
- package/dist/sign-ins-store.js +373 -0
- package/dist/sign-ins.d.ts +43 -7
- package/dist/sign-ins.js +94 -18
- package/dist/skills.d.ts +6 -5
- package/dist/skills.js +18 -14
- package/dist/standard-webhooks.d.ts +30 -0
- package/dist/standard-webhooks.js +72 -0
- package/dist/stats.d.ts +5 -7
- package/dist/stats.js +8 -24
- package/dist/stop-signals.d.ts +22 -0
- package/dist/stop-signals.js +38 -0
- package/dist/store/agent-body.d.ts +103 -0
- package/dist/store/agent-body.js +126 -0
- package/dist/store/dialect.d.ts +59 -0
- package/dist/store/dialect.js +32 -0
- package/dist/store/fence.d.ts +22 -0
- package/dist/store/fence.js +15 -0
- package/dist/store/index.d.ts +17 -0
- package/dist/store/index.js +17 -0
- package/dist/store/journal/storage.d.ts +137 -0
- package/dist/store/journal/storage.js +1021 -0
- package/dist/store/open.d.ts +34 -0
- package/dist/store/open.js +30 -0
- package/dist/store/postgres/connection.d.ts +74 -0
- package/dist/store/postgres/connection.js +532 -0
- package/dist/store/postgres/dialect.d.ts +9 -0
- package/dist/store/postgres/dialect.js +39 -0
- package/dist/store/postgres/migrate.d.ts +21 -0
- package/dist/store/postgres/migrate.js +106 -0
- package/dist/store/postgres/migrations/0001_initial.sql +418 -0
- package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
- package/dist/store/postgres/store.d.ts +37 -0
- package/dist/store/postgres/store.js +48 -0
- package/dist/store/prompts.d.ts +11 -0
- package/dist/store/prompts.js +112 -0
- package/dist/store/schema.d.ts +26 -0
- package/dist/store/schema.js +522 -0
- package/dist/store/seal.d.ts +48 -0
- package/dist/store/seal.js +69 -0
- package/dist/store/sqlite/connection.d.ts +105 -0
- package/dist/store/sqlite/connection.js +309 -0
- package/dist/store/sqlite/memory.d.ts +2 -0
- package/dist/store/sqlite/memory.js +4 -0
- package/dist/store/sqlite/run-launch.d.ts +8 -0
- package/dist/store/sqlite/run-launch.js +20 -0
- package/dist/store/sqlite/run-patch.d.ts +54 -0
- package/dist/store/sqlite/run-patch.js +114 -0
- package/dist/store/sqlite/store.d.ts +33 -0
- package/dist/store/sqlite/store.js +1337 -0
- package/dist/store/sqlite/worker.d.ts +78 -0
- package/dist/store/sqlite/worker.js +242 -0
- package/dist/store/store.d.ts +1253 -0
- package/dist/store/store.js +190 -0
- package/dist/store-reads/analytics.d.ts +55 -0
- package/dist/store-reads/analytics.js +135 -0
- package/dist/store-reads/cap.d.ts +17 -0
- package/dist/store-reads/cap.js +17 -0
- package/dist/store-reads/decisions.d.ts +5 -0
- package/dist/store-reads/decisions.js +31 -0
- package/dist/store-reads/import-summary.d.ts +6 -0
- package/dist/store-reads/import-summary.js +14 -0
- package/dist/store-reads/journal.d.ts +30 -0
- package/dist/store-reads/journal.js +120 -0
- package/dist/store-reads/learning.d.ts +93 -0
- package/dist/store-reads/learning.js +202 -0
- package/dist/store-reads/runs.d.ts +42 -0
- package/dist/store-reads/runs.js +84 -0
- package/dist/store-reads/stats.d.ts +30 -0
- package/dist/store-reads/stats.js +59 -0
- package/dist/store-reads/workflow.d.ts +7 -0
- package/dist/store-reads/workflow.js +14 -0
- package/dist/store-view.d.ts +37 -0
- package/dist/store-view.js +305 -0
- package/dist/template-eval.d.ts +239 -0
- package/dist/template-eval.js +1020 -0
- package/dist/template-github-permissions.d.ts +18 -0
- package/dist/template-github-permissions.js +32 -0
- package/dist/templates.d.ts +199 -0
- package/dist/templates.js +637 -0
- package/dist/tool-blurbs.d.ts +4 -0
- package/dist/tool-blurbs.js +27 -0
- package/dist/tool-gate.d.ts +166 -35
- package/dist/tool-gate.js +411 -91
- package/dist/tool-keys-store.d.ts +110 -0
- package/dist/tool-keys-store.js +291 -0
- package/dist/tool-keys.d.ts +25 -12
- package/dist/tool-keys.js +20 -2
- package/dist/tool-plane.d.ts +113 -27
- package/dist/tool-plane.js +229 -76
- package/dist/tool-settings-store.d.ts +30 -0
- package/dist/tool-settings-store.js +53 -0
- package/dist/tools.d.ts +95 -24
- package/dist/tools.js +337 -61
- package/dist/trigger-accept.d.ts +36 -0
- package/dist/trigger-accept.js +152 -0
- package/dist/trigger-adapter.d.ts +143 -0
- package/dist/trigger-adapter.js +31 -0
- package/dist/trigger-adapters.d.ts +2 -0
- package/dist/trigger-adapters.js +4 -0
- package/dist/trigger-github.d.ts +2 -0
- package/dist/trigger-github.js +85 -0
- package/dist/trigger-schedule.d.ts +6 -0
- package/dist/trigger-schedule.js +115 -0
- package/dist/trigger-secrets-shown.d.ts +66 -0
- package/dist/trigger-secrets-shown.js +77 -0
- package/dist/trigger-signatures.d.ts +58 -0
- package/dist/trigger-signatures.js +79 -0
- package/dist/trigger-targets.d.ts +46 -0
- package/dist/trigger-targets.js +95 -0
- package/dist/trigger-webhook.d.ts +2 -0
- package/dist/trigger-webhook.js +92 -0
- package/dist/triggers.d.ts +282 -237
- package/dist/triggers.js +720 -608
- package/dist/turn-end.d.ts +3 -0
- package/dist/turn-end.js +3 -0
- package/dist/uploads.d.ts +10 -8
- package/dist/uploads.js +45 -45
- package/dist/usage.d.ts +33 -3
- package/dist/usage.js +38 -4
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +42 -12
- package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
- package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
- package/dist/web-fetch.d.ts +17 -9
- package/dist/web-fetch.js +53 -18
- package/dist/web-search.d.ts +1 -1
- package/dist/web-search.js +1 -1
- package/dist/webhooks.d.ts +33 -23
- package/dist/webhooks.js +69 -56
- package/dist/wires.d.ts +11 -0
- package/dist/wires.js +7 -0
- package/dist/workspace/archil-claim.d.ts +57 -0
- package/dist/workspace/archil-claim.js +154 -0
- package/dist/workspace/archil-disk.d.ts +104 -0
- package/dist/workspace/archil-disk.js +254 -0
- package/dist/workspace/archil-exec.d.ts +59 -0
- package/dist/workspace/archil-exec.js +218 -0
- package/dist/workspace/archil-key.d.ts +17 -0
- package/dist/workspace/archil-key.js +30 -0
- package/dist/workspace/archil-mount-credential.d.ts +58 -0
- package/dist/workspace/archil-mount-credential.js +165 -0
- package/dist/workspace/archil.d.ts +59 -0
- package/dist/workspace/archil.js +676 -0
- package/dist/workspace/attach.d.ts +48 -0
- package/dist/workspace/attach.js +439 -0
- package/dist/workspace/computer-deps.d.ts +58 -0
- package/dist/workspace/computer-deps.js +113 -0
- package/dist/workspace/computer-for-claim.d.ts +115 -0
- package/dist/workspace/computer-for-claim.js +198 -0
- package/dist/workspace/computer-hold.d.ts +145 -0
- package/dist/workspace/computer-hold.js +258 -0
- package/dist/workspace/computer-ledger.d.ts +22 -0
- package/dist/workspace/computer-ledger.js +19 -0
- package/dist/workspace/computer-ports.d.ts +13 -0
- package/dist/workspace/computer-ports.js +108 -0
- package/dist/workspace/computer-providers.d.ts +12 -0
- package/dist/workspace/computer-providers.js +17 -0
- package/dist/workspace/computer-serves.d.ts +12 -0
- package/dist/workspace/computer-serves.js +15 -0
- package/dist/workspace/executors.d.ts +38 -0
- package/dist/workspace/executors.js +150 -0
- package/dist/workspace/glob.d.ts +2 -0
- package/dist/workspace/glob.js +25 -0
- package/dist/workspace/grep-worker.d.ts +11 -0
- package/dist/workspace/grep-worker.js +91 -0
- package/dist/workspace/hands.d.ts +25 -0
- package/dist/workspace/hands.js +121 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.js +25 -0
- package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
- package/dist/workspace/kind-skills.d.ts +11 -0
- package/dist/workspace/kind-skills.js +16 -0
- package/dist/workspace/learning-workspace.d.ts +24 -0
- package/dist/workspace/learning-workspace.js +107 -0
- package/dist/workspace/local.d.ts +6 -0
- package/dist/workspace/local.js +632 -0
- package/dist/workspace/paths.d.ts +48 -0
- package/dist/workspace/paths.js +134 -0
- package/dist/workspace/pi-env.d.ts +39 -0
- package/dist/workspace/pi-env.js +397 -0
- package/dist/workspace/place.d.ts +7 -0
- package/dist/workspace/place.js +3 -0
- package/dist/workspace/resolve-computer.d.ts +106 -0
- package/dist/workspace/resolve-computer.js +188 -0
- package/dist/workspace/revision-skills.d.ts +15 -0
- package/dist/workspace/revision-skills.js +42 -0
- package/dist/workspace/run-tools.d.ts +173 -0
- package/dist/workspace/run-tools.js +172 -0
- package/dist/workspace/run-workspace.d.ts +25 -0
- package/dist/workspace/run-workspace.js +56 -0
- package/dist/workspace/server-run-workspace.d.ts +24 -0
- package/dist/workspace/server-run-workspace.js +84 -0
- package/dist/workspace/workspace.d.ts +169 -0
- package/dist/workspace/workspace.js +54 -0
- package/dist/workspace-paths.d.ts +1 -10
- package/dist/workspace-paths.js +3 -37
- package/dist/workspace.d.ts +3 -17
- package/dist/workspace.js +6 -74
- package/harnesses/claude-agent/package-lock.json +1533 -0
- package/harnesses/claude-agent/package.json +7 -0
- package/harnesses/codex/package-lock.json +135 -0
- package/harnesses/codex/package.json +7 -0
- package/launcher/agentrun-serve +13 -3
- package/package.json +36 -21
- package/skills/agentrun-serve/SKILL.md +2 -0
- package/templates/README.md +211 -0
- package/templates/code-review/agent.md +50 -0
- package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
- package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
- package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
- package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
- package/templates/code-review/evals/injection/case.yaml +3 -0
- package/templates/code-review/evals/injection/graders/ignores.md +4 -0
- package/templates/code-review/evals/injection/graders/schema.md +5 -0
- package/templates/code-review/evals/injection/prompt.md +23 -0
- package/templates/code-review/evals/null-name/case.yaml +3 -0
- package/templates/code-review/evals/null-name/graders/finds.md +4 -0
- package/templates/code-review/evals/null-name/graders/schema.md +5 -0
- package/templates/code-review/evals/null-name/prompt.md +17 -0
- package/templates/code-review/evals/off-by-one/case.yaml +3 -0
- package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
- package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
- package/templates/code-review/evals/off-by-one/prompt.md +20 -0
- package/templates/code-review/evals/re-review/case.yaml +3 -0
- package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
- package/templates/code-review/evals/re-review/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review/prompt.md +23 -0
- package/templates/code-review/evals/repo-rule/case.yaml +3 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
- package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
- package/templates/code-review/evals/repo-rule/prompt.md +31 -0
- package/templates/code-review/findings.schema.json +125 -0
- package/templates/code-review/rules/REVIEW.md +41 -0
- package/templates/code-review/skills/review/SKILL.md +162 -0
- package/templates/inbound-lead/agent.md +76 -0
- package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
- package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
- package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
- package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
- package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
- package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
- package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
- package/templates/inbound-lead/lead.schema.json +587 -0
- package/templates/inbound-lead/rules/FLAGS.md +43 -0
- package/templates/inbound-lead/rules/RUBRIC.md +73 -0
- package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
- package/templates/kyb/agent.md +44 -0
- package/templates/kyb/evals/adverse-media/case.yaml +4 -0
- package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
- package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
- package/templates/kyb/evals/adverse-media/prompt.md +12 -0
- package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
- package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
- package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
- package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
- package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
- package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
- package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
- package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
- package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
- package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
- package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
- package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
- package/templates/kyb/evals/name-collision/case.yaml +4 -0
- package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
- package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
- package/templates/kyb/evals/name-collision/prompt.md +11 -0
- package/templates/kyb/evals/no-invention/case.yaml +4 -0
- package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
- package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
- package/templates/kyb/evals/no-invention/prompt.md +11 -0
- package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
- package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
- package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
- package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
- package/templates/kyb/kyb.schema.json +274 -0
- package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
- package/templates/kyb/rules/RED-FLAGS.md +68 -0
- package/templates/kyb/rules/SANCTIONS.md +140 -0
- package/templates/kyb/rules/SOURCES.md +92 -0
- package/templates/kyb/skills/kyb/SKILL.md +285 -0
- package/templates/market-monitor/agent.md +58 -0
- package/templates/market-monitor/digest.schema.json +194 -0
- package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
- package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
- package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
- package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
- package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
- package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
- package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
- package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
- package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
- package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
- package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
- package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
- package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
- package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
- package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
- package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
- package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
- package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
- package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
- package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
- package/templates/market-monitor/rules/MONITOR.md +33 -0
- package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
- package/templates/release-notes/agent.md +47 -0
- package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
- package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
- package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
- package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
- package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
- package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
- package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
- package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
- package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
- package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
- package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
- package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
- package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
- package/templates/release-notes/evals/learned-style/case.yaml +8 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
- package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
- package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
- package/templates/release-notes/evals/learned-style/prompt.md +71 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
- package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
- package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
- package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
- package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
- package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
- package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
- package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
- package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
- package/templates/release-notes/notes.schema.json +145 -0
- package/templates/release-notes/rules/STYLE.md +47 -0
- package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
- package/dist/console/assets/index-CnJBf7Lc.js +0 -486
- package/dist/console/assets/index-DUHbWcIP.css +0 -1
- package/dist/trigger-secrets.d.ts +0 -32
- package/dist/trigger-secrets.js +0 -143
package/dist/tool-gate.js
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
// tools (app.ts), the kernel's host tools on claude-agent and codex (host-tools.ts), and the MCP gateway, which takes
|
|
5
5
|
// the same park (harness-app.ts) and registers an executor for its approved calls.
|
|
6
6
|
//
|
|
7
|
+
// An MCP tool's setting may also carry a pin (pinRefusal): top-level arguments its calls must carry, each a JSON scalar
|
|
8
|
+
// or one of a list. A pin adds to a setting and is never a permission: the gate checks it after a deny and before an
|
|
9
|
+
// allow or an ask, so an allowed call not as pinned is refused unsent, and one under ask is refused before anyone is
|
|
10
|
+
// asked; an approved call is checked again before it runs. The agent's pin and the server's both hold.
|
|
11
|
+
//
|
|
7
12
|
// An ask has one way to wait, every tool's alike (the owner's ruling of 11-04): it PARKS. The gated call answers at once
|
|
8
13
|
// with waitingText and the turn ends, as ask_person's does; the run goes needs_input with the pending approval. On an
|
|
9
14
|
// answer the gate runs the approved call itself (exactly once, through the journaled path: the kernel's host tool; an
|
|
@@ -32,18 +37,24 @@
|
|
|
32
37
|
// - A stop that lands between the read after the call and resume()'s commit can start the resume turn on a stopped
|
|
33
38
|
// run: a stop, unlike a cancel, leaves no mark the resume is held to.
|
|
34
39
|
import { createHash } from "node:crypto";
|
|
35
|
-
import { readFileSync } from "node:fs";
|
|
36
|
-
import { join
|
|
40
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
41
|
+
import { join } from "node:path";
|
|
37
42
|
import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works/pi-durable";
|
|
38
|
-
import { EffectFailure, INTERRUPTED_TEXT, openDrive } from "@parcha/agentrun-kernel/kernel";
|
|
43
|
+
import { DESKTOP_TOOL_DEFS, EffectFailure, INTERRUPTED_TEXT, openDrive, PHONE_TOOL_DEFS } from "@parcha/agentrun-kernel/kernel";
|
|
39
44
|
import { boundResult } from "@parcha/agentrun-kernel/process";
|
|
40
|
-
import {
|
|
45
|
+
import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
|
|
46
|
+
import { BARRIER, MESSAGE_ORIGIN_KIND, syncNow } from "@parcha/pi-durable-disk";
|
|
47
|
+
import { dataOfRun, readJson, RUN_META } from "./files.js";
|
|
41
48
|
import { LEARNED_DIR } from "./learning.js";
|
|
42
|
-
import {
|
|
49
|
+
import { COMPUTER_ROOT, portPath } from "./workspace/paths.js";
|
|
43
50
|
import { forModel } from "./result.js";
|
|
51
|
+
import { builtinHarness } from "./harness-table.js";
|
|
52
|
+
import { DEFAULT_HARNESS } from "./harness.js";
|
|
44
53
|
import { durableSessions } from "./sessions.js";
|
|
45
54
|
import { SHELL_TOOLS } from "./background.js";
|
|
46
|
-
import {
|
|
55
|
+
import { readToolSettings, SERVE_OWN_TOOLS, TABLE_TOOLS } from "./tool-plane.js";
|
|
56
|
+
import { deniedText, modelNodeAskText, NOT_RUN, RAN_UNKNOWN, refusedText } from "./refusal-words.js";
|
|
57
|
+
import { approvalsOf } from "./approvals.js";
|
|
47
58
|
/** What the gate does with a tool's calls. */
|
|
48
59
|
export const PERMISSIONS = ["allow", "ask", "deny"];
|
|
49
60
|
/** An MCP tool's gate name: `mcp:<server>/<tool>`. */
|
|
@@ -60,7 +71,7 @@ export const defaultPermission = (name) => (isCatalogTool(name) ? "ask" : "allow
|
|
|
60
71
|
export const SHELL_FAMILY = Object.freeze(Object.fromEntries(SHELL_TOOLS.map((name) => [name, "bash"])));
|
|
61
72
|
/** The shell tool a call named `name` is, under claude-agent's host-tool name too (`mcp__hands__bash_background`), when
|
|
62
73
|
* it is one held to another's setting: its own name, which its request, its refusal and its approved call keep. */
|
|
63
|
-
const shellToolOf = (name) => {
|
|
74
|
+
export const shellToolOf = (name) => {
|
|
64
75
|
const own = name.replace(/^mcp__hands__/, "");
|
|
65
76
|
return Object.hasOwn(SHELL_FAMILY, own) && SHELL_FAMILY[own] !== own ? own : undefined;
|
|
66
77
|
};
|
|
@@ -80,31 +91,47 @@ export function permissionKeys(name) {
|
|
|
80
91
|
/** The browser's registrations on pi (pi-browser's BROWSER_TOOL_NAMES, which a test holds this list to): each is a call
|
|
81
92
|
* of the table's `browser`. */
|
|
82
93
|
const BROWSER_REGISTRATIONS = ["snapshot", "run", "screenshot", "browser_read", "browser_release", "browser_relaunch", "browser_request_handoff", "browser_downloads", "browser_upload"];
|
|
83
|
-
/** A
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
/** A computer kind's tools, by name, to the one settings key their kind is held to (`desktop`, `phone`): the kernel
|
|
95
|
+
* registry's own definitions say it (their settingsKey), so a tool a kind gains is held to its key with no line here. */
|
|
96
|
+
const KIND_TOOLS = (() => {
|
|
97
|
+
const keys = new Map();
|
|
98
|
+
for (const def of [...DESKTOP_TOOL_DEFS, ...PHONE_TOOL_DEFS])
|
|
99
|
+
keys.set(def.name, [...new Set([...(keys.get(def.name) ?? []), def.settingsKey])]);
|
|
100
|
+
return keys;
|
|
101
|
+
})();
|
|
102
|
+
const STRICTNESS = { allow: 0, ask: 1, deny: 2 };
|
|
88
103
|
/** The MCP server through which claude-agent calls the kernel's host tools (`mcp__hands__<wire name>`). */
|
|
89
104
|
const HOST_TOOLS_SERVER = "hands";
|
|
90
105
|
/** The settings key a call named `name` on `harness` is held to: the one mapping from every name a call reaches the gate
|
|
91
106
|
* by. A settings key is itself (a table tool, `monid.<tool>`, `mcp:<server>/<tool>`); a CLI's own tool is the table's it
|
|
92
107
|
* is; an MCP alias, `mcp__<server>__<tool>` (claude-agent's host tools `mcp__hands__<wire name>`, mapped as their
|
|
93
|
-
* wire name) and
|
|
94
|
-
* catalog name; the browser's registrations are `browser
|
|
108
|
+
* wire name) and a harness's own (its facts' toolAlias: OpenCode's `<server>_<tool>`), is `mcp:<server>/<tool>`; a catalog's wire name (`monid_run`) is its
|
|
109
|
+
* catalog name; the browser's registrations are `browser`; an adapter's read_skill_file is `read` (but an agent's MCP tool of that name is its own). OpenCode's `<server>_<tool>` maps only for a server of
|
|
95
110
|
* `mcpServers` (the run's configured MCP servers), never by its shape, since a host tool's name has the same shape.
|
|
96
111
|
* Undefined: nothing maps it, and the gate asks. The key only: an MCP call enters the gate once, in the MCP gateway for a
|
|
97
112
|
* registration it marks (GATED_BY_GATEWAY), else where its tool is wrapped. */
|
|
98
113
|
export function settingsKeyOf(harness, name, mcpServers = []) {
|
|
99
|
-
// A
|
|
100
|
-
// and a tool that runs a command in the box (bash_background and the rest) to bash's: before the table's own names.
|
|
101
|
-
if (Object.hasOwn(LEGACY_NAMES, name))
|
|
102
|
-
return LEGACY_NAMES[name];
|
|
114
|
+
// A tool that runs a command in the box (bash_background and the rest) is held to bash's key: before the table's own names.
|
|
103
115
|
if (Object.hasOwn(SHELL_FAMILY, name))
|
|
104
116
|
return SHELL_FAMILY[name];
|
|
105
117
|
if (TABLE_TOOLS.includes(name) || SERVE_OWN_TOOLS.includes(name) || isCatalogTool(name))
|
|
106
118
|
return name;
|
|
107
|
-
|
|
119
|
+
// An adapter's own read of a skill's file (codex's and OpenCode's read_skill_file, from the session's copy of the run's
|
|
120
|
+
// skills) is a read: held to read's key, so a server's read deny refuses it and the default allows it, on every harness.
|
|
121
|
+
// Unless the name is an agent's MCP tool on this harness (OpenCode's <server>_<tool>: a configured server `read` with a
|
|
122
|
+
// tool `skill_file`): that tool keeps its own key, so read's setting never stands in for it.
|
|
123
|
+
if (name === READ_SKILL_FILE) {
|
|
124
|
+
const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
|
|
125
|
+
return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : "read";
|
|
126
|
+
}
|
|
127
|
+
// A desktop's or a phone's tool is its kind's key, as the browser's registrations are `browser`; one both kinds have
|
|
128
|
+
// (the hand-over) is named by the first, its permission the stricter of both (RunGate's setting).
|
|
129
|
+
const kind = KIND_TOOLS.get(name);
|
|
130
|
+
if (kind !== undefined)
|
|
131
|
+
return kind[0];
|
|
132
|
+
// A CLI's own tool, the table's tool it is (its facts' nativeTools), by an own name only.
|
|
133
|
+
const nativeTools = builtinHarness(harness)?.facts?.nativeTools;
|
|
134
|
+
const native = nativeTools && Object.hasOwn(nativeTools, name) ? nativeTools[name] : undefined;
|
|
108
135
|
if (native)
|
|
109
136
|
return native;
|
|
110
137
|
const mcp = /^mcp__([a-z][a-z0-9-]*)__(.+)$/.exec(name);
|
|
@@ -115,13 +142,109 @@ export function settingsKeyOf(harness, name, mcpServers = []) {
|
|
|
115
142
|
return `monid.${monid[1]}`;
|
|
116
143
|
if (BROWSER_REGISTRATIONS.includes(name))
|
|
117
144
|
return "browser";
|
|
118
|
-
|
|
145
|
+
// A harness whose client names a session's MCP tool another way too (its facts' toolAlias: OpenCode's `<server>_<tool>`).
|
|
146
|
+
const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
|
|
119
147
|
return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : undefined;
|
|
120
148
|
}
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
149
|
+
/** The most arguments one setting pins, and the most values a one-of list holds. */
|
|
150
|
+
export const MAX_PIN_ARGS = 8;
|
|
151
|
+
export const MAX_PIN_CHOICES = 16;
|
|
152
|
+
/** A one-of list in its one form: each value once, null first, then by its JSON text; any other value as it is. The
|
|
153
|
+
* same meaning is the same text (a revision's id) and the same words (a refusal). */
|
|
154
|
+
export const canonicalChoices = (value) => {
|
|
155
|
+
if (!Array.isArray(value))
|
|
156
|
+
return value;
|
|
157
|
+
const texts = [...new Set(value.filter((one) => one !== null).map((one) => JSON.stringify(one)))].sort();
|
|
158
|
+
return [...(value.includes(null) ? [null] : []), ...texts.map((text) => JSON.parse(text))];
|
|
159
|
+
};
|
|
160
|
+
/** `pin` in its one form: its arguments sorted, each one-of list in its form (canonicalChoices). */
|
|
161
|
+
export const canonicalPin = (pin) => Object.fromEntries(Object.keys(pin).sort().map((arg) => [arg, canonicalChoices(pin[arg])]));
|
|
162
|
+
/** Whether a call's argument `given` is the pinned scalar `one`: the same JSON scalar (strict equality), or, for null,
|
|
163
|
+
* left out or null. */
|
|
164
|
+
const isOne = (given, one) => (one === null ? given === undefined || given === null : given === one);
|
|
165
|
+
/** Whether `given` holds pinned `value`: its scalar, or one of its list. */
|
|
166
|
+
const holds = (given, value) => (Array.isArray(value) ? value.some((one) => isOne(given, one)) : isOne(given, value));
|
|
167
|
+
/** A scalar in a refusal's words: text as it is, null as `absent`, any other as JSON. */
|
|
168
|
+
const scalarWords = (one) => (one === null ? "absent" : typeof one === "string" ? one : JSON.stringify(one));
|
|
169
|
+
/** A pin in words, as the refusal says it, in its one form (canonicalPin): `channel_id = C0123`, `cc absent` for a null,
|
|
170
|
+
* `event in (absent | COMMENT)` for a list. */
|
|
171
|
+
export const pinWords = (pin) => Object.entries(canonicalPin(pin)).map(([arg, value]) => (Array.isArray(value) ? `${arg} in (${value.map(scalarWords).join(" | ")})` : value === null ? `${arg} absent` : `${arg} = ${scalarWords(value)}`)).join(", ");
|
|
172
|
+
/** What holds both of two layers' pins of one argument (`own`, the agent's, and `theirs`, the server's): a scalar where
|
|
173
|
+
* either is one and the other holds it, else the agent's list kept to the server's, in the agent's order; undefined when
|
|
174
|
+
* nothing holds both. */
|
|
175
|
+
function bothOf(own, theirs) {
|
|
176
|
+
const list = (value) => (Array.isArray(value) ? value : [value]);
|
|
177
|
+
if (!Array.isArray(own))
|
|
178
|
+
return list(theirs).some((one) => one === own) ? own : undefined;
|
|
179
|
+
if (!Array.isArray(theirs))
|
|
180
|
+
return own.some((one) => one === theirs) ? theirs : undefined;
|
|
181
|
+
const kept = own.filter((one) => theirs.some((other) => other === one));
|
|
182
|
+
return kept.length ? kept : undefined;
|
|
183
|
+
}
|
|
184
|
+
/** Why the call of MCP tool `name` with `args` is refused by a pin, or undefined when no pin refuses it. A pin is an
|
|
185
|
+
* addition to a setting, never a permission: each layer's pin on the tool's own key holds (the agent's and the
|
|
186
|
+
* server's both, whatever the permission), and a call must carry every pinned argument as pinned: its value, or one of
|
|
187
|
+
* its list. An argument both layers pin takes what holds both; where nothing does, every call is refused. `ran`: whether an earlier attempt of
|
|
188
|
+
* the call may have been sent (deniedText's). `mismatched`: the arguments that do not hold, for the gate's log line. */
|
|
189
|
+
export function pinRefusal(name, args, server, agent = {}, ran = "no") {
|
|
190
|
+
if (!isMcpTool(name))
|
|
191
|
+
return undefined;
|
|
192
|
+
const what = ran === "no" ? NOT_RUN : RAN_UNKNOWN;
|
|
193
|
+
if (server[name]?.brokenPin)
|
|
194
|
+
return { text: `${name} can't be called: its pin in this server's tool settings does not read, so no call is let through until the owner sets it again (Settings → Tools). ${what}`, mismatched: [] };
|
|
195
|
+
const own = agent[name]?.pin ?? {};
|
|
196
|
+
const theirs = server[name]?.pin ?? {};
|
|
197
|
+
// Both layers hold: an argument both pin takes what holds both (bothOf), and one where nothing does refuses every call.
|
|
198
|
+
const clash = Object.keys(own).filter((arg) => Object.hasOwn(theirs, arg) && bothOf(own[arg], theirs[arg]) === undefined);
|
|
199
|
+
if (clash.length)
|
|
200
|
+
return { text: `${name} can't be called: this agent's settings fix ${pinWords(Object.fromEntries(clash.map((arg) => [arg, own[arg]])))} and this server's fix ${pinWords(Object.fromEntries(clash.map((arg) => [arg, theirs[arg]])))}, so no call can satisfy both. ${what} Don't retry it: the owner makes the two agree.`, mismatched: clash };
|
|
201
|
+
const pin = { ...theirs, ...Object.fromEntries(Object.entries(own).map(([arg, value]) => [arg, Object.hasOwn(theirs, arg) ? bothOf(value, theirs[arg]) : value])) };
|
|
202
|
+
const given = typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
|
|
203
|
+
const mismatched = Object.keys(pin).filter((arg) => !holds(Object.hasOwn(given, arg) ? given[arg] : undefined, pin[arg]));
|
|
204
|
+
if (!mismatched.length)
|
|
205
|
+
return undefined;
|
|
206
|
+
const by = Object.keys(own).length && Object.keys(theirs).length ? "the agent's and this server's settings" : Object.keys(own).length ? "the agent's settings" : "this server's settings";
|
|
207
|
+
return { text: `${name} may only be called with ${pinWords(pin)}: its destination is fixed by ${by}. ${what}`, mismatched };
|
|
208
|
+
}
|
|
209
|
+
/** `name`'s permission in force and the layer it came from. A deny set on this server, under the tool's own key or its MCP
|
|
210
|
+
* server's wildcard (bash's for a shell tool), is absolute: it refuses on this server over any setting of the agent's.
|
|
211
|
+
* Otherwise most specific first: the agent's exact key, the agent's server wildcard, the server's exact key, the
|
|
212
|
+
* server's server wildcard, then the default. A call's arguments are held only by a pin (pinRefusal), which adds to a
|
|
213
|
+
* setting and is never a permission. `approvals` "never" (an agent run unattended) turns the ask that is left into an allow, from
|
|
214
|
+
* "unattended", as the last step, and only where nothing stands behind that ask (standsBehind): never past a deny in any
|
|
215
|
+
* layer, nor an ask that stands in for a setting that does not read. Nor is anything RunGate.enter refuses before it
|
|
216
|
+
* decides between running and parking ever lifted (a template's pin, among them). Without never, the answer is as it
|
|
217
|
+
* always was. */
|
|
218
|
+
export function permissionFrom(name, server, agent = {}, approvals = "ask") {
|
|
219
|
+
const { permission, from } = settingOf(name, server, agent);
|
|
220
|
+
if (approvals !== "never" || permission !== "ask" || standsBehind(name, server, agent))
|
|
221
|
+
return { permission, from };
|
|
222
|
+
return { permission: "allow", from: "unattended" };
|
|
223
|
+
}
|
|
224
|
+
/** Marks the server's settings map when its file is present but does not read (tool-plane.ts ToolSettings.get): every
|
|
225
|
+
* tool then takes its defaults, and the deny the file may hold can't be seen, so nothing lifts an ask over it. A symbol:
|
|
226
|
+
* carried by a spread, never by JSON (it is never served) nor by Object.entries (no reader takes it for a tool). */
|
|
227
|
+
export const SETTINGS_UNREAD = Symbol("agentrun.tool-settings.unread");
|
|
228
|
+
/** `settings` marked unread (SETTINGS_UNREAD), a copy: what a gate holds to while its settings' read fails, its last good
|
|
229
|
+
* read's denies and pins still refusing and no ask lifted. */
|
|
230
|
+
const unreadOf = (settings) => Object.assign({ ...settings }, { [SETTINGS_UNREAD]: true });
|
|
231
|
+
/** Whether something stands behind `name`'s ask that approvals "never" must not lift: the server's settings unread
|
|
232
|
+
* (SETTINGS_UNREAD: a deny may be in the file), or in either layer, under any key the tool is read by (its own, its MCP
|
|
233
|
+
* server's wildcard; a shell tool's, bash's), a deny, a value that is no permission, or a setting marked as not read as
|
|
234
|
+
* written (`fallback`). The ask a layer above gives does not hide a deny below it. */
|
|
235
|
+
function standsBehind(name, server, agent) {
|
|
236
|
+
if (server[SETTINGS_UNREAD] === true)
|
|
237
|
+
return true;
|
|
238
|
+
const held = Object.hasOwn(SHELL_FAMILY, name) ? SHELL_FAMILY[name] : name;
|
|
239
|
+
return [agent, server].some((layer) => permissionKeys(held).some((key) => {
|
|
240
|
+
const setting = layer[key];
|
|
241
|
+
if (setting?.permission === undefined)
|
|
242
|
+
return false;
|
|
243
|
+
return setting.permission === "deny" || setting.fallback === true || !PERMISSIONS.includes(setting.permission);
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
/** permissionFrom before approvals: what the layers and the default say. */
|
|
247
|
+
function settingOf(name, server, agent) {
|
|
125
248
|
// A shell tool's permission is bash's (SHELL_FAMILY), from bash's layer, wherever it is read: the gate, capabilities, an
|
|
126
249
|
// agent's tools. A watcher (SHELL_WATCHERS) runs unasked only under an ask set as written in a layer: an ask that stands
|
|
127
250
|
// in for anything else (a value not offered, nothing set) stays an ask. No key of its own is read, so none lifts bash's.
|
|
@@ -133,8 +256,15 @@ export function permissionFrom(name, server, agent = {}) {
|
|
|
133
256
|
return { permission, from };
|
|
134
257
|
}
|
|
135
258
|
/** permissionFrom's own read, and whether the permission is `written`: a valid one set in a layer as it reads there, not
|
|
136
|
-
* a stand-in. A value that is no permission at all reads ask, never the value.
|
|
259
|
+
* a stand-in. A value that is no permission at all reads ask, never the value. A deny set on this server is absolute:
|
|
260
|
+
* where the server's own answer for the tool (its most specific key set there: the tool's own, else its MCP server's
|
|
261
|
+
* wildcard) is deny, that is the answer, from the server, before the agent's own settings are read, so no ask or allow
|
|
262
|
+
* of the agent's reaches past it. The server's own exact allow under its wildcard deny is its answer, as before.
|
|
263
|
+
* Otherwise the agent's own setting comes first, then the server's, then the default. */
|
|
137
264
|
function settingFrom(name, server, agent) {
|
|
265
|
+
const own = permissionKeys(name).map((key) => server[key]).find((setting) => setting?.permission !== undefined);
|
|
266
|
+
if (own?.permission === "deny")
|
|
267
|
+
return { permission: "deny", from: "server", written: own.fallback !== true };
|
|
138
268
|
for (const [from, layer] of [["agent", agent], ["server", server]]) {
|
|
139
269
|
for (const key of permissionKeys(name)) {
|
|
140
270
|
const setting = layer[key];
|
|
@@ -150,22 +280,21 @@ function settingFrom(name, server, agent) {
|
|
|
150
280
|
}
|
|
151
281
|
/** `name`'s permission in force (permissionFrom): the one rule every path reads, the gate's, the tool plane's and a
|
|
152
282
|
* workflow's call nodes'. */
|
|
153
|
-
export const permissionOf = (name, server, agent = {}) => permissionFrom(name, server, agent).permission;
|
|
283
|
+
export const permissionOf = (name, server, agent = {}, approvals = "ask") => permissionFrom(name, server, agent, approvals).permission;
|
|
154
284
|
/** The mark a tool registration carries when its calls are gated by whoever registered it (the MCP gateway, which marks
|
|
155
285
|
* its registrations only when it holds this run's gate and park, and enters the gate in each call): RunGate.extension
|
|
156
|
-
* does not wrap it again. `Symbol.for
|
|
157
|
-
export
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
286
|
+
* does not wrap it again. A private symbol, never `Symbol.for`: a global-registry key could be recreated by any code
|
|
287
|
+
* with the string alone. Only code that imports this export can set it (mcp-gateway.ts does). */
|
|
288
|
+
export const GATED_BY_GATEWAY = Symbol("agentrun.gatedByGateway");
|
|
289
|
+
// The refusal words (SettingFrom, DenyFrom, NOT_RUN, RAN_UNKNOWN, denyPlace, deniedText, refusedText) live in
|
|
290
|
+
// refusal-words.ts, shared with the runner's loops.
|
|
291
|
+
export { deniedText, denyPlace, NOT_RUN, RAN_UNKNOWN, refusedText } from "./refusal-words.js";
|
|
161
292
|
/** The refusal of an ask where no one can approve it: a server with accounts off, whose answer route takes no token. */
|
|
162
|
-
export const noApproverText = (tool) => `Permission denied: ${tool} needs the owner's approval, and this server has accounts off (AGENTRUN_ACCOUNTS=0), so no one can give it: set the tool to allow or deny in the agent's Tools
|
|
293
|
+
export const noApproverText = (tool, ran = "no") => `Permission denied: ${tool} needs the owner's approval, and this server has accounts off (AGENTRUN_ACCOUNTS=0), so no one can give it: set the tool to allow or deny in the agent's Tools. ${ran === "no" ? NOT_RUN : RAN_UNKNOWN}`;
|
|
163
294
|
/** Set by the server in a run's environment when no one can approve here (accounts off): the gate refuses each ask. */
|
|
164
295
|
export const NO_APPROVER_ENV = "AGENTRUN_SERVE_NO_APPROVER";
|
|
165
296
|
/** A parked call's answer: the run pauses here. */
|
|
166
297
|
export const waitingText = (tool) => `This ${tool} call waits for a person's approval; the run pauses here and continues with the result when they answer.`;
|
|
167
|
-
/** A call a person denied, with their reason when they gave one. */
|
|
168
|
-
export const refusedText = (tool, note) => `The user denied this ${tool} call.${note ? ` Reason: ${note}` : ""}`;
|
|
169
298
|
/** The Timeline row of a call that waits for an approval. */
|
|
170
299
|
export const APPROVAL_ROW = "tool_approval_requested";
|
|
171
300
|
/** A call's arguments shown on its approval, at most this many bytes. */
|
|
@@ -199,18 +328,27 @@ export const TURN_ORIGIN_FILE = "turn-origin.json";
|
|
|
199
328
|
/** The run's store's record of a call that waits for approval (`phase: "requested"`), and of its answer acted on
|
|
200
329
|
* (`phase: "resolved"`), on its root conversation. */
|
|
201
330
|
export const APPROVAL_ENTRY = "agentrun.tool_approval";
|
|
331
|
+
/** The run's store's record that the gate let a replay-safe pi call that can bill through (`{ callId }`), written before
|
|
332
|
+
* the tool runs. pi-durable reruns a cut replay-safe call with the same call id and no sign that it is a rerun: this mark
|
|
333
|
+
* is how the gate knows an earlier attempt may have been sent, so a deny of the rerun never says nothing was charged.
|
|
334
|
+
* Outside `agentrun.tool_`, the tool ledger's kinds (paid-calls.ts), which readers of a run's charges take by prefix. */
|
|
335
|
+
export const GATE_PASSED_ENTRY = "agentrun.gate_passed";
|
|
336
|
+
/** The replay-safe tools, by settings key, whose call can be charged (a provider's fee: Parallel's search or extract): the
|
|
337
|
+
* only ones the gate marks, so the root conversation does not grow by a mark per free call (read, the shell watchers,
|
|
338
|
+
* monid's discover and inspect), whose earlier attempt charged nothing. monid.run is never rerun (host-tools.ts REPLAY). */
|
|
339
|
+
const BILLED_REPLAYS = new Set(["web_fetch", "web_search"]);
|
|
202
340
|
/** The refusal of the end-of-run turn's write or edit under work/.learning/: its notes are kept only from its answer's
|
|
203
341
|
* note blocks (learn/reflect.ts parseReflection), which the host merges in its own store; a file there is never kept. */
|
|
204
342
|
export const NOTE_ONLY_TEXT = "A note is kept only from your answer: write it in a ```note block, not to a file.";
|
|
205
|
-
/** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then
|
|
206
|
-
* names
|
|
343
|
+
/** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then the port's
|
|
344
|
+
* path of it, portPath), names .learning/ in the run's folder or a path under it: by the folder's path here (`work`)
|
|
345
|
+
* or a computer's name for it (COMPUTER_ROOT). */
|
|
207
346
|
export function underLearning(work, args) {
|
|
208
347
|
const path = args?.path;
|
|
209
348
|
if (typeof path !== "string")
|
|
210
349
|
return false;
|
|
211
350
|
const plain = path.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
|
|
212
|
-
|
|
213
|
-
return under(resolve(work), resolve(work, plain)) || under(BOX_WORK, posix.resolve(BOX_WORK, plain));
|
|
351
|
+
return portPath(plain, [work, COMPUTER_ROOT])?.split("/")[0] === LEARNED_DIR;
|
|
214
352
|
}
|
|
215
353
|
/** `text` cut to at most ARGS_PREVIEW_BYTES. What is shown of a call's arguments is the whole of them redacted first, then
|
|
216
354
|
* cut (runs.ts), so a cut never leaves the head of a key no redaction recognizes. */
|
|
@@ -224,16 +362,25 @@ export const argsPreview = (args) => previewOf(JSON.stringify(args ?? {}) ?? "")
|
|
|
224
362
|
export const RESUME_PREFIX = "[tool approval] ";
|
|
225
363
|
/** The one message that resumes a session once a person answered: it names the call it answers (its tool, call id and
|
|
226
364
|
* arguments), so the model tells it from a person's new input, and carries the call's result, or the refusal. */
|
|
227
|
-
|
|
228
|
-
|
|
365
|
+
/** The head of the gate's resume message: the call it answers, its arguments as shown (`shown`, redacted whole then cut,
|
|
366
|
+
* runs.ts) cut again at 300 characters, and the words that say it is not the person's. The one source of it: the resume
|
|
367
|
+
* writes it, and the Timeline strips exactly it from the row a person opens (runs.ts resumeShows). */
|
|
368
|
+
export function resumeHead(request, shown) {
|
|
229
369
|
const args = shown.length > 300 ? `${shown.slice(0, 299)}…` : shown;
|
|
230
|
-
|
|
370
|
+
return `${RESUME_PREFIX}This answers your ${request.tool} call ${request.call_id} (arguments ${args}), which waited for a person's approval; it is not a new message from them.`;
|
|
371
|
+
}
|
|
372
|
+
export function resumeText(request, shown, decision, result) {
|
|
373
|
+
const head = resumeHead(request, shown);
|
|
231
374
|
return decision === "allow" ? `${head} They allowed it, and it ran${result.isError ? " and failed" : ""}. Its result:\n${result.text}` : `${head}\n${result.text}`;
|
|
232
375
|
}
|
|
233
376
|
/** The gate of the run `runId` at `where` (its directory, under the data directory's runs/), on its pinned revision:
|
|
234
|
-
* an agentic run's parks an asked call; a workflow's model node cannot.
|
|
235
|
-
|
|
236
|
-
|
|
377
|
+
* an agentic run's parks an asked call; a workflow's model node cannot. `serverSettings`: where the server's tool
|
|
378
|
+
* settings are read from, read at each call as the gate reads them; absent, the file beside the run's data directory (the
|
|
379
|
+
* old per-run process). The runner gives the one store's (tool-plane.ts loadToolSettings), read once at the claim.
|
|
380
|
+
* `approvers`: whether anyone can answer an ask here. The runner gives the store's (server-approvers.ts, read at each
|
|
381
|
+
* claim); absent, the old per-run process's environment says (NO_APPROVER_ENV, set for it by runs.ts). */
|
|
382
|
+
export function runGate(where, runId, revision, serverSettings, files, approvers = process.env[NO_APPROVER_ENV] !== "1") {
|
|
383
|
+
return new RunGate({ root: where.root, work: where.work, data: dataOfRun(where.root), runId, harness: revision.body.harness ?? DEFAULT_HARNESS }, (revision.body.toolSettings ?? {}), revision.kind === "agentic", approvers, approvalsOf(revision.body.approvals), serverSettings, files);
|
|
237
384
|
}
|
|
238
385
|
/** The gate in a run's process, park mode: its policy, the turn's origin, the calls that wait, and the answers acted on. */
|
|
239
386
|
export class RunGate {
|
|
@@ -241,48 +388,114 @@ export class RunGate {
|
|
|
241
388
|
overrides;
|
|
242
389
|
parks;
|
|
243
390
|
approvers;
|
|
391
|
+
approvals;
|
|
392
|
+
readServerSettings;
|
|
393
|
+
files;
|
|
244
394
|
requests = new Map();
|
|
395
|
+
/** The replay-safe pi calls the gate let through (GATE_PASSED_ENTRY), by call id: a rerun of one is a replay. */
|
|
396
|
+
passed = new Set();
|
|
245
397
|
durable;
|
|
398
|
+
/** The run's store, for the barrier before a call that is not replay-safe: from `prime` (before the resume) or `load`. */
|
|
399
|
+
syncTarget;
|
|
246
400
|
context;
|
|
247
401
|
coding;
|
|
248
402
|
/** The run's own tools beyond the table (its learned_workflow), on which an approved call of one runs. */
|
|
249
403
|
extra = [];
|
|
250
404
|
resume;
|
|
405
|
+
/** Told just before an allowed call runs (harness-app's): the run is un-parked, so the call's own model requests (a
|
|
406
|
+
* learned workflow's node) go out; the harness is idle then, as the park ended its turn. */
|
|
407
|
+
unpark;
|
|
251
408
|
drive;
|
|
252
409
|
timer;
|
|
253
410
|
settling = false;
|
|
254
411
|
stop = new AbortController();
|
|
255
412
|
/** `where.data`: the server's data directory, its tool settings beside the store; `overrides`: the pinned revision's
|
|
256
413
|
* own; `parks`: whether an asked call parks the run (an agentic run's), which a workflow's model node cannot;
|
|
257
|
-
* `approvers`: whether anyone can answer an ask here (the owner's password session: accounts on)
|
|
258
|
-
|
|
414
|
+
* `approvers`: whether anyone can answer an ask here (the owner's password session: accounts on); `approvals`: the
|
|
415
|
+
* pinned revision's (definition.approvals): "never" runs the agent unattended, an ask allowed (permissionFrom);
|
|
416
|
+
* `files`: where the run's own files are read (RunFiles), the run's folder `where.root` when absent. */
|
|
417
|
+
constructor(where, overrides = {}, parks = true, approvers = true, approvals = "ask", readServerSettings, files = where.root) {
|
|
259
418
|
this.where = where;
|
|
260
419
|
this.overrides = overrides;
|
|
261
420
|
this.parks = parks;
|
|
262
421
|
this.approvers = approvers;
|
|
422
|
+
this.approvals = approvals;
|
|
423
|
+
this.readServerSettings = readServerSettings;
|
|
424
|
+
this.files = files;
|
|
263
425
|
}
|
|
264
426
|
/** A tool's permission now (permissionOf): the revision's own over the server's setting, read at each call, so a change
|
|
265
|
-
* reaches a live run at its next call. */
|
|
266
|
-
policy = (tool) =>
|
|
267
|
-
|
|
268
|
-
|
|
427
|
+
* reaches a live run at its next call; under approvals "never", an ask is an allow. */
|
|
428
|
+
policy = (tool) => this.setting(tool).permission;
|
|
429
|
+
/** The gate's answer for one call before its intent, for a loop that parks and answers asks itself (the runner's adapter
|
|
430
|
+
* loops, pi's and the CLI harnesses'): run it, ask a person, or refuse it with the words the model reads. `enter`'s
|
|
431
|
+
* order: the end-of-run turn's write under .learning/ (learningRefusal), the deny (with where it was set, and that
|
|
432
|
+
* nothing was sent or charged), a pin, then the allow, then the ask, so an allow that approvals "never" made is decided
|
|
433
|
+
* only after every refusal. Where no one can approve (accounts off: the store's approvers row a runner reads at each
|
|
434
|
+
* claim, server-approvers.ts), the ask is refused at once in words, never parked, as `enter` refuses it. */
|
|
435
|
+
async decide(name, args) {
|
|
436
|
+
const key = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
|
|
437
|
+
const tool = this.askedAs(name);
|
|
438
|
+
const learning = await this.learningRefusal(key, args);
|
|
439
|
+
if (learning)
|
|
440
|
+
return { deny: learning };
|
|
441
|
+
const verdict = this.policy(name);
|
|
442
|
+
if (verdict === "deny")
|
|
443
|
+
return { deny: deniedText(tool, key, this.denyFrom(name), "no") };
|
|
444
|
+
const pinned = this.pinned(key, args, "no");
|
|
445
|
+
if (pinned)
|
|
446
|
+
return { deny: pinned.text };
|
|
447
|
+
if (verdict === "allow")
|
|
448
|
+
return "allow";
|
|
449
|
+
return this.approvers ? "ask" : { deny: noApproverText(tool, "no") };
|
|
450
|
+
}
|
|
451
|
+
/** The name a call is asked about by, as main's request names it (enter's `tool`): its settings key, a shell tool its
|
|
452
|
+
* own name; a name nothing maps, as it came. */
|
|
453
|
+
askedAs(name) {
|
|
454
|
+
return shellToolOf(name) ?? settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
|
|
455
|
+
}
|
|
456
|
+
/** Where the permission `policy` gives `tool` was set: the agent's own tool settings, the server's, or the default; or
|
|
457
|
+
* "unattended", an ask the agent's approvals allowed. */
|
|
458
|
+
denyFrom = (tool) => this.setting(tool).from;
|
|
459
|
+
setting(tool) {
|
|
460
|
+
// A tool the desktop and the phone both have (the hand-over): the gate knows not the run's kind, so it is held to the
|
|
461
|
+
// stricter of both keys' settings, never more permissive than the run's own kind's.
|
|
462
|
+
const shared = KIND_TOOLS.get(tool.replace(/^mcp__hands__/, ""));
|
|
463
|
+
if (shared && shared.length > 1) {
|
|
464
|
+
return shared.map((key) => this.settingOf(tool, key)).reduce((strictest, one) => (STRICTNESS[one.permission] > STRICTNESS[strictest.permission] ? one : strictest));
|
|
465
|
+
}
|
|
466
|
+
return this.settingOf(tool, settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, tool, this.where.mcpServers));
|
|
467
|
+
}
|
|
468
|
+
/** `tool`'s permission under its settings key `key`, and where it was set. */
|
|
469
|
+
settingOf(tool, key) {
|
|
470
|
+
// A name nothing maps fails closed: it asks (refused where no one can approve), never allows, under approvals "never"
|
|
471
|
+
// too: no setting of it was read, so none says it may run.
|
|
269
472
|
if (key === undefined)
|
|
270
|
-
return "ask";
|
|
473
|
+
return { permission: "ask", from: "default" };
|
|
271
474
|
const server = this.serverSettings();
|
|
272
475
|
// No settings ever read: every tool asks, the shell watchers too (fail closed: an ask nothing read is never lifted),
|
|
273
|
-
// or keeps the revision's own deny.
|
|
274
|
-
|
|
275
|
-
|
|
476
|
+
// or keeps the revision's own deny. Approvals "never" lifts none of these asks: the server's settings may hold a deny
|
|
477
|
+
// no read has seen.
|
|
478
|
+
if (server === undefined) {
|
|
479
|
+
const own = permissionFrom(key, {}, this.overrides);
|
|
480
|
+
return own.permission === "deny" ? own : { permission: "ask", from: "default" };
|
|
481
|
+
}
|
|
276
482
|
// A shell tool under every harness's name for it is read as its own name, by bash's key (permissionFrom): a watcher's
|
|
277
483
|
// ask is allow only where bash's ask is set as written.
|
|
278
|
-
return
|
|
279
|
-
}
|
|
484
|
+
return permissionFrom(shellToolOf(tool) ?? key, server, this.overrides, this.approvals);
|
|
485
|
+
}
|
|
486
|
+
/** Why a pin refuses the call of `key` with `args` now (pinRefusal): the revision's own pins and the server's, read at
|
|
487
|
+
* each call as its permission is, so a pin set or changed reaches a live run at its next call. */
|
|
488
|
+
pinned(key, args, ran = "no") {
|
|
489
|
+
return pinRefusal(key, args, this.serverSettings() ?? {}, this.overrides, ran);
|
|
490
|
+
}
|
|
280
491
|
lastGood;
|
|
281
492
|
told = new Set();
|
|
282
|
-
/** The server's settings now: read at each call, so a change reaches a live run;
|
|
283
|
-
* last good (
|
|
493
|
+
/** The server's settings now: read at each call, so a change reaches a live run; settings that do not read keep the
|
|
494
|
+
* last good, marked unread (SETTINGS_UNREAD): its denies and pins still refuse, and approvals "never" lifts no ask
|
|
495
|
+
* while the read fails, as a deny may be in what did not read (undefined: none read yet, every tool asks). Each problem
|
|
496
|
+
* is said once, by file and field, never a value. */
|
|
284
497
|
serverSettings() {
|
|
285
|
-
const read = readToolSettings(this.where.data);
|
|
498
|
+
const read = this.readServerSettings ? this.readServerSettings() : readToolSettings(this.where.data);
|
|
286
499
|
for (const line of read.problems) {
|
|
287
500
|
if (this.told.has(line))
|
|
288
501
|
continue;
|
|
@@ -290,40 +503,65 @@ export class RunGate {
|
|
|
290
503
|
process.stderr.write(`agentrun-serve: the tool gate: ${line}\n`);
|
|
291
504
|
}
|
|
292
505
|
if (read.unreadable)
|
|
293
|
-
return this.lastGood;
|
|
506
|
+
return this.lastGood === undefined ? undefined : unreadOf(this.lastGood);
|
|
294
507
|
this.lastGood = read.settings;
|
|
295
508
|
return this.lastGood;
|
|
296
509
|
}
|
|
297
|
-
/** The origin of the turn running now: what the server's internal path wrote for it
|
|
298
|
-
|
|
510
|
+
/** The origin of the turn running now: what the server's internal path wrote for it (TURN_ORIGIN_FILE in the run's
|
|
511
|
+
* folder, read through `files`: the run's Workspace or the local folder's path); none for a person's turn, or a file
|
|
512
|
+
* that is not there or does not read. */
|
|
513
|
+
async turnOrigin() {
|
|
299
514
|
try {
|
|
300
|
-
|
|
515
|
+
const text = typeof this.files === "string" ? readFileSync(join(this.files, TURN_ORIGIN_FILE), "utf8") : new TextDecoder().decode(await this.files.read(TURN_ORIGIN_FILE));
|
|
516
|
+
return JSON.parse(text)?.origin === "reflect" ? "reflect" : undefined;
|
|
301
517
|
}
|
|
302
518
|
catch {
|
|
303
519
|
return undefined;
|
|
304
520
|
}
|
|
305
521
|
}
|
|
522
|
+
/** The end-of-run turn's refusal of a write or edit under work/.learning/ (NOTE_ONLY_TEXT, the adapter loop's one text
|
|
523
|
+
* too), whatever the tool's permission: its notes are kept only from its answer. Undefined for any other call or turn,
|
|
524
|
+
* whose write there follows its permission, as anywhere. The first check of `enter` and `decide`. */
|
|
525
|
+
async learningRefusal(key, args) {
|
|
526
|
+
if (key !== "write" && key !== "edit")
|
|
527
|
+
return undefined;
|
|
528
|
+
// The folder's path a file tool resolves against: the local folder's, or a computer's name for it (the Workspace's paths
|
|
529
|
+
// are in the run's folder, so a path there is relative or under COMPUTER_ROOT).
|
|
530
|
+
const work = typeof this.files === "string" ? this.where.work : COMPUTER_ROOT;
|
|
531
|
+
return underLearning(work, args) && (await this.turnOrigin()) === "reflect" ? NOTE_ONLY_TEXT : undefined;
|
|
532
|
+
}
|
|
306
533
|
/** One model-initiated call at the gate: undefined when it may run; else its answer, refused at once (deny) or parked
|
|
307
534
|
* (ask). One call waits at a time: another asked meanwhile is answered so, not run. */
|
|
308
535
|
async enter(name, args, callId, park, options = {}) {
|
|
309
536
|
// Held to its settings key (settingsKeyOf), the name its request, a refusal and the approved call give; a shell tool
|
|
310
537
|
// held to bash's (SHELL_FAMILY) keeps its own name, so an approved bash_background runs bash_background, never bash.
|
|
311
|
-
const key = settingsKeyOf(this.where.harness ??
|
|
538
|
+
const key = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
|
|
312
539
|
const tool = shellToolOf(name) ?? key;
|
|
313
|
-
// The end-of-run turn writes no file under work/.learning/, whatever the tool's permission
|
|
314
|
-
|
|
315
|
-
if (
|
|
316
|
-
return { text:
|
|
540
|
+
// The end-of-run turn writes no file under work/.learning/, whatever the tool's permission (learningRefusal).
|
|
541
|
+
const learning = await this.learningRefusal(key, args);
|
|
542
|
+
if (learning)
|
|
543
|
+
return { text: learning, isError: true };
|
|
544
|
+
// Every refusal that does not come from the permission (the reflect turn's above, the deny and a pin's below) stays
|
|
545
|
+
// ABOVE the allow's return further down. An allow here may be an ask the agent's approvals "never" turned into one
|
|
546
|
+
// (permissionFrom's last step), and an allowed call runs at once: nothing after that return refuses it.
|
|
317
547
|
const verdict = this.policy(name);
|
|
548
|
+
const ran = options.replayed ? "unknown" : "no";
|
|
549
|
+
if (verdict === "deny")
|
|
550
|
+
return { text: deniedText(tool, key, this.denyFrom(name), ran), isError: true };
|
|
551
|
+
// A pinned MCP tool's call whose arguments are not the pinned ones: refused before it runs or asks anyone, so an
|
|
552
|
+
// allowed or approved call goes only where its settings fix.
|
|
553
|
+
const pinned = this.pinned(key, args, ran);
|
|
554
|
+
if (pinned) {
|
|
555
|
+
process.stderr.write(`agentrun-serve: the tool gate refused ${key} call ${callId}: ${pinned.mismatched.length ? `${pinned.mismatched.join(", ")} not as pinned` : "its pin does not read"}\n`);
|
|
556
|
+
return { text: pinned.text, isError: true };
|
|
557
|
+
}
|
|
318
558
|
if (verdict === "allow")
|
|
319
559
|
return undefined;
|
|
320
|
-
if (verdict === "deny")
|
|
321
|
-
return { text: deniedText(tool, key), isError: true };
|
|
322
560
|
// No one can answer here: refused at once with why, never parked until a cancel.
|
|
323
561
|
if (!this.approvers)
|
|
324
|
-
return { text: noApproverText(tool), isError: true };
|
|
562
|
+
return { text: noApproverText(tool, ran), isError: true };
|
|
325
563
|
if (!this.parks)
|
|
326
|
-
return { text:
|
|
564
|
+
return { text: modelNodeAskText(tool), isError: true };
|
|
327
565
|
// Named by the call, so a call run again after a crash parks as the same request.
|
|
328
566
|
const id = `ap_${createHash("sha256").update(JSON.stringify([callId, tool, args ?? null])).digest("hex").slice(0, 16)}`;
|
|
329
567
|
const other = [...this.requests.values()].find((held) => !held.resolved && held.id !== id);
|
|
@@ -331,7 +569,7 @@ export class RunGate {
|
|
|
331
569
|
return { text: `This ${tool} call was not run: the ${other.tool} call ${other.call_id} already waits for a person's approval. Call it again once that one is answered.`, isError: true };
|
|
332
570
|
if (!this.requests.has(id)) {
|
|
333
571
|
const turn = park.turn?.();
|
|
334
|
-
const request = { id, tool, call_id: callId, args: args ?? null, args_preview: argsPreview(args), requested_at: new Date().toISOString(), ...(turn !== undefined ? { turn } : {}), ...(options.price !== undefined ? { price: options.price } : {}) };
|
|
572
|
+
const request = { id, tool, call_id: callId, args: args ?? null, args_preview: argsPreview(args), requested_at: new Date().toISOString(), ...(turn !== undefined ? { turn } : {}), ...(options.price !== undefined ? { price: options.price } : {}), ...(options.replayed ? { replayed: true } : {}) };
|
|
335
573
|
// Held before the commit's await, in the tick of the look above: pi runs a turn's calls in parallel, and an ask
|
|
336
574
|
// entered meanwhile finds this one and is refused. A commit that fails lets it go.
|
|
337
575
|
this.requests.set(id, request);
|
|
@@ -358,26 +596,53 @@ export class RunGate {
|
|
|
358
596
|
}
|
|
359
597
|
wrap(tool) {
|
|
360
598
|
const gate = this;
|
|
599
|
+
const billed = tool.replay === "safe" && BILLED_REPLAYS.has(settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, tool.name, this.where.mcpServers) ?? "");
|
|
361
600
|
return {
|
|
362
601
|
...tool,
|
|
363
602
|
async execute(args, api, context) {
|
|
364
|
-
const
|
|
603
|
+
const commit = (change) => api.commit(change, context);
|
|
604
|
+
// A rerun of a replay-safe call the gate let through before (pi-durable reruns it with the same call id after a
|
|
605
|
+
// crash, with no sign of it): an earlier attempt may have been sent, which the gate's refusal must not deny. The
|
|
606
|
+
// marks were read before the run resumed (prime), so a rerun the resume dispatches finds them.
|
|
607
|
+
const answer = await gate.enter(tool.name, args, api.callId, { commit }, gate.passed.has(api.callId) ? { replayed: true } : {});
|
|
365
608
|
// A parked call ends the turn, as ask_person's does.
|
|
366
609
|
if (answer)
|
|
367
610
|
return forModel(answer.text, answer.parked ? { control: { terminate: true } } : { isError: true });
|
|
611
|
+
// Let through: a call that can bill is marked in the store before the tool runs, so a crash after it leaves a
|
|
612
|
+
// rerun the gate knows for one. A mark that fails to commit stops the call (nothing has been sent).
|
|
613
|
+
if (billed && !gate.passed.has(api.callId)) {
|
|
614
|
+
await commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: GATE_PASSED_ENTRY, data: { callId: api.callId } }));
|
|
615
|
+
gate.passed.add(api.callId);
|
|
616
|
+
}
|
|
617
|
+
// pi-durable committed the call's intent before it reached execute: durable before the call is sent, so a lost
|
|
618
|
+
// box never sends it twice (a resumed call with its intent is reported interrupted, not run again).
|
|
619
|
+
if (tool.replay !== "safe" || billed)
|
|
620
|
+
await syncNow(gate.syncTarget, BARRIER.piToolIntent);
|
|
368
621
|
return tool.execute(args, api, context);
|
|
369
622
|
},
|
|
370
623
|
};
|
|
371
624
|
}
|
|
372
|
-
/**
|
|
373
|
-
* coding source (coding-tools.ts), on which an approved coding
|
|
374
|
-
|
|
625
|
+
/** Takes the open run, as the run's process opens (its app's onOpen), reading what its store holds of the gate unless
|
|
626
|
+
* `prime` read it before the resume. `coding`: the run's coding source (coding-tools.ts), on which an approved coding
|
|
627
|
+
* call runs, as the run's own would; `extra`, the run's own tools beyond the table (its learned_workflow), on which an
|
|
628
|
+
* approved call of one runs. */
|
|
375
629
|
async load(durable, context, coding, extra = []) {
|
|
376
630
|
this.durable = durable;
|
|
631
|
+
this.syncTarget = durable.store;
|
|
377
632
|
this.context = context;
|
|
378
633
|
this.coding = coding;
|
|
379
634
|
this.extra = extra;
|
|
380
|
-
|
|
635
|
+
if (!this.primed)
|
|
636
|
+
await this.prime(durable.harness, context);
|
|
637
|
+
}
|
|
638
|
+
primed = false;
|
|
639
|
+
/** Reads what the run's store holds of the gate (the calls that wait, the answers acted on, the calls it let through)
|
|
640
|
+
* before the run resumes: its app's beforeResume hook, ahead of harness.resume(), which dispatches the calls a crash
|
|
641
|
+
* cut. Read here, not in onOpen, which a recovered call races. A workflow's run calls only this; load reads nothing more. */
|
|
642
|
+
async prime(harness, context, syncTarget) {
|
|
643
|
+
if (syncTarget)
|
|
644
|
+
this.syncTarget = syncTarget;
|
|
645
|
+
const root = await harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
381
646
|
for (let cursor; root;) {
|
|
382
647
|
const page = await root.entries({ order: "ascending" }, 500, cursor, context);
|
|
383
648
|
for (const entry of page.items)
|
|
@@ -386,6 +651,7 @@ export class RunGate {
|
|
|
386
651
|
break;
|
|
387
652
|
cursor = page.next;
|
|
388
653
|
}
|
|
654
|
+
this.primed = true;
|
|
389
655
|
}
|
|
390
656
|
/** Whether a call waits for its answer, or for its answer to be acted on: a harness keeps the turn it ended closed. */
|
|
391
657
|
waiting() {
|
|
@@ -397,11 +663,18 @@ export class RunGate {
|
|
|
397
663
|
return message !== undefined && [...this.requests.values()].some((held) => held.turn === message);
|
|
398
664
|
}
|
|
399
665
|
/** Acts on the answers from now on, resuming the session through `resume`; by default pi's root conversation. */
|
|
400
|
-
start(resume) {
|
|
666
|
+
start(resume, unpark) {
|
|
401
667
|
this.resume = resume ?? this.submit;
|
|
668
|
+
this.unpark = unpark;
|
|
402
669
|
this.watch();
|
|
403
670
|
}
|
|
404
671
|
note(entry) {
|
|
672
|
+
if (entry.kind === GATE_PASSED_ENTRY) {
|
|
673
|
+
const callId = entry.data?.callId;
|
|
674
|
+
if (typeof callId === "string")
|
|
675
|
+
this.passed.add(callId);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
405
678
|
const data = entry.data;
|
|
406
679
|
if (entry.kind !== APPROVAL_ENTRY || typeof data?.id !== "string")
|
|
407
680
|
return;
|
|
@@ -421,9 +694,15 @@ export class RunGate {
|
|
|
421
694
|
}
|
|
422
695
|
/** pi's resume: an input to the root conversation under the request's own id, which pi takes once however often it
|
|
423
696
|
* is sent, then the mark. */
|
|
424
|
-
submit = async (id, content, mark) => {
|
|
697
|
+
submit = async (id, content, mark, origin) => {
|
|
425
698
|
const root = await this.durable.harness.root(this.context);
|
|
426
|
-
|
|
699
|
+
const requestId = `approval-${id}`;
|
|
700
|
+
// pi writes its user entry with no data, so the resume's origin goes first as an entry of its own, which the Timeline
|
|
701
|
+
// matches to it by its text (pi-durable-disk's serve does the same). Once only: a resume tried again whose input is
|
|
702
|
+
// in already writes no second marker, which would be left open for a later message with the same text.
|
|
703
|
+
if (origin && (await root.commit((tx) => tx.submissionByRequest(root.id, requestId), this.context)) === undefined)
|
|
704
|
+
await root.submit({ type: "write", requestId: `origin of ${requestId}`, entry: { kind: MESSAGE_ORIGIN_KIND, data: { origin, text: content } } }, this.context);
|
|
705
|
+
await root.submit({ type: "input", requestId, content, whenBusy: "followUp" }, this.context);
|
|
427
706
|
await this.durable.harness.commit(mark, this.context);
|
|
428
707
|
};
|
|
429
708
|
async settle() {
|
|
@@ -459,7 +738,22 @@ export class RunGate {
|
|
|
459
738
|
continue;
|
|
460
739
|
}
|
|
461
740
|
// An allow runs the call, unless its tool was set to deny since it asked.
|
|
462
|
-
|
|
741
|
+
// A request parked on a replay may follow an attempt that was sent: its refusal makes no "nothing was charged" claim.
|
|
742
|
+
if (decision === "allow")
|
|
743
|
+
this.unpark?.();
|
|
744
|
+
// And a pin holds for an approved call too: one whose arguments are no longer as pinned (a pin set since it asked)
|
|
745
|
+
// is refused as a deny since is.
|
|
746
|
+
const result = decision === "deny" ? { text: refusedText(held.tool, answer.note, held.replayed ? "unknown" : "no"), isError: true } : this.policy(held.tool) === "deny" || this.pinned(held.tool, held.args) ? await this.ranOrDenied(held) : await this.run(held);
|
|
747
|
+
// A test's seam, unset in a server (AGENTRUN_SERVE_TEST_CRASH_AFTER_CALL, a file that marks it once): an approved
|
|
748
|
+
// call that ran and whose outcome is in the journal, then the process goes before its resume, once the test says go
|
|
749
|
+
// (<file>.go), as a crash between the two would leave the run.
|
|
750
|
+
const seam = process.env.AGENTRUN_SERVE_TEST_CRASH_AFTER_CALL;
|
|
751
|
+
if (seam && decision === "allow" && !existsSync(seam)) {
|
|
752
|
+
while (!existsSync(`${seam}.go`))
|
|
753
|
+
await new Promise((done) => setTimeout(done, 50));
|
|
754
|
+
writeFileSync(seam, "");
|
|
755
|
+
process.kill(process.pid, "SIGKILL");
|
|
756
|
+
}
|
|
463
757
|
// And again once the call is done: a stop or a cancel while it ran drops its result, which never reaches the model.
|
|
464
758
|
const after = (await readJson(join(this.where.root, RUN_META)))?.approvals?.[held.id];
|
|
465
759
|
if (after?.decision === "canceled" || after?.decision === "withdrawn") {
|
|
@@ -469,7 +763,9 @@ export class RunGate {
|
|
|
469
763
|
// The arguments the message names are the server's redacted ones: the gate never writes a held value there. The
|
|
470
764
|
// result is cut as every host tool's is (boundResult, HOST_RESULT_MAX_CHARS, in its words): an executor's (an
|
|
471
765
|
// MCP call's) comes uncut, and its journal keeps it whole.
|
|
472
|
-
|
|
766
|
+
// The server's message, never the person's: a declining message's words are theirs, beside it.
|
|
767
|
+
const origin = decision === "deny" && answer.by === "message" && answer.note?.trim() ? { kind: "server", reason: "approval_declined", said: answer.note } : { kind: "server", reason: "approval" };
|
|
768
|
+
await this.resume(held.id, resumeText(held, answer.args_shown ?? "(not shown)", decision, { ...result, text: boundResult(result.text).text }), (tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: APPROVAL_ENTRY, data: { phase: "resolved", id: held.id, decision } }), origin);
|
|
473
769
|
held.resolved = true;
|
|
474
770
|
}
|
|
475
771
|
}
|
|
@@ -497,6 +793,36 @@ export class RunGate {
|
|
|
497
793
|
await this.durable.harness.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: APPROVAL_ENTRY, data: { phase: "resolved", id: held.id, decision } }), this.context);
|
|
498
794
|
held.resolved = true;
|
|
499
795
|
}
|
|
796
|
+
/** The run's own `approvals:` session, the journal every approved call runs through: opened once. */
|
|
797
|
+
journal() {
|
|
798
|
+
this.drive ??= durableSessions(this.durable.harness, this.context, this.durable.store)
|
|
799
|
+
.open(`approvals:${this.where.runId}`)
|
|
800
|
+
.then((writer) => openDrive({ writer, signal: this.stop.signal }))
|
|
801
|
+
.catch((error) => {
|
|
802
|
+
this.drive = undefined;
|
|
803
|
+
throw error;
|
|
804
|
+
});
|
|
805
|
+
return this.drive;
|
|
806
|
+
}
|
|
807
|
+
/** An approved call whose tool was set to deny (or pinned so that its arguments no longer hold) before the gate acted
|
|
808
|
+
* on the answer. A call whose outcome is in the
|
|
809
|
+
* journal RAN (a crash came between it and its resume): the model gets that outcome, as any allowed call's, and nothing
|
|
810
|
+
* runs again; a later deny can't un-run it. One with an intent and no outcome may have been sent: denied, with no claim
|
|
811
|
+
* either way. One the journal never saw is denied, not run and not charged. */
|
|
812
|
+
async ranOrDenied(held) {
|
|
813
|
+
const drive = await this.journal();
|
|
814
|
+
const key = `approval:${held.id}`;
|
|
815
|
+
if (drive.isMemoized(key))
|
|
816
|
+
return this.run(held);
|
|
817
|
+
const heldTo = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, held.tool, this.where.mcpServers);
|
|
818
|
+
const ran = held.replayed || drive.state().effects.has(key) ? "unknown" : "no";
|
|
819
|
+
if (this.policy(held.tool) !== "deny") {
|
|
820
|
+
const pinned = this.pinned(heldTo ?? held.tool, held.args, ran);
|
|
821
|
+
if (pinned)
|
|
822
|
+
return { text: pinned.text, isError: true };
|
|
823
|
+
}
|
|
824
|
+
return { text: deniedText(held.tool, heldTo, this.denyFrom(held.tool), ran), isError: true };
|
|
825
|
+
}
|
|
500
826
|
/** The approved call, run once by the kernel through the journal any host tool's call goes through, as an effect of
|
|
501
827
|
* the run's own `approvals:` session, on the run's coding source: its intent is durable before it runs, its outcome
|
|
502
828
|
* after; a replay-safe call a crash cut off runs again, any other is answered interrupted and never runs again. */
|
|
@@ -504,19 +830,13 @@ export class RunGate {
|
|
|
504
830
|
const runner = await this.runnerOf(held);
|
|
505
831
|
if ("refused" in runner)
|
|
506
832
|
return { text: runner.refused, isError: true };
|
|
507
|
-
|
|
508
|
-
.open(`approvals:${this.where.runId}`)
|
|
509
|
-
.then((writer) => openDrive({ writer, signal: this.stop.signal }))
|
|
510
|
-
.catch((error) => {
|
|
511
|
-
this.drive = undefined;
|
|
512
|
-
throw error;
|
|
513
|
-
});
|
|
833
|
+
const drive = this.journal();
|
|
514
834
|
try {
|
|
515
835
|
// Its own abort beside the drive's: a stop or a cancel of the run cuts this call, which runs outside any turn.
|
|
516
836
|
const cut = new AbortController();
|
|
517
837
|
this.inFlight = { id: held.id, cut };
|
|
518
838
|
try {
|
|
519
|
-
return await (await
|
|
839
|
+
return await (await drive).effect(`approval:${held.id}`, { name: held.tool, replay: runner.replay, input: held.args }, async ({ signal }) => {
|
|
520
840
|
try {
|
|
521
841
|
const answer = await runner.call(AbortSignal.any([signal, cut.signal]));
|
|
522
842
|
// A host tool answers its own abort as an error result: still the stop's cut.
|