@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/server.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ObservationLearning } from "./observation/learning.js";
|
|
|
16
16
|
import { cliLearningOf } from "./store/agent-body.js";
|
|
17
17
|
import { maintainObservations, Observations } from './observation/observer.js';
|
|
18
18
|
import { isObservationRoute, observationHttp } from './observation/http.js';
|
|
19
|
-
import { SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
19
|
+
import { forgetSdkCopies, SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
20
20
|
import { learningModelOf } from "./learning-model.js";
|
|
21
21
|
import { answerSkill } from './skill-route.js';
|
|
22
22
|
import { RemoteConnectors, verifyRemote, REMOTE_COMPLETION_BODY_BYTES } from './native/remote.js';
|
|
@@ -33,12 +33,13 @@ import { createServer } from "node:http";
|
|
|
33
33
|
import proxyaddr from "proxy-addr";
|
|
34
34
|
import { API_ONLY_HOOKED_KINDS, apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerSkipped, servedApiOnly } from "./api-only.js";
|
|
35
35
|
import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
|
|
36
|
-
import { holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
|
|
36
|
+
import { composioOutsideNamespaceServers, holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
|
|
37
37
|
import { declaredKeys, keysOwed, keysOwedRefusal, runKeysOf, runKeysTriggerSkipped, undeclaredKeys, withCarried } from "./run-keys.js";
|
|
38
38
|
import { capacityOverStore, capacityWindowOf } from "./capacity.js";
|
|
39
39
|
import { carriedFields } from "./answer-json.js";
|
|
40
40
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
41
41
|
import { pathToFileURL } from "node:url";
|
|
42
|
+
import { isDeepStrictEqual } from "node:util";
|
|
42
43
|
import { Worker } from "node:worker_threads";
|
|
43
44
|
import { once } from "node:events";
|
|
44
45
|
import { existsSync } from "node:fs";
|
|
@@ -50,7 +51,7 @@ import { uuidv7 } from "./ids.js";
|
|
|
50
51
|
import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, definitionOf, etagOf, externalKey, getAgent, listAgents, makeRevision, ownedElsewhere, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
|
|
51
52
|
import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
|
|
52
53
|
import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
|
|
53
|
-
import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV } from "./web-run.js";
|
|
54
|
+
import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV, withHeld } from "./web-run.js";
|
|
54
55
|
import { FAUX_MONID_ENV, MONID_KEY_ENV, monidReads, pinMonid, PRICED_BY_USAGE } from "./monid.js";
|
|
55
56
|
import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
56
57
|
import { ApiError, invalid, sentence, unsupported } from "./errors.js";
|
|
@@ -64,15 +65,15 @@ import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARN
|
|
|
64
65
|
import { claudeCliIn, HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
65
66
|
import { DEFAULT_PORT, healthOf, hostMemory, maxRunsOf, runsThatFit } from "./host.js";
|
|
66
67
|
import { DEFAULT_HOST, elsewhereOf, listenOn, minFreeMibOf, takeOver, urlOf } from "./listen-first.js";
|
|
67
|
-
import { IMPORT_ASKED, MAX_CANDIDATES } from "./import.js";
|
|
68
|
+
import { IMPORT_ASKED, IMPORT_HEAP_MB, MAX_CANDIDATES } from "./import.js";
|
|
68
69
|
import { answerStoreCall } from "./import-proxy.js";
|
|
69
|
-
import {
|
|
70
|
+
import { inLearningQueue, LEARNING_LABEL, secretsShown, learningOf, learnsOf, RUN_LEARNING_USE, seedOf } from "./learning.js";
|
|
70
71
|
import { askReplay, ReplayRefused, replayView } from "./runner/promotion.js";
|
|
71
|
-
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite,
|
|
72
|
-
import { purgedRun
|
|
72
|
+
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite, learningLog, pendingCount, readLearnedFile, sendText, statusesOf, textBody, workflowAtDigest, workflowRevisions } from "./learning-routes.js";
|
|
73
|
+
import { purgedRun } from "./purged-workflow.js";
|
|
73
74
|
import { answerLlms, MCP_PATH, mcpEndpoint } from "./mcp.js";
|
|
74
75
|
import { openapiDocument, servedOpenapi, UNSUPPORTED } from "./openapi.js";
|
|
75
|
-
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, placesOf, resolvePlace } from "./place.js";
|
|
76
|
+
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, noBoxRefusal, placesOf, resolvePlace } from "./place.js";
|
|
76
77
|
import { boxAllowOf, boxAllowSetIn } from "./box-settings.js";
|
|
77
78
|
import { dockerLimitsOf } from "./workspace/computer-deps.js";
|
|
78
79
|
import { Owner, passwordProblem, SESSION_MS } from "./owner.js";
|
|
@@ -90,7 +91,7 @@ import { screenWaitEnded } from "./browser-wait-ended.js";
|
|
|
90
91
|
import { durationMs, logLine } from "./print.js";
|
|
91
92
|
import { keepPresence, refusedEnd, runnersRefused } from "./runner/presence.js";
|
|
92
93
|
import { approve, archiveRun, cancel, message, pause as pauseRunOverStore, prepareLaunch, raiseCap, resume as resumeRunOverStore, startInline, startRun, stop as stopRunOverStore } from "./runs-over-store.js";
|
|
93
|
-
import { builtOfNow, factsOverStore, listedItem, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
94
|
+
import { builtOfNow, factsOverStore, keptFactory, listedItem, liveOf, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
94
95
|
import { healEndedCosts } from "./cost-heal.js";
|
|
95
96
|
import { reconcileProjectCheckpoints } from "./source-sync/checkpoints.js";
|
|
96
97
|
import { acknowledgeProjects } from "./source-sync/checkpoint-gate.js";
|
|
@@ -106,34 +107,38 @@ import { agentPointers, cutHanded, handedSecretValues, launchValuesOf, RETIRED_M
|
|
|
106
107
|
import { runCutValues } from "./run-cut.js";
|
|
107
108
|
import { readLaunchBody } from "./run-launch.js";
|
|
108
109
|
import { modelKeyMisfit, modelKeyOf, modelKeyRequired, noServerKeyFor, runModelOrigin, serverKeyMissing } from "./run-model-key.js";
|
|
110
|
+
import { exportReadsOverStore } from "./run-export-store.js";
|
|
109
111
|
import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
|
|
112
|
+
import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
|
|
110
113
|
import { triggerTargets } from "./trigger-targets.js";
|
|
111
114
|
import { labelFilter, labelsIssues } from "./run-labels.js";
|
|
112
115
|
import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
|
|
116
|
+
import { observationOf } from "./factory-activity.js";
|
|
117
|
+
import { factoryRunsPage } from "./factory-runs.js";
|
|
113
118
|
import { runEntries } from "./store-reads/journal.js";
|
|
114
119
|
import { metersOverStore, spendOverStore } from "./store-reads/cap.js";
|
|
115
120
|
import { watchRun } from "./live/stream.js";
|
|
116
121
|
import { stats as statsOverStore } from "./store-reads/stats.js";
|
|
117
122
|
import { analytics as analyticsOverStore } from "./store-reads/analytics.js";
|
|
118
123
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
119
|
-
import { openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
124
|
+
import { LearningRecordRefused, openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
120
125
|
import { agentDeleting, answerOf, logged, purgedAgent } from "./agents.js";
|
|
121
126
|
import { keepGrade } from "./runner/feedback-round.js";
|
|
122
127
|
import { gradeRow, notAuditableOf } from "./runner/audit.js";
|
|
123
|
-
import { namedDisksOf } from "./learn/learning-of.js";
|
|
124
128
|
import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
|
|
125
|
-
import { auditLoopOf, COMPILE_AFTER_MAX } from "./learning-setting.js";
|
|
129
|
+
import { auditLoopOf, COMPILE_AFTER_MAX, holdsReservedKey, RESERVED_SEGMENT } from "./learning-setting.js";
|
|
126
130
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
127
131
|
import { championOf, forgetRunCopies, GRADE_SOURCES, gradeView, LABEL_MAX, promotionsOf, promotionsShown, servingOf, servingStateOf, shownDeep } from "./learn/promote.js";
|
|
128
132
|
import { workflowNodesOf } from "./learn/workflow-nodes.js";
|
|
129
133
|
import { deleteLearning } from "./learn/delete.js";
|
|
134
|
+
import { forgetLegacyRunLearning, legacyGradesKey, legacyPromotionsKey } from "./learn/legacy/scrub.js";
|
|
130
135
|
import { runModelRef } from "./model.js";
|
|
131
136
|
import { ollamaHostOf, ollamaHostRefused, ollamaListing, ollamaModels, ollamaReading } from "./ollama-provider.js";
|
|
132
137
|
import { REDACTED } from "./secret-cut.js";
|
|
133
138
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
134
139
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
135
140
|
import { runLines } from "./usage-lines.js";
|
|
136
|
-
import { boxesByDefault, boxesLog, enabledBoxes, placeOffers, withNetworks } from "./place-offers.js";
|
|
141
|
+
import { boxesByDefault, boxesLog, DOCKER_NO_SOCKET, enabledBoxes, LOCAL_BOXES, placeOffers, withNetworks } from "./place-offers.js";
|
|
137
142
|
import { dockerComputerRefusal, dockerPathsOf, FAUX_MOUNTINFO_ENV, remoteDockerOnce } from "./box-paths.js";
|
|
138
143
|
import { dockerDaemonCheck } from "./docker-daemon.js";
|
|
139
144
|
import { hostAddressesOnce, noHostAddresses, retryHostAddresses, unionOf } from "./docker-host-addresses.js";
|
|
@@ -144,7 +149,7 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
|
144
149
|
import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
145
150
|
import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
|
|
146
151
|
import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
|
|
147
|
-
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace,
|
|
152
|
+
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, signOutClaudeLogin, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
148
153
|
import { ClaudeSignIns } from "./claude-sign-in.js";
|
|
149
154
|
import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
|
|
150
155
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
@@ -152,7 +157,7 @@ import { recordDataRoot } from "./runner/disk-free.js";
|
|
|
152
157
|
import { recordRunEnv, runFacingNames } from "./runner/runner-check.js";
|
|
153
158
|
import { DRAIN_TIMEOUT } from "./runner/beside.js";
|
|
154
159
|
import { runnerName } from "./runner/runner.js";
|
|
155
|
-
import { analyticsFilter, analyticsView, statsView } from "./stats.js";
|
|
160
|
+
import { analyticsFilter, analyticsView, statsView, utcOf } from "./stats.js";
|
|
156
161
|
import { loggedReads, within, WRAPPED_WAIT_MS, wrappedView } from "./wrapped.js";
|
|
157
162
|
import { joinedBasis } from "./runner/metrics.js";
|
|
158
163
|
import { unifiedUsage } from "./unified-usage.js";
|
|
@@ -167,7 +172,8 @@ import { SIGN_INS_DIR, vendorsOver } from "./sign-ins.js";
|
|
|
167
172
|
import { signInsOverStore } from "./sign-ins-store.js";
|
|
168
173
|
import { boundTool, MCP_AUTH_TYPES, marked, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
|
|
169
174
|
import { composioEnvKey, composioMadeKey, composioPerRun } from "./composio-made.js";
|
|
170
|
-
import {
|
|
175
|
+
import { ownersComposioUsers, ownersUser } from "./composio-owners.js";
|
|
176
|
+
import { COMPOSIO_PER_RUN, composioForget, composioNote, composioSave, composioTokenUser, composioToolkits, composioTools } from "./composio-preset.js";
|
|
171
177
|
import { ComposioTriggers, composioNoPublicUrl } from "./composio-triggers.js";
|
|
172
178
|
import { loopbackWords, mcpServersOverStore } from "./mcp-servers-store.js";
|
|
173
179
|
import { MCP_ALLOW_LOOPBACK_ENV, startSwitches, WEBHOOK_PRIVATE_TARGETS_ENV } from "./start-switches.js";
|
|
@@ -202,7 +208,7 @@ import { hereOf, Marketplace, marketplaceUrlOf } from "./marketplace.js";
|
|
|
202
208
|
import { templateInstallLink, templateLink, templatesLink } from "./console-links.js";
|
|
203
209
|
import { GITHUB_HOSTS, IMPORT_LIMITS } from "./template-source.js";
|
|
204
210
|
import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, inputSchemaOf, isObject, stable, unknownFields } from "./validate.js";
|
|
205
|
-
import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
211
|
+
import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, DEFAULT_BROWSER_VENDOR, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
206
212
|
import { wakeAnsweredBySetting } from "./settings-wake.js";
|
|
207
213
|
import { toolSettingsOverStore } from "./tool-settings-store.js";
|
|
208
214
|
import { readApprovers, writeApprovers } from "./server-approvers.js";
|
|
@@ -215,7 +221,7 @@ import { heldRoute, holdIssues, runComputerRead } from "./computer-held-routes.j
|
|
|
215
221
|
import { COMPUTER_ROUTES, computerHoldOf, computerRoute, runComputerKind } from "./computer-routes.js";
|
|
216
222
|
import { runOver } from "./computer-commands.js";
|
|
217
223
|
import { mintViewerCredential, VIEWER_PARAM, viewerCookie, viewerCredentialFor, viewerCredentialKey, viewerCredentialOf } from "./viewer-credential.js";
|
|
218
|
-
import { ATTACH_PATH, AttachHub, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
224
|
+
import { ATTACH_PATH, AttachHub, containerSigns, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
219
225
|
import { dockerDaemonOf } from "@parcha/agentrun-computer/docker";
|
|
220
226
|
import { createAttachRoutes, liveRelays, pairedView } from "./computer-attach.js";
|
|
221
227
|
import { pairedRefusal, withPaired } from "./workspace/attached-computers.js";
|
|
@@ -258,9 +264,6 @@ const TEMPLATE_UPLOAD_BODY = Math.ceil((IMPORT_LIMITS.packageBytes * 4) / 3) + M
|
|
|
258
264
|
/** The starts that may begin setup's import without ending it (a worker that failed, a process that ended) before the
|
|
259
265
|
* owner's yes is dropped: an import that fails the same way each time is not taken up at every start for good. */
|
|
260
266
|
const IMPORT_STARTS = 3;
|
|
261
|
-
/** The heap of the worker that counts or imports this machine's sessions. A run is read whole, at most MAX_RUN_BYTES of
|
|
262
|
-
* files (import.ts), which this holds several times over. */
|
|
263
|
-
const IMPORT_HEAP_MB = 2048;
|
|
264
267
|
const MAX_MESSAGE = 20_000;
|
|
265
268
|
const MAX_WAIT_MS = 25_000;
|
|
266
269
|
/** A run body's fields that a launch hook's host can't set on a firing's run (RunCreate `trigger_firing`): its trigger's
|
|
@@ -268,6 +271,14 @@ const MAX_WAIT_MS = 25_000;
|
|
|
268
271
|
const HANDED_FIXED = ["revision", "hold", "hold_minutes"];
|
|
269
272
|
/** How often the server fails the runs still queued while no runner here can take them (runner/presence.ts). */
|
|
270
273
|
const REFUSED_SWEEP_MS = 2_000;
|
|
274
|
+
/** How long the server's stop waits for a ChatGPT sign-in it cancelled to end (ChatGPTPlan.close): one past its code's
|
|
275
|
+
* exchange saves its row before the store closes; one OpenAI holds longer does not hold the stop. */
|
|
276
|
+
const PLAN_CLOSE_MS = 2_000;
|
|
277
|
+
/** The ChatGPT sign-ins `plan` cancels, ended, or `ms` gone. */
|
|
278
|
+
const planClosed = (plan, ms) => {
|
|
279
|
+
let timer;
|
|
280
|
+
return Promise.race([plan.close(), new Promise((done) => (timer = setTimeout(done, ms)))]).finally(() => clearTimeout(timer));
|
|
281
|
+
};
|
|
271
282
|
const PAGE_ROWS = 500;
|
|
272
283
|
const FILE_LIST_CAP = 2_000;
|
|
273
284
|
/** Where the stop's lines go (ServeOptions.notice). Best-effort: a notice that throws never stops a close or a start. */
|
|
@@ -371,6 +382,7 @@ export const ROUTES = [
|
|
|
371
382
|
{ method: "PUT", pattern: /^\/agents\/([^/]+)\/definition$/, name: "updateDefinition" },
|
|
372
383
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/revisions$/, name: "listRevisions" },
|
|
373
384
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/package$/, name: "getAgentPackage" },
|
|
385
|
+
{ method: "GET", pattern: /^\/agents\/([^/]+)\/revisions\/([^/]+)\/skills$/, name: "getRevisionSkills" },
|
|
374
386
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/current$/, name: "setCurrent" },
|
|
375
387
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/archive$/, name: "archiveAgent" },
|
|
376
388
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/unarchive$/, name: "unarchiveAgent" },
|
|
@@ -404,6 +416,8 @@ export const ROUTES = [
|
|
|
404
416
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/trace$/, name: "getRunTrace" },
|
|
405
417
|
// A run's usage lines (run-usage.ts): by meter, model, charger and provider, each with its quantity and its cost.
|
|
406
418
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/usage$/, name: "getRunUsage" },
|
|
419
|
+
// A run's share bundle (run-export.ts): an ended run as one agentrun.share/1 document, every string cut by the scrubber.
|
|
420
|
+
{ method: "GET", pattern: /^\/runs\/([^/]+)\/export$/, name: "getRunExport" },
|
|
407
421
|
{ method: "POST", pattern: /^\/workflows\/validate$/, name: "validateWorkflow" },
|
|
408
422
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/pause$/, name: "pauseRun" },
|
|
409
423
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/resume$/, name: "resumeRun" },
|
|
@@ -481,6 +495,7 @@ export const ROUTES = [
|
|
|
481
495
|
{ method: "PUT", pattern: /^\/settings\/claude-login$/, name: "turnOnClaudeLogin" },
|
|
482
496
|
{ method: "DELETE", pattern: /^\/settings\/claude-login$/, name: "turnOffClaudeLogin" },
|
|
483
497
|
{ method: "POST", pattern: /^\/settings\/claude-login\/login$/, name: "startClaudeLogin" },
|
|
498
|
+
{ method: "POST", pattern: /^\/settings\/claude-login\/sign-out$/, name: "signOutClaudeLogin" },
|
|
484
499
|
// The model gateway saved in the console (model-gateway.ts): its save, removal and test the owner's session's alone.
|
|
485
500
|
{ method: "GET", pattern: /^\/settings\/model-gateway$/, name: "getModelGateway" },
|
|
486
501
|
{ method: "PUT", pattern: /^\/settings\/model-gateway$/, name: "saveModelGateway" },
|
|
@@ -618,7 +633,7 @@ async function keptBrowserOf(store, runId) {
|
|
|
618
633
|
const kept = plane ? keptVendor(plane).browser : undefined;
|
|
619
634
|
if (kept !== undefined)
|
|
620
635
|
return kept;
|
|
621
|
-
return granted ?
|
|
636
|
+
return granted ? DEFAULT_BROWSER_VENDOR : undefined;
|
|
622
637
|
}
|
|
623
638
|
/** keptBrowserOf's answer for a run whose browser is its agent's browser computer. */
|
|
624
639
|
const ON_COMPUTER = Symbol("the agent's browser computer");
|
|
@@ -718,7 +733,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
718
733
|
const memory = hostMemory();
|
|
719
734
|
// The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
|
|
720
735
|
const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
|
|
721
|
-
const tools = toolsView(env, toolSettings, noBoxReason(boxes), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
736
|
+
const tools = toolsView(env, toolSettings, noBoxReason(boxes, enabledBoxes(env)), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
722
737
|
const browser = tools.find((tool) => tool.name === "browser");
|
|
723
738
|
return {
|
|
724
739
|
backend: "local",
|
|
@@ -736,8 +751,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
736
751
|
// their words name the model it lacks. One whose default lacks a key while another model runs is (its `needs` says
|
|
737
752
|
// what the default lacks).
|
|
738
753
|
harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
|
|
739
|
-
/** The places a revision may name (`definition.place`), this host's default
|
|
740
|
-
|
|
754
|
+
/** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
|
|
755
|
+
* and whether this server has each box. */
|
|
756
|
+
places: placesOf(boxes, boxAllowOf(env), !!runnerShell?.size),
|
|
741
757
|
models,
|
|
742
758
|
learning_model,
|
|
743
759
|
/** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
|
|
@@ -781,7 +797,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
781
797
|
thinking: [...THINKING_LEVELS],
|
|
782
798
|
/** The browser a run's `browser` tool drives: the vendor it resolves to under the server's settings when the tool is
|
|
783
799
|
* available here (tools[]), a browser provider's id (tool-plane.ts BROWSER_VENDOR_IDS), else none. */
|
|
784
|
-
browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved :
|
|
800
|
+
browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved : DEFAULT_BROWSER_VENDOR))(browser.resolves?.[DEFAULT_HARNESS]) : "none",
|
|
785
801
|
/** A tool setting's `permission` (definition.tool_settings, /v2/settings/tools): allow, ask or deny, which the tool
|
|
786
802
|
* gate holds every tool call to (tool-gate.ts); an ask is answered at POST /runs/{id}/approvals/{approval_id}. */
|
|
787
803
|
tool_permissions: true,
|
|
@@ -798,10 +814,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
798
814
|
* (tool-keys-store.ts), never in the clear. */
|
|
799
815
|
tool_keys: { routes: true, at_rest: "sealed" },
|
|
800
816
|
/** GET /settings/harness-keys and PUT/DELETE of one key: a plan-billed recipe's keys, saved for that harness alone
|
|
801
|
-
* (harness-keys.ts); `harnesses` its ids here
|
|
802
|
-
*
|
|
803
|
-
|
|
804
|
-
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id), kept: [] },
|
|
817
|
+
* (harness-keys.ts); `harnesses` its ids here. The page's own GET lists the ids with keys kept whose recipe the
|
|
818
|
+
* server no longer names, so the console offers the page on `routes`, as it does tool keys'. */
|
|
819
|
+
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id) },
|
|
805
820
|
/** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
|
|
806
821
|
* which always exists (seal-key.ts), so MCP credentials are always kept sealed. Every harness of the table runs a
|
|
807
822
|
* grant (runnable.ts takes one on any), a module's among them. `composio_per_run`: a per-run Composio server takes
|
|
@@ -963,8 +978,8 @@ export async function startServe(options) {
|
|
|
963
978
|
dockerLimitsOf(process.env);
|
|
964
979
|
// The Docker host's addresses an operator names (workspace/computer-deps.ts): a bad entry stops the start, in words.
|
|
965
980
|
dockerHostAddressesOf(process.env);
|
|
966
|
-
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one
|
|
967
|
-
//
|
|
981
|
+
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one set without the region, or a value
|
|
982
|
+
// the PUT would refuse (no S3 URL for a region serve doesn't know), stops the start, in words naming each variable.
|
|
968
983
|
archilSettingsFromEnv(process.env);
|
|
969
984
|
const boxAllow = boxAllowOf(process.env);
|
|
970
985
|
const maxRuns = maxRunsOf(process.env, options.maxRuns);
|
|
@@ -980,8 +995,9 @@ export async function startServe(options) {
|
|
|
980
995
|
// One server per data root: the store's owner lock (StoreOwned), then the data root's own (server-lock.ts), both taken
|
|
981
996
|
// when startHolding opens the store; a data directory an earlier version wrote is refused there too
|
|
982
997
|
// (StoreFromEarlierVersion), in words, to start fresh. No oldHomes/oldLayout checks, no migration.
|
|
983
|
-
// What a start that fails stops: the
|
|
984
|
-
// store handle it opened
|
|
998
|
+
// What a start that fails stops: first the timers it set (each put at the front, so none ticks on a closing store), then
|
|
999
|
+
// the rest in the order they began: the store handle it opened, its locks, and the webhook deliveries it began, which
|
|
1000
|
+
// would write the next server's outbox.
|
|
985
1001
|
const stops = [];
|
|
986
1002
|
try {
|
|
987
1003
|
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost }, stops);
|
|
@@ -1021,7 +1037,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1021
1037
|
const learningOfAgent = async (entry) => {
|
|
1022
1038
|
if (learning === "off" || entry.revision?.kind !== "agentic" || !learnsOf(entry.revision.body.learning))
|
|
1023
1039
|
return undefined;
|
|
1024
|
-
const pending = await pendingCount(
|
|
1040
|
+
const pending = await pendingCount(store, entry.agent.id);
|
|
1025
1041
|
return pending === undefined ? undefined : { pending };
|
|
1026
1042
|
};
|
|
1027
1043
|
const log = options.log;
|
|
@@ -1093,7 +1109,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1093
1109
|
const beside = { runner: runnerName(), incarnation: randomUUID() };
|
|
1094
1110
|
// The data root's own lock, once the store is held (so a deploy on Postgres waits at the store's owner lock first): the
|
|
1095
1111
|
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
1096
|
-
// uploads, harness installs
|
|
1112
|
+
// uploads, harness installs), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
1097
1113
|
// Postgres) would share. The lock is SQLite's EXCLUSIVE lock (server-lock.ts): the kernel drops it when its process
|
|
1098
1114
|
// dies, so a crashed server never leaves it held.
|
|
1099
1115
|
// Its wait runs from when the store was held at the earliest, since a store on Postgres may have been waited for first.
|
|
@@ -1135,7 +1151,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1135
1151
|
// process of its own made is relayed to that runner's attach listener the same way (dial-relay.ts).
|
|
1136
1152
|
const reach = liveReachOf(process.env, seal.key);
|
|
1137
1153
|
// A runner in a process of its own that relays its dials (dial-relay.ts): one whose attach listener said it is there
|
|
1138
|
-
// within
|
|
1154
|
+
// within RUNNER_STALE_MS on the store's clock (liveRelays), at a host this server dials.
|
|
1139
1155
|
const relayedNow = async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined);
|
|
1140
1156
|
const attachLog = (event, fields) => (log ? log(logLine(event, fields)) : void process.stderr.write(`agentrun-serve: ${logLine(event, fields)}\n`));
|
|
1141
1157
|
const attach = createAttachRoutes({
|
|
@@ -1150,10 +1166,24 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1150
1166
|
// not (its runners on other hosts, AGENTRUN_RUNNER_HOSTS), so the tick runs on both. It does nothing while no computer
|
|
1151
1167
|
// is paired; with a runner beside it, nothing past its one read of the routes while no route row is there and no box
|
|
1152
1168
|
// is relayed (computer-attach.ts tick).
|
|
1169
|
+
// The ticks still running, so a failed start and close() wait them out before the store closes.
|
|
1170
|
+
const routeTicks = new Set();
|
|
1153
1171
|
const routeTick = options.apiOnly !== true
|
|
1154
|
-
? setInterval(() =>
|
|
1172
|
+
? setInterval(() => {
|
|
1173
|
+
const ticked = attach.tick()
|
|
1174
|
+
.catch((error) => attachLog("computer_route_tick_failed", { error: error instanceof Error ? error.message : String(error) }))
|
|
1175
|
+
.finally(() => void routeTicks.delete(ticked));
|
|
1176
|
+
routeTicks.add(ticked);
|
|
1177
|
+
}, PAIRED_ROUTE_MS)
|
|
1155
1178
|
: undefined;
|
|
1156
1179
|
routeTick?.unref();
|
|
1180
|
+
// A start that fails after this point clears it as the close does. Each timer's stop goes first (unshift), ahead of
|
|
1181
|
+
// the store's close: a failed start stops its timers and waits out their ticks and sweeps, then closes the store, so
|
|
1182
|
+
// no tick or sweep ever reads a store that is closing.
|
|
1183
|
+
stops.unshift(async () => {
|
|
1184
|
+
clearInterval(routeTick);
|
|
1185
|
+
await Promise.all(routeTicks);
|
|
1186
|
+
});
|
|
1157
1187
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
1158
1188
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
1159
1189
|
const own = (env) => withSealKey(env, seal.text);
|
|
@@ -1201,11 +1231,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1201
1231
|
const fields = { count: offList.length, servers: offList.join(","), line: `runs that grant these per_run MCP servers the API token saved are refused, nothing sent, until ${API_ONLY_MCP_ORIGINS_ENV} lists their origin` };
|
|
1202
1232
|
log ? log(logLine("api_only_mcp_off_list", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_mcp_off_list", fields)}\n`);
|
|
1203
1233
|
}
|
|
1234
|
+
// And the Composio servers the token saved before its users were namespaced, which may call as the owner's user: refused
|
|
1235
|
+
// at every claim (composioOutsideNamespace) until deleted. Their names alone, never a user or an address.
|
|
1236
|
+
const outside = options.apiOnly ? await composioOutsideNamespaceServers(store) : [];
|
|
1237
|
+
if (outside.length) {
|
|
1238
|
+
const fields = { count: outside.length, servers: outside.join(","), line: "runs that grant these Composio servers the API token saved before its Composio users were namespaced are refused, nothing sent: delete each, then save it again" };
|
|
1239
|
+
log ? log(logLine("api_only_composio_outside_namespace", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_composio_outside_namespace", fields)}\n`);
|
|
1240
|
+
}
|
|
1204
1241
|
const mcpServers = mcpServersOverStore(store, own(withSecrets(base, "own")), VERSION);
|
|
1205
1242
|
if (options.githubMcpOrigin)
|
|
1206
1243
|
mcpServers.appOrigin = options.githubMcpOrigin;
|
|
1207
1244
|
if (options.composioMcpOrigin)
|
|
1208
1245
|
mcpServers.composioOrigin = options.composioMcpOrigin;
|
|
1246
|
+
if (options.composioControl)
|
|
1247
|
+
mcpServers.composioControl = options.composioControl;
|
|
1209
1248
|
mcpServers.standIns = options.mcpStandIns === true;
|
|
1210
1249
|
// The saved MCP servers' metadata (their addresses and the tools they list), a snapshot the checks read in step (which
|
|
1211
1250
|
// servers are saved, a workflow's grants, the template apply): the server is the one writer of these rows (a save,
|
|
@@ -1247,11 +1286,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1247
1286
|
// where it is signed in. A sign-in, a sign-out or an expiry it sees makes the reading again, as a key's save does.
|
|
1248
1287
|
const plan = new ChatGPTPlan({ store, sealKey: seal.key, log: (fields) => (log ? log(logLine("chatgpt", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("chatgpt", fields)}\n`)), changed: () => keysChanged() });
|
|
1249
1288
|
await plan.load();
|
|
1250
|
-
stops.push(
|
|
1289
|
+
stops.push(() => planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS));
|
|
1251
1290
|
// Claude Code's login on this machine (claude-login.ts): env carries where it is while the owner has it on, so
|
|
1252
1291
|
// claude-agent's model checks see a model without a key. Unset, its switch follows the listen address: there on
|
|
1253
1292
|
// loopback, off past it. A setting kept where the mode is now off or refused goes first.
|
|
1254
1293
|
const loginOff = claudeLoginSwitchedOff(base, options.host ?? DEFAULT_HOST);
|
|
1294
|
+
// The routes' gate and capabilities' features.claude_login, from one rule (claude-login.ts claudeLoginServed).
|
|
1295
|
+
const loginServed = claudeLoginServed(loginOff, options.apiOnly === true);
|
|
1255
1296
|
// The API keys made in the console (api-keys.ts), read once here: this process is the store's one server, so the keys
|
|
1256
1297
|
// it holds are the store's. No value is kept, so none joins the server's secrets: a key in a text is cut by its shape
|
|
1257
1298
|
// (redact/match.ts).
|
|
@@ -1270,15 +1311,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1270
1311
|
// since keys are made and revoked while the server runs, and the login's turn-on takes the keys' turn (oneOwnerDeps).
|
|
1271
1312
|
const oneOwner = oneOwnerDeps({ apiOnly: options.apiOnly === true, tokens: tokens.length, keysDormant: options.harnessSignIn === true }, apiKeys);
|
|
1272
1313
|
/** Why this server makes no API key now, in words; undefined when it does. The one-owner rule from its other side: a
|
|
1273
|
-
* recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's.
|
|
1314
|
+
* recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's. A
|
|
1315
|
+
* login kept while its folders are refused (the view's `refused`) counts as on: a mended folder brings it back with
|
|
1316
|
+
* no turn-on, so a key made meanwhile would open the person's plan to an app. Its turn-off removes it, and a key then. */
|
|
1274
1317
|
const apiKeysRefused = async () => options.harnessSignIn ? HARNESS_SIGN_IN_REFUSES_API_KEYS : (await claudeLoginSetting(store.settings)) ? LOGIN_REFUSES_API_KEYS : undefined;
|
|
1275
1318
|
// Making a key, revoking one and turning the login on each take a turn (ApiKeys.inTurn; the login's is taken in
|
|
1276
1319
|
// turnOnClaudeLogin, through oneOwnerDeps' `turn`), one at a time: each decides by what the others left once their writes
|
|
1277
1320
|
// landed or were undone, never by a key taken out for a removal that then fails.
|
|
1278
1321
|
// The sign-in this server starts, kept for this process (claude-sign-in.ts). Its queue is the one way the login's
|
|
1279
|
-
// setting changes, the drop here included. A server whose user
|
|
1322
|
+
// setting changes, the drop here included. A server whose user may not use the saved login's folders (its home, or
|
|
1323
|
+
// those its env gives this machine's login: loginRefused) keeps it, refused in words, and logs why.
|
|
1280
1324
|
const claudeSignIns = new ClaudeSignIns({ limitMs: options.claudeSignInLimitMs });
|
|
1281
|
-
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused()
|
|
1325
|
+
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused(), base, (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
|
|
1282
1326
|
// The status checks' folders a server killed mid-check left in the temporary folder, each with a copy of the account
|
|
1283
1327
|
// file (the harness's sweepClaudeStatusFolders): this user's alone, and only once the check has ended by the end it
|
|
1284
1328
|
// wrote in its folder, so a check another server on this host runs now stays. Where the mode is there, as status
|
|
@@ -1309,12 +1353,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1309
1353
|
const isolation = await runIsolationOf(base, 1, () => { }).then(runIsolationName, () => "process");
|
|
1310
1354
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1311
1355
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1312
|
-
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets };
|
|
1313
|
-
|
|
1314
|
-
const compose = (runnerShell) => {
|
|
1315
|
-
const made = askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1316
|
-
return { ...made, features: { ...made.features, harness_keys: { ...made.features.harness_keys, kept: harnessKeys.unnamed() } } };
|
|
1317
|
-
};
|
|
1356
|
+
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1357
|
+
const compose = (runnerShell) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1318
1358
|
const recompose = () => void (caps = compose());
|
|
1319
1359
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1320
1360
|
let offersFrom;
|
|
@@ -1435,31 +1475,121 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1435
1475
|
* key's save does. A sign-in this server starts opens a browser on its machine, so only where the console is on
|
|
1436
1476
|
* loopback here; it is kept for this process (claudeSignIns, above), and one still waiting is ended at the stop. */
|
|
1437
1477
|
stops.push(async () => claudeSignIns.close());
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1478
|
+
// The latest hand-over of the login (a turn on or off, or a refresh), until env, needs and the offers are made from
|
|
1479
|
+
// it. It never fails: a failed reading is answered to the request that handed the login over, as a key's save is.
|
|
1480
|
+
let handing = Promise.resolve();
|
|
1481
|
+
// Which the latest hand-over was (`why`: a refresh's or a turn on's or off's), whether its reading is still going
|
|
1482
|
+
// (`out`), and whether it failed (`failed`): the login held is then one env, needs and the offers were not made from,
|
|
1483
|
+
// and the next refresh hands it over again, though it finds it unchanged.
|
|
1484
|
+
let handed = { n: 0, why: "turn", out: false, failed: false };
|
|
1485
|
+
/** The server's login replaced by `login`, then env, needs and the offers made again from it (keysChanged). */
|
|
1486
|
+
const handOver = (login, why) => {
|
|
1487
|
+
claudeLogin = login;
|
|
1488
|
+
const mine = { n: handed.n + 1, why, out: true, failed: false };
|
|
1489
|
+
handed = mine;
|
|
1490
|
+
const made = keysChanged();
|
|
1491
|
+
// Only the latest hand-over's end counts: an earlier one that ends after it says nothing of the login held.
|
|
1492
|
+
const ended = (failed) => void (handed === mine && (handed = { ...mine, out: false, failed }));
|
|
1493
|
+
handing = made.then(() => ended(false), () => ended(true));
|
|
1494
|
+
return made;
|
|
1495
|
+
};
|
|
1496
|
+
const loginDeps = () => {
|
|
1497
|
+
// A turn hands the login over inside its turn (`saved`) and waits for the reading after it (`changed`), outside the
|
|
1498
|
+
// turn, so a sign-in pressed meanwhile never waits on it; a refresh asked meanwhile waits for it (`handing`).
|
|
1499
|
+
let made = Promise.resolve();
|
|
1500
|
+
return {
|
|
1501
|
+
signIns: claudeSignIns,
|
|
1502
|
+
settings: store.settings,
|
|
1503
|
+
data,
|
|
1504
|
+
env: base,
|
|
1505
|
+
pinned: async () => claudeCliIn(installDirOf(data, LOGIN_HARNESS), (await import("@parcha/agentrun-harness-claude")).claudeAgentPlatform()),
|
|
1506
|
+
// `refused` and `turn`: the keys are counted when the refusal is asked (inside the turn-on's turn, the keys' own).
|
|
1507
|
+
...oneOwner,
|
|
1508
|
+
sameMachine: isLoopback(host) && !options.publicUrl,
|
|
1509
|
+
claude: () => import("@parcha/agentrun-harness-claude"),
|
|
1510
|
+
saved: (login) => {
|
|
1511
|
+
made = handOver(login, "turn");
|
|
1512
|
+
},
|
|
1513
|
+
changed: () => made,
|
|
1514
|
+
};
|
|
1515
|
+
};
|
|
1516
|
+
// The refresh asked and not yet started: a request that asks for one meanwhile shares it, since its look at the
|
|
1517
|
+
// folders comes after that request asked. It answers the hand-over it waited for (handed.n).
|
|
1518
|
+
let asked;
|
|
1519
|
+
// How many times a request looks at the login's folders (loginNow) before it gives up on a login that keeps changing.
|
|
1520
|
+
const LOGIN_ROUNDS = 3;
|
|
1521
|
+
/** One look at the login's folders (loginNow), and the wait for the latest hand-over's reading after it: answers which
|
|
1522
|
+
* hand-over that was, once its reading has ended. */
|
|
1523
|
+
const refreshOnce = () => {
|
|
1524
|
+
if (asked)
|
|
1525
|
+
return asked;
|
|
1526
|
+
if (claudeSignIns.busy)
|
|
1527
|
+
log?.(logLine("claude_login_wait", { why: "queue" }));
|
|
1528
|
+
asked = claudeSignIns
|
|
1529
|
+
.serial(async () => {
|
|
1530
|
+
asked = undefined;
|
|
1531
|
+
const login = loginOf(await claudeLoginSetting(store.settings), data, base);
|
|
1532
|
+
if (!isDeepStrictEqual(login, claudeLogin) || handed.failed)
|
|
1533
|
+
return { made: handOver(login, "refresh"), n: handed.n };
|
|
1534
|
+
if (handed.out)
|
|
1535
|
+
log?.(logLine("claude_login_wait", { why: handed.why }));
|
|
1536
|
+
return { made: handing, n: handed.n };
|
|
1537
|
+
})
|
|
1538
|
+
.then(async ({ made, n }) => {
|
|
1539
|
+
await made;
|
|
1540
|
+
return n;
|
|
1541
|
+
});
|
|
1542
|
+
return asked;
|
|
1543
|
+
};
|
|
1544
|
+
/** The login runs here go on, as its folders are now (loginOf, one look at them), handed over where it differs from
|
|
1545
|
+
* the one held. The held one is the start's or the last turn's, and a folder mended with a chmod since (or refused
|
|
1546
|
+
* since) changes it with no turn: a run's check, a save's, a template's plan or apply (prepareApply) and capabilities
|
|
1547
|
+
* ask this first, so they agree with the Settings view, which looks at the folders itself (loginAt). It answers once env,
|
|
1548
|
+
* needs and the offers are made from the login it found, so no request sees a new login with the offers made before
|
|
1549
|
+
* it. The look and the hand-over are one turn on the sign-ins' queue, the one way the setting changes, so a turn on or
|
|
1550
|
+
* off asked meanwhile lands before the look or after the hand-over, never between them. The reading after the
|
|
1551
|
+
* hand-over (keysChanged) goes on outside the queue, as a turn on's or off's does, so a sign-in, a turn on or off and
|
|
1552
|
+
* the server's stop never wait on its probe of the offers; where a turn off lands during it, the turn off's own
|
|
1553
|
+
* reading overtakes it (keysChanged's latest probe stands). Every refresh then waits for the latest hand-over's
|
|
1554
|
+
* reading, its own or another's (a turn's, or another refresh's). A refresh that finds the login as held, where the
|
|
1555
|
+
* latest reading failed, hands it over again, so a failed reading is made again by the next request, never left. The
|
|
1556
|
+
* log says when a refresh waits: for its turn (why=queue), or for another's reading (why=refresh or why=turn).
|
|
1557
|
+
* A reading that ends is not always one the offers were made by: a later hand-over (a turn on or off asked meanwhile)
|
|
1558
|
+
* may have started a probe that dropped its own, or another's reading it waited for failed. So once its wait ends, a
|
|
1559
|
+
* request goes on only where the hand-over it waited for is still the latest and did not fail; else it looks again
|
|
1560
|
+
* (refreshOnce), which waits for the later one or hands a failed one over again. A reading its own hand-over started
|
|
1561
|
+
* that fails is answered to it. A probe with no hand-over (a key's save, a harness key's, a new Ollama listing) can
|
|
1562
|
+
* drop the hand-over's too, and then fail or still be out: the hand-over is still the latest and did not fail, yet the
|
|
1563
|
+
* offers held were made before it. So the request also goes on only where the offers held are made from the inputs
|
|
1564
|
+
* now (offersMadeFrom); where not, it makes them as a key's save does (keysChanged: it waits for the probe out of
|
|
1565
|
+
* these inputs, or probes itself, and a probe of its own that fails is answered to it). It looks at most LOGIN_ROUNDS
|
|
1566
|
+
* times, then is refused (unavailable, retryable), so turns that keep coming never hold it for ever. */
|
|
1567
|
+
const loginNow = async () => {
|
|
1568
|
+
if (loginOff !== undefined)
|
|
1569
|
+
return;
|
|
1570
|
+
for (let round = 1;; round++) {
|
|
1571
|
+
const n = await refreshOnce();
|
|
1572
|
+
const latest = () => handed.n === n && !handed.failed;
|
|
1573
|
+
if (latest() && !offersMadeFrom(offersInputs(env)))
|
|
1574
|
+
await keysChanged();
|
|
1575
|
+
if (latest() && offersMadeFrom(offersInputs(env)))
|
|
1576
|
+
return;
|
|
1577
|
+
if (round >= LOGIN_ROUNDS)
|
|
1578
|
+
throw new ApiError("unavailable", `Claude Code's login on this machine was handed over again, or the offers made from it failed, each time this request waited for them, ${LOGIN_ROUNDS} times: ask again.`);
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1453
1581
|
// The boxes a place may name, read once from the computers runs execute on (place-offers.ts): AGENTRUN_BOXES lists
|
|
1454
|
-
// them,
|
|
1455
|
-
// run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's
|
|
1582
|
+
// them, the local box (Docker's) alone when it is not set; the local box by Docker's probe, a vendor's by its
|
|
1583
|
+
// provider's required keys, read as a run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's
|
|
1584
|
+
// answer, and nothing asks Docker.
|
|
1456
1585
|
const fauxDocker = Boolean(options.faux) && options.fauxDocker === true;
|
|
1457
|
-
//
|
|
1458
|
-
// `probeContainer`
|
|
1586
|
+
// Where the probe takes this server to be is its own marks (place-offers.ts containerOf), faux or not, so a faux server
|
|
1587
|
+
// in AgentRun's image (the deploy walk's) says the image's words; `probeContainer` pins it for a test.
|
|
1459
1588
|
// The probe names Docker's architecture too, which says which computerd build a Docker computer binds (below).
|
|
1460
1589
|
let dockerArch;
|
|
1461
|
-
const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } :
|
|
1462
|
-
|
|
1590
|
+
const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } : {}) });
|
|
1591
|
+
// Docker answers here: the local box (on this machine's container engine) is available.
|
|
1592
|
+
const docker = found.some((offer) => LOCAL_BOXES.includes(offer.id) && offer.available);
|
|
1463
1593
|
// Under --faux, the mountinfo a test gives (fauxMountinfo, or FAUX_MOUNTINFO_ENV in the process's own environment, which
|
|
1464
1594
|
// `env` leaves out: a server under test in a container names its own /proc/self/mountinfo there); with none, a faux
|
|
1465
1595
|
// server is on a host.
|
|
@@ -1559,7 +1689,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1559
1689
|
}
|
|
1560
1690
|
else if (box?.available)
|
|
1561
1691
|
return { up: true };
|
|
1562
|
-
|
|
1692
|
+
// A container with no Docker socket at the start had no daemon there, as Settings → Computers words none
|
|
1693
|
+
// (noDockerWords, the vendors that fit each kind): not the start's words, which point at that very page.
|
|
1694
|
+
return { up: false, absent: box?.reason === DOCKER_NO_SOCKET, reason: box?.reason ?? `${provider} is not a box this server has` };
|
|
1563
1695
|
};
|
|
1564
1696
|
let computerRoutes;
|
|
1565
1697
|
// The programs a provider runs on this machine (the phone's adb), looked for on PATH once, at the start, as the boxes
|
|
@@ -1579,8 +1711,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1579
1711
|
: {
|
|
1580
1712
|
hostWhy,
|
|
1581
1713
|
kinds: { SETTING_KINDS, PROVIDERS: COMPUTER_PROVIDERS, servingRefusals },
|
|
1582
|
-
// The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own
|
|
1583
|
-
|
|
1714
|
+
// The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own, each given the
|
|
1715
|
+
// server's values of the host variables its descriptor reads (Docker's PATH, HOME and DOCKER_HOST, for its test and
|
|
1716
|
+
// an agent computer's release).
|
|
1717
|
+
factories: computerProviderFactories(computerProviderMakers({ env: process.env }), (id) => storeLedger(store.computerLedger, id)),
|
|
1584
1718
|
answers: dockerAnswers,
|
|
1585
1719
|
}),
|
|
1586
1720
|
}));
|
|
@@ -1668,27 +1802,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1668
1802
|
const allInViewOf = async (runId, view) => {
|
|
1669
1803
|
const cost = (view.cost ?? {});
|
|
1670
1804
|
const own = typeof cost.usd === "number" && cost.upper_bound !== true ? cost.usd : null;
|
|
1671
|
-
|
|
1672
|
-
// a 500: the revision ledger its `learning_usd` and `all_in_usd` share is read from takes the champion with no record
|
|
1673
|
-
// skipped (as before the purge), so a revision a purged run wrote may be the one it counts as serving, for this read
|
|
1674
|
-
// alone. Figures only: no text is read or shown. Every write that asks the gate still fails closed (decideCheck
|
|
1675
|
-
// throws, so no promote lands; recordPromotion trims nothing). Such a read says so: `cost.degraded`.
|
|
1676
|
-
let degraded = false;
|
|
1677
|
-
const all = await runAllInOverStore(store, runId, own, (agentId, records) => refusedFor(agentId, records).catch((error) => {
|
|
1678
|
-
degraded = true;
|
|
1679
|
-
const line = `learning: run ${runId}: its costs were read without the purge gate's answer: ${error instanceof Error ? error.message : String(error)}`;
|
|
1680
|
-
if (log)
|
|
1681
|
-
log(logLine("learning", { line }));
|
|
1682
|
-
else
|
|
1683
|
-
process.stderr.write(`agentrun-serve: ${line}\n`);
|
|
1684
|
-
return Object.assign(() => false, { unread: true });
|
|
1685
|
-
}));
|
|
1805
|
+
const all = await runAllInOverStore(store, runId, own);
|
|
1686
1806
|
if (!all)
|
|
1687
1807
|
return {};
|
|
1688
1808
|
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1689
1809
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1690
1810
|
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1691
|
-
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd
|
|
1811
|
+
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } };
|
|
1692
1812
|
};
|
|
1693
1813
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1694
1814
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -1805,7 +1925,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1805
1925
|
};
|
|
1806
1926
|
const uploadsTimer = setInterval(sweepUploads, UPLOAD_SWEEP_EVERY_MS);
|
|
1807
1927
|
uploadsTimer.unref();
|
|
1808
|
-
stops.
|
|
1928
|
+
stops.unshift(async () => {
|
|
1809
1929
|
clearInterval(uploadsTimer);
|
|
1810
1930
|
await sweeping;
|
|
1811
1931
|
});
|
|
@@ -1883,6 +2003,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1883
2003
|
};
|
|
1884
2004
|
const refusedTimer = setInterval(() => void sweepRefused(), REFUSED_SWEEP_MS);
|
|
1885
2005
|
refusedTimer.unref();
|
|
2006
|
+
stops.unshift(async () => {
|
|
2007
|
+
refusedStopped = true;
|
|
2008
|
+
clearInterval(refusedTimer);
|
|
2009
|
+
await refusedSweep;
|
|
2010
|
+
});
|
|
1886
2011
|
// The runner beside this server, when its run isolation was refused (cli.ts): its word, kept in this store until the stop.
|
|
1887
2012
|
let refusedBeside;
|
|
1888
2013
|
const sourceWorkspaces = { data, sealKey, env: withSecrets(process.env, "own"), ...(options.archilControl ? { control: options.archilControl } : {}) };
|
|
@@ -1933,6 +2058,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1933
2058
|
};
|
|
1934
2059
|
const localSourceTimer = setInterval(() => void sweepLocalSources(), 30_000);
|
|
1935
2060
|
localSourceTimer.unref();
|
|
2061
|
+
// As close() does: aborted first, so a sync in flight stops instead of being waited out.
|
|
2062
|
+
stops.unshift(async () => {
|
|
2063
|
+
stopping.abort();
|
|
2064
|
+
clearInterval(localSourceTimer);
|
|
2065
|
+
await localSourceSweep;
|
|
2066
|
+
});
|
|
1936
2067
|
const startDeps = {
|
|
1937
2068
|
project: { ...sourceProjects, place: async (given) => {
|
|
1938
2069
|
try {
|
|
@@ -1985,17 +2116,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1985
2116
|
// Whether that is the operator's own setting, not the default: a browser is held to an operator's list alone.
|
|
1986
2117
|
...(boxAllowSetIn(process.env) ? { boxAllowSet: true } : {}),
|
|
1987
2118
|
modelOf,
|
|
1988
|
-
// The run's learning start: the server's learning switch, the agent's seed read now from its learning
|
|
2119
|
+
// The run's learning start: the server's learning switch, the agent's seed read now from its learning rows, and
|
|
1989
2120
|
// the host's secrets as they are shown now to cut the corrections a run is given, a loopback address kept (local): the
|
|
1990
2121
|
// run's own machine. runs-over-store.learningStartFor pins the result (seed, section, workflows) in the launch for the
|
|
1991
2122
|
// runner; a seed that cannot be read starts the run with nothing learned (a fault never refuses it). The runner's spec
|
|
1992
2123
|
// builders read it back as the run's end-of-run step (runner/learning-end.ts learningEndOfRun).
|
|
1993
2124
|
learning,
|
|
1994
2125
|
seedFor: async (agentId) => {
|
|
1995
|
-
//
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning folder could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
2126
|
+
// A store fault surfaces here as a seedOf error, so the run starts with nothing learned, never refused.
|
|
2127
|
+
return seedOf(data, store, agentId).then((seed) => ({ seed }), (error) => {
|
|
2128
|
+
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
1999
2129
|
return { failed: error.message };
|
|
2000
2130
|
});
|
|
2001
2131
|
},
|
|
@@ -2014,22 +2144,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2014
2144
|
return [...serverSecrets(), ...pointers];
|
|
2015
2145
|
};
|
|
2016
2146
|
const learningShown = async (agentId) => secretsShown(await learningValues(agentId));
|
|
2017
|
-
//
|
|
2018
|
-
|
|
2019
|
-
//
|
|
2020
|
-
const
|
|
2021
|
-
// The agent's audit ledger on its learning folder's main (learn/audit.ts), oldest first.
|
|
2022
|
-
const auditsOfAgent = async (agentId) => {
|
|
2023
|
-
const { workspace, end } = learningFolderOf(data, agentId);
|
|
2024
|
-
try {
|
|
2025
|
-
return await readAudits(workspace);
|
|
2026
|
-
}
|
|
2027
|
-
finally {
|
|
2028
|
-
await end().catch(() => undefined);
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2031
|
-
// What a run held for its owner's OK reads as it stands on its agent's learning folder's main (statusesOf).
|
|
2032
|
-
const statuses = (agentId) => statusesOf(data, agentId);
|
|
2147
|
+
// The agent's audit ledger (learn/audit.ts), oldest first.
|
|
2148
|
+
const auditsOfAgent = (agentId) => readAudits(store.learning, agentId);
|
|
2149
|
+
// What a run held for its owner's OK reads as it stands in its agent's learning (statusesOf).
|
|
2150
|
+
const statuses = (agentId) => statusesOf(store, agentId);
|
|
2033
2151
|
const viewDepsFor = (origin) => ({ origin, serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses });
|
|
2034
2152
|
// A run read as a whole (its own read, its archive) lists its recordings too, from its recordings folder on this machine
|
|
2035
2153
|
// (run-recordings.ts), where the runner beside it wrote them; every other read of the view opens no file.
|
|
@@ -2066,6 +2184,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2066
2184
|
const servedTimelineDeps = { serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses };
|
|
2067
2185
|
const timelines = runTimelines({
|
|
2068
2186
|
context: ctx,
|
|
2187
|
+
...(options.timelinePollMs !== undefined ? { pollMs: options.timelinePollMs } : {}),
|
|
2069
2188
|
// The run's rows as served (run-timeline-served.ts), by its one cut (run-cut.ts, read for each page: a secret rotated
|
|
2070
2189
|
// or saved since is cut at once), the set its view's words, title and error are cut of: each secret this server never
|
|
2071
2190
|
// shows and each browser sign-in pointer the run was handed; its decision rows among them, its error rows in the
|
|
@@ -2076,15 +2195,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2076
2195
|
// A live run's model requests sent and not answered (in-flight.ts), from its booking's records in its journal.
|
|
2077
2196
|
inFlight: async (forStore, runId, context) => modelsInFlight(await runEntries(forStore, runId, context)),
|
|
2078
2197
|
});
|
|
2079
|
-
/** `text
|
|
2080
|
-
*
|
|
2081
|
-
* open here
|
|
2082
|
-
*
|
|
2083
|
-
* cut, and a message written uncut would show those values once the run's end lets its reads go uncut-withheld.
|
|
2084
|
-
* Read inside the turn that writes the message (runWrite), never before it: a message written first in that turn
|
|
2085
|
-
* (one that hands a new key) is in the seal read here, so a message that says that key without handing it is cut of
|
|
2086
|
-
* it too. Both writers of a message read it: a person's (sendMessage) and a trigger's (trigger-targets.ts
|
|
2087
|
-
* message_run, which skips with those words). */
|
|
2198
|
+
/** `text`, a person's words written into run `runId`, cut of `handed` and of what the run holds now, read inside runWrite:
|
|
2199
|
+
* a message (sendMessage, and a trigger's message_run) and an approval's note (answerApproval). A seal that doesn't
|
|
2200
|
+
* open here refuses the words (409 not_continuable, reason withheld, WITHHELD_MESSAGE) and nothing is written: unread
|
|
2201
|
+
* values can't be cut. */
|
|
2088
2202
|
async function cutHeld(runId, text, handed = []) {
|
|
2089
2203
|
const held = launchValuesOf(sealKey, runId, (await store.runs.launch(runId)).sealed);
|
|
2090
2204
|
if (held === "unreadable")
|
|
@@ -2520,7 +2634,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2520
2634
|
// runner's child holds many).
|
|
2521
2635
|
...(process.execArgv.some((arg) => arg.startsWith("--input-type")) ? { execArgv: workerArgs(process.execArgv) } : {}),
|
|
2522
2636
|
// Its own heap, at most IMPORT_HEAP_MB whatever the machine's memory: an import that needs more ends as a failed
|
|
2523
|
-
// worker (said, and counted: IMPORT_STARTS)
|
|
2637
|
+
// worker (said, and counted: IMPORT_STARTS). A Wrapped read also starts the import package's read threads
|
|
2638
|
+
// (wrappedReading), each with a heap of its own outside this one, capped at its start: a 16 MB young generation
|
|
2639
|
+
// and the import's workerOldMb (64 MB) old one. Their finished reads wait for this thread mostly as transferred
|
|
2640
|
+
// ArrayBuffers (record indexes, request counts), memory outside this cap. So a Wrapped read holds IMPORT_HEAP_MB
|
|
2641
|
+
// for this thread's own heap, plus threads x (workerOldMb + 16) MB, plus readAhead for the replies waiting to be
|
|
2642
|
+
// taken, with up to `threads` replies in flight on top: the pool checks readAhead before it starts a read.
|
|
2524
2643
|
resourceLimits: { maxOldGenerationSizeMb: IMPORT_HEAP_MB },
|
|
2525
2644
|
});
|
|
2526
2645
|
workers.set(worker, { task, exit: once(worker, "exit").catch(() => undefined) });
|
|
@@ -2833,41 +2952,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2833
2952
|
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. ${again}`, { retry_after_ms: 5_000 });
|
|
2834
2953
|
}
|
|
2835
2954
|
};
|
|
2836
|
-
/**
|
|
2837
|
-
*
|
|
2838
|
-
|
|
2839
|
-
* read off its row, so a purged run whose launch is gone still names it). A run's kept disk, or a launch's kind
|
|
2840
|
-
* "agent", is the agent's own disk, mounted only while it is still the stored one (workspace/run-disk.ts runDiskOf):
|
|
2841
|
-
* one no longer stored was removed at Archil, its folder with it. */
|
|
2842
|
-
const learningDisksOf = async (agentId, agentDisk) => {
|
|
2843
|
-
const disks = new Set();
|
|
2844
|
-
const stored = agentDisk ? await agentDiskOf(store, agentId) : undefined;
|
|
2845
|
-
if (stored)
|
|
2846
|
-
disks.add(stored.diskId);
|
|
2847
|
-
for (const disk of await namedDisksOf(store, agentId))
|
|
2848
|
-
disks.add(disk);
|
|
2849
|
-
return [...disks];
|
|
2850
|
-
};
|
|
2851
|
-
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete over the agent's
|
|
2852
|
-
* learning folder on this server's disk, as the learning routes open it (learningFolderOf), which deleteLearning ends
|
|
2853
|
-
* in its finally, and over its folder on each Archil disk a launch of its runs named and, for a reset (`agentDisk`),
|
|
2854
|
-
* on its own disk, which the agent's delete removes whole in step 3 (archil-routes.ts removeLearningFolder; Archil
|
|
2855
|
-
* off or refusing is 503 unavailable, nothing here deleted, for the next call). */
|
|
2856
|
-
const learningDelete = options.deleteLearning ?? ((given, agentId, { keepResetLedger = false, agentDisk = false } = {}) => deleteLearning(given, agentId, learningFolderOf(data, agentId), {
|
|
2857
|
-
keepResetLedger,
|
|
2858
|
-
elsewhere: async () => {
|
|
2859
|
-
for (const diskId of await learningDisksOf(agentId, agentDisk)) {
|
|
2860
|
-
try {
|
|
2861
|
-
await archil.removeLearningFolder(agentId, diskId);
|
|
2862
|
-
}
|
|
2863
|
-
catch (error) {
|
|
2864
|
-
if (!(error instanceof ApiError && ["unavailable", "upstream_failed"].includes(error.code)))
|
|
2865
|
-
throw error;
|
|
2866
|
-
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. The agent's learning folder on this server and its learning records are kept: send the DELETE again once it can be reached.`, { retry_after_ms: 5_000 });
|
|
2867
|
-
}
|
|
2868
|
-
}
|
|
2869
|
-
},
|
|
2870
|
-
}));
|
|
2955
|
+
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete of the agent's
|
|
2956
|
+
* learning rows (learn/delete.ts). */
|
|
2957
|
+
const learningDelete = options.deleteLearning ?? ((given, agentId, options) => deleteLearning(given, agentId, options));
|
|
2871
2958
|
/** What DELETE /agents/{id} does outside the store's rows, on this server (agent-delete.ts AgentDeleteHost). */
|
|
2872
2959
|
const agentDeleteHost = {
|
|
2873
2960
|
store,
|
|
@@ -2920,7 +3007,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2920
3007
|
// DELETE. A run on its agent's own disk: with its agent's delete that disk went whole (removeDisk), its folder with
|
|
2921
3008
|
// it; deleted alone, its folder there is deleted, the disk kept, read from its disk setting, which goes after.
|
|
2922
3009
|
const launched = await store.runs.launch(runId).then((row) => readLaunchBody(row.body)?.archilDisk, (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
|
|
2923
|
-
// The agent's learning folder there too
|
|
3010
|
+
// The agent's learning folder there too, kept from before learning moved to the store's rows: a Mode 2 end wrote
|
|
3011
|
+
// the run's diff and correction in it, and nothing reads it (learn/legacy/scrub.ts).
|
|
2924
3012
|
if (launched?.kind === "launch") {
|
|
2925
3013
|
await notYetWith(() => archil.removeRunFolder(agentId, runId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
2926
3014
|
await notYetWith(() => archil.removeLearningFolder(agentId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
@@ -2943,8 +3031,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2943
3031
|
await forgetKept("run", runId);
|
|
2944
3032
|
},
|
|
2945
3033
|
forgetAgent: async (agentId) => {
|
|
2946
|
-
// The agent's folder (its runs' folders, its home,
|
|
3034
|
+
// The agent's folder (its runs' folders, its home, the learning folder kept from before the store's rows) and its
|
|
3035
|
+
// scratch folder, and the old learning settings keys (learn/legacy/scrub.ts), as the agent's purge took them before.
|
|
2947
3036
|
await rm(agentFolder(data, agentId), { recursive: true, force: true });
|
|
3037
|
+
for (const key of [legacyGradesKey(agentId), legacyPromotionsKey(agentId)])
|
|
3038
|
+
await store.settings.remove(key);
|
|
2948
3039
|
await rm(join(data, "scratch", agentDirName(agentId)), { recursive: true, force: true });
|
|
2949
3040
|
// Private source metadata is owned by this exact agent. Prefix siblings with dotted IDs are left alone.
|
|
2950
3041
|
for (const key of [`source-sync.agent.${agentId}`, `source-sync.local.${agentId}`])
|
|
@@ -2959,12 +3050,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2959
3050
|
// The replay runs of its input, its audit's shadow run and a learning run it names (the store's), and its audit's shadow
|
|
2960
3051
|
// run by its id (one whose launch is gone too).
|
|
2961
3052
|
madeFrom: async (runId) => [...new Set([...(await store.runs.madeFrom(runId)), shadowRunId(runId)])],
|
|
2962
|
-
// Its copies in the agent's promotion records
|
|
2963
|
-
//
|
|
2964
|
-
//
|
|
3053
|
+
// Its copies in the agent's promotion records. Its learning rows (its saves' words, its notes and workflow files, its
|
|
3054
|
+
// grades and audits) go with the run's rows in the store's purge (Store.learning.purgeRun). Then its text off the
|
|
3055
|
+
// learning kept from before the rows (learn/legacy/scrub.ts: the agent's old learning folder here, the old settings
|
|
3056
|
+
// keys), in the agent's queue: a folder that can't be written now is 503, the run purged or kept as the purge had
|
|
3057
|
+
// got, and the next DELETE does it again.
|
|
2965
3058
|
forgetCopies: async (agentId, runId) => {
|
|
2966
|
-
await forgetRunCopies(store.
|
|
2967
|
-
await
|
|
3059
|
+
await forgetRunCopies(store.learning, agentId, runId);
|
|
3060
|
+
await forgetSdkCopies(store, agentId, runId);
|
|
3061
|
+
await notYetWith(() => forgetLegacyRunLearning(data, agentId, runId, store), ["unavailable"], "The agent's old learning folder keeps the run's text until the DELETE is sent again.");
|
|
2968
3062
|
},
|
|
2969
3063
|
// /usage's meters and a live read's spend, from its journal, as they read now (store-reads/cap.ts), and how its
|
|
2970
3064
|
// learning ended as /stats counts it (its state and reason alone).
|
|
@@ -2991,7 +3085,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2991
3085
|
store,
|
|
2992
3086
|
deleteLearning: learningDelete,
|
|
2993
3087
|
cancel: agentDeleteHost.cancel,
|
|
2994
|
-
inQueue: (agentId, work) =>
|
|
3088
|
+
inQueue: (agentId, work) => inLearningQueue(data, agentId, work),
|
|
2995
3089
|
waitMs: agentDeleteHost.waitMs,
|
|
2996
3090
|
pollMs: agentDeleteHost.pollMs,
|
|
2997
3091
|
};
|
|
@@ -3130,6 +3224,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3130
3224
|
await launchNative(native);
|
|
3131
3225
|
return;
|
|
3132
3226
|
}
|
|
3227
|
+
// Claude Code's login as its folders are now, before the checks read env and the offers made with it.
|
|
3228
|
+
await loginNow();
|
|
3133
3229
|
const shape = { ...shapeOf(revision), place, ...(revision.body.place ? {} : { unnamed: true }) };
|
|
3134
3230
|
// An agentic revision's MCP tools are checked as its save pinned them (its pin, never the server's listing now), for
|
|
3135
3231
|
// a server still saved here; a granted tool its pin does not hold is said first, with how to pin it.
|
|
@@ -3289,8 +3385,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3289
3385
|
}
|
|
3290
3386
|
/** A definition being saved: refused (422 by field) when it can never run here; else what this host still lacks, and
|
|
3291
3387
|
* its pins (mcpListingOf, monidPinOf), each carrying from `previous` what its grants did not change. A revision that
|
|
3292
|
-
* names no place is checked where it would run (fallbackPlace).
|
|
3293
|
-
|
|
3388
|
+
* names no place is checked where it would run (fallbackPlace). `toolsUnnamed`: a create whose definition names no tools
|
|
3389
|
+
* (the store has given it its empty list by now), which would get a shell in the default box. */
|
|
3390
|
+
async function saveable(revision, previous, { toolsUnnamed = false } = {}) {
|
|
3294
3391
|
// The store's NewRevision keeps the revision's fields under `body` (AgenticBody|WorkflowBody); build the flat shape the
|
|
3295
3392
|
// host checks (runnable.ts RevisionShape) from it, as shapeOf does for a run's Revision.
|
|
3296
3393
|
const body = revision.body;
|
|
@@ -3305,6 +3402,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3305
3402
|
}
|
|
3306
3403
|
if (cliLearningOf(body) || sdkOf(body))
|
|
3307
3404
|
return { warnings: [], stamp: {} };
|
|
3405
|
+
const noPlace = await noPlaceOf(revision, toolsUnnamed);
|
|
3406
|
+
await loginNow();
|
|
3308
3407
|
// A workflow's own issues, as POST /workflows/validate lists them (workflowIssues: the DSL's checks, the durable
|
|
3309
3408
|
// runner's refusal), refuse its save before anything is written, each at its path under definition.workflow. Asked
|
|
3310
3409
|
// with no tools list: its run binds every tool its call nodes name whether `tools` lists it or not (tools.ts
|
|
@@ -3342,15 +3441,31 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3342
3441
|
blockers.push(...added.filter((b) => b.unpriced || b.short));
|
|
3343
3442
|
blockers.push(...added.filter((b) => !b.unpriced && !b.short).map((b) => ({ ...b, reason: "not_an_option", fix: "Pick another provider for this tool in definition.tool_settings, or clear the agent's default cap (max_cost_usd: 0).", host: false })));
|
|
3344
3443
|
}
|
|
3345
|
-
|
|
3444
|
+
// A shell tool with no place is refused there already (runnable.ts shellOnRunner); no tools named is refused here.
|
|
3445
|
+
const never = blockers.filter((b) => !b.host).map(issueOf);
|
|
3446
|
+
if (noPlace && !never.some((issue) => issue.field === noPlace.field))
|
|
3447
|
+
never.unshift(noPlace);
|
|
3346
3448
|
if (never.length)
|
|
3347
|
-
throw invalid(never
|
|
3449
|
+
throw invalid(never);
|
|
3348
3450
|
const mcpPin = listing.pin();
|
|
3349
3451
|
// A computer every tool of which is set to deny, here or in the agent's own settings: its runs never start it.
|
|
3350
3452
|
const denied = await deniedComputer(shape, settings.get(), shellOf);
|
|
3351
3453
|
const off = denied ? [{ field: "definition.computer", reason: "not_allowed", message: computerDeniedWords(denied) }] : [];
|
|
3352
3454
|
return { warnings: [...blockers.map(issueOf), ...off, ...usage], stamp: { ...(mcpPin ? { mcpPin } : {}), ...(monid ? { monidPin: monid } : {}) } };
|
|
3353
3455
|
}
|
|
3456
|
+
/** Why a new `revision` cannot be saved for want of a place, the one check a save (saveable) and an apply's plan
|
|
3457
|
+
* (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
|
|
3458
|
+
* and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
|
|
3459
|
+
* runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
|
|
3460
|
+
* noBoxRefusal). On Mode 2 it saves for the runner, as it always did. Native, CLI-learning and SDK agents run elsewhere. */
|
|
3461
|
+
async function noPlaceOf(revision, toolsUnnamed) {
|
|
3462
|
+
const body = revision.body;
|
|
3463
|
+
if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
|
|
3464
|
+
return undefined;
|
|
3465
|
+
if (body.place !== undefined || body.computer !== undefined)
|
|
3466
|
+
return undefined;
|
|
3467
|
+
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, (await shellOf({ kind: "none" })) === "local");
|
|
3468
|
+
}
|
|
3354
3469
|
/** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
|
|
3355
3470
|
* cannot be pinned refuses the save (422). Undefined when it grants none. */
|
|
3356
3471
|
async function monidPinOf(revision, previous) {
|
|
@@ -3381,16 +3496,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3381
3496
|
};
|
|
3382
3497
|
/** POST /agents' body made into its agent, as that route makes one, with what this host still lacks for it. A new agent
|
|
3383
3498
|
* that names no place is given this server's box (place.ts defaultPlaceOf), stamped on its revision, when it names no
|
|
3384
|
-
* tools (it gets bash) or a tool that needs a shell
|
|
3385
|
-
* (browser), keeps the runner. */
|
|
3386
|
-
async function createAgentOf(body, template) {
|
|
3499
|
+
* tools (it gets bash) or a tool that needs a shell, and refused where Docker's box is not here and the runner has no
|
|
3500
|
+
* shell (saveable); one whose tools need none, or that names a tool the box refuses (browser), keeps the runner. */
|
|
3501
|
+
async function createAgentOf(body, template, { toolsUnnamed } = {}) {
|
|
3387
3502
|
let warnings = [];
|
|
3388
3503
|
const definition = checkDefinitionBody(body, { harnesses });
|
|
3389
3504
|
const named = Array.isArray(definition.definition.tools) ? definition.definition.tools : [];
|
|
3390
3505
|
const place = fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3391
3506
|
const tools = defaultToolsAt(place);
|
|
3392
3507
|
const entry = await agents.create(definition, async (revision) => {
|
|
3393
|
-
|
|
3508
|
+
// A template's apply says whether its package named its tools (applyWith): one that named none, and no computer
|
|
3509
|
+
// list, is the agent that would get Docker's box, whatever its grants compiled to, and is refused where there is none.
|
|
3510
|
+
const saved = await saveable(revision, null, { toolsUnnamed: toolsUnnamed ?? definition.definition.tools === undefined });
|
|
3394
3511
|
warnings = saved.warnings;
|
|
3395
3512
|
return saved.stamp;
|
|
3396
3513
|
}, place.mode === "sandbox" && tools ? { place, tools } : undefined, template);
|
|
@@ -3431,13 +3548,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3431
3548
|
throw new ApiError("agent_archived", `The agent ${id} is archived: unarchive it, then apply the ${pkg.name} template onto it again.`);
|
|
3432
3549
|
return entry;
|
|
3433
3550
|
}
|
|
3434
|
-
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning
|
|
3551
|
+
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning as this server
|
|
3435
3552
|
* reads it, cut of the host's secrets as the learning reads cut them, and a replay run's launch made as a run's start
|
|
3436
3553
|
* makes one now (prepareLaunch: the agent's current revision, model, plane and learning start). */
|
|
3437
3554
|
const replayAskOf = (entry) => ({
|
|
3438
3555
|
admitAuxiliary: auxiliaryAdmitter(store, { data, project: startDeps.project }),
|
|
3439
3556
|
store, agentId: entry.agent.id, context: ctx, log: (line) => void log?.(line),
|
|
3440
|
-
|
|
3557
|
+
shown: () => learningShown(entry.agent.id),
|
|
3441
3558
|
launchOf: async (input) => {
|
|
3442
3559
|
const { launch, revision } = await prepareLaunch(startDeps, entry, { input });
|
|
3443
3560
|
return { launch, revisionId: revision.id };
|
|
@@ -3508,6 +3625,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3508
3625
|
* skipped for a connection this server lacks), and the computer it picks. Any other refusal is the apply's own. */
|
|
3509
3626
|
async function planTemplate(template, body) {
|
|
3510
3627
|
const p = await prepareApply(template, body, { plan: true });
|
|
3628
|
+
// A fresh apply refused for want of a place (createAgentOf's save) is refused here, in the same words: no plan of a
|
|
3629
|
+
// create the apply would refuse.
|
|
3630
|
+
if (!p.onto) {
|
|
3631
|
+
const { definition, skills } = checkDefinitionBody(p.made.agent, { harnesses });
|
|
3632
|
+
const refused = await noPlaceOf(makeRevision(definition, skills ?? {}, undefined), p.toolsUnnamed);
|
|
3633
|
+
if (refused)
|
|
3634
|
+
throw invalid([refused]);
|
|
3635
|
+
}
|
|
3511
3636
|
// A monid grant is pinned to monid's listing when the agent is saved (saveable: monidPinOf), read with the monid key:
|
|
3512
3637
|
// with none here the apply is refused, so the plan lists the key. A grant the agent's current pin carries reads
|
|
3513
3638
|
// nothing (pinMonid with no key answers before any request).
|
|
@@ -3585,6 +3710,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3585
3710
|
const had = onto ? await store.triggers.list(onto.agent.id) : [];
|
|
3586
3711
|
if (onto && !plan && options.templateApplyRead)
|
|
3587
3712
|
await options.templateApplyRead(onto.agent.id);
|
|
3713
|
+
// Claude Code's login as its folders are now, before the choice, the harness and the model are read from env and the
|
|
3714
|
+
// offers made with it.
|
|
3715
|
+
await loginNow();
|
|
3588
3716
|
// A model choice's own keys are needed as the package's are: missing, the apply is refused and nothing is made. Under
|
|
3589
3717
|
// the run-keys setting, a tool key is each run's to carry (run-keys.ts): its agent is made, the warning says so, and a
|
|
3590
3718
|
// run that does not carry it is refused. A model key is still the server's, and so is monid's: the agent's monid tools
|
|
@@ -3734,12 +3862,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3734
3862
|
// triggers are the package's is on each trigger (its mark), not here.
|
|
3735
3863
|
const digest = parametersDigest(sealKey, stable(parameters));
|
|
3736
3864
|
const origin = { id: pkg.id, version: pkg.version, sha: pkg.origin?.sha ?? null, parameters_digest: digest, secrets: declared };
|
|
3737
|
-
|
|
3865
|
+
// A package that names no tools and no computer list makes the agent a create that names no tools makes (createAgentOf),
|
|
3866
|
+
// whatever its grants compiled to: it would get Docker's box, and is refused where there is none (noPlaceOf).
|
|
3867
|
+
const toolsUnnamed = pkg.tools === undefined && !pick;
|
|
3868
|
+
return { pkg, onto, missing, unsaved, saved, mapped, grants, pick, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned: [...keyWarnings, ...skipped, ...kept, ...modelWarnings, ...computerWarnings] };
|
|
3738
3869
|
}
|
|
3739
3870
|
/** applyTemplate's work, in its turn on the agent where it has agent_id: prepareApply's reads and checks, then its
|
|
3740
3871
|
* writes. */
|
|
3741
3872
|
async function applyWith(template, body) {
|
|
3742
|
-
const { pkg, onto, saved, mapped, grants, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3873
|
+
const { pkg, onto, saved, mapped, grants, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3743
3874
|
// A fresh apply of what already made a live agent here (the same package and parameters) still makes one, and says
|
|
3744
3875
|
// which is there: an apply with its agent_id updates that one instead. Read before this apply's agent is made.
|
|
3745
3876
|
const twins = (await twinsOf(onto, pkg.id, digest))
|
|
@@ -3753,7 +3884,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3753
3884
|
throw new ApiError("precondition_failed", `The agent ${onto.agent.id} changed while this apply of the ${pkg.name} template read it (an edit, or another apply, wrote a revision): nothing was changed. Apply it with agent_id again to update the agent as it is now.`);
|
|
3754
3885
|
throw error;
|
|
3755
3886
|
})
|
|
3756
|
-
: await createAgentOf(made.agent, origin);
|
|
3887
|
+
: await createAgentOf(made.agent, origin, { toolsUnnamed });
|
|
3757
3888
|
// An update's triggers are reconciled by name with the ones the agent has: the package's trigger of a name the agent
|
|
3758
3889
|
// has (of the same kind) is changed in place, keeping its id, a feed's seen items, a webhook's secret and whether the
|
|
3759
3890
|
// owner turned it off (an unmarked one is adopted so, and only so: notOurs above), its settings the package's whole
|
|
@@ -3936,6 +4067,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3936
4067
|
* tunnel's own port, say); else, with no Host, its own. Links made outside a request (the owner's, the webhooks') are
|
|
3937
4068
|
* at the public URL or the server's own address. */
|
|
3938
4069
|
const linkOrigin = (req) => (options.publicUrl ?? (req.headers.host ? ownOrigin(req) : url)).replace(/\/+$/, "");
|
|
4070
|
+
/** Who hands a run's launch secrets: the API token (every caller on an API-only server; elsewhere a request with an
|
|
4071
|
+
* Authorization header that may not write a secret), or the owner's session. */
|
|
4072
|
+
const handedBy = (req) => (options.apiOnly || (req.headers.authorization !== undefined && !mayHoldSecrets(req)) ? "token" : "owner");
|
|
3939
4073
|
/** A run body's launch secrets taken out of it, before anything else reads the body: `mcp_auth`, the credentials a run's
|
|
3940
4074
|
* caller hands its per_run MCP servers for this run alone (mcp-probe.ts mcpAuthOf), and `model_key`, the run's own model
|
|
3941
4075
|
* key (run-model-key.ts), such as a LiteLLM virtual key minted for it. They never reach the run's saved body, its
|
|
@@ -3946,8 +4080,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3946
4080
|
* the model key must be text, else 422, nothing written. A retry its key already answered replays that answer even
|
|
3947
4081
|
* when the server has since changed or gone, since it does no new work. `keys`, the run's own tool keys (run-keys.ts),
|
|
3948
4082
|
* go the same way: each a tool key name to its value as text, else 422 by name, never with the value; whether the
|
|
3949
|
-
* run's revision reads each is its start's check (prepareLaunch), by name alone.
|
|
3950
|
-
|
|
4083
|
+
* run's revision reads each is its start's check (prepareLaunch), by name alone. `by`: who hands them (handedBy). A
|
|
4084
|
+
* per-run Composio binding is sealed with it, and the token's binding of a Composio user the owner connects here
|
|
4085
|
+
* (composio-owners.ts, read at this check) is 422 at its composio_user_id, nothing written. */
|
|
4086
|
+
function handedLaunchSecrets(body, by) {
|
|
3951
4087
|
if (body.mcp_auth === undefined && body.model_key === undefined && body.keys === undefined)
|
|
3952
4088
|
return { body, handed: async () => ({}) };
|
|
3953
4089
|
const { mcp_auth, model_key, keys: given, ...rest } = body;
|
|
@@ -3955,6 +4091,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3955
4091
|
const issues = [];
|
|
3956
4092
|
const mcp = mcp_auth === undefined ? undefined : mcpAuthOf(mcp_auth, issues);
|
|
3957
4093
|
const auth = {};
|
|
4094
|
+
let owners;
|
|
3958
4095
|
for (const [server, entry] of Object.entries(mcp ?? {})) {
|
|
3959
4096
|
const row = await getMcpServer(store, server);
|
|
3960
4097
|
const field = `mcp_auth.${server}`;
|
|
@@ -3965,10 +4102,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3965
4102
|
// A per-run Composio server takes a binding (its key is its own); a per_run server takes headers; no other takes either.
|
|
3966
4103
|
const perRunComposio = composioPerRun(row, await store.settings.get(composioMadeKey(server)));
|
|
3967
4104
|
if ("composio" in entry) {
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
4105
|
+
// A token's binding never calls as a user the owner calls as here (composio-owners.ts), one refusal per profile: on
|
|
4106
|
+
// API-only, where every caller is the token, McpServersOverStore.tokenBinding (which also checks a named account
|
|
4107
|
+
// is listed under the user); on the full profile, the token's binding here. The owner's session binds any user.
|
|
4108
|
+
const refused = perRunComposio && options.apiOnly ? await mcpServers.tokenBinding(server, row, entry.composio, field, options.composioControl ?? {}, stopping.signal) : undefined;
|
|
4109
|
+
if (!perRunComposio)
|
|
3971
4110
|
issues.push({ field, reason: "not_an_option", message: `The MCP server ${server} is not a per-run Composio server: only one saved through the Composio preset with user_id "${COMPOSIO_PER_RUN}" takes a Composio account from a run.` });
|
|
4111
|
+
else if (refused)
|
|
4112
|
+
issues.push(refused);
|
|
4113
|
+
else if (!options.apiOnly && by === "token" && ownersUser((owners ??= await ownersComposioUsers(store)), entry.composio.user_id))
|
|
4114
|
+
issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is a Composio user the owner connects on this install: a run the API token starts or messages binds its own person's Composio user, never the owner's." });
|
|
4115
|
+
else
|
|
4116
|
+
auth[server] = { composio: { ...entry.composio, by }, origin: new URL(row.url).origin };
|
|
3972
4117
|
}
|
|
3973
4118
|
else if (row.auth === "per_run")
|
|
3974
4119
|
auth[server] = { headers: entry.headers, origin: new URL(row.url).origin };
|
|
@@ -4002,7 +4147,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4002
4147
|
throw misfit(why);
|
|
4003
4148
|
}
|
|
4004
4149
|
else if (serverKeyMissing(env, target))
|
|
4005
|
-
throw modelKeyRequired(false);
|
|
4150
|
+
throw modelKeyRequired(false, env);
|
|
4006
4151
|
const origin = runModelOrigin(env);
|
|
4007
4152
|
return sealRunLaunch(sealKey, runId, { ...(handed.mcp ? { mcp: handed.mcp } : {}), ...(handed.model !== undefined && origin ? { model: { key: handed.model, origin } } : {}), ...(handed.keys ? { keys: handed.keys } : {}) });
|
|
4008
4153
|
};
|
|
@@ -4049,7 +4194,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4049
4194
|
const model = handed.model !== undefined && origin ? { key: handed.model, origin } : held.model;
|
|
4050
4195
|
const keys = handed.keys ?? held.keys;
|
|
4051
4196
|
if (!model && needsKey)
|
|
4052
|
-
throw modelKeyRequired(true);
|
|
4197
|
+
throw modelKeyRequired(true, env);
|
|
4053
4198
|
const unpaid = owed.length && revision ? keysOwed(revision, env, Object.keys(keys ?? {})) : [];
|
|
4054
4199
|
if (unpaid.length)
|
|
4055
4200
|
throw keysOwedRefusal(unpaid);
|
|
@@ -4061,7 +4206,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4061
4206
|
}
|
|
4062
4207
|
async function createRun(req, agentId) {
|
|
4063
4208
|
const entry = await needRunnableAgent(agentId);
|
|
4064
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
4209
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
4065
4210
|
// The host's run for a firing the launch hook handed it: the firing's own run, under the firing's key (a second start
|
|
4066
4211
|
// answers that run), started by the trigger's target policy as a firing here starts one (its cap, which the host's may
|
|
4067
4212
|
// lower, its effort when it sets one, its previous result, its trigger, origin and title), with the host's body and
|
|
@@ -4108,7 +4253,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4108
4253
|
* Its first run makes the agent, a version's first run its revision; a later run of the version reuses both
|
|
4109
4254
|
* (runs-over-store startInline). The answer is POST /agents/{agent_id}/runs' own: 202 and the run. */
|
|
4110
4255
|
async function createInlineRun(req) {
|
|
4111
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
4256
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
4112
4257
|
if (isObject(body.definition) && body.definition.cli_learning !== undefined)
|
|
4113
4258
|
throw new ApiError("input_invalid", "CLI learning references are registered only through /cli-learning/connections on the source machine.");
|
|
4114
4259
|
if (isObject(body.definition) && body.definition.native !== undefined)
|
|
@@ -4256,7 +4401,73 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4256
4401
|
throw new ApiError("bad_request", "source is one source's name (claude-code, codex, ...), or live; once");
|
|
4257
4402
|
return given[0];
|
|
4258
4403
|
}
|
|
4259
|
-
|
|
4404
|
+
/** GET /runs' `from` and `to`, each once: ISO instants with a zone (the server reads no time zone of its own), the window
|
|
4405
|
+
* [from, to) of the runs' starts, in ms. Either one alone; a `from` after `to` is 400, one equal to it an empty window. */
|
|
4406
|
+
function windowParams(url) {
|
|
4407
|
+
const instant = (name) => {
|
|
4408
|
+
const given = url.searchParams.getAll(name);
|
|
4409
|
+
if (given.length === 0)
|
|
4410
|
+
return undefined;
|
|
4411
|
+
// As the analytics' bounds read (stats.ts utcOf): an RFC 3339 date-time that exists, to the ms.
|
|
4412
|
+
const iso = given.length === 1 ? utcOf(given[0]) : undefined;
|
|
4413
|
+
if (iso === undefined)
|
|
4414
|
+
throw new ApiError("bad_request", `${name} is one RFC 3339 date-time with its zone (2026-11-01T00:00:00Z, or an offset such as +01:00), to the millisecond; once`);
|
|
4415
|
+
return Date.parse(iso);
|
|
4416
|
+
};
|
|
4417
|
+
const from = instant("from"), to = instant("to");
|
|
4418
|
+
if (from !== undefined && to !== undefined && from > to)
|
|
4419
|
+
throw new ApiError("bad_request", "from is at or before to: the window [from, to) of the runs' starts");
|
|
4420
|
+
return { ...(from !== undefined ? { startedFrom: from } : {}), ...(to !== undefined ? { startedBefore: to } : {}) };
|
|
4421
|
+
}
|
|
4422
|
+
/** GET /runs' `model`, once: a model as a run's metrics name it, `provider/model`. */
|
|
4423
|
+
function modelParam(url) {
|
|
4424
|
+
const given = url.searchParams.getAll("model");
|
|
4425
|
+
if (given.length === 0)
|
|
4426
|
+
return undefined;
|
|
4427
|
+
if (given.length > 1 || !/^[^\u0000-\u001f\u007f]{1,256}$/.test(given[0]))
|
|
4428
|
+
throw new ApiError("bad_request", "model is one model as a run's metrics name it (provider/model); once");
|
|
4429
|
+
return given[0];
|
|
4430
|
+
}
|
|
4431
|
+
/** GET /runs' own filters: `source`, the window (`from`, `to`) and `model`. */
|
|
4432
|
+
function runsOnly(url) {
|
|
4433
|
+
const source = sourceParam(url), model = modelParam(url);
|
|
4434
|
+
return { ...(source !== undefined ? { source } : {}), ...windowParams(url), ...(model !== undefined ? { model } : {}) };
|
|
4435
|
+
}
|
|
4436
|
+
async function runsPage(url, filter, origin, only = {}) {
|
|
4437
|
+
const vd = viewDepsFor(origin);
|
|
4438
|
+
// The Agent Factory's page, from the rows too: each run's list item and what its listing keeps for the factory
|
|
4439
|
+
// (store-view.ts KeptFactory), built once per change of the run as the list below builds them, so a refresh builds no
|
|
4440
|
+
// view of a run that has not moved, however many runs the board holds and however long they ran. Two reads for the
|
|
4441
|
+
// page (the listings, the runners' ticks), then per run only what is read as it stands now: who observes it
|
|
4442
|
+
// (observationOf) and its computer (runComputerRead, which reads a journal only for a desktop or phone that is up,
|
|
4443
|
+
// or a computer held for its owner). A listing behind, cut of other secrets, or built before listings kept the
|
|
4444
|
+
// factory's part is built first, once: the page shows that build whether or not its write landed (a run that moved
|
|
4445
|
+
// again meanwhile stays behind, for the lister or the next page), so a busy run costs one build a page, never the
|
|
4446
|
+
// several a status filter makes below (listNow), which this page has no need of.
|
|
4447
|
+
if (url.searchParams.has("scope"))
|
|
4448
|
+
return factoryRunsPage(store, url, filter, async (rows) => {
|
|
4449
|
+
const secrets = serverSecrets();
|
|
4450
|
+
const now = vd.now ?? Date.now;
|
|
4451
|
+
const ids = rows.map((row) => row.id);
|
|
4452
|
+
const kept = new Map((await store.runs.listings(ids)).map((read) => [read.id, read]));
|
|
4453
|
+
const ticks = new Map((await store.live.read(ids)).map((tick) => [tick.runId, tick.updatedAt]));
|
|
4454
|
+
const runs = [];
|
|
4455
|
+
for (const row of rows) {
|
|
4456
|
+
const read = kept.get(row.id);
|
|
4457
|
+
// A run purged since the page's rows were read has no listing to show (Runs.listings).
|
|
4458
|
+
if (!read)
|
|
4459
|
+
continue;
|
|
4460
|
+
const held = read.listing !== null && !read.behind && builtOfNow(read.listing, secrets) && keptFactory(read.listing, secrets) ? read.listing : undefined;
|
|
4461
|
+
const listing = held ?? (await lister.build(row.id, read.listMark, vd)).listing;
|
|
4462
|
+
const factory = listing && keptFactory(listing, secrets);
|
|
4463
|
+
if (!listing || !factory)
|
|
4464
|
+
continue;
|
|
4465
|
+
const observation = await observationOf(store, factory.observed, liveOf(row, now()), ticks.get(row.id), now);
|
|
4466
|
+
const summary = { ...listedItem(listing, origin, row.archivedAt ?? read.agentArchivedAt, secrets), factory: { ...factory.activity, observation } };
|
|
4467
|
+
runs.push({ ...summary, ...(await runComputerRead(store, row.id, summary, { context: ctx })) });
|
|
4468
|
+
}
|
|
4469
|
+
return runs;
|
|
4470
|
+
});
|
|
4260
4471
|
const limit = limitOf(url.searchParams.get("limit"));
|
|
4261
4472
|
const offset = cursorOf(url.searchParams.get("cursor"));
|
|
4262
4473
|
const status = url.searchParams.get("status");
|
|
@@ -4268,12 +4479,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4268
4479
|
const archived = archivedParam(url);
|
|
4269
4480
|
// `label=<key>:<value>`, once: only the runs holding it (run-labels.ts), filtered in the store.
|
|
4270
4481
|
const labels = labelFilter(url.searchParams.getAll("label"));
|
|
4271
|
-
const vd = viewDepsFor(origin);
|
|
4272
4482
|
// The page from the runs' rows alone (store/schema.ts RUN_LISTING_COLUMNS): filtered (`status` on the listing's status),
|
|
4273
4483
|
// ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
|
|
4274
4484
|
// journals. An audit's shadow run is no row of the list (learn/audit.ts): it is read by id, and its cost is its served
|
|
4275
4485
|
// run's. A run's archive is its own or its agent's.
|
|
4276
|
-
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...
|
|
4486
|
+
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...only, archived };
|
|
4277
4487
|
// A listing is built by the server's lister (run-listing.ts) once per change, so a list finds it current. One that is
|
|
4278
4488
|
// behind (a write landed since, or the lister has not reached it since the store was upgraded) is built here, written
|
|
4279
4489
|
// back, and shown as built: for a status filter, first every run still going whose listing is behind (its row's
|
|
@@ -4285,7 +4495,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4285
4495
|
// A write that lands while a listing is built moves the run's mark, so the listing is not written (Runs.putListing),
|
|
4286
4496
|
// and a run still going is left with no status on its row: the build is made again from the mark that write left, up
|
|
4287
4497
|
// to LIST_TRIES builds, so a filter never leaves off a run because a write met its build. Each is the lister's build
|
|
4288
|
-
// (Lister.build), so a held listing built here has its agent's learning
|
|
4498
|
+
// (Lister.build), so a held listing built here has its agent's learning read by the lister's passes after it.
|
|
4289
4499
|
const listNow = async (runId, read) => {
|
|
4290
4500
|
for (let mark = read, tries = 1;; tries++) {
|
|
4291
4501
|
const { listing, written } = await lister.build(runId, mark, vd);
|
|
@@ -4766,6 +4976,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4766
4976
|
const found = matching.find((r) => r.method === req.method || (req.method === "HEAD" && r.method === "GET"));
|
|
4767
4977
|
if (!found)
|
|
4768
4978
|
throw new ApiError("method_not_allowed", `${req.method} is not a method of ${path}`, {}, { allow: [...new Set(matching.map((r) => r.method))].join(", ") });
|
|
4979
|
+
// On API-only, a login route never gets here: the API-only gate refused it before routing.
|
|
4769
4980
|
if (CLAUDE_LOGIN_ROUTES.has(found.name) && loginOff)
|
|
4770
4981
|
throw new ApiError("not_found", claudeLoginRouteOff(found.name, loginOff));
|
|
4771
4982
|
if (found.name === "getCapabilities") {
|
|
@@ -4775,6 +4986,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4775
4986
|
const runnerShell = shellTools(await shellOf({ kind: "none" }));
|
|
4776
4987
|
await planNow();
|
|
4777
4988
|
await ollamaNow();
|
|
4989
|
+
await loginNow();
|
|
4778
4990
|
const answer = forCaller(runnerShell.size ? compose(runnerShell) : caps, byOwnerSession(req));
|
|
4779
4991
|
// features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
|
|
4780
4992
|
// runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
|
|
@@ -4784,12 +4996,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4784
4996
|
// skew check; left out when the store cannot say (a read that failed).
|
|
4785
4997
|
const state = await store.schemaState?.().catch(() => undefined);
|
|
4786
4998
|
const storeSchema = state ? { store_schema: { version: state.version, runner_floor: state.runnerFloor, known: state.known } } : {};
|
|
4787
|
-
//
|
|
4788
|
-
// the
|
|
4789
|
-
|
|
4790
|
-
|
|
4999
|
+
// This route answers before any bearer check, the same to every caller. A bearer this server does not take still
|
|
5000
|
+
// gets the answer, and the auth_failed line any other route writes for it.
|
|
5001
|
+
if (req.headers.authorization !== undefined && !byOwnerSession(req) && !bearer(req.headers.authorization, req))
|
|
5002
|
+
authFailed(`/v2${path}`, "wrong_token");
|
|
5003
|
+
// tools[].held: the server's keyless holds on each web tool now (web-run.ts withHeld), never cached.
|
|
4791
5004
|
// features.api_keys.routes: false on an API-only server, which serves none of the keys' routes and reads no key.
|
|
4792
|
-
return send(res, 200, { ...answer, ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features,
|
|
5005
|
+
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: loginServed, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
|
|
4793
5006
|
}
|
|
4794
5007
|
if (found.name === "getOpenapi")
|
|
4795
5008
|
return send(res, 200, servedOpenapi(openapi, ownerCookieName(req)));
|
|
@@ -5331,6 +5544,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5331
5544
|
const page = all.slice(offset, offset + limit).map((row) => revisionView(entry.agent, row));
|
|
5332
5545
|
return send(res, 200, { revisions: page, next_cursor: nextCursor(offset + limit, all.length) });
|
|
5333
5546
|
}
|
|
5547
|
+
case "getRevisionSkills": {
|
|
5548
|
+
// Only the named revision is needed: the full agent view and numbered history load every skill bundle.
|
|
5549
|
+
if (!ID.test(id) || !await store.agents.get(id))
|
|
5550
|
+
throw new ApiError("not_found", `no agent ${id}`);
|
|
5551
|
+
const selected = await store.agents.revision(decodeURIComponent(second));
|
|
5552
|
+
if (!selected || selected.agentId !== id)
|
|
5553
|
+
throw new ApiError("not_found", "no such revision for this agent");
|
|
5554
|
+
// The complete immutable file map is needed before replacing skills in a definition edit. Native discovery
|
|
5555
|
+
// metadata is separate: this read never follows a connection to its source machine or filesystem.
|
|
5556
|
+
return send(res, 200, { revision: selected.id, skills: selected.skills ?? {} });
|
|
5557
|
+
}
|
|
5334
5558
|
case "getAgentPackage": {
|
|
5335
5559
|
const entry = await needAgent(id);
|
|
5336
5560
|
const { agent, revision } = entry;
|
|
@@ -5470,7 +5694,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5470
5694
|
case "listAllRuns": {
|
|
5471
5695
|
const agent = url.searchParams.get("agent") ?? undefined;
|
|
5472
5696
|
const revision = url.searchParams.get("revision") ?? undefined;
|
|
5473
|
-
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req),
|
|
5697
|
+
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req), runsOnly(url)));
|
|
5474
5698
|
}
|
|
5475
5699
|
case "getRun": {
|
|
5476
5700
|
const run = await runRead(id, linkOrigin(req));
|
|
@@ -5487,7 +5711,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5487
5711
|
const run = await needRun(id);
|
|
5488
5712
|
if (run.kind === "workflow")
|
|
5489
5713
|
throw unsupported("messages.steer_workflow_runs", "A workflow run takes no messages here: its workflow runs to its end, or a cancel ends it.");
|
|
5490
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
5714
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
5491
5715
|
const answer = await idempotent(req, `/runs/${id}/messages`, body, async () => {
|
|
5492
5716
|
const secrets = await handed();
|
|
5493
5717
|
const seal = await messageSeal(run, secrets);
|
|
@@ -5536,7 +5760,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5536
5760
|
case "deleteRun": {
|
|
5537
5761
|
// In its agent's delete turn (an agent's delete or purge, or another purge of one of its runs, finishes first), the
|
|
5538
5762
|
// run read in that turn, so a DELETE after one that finished is 204 again (purgeRun: a purged run's only work is
|
|
5539
|
-
// its learning
|
|
5763
|
+
// its learning rows' delete, again).
|
|
5540
5764
|
const row = ID.test(id) ? await store.runs.get(id) : undefined;
|
|
5541
5765
|
if (!row)
|
|
5542
5766
|
throw new ApiError("not_found", `no run ${id}`);
|
|
@@ -5570,7 +5794,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5570
5794
|
issues.push({ field: "note", reason: "wrong_type", message: "note is a string of at most 2000 characters" });
|
|
5571
5795
|
if (issues.length)
|
|
5572
5796
|
throw invalid(issues);
|
|
5573
|
-
|
|
5797
|
+
// A note is cut as a message is, in the turn that writes it (cutHeld): refused when the seal does not open here.
|
|
5798
|
+
const note = typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined;
|
|
5799
|
+
await runWrite(run.agentId, run.id, async () => approve(store, run, decodeURIComponent(second), body.decision, note === undefined ? undefined : await cutHeld(run.id, note), body.confirm_destructive === true));
|
|
5574
5800
|
res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
5575
5801
|
return void res.end();
|
|
5576
5802
|
}
|
|
@@ -5586,6 +5812,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5586
5812
|
throw invalid([{ field: "correct", reason: body.correct === undefined ? "missing" : "wrong_type", message: "correct is true or false: whether the run's answer was right" }]);
|
|
5587
5813
|
if (body.expected !== undefined && !isObject(body.expected))
|
|
5588
5814
|
throw invalid([{ field: "expected", reason: "wrong_type", message: "expected is an object: the fields a right answer's JSON holds" }]);
|
|
5815
|
+
if (holdsReservedKey(body.expected))
|
|
5816
|
+
throw invalid([{ field: "expected", reason: "not_allowed", message: `expected holds no key named ${RESERVED_SEGMENT}, at any depth` }]);
|
|
5589
5817
|
if (body.source !== undefined && !GRADE_SOURCES.includes(body.source))
|
|
5590
5818
|
throw invalid([{ field: "source", reason: "not_an_option", message: `source is one of ${GRADE_SOURCES.join(", ")}` }]);
|
|
5591
5819
|
if (body.label !== undefined && (typeof body.label !== "string" || body.label.length > LABEL_MAX))
|
|
@@ -5612,11 +5840,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5612
5840
|
const kept = await runWrite(row.agentId, row.id, async () => {
|
|
5613
5841
|
// Kept with what it asks of the run's learning (runner/feedback-round.ts): nothing, or a look-back.
|
|
5614
5842
|
// Its feedback round is a turn with no caller's model key: on the server's key for the run's route, else not opened.
|
|
5615
|
-
|
|
5843
|
+
// A purge of the run from another process, past the check above: the grade's write refuses it in its own
|
|
5844
|
+
// transaction (Store.learning changeRecords), nothing written, and it answers as a purged run's grade does.
|
|
5845
|
+
const graded = gradeView(await keepGrade(store, row.agentId, grade, typeof body.label === "string" ? body.label : undefined, (launch) => !serverKeyMissing(env, { kind: "agentic", model: launch.model, native: Boolean(launch.native) })).catch(async (error) => {
|
|
5846
|
+
const now = error instanceof LearningRecordRefused ? await store.runs.get(row.id) : undefined;
|
|
5847
|
+
throw now && now.purgedAt !== null ? purgedRun(now) : error;
|
|
5848
|
+
}));
|
|
5616
5849
|
// A grade of a run its learned workflow answered alone is an audit row too (runner/audit.ts gradeRow): the hold rule
|
|
5617
5850
|
// reads it with the shadows'. A row not written now is logged, never the grade refused.
|
|
5618
5851
|
const said = (line) => log?.(logLine("audit", { run: row.id, said: line }));
|
|
5619
|
-
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx,
|
|
5852
|
+
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, shown: () => learningShown(row.agentId), log: said }, row, grade.correct, grade.expected).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
|
|
5620
5853
|
return graded;
|
|
5621
5854
|
});
|
|
5622
5855
|
// Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
|
|
@@ -5659,7 +5892,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5659
5892
|
},
|
|
5660
5893
|
computer: () => (viewed ? { kind: viewed } : computerOf(kept, env, family, own)),
|
|
5661
5894
|
session: (kind) => sessionIn(kind, entries, run.terminal || (parked && kind !== "browser")),
|
|
5662
|
-
|
|
5895
|
+
// The keep's `until` is on the store's clock (computer-kept.ts Kept.until), so its lapse is judged on it; a
|
|
5896
|
+
// clock or a row that can't be read says nothing.
|
|
5897
|
+
lapsed: async (kind) => {
|
|
5898
|
+
if (!parked)
|
|
5899
|
+
return undefined;
|
|
5900
|
+
const at = await store.sealedKeys.clock().catch(() => undefined);
|
|
5901
|
+
return at === undefined ? undefined : lapsedOf(kind, await readKept(store.settings, run.id).catch(() => undefined), at);
|
|
5902
|
+
},
|
|
5663
5903
|
hold: () => hold,
|
|
5664
5904
|
// A going run's browser let go while it waited for its person: the Screen tab says so, with when. One settings
|
|
5665
5905
|
// row (browser-wait-ended.ts), never the run's journal: this is read on every Screen poll.
|
|
@@ -5856,6 +6096,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5856
6096
|
// or where its figure is not its booking's.
|
|
5857
6097
|
// Names through the run's cut, and a withheld run refused (403), as its trace is.
|
|
5858
6098
|
return send(res, 200, await servedRunUsage({ serverSecrets, signIns, sealKey }, store, id));
|
|
6099
|
+
case "getRunExport": {
|
|
6100
|
+
await needRun(id);
|
|
6101
|
+
const restore = restoreIdsOf(url);
|
|
6102
|
+
const viewDeps = viewDepsFor(ownOriginOf());
|
|
6103
|
+
let bundle;
|
|
6104
|
+
try {
|
|
6105
|
+
bundle = await runExport(id, exportReadsOverStore(store, id, { view: viewDeps, timeline: servedTimelineDeps, runReads: runReadsDeps, cut: { serverSecrets, signIns, sealKey } }, ctx), { restore, version: VERSION, ...(options.shareScrub ? { scrub: options.shareScrub } : {}) });
|
|
6106
|
+
}
|
|
6107
|
+
catch (error) {
|
|
6108
|
+
if (error instanceof ApiError)
|
|
6109
|
+
throw error;
|
|
6110
|
+
// Fails closed: a scrub that failed, a read-back that found a value, or anything else that threw while the
|
|
6111
|
+
// bundle was made. Not one byte of it: a 500 with an empty body. The log names why, never a word of the run.
|
|
6112
|
+
log?.(logLine("export_failed", { run: id, why: error instanceof ExportFailed ? error.message : error?.name ?? "error" }));
|
|
6113
|
+
res.writeHead(500, { "cache-control": "no-store", "content-length": "0" });
|
|
6114
|
+
return void res.end();
|
|
6115
|
+
}
|
|
6116
|
+
res.writeHead(200, { "content-type": "application/json", "cache-control": "no-store", "x-content-type-options": "nosniff", "content-length": String(Buffer.byteLength(bundle.body)) });
|
|
6117
|
+
return void res.end(bundle.body);
|
|
6118
|
+
}
|
|
5859
6119
|
case "getRunTrace":
|
|
5860
6120
|
await needRun(id);
|
|
5861
6121
|
// The run's spans over its served Timeline rows and its journal (run-trace.ts): cut by the run's one cut, as its
|
|
@@ -6049,6 +6309,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6049
6309
|
const { revoked } = await plan.signOut();
|
|
6050
6310
|
return send(res, 200, revoked ? { revoked } : { revoked, message: SIGN_OUT_UNCONFIRMED });
|
|
6051
6311
|
}
|
|
6312
|
+
// Its sign-out (claude-login.ts signOutClaudeLogin): AgentRun's own login removed, the mode off; this machine's own
|
|
6313
|
+
// login refused in words.
|
|
6314
|
+
case "signOutClaudeLogin":
|
|
6315
|
+
try {
|
|
6316
|
+
return send(res, 200, await signOutClaudeLogin(loginDeps()), { "cache-control": "no-store" });
|
|
6317
|
+
}
|
|
6318
|
+
catch (error) {
|
|
6319
|
+
if (error instanceof ClaudeLoginRefused)
|
|
6320
|
+
throw new ApiError(error.code, error.message);
|
|
6321
|
+
throw error;
|
|
6322
|
+
}
|
|
6052
6323
|
// Claude Code's login on this machine (claude-login.ts): only its status is read, by asking the CLI.
|
|
6053
6324
|
case "getClaudeLogin":
|
|
6054
6325
|
case "turnOnClaudeLogin":
|
|
@@ -6089,7 +6360,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6089
6360
|
case "getMcpServer":
|
|
6090
6361
|
return send(res, 200, await mcpServers.get(id));
|
|
6091
6362
|
case "previewMcpServer":
|
|
6092
|
-
|
|
6363
|
+
// The API token's preview, as the gate reads a token's save: a server it saved is previewed at its shown address.
|
|
6364
|
+
return send(res, 200, await mcpServers.preview(await bodyOf(req), stopping.signal, req.headers.authorization !== undefined && !mayHoldSecrets(req)));
|
|
6093
6365
|
case "saveMcpServer": {
|
|
6094
6366
|
const body = await bodyOf(req);
|
|
6095
6367
|
const preset = await mcpServers.composioPreset(id);
|
|
@@ -6124,10 +6396,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6124
6396
|
return send(res, 200, over.note ? { ...saved, composio: over.note } : saved);
|
|
6125
6397
|
}
|
|
6126
6398
|
// Composio makes the managed MCP server; what is kept is the ordinary MCP save, so the key is a sealed header.
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
case "
|
|
6130
|
-
|
|
6399
|
+
// A listing stops at Composio when the console stops asking (Cancel, a key edit: the response closes), or the server
|
|
6400
|
+
// stops.
|
|
6401
|
+
case "listComposioTools": {
|
|
6402
|
+
const done = new AbortController();
|
|
6403
|
+
res.once("close", () => done.abort());
|
|
6404
|
+
return send(res, 200, await composioTools(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
|
|
6405
|
+
}
|
|
6406
|
+
case "listComposioToolkits": {
|
|
6407
|
+
const done = new AbortController();
|
|
6408
|
+
res.once("close", () => done.abort());
|
|
6409
|
+
return send(res, 200, await composioToolkits(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
|
|
6410
|
+
}
|
|
6131
6411
|
case "saveComposioServer": {
|
|
6132
6412
|
// The name is checked before Composio is called: a refused name leaves nothing made there.
|
|
6133
6413
|
mcpNameOf(id);
|
|
@@ -6139,11 +6419,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6139
6419
|
// server, in the delete's words, checked in its project's turn before the row is written. An API-only server's token
|
|
6140
6420
|
// saves one that names its key by api_key_env (the secret-write gate), and over a saved server only one it saved
|
|
6141
6421
|
// (mcp-secret-writes.ts tokenWriteOverRefused), landing only while the row still has the credential the gate read
|
|
6142
|
-
// (secretSeen) and the token's mark. The
|
|
6422
|
+
// (secretSeen) and the token's mark. The token's save stands on no auth config or ACTIVE account that no server it
|
|
6423
|
+
// saved holds (tokenStandsOn, tokenAccountOn), as a Composio user in its own namespace (composioTokenUser). The body
|
|
6424
|
+
// names no address or headers (composioSave refuses them).
|
|
6143
6425
|
const answer = await inComposioTurn(async () => {
|
|
6144
6426
|
const over = {};
|
|
6145
6427
|
const guard = { turn: (work) => composioTriggers.inTurnOf(id, work), inUse: () => composioTriggers.inUse(id, SAVE_AFTER_TRIGGERS) };
|
|
6146
|
-
const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url);
|
|
6428
|
+
const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url, byToken ? (config) => mcpServers.tokenStandsOn(config) : undefined, byToken ? (user, account) => mcpServers.tokenAccountOn(user, account) : undefined, byToken ? composioTokenUser : undefined);
|
|
6147
6429
|
await refreshMcpMeta();
|
|
6148
6430
|
return over.dropped ? { ...saved, composio: await composioLeft(id, over.dropped) } : saved;
|
|
6149
6431
|
});
|
|
@@ -6158,7 +6440,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6158
6440
|
case "deleteComposioSubscription":
|
|
6159
6441
|
return send(res, 200, await composioTriggers.forget(id), { "cache-control": "no-store" });
|
|
6160
6442
|
case "refreshMcpServer": {
|
|
6161
|
-
const refreshed = await mcpServers.refresh(id, stopping.signal
|
|
6443
|
+
const refreshed = await mcpServers.refresh(id, stopping.signal);
|
|
6162
6444
|
await refreshMcpMeta();
|
|
6163
6445
|
return send(res, 200, refreshed);
|
|
6164
6446
|
}
|
|
@@ -6270,24 +6552,23 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6270
6552
|
// definition's: an archived agent's too.
|
|
6271
6553
|
case "getAgentLearning": {
|
|
6272
6554
|
const entry = await needAgent(id);
|
|
6273
|
-
// The agent's learning view: its corrections, workflows and log from its learning
|
|
6555
|
+
// The agent's learning view: its corrections, workflows and log from its learning rows; its run-fared counts and
|
|
6274
6556
|
// its impact over the one store (agentLearningOverStore), from each run's launch, journal and learning end.
|
|
6275
6557
|
const { counts, impact } = await agentLearningOverStore(store, id);
|
|
6276
6558
|
// Each workflow's status past its README.md's: where it stands as GET .../learning/promotions says it (servingStateOf
|
|
6277
6559
|
// over the same records and the money rule's decision, costStopOverStore), so the view never says a workflow serves
|
|
6278
6560
|
// that does not run first.
|
|
6279
|
-
const records = await promotionsOf(store.
|
|
6280
|
-
const refused = await refusedFor(id, records);
|
|
6561
|
+
const records = await promotionsOf(store.learning, id);
|
|
6281
6562
|
const costStop = await costStopOverStore(store, id);
|
|
6282
6563
|
const body = entry.revision?.body;
|
|
6283
6564
|
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6284
|
-
return send(res, 200, { ...await agentLearning(
|
|
6565
|
+
return send(res, 200, { ...await agentLearning(store, id, await learningShown(id), counts, impact, (workflow) => servingStateOf(records, workflow, costStop)), learning_model: await learningModelOf(modelEnv, entry.revision) });
|
|
6285
6566
|
}
|
|
6286
6567
|
case "getLearningCost": {
|
|
6287
6568
|
await needAgent(id);
|
|
6288
6569
|
// The agent's cost per run over the one store (agentCostOverStore): each ended run's figures and path, aggregates only.
|
|
6289
6570
|
const { limit, csv } = learningCostQuery(url);
|
|
6290
|
-
const read = await agentCostOverStore(store, id, limit
|
|
6571
|
+
const read = await agentCostOverStore(store, id, limit);
|
|
6291
6572
|
// Each workflow's name as the other learning reads show it: one that holds a secret or a sign-in's value is cut.
|
|
6292
6573
|
const shown = await learningShown(id);
|
|
6293
6574
|
const cost = { ...read, runs: read.runs.map((run) => (run.workflow === null ? run : { ...run, workflow: shown.name(run.workflow) })), workflows: read.workflows.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), bill: { ...read.bill, revisions: read.bill.revisions.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), holds: read.bill.holds.map((one) => ({ ...one, workflow: shown.name(one.workflow), reason: shown.text(one.reason) })) } };
|
|
@@ -6303,28 +6584,25 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6303
6584
|
// its holds (a check's, an audit's). Every text in them cut as the other learning reads cut theirs
|
|
6304
6585
|
// (promotionsShown: a reason as well as each workflow's name). Beside what serves, each one's state, its check's
|
|
6305
6586
|
// numbers and its audit line (learn/audit.ts servingLinesOf), at the agent's numbers.
|
|
6306
|
-
const records = await promotionsOf(store.
|
|
6307
|
-
// Every champion below skips a record the purge gate refuses at its commit, as a run's claim does (championOf).
|
|
6308
|
-
const refused = await refusedFor(id, records);
|
|
6587
|
+
const records = await promotionsOf(store.learning, id);
|
|
6309
6588
|
const shown = await learningShown(id);
|
|
6310
|
-
const shownRead = promotionsShown(records, shown
|
|
6589
|
+
const shownRead = promotionsShown(records, shown);
|
|
6311
6590
|
// A ledger that can't be read now leaves each audit line at no rows, never the read refused.
|
|
6312
6591
|
const loop = auditLoopOf(entry.revision?.body?.learning);
|
|
6313
6592
|
// Each one's state with the money rule's decision a run's launch reads (costStopOverStore): a champion it stopped
|
|
6314
6593
|
// running first reads `stopped`.
|
|
6315
|
-
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id)
|
|
6594
|
+
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id));
|
|
6316
6595
|
// Why its runs are never audited, when the agent can call a tool that writes (learn/audit.ts auditWriterOf, the
|
|
6317
6596
|
// rule startAudit reads); and how many of the serving revision's runs a trigger started (never audited).
|
|
6318
6597
|
const writer = auditWriterOf(entry.revision ?? undefined);
|
|
6319
6598
|
const auditsOff = writer === undefined ? null : shown.text(auditsOffWords(writer));
|
|
6320
|
-
// The champion's own revision, read by its recorded digest
|
|
6321
|
-
//
|
|
6322
|
-
//
|
|
6599
|
+
// The champion's own revision, read by its recorded digest from the workflow's versions. Its nodes with their tiers
|
|
6600
|
+
// and code checks, and the check it was promoted on; nodes null when no version holds its text (or the rows can't
|
|
6601
|
+
// be read now).
|
|
6323
6602
|
const championRead = async (workflow, digest) => {
|
|
6324
|
-
const champion = championOf(records, workflow
|
|
6603
|
+
const champion = championOf(records, workflow);
|
|
6325
6604
|
const record = champion?.digest === digest ? champion : undefined;
|
|
6326
|
-
const
|
|
6327
|
-
const read = await workflowAtDigest(data, id, workflow, digest, commits, store).catch(() => undefined);
|
|
6605
|
+
const read = await workflowAtDigest(store, id, workflow, digest).catch(() => undefined);
|
|
6328
6606
|
let doc;
|
|
6329
6607
|
try {
|
|
6330
6608
|
doc = read ? JSON.parse(read.text) : undefined;
|
|
@@ -6334,7 +6612,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6334
6612
|
}
|
|
6335
6613
|
return shownDeep({ digest, commit: read?.commit ?? null, nodes: doc === undefined ? null : workflowNodesOf(doc), check: record?.check ?? null }, shown);
|
|
6336
6614
|
};
|
|
6337
|
-
const serving = await Promise.all(servingOf(records
|
|
6615
|
+
const serving = await Promise.all(servingOf(records).map(async (one, i) => ({
|
|
6338
6616
|
...shownRead.serving[i], ...lines[i], audits_off: auditsOff,
|
|
6339
6617
|
not_auditable: one.digest === null ? 0 : await notAuditableOf(store, id, one.workflow, one.digest, loop).catch(() => 0),
|
|
6340
6618
|
champion: one.digest === null ? null : await championRead(one.workflow, one.digest),
|
|
@@ -6343,7 +6621,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6343
6621
|
}
|
|
6344
6622
|
case "listLearningAudits": {
|
|
6345
6623
|
await needAgent(id);
|
|
6346
|
-
// The audit ledger (learn/audit.ts
|
|
6624
|
+
// The audit ledger (the agent's audit records, learn/audit.ts), oldest first: each workflow's name and every other text cut as the
|
|
6347
6625
|
// promotions read cuts its own.
|
|
6348
6626
|
const shown = await learningShown(id);
|
|
6349
6627
|
const rows = await auditsOfAgent(id);
|
|
@@ -6370,11 +6648,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6370
6648
|
}
|
|
6371
6649
|
case "listLearningLog":
|
|
6372
6650
|
await needAgent(id);
|
|
6373
|
-
return send(res, 200, await learningLog(
|
|
6651
|
+
return send(res, 200, await learningLog(store, id, url.searchParams, await learningShown(id)));
|
|
6374
6652
|
case "getLearningCorrections": {
|
|
6375
6653
|
await needAgent(id);
|
|
6376
6654
|
// corrections.md whole, as every run of the agent is served it under # Learned, with its ETag in the body and the header.
|
|
6377
|
-
const read = await correctionsView(
|
|
6655
|
+
const read = await correctionsView(store, id, await learningShown(id));
|
|
6378
6656
|
return send(res, 200, read, { etag: read.etag });
|
|
6379
6657
|
}
|
|
6380
6658
|
case "putLearningCorrections": {
|
|
@@ -6383,7 +6661,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6383
6661
|
// What it refuses is what the reads cut: the host's secrets and the agent's sign-in pointers.
|
|
6384
6662
|
const refuse = await learningValues(id);
|
|
6385
6663
|
// A write to the agent's learning: in its delete turn (agentWrite), the body read before, outside it.
|
|
6386
|
-
const written = await agentWrite(id, () => correctionsWrite(
|
|
6664
|
+
const written = await agentWrite(id, () => correctionsWrite(store, id, { text, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse }));
|
|
6387
6665
|
return send(res, 200, written, { etag: written.etag });
|
|
6388
6666
|
}
|
|
6389
6667
|
case "deleteAgentLearning": {
|
|
@@ -6397,10 +6675,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6397
6675
|
}
|
|
6398
6676
|
case "listLearnedWorkflowRevisions":
|
|
6399
6677
|
await needAgent(id);
|
|
6400
|
-
return send(res, 200, await workflowRevisions(
|
|
6678
|
+
return send(res, 200, await workflowRevisions(store, id, second, url.searchParams, await learningShown(id)));
|
|
6401
6679
|
case "readLearningFile":
|
|
6402
6680
|
await needAgent(id);
|
|
6403
|
-
return sendText(res, 200, await readLearnedFile(
|
|
6681
|
+
return sendText(res, 200, await readLearnedFile(store, id, second, await learningShown(id)));
|
|
6404
6682
|
case "retireLearningFile":
|
|
6405
6683
|
case "approveLearningFile":
|
|
6406
6684
|
case "restoreLearningFile": {
|
|
@@ -6408,7 +6686,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6408
6686
|
const refuse = await learningValues(id);
|
|
6409
6687
|
const action = found.name === "approveLearningFile" ? "approve" : found.name === "restoreLearningFile" ? "restore" : "retire";
|
|
6410
6688
|
// A change to a workflow is a write to the agent's learning: in its delete turn (agentWrite).
|
|
6411
|
-
const written = await agentWrite(id, () => changeWorkflow(
|
|
6689
|
+
const written = await agentWrite(id, () => changeWorkflow(store, id, second, { action, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse, draftTools: () => learnedDraftToolsOf(id) }));
|
|
6412
6690
|
// A run's list row that read a workflow held for the owner's OK says what the folder says now, at the next list.
|
|
6413
6691
|
await lister.learningChanged(id);
|
|
6414
6692
|
return sendText(res, written.status, { ...written, text: secretsShown(refuse).text(written.text) });
|
|
@@ -6444,7 +6722,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6444
6722
|
case "getRunLearning": {
|
|
6445
6723
|
const run = await needRun(id);
|
|
6446
6724
|
// The run's learning view over the store (learning-1's runLearningOverStore): its end, the notes it was given and its seed
|
|
6447
|
-
// from its launch, what it holds for the owner's OK as the store's run view reads it (
|
|
6725
|
+
// from its launch, what it holds for the owner's OK as the store's run view reads it (at its agent's newest save), as main.
|
|
6448
6726
|
// Cut by the run's one cut, and refused for a withheld run (run-learning-served.ts).
|
|
6449
6727
|
return send(res, 200, await servedRunLearning({ serverSecrets, signIns, sealKey, statuses }, store, run.id));
|
|
6450
6728
|
}
|
|
@@ -6883,7 +7161,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6883
7161
|
names = loopbackNames(host, options.allowHosts, options.publicUrl);
|
|
6884
7162
|
// An address of every interface is reached on this machine at its loopback one.
|
|
6885
7163
|
const url = urlOf(server, host);
|
|
6886
|
-
owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port));
|
|
7164
|
+
owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port, { container: () => containerSigns() !== undefined }));
|
|
6887
7165
|
webhooks.attach(options.publicUrl ?? url);
|
|
6888
7166
|
slack.attach(options.publicUrl ?? url);
|
|
6889
7167
|
// A local install is the one server an MCP server's URL may be on loopback for (anywhere else, loopback is this machine's
|
|
@@ -7209,8 +7487,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7209
7487
|
closing = true;
|
|
7210
7488
|
stopping.abort();
|
|
7211
7489
|
clearInterval(localSourceTimer);
|
|
7212
|
-
// Cancel a pending ChatGPT callback without signing out or changing the saved credential
|
|
7213
|
-
|
|
7490
|
+
// Cancel a pending ChatGPT callback without signing out or changing the saved credential. One past its code's
|
|
7491
|
+
// exchange is waited for a short while (planClosed), so its row lands before the store closes.
|
|
7492
|
+
const planStopped = planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS);
|
|
7214
7493
|
// The CLI's sign-in still waiting for its browser ends with the server, which forgets it: left running, its CLI would
|
|
7215
7494
|
// keep the browser's callback port from the next server's sign-in. Awaited until its process is gone.
|
|
7216
7495
|
const signInStopped = claudeSignIns.close();
|
|
@@ -7235,6 +7514,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7235
7514
|
await schemaSealed;
|
|
7236
7515
|
await installStopped;
|
|
7237
7516
|
await signInStopped;
|
|
7517
|
+
await planStopped;
|
|
7238
7518
|
await observationStopped;
|
|
7239
7519
|
await localSourceSweep;
|
|
7240
7520
|
// The ends' follower stops before the webhooks it feeds and the store it reads.
|
|
@@ -7245,6 +7525,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7245
7525
|
// An upgraded socket is no connection closeAllConnections ends, and server.close waits for it.
|
|
7246
7526
|
viewers.close();
|
|
7247
7527
|
clearInterval(routeTick);
|
|
7528
|
+
// A tick already running reads the store: waited out here, before the store closes below.
|
|
7529
|
+
await Promise.all(routeTicks);
|
|
7248
7530
|
await attach.close();
|
|
7249
7531
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
7250
7532
|
// No request is left to use a key: its last-use writes end before the store they write to closes.
|
|
@@ -7282,7 +7564,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7282
7564
|
tokenMade: stored?.made ?? false,
|
|
7283
7565
|
...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
|
|
7284
7566
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7285
|
-
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env)),
|
|
7567
|
+
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), (await shellOf({ kind: "none" })) === "local"),
|
|
7286
7568
|
attachHub,
|
|
7287
7569
|
beside,
|
|
7288
7570
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|