@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/server.js
CHANGED
|
@@ -18,7 +18,7 @@ import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_
|
|
|
18
18
|
import { FAUX_WEB_ENV } from "./web-fetch-direct.js";
|
|
19
19
|
import { FAUX_MONID_ENV } from "./monid.js";
|
|
20
20
|
import { FAUX_EXA_ENV } from "./exa-keyless.js";
|
|
21
|
-
import { FAUX_BROWSER_ENV, NODE_TOOLS, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
21
|
+
import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
22
22
|
import { ApiError, invalid, unsupported } from "./errors.js";
|
|
23
23
|
import { deref, explain } from "./explain.js";
|
|
24
24
|
import { HOME_HOST_OWNED } from "./files.js";
|
|
@@ -27,16 +27,17 @@ import { homePath, hostOwnedOf } from "./home-path.js";
|
|
|
27
27
|
import { chooseModel, EFFORTS, FAUX_ENV, FAUX_UPSTREAM_ENV, MODEL_NODES, modelSource, THINKING_LEVELS, unpricedModels, withoutFaux } from "./model.js";
|
|
28
28
|
import { DEFAULT_HARNESS, HARNESSES, harnessOfBody, harnessOffers } from "./harness.js";
|
|
29
29
|
import { HARNESS_TABLE_ENV, harnessOf } from "./harness-table.js";
|
|
30
|
-
import { HarnessInstall,
|
|
30
|
+
import { HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
31
31
|
import { healthOf, hostMemory, maxRunsOf, MIN_FREE_MIB, runsThatFit } from "./host.js";
|
|
32
32
|
import { IMPORT_ASKED } from "./import.js";
|
|
33
33
|
import { answerStoreCall } from "./import-proxy.js";
|
|
34
34
|
import { gradeModelOf, LEARNING_LABEL, learningBudgetOf, learningOf, seedOf } from "./learning.js";
|
|
35
|
-
import { agentLearning, learningLog, learningNotes, noteBody, pendingCount, readNote, secretsShown, sendNote, writeNote } from "./learning-routes.js";
|
|
35
|
+
import { agentLearning, learningLog, learningNotes, noteBody, pendingCount, promotable, readNote, secretsShown, sendNote, statusesOf, writeNote } from "./learning-routes.js";
|
|
36
36
|
import { answerLlms, MCP_PATH, mcpEndpoint } from "./mcp.js";
|
|
37
37
|
import { openapiDocument, servedOpenapi, UNSUPPORTED } from "./openapi.js";
|
|
38
38
|
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, placesOf } from "./place.js";
|
|
39
|
-
import { BOX_ALLOW_ENV, boxAllowOf,
|
|
39
|
+
import { BOX_ALLOW_ENV, boxAllowOf, boxAllowSetIn, boxNetworkOf, FAUX_BOX_ENV, fauxBoxes } from "./box-settings.js";
|
|
40
|
+
import { dockerLimitsOf } from "./workspace/computer-deps.js";
|
|
40
41
|
import { Owner, passwordProblem, SESSION_MS } from "./owner.js";
|
|
41
42
|
import { answerPage, byOwnerSession, heldSessions, isJson, overHttps, ownerCookie, ownOrigin, sendHostRefused, signedIn } from "./page.js";
|
|
42
43
|
import { hostFix, hostName, loopbackNames } from "./host-check.js";
|
|
@@ -45,10 +46,11 @@ import { browserHandBack, handBackTarget } from "./browser-commands.js";
|
|
|
45
46
|
import { computerView } from "./computer-view.js";
|
|
46
47
|
import { durationMs, logLine } from "./print.js";
|
|
47
48
|
import { approve, archiveRun, cancel, message, pause as pauseRunOverStore, raiseCap, resume as resumeRunOverStore, startInline, startRun, stop as stopRunOverStore } from "./runs-over-store.js";
|
|
48
|
-
import { momentOverStore, summaryOverStore, timelineOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
49
|
+
import { factsOverStore, momentOverStore, summaryOverStore, timelineOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
49
50
|
import { HELD_WAITS } from "./runner/journal-kinds.js";
|
|
50
51
|
import { servedTimelineRows } from "./run-timeline-served.js";
|
|
51
52
|
import { servedRunDiff, servedRunLearning } from "./run-learning-served.js";
|
|
53
|
+
import { agentPointers, WITHHELD_LEARNING } from "./handed-values.js";
|
|
52
54
|
import { runCutValues } from "./run-cut.js";
|
|
53
55
|
import { readLaunchBody } from "./run-launch.js";
|
|
54
56
|
import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
|
|
@@ -60,17 +62,15 @@ import { watchRun } from "./live/stream.js";
|
|
|
60
62
|
import { stats as statsOverStore } from "./store-reads/stats.js";
|
|
61
63
|
import { analytics as analyticsOverStore } from "./store-reads/analytics.js";
|
|
62
64
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
63
|
-
import { openStore,
|
|
65
|
+
import { openStore, StoreOwned, storeTarget } from "./store/index.js";
|
|
66
|
+
import { answerOf, logged } from "./agents.js";
|
|
64
67
|
import { FINAL_STATES } from "./store/store.js";
|
|
65
68
|
import { runModelRef } from "./model.js";
|
|
66
69
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
67
70
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
68
|
-
/** A busy store, and the home_busy answer it maps to (byte-identical to the old agents.ts words), for a read or write that
|
|
69
|
-
* meets the one store under load. */
|
|
70
|
-
const storeBusy = (error) => error instanceof StoreBusy;
|
|
71
|
-
const homeBusy = () => new ApiError("home_busy", "the agent store is busy with another write; try again", { retry_after_ms: 500 });
|
|
72
71
|
import { runLines } from "./usage-lines.js";
|
|
73
72
|
import { boxesByDefault, boxesLog, boxRegistry, enabledBoxes, VM_NO_LIST, VM_PROVIDER } from "./boxes.js";
|
|
73
|
+
import { dockerDaemonCheck } from "./docker-daemon.js";
|
|
74
74
|
import { egressParentTooLong, FAUX_EGRESS_ENV, MAX_EGRESS_PARENT, sweepEgressDirs } from "./box-egress.js";
|
|
75
75
|
import { startEgressContainer } from "./box-egress-vm.js";
|
|
76
76
|
import { dockerComputerRefusal, dockerPathsOf, egressParentOf, FAUX_MOUNTINFO_ENV, remoteDockerOnce } from "./box-paths.js";
|
|
@@ -83,39 +83,38 @@ import { blockersOf, CODE_NODES_ENV, issueOf, MCP_HARNESSES, NOT_SET_UP } from "
|
|
|
83
83
|
import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
84
84
|
import { isSecretWriteOperation, SECRET_WRITE_REFUSAL, secretsWritableFields, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
85
85
|
import { bootSealKey, withSealKey } from "./seal-key.js";
|
|
86
|
+
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
87
|
+
import { DRAIN_TIMEOUT } from "./runner/beside.js";
|
|
86
88
|
import { analyticsFilter, analyticsView, statsView } from "./stats.js";
|
|
87
|
-
import { agentLearningOverStore, learningCountsOverStore } from "./store-reads/learning.js";
|
|
88
|
-
import {
|
|
89
|
-
import { keyOf, SEAL_KEY_ENV, sealKeyOf, TOOL_FIELDS } from "./tool-keys.js";
|
|
89
|
+
import { agentLearningOverStore, learningCountsOverStore, learningSpendOverStore } from "./store-reads/learning.js";
|
|
90
|
+
import { keyOf, SEAL_KEY_ENV, TOOL_FIELDS } from "./tool-keys.js";
|
|
90
91
|
import { toolKeysOverStore } from "./tool-keys-store.js";
|
|
91
92
|
import { SIGN_INS_DIR, vendorsOver } from "./sign-ins.js";
|
|
92
|
-
// E1b builds the store-backed sign-ins bridge (the old SignIns interface — peek/forgotten/view/forget — over store.signIns,
|
|
93
|
-
// byte-identical v2 shapes; "held"/held_by from a live run whose sign_in_handed holds the pointer, verified_at from the
|
|
94
|
-
// last holder's lease end). TODO(E1b): wire its sha; named import until then.
|
|
95
93
|
import { signInsOverStore } from "./sign-ins-store.js";
|
|
96
94
|
import { MCP_AUTH_TYPES } from "./mcp-probe.js";
|
|
97
95
|
import { mcpServersOverStore } from "./mcp-servers-store.js";
|
|
98
96
|
import { privateHostsRoute } from "./mcp-private-hosts.js";
|
|
99
97
|
import { metaToolOf } from "./mcp-meta.js";
|
|
100
98
|
import { MCP_SETTINGS_PAGE, signInCookie, startedHere } from "./mcp-oauth.js";
|
|
101
|
-
import { WEBHOOK_EVENTS, Webhooks } from "./webhooks.js";
|
|
99
|
+
import { OUTBOUND_WEBHOOK, WEBHOOK_EVENTS, waitMarkerOf, Webhooks } from "./webhooks.js";
|
|
102
100
|
import { appPermissionWarnings } from "./template-github-permissions.js";
|
|
103
101
|
import { templateApplied, templateTriggerSecret, templateWebhookSecrets, triggerMade, triggerRotated, webhookSaved, withTriggerSecret } from "./trigger-secrets-shown.js";
|
|
104
102
|
import { openServerSecretsOverStore } from "./server-secrets-store.js";
|
|
105
103
|
import { HOOK_TOLERANCE_S } from "./standard-webhooks.js";
|
|
106
104
|
import { GitHubConnect, GitHubConnection, INSTALLED_PATH, startedHere as gitHubStartedHere, stateCookie } from "./github-connection.js";
|
|
105
|
+
import { FAUX_GITHUB, FAUX_GITHUB_FILE, startFauxGitHub } from "./github-faux.js";
|
|
107
106
|
import { GITHUB_API } from "./github.js";
|
|
108
107
|
import { HookCut, receivePush } from "./push-handler.js";
|
|
109
108
|
import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
|
|
110
109
|
import { webhook } from "./trigger-webhook.js";
|
|
111
110
|
import { SCHEME_NAMES } from "./trigger-signatures.js";
|
|
112
|
-
import { permissionFrom
|
|
111
|
+
import { permissionFrom } from "./tool-gate.js";
|
|
113
112
|
import { CATCHUP_WINDOW_S, FAILURES_TO_PAUSE, HISTORY_KEPT, MIN_EVERY_S, PAYLOAD_KEPT_BYTES, SOURCE_KINDS, TARGET_KINDS, Triggers } from "./triggers.js";
|
|
114
|
-
import { applyBodyOf, compiled,
|
|
113
|
+
import { applyBodyOf, compiled, githubTriggerUnconnected, githubTriggerWords, madeTriggerIssues, packageModel, packageView, readPackages } from "./templates.js";
|
|
115
114
|
import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, isObject, stable, unknownFields } from "./validate.js";
|
|
116
115
|
import { agentTools, browserKeyRow, isUnavailable, keptVendor, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
117
116
|
import { toolSettingsOverStore } from "./tool-settings-store.js";
|
|
118
|
-
import { writeApprovers } from "./server-approvers.js";
|
|
117
|
+
import { readApprovers, writeApprovers } from "./server-approvers.js";
|
|
119
118
|
import { MAX_FILES_PER_RUN, MAX_UPLOAD_BYTES, Uploads, UPLOADS_DIR } from "./uploads.js";
|
|
120
119
|
import { entryAt, listFiles, sendFile as sendWorkspaceFile, viewOf } from "./run-files.js";
|
|
121
120
|
import { COMPUTER_ROUTES, computerHoldOf, computerRoute } from "./computer-routes.js";
|
|
@@ -127,9 +126,8 @@ import { computerCapabilities, createComputerRoutes, folderModeOf, settingsCompu
|
|
|
127
126
|
import { FAUX_VIEW_PATH, fauxComputers } from "./faux-computers.js";
|
|
128
127
|
import { runComputerField } from "./run-computer.js";
|
|
129
128
|
import { writesHeld } from "./workspace.js";
|
|
130
|
-
import { agentHomeFolder, claimKinds, computerProviderFactories, computerProviderMakers, computerReadiness, dockerHostAddressesOf, isWorkspaceError, localWorkspace, serverRunWorkspace, storeLedger } from "./workspace/index.js";
|
|
129
|
+
import { agentHomeFolder, claimKinds, computerProviderFactories, computerProviderMakers, computerReadiness, dockerHostAddressesOf, isWorkspaceError, localWorkspace, runShellOf, serverRunWorkspace, storeLedger } from "./workspace/index.js";
|
|
131
130
|
import { keyReader } from "./key-meta.js";
|
|
132
|
-
// server-lock.ts is gone: the store's EXCLUSIVE connection is the one-server lock (StoreOwned refuses a second server).
|
|
133
131
|
export const CONTRACT = "agentrun.v2/0";
|
|
134
132
|
/** A process's flags for a worker of it: without --input-type and the code string given with -e, --eval, -p or --print. */
|
|
135
133
|
const workerArgs = (args) => args.filter((arg, i) => !arg.startsWith("--input-type") && !/^(?:-e|--eval|-p|--print)(?:=|$)/.test(arg) && !/^(?:-e|--eval|-p|--print)$/.test(args[i - 1] ?? ""));
|
|
@@ -213,8 +211,6 @@ export const ROUTES = [
|
|
|
213
211
|
{ method: "DELETE", pattern: /^\/agents\/([^/]+)\/sign-ins\/([^/]+)$/, name: "forgetSignIn" },
|
|
214
212
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/runs$/, name: "createRun" },
|
|
215
213
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/runs$/, name: "listRuns" },
|
|
216
|
-
{ method: "GET", pattern: /^\/agents\/([^/]+)\/home$/, name: "exportHome", capability: "home.export" },
|
|
217
|
-
{ method: "PUT", pattern: /^\/agents\/([^/]+)\/home$/, name: "importHome", capability: "home.import" },
|
|
218
214
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/home\/files$/, name: "listHomeFiles" },
|
|
219
215
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/home\/files\/(.+)$/, name: "readHomeFile" },
|
|
220
216
|
{ method: "PUT", pattern: /^\/agents\/([^/]+)\/home\/files\/(.+)$/, name: "writeHomeFile" },
|
|
@@ -230,7 +226,6 @@ export const ROUTES = [
|
|
|
230
226
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/approvals\/([^/]+)$/, name: "answerApproval" },
|
|
231
227
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/archive$/, name: "archiveRun" },
|
|
232
228
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/unarchive$/, name: "unarchiveRun" },
|
|
233
|
-
{ method: "POST", pattern: /^\/runs\/([^/]+)\/kill$/, name: "killRun", capability: "runs.kill" },
|
|
234
229
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/graph$/, name: "getRunGraph" },
|
|
235
230
|
{ method: "POST", pattern: /^\/workflows\/validate$/, name: "validateWorkflow" },
|
|
236
231
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/pause$/, name: "pauseRun" },
|
|
@@ -312,6 +307,7 @@ export const ROUTES = [
|
|
|
312
307
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/files\/([^/]+)\/retire$/, name: "retireLearningFile" },
|
|
313
308
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/files\/([^/]+)\/approve$/, name: "approveLearningFile" },
|
|
314
309
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/files\/([^/]+)\/restore$/, name: "restoreLearningFile" },
|
|
310
|
+
{ method: "POST", pattern: /^\/agents\/([^/]+)\/learning\/workflows\/([^/]+)\/promote$/, name: "promoteLearnedWorkflow" },
|
|
315
311
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/learning$/, name: "getRunLearning" },
|
|
316
312
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/learning\/diff$/, name: "getRunLearningDiff" },
|
|
317
313
|
];
|
|
@@ -409,14 +405,15 @@ export function forCaller(caps, ownerSession) {
|
|
|
409
405
|
}
|
|
410
406
|
/** The capabilities document from offers already resolved, under the server's learning switch, tool settings and box
|
|
411
407
|
* offers: cheap, made again after each key or tool-settings write with the offers the server holds; and `needs` as
|
|
412
|
-
* needsOf says it for a revision that names no model (null when it runs).
|
|
413
|
-
|
|
408
|
+
* needsOf says it for a revision that names no model (null when it runs). `runnerShell`: the sandbox-only tools a run
|
|
409
|
+
* on the runner has a shell for here (tools.ts shellTools; bash in Mode 2), available with no box. */
|
|
410
|
+
function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced }, toolSettings, boxes, gradeModel, refused = {}, runnerShell) {
|
|
414
411
|
const models = { ...modelSource(env), ready: needs === null, needs, priced };
|
|
415
412
|
// Both limits apply: the cap on the count, and the memory each run reserves (host.ts).
|
|
416
413
|
const memory = hostMemory();
|
|
417
414
|
// The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
|
|
418
415
|
const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
|
|
419
|
-
const tools = toolsView(env, toolSettings, noBoxReason(boxes), refused).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
416
|
+
const tools = toolsView(env, toolSettings, noBoxReason(boxes), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
420
417
|
const browser = tools.find((tool) => tool.name === "browser");
|
|
421
418
|
return {
|
|
422
419
|
backend: "local",
|
|
@@ -476,13 +473,13 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced },
|
|
|
476
473
|
* it over from the viewer and hands it back, and answers the agent's ask for them (POST /runs/{id}/browser/hand-back,
|
|
477
474
|
* browser-person.ts). */
|
|
478
475
|
browser_live: { read_only: false, take_over: true, ask: true },
|
|
479
|
-
/** An agent's browser stays signed in between its runs (sign-ins.ts)
|
|
480
|
-
* browser vendor here (Browserbase's or Kernel's; local Chrome keeps none). */
|
|
481
|
-
sign_ins:
|
|
476
|
+
/** An agent's browser stays signed in between its runs (sign-ins-store.ts), each pointer sealed under the server's seal
|
|
477
|
+
* key: with a browser vendor here (Browserbase's or Kernel's; local Chrome keeps none). */
|
|
478
|
+
sign_ins: tools.some((tool) => tool.name === "browser" && tool.available),
|
|
482
479
|
vault: false,
|
|
483
480
|
query: false,
|
|
484
|
-
/** GET, PUT and DELETE /settings/tool-keys: a tool's key saved by name, kept sealed under the
|
|
485
|
-
* (tool-keys.ts)
|
|
481
|
+
/** GET, PUT and DELETE /settings/tool-keys: a tool's key saved by name, kept sealed under the server's seal key
|
|
482
|
+
* (tool-keys-store.ts), never in the clear. */
|
|
486
483
|
tool_keys: { routes: true, at_rest: "sealed" },
|
|
487
484
|
/** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
|
|
488
485
|
* which always exists (seal-key.ts), so MCP credentials are always kept sealed. */
|
|
@@ -490,7 +487,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced },
|
|
|
490
487
|
/** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
|
|
491
488
|
learning,
|
|
492
489
|
/** /settings/webhook: one URL POSTed, signed by the Standard Webhooks spec, when a run needs its person and when it
|
|
493
|
-
* ends (webhooks.ts); its secret kept sealed under the same seal key
|
|
490
|
+
* ends (webhooks.ts); its secret kept sealed under the same seal key. */
|
|
494
491
|
// Always sealed: the server starts with its seal key (seal-key.ts bootSealKey), so nothing is kept in the clear.
|
|
495
492
|
webhooks: { routes: true, events: [...WEBHOOK_EVENTS], signing: "standard-webhooks/v1", at_rest: "sealed" },
|
|
496
493
|
/** /triggers: what starts an agent's capped runs with no caller (triggers.ts). */
|
|
@@ -555,7 +552,9 @@ export async function startServe(options) {
|
|
|
555
552
|
if (options.drainTimeout !== undefined && durationMs(options.drainTimeout) === undefined)
|
|
556
553
|
throw new Error(`the drain timeout ${options.drainTimeout} is not a duration such as 8s`);
|
|
557
554
|
enabledBoxes(process.env);
|
|
558
|
-
|
|
555
|
+
// A Docker computer's size an operator sets (workspace/computer-deps.ts): a value the Docker provider refuses stops the
|
|
556
|
+
// start, in its words.
|
|
557
|
+
dockerLimitsOf(process.env);
|
|
559
558
|
// The Docker host's addresses an operator names (workspace/computer-deps.ts): a bad entry stops the start, in words.
|
|
560
559
|
dockerHostAddressesOf(process.env);
|
|
561
560
|
const boxAllow = boxAllowOf(process.env);
|
|
@@ -568,9 +567,9 @@ export async function startServe(options) {
|
|
|
568
567
|
const minFreeBytes = options.minFreeBytes ?? minFreeMib * 2 ** 20;
|
|
569
568
|
// The template packages, each checked whole (templates.ts readPackage): a broken one stops the start.
|
|
570
569
|
const templates = readPackages(options.templates);
|
|
571
|
-
// One server per data root
|
|
572
|
-
// data directory an earlier version wrote is refused there too
|
|
573
|
-
//
|
|
570
|
+
// One server per data root: the store's owner lock (StoreOwned), then the data root's own (server-lock.ts), both taken
|
|
571
|
+
// when startHolding opens the store; a data directory an earlier version wrote is refused there too
|
|
572
|
+
// (StoreFromEarlierVersion), in words, to start fresh. No oldHomes/oldLayout checks, no migration.
|
|
574
573
|
// What a start that fails stops: the webhook deliveries it began, which would write the next server's outbox, and the
|
|
575
574
|
// store handle it opened.
|
|
576
575
|
const stops = [];
|
|
@@ -583,6 +582,27 @@ export async function startServe(options) {
|
|
|
583
582
|
throw error;
|
|
584
583
|
}
|
|
585
584
|
}
|
|
585
|
+
/** How much longer than its drain timeout a start waits for the server it replaces (a redeploy, a restart that starts the
|
|
586
|
+
* new server before the old one has exited): the old one's close, after its runs' drain. */
|
|
587
|
+
const START_WAIT_MARGIN_MS = 30_000;
|
|
588
|
+
/** `take()`, tried again every 250 ms while `held(error)` says the server this one replaces still holds what it takes, up
|
|
589
|
+
* to `until` (epoch ms); `waiting` is told this wait's `until` once, as it begins. Past `until`, or on any other error,
|
|
590
|
+
* it throws. */
|
|
591
|
+
async function whileReplaced(take, held, until, waiting) {
|
|
592
|
+
let told = false;
|
|
593
|
+
for (;;) {
|
|
594
|
+
try {
|
|
595
|
+
return await take();
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
if (!held(error) || Date.now() >= until)
|
|
599
|
+
throw error;
|
|
600
|
+
if (!told)
|
|
601
|
+
(told = true), waiting(until);
|
|
602
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
586
606
|
async function startHolding(options, data, checked, stops) {
|
|
587
607
|
const { maxRuns, minFreeBytes, learning, learningBudget, boxAllow, templates } = checked;
|
|
588
608
|
/** What an agent's view says of its learning: how many learned items wait for its owner's OK, for an agent that learns
|
|
@@ -594,14 +614,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
594
614
|
const pending = await pendingCount(data, entry.agent.id);
|
|
595
615
|
return pending === undefined ? undefined : { pending };
|
|
596
616
|
};
|
|
597
|
-
const tokenFile = options.token === undefined ? join(data, TOKEN_FILE) : null;
|
|
598
|
-
const stored = options.token === undefined ? await tokenIn(tokenFile) : undefined;
|
|
599
|
-
const token = options.token ?? stored.token;
|
|
600
|
-
// Given a token (AGENTRUN_TOKEN), a .token an earlier start made holds one this server refuses: it goes, so nothing
|
|
601
|
-
// (a person told the token is there, a CLI that reads it) takes a dead token from it. A later start without one makes a
|
|
602
|
-
// new file and token.
|
|
603
|
-
if (options.token !== undefined)
|
|
604
|
-
await rm(join(data, TOKEN_FILE), { force: true });
|
|
605
617
|
const log = options.log;
|
|
606
618
|
const quiet = process.env.AGENTRUN_LOG === "quiet";
|
|
607
619
|
const authFailed = (route, reason) => log?.(logLine("auth_failed", { route, reason }));
|
|
@@ -616,12 +628,49 @@ async function startHolding(options, data, checked, stops) {
|
|
|
616
628
|
let triggerSettings = new Map();
|
|
617
629
|
const base = { ...withoutFaux(process.env), [DATA_ENV]: data, ...(options.allowCodeNodes ? { [CODE_NODES_ENV]: "1" } : {}), ...(options.faux ? { [FAUX_ENV]: resolve(options.faux) } : {}), ...(options.harnessTable ? { [HARNESS_TABLE_ENV]: resolve(options.harnessTable) } : {}) };
|
|
618
630
|
// The one store (module A), opened here as this data root's single owner, before the settings layers that read it: its
|
|
619
|
-
//
|
|
620
|
-
// words, to start fresh (no oldHomes/oldLayout checks, no migration). Every agent, run, setting and sign-in is a row; the
|
|
631
|
+
// owner lock holds the store to this server (the data root's own lock follows), and it refuses a data directory an
|
|
632
|
+
// earlier version wrote, in words, to start fresh (no oldHomes/oldLayout checks, no migration). Every agent, run, setting and sign-in is a row; the
|
|
621
633
|
// server writes and reads rows, and a runner (its own process, sharing only this store) runs every run.
|
|
622
|
-
// On Postgres when this process's AGENTRUN_STORE_URL secret names one (store/open.ts)
|
|
623
|
-
|
|
634
|
+
// On Postgres when this process's AGENTRUN_STORE_URL secret names one (store/open.ts).
|
|
635
|
+
// A server deploying while the old one still holds the schema waits for it (said once), never exits at once.
|
|
636
|
+
// The server this one replaces may still be stopping (a redeploy, a restart that starts this one before the old one has
|
|
637
|
+
// exited): its close comes after its runs' drain, so this start waits for as long as its own drain timeout and a
|
|
638
|
+
// margin, saying so once, before it refuses. On Postgres the store's owner lock waits on its own (store/open.ts); on
|
|
639
|
+
// SQLite the store file's owner lock is waited for here, and the data root's lock below on either.
|
|
640
|
+
const replacedDrainMs = durationMs(options.drainTimeout ?? DRAIN_TIMEOUT) ?? 0;
|
|
641
|
+
const replacedUntil = Date.now() + replacedDrainMs + START_WAIT_MARGIN_MS;
|
|
642
|
+
const sayReplaced = noticeOf(options);
|
|
643
|
+
let replacedTold = false;
|
|
644
|
+
const waitingForReplaced = (until) => {
|
|
645
|
+
if (replacedTold)
|
|
646
|
+
return;
|
|
647
|
+
replacedTold = true;
|
|
648
|
+
sayReplaced(`another server holds this data root: waiting up to ${Math.max(1, Math.ceil((until - Date.now()) / 1000))} s for the previous server to stop`);
|
|
649
|
+
};
|
|
650
|
+
const onSqlite = storeTarget(data).kind === "sqlite";
|
|
651
|
+
const store = await whileReplaced(() => openStore({
|
|
652
|
+
dataDir: data, role: "server",
|
|
653
|
+
warn: (message) => void process.stderr.write(`agentrun-serve: ${message}\n`),
|
|
654
|
+
...(options.onStoreLost ? { onOwnerLost: options.onStoreLost } : {}),
|
|
655
|
+
}), (error) => onSqlite && error instanceof StoreOwned, replacedUntil, waitingForReplaced);
|
|
624
656
|
stops.push(() => store.close());
|
|
657
|
+
// 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
|
|
658
|
+
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
659
|
+
// uploads, harness installs, learning folders), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
660
|
+
// Postgres) would share. The lock is SQLite's EXCLUSIVE lock (server-lock.ts): the kernel drops it when its process
|
|
661
|
+
// dies, so a crashed server never leaves it held.
|
|
662
|
+
// Its wait runs from when the store was held at the earliest, since a store on Postgres may have been waited for first.
|
|
663
|
+
const dataLock = await whileReplaced(() => takeServerLock(data), (error) => error instanceof ServerLockHeldError, Math.max(replacedUntil, Date.now() + START_WAIT_MARGIN_MS), waitingForReplaced);
|
|
664
|
+
stops.push(async () => dataLock.release());
|
|
665
|
+
// The token, once both locks are held: a start the locks refuse reads, makes and removes nothing in the data root.
|
|
666
|
+
const tokenFile = options.token === undefined ? join(data, TOKEN_FILE) : null;
|
|
667
|
+
const stored = options.token === undefined ? await tokenIn(tokenFile) : undefined;
|
|
668
|
+
const token = options.token ?? stored.token;
|
|
669
|
+
// Given a token (AGENTRUN_TOKEN), a .token an earlier start made holds one this server refuses: it goes, so nothing
|
|
670
|
+
// (a person told the token is there, a CLI that reads it) takes a dead token from it. A later start without one makes a
|
|
671
|
+
// new file and token.
|
|
672
|
+
if (options.token !== undefined)
|
|
673
|
+
await rm(join(data, TOKEN_FILE), { force: true });
|
|
625
674
|
// No start without a seal key (seal-key.ts), checked against the store before anything reads it: the one handed over,
|
|
626
675
|
// else the one in the data directory beside the store, made at the first start with only its path printed. A store whose
|
|
627
676
|
// secrets another key sealed is refused, in words, and no key is made over them. Every secret here is kept under it;
|
|
@@ -631,7 +680,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
631
680
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
632
681
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
633
682
|
const own = (env) => withSealKey(env, seal.text);
|
|
634
|
-
// Which fields are the server's is read from what it is started with alone: handed the saved keys too,
|
|
683
|
+
// Which fields are the server's is read from what it is started with alone: handed the saved keys too, the tool keys would
|
|
635
684
|
// call each the server's, and none could be deleted. The keys are sealed rows in the store; load() reads them once here.
|
|
636
685
|
const toolKeys = toolKeysOverStore(store, own(withSecrets(base, "own")), (fields) => (log ? log(logLine("tool_keys", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("tool_keys", fields)}\n`)));
|
|
637
686
|
await toolKeys.load();
|
|
@@ -696,7 +745,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
696
745
|
// With accounts off no one can answer an ask (the answer route takes the owner's session alone): each tool ask is
|
|
697
746
|
// offered for says it needs the password sign-in, as learning's approve does.
|
|
698
747
|
const askNeeds = (made) => (options.accounts ? made : { ...made, tools: made.tools.map((tool) => (tool.permissions.includes("ask") ? { ...tool, ask_needs: "password" } : tool)) });
|
|
699
|
-
const
|
|
748
|
+
const compose = (runnerShell) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, options.gradeModel, toolKeys.refused(), runnerShell));
|
|
749
|
+
const recompose = () => void (caps = compose());
|
|
700
750
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
701
751
|
let offersFrom;
|
|
702
752
|
let probes = 0;
|
|
@@ -829,10 +879,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
829
879
|
// process sees it.
|
|
830
880
|
const vmSecrets = () => [...serverSecrets(), ...VM_PROVIDER.keys.map((name) => env[name] ?? "").filter(Boolean)];
|
|
831
881
|
const vmRelayHalf = vmBoxes && vmClient ? vmRelay(vmClient, vmSecrets) : undefined;
|
|
832
|
-
const vmLimits = (() => {
|
|
833
|
-
const limits = boxLimitsOf(env);
|
|
834
|
-
return { cpus: limits.cpus, memoryMb: memoryMbOf(limits.memory) };
|
|
835
|
-
})();
|
|
836
882
|
// Daytona could not keep a run's box's domain list: said in the log and in capabilities, which recompose now.
|
|
837
883
|
// Daytona's own words go to the log, so a refusal for another cause is not taken silently for a tier that takes no list.
|
|
838
884
|
const onNoBoxList = (code, message) => {
|
|
@@ -876,15 +922,39 @@ async function startHolding(options, data, checked, stops) {
|
|
|
876
922
|
: kind === "browser" ? browserToolNames : capabilityToolDefs(kind).map((def) => def.name);
|
|
877
923
|
let faux;
|
|
878
924
|
const fauxOf = () => (faux ??= fauxComputers({ viewerBase: ownOriginOf() }));
|
|
925
|
+
/** Whether a computer on a provider that binds a folder of this machine (Docker) can be had here now: Settings →
|
|
926
|
+
* Computers' view and a run's start check (below) both ask it. Where AGENTRUN_BOXES lists Docker and it is no faux
|
|
927
|
+
* box, its daemon is asked (docker-daemon.ts: a short `docker version`, its answer kept a while and asked again, so a
|
|
928
|
+
* daemon that stops after the start is seen, and one that is gone says so in noDockerWords); once it answers, the
|
|
929
|
+
* box's start-time answer stands. A box the start did not make keeps its reason ("start Docker, then restart
|
|
930
|
+
* AgentRun"): the start's checks of Docker (Docker elsewhere, this server's paths, host addresses, its network) ran
|
|
931
|
+
* without it, so a daemon that answers later is not taken. Else the box's start-time answer (boxOffers), with its
|
|
932
|
+
* reason, which says how to fix it. The provider whose computers run on this machine's container engine is the one
|
|
933
|
+
* whose descriptor declares `local`. */
|
|
934
|
+
const dockerDaemon = dockerDaemonCheck({ env });
|
|
935
|
+
const dockerAnswers = async (provider) => {
|
|
936
|
+
const box = boxAvailability(boxOffers).find((one) => one.id === provider);
|
|
937
|
+
const local = COMPUTER_PROVIDERS.find((one) => one.id === provider)?.local === true;
|
|
938
|
+
if (local && !fauxBox && enabledBoxes(env).has(provider)) {
|
|
939
|
+
const daemon = await dockerDaemon();
|
|
940
|
+
if (!daemon.up || box?.available)
|
|
941
|
+
return daemon;
|
|
942
|
+
}
|
|
943
|
+
else if (box?.available)
|
|
944
|
+
return { up: true };
|
|
945
|
+
return { up: false, absent: false, reason: box?.reason ?? `${provider} is not a box this server has` };
|
|
946
|
+
};
|
|
879
947
|
let computerRoutes;
|
|
880
948
|
const computersOf = () => (computerRoutes ??= createComputerRoutes({
|
|
881
949
|
store, sealKey, tools: kindTools, mode: folderModeOf(store), env: process.env,
|
|
882
950
|
...(options.faux
|
|
951
|
+
// --faux's providers stand in for every vendor's, a local one's daemon included.
|
|
883
952
|
? { kinds: fauxOf().kinds, factories: fauxOf().factories, keyTable: fauxOf().keyTable }
|
|
884
953
|
: {
|
|
885
954
|
kinds: { SETTING_KINDS, PROVIDERS: COMPUTER_PROVIDERS, servingRefusals },
|
|
886
955
|
// The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own.
|
|
887
956
|
factories: computerProviderFactories(computerProviderMakers(), (id) => storeLedger(store.computerLedger, id)),
|
|
957
|
+
answers: dockerAnswers,
|
|
888
958
|
}),
|
|
889
959
|
}));
|
|
890
960
|
/** Whether an agent's computer setting can be had here now, by the answers the runner's claim gives (resolve-computer.ts
|
|
@@ -892,13 +962,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
892
962
|
* runner composes with: runner/main.ts gives it no faux, so the package's, under --faux too), in the folder mode of
|
|
893
963
|
* now, with keys read as the runner reads them (the secrets this process was started with, withSecrets "own", as
|
|
894
964
|
* runner/main.ts runEnv hands them; else the saved one). What runnable.ts checks for an agent with
|
|
895
|
-
* a computer setting, in place of the box check
|
|
896
|
-
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
965
|
+
* a computer setting, in place of the box check; whether Docker answers here is dockerAnswers'. */
|
|
966
|
+
/** The server's folder mode now: 2 when the owner's Archil settings are saved (the run's folder on the disk), else 1. */
|
|
967
|
+
const modeNow = async () => ((await folderModeOf(store)()) === "disk" ? 2 : 1);
|
|
968
|
+
const computerReady = async (setting) => computerReadiness(setting, await modeNow(), claimKinds({}), keyReader(store, sealKey, own(withSecrets(process.env, "own"))), dockerAnswers, boxAllow);
|
|
969
|
+
/** Where a run of an agent with computer `setting` has its shell here now (resolve-computer.ts runShellOf, in the
|
|
970
|
+
* folder mode of now, over the registry the claim reads): what runnable.ts lets a sandbox-only tool on the runner by,
|
|
971
|
+
* and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec. */
|
|
972
|
+
const shellOf = async (setting) => runShellOf(setting, await modeNow(), claimKinds({}));
|
|
902
973
|
const archil = createArchilRoutes({ store, sealKey, env: process.env });
|
|
903
974
|
/** A run's computer on its read: its revision's computer setting, else the one its place says; absent for none. */
|
|
904
975
|
const runComputerOf = async (runId, view) => {
|
|
@@ -940,9 +1011,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
940
1011
|
// (under faux, the vendor's fake alone), under this server's seal key. The store holds whether a sign-in is still held
|
|
941
1012
|
// (a live run's sign_in_handed) and who was handed it, so this takes no `holds`/`handedTo` callback — one store, one lock.
|
|
942
1013
|
const signIns = signInsOverStore(store, sealKey, vendorsOver(() => env, checkFetch));
|
|
943
|
-
|
|
944
|
-
//
|
|
945
|
-
|
|
1014
|
+
// The outbound webhook and its outbox, in the store; its signing secret among the server's sealed settings, which list it
|
|
1015
|
+
// (and each one it held before) with the server's own secrets.
|
|
1016
|
+
const webhooks = new Webhooks(store, triggerSettings.get(OUTBOUND_WEBHOOK.id), (fields) => (log ? log(logLine("webhook", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("webhook", fields)}\n`)), options.webhookRetryMs);
|
|
1017
|
+
await webhooks.load();
|
|
946
1018
|
stops.push(() => webhooks.close());
|
|
947
1019
|
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
948
1020
|
// Under the data directory's lock and before this server answers anything, so no PUT of its own is in flight: an upload
|
|
@@ -950,6 +1022,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
950
1022
|
const swept = await uploads.sweep();
|
|
951
1023
|
if (swept > 0)
|
|
952
1024
|
log?.(logLine("uploads_swept", { removed: swept }));
|
|
1025
|
+
// A run's hold of its files goes at its claim, once they are in its workspace; one that ended before any claim copied
|
|
1026
|
+
// them (cancelled while queued) leaves its hold, which goes here, as does one whose run is gone.
|
|
1027
|
+
for (const runId of await uploads.holders()) {
|
|
1028
|
+
const row = await store.runs.get(runId);
|
|
1029
|
+
if (!row || FINAL_STATES.includes(row.state))
|
|
1030
|
+
await uploads.release(runId);
|
|
1031
|
+
}
|
|
953
1032
|
const documents = options.documents ?? process.env[DOCUMENTS_ENV];
|
|
954
1033
|
if (documents !== undefined && !(await stat(documents).then((info) => info.isDirectory(), () => false)))
|
|
955
1034
|
throw new Error(`the documents directory ${documents} is not a directory`);
|
|
@@ -957,10 +1036,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
957
1036
|
// of each at a time, which every run on that harness, and the save of an agent on it, waits for or starts; once one is
|
|
958
1037
|
// in, the offers are probed again, so capabilities no longer say it installs on first use. Each is its table entry's
|
|
959
1038
|
// `installs` (a test's stand-in has none).
|
|
960
|
-
// Claude Code as an earlier build installed it, at the top of the harnesses directory itself (read-only): removed once,
|
|
961
|
-
// before the first install, which then goes in beside nothing. Any other layout is left as it is.
|
|
962
|
-
let flat;
|
|
963
|
-
const flatRemoved = () => (flat ??= removeFlatInstall(harnessesOf(data)).then((removed) => void (removed && log?.(logLine("harness_install_removed", { dir: harnessesOf(data), said: `removed the earlier Claude Code install at ${harnessesOf(data)}: it installs again under harnesses/claude-agent` }))), (error) => ((flat = undefined), Promise.reject(error))));
|
|
964
1039
|
const installed = HARNESSES.flatMap((id) => {
|
|
965
1040
|
const harness = harnessOf(base, id);
|
|
966
1041
|
return harness?.installs && harness.pins ? [{ entry: harness.installs, pins: harness.pins }] : [];
|
|
@@ -969,7 +1044,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
969
1044
|
const lock = options.harnessLocks?.[entry.id];
|
|
970
1045
|
// npm past its SIGTERM's grace (it waits on a tarball once it writes): killed, and the line says so.
|
|
971
1046
|
const onKilled = () => log?.(logLine("harness_install_killed", { harness: entry.id, said: `npm did not stop within ${NPM_STOP_GRACE_MS / 1000} s of SIGTERM; killed` }));
|
|
972
|
-
return [entry.id, new HarnessInstall(entry, installDirOf(data, entry.id), pins,
|
|
1047
|
+
return [entry.id, new HarnessInstall(entry, installDirOf(data, entry.id), pins, (entry, dir, pins, signal) => npmInstall(entry, dir, pins, { signal, onKilled, ...(lock ? { lock } : {}) }), (ms) => {
|
|
973
1048
|
log?.(logLine("harness_installed", { harness: entry.id, ms, dir: installDirOf(data, entry.id) }));
|
|
974
1049
|
void probe(`${entry.id}_installed`).catch(() => undefined);
|
|
975
1050
|
})];
|
|
@@ -1003,6 +1078,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1003
1078
|
told: (error) => told(error),
|
|
1004
1079
|
runnable,
|
|
1005
1080
|
readyFiles: (ids) => uploads.readyFiles(ids),
|
|
1081
|
+
files: { hold: (runId, ids) => uploads.hold(runId, ids), release: (runId) => uploads.release(runId) },
|
|
1006
1082
|
fallbackPlace: (kind, tools) => fallbackPlace(kind, tools),
|
|
1007
1083
|
workflowTitle,
|
|
1008
1084
|
serverSecrets,
|
|
@@ -1011,15 +1087,22 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1011
1087
|
approvers: options.accounts === true,
|
|
1012
1088
|
...(documents ? { documents: resolve(documents) } : {}),
|
|
1013
1089
|
...(boxAllow !== undefined ? { boxAllow } : {}),
|
|
1090
|
+
// Whether that is the operator's own setting, not the default: a browser is held to an operator's list alone.
|
|
1091
|
+
...(boxAllowSetIn(process.env) ? { boxAllowSet: true } : {}),
|
|
1014
1092
|
modelOf,
|
|
1015
1093
|
// The run's learning start, decided at start as the old file-backed start decided it (learning-run.ts onStart/seedFor):
|
|
1016
1094
|
// the server's learning switch, the budget its # Learned section fits, the agent's seed read now from its learning folder
|
|
1017
|
-
// (git), and the host's secrets as they are shown now to cut the notes a run is given
|
|
1018
|
-
//
|
|
1019
|
-
//
|
|
1020
|
-
//
|
|
1095
|
+
// (git), and the host's secrets as they are shown now to cut the notes a run is given, a loopback address kept (local),
|
|
1096
|
+
// as the run's .learning/ files keep it: the run's own machine, which an agent with no read tool learns of only here.
|
|
1097
|
+
// runs-over-store.learningStartFor pins the result (given/seed/section/seedNotes) in the launch for the runner; a seed
|
|
1098
|
+
// that cannot be read starts the run with nothing learned (a fault never refuses it). The runner's spec builders read
|
|
1099
|
+
// it back as the run's end-of-run step (runner/learning-end.ts learningEndOfRun, in adapter-run-spec.ts and
|
|
1100
|
+
// cli-run-spec.ts).
|
|
1021
1101
|
learning,
|
|
1022
1102
|
learningBudget,
|
|
1103
|
+
// The model the server names to grade what a run proposes (capabilities' learning.grade_model), carried on each learning
|
|
1104
|
+
// start for the runner's learning run to grade on: none, the agent's own.
|
|
1105
|
+
...(gradeModelOf(env, options.gradeModel) ? { gradeModel: gradeModelOf(env, options.gradeModel) } : {}),
|
|
1023
1106
|
seedFor: async (agentId) => {
|
|
1024
1107
|
// The switch runs no git in this process (learning.ts seedOf: the folder's own script and file API, which checks git
|
|
1025
1108
|
// itself); a git or folder fault surfaces here as a seedOf error, so the run starts with nothing learned, never refused.
|
|
@@ -1028,24 +1111,34 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1028
1111
|
return { failed: error.message };
|
|
1029
1112
|
});
|
|
1030
1113
|
},
|
|
1031
|
-
shown: () => secretsShown(serverSecrets()),
|
|
1114
|
+
shown: () => secretsShown(serverSecrets(), { local: true }),
|
|
1032
1115
|
};
|
|
1033
1116
|
// A run's served view and its live moment, from the store (store-view): `origin` is where this request reaches the
|
|
1034
1117
|
// console, the secrets are cut live, and the sign-ins give the handed-pointer cut. Trigger and background reads (no
|
|
1035
1118
|
// request) use the server's public address, else its own.
|
|
1036
1119
|
// The run's key read from this server's environment with the keys a person saved, as its Timeline reads it (keyEnv below).
|
|
1037
|
-
|
|
1120
|
+
// The learning routes' cut: the server's secrets and agent `agentId`'s own sign-in pointers, live and forgotten; 403 when
|
|
1121
|
+
// one of them can't be read here (agentPointers), never a shorter cut.
|
|
1122
|
+
const learningValues = async (agentId) => {
|
|
1123
|
+
const pointers = await agentPointers(signIns, agentId);
|
|
1124
|
+
if (pointers === "unreadable")
|
|
1125
|
+
throw new ApiError("forbidden", WITHHELD_LEARNING);
|
|
1126
|
+
return [...serverSecrets(), ...pointers];
|
|
1127
|
+
};
|
|
1128
|
+
const learningShown = async (agentId) => secretsShown(await learningValues(agentId));
|
|
1129
|
+
// What a run held for its owner's OK reads as it stands on its agent's learning folder's main (statusesOf).
|
|
1130
|
+
const statuses = (agentId) => statusesOf(data, agentId);
|
|
1131
|
+
const viewDepsFor = (origin) => ({ origin, serverSecrets, signIns, keyEnv: () => own(withSecrets(process.env, "all", storedKeys)), statuses });
|
|
1038
1132
|
const ownOriginOf = () => options.publicUrl ?? url;
|
|
1039
1133
|
// The run read routes (a run's files, its browser state, its workflow graph) over the one store (run-reads-over-store):
|
|
1040
1134
|
// a run's files through the server's read-only Workspace of its folder (serverRunWorkspace, no runner claim), its view
|
|
1041
1135
|
// and withheld verdict from store-view. The live browser viewer reads the runner's published handover from the store
|
|
1042
|
-
// (liveViewerLink, the one the runner's browser tool wrote under its claim),
|
|
1043
|
-
//
|
|
1044
|
-
// its own stub (store-reads journal + SSE) until E2c's timeline lands.
|
|
1136
|
+
// (liveViewerLink, the one the runner's browser tool wrote under its claim), opened with the server's seal key. The
|
|
1137
|
+
// timeline route keeps its own stub (store-reads journal + SSE) until E2c's timeline lands.
|
|
1045
1138
|
const runReadsDeps = {
|
|
1046
1139
|
runWorkspace: (_store, runId) => serverRunWorkspace(store, runId, { data, sealKey }),
|
|
1047
1140
|
env,
|
|
1048
|
-
|
|
1141
|
+
runFacts: (_store, runId) => factsOverStore(store, runId, viewDepsFor(ownOriginOf())),
|
|
1049
1142
|
withheld: (_store, runId) => withheldOverStore(store, runId, viewDepsFor(ownOriginOf())),
|
|
1050
1143
|
cutValues: (_store, runId) => runCutValues({ serverSecrets, signIns }, store, runId),
|
|
1051
1144
|
context: ctx,
|
|
@@ -1061,7 +1154,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1061
1154
|
// shows and each browser sign-in pointer the run was handed; its decision rows among them, its error rows in the
|
|
1062
1155
|
// error's words. A run whose hand can't be read back here is withheld: none of its rows. A run's Timeline is read
|
|
1063
1156
|
// from its journal, which keeps what the run said whole.
|
|
1064
|
-
timelineRows: (forStore, runId, context) => servedTimelineRows({ serverSecrets, signIns, keyEnv: () => own(withSecrets(process.env, "all", storedKeys)) }, forStore, runId, context),
|
|
1157
|
+
timelineRows: (forStore, runId, context) => servedTimelineRows({ serverSecrets, signIns, keyEnv: () => own(withSecrets(process.env, "all", storedKeys)), statuses }, forStore, runId, context),
|
|
1065
1158
|
runView: (forStore, runId) => viewOverStore(forStore, runId, viewDepsFor(ownOriginOf())),
|
|
1066
1159
|
});
|
|
1067
1160
|
const triggerDeps = {
|
|
@@ -1070,6 +1163,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1070
1163
|
needAgent,
|
|
1071
1164
|
momentOf: (runId) => momentOverStore(store, runId, viewDepsFor(ownOriginOf())),
|
|
1072
1165
|
runStatus: async (runId) => (await viewOverStore(store, runId, viewDepsFor(ownOriginOf())))?.status ?? null,
|
|
1166
|
+
completedOutput: async (runId) => {
|
|
1167
|
+
const view = await viewOverStore(store, runId, viewDepsFor(ownOriginOf()));
|
|
1168
|
+
if (view?.status !== "completed")
|
|
1169
|
+
return undefined;
|
|
1170
|
+
return { output: view.result?.output ?? null, endedAt: view.ended_at ?? null };
|
|
1171
|
+
},
|
|
1073
1172
|
};
|
|
1074
1173
|
const targets = triggerTargets(store, triggerDeps);
|
|
1075
1174
|
const expected = digest(`Bearer ${token}`);
|
|
@@ -1148,7 +1247,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1148
1247
|
// Connect GitHub: the server's one GitHub App, in the store's trigger_settings (adapter github, scope server), where the
|
|
1149
1248
|
// runner reads it per claim (runner/github-app.ts).
|
|
1150
1249
|
const github = new GitHubConnection(triggerSettings.get("github"));
|
|
1151
|
-
|
|
1250
|
+
// --faux-github (with --faux only): the fake App is connected afresh at each start, its API in this process.
|
|
1251
|
+
const was = options.faux && options.fauxGitHub ? github.view() : undefined;
|
|
1252
|
+
if (was && was.slug !== FAUX_GITHUB.slug)
|
|
1253
|
+
throw new Error(`--faux-github connects a fake GitHub App, and this data directory has the GitHub App ${was.slug} connected: use a scratch data directory.`);
|
|
1254
|
+
const fauxGitHub = options.faux && options.fauxGitHub ? await startFauxGitHub() : undefined;
|
|
1255
|
+
if (fauxGitHub) {
|
|
1256
|
+
stops.push(() => fauxGitHub.close());
|
|
1257
|
+
if (was)
|
|
1258
|
+
await github.remove();
|
|
1259
|
+
await github.save(fauxGitHub.app);
|
|
1260
|
+
await github.setInstallations([{ id: FAUX_GITHUB.installation, account: FAUX_GITHUB.account }]);
|
|
1261
|
+
await writeFile(join(data, FAUX_GITHUB_FILE), `${JSON.stringify({ webhook_secret: fauxGitHub.app.webhookSecret, installation: FAUX_GITHUB.installation, account: FAUX_GITHUB.account, repositories: FAUX_GITHUB.repositories })}\n`, { mode: 0o600 });
|
|
1262
|
+
}
|
|
1263
|
+
const githubConnect = new GitHubConnect(github, { ...(options.publicUrl ? { publicUrl: options.publicUrl.replace(/\/+$/, "") } : {}), api: fauxGitHub?.url ?? options.githubApi ?? GITHUB_API, say: (fields) => log?.(logLine("github", fields)) });
|
|
1152
1264
|
/** The connection a GitHub template or the console reads: the App's id, slug and installations, never a secret. */
|
|
1153
1265
|
const githubConnection = () => github.view();
|
|
1154
1266
|
/** What applying a template reads of the server (templates.ts TemplatesDeps). */
|
|
@@ -1310,16 +1422,24 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1310
1422
|
return value;
|
|
1311
1423
|
}
|
|
1312
1424
|
/** The tools a learned draft of agent `id` may name, as a run's merge reads them (learning-run.ts draftTools): its
|
|
1313
|
-
* current revision's, those the gate allows under the server's settings and the agent's own.
|
|
1314
|
-
|
|
1315
|
-
|
|
1425
|
+
* current revision's, those the gate allows under the server's settings and the agent's own. `entry`: the agent as the
|
|
1426
|
+
* caller already read it, so what it checks and what it copies are one revision's (a promotion). */
|
|
1427
|
+
async function learnedDraftToolsOf(id, entry) {
|
|
1428
|
+
const revision = (entry ?? (await needAgent(id))).revision;
|
|
1316
1429
|
if (revision?.kind !== "agentic")
|
|
1317
|
-
return { tools: [], gated: {} };
|
|
1318
|
-
const [{ learnedDraftTools }, {
|
|
1430
|
+
return { tools: [], gated: {}, deniedBy: {} };
|
|
1431
|
+
const [{ learnedDraftTools, mcpGrantsListed }, { permissionFrom }, { learnedAskFits }] = await Promise.all([import("./tools.js"), import("./tool-gate.js"), import("./learned-workflow.js")]);
|
|
1319
1432
|
const server = settings.get();
|
|
1320
1433
|
// The revision row's body is the agentic body JSON (store-backed RevisionRow types it as unknown).
|
|
1321
1434
|
const body = revision.body;
|
|
1322
|
-
|
|
1435
|
+
// A server's wildcard grant read as the tools its server lists now (tools.ts mcpGrantsListed, LS-07).
|
|
1436
|
+
const rows = (body.tools ?? []).some((name) => /^mcp:[^/]+\/\*$/.test(name)) ? await store.mcp.servers().catch(() => []) : [];
|
|
1437
|
+
const listed = new Map(rows.map((row) => [row.name, (row.tools ?? []).flatMap((tool) => (typeof tool?.name === "string" ? [tool.name] : []))]));
|
|
1438
|
+
const gate = (name) => permissionFrom(name, server, (body.toolSettings ?? {}), body.approvals === "never" ? "never" : "ask");
|
|
1439
|
+
// `deniedBy`: where each deny was set (the agent's tool settings, the server's), which a refused draft's words name.
|
|
1440
|
+
const { tools, gated, deniedBy, asked } = learnedDraftTools(mcpGrantsListed(body.tools ?? [], (name) => listed.get(name) ?? []), (name) => gate(name).permission, undefined, (name) => gate(name).from, { mcp: true, approvers: await readApprovers(store.settings) });
|
|
1441
|
+
// #2424's card rule (learnedAskFits): a restored draft whose ask-set MCP tools would not all show is refused.
|
|
1442
|
+
return { tools, gated, deniedBy, ask: { asked, fits: learnedAskFits } };
|
|
1323
1443
|
}
|
|
1324
1444
|
async function needAgent(id) {
|
|
1325
1445
|
const entry = ID.test(id) ? await agents.get(id) : null;
|
|
@@ -1407,7 +1527,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1407
1527
|
* does not have yet. `capped`: the run has a spend cap, which a web tool's resolution reads (tool-plane.ts). */
|
|
1408
1528
|
async function runnable(revision, place, { capped = false } = {}) {
|
|
1409
1529
|
const shape = { ...shapeOf(revision), place, ...(revision.body.place ? {} : { unnamed: true }) };
|
|
1410
|
-
const blockers = await blockersOf(env, shape, settings.get(), { capped, boxes: boxOffers, computerReady, offers, mcp: mcpTools, decisionPrice });
|
|
1530
|
+
const blockers = await blockersOf(env, shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, offers, mcp: mcpTools, decisionPrice });
|
|
1411
1531
|
if (!blockers.length)
|
|
1412
1532
|
return;
|
|
1413
1533
|
const message = blockers.map((b) => b.message).join(" ");
|
|
@@ -1443,14 +1563,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1443
1563
|
}
|
|
1444
1564
|
const named = (revision.kind === "agentic" ? { kind: "agentic", ...body } : workflowShape(body));
|
|
1445
1565
|
const shape = named.place ? named : { ...named, place: fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
1446
|
-
const blockers = await blockersOf(env, shape, settings.get(), { boxes: boxOffers, computerReady, offers, mcp: mcpTools });
|
|
1566
|
+
const blockers = await blockersOf(env, shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, offers, mcp: mcpTools });
|
|
1447
1567
|
// An agent's default cap caps each run started without one of its own, and a web tool resolves by the cap: what a cap
|
|
1448
1568
|
// alone keeps from running under the definition's own picks, whatever this host's settings, would keep every such run
|
|
1449
1569
|
// from running, so the save is refused, not each run (claude-agent's or codex's own search, picked, under a cap).
|
|
1450
1570
|
if ((body.maxCostUsd ?? 0) > 0) {
|
|
1451
1571
|
const key = (b) => `${b.field}\n${b.message}`;
|
|
1452
|
-
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, offers, mcp: mcpTools })).map(key));
|
|
1453
|
-
const capped = await blockersOf(env, shape, {}, { capped: true, boxes: boxOffers, computerReady, offers, mcp: mcpTools, decisionPrice });
|
|
1572
|
+
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp: mcpTools })).map(key));
|
|
1573
|
+
const capped = await blockersOf(env, shape, {}, { capped: true, boxes: boxOffers, computerReady, shellOf, offers, mcp: mcpTools, decisionPrice });
|
|
1454
1574
|
// A model with no price (`unpriced`) is a setting this host fixes (AGENT_MODEL_PRICE): a warning, as it is; the
|
|
1455
1575
|
// agent saves and updates, and only a run under the cap is refused (409). A tool's pick a cap rules out refuses it.
|
|
1456
1576
|
const added = capped.filter((b) => !plain.has(key(b)));
|
|
@@ -1473,6 +1593,52 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1473
1593
|
const entry = await agents.create(definition, async (revision) => void (warnings = await saveable(revision)), "place" in fresh ? { place: fresh.place, tools: NEW_AGENT_TOOLS } : undefined);
|
|
1474
1594
|
return { entry, warnings };
|
|
1475
1595
|
}
|
|
1596
|
+
/** Agent `source`'s learned workflow `raw` made into a workflow agent of its own, as POST /agents makes one
|
|
1597
|
+
* (createAgentOf: the definition's checks, the workflow's validation and what this host refuses of it). Only an active
|
|
1598
|
+
* one, checked again as a restore checks it (learning-routes.ts promotable). Its revision is a workflow revision of the
|
|
1599
|
+
* learned workflow.json, its tools those its call nodes call (each one the source agent has and its gate allows), and
|
|
1600
|
+
* the source's policy as it is now: its own tool settings, its approvals and its default cap, never more. Named
|
|
1601
|
+
* `body.name`, else the workflow's own; its id is the workflow's name, with -2, -3 and on past an agent's id or name
|
|
1602
|
+
* already here. The learned workflow stays where it is, unchanged. */
|
|
1603
|
+
async function promoteOf(source, raw, body) {
|
|
1604
|
+
const extra = unknownFields(body, ["name"]);
|
|
1605
|
+
if (body.name !== undefined && (typeof body.name !== "string" || body.name.trim() === "" || body.name.length > 200))
|
|
1606
|
+
extra.push({ field: "name", reason: "wrong_type", message: "name is the new agent's name: text of 1 to 200 characters" });
|
|
1607
|
+
if (extra.length)
|
|
1608
|
+
throw invalid(extra);
|
|
1609
|
+
const id = source.agent.id;
|
|
1610
|
+
const learned = await promotable(data, id, raw, { refuse: await learningValues(id), draftTools: () => learnedDraftToolsOf(id, source) });
|
|
1611
|
+
// Its policy from the same read of the source as the tools checked above: one revision's, whatever is saved meanwhile.
|
|
1612
|
+
const policy = (source.revision?.body ?? {});
|
|
1613
|
+
const promoted = (agentId) => ({
|
|
1614
|
+
id: agentId,
|
|
1615
|
+
name: typeof body.name === "string" ? body.name.trim() : agentId,
|
|
1616
|
+
...(learned.description ? { description: learned.description } : {}),
|
|
1617
|
+
workflow: learned.workflow,
|
|
1618
|
+
tools: learned.calls,
|
|
1619
|
+
...(policy.toolSettings ? { tool_settings: policy.toolSettings } : {}),
|
|
1620
|
+
...(policy.approvals === "never" ? { approvals: "never" } : {}),
|
|
1621
|
+
...(policy.maxCostUsd !== undefined ? { max_cost_usd: policy.maxCostUsd } : {}),
|
|
1622
|
+
...(policy.capMode !== undefined ? { cap_mode: policy.capMode } : {}),
|
|
1623
|
+
});
|
|
1624
|
+
const note = `Made from the learned workflow ${learned.name} of agent ${id}.`;
|
|
1625
|
+
// Another promotion (or a create) may take the id between the read and the write: the next one is tried.
|
|
1626
|
+
for (let tries = 0;; tries++) {
|
|
1627
|
+
const all = [...(await agents.list()), ...(await agents.list({ archived: true }))];
|
|
1628
|
+
const taken = new Set(all.flatMap((entry) => [entry.agent.id, entry.agent.name]));
|
|
1629
|
+
let n = 1;
|
|
1630
|
+
while (taken.has(n === 1 ? learned.name : `${learned.name}-${n}`))
|
|
1631
|
+
n++;
|
|
1632
|
+
const agentId = n === 1 ? learned.name : `${learned.name}-${n}`;
|
|
1633
|
+
try {
|
|
1634
|
+
return await createAgentOf({ definition: promoted(agentId), note });
|
|
1635
|
+
}
|
|
1636
|
+
catch (error) {
|
|
1637
|
+
if (!(error instanceof ApiError && error.code === "agent_exists") || tries >= 4)
|
|
1638
|
+
throw error;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1476
1642
|
/** A template package applied: its parameters and the owner's grants checked (422), then the secrets and required MCP
|
|
1477
1643
|
* servers it names (409, nothing made; an MCP server it can do without is skipped, with a warning), then its
|
|
1478
1644
|
* agent made as POST /agents makes one, its MCP tools at the owner's own settings save those granted, set to allow (a
|
|
@@ -1487,14 +1653,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1487
1653
|
const saved = pkg.mcp.filter((need) => mcpMeta.has(need.server));
|
|
1488
1654
|
const unsaved = pkg.mcp.filter((need) => !saved.includes(need));
|
|
1489
1655
|
const needed = unsaved.filter((need) => need.required);
|
|
1490
|
-
|
|
1491
|
-
// the agent is made, so the apply is refused first, naming each one.
|
|
1492
|
-
const unsealed = sealKeyOf(env[SEAL_KEY_ENV]) ? [] : pkg.triggers.flatMap((trigger, i) => (isObject(trigger.source) && trigger.source.kind === "webhook" ? [i] : []));
|
|
1493
|
-
if (missing.length || needed.length || unsealed.length) {
|
|
1656
|
+
if (missing.length || needed.length) {
|
|
1494
1657
|
const fix = "Add it in Settings → Model keys or Settings → Tool keys, or set it where AgentRun starts, then apply the template again.";
|
|
1495
1658
|
const server = "Add it in Settings → MCP servers, under that name, then apply the template again.";
|
|
1496
|
-
|
|
1497
|
-
throw new ApiError("agent_not_runnable", `The ${pkg.name} template needs ${[...missing, ...needed.map((need) => `the MCP server ${need.server}`), ...(unsealed.length ? ["a seal key for its webhook trigger's secret"] : [])].join(" and ")}, which this server does not have. Nothing was created.`, { fields: [...missing.map((name) => ({ field: `secrets.${name}`, reason: NOT_SET_UP, message: `${name} is not set on this server.`, fix })), ...needed.map((need) => ({ field: `mcp.${need.server}`, reason: NOT_SET_UP, message: `No MCP server ${need.server} is saved on this server.`, fix: server })), ...unsealed.map((i) => ({ field: `triggers.${i}`, reason: NOT_SET_UP, message: `This server has no seal key (${SEAL_KEY_ENV}), so it cannot keep the webhook trigger's secret.`, fix: sealing }))] });
|
|
1659
|
+
throw new ApiError("agent_not_runnable", `The ${pkg.name} template needs ${[...missing, ...needed.map((need) => `the MCP server ${need.server}`)].join(" and ")}, which this server does not have. Nothing was created.`, { fields: [...missing.map((name) => ({ field: `secrets.${name}`, reason: NOT_SET_UP, message: `${name} is not set on this server.`, fix })), ...needed.map((need) => ({ field: `mcp.${need.server}`, reason: NOT_SET_UP, message: `No MCP server ${need.server} is saved on this server.`, fix: server }))] });
|
|
1498
1660
|
}
|
|
1499
1661
|
// An MCP server the package can do without is skipped, and said: its tools are not granted.
|
|
1500
1662
|
const skipped = unsaved.map((need) => ({ field: `mcp.${need.server}`, reason: NOT_SET_UP, message: `No MCP server ${need.server} is saved on this server, so the agent was made without its tools (${need.tools.join(", ")}). Save it in Settings → MCP servers and apply again to grant them.` }));
|
|
@@ -1509,13 +1671,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1509
1671
|
const server = settings.get();
|
|
1510
1672
|
const denied = grants.filter((tool) => { const set = permissionFrom(tool, server); return set.from === "server" && set.permission === "deny"; });
|
|
1511
1673
|
const kept = denied.map((tool) => ({ field: `grants.${tool}`, reason: "not_allowed", message: `${tool} is denied on this server (Settings → Tools), so the agent was not allowed it: its runs are refused it until the owner changes that setting.` }));
|
|
1512
|
-
// The tools this server's own settings pin (or hold refused for a pin that does not read): a package's pin the agent
|
|
1513
|
-
// store can't keep yet is covered there, so its grant stands; any other such tool is made deny (compiled).
|
|
1514
1674
|
// The agent's approvals: the apply's override, else the package's own (a template whose job runs on triggers says
|
|
1515
1675
|
// never), else ask. Deny and pins hold either way.
|
|
1516
1676
|
const chosenApprovals = approvals ?? pkg.approvals;
|
|
1517
|
-
const
|
|
1518
|
-
const made = compiled(pkg, parameters, { ...(harness ? { harness } : {}), ...(model ? { model } : {}), mcp: saved, defaultTools, grants: grants.filter((tool) => !denied.includes(tool)), serverPinned, ...(chosenApprovals ? { approvals: chosenApprovals } : {}) }, templateDeps);
|
|
1677
|
+
const made = compiled(pkg, parameters, { ...(harness ? { harness } : {}), ...(model ? { model } : {}), mcp: saved, defaultTools, grants: grants.filter((tool) => !denied.includes(tool)), ...(chosenApprovals ? { approvals: chosenApprovals } : {}) }, templateDeps);
|
|
1519
1678
|
// Every trigger is checked as POST /triggers checks it, its parameters filled, before anything is made: a schedule
|
|
1520
1679
|
// from a parameter that does not read, or a date that has passed, refuses the apply (422 under triggers.<i>).
|
|
1521
1680
|
const refusedTriggers = madeTriggerIssues(made.triggers, Date.now());
|
|
@@ -1568,9 +1727,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1568
1727
|
}
|
|
1569
1728
|
// A pinned send whose destination parameter was not given is denied, never let go anywhere: said, by its gate name.
|
|
1570
1729
|
const unpinned = made.unpinned.map(({ tool, parameters: named }) => ({ field: `pins.${tool}`, reason: NOT_SET_UP, message: `${tool}'s arguments are fixed by ${named.map((one) => `the ${one} parameter`).join(" and ")}, which was not given, so the agent was made with ${tool} set to deny: it can't call it at all. Apply again with ${named.join(" and ")} set to let it.` }));
|
|
1571
|
-
// A pin this server's agent store does not keep yet (tool-plane.ts AGENT_LAYER_PINS): said, with the setting that holds
|
|
1572
|
-
// the send to its destination meanwhile, the server's.
|
|
1573
|
-
const unkept = made.unkept.map(({ tool, pin }) => ({ field: `pins.${tool}`, reason: NOT_SET_UP, message: serverPinned.has(tool) ? `${tool} is not pinned to ${pinWords(pin)} for this agent yet (this server's agent store keeps an agent's own pin from the store cutover on); this server's own pin of ${tool} holds its calls meanwhile.` : `${tool} is not pinned to ${pinWords(pin)} for this agent yet: this server's agent store keeps an agent's own pin from the store cutover on. Until then the agent was made with ${tool} set to deny, so nothing it reads can send it elsewhere. Pin it on this server, which holds every agent's calls of ${tool}, and apply again to let it.`, ...(serverPinned.has(tool) ? {} : { fix: `Add ${JSON.stringify({ [tool]: { pin } })} to this server's tool settings (Settings → Tools; PUT /v2/settings/tools replaces the whole map, so send it with the rest).` }) }));
|
|
1574
1730
|
// A GitHub tool the package grants that Connect GitHub's App may not use (its manifest asks for less), where the github
|
|
1575
1731
|
// MCP server runs on the App's tokens: said now, before a run's first call is refused (template-github-permissions.ts).
|
|
1576
1732
|
const appShort = appPermissionWarnings({ name: pkg.name, mcp: saved }, (server) => mcpMeta.get(server)?.auth === "github_app");
|
|
@@ -1578,12 +1734,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1578
1734
|
const hooks = made.triggers.flatMap((trigger, i) => (isObject(trigger.source) && trigger.source.kind === "webhook" ? [templateTriggerSecret(i)] : []));
|
|
1579
1735
|
// Each github trigger: what it runs on, when made (a note, never a lack); skipped, what to do about it.
|
|
1580
1736
|
const githubTriggers = made.triggers.flatMap((trigger, i) => (isObject(trigger.source) && trigger.source.kind === "github"
|
|
1581
|
-
? [unconnected.has(i) ? { field: `triggers.${i}`, reason: NOT_SET_UP, message:
|
|
1737
|
+
? [unconnected.has(i) ? { field: `triggers.${i}`, reason: NOT_SET_UP, message: githubTriggerUnconnected(pkg.name, trigger.source) } : { field: `triggers.${i}`, reason: "not_an_option", message: githubTriggerWords(pkg.name, trigger.source) }]
|
|
1582
1738
|
: []));
|
|
1583
1739
|
// Each trigger it made, a webhook trigger's with its secret's metadata; the values go back beside the answer, never in it
|
|
1584
1740
|
// (the route adds them to the first answer to the owner's session, after the Idempotency-Key's record is written).
|
|
1585
1741
|
const minted = new Map(secrets.map(({ trigger_id, secret }) => [trigger_id, secret]));
|
|
1586
|
-
const applied = { template: pkg.name, version: pkg.version, agent_id: entry.agent.id, trigger_ids: ids, ...templateWebhookSecrets([...minted.keys()], new Date().toISOString()), warnings: [...skipped, ...kept, ...modelWarnings, ...unpinned, ...
|
|
1742
|
+
const applied = { template: pkg.name, version: pkg.version, agent_id: entry.agent.id, trigger_ids: ids, ...templateWebhookSecrets([...minted.keys()], new Date().toISOString()), warnings: [...skipped, ...kept, ...modelWarnings, ...unpinned, ...warnings, ...hooks, ...githubTriggers, ...appShort] };
|
|
1587
1743
|
return { applied, minted };
|
|
1588
1744
|
}
|
|
1589
1745
|
/** A run create's issues told from the input this server checks (explain.ts): an agentic run's `{content: string}`,
|
|
@@ -1986,8 +2142,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1986
2142
|
total.unpriced++;
|
|
1987
2143
|
total.usd += usd ?? soFar;
|
|
1988
2144
|
}
|
|
1989
|
-
// What learning spent on this server, outside any run (
|
|
1990
|
-
|
|
2145
|
+
// What learning spent on this server, outside any run (store-reads/learning.ts learningSpendOverStore): each run's grade, on
|
|
2146
|
+
// the day its learning ended.
|
|
2147
|
+
for (const entry of await learningSpendOverStore(store, { from, to })) {
|
|
1991
2148
|
const at = Date.parse(entry.at);
|
|
1992
2149
|
if (at >= from && at < to)
|
|
1993
2150
|
add(lineKey(entry.agent, entry.at, "learning"), entry.cost);
|
|
@@ -2217,8 +2374,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2217
2374
|
throw new ApiError("method_not_allowed", `${req.method} is not a method of ${path}`, {}, { allow: [...new Set(matching.map((r) => r.method))].join(", ") });
|
|
2218
2375
|
if (found.name === "getCapabilities") {
|
|
2219
2376
|
// features.computers: the computer kinds this server offers now (computers.ts), read at each answer, since turning
|
|
2220
|
-
// Archil on or off, or saving a key, changes them.
|
|
2221
|
-
|
|
2377
|
+
// Archil on or off, or saving a key, changes them. So does a shell on the runner (bash on Archil's serverless exec
|
|
2378
|
+
// in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box.
|
|
2379
|
+
const runnerShell = shellTools(await shellOf({ kind: "none" }));
|
|
2380
|
+
const answer = forCaller(runnerShell.size ? compose(runnerShell) : caps, byOwnerSession(req));
|
|
2222
2381
|
return send(res, 200, { ...answer, features: { ...answer.features, computers: await computerCapabilities(computersOf()) } });
|
|
2223
2382
|
}
|
|
2224
2383
|
if (found.name === "getOpenapi")
|
|
@@ -2290,6 +2449,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2290
2449
|
authFailed(`/v2${path}`, "approve_without_session");
|
|
2291
2450
|
throw new ApiError("forbidden", owner ? "Approving a note takes the owner's password sign-in in the console, never a token." : "Approving a note takes the owner's password sign-in, and this server has no accounts (AGENTRUN_ACCOUNTS=0).");
|
|
2292
2451
|
}
|
|
2452
|
+
// Making a learned workflow an agent of its own gives it runs of its own, outside any agentic run's turn: the owner's
|
|
2453
|
+
// click alone, the same session as an approval.
|
|
2454
|
+
if (found.name === "promoteLearnedWorkflow" && !byOwnerSession(req) && req.headers.authorization !== undefined) {
|
|
2455
|
+
authFailed(`/v2${path}`, "promote_without_session");
|
|
2456
|
+
throw new ApiError("forbidden", owner ? "Making a learned workflow an agent takes the owner's password sign-in in the console, never a token." : "Making a learned workflow an agent takes the owner's password sign-in, and this server has no accounts (AGENTRUN_ACCOUNTS=0).");
|
|
2457
|
+
}
|
|
2293
2458
|
// A run's live computer view is a full-control credential for its computer: the owner's signed-in page alone, as
|
|
2294
2459
|
// approving a note is (never a token a run, an MCP client or a script may hold).
|
|
2295
2460
|
if ((found.name === "getRunBrowser" || found.name === "handBackRunBrowser" || found.name === "getRunComputer") && !byOwnerSession(req) && req.headers.authorization !== undefined) {
|
|
@@ -2479,7 +2644,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2479
2644
|
return send(res, answer.status, answer.body, answer.headers);
|
|
2480
2645
|
}
|
|
2481
2646
|
case "raiseRunCap": {
|
|
2482
|
-
|
|
2647
|
+
// The run is read once its body is in, right before the raise row is written: the pause the answer names
|
|
2648
|
+
// (raiseFollowUpId) is the one the run stands at when its runner takes that row, never one an earlier raise ended
|
|
2649
|
+
// while this body was on its way.
|
|
2650
|
+
if (!ID.test(id) || !(await store.runs.get(id)))
|
|
2651
|
+
throw new ApiError("not_found", `no run ${id}`);
|
|
2483
2652
|
const body = await bodyOf(req);
|
|
2484
2653
|
const extra = unknownFields(body, ["max_cost_usd"]);
|
|
2485
2654
|
if (extra.length)
|
|
@@ -2487,6 +2656,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2487
2656
|
const cap = body.max_cost_usd;
|
|
2488
2657
|
if (!(typeof cap === "number" && Number.isFinite(cap) && cap > 0))
|
|
2489
2658
|
throw invalid([{ field: "max_cost_usd", reason: cap === undefined ? "missing" : "wrong_type", message: "max_cost_usd is a number above 0" }]);
|
|
2659
|
+
const run = await needRun(id);
|
|
2490
2660
|
const now = run.maxCostUsd;
|
|
2491
2661
|
if (now === undefined)
|
|
2492
2662
|
throw invalid([{ field: "max_cost_usd", reason: "not_allowed", message: "This run has no cap to raise: a cap is named when a run starts." }]);
|
|
@@ -2666,7 +2836,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2666
2836
|
throw invalid([{ field: "workflow", reason: body.workflow === undefined ? "missing" : "wrong_type", message: "workflow is the workflow definition, an object" }]);
|
|
2667
2837
|
if (body.tools !== undefined && !(Array.isArray(body.tools) && body.tools.every((t) => typeof t === "string")))
|
|
2668
2838
|
throw invalid([{ field: "tools", reason: "wrong_type", message: "tools is a list of tool names" }]);
|
|
2669
|
-
const { workflowIssues } = await import("
|
|
2839
|
+
const { workflowIssues } = await import("./workflow-run.js");
|
|
2670
2840
|
const { issues, warnings } = await workflowIssues(body.workflow, body.tools);
|
|
2671
2841
|
// What a save refuses on this host (a model node's tool, a code node where none runs), and what it lacks yet.
|
|
2672
2842
|
if (!issues.length) {
|
|
@@ -2849,14 +3019,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2849
3019
|
return send(res, 200, withDefaults(settings.get()));
|
|
2850
3020
|
}
|
|
2851
3021
|
// A person's view and control of what an agent learned (learning-routes.ts). Every text cut of the host's secrets as
|
|
2852
|
-
// they are now
|
|
3022
|
+
// they are now and of the agent's own sign-in pointers, live and forgotten (agentPointers); a write as the
|
|
3023
|
+
// definition's: an archived agent's too.
|
|
2853
3024
|
case "getAgentLearning": {
|
|
2854
3025
|
await needAgent(id);
|
|
2855
3026
|
// The agent's learning view: its notes, skills, workflows and log from its learning folder; its run-fared counts, each
|
|
2856
3027
|
// note's runs (given it and that read it) and its impact over the one store (agentLearningOverStore), from each run's
|
|
2857
3028
|
// launch, journal and learning end.
|
|
2858
3029
|
const { counts, impact, notes } = await agentLearningOverStore(store, id);
|
|
2859
|
-
return send(res, 200, await agentLearning(data, id,
|
|
3030
|
+
return send(res, 200, await agentLearning(data, id, await learningShown(id), counts, impact, notes));
|
|
2860
3031
|
}
|
|
2861
3032
|
case "listLearningNotes":
|
|
2862
3033
|
case "listLearningLog":
|
|
@@ -2864,12 +3035,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2864
3035
|
if (found.name === "listLearningNotes") {
|
|
2865
3036
|
// The notes from the agent's learning folder, each with its runs over the one store (agentLearningOverStore's noteRuns).
|
|
2866
3037
|
const { notes } = await agentLearningOverStore(store, id);
|
|
2867
|
-
return send(res, 200, await learningNotes(data, id, url.searchParams,
|
|
3038
|
+
return send(res, 200, await learningNotes(data, id, url.searchParams, await learningShown(id), notes));
|
|
2868
3039
|
}
|
|
2869
|
-
return send(res, 200, await learningLog(data, id, url.searchParams,
|
|
3040
|
+
return send(res, 200, await learningLog(data, id, url.searchParams, await learningShown(id)));
|
|
2870
3041
|
case "readLearningFile":
|
|
2871
3042
|
await needAgent(id);
|
|
2872
|
-
return sendNote(res, 200, await readNote(data, id, second,
|
|
3043
|
+
return sendNote(res, 200, await readNote(data, id, second, await learningShown(id)));
|
|
2873
3044
|
case "writeLearningFile":
|
|
2874
3045
|
case "retireLearningFile":
|
|
2875
3046
|
case "approveLearningFile":
|
|
@@ -2877,18 +3048,30 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2877
3048
|
await needAgent(id);
|
|
2878
3049
|
const header = (name) => (typeof req.headers[name] === "string" ? req.headers[name] : undefined);
|
|
2879
3050
|
const body = found.name === "writeLearningFile" ? await noteBody(req, MAX_BODY) : undefined;
|
|
2880
|
-
|
|
3051
|
+
// What it refuses is what the reads cut: a note shown cut is never saved over the hidden text.
|
|
3052
|
+
const refuse = await learningValues(id);
|
|
3053
|
+
const written = await writeNote(data, id, second, { ifMatch: header("if-match"), ifNoneMatch: header("if-none-match"), body, refuse, approve: found.name === "approveLearningFile", restore: found.name === "restoreLearningFile", draftTools: () => learnedDraftToolsOf(id) });
|
|
2881
3054
|
// A name holding a secret (one the checks let by) is never echoed, not even as where the note is.
|
|
2882
|
-
const shown = secretsShown(
|
|
3055
|
+
const shown = secretsShown(refuse);
|
|
2883
3056
|
const located = written.status === 201 && shown.name(written.file) === written.file;
|
|
2884
3057
|
return sendNote(res, written.status, { ...written, text: shown.text(written.text) }, located ? { location: `/v2/agents/${encodeURIComponent(id)}/learning/files/${written.file}` } : {});
|
|
2885
3058
|
}
|
|
3059
|
+
case "promoteLearnedWorkflow": {
|
|
3060
|
+
// The source read once the body is in, as it is then: what promoteOf checks and what it copies are that one read.
|
|
3061
|
+
const body = await bodyOf(req);
|
|
3062
|
+
const source = await needAgent(id);
|
|
3063
|
+
const answer = await idempotent(req, `/agents/${id}/learning/workflows/${second}/promote`, body, async () => {
|
|
3064
|
+
const { entry, warnings } = await promoteOf(source, second, body);
|
|
3065
|
+
return { status: 201, body: { ...agentView(entry, linkOrigin(req), await agentExtra(entry)), warnings }, headers: { location: `/v2/agents/${entry.agent.id}`, etag: etagOf(entry) } };
|
|
3066
|
+
});
|
|
3067
|
+
return send(res, answer.status, answer.body, answer.headers);
|
|
3068
|
+
}
|
|
2886
3069
|
case "getRunLearning": {
|
|
2887
3070
|
const run = await needRun(id);
|
|
2888
3071
|
// The run's learning view over the store (learning-1's runLearningOverStore): its end, the notes it was given and its seed
|
|
2889
|
-
// from its launch, what it holds for the owner's OK as the store's run view reads it (
|
|
3072
|
+
// from its launch, what it holds for the owner's OK as the store's run view reads it (on its folder's main), as main.
|
|
2890
3073
|
// Cut by the run's one cut, and refused for a withheld run (run-learning-served.ts).
|
|
2891
|
-
return send(res, 200, await servedRunLearning({ serverSecrets, signIns }, store, run.id));
|
|
3074
|
+
return send(res, 200, await servedRunLearning({ serverSecrets, signIns, statuses }, store, run.id));
|
|
2892
3075
|
}
|
|
2893
3076
|
case "getRunLearningDiff": {
|
|
2894
3077
|
const run = await needRun(id);
|
|
@@ -2902,11 +3085,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2902
3085
|
case "saveWebhook": {
|
|
2903
3086
|
// Never through `idempotent`: its record would keep the answer, and the first one holds the secret.
|
|
2904
3087
|
// Its minted secret to the owner's session alone (trigger-secrets-shown.ts); the token gets its metadata and the words.
|
|
2905
|
-
const saved = webhooks.save(await bodyOf(req));
|
|
3088
|
+
const saved = await webhooks.save(await bodyOf(req));
|
|
2906
3089
|
return send(res, saved.created ? 201 : 200, webhookSaved(saved.view, saved.secret, mayHoldSecrets(req)));
|
|
2907
3090
|
}
|
|
2908
3091
|
case "deleteWebhook":
|
|
2909
|
-
webhooks.remove();
|
|
3092
|
+
await webhooks.remove();
|
|
2910
3093
|
return void res.writeHead(204, { "cache-control": "no-store" }).end();
|
|
2911
3094
|
case "testWebhook":
|
|
2912
3095
|
return send(res, 200, await webhooks.test());
|
|
@@ -3025,9 +3208,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3025
3208
|
// A request cut before its body was read (push-handler.ts readCapped): its socket goes once the answer is out.
|
|
3026
3209
|
if (error instanceof HookCut)
|
|
3027
3210
|
res.once("finish", () => req.socket.destroy());
|
|
3028
|
-
// A store still busy past a request's wait is home_busy, whichever read or
|
|
3029
|
-
|
|
3030
|
-
|
|
3211
|
+
// A store still busy past a request's wait, or a write still open at its deadline, is home_busy, whichever read or
|
|
3212
|
+
// write met it: the request may be sent again, never a 500 (agents.ts answerOf, as an MCP tool's call answers).
|
|
3213
|
+
const known = answerOf(error);
|
|
3214
|
+
if (logged(error))
|
|
3031
3215
|
process.stderr.write(`agentrun-serve: ${error?.stack ?? String(error)}\n`);
|
|
3032
3216
|
send(res, known.status, known.body(requestId), known.headers);
|
|
3033
3217
|
};
|
|
@@ -3058,7 +3242,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3058
3242
|
return void mcp(req, res).catch(fail);
|
|
3059
3243
|
if (raw === "/llms.txt")
|
|
3060
3244
|
return void answerLlms(req, res).catch(fail);
|
|
3061
|
-
if (answerPage(req, res, raw, { token,
|
|
3245
|
+
if (answerPage(req, res, raw, { token, authFailed, console: options.console, takesBytes, ...(owner ? { owner } : {}), ...(options.publicUrl ? { publicUrl: options.publicUrl } : {}) }))
|
|
3062
3246
|
return;
|
|
3063
3247
|
// Under --faux only: a faux desktop's live view, a page on this server's own address (faux-computers.ts viewPage), so
|
|
3064
3248
|
// a run's take-over has a viewer to open in the console's real-browser flows. Gone after the computer's release.
|
|
@@ -3197,8 +3381,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3197
3381
|
const heldReadAt = new Map();
|
|
3198
3382
|
const HELD_WAIT_REREAD_MS = 1_000;
|
|
3199
3383
|
const waitKinds = new Set(["question", "approval", "budget", "browser"]);
|
|
3200
|
-
/** The wait of a run its runner left parked (or let go of),
|
|
3201
|
-
*
|
|
3384
|
+
/** The wait of a run its runner left parked (or let go of), or holds in its claim, told once per ask: its marker the
|
|
3385
|
+
* ask's own (webhooks.ts waitMarkerOf), its kind the pending card's (a stop's when it waits on no card). */
|
|
3202
3386
|
const tellWait = async (row) => {
|
|
3203
3387
|
const seen = `${row.state}\n${row.epoch}\n${row.runner ?? ""}\n${row.summary ?? ""}`;
|
|
3204
3388
|
if (readWaits.get(row.id) === seen)
|
|
@@ -3207,13 +3391,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3207
3391
|
if (view?.status !== "input_required")
|
|
3208
3392
|
return void readWaits.set(row.id, seen);
|
|
3209
3393
|
const rows = (await timelineOverStore(store, row.id, viewDepsFor(ownOriginOf()))) ?? [];
|
|
3210
|
-
|
|
3394
|
+
// One marker per ask, so the held read and the let-go read of one ask agree, whatever row shows last.
|
|
3395
|
+
const marker = waitMarkerOf(rows, view.pending, view.state === "waiting", LEARNING_LABEL);
|
|
3211
3396
|
if (!marker)
|
|
3212
3397
|
return void readWaits.set(row.id, seen);
|
|
3213
3398
|
const card = view.pending?.kind;
|
|
3214
3399
|
const kind = view.state !== "waiting" ? "stopped" : typeof card === "string" && waitKinds.has(card) ? card : "question";
|
|
3215
3400
|
const notice = { run_id: row.id, agent_id: row.agentId, status: "input_required", title: typeof view.title === "string" ? view.title : "", pending: { kind } };
|
|
3216
|
-
if (webhooks.emit("run.needs_input", notice, marker) !== "unsaved")
|
|
3401
|
+
if ((await webhooks.emit("run.needs_input", notice, marker)) !== "unsaved")
|
|
3217
3402
|
readWaits.set(row.id, seen);
|
|
3218
3403
|
};
|
|
3219
3404
|
let openRuns = new Set();
|
|
@@ -3253,7 +3438,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3253
3438
|
heldReadAt.delete(id);
|
|
3254
3439
|
if (!now?.endedAt || toldEnds.get(id) === now.endedAt)
|
|
3255
3440
|
continue;
|
|
3256
|
-
if (webhooks.emit("run.ended", now.notice, now.endedAt) !== "unsaved")
|
|
3441
|
+
if ((await webhooks.emit("run.ended", now.notice, now.endedAt)) !== "unsaved")
|
|
3257
3442
|
toldEnds.set(id, now.endedAt);
|
|
3258
3443
|
}
|
|
3259
3444
|
openRuns = open;
|
|
@@ -3313,8 +3498,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3313
3498
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
3314
3499
|
await mcpStopped;
|
|
3315
3500
|
await githubStopped;
|
|
3501
|
+
// --faux-github's fake GitHub API, once nothing asks it anything.
|
|
3502
|
+
await fauxGitHub?.close();
|
|
3316
3503
|
// The store's EXCLUSIVE lock is the one-server lock: closing it releases it for the next server.
|
|
3317
3504
|
await store.close();
|
|
3505
|
+
dataLock.release();
|
|
3318
3506
|
seal.release();
|
|
3319
3507
|
}
|
|
3320
3508
|
return {
|