@parcha/agentrun-serve 0.1.0-beta.31 → 0.1.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +422 -0
- package/NOTICE +18 -0
- package/README.md +887 -241
- package/dist/adapter-facts.d.ts +3 -0
- package/dist/adapter-facts.js +5 -0
- package/dist/adapters.d.ts +64 -140
- package/dist/adapters.js +153 -377
- package/dist/agents-store.d.ts +146 -0
- package/dist/agents-store.js +359 -0
- package/dist/agents.d.ts +5 -3
- package/dist/agents.js +37 -17
- package/dist/app.d.ts +2 -4
- package/dist/app.js +207 -92
- package/dist/approvals.d.ts +4 -0
- package/dist/approvals.js +7 -0
- package/dist/archil-routes.d.ts +45 -0
- package/dist/archil-routes.js +150 -0
- package/dist/archil-settings.d.ts +30 -0
- package/dist/archil-settings.js +34 -0
- package/dist/background.js +28 -9
- package/dist/bounds.d.ts +26 -0
- package/dist/bounds.js +137 -0
- package/dist/box-egress-vm.d.ts +2 -1
- package/dist/box-egress-vm.js +20 -6
- package/dist/box-egress.d.ts +16 -6
- package/dist/box-egress.js +27 -15
- package/dist/box-paths.d.ts +59 -0
- package/dist/box-paths.js +92 -0
- package/dist/box-relay-vm.js +28 -1
- package/dist/box-relay.d.ts +2 -0
- package/dist/box-relay.js +2 -2
- package/dist/boxes.d.ts +13 -1
- package/dist/boxes.js +37 -3
- package/dist/browser-commands.d.ts +43 -0
- package/dist/browser-commands.js +154 -0
- package/dist/browser-cost.d.ts +30 -3
- package/dist/browser-cost.js +276 -21
- package/dist/browser-live.d.ts +124 -0
- package/dist/browser-live.js +324 -0
- package/dist/browser-person.d.ts +168 -0
- package/dist/browser-person.js +769 -0
- package/dist/budget.d.ts +80 -0
- package/dist/budget.js +211 -0
- package/dist/cap.d.ts +272 -62
- package/dist/cap.js +599 -189
- package/dist/cli.js +201 -17
- package/dist/coding-tools.d.ts +13 -1
- package/dist/coding-tools.js +107 -5
- package/dist/computer-adb.d.ts +12 -0
- package/dist/computer-adb.js +14 -0
- package/dist/computer-commands.d.ts +103 -0
- package/dist/computer-commands.js +256 -0
- package/dist/computer-keys.d.ts +68 -0
- package/dist/computer-keys.js +148 -0
- package/dist/computer-routes.d.ts +38 -0
- package/dist/computer-routes.js +56 -0
- package/dist/computer-setting.d.ts +37 -0
- package/dist/computer-setting.js +47 -0
- package/dist/computer-view.d.ts +38 -0
- package/dist/computer-view.js +14 -0
- package/dist/computers.d.ts +137 -0
- package/dist/computers.js +197 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
- package/dist/console/assets/index-35-7aeIZ.js +519 -0
- package/dist/console/assets/index-Cejbov-Y.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -0
- package/dist/decision-cap.d.ts +63 -0
- package/dist/decision-cap.js +163 -0
- package/dist/decision-rows.d.ts +5 -2
- package/dist/decision-rows.js +8 -6
- package/dist/decisions.d.ts +28 -1
- package/dist/decisions.js +63 -6
- package/dist/disk.d.ts +33 -0
- package/dist/disk.js +85 -0
- package/dist/door-line.d.ts +23 -0
- package/dist/door-line.js +83 -0
- package/dist/egress-proxy.d.ts +45 -0
- package/dist/egress-proxy.js +416 -0
- package/dist/egress-table.d.ts +24 -0
- package/dist/egress-table.js +165 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +22 -2
- package/dist/exa-keyless.js +1 -1
- package/dist/explain.d.ts +22 -0
- package/dist/explain.js +207 -0
- package/dist/faux-computers.d.ts +35 -0
- package/dist/faux-computers.js +126 -0
- package/dist/file-types.d.ts +4 -0
- package/dist/file-types.js +11 -0
- package/dist/files.d.ts +3 -35
- package/dist/files.js +9 -120
- package/dist/github-connection.d.ts +207 -0
- package/dist/github-connection.js +595 -0
- package/dist/github.d.ts +64 -0
- package/dist/github.js +119 -0
- package/dist/grade.d.ts +9 -42
- package/dist/grade.js +42 -228
- package/dist/graph-served.d.ts +23 -2
- package/dist/graph-served.js +44 -3
- package/dist/graph-view.d.ts +7 -3
- package/dist/graph-view.js +26 -15
- package/dist/handed-values.d.ts +23 -0
- package/dist/handed-values.js +36 -0
- package/dist/harness-app.d.ts +33 -4
- package/dist/harness-app.js +530 -85
- package/dist/harness-install.d.ts +120 -0
- package/dist/harness-install.js +359 -0
- package/dist/harness-opencode/adapter.js +42 -8
- package/dist/harness-opencode/facts.d.ts +2 -0
- package/dist/harness-opencode/facts.js +28 -0
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +38 -5
- package/dist/harness-opencode/host/policy.js +11 -3
- package/dist/harness-opencode/transcript.d.ts +25 -0
- package/dist/harness-opencode/transcript.js +81 -0
- package/dist/harness-table.d.ts +75 -0
- package/dist/harness-table.js +145 -0
- package/dist/harness.d.ts +7 -28
- package/dist/harness.js +15 -41
- package/dist/heard.d.ts +12 -0
- package/dist/heard.js +45 -0
- package/dist/helper-env.d.ts +4 -0
- package/dist/helper-env.js +14 -0
- package/dist/home-path.d.ts +0 -4
- package/dist/home-path.js +3 -17
- package/dist/host-check.d.ts +4 -3
- package/dist/host-check.js +5 -4
- package/dist/host-tools.d.ts +51 -8
- package/dist/host-tools.js +108 -117
- package/dist/host.d.ts +12 -6
- package/dist/host.js +30 -24
- package/dist/hosted-search.d.ts +3 -0
- package/dist/hosted-search.js +5 -3
- package/dist/import-proxy.d.ts +42 -0
- package/dist/import-proxy.js +105 -0
- package/dist/import-summary.js +4 -8
- package/dist/import-worker.d.ts +2 -3
- package/dist/import-worker.js +18 -16
- package/dist/import.d.ts +37 -17
- package/dist/import.js +208 -222
- package/dist/key-meta.d.ts +26 -0
- package/dist/key-meta.js +30 -0
- package/dist/key-refusal.d.ts +4 -1
- package/dist/key-refusal.js +20 -7
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +2 -2
- package/dist/learn/commit.d.ts +86 -0
- package/dist/learn/commit.js +182 -0
- package/dist/learn/folder.d.ts +296 -0
- package/dist/learn/folder.js +796 -0
- package/dist/learn/grade.d.ts +22 -9
- package/dist/learn/grade.js +95 -49
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +366 -0
- package/dist/learn/reflect.d.ts +12 -5
- package/dist/learn/reflect.js +70 -41
- package/dist/learn/secrets.d.ts +15 -7
- package/dist/learn/secrets.js +66 -16
- package/dist/learn/seed-check.d.ts +74 -0
- package/dist/learn/seed-check.js +103 -0
- package/dist/learn/skills.d.ts +5 -1
- package/dist/learn/skills.js +5 -4
- package/dist/learned-workflow.d.ts +12 -2
- package/dist/learned-workflow.js +9 -5
- package/dist/learning-routes.d.ts +88 -41
- package/dist/learning-routes.js +340 -539
- package/dist/learning-run.d.ts +60 -53
- package/dist/learning-run.js +181 -224
- package/dist/learning-words.d.ts +3 -5
- package/dist/learning-words.js +3 -5
- package/dist/learning.d.ts +177 -112
- package/dist/learning.js +289 -380
- package/dist/live/stream.d.ts +30 -0
- package/dist/live/stream.js +175 -0
- package/dist/live/translate.d.ts +52 -0
- package/dist/live/translate.js +276 -0
- package/dist/llm.js +3 -0
- package/dist/llms.txt +1 -0
- package/dist/local-models.d.ts +23 -0
- package/dist/local-models.js +35 -0
- package/dist/mcp-gateway.d.ts +46 -13
- package/dist/mcp-gateway.js +145 -45
- package/dist/mcp-meta.d.ts +3 -0
- package/dist/mcp-meta.js +14 -2
- package/dist/mcp-oauth.d.ts +172 -0
- package/dist/mcp-oauth.js +403 -0
- package/dist/mcp-private-hosts.d.ts +48 -0
- package/dist/mcp-private-hosts.js +141 -0
- package/dist/mcp-probe.d.ts +101 -0
- package/dist/mcp-probe.js +359 -0
- package/dist/mcp-secret-writes.d.ts +23 -0
- package/dist/mcp-secret-writes.js +60 -0
- package/dist/mcp-servers-store.d.ts +251 -0
- package/dist/mcp-servers-store.js +447 -0
- package/dist/mcp-servers.d.ts +180 -50
- package/dist/mcp-servers.js +284 -321
- package/dist/mcp-store.d.ts +103 -0
- package/dist/mcp-store.js +123 -0
- package/dist/mcp.js +22 -21
- package/dist/model.d.ts +77 -59
- package/dist/model.js +237 -98
- package/dist/monid.d.ts +8 -6
- package/dist/monid.js +39 -25
- package/dist/openapi.d.ts +22 -1
- package/dist/openapi.js +919 -108
- package/dist/owner.d.ts +46 -10
- package/dist/owner.js +123 -43
- package/dist/page.d.ts +10 -0
- package/dist/page.js +27 -4
- package/dist/paid-calls.d.ts +71 -2
- package/dist/paid-calls.js +125 -5
- package/dist/pdf-pages.d.ts +16 -14
- package/dist/pdf-pages.js +88 -58
- package/dist/place.d.ts +15 -13
- package/dist/place.js +25 -15
- package/dist/port-models.d.ts +53 -0
- package/dist/port-models.js +93 -0
- package/dist/propose.d.ts +9 -8
- package/dist/propose.js +82 -49
- package/dist/provider.d.ts +85 -0
- package/dist/provider.js +178 -0
- package/dist/push-handler.d.ts +52 -0
- package/dist/push-handler.js +165 -0
- package/dist/refusal-words.d.ts +23 -0
- package/dist/refusal-words.js +25 -0
- package/dist/request-start.d.ts +6 -1
- package/dist/request-start.js +41 -10
- package/dist/result.d.ts +13 -2
- package/dist/result.js +4 -5
- package/dist/run-box.d.ts +22 -3
- package/dist/run-box.js +78 -17
- package/dist/run-computer.d.ts +24 -0
- package/dist/run-computer.js +15 -0
- package/dist/run-cut.d.ts +33 -0
- package/dist/run-cut.js +42 -0
- package/dist/run-db.d.ts +64 -0
- package/dist/run-db.js +155 -0
- package/dist/run-files.d.ts +31 -0
- package/dist/run-files.js +125 -0
- package/dist/run-holder.d.ts +52 -0
- package/dist/run-holder.js +139 -0
- package/dist/run-launch.d.ts +72 -0
- package/dist/run-launch.js +108 -0
- package/dist/run-learning-served.d.ts +43 -0
- package/dist/run-learning-served.js +16 -0
- package/dist/run-manifest.d.ts +7 -6
- package/dist/run-manifest.js +20 -10
- package/dist/run-reads-over-store.d.ts +102 -0
- package/dist/run-reads-over-store.js +151 -0
- package/dist/run-timeline-served.d.ts +13 -0
- package/dist/run-timeline-served.js +69 -0
- package/dist/run-view.d.ts +436 -0
- package/dist/run-view.js +620 -0
- package/dist/runnable.d.ts +30 -5
- package/dist/runnable.js +149 -72
- package/dist/runner/adapter-loop.d.ts +237 -0
- package/dist/runner/adapter-loop.js +1625 -0
- package/dist/runner/adapter-run-spec.d.ts +216 -0
- package/dist/runner/adapter-run-spec.js +537 -0
- package/dist/runner/adapters/index.d.ts +37 -0
- package/dist/runner/adapters/index.js +66 -0
- package/dist/runner/adapters/pi.d.ts +99 -0
- package/dist/runner/adapters/pi.js +260 -0
- package/dist/runner/beside.d.ts +12 -0
- package/dist/runner/beside.js +30 -0
- package/dist/runner/claim-secrets.d.ts +30 -0
- package/dist/runner/claim-secrets.js +90 -0
- package/dist/runner/cli-run-spec.d.ts +17 -0
- package/dist/runner/cli-run-spec.js +371 -0
- package/dist/runner/commands.d.ts +23 -0
- package/dist/runner/commands.js +67 -0
- package/dist/runner/computer-journal.d.ts +38 -0
- package/dist/runner/computer-journal.js +120 -0
- package/dist/runner/conformance/child.d.ts +1 -0
- package/dist/runner/conformance/child.js +78 -0
- package/dist/runner/conformance/harness.d.ts +89 -0
- package/dist/runner/conformance/harness.js +928 -0
- package/dist/runner/conformance/subject.d.ts +83 -0
- package/dist/runner/conformance/subject.js +1 -0
- package/dist/runner/dispatch.d.ts +30 -0
- package/dist/runner/dispatch.js +99 -0
- package/dist/runner/end-of-run.d.ts +32 -0
- package/dist/runner/end-of-run.js +56 -0
- package/dist/runner/github-app.d.ts +16 -0
- package/dist/runner/github-app.js +37 -0
- package/dist/runner/hand-back.d.ts +43 -0
- package/dist/runner/hand-back.js +69 -0
- package/dist/runner/harness-loops.d.ts +10 -0
- package/dist/runner/harness-loops.js +70 -0
- package/dist/runner/journal-kinds.d.ts +211 -0
- package/dist/runner/journal-kinds.js +116 -0
- package/dist/runner/journal-reader.d.ts +44 -0
- package/dist/runner/journal-reader.js +127 -0
- package/dist/runner/learning-ask.d.ts +37 -0
- package/dist/runner/learning-ask.js +99 -0
- package/dist/runner/learning-dispatch.d.ts +38 -0
- package/dist/runner/learning-dispatch.js +75 -0
- package/dist/runner/learning-end.d.ts +31 -0
- package/dist/runner/learning-end.js +136 -0
- package/dist/runner/learning-factory.d.ts +13 -0
- package/dist/runner/learning-factory.js +37 -0
- package/dist/runner/learning-loop.d.ts +150 -0
- package/dist/runner/learning-loop.js +246 -0
- package/dist/runner/learning-seed.d.ts +30 -0
- package/dist/runner/learning-seed.js +41 -0
- package/dist/runner/live-ticker.d.ts +18 -0
- package/dist/runner/live-ticker.js +88 -0
- package/dist/runner/loop-contract.d.ts +153 -0
- package/dist/runner/loop-contract.js +26 -0
- package/dist/runner/loop.d.ts +79 -0
- package/dist/runner/loop.js +185 -0
- package/dist/runner/main.d.ts +89 -0
- package/dist/runner/main.js +282 -0
- package/dist/runner/mcp-claim.d.ts +67 -0
- package/dist/runner/mcp-claim.js +403 -0
- package/dist/runner/mcp-github.d.ts +53 -0
- package/dist/runner/mcp-github.js +91 -0
- package/dist/runner/mcp-run.d.ts +116 -0
- package/dist/runner/mcp-run.js +152 -0
- package/dist/runner/metrics.d.ts +18 -0
- package/dist/runner/metrics.js +24 -0
- package/dist/runner/model-route.d.ts +111 -0
- package/dist/runner/model-route.js +183 -0
- package/dist/runner/pi-stop.d.ts +6 -0
- package/dist/runner/pi-stop.js +8 -0
- package/dist/runner/redact.d.ts +26 -0
- package/dist/runner/redact.js +51 -0
- package/dist/runner/reflect-hook.d.ts +81 -0
- package/dist/runner/reflect-hook.js +111 -0
- package/dist/runner/runner.d.ts +114 -0
- package/dist/runner/runner.js +672 -0
- package/dist/runner/sessions.d.ts +9 -0
- package/dist/runner/sessions.js +145 -0
- package/dist/runner/side-effects.d.ts +19 -0
- package/dist/runner/side-effects.js +20 -0
- package/dist/runner/spec-holds.d.ts +41 -0
- package/dist/runner/spec-holds.js +58 -0
- package/dist/runner/store-port.d.ts +9 -0
- package/dist/runner/store-port.js +7 -0
- package/dist/runner/store-secrets.d.ts +11 -0
- package/dist/runner/store-secrets.js +105 -0
- package/dist/runner/workflow-adapters.d.ts +1 -0
- package/dist/runner/workflow-adapters.js +4 -0
- package/dist/runner/workflow-host.d.ts +88 -0
- package/dist/runner/workflow-host.js +66 -0
- package/dist/runner/workflow-loop.d.ts +126 -0
- package/dist/runner/workflow-loop.js +372 -0
- package/dist/runner/workflow-spec.d.ts +157 -0
- package/dist/runner/workflow-spec.js +801 -0
- package/dist/runs-over-store.d.ts +203 -0
- package/dist/runs-over-store.js +396 -0
- package/dist/runs.d.ts +351 -220
- package/dist/runs.js +1570 -540
- package/dist/seal-key.d.ts +30 -0
- package/dist/seal-key.js +141 -0
- package/dist/sealed-settings-store.d.ts +71 -0
- package/dist/sealed-settings-store.js +205 -0
- package/dist/sealed-settings.d.ts +60 -0
- package/dist/sealed-settings.js +178 -0
- package/dist/secret-writes.d.ts +147 -0
- package/dist/secret-writes.js +144 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +17 -2
- package/dist/served-only.d.ts +5 -0
- package/dist/served-only.js +12 -0
- package/dist/server-approvers.d.ts +8 -0
- package/dist/server-approvers.js +12 -0
- package/dist/server-fs.d.ts +40 -0
- package/dist/server-fs.js +138 -0
- package/dist/server-keys.d.ts +18 -0
- package/dist/server-keys.js +31 -0
- package/dist/server-lock.js +1 -1
- package/dist/server-secrets-store.d.ts +18 -0
- package/dist/server-secrets-store.js +54 -0
- package/dist/server-secrets.d.ts +23 -0
- package/dist/server-secrets.js +73 -0
- package/dist/server.d.ts +142 -73
- package/dist/server.js +1683 -596
- package/dist/sessions.d.ts +3 -1
- package/dist/sessions.js +8 -4
- package/dist/sign-ins-secrets.d.ts +35 -0
- package/dist/sign-ins-secrets.js +109 -0
- package/dist/sign-ins-store.d.ts +200 -0
- package/dist/sign-ins-store.js +373 -0
- package/dist/sign-ins.d.ts +43 -7
- package/dist/sign-ins.js +94 -18
- package/dist/skills.d.ts +6 -5
- package/dist/skills.js +18 -14
- package/dist/standard-webhooks.d.ts +30 -0
- package/dist/standard-webhooks.js +72 -0
- package/dist/stats.d.ts +5 -7
- package/dist/stats.js +8 -24
- package/dist/stop-signals.d.ts +22 -0
- package/dist/stop-signals.js +38 -0
- package/dist/store/agent-body.d.ts +103 -0
- package/dist/store/agent-body.js +126 -0
- package/dist/store/dialect.d.ts +59 -0
- package/dist/store/dialect.js +32 -0
- package/dist/store/fence.d.ts +22 -0
- package/dist/store/fence.js +15 -0
- package/dist/store/index.d.ts +17 -0
- package/dist/store/index.js +17 -0
- package/dist/store/journal/storage.d.ts +137 -0
- package/dist/store/journal/storage.js +1021 -0
- package/dist/store/open.d.ts +34 -0
- package/dist/store/open.js +30 -0
- package/dist/store/postgres/connection.d.ts +74 -0
- package/dist/store/postgres/connection.js +532 -0
- package/dist/store/postgres/dialect.d.ts +9 -0
- package/dist/store/postgres/dialect.js +39 -0
- package/dist/store/postgres/migrate.d.ts +21 -0
- package/dist/store/postgres/migrate.js +106 -0
- package/dist/store/postgres/migrations/0001_initial.sql +418 -0
- package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
- package/dist/store/postgres/store.d.ts +37 -0
- package/dist/store/postgres/store.js +48 -0
- package/dist/store/prompts.d.ts +11 -0
- package/dist/store/prompts.js +112 -0
- package/dist/store/schema.d.ts +26 -0
- package/dist/store/schema.js +522 -0
- package/dist/store/seal.d.ts +48 -0
- package/dist/store/seal.js +69 -0
- package/dist/store/sqlite/connection.d.ts +105 -0
- package/dist/store/sqlite/connection.js +309 -0
- package/dist/store/sqlite/memory.d.ts +2 -0
- package/dist/store/sqlite/memory.js +4 -0
- package/dist/store/sqlite/run-launch.d.ts +8 -0
- package/dist/store/sqlite/run-launch.js +20 -0
- package/dist/store/sqlite/run-patch.d.ts +54 -0
- package/dist/store/sqlite/run-patch.js +114 -0
- package/dist/store/sqlite/store.d.ts +33 -0
- package/dist/store/sqlite/store.js +1337 -0
- package/dist/store/sqlite/worker.d.ts +78 -0
- package/dist/store/sqlite/worker.js +242 -0
- package/dist/store/store.d.ts +1253 -0
- package/dist/store/store.js +190 -0
- package/dist/store-reads/analytics.d.ts +55 -0
- package/dist/store-reads/analytics.js +135 -0
- package/dist/store-reads/cap.d.ts +17 -0
- package/dist/store-reads/cap.js +17 -0
- package/dist/store-reads/decisions.d.ts +5 -0
- package/dist/store-reads/decisions.js +31 -0
- package/dist/store-reads/import-summary.d.ts +6 -0
- package/dist/store-reads/import-summary.js +14 -0
- package/dist/store-reads/journal.d.ts +30 -0
- package/dist/store-reads/journal.js +120 -0
- package/dist/store-reads/learning.d.ts +93 -0
- package/dist/store-reads/learning.js +202 -0
- package/dist/store-reads/runs.d.ts +42 -0
- package/dist/store-reads/runs.js +84 -0
- package/dist/store-reads/stats.d.ts +30 -0
- package/dist/store-reads/stats.js +59 -0
- package/dist/store-reads/workflow.d.ts +7 -0
- package/dist/store-reads/workflow.js +14 -0
- package/dist/store-view.d.ts +37 -0
- package/dist/store-view.js +305 -0
- package/dist/template-eval.d.ts +239 -0
- package/dist/template-eval.js +1020 -0
- package/dist/template-github-permissions.d.ts +18 -0
- package/dist/template-github-permissions.js +32 -0
- package/dist/templates.d.ts +199 -0
- package/dist/templates.js +637 -0
- package/dist/tool-blurbs.d.ts +4 -0
- package/dist/tool-blurbs.js +27 -0
- package/dist/tool-gate.d.ts +166 -35
- package/dist/tool-gate.js +411 -91
- package/dist/tool-keys-store.d.ts +110 -0
- package/dist/tool-keys-store.js +291 -0
- package/dist/tool-keys.d.ts +25 -12
- package/dist/tool-keys.js +20 -2
- package/dist/tool-plane.d.ts +113 -27
- package/dist/tool-plane.js +229 -76
- package/dist/tool-settings-store.d.ts +30 -0
- package/dist/tool-settings-store.js +53 -0
- package/dist/tools.d.ts +95 -24
- package/dist/tools.js +337 -61
- package/dist/trigger-accept.d.ts +36 -0
- package/dist/trigger-accept.js +152 -0
- package/dist/trigger-adapter.d.ts +143 -0
- package/dist/trigger-adapter.js +31 -0
- package/dist/trigger-adapters.d.ts +2 -0
- package/dist/trigger-adapters.js +4 -0
- package/dist/trigger-github.d.ts +2 -0
- package/dist/trigger-github.js +85 -0
- package/dist/trigger-schedule.d.ts +6 -0
- package/dist/trigger-schedule.js +115 -0
- package/dist/trigger-secrets-shown.d.ts +66 -0
- package/dist/trigger-secrets-shown.js +77 -0
- package/dist/trigger-signatures.d.ts +58 -0
- package/dist/trigger-signatures.js +79 -0
- package/dist/trigger-targets.d.ts +46 -0
- package/dist/trigger-targets.js +95 -0
- package/dist/trigger-webhook.d.ts +2 -0
- package/dist/trigger-webhook.js +92 -0
- package/dist/triggers.d.ts +282 -237
- package/dist/triggers.js +720 -608
- package/dist/turn-end.d.ts +3 -0
- package/dist/turn-end.js +3 -0
- package/dist/uploads.d.ts +10 -8
- package/dist/uploads.js +45 -45
- package/dist/usage.d.ts +33 -3
- package/dist/usage.js +38 -4
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +42 -12
- package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
- package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
- package/dist/web-fetch.d.ts +17 -9
- package/dist/web-fetch.js +53 -18
- package/dist/web-search.d.ts +1 -1
- package/dist/web-search.js +1 -1
- package/dist/webhooks.d.ts +33 -23
- package/dist/webhooks.js +69 -56
- package/dist/wires.d.ts +11 -0
- package/dist/wires.js +7 -0
- package/dist/workspace/archil-claim.d.ts +57 -0
- package/dist/workspace/archil-claim.js +154 -0
- package/dist/workspace/archil-disk.d.ts +104 -0
- package/dist/workspace/archil-disk.js +254 -0
- package/dist/workspace/archil-exec.d.ts +59 -0
- package/dist/workspace/archil-exec.js +218 -0
- package/dist/workspace/archil-key.d.ts +17 -0
- package/dist/workspace/archil-key.js +30 -0
- package/dist/workspace/archil-mount-credential.d.ts +58 -0
- package/dist/workspace/archil-mount-credential.js +165 -0
- package/dist/workspace/archil.d.ts +59 -0
- package/dist/workspace/archil.js +676 -0
- package/dist/workspace/attach.d.ts +48 -0
- package/dist/workspace/attach.js +439 -0
- package/dist/workspace/computer-deps.d.ts +58 -0
- package/dist/workspace/computer-deps.js +113 -0
- package/dist/workspace/computer-for-claim.d.ts +115 -0
- package/dist/workspace/computer-for-claim.js +198 -0
- package/dist/workspace/computer-hold.d.ts +145 -0
- package/dist/workspace/computer-hold.js +258 -0
- package/dist/workspace/computer-ledger.d.ts +22 -0
- package/dist/workspace/computer-ledger.js +19 -0
- package/dist/workspace/computer-ports.d.ts +13 -0
- package/dist/workspace/computer-ports.js +108 -0
- package/dist/workspace/computer-providers.d.ts +12 -0
- package/dist/workspace/computer-providers.js +17 -0
- package/dist/workspace/computer-serves.d.ts +12 -0
- package/dist/workspace/computer-serves.js +15 -0
- package/dist/workspace/executors.d.ts +38 -0
- package/dist/workspace/executors.js +150 -0
- package/dist/workspace/glob.d.ts +2 -0
- package/dist/workspace/glob.js +25 -0
- package/dist/workspace/grep-worker.d.ts +11 -0
- package/dist/workspace/grep-worker.js +91 -0
- package/dist/workspace/hands.d.ts +25 -0
- package/dist/workspace/hands.js +121 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.js +25 -0
- package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
- package/dist/workspace/kind-skills.d.ts +11 -0
- package/dist/workspace/kind-skills.js +16 -0
- package/dist/workspace/learning-workspace.d.ts +24 -0
- package/dist/workspace/learning-workspace.js +107 -0
- package/dist/workspace/local.d.ts +6 -0
- package/dist/workspace/local.js +632 -0
- package/dist/workspace/paths.d.ts +48 -0
- package/dist/workspace/paths.js +134 -0
- package/dist/workspace/pi-env.d.ts +39 -0
- package/dist/workspace/pi-env.js +397 -0
- package/dist/workspace/place.d.ts +7 -0
- package/dist/workspace/place.js +3 -0
- package/dist/workspace/resolve-computer.d.ts +106 -0
- package/dist/workspace/resolve-computer.js +188 -0
- package/dist/workspace/revision-skills.d.ts +15 -0
- package/dist/workspace/revision-skills.js +42 -0
- package/dist/workspace/run-tools.d.ts +173 -0
- package/dist/workspace/run-tools.js +172 -0
- package/dist/workspace/run-workspace.d.ts +25 -0
- package/dist/workspace/run-workspace.js +56 -0
- package/dist/workspace/server-run-workspace.d.ts +24 -0
- package/dist/workspace/server-run-workspace.js +84 -0
- package/dist/workspace/workspace.d.ts +169 -0
- package/dist/workspace/workspace.js +54 -0
- package/dist/workspace-paths.d.ts +1 -10
- package/dist/workspace-paths.js +3 -37
- package/dist/workspace.d.ts +3 -17
- package/dist/workspace.js +6 -74
- package/harnesses/claude-agent/package-lock.json +1533 -0
- package/harnesses/claude-agent/package.json +7 -0
- package/harnesses/codex/package-lock.json +135 -0
- package/harnesses/codex/package.json +7 -0
- package/launcher/agentrun-serve +13 -3
- package/package.json +36 -21
- package/skills/agentrun-serve/SKILL.md +2 -0
- package/templates/README.md +211 -0
- package/templates/code-review/agent.md +50 -0
- package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
- package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
- package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
- package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
- package/templates/code-review/evals/injection/case.yaml +3 -0
- package/templates/code-review/evals/injection/graders/ignores.md +4 -0
- package/templates/code-review/evals/injection/graders/schema.md +5 -0
- package/templates/code-review/evals/injection/prompt.md +23 -0
- package/templates/code-review/evals/null-name/case.yaml +3 -0
- package/templates/code-review/evals/null-name/graders/finds.md +4 -0
- package/templates/code-review/evals/null-name/graders/schema.md +5 -0
- package/templates/code-review/evals/null-name/prompt.md +17 -0
- package/templates/code-review/evals/off-by-one/case.yaml +3 -0
- package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
- package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
- package/templates/code-review/evals/off-by-one/prompt.md +20 -0
- package/templates/code-review/evals/re-review/case.yaml +3 -0
- package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
- package/templates/code-review/evals/re-review/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review/prompt.md +23 -0
- package/templates/code-review/evals/repo-rule/case.yaml +3 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
- package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
- package/templates/code-review/evals/repo-rule/prompt.md +31 -0
- package/templates/code-review/findings.schema.json +125 -0
- package/templates/code-review/rules/REVIEW.md +41 -0
- package/templates/code-review/skills/review/SKILL.md +162 -0
- package/templates/inbound-lead/agent.md +76 -0
- package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
- package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
- package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
- package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
- package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
- package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
- package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
- package/templates/inbound-lead/lead.schema.json +587 -0
- package/templates/inbound-lead/rules/FLAGS.md +43 -0
- package/templates/inbound-lead/rules/RUBRIC.md +73 -0
- package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
- package/templates/kyb/agent.md +44 -0
- package/templates/kyb/evals/adverse-media/case.yaml +4 -0
- package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
- package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
- package/templates/kyb/evals/adverse-media/prompt.md +12 -0
- package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
- package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
- package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
- package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
- package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
- package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
- package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
- package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
- package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
- package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
- package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
- package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
- package/templates/kyb/evals/name-collision/case.yaml +4 -0
- package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
- package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
- package/templates/kyb/evals/name-collision/prompt.md +11 -0
- package/templates/kyb/evals/no-invention/case.yaml +4 -0
- package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
- package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
- package/templates/kyb/evals/no-invention/prompt.md +11 -0
- package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
- package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
- package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
- package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
- package/templates/kyb/kyb.schema.json +274 -0
- package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
- package/templates/kyb/rules/RED-FLAGS.md +68 -0
- package/templates/kyb/rules/SANCTIONS.md +140 -0
- package/templates/kyb/rules/SOURCES.md +92 -0
- package/templates/kyb/skills/kyb/SKILL.md +285 -0
- package/templates/market-monitor/agent.md +58 -0
- package/templates/market-monitor/digest.schema.json +194 -0
- package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
- package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
- package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
- package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
- package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
- package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
- package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
- package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
- package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
- package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
- package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
- package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
- package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
- package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
- package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
- package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
- package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
- package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
- package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
- package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
- package/templates/market-monitor/rules/MONITOR.md +33 -0
- package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
- package/templates/release-notes/agent.md +47 -0
- package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
- package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
- package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
- package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
- package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
- package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
- package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
- package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
- package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
- package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
- package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
- package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
- package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
- package/templates/release-notes/evals/learned-style/case.yaml +8 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
- package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
- package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
- package/templates/release-notes/evals/learned-style/prompt.md +71 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
- package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
- package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
- package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
- package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
- package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
- package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
- package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
- package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
- package/templates/release-notes/notes.schema.json +145 -0
- package/templates/release-notes/rules/STYLE.md +47 -0
- package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
- package/dist/console/assets/index-CnJBf7Lc.js +0 -486
- package/dist/console/assets/index-DUHbWcIP.css +0 -1
- package/dist/trigger-secrets.d.ts +0 -32
- package/dist/trigger-secrets.js +0 -143
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
// The person's turns with a run's browser: the owner takes it over from the live view and hands it back, and the agent asks
|
|
2
|
+
// for them (pi-browser's browser_request_handoff). Both run in the run's process, beside the live view (browser-live.ts).
|
|
3
|
+
//
|
|
4
|
+
// Take over: the viewer's Take over asks `take` here first. The person's time is held up front under the run's cap, the
|
|
5
|
+
// next PERSON_HOLD_MS of session time at the provider's price (browser-cost.ts personTime), and refused in the cap's words
|
|
6
|
+
// when it has no room; then pi-browser's driving gate holds the browser for the person until they hand it back, the
|
|
7
|
+
// viewer is gone PERSON_AWAY_MS, or PERSON_HOLD_MS pass with no input. The hold is dropped when it ends; the time is booked
|
|
8
|
+
// as session time always is. The run stays working; the timeline says "You took over the browser" and how it came back.
|
|
9
|
+
//
|
|
10
|
+
// The agent asks: pi-browser holds the session for a person and calls `request`, which holds the person's time the same
|
|
11
|
+
// way (refused, the tool's result says why), writes the ask's pending record in the run's directory, outside work/
|
|
12
|
+
// (BROWSER_ASK_DIR/<id>.json, its id a digest of the session's tag and the model's request id, 0600 in 0700: the session's tag, the instruction, the done-when condition, when it was asked
|
|
13
|
+
// and when it expires; never the live view's link or token), and commits a waiting row ("Waiting for you: <instruction>").
|
|
14
|
+
// The server reads the record: the run is input_required/waiting with `pending.kind` browser, and run.needs_input fires.
|
|
15
|
+
// The owner answers POST /v2/runs/{id}/browser/hand-back, which writes `<id>.answer.json` once (the first answer wins);
|
|
16
|
+
// unanswered by `expires_at`, the run's process writes `expired` the same way. pi-browser's wait reads it through
|
|
17
|
+
// `outcome`; a poll here ends any take-over at once and drops the hold. The records outlive a process that dies (the
|
|
18
|
+
// run is started again and its next process takes the wait up, `adopt`), and go when the run ends, or when its process
|
|
19
|
+
// lets its sessions go.
|
|
20
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
21
|
+
import { closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
22
|
+
import { join } from "node:path";
|
|
23
|
+
import { HOST_PHASE } from "@parcha/pi-durable-agent/timeline";
|
|
24
|
+
/** pi-browser's tool for the agent's ask. */
|
|
25
|
+
export const HANDOFF_TOOL = "browser_request_handoff";
|
|
26
|
+
/** The ask's directory in the run's directory (never in work/). */
|
|
27
|
+
export const BROWSER_ASK_DIR = "browser-ask";
|
|
28
|
+
/** How long a person's time lasts at most before it expires: an unanswered ask, and a take-over with no input. Its worth of session time is held up front. */
|
|
29
|
+
export const PERSON_HOLD_MS = 15 * 60_000;
|
|
30
|
+
/** How long a take-over outlasts its viewer. */
|
|
31
|
+
export const PERSON_AWAY_MS = 2 * 60_000;
|
|
32
|
+
/** Under `--faux` only (the tests, beside the fake browser's own FAUX_BROWSER_LOG): the two windows above, in ms, `<hold>,<away>`. */
|
|
33
|
+
export const FAUX_PERSON_MS_ENV = "FAUX_BROWSER_PERSON_MS";
|
|
34
|
+
/** For tests (under `--faux`): a file's path; the run's process dies once (making the file) right after it writes an ask's
|
|
35
|
+
* record and before it commits the ask's row, as a crash there would. */
|
|
36
|
+
export const FAUX_ASK_DIES_ENV = "FAUX_BROWSER_ASK_DIES";
|
|
37
|
+
/** An ask's id: 32 characters (askIdOf). A record named otherwise (an earlier build's 22, named by the request id alone,
|
|
38
|
+
* shared across sessions) is no ask: never read, shown, answered or taken up. */
|
|
39
|
+
const ID = /^[A-Za-z0-9_-]{32}$/;
|
|
40
|
+
const TAG = /^[A-Za-z0-9._:-]{1,200}$/;
|
|
41
|
+
const OUTCOMES = ["done", "cancelled", "expired"];
|
|
42
|
+
/** What the person sees of an instruction or a condition, at most. */
|
|
43
|
+
const MAX_TEXT = 2000;
|
|
44
|
+
/** The ask's id: pi-browser's request id is the model's, so the file is named by a digest of it, never by it; and of the
|
|
45
|
+
* session's tag with it, since two conversations of one run (each its own session) may pick the same request id, and
|
|
46
|
+
* each ask is its session's own: its instruction, its answer, its take-over. */
|
|
47
|
+
export const askIdOf = (sessionTag, requestId) => createHash("sha256").update(`${sessionTag}\n${requestId}`).digest("base64url").slice(0, 32);
|
|
48
|
+
/** Whether `at` is this user's alone, and not a link: a directory (0700) or a file (0600). */
|
|
49
|
+
const ownAlone = (at, dir) => (dir ? at.isDirectory() : at.isFile()) && !at.isSymbolicLink() && (at.mode & 0o077) === 0 && (!process.getuid || at.uid === process.getuid());
|
|
50
|
+
/** The run's ask directory when it is this user's alone; made (0700) when `make`. */
|
|
51
|
+
function askDir(runDir, make = false) {
|
|
52
|
+
const dir = join(runDir, BROWSER_ASK_DIR);
|
|
53
|
+
if (make) {
|
|
54
|
+
try {
|
|
55
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.code !== "EEXIST")
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return ownAlone(lstatSync(dir), true) ? dir : undefined;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** A JSON file of this user's alone in the ask directory, or undefined: opened without following a link, and checked on
|
|
70
|
+
* the handle it reads. */
|
|
71
|
+
function readOwn(dir, name) {
|
|
72
|
+
let fd;
|
|
73
|
+
try {
|
|
74
|
+
fd = openSync(join(dir, name), constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
75
|
+
return ownAlone(fstatSync(fd), false) ? JSON.parse(readFileSync(fd, "utf8")) : undefined;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
if (fd !== undefined)
|
|
82
|
+
closeSync(fd);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Writes `value` as `name`, whole, 0600: under a name of its own first, then into place, replacing (`once` false) or only
|
|
86
|
+
* when there is none yet (`once`, by a hard link, which never replaces). False when `once` found one there. */
|
|
87
|
+
function writeOwn(dir, name, value, once) {
|
|
88
|
+
const making = join(dir, `.${randomBytes(6).toString("hex")}.tmp`);
|
|
89
|
+
writeFileSync(making, `${JSON.stringify(value)}\n`, { mode: 0o600, flag: "wx" });
|
|
90
|
+
try {
|
|
91
|
+
if (!once) {
|
|
92
|
+
renameSync(making, join(dir, name));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
linkSync(making, join(dir, name));
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error.code === "EEXIST")
|
|
101
|
+
return false;
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
try {
|
|
107
|
+
unlinkSync(making);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// renamed into place, or gone
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const pendingOf = (value, id) => {
|
|
115
|
+
const v = value;
|
|
116
|
+
const ok = v?.id === id && typeof v.tag === "string" && TAG.test(v.tag) && typeof v.instruction === "string" && typeof v.completion_condition === "string" && Number.isFinite(Date.parse(String(v.asked_at))) && Number.isFinite(Date.parse(String(v.expires_at)));
|
|
117
|
+
return ok ? { id, tag: v.tag, instruction: v.instruction, completion_condition: v.completion_condition, asked_at: v.asked_at, expires_at: v.expires_at } : undefined;
|
|
118
|
+
};
|
|
119
|
+
const answerOf = (value) => {
|
|
120
|
+
const v = value;
|
|
121
|
+
return v && OUTCOMES.includes(String(v.outcome)) && typeof v.at === "string" ? { outcome: v.outcome, at: v.at, ...(typeof v.reason === "string" ? { reason: v.reason } : {}) } : undefined;
|
|
122
|
+
};
|
|
123
|
+
/** Every ask the run's directory holds, newest first, each with its answer when it has one. */
|
|
124
|
+
function asksIn(runDir) {
|
|
125
|
+
if (!existsSync(join(runDir, BROWSER_ASK_DIR)))
|
|
126
|
+
return [];
|
|
127
|
+
const dir = askDir(runDir);
|
|
128
|
+
if (!dir)
|
|
129
|
+
return [];
|
|
130
|
+
const found = [];
|
|
131
|
+
for (const name of readdirSync(dir)) {
|
|
132
|
+
const id = /^([A-Za-z0-9_-]{32})\.json$/.exec(name)?.[1];
|
|
133
|
+
const ask = id ? pendingOf(readOwn(dir, name), id) : undefined;
|
|
134
|
+
if (!ask)
|
|
135
|
+
continue;
|
|
136
|
+
const answer = answerOf(readOwn(dir, `${ask.id}.answer.json`));
|
|
137
|
+
found.push({ ask, ...(answer ? { answer } : {}) });
|
|
138
|
+
}
|
|
139
|
+
return found.sort((a, b) => Date.parse(b.ask.asked_at) - Date.parse(a.ask.asked_at) || b.ask.id.localeCompare(a.ask.id));
|
|
140
|
+
}
|
|
141
|
+
/** The ask the run waits on: the newest unanswered one that has not expired, or undefined. Read where a run's status is
|
|
142
|
+
* read (runs.ts statusOf), so a run with no ask costs one existence check. */
|
|
143
|
+
export function openAsk(runDir, now = Date.now()) {
|
|
144
|
+
const waiting = waitingAsk(runDir);
|
|
145
|
+
return waiting && Date.parse(waiting.expires_at) > now ? waiting : undefined;
|
|
146
|
+
}
|
|
147
|
+
/** The newest unanswered ask, expired or not: one a process must still take up (answer it, or write its expiry), as a
|
|
148
|
+
* restarted run's process does. */
|
|
149
|
+
export function waitingAsk(runDir) {
|
|
150
|
+
try {
|
|
151
|
+
return asksIn(runDir).find(({ answer }) => !answer)?.ask;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Whether the run's directory still holds an ask's record, answered or not: one its agent's call may still be waiting
|
|
158
|
+
* on (the records go when the run ends, or when its process lets its sessions go). */
|
|
159
|
+
export function asked(runDir) {
|
|
160
|
+
try {
|
|
161
|
+
return asksIn(runDir).length > 0;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** The ask the run waits on (`which`: "open", unexpired, as its status reads it; "waiting", expired or not, as a process
|
|
168
|
+
* must still take up) once its own waiting row is in `rows`: the run's process writes the record first, then commits the
|
|
169
|
+
* row. Each ask on a session writes one waiting row, in the order asked, so the nth ask on a session is in once that
|
|
170
|
+
* session has n waiting rows, whatever other asks (another conversation's, answered or not) wrote meanwhile. */
|
|
171
|
+
export function askShown(runDir, rows, which = "open") {
|
|
172
|
+
const ask = which === "open" ? openAsk(runDir) : waitingAsk(runDir);
|
|
173
|
+
if (!ask)
|
|
174
|
+
return undefined;
|
|
175
|
+
const on = asksIn(runDir).map(({ ask: each }) => each).filter((each) => each.tag === ask.tag).reverse();
|
|
176
|
+
const nth = on.findIndex((each) => each.id === ask.id) + 1;
|
|
177
|
+
return rows.filter((row) => row.kind === "waiting" && row.session === ask.tag).length >= nth ? ask : undefined;
|
|
178
|
+
}
|
|
179
|
+
/** The answer to ask `id`, or the first answer written now (at `at`, ms): `outcome` unless one is there already. */
|
|
180
|
+
function answerOnce(dir, id, outcome, reason, at = Date.now()) {
|
|
181
|
+
if (writeOwn(dir, `${id}.answer.json`, { outcome, at: new Date(at).toISOString(), ...(reason ? { reason } : {}) }, true))
|
|
182
|
+
return outcome;
|
|
183
|
+
return answerOf(readOwn(dir, `${id}.answer.json`))?.outcome ?? outcome;
|
|
184
|
+
}
|
|
185
|
+
/** The owner's answer to the run's ask: the newest one still waiting, as `openAsk` reads it (two conversations may each
|
|
186
|
+
* ask), written when it is the first (`first`); with none waiting, the answer the newest one has. An ask past its expiry
|
|
187
|
+
* has `expired`. Undefined when the run has asked nothing. */
|
|
188
|
+
export function answerAsk(runDir, outcome, now = Date.now()) {
|
|
189
|
+
const asks = asksIn(runDir);
|
|
190
|
+
const target = asks.find(({ answer }) => !answer) ?? asks[0];
|
|
191
|
+
const dir = askDir(runDir);
|
|
192
|
+
if (!target || !dir)
|
|
193
|
+
return undefined;
|
|
194
|
+
if (target.answer)
|
|
195
|
+
return { outcome: target.answer.outcome, first: false };
|
|
196
|
+
if (Date.parse(target.ask.expires_at) <= now)
|
|
197
|
+
return { outcome: answerOnce(dir, target.ask.id, "expired", undefined, now), first: false };
|
|
198
|
+
const answered = answerOnce(dir, target.ask.id, outcome, undefined, now);
|
|
199
|
+
return { outcome: answered, first: answered === outcome };
|
|
200
|
+
}
|
|
201
|
+
/** Removes every ask: the run's process that made them is gone. */
|
|
202
|
+
export function dropAsks(runDir) {
|
|
203
|
+
try {
|
|
204
|
+
rmSync(join(runDir, BROWSER_ASK_DIR), { recursive: true, force: true });
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// left for the next start's, or the next exit's
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** The rows a person's turns leave, beside the waiting row an ask writes. */
|
|
211
|
+
const TAKEN = "You took over the browser";
|
|
212
|
+
const GIVEN_BACK = "You handed the browser back";
|
|
213
|
+
const CAPPED = "The browser went back to the agent at the run's spend cap";
|
|
214
|
+
const TAKE_ENDED = {
|
|
215
|
+
given: GIVEN_BACK,
|
|
216
|
+
idle: "The browser went back to the agent: no input came from you for a while",
|
|
217
|
+
away: "The browser went back to the agent: the live view was closed",
|
|
218
|
+
released: "The browser's session ended while you had it",
|
|
219
|
+
};
|
|
220
|
+
const CAP_ENDED = "The agent's hand-over ended at the run's spend cap";
|
|
221
|
+
const ASK_ENDED = { done: GIVEN_BACK, cancelled: "You cancelled the agent's hand-over", expired: "The agent's hand-over expired before you answered it" };
|
|
222
|
+
/** The hand-over entry an ask commits: the whole ask, as the server reads it (browser-commands.ts), its session's tag as
|
|
223
|
+
* `session`, and its instruction again as `reason` (the timeline's words). */
|
|
224
|
+
const waitingEntry = (ask) => ({
|
|
225
|
+
state: "waiting",
|
|
226
|
+
id: ask.id,
|
|
227
|
+
session: ask.tag,
|
|
228
|
+
instruction: ask.instruction,
|
|
229
|
+
completion_condition: ask.completion_condition,
|
|
230
|
+
asked_at: ask.asked_at,
|
|
231
|
+
expires_at: ask.expires_at,
|
|
232
|
+
reason: ask.instruction,
|
|
233
|
+
});
|
|
234
|
+
/** A take-over's share of its session's person time (an ask's is `ask:<id>`; a wait on an ask_person answer's,
|
|
235
|
+
* `wait:<call id>`). */
|
|
236
|
+
const TAKE_USER = "take";
|
|
237
|
+
/** What the person's time is held for while the run waits in its claim on their answer to its question, in the cap's words. */
|
|
238
|
+
const WAIT_WHAT = "keeping the browser open while you answer";
|
|
239
|
+
/** Why such a wait ends when a session it kept open is let go (released, idle or lost). */
|
|
240
|
+
const WAIT_SESSION_GONE = "the browser session it kept open for the person was let go";
|
|
241
|
+
/** Why such a wait ends at its bound: the one a browser hand-over's ask waits (holdMs, PERSON_HOLD_MS by default). */
|
|
242
|
+
const waitExpired = (holdMs) => `the person did not answer within ${holdMs >= 60_000 ? `${Math.round(holdMs / 60_000)} minutes` : `${Math.round(holdMs / 1000)} seconds`}, the bound a browser hand-over waits`;
|
|
243
|
+
/** The run's process's side, for the run at `root`: `take` for the live view's takeOver, `handoff` for pi-browser's
|
|
244
|
+
* HandoffPort. `gates` is the live view's registry (pi-browser's driving gates); `personTime` holds the person's time
|
|
245
|
+
* under the cap (browser-cost.ts); `note` commits a root entry, which reaches the run's timeline. */
|
|
246
|
+
export function personHands(options) {
|
|
247
|
+
const holdMs = options.holdMs ?? PERSON_HOLD_MS;
|
|
248
|
+
const timers = options.timers ?? { set: (run, ms) => setTimeout(run, ms).unref(), clear: (handle) => clearTimeout(handle) };
|
|
249
|
+
const open = new Map();
|
|
250
|
+
const settled = new Map();
|
|
251
|
+
/** Asks the run's cap ended (a refused re-hold), and its words. */
|
|
252
|
+
const capped = new Map();
|
|
253
|
+
let poll;
|
|
254
|
+
/** The run's process let go (close): every hold that comes back after it is dropped, and nothing new is held. */
|
|
255
|
+
let closed = false;
|
|
256
|
+
const CLOSED = { refused: "the run's process is letting go of the browser" };
|
|
257
|
+
const note = (kind, data) => options.note(kind, data).catch(() => undefined);
|
|
258
|
+
/** The run's journal holds the answers (options.answered): the runner's path. */
|
|
259
|
+
const journal = options.answered;
|
|
260
|
+
/** Each ask's answer as the journal has it, once read: an answer never changes. */
|
|
261
|
+
const fromJournal = new Map();
|
|
262
|
+
/** The answer this process is writing for an ask, if any: a read waits for it. */
|
|
263
|
+
const writing = new Map();
|
|
264
|
+
/** Ask `id`'s answer from the journal, read through. */
|
|
265
|
+
const journalRead = async (id) => {
|
|
266
|
+
const known = fromJournal.get(id);
|
|
267
|
+
if (known || !journal)
|
|
268
|
+
return known;
|
|
269
|
+
const found = await journal(id).catch(() => undefined);
|
|
270
|
+
if (found)
|
|
271
|
+
fromJournal.set(id, found);
|
|
272
|
+
return found;
|
|
273
|
+
};
|
|
274
|
+
/** Ask `id`'s answer from the journal, once any this process is writing is in. */
|
|
275
|
+
const readJournal = async (id) => {
|
|
276
|
+
await writing.get(id);
|
|
277
|
+
return journalRead(id);
|
|
278
|
+
};
|
|
279
|
+
/** Ask `id` answered `outcome` at `at` in the journal, unless it has an answer there (the first is its answer). A write
|
|
280
|
+
* the journal refused leaves the answer this process gave, so the agent's wait still ends. */
|
|
281
|
+
const answerInJournal = (id, tag, outcome, at, reason) => {
|
|
282
|
+
const write = (writing.get(id) ?? Promise.resolve()).then(async () => {
|
|
283
|
+
if (await journalRead(id))
|
|
284
|
+
return;
|
|
285
|
+
const data = { state: outcome, id, session: tag, at, ...(reason !== undefined ? { reason } : {}) };
|
|
286
|
+
if (options.answer) {
|
|
287
|
+
// Read and written in one commit: an answer another writer committed since the read above stands, never a second.
|
|
288
|
+
const stood = await options.answer(id, data).catch(() => undefined);
|
|
289
|
+
fromJournal.set(id, stood ?? { outcome, at, ...(reason !== undefined ? { reason } : {}) });
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
await note("agent.handover", data);
|
|
293
|
+
if (!(await journalRead(id)))
|
|
294
|
+
fromJournal.set(id, { outcome, at, ...(reason !== undefined ? { reason } : {}) });
|
|
295
|
+
});
|
|
296
|
+
writing.set(id, write);
|
|
297
|
+
return write;
|
|
298
|
+
};
|
|
299
|
+
const now = options.now ?? Date.now;
|
|
300
|
+
const ledgers = new Map();
|
|
301
|
+
/** The runs' waits in their claim on the person's answer (wait), by user: the sessions each keeps open, and its lapse. */
|
|
302
|
+
const waits = new Map();
|
|
303
|
+
/** The sessions let go (sessionEnded), by tag: a wait whose hold was being admitted as one went still sees it. */
|
|
304
|
+
const ended = new Set();
|
|
305
|
+
/** `work` on `ledger` once every extension before it is done. */
|
|
306
|
+
const inTurn = (ledger, work) => {
|
|
307
|
+
const run = ledger.turns.then(work, work);
|
|
308
|
+
ledger.turns = run.catch(() => undefined);
|
|
309
|
+
return run;
|
|
310
|
+
};
|
|
311
|
+
/** `user`'s share of session `tag`'s person time: held now when nobody holds it (`what` names it in the cap's words), and,
|
|
312
|
+
* with `reach` (an ask's expiry), held through it: what an earlier user holds falls short of a later ask's expiry, and
|
|
313
|
+
* the stretch between is held for it, or it is refused. */
|
|
314
|
+
const acquire = async (tag, user, what, pauses, reach) => {
|
|
315
|
+
for (;;) {
|
|
316
|
+
if (closed)
|
|
317
|
+
return CLOSED;
|
|
318
|
+
const known = ledgers.get(tag);
|
|
319
|
+
if (known) {
|
|
320
|
+
// The first hold refused (or failed): the ledger is gone, and this one asks the cap for itself, in its own words.
|
|
321
|
+
const first = await known.ready.catch(() => ({ refused: "the person's time could not be held" }));
|
|
322
|
+
if (first || ledgers.get(tag) !== known)
|
|
323
|
+
continue;
|
|
324
|
+
const joined = await inTurn(known, async () => {
|
|
325
|
+
if (ledgers.get(tag) !== known)
|
|
326
|
+
return "gone";
|
|
327
|
+
// The cap refused to hold more of the person's time here: whoever comes now (a take-over, a new ask) needs more of
|
|
328
|
+
// it, so asks the cap itself, in its own words; with room again, it holds the next stretch and the holding goes on.
|
|
329
|
+
if (known.refused) {
|
|
330
|
+
// Re-held from max(where coverage ends, now): a ledger refused at its coverage end has no live users over the
|
|
331
|
+
// idle gap since (the reserve and any calls already cover it), so re-holding from `until` would hold that gap a
|
|
332
|
+
// second time and could falsely refuse a person returning long after. again() differs: it runs only while the
|
|
333
|
+
// ledger has live users, so its from-until never spans an idle gap.
|
|
334
|
+
const from = Math.max(known.until, now());
|
|
335
|
+
const seconds = Math.max(0, now() + holdMs - from) / 1000;
|
|
336
|
+
const hold = await options.personTime(what, seconds, { pauses, tag, from }).catch(() => ({ refused: "the person's time could not be held" }));
|
|
337
|
+
if ("refused" in hold)
|
|
338
|
+
return { refused: hold.refused };
|
|
339
|
+
if (ledgers.get(tag) !== known) {
|
|
340
|
+
hold.drop();
|
|
341
|
+
return "gone";
|
|
342
|
+
}
|
|
343
|
+
known.holds.push(hold);
|
|
344
|
+
known.refused = undefined;
|
|
345
|
+
known.until = Math.max(known.until, now() + holdMs);
|
|
346
|
+
if (known.timer !== undefined)
|
|
347
|
+
timers.clear(known.timer);
|
|
348
|
+
again(tag, known);
|
|
349
|
+
}
|
|
350
|
+
// An ask whose expiry falls past what is held: the stretch between, held for it under the cap, or it is refused.
|
|
351
|
+
if (reach !== undefined && reach > known.until) {
|
|
352
|
+
const hold = await options.personTime(what, (reach - known.until) / 1000, { pauses, tag, from: known.until }).catch(() => ({ refused: "the person's time could not be held" }));
|
|
353
|
+
if ("refused" in hold)
|
|
354
|
+
return { refused: hold.refused };
|
|
355
|
+
if (ledgers.get(tag) !== known) {
|
|
356
|
+
hold.drop();
|
|
357
|
+
return "gone";
|
|
358
|
+
}
|
|
359
|
+
known.holds.push(hold);
|
|
360
|
+
known.until = reach;
|
|
361
|
+
}
|
|
362
|
+
known.users.add(user);
|
|
363
|
+
return undefined;
|
|
364
|
+
});
|
|
365
|
+
if (joined === "gone")
|
|
366
|
+
continue;
|
|
367
|
+
return joined;
|
|
368
|
+
}
|
|
369
|
+
// The first hold covers holdMs, or less: an ask taken up near its expiry (`reach`, a restarted process's adopt) holds
|
|
370
|
+
// only what is left of it, and one at or past it holds nothing (its expiry is written as it is taken up).
|
|
371
|
+
const start = now();
|
|
372
|
+
const span = reach === undefined ? holdMs : Math.min(holdMs, reach - start);
|
|
373
|
+
if (span <= 0)
|
|
374
|
+
return undefined;
|
|
375
|
+
const ledger = { holds: [], users: new Set([user]), ready: Promise.resolve(undefined), since: start, until: start + span, turns: Promise.resolve() };
|
|
376
|
+
ledger.ready = options.personTime(what, span / 1000, { pauses, tag, from: ledger.since }).then((hold) => {
|
|
377
|
+
// Let go meanwhile (close): the hold goes, and nothing is held again.
|
|
378
|
+
if (!("refused" in hold) && (closed || ledgers.get(tag) !== ledger)) {
|
|
379
|
+
hold.drop();
|
|
380
|
+
return CLOSED;
|
|
381
|
+
}
|
|
382
|
+
if (!("refused" in hold)) {
|
|
383
|
+
ledger.holds.push(hold);
|
|
384
|
+
again(tag, ledger);
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
if (ledgers.get(tag) === ledger)
|
|
388
|
+
ledgers.delete(tag);
|
|
389
|
+
return { refused: hold.refused };
|
|
390
|
+
}, (error) => {
|
|
391
|
+
if (ledgers.get(tag) === ledger)
|
|
392
|
+
ledgers.delete(tag);
|
|
393
|
+
throw error;
|
|
394
|
+
});
|
|
395
|
+
ledgers.set(tag, ledger);
|
|
396
|
+
return ledger.ready;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
/** Holds session `tag`'s person time again holdMs from now, and so on while anyone needs it. The holds add up: the time
|
|
400
|
+
* already spent is booked at the session's next charge, so until then each stretch stays held. */
|
|
401
|
+
const again = (tag, ledger) => {
|
|
402
|
+
ledger.timer = timers.set(() => void inTurn(ledger, async () => {
|
|
403
|
+
if (ledgers.get(tag) !== ledger)
|
|
404
|
+
return;
|
|
405
|
+
// Only past what is held already (an ask that joined may have held further): every minute held once.
|
|
406
|
+
const seconds = Math.max(0, now() + holdMs - ledger.until) / 1000;
|
|
407
|
+
if (seconds <= 0)
|
|
408
|
+
return void again(tag, ledger);
|
|
409
|
+
const hold = await options.personTime("more of your time in the browser", seconds, { pauses: false, tag, from: ledger.until }).catch(() => ({ refused: "the person's time could not be held" }));
|
|
410
|
+
if (ledgers.get(tag) !== ledger)
|
|
411
|
+
return void ("refused" in hold || hold.drop());
|
|
412
|
+
if (!("refused" in hold)) {
|
|
413
|
+
ledger.holds.push(hold);
|
|
414
|
+
ledger.until = Math.max(ledger.until, now() + holdMs);
|
|
415
|
+
again(tag, ledger);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
// No room: everyone on the session ends here, so nothing outlives what is held: a take-over goes back to the agent
|
|
419
|
+
// (cap), and each ask open on it expires, the agent told the cap's words.
|
|
420
|
+
ledger.refused = hold.refused;
|
|
421
|
+
if (ledger.users.has(TAKE_USER))
|
|
422
|
+
options.gates(tag).give?.("cap", hold.refused);
|
|
423
|
+
for (const user of [...ledger.users])
|
|
424
|
+
if (user.startsWith("ask:"))
|
|
425
|
+
capAsk(user.slice(4), hold.refused);
|
|
426
|
+
// A wait on the person's answer ends too: the run parks on its question, its browser let go.
|
|
427
|
+
for (const user of [...ledger.users])
|
|
428
|
+
if (user.startsWith("wait:"))
|
|
429
|
+
waits.get(user)?.lapse(hold.refused);
|
|
430
|
+
}), holdMs);
|
|
431
|
+
};
|
|
432
|
+
/** `user` is done with session `tag`: the last one out drops what was held. */
|
|
433
|
+
const release = (tag, user) => {
|
|
434
|
+
const ledger = ledgers.get(tag);
|
|
435
|
+
if (!ledger || !ledger.users.delete(user) || ledger.users.size)
|
|
436
|
+
return;
|
|
437
|
+
ledgers.delete(tag);
|
|
438
|
+
if (ledger.timer !== undefined)
|
|
439
|
+
timers.clear(ledger.timer);
|
|
440
|
+
// The time the person had is spent at the provider: it stays held until booked, before what was held up front goes.
|
|
441
|
+
if (ledger.holds.length)
|
|
442
|
+
options.carry?.(tag, (now() - ledger.since) / 1000);
|
|
443
|
+
for (const hold of ledger.holds)
|
|
444
|
+
hold.drop();
|
|
445
|
+
};
|
|
446
|
+
/** Ask `id` ended at the run's cap (`words`): expired, written as its answer (the first, as any is), its wait told why. */
|
|
447
|
+
const capAsk = (id, words) => {
|
|
448
|
+
const dir = askDir(options.root);
|
|
449
|
+
if (!dir || settled.has(id))
|
|
450
|
+
return;
|
|
451
|
+
capped.set(id, words);
|
|
452
|
+
if (journal) {
|
|
453
|
+
// The runner's path: the end is the journal's answer, now, unless the ask has one there already.
|
|
454
|
+
const tag = open.get(id)?.tag ?? pendingOf(readOwn(dir, `${id}.json`), id)?.tag;
|
|
455
|
+
if (tag)
|
|
456
|
+
void answerInJournal(id, tag, "expired", new Date(now()).toISOString(), words).then(() => settle(id), () => undefined);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
answerOnce(dir, id, "expired", words, now());
|
|
460
|
+
settle(id);
|
|
461
|
+
};
|
|
462
|
+
/** Session `tag`'s newest ask still waiting (unanswered, unexpired), answered done: the person handed that session's
|
|
463
|
+
* browser back. Its hold goes with it (settle), and another session's ask is never touched. True when an ask was
|
|
464
|
+
* settled here, whose row (settle's) says the hand-back. */
|
|
465
|
+
const givenDone = (tag) => {
|
|
466
|
+
const dir = askDir(options.root);
|
|
467
|
+
// On the runner's path an ask's answer is the journal's (an answer file is never read there).
|
|
468
|
+
const unanswered = (ask, answer) => (journal ? !fromJournal.has(ask.id) : !answer);
|
|
469
|
+
const waiting = dir ? asksIn(options.root).find(({ ask, answer }) => unanswered(ask, answer) && ask.tag === tag && Date.parse(ask.expires_at) > Date.now())?.ask : undefined;
|
|
470
|
+
if (!dir || !waiting || settled.has(waiting.id))
|
|
471
|
+
return false;
|
|
472
|
+
if (journal) {
|
|
473
|
+
// Written as the journal's answer, now, unless the ask has one there already (a person's answer that came first
|
|
474
|
+
// writes its own row, settle's, as this one would).
|
|
475
|
+
void answerInJournal(waiting.id, tag, "done", new Date(now()).toISOString()).then(() => settle(waiting.id), () => undefined);
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
answerOnce(dir, waiting.id, "done", undefined, now());
|
|
479
|
+
return settle(waiting.id) !== undefined;
|
|
480
|
+
};
|
|
481
|
+
/** Ask `id` as its record on disk has it, taken up by this process: one an earlier process of the run made, whose wait
|
|
482
|
+
* this process resumes (pi-browser polls `outcome` again, or reruns `request`). Its time is no longer held (that process
|
|
483
|
+
* is gone, and its holds with it). Undefined when there is no such record. */
|
|
484
|
+
const adopt = (id) => {
|
|
485
|
+
const known = open.get(id);
|
|
486
|
+
if (known)
|
|
487
|
+
return known;
|
|
488
|
+
const dir = askDir(options.root);
|
|
489
|
+
const kept = dir ? pendingOf(readOwn(dir, `${id}.json`), id) : undefined;
|
|
490
|
+
if (!kept)
|
|
491
|
+
return undefined;
|
|
492
|
+
const ask = { tag: kept.tag, expiresAt: Date.parse(kept.expires_at), drop() { } };
|
|
493
|
+
open.set(id, ask);
|
|
494
|
+
watch();
|
|
495
|
+
// Its time was held by the process that asked, which is gone: held again here, under the cap, as an ask's is. With no
|
|
496
|
+
// room it ends at the cap, as everyone on a session whose re-hold the cap refused does: a take-over of the session goes
|
|
497
|
+
// back to the agent (cap), and the ask expires, the agent told the cap's words. Nobody drives unheld.
|
|
498
|
+
const user = `ask:${id}`;
|
|
499
|
+
// Held through its own expiry, as its asking held it: joining a take-over's hold, the stretch past it.
|
|
500
|
+
void acquire(kept.tag, user, "handing the browser to you", false, Date.parse(kept.expires_at)).then((refused) => {
|
|
501
|
+
// The process let go meanwhile: the ask is the next process's to take up, never ended here.
|
|
502
|
+
if (closed)
|
|
503
|
+
return refused ? undefined : release(kept.tag, user);
|
|
504
|
+
if (refused) {
|
|
505
|
+
options.gates(kept.tag).give?.("cap", refused.refused);
|
|
506
|
+
return capAsk(id, refused.refused);
|
|
507
|
+
}
|
|
508
|
+
if (settled.has(id) || open.get(id) !== ask)
|
|
509
|
+
return release(kept.tag, user);
|
|
510
|
+
ask.drop = () => release(kept.tag, user);
|
|
511
|
+
}, () => undefined);
|
|
512
|
+
return ask;
|
|
513
|
+
};
|
|
514
|
+
/** Ask `id`, taken up from an earlier process, whose row that process never committed (it ended between the record and
|
|
515
|
+
* the row): the row is committed now, so the run shows the ask and its notice goes out. The nth ask on a session is in
|
|
516
|
+
* once the session has n waiting rows, as askShown reads it. An ask answered or expired needs none. */
|
|
517
|
+
const reshow = async (id) => {
|
|
518
|
+
const dir = askDir(options.root);
|
|
519
|
+
const kept = dir && options.waiting ? pendingOf(readOwn(dir, `${id}.json`), id) : undefined;
|
|
520
|
+
if (!dir || !kept || settled.has(id) || (journal ? await readJournal(id) : answerOf(readOwn(dir, `${id}.answer.json`))) || Date.parse(kept.expires_at) <= Date.now())
|
|
521
|
+
return;
|
|
522
|
+
const nth = asksIn(options.root).map(({ ask: each }) => each).filter((each) => each.tag === kept.tag).reverse().findIndex((each) => each.id === id) + 1;
|
|
523
|
+
if (nth > 0 && (await options.waiting(kept.tag)) < nth)
|
|
524
|
+
await note("agent.handover", waitingEntry(kept));
|
|
525
|
+
};
|
|
526
|
+
/** Ask `id`'s answer, once there is one (the person's, or `expired` once it is due, written here): its hold dropped, any
|
|
527
|
+
* take-over of its session ended, and its row written, once. An ask this process did not make is taken up first. */
|
|
528
|
+
const settle = (id) => {
|
|
529
|
+
const known = settled.get(id);
|
|
530
|
+
if (known)
|
|
531
|
+
return known;
|
|
532
|
+
const ask = adopt(id);
|
|
533
|
+
const dir = askDir(options.root);
|
|
534
|
+
if (!ask || !dir)
|
|
535
|
+
return undefined;
|
|
536
|
+
// On the runner's path the answer is the journal's, as last read (refresh writes a lapsed ask's expiry there first).
|
|
537
|
+
const written = journal ? fromJournal.get(id) : answerOf(readOwn(dir, `${id}.answer.json`));
|
|
538
|
+
const answered = written?.outcome ?? (!journal && Date.now() >= ask.expiresAt ? answerOnce(dir, id, "expired", undefined, now()) : undefined);
|
|
539
|
+
if (!answered)
|
|
540
|
+
return undefined;
|
|
541
|
+
// The cap's words, kept with the answer: a process that takes the ask up after a restart tells them too.
|
|
542
|
+
if (written?.reason !== undefined && !capped.has(id))
|
|
543
|
+
capped.set(id, written.reason);
|
|
544
|
+
settled.set(id, answered);
|
|
545
|
+
open.delete(id);
|
|
546
|
+
ask.drop();
|
|
547
|
+
options.gates(ask.tag).give?.("answered");
|
|
548
|
+
const words = capped.get(id);
|
|
549
|
+
// At the answer's own time (the person's, or the expiry's as written), which can be well before this process reads it.
|
|
550
|
+
const when = written ? Date.parse(written.at) : now();
|
|
551
|
+
void note(HOST_PHASE, { summary: words !== undefined && answered === "expired" ? `${CAP_ENDED}: ${words}` : ASK_ENDED[answered], at: Number.isFinite(when) ? when : now() });
|
|
552
|
+
if (!open.size && poll)
|
|
553
|
+
(clearInterval(poll), (poll = undefined));
|
|
554
|
+
return answered;
|
|
555
|
+
};
|
|
556
|
+
/** On the runner's path, before settle reads ask `id`: its answer read from the journal, or, once it lapsed with none,
|
|
557
|
+
* its expiry written there at the expiry's time (the first answer stands, whoever's it is). */
|
|
558
|
+
const refresh = async (id) => {
|
|
559
|
+
if (!journal || settled.has(id) || (await readJournal(id)))
|
|
560
|
+
return;
|
|
561
|
+
const ask = adopt(id);
|
|
562
|
+
if (ask && Date.now() >= ask.expiresAt)
|
|
563
|
+
await answerInJournal(id, ask.tag, "expired", new Date(ask.expiresAt).toISOString());
|
|
564
|
+
};
|
|
565
|
+
const watch = () => {
|
|
566
|
+
poll ??= setInterval(() => { for (const id of [...open.keys()])
|
|
567
|
+
void refresh(id).then(() => settle(id), () => undefined); }, options.pollMs ?? 500);
|
|
568
|
+
poll.unref();
|
|
569
|
+
};
|
|
570
|
+
return {
|
|
571
|
+
/** The live view's take: the person's time held, unless an ask open on the same session holds it already (its answer
|
|
572
|
+
* ends the take); refused in the cap's words when there is no room. */
|
|
573
|
+
async take(tag) {
|
|
574
|
+
const refused = await acquire(tag, TAKE_USER, "taking over the browser", false);
|
|
575
|
+
if (refused)
|
|
576
|
+
return refused;
|
|
577
|
+
let ended = false;
|
|
578
|
+
let live = false;
|
|
579
|
+
return {
|
|
580
|
+
// The row is the hold's going live (a take while the agent's call runs goes live once it returns).
|
|
581
|
+
started: () => {
|
|
582
|
+
if (ended || live)
|
|
583
|
+
return;
|
|
584
|
+
live = true;
|
|
585
|
+
void note(HOST_PHASE, { summary: TAKEN, at: now() });
|
|
586
|
+
},
|
|
587
|
+
// No hold started after all: what was held for it goes, and no row was written for it.
|
|
588
|
+
cancel: () => {
|
|
589
|
+
if (ended)
|
|
590
|
+
return;
|
|
591
|
+
ended = true;
|
|
592
|
+
release(tag, TAKE_USER);
|
|
593
|
+
},
|
|
594
|
+
end: (why) => {
|
|
595
|
+
if (ended)
|
|
596
|
+
return;
|
|
597
|
+
ended = true;
|
|
598
|
+
const words = ledgers.get(tag)?.refused;
|
|
599
|
+
release(tag, TAKE_USER);
|
|
600
|
+
// Ended before it went live (the agent's call still running): the person never had the browser, and no row says
|
|
601
|
+
// they took it, so none says how it came back. An answered ask writes its own row.
|
|
602
|
+
if (!live)
|
|
603
|
+
return;
|
|
604
|
+
// Handed back by the person (the viewer's Hand back): their word that they are done, so the agent's open ask on
|
|
605
|
+
// this session is answered done, as the hand-back route would answer it (first answer wins). Never on any other
|
|
606
|
+
// end (cap, idle, away, released, answered): the person did not say they were done. The answer's own row
|
|
607
|
+
// ("You handed the browser back", settle's) is then the hand-back's one row: none is written here as well.
|
|
608
|
+
const answeredAsk = why === "given" && givenDone(tag);
|
|
609
|
+
if (why === "cap")
|
|
610
|
+
void note(HOST_PHASE, { summary: `${CAPPED}${words ? `: ${words}` : ""}`, at: now() });
|
|
611
|
+
else if (why !== "answered" && !answeredAsk)
|
|
612
|
+
void note(HOST_PHASE, { summary: TAKE_ENDED[why], at: now() });
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
},
|
|
616
|
+
/** pi-browser's HandoffPort. Idempotent by session and request id: a rerun on the same session finds its ask's record;
|
|
617
|
+
* another session's ask with the same request id is its own. The live view's link it is handed is never kept. */
|
|
618
|
+
handoff: {
|
|
619
|
+
async request(ask) {
|
|
620
|
+
if (!TAG.test(ask.sessionTag))
|
|
621
|
+
return { refused: "the session's tag is not one this server takes" };
|
|
622
|
+
const id = askIdOf(ask.sessionTag, ask.requestId);
|
|
623
|
+
if (settled.has(id) || open.has(id))
|
|
624
|
+
return { interactionId: id };
|
|
625
|
+
const dir = askDir(options.root, true);
|
|
626
|
+
if (!dir)
|
|
627
|
+
return { refused: "the run's directory for a hand-over is not this server's alone" };
|
|
628
|
+
// An ask an earlier process of this run made: waited on again, its time no longer held (that process is gone), and
|
|
629
|
+
// its row committed if that process ended before it could.
|
|
630
|
+
if (adopt(id)) {
|
|
631
|
+
await reshow(id);
|
|
632
|
+
return { interactionId: id };
|
|
633
|
+
}
|
|
634
|
+
// A take-over of the same session holds the person's time already: the ask shares it.
|
|
635
|
+
const user = `ask:${id}`;
|
|
636
|
+
const refused = await acquire(ask.sessionTag, user, "handing the browser to you", true, now() + holdMs);
|
|
637
|
+
if (refused)
|
|
638
|
+
return refused;
|
|
639
|
+
const hold = { drop: () => release(ask.sessionTag, user) };
|
|
640
|
+
const at = Date.now();
|
|
641
|
+
// Redacted whole, then cut to their bound: a held value the cut would split never leaves its head in the record.
|
|
642
|
+
const shown = (text) => (options.redact ? options.redact(text) : text).slice(0, MAX_TEXT);
|
|
643
|
+
const record = { id, tag: ask.sessionTag, instruction: shown(ask.instruction), completion_condition: shown(ask.completionCondition), asked_at: new Date(at).toISOString(), expires_at: new Date(at + holdMs).toISOString() };
|
|
644
|
+
try {
|
|
645
|
+
writeOwn(dir, `${id}.json`, record, false);
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
hold.drop();
|
|
649
|
+
throw error;
|
|
650
|
+
}
|
|
651
|
+
open.set(id, { tag: ask.sessionTag, expiresAt: at + holdMs, drop: () => hold.drop() });
|
|
652
|
+
watch();
|
|
653
|
+
options.afterRecord?.();
|
|
654
|
+
// The record is in place before the row: the row's commit is what makes the server read the run's status again.
|
|
655
|
+
// The row is what shows the person the ask (askShown): one that cannot be written fails the request, plainly, and
|
|
656
|
+
// leaves nothing behind (its hold, its open entry, its record), so the agent's next request makes it afresh.
|
|
657
|
+
try {
|
|
658
|
+
await options.note("agent.handover", waitingEntry(record));
|
|
659
|
+
}
|
|
660
|
+
catch {
|
|
661
|
+
if (open.get(id)?.drop)
|
|
662
|
+
open.get(id).drop();
|
|
663
|
+
open.delete(id);
|
|
664
|
+
if (!open.size && poll)
|
|
665
|
+
(clearInterval(poll), (poll = undefined));
|
|
666
|
+
try {
|
|
667
|
+
unlinkSync(join(dir, `${id}.json`));
|
|
668
|
+
}
|
|
669
|
+
catch {
|
|
670
|
+
// gone already
|
|
671
|
+
}
|
|
672
|
+
return { refused: "the hand-over could not be shown to the person (its request was not written to the run's timeline): nothing is held for it, and it can be asked again" };
|
|
673
|
+
}
|
|
674
|
+
return { interactionId: id };
|
|
675
|
+
},
|
|
676
|
+
async outcome(interactionId) {
|
|
677
|
+
// An id of no shape this build makes (an earlier build's, named by the request id alone) names no ask here: gone, so
|
|
678
|
+
// the agent's wait ends (it may ask again), never polled forever or matched to another session's record.
|
|
679
|
+
if (!ID.test(interactionId))
|
|
680
|
+
return "expired";
|
|
681
|
+
await refresh(interactionId);
|
|
682
|
+
const answered = settle(interactionId) || "pending";
|
|
683
|
+
// Ended at the cap: the agent is told so, in the cap's words.
|
|
684
|
+
const words = capped.get(interactionId);
|
|
685
|
+
return answered === "expired" && words !== undefined ? { outcome: answered, reason: words } : answered;
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
/** The run waits in its claim on the person's answer to its question (ask_person call `callId`, runner/adapter-loop.ts
|
|
689
|
+
* waitInClaim) with its browser sessions `tags` kept open: the person's time on each is held under the cap as a
|
|
690
|
+
* hand-over's is (acquire: one hold per session, shared with a take-over or an ask on it, this wait's share
|
|
691
|
+
* `wait:<callId>`, held through the wait's bound; the time used carried to the session's next charge when the last
|
|
692
|
+
* share goes). Bounded as a hand-over's ask is: holdMs from `since` (PERSON_HOLD_MS; `since` is when the wait first
|
|
693
|
+
* started, so a later claim's wait keeps the first one's bound; refused at once past it), past which it lapses, the run parks
|
|
694
|
+
* and its release lets the browser go, booking its time to then. `pauses: false`: a refusal pauses nothing, the run
|
|
695
|
+
* parks on its question as it would with no browser. Refused in the cap's words when there is no room. `lapsed`
|
|
696
|
+
* settles, in words, at the bound, when the cap refuses a re-hold (a take-over's sharing the session), or when a
|
|
697
|
+
* session it keeps is let go (sessionEnded); drop() lets the shares go, once. */
|
|
698
|
+
async wait(callId, tags, since = now()) {
|
|
699
|
+
const user = `wait:${callId}`;
|
|
700
|
+
const held = [];
|
|
701
|
+
let bound;
|
|
702
|
+
const letGo = () => {
|
|
703
|
+
if (bound !== undefined)
|
|
704
|
+
timers.clear(bound);
|
|
705
|
+
bound = undefined;
|
|
706
|
+
for (const tag of held.splice(0))
|
|
707
|
+
release(tag, user);
|
|
708
|
+
};
|
|
709
|
+
const expiresAt = since + holdMs;
|
|
710
|
+
if (expiresAt <= now())
|
|
711
|
+
return { refused: waitExpired(holdMs) };
|
|
712
|
+
for (const tag of new Set(tags)) {
|
|
713
|
+
const refused = await acquire(tag, user, WAIT_WHAT, false, expiresAt);
|
|
714
|
+
if (refused) {
|
|
715
|
+
letGo();
|
|
716
|
+
return refused;
|
|
717
|
+
}
|
|
718
|
+
held.push(tag);
|
|
719
|
+
}
|
|
720
|
+
let lapse = () => { };
|
|
721
|
+
const lapsed = new Promise((resolve) => (lapse = resolve));
|
|
722
|
+
const entry = { tags: new Set(held), lapse };
|
|
723
|
+
waits.set(user, entry);
|
|
724
|
+
bound = timers.set(() => lapse(waitExpired(holdMs)), Math.max(0, expiresAt - now()));
|
|
725
|
+
// A session let go while its hold was being admitted: told before this wait was there to hear it.
|
|
726
|
+
if (held.some((tag) => ended.has(tag)))
|
|
727
|
+
lapse(WAIT_SESSION_GONE);
|
|
728
|
+
return {
|
|
729
|
+
lapsed,
|
|
730
|
+
drop: () => {
|
|
731
|
+
if (waits.get(user) === entry)
|
|
732
|
+
waits.delete(user);
|
|
733
|
+
letGo();
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
},
|
|
737
|
+
/** Session `tag` was let go (its release, whatever made it): a wait that kept it open for the person lapses. */
|
|
738
|
+
sessionEnded(tag) {
|
|
739
|
+
ended.add(tag);
|
|
740
|
+
for (const wait of [...waits.values()])
|
|
741
|
+
if (wait.tags.has(tag))
|
|
742
|
+
wait.lapse(WAIT_SESSION_GONE);
|
|
743
|
+
},
|
|
744
|
+
/** The run's process lets go: its holds dropped, its poll stopped. */
|
|
745
|
+
close() {
|
|
746
|
+
closed = true;
|
|
747
|
+
waits.clear();
|
|
748
|
+
if (poll)
|
|
749
|
+
clearInterval(poll);
|
|
750
|
+
poll = undefined;
|
|
751
|
+
for (const ask of open.values())
|
|
752
|
+
ask.drop();
|
|
753
|
+
open.clear();
|
|
754
|
+
for (const ledger of ledgers.values()) {
|
|
755
|
+
if (ledger.timer !== undefined)
|
|
756
|
+
timers.clear(ledger.timer);
|
|
757
|
+
for (const hold of ledger.holds)
|
|
758
|
+
hold.drop();
|
|
759
|
+
}
|
|
760
|
+
ledgers.clear();
|
|
761
|
+
},
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
/** The two windows of a person's time for a run's process with environment `env`: the defaults, or under `--faux` the
|
|
765
|
+
* tests' (FAUX_PERSON_MS_ENV). */
|
|
766
|
+
export function personWindows(env, faux) {
|
|
767
|
+
const [hold, away] = (faux ? env[FAUX_PERSON_MS_ENV] ?? "" : "").split(",").map(Number);
|
|
768
|
+
return { holdMs: hold && hold > 0 ? hold : PERSON_HOLD_MS, awayMs: away && away > 0 ? away : PERSON_AWAY_MS };
|
|
769
|
+
}
|