@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-db.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// How the server opens a run's database, run.sqlite, which the run's own process writes: in WAL, under an exclusive lock,
|
|
2
|
+
// with no automatic checkpoint, and ended by process.exit with no close (pi-durable-disk's exclusive profile, keepWal),
|
|
3
|
+
// so its WAL stays until whoever takes the run back checkpoints it. The server never opens it read-write while a
|
|
4
|
+
// process holds the run: every read is a fresh read-only open with no locking (`vfs=unix-none`) and an exclusive
|
|
5
|
+
// locking mode (the WAL index in heap, no -shm), kept for that read alone, since a connection kept open falls behind
|
|
6
|
+
// the WAL; and a read whose last entry is below one already seen for that run is refused, never shown (the monotonic
|
|
7
|
+
// guard). The one read-write open is the checkpoint when the server takes the run back (runs.ts), with no process left.
|
|
8
|
+
import { closeSync, openSync, readSync, statSync } from "node:fs";
|
|
9
|
+
import { DatabaseSync } from "node:sqlite";
|
|
10
|
+
import { forgetWalWalk, walHasCommit } from "@parcha/agentrun-pi/durable";
|
|
11
|
+
import { profilePragmas } from "@parcha/pi-durable-disk/internals";
|
|
12
|
+
const observers = new Set();
|
|
13
|
+
/** Tells `observer` of every open of a run's database from here on (tests); the returned call stops it. */
|
|
14
|
+
export function observeRunDbOpens(observer) {
|
|
15
|
+
observers.add(observer);
|
|
16
|
+
return () => void observers.delete(observer);
|
|
17
|
+
}
|
|
18
|
+
/** `file` as a SQLite URI path: each segment percent-encoded, so a `?`, `#` or `%` in it is never read as a parameter. */
|
|
19
|
+
const uriPath = (file) => file.split("/").map(encodeURIComponent).join("/");
|
|
20
|
+
/** What says run database `file` changed: its inode, size and modification time, and its header's file change counter and
|
|
21
|
+
* page count (bytes 24 to 31). In WAL mode SQLite does not bump the counter at each commit, but a checkpoint writes the
|
|
22
|
+
* database file, so its time and size move; a reader of the file alone compares this before and after its read. */
|
|
23
|
+
function fileMark(file) {
|
|
24
|
+
const at = statSync(file, { bigint: true });
|
|
25
|
+
const header = Buffer.alloc(8);
|
|
26
|
+
const fd = openSync(file, "r");
|
|
27
|
+
try {
|
|
28
|
+
readSync(fd, header, 0, 8, 24);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
closeSync(fd);
|
|
32
|
+
}
|
|
33
|
+
return `${at.ino}:${at.size}:${at.mtimeNs}:${header.toString("hex")}`;
|
|
34
|
+
}
|
|
35
|
+
/** Tests' seams: `afterPlan`, called between a read's choice of how to open the file and its open; `madeReads`, called
|
|
36
|
+
* with each MonotonicReads made; `beforeCheckpoint`, called with the take-back's connection just before its close. */
|
|
37
|
+
export const runDbTestHooks = {};
|
|
38
|
+
/** A read of a run's database file alone whose file changed during it (a run's process wrote and a take-back checkpointed
|
|
39
|
+
* meanwhile), every try: none of them is shown. */
|
|
40
|
+
export class ChangedReadError extends Error {
|
|
41
|
+
constructor(file, tries) {
|
|
42
|
+
super(`the run's database ${file} changed during each of ${tries} reads`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** How many times a read whose file changed during it is made again before ChangedReadError. */
|
|
46
|
+
const READ_TRIES = 3;
|
|
47
|
+
/**
|
|
48
|
+
* One read of run database `file`: `read(db)` on a fresh read-only, lock-free connection, closed after it. A WAL that
|
|
49
|
+
* holds a commit SQLite's recovery takes (walHasCommit): opened with no locking (`vfs=unix-none`), the WAL read too. No
|
|
50
|
+
* WAL, or one with no verified commit yet (a fresh WAL's first transaction, its frames written and no commit): the
|
|
51
|
+
* database file alone, as an immutable file, which is whole then; its read is kept only when the file did not change
|
|
52
|
+
* during it (fileMark), else it is dropped and made again. SQLite's lock-free reader of a WAL with no commit recovers no
|
|
53
|
+
* frame, and its close, a checkpoint with nothing to copy, removes the WAL (sqlite3WalClose) under the writer still
|
|
54
|
+
* writing it, whose commits are then lost; with a commit, that close's checkpoint must write the database file, which
|
|
55
|
+
* this read-only connection cannot, so it fails and removes nothing. Every read and the take-back's checkpoint run in one
|
|
56
|
+
* turn of this process's event loop, and the run's process only appends to its WAL, so the WAL a read opens holds at
|
|
57
|
+
* least the commit its check saw. A read-only close checkpoints nothing it can write. `held`: whether a process holds the
|
|
58
|
+
* run now (reported to observers).
|
|
59
|
+
*/
|
|
60
|
+
export function readRunDbSync(file, held, read) {
|
|
61
|
+
for (let attempt = 1;; attempt++) {
|
|
62
|
+
for (const observer of observers)
|
|
63
|
+
observer({ file, mode: "read", held });
|
|
64
|
+
// A WAL is opened only once it holds a commit SQLite's recovery takes (agentrun-pi walHasCommit).
|
|
65
|
+
const immutable = !walHasCommit(`${file}-wal`);
|
|
66
|
+
const before = immutable ? fileMark(file) : undefined;
|
|
67
|
+
runDbTestHooks.afterPlan?.(file);
|
|
68
|
+
const db = new DatabaseSync(immutable ? `file:${uriPath(file)}?mode=ro&immutable=1` : `file:${uriPath(file)}?mode=ro&vfs=unix-none`, { readOnly: true });
|
|
69
|
+
let result;
|
|
70
|
+
try {
|
|
71
|
+
db.exec("PRAGMA locking_mode = EXCLUSIVE");
|
|
72
|
+
result = read(db);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
db.close();
|
|
76
|
+
}
|
|
77
|
+
if (!immutable || fileMark(file) === before)
|
|
78
|
+
return result;
|
|
79
|
+
for (const observer of observers)
|
|
80
|
+
observer({ file, mode: "dropped", held });
|
|
81
|
+
if (attempt >= READ_TRIES)
|
|
82
|
+
throw new ChangedReadError(file, attempt);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** readRunDbSync, for an async caller. */
|
|
86
|
+
export async function readRunDb(file, held, read) {
|
|
87
|
+
return readRunDbSync(file, held, read);
|
|
88
|
+
}
|
|
89
|
+
/** A read of a run's database whose last entry is below one already seen for that run: an older view of the file, which a
|
|
90
|
+
* read must never show (the monotonic guard). The caller keeps what it read before. */
|
|
91
|
+
export class BehindReadError extends Error {
|
|
92
|
+
seen;
|
|
93
|
+
read;
|
|
94
|
+
constructor(seen, read) {
|
|
95
|
+
super(`the run's database read ends at entry ${read}, behind entry ${seen} read before`);
|
|
96
|
+
this.seen = seen;
|
|
97
|
+
this.read = read;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** The highest entry id each run's reads have seen: a read below it is refused (BehindReadError). */
|
|
101
|
+
export class MonotonicReads {
|
|
102
|
+
#seen = new Map();
|
|
103
|
+
constructor() {
|
|
104
|
+
runDbTestHooks.madeReads?.(this);
|
|
105
|
+
}
|
|
106
|
+
/** How many runs' reads it keeps. */
|
|
107
|
+
get size() {
|
|
108
|
+
return this.#seen.size;
|
|
109
|
+
}
|
|
110
|
+
/** Accepts run `runId`'s read that ends at entry `last` (0 for none), or throws BehindReadError. */
|
|
111
|
+
accept(runId, last) {
|
|
112
|
+
const seen = this.#seen.get(runId) ?? 0;
|
|
113
|
+
if (last < seen)
|
|
114
|
+
throw new BehindReadError(seen, last);
|
|
115
|
+
this.#seen.set(runId, last);
|
|
116
|
+
}
|
|
117
|
+
/** Forgets run `runId`'s reads: a run that is gone, or whose store was replaced. */
|
|
118
|
+
forget(runId) {
|
|
119
|
+
this.#seen.delete(runId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** A read-write open of a run's database while a process holds the run: refused, never made. */
|
|
123
|
+
export class HeldRunDbError extends Error {
|
|
124
|
+
constructor(file) {
|
|
125
|
+
super(`the server never opens a run's database read-write while a process holds the run (${file})`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Checkpoints the run database at `file` into its database file and removes its WAL, once no process holds the run
|
|
129
|
+
* (`held` false; true throws HeldRunDbError before any open). A database with no WAL left is untouched but for the
|
|
130
|
+
* open. The one read-write open the server makes of a run's database. */
|
|
131
|
+
export async function checkpointRunDb(file, held, platform = process.platform) {
|
|
132
|
+
for (const observer of observers)
|
|
133
|
+
observer({ file, mode: "checkpoint", held });
|
|
134
|
+
if (held)
|
|
135
|
+
throw new HeldRunDbError(file);
|
|
136
|
+
const db = new DatabaseSync(file, { timeout: 0 });
|
|
137
|
+
try {
|
|
138
|
+
// As its writer opened it (pi-durable-disk's exclusive profile): the WAL index in heap, so no -shm is made; and on
|
|
139
|
+
// macOS F_FULLFSYNC (`fullfsync`, `checkpoint_fullfsync`), as fsync there leaves the drive's cache unflushed. And
|
|
140
|
+
// synchronous FULL whatever level the run's journal runs at, so the checkpoint's copy is synced into the database file
|
|
141
|
+
// before the WAL that held it is removed (pi-durable-disk barriers.ts lists this store as FULL).
|
|
142
|
+
for (const [pragma, value] of Object.entries(profilePragmas("exclusive", platform, "FULL")))
|
|
143
|
+
db.exec(`PRAGMA ${pragma} = ${value}`);
|
|
144
|
+
db.prepare("SELECT count(*) FROM sqlite_schema").get();
|
|
145
|
+
runDbTestHooks.beforeCheckpoint?.(db);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
// The close checkpoints: it copies into the database file only pages the WAL holds too, so a lock-free reader still
|
|
149
|
+
// reading the WAL reads the same bytes either way; then it removes the WAL, which a reader that holds it open goes on
|
|
150
|
+
// reading. Never wal_checkpoint(TRUNCATE): that cuts the WAL under such a reader, whose read then fails.
|
|
151
|
+
db.close();
|
|
152
|
+
// The WAL is gone, and with it what was kept of its walk (walHasCommit).
|
|
153
|
+
forgetWalWalk(`${file}-wal`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { type Entry, type Workspace } from "./workspace/index.js";
|
|
3
|
+
/** How many folders deep the list goes: a folder below it is not entered, and the list says it is not whole. */
|
|
4
|
+
export declare const WALK_DEPTH = 16;
|
|
5
|
+
/** The CSP a served HTML file runs under: an opaque origin, no scripts, no network. */
|
|
6
|
+
export declare const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox; form-action 'none'";
|
|
7
|
+
export type FileView = {
|
|
8
|
+
path: string;
|
|
9
|
+
size_bytes: number;
|
|
10
|
+
modified_at: string;
|
|
11
|
+
content_type: string | null;
|
|
12
|
+
unreadable?: true;
|
|
13
|
+
};
|
|
14
|
+
/** File `path` as the API lists it, from its Workspace listing entry. */
|
|
15
|
+
export declare const viewOf: (path: string, entry: Entry) => FileView;
|
|
16
|
+
/** The files of `workspace`, walked from its root: each file's own size and time, a dot-name and all below it left
|
|
17
|
+
* out. It stops past `cap` files. `deep` when a folder more than WALK_DEPTH deep was there and not entered. A name at
|
|
18
|
+
* the root that `owned` says is the host's (an agent home's learning/) is named in `owned`, and nothing below it read. */
|
|
19
|
+
export declare function listFiles(workspace: Workspace, cap: number, { owned: isOwned }?: {
|
|
20
|
+
owned?: (name: string) => boolean;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
files: FileView[];
|
|
23
|
+
deep: boolean;
|
|
24
|
+
owned: string[];
|
|
25
|
+
}>;
|
|
26
|
+
/** The listing entry at `rel`, a file's or a folder's, or undefined when there is none: not there, or a link (never
|
|
27
|
+
* listed). */
|
|
28
|
+
export declare function entryAt(workspace: Workspace, rel: string): Promise<Entry | undefined>;
|
|
29
|
+
/** File `rel` of `workspace`, raw, in reads of SEND_CHUNK: its length from the listing, so HEAD reads no byte. `who`
|
|
30
|
+
* names who makes a file private, in the words of a 403. */
|
|
31
|
+
export declare function sendFile(req: IncomingMessage, res: ServerResponse, url: URL, workspace: Workspace, rel: string, who: string): Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
import { INLINE_TYPES, typeOf } from "./file-types.js";
|
|
3
|
+
import { isWorkspaceError } from "./workspace/index.js";
|
|
4
|
+
/** How many folders deep the list goes: a folder below it is not entered, and the list says it is not whole. */
|
|
5
|
+
export const WALK_DEPTH = 16;
|
|
6
|
+
/** How much one read of a file being sent takes. */
|
|
7
|
+
const SEND_CHUNK = 4 * 1024 * 1024;
|
|
8
|
+
/** The CSP a served HTML file runs under: an opaque origin, no scripts, no network. */
|
|
9
|
+
export const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox; form-action 'none'";
|
|
10
|
+
/** File `path` as the API lists it, from its Workspace listing entry. */
|
|
11
|
+
export const viewOf = (path, entry) => ({
|
|
12
|
+
path, size_bytes: entry.size, modified_at: new Date(entry.mtimeMs).toISOString(), content_type: typeOf(path) ?? null, ...(entry.unreadable ? { unreadable: true } : {}),
|
|
13
|
+
});
|
|
14
|
+
/** A folder the list skips, saying nothing: not there, a link on the way, or one this server may not enter. A backend
|
|
15
|
+
* that cannot answer (UNAVAILABLE, TIMEOUT) fails the list. */
|
|
16
|
+
const skipped = (error) => isWorkspaceError(error) && (error.code === "NOT_FOUND" || error.code === "ESCAPE" || error.code === "REFUSED");
|
|
17
|
+
/** The files of `workspace`, walked from its root: each file's own size and time, a dot-name and all below it left
|
|
18
|
+
* out. It stops past `cap` files. `deep` when a folder more than WALK_DEPTH deep was there and not entered. A name at
|
|
19
|
+
* the root that `owned` says is the host's (an agent home's learning/) is named in `owned`, and nothing below it read. */
|
|
20
|
+
export async function listFiles(workspace, cap, { owned: isOwned } = {}) {
|
|
21
|
+
const files = [];
|
|
22
|
+
const owned = [];
|
|
23
|
+
let deep = false;
|
|
24
|
+
const into = async (dir, level) => {
|
|
25
|
+
let entries;
|
|
26
|
+
try {
|
|
27
|
+
entries = await workspace.list(dir);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (skipped(error))
|
|
31
|
+
return true;
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
if (entry.name.startsWith("."))
|
|
36
|
+
continue;
|
|
37
|
+
if (dir === "" && isOwned?.(entry.name)) {
|
|
38
|
+
owned.push(entry.name);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const path = dir === "" ? entry.name : `${dir}/${entry.name}`;
|
|
42
|
+
if (entry.kind === "file") {
|
|
43
|
+
files.push(viewOf(path, entry));
|
|
44
|
+
if (files.length > cap)
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
else if (level + 1 > WALK_DEPTH)
|
|
48
|
+
deep = true;
|
|
49
|
+
else if (!(await into(path, level + 1)))
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
await into("", 0);
|
|
55
|
+
return { files, deep, owned };
|
|
56
|
+
}
|
|
57
|
+
/** The listing entry at `rel`, a file's or a folder's, or undefined when there is none: not there, or a link (never
|
|
58
|
+
* listed). */
|
|
59
|
+
export async function entryAt(workspace, rel) {
|
|
60
|
+
const cut = rel.lastIndexOf("/");
|
|
61
|
+
const name = rel.slice(cut + 1);
|
|
62
|
+
try {
|
|
63
|
+
return (await workspace.list(cut < 0 ? "" : rel.slice(0, cut))).find((entry) => entry.name === name);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (skipped(error))
|
|
67
|
+
return undefined;
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** The listing entry of file `rel`, or undefined when there is none: not there, a link (never listed), a folder. */
|
|
72
|
+
const fileEntry = async (workspace, rel) => {
|
|
73
|
+
const entry = await entryAt(workspace, rel);
|
|
74
|
+
return entry?.kind === "file" ? entry : undefined;
|
|
75
|
+
};
|
|
76
|
+
/** File `rel` of `workspace`, raw, in reads of SEND_CHUNK: its length from the listing, so HEAD reads no byte. `who`
|
|
77
|
+
* names who makes a file private, in the words of a 403. */
|
|
78
|
+
export async function sendFile(req, res, url, workspace, rel, who) {
|
|
79
|
+
const unreadable = () => new ApiError("system_file_forbidden", `This file was created private by ${who}: this server cannot read it.`, { details: { reason: "unreadable" } });
|
|
80
|
+
const entry = await fileEntry(workspace, rel);
|
|
81
|
+
if (!entry)
|
|
82
|
+
throw new ApiError("not_found", "no such file");
|
|
83
|
+
if (entry.unreadable)
|
|
84
|
+
throw unreadable();
|
|
85
|
+
// A GET reads its first chunk before the head: a file gone, or swapped for a link, since the listing is a 404, not a
|
|
86
|
+
// broken 200. A HEAD reads none.
|
|
87
|
+
const first = req.method === "HEAD" ? new Uint8Array(0) : await workspace.read(rel, { offset: 0, length: Math.min(SEND_CHUNK, entry.size) }).catch((error) => {
|
|
88
|
+
if (isWorkspaceError(error, "REFUSED"))
|
|
89
|
+
throw unreadable();
|
|
90
|
+
if (skipped(error))
|
|
91
|
+
throw new ApiError("not_found", "no such file");
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
94
|
+
const type = typeOf(rel) ?? "application/octet-stream";
|
|
95
|
+
const download = url.searchParams.get("download") === "1" || !INLINE_TYPES.has(type);
|
|
96
|
+
const name = rel.split("/").at(-1).replace(/[^\w.-]/g, "_");
|
|
97
|
+
res.writeHead(200, {
|
|
98
|
+
"content-type": type,
|
|
99
|
+
"content-length": entry.size,
|
|
100
|
+
"x-content-type-options": "nosniff",
|
|
101
|
+
"cache-control": "no-store",
|
|
102
|
+
...(type.startsWith("text/html") ? { "content-security-policy": FILE_CSP } : {}),
|
|
103
|
+
...(download ? { "content-disposition": `attachment; filename="${name}"` } : {}),
|
|
104
|
+
});
|
|
105
|
+
if (req.method === "HEAD")
|
|
106
|
+
return void res.end();
|
|
107
|
+
// The length said is the listing's: a file that changes while it is sent is cut there, or the answer ends short.
|
|
108
|
+
try {
|
|
109
|
+
let sent = 0;
|
|
110
|
+
for (let chunk = first;; chunk = await workspace.read(rel, { offset: sent, length: Math.min(SEND_CHUNK, entry.size - sent) })) {
|
|
111
|
+
if (chunk.length === 0 || res.destroyed)
|
|
112
|
+
break;
|
|
113
|
+
if (!res.write(chunk))
|
|
114
|
+
await new Promise((resolve) => { res.once("drain", resolve); res.once("close", resolve); });
|
|
115
|
+
sent += chunk.length;
|
|
116
|
+
if (sent >= entry.size)
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Mid-answer there is no status left to give: the answer ends, short of its length, which the client sees.
|
|
122
|
+
return void res.destroy();
|
|
123
|
+
}
|
|
124
|
+
res.end();
|
|
125
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ProcessTable } from "@parcha/pi-durable-disk/internals";
|
|
2
|
+
/** Tests' seam: a process table read in place of this machine's (pi-durable-disk processTable: /proc on Linux, ps on
|
|
3
|
+
* macOS, where a process's environment is read with `ps -E`). */
|
|
4
|
+
export declare const runHolderTestHooks: {
|
|
5
|
+
table?: ProcessTable;
|
|
6
|
+
};
|
|
7
|
+
/** What a launch's claim names until its process is spawned and named in its place. */
|
|
8
|
+
export declare const LAUNCH_HOLDER = "launching";
|
|
9
|
+
/** The mark a launch puts in its process's environment, `<run id>:<epoch>`: how a row that still names LAUNCH_HOLDER (its
|
|
10
|
+
* server went, or its store was held, before the process was named) finds the process that launch started. */
|
|
11
|
+
export declare const RUN_LAUNCH_ENV = "AGENTRUN_RUN_LAUNCH";
|
|
12
|
+
/** The epoch of the run's claim its process was launched under (runs.ts launch): a run process reads it here to label the
|
|
13
|
+
* box it makes (run-box.ts EPOCH_LABEL). */
|
|
14
|
+
export declare const RUN_EPOCH_ENV = "AGENTRUN_RUN_EPOCH";
|
|
15
|
+
/** A run's process as its row names it. */
|
|
16
|
+
export type RunHolder = {
|
|
17
|
+
pid: number;
|
|
18
|
+
start: number;
|
|
19
|
+
boot: string | null;
|
|
20
|
+
door?: string;
|
|
21
|
+
nonce?: string;
|
|
22
|
+
};
|
|
23
|
+
/** The holder a row's claim names, or undefined for none, the server (a take-back) or anything that is not one. */
|
|
24
|
+
export declare function holderOf(claim: string | null | undefined): RunHolder | undefined;
|
|
25
|
+
/** Process `pid` as a holder: its start and this boot, read now; undefined once it is gone, or when the process listing
|
|
26
|
+
* cannot be read (its identity is then not known, and nothing is named for it). */
|
|
27
|
+
export declare function holderOfProcess(pid: number): RunHolder | undefined;
|
|
28
|
+
/** The live processes run `runId`'s launch at `epoch` started, by their mark (RUN_LAUNCH_ENV). Throws when the processes
|
|
29
|
+
* cannot be listed: a process is never taken for gone on a failed look. */
|
|
30
|
+
export declare function launchedProcesses(runId: string, epoch: number): RunHolder[];
|
|
31
|
+
/** The process a row's claim (`holder` at `epoch`) names: the one it names outright, or for a launch not yet named, the
|
|
32
|
+
* one that launch started; undefined for none or the server. */
|
|
33
|
+
export declare function holderOfClaim(runId: string, claim: {
|
|
34
|
+
epoch: number;
|
|
35
|
+
holder: string | null;
|
|
36
|
+
}): RunHolder | undefined;
|
|
37
|
+
/** What can be told of `holder`'s process: `alive` (its pid names a process of the same start, on this boot), `gone`, or
|
|
38
|
+
* `unknown` (the process listing, or this boot's id, cannot be read). Unknown is never taken for gone, nor for a
|
|
39
|
+
* process that may be killed, however long it lasts. */
|
|
40
|
+
export type HolderState = "alive" | "gone" | "unknown";
|
|
41
|
+
export declare function holderState(holder: RunHolder): HolderState;
|
|
42
|
+
/** Whether `holder`'s process may live: alive, or unknown (never taken over on a look that failed). */
|
|
43
|
+
export declare function holderLives(holder: RunHolder): boolean;
|
|
44
|
+
/** Kills `holder`'s process with SIGKILL when it is confirmed alive, without waiting: true when it was. Never this
|
|
45
|
+
* process. An identity that cannot be checked throws: nothing is killed unidentified, and its caller claims nothing. */
|
|
46
|
+
export declare function killHolder(holder: RunHolder): boolean;
|
|
47
|
+
/** Sends `name` to `pid`: true when it was sent. ESRCH (it exited since the look) and EPERM (the pid is another user's
|
|
48
|
+
* now, so not the holder's) are no error and send nothing: false, and no kill is tried again on either. */
|
|
49
|
+
export declare function signal(pid: number, name: NodeJS.Signals): boolean;
|
|
50
|
+
/** Kills `holder`'s process when it lives and waits until it is gone (at most `waitMs`, else it throws): what a claim
|
|
51
|
+
* over a holder does first. */
|
|
52
|
+
export declare function fenceHolder(holder: RunHolder | undefined, waitMs?: number): Promise<void>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Who holds a run, as its row's claim names it (store.sqlite claim_holder): the run's process by its pid, the start of
|
|
2
|
+
// that process (so a pid a later process reuses is never taken for it) and this machine's boot, its launch's door nonce,
|
|
3
|
+
// and, once its door has proven that nonce (door-line.ts), its door. The row's epoch is the whole lock: the server claims a run only from the epoch it read, and kills a holder that
|
|
4
|
+
// still lives before it claims over it, so no process of a lower epoch runs (or commits to the run's store) after the
|
|
5
|
+
// bump. The server writes the holder (launch, then the door its process names on stdout); the run's process never
|
|
6
|
+
// opens store.sqlite.
|
|
7
|
+
import { processTable } from "@parcha/pi-durable-disk/internals";
|
|
8
|
+
/** Tests' seam: a process table read in place of this machine's (pi-durable-disk processTable: /proc on Linux, ps on
|
|
9
|
+
* macOS, where a process's environment is read with `ps -E`). */
|
|
10
|
+
export const runHolderTestHooks = {};
|
|
11
|
+
const tableOf = () => runHolderTestHooks.table ?? processTable();
|
|
12
|
+
/** What a launch's claim names until its process is spawned and named in its place. */
|
|
13
|
+
export const LAUNCH_HOLDER = "launching";
|
|
14
|
+
/** The mark a launch puts in its process's environment, `<run id>:<epoch>`: how a row that still names LAUNCH_HOLDER (its
|
|
15
|
+
* server went, or its store was held, before the process was named) finds the process that launch started. */
|
|
16
|
+
export const RUN_LAUNCH_ENV = "AGENTRUN_RUN_LAUNCH";
|
|
17
|
+
/** The epoch of the run's claim its process was launched under (runs.ts launch): a run process reads it here to label the
|
|
18
|
+
* box it makes (run-box.ts EPOCH_LABEL). */
|
|
19
|
+
export const RUN_EPOCH_ENV = "AGENTRUN_RUN_EPOCH";
|
|
20
|
+
/** The holder a row's claim names, or undefined for none, the server (a take-back) or anything that is not one. */
|
|
21
|
+
export function holderOf(claim) {
|
|
22
|
+
if (typeof claim !== "string" || !claim.startsWith("{"))
|
|
23
|
+
return undefined;
|
|
24
|
+
let value;
|
|
25
|
+
try {
|
|
26
|
+
value = JSON.parse(claim);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const holder = value;
|
|
32
|
+
if (!Number.isSafeInteger(holder.pid) || holder.pid <= 0 || !Number.isSafeInteger(holder.start))
|
|
33
|
+
return undefined;
|
|
34
|
+
if (holder.boot !== null && typeof holder.boot !== "string")
|
|
35
|
+
return undefined;
|
|
36
|
+
if (holder.door !== undefined && typeof holder.door !== "string")
|
|
37
|
+
return undefined;
|
|
38
|
+
if (holder.nonce !== undefined && typeof holder.nonce !== "string")
|
|
39
|
+
return undefined;
|
|
40
|
+
return { pid: holder.pid, start: holder.start, boot: holder.boot ?? null, ...(holder.door === undefined ? {} : { door: holder.door }), ...(holder.nonce === undefined ? {} : { nonce: holder.nonce }) };
|
|
41
|
+
}
|
|
42
|
+
/** Process `pid` as a holder: its start and this boot, read now; undefined once it is gone, or when the process listing
|
|
43
|
+
* cannot be read (its identity is then not known, and nothing is named for it). */
|
|
44
|
+
export function holderOfProcess(pid) {
|
|
45
|
+
const table = tableOf();
|
|
46
|
+
try {
|
|
47
|
+
const start = table.snapshot().info(pid)?.start;
|
|
48
|
+
return start === undefined ? undefined : { pid, start, boot: table.bootId() ?? null };
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The live processes run `runId`'s launch at `epoch` started, by their mark (RUN_LAUNCH_ENV). Throws when the processes
|
|
55
|
+
* cannot be listed: a process is never taken for gone on a failed look. */
|
|
56
|
+
export function launchedProcesses(runId, epoch) {
|
|
57
|
+
const table = tableOf();
|
|
58
|
+
let look;
|
|
59
|
+
let marked;
|
|
60
|
+
try {
|
|
61
|
+
look = table.snapshot();
|
|
62
|
+
marked = look.withMark(RUN_LAUNCH_ENV, `${runId}:${epoch}`);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// Never a kill on a look that failed: whoever asked waits and tries again.
|
|
66
|
+
throw new Error(`the process its launch started cannot be looked for (${error.message}); it is never killed unidentified`, { cause: error });
|
|
67
|
+
}
|
|
68
|
+
const boot = table.bootId() ?? null;
|
|
69
|
+
// The run's process, not a command of it that inherited the mark: a marked process whose parent is not marked. A
|
|
70
|
+
// process whose environment cannot be read (another user's, or one inside an exec) carries no mark here, so it is
|
|
71
|
+
// never killed; the run's store, which such a process would hold, refuses a second writer by its own lock.
|
|
72
|
+
return marked.flatMap((pid) => {
|
|
73
|
+
const info = look.info(pid);
|
|
74
|
+
return info === undefined || marked.includes(info.ppid) ? [] : [{ pid, start: info.start, boot }];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** The process a row's claim (`holder` at `epoch`) names: the one it names outright, or for a launch not yet named, the
|
|
78
|
+
* one that launch started; undefined for none or the server. */
|
|
79
|
+
export function holderOfClaim(runId, claim) {
|
|
80
|
+
const named = holderOf(claim.holder);
|
|
81
|
+
if (named !== undefined || claim.holder !== LAUNCH_HOLDER)
|
|
82
|
+
return named;
|
|
83
|
+
return launchedProcesses(runId, claim.epoch)[0];
|
|
84
|
+
}
|
|
85
|
+
export function holderState(holder) {
|
|
86
|
+
const table = tableOf();
|
|
87
|
+
let boot;
|
|
88
|
+
let start;
|
|
89
|
+
try {
|
|
90
|
+
boot = table.bootId() ?? null;
|
|
91
|
+
if (holder.boot !== null && boot !== null && holder.boot !== boot)
|
|
92
|
+
return "gone";
|
|
93
|
+
start = table.snapshot().info(holder.pid)?.start;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return "unknown";
|
|
97
|
+
}
|
|
98
|
+
return start === holder.start ? "alive" : "gone";
|
|
99
|
+
}
|
|
100
|
+
/** Whether `holder`'s process may live: alive, or unknown (never taken over on a look that failed). */
|
|
101
|
+
export function holderLives(holder) {
|
|
102
|
+
return holderState(holder) !== "gone";
|
|
103
|
+
}
|
|
104
|
+
/** Kills `holder`'s process with SIGKILL when it is confirmed alive, without waiting: true when it was. Never this
|
|
105
|
+
* process. An identity that cannot be checked throws: nothing is killed unidentified, and its caller claims nothing. */
|
|
106
|
+
export function killHolder(holder) {
|
|
107
|
+
if (holder.pid === process.pid)
|
|
108
|
+
return false;
|
|
109
|
+
const state = holderState(holder);
|
|
110
|
+
if (state === "gone")
|
|
111
|
+
return false;
|
|
112
|
+
if (state === "unknown")
|
|
113
|
+
throw new Error(`the run's holder ${holder.pid} cannot be checked (the process listing failed): it is never killed unidentified, and nothing is claimed over it`);
|
|
114
|
+
return signal(holder.pid, "SIGKILL");
|
|
115
|
+
}
|
|
116
|
+
/** Sends `name` to `pid`: true when it was sent. ESRCH (it exited since the look) and EPERM (the pid is another user's
|
|
117
|
+
* now, so not the holder's) are no error and send nothing: false, and no kill is tried again on either. */
|
|
118
|
+
export function signal(pid, name) {
|
|
119
|
+
try {
|
|
120
|
+
process.kill(pid, name);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
const code = error.code;
|
|
125
|
+
if (code === "ESRCH" || code === "EPERM")
|
|
126
|
+
return false;
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Kills `holder`'s process when it lives and waits until it is gone (at most `waitMs`, else it throws): what a claim
|
|
131
|
+
* over a holder does first. */
|
|
132
|
+
export async function fenceHolder(holder, waitMs = 10_000) {
|
|
133
|
+
if (holder === undefined || !killHolder(holder))
|
|
134
|
+
return;
|
|
135
|
+
for (const end = Date.now() + waitMs; holderState(holder) !== "gone"; await new Promise((resolve) => setTimeout(resolve, 20))) {
|
|
136
|
+
if (Date.now() > end)
|
|
137
|
+
throw new Error(`the run's holder ${holder.pid} still lives ${waitMs / 1000} s after SIGKILL`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type MessageOrigin } from "@parcha/pi-durable-agent/timeline";
|
|
2
|
+
import type { Plane } from "./tool-plane.js";
|
|
3
|
+
import type { RunTrigger } from "./triggers.js";
|
|
4
|
+
import { type Json } from "./validate.js";
|
|
5
|
+
import type { Place } from "./workspace/place.js";
|
|
6
|
+
/** What a run is launched with: everything its runner needs to build the run's spec at its claim, nothing derived later.
|
|
7
|
+
* The server writes it once at start; the runner reads it at each claim (its claim rebuilds the run from the store, this
|
|
8
|
+
* body included). `harness` picks the loop's adapter (a built-in learning run names "learning"; absent, the revision's
|
|
9
|
+
* harness is used); `input` is the start request's body for a person's or a trigger's run, or an object a built-in run
|
|
10
|
+
* names (a learning run's `{ runId }`). `model`, `plane`, `approvers`, `documents` and `boxAllow` are the per-run choices
|
|
11
|
+
* the old path recomputed; here they are pinned at start, and optional (a built-in run may name none). */
|
|
12
|
+
export interface RunLaunch {
|
|
13
|
+
/** The start request's body, as the person or trigger gave it, or an object a built-in run names. */
|
|
14
|
+
readonly input: unknown;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly place: Place;
|
|
17
|
+
/** The loop's adapter, when not the revision's: a built-in learning run names "learning". */
|
|
18
|
+
readonly harness?: string;
|
|
19
|
+
/** The run's model, pinned at start. */
|
|
20
|
+
readonly model?: {
|
|
21
|
+
readonly provider: string;
|
|
22
|
+
readonly modelId: string;
|
|
23
|
+
};
|
|
24
|
+
readonly effort?: string;
|
|
25
|
+
readonly maxCostUsd?: number;
|
|
26
|
+
readonly capMode?: string;
|
|
27
|
+
/** The tool plane as the server resolved it at start (tool-plane.ts). */
|
|
28
|
+
readonly plane?: Plane;
|
|
29
|
+
/** Whether a person can answer a tool call's approval for this run. */
|
|
30
|
+
readonly approvers?: boolean;
|
|
31
|
+
/** The documents directory a workflow's reads are rooted at, when the server gives one. */
|
|
32
|
+
readonly documents?: string;
|
|
33
|
+
/** What a run's box may reach, as the server resolved it: the list, or "none". */
|
|
34
|
+
readonly boxAllow?: readonly string[] | "none";
|
|
35
|
+
/** The uploaded file ids the run was started with, in order (the create body's file_ids, already checked ready): the
|
|
36
|
+
* runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
|
|
37
|
+
readonly files?: readonly string[];
|
|
38
|
+
/** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
|
|
39
|
+
* no learning folder or git: `given`, the notes its # Learned section names (each `{file, name}`, as /runs/{id}/learning
|
|
40
|
+
* shows them); `seed`, the learning commit's sha (or null when the seed could not be read); and `section`, the exact
|
|
41
|
+
* # Learned text to lay into the prompt for those notes (what the old layLearned laid), within the learning budget; and
|
|
42
|
+
* `seedNotes`, the count of all notes in the seed before the budget picked `given` (present with a read seed; absent when
|
|
43
|
+
* the seed could not be read). Absent when the run does not learn. */
|
|
44
|
+
readonly learning?: {
|
|
45
|
+
readonly given: readonly {
|
|
46
|
+
readonly file: string;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
}[];
|
|
49
|
+
readonly seed: string | null;
|
|
50
|
+
readonly section: string;
|
|
51
|
+
readonly seedNotes?: number;
|
|
52
|
+
};
|
|
53
|
+
/** The trigger and firing that started the run, or none for a person's run. */
|
|
54
|
+
readonly trigger?: RunTrigger;
|
|
55
|
+
/** Who the first message is from, when not the person: kept only through the fail-safe below. */
|
|
56
|
+
readonly inputOrigin?: MessageOrigin;
|
|
57
|
+
/** A run that re-asks its agent after it ends (a trigger's follow-up). */
|
|
58
|
+
readonly followUp?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** The input's origin kept through the fail-safe (#1856): the stored one only if it names `trigger` with
|
|
61
|
+
* owner === (its source is a schedule), else that trigger's own with owner false (its source a best-effort label: the
|
|
62
|
+
* stored one when it is a known source other than a schedule's, else "webhook"). A run with no trigger keeps none. */
|
|
63
|
+
export declare function keepInputOrigin(stored: unknown, trigger: RunTrigger | null): MessageOrigin | undefined;
|
|
64
|
+
/** The JSON body the server stores for a run's launch. `harness` is a top-level field, so the loop factory reads it from the
|
|
65
|
+
* stored body without parsing the rest. */
|
|
66
|
+
export declare function launchBody(launch: RunLaunch): Json;
|
|
67
|
+
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
68
|
+
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
69
|
+
export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
|
|
70
|
+
/** The run's learning start (its given notes, its seed sha and its # Learned section), read from one place by learning's
|
|
71
|
+
* routes and the runner; undefined when the run does not learn. */
|
|
72
|
+
export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning"];
|