@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
|
@@ -13,27 +13,28 @@
|
|
|
13
13
|
// Shared with the pi spec: the run's Workspace and its uploaded files, a sandbox run's computer, the kernel registry's
|
|
14
14
|
// hands on them (runTools), the gate from the store's tool settings, the system prompt (environment line, instructions
|
|
15
15
|
// with what the agent learned and its skills, effort guidance), the first message, the end's metrics and the release.
|
|
16
|
-
import { mkdir } from "node:fs/promises";
|
|
16
|
+
import { mkdir, rm, rmdir } from "node:fs/promises";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
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
|
-
import {
|
|
21
|
+
import { noNewPrivsPrefix } from "@parcha/pi-durable-disk/internals";
|
|
22
|
+
import { confineOf, thinkingFor } from "../adapters.js";
|
|
22
23
|
import { installDirOf, installingWords, installSettled } from "../harness-install.js";
|
|
23
24
|
import { HarnessUnavailable } from "../provider.js";
|
|
24
25
|
import { effortGuidance } from "../effort-guidance.js";
|
|
25
26
|
import { environmentLine } from "../environment.js";
|
|
26
27
|
import { harnessOf } from "../harness-table.js";
|
|
27
28
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
28
|
-
import { layLearningSeed } from "./learning-seed.js";
|
|
29
|
+
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
29
30
|
import { learningWorkspace } from "../learn/folder.js";
|
|
30
31
|
import { learningEndOfRun } from "./learning-end.js";
|
|
31
32
|
import { providerModels, runModels } from "../model.js";
|
|
32
33
|
import { firstMessage } from "../run-manifest.js";
|
|
33
|
-
import { learningStartOf } from "../run-launch.js";
|
|
34
|
+
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
34
35
|
import { readsFiles, systemOf } from "../skills.js";
|
|
35
36
|
import { DATA_ENV } from "../server-fs.js";
|
|
36
|
-
import {
|
|
37
|
+
import { copyRunFiles } from "../uploads.js";
|
|
37
38
|
import { isObject } from "../validate.js";
|
|
38
39
|
import { runFolder, scratchFolder } from "../workspace/paths.js";
|
|
39
40
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
@@ -43,18 +44,23 @@ import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
|
43
44
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
44
45
|
import { imageWaitWords } from "../workspace/computer-deps.js";
|
|
45
46
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
46
|
-
import { adapterRunGate, answersCut, buildToolHost, hostToolCtxOf, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, webHostTools, webToolNames } from "./adapter-run-spec.js";
|
|
47
|
+
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools, webToolNames } from "./adapter-run-spec.js";
|
|
48
|
+
import { openTierProxies } from "./adapters/pi.js";
|
|
47
49
|
import { signInReads } from "../sign-ins-store.js";
|
|
48
|
-
import { claimSecrets, withModelKeys } from "./claim-secrets.js";
|
|
50
|
+
import { claimSecrets, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
49
51
|
import { mcpForClaim } from "./mcp-run.js";
|
|
50
52
|
import { TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
51
53
|
import { resolveHarness } from "./adapters/index.js";
|
|
52
54
|
import { entriesOf } from "./loop.js";
|
|
53
|
-
import {
|
|
55
|
+
import { bookedSpend, cliRunMetrics } from "./metrics.js";
|
|
56
|
+
import { journalEntries } from "./journal-reader.js";
|
|
54
57
|
import { specBuilt } from "./spec-holds.js";
|
|
55
58
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
56
59
|
import { githubAppAccess } from "./github-app.js";
|
|
57
60
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
61
|
+
import { bashPolicyOf } from "../bash-read-only.js";
|
|
62
|
+
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
63
|
+
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;
|
|
58
64
|
/** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
|
|
59
65
|
* harness's own wire where its entry says its model is chosen there (a pin there is its own provider/model-id, never a
|
|
60
66
|
* gateway's), else as the run's usual models, a pin sent as pinned (modelAskOf). */
|
|
@@ -99,6 +105,22 @@ function cliRunEnv(env, data, claimed = {}) {
|
|
|
99
105
|
Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
|
|
100
106
|
return out;
|
|
101
107
|
}
|
|
108
|
+
/** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
|
|
109
|
+
* laid things in since (a follow-up's) stays, with what is in it. */
|
|
110
|
+
export async function sweepScratch(dir, parents) {
|
|
111
|
+
await rm(dir, { recursive: true, force: true });
|
|
112
|
+
for (const parent of parents) {
|
|
113
|
+
try {
|
|
114
|
+
await rmdir(parent);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
const code = error.code;
|
|
118
|
+
if (code === "ENOTEMPTY" || code === "EEXIST" || code === "ENOENT")
|
|
119
|
+
return;
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
102
124
|
/**
|
|
103
125
|
* One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
|
|
104
126
|
*
|
|
@@ -134,7 +156,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
134
156
|
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
|
|
135
157
|
// credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
|
|
136
158
|
// First, before the session opens: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its words.
|
|
137
|
-
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, deps.githubApi ? { api: deps.githubApi } : {}),
|
|
159
|
+
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold: (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
|
|
160
|
+
redact.hold(values); } }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
|
|
138
161
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
139
162
|
holds.hold({ passed: mcp });
|
|
140
163
|
// The harness: the launch's, else the revision's. Its table entry (facts, model choice, adapter, skill check), read from
|
|
@@ -146,6 +169,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
146
169
|
if (!name || !entry?.facts || !entry.adapter || !runner)
|
|
147
170
|
throw new Error(`run ${claim.runId}: ${JSON.stringify(name)} is not a CLI harness this runner runs`);
|
|
148
171
|
const facts = entry.facts;
|
|
172
|
+
// The level the harness thinks at: the run's effort, else above its highest (codex stops at xhigh) its highest. The
|
|
173
|
+
// run's metrics name this level, the one it ran at, never a level the harness has not.
|
|
174
|
+
const thinking = launch.effort ? thinkingFor(facts, launch.effort) : undefined;
|
|
149
175
|
// The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
|
|
150
176
|
// on the claim's Archil disk (archil-claim.ts: its keys from the store's sealed rows, under the runner's seal key, in
|
|
151
177
|
// this claim's memory only, dropped at the release); else Mode 1, the run's local folder.
|
|
@@ -166,30 +192,40 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
166
192
|
? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
|
|
167
193
|
: await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
|
|
168
194
|
holds.hold({ ws });
|
|
169
|
-
if (launch.files?.length)
|
|
170
|
-
|
|
171
|
-
if (!copied) {
|
|
172
|
-
const uploads = new Uploads(join(deps.data, UPLOADS_DIR));
|
|
173
|
-
await uploads.copyInto(ws.workspace, await uploads.readyFiles(launch.files));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
195
|
+
if (launch.files?.length)
|
|
196
|
+
await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
|
|
176
197
|
// The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
|
|
177
198
|
// It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
|
|
178
199
|
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,
|
|
179
200
|
// revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
|
|
180
201
|
// run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does.
|
|
181
|
-
|
|
202
|
+
// A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
|
|
203
|
+
// whose computer is a browser is refused in words at its claim, before anything is made.
|
|
204
|
+
{ ...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)) } : {}) });
|
|
182
205
|
holds.hold({ computer });
|
|
183
|
-
// The CLI works in the run's scratch folder on this machine (its working directory,
|
|
184
|
-
//
|
|
185
|
-
// folder for the run's file tools: a path the CLI builds from its working directory lands in the run's folder, and
|
|
186
|
-
// other absolute path is refused (workspace/paths.ts portPath).
|
|
206
|
+
// The CLI works in the run's scratch folder on this machine (its working directory), its own files (home, state, the
|
|
207
|
+
// skills laid for it) in this claim's private folder inside it, never on the run's disk. The scratch is an alias of the
|
|
208
|
+
// run's folder for the run's file tools: a path the CLI builds from its working directory lands in the run's folder, and
|
|
209
|
+
// any other absolute path is refused (workspace/paths.ts portPath).
|
|
210
|
+
// The private folder is swept at the spec's release, the claim's end, then the scratch folder if nothing else is in it:
|
|
211
|
+
// the next claim, here or on another runner, lays its own, its harness's session coming back from the run's journal.
|
|
212
|
+
// Its own per claim (by the claim's epoch), so a run reopened while this claim still lets go (its release follows the
|
|
213
|
+
// run's end commit) never has the next claim's folder swept from under it.
|
|
187
214
|
const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
|
|
188
|
-
const
|
|
189
|
-
|
|
215
|
+
const harnesses = join(scratch, "harness");
|
|
216
|
+
const dir = join(harnesses, String(claim.epoch));
|
|
217
|
+
holds.hold({ scratch: { sweep: () => sweepScratch(dir, [harnesses, scratch]) } });
|
|
218
|
+
// Made again once if a parent went as it was made (the last claim's sweep removing the then empty scratch folder).
|
|
219
|
+
await mkdir(dir, { recursive: true, mode: 0o700 }).catch(async (error) => {
|
|
220
|
+
if (error.code !== "ENOENT")
|
|
221
|
+
throw error;
|
|
222
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
223
|
+
});
|
|
190
224
|
// The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
|
|
191
225
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
192
|
-
|
|
226
|
+
// Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv), as the pi spec does.
|
|
227
|
+
const bashPolicy = bashPolicyOf(body.toolSettings);
|
|
228
|
+
const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }) });
|
|
193
229
|
holds.hold({ tools });
|
|
194
230
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
195
231
|
// The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
|
|
@@ -197,19 +233,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
197
233
|
// own skills through systemOf with the harness's own check (a harness that loads skills itself keeps in the prompt only
|
|
198
234
|
// those it would refuse, and is handed the rest), then the effort guidance.
|
|
199
235
|
const start = learningStartOf(launch);
|
|
200
|
-
|
|
236
|
+
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
237
|
+
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
201
238
|
const check = await entry.skillCheck?.();
|
|
202
239
|
// The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts).
|
|
203
240
|
await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: launch.computer?.kind });
|
|
204
241
|
// A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
|
|
205
242
|
// the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
|
|
206
|
-
const seedLaid = start
|
|
243
|
+
const seedLaid = start && !seedFailed(start)
|
|
207
244
|
? await layLearningSeed({
|
|
208
245
|
work: ws.workspace,
|
|
209
246
|
seed: start.seed,
|
|
210
247
|
folder: () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil })),
|
|
211
248
|
own: Object.keys(revisionRow.skills ?? {}),
|
|
212
|
-
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data))),
|
|
249
|
+
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
|
|
213
250
|
log,
|
|
214
251
|
})
|
|
215
252
|
: undefined;
|
|
@@ -238,20 +275,50 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
238
275
|
if (typeof settled === "object")
|
|
239
276
|
throw new HarnessUnavailable(settled.failed, "install");
|
|
240
277
|
}
|
|
241
|
-
|
|
278
|
+
// The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
|
|
279
|
+
// (pi-durable-disk's noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
|
|
280
|
+
// or a command it runs reaches grants nothing; none on macOS. Where setpriv is not usable the run is refused, in pi's words.
|
|
281
|
+
const confine = confineOf(noNewPrivsPrefix());
|
|
282
|
+
const built = await entry.adapter(env, { model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}) });
|
|
242
283
|
// The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
|
|
243
284
|
// every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
|
|
244
285
|
// the CLI's own error names the harness first, as main words it (harness-app.ts: `<harness>: <error>`), so the run's
|
|
245
286
|
// error and its Timeline row say which CLI said it.
|
|
287
|
+
// The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
|
|
288
|
+
// lay chose the workflows, below): each on a proxy of its own beside the CLI session's (openTierProxies, pi's), on the
|
|
289
|
+
// session's booking, reached through the session's port with a `tier`. The CLI never sees them.
|
|
290
|
+
const tierRoutes = new Map();
|
|
246
291
|
const adapter = {
|
|
247
292
|
...built,
|
|
248
293
|
open: async (spec, io) => {
|
|
249
294
|
const session = await built.open(spec, { ...io, dir, cwd: scratch });
|
|
295
|
+
let tiers;
|
|
296
|
+
try {
|
|
297
|
+
tiers = await openTierProxies(tierRoutes, io.models, cut);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
await session.close().catch(() => undefined);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
io.signal.addEventListener("abort", () => void tiers.close(), { once: true });
|
|
250
304
|
const turnEnd = session.turnEnd.bind(session);
|
|
251
|
-
|
|
305
|
+
const close = session.close.bind(session);
|
|
306
|
+
const port = session.port?.bind(session);
|
|
307
|
+
return Object.assign(session, {
|
|
308
|
+
turnEnd: async () => {
|
|
252
309
|
const end = await turnEnd();
|
|
253
310
|
return end.error ? { ...end, error: `${name}: ${end.error}` } : end;
|
|
254
|
-
}
|
|
311
|
+
},
|
|
312
|
+
close: async () => {
|
|
313
|
+
await close();
|
|
314
|
+
await tiers.close();
|
|
315
|
+
},
|
|
316
|
+
// The session's port; with a `tier`, that tier's proxy, while the session's own port is up (none once closed).
|
|
317
|
+
port: (label, tier) => {
|
|
318
|
+
const own = port?.(label);
|
|
319
|
+
return tier === undefined || own === undefined ? own : tiers.port(label, tier);
|
|
320
|
+
},
|
|
321
|
+
});
|
|
255
322
|
},
|
|
256
323
|
};
|
|
257
324
|
// The run's cap (its launch's maxCostUsd): the kernel's check before each paid request, at the catalog price of the
|
|
@@ -265,8 +332,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
265
332
|
// kernel runCap from these over the run's own sessions; the spec carries no beforeRequest of its own.
|
|
266
333
|
const runCap = {
|
|
267
334
|
capUsd: () => launch.maxCostUsd,
|
|
268
|
-
// One model per CLI session: every request it sends is the run's model, whatever id its provider names it by.
|
|
269
|
-
|
|
335
|
+
// One model per CLI session: every request it sends is the run's model, whatever id its provider names it by. A
|
|
336
|
+
// learned node's request on a tier's proxy names its tier (ModelRequest.route) and is priced as that route books it,
|
|
337
|
+
// even under an id the run's model shares.
|
|
338
|
+
modelOf: (id, by) => {
|
|
339
|
+
if (by === undefined)
|
|
340
|
+
return capModel;
|
|
341
|
+
const tierRoute = tierRoutes.get(by);
|
|
342
|
+
return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
|
|
343
|
+
},
|
|
270
344
|
...(launch.capMode === "strict" ? { mode: "strict" } : {}),
|
|
271
345
|
};
|
|
272
346
|
const cap = capUsd === undefined
|
|
@@ -279,9 +353,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
279
353
|
followUpOf: (raised) => followUpOf(raised),
|
|
280
354
|
};
|
|
281
355
|
// 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
|
|
282
|
-
// store at each decide
|
|
283
|
-
//
|
|
284
|
-
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace);
|
|
356
|
+
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
357
|
+
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
358
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
|
|
285
359
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
286
360
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
287
361
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -308,6 +382,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
308
382
|
if (webNames.length || learns) {
|
|
309
383
|
// The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
|
|
310
384
|
const toolEnv = { ...claimed };
|
|
385
|
+
// The decision keys its learned workflows' typed questions need, as the pi spec reads them (claim-secrets.ts
|
|
386
|
+
// learnedDecisionKeys): onto this copy alone, never the CLI's own environment or its model's (cliRunEnv, above), and
|
|
387
|
+
// held by the redactors as the claim's keys are.
|
|
388
|
+
if (learns) {
|
|
389
|
+
const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
|
|
390
|
+
for (const redact of new Set([held, cut]))
|
|
391
|
+
holdClaimed(redact, learnedKeys);
|
|
392
|
+
Object.assign(toolEnv, learnedKeys);
|
|
393
|
+
}
|
|
311
394
|
handedKeys = runnerSecrets(toolEnv);
|
|
312
395
|
// The run's resolved tool plane (its web tools' providers), as the pi spec hands it its web tools.
|
|
313
396
|
delete toolEnv[TOOL_PLANE_ENV];
|
|
@@ -318,8 +401,29 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
318
401
|
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held });
|
|
319
402
|
webTools = await webHostTools(host, granted, ctx);
|
|
320
403
|
}
|
|
321
|
-
if (learns)
|
|
322
|
-
|
|
404
|
+
if (learns) {
|
|
405
|
+
// A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
|
|
406
|
+
// keys, pi's wires, since pi-ai's client sends these, never the CLI); one refused fails its node in its words.
|
|
407
|
+
// Their models' keys (tierModelKeys: a saved one too, which claimSecrets opened only for the run's own model), held by
|
|
408
|
+
// the redactors, on the tiers' route env alone (withModelKeys, never enumerable), never on the tools' (toolEnv).
|
|
409
|
+
const tierKeys = await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
410
|
+
for (const redact of new Set([held, cut]))
|
|
411
|
+
holdClaimed(redact, tierKeys);
|
|
412
|
+
const modelEnv = withModelKeys(deps.env, { ...claimed, ...tierKeys });
|
|
413
|
+
const tiers = new Map();
|
|
414
|
+
for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
|
|
415
|
+
if ("why" in routed)
|
|
416
|
+
tiers.set(tier, { why: routed.why });
|
|
417
|
+
else {
|
|
418
|
+
tierRoutes.set(tier, routed);
|
|
419
|
+
tiers.set(tier, { model: routed.model });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
|
|
423
|
+
// own MCP as the loop wraps it.
|
|
424
|
+
gate.learn(workflows);
|
|
425
|
+
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}) });
|
|
426
|
+
}
|
|
323
427
|
}
|
|
324
428
|
const session = {
|
|
325
429
|
key: `run:${claim.runId}`,
|
|
@@ -327,9 +431,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
327
431
|
system: [environmentLine(), instructions, guidance].filter((line) => Boolean(line)),
|
|
328
432
|
// The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
|
|
329
433
|
// redactor, as pi's do.
|
|
330
|
-
tools: [...tools.hostTools(withKindTools(granted, tools),
|
|
434
|
+
tools: [...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))],
|
|
331
435
|
context: "fresh",
|
|
332
|
-
...(
|
|
436
|
+
...(thinking ? { thinking } : {}),
|
|
333
437
|
};
|
|
334
438
|
const content = isObject(launch.input) && typeof launch.input.content === "string" ? launch.input.content : "";
|
|
335
439
|
const input = await firstMessage(content, ws.workspace);
|
|
@@ -364,14 +468,28 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
364
468
|
...(mcp ? { mcp } : {}),
|
|
365
469
|
// The run's end-of-run step, when it learns (the spec's, preferred over the loop's deps': adapter-loop.ts stepOf).
|
|
366
470
|
...(endOfRun ? { endOfRun } : {}),
|
|
471
|
+
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
367
472
|
// The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
|
|
368
473
|
...(life ? { lifecycle: life } : {}),
|
|
369
474
|
agentId: runRow.agentId,
|
|
370
475
|
workRoot: root,
|
|
371
|
-
//
|
|
476
|
+
// Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
|
|
477
|
+
// against on the run's rows.
|
|
478
|
+
cwd: scratch,
|
|
479
|
+
// The end's metrics: its tools from the run's record, its tokens and model requests its booking's, at its model
|
|
480
|
+
// (metrics.ts cliRunMetrics). Its cost is its booking's too: the harness's own record carries no per-request cost or
|
|
481
|
+
// usage, so its model requests are counted at what the run's model proxy booked them at (bookedSpend over every
|
|
482
|
+
// session of its journal), as a pi run's are at its answers' costs and tokens.
|
|
372
483
|
endPatch: async () => {
|
|
373
484
|
const entries = await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context);
|
|
374
|
-
|
|
485
|
+
// Its tokens and model requests, and its model requests' cost, from one read of its booking (cliRunMetrics); its
|
|
486
|
+
// decisions (a learned workflow's) at what they were booked at too.
|
|
487
|
+
const all = (await journalEntries(deps.journal(claim), context));
|
|
488
|
+
const booked = bookedSpend(all, "model");
|
|
489
|
+
const metrics = cliRunMetrics(entries, booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}` });
|
|
490
|
+
const model = booked.usd;
|
|
491
|
+
const decisions = bookedSpend(all, "decisions").usd;
|
|
492
|
+
const costUsd = model === null || decisions === null ? null : model + decisions;
|
|
375
493
|
// Its paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own
|
|
376
494
|
// session, are the run's cost too, as the pi spec's.
|
|
377
495
|
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. */
|
|
@@ -26,6 +26,7 @@ export declare function suiteTools(countFile?: string): {
|
|
|
26
26
|
letSlowGo: () => void;
|
|
27
27
|
slowStarted: Promise<void>;
|
|
28
28
|
};
|
|
29
|
+
/** A store in a data directory of its own, one queued run, and runners started on it (each its own connection). */
|
|
29
30
|
/** The stores' clock skew a runner process reads (child.ts): the file holds the milliseconds the clock moved, so the
|
|
30
31
|
* process's store moves with the case's (runOut). */
|
|
31
32
|
export declare const storeClockOf: (file: string | undefined) => (() => number);
|