@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
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 +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +90 -8
- package/dist/archil-settings.js +150 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -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/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- 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 +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- 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/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- 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 +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- 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/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- 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/release-notes/agent.md +11 -0
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -2,7 +2,7 @@ import type { Context } from "@earendil-works/chord";
|
|
|
2
2
|
import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
3
3
|
import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
5
|
-
import type { installSettled } from "../harness-install.js";
|
|
5
|
+
import type { installForClaim, installSettled } from "../harness-install.js";
|
|
6
6
|
import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
|
|
7
7
|
import { type PinnedModel, type Tier } from "../model.js";
|
|
8
8
|
import { type RunLaunch } from "../run-launch.js";
|
|
@@ -14,12 +14,13 @@ import { type HostToolCtx } from "../host-tools.js";
|
|
|
14
14
|
import { type LearnedWorkflow } from "../learning.js";
|
|
15
15
|
import { type ToolResults } from "../workspace/run-tools.js";
|
|
16
16
|
import { type ClaimMcp } from "./mcp-run.js";
|
|
17
|
-
import { type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
|
|
17
|
+
import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
|
|
18
18
|
import { type Claim, type Journal } from "./loop-contract.js";
|
|
19
19
|
import type { ModelRoute } from "./model-route.js";
|
|
20
20
|
import { type ArchilClaimOptions } from "../workspace/archil-claim.js";
|
|
21
21
|
import { type claimComputer, type ComputerDeps } from "../workspace/computer-deps.js";
|
|
22
22
|
import type { RunComputer } from "../workspace/run-tools.js";
|
|
23
|
+
import type { RunComputerHold } from "./computer-journal.js";
|
|
23
24
|
import type { ShellPlace } from "../workspace/resolve-computer.js";
|
|
24
25
|
import type { Workspace } from "../workspace/workspace.js";
|
|
25
26
|
import { type HeldRedact } from "./redact.js";
|
|
@@ -44,6 +45,8 @@ export interface ClaimDeps {
|
|
|
44
45
|
export interface ClaimComputer {
|
|
45
46
|
readonly computer?: RunComputer;
|
|
46
47
|
readonly hold?: unknown;
|
|
48
|
+
/** The run's desktop or phone and the person's hold on it: the spec's `computer` (AdapterRunSpec.computer). */
|
|
49
|
+
readonly held?: RunComputerHold;
|
|
47
50
|
release(): Promise<void>;
|
|
48
51
|
}
|
|
49
52
|
/** The one shared claim-time computer every spec takes (computer-for-claim.ts), passed in by the runner: the composer's
|
|
@@ -96,12 +99,27 @@ export interface AdapterSpecDeps {
|
|
|
96
99
|
/** How a CLI run's claim waits for its harness's first-use install (harness-install.ts installSettled); a test wraps it
|
|
97
100
|
* to see the claim reach the wait. Absent, installSettled itself. */
|
|
98
101
|
readonly installSettled?: typeof installSettled;
|
|
102
|
+
/** How a CLI run's claim installs its harness when nothing installs it (harness-install.ts installForClaim); a test gives
|
|
103
|
+
* its own, so none reaches npm. Absent, installForClaim itself. */
|
|
104
|
+
readonly installForClaim?: typeof installForClaim;
|
|
105
|
+
/** For tests only: the lock a claim's first-use install of each harness installs by (harness-install.ts installForClaim),
|
|
106
|
+
* by harness, as the server's own option of that name gives its installs. The CLI's runner never sets it, and no
|
|
107
|
+
* environment variable, flag or setting maps onto it; absent, the lock AgentRun ships. */
|
|
108
|
+
readonly harnessLocks?: Readonly<Record<string, string>>;
|
|
99
109
|
/** A test runner's fake GitHub API, where the GitHub App's installation tokens are minted (runner/github-app.ts). Absent,
|
|
100
110
|
* https://api.github.com: the CLI's runner never sets it, and no environment variable, flag or setting maps onto it. */
|
|
101
111
|
readonly githubApi?: string;
|
|
112
|
+
/** A test runner's GitHub site, where a run's pull request is checked out from (pr-checkout.ts): a folder of bare
|
|
113
|
+
* repositories, or a git server on loopback. Absent, https://github.com; nothing kept, no environment variable and no
|
|
114
|
+
* flag reaches it. */
|
|
115
|
+
readonly githubWeb?: string;
|
|
102
116
|
/** A test runner's fake GitHub MCP origin, the one a github_app server may be at (mcp-claim.ts githubMcpOrigin):
|
|
103
117
|
* for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP (github.ts GITHUB_MCP_ORIGIN). Only a test's in-process runner sets it; the CLI's runner never does. */
|
|
104
118
|
readonly githubMcpOrigin?: string;
|
|
119
|
+
/** For tests only: the adapter loop's model retry (adapter-loop.ts retry and stream), so a test whose provider fails a run
|
|
120
|
+
* on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
|
|
121
|
+
* it; absent, MODEL_RETRY and MODEL_STREAM. */
|
|
122
|
+
readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
|
|
105
123
|
}
|
|
106
124
|
/** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
|
|
107
125
|
* model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
|
|
@@ -155,8 +173,9 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
|
|
|
155
173
|
toolSettings?: unknown;
|
|
156
174
|
harness?: string;
|
|
157
175
|
approvals?: Approvals;
|
|
176
|
+
maxToolCalls?: number;
|
|
158
177
|
};
|
|
159
|
-
}, root: RunFiles, shell?: ShellPlace): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
178
|
+
}, root: RunFiles, shell?: ShellPlace, mcpServers?: readonly string[]): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
160
179
|
readonly permissions: RunPermissions;
|
|
161
180
|
readonly learn: (flows: readonly LearnedWorkflow[]) => void;
|
|
162
181
|
}>;
|
|
@@ -167,7 +186,7 @@ export declare function storeSettings(store: Pick<Store, "settings">): Promise<A
|
|
|
167
186
|
* tools) is held until the spec's release; a build that throws part-way lets go what it made by then (spec-holds.ts). */
|
|
168
187
|
export declare function adapterRunSpecFromLaunch(launch: RunLaunch, run: AdapterRun, deps: AdapterSpecDeps, claim: Claim): Promise<AdapterRunSpec>;
|
|
169
188
|
/** The host-tool ctx a non-hand tool is wrapped with (host-tools.ts hostToolOf): the run's own Harness (its commit,
|
|
170
|
-
* snapshot
|
|
189
|
+
* snapshot and task reads), the results map, and the run's folder as the api env's cwd (a tool reads no
|
|
171
190
|
* file environment, so an error names a path relative to it). Shared by the pi spec's bindNonHandTools and the CLI spec's
|
|
172
191
|
* learned_workflow. */
|
|
173
192
|
export declare function hostToolCtxOf(run: AdapterRun, context: Context, results: ToolResults, root: string): HostToolCtx;
|
|
@@ -175,6 +194,22 @@ export declare function hostToolCtxOf(run: AdapterRun, context: Context, results
|
|
|
175
194
|
* a workflow it may run (`workflows`: the claim's seed lay chose them, runner/learning-seed.ts). A revision never names
|
|
176
195
|
* the tool among its own: the run has it beside them, so the harness is told of it as of theirs. */
|
|
177
196
|
export declare const learnsWorkflows: (kind: string, workflows: readonly LearnedWorkflow[]) => boolean;
|
|
197
|
+
/** A tier a learned workflow's node names, as the run has it: its model's id, or why it could not be reached. */
|
|
198
|
+
export type LearnedTier = {
|
|
199
|
+
readonly model: string;
|
|
200
|
+
} | {
|
|
201
|
+
readonly why: string;
|
|
202
|
+
};
|
|
203
|
+
/** The tiers other than the default that `workflows`' model nodes and `llm` calls name (model.ts nodeTiers, llmTiers),
|
|
204
|
+
* in TIERS order. A workflow that does not parse names none: its call refuses it. */
|
|
205
|
+
export declare function learnedTiers(workflows: readonly LearnedWorkflow[]): Tier[];
|
|
206
|
+
/** The route of each tier `workflows` name (learnedTiers) that `env` names a model of its own for (tierModelOf:
|
|
207
|
+
* AGENT_MODEL_FAST, AGENT_MODEL_STRONG), through `routeOf` (the run's one route, as its own model's): the model a node
|
|
208
|
+
* of that tier runs on, priced at its own price. A tier with no model of its own is left out (its nodes run on the
|
|
209
|
+
* run's model); one whose route is refused is `why`, so its nodes fail in those words and never run on another model. */
|
|
210
|
+
export declare function learnedTierRoutes(workflows: readonly LearnedWorkflow[], env: NodeJS.ProcessEnv, routeOf: (tier: Tier) => Promise<ModelRoute>): Promise<Map<Tier, ModelRoute | {
|
|
211
|
+
why: string;
|
|
212
|
+
}>>;
|
|
178
213
|
/** The run's learned_workflow tool as a HostTool, listed when the run has it (learnsWorkflows: an agentic revision whose
|
|
179
214
|
* agent learned workflows, by learning.ts chooseWorkflows as main's start chooses them, so the tool set the model sees
|
|
180
215
|
* matches main). `granted`, the revision's own tools, are the ones its workflows' call nodes may call. Every run's session — pi's and every CLI harness's — has a model
|
|
@@ -193,9 +228,16 @@ export declare function learnedWorkflowHostTool(opts: {
|
|
|
193
228
|
/** The run's gate's permissions (adapterRunGate): each call node's tool is held to them, as main holds it. */
|
|
194
229
|
readonly permissions: RunPermissions;
|
|
195
230
|
readonly ctx: HostToolCtx;
|
|
231
|
+
/** The run's models of other tiers (pi's: learnedTierRoutes), by tier: a node of one runs on that model, through the
|
|
232
|
+
* session's port of the tier (AdapterSession.port's `tier`); one with `why` fails in those words. A tier not here runs
|
|
233
|
+
* on the session's model. */
|
|
234
|
+
readonly tiers?: ReadonlyMap<string, LearnedTier>;
|
|
196
235
|
/** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
|
|
197
236
|
* catalog name, each run through the run's own MCP as the loop wraps it. */
|
|
198
237
|
readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
|
|
238
|
+
/** The model a node on the session's own port runs on (a node of no tier, or of a tier not in `tiers`), as the run's
|
|
239
|
+
* route names it: what its trace says it ran on. A node of a tier in `tiers` names that tier's model. */
|
|
240
|
+
readonly modelName?: (tier: string | undefined) => string | undefined;
|
|
199
241
|
}): Promise<HostTool | undefined>;
|
|
200
242
|
/** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
|
|
201
243
|
* hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
2
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
3
3
|
import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
4
|
+
import { inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
4
5
|
import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
|
|
5
|
-
import { thinkingLevel } from "../model.js";
|
|
6
|
+
import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes } from "../model.js";
|
|
6
7
|
import { firstMessage } from "../run-manifest.js";
|
|
7
8
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
8
9
|
import { isObject } from "../validate.js";
|
|
9
|
-
import { deniedText, noApproverText, runGate } from "../tool-gate.js";
|
|
10
|
+
import { deniedText, mcpServersOf, noApproverText, runGate } from "../tool-gate.js";
|
|
10
11
|
import { loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
11
12
|
import { readApprovers } from "../server-approvers.js";
|
|
12
13
|
import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
|
|
@@ -16,34 +17,37 @@ import { WEB_SEARCH_TOOL } from "../web-search.js";
|
|
|
16
17
|
import { environmentLine } from "../environment.js";
|
|
17
18
|
import { effortGuidance } from "../effort-guidance.js";
|
|
18
19
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
19
|
-
import { layLearningSeed } from "./learning-seed.js";
|
|
20
|
+
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
20
21
|
import { learningWorkspace } from "../learn/folder.js";
|
|
21
22
|
import { learningEndOfRun } from "./learning-end.js";
|
|
22
23
|
import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
|
|
23
|
-
import { PORT_PROVIDER } from "../port-models.js";
|
|
24
|
+
import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
|
|
24
25
|
import { promptOf, readsFiles } from "../skills.js";
|
|
25
26
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
26
27
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
27
28
|
import { COMPUTER_ROOT, runFolder } from "../workspace/paths.js";
|
|
28
29
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
29
|
-
import {
|
|
30
|
+
import { copyRunFiles } from "../uploads.js";
|
|
30
31
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
31
32
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
32
|
-
import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
|
|
33
|
+
import { claimSecrets, learnedDecisionKeys, savedModelKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
33
34
|
import { mcpForClaim } from "./mcp-run.js";
|
|
34
|
-
import { join } from "node:path";
|
|
35
35
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
36
36
|
import { piAdapter } from "./adapters/pi.js";
|
|
37
|
-
import {
|
|
37
|
+
import { agentEntriesOf } from "./loop.js";
|
|
38
|
+
import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
|
|
39
|
+
import { wireName } from "../catalog.js";
|
|
38
40
|
import { ClaimRefused } from "./loop-contract.js";
|
|
39
41
|
import { runMetrics } from "./metrics.js";
|
|
40
42
|
import { specBuilt } from "./spec-holds.js";
|
|
41
43
|
import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
42
44
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
43
|
-
import { imageWaitWords } from "../workspace/computer-deps.js";
|
|
45
|
+
import { computerReadyWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
44
46
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
45
47
|
import { githubAppAccess } from "./github-app.js";
|
|
48
|
+
import { prCheckoutForClaim } from "./pr-checkout.js";
|
|
46
49
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
50
|
+
import { bashPolicyOf } from "../bash-read-only.js";
|
|
47
51
|
/** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
|
|
48
52
|
export const PI_WIRES = Object.freeze(["anthropic-messages", "openai-responses"]);
|
|
49
53
|
/** The browser's catalog name (tools.ts TOOLS.browser). */
|
|
@@ -59,7 +63,8 @@ export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger
|
|
|
59
63
|
* model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
|
|
60
64
|
* overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
|
|
61
65
|
export function capModelOf(route) {
|
|
62
|
-
|
|
66
|
+
// A model serve has no price for carries placeholder zeros: the cap reads it as unknown (null), never as $0.
|
|
67
|
+
const cost = route.unpriced ? undefined : route.cost;
|
|
63
68
|
const price = cost
|
|
64
69
|
? {
|
|
65
70
|
input: cost.input,
|
|
@@ -72,6 +77,11 @@ export function capModelOf(route) {
|
|
|
72
77
|
// The cap reads a request's provider overhead by the route's own wire (providerInputOverhead).
|
|
73
78
|
return { id: route.model, api: route.provider.api, price, outputCeiling: route.outputCeiling ?? null };
|
|
74
79
|
}
|
|
80
|
+
/** The key of a subagent tier's route in a run's tier routes and proxies (a key of its own, never a learned workflow's
|
|
81
|
+
* tier: those nodes keep their own route and fallback). */
|
|
82
|
+
const SUBAGENT_ROUTE = "subagent-";
|
|
83
|
+
const subagentRoute = (tier) => `${SUBAGENT_ROUTE}${tier}`;
|
|
84
|
+
const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
|
|
75
85
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
76
86
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
77
87
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -79,19 +89,21 @@ export function capModelOf(route) {
|
|
|
79
89
|
export function modelAskOf(pinned, ref) {
|
|
80
90
|
return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
|
|
81
91
|
}
|
|
82
|
-
export async function adapterRunGate(store, claim, revision, root, shell) {
|
|
92
|
+
export async function adapterRunGate(store, claim, revision, root, shell, mcpServers = []) {
|
|
83
93
|
let current = await storeSettings(store);
|
|
84
94
|
const approvers = await readApprovers(store.settings);
|
|
85
95
|
// A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
|
|
86
96
|
const folder = typeof root === "string" ? root : COMPUTER_ROOT;
|
|
87
97
|
// Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
|
|
88
|
-
// default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
|
|
89
|
-
|
|
98
|
+
// default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused. The run's MCP servers
|
|
99
|
+
// (mcpServersOf its grants), so a harness naming an MCP tool its own way (OpenCode's `<server>_<tool>`) is held to that
|
|
100
|
+
// tool's settings, never to a table tool's of the same shape.
|
|
101
|
+
const gate = runGate({ root: folder, work: folder, ...(shell === undefined ? {} : { computer: shell === "computer" }), mcpServers }, claim.runId, revision, () => current, approvers);
|
|
90
102
|
// The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
|
|
91
103
|
let learned = [];
|
|
92
|
-
const decide = async (call) => {
|
|
104
|
+
const decide = async (call, options = {}) => {
|
|
93
105
|
current = await storeSettings(store);
|
|
94
|
-
const decision = await gate.decide(call.tool, call.args);
|
|
106
|
+
const decision = await gate.decide(call.tool, call.args, options);
|
|
95
107
|
// A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings, decided for the whole call
|
|
96
108
|
// before any node runs, never mid-run: one set to deny refuses the call in the gate's words, nothing sent; one set to
|
|
97
109
|
// ask asks for the call, up front, on the run's one card (a running workflow can't park mid-call: it is never run
|
|
@@ -131,7 +143,9 @@ export async function adapterRunGate(store, claim, revision, root, shell) {
|
|
|
131
143
|
const asks = (await mcpOf(args)).filter((one) => gate.policy(one) === "ask");
|
|
132
144
|
return asks.length ? learnedAskShown(asks) : undefined;
|
|
133
145
|
};
|
|
134
|
-
|
|
146
|
+
// The revision's tool-call budget (tool-budget.ts), which the adapter loop holds each conversation's calls to.
|
|
147
|
+
const toolCalls = revision.body.maxToolCalls;
|
|
148
|
+
return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, learn: (flows) => void (learned = flows), ...(toolCalls === undefined ? {} : { toolCalls }) });
|
|
135
149
|
}
|
|
136
150
|
/** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
|
|
137
151
|
* and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
|
|
@@ -172,7 +186,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
172
186
|
// The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
|
|
173
187
|
// on the claim's Archil disk (archil-claim.ts: its keys from the store's sealed rows, under the runner's seal key, in this
|
|
174
188
|
// claim's memory only); else Mode 1, the run's local folder. The same for the pi and the CLI spec.
|
|
175
|
-
const archilSettings = await loadArchilSettings(deps.store);
|
|
189
|
+
const archilSettings = await loadArchilSettings(deps.store, deps.env);
|
|
176
190
|
const mode = archilSettings === undefined ? 1 : 2;
|
|
177
191
|
const archil = archilSettings === undefined
|
|
178
192
|
? undefined
|
|
@@ -183,7 +197,8 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
183
197
|
// The mint is lazy (archil-claim.ts token(), k2's run-tools.ts): only a mounting computer asks for it, so a Mode 2 run
|
|
184
198
|
// with no computer makes no control-plane call. mountControl (a test's loopback control-plane fake) is spread into the
|
|
185
199
|
// mount, so no test reaches the real control plane. MOUNT_TTL_MS is the credential's safety net (its computer's 24 h bound), not its lifetime.
|
|
186
|
-
|
|
200
|
+
// The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one.
|
|
201
|
+
: await archilClaim({ settings: archilSettings, keys: deps.store.sealedKeys, sealKey: deps.sealKey, signal: run.signal ?? new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS, ...(deps.mountControl ?? {}) }, run: { agentId: runRow.agentId, ...(launch.archilDisk ? { launch: launch.archilDisk } : {}), store: deps.store }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
|
|
187
202
|
// Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go.
|
|
188
203
|
holds.hold({ archil });
|
|
189
204
|
// The run's Workspace at the claim: Mode 1 the run's local folder (made here, the server's start made it before); Mode 2
|
|
@@ -192,36 +207,41 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
192
207
|
? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
|
|
193
208
|
: await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
|
|
194
209
|
holds.hold({ ws });
|
|
195
|
-
// The run's uploaded files, copied into its work/inputs/ before the first turn,
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
210
|
+
// The run's uploaded files, copied into its work/inputs/ before the first turn, from what its start held for it, once
|
|
211
|
+
// per run (uploads.ts copyRunFiles); a copy that fails ends the run failed, saying why.
|
|
212
|
+
if (launch.files?.length)
|
|
213
|
+
await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
|
|
214
|
+
// The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
|
|
215
|
+
// turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
|
|
216
|
+
// there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
|
|
217
|
+
// person's stop ends the fetch at once (run.stopped).
|
|
218
|
+
const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
|
|
219
|
+
holds.hold({ checkout });
|
|
205
220
|
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
|
|
206
221
|
// credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
|
|
207
222
|
// anything the spec would have to let go: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its
|
|
208
223
|
// words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
|
|
209
|
-
|
|
224
|
+
// A credential the claim opens mid-run (a GitHub App token, a per_run server's handed one) joins the run's redactor.
|
|
225
|
+
const hold = (values) => cut.hold(values);
|
|
226
|
+
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
|
|
210
227
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
211
228
|
holds.hold({ passed: mcp });
|
|
212
229
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
213
230
|
// Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
|
|
214
231
|
// when the computer cannot be had: the run fails in its words.
|
|
215
|
-
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,
|
|
232
|
+
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
|
|
216
233
|
// revokeMount removes the run's Archil mount credential when the computer is released (and if a start fails after a mint);
|
|
217
|
-
// the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent.
|
|
218
|
-
|
|
234
|
+
// the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent. What
|
|
235
|
+
// became of the agent's own computer (a persistent setting) is said on the run's timeline.
|
|
236
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
219
237
|
// The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
|
|
220
238
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
221
239
|
// A desktop's or a phone's hold (the person's take-over) wraps its ports: a call made while the person holds it waits,
|
|
222
240
|
// and the agent's hand-over (computer_request_handoff) asks the person through it.
|
|
223
241
|
holds.hold({ computer });
|
|
224
|
-
|
|
242
|
+
// Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv).
|
|
243
|
+
const bashPolicy = bashPolicyOf(body.toolSettings);
|
|
244
|
+
const tools = await runTools(ws.workspace, computer.computer, { mode, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }) });
|
|
225
245
|
holds.hold({ tools });
|
|
226
246
|
// The run's model route: its model through routeOf (NEVER re-resolved — the launch's model, pinned at start), the catalog
|
|
227
247
|
// price with tiers for the cap, and the proxy's price (pi-ai calculateCost, tiered).
|
|
@@ -236,7 +256,11 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
236
256
|
holdClaimed(cut, toolEnv);
|
|
237
257
|
// The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
|
|
238
258
|
// saved in Settings → Model keys runs the next run with no restart (withModelKeys).
|
|
239
|
-
const
|
|
259
|
+
const modelEnv = withModelKeys(deps.env, toolEnv);
|
|
260
|
+
const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
|
|
261
|
+
// The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
|
|
262
|
+
// lay chose the workflows, below): read when the session opens (pi.ts options.tiers), each on a proxy of its own.
|
|
263
|
+
const tierRoutes = new Map();
|
|
240
264
|
// The run's pi-native extensions, in the root agent through the pi adapter (PiAdapterOptions.extensions), which installs
|
|
241
265
|
// them in the claim's registry and offers each tool once:
|
|
242
266
|
// - ask_person is pi's own tool (tools.ts): a run granted it carries its native extension, so pi runs it as its own tool
|
|
@@ -246,16 +270,46 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
246
270
|
// refuses it (runnable.ts). pi only.
|
|
247
271
|
// - the browser's durable extension, when the run gets one (bindNonHandTools, below, before the session opens).
|
|
248
272
|
const native = granted.includes(ASK_TOOL) ? [defineExtension({ name: "ask_person", tools: [askPerson] })] : [];
|
|
273
|
+
// pi-native tools in the session's own extension (PiAdapterOptions.tools): the subagent tool, pushed below.
|
|
274
|
+
const piTools = [];
|
|
275
|
+
// A run granted subagent (runner/subagent.ts): the model of each of its tiers, the revision's own (modelTiers) else the
|
|
276
|
+
// host's for the tier (AGENT_MODEL_FAST, AGENT_MODEL_STRONG), each on a route of its own (its proxy on the session's
|
|
277
|
+
// booking, adapters/pi.ts tiers). A tier with neither is the agent's own model, as a learned workflow's node of it runs
|
|
278
|
+
// on the run's. A tier no route can be made for here is no failure of the run: a call on it answers why. A tier's model may be another
|
|
279
|
+
// provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's model): so
|
|
280
|
+
// its route reads every model key the server holds (savedModelKeys). Those reach the tier's proxy alone, as its
|
|
281
|
+
// credential, never the run's tools (toolEnv).
|
|
282
|
+
// Each is in tierRoutes under its own key (subagentRoute: never a learned workflow's tier, whose nodes keep their own
|
|
283
|
+
// routes and fallback), on a proxy of its own that names that key on each request, so the cap prices a child's
|
|
284
|
+
// requests as that route books them.
|
|
285
|
+
const tierWhy = new Map();
|
|
286
|
+
if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL)) {
|
|
287
|
+
const savedKeys = await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
|
|
288
|
+
holdClaimed(cut, savedKeys);
|
|
289
|
+
const tierEnv = withModelKeys(deps.env, { ...savedKeys, ...toolEnv });
|
|
290
|
+
for (const tier of SUBAGENT_TIERS) {
|
|
291
|
+
if (body.modelTiers?.[tier] === undefined && tierModelOf(tierEnv, tier) === undefined)
|
|
292
|
+
continue;
|
|
293
|
+
try {
|
|
294
|
+
tierRoutes.set(subagentRoute(tier), await deps.routeOf(body.modelTiers?.[tier], tierEnv, tier, PI_WIRES, undefined, cut));
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
tierWhy.set(tier, cut(error instanceof Error ? error.message : String(error)));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
249
301
|
const adapter = piAdapter({
|
|
250
302
|
run,
|
|
251
303
|
// Read when the session opens (pi.ts), so the browser's extension pushed by bindNonHandTools below is in it.
|
|
252
304
|
extensions: native,
|
|
305
|
+
tools: piTools,
|
|
253
306
|
model: route.model,
|
|
254
307
|
provider: route.provider,
|
|
255
308
|
redact: cut,
|
|
256
309
|
...(route.like ? { like: route.like } : {}),
|
|
257
310
|
...(route.price ? { price: route.price } : {}),
|
|
258
311
|
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
312
|
+
tiers: tierRoutes,
|
|
259
313
|
});
|
|
260
314
|
// The gate before a call's intent: the run's revision's tool settings through runGate (approvals "never" turns the one
|
|
261
315
|
// ask it leaves into an allow). The adapter loop asks `gate` and handles the ask/park/answer on the journal itself, so
|
|
@@ -263,16 +317,23 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
263
317
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
264
318
|
// The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
|
|
265
319
|
// the same path), for its path checks; it reads nothing in it.
|
|
266
|
-
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
|
|
320
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted));
|
|
267
321
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
268
322
|
// uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
|
|
269
323
|
// launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
|
|
270
324
|
// tool calls and its decisions all on one rule and one booking), so the spec carries no beforeRequest of its own.
|
|
271
325
|
const capUsd = launch.maxCostUsd;
|
|
272
326
|
const capModel = capModelOf(route);
|
|
327
|
+
// And each tier's model (tierRoutes, filled below), by the route its request names (its tier's proxy, ModelRequest.route),
|
|
328
|
+
// priced as that route books it: one id the run's model and a tier share is priced apart, never at the other's price.
|
|
273
329
|
const runCap = {
|
|
274
330
|
capUsd: () => launch.maxCostUsd,
|
|
275
|
-
modelOf: (id) =>
|
|
331
|
+
modelOf: (id, by) => {
|
|
332
|
+
if (by === undefined)
|
|
333
|
+
return id === route.model ? capModel : undefined;
|
|
334
|
+
const tierRoute = tierRoutes.get(by);
|
|
335
|
+
return tierRoute && tierRoute.model === id ? capModelOf(tierRoute) : undefined;
|
|
336
|
+
},
|
|
276
337
|
...(launch.capMode === "strict" ? { mode: "strict" } : {}),
|
|
277
338
|
};
|
|
278
339
|
// The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
|
|
@@ -312,6 +373,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
312
373
|
own: Object.keys(revisionRow.skills ?? {}),
|
|
313
374
|
shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
|
|
314
375
|
log,
|
|
376
|
+
...(start.notesOnly ? { workflows: false } : {}),
|
|
315
377
|
})
|
|
316
378
|
: undefined;
|
|
317
379
|
// The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
|
|
@@ -319,7 +381,22 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
319
381
|
// onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
|
|
320
382
|
// becomes its model's.
|
|
321
383
|
const workflows = seedLaid?.workflows ?? [];
|
|
384
|
+
// A tier a learned workflow's node names and the host has a model of: none can't be reached is left as `why`, and its
|
|
385
|
+
// node fails in those words (learnedWorkflowHostTool), never on another model.
|
|
386
|
+
const tierUnreachable = new Map();
|
|
322
387
|
if (learnsWorkflows(revision.kind, workflows)) {
|
|
388
|
+
// The keys those tiers' models need (tierModelKeys: a key saved in Settings too, which claimSecrets opened only for the
|
|
389
|
+
// run's own model), held by the run's one redactor, on the tiers' route env alone (withModelKeys, never enumerable),
|
|
390
|
+
// never on the tools' (toolEnv).
|
|
391
|
+
const tierKeys = await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
392
|
+
holdClaimed(cut, tierKeys);
|
|
393
|
+
const tierEnv = withModelKeys(deps.env, { ...toolEnv, ...tierKeys });
|
|
394
|
+
for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
|
|
395
|
+
if ("why" in routed)
|
|
396
|
+
tierUnreachable.set(tier, routed.why);
|
|
397
|
+
else
|
|
398
|
+
tierRoutes.set(tier, routed);
|
|
399
|
+
}
|
|
323
400
|
const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
|
|
324
401
|
holdClaimed(cut, learnedKeys);
|
|
325
402
|
Object.assign(toolEnv, learnedKeys);
|
|
@@ -339,9 +416,10 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
339
416
|
const handTools = tools.hostTools(withKindTools(granted, tools), results);
|
|
340
417
|
// The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
|
|
341
418
|
// words, pass the run's one redactor before the harness, the model or the record has them.
|
|
419
|
+
const tiers = new Map([...[...tierRoutes].filter(([tier]) => !isSubagentRoute(tier)).map(([tier, { model }]) => [tier, { model }]), ...[...tierUnreachable].map(([tier, why]) => [tier, { why }])]);
|
|
342
420
|
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate).
|
|
343
421
|
gate.learn(workflows);
|
|
344
|
-
const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, mcp)).map((tool) => answersCut(tool, cut));
|
|
422
|
+
const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, tiers, mcp, () => route.model)).map((tool) => answersCut(tool, cut));
|
|
345
423
|
const sessionTools = [...handTools, ...nonHandTools];
|
|
346
424
|
// The run's system prompt, as main's per-run process builds it (app.ts): the environment line first (environment.ts, as
|
|
347
425
|
// pi installs it before every other section), then the revision's instructions with what the agent learned laid in
|
|
@@ -352,7 +430,32 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
352
430
|
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
353
431
|
const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
|
|
354
432
|
const guidance = effortGuidance(launch.effort);
|
|
355
|
-
const system = [environmentLine(), instructions, guidance].filter((line) => Boolean(line));
|
|
433
|
+
const system = [environmentLine(), checkout?.note, instructions, guidance].filter((line) => Boolean(line));
|
|
434
|
+
// The subagent tool, one of the session's own tools (no extension of its own): a child's tools are a subset of the
|
|
435
|
+
// revision's grants (each by its session name: an MCP tool's wire name, the browser's registrations), its model the
|
|
436
|
+
// agent's own or one of the tiers resolved above.
|
|
437
|
+
if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL)) {
|
|
438
|
+
const browserNames = native.filter((extension) => extension.name !== "ask_person").flatMap((extension) => (extension.tools ?? []).map((tool) => tool.name));
|
|
439
|
+
piTools.push(subagentTool({
|
|
440
|
+
granted,
|
|
441
|
+
sessionNames: (catalog) => (catalog === BROWSER_TOOL ? browserNames : [wireName(catalog)]),
|
|
442
|
+
tier: (tier) => {
|
|
443
|
+
const why = tierWhy.get(tier);
|
|
444
|
+
if (why !== undefined)
|
|
445
|
+
return { why };
|
|
446
|
+
// A tier with no model of its own (no model_tiers, no AGENT_MODEL_<TIER>): the agent's own model.
|
|
447
|
+
const at = tierRoutes.get(subagentRoute(tier));
|
|
448
|
+
if (!at)
|
|
449
|
+
return { ref: { provider: PORT_PROVIDER, modelId: route.model } };
|
|
450
|
+
// A capped run never sends a request it cannot price: an unpriced tier refuses the call, and the run goes on.
|
|
451
|
+
if (at.unpriced && launch.maxCostUsd !== undefined)
|
|
452
|
+
return { why: `${at.model} has no known price here, so this run's cost cap cannot hold its requests.` };
|
|
453
|
+
return { ref: { provider: tierProvider(subagentRoute(tier)), modelId: at.model } };
|
|
454
|
+
},
|
|
455
|
+
preamble: environmentLine(),
|
|
456
|
+
...(revision.body.maxToolCalls !== undefined ? { toolCalls: revision.body.maxToolCalls } : {}),
|
|
457
|
+
}));
|
|
458
|
+
}
|
|
356
459
|
// The level pi thinks at: the launch's effort (the run's own, else its revision's, else the host's), every level pi's
|
|
357
460
|
// agent takes; none, pi's default.
|
|
358
461
|
const thinking = thinkingLevel(launch.effort);
|
|
@@ -402,14 +505,19 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
402
505
|
...(mcp ? { mcp } : {}),
|
|
403
506
|
// The run's end-of-run step, when it learns (the spec's, which the loop prefers over its deps': adapter-loop.ts stepOf).
|
|
404
507
|
...(endOfRun ? { endOfRun } : {}),
|
|
508
|
+
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
405
509
|
// The tool host's install lifecycle (its bindings' onConversation/beforeResume/beforeRelease), run by the adapter loop.
|
|
406
510
|
lifecycle: life,
|
|
407
511
|
agentId: runRow.agentId,
|
|
512
|
+
// The run's desktop or phone and the person's hold on it, as the claim made them: the loop shows it up and applies a
|
|
513
|
+
// take-over and a hand-back to it.
|
|
514
|
+
...(computer.held ? { computer: computer.held } : {}),
|
|
408
515
|
workRoot: root,
|
|
409
516
|
// The end's metrics and cost, from the run's journal, as the old per-run end path read them (metrics.ts runMetrics =
|
|
410
517
|
// runs.ts storedMetrics/costOf). A pi run adds its effort, no model (metrics.ts).
|
|
411
518
|
endPatch: async () => {
|
|
412
|
-
|
|
519
|
+
// The root's entries and every conversation a task of the run owns (a subagent's): a child's requests are the run's.
|
|
520
|
+
const entries = await agentEntriesOf(deps.journal(claim), context);
|
|
413
521
|
const { metrics, costUsd } = runMetrics(entries, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}) });
|
|
414
522
|
// Its paid tool calls (a Parallel search's, a monid call's, a person's browser time), booked on the run's one ledger
|
|
415
523
|
// (the paid tool calls on its cap, in their own session, not on the root), are the run's cost too.
|
|
@@ -425,7 +533,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
|
|
|
425
533
|
};
|
|
426
534
|
}
|
|
427
535
|
/** The host-tool ctx a non-hand tool is wrapped with (host-tools.ts hostToolOf): the run's own Harness (its commit,
|
|
428
|
-
* snapshot
|
|
536
|
+
* snapshot and task reads), the results map, and the run's folder as the api env's cwd (a tool reads no
|
|
429
537
|
* file environment, so an error names a path relative to it). Shared by the pi spec's bindNonHandTools and the CLI spec's
|
|
430
538
|
* learned_workflow. */
|
|
431
539
|
export function hostToolCtxOf(run, context, results, root) {
|
|
@@ -435,7 +543,6 @@ export function hostToolCtxOf(run, context, results, root) {
|
|
|
435
543
|
env: async () => ({ cwd: root }),
|
|
436
544
|
commit: (change, at, options) => run.harness.commit(change, at, options),
|
|
437
545
|
snapshot: ((...args) => Reflect.apply(run.harness.snapshot, run.harness, args)),
|
|
438
|
-
conversation: ((id, at) => run.harness.conversation(id, at)),
|
|
439
546
|
waitForTask: (id, at) => run.harness.waitForTask(id, at),
|
|
440
547
|
agent: async (at) => {
|
|
441
548
|
const conversation = await run.harness.conversation(ROOT_CONVERSATION_ID, at);
|
|
@@ -449,6 +556,42 @@ export function hostToolCtxOf(run, context, results, root) {
|
|
|
449
556
|
* a workflow it may run (`workflows`: the claim's seed lay chose them, runner/learning-seed.ts). A revision never names
|
|
450
557
|
* the tool among its own: the run has it beside them, so the harness is told of it as of theirs. */
|
|
451
558
|
export const learnsWorkflows = (kind, workflows) => kind === "agentic" && workflows.length > 0;
|
|
559
|
+
/** The tiers other than the default that `workflows`' model nodes and `llm` calls name (model.ts nodeTiers, llmTiers),
|
|
560
|
+
* in TIERS order. A workflow that does not parse names none: its call refuses it. */
|
|
561
|
+
export function learnedTiers(workflows) {
|
|
562
|
+
const named = new Set();
|
|
563
|
+
for (const flow of workflows) {
|
|
564
|
+
let doc;
|
|
565
|
+
try {
|
|
566
|
+
doc = JSON.parse(flow.workflow);
|
|
567
|
+
const nodes = workflowNodes(doc, inspectWorkflow(doc));
|
|
568
|
+
for (const tier of llmTiers(nodes, nodeTiers(nodes)))
|
|
569
|
+
named.add(tier);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return TIERS.filter((tier) => tier !== "default" && named.has(tier));
|
|
576
|
+
}
|
|
577
|
+
/** The route of each tier `workflows` name (learnedTiers) that `env` names a model of its own for (tierModelOf:
|
|
578
|
+
* AGENT_MODEL_FAST, AGENT_MODEL_STRONG), through `routeOf` (the run's one route, as its own model's): the model a node
|
|
579
|
+
* of that tier runs on, priced at its own price. A tier with no model of its own is left out (its nodes run on the
|
|
580
|
+
* run's model); one whose route is refused is `why`, so its nodes fail in those words and never run on another model. */
|
|
581
|
+
export async function learnedTierRoutes(workflows, env, routeOf) {
|
|
582
|
+
const routes = new Map();
|
|
583
|
+
for (const tier of learnedTiers(workflows)) {
|
|
584
|
+
if (tierModelOf(env, tier) === undefined)
|
|
585
|
+
continue;
|
|
586
|
+
try {
|
|
587
|
+
routes.set(tier, await routeOf(tier));
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
routes.set(tier, { why: String(error?.message ?? error).slice(0, 300) });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return routes;
|
|
594
|
+
}
|
|
452
595
|
/** The run's learned_workflow tool as a HostTool, listed when the run has it (learnsWorkflows: an agentic revision whose
|
|
453
596
|
* agent learned workflows, by learning.ts chooseWorkflows as main's start chooses them, so the tool set the model sees
|
|
454
597
|
* matches main). `granted`, the revision's own tools, are the ones its workflows' call nodes may call. Every run's session — pi's and every CLI harness's — has a model
|
|
@@ -459,9 +602,21 @@ export async function learnedWorkflowHostTool(opts) {
|
|
|
459
602
|
if (!learnsWorkflows(opts.kind, opts.workflows))
|
|
460
603
|
return undefined;
|
|
461
604
|
const flows = opts.workflows;
|
|
462
|
-
const
|
|
605
|
+
const tiers = opts.tiers ?? new Map();
|
|
463
606
|
const mcpTools = (opts.mcp?.tools ?? []).map((one) => opts.mcp.catalogOf(one.name)).filter((name) => typeof name === "string");
|
|
464
|
-
const
|
|
607
|
+
const byProvider = new Map([[PORT_PROVIDER, await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL)]]);
|
|
608
|
+
for (const [tier, model] of tiers)
|
|
609
|
+
if ("model" in model)
|
|
610
|
+
byProvider.set(tierProvider(tier), await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL, tier));
|
|
611
|
+
const modelOf = (tier) => {
|
|
612
|
+
const model = tier === undefined ? undefined : tiers.get(tier);
|
|
613
|
+
if (model === undefined)
|
|
614
|
+
return { provider: PORT_PROVIDER, modelId: "session" };
|
|
615
|
+
if ("why" in model)
|
|
616
|
+
throw new Error(`the run's ${tier} model could not be reached: ${model.why}`);
|
|
617
|
+
return { provider: tierProvider(tier), modelId: model.model };
|
|
618
|
+
};
|
|
619
|
+
const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: tieredModels(byProvider), modelOf, policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools, ...(opts.modelName ? { modelName: opts.modelName } : {}) });
|
|
465
620
|
return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
|
|
466
621
|
}
|
|
467
622
|
/** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
|
|
@@ -558,7 +713,7 @@ export async function webHostTools(host, granted, ctx) {
|
|
|
558
713
|
}
|
|
559
714
|
return tools;
|
|
560
715
|
}
|
|
561
|
-
async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, mcp) {
|
|
716
|
+
async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, tiers, mcp, modelName) {
|
|
562
717
|
// Fail closed (browserListed): the browser binds only on the native route (BROWSER_ON_RUNNER) and with the claim's
|
|
563
718
|
// one-ledger booking on its ToolHost (host.ledger.paid); otherwise its extension is not installed. learned_workflow
|
|
564
719
|
// binds below with no web tool, so a learned run with no web tool still lists it.
|
|
@@ -571,7 +726,7 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
|
|
|
571
726
|
// the session's tools the harness is told of: its model nodes run on the session's proxied models (run.ledger.models),
|
|
572
727
|
// each a request on the run's one route labelled learned_workflow. The agent's scoped keys (host.env) are its call
|
|
573
728
|
// nodes'.
|
|
574
|
-
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, ...(mcp ? { mcp } : {}) });
|
|
729
|
+
const learned = await learnedWorkflowHostTool({ run, kind, granted, plane, env: host.env, work: root, workflows, permissions, ctx, tiers, ...(mcp ? { mcp } : {}), ...(modelName ? { modelName } : {}) });
|
|
575
730
|
if (learned)
|
|
576
731
|
tools.push(learned);
|
|
577
732
|
// The browser (tl-browser), on pi's native route: tools.ts's own binding on this run's ToolHost (its store, claim and seal
|