@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60
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 +402 -1
- package/README.md +516 -190
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +7 -0
- package/dist/chatgpt-plan.js +35 -11
- package/dist/claude-login-token.d.ts +20 -11
- package/dist/claude-login-token.js +175 -107
- package/dist/claude-login.d.ts +124 -33
- package/dist/claude-login.js +562 -85
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-QnwGVBeU.js +166 -0
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/share-pz61zIn9.js +6 -0
- package/dist/console/assets/styles-CcceGcu2.js +291 -0
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +10 -8
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +21 -6
- package/dist/harness.js +6 -2
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +20 -8
- package/dist/import.js +448 -187
- package/dist/key-refusal.d.ts +14 -2
- package/dist/key-refusal.js +97 -33
- package/dist/learn/audit.d.ts +28 -27
- package/dist/learn/audit.js +87 -62
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +9 -6
- package/dist/learn/compile.js +51 -28
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +119 -102
- package/dist/learn/promote.js +119 -262
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +22 -2
- package/dist/mcp-gateway.js +85 -11
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +290 -79
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +58 -34
- package/dist/place-offers.js +96 -54
- package/dist/place.d.ts +41 -20
- package/dist/place.js +97 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +42 -9
- package/dist/redact/match.js +356 -54
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +8 -5
- package/dist/runnable.js +26 -9
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +73 -46
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +10 -9
- package/dist/runner/audit.js +64 -67
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +87 -58
- package/dist/runner/compare-end.d.ts +2 -3
- package/dist/runner/compare-end.js +30 -11
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +3 -4
- package/dist/runner/held.d.ts +5 -12
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +8 -2
- package/dist/runner/journal-kinds.js +23 -5
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +23 -7
- package/dist/runner/learning-end.d.ts +14 -24
- package/dist/runner/learning-end.js +52 -94
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +13 -12
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +12 -11
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +39 -36
- package/dist/runner/promotion.js +168 -112
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +21 -14
- package/dist/runner/run-child-host.js +187 -141
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +3 -4
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +10 -12
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +26 -7
- package/dist/sdk/runs.js +194 -78
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +55 -9
- package/dist/secrets.js +345 -21
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +10 -3
- package/dist/server-keys.js +16 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +30 -18
- package/dist/server.js +520 -238
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +60 -11
- package/dist/store/schema.js +147 -17
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +9 -0
- package/dist/store/sqlite/store.js +194 -46
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +286 -38
- package/dist/store/store.js +27 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +50 -45
- package/dist/store-reads/learning.js +153 -116
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +49 -17
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +54 -13
- package/dist/tool-plane.js +103 -32
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +34 -0
- package/dist/web-holds.js +89 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +76 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +38 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +19 -4
- package/dist/workspace/computer-providers.js +40 -6
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +2 -3
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +7 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -14
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/workspace/local.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
import { spawn } from "node:child_process";
|
|
35
35
|
import { randomBytes } from "node:crypto";
|
|
36
36
|
import { constants } from "node:fs";
|
|
37
|
-
import { access, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir, unlink } from "node:fs/promises";
|
|
37
|
+
import { access, link, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir, unlink } from "node:fs/promises";
|
|
38
38
|
import { join } from "node:path";
|
|
39
39
|
import { Worker } from "node:worker_threads";
|
|
40
40
|
import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
|
|
@@ -379,6 +379,46 @@ class LocalWorkspace {
|
|
|
379
379
|
}
|
|
380
380
|
}, { make: true });
|
|
381
381
|
}
|
|
382
|
+
async writeNew(path, data) {
|
|
383
|
+
const bytes = bytesOf(data);
|
|
384
|
+
const segments = LocalWorkspace.#below(path, "a file");
|
|
385
|
+
const name = segments.at(-1);
|
|
386
|
+
return this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
387
|
+
try {
|
|
388
|
+
// The bytes in a temporary file of their own first, made durable; then a hard link gives them the name, which the
|
|
389
|
+
// kernel refuses (EEXIST) when anything is at it, a file, a folder or a link, in the same step that would make it.
|
|
390
|
+
const temp = `.workspace-${randomBytes(8).toString("hex")}.tmp`;
|
|
391
|
+
const handle = await dir.open(temp, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
392
|
+
let made = false;
|
|
393
|
+
try {
|
|
394
|
+
await handle.writeFile(bytes);
|
|
395
|
+
await handle.sync();
|
|
396
|
+
await handle.close();
|
|
397
|
+
await dir.confirm(path);
|
|
398
|
+
try {
|
|
399
|
+
await link(dir.at(temp), dir.at(name));
|
|
400
|
+
made = true;
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (errno(error) !== "EEXIST")
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
await handle.close().catch(() => undefined);
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
finally {
|
|
412
|
+
await unlink(dir.at(temp)).catch(() => undefined);
|
|
413
|
+
}
|
|
414
|
+
await dir.handle.sync();
|
|
415
|
+
return made;
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
throw failed(error, path);
|
|
419
|
+
}
|
|
420
|
+
}, { make: true });
|
|
421
|
+
}
|
|
382
422
|
async append(path, data) {
|
|
383
423
|
const bytes = bytesOf(data);
|
|
384
424
|
const segments = LocalWorkspace.#below(path, "a file");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Settings } from "../store/index.js";
|
|
2
|
+
/** The settings prefix of the left removes. */
|
|
3
|
+
export declare const MOUNT_REVOKE_PREFIX = "archil_revoke:";
|
|
4
|
+
/** The settings key of run `runId`'s left remove. */
|
|
5
|
+
export declare const mountRevokeKeyOf: (runId: string) => string;
|
|
6
|
+
/** A remove left: the claim epoch it reaches up to, the disk its credentials are on, and when it was left (ms, the
|
|
7
|
+
* store's clock), which the janitor reads as a kept row's `until`. */
|
|
8
|
+
export type LeftRevoke = {
|
|
9
|
+
readonly epoch: number;
|
|
10
|
+
readonly disk: string;
|
|
11
|
+
readonly until: number;
|
|
12
|
+
};
|
|
13
|
+
/** A row's value as a LeftRevoke, or undefined for anything else. */
|
|
14
|
+
export declare function leftRevokeOf(value: unknown): LeftRevoke | undefined;
|
|
15
|
+
/** Leaves run `runId`'s remove for the janitor. A row already there for a later or the same epoch is kept: its remove
|
|
16
|
+
* reaches this one's credentials too. One for an earlier epoch is replaced, by compare-and-set. */
|
|
17
|
+
export declare function leaveMountRevoke(settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, runId: string, left: LeftRevoke): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* The janitor's pass over the left removes: each asked of `revoke` (the kept pass's revokeMount, which asks nothing past
|
|
20
|
+
* the row's time plus MOUNT_TTL_MS), bounded by `deleteMs` (KEPT_DELETE_MS) as a kept computer's delete is, its Archil
|
|
21
|
+
* calls cut at the bound by the signal it is handed; and its row removed once that answers, only while it still reads as
|
|
22
|
+
* read (a later claim's left since stays). One that throws or passes its bound is left for the next pass, said in
|
|
23
|
+
* `failed`, and the pass goes on. Never throws.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sweepMountRevokes(deps: {
|
|
26
|
+
readonly settings: Pick<Settings, "all" | "removeIf">;
|
|
27
|
+
readonly revoke: (runId: string, left: LeftRevoke, signal: AbortSignal) => Promise<void>;
|
|
28
|
+
readonly deleteMs?: number;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
readonly failed: readonly string[];
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { bounded, KEPT_DELETE_MS } from "./computer-kept.js";
|
|
2
|
+
/** The settings prefix of the left removes. */
|
|
3
|
+
export const MOUNT_REVOKE_PREFIX = "archil_revoke:";
|
|
4
|
+
/** The settings key of run `runId`'s left remove. */
|
|
5
|
+
export const mountRevokeKeyOf = (runId) => `${MOUNT_REVOKE_PREFIX}${runId}`;
|
|
6
|
+
/** A row's value as a LeftRevoke, or undefined for anything else. */
|
|
7
|
+
export function leftRevokeOf(value) {
|
|
8
|
+
if (!value || typeof value !== "object")
|
|
9
|
+
return undefined;
|
|
10
|
+
const { epoch, disk, until } = value;
|
|
11
|
+
if (typeof epoch !== "number" || !Number.isSafeInteger(epoch) || typeof disk !== "string" || disk === "" || typeof until !== "number" || !Number.isFinite(until))
|
|
12
|
+
return undefined;
|
|
13
|
+
return { epoch, disk, until };
|
|
14
|
+
}
|
|
15
|
+
/** How many times a write reads the row again after losing it to another between its read and its write. */
|
|
16
|
+
const LEAVE_TRIES = 3;
|
|
17
|
+
/** Leaves run `runId`'s remove for the janitor. A row already there for a later or the same epoch is kept: its remove
|
|
18
|
+
* reaches this one's credentials too. One for an earlier epoch is replaced, by compare-and-set. */
|
|
19
|
+
export async function leaveMountRevoke(settings, runId, left) {
|
|
20
|
+
const key = mountRevokeKeyOf(runId);
|
|
21
|
+
const row = { epoch: left.epoch, disk: left.disk, until: left.until };
|
|
22
|
+
for (let tries = 0; tries < LEAVE_TRIES; tries += 1) {
|
|
23
|
+
const was = await settings.get(key);
|
|
24
|
+
if (was === undefined) {
|
|
25
|
+
const kept = leftRevokeOf(await settings.putIfAbsent(key, row));
|
|
26
|
+
if (kept && kept.epoch >= row.epoch)
|
|
27
|
+
return;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const other = leftRevokeOf(was);
|
|
31
|
+
if (other && other.epoch >= row.epoch)
|
|
32
|
+
return;
|
|
33
|
+
if (await settings.replaceIf(key, was, row))
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`run ${runId}'s Archil mount credential remove could not be left for the janitor: its row kept changing`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The janitor's pass over the left removes: each asked of `revoke` (the kept pass's revokeMount, which asks nothing past
|
|
40
|
+
* the row's time plus MOUNT_TTL_MS), bounded by `deleteMs` (KEPT_DELETE_MS) as a kept computer's delete is, its Archil
|
|
41
|
+
* calls cut at the bound by the signal it is handed; and its row removed once that answers, only while it still reads as
|
|
42
|
+
* read (a later claim's left since stays). One that throws or passes its bound is left for the next pass, said in
|
|
43
|
+
* `failed`, and the pass goes on. Never throws.
|
|
44
|
+
*/
|
|
45
|
+
export async function sweepMountRevokes(deps) {
|
|
46
|
+
const failed = [];
|
|
47
|
+
let rows;
|
|
48
|
+
try {
|
|
49
|
+
rows = await deps.settings.all({ prefix: MOUNT_REVOKE_PREFIX });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return { failed: [`the left Archil mount credential removes could not be read: ${error?.message ?? String(error)}`] };
|
|
53
|
+
}
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const runId = row.key.slice(MOUNT_REVOKE_PREFIX.length);
|
|
56
|
+
const cut = new AbortController();
|
|
57
|
+
try {
|
|
58
|
+
const left = leftRevokeOf(row.value);
|
|
59
|
+
if (left)
|
|
60
|
+
await bounded(deps.deleteMs ?? KEPT_DELETE_MS, deps.revoke(runId, left, cut.signal));
|
|
61
|
+
await deps.settings.removeIf(row.key, row.value);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
failed.push(`the Archil mount credential of run ${runId}: ${error?.message ?? String(error)}`);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
// Its Archil calls cut, where the bound passed first.
|
|
68
|
+
cut.abort(new Error("the janitor's bound on the remove passed"));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { failed };
|
|
72
|
+
}
|
|
@@ -16,14 +16,13 @@
|
|
|
16
16
|
// hub (runner/beside.ts, under the name and incarnation Serve.beside gives it): the box stays where it is, and a runner
|
|
17
17
|
// apart's take for another run is refused while that hold lasts.
|
|
18
18
|
//
|
|
19
|
-
// A route is stale only when its runner is not live (runner/presence.ts: no word of it for
|
|
19
|
+
// A route is stale only when its runner is not live (runner/presence.ts: no word of it for RUNNER_STALE_MS; a runner
|
|
20
20
|
// beside its server says it is there with no relay) or names another incarnation (that runner restarted since, or the
|
|
21
21
|
// server it ran beside did); or when its run is final, so a runner's release that never dropped its route (its write
|
|
22
22
|
// failed) keeps the box from no other run. A route of another run, on a live runner, refuses the take: one run at a time.
|
|
23
23
|
import { ATTACH_HELLO_MS, ATTACH_REDIAL_MAX_MS } from "@parcha/agentrun-computer";
|
|
24
24
|
import { RELAY_CONNECT_MS } from "../live-reach.js";
|
|
25
|
-
import {
|
|
26
|
-
import { FINAL_STATES } from "../store/index.js";
|
|
25
|
+
import { FINAL_STATES, RUNNER_STALE_MS } from "../store/index.js";
|
|
27
26
|
/** The settings key prefix of the paired computers' routes, one row per computer. */
|
|
28
27
|
export const ROUTE_PREFIX = "paired_route:";
|
|
29
28
|
/** The settings key of computer `id`'s route. */
|
|
@@ -105,12 +104,12 @@ export const lateWords = (name, runner) => `${name} did not reach runner ${runne
|
|
|
105
104
|
const changedWords = (name) => `${name}'s route changed while this run took it: its next claim tries again`;
|
|
106
105
|
/** Why `route` keeps computer `name` from `want`'s run, or undefined where the run may take it: no route, the run's own
|
|
107
106
|
* (a resume on another runner), a route whose runner is not live or restarted since, or one whose run is final. A
|
|
108
|
-
* live runner is any runner's row seen within
|
|
107
|
+
* live runner is any runner's row seen within RUNNER_STALE_MS, with a relay or without one: the runner beside its
|
|
109
108
|
* server keeps none, and its route holds the same. */
|
|
110
109
|
async function holdsAgainst(deps, route, want, name) {
|
|
111
110
|
if (route.runner === null || route.run === want.run)
|
|
112
111
|
return undefined;
|
|
113
|
-
const at = (await deps.runners.live(
|
|
112
|
+
const at = (await deps.runners.live(RUNNER_STALE_MS)).find((row) => row.runner === route.runner);
|
|
114
113
|
if (at === undefined || at.incarnation !== route.incarnation)
|
|
115
114
|
return undefined;
|
|
116
115
|
// A run that ended, stopped or failed holds nothing: its runner's release dropped the route, or that write failed. It
|
|
@@ -6,16 +6,12 @@ export declare const agentDirName: (agentId: string) => string;
|
|
|
6
6
|
export declare const agentFolder: (dataDir: string, agentId: string) => string;
|
|
7
7
|
/** Run `runId`'s folder as a key from a disk's root: `agents/<agent>/runs/<run>/work` (an Archil workspace's root). */
|
|
8
8
|
export declare const runKey: (agentId: string, runId: string) => string;
|
|
9
|
-
/** Agent `agentId`'s learning folder as a key from a disk's root: `agents/<agent>/learning`. */
|
|
10
|
-
export declare const learningKey: (agentId: string) => string;
|
|
11
9
|
/** Run `runId`'s folder, the root of its Workspace: `<data>/disk/agents/<agent>/runs/<run>/work`. */
|
|
12
10
|
export declare const runFolder: (dataDir: string, agentId: string, runId: string) => string;
|
|
13
11
|
/** The recordings folder's name: beside a run's folder on this machine, and the run files route's path to it. */
|
|
14
12
|
export declare const RECORDINGS = "recordings";
|
|
15
13
|
/** Run `runId`'s recordings on this machine, beside its folder: `<data>/disk/agents/<agent>/runs/<run>/recordings`. */
|
|
16
14
|
export declare const recordingsFolder: (dataDir: string, agentId: string, runId: string) => string;
|
|
17
|
-
/** Agent `agentId`'s learning folder, the root of its learning Workspace: `<data>/disk/agents/<agent>/learning`. */
|
|
18
|
-
export declare const agentLearningFolder: (dataDir: string, agentId: string) => string;
|
|
19
15
|
/** Agent `agentId`'s home as a key from a disk's root: `agents/<agent>/home`. */
|
|
20
16
|
export declare const homeKey: (agentId: string) => string;
|
|
21
17
|
/** Agent `agentId`'s home, the root of its home Workspace: `<data>/disk/agents/<agent>/home`. */
|
package/dist/workspace/paths.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Layout, under a server's data directory, or from the root of an Archil disk (the same keys, without <data>/disk):
|
|
4
4
|
// <data>/disk/agents/<agent>/runs/<run>/work a run's folder (runFolder; runKey on a disk): its Workspace's root
|
|
5
|
-
// <data>/disk/agents/<agent>/learning an agent's learning folder (agentLearningFolder; learningKey): its git
|
|
6
|
-
// folder
|
|
7
5
|
// <data>/disk/agents/<agent>/home an agent's home (agentHomeFolder; homeKey): the files its owner keeps
|
|
8
6
|
// for it
|
|
9
7
|
// and on this machine alone:
|
|
@@ -41,16 +39,12 @@ export const agentDirName = (agentId) => `${checkId(agentId, "agent").toLowerCas
|
|
|
41
39
|
export const agentFolder = (dataDir, agentId) => join(dataDir, DISK_DIR, "agents", agentDirName(agentId));
|
|
42
40
|
/** Run `runId`'s folder as a key from a disk's root: `agents/<agent>/runs/<run>/work` (an Archil workspace's root). */
|
|
43
41
|
export const runKey = (agentId, runId) => `agents/${agentDirName(agentId)}/runs/${checkId(runId, "run")}/work`;
|
|
44
|
-
/** Agent `agentId`'s learning folder as a key from a disk's root: `agents/<agent>/learning`. */
|
|
45
|
-
export const learningKey = (agentId) => `agents/${agentDirName(agentId)}/learning`;
|
|
46
42
|
/** Run `runId`'s folder, the root of its Workspace: `<data>/disk/agents/<agent>/runs/<run>/work`. */
|
|
47
43
|
export const runFolder = (dataDir, agentId, runId) => join(dataDir, DISK_DIR, runKey(agentId, runId));
|
|
48
44
|
/** The recordings folder's name: beside a run's folder on this machine, and the run files route's path to it. */
|
|
49
45
|
export const RECORDINGS = "recordings";
|
|
50
46
|
/** Run `runId`'s recordings on this machine, beside its folder: `<data>/disk/agents/<agent>/runs/<run>/recordings`. */
|
|
51
47
|
export const recordingsFolder = (dataDir, agentId, runId) => join(dirname(runFolder(dataDir, agentId, runId)), RECORDINGS);
|
|
52
|
-
/** Agent `agentId`'s learning folder, the root of its learning Workspace: `<data>/disk/agents/<agent>/learning`. */
|
|
53
|
-
export const agentLearningFolder = (dataDir, agentId) => join(dataDir, DISK_DIR, learningKey(agentId));
|
|
54
48
|
/** Agent `agentId`'s home as a key from a disk's root: `agents/<agent>/home`. */
|
|
55
49
|
export const homeKey = (agentId) => `agents/${agentDirName(agentId)}/home`;
|
|
56
50
|
/** Agent `agentId`'s home, the root of its home Workspace: `<data>/disk/agents/<agent>/home`. */
|
|
@@ -261,9 +261,12 @@ export declare function runFolderOf(setting: ComputerSetting, mode: 1 | 2, regis
|
|
|
261
261
|
* runs nothing: "none". The setting is the agent's as saved; where it has none, the caller gives the server's default.
|
|
262
262
|
*/
|
|
263
263
|
export declare function runShellOf(setting: ComputerSetting, mode: 1 | 2, registry: Pick<KindRegistry, "SETTING_KINDS" | "servingRefusals" | "PROVIDERS">): ShellPlace;
|
|
264
|
-
/** What a choice of computer leaves out of the shell, in plain words: shown beside it (GET /v2/computers shell_note)
|
|
265
|
-
*
|
|
264
|
+
/** What a choice of no computer leaves out of the shell, in plain words: shown beside it (GET /v2/computers shell_note).
|
|
265
|
+
* A computer that mounts the folder leaves nothing out; one that doesn't says so in its own words (APART_SHELL_NOTES). */
|
|
266
266
|
export declare const SHELL_NOTES: Readonly<Record<Exclude<ShellPlace, "computer">, string>>;
|
|
267
|
+
/** What a computer that gives the run no shell of its own leaves out (it doesn't mount the run's folder, or runs no
|
|
268
|
+
* programs): a computer all the same, so never "no computer". */
|
|
269
|
+
export declare const APART_SHELL_NOTES: Readonly<Record<Exclude<ShellPlace, "computer">, string>>;
|
|
267
270
|
/** The host tools a run with its shell at `shell` gets, by name: the kernel registry's own list (hostToolDefs), never a
|
|
268
271
|
* second one: the file tools always, bash with a shell, the five background tools on a computer. */
|
|
269
272
|
export declare const hostToolsOf: (shell: ShellPlace) => string[];
|
|
@@ -224,12 +224,18 @@ export function runShellOf(setting, mode, registry) {
|
|
|
224
224
|
return "none";
|
|
225
225
|
return shellPlaceOf(mounts, mode);
|
|
226
226
|
}
|
|
227
|
-
/** What a choice of computer leaves out of the shell, in plain words: shown beside it (GET /v2/computers shell_note)
|
|
228
|
-
*
|
|
227
|
+
/** What a choice of no computer leaves out of the shell, in plain words: shown beside it (GET /v2/computers shell_note).
|
|
228
|
+
* A computer that mounts the folder leaves nothing out; one that doesn't says so in its own words (APART_SHELL_NOTES). */
|
|
229
229
|
export const SHELL_NOTES = Object.freeze({
|
|
230
230
|
local: "No computer: bash runs in a fresh container on the folder's own storage; background commands need a computer.",
|
|
231
231
|
none: "No computer on this server: the agent gets the file tools only, no shell. Pick a computer to run commands.",
|
|
232
232
|
});
|
|
233
|
+
/** What a computer that gives the run no shell of its own leaves out (it doesn't mount the run's folder, or runs no
|
|
234
|
+
* programs): a computer all the same, so never "no computer". */
|
|
235
|
+
export const APART_SHELL_NOTES = Object.freeze({
|
|
236
|
+
local: "This computer doesn't mount the run's folder: bash runs in a fresh container on the folder's own storage; background commands need a computer that mounts it.",
|
|
237
|
+
none: "This computer gives the run no shell: the agent gets the file tools only. Pick a computer that mounts the run's folder to run commands.",
|
|
238
|
+
});
|
|
233
239
|
/** The host tools a run with its shell at `shell` gets, by name: the kernel registry's own list (hostToolDefs), never a
|
|
234
240
|
* second one: the file tools always, bash with a shell, the five background tools on a computer. */
|
|
235
241
|
export const hostToolsOf = (shell) => hostToolDefs({ maxExecS: 600, shell }).map((def) => def.name);
|
|
@@ -237,7 +243,7 @@ export const hostToolsOf = (shell) => hostToolDefs({ maxExecS: 600, shell }).map
|
|
|
237
243
|
* gives, and what it leaves out, in words (none for a computer that mounts the folder). */
|
|
238
244
|
export function shellChoiceOf(setting, mode, registry) {
|
|
239
245
|
const shell = runShellOf(setting, mode, registry);
|
|
240
|
-
return { shell, host_tools: hostToolsOf(shell), ...(shell === "computer" ? {} : { shell_note: SHELL_NOTES[shell] }) };
|
|
246
|
+
return { shell, host_tools: hostToolsOf(shell), ...(shell === "computer" ? {} : { shell_note: (setting.kind === "none" ? SHELL_NOTES : APART_SHELL_NOTES)[shell] }) };
|
|
241
247
|
}
|
|
242
248
|
/** The server's default where an agent has no computer setting: in Mode 1 a sandbox on the first provider that binds a
|
|
243
249
|
* folder of this machine and answers here (Docker), else none; in Mode 2 none. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Store } from "../store/index.js";
|
|
2
2
|
import type { ComputerDeps } from "./computer-deps.js";
|
|
3
|
-
import { type KeptHolder } from "./computer-kept.js";
|
|
4
3
|
/** The longest a run's end may spend on its computers, every try with its pauses: past it the provider's calls are cut
|
|
5
4
|
* (one that takes no signal, a release, left to finish on its own) and the run's end goes on, said in the log. */
|
|
6
5
|
export declare const RUN_END_COMPUTERS_MS = 120000;
|
|
@@ -9,18 +8,25 @@ export declare const RUN_END_RETRY_MS = 5000;
|
|
|
9
8
|
export interface RunEndComputersDeps {
|
|
10
9
|
/** The run's row and launch (its revision and place) and the agent's revision, where its computer setting is; the
|
|
11
10
|
* computer ledger, for a provider that keeps one. */
|
|
12
|
-
readonly store: Pick<Store, "agents" | "computerLedger" | "settings"> & {
|
|
11
|
+
readonly store: Pick<Store, "agents" | "computerLedger" | "settings" | "sealedKeys"> & {
|
|
13
12
|
readonly runs: Pick<Store["runs"], "get" | "launch">;
|
|
14
13
|
readonly computerIntervals?: Store["computerIntervals"];
|
|
15
14
|
};
|
|
15
|
+
/** The runs' environment and the server's seal key, as the janitor is handed them: with them, a machine kept on Archil
|
|
16
|
+
* that this end deletes has its park's mount credential removed (computer-janitor.ts keptMountRevoke) before its row
|
|
17
|
+
* is marked ended. Absent `env`: that row is left ending, for the janitor's kept pass. */
|
|
18
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
19
|
+
readonly sealKey?: Buffer | undefined;
|
|
20
|
+
/** Archil's control plane for that remove: a test's fake. Absent: the region's own. */
|
|
21
|
+
readonly mountControl?: {
|
|
22
|
+
readonly baseUrl?: string;
|
|
23
|
+
readonly fetch?: typeof fetch;
|
|
24
|
+
};
|
|
16
25
|
/** The run's computers as the runner composed them (computer-deps.ts computerDepsFrom): the registry, the provider
|
|
17
26
|
* makers, the key reader, and --faux's launch with the providers it takes. */
|
|
18
27
|
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf" | "keyTable" | "settings" | "launch" | "launches">;
|
|
19
28
|
/** Where what was let go, and a provider that failed, are said. */
|
|
20
29
|
readonly log: (line: string) => void;
|
|
21
|
-
/** The runner this end runs in (its name and presence incarnation), read at each end: a computer kept pinned to it is
|
|
22
|
-
* its own to let go here. Absent: every kept row that names a runner is another's. */
|
|
23
|
-
readonly self?: () => KeptHolder | undefined;
|
|
24
30
|
/** The bound on every try. Default RUN_END_COMPUTERS_MS. */
|
|
25
31
|
readonly timeoutMs?: number;
|
|
26
32
|
/** The pause between tries. Default RUN_END_RETRY_MS. */
|
|
@@ -16,15 +16,41 @@
|
|
|
16
16
|
// run's end stands. The janitor (computer-janitor.ts) ends a computer of a run that is over on its next sweep too, for a
|
|
17
17
|
// server that stopped before this ran, or a vendor that stayed down past the bound.
|
|
18
18
|
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
|
|
19
|
+
// A machine the run's park kept (computer-kept.ts) goes too when this end's provider lists it, whichever runner kept it:
|
|
20
|
+
// the run is final, so it has no user. Its row is marked ending first (endingKept), so no claim takes it back while the
|
|
21
|
+
// delete runs (a follow-up that queues the run again makes a new one). Once that machine is gone, its row is marked
|
|
22
|
+
// ended here (finishedKept), whatever came of the other machines' deletes: its own delete answered ok, or its vendor
|
|
23
|
+
// says it is gone already, or a later try's list no longer shows it. A row left ending refuses the run's next park until
|
|
24
|
+
// a janitor's pass, so a follow-up would keep nothing, and no retry here would find the machine to end it by. A row
|
|
25
|
+
// whose machine this list never showed (another runner's engine) stays ending for that runner's end. A
|
|
26
|
+
// row a later claim wrote or is taking back (a follow-up that queued the run again while this end
|
|
27
|
+
// waited on the store) is that claim's: the mark leaves it as it stands, and the delete leaves its machine. A row
|
|
28
|
+
// that reads ended once the deletes are done is removed (forgetEnded): the resume it was ended for came and went, so a
|
|
29
|
+
// follow-up that queues the run again reads no keep and never says that lapse again, with no janitor's pass to wait for.
|
|
30
|
+
//
|
|
31
|
+
// A later claim that took the run before this end got to it (a follow-up queued the stopped run again, claimed it and
|
|
32
|
+
// took the kept machine back, the row gone) holds a machine labelled at the epoch of the claim that made it, at or below
|
|
33
|
+
// the ending claim's: deleted here, it would go from under that claim's turn. So an end whose run a later claim has
|
|
34
|
+
// taken (its epoch moved past the end's own move, run-patch.ts) lets nothing go, and leaves the kept row as it reads:
|
|
35
|
+
// every machine left is that claim's to let go, at its own end or its launch (releaseOlderClaims). Read before the mark
|
|
36
|
+
// and again after it: a claim takes a row only after its claim, so one not yet there once the row reads ending, ended or
|
|
37
|
+
// gone can no longer take a machine of this end's. A read that fails, or finds no run, can't tell whether a later claim
|
|
38
|
+
// has the run, and a machine's old label can't either: the end lets nothing go then too (before the mark, it marks
|
|
39
|
+
// nothing), said in the log. What is left goes at the run's next end or the computer janitor's sweep. That sweep skips a
|
|
40
|
+
// provider whose vendor ends its own machines (its capabilities().lifetime is "vendor"; VENDOR_ENDS_ITS_OWN below names
|
|
41
|
+
// them): there the janitor ends only a machine a park kept, by its row, and any other machine left runs until the
|
|
42
|
+
// vendor's own lifetime ends it.
|
|
43
|
+
// A machine kept on Archil has its park's mount credential removed before its row is marked ended
|
|
44
|
+
// (computer-janitor.ts keptMountRevoke, as the janitor's kept pass removes it): an ended row is one no janitor pass
|
|
45
|
+
// removes a credential for, so one marked ended first would leave it valid for its ttl with no machine. A remove that
|
|
46
|
+
// fails, or an end composed without the runs' environment, leaves the row ending, and the janitor's kept pass removes the
|
|
47
|
+
// credential and ends it.
|
|
48
|
+
import { epochOf, ok, releaseOlder } from "@parcha/agentrun-computer";
|
|
24
49
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
25
50
|
import { readLaunchBody } from "../run-launch.js";
|
|
26
51
|
import { settingOf } from "./computer-for-claim.js";
|
|
27
|
-
import {
|
|
52
|
+
import { keptMountRevoke } from "./computer-janitor.js";
|
|
53
|
+
import { endingKept, finishedKept, forgetEnded } from "./computer-kept.js";
|
|
28
54
|
import { storeLedger } from "./computer-ledger.js";
|
|
29
55
|
import { providerKeys } from "./resolve-computer.js";
|
|
30
56
|
import { endingDeletes, intervalWrites } from "./computer-intervals.js";
|
|
@@ -33,11 +59,72 @@ import { endingDeletes, intervalWrites } from "./computer-intervals.js";
|
|
|
33
59
|
export const RUN_END_COMPUTERS_MS = 120_000;
|
|
34
60
|
/** The pause before a run's end asks a provider that did not answer again. */
|
|
35
61
|
export const RUN_END_RETRY_MS = 5_000;
|
|
62
|
+
/** The providers whose vendor ends its own machines at their lifetime (their capabilities().lifetime is "vendor"), by
|
|
63
|
+
* their labels: the janitor's provider sweep skips them (computer-janitor.ts sweepServerComputers), so there it ends
|
|
64
|
+
* only a machine a park kept (its kept pass, on any provider). Kept by hand, and held to the registry by
|
|
65
|
+
* run-end-computers-vendor-list.test.mjs: a provider added with lifetime "vendor" must be named here too. */
|
|
66
|
+
const VENDOR_ENDS_ITS_OWN = "E2B, Daytona, Modal, Morph, Browserbase, Kernel or the phone harness";
|
|
36
67
|
/** Why a run's end can't have its provider here, which no later try changes: its keys or options. */
|
|
37
68
|
class NoProviderHere extends Error {
|
|
38
69
|
}
|
|
39
70
|
/** A releaseOlder answer no later try changes: fenced by a later claim's computer (refused), asked wrongly, or cut. */
|
|
40
71
|
const FINAL_CODES = new Set(["refused", "invalid", "aborted"]);
|
|
72
|
+
/** `provider` with the kept machine `id` out of its lists, where releaseOlder would delete it (labelled at or below the
|
|
73
|
+
* ending claim's `epoch`, or with no epoch it can read); labelled above, it stays listed and fences the call as before. */
|
|
74
|
+
function sparing(provider, id, epoch) {
|
|
75
|
+
return new Proxy(provider, {
|
|
76
|
+
get(target, key) {
|
|
77
|
+
if (key !== "list") {
|
|
78
|
+
const value = Reflect.get(target, key, target);
|
|
79
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
80
|
+
}
|
|
81
|
+
return async (...args) => {
|
|
82
|
+
const listed = await target.list(...args);
|
|
83
|
+
if (!listed.ok)
|
|
84
|
+
return listed;
|
|
85
|
+
return ok(listed.value.filter((info) => {
|
|
86
|
+
if (info.ref.id !== id)
|
|
87
|
+
return true;
|
|
88
|
+
const read = epochOf(info.labels);
|
|
89
|
+
return read.ok && read.value > epoch;
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** `provider` that calls `gone` once the kept machine `id` is gone, whatever comes of the other deletes in the same
|
|
96
|
+
* release: its own delete answered ok, or not_found or gone (its vendor ended it already), or a list no longer shows it
|
|
97
|
+
* where an earlier one did (a delete that went through with its answer lost). `seen` carries what earlier lists showed
|
|
98
|
+
* across tries, each of which makes its provider anew. */
|
|
99
|
+
function finishing(provider, id, seen, gone) {
|
|
100
|
+
return new Proxy(provider, {
|
|
101
|
+
get(target, key) {
|
|
102
|
+
if (key === "list") {
|
|
103
|
+
return async (...args) => {
|
|
104
|
+
const listed = await target.list(...args);
|
|
105
|
+
if (!listed.ok)
|
|
106
|
+
return listed;
|
|
107
|
+
if (listed.value.some((info) => info.ref.id === id))
|
|
108
|
+
seen.listed = true;
|
|
109
|
+
else if (seen.listed)
|
|
110
|
+
await gone();
|
|
111
|
+
return listed;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (key === "release") {
|
|
115
|
+
return async (...args) => {
|
|
116
|
+
const released = await target.release(...args);
|
|
117
|
+
const [ref, how] = args;
|
|
118
|
+
if (ref.id === id && how === "delete" && (released.ok || released.error.code === "not_found" || released.error.code === "gone"))
|
|
119
|
+
await gone();
|
|
120
|
+
return released;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const value = Reflect.get(target, key, target);
|
|
124
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
41
128
|
/** Waits `ms`, or less when `signal` aborts first: whether the wait ran its course. */
|
|
42
129
|
const pause = (ms, signal) => new Promise((resolve) => {
|
|
43
130
|
if (signal.aborted)
|
|
@@ -52,19 +139,6 @@ const pause = (ms, signal) => new Promise((resolve) => {
|
|
|
52
139
|
}, ms);
|
|
53
140
|
signal.addEventListener("abort", done, { once: true });
|
|
54
141
|
});
|
|
55
|
-
/** `provider` with the computer `id` left out of its lists: releaseOlder never sees it, so never deletes it. */
|
|
56
|
-
const sparing = (provider, id) => new Proxy(provider, {
|
|
57
|
-
get(target, key) {
|
|
58
|
-
if (key !== "list") {
|
|
59
|
-
const value = Reflect.get(target, key, target);
|
|
60
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
61
|
-
}
|
|
62
|
-
return async (...args) => {
|
|
63
|
-
const listed = await target.list(...args);
|
|
64
|
-
return listed.ok ? { ...listed, value: listed.value.filter((info) => info.ref.id !== id) } : listed;
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
142
|
/** The run's end for its computers (RunEndComputersDeps): given the claim that ended the run, every computer of the run
|
|
69
143
|
* at or below its epoch deleted, a provider that did not answer asked again until the bound. Never throws: a failure
|
|
70
144
|
* is said in the log. */
|
|
@@ -72,6 +146,8 @@ export function runEndComputers(deps) {
|
|
|
72
146
|
const { store, computers, log } = deps;
|
|
73
147
|
/** Each computer let go here ends its interval (computer-intervals.ts), on its provider's ok alone. */
|
|
74
148
|
const writes = intervalWrites(store, log);
|
|
149
|
+
/** The remove of a kept row's Archil mount credential, its ttl judged on the store's clock. */
|
|
150
|
+
const revokeMount = deps.env !== undefined ? keptMountRevoke({ settings: store.settings, sealedKeys: store.sealedKeys, env: deps.env, sealKey: deps.sealKey, ...(deps.mountControl ? { mountControl: deps.mountControl } : {}) }, () => store.sealedKeys.clock()) : undefined;
|
|
75
151
|
/** The provider the run's computers are on, by the agent's setting; undefined where none of them is this end's to let
|
|
76
152
|
* go (none, the agent's own, a paired computer, --faux's). */
|
|
77
153
|
const providerOf = async (runId, epoch) => {
|
|
@@ -98,15 +174,26 @@ export function runEndComputers(deps) {
|
|
|
98
174
|
// A throw from here on is the vendor's or the daemon's (Docker's architecture asked): asked again.
|
|
99
175
|
return endingDeletes(await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) }), entry.id, writes);
|
|
100
176
|
};
|
|
101
|
-
/**
|
|
102
|
-
* that
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
177
|
+
/** Whether the end of the claim at `epoch` lets none of run `runId`'s computers go: a later claim took the run since
|
|
178
|
+
* (that end moved the run's epoch once past the claim's, run-patch.ts, and only a claim or its release moves it
|
|
179
|
+
* again), or the run can't be read to tell (the read failed, or found no run). A machine a later claim took back keeps
|
|
180
|
+
* its maker's label, at or below `epoch`, so only this read keeps the deletes off it. Said once in the log when so. */
|
|
181
|
+
const movedOn = async (runId, epoch) => {
|
|
182
|
+
const read = await store.runs.get(runId).then((run) => (run ? { run } : { why: "no such run" }), (error) => ({ why: error instanceof Error ? error.message : String(error) }));
|
|
183
|
+
if ("why" in read) {
|
|
184
|
+
log(`run ${runId}'s end at claim ${epoch} lets no computer go: the run could not be read (${read.why}) to tell whether a later claim holds one of them, so they are left for that claim, the run's next end or the computer janitor (on ${VENDOR_ENDS_ITS_OWN} it ends only a machine a park kept: any other there runs until the vendor's own lifetime ends it)`);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (read.run.epoch <= epoch + 1)
|
|
188
|
+
return false;
|
|
189
|
+
log(`run ${runId}'s end at claim ${epoch} lets no computer go: a later claim took the run again and may hold one of them, so they are that claim's to let go`);
|
|
190
|
+
return true;
|
|
106
191
|
};
|
|
107
192
|
return async ({ runId, epoch }) => {
|
|
108
193
|
if (epoch <= 1)
|
|
109
194
|
return;
|
|
195
|
+
if (await movedOn(runId, epoch))
|
|
196
|
+
return;
|
|
110
197
|
const bound = deps.timeoutMs ?? RUN_END_COMPUTERS_MS;
|
|
111
198
|
const signal = AbortSignal.timeout(bound);
|
|
112
199
|
let said = false;
|
|
@@ -116,17 +203,53 @@ export function runEndComputers(deps) {
|
|
|
116
203
|
said = true;
|
|
117
204
|
log(`run ${runId} is over, but its computers could not be let go: ${why}`);
|
|
118
205
|
};
|
|
206
|
+
// Its kept row, where its park kept one, marked ending before any delete: no claim takes that machine back now. A
|
|
207
|
+
// later claim's keep is left as it stands, its machine with it (endingKept). A mark the store fails is tried again;
|
|
208
|
+
// a machine whose row no try marked is not deleted, since a claim could still take the row and attach it mid-delete:
|
|
209
|
+
// it is left for its row's own time (its keeper's end, or a janitor's pass, which marks the row first). A row that
|
|
210
|
+
// could not even be read names no machine, so none of the run's is deleted here, and the janitor's sweep ends them.
|
|
211
|
+
const marked = await endingKept(store.settings, runId, epoch);
|
|
212
|
+
if (marked.kind === "unmarked") {
|
|
213
|
+
log(`run ${runId} is over, but its kept computer's row could not be marked ending (${marked.why}): ${marked.id === undefined ? "no computer of the run is let go here, and the computer janitor's next sweep ends them" : `${marked.id} is left for its row's time, which ends it`}`);
|
|
214
|
+
if (marked.id === undefined)
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (await movedOn(runId, epoch))
|
|
218
|
+
return;
|
|
219
|
+
/** The kept machine this end leaves: a later claim's, or one whose row no try marked. */
|
|
220
|
+
const spared = marked.kind === "marked" ? undefined : marked.id;
|
|
221
|
+
/** The kept row this end marked ending: ended as soon as its own machine is gone (finishing), so a follow-up's park
|
|
222
|
+
* writes its own keep, though another machine's delete failed and this end asks again or gives up. On Archil, its
|
|
223
|
+
* park's mount credential is removed first (finishedKept); one that fails leaves the row ending, said. */
|
|
224
|
+
const kept = marked.kind === "marked" ? marked.kept : undefined;
|
|
225
|
+
const seen = { listed: false };
|
|
226
|
+
let finished = false;
|
|
227
|
+
const revoked = revokeMount && (async (id, row) => {
|
|
228
|
+
try {
|
|
229
|
+
await revokeMount(id, row);
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
log(`run ${runId} is over and its kept ${row.kind} ${row.id} is gone, but its mount credential could not be removed (${error instanceof Error ? error.message : String(error)}): its row is left ending, and the computer janitor's next pass removes it`);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
const gone = async () => {
|
|
237
|
+
if (finished || !kept)
|
|
238
|
+
return;
|
|
239
|
+
finished = true;
|
|
240
|
+
await finishedKept(store.settings, runId, kept, revoked);
|
|
241
|
+
};
|
|
119
242
|
/** The last try's failure, for the line said at the bound. */
|
|
120
243
|
let why = `its provider did not answer within ${bound / 1000} s`;
|
|
121
244
|
const tries = async () => {
|
|
122
245
|
for (;;) {
|
|
123
246
|
try {
|
|
124
|
-
const
|
|
125
|
-
if (!
|
|
247
|
+
const found = await providerOf(runId, epoch);
|
|
248
|
+
if (!found)
|
|
126
249
|
return;
|
|
127
|
-
const
|
|
250
|
+
const provider = spared !== undefined ? sparing(found, spared, epoch) : kept ? finishing(found, kept.id, seen, gone) : found;
|
|
128
251
|
// Every claim's at or below this one's: a computer of a later epoch fences the call (a later claim holds the run).
|
|
129
|
-
const released = await releaseOlder(
|
|
252
|
+
const released = await releaseOlder(provider, runId, epoch + 1, { signal });
|
|
130
253
|
if (released.ok) {
|
|
131
254
|
const names = released.value.released.map((ref) => ref.name);
|
|
132
255
|
if (names.length > 0)
|
|
@@ -162,5 +285,7 @@ export function runEndComputers(deps) {
|
|
|
162
285
|
finally {
|
|
163
286
|
signal.removeEventListener("abort", stop);
|
|
164
287
|
}
|
|
288
|
+
// Its row, where it reads ended now (this end finished it, or it was ended before): the run's no more.
|
|
289
|
+
await forgetEnded(store.settings, runId, epoch);
|
|
165
290
|
};
|
|
166
291
|
}
|