@parcha/agentrun-serve 0.1.0-beta.30 → 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 +472 -0
- package/NOTICE +18 -0
- package/README.md +1042 -240
- 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 +12 -5
- package/dist/agents.js +40 -17
- package/dist/app.d.ts +2 -4
- package/dist/app.js +227 -97
- 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.d.ts +2 -1
- package/dist/background.js +69 -29
- package/dist/bounds.d.ts +26 -0
- package/dist/bounds.js +137 -0
- package/dist/box-egress-vm.d.ts +126 -0
- package/dist/box-egress-vm.js +364 -0
- package/dist/box-egress.d.ts +19 -8
- 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.d.ts +4 -0
- package/dist/box-relay-vm.js +103 -55
- package/dist/box-relay.d.ts +2 -0
- package/dist/box-relay.js +2 -2
- package/dist/boxes.d.ts +20 -3
- package/dist/boxes.js +67 -14
- 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 +274 -63
- package/dist/cap.js +599 -188
- package/dist/cli.js +226 -16
- 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 +31 -4
- package/dist/decisions.js +66 -8
- 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 -32
- package/dist/files.js +9 -117
- 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 +14 -44
- package/dist/grade.js +55 -233
- 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 +539 -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 +13 -0
- package/dist/host-check.js +35 -0
- 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/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- 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 +25 -9
- package/dist/learn/grade.js +98 -50
- 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 +72 -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 +7 -1
- package/dist/learn/skills.js +21 -4
- package/dist/learned-workflow.d.ts +12 -2
- package/dist/learned-workflow.js +9 -5
- package/dist/learning-routes.d.ts +107 -31
- package/dist/learning-routes.js +358 -403
- package/dist/learning-run.d.ts +61 -54
- package/dist/learning-run.js +183 -205
- package/dist/learning-words.d.ts +10 -8
- package/dist/learning-words.js +29 -13
- package/dist/learning.d.ts +186 -113
- package/dist/learning.js +345 -381
- 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 +129 -0
- package/dist/mcp-gateway.js +508 -0
- package/dist/mcp-meta.d.ts +20 -0
- package/dist/mcp-meta.js +50 -0
- 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 +185 -34
- package/dist/mcp-servers.js +304 -298
- 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 +965 -111
- package/dist/owner.d.ts +46 -10
- package/dist/owner.js +123 -43
- package/dist/page.d.ts +12 -0
- package/dist/page.js +28 -2
- 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 +18 -15
- package/dist/place.js +36 -18
- package/dist/port-models.d.ts +53 -0
- package/dist/port-models.js +93 -0
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -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 +91 -20
- 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 +36 -4
- package/dist/runnable.js +157 -31
- 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 +360 -222
- package/dist/runs.js +1619 -536
- 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 +22 -0
- package/dist/secrets.js +37 -4
- 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 +152 -74
- package/dist/server.js +1757 -588
- 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 +183 -37
- package/dist/tool-gate.js +450 -99
- package/dist/tool-keys-store.d.ts +110 -0
- package/dist/tool-keys-store.js +291 -0
- package/dist/tool-keys.d.ts +27 -13
- package/dist/tool-keys.js +24 -10
- package/dist/tool-plane.d.ts +115 -25
- package/dist/tool-plane.js +251 -74
- 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 +344 -65
- 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 +56 -21
- 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 -25
- 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-34jfpIbQ.js +0 -481
- 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/run-view.js
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
// A run's served view, as pure functions over the run's rows (its timeline) and what the store kept, separate from how the
|
|
2
|
+
// run is held or read. The server cut feeds these from the one store's readers; before it, runs.ts feeds them from a run's
|
|
3
|
+
// in-memory rows. The functions move here unchanged, so the figures and words a person sees do not change: the extraction
|
|
4
|
+
// is what the existing view, cost and timeline tests already pin.
|
|
5
|
+
//
|
|
6
|
+
// The pieces here so far: the cost reads (a run's cost, its paid tools' charges, the cost a view shows, what it has cost so
|
|
7
|
+
// far when the total is unknown) and the served row transforms a view applies to the timeline (the over-cap row, the
|
|
8
|
+
// paused run's waiting row). All read the same rows the timeline renders.
|
|
9
|
+
import { NOTE_SUFFIX, chargedTool, isMessageRow, registerLabel, registerTurnEnding, scrubUrls } from "@parcha/pi-durable-agent/timeline";
|
|
10
|
+
import { CAP_TOLERANCE, FIT_TOLERANCE, money, roomRefusal } from "./cap.js";
|
|
11
|
+
import { servedOnly } from "./served-only.js";
|
|
12
|
+
import { APPROVAL_ROW, previewOf } from "./tool-gate.js";
|
|
13
|
+
import { ASK_TOOL } from "./tools.js";
|
|
14
|
+
import { LEARNING_LABEL } from "./learning.js";
|
|
15
|
+
import { builtinHarness } from "./harness-table.js";
|
|
16
|
+
import { cutStrings, redacted, withoutLoopback } from "./key-refusal.js";
|
|
17
|
+
import { pointerHash } from "./sign-ins.js";
|
|
18
|
+
import { MIN_SECRET } from "./learn/secrets.js";
|
|
19
|
+
import { KINDS } from "./runner/journal-kinds.js";
|
|
20
|
+
/** The run's newest usage row, which carries its cost. */
|
|
21
|
+
const usageOf = (rows) => rows.findLast((r) => r.kind === "usage");
|
|
22
|
+
/** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
|
|
23
|
+
export const costOf = (rows) => {
|
|
24
|
+
const usage = usageOf(rows);
|
|
25
|
+
return usage ? (usage.usage?.usd ?? null) : 0;
|
|
26
|
+
};
|
|
27
|
+
/** Whether `row` carries a paid tool's charge counted here: `tool`'s alone when given, every other tool's with `others`
|
|
28
|
+
* (chargedTool: a charge's own `phase` row, or a browser call's row its charges fold into). */
|
|
29
|
+
const chargeOf = (row, tool, others) => {
|
|
30
|
+
const charged = chargedTool(row);
|
|
31
|
+
return charged !== undefined && (tool === undefined || (others ? charged !== tool : charged === tool));
|
|
32
|
+
};
|
|
33
|
+
/** What a run's paid tools charged (`tool`'s alone, when given; every other tool's with `others`), from the same rows its
|
|
34
|
+
* cost is read from: each charge's line carries it (`usage` on a `phase` row), and a browser call's row what its charges
|
|
35
|
+
* came to; null when one is unknown. A call still marked, in flight or cut, is no charge here. */
|
|
36
|
+
export const toolCostOf = (rows, tool, others = false) => rows.reduce((sum, row) => (!chargeOf(row, tool, others) ? sum : sum === null || row.usage.usd === null ? null : sum + row.usage.usd), 0);
|
|
37
|
+
/** What a run's paid tools are known to have charged (`tool`'s alone, when given; every other tool's with `others`): each
|
|
38
|
+
* charge's line that names its cost, a charge of unknown cost adding nothing (a browser call's row, what is known of it). */
|
|
39
|
+
export const knownToolCostOf = (rows, tool, others = false) => rows.reduce((sum, row) => (!chargeOf(row, tool, others) ? sum : sum + (row.usage.usd ?? row.usage.so_far_usd ?? 0)), 0);
|
|
40
|
+
/** A run's cost for its views: its usage row's, else what the store kept when it carried the run back (0 before any
|
|
41
|
+
* request). A usage row that says unknown, or says nothing, stays unknown: what the store kept dates from before a
|
|
42
|
+
* follow-up. */
|
|
43
|
+
export function costView(rows, stored, decisions) {
|
|
44
|
+
const usage = usageOf(rows);
|
|
45
|
+
// A workflow run's decisions, once its end is read: their cost joins its model nodes', and one unknown makes it unknown.
|
|
46
|
+
if (decisions !== undefined) {
|
|
47
|
+
const models = usage ? (usage.usage?.usd ?? null) : 0;
|
|
48
|
+
return models === null || decisions === null ? null : models + decisions;
|
|
49
|
+
}
|
|
50
|
+
if (!usage)
|
|
51
|
+
return stored === undefined ? 0 : stored;
|
|
52
|
+
return usage.usage?.usd ?? null;
|
|
53
|
+
}
|
|
54
|
+
export function soFarOf(rows, decisions) {
|
|
55
|
+
if (decisions === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
const usage = usageOf(rows)?.usage;
|
|
58
|
+
const models = !usage ? { known: 0, unpriced: 0 } : usage.usd !== null ? { known: usage.usd, unpriced: 0 } : usage.so_far_usd !== undefined && usage.unpriced !== undefined ? { known: usage.so_far_usd, unpriced: usage.unpriced } : undefined;
|
|
59
|
+
if (!models)
|
|
60
|
+
return undefined;
|
|
61
|
+
const unpriced = models.unpriced + (decisions?.unpriced ?? 0);
|
|
62
|
+
return unpriced > 0 ? { so_far_usd: Math.round((models.known + (decisions?.known ?? 0)) * 1e6) / 1e6, unpriced } : undefined;
|
|
63
|
+
}
|
|
64
|
+
/** An amount in an over-cap row's or failure's words, to the cent ($0.38020940000000003 is $0.38; $1 is $1), as money
|
|
65
|
+
* says it; `centsUp` to the cent above, for what a run went over by and a bound, so neither reads $0 or under. */
|
|
66
|
+
export const cents = (usd) => money(Math.round(usd * 100) / 100);
|
|
67
|
+
export const centsUp = (usd) => money(Math.ceil(usd * 100 - 1e-9) / 100);
|
|
68
|
+
/** Whether a run that spent `usd` passed its `cap` by no more than `bound`, the bounds of the requests that ended since
|
|
69
|
+
* its cost last fit (bounds.ts): a cache miss an expected-cost cap (cap.ts) admits the risk of, never a cap the run's own
|
|
70
|
+
* rule broke. */
|
|
71
|
+
export const overByMiss = (usd, cap, bound) => bound > 0 && usd - cap <= bound + FIT_TOLERANCE;
|
|
72
|
+
/** The row that says a run's booked spend passed its cap, and by how much, after its usage row: a request's cost is
|
|
73
|
+
* booked once it answers, never clipped, and under an expected-cost cap (cap.ts) a request that missed the cache can cost
|
|
74
|
+
* up to its bound beyond what it was admitted at; one carrying a native web search is held at an allowance, not a bound,
|
|
75
|
+
* so a run can pass its cap by its last request. The next request is then refused. `bound`: the requests' that ended since the cost last fit,
|
|
76
|
+
* bound; when the run passed its cap by no more than it, the row says a cache miss did it, and the most it could have. */
|
|
77
|
+
export function withOverCap(rows, cap, bound = 0) {
|
|
78
|
+
const at = rows.findLastIndex((row) => row.kind === "usage");
|
|
79
|
+
const usd = rows[at]?.usage?.usd;
|
|
80
|
+
if (cap === undefined || typeof usd !== "number" || usd <= cap + FIT_TOLERANCE)
|
|
81
|
+
return rows;
|
|
82
|
+
const { usage: _, ...usage } = rows[at];
|
|
83
|
+
// In cents: what it went over by and the bound rounded up, so "at most" holds.
|
|
84
|
+
const summary = overByMiss(usd, cap, bound) ? `Went ${centsUp(usd - cap)} over its cap on a cache miss (at most ${centsUp(bound)}).` : `Spent ${cents(usd)}, ${centsUp(usd - cap)} over the run's cap of ${cents(cap)}`;
|
|
85
|
+
const over = { ...usage, id: `${usage.id}:over_cap`, kind: "phase", summary, text: null };
|
|
86
|
+
return [...rows.slice(0, at + 1), over, ...rows.slice(at + 1)];
|
|
87
|
+
}
|
|
88
|
+
/** The row of a refusal for room a run paused at (servedError): the server's `phase` row in these words (origin server,
|
|
89
|
+
* its id the refusal's with NOTE_SUFFIX, so it is no message: isMessageRow), marked `paused`, never an error row. The
|
|
90
|
+
* refusal's sentence is the pause's (pending.said), which a client shows once, as its banner. */
|
|
91
|
+
export const BUDGET_PAUSED = "Paused at the run's cap";
|
|
92
|
+
/** The waiting row of a run paused at its cap, after the refusal's row: "Waiting for you to raise the cap", and no
|
|
93
|
+
* more: the refusal's words are the pause's (pending.said), which a client shows once, as its banner. */
|
|
94
|
+
export const BUDGET_WAITING = "Waiting for you to raise the cap";
|
|
95
|
+
export function withPaused(rows) {
|
|
96
|
+
const at = rows.findLastIndex((row) => row.paused === true);
|
|
97
|
+
if (at < 0)
|
|
98
|
+
return [...rows];
|
|
99
|
+
// The refusal's own marker (`paused`, servedError) and the server's origin stay on the refusal's row: the waiting row
|
|
100
|
+
// is no refusal and no row of the server's, and keeps the id it had, the refusal's own with ":paused".
|
|
101
|
+
const { paused: _marker, origin: _origin, ...refusal } = rows[at];
|
|
102
|
+
const own = refusal.id.endsWith(NOTE_SUFFIX) ? refusal.id.slice(0, -NOTE_SUFFIX.length) : refusal.id;
|
|
103
|
+
// Only the served view makes it (servedOnly): once the run is raised, show() stops making it and it goes, even while a
|
|
104
|
+
// live process feeds the timeline (keepCommitted).
|
|
105
|
+
const paused = servedOnly({ ...refusal, id: `${own}:paused`, kind: "waiting", summary: BUDGET_WAITING, text: BUDGET_WAITING, tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null });
|
|
106
|
+
return [...rows.slice(0, at + 1), paused, ...rows.slice(at + 1)];
|
|
107
|
+
}
|
|
108
|
+
/** A text clipped to `max` characters, with an ellipsis where it is cut (runs.ts' clip). */
|
|
109
|
+
const clip = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
110
|
+
const ASKED = "Asked you: ";
|
|
111
|
+
// ask_person's label and that it ends its turn: a person's reply is their next message, never a steer (runs.ts). Registered
|
|
112
|
+
// here so both the file path and the store-backed view render the call the same, whichever module loads first.
|
|
113
|
+
registerLabel(ASK_TOOL, (args) => `${ASKED}${typeof args.question === "string" ? args.question : ""}`, undefined, { name: "Ask you a question" });
|
|
114
|
+
registerTurnEnding(ASK_TOOL);
|
|
115
|
+
/** The waiting row after each answered `ask_person` call, which the timeline module does not know. The question comes from
|
|
116
|
+
* the call's row, whose label this module registers. The server fed its rows through this; the store-backed view feeds the
|
|
117
|
+
* same rows through it, so a run waiting on a question reads the same pending. */
|
|
118
|
+
export function withAsks(rows) {
|
|
119
|
+
const out = [];
|
|
120
|
+
const questions = new Map();
|
|
121
|
+
for (const row of rows) {
|
|
122
|
+
out.push(row);
|
|
123
|
+
if (row.kind === "tool_use" && row.tool_name === ASK_TOOL && row.tool_use_id && row.summary?.startsWith(ASKED))
|
|
124
|
+
questions.set(row.tool_use_id, row.summary.slice(ASKED.length));
|
|
125
|
+
if (row.kind === "tool_result" && row.tool_name === ASK_TOOL && row.tool_status === "success") {
|
|
126
|
+
const question = questions.get(row.tool_use_id ?? "") || "the agent asked you a question";
|
|
127
|
+
out.push({ ...row, id: `${row.id}:waiting`, kind: "waiting", summary: `Waiting for you: ${clip(question, 480)}`, text: clip(question, 2000), tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/** A call withdrawn with its run (a cancel, or a stop while it waited): never run, and an answer after is 409. */
|
|
133
|
+
export const withdrawn = (answer) => answer?.decision === "canceled" || answer?.decision === "withdrawn";
|
|
134
|
+
const dataOf = (entry) => entry.data;
|
|
135
|
+
/** The tool calls a run waits (or waited) for a person's approval on, from its journal's `agentrun.ask` entries, by the
|
|
136
|
+
* call's id: a re-ask of the same call keeps the first request, as the gate's park did; one with an answer is resolved,
|
|
137
|
+
* so the run waits on it no more (the file path's `resolved` once its process acted). The card's id and call id are both
|
|
138
|
+
* the call's id, and its arguments are kept as JSON (shown cut and redacted by the view), as the file path kept them. */
|
|
139
|
+
export function asksOf(entries) {
|
|
140
|
+
const answered = new Set();
|
|
141
|
+
for (const entry of entries)
|
|
142
|
+
if (entry.kind === KINDS.answer) {
|
|
143
|
+
const d = dataOf(entry);
|
|
144
|
+
if (typeof d?.callId === "string")
|
|
145
|
+
answered.add(d.callId);
|
|
146
|
+
}
|
|
147
|
+
const map = new Map();
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
if (entry.kind !== KINDS.ask)
|
|
150
|
+
continue;
|
|
151
|
+
const d = dataOf(entry);
|
|
152
|
+
if (typeof d?.callId !== "string" || map.has(d.callId))
|
|
153
|
+
continue;
|
|
154
|
+
map.set(d.callId, {
|
|
155
|
+
id: d.callId,
|
|
156
|
+
tool: d.tool,
|
|
157
|
+
call_id: d.callId,
|
|
158
|
+
args_json: JSON.stringify(d.args ?? {}) ?? "{}",
|
|
159
|
+
requested_at: d.requestedAt,
|
|
160
|
+
...(typeof d.price === "number" || d.price === "not metered" ? { price: d.price } : {}),
|
|
161
|
+
...(answered.has(d.callId) ? { resolved: true } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return map;
|
|
165
|
+
}
|
|
166
|
+
/** The answers a run got to its asks, from its journal's `agentrun.answer` entries, by the call's id (the key the moment
|
|
167
|
+
* and the pending views read as run.meta.approvals): a person's allow or deny with any note, or a withdrawal taken when
|
|
168
|
+
* the run was stopped or cancelled while the call waited. The first answer for a call stands, but for a stop's
|
|
169
|
+
* withdrawal over an allow the call had not finished on (its `superseded`, as main's stop superseded it): that is the
|
|
170
|
+
* call's answer, keeping the one it overrode. A call asked about with no answer that the run's journal ENDED after (an
|
|
171
|
+
* agentrun.end follows its ask) reads withdrawn, whatever the run's state is now: a run that ended never waits on that
|
|
172
|
+
* call (its end wrote no withdrawal only when its journal would not take it), a reopen of it included; in the words of
|
|
173
|
+
* the first end after it (a stop's end: stopped; a completed or failed one: `ended`). So does every unanswered call of
|
|
174
|
+
* a run `final` as stopped or failed (states no reopen leaves), whose end its journal may not hold (written on the run's
|
|
175
|
+
* row alone). A call asked in the turn going now (no end after it, the run not final) waits. */
|
|
176
|
+
export function answersOf(entries, { final } = {}) {
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const entry of entries) {
|
|
179
|
+
if (entry.kind !== KINDS.answer)
|
|
180
|
+
continue;
|
|
181
|
+
const d = dataOf(entry);
|
|
182
|
+
if (typeof d?.callId !== "string")
|
|
183
|
+
continue;
|
|
184
|
+
// The runner writes { callId, approved, note? } (journal-kinds.ts AnswerData): its decision is read from `approved`.
|
|
185
|
+
const decision = d.decision ?? (d.approved === true ? "allow" : d.approved === false ? "deny" : undefined);
|
|
186
|
+
if (decision === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
const given = out[d.callId];
|
|
189
|
+
if (given && !(decision === "withdrawn" && d.superseded))
|
|
190
|
+
continue;
|
|
191
|
+
const superseded = given ? { superseded: { decision: given.decision, answered_at: given.answered_at, ...(given.note !== undefined ? { note: given.note } : {}), ...(given.by ? { by: given.by } : {}) } } : {};
|
|
192
|
+
// A deny a person's message gave keeps that it was (`by`): its row reads "Declined by your message".
|
|
193
|
+
out[d.callId] = { decision, ...(d.note !== undefined ? { note: d.note } : {}), answered_at: d.answeredAt ?? "", ...(decision === "deny" && d.by === "message" ? { by: "message" } : {}), ...superseded };
|
|
194
|
+
}
|
|
195
|
+
// How the run ended after each entry: the state of the first agentrun.end at or after it, else the final row's.
|
|
196
|
+
let endedAs = final;
|
|
197
|
+
const endsAfter = [];
|
|
198
|
+
for (let at = entries.length - 1; at >= 0; at--) {
|
|
199
|
+
if (entries[at].kind === KINDS.end)
|
|
200
|
+
endedAs = dataOf(entries[at])?.state ?? "ended";
|
|
201
|
+
endsAfter[at] = endedAs;
|
|
202
|
+
}
|
|
203
|
+
entries.forEach((entry, at) => {
|
|
204
|
+
const state = endsAfter[at];
|
|
205
|
+
if (entry.kind !== KINDS.ask || state === undefined)
|
|
206
|
+
return;
|
|
207
|
+
const { callId } = dataOf(entry);
|
|
208
|
+
if (typeof callId === "string" && !(callId in out))
|
|
209
|
+
out[callId] = { decision: "withdrawn", answered_at: "", ...(state === "stopped" ? {} : { ended: true }) };
|
|
210
|
+
});
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
/** The run's active cap park, from its journal: the last agentrun.budget entry the cap wrote when it parked the run for
|
|
214
|
+
* room, unless an agentrun.raise after it cleared the pause (the run goes on at the raised cap then). A re-park writes a
|
|
215
|
+
* fresh budget entry, which a raise before it does not clear, so the last of the two in log order decides. */
|
|
216
|
+
function activeBudget(entries) {
|
|
217
|
+
let mark;
|
|
218
|
+
for (const entry of entries) {
|
|
219
|
+
if (entry.kind === KINDS.budget)
|
|
220
|
+
mark = dataOf(entry);
|
|
221
|
+
else if (entry.kind === KINDS.raise)
|
|
222
|
+
mark = undefined;
|
|
223
|
+
}
|
|
224
|
+
return mark;
|
|
225
|
+
}
|
|
226
|
+
/** Whether the run stands parked at its cap now (an active agentrun.budget park, no raise since): the store-backed fact the
|
|
227
|
+
* status table reads (RunFacts.budgetWaiting), as the file-backed view read a workflow's pause file and an agentic run's
|
|
228
|
+
* turn refusal. */
|
|
229
|
+
export const budgetWaitingOf = (entries) => activeBudget(entries) !== undefined;
|
|
230
|
+
/** The budget card a run parked at its cap shows (pending, kind budget), from its agentrun.budget entry, the same way the
|
|
231
|
+
* file-backed view built it from the run's pause mark (runs.ts workflowBudgetPending): its cap (the run's launch cap, else
|
|
232
|
+
* the park's), what the cap counted as taken and the least the refused step needs, the raise offered (recomputed from
|
|
233
|
+
* those by the view's one formula), and the cap's words at the run's last meaningful row. The overshoot bound reads 0: the
|
|
234
|
+
* kernel cap's parkOf keeps no cache-miss bound. Undefined when no park is active. */
|
|
235
|
+
export function budgetOf(entries, run) {
|
|
236
|
+
const mark = activeBudget(entries);
|
|
237
|
+
if (!mark)
|
|
238
|
+
return undefined;
|
|
239
|
+
const p = mark.pending;
|
|
240
|
+
const cap = run.meta.max_cost_usd ?? p.cap_usd;
|
|
241
|
+
const figures = p.spent_usd !== undefined && p.needs_usd !== undefined
|
|
242
|
+
? { spent_usd: micro(p.spent_usd), needs_usd: micro(p.needs_usd), ...(p.least_cap_usd !== undefined ? { least_cap_usd: p.least_cap_usd } : {}), suggested_cap_usd: suggestedCap(cap, p.spent_usd, p.needs_usd), overshoot_bound_usd: microUp(0) }
|
|
243
|
+
: {};
|
|
244
|
+
return { kind: "budget", cap_usd: cap, ...figures, said: mark.words, at: meaningful(run.rows)?.timestamp ?? run.updatedAt };
|
|
245
|
+
}
|
|
246
|
+
/** Read only on a run's `rows`, which hold no QUIET row (take). */
|
|
247
|
+
const shows = (r) => r.kind !== "usage" && r.kind !== "phase";
|
|
248
|
+
export const meaningful = (rows) => rows.findLast((r) => shows(r) && r.agent_label !== LEARNING_LABEL);
|
|
249
|
+
// A run's messages are its message rows (isMessageRow): a person's, and those the server wrote, the message its turn took.
|
|
250
|
+
export const usersOf = (rows) => rows.filter(isMessageRow).length;
|
|
251
|
+
// A row's place in the store: its entry's id. The store mints conversation and entry ids from one counter, so entry ids
|
|
252
|
+
// order rows across conversations and the conversation is no part of the order.
|
|
253
|
+
const placeOf = (id) => Number(id.slice(id.lastIndexOf(":") + 1));
|
|
254
|
+
/** Whether the turn a stop ended is still where the run stands: no message shown is newer than the stop's. By order,
|
|
255
|
+
* never by a count or by the stopped message itself, which a compaction can take off the rows. */
|
|
256
|
+
export const stoppedAt = (meta, rows) => {
|
|
257
|
+
if (meta.stopped_at === undefined)
|
|
258
|
+
return meta.stopped_after !== undefined && meta.stopped_after === usersOf(rows);
|
|
259
|
+
const at = placeOf(meta.stopped_at);
|
|
260
|
+
return !rows.some((r) => isMessageRow(r) && placeOf(r.id) > at);
|
|
261
|
+
};
|
|
262
|
+
export const stopped = (run) => stoppedAt(run.meta, run.rows);
|
|
263
|
+
/** The tool call that waits for a person's answer: requested in the run's store, not resolved there, not answered. */
|
|
264
|
+
export const waitingApproval = (run) => [...(run.approvals?.values() ?? [])].find((a) => !a.resolved && !run.meta.approvals?.[a.id]);
|
|
265
|
+
/** One answered (allow or deny) whose answer the run's process has not acted on yet. */
|
|
266
|
+
export const actingOn = (run) => [...(run.approvals?.values() ?? [])].some((a) => !a.resolved && run.meta.approvals?.[a.id] && !withdrawn(run.meta.approvals[a.id]));
|
|
267
|
+
/** What is shown of a call's arguments: the whole of them redacted with the run's redactor, then cut (previewOf), so
|
|
268
|
+
* no cut leaves the head of a held key. */
|
|
269
|
+
export const shownArgs = (approval, redact) => previewOf(redact(approval.args_json));
|
|
270
|
+
/** A dollar figure to a millionth, as the timeline's cost.usd is. */
|
|
271
|
+
export const micro = (usd) => Math.round(usd * 1e6) / 1e6;
|
|
272
|
+
/** A bound to a millionth, rounded up, so "at most" holds. No bound is 0, never -0: the ceiling of a hair under 0 is -0,
|
|
273
|
+
* which the budget card would print as "-0". */
|
|
274
|
+
export const microUp = (usd) => Math.ceil(usd * 1e6 - 1e-9) / 1e6 + 0;
|
|
275
|
+
/** How many of the refused request's least a run paused at its cap is offered on top of what was taken (suggestedCap). */
|
|
276
|
+
export const SUGGESTED_RAISE_FACTOR = 10;
|
|
277
|
+
/** The raise a run paused at its cap is offered: what the cap counted as taken plus SUGGESTED_RAISE_FACTOR times the
|
|
278
|
+
* refused request's least, rounded up to a whole dollar, and always above the cap (the next dollar above it, if not),
|
|
279
|
+
* so a PATCH with it is a raise. */
|
|
280
|
+
export const suggestedCap = (cap, spentUsd, needsUsd) => {
|
|
281
|
+
// A hair under, so a sum a float puts just past a whole dollar (3.0000000000000004) stays that dollar.
|
|
282
|
+
const up = Math.ceil(spentUsd + SUGGESTED_RAISE_FACTOR * needsUsd - 1e-9);
|
|
283
|
+
// Above the cap as a raise must be (by more than CAP_TOLERANCE, takeRaise), so a PATCH with it is always taken.
|
|
284
|
+
return up > cap + CAP_TOLERANCE ? up : Math.floor(cap + CAP_TOLERANCE) + 1;
|
|
285
|
+
};
|
|
286
|
+
/** The words of the cap's refusal for room an agentic run stands paused at: its newest message's turn ended on it (cap.ts
|
|
287
|
+
* roomRefusal: what is left of its cap cannot buy the next request's least, which a higher cap would send), and nothing
|
|
288
|
+
* came since. The run then waits for its cap to be raised (input_required, `pending.kind` budget), never failed; a
|
|
289
|
+
* refusal no cap fixes (an unknown spend, no price) still fails it (decide). Undefined for any other run. */
|
|
290
|
+
const refusedAt = (run, { inFlight = true } = {}) => {
|
|
291
|
+
// `inFlight: false`: a message counted but not yet shown does not move the run past its refusal (one that may not
|
|
292
|
+
// answer its person reads the pause through it).
|
|
293
|
+
if (run.kind !== "agentic" || run.cancel || (inFlight && run.submitted > 0) || run.turns.open > 0 || stopped(run))
|
|
294
|
+
return undefined;
|
|
295
|
+
const end = run.turns.end();
|
|
296
|
+
return end?.status === "failed" ? roomRefusal(end.error) : undefined;
|
|
297
|
+
};
|
|
298
|
+
/** The pause a run stands at, by its refusal's own start mark (its entry), so no row shown after it moves it; a store
|
|
299
|
+
* with no such mark keys it to the refusal's row. Undefined when it stands at no refusal for room. */
|
|
300
|
+
export const pauseOf = (run, read = {}) => {
|
|
301
|
+
if (refusedAt(run, read) === undefined)
|
|
302
|
+
return undefined;
|
|
303
|
+
if (run.capMark !== undefined)
|
|
304
|
+
return `mark:${run.capMark}`;
|
|
305
|
+
const row = meaningful(run.rows)?.id;
|
|
306
|
+
return row === undefined ? undefined : `row:${row}`;
|
|
307
|
+
};
|
|
308
|
+
/** Its cap was raised since the refusal it stands at (a raise names that pause): it waits for its follow-up then, not
|
|
309
|
+
* for a raise (input_required, idle). */
|
|
310
|
+
const raisedSince = (run, read = {}) => {
|
|
311
|
+
const pause = pauseOf(run, read);
|
|
312
|
+
return pause !== undefined && run.meta.cap_raised?.some((raise) => raise.pause === pause) === true;
|
|
313
|
+
};
|
|
314
|
+
/** The follow-up a raise of the pause it stands at asked for and that has not gone yet: one per pause. */
|
|
315
|
+
export const continuationOf = (run) => {
|
|
316
|
+
// A run that has ended, or is ending (its follow-up's tries spent: failRaised, a cancel), sends none any more.
|
|
317
|
+
if (run.outcome || run.finishing || run.cancel)
|
|
318
|
+
return undefined;
|
|
319
|
+
const pause = pauseOf(run);
|
|
320
|
+
const next = run.meta.cap_continue;
|
|
321
|
+
return pause !== undefined && next?.pause === pause && !next.sent ? next : undefined;
|
|
322
|
+
};
|
|
323
|
+
export const pausedAt = (run, read = {}) => (raisedSince(run, read) ? undefined : refusedAt(run, read));
|
|
324
|
+
/** Raised at the pause it stands at, and that raise's follow-up still to go (continuationOf): the run goes on without a
|
|
325
|
+
* person, once the follow-up opens its next process (resumeRaised). */
|
|
326
|
+
export const raisedToGo = (run) => raisedSince(run) && continuationOf(run) !== undefined;
|
|
327
|
+
export const pendingOf = (rows) => {
|
|
328
|
+
const last = meaningful(rows);
|
|
329
|
+
return last?.kind === "waiting" ? { kind: "question", question: last.text ?? last.summary ?? "", asked_at: last.timestamp } : null;
|
|
330
|
+
};
|
|
331
|
+
/** The run's pending approval (`pending`, kind approval): the call that waits; else undefined. */
|
|
332
|
+
export const approvalOf = (run, redact) => {
|
|
333
|
+
const waiting = waitingApproval(run);
|
|
334
|
+
return waiting ? { kind: "approval", id: waiting.id, tool: waiting.tool, call_id: waiting.call_id, args_preview: shownArgs(waiting, redact), requested_at: waiting.requested_at, ...(waiting.price !== undefined ? { price: waiting.price } : {}) } : undefined;
|
|
335
|
+
};
|
|
336
|
+
/** A run paused at its cap waits on a raise: its cap, what the cap counted as taken and the least the refused request
|
|
337
|
+
* needs (its refusal's mark; none from a store written before it kept them), the raise it is offered (suggestedCap),
|
|
338
|
+
* the refusal's words, and when it came (its error row's time). The figures are as the cap counts them, never rounded.
|
|
339
|
+
* What was taken is the store's spend once its process is gone (`spentNow`), when that is lower: the refusal counted
|
|
340
|
+
* requests still answering at what it held for them, and they have settled. */
|
|
341
|
+
export const budgetPending = (run, spentNow) => {
|
|
342
|
+
const said = pausedAt(run);
|
|
343
|
+
const cap = run.meta.max_cost_usd;
|
|
344
|
+
if (said === undefined || cap === undefined)
|
|
345
|
+
return undefined;
|
|
346
|
+
const r = run.capRefusal;
|
|
347
|
+
const spent = r && spentNow !== undefined ? Math.min(r.spentUsd, spentNow) : r?.spentUsd;
|
|
348
|
+
// Shown as cost.usd is (to a millionth of a dollar), the suggestion from the figures as the cap counts them. The least cap
|
|
349
|
+
// that sends the refused request is the one its words name (`said`), carried from the refusal that wrote them, never
|
|
350
|
+
// worked out again here from figures that may have moved since. With them, the most a cache miss could make the refused
|
|
351
|
+
// request cost beyond what it needs (cap.ts), 0 for none.
|
|
352
|
+
const figures = r && spent !== undefined ? { spent_usd: micro(spent), needs_usd: micro(r.needsUsd), least_cap_usd: r.leastCapUsd, suggested_cap_usd: suggestedCap(cap, spent, r.needsUsd), overshoot_bound_usd: microUp(r.boundUsd ?? 0) } : {};
|
|
353
|
+
return { kind: "budget", cap_usd: cap, ...figures, said, at: meaningful(run.rows)?.timestamp ?? run.updatedAt };
|
|
354
|
+
};
|
|
355
|
+
/** A run whose agent asked for the person in its browser waits on their hand-back: what it asked them to do, when it is
|
|
356
|
+
* done, and when the ask expires. Never the session's tag or the live view's link. The two texts are the model's, so
|
|
357
|
+
* redacted with the run's redactor (`redact`), as a tool call's arguments are: a held value it echoes never shows. */
|
|
358
|
+
export const browserPending = (ask, redact) => ask && { kind: "browser", instruction: redact(ask.instruction), completion_condition: redact(ask.completion_condition), asked_at: ask.asked_at, expires_at: ask.expires_at };
|
|
359
|
+
/** A run whose agent asked for the person on its desktop or phone waits on their hand-back, the same way: the two texts
|
|
360
|
+
* are the model's, so redacted. */
|
|
361
|
+
export const computerPending = (ask, redact) => ask && { kind: "computer", computer: ask.computer ?? "desktop", instruction: redact(ask.instruction), completion_condition: redact(ask.completion_condition), asked_at: ask.asked_at, expires_at: ask.expires_at };
|
|
362
|
+
/** A run's status and state, by the contract's table. `facts` carries the run's file-backed reads (a workflow's pause,
|
|
363
|
+
* the browser ask); every other read is over the run's rows, its turns and its store entries. */
|
|
364
|
+
export function statusOf(run, facts) {
|
|
365
|
+
if (run.outcome)
|
|
366
|
+
return { status: run.outcome, state: "idle" };
|
|
367
|
+
if (run.finishing)
|
|
368
|
+
return { status: run.finishing, state: "idle" };
|
|
369
|
+
// A paused workflow run finishes what it has in flight and starts nothing new until it is resumed (pause.ts). A held run
|
|
370
|
+
// read without its directory (a view built for a count) has no mark to read.
|
|
371
|
+
// One paused at its cap waits for a raise (budget.ts): input_required and waiting, with or without its process.
|
|
372
|
+
// Raised, it waits for a place to open again in (finishRaise): queued, as a run not yet started is.
|
|
373
|
+
if (run.kind === "workflow" && run.placeWait && !run.cancel)
|
|
374
|
+
return { status: "queued", state: "working" };
|
|
375
|
+
if (run.kind === "workflow")
|
|
376
|
+
return facts.budgetWaiting() ? { status: "input_required", state: "waiting" } : facts.paused() ? { status: "paused", state: "idle" } : { status: run.working ? "working" : "queued", state: "working" };
|
|
377
|
+
const users = usersOf(run.rows);
|
|
378
|
+
if (run.submitted > 0)
|
|
379
|
+
return { status: users ? "working" : "queued", state: "working" };
|
|
380
|
+
// No rows is a run not shown yet (adopted, before its first snapshot), whatever an old stop says. Rows with no
|
|
381
|
+
// message of the person's are a compaction's (it shows its summary), which can summarize every message of a stop.
|
|
382
|
+
if (!run.rows.length)
|
|
383
|
+
return { status: "queued", state: "working" };
|
|
384
|
+
if (stopped(run))
|
|
385
|
+
return { status: "input_required", state: "idle" };
|
|
386
|
+
if (!users)
|
|
387
|
+
return { status: "queued", state: "working" };
|
|
388
|
+
// A tool call parked for approval (tool-gate.ts) waits for the person; once answered, its process acts on it.
|
|
389
|
+
if (run.kind === "agentic" && run.submitted === 0 && !run.working) {
|
|
390
|
+
if (waitingApproval(run))
|
|
391
|
+
return { status: "input_required", state: "waiting" };
|
|
392
|
+
if (actingOn(run))
|
|
393
|
+
return { status: "working", state: "working" };
|
|
394
|
+
}
|
|
395
|
+
// Parked at its cap, as the store-backed view's fact says it (an active agentrun.budget park, no raise since): it waits
|
|
396
|
+
// for the cap to be raised. The file-backed view reads an agentic run's pause from the turn's refusal (refusedAt, below),
|
|
397
|
+
// where this fact is always false, so this is a no-op there; a workflow run reads it through the facts above.
|
|
398
|
+
if (facts.budgetWaiting())
|
|
399
|
+
return { status: "input_required", state: "waiting" };
|
|
400
|
+
// Every message's turn is over and the newest one's ended interrupted, with no stop of the person's saying so (the
|
|
401
|
+
// harness ended it on its own): the run waits for the person, as after a stop, never working for good.
|
|
402
|
+
if (run.kind === "agentic" && run.submitted === 0 && run.turns.end()?.status === "interrupted")
|
|
403
|
+
return { status: "input_required", state: "idle" };
|
|
404
|
+
// Paused at its cap: it waits for the cap to be raised. Raised, it is queued while the raise's follow-up is still to go
|
|
405
|
+
// (raisedToGo: from the moment the raise is taken, through its paused process's let-go and the follow-up's tries), since
|
|
406
|
+
// nothing waits on a person; for a message only if that follow-up will not go.
|
|
407
|
+
if (refusedAt(run) !== undefined)
|
|
408
|
+
return pausedAt(run) !== undefined ? { status: "input_required", state: "waiting" } : raisedToGo(run) ? { status: "queued", state: "working" } : { status: "input_required", state: "idle" };
|
|
409
|
+
// Its agent asked for the person in its browser (browser-person.ts): its turn is still open, the tool call waiting for
|
|
410
|
+
// the hand-back, and the run waits on the person until they answer or the ask expires.
|
|
411
|
+
if (facts.browserAsk())
|
|
412
|
+
return { status: "input_required", state: "waiting" };
|
|
413
|
+
// So does one whose agent asked for them on its desktop or phone (computer_request_handoff).
|
|
414
|
+
if (facts.computerAsk?.())
|
|
415
|
+
return { status: "input_required", state: "waiting" };
|
|
416
|
+
if (run.working)
|
|
417
|
+
return { status: "working", state: "working" };
|
|
418
|
+
if (meaningful(run.rows)?.kind === "waiting")
|
|
419
|
+
return { status: "input_required", state: "waiting" };
|
|
420
|
+
return { status: "working", state: "idle" };
|
|
421
|
+
}
|
|
422
|
+
/** A run has reached a last state. */
|
|
423
|
+
const TERMINAL = new Set(["completed", "failed", "cancelled"]);
|
|
424
|
+
/** A run's live moment (RunMoment), computed from the same status table and predicates a person's view reads, plus whether
|
|
425
|
+
* a runner holds its claim now (`live`). The server passes its live Run with `live = this.live(run)`; the store-backed
|
|
426
|
+
* view passes a value built from the run's row and journal, so an act's acceptance is decided the same way either path. */
|
|
427
|
+
export function momentOf(run, facts, live) {
|
|
428
|
+
const { status, state } = statusOf(run, facts);
|
|
429
|
+
const terminal = TERMINAL.has(status);
|
|
430
|
+
const waiting = waitingApproval(run);
|
|
431
|
+
// The pause words from the turn's refusal (the file-backed view), else the cap park the store-backed view carries, so a
|
|
432
|
+
// run parked at its cap reads paused and raiseCap resumes it either way.
|
|
433
|
+
const pausedWords = pausedAt(run) ?? run.pausedWords;
|
|
434
|
+
const answered = run.meta.approvals;
|
|
435
|
+
return {
|
|
436
|
+
id: run.id,
|
|
437
|
+
agentId: run.agentId,
|
|
438
|
+
kind: run.kind,
|
|
439
|
+
...(run.imported ? { importedSource: run.imported.source } : {}),
|
|
440
|
+
cancelled: run.cancel,
|
|
441
|
+
terminal,
|
|
442
|
+
...(terminal ? { terminalKind: status } : {}),
|
|
443
|
+
// The message "working" predicate (runs.ts message): queued, working-working, or its agent waits on the person in its
|
|
444
|
+
// browser (mid-turn, the tool call waiting inside the turn).
|
|
445
|
+
working: status === "queued" || (status === "working" && state === "working") || facts.browserAsk() !== undefined || facts.computerAsk?.() !== undefined,
|
|
446
|
+
awaitingAnswer: status === "input_required" && state === "waiting",
|
|
447
|
+
// Whether its harness takes a message mid-turn (runs.ts steers): every workflow run, and an agentic run whose harness
|
|
448
|
+
// steers (pi).
|
|
449
|
+
steers: run.kind !== "agentic" || (builtinHarness(run.harness)?.steer ?? false),
|
|
450
|
+
...(run.meta.max_cost_usd !== undefined ? { maxCostUsd: run.meta.max_cost_usd } : {}),
|
|
451
|
+
...(pausedWords !== undefined ? { pausedWords } : {}),
|
|
452
|
+
paused: pausedWords !== undefined,
|
|
453
|
+
live,
|
|
454
|
+
// Whether it waits on a person (runs.ts waitsOnPerson): a parked approval, a pause at its cap (read through a message
|
|
455
|
+
// counted but not shown), or a question its turn ended on.
|
|
456
|
+
waitsOnPerson: run.kind === "agentic" && (waiting !== undefined || pausedAt(run, { inFlight: false }) !== undefined || (status === "input_required" && state === "waiting")),
|
|
457
|
+
...(waiting ? { waitingApprovalId: waiting.id } : {}),
|
|
458
|
+
...(run.approvals ? { approvalIds: new Set(run.approvals.keys()) } : {}),
|
|
459
|
+
...(answered ? { answeredApprovals: Object.fromEntries(Object.entries(answered).map(([id, a]) => [id, { decision: a.decision, ...(a.ended ? { ended: true } : {}) }])) } : {}),
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// --- What a run serves of its error, its review and its handed sign-in: the redaction choke point, as pure functions over
|
|
463
|
+
// the run's refused values and (for a run read from its row alone) the sign-in reads injected as `signIns`. The server
|
|
464
|
+
// passes its own serverSecrets and signIns; the store-backed view passes the same. summaryOfRow is the ONE summary choke
|
|
465
|
+
// point: a run whose summary holds a handed pointer serves it cut, and an unreadable handed hash withholds it (rowShown). ---
|
|
466
|
+
/** An ended run's words, withheld while this server can't read the sign-in it was handed (load). */
|
|
467
|
+
export const WITHHELD_SIGN_IN = "This server can't read the run's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so nothing the run said is shown.";
|
|
468
|
+
/** A withheld run's title: a short line that fits the title's length and holds nothing the run said, so a title that
|
|
469
|
+
* repeats the handed sign-in is never served when this server can't cut it. The full sentence stays in the run's error
|
|
470
|
+
* and review. */
|
|
471
|
+
export const WITHHELD_TITLE = "Withheld: a sign-in this run used can't be read";
|
|
472
|
+
/** What a `sign_in_handed` the server did not write (anything but a non-empty array of SHA-256 hashes: a `true` or one
|
|
473
|
+
* hash an older build wrote, or a damaged value) reads as: some pointer was handed, which one is not known, so the run is
|
|
474
|
+
* hidden or withheld, never served uncut, and forget waits for it while it goes. */
|
|
475
|
+
export const MALFORMED = "malformed";
|
|
476
|
+
/** A run's `sign_in_handed` as read from its serve.json: undefined when absent (never handed one); the hashes it names;
|
|
477
|
+
* MALFORMED for any other value. */
|
|
478
|
+
export function handedMark(value) {
|
|
479
|
+
if (value === undefined)
|
|
480
|
+
return undefined;
|
|
481
|
+
if (Array.isArray(value) && value.length && value.every((hash) => typeof hash === "string" && /^[0-9a-f]{64}$/.test(hash)))
|
|
482
|
+
return [...new Set(value)];
|
|
483
|
+
return MALFORMED;
|
|
484
|
+
}
|
|
485
|
+
/** Every secret value a run's errors never show, as learning's checker holds them: every one this server never shows
|
|
486
|
+
* (serverSecrets, read now, so one rotated is cut at once) and what each launch handed the run. */
|
|
487
|
+
export const refusedValuesOf = (serverSecrets, handed) => [...serverSecrets(), ...(handed ?? [])];
|
|
488
|
+
/** A run's redactor (decision-rows.ts, tool previews): redacted over its refused values. */
|
|
489
|
+
export const redactorOf = (values) => (text) => redacted(text, values);
|
|
490
|
+
/** What serve shows of a run's error text, for every run kind: no held secret (redacted, key-refusal.ts' one rule) and
|
|
491
|
+
* no loopback address. */
|
|
492
|
+
export const shownOf = (values) => (text) => withoutLoopback(redacted(text, values));
|
|
493
|
+
/** A run's error as its view and the run lists serve it: its message, and its detail strings, in `shown`'s terms. */
|
|
494
|
+
export const servedRunErrorWith = (shown, error) => ({ ...error, message: shown(error.message), ...(error.details !== undefined ? { details: cutStrings(error.details, shown) } : {}) });
|
|
495
|
+
/** A run's review as its view serves it: its reason (an escalation's own words) in `shown`'s terms, or withheld as its
|
|
496
|
+
* other words are while the run is hidden (`unshown`), as a list row read from disk withholds it. */
|
|
497
|
+
export const servedReviewWith = (shown, unshown, review) => (review && { ...review, reason: unshown ? WITHHELD_SIGN_IN : shown(review.reason) });
|
|
498
|
+
/** The pointers a run was handed, read back to cut them (sign-ins.ts peek and forgotten), by its `sign_in_handed`: none
|
|
499
|
+
* for a run with no mark (it was never handed one); else, for each hash it names, the live or forgotten pointer whose
|
|
500
|
+
* SHA-256 it is. `unreadable` when what it was handed can't be read back here: a MALFORMED mark, no vendor browser kept
|
|
501
|
+
* beside the mark, the sign-ins file can't be read, or any of its hashes matches no pointer that opens (one under another
|
|
502
|
+
* seal key or none, one forgotten and dropped past MAX_FORGOTTEN, the sign-ins file gone). Fails closed: a marked run is
|
|
503
|
+
* cut of every pointer it was handed, or withheld, never served uncut. Read anew at each call: nothing caches this
|
|
504
|
+
* verdict, so a run withheld while its key was missing is shown once it opens. */
|
|
505
|
+
export async function handedPointers(signIns, agentId, browser, handed) {
|
|
506
|
+
if (handed === undefined)
|
|
507
|
+
return { refs: [] };
|
|
508
|
+
if (handed === MALFORMED || !signIns || !browser)
|
|
509
|
+
return "unreadable";
|
|
510
|
+
const live = await signIns.peek(agentId, browser).catch(() => "unreadable");
|
|
511
|
+
const gone = await signIns.forgotten(agentId, browser).catch(() => "unreadable");
|
|
512
|
+
if (gone === "unreadable")
|
|
513
|
+
return "unreadable";
|
|
514
|
+
const kept = [...(typeof live === "object" ? [live.ref] : []), ...gone.refs];
|
|
515
|
+
const refs = handed.map((hash) => kept.find((ref) => pointerHash(ref) === hash));
|
|
516
|
+
return refs.every((ref) => ref !== undefined) ? { refs: refs } : "unreadable";
|
|
517
|
+
}
|
|
518
|
+
/** shown() for a run this server holds no Run for (an ended one a list reads from its row and serve.json alone): cut of
|
|
519
|
+
* every secret this server never shows (serverSecrets) and of what the run was handed of its agent's sign-in
|
|
520
|
+
* (handedPointers); `withheld` when that can't be read back here, as a load would hide the run. `browser` and `handed`
|
|
521
|
+
* come from the run's record (its plane's vendor browser and its `sign_in_handed` mark); `damaged` when the record was
|
|
522
|
+
* there but unreadable, so what it was handed went with it. This is the summary choke point. */
|
|
523
|
+
export async function rowShown(deps, agentId, browser, handed, damaged = false) {
|
|
524
|
+
if (damaged)
|
|
525
|
+
return "withheld";
|
|
526
|
+
const pointers = await handedPointers(deps.signIns, agentId, browser, handed);
|
|
527
|
+
if (pointers === "unreadable")
|
|
528
|
+
return "withheld";
|
|
529
|
+
const values = [...deps.serverSecrets(), ...pointers.refs.filter((ref) => ref.length >= MIN_SECRET)];
|
|
530
|
+
return (text) => withoutLoopback(redacted(text, values));
|
|
531
|
+
}
|
|
532
|
+
/** A call that waited for approval, once its outcome shows below its approval: its own rows (the call's, its result's) say
|
|
533
|
+
* only that it was held. A client folds them into the call's step, at the call's place above the approval row. */
|
|
534
|
+
export const HELD = "Held for your approval";
|
|
535
|
+
/** At most this many code points of a person's note on a row's summary; the record keeps it whole. */
|
|
536
|
+
export const NOTE_CHARS = 200;
|
|
537
|
+
/** `text` cut to `max` code points, an ellipsis last when cut: a pair of surrogates is never halved. */
|
|
538
|
+
export const clipPoints = (text, max) => {
|
|
539
|
+
const points = Array.from(text);
|
|
540
|
+
return points.length > max ? `${points.slice(0, max - 1).join("")}…` : text;
|
|
541
|
+
};
|
|
542
|
+
/** A person's note as a row's summary shows it: redacted whole with the run's redactor (`redact`), its links' query values
|
|
543
|
+
* elided (scrubUrls), its first non-empty line, cut to NOTE_CHARS code points. None for an empty note. */
|
|
544
|
+
export function noteShown(note, redact) {
|
|
545
|
+
if (!note?.trim())
|
|
546
|
+
return undefined;
|
|
547
|
+
const line = scrubUrls(redact(note)).split(/\r?\n/).map((part) => part.trim()).find(Boolean);
|
|
548
|
+
return line ? clipPoints(line, NOTE_CHARS) : undefined;
|
|
549
|
+
}
|
|
550
|
+
/** What came of an approval, as its outcome row's summary says it. A deny: "You declined <tool>: <note>" (one colon), or
|
|
551
|
+
* "You declined <tool>." with none; a declining message adds nothing (it shows as the person's own row). An allow: that it
|
|
552
|
+
* ran and where its result went, or that it failed; a note sent with an allow is shown nowhere, as on main. */
|
|
553
|
+
export function outcomeSays(tool, answer, failed, redact) {
|
|
554
|
+
if (answer.decision === "deny") {
|
|
555
|
+
if (answer.by === "message")
|
|
556
|
+
return `AgentRun: Your message declined ${tool}.`;
|
|
557
|
+
const note = noteShown(answer.note, redact);
|
|
558
|
+
return note ? `AgentRun: You declined ${tool}: ${note}` : `AgentRun: You declined ${tool}.`;
|
|
559
|
+
}
|
|
560
|
+
return `AgentRun: ${tool} ran once you allowed it${failed ? ", and failed" : "; its result went to the agent"}`;
|
|
561
|
+
}
|
|
562
|
+
/** What a person reads when they open the outcome row: the outcome, then the call's result (`rest`), or the refusal's words.
|
|
563
|
+
* An empty result says so: "Its result: (no output)", never "Its result:" and nothing. */
|
|
564
|
+
export function outcomeShows(tool, answer, rest, failed) {
|
|
565
|
+
if (answer.decision === "deny")
|
|
566
|
+
return `${answer.by === "message" ? `Your message declined ${tool}.` : `You declined ${tool}.`}${rest.trim() ? `\n${rest.trim()}` : ""}`;
|
|
567
|
+
const head = `${tool} ran once you allowed it${failed ? ", and failed" : ""}.`;
|
|
568
|
+
return rest.trim() ? `${head} Its result:\n${rest}` : `${head} Its result: (no output)`;
|
|
569
|
+
}
|
|
570
|
+
/** A call's own rows (its call's, its result's) before its outcome shows: what came of the approval so far. */
|
|
571
|
+
function callSays(answer) {
|
|
572
|
+
if (!answer)
|
|
573
|
+
return "Not run yet: it waits for your approval";
|
|
574
|
+
if (answer.decision === "canceled")
|
|
575
|
+
return "Not run: the run was cancelled while it waited";
|
|
576
|
+
if (answer.decision === "withdrawn")
|
|
577
|
+
return answer.ended ? "Not run: the run ended while it waited" : "Not run: the run was stopped while it waited";
|
|
578
|
+
return "Allowed: it runs now";
|
|
579
|
+
}
|
|
580
|
+
/** A synthesized row's id: the approval's own, so a pass over rows this function gave drops and remakes it. */
|
|
581
|
+
const approvalRowId = (callId) => `approval:${callId}`;
|
|
582
|
+
/** The rows of a run whose calls waited for approval, as the runner writes it (store-view.ts): the gate's ask
|
|
583
|
+
* (agentrun.ask, `asks`) and the person's answer (agentrun.answer, `answers`) are journal entries, and an allowed call runs
|
|
584
|
+
* in place, so its result row is its real result; a denied one's is the refusal. Each such call reads in order: its own
|
|
585
|
+
* rows, then the approval row, then, once there is one, the outcome row; its own rows say only that it was held once the
|
|
586
|
+
* outcome shows below, and before that what came of the approval so far. Arguments and notes go through `redact`, the
|
|
587
|
+
* run's redactor, before any cut. The rows this function makes are dropped first, so a pass over its own output gives the
|
|
588
|
+
* same rows. */
|
|
589
|
+
export function withApprovalRows(rows, asks, answers, redact) {
|
|
590
|
+
if (!asks.size)
|
|
591
|
+
return [...rows];
|
|
592
|
+
const given = rows.filter((row) => !row.id.startsWith("approval:"));
|
|
593
|
+
const byCall = new Map([...asks.values()].map((approval) => [approval.call_id, approval]));
|
|
594
|
+
const owns = (row) => (row.kind === "tool_use" || row.kind === "tool_result") && !!row.tool_use_id && byCall.has(row.tool_use_id);
|
|
595
|
+
const lastOf = new Map();
|
|
596
|
+
for (const row of given)
|
|
597
|
+
if (owns(row))
|
|
598
|
+
lastOf.set(row.tool_use_id, row.id);
|
|
599
|
+
return given.flatMap((row) => {
|
|
600
|
+
if (!owns(row))
|
|
601
|
+
return [row];
|
|
602
|
+
const approval = byCall.get(row.tool_use_id);
|
|
603
|
+
const answer = answers[approval.id];
|
|
604
|
+
const result = given.find((other) => other.kind === "tool_result" && other.tool_use_id === approval.call_id);
|
|
605
|
+
// The outcome shows once there is one: a deny's at once, an allow's when its call's result is in.
|
|
606
|
+
const outcome = answer?.decision === "deny" || (answer?.decision === "allow" && result !== undefined);
|
|
607
|
+
const own = { ...row, summary: outcome ? HELD : callSays(answer), tool_status: null };
|
|
608
|
+
if (lastOf.get(approval.call_id) !== row.id)
|
|
609
|
+
return [own];
|
|
610
|
+
const args = shownArgs(approval, redact);
|
|
611
|
+
const head = !answer ? "Waiting for your approval" : answer.decision === "canceled" ? "Withdrawn when the run was cancelled" : answer.decision === "withdrawn" ? (answer.ended ? "Withdrawn when the run ended" : "Withdrawn when the run was stopped") : answer.by === "message" ? "Declined by your message" : "Asked your approval";
|
|
612
|
+
const asked = { ...row, id: approvalRowId(approval.call_id), kind: APPROVAL_ROW, summary: `${head}: ${approval.tool} ${clip(args, 400)}`, text: args, tool_name: approval.tool, tool_status: null, tool_input_preview: clip(args, 500), tool_result_preview: null, tool_result_size_bytes: null };
|
|
613
|
+
if (!outcome)
|
|
614
|
+
return [own, asked];
|
|
615
|
+
const failed = answer.decision === "allow" && result?.tool_status === "failed";
|
|
616
|
+
// The result's words: a tool_result row keeps them as its preview (the renderer's, redacted and cut), its text empty.
|
|
617
|
+
const told = { ...(result ?? row), id: `${approvalRowId(approval.call_id)}:outcome`, kind: "phase", origin: "server", summary: outcomeSays(approval.tool, answer, failed, redact), text: outcomeShows(approval.tool, answer, redact(result?.text || result?.tool_result_preview || ""), failed), tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null };
|
|
618
|
+
return [own, asked, told];
|
|
619
|
+
});
|
|
620
|
+
}
|