@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -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 +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- 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 +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- 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.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- 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/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -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 +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- 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/harness.d.ts +4 -3
- package/dist/harness.js +16 -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 +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- 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 +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -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 +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- 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 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- 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.js +118 -8
- 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.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -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 +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- 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 +56 -10
- 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-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- 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/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- 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 +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- 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/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- 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 +49 -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 +64 -20
- package/dist/store/store.d.ts +38 -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 +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- 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 +274 -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-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- 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 +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- 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.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -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/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- 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-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- 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 +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- 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-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- 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/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- 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/runner/beside.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
// A runner beside a server on the same data directory: the CLI start's server-and-runner, the `runner` subcommand and
|
|
2
2
|
// the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
|
|
3
|
+
import { maxRunsOf } from "../host.js";
|
|
4
|
+
import { durationMs } from "../print.js";
|
|
5
|
+
import { runnerCloseBoundMs } from "./runner.js";
|
|
6
|
+
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
7
|
+
export const DRAIN_TIMEOUT = "30s";
|
|
8
|
+
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
9
|
+
* number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
|
|
10
|
+
* memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
|
|
11
|
+
* before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
|
|
12
|
+
export function besideRunnerOptions(serve, env) {
|
|
13
|
+
const drainTimeout = serve.drainTimeout ?? DRAIN_TIMEOUT;
|
|
14
|
+
const drainMs = durationMs(drainTimeout);
|
|
15
|
+
if (drainMs === undefined)
|
|
16
|
+
throw new Error(`the drain timeout ${drainTimeout} is not a duration such as 8s`);
|
|
17
|
+
return { loops: maxRunsOf(env, serve.maxRuns), drainMs };
|
|
18
|
+
}
|
|
19
|
+
/** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
|
|
20
|
+
* and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
|
|
21
|
+
* the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
|
|
22
|
+
export function besideStopping(server, held, drainMs) {
|
|
23
|
+
return { runs: server.runs + held, boundMs: Math.max(server.boundMs, runnerCloseBoundMs(drainMs)) };
|
|
24
|
+
}
|
|
3
25
|
/** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
|
|
4
26
|
* its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
|
|
5
27
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
6
|
-
* caller hands its own: the template eval's in-process server, its faux's).
|
|
7
|
-
*
|
|
8
|
-
|
|
28
|
+
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
29
|
+
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
30
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
|
|
31
|
+
* closes its store. */
|
|
32
|
+
export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {}) {
|
|
9
33
|
const { startRunner } = await import("./runner.js");
|
|
10
34
|
const { dispatchRunner } = await import("./harness-loops.js");
|
|
11
35
|
const { routeOf } = await import("./model-route.js");
|
|
@@ -14,17 +38,35 @@ export async function runnerBeside(dataDir, { loops, env } = {}) {
|
|
|
14
38
|
// The server's store, the runner's one way in (main.ts openRunnerStore, store/open.ts): Postgres when this process's
|
|
15
39
|
// AGENTRUN_STORE_URL secret names one, else SQLite in the data directory; a schema it does not know is RunnerRefused.
|
|
16
40
|
const { store } = await openRunnerStore(dataDir, process.env, (message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`), undefined);
|
|
17
|
-
// The server's seal key (seal-key.ts)
|
|
18
|
-
// environment as it loads), else the one
|
|
19
|
-
// seals the live-viewer tokens, and there is no
|
|
41
|
+
// The server's seal key (seal-key.ts), booted the one way and checked against the store: the one handed over (read
|
|
42
|
+
// through secrets.js, which moves it out of the environment as it loads), else the one in the data directory. A runner
|
|
43
|
+
// never starts without it, nor with a key that is not the store's: it seals the live-viewer tokens, and there is no
|
|
44
|
+
// stand-in key.
|
|
20
45
|
const { bootSealKey } = await import("../seal-key.js");
|
|
21
|
-
|
|
46
|
+
let seal;
|
|
47
|
+
try {
|
|
48
|
+
seal = await bootSealKey(store, dataDir, { role: "runner" });
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
await store.close();
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
22
54
|
// The beside-runner sees the server's environment as a separate runner would (runEnv, not withoutFaux): so an API run on
|
|
23
55
|
// a --faux server reaches the faux gateway and its computers. The run's claim-time computer is composed once, the one way
|
|
24
|
-
// (workspace/computer-deps.ts computerDepsFrom), from that same environment
|
|
56
|
+
// (workspace/computer-deps.ts computerDepsFrom), from that same environment; a Docker computer's mounts by where this
|
|
57
|
+
// process's Docker has the data directory (box-paths.ts), read once.
|
|
25
58
|
const runs = env ?? runEnv(process.env);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
59
|
+
const { dockerPathsForRuns } = await import("../box-paths.js");
|
|
60
|
+
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
61
|
+
const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
|
|
62
|
+
const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
|
|
63
|
+
// It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
|
|
64
|
+
const { runnerMemory } = await import("./memory-claim.js");
|
|
65
|
+
const runner = startRunner({ store, createLoop, memory: runnerMemory(store), ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
66
|
+
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
67
|
+
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
68
|
+
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
69
|
+
const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
|
|
70
|
+
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
71
|
+
return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
|
|
30
72
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { LearnedWorkflow } from "../learning.js";
|
|
1
2
|
import type { RunLaunch } from "../run-launch.js";
|
|
2
3
|
import type { SealedKeys } from "../store/store.js";
|
|
3
|
-
import type { Revision } from "
|
|
4
|
+
import type { Revision } from "../agent-rows.js";
|
|
4
5
|
/** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
|
|
5
6
|
* environment (its own, with no server secret in it: those are the store's). */
|
|
6
7
|
export interface ClaimSecretsDeps {
|
|
@@ -15,6 +16,14 @@ export interface ClaimSecretsDeps {
|
|
|
15
16
|
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
16
17
|
* decision provider keys. A fresh object per claim, so no run's keys reach another's. */
|
|
17
18
|
export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
|
|
19
|
+
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
20
|
+
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
21
|
+
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
22
|
+
* run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
|
|
23
|
+
* lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
|
|
24
|
+
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
25
|
+
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
26
|
+
export declare function learnedDecisionKeys(deps: ClaimSecretsDeps, workflows: readonly Pick<LearnedWorkflow, "workflow">[], allowed: (provider: string) => boolean): Promise<Record<string, string>>;
|
|
18
27
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
19
28
|
export declare const MODEL_KEY_NAMES: readonly string[];
|
|
20
29
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// key), never from this process's environment or a pipe (the old per-run process read its own over a pipe; the runner is
|
|
3
3
|
// one process for many runs). Scoped to the run as the old per-run environment was: the keys its revision's tools unlock
|
|
4
4
|
// and its model needs (runs.ts keysFor/needsOf), and its decision provider keys (decisions.ts decisionKeysFor, Parallel's
|
|
5
|
-
// where a web tool resolves there), and no other
|
|
5
|
+
// where a web tool resolves there), and no other; an agentic run's learned workflows add the keys of the decision
|
|
6
|
+
// providers they name, read once the claim's seed lay chose them (learnedDecisionKeys). So a run that names no monid never gets the monid key, and two runs on
|
|
6
7
|
// one runner never see each other's keys: each claim reads its own, into its own environment. (MCP credentials are the
|
|
7
8
|
// other per-claim secret; they come through mcp-claim.ts, which already opens them from the store under the claim.)
|
|
8
|
-
import { decisionKeysFor } from "../decisions.js";
|
|
9
|
-
import { GATEWAY_KEY_ENV, PROVIDER_KEYS } from "../model.js";
|
|
10
|
-
import { keysFor, needsOf, RUN_SECRETS } from "../
|
|
9
|
+
import { decisionKeysFor, providersNamed } from "../decisions.js";
|
|
10
|
+
import { GATEWAY_KEY_ENV, PROVIDER_KEYS, workflowNodes } from "../model.js";
|
|
11
|
+
import { keysFor, needsOf, RUN_SECRETS } from "../run-secrets.js";
|
|
11
12
|
import { DECISION_KEYS, withoutSecrets } from "../secrets.js";
|
|
12
13
|
import { getSealedKey } from "../server-keys.js";
|
|
13
14
|
import { handsParallel } from "../tool-plane.js";
|
|
@@ -19,17 +20,7 @@ const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
|
|
|
19
20
|
* decision provider keys. A fresh object per claim, so no run's keys reach another's. */
|
|
20
21
|
export async function claimSecrets(deps, revision, launch) {
|
|
21
22
|
const base = withoutSecrets(deps.env ?? {});
|
|
22
|
-
|
|
23
|
-
// put on the environment its tools run under. The server process's own environment value wins over the store's by the same
|
|
24
|
-
// name (the secrets rule 4: env always overrides a pasted value), so a key set where the server starts is not shadowed by a
|
|
25
|
-
// stale one saved in the store.
|
|
26
|
-
const working = { ...base };
|
|
27
|
-
// A name present with no value (`-e NAME`, an empty optional secret) is not a key: the store's saved one stands.
|
|
28
|
-
for (const name of CANDIDATES) {
|
|
29
|
-
const value = deps.env?.[name] || (deps.sealKey ? await getSealedKey(deps.store, deps.sealKey, name) : undefined);
|
|
30
|
-
if (value !== undefined)
|
|
31
|
-
working[name] = value;
|
|
32
|
-
}
|
|
23
|
+
const working = await workingEnv(deps);
|
|
33
24
|
const needs = await needsOf(revision);
|
|
34
25
|
// An agentic run's model keys are its PINNED model's (the launch's, chosen at its start), the one its route sends, never
|
|
35
26
|
// the host's default now: a key saved since the run started (another provider's, now first) would otherwise be opened
|
|
@@ -44,6 +35,49 @@ export async function claimSecrets(deps, revision, launch) {
|
|
|
44
35
|
env[name] = value;
|
|
45
36
|
return env;
|
|
46
37
|
}
|
|
38
|
+
/** Every candidate secret in a working environment over the runner's base, read for one claim and scoped by its caller, so
|
|
39
|
+
* a key the run does not need is never put on the environment its tools run under. The server process's own environment
|
|
40
|
+
* value wins over the store's by the same name (the secrets rule 4: env always overrides a pasted value), so a key set
|
|
41
|
+
* where the server starts is not shadowed by a stale one saved in the store. */
|
|
42
|
+
async function workingEnv(deps) {
|
|
43
|
+
const working = { ...withoutSecrets(deps.env ?? {}) };
|
|
44
|
+
// A name present with no value (`-e NAME`, an empty optional secret) is not a key: the store's saved one stands.
|
|
45
|
+
for (const name of CANDIDATES) {
|
|
46
|
+
const value = deps.env?.[name] || (deps.sealKey ? await getSealedKey(deps.store, deps.sealKey, name) : undefined);
|
|
47
|
+
if (value !== undefined)
|
|
48
|
+
working[name] = value;
|
|
49
|
+
}
|
|
50
|
+
return working;
|
|
51
|
+
}
|
|
52
|
+
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
53
|
+
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
54
|
+
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
55
|
+
* run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
|
|
56
|
+
* lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
|
|
57
|
+
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
58
|
+
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
59
|
+
export async function learnedDecisionKeys(deps, workflows, allowed) {
|
|
60
|
+
if (!workflows.length)
|
|
61
|
+
return {};
|
|
62
|
+
const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
|
|
63
|
+
const named = new Set();
|
|
64
|
+
for (const { workflow } of workflows) {
|
|
65
|
+
let nodes;
|
|
66
|
+
try {
|
|
67
|
+
const doc = JSON.parse(workflow);
|
|
68
|
+
nodes = workflowNodes(doc, inspectWorkflow(doc));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
for (const id of providersNamed(nodes))
|
|
74
|
+
named.add(id);
|
|
75
|
+
}
|
|
76
|
+
const providers = [...named].filter((id) => allowed(id));
|
|
77
|
+
if (!providers.length)
|
|
78
|
+
return {};
|
|
79
|
+
return decisionKeysFor(await workingEnv(deps), { providers, parallelWeb: false });
|
|
80
|
+
}
|
|
47
81
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
48
82
|
export const MODEL_KEY_NAMES = [...new Set([...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV])];
|
|
49
83
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -7,6 +7,8 @@ export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./
|
|
|
7
7
|
/** What the runner hands the CLI spec builder: the same deps the pi spec takes (computerForClaim, computerDeps and
|
|
8
8
|
* makeArchilDisk are on AdapterSpecDeps, shared by both). One per runner. */
|
|
9
9
|
export type CliSpecDeps = AdapterSpecDeps;
|
|
10
|
+
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
11
|
+
export declare const cliRefusesKind: (kind: string) => string | undefined;
|
|
10
12
|
/**
|
|
11
13
|
* One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
|
|
12
14
|
*
|
|
@@ -19,6 +19,8 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
19
19
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
20
|
import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
21
21
|
import { thinkingFor } from "../adapters.js";
|
|
22
|
+
import { installDirOf, installingWords, installSettled } from "../harness-install.js";
|
|
23
|
+
import { HarnessUnavailable } from "../provider.js";
|
|
22
24
|
import { effortGuidance } from "../effort-guidance.js";
|
|
23
25
|
import { environmentLine } from "../environment.js";
|
|
24
26
|
import { harnessOf } from "../harness-table.js";
|
|
@@ -28,7 +30,7 @@ import { learningWorkspace } from "../learn/folder.js";
|
|
|
28
30
|
import { learningEndOfRun } from "./learning-end.js";
|
|
29
31
|
import { providerModels, runModels } from "../model.js";
|
|
30
32
|
import { firstMessage } from "../run-manifest.js";
|
|
31
|
-
import { learningStartOf } from "../run-launch.js";
|
|
33
|
+
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
32
34
|
import { readsFiles, systemOf } from "../skills.js";
|
|
33
35
|
import { DATA_ENV } from "../server-fs.js";
|
|
34
36
|
import { INPUTS_DIR, UPLOADS_DIR, Uploads } from "../uploads.js";
|
|
@@ -43,16 +45,19 @@ import { imageWaitWords } from "../workspace/computer-deps.js";
|
|
|
43
45
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
44
46
|
import { adapterRunGate, answersCut, buildToolHost, hostToolCtxOf, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, webHostTools, webToolNames } from "./adapter-run-spec.js";
|
|
45
47
|
import { signInReads } from "../sign-ins-store.js";
|
|
46
|
-
import { claimSecrets, withModelKeys } from "./claim-secrets.js";
|
|
48
|
+
import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
|
|
47
49
|
import { mcpForClaim } from "./mcp-run.js";
|
|
48
50
|
import { TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
49
51
|
import { resolveHarness } from "./adapters/index.js";
|
|
50
52
|
import { entriesOf } from "./loop.js";
|
|
51
|
-
import { runMetrics } from "./metrics.js";
|
|
53
|
+
import { bookedSpend, runMetrics } from "./metrics.js";
|
|
54
|
+
import { journalEntries } from "./journal-reader.js";
|
|
52
55
|
import { specBuilt } from "./spec-holds.js";
|
|
53
56
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
54
57
|
import { githubAppAccess } from "./github-app.js";
|
|
55
58
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
59
|
+
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
60
|
+
export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
|
|
56
61
|
/** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
|
|
57
62
|
* harness's own wire where its entry says its model is chosen there (a pin there is its own provider/model-id, never a
|
|
58
63
|
* gateway's), else as the run's usual models, a pin sent as pinned (modelAskOf). */
|
|
@@ -144,6 +149,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
144
149
|
if (!name || !entry?.facts || !entry.adapter || !runner)
|
|
145
150
|
throw new Error(`run ${claim.runId}: ${JSON.stringify(name)} is not a CLI harness this runner runs`);
|
|
146
151
|
const facts = entry.facts;
|
|
152
|
+
// The level the harness thinks at: the run's effort, else above its highest (codex stops at xhigh) its highest. The
|
|
153
|
+
// run's metrics name this level, the one it ran at, never a level the harness has not.
|
|
154
|
+
const thinking = launch.effort ? thinkingFor(facts, launch.effort) : undefined;
|
|
147
155
|
// The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
|
|
148
156
|
// on the claim's Archil disk (archil-claim.ts: its keys from the store's sealed rows, under the runner's seal key, in
|
|
149
157
|
// this claim's memory only, dropped at the release); else Mode 1, the run's local folder.
|
|
@@ -176,7 +184,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
176
184
|
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
|
|
177
185
|
// revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
|
|
178
186
|
// run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does.
|
|
179
|
-
|
|
187
|
+
// A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
|
|
188
|
+
// whose computer is a browser is refused in words at its claim, before anything is made.
|
|
189
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)) } : {}) });
|
|
180
190
|
holds.hold({ computer });
|
|
181
191
|
// The CLI works in the run's scratch folder on this machine (its working directory, swept at the run's end), its own
|
|
182
192
|
// files (home, state) in a private folder inside it, never on the run's disk. The scratch is an alias of the run's
|
|
@@ -195,19 +205,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
195
205
|
// own skills through systemOf with the harness's own check (a harness that loads skills itself keeps in the prompt only
|
|
196
206
|
// those it would refuse, and is handed the rest), then the effort guidance.
|
|
197
207
|
const start = learningStartOf(launch);
|
|
198
|
-
|
|
208
|
+
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
209
|
+
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
199
210
|
const check = await entry.skillCheck?.();
|
|
200
211
|
// The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts).
|
|
201
212
|
await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: launch.computer?.kind });
|
|
202
213
|
// A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
|
|
203
214
|
// the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
|
|
204
|
-
const seedLaid = start
|
|
215
|
+
const seedLaid = start && !seedFailed(start)
|
|
205
216
|
? await layLearningSeed({
|
|
206
217
|
work: ws.workspace,
|
|
207
218
|
seed: start.seed,
|
|
208
219
|
folder: () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil })),
|
|
209
220
|
own: Object.keys(revisionRow.skills ?? {}),
|
|
210
|
-
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data))),
|
|
221
|
+
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
|
|
211
222
|
log,
|
|
212
223
|
})
|
|
213
224
|
: undefined;
|
|
@@ -225,6 +236,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
225
236
|
holdClaimed(redact, claimed);
|
|
226
237
|
const env = cliRunEnv(deps.env, deps.data, claimed);
|
|
227
238
|
const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
|
|
239
|
+
// A harness that installs on first use, whose install is running now (the server started it at an agent's save, or a
|
|
240
|
+
// run's start): the claim waits for it, bounded by the install's own limit, saying so on the run's timeline, and runs on
|
|
241
|
+
// it. A stop of the run ends the wait at once (the install goes on). An install that failed fails the run in its own
|
|
242
|
+
// words; with none running, the adapter says what is missing, as before.
|
|
243
|
+
if (entry.installs && entry.pins) {
|
|
244
|
+
const installs = entry.installs;
|
|
245
|
+
const waitOn = run.stopped ?? run.signal;
|
|
246
|
+
const settled = await (deps.installSettled ?? installSettled)(installs, installDirOf(deps.data, name), await entry.pins(), { ...(waitOn ? { signal: waitOn } : {}), onWait: () => run.phase?.(installingWords(installs.label)) });
|
|
247
|
+
if (typeof settled === "object")
|
|
248
|
+
throw new HarnessUnavailable(settled.failed, "install");
|
|
249
|
+
}
|
|
228
250
|
const built = await entry.adapter(env, { model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(native.length ? { skills: native } : {}) });
|
|
229
251
|
// The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
|
|
230
252
|
// every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
|
|
@@ -260,14 +282,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
260
282
|
? undefined
|
|
261
283
|
: {
|
|
262
284
|
capUsd,
|
|
263
|
-
park
|
|
285
|
+
// A park names the cap the loop holds the run to then (a raise's, else this one).
|
|
286
|
+
park: (refusal, capNow) => parkOf(refusal, capNow),
|
|
264
287
|
checkRaise,
|
|
265
288
|
followUpOf: (raised) => followUpOf(raised),
|
|
266
289
|
};
|
|
267
290
|
// The gate before a call's intent, the same as the pi spec: the revision's tool settings over the store's, read from the
|
|
268
|
-
// store at each decide
|
|
269
|
-
//
|
|
270
|
-
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace);
|
|
291
|
+
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
292
|
+
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
293
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
|
|
271
294
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
272
295
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
273
296
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -294,6 +317,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
294
317
|
if (webNames.length || learns) {
|
|
295
318
|
// The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
|
|
296
319
|
const toolEnv = { ...claimed };
|
|
320
|
+
// The decision keys its learned workflows' typed questions need, as the pi spec reads them (claim-secrets.ts
|
|
321
|
+
// learnedDecisionKeys): onto this copy alone, never the CLI's own environment or its model's (cliRunEnv, above), and
|
|
322
|
+
// held by the redactors as the claim's keys are.
|
|
323
|
+
if (learns) {
|
|
324
|
+
const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
|
|
325
|
+
for (const redact of new Set([held, cut]))
|
|
326
|
+
holdClaimed(redact, learnedKeys);
|
|
327
|
+
Object.assign(toolEnv, learnedKeys);
|
|
328
|
+
}
|
|
297
329
|
handedKeys = runnerSecrets(toolEnv);
|
|
298
330
|
// The run's resolved tool plane (its web tools' providers), as the pi spec hands it its web tools.
|
|
299
331
|
delete toolEnv[TOOL_PLANE_ENV];
|
|
@@ -304,8 +336,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
304
336
|
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held });
|
|
305
337
|
webTools = await webHostTools(host, granted, ctx);
|
|
306
338
|
}
|
|
307
|
-
if (learns)
|
|
308
|
-
|
|
339
|
+
if (learns) {
|
|
340
|
+
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
|
|
341
|
+
// own MCP as the loop wraps it.
|
|
342
|
+
gate.learn(workflows);
|
|
343
|
+
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, ...(mcp ? { mcp } : {}) });
|
|
344
|
+
}
|
|
309
345
|
}
|
|
310
346
|
const session = {
|
|
311
347
|
key: `run:${claim.runId}`,
|
|
@@ -313,9 +349,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
313
349
|
system: [environmentLine(), instructions, guidance].filter((line) => Boolean(line)),
|
|
314
350
|
// The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
|
|
315
351
|
// redactor, as pi's do.
|
|
316
|
-
tools: [...tools.hostTools(withKindTools(granted, tools),
|
|
352
|
+
tools: [...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))],
|
|
317
353
|
context: "fresh",
|
|
318
|
-
...(
|
|
354
|
+
...(thinking ? { thinking } : {}),
|
|
319
355
|
};
|
|
320
356
|
const content = isObject(launch.input) && typeof launch.input.content === "string" ? launch.input.content : "";
|
|
321
357
|
const input = await firstMessage(content, ws.workspace);
|
|
@@ -354,10 +390,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
354
390
|
...(life ? { lifecycle: life } : {}),
|
|
355
391
|
agentId: runRow.agentId,
|
|
356
392
|
workRoot: root,
|
|
357
|
-
// The end's metrics
|
|
393
|
+
// The end's metrics from the run's record; a CLI run's carry its model. Its cost is its booking's: the harness's own
|
|
394
|
+
// record carries no per-request cost, so its model requests are counted at what the run's model proxy booked them at
|
|
395
|
+
// (metrics.ts bookedSpend over every session of its journal), as a pi run's are at its answers' costs.
|
|
358
396
|
endPatch: async () => {
|
|
359
397
|
const entries = await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context);
|
|
360
|
-
const { metrics
|
|
398
|
+
const { metrics } = runMetrics(entries, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}` });
|
|
399
|
+
// Its model requests and its decisions (a learned workflow's) at what they were booked at (bookedSpend).
|
|
400
|
+
const all = (await journalEntries(deps.journal(claim), context));
|
|
401
|
+
const model = bookedSpend(all, "model").usd;
|
|
402
|
+
const decisions = bookedSpend(all, "decisions").usd;
|
|
403
|
+
const costUsd = model === null || decisions === null ? null : model + decisions;
|
|
361
404
|
// Its paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own
|
|
362
405
|
// session, are the run's cost too, as the pi spec's.
|
|
363
406
|
const paid = run.ledger?.paid ? run.ledger.paid.spentUsd() : 0;
|
package/dist/runner/commands.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Commands as rows (design: "Commands from the console are rows, not files or doors"). The server inserts one through
|
|
2
2
|
// sendCommand; a runner reads them with store.commands(run, after) and hands each to the run's loop. A command's
|
|
3
3
|
// taken_at is set once: by the loop's journal commit that applies it, or by the runner's refusal with a reason.
|
|
4
|
-
import { originOf } from "
|
|
4
|
+
import { originOf } from "../timeline/index.js";
|
|
5
5
|
/** stop and cancel both end the run, stopped: a cancel's end says it was cancelled, as main's cancel ends a run for good.
|
|
6
6
|
* browser_hand_back is a person's answer to the agent's browser hand-over (runner/hand-back.ts). computer_take_over and
|
|
7
7
|
* computer_hand_back are a person's turn with the run's desktop or phone (computer-commands.ts, runner/computer-journal.ts).
|
|
@@ -23,11 +23,24 @@ export declare const isComputerCommand: (command: Pick<Command, "kind">) => bool
|
|
|
23
23
|
/** The journal's side of run `runId`'s hold, for the pass whose Harness `commit` writes root entries (in one commit, in
|
|
24
24
|
* order). `now` is the clock the up entry is stamped with. */
|
|
25
25
|
export declare function journalHold(runId: string, computer: RunComputerHold, commit: (entries: readonly RootEntry[]) => Promise<void>, now?: () => number): {
|
|
26
|
-
/** The run's computer is up for this pass: the server shows it live, the agent driving.
|
|
27
|
-
|
|
26
|
+
/** The run's computer is up for this pass: the server shows it live, the agent driving. `prior`, the run's root
|
|
27
|
+
* entries before this pass: a take they still hold in force was on the computer of an earlier claim, whose runner
|
|
28
|
+
* lost the run (a crash, a lapsed lease: its own end of the take, if it wrote one, was refused by the fence) and
|
|
29
|
+
* whose computer this claim's start let go (releaseOlder deletes a lower epoch's computers). That take ends here,
|
|
30
|
+
* `released`, once, with its row when it had reached the person, so they read why the desktop is the agent's again.
|
|
31
|
+
* Only a hold that has had no take yet (a new claim's computer) ends one so: a restart within the claim keeps its own. */
|
|
32
|
+
up: (prior?: readonly {
|
|
33
|
+
readonly kind: string;
|
|
34
|
+
readonly data?: unknown;
|
|
35
|
+
}[]) => Promise<void>;
|
|
28
36
|
/** Applies a take-over or hand-back row to the hold: `taken` when it changed the hold (the change's commit takes the
|
|
29
37
|
* row: its entries carry the row's id as `by`), else refused in words. */
|
|
30
38
|
apply(command: Command): CommandOutcome;
|
|
39
|
+
/** The run's end (#2134). From here nothing new is taken (hold.finish), so no take begins after this wait and is cut
|
|
40
|
+
* by the release. While a person holds the computer, the Timeline says the run waits for the hand-back, and this
|
|
41
|
+
* resolves once the agent drives again (a hand-back, the hold's idle bound, the viewer gone) or `cut` settles first
|
|
42
|
+
* (a stop, a lost claim). With the agent driving, it resolves at once and writes nothing. */
|
|
43
|
+
heldAtEnd(cut: Promise<unknown>): Promise<void>;
|
|
31
44
|
/** Whether `data`, a computer entry's, is the change row `id` made: the commit that writes it takes the row. */
|
|
32
45
|
madeBy: (data: Record<string, unknown>, id: number) => boolean;
|
|
33
46
|
/** Every commit asked for so far is done. */
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
//
|
|
9
9
|
// onComputerHold is the change signal for whoever else in the runner's process shows the hold (tl-browser's run-side
|
|
10
10
|
// viewer and its bar): it fires after each computer.hold change entry is committed, with that change's Timeline words.
|
|
11
|
-
import { HOST_PHASE } from "
|
|
12
|
-
import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, holdWords, takeEndedWords, } from "../computer-commands.js";
|
|
11
|
+
import { HOST_PHASE } from "../timeline/index.js";
|
|
12
|
+
import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, holdIn, holdWords, takeEndedWords, } from "../computer-commands.js";
|
|
13
13
|
const listeners = new Map();
|
|
14
14
|
/** Calls `listener` after each change of run `runId`'s hold is committed to its journal, in order, in this process.
|
|
15
15
|
* Returns the unsubscribe. */
|
|
@@ -84,8 +84,19 @@ export function journalHold(runId, computer, commit, now = Date.now) {
|
|
|
84
84
|
void write(entries).then(() => change && signal(runId, change), () => undefined);
|
|
85
85
|
});
|
|
86
86
|
return {
|
|
87
|
-
/** The run's computer is up for this pass: the server shows it live, the agent driving.
|
|
88
|
-
|
|
87
|
+
/** The run's computer is up for this pass: the server shows it live, the agent driving. `prior`, the run's root
|
|
88
|
+
* entries before this pass: a take they still hold in force was on the computer of an earlier claim, whose runner
|
|
89
|
+
* lost the run (a crash, a lapsed lease: its own end of the take, if it wrote one, was refused by the fence) and
|
|
90
|
+
* whose computer this claim's start let go (releaseOlder deletes a lower epoch's computers). That take ends here,
|
|
91
|
+
* `released`, once, with its row when it had reached the person, so they read why the desktop is the agent's again.
|
|
92
|
+
* Only a hold that has had no take yet (a new claim's computer) ends one so: a restart within the claim keeps its own. */
|
|
93
|
+
up: async (prior = []) => {
|
|
94
|
+
const before = holdIn(prior.map((entry) => ({ kind: entry.kind, data: entry.data })));
|
|
95
|
+
if (before.up && before.state !== "agent" && before.take !== undefined && hold.epoch() === 0) {
|
|
96
|
+
const at = now();
|
|
97
|
+
const ended = { kind: COMPUTER_HOLD_KIND, data: { state: "agent", take: before.take, computer: kind, at, ended: "released" } };
|
|
98
|
+
await write(before.state === "person" ? [ended, phase(words.ended.released, at)] : [ended]);
|
|
99
|
+
}
|
|
89
100
|
const at = now();
|
|
90
101
|
const take = hold.current();
|
|
91
102
|
// A pass that starts while a take is in force (a restart within the claim) says so after the up entry.
|
|
@@ -99,7 +110,9 @@ export function journalHold(runId, computer, commit, now = Date.now) {
|
|
|
99
110
|
apply(command) {
|
|
100
111
|
const body = (command.body ?? {});
|
|
101
112
|
if (command.kind === COMPUTER_TAKE_OVER) {
|
|
102
|
-
|
|
113
|
+
if (hold.take({ by: command.id }))
|
|
114
|
+
return { taken: true };
|
|
115
|
+
return { refused: hold.finishing() ? `The agent is done and the run is ending, so its ${kind} can't be taken over now.` : `The ${kind} is already taken over, or not up now.` };
|
|
103
116
|
}
|
|
104
117
|
if (typeof body.ask === "string") {
|
|
105
118
|
const outcome = body.outcome === "cancelled" ? "cancelled" : "done";
|
|
@@ -110,6 +123,29 @@ export function journalHold(runId, computer, commit, now = Date.now) {
|
|
|
110
123
|
return { refused: takeEndedWords(kind, "given") };
|
|
111
124
|
return hold.give("given", { by: command.id }) ? { taken: true } : { refused: takeEndedWords(kind, "given") };
|
|
112
125
|
},
|
|
126
|
+
/** The run's end (#2134). From here nothing new is taken (hold.finish), so no take begins after this wait and is cut
|
|
127
|
+
* by the release. While a person holds the computer, the Timeline says the run waits for the hand-back, and this
|
|
128
|
+
* resolves once the agent drives again (a hand-back, the hold's idle bound, the viewer gone) or `cut` settles first
|
|
129
|
+
* (a stop, a lost claim). With the agent driving, it resolves at once and writes nothing. */
|
|
130
|
+
async heldAtEnd(cut) {
|
|
131
|
+
hold.finish();
|
|
132
|
+
let off = () => { };
|
|
133
|
+
const back = new Promise((resolve) => {
|
|
134
|
+
off = hold.on(() => void (hold.state() === "agent" && resolve()));
|
|
135
|
+
if (hold.state() === "agent")
|
|
136
|
+
resolve();
|
|
137
|
+
});
|
|
138
|
+
try {
|
|
139
|
+
if (hold.state() === "agent")
|
|
140
|
+
return;
|
|
141
|
+
// A row the journal refuses (a lost claim's fence) is the cut's to answer, not this wait's.
|
|
142
|
+
await write([phase(words.ending, now())]).catch(() => undefined);
|
|
143
|
+
await Promise.race([back, cut]);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
off();
|
|
147
|
+
}
|
|
148
|
+
},
|
|
113
149
|
/** Whether `data`, a computer entry's, is the change row `id` made: the commit that writes it takes the row. */
|
|
114
150
|
madeBy: (data, id) => data.by === id,
|
|
115
151
|
/** Every commit asked for so far is done. */
|