@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { Models } from "@earendil-works/pi-ai";
|
|
3
|
-
import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
|
|
4
|
-
import { type AgentAdapter, type SessionIO, type Wire } from "@parcha/agentrun-kernel";
|
|
5
|
-
import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
|
|
3
|
+
import { type Extension, type Harness, type Registry, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
+
import { type AgentAdapter, type SessionIO, type SessionPort, type Wire } from "@parcha/agentrun-kernel";
|
|
5
|
+
import { type ModelProxy, type ProviderPolicy } from "@parcha/agentrun-kernel/host";
|
|
6
6
|
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
7
7
|
/** What the adapter loop lends pi for one claim: the run's Harness, its registry, and where pi's models go. */
|
|
8
8
|
export interface PiRun {
|
|
@@ -16,6 +16,17 @@ export interface PreIntentCall {
|
|
|
16
16
|
readonly callId: string;
|
|
17
17
|
readonly tool: string;
|
|
18
18
|
readonly args: Record<string, unknown>;
|
|
19
|
+
/** An earlier attempt of the call may have been sent (a CLI's kernel bridge, asking about a replay-safe call a crash
|
|
20
|
+
* cut: GateCall's `replayed`), so a refusal never says nothing was. */
|
|
21
|
+
readonly replayed?: true;
|
|
22
|
+
/** The tool calls the call's conversation made before it, at most `upTo`, read from its committed entries (tool-budget.ts
|
|
23
|
+
* countCalls), for the gate's tool-call budget: pi's model-issued calls only, never a nested call or a CLI's. */
|
|
24
|
+
readonly callsBefore?: (upTo: number) => Promise<number>;
|
|
25
|
+
/** The call's conversation's own tool-call budget (tool-budget.ts ConversationToolBudget, a subagent's), if it has one. */
|
|
26
|
+
readonly ownBudget?: () => Promise<number | undefined>;
|
|
27
|
+
/** A call a running tool made (pi's nested call), part of a call already let through: the cap's wrap-up never refuses
|
|
28
|
+
* one (tool-budget.ts), so a tool in flight is never cut short. */
|
|
29
|
+
readonly nested?: true;
|
|
19
30
|
}
|
|
20
31
|
/** The host's answer before a call's intent: run it, refuse it, or park the run on it (the call never moves on here). */
|
|
21
32
|
export type PreIntentAnswer = "allow" | {
|
|
@@ -66,9 +77,34 @@ export interface PiAdapterOptions {
|
|
|
66
77
|
* claim's Harness. Their tools pass the session's gate (its beforeTool hook), and every conversation they open takes
|
|
67
78
|
* its model from the root's agent, through this session's proxy and its booking. */
|
|
68
79
|
readonly extensions?: readonly Extension[];
|
|
80
|
+
/** pi-native tools the session's own extension carries beside its host tools (the subagent tool: runner/subagent.ts):
|
|
81
|
+
* pi's own tool tasks, under the session's gate like every call. Read when the session opens. A conversation one of
|
|
82
|
+
* them opens keeps the session's extension, so its calls pass the same gate; its own `tools` say which it is offered. */
|
|
83
|
+
readonly tools?: readonly ToolRegistration[];
|
|
84
|
+
/** The run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST,
|
|
85
|
+
* AGENT_MODEL_STRONG), by tier, each a model route as the session's is: read when the session opens, each on a proxy of
|
|
86
|
+
* its own beside the session's (its origin, credential, price and fetch), on the session's booking (io.models), so its
|
|
87
|
+
* requests are the run's, under its one cap, each priced at its own model. Reached through `port(label, tier)`. */
|
|
88
|
+
readonly tiers?: ReadonlyMap<string, TierModel>;
|
|
69
89
|
}
|
|
70
90
|
/** pi as an AgentAdapter for one claim's run. */
|
|
71
91
|
export declare function piAdapter(options: PiAdapterOptions): AgentAdapter;
|
|
92
|
+
/** A tier's model as its proxy takes it: its route's provider, model, catalog entry, price and fetch (model-route.ts). */
|
|
93
|
+
export type TierModel = Pick<PiAdapterOptions, "provider" | "model" | "like" | "price" | "fetch">;
|
|
94
|
+
/** The tier proxies a session holds (openTierProxies): each tier's port for a side request under `label`, and their close. */
|
|
95
|
+
export interface TierProxies {
|
|
96
|
+
port(label: string, tier: string): SessionPort | undefined;
|
|
97
|
+
/** Each tier, its route and its proxy: a subagent's child on the tier is sent there on the proxy's own key. */
|
|
98
|
+
readonly each: readonly (readonly [string, TierModel, ModelProxy])[];
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/** A run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST, AGENT_MODEL_STRONG),
|
|
102
|
+
* each on a proxy of its own beside the session's, on the session's booking (`hooks`, io.models): the one way every
|
|
103
|
+
* harness serves them, pi's session and a CLI harness's (cli-run-spec.ts). Only the host's own requests reach them (side
|
|
104
|
+
* keys, AdapterSession.port's `tier`), sent by pi-ai's client of the tier model's own wire (port-models.ts), so a tier
|
|
105
|
+
* proxy speaks its model's route (model-route.ts routeOf, its translation fetch for a model of neither wire), never the
|
|
106
|
+
* harness's. One that fails to start closes those started. */
|
|
107
|
+
export declare function openTierProxies(tiers: ReadonlyMap<string, TierModel>, hooks: SessionIO["models"], redact?: (text: string) => string, tools?: readonly string[]): Promise<TierProxies>;
|
|
72
108
|
/** The session proxy's policy on Messages: claude-agent's (no fork), with pi's tools, the host's own names (`tools`), as
|
|
73
109
|
* the names its client offers by themselves (its builtins). The CLI's own `mcp__hands__` prefix is not pi's: under it
|
|
74
110
|
* every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
|
|
@@ -6,9 +6,10 @@ import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
|
6
6
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
8
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
9
|
-
import { sessionProvider } from "../../port-models.js";
|
|
9
|
+
import { sessionProvider, tierProvider } from "../../port-models.js";
|
|
10
10
|
import { KINDS } from "../journal-kinds.js";
|
|
11
11
|
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
12
|
+
import { ConversationToolBudget, countCalls } from "../../tool-budget.js";
|
|
12
13
|
const PROVIDER = "agentrun-session";
|
|
13
14
|
const INPUT_REQUEST = "agentrun:input";
|
|
14
15
|
/** pi as an AgentAdapter for one claim's run. */
|
|
@@ -21,35 +22,75 @@ export function piAdapter(options) {
|
|
|
21
22
|
open: (spec, io) => openPi(options, spec, io),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
/** The names of the run's pi-native extensions'
|
|
25
|
+
/** The names of the run's pi-native tools (options.extensions' and options.tools): the model is offered them beside the session's
|
|
25
26
|
* own (so it may call one), and pi runs it. Offered and run by one mechanism; sessionOn never also piTool-wraps a session
|
|
26
27
|
* tool a native extension already owns, so the name is in the request's tools exactly once. */
|
|
27
|
-
const nativeToolNames = (options) => (options.extensions ?? []).flatMap((extension) => extension.tools ?? []).map((tool) => tool.name);
|
|
28
|
+
const nativeToolNames = (options) => [...(options.extensions ?? []).flatMap((extension) => extension.tools ?? []), ...(options.tools ?? [])].map((tool) => tool.name);
|
|
28
29
|
async function openPi(options, spec, io) {
|
|
29
|
-
const { model } = options;
|
|
30
30
|
const context = withAbortSignal(io.signal, BACKGROUND_CONTEXT);
|
|
31
31
|
// The session's route: pi-ai's requests reach the provider only through this proxy, which admits and books each one
|
|
32
32
|
// through the runner's booking (io.models).
|
|
33
|
-
const proxy = await
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
origin: options.provider.origin,
|
|
38
|
-
credential: async () => (await options.provider.credential()) ?? "",
|
|
39
|
-
...(options.price ? { price: options.price } : {}),
|
|
40
|
-
...(options.provider.headers ? { headers: options.provider.headers } : {}),
|
|
41
|
-
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
42
|
-
...(options.redact ? { redact: options.redact } : {}),
|
|
43
|
-
}, randomBytes(32).toString("base64url"));
|
|
44
|
-
// An open that fails from here (the claim lost while the session opened) closes the proxy: its server would hold the
|
|
45
|
-
// runner's process open.
|
|
33
|
+
const proxy = await routeProxy(options, io.models, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)], options.redact);
|
|
34
|
+
// An open that fails from here (the claim lost while the session opened) closes the proxies: their servers would hold
|
|
35
|
+
// the runner's process open.
|
|
36
|
+
let tiers;
|
|
46
37
|
try {
|
|
47
|
-
|
|
38
|
+
// A tier's proxy admits the session's tools too: a subagent's child on the tier offers them (runner/subagent.ts).
|
|
39
|
+
tiers = await openTierProxies(options.tiers ?? new Map(), io.models, options.redact, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)]);
|
|
40
|
+
return await sessionOn(proxy, options, spec, io, context, tiers);
|
|
48
41
|
}
|
|
49
42
|
catch (error) {
|
|
50
43
|
await proxy.close().catch(() => undefined);
|
|
44
|
+
await tiers?.close();
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A proxy on `hooks` (the session's booking: its requests are the run's, under its one cap) for `route`'s model, with its
|
|
49
|
+
* origin, credential, price and fetch, its provider's errors through `redact`. `tools`: the tool names its policy admits
|
|
50
|
+
* by name on a request of the session's own key (none for a tier's: only side keys reach it). */
|
|
51
|
+
async function routeProxy(route, hooks, tools, redact, tier) {
|
|
52
|
+
return startModelProxy({
|
|
53
|
+
// A tier's proxy names its tier on each request (ModelRequest.route), so the run's cap prices it as this route books it.
|
|
54
|
+
...(tier === undefined ? {} : { route: tier }),
|
|
55
|
+
policy: await policyFor(route.provider, route.model, tools),
|
|
56
|
+
hooks,
|
|
57
|
+
model: route.model,
|
|
58
|
+
origin: route.provider.origin,
|
|
59
|
+
credential: async () => (await route.provider.credential()) ?? "",
|
|
60
|
+
...(route.price ? { price: route.price } : {}),
|
|
61
|
+
...(route.provider.headers ? { headers: route.provider.headers } : {}),
|
|
62
|
+
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
63
|
+
...(redact ? { redact } : {}),
|
|
64
|
+
}, randomBytes(32).toString("base64url"));
|
|
65
|
+
}
|
|
66
|
+
/** A run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST, AGENT_MODEL_STRONG),
|
|
67
|
+
* each on a proxy of its own beside the session's, on the session's booking (`hooks`, io.models): the one way every
|
|
68
|
+
* harness serves them, pi's session and a CLI harness's (cli-run-spec.ts). Only the host's own requests reach them (side
|
|
69
|
+
* keys, AdapterSession.port's `tier`), sent by pi-ai's client of the tier model's own wire (port-models.ts), so a tier
|
|
70
|
+
* proxy speaks its model's route (model-route.ts routeOf, its translation fetch for a model of neither wire), never the
|
|
71
|
+
* harness's. One that fails to start closes those started. */
|
|
72
|
+
export async function openTierProxies(tiers, hooks, redact, tools = []) {
|
|
73
|
+
const open = new Map();
|
|
74
|
+
const close = async () => {
|
|
75
|
+
for (const { proxy } of open.values())
|
|
76
|
+
await proxy.close().catch(() => undefined);
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
for (const [tier, route] of tiers)
|
|
80
|
+
open.set(tier, { proxy: await routeProxy(route, hooks, tools, redact, tier), route });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
await close();
|
|
51
84
|
throw error;
|
|
52
85
|
}
|
|
86
|
+
return {
|
|
87
|
+
port: (label, tier) => {
|
|
88
|
+
const at = open.get(tier);
|
|
89
|
+
return at ? { url: at.proxy.url, key: at.proxy.sideKey(label), model: at.route.model, api: at.route.provider.api } : undefined;
|
|
90
|
+
},
|
|
91
|
+
each: [...open].map(([tier, { proxy, route }]) => [tier, route, proxy]),
|
|
92
|
+
close,
|
|
93
|
+
};
|
|
53
94
|
}
|
|
54
95
|
/** The session proxy's policy on Messages: claude-agent's (no fork), with pi's tools, the host's own names (`tools`), as
|
|
55
96
|
* the names its client offers by themselves (its builtins). The CLI's own `mcp__hands__` prefix is not pi's: under it
|
|
@@ -71,7 +112,7 @@ export async function policyFor(provider, model, tools) {
|
|
|
71
112
|
return codexPolicy({ model, tools });
|
|
72
113
|
}
|
|
73
114
|
/** The session on its proxy: pi's models through it, the host's tools and the gate as pi's extension, the root's state. */
|
|
74
|
-
async function sessionOn(proxy, options, spec, io, context) {
|
|
115
|
+
async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
75
116
|
const { run, model, like } = options;
|
|
76
117
|
const { api } = options.provider;
|
|
77
118
|
const models = createModels();
|
|
@@ -79,11 +120,30 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
79
120
|
// proxy's booking does), so the model's cost stays $0. Image input on either wire (sessionModel): a host tool's images
|
|
80
121
|
// (a screenshot) reach the model in its tool result.
|
|
81
122
|
models.setProvider(sessionProvider(api, proxy, model, { provider: PROVIDER, keyName: "AGENTRUN_SESSION_KEY", ...(like ? { like } : {}), reasoning: false }));
|
|
82
|
-
|
|
123
|
+
// Each tier's model at its own proxy, under its own provider id (tierProvider): a conversation whose agent names it
|
|
124
|
+
// (a subagent's) is sent there, and booked as the session's own requests are.
|
|
125
|
+
for (const [tier, route, at] of tiers.each)
|
|
126
|
+
models.setProvider(sessionProvider(route.provider.api, at, route.model, { provider: tierProvider(tier), keyName: "AGENTRUN_SESSION_KEY", ...(route.like ? { like: route.like } : {}), reasoning: false }));
|
|
127
|
+
// A child made on an earlier claim keeps the tier's model it was made on; when the tier's model has changed since (the
|
|
128
|
+
// server's AGENT_MODEL_STRONG, say), that one is not here, and the child resumes on the tier's model now, as a new call
|
|
129
|
+
// on the tier would run.
|
|
130
|
+
const tierModel = new Map(tiers.each.map(([tier, route]) => [tierProvider(tier), route.model]));
|
|
131
|
+
run.setModels(tierModel.size === 0 ? models : new Proxy(models, {
|
|
132
|
+
get(target, key) {
|
|
133
|
+
if (key === "getModel")
|
|
134
|
+
return (provider, id) => target.getModel(provider, id) ?? (tierModel.has(provider) ? target.getModel(provider, tierModel.get(provider)) : undefined);
|
|
135
|
+
const value = Reflect.get(target, key, target);
|
|
136
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
137
|
+
},
|
|
138
|
+
}));
|
|
83
139
|
// A session tool whose name a native extension already owns is run by that extension (pi's own tool task), so it is not
|
|
84
140
|
// piTool-wrapped here too: one tool by that name on the agent, offered once.
|
|
85
141
|
const owned = new Set(nativeToolNames(options));
|
|
86
|
-
|
|
142
|
+
// The calls the gate let through in this session, before their intent. pi runs a call's beforeTool only before its
|
|
143
|
+
// intent: a call it runs with no pass here is one it reruns after a crash (a replay-safe call whose intent an earlier
|
|
144
|
+
// attempt stored), told to the host tool as an attempt above 0, so the loop asks the gate about it again.
|
|
145
|
+
const passed = new Set();
|
|
146
|
+
const tools = [...spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined))), ...(options.tools ?? [])];
|
|
87
147
|
// A refused call's words (the gate's deny, main's), by call: its result is those words alone, as main gives them.
|
|
88
148
|
const refusals = refusalWords();
|
|
89
149
|
const extension = defineExtension({
|
|
@@ -91,12 +151,17 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
91
151
|
tools,
|
|
92
152
|
hooks: [
|
|
93
153
|
hook(ToolTask, {
|
|
94
|
-
beforeTool: async (call,
|
|
154
|
+
beforeTool: async (call, api, hookContext) => {
|
|
95
155
|
if (!io.gate)
|
|
96
156
|
return undefined;
|
|
97
|
-
|
|
98
|
-
|
|
157
|
+
// A model-issued call's count, read only when the gate holds a budget: a nested call (one a tool made) is its
|
|
158
|
+
// parent's part, and is marked so (the cap's wrap-up lets it through).
|
|
159
|
+
const counted = call.parent === undefined ? { callsBefore: (upTo) => callsBefore(api, call.id, upTo, hookContext), ownBudget: async () => (await api.snapshot(ConversationToolBudget, api.conversationId, hookContext))?.toolCalls } : { nested: true };
|
|
160
|
+
const answer = await io.gate({ callId: call.id, tool: call.name, args: (call.arguments ?? {}), ...counted }, hookContext);
|
|
161
|
+
if (answer === "allow") {
|
|
162
|
+
passed.add(call.id);
|
|
99
163
|
return undefined;
|
|
164
|
+
}
|
|
100
165
|
if ("deny" in answer) {
|
|
101
166
|
refusals.refuse(call.id, answer.deny);
|
|
102
167
|
return { block: answer.deny };
|
|
@@ -152,7 +217,14 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
152
217
|
const existing = await run.harness.commit((tx) => tx.submissionByRequest(root.id, INPUT_REQUEST), context);
|
|
153
218
|
if (existing)
|
|
154
219
|
input = await run.harness.submission(existing.id, context);
|
|
155
|
-
|
|
220
|
+
// Once that first input is settled, a later input of the root still in flight (a follow-up a reopen sent, its turn cut by
|
|
221
|
+
// a lost claim or a drain) is the turn the session is in: its end is the one recover() reads, never the first input's.
|
|
222
|
+
const later = existing && (existing.status === "done" || existing.status === "unanswered")
|
|
223
|
+
? (await run.harness.inspect(context)).submissions.filter((one) => one.conversationId === root.id && one.type === "input").at(-1)
|
|
224
|
+
: undefined;
|
|
225
|
+
if (later)
|
|
226
|
+
input = await run.harness.submission(later.id, context);
|
|
227
|
+
let state = existing === undefined ? "new" : later ? "open_turn" : existing.status === "done" ? "idle" : "open_turn";
|
|
156
228
|
let running;
|
|
157
229
|
const watch = (submission) => {
|
|
158
230
|
running = submission.wait(context).then((record) => {
|
|
@@ -200,11 +272,17 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
200
272
|
async close() {
|
|
201
273
|
closed = true;
|
|
202
274
|
await proxy.close().catch(() => undefined);
|
|
275
|
+
await tiers.close();
|
|
203
276
|
},
|
|
204
277
|
// The session's own model route for a request the host sends beside pi's (a learned workflow's model node): its proxy
|
|
205
278
|
// with a side key minted for `label`, pi's model and the provider's wire (never a literal), so the request goes through
|
|
206
|
-
// the same policy, origin, credential, price and booking as pi's own, labelled.
|
|
207
|
-
|
|
279
|
+
// the same policy, origin, credential, price and booking as pi's own, labelled. `tier`: that tier's proxy and model
|
|
280
|
+
// instead (options.tiers), on the same booking; none for a tier the session has no proxy of. None once closed.
|
|
281
|
+
port: (label, tier) => {
|
|
282
|
+
if (closed)
|
|
283
|
+
return undefined;
|
|
284
|
+
return tier === undefined ? { url: proxy.url, key: proxy.sideKey(label), model, api } : tiers.port(label, tier);
|
|
285
|
+
},
|
|
208
286
|
// A steer: pi places it in the turn in flight, at its next boundary. `id`: its request id (the command's), so the
|
|
209
287
|
// commit that places it is the one that takes its row. `origin` (a trigger's message): its input is the host's user
|
|
210
288
|
// entry (KINDS.input) with that origin, in the same submission, so the attribution lands with the message or not at all.
|
|
@@ -239,6 +317,20 @@ export function refusalWords() {
|
|
|
239
317
|
},
|
|
240
318
|
};
|
|
241
319
|
}
|
|
320
|
+
/** The tool calls a hook's conversation made before `callId`, at most `upTo`: its committed entries read oldest first, a
|
|
321
|
+
* page at a time, only as far as the count needs (tool-budget.ts countCalls). */
|
|
322
|
+
async function callsBefore(api, callId, upTo, context) {
|
|
323
|
+
let counted = { count: 0, done: upTo <= 0 };
|
|
324
|
+
let cursor;
|
|
325
|
+
while (!counted.done) {
|
|
326
|
+
const page = await api.entries({ order: "ascending" }, 100, cursor, context);
|
|
327
|
+
counted = countCalls(page.items, callId, upTo, counted.count);
|
|
328
|
+
cursor = page.next;
|
|
329
|
+
if (cursor === undefined)
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
return counted.count;
|
|
333
|
+
}
|
|
242
334
|
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
243
335
|
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
244
336
|
* default (50 KB or 2,000 lines, its head kept) would cut the end off a host tool's answer, where the answer says how to
|
|
@@ -249,8 +341,9 @@ export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS
|
|
|
249
341
|
/** A host tool as a pi tool: replay-safe or at most once, its answer the host's text and any images it shows, passed
|
|
250
342
|
* whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
|
|
251
343
|
* agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
|
|
252
|
-
* and pi's output stream (the running tool's live slot)
|
|
253
|
-
|
|
344
|
+
* and pi's output stream (the running tool's live slot); and its attempt (`attemptOf`: above 0 for a call the gate did
|
|
345
|
+
* not pass in this session, pi's rerun after a crash). */
|
|
346
|
+
function piTool(tool, io, attemptOf = () => undefined) {
|
|
254
347
|
return defineTool({
|
|
255
348
|
name: tool.name,
|
|
256
349
|
description: tool.description,
|
|
@@ -259,12 +352,14 @@ function piTool(tool, io) {
|
|
|
259
352
|
outputLimits: HOST_TOOL_OUTPUT,
|
|
260
353
|
execute: async (args, api, toolContext) => {
|
|
261
354
|
io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
|
|
355
|
+
const attempt = attemptOf(api.callId);
|
|
262
356
|
const ref = (await api.agent(toolContext)).model;
|
|
263
357
|
const model = ref === undefined ? undefined : api.models.getModel(ref.provider, ref.modelId);
|
|
264
358
|
const answer = await tool.call(args ?? {}, {
|
|
265
359
|
callId: api.callId, signal: toolContext.abortSignal ?? io.signal,
|
|
266
360
|
...(model ? { model } : {}),
|
|
267
361
|
output: (chunk) => api.output(chunk),
|
|
362
|
+
...(attempt === undefined ? {} : { attempt }),
|
|
268
363
|
});
|
|
269
364
|
io.onEvent({ type: "tool_end", callId: api.callId, name: tool.name, isError: Boolean(answer.isError), result: answer.text });
|
|
270
365
|
const images = (answer.images ?? []).map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }));
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -37,3 +37,11 @@ export declare function runnerBeside(dataDir: string, { loops, drainMs, env, jan
|
|
|
37
37
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
38
38
|
close: () => Promise<void>;
|
|
39
39
|
}>;
|
|
40
|
+
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
41
|
+
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
42
|
+
* server's runs reach its fakes. For a launcher that starts serve in-process (a demo, a smoke): a server alone leaves
|
|
43
|
+
* every run queued. close() stops both. */
|
|
44
|
+
export declare function serveWithRunner(options: import("../server.js").ServeOptions): Promise<{
|
|
45
|
+
serve: import("../server.js").Serve;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
}>;
|
package/dist/runner/beside.js
CHANGED
|
@@ -58,7 +58,9 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {
|
|
|
58
58
|
const runs = env ?? runEnv(process.env);
|
|
59
59
|
const { dockerPathsForRuns } = await import("../box-paths.js");
|
|
60
60
|
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
61
|
-
const
|
|
61
|
+
const { PROVIDERS } = await import("@parcha/agentrun-computer");
|
|
62
|
+
const { hostCommandRefusals } = await import("../computers.js");
|
|
63
|
+
const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
|
|
62
64
|
const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
|
|
63
65
|
// It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
|
|
64
66
|
const { runnerMemory } = await import("./memory-claim.js");
|
|
@@ -67,6 +69,26 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {
|
|
|
67
69
|
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
68
70
|
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
69
71
|
const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
|
|
72
|
+
// Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
|
|
73
|
+
const { claimInstallsStopped } = await import("../harness-install.js");
|
|
70
74
|
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
71
|
-
return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
|
|
75
|
+
return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await claimInstallsStopped(); await store.close(); seal.release(); } };
|
|
76
|
+
}
|
|
77
|
+
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
78
|
+
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
79
|
+
* server's runs reach its fakes. For a launcher that starts serve in-process (a demo, a smoke): a server alone leaves
|
|
80
|
+
* every run queued. close() stops both. */
|
|
81
|
+
export async function serveWithRunner(options) {
|
|
82
|
+
const { fauxEnvOf, startServe } = await import("../server.js");
|
|
83
|
+
const { besideRunEnv } = await import("./main.js");
|
|
84
|
+
const { loops, drainMs } = besideRunnerOptions(options, process.env);
|
|
85
|
+
const serve = await startServe(options);
|
|
86
|
+
const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)) }).catch(async (error) => {
|
|
87
|
+
await serve.close();
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
// Once: a second call (a SIGTERM and a SIGINT both) is the first one's promise, so the runner's store is never closed
|
|
91
|
+
// under a run still finishing.
|
|
92
|
+
let closing;
|
|
93
|
+
return { serve, close: () => (closing ??= Promise.all([beside.close(), serve.close()]).then(() => undefined)) };
|
|
72
94
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LearnedWorkflow } from "../learning.js";
|
|
2
|
+
import { type Tier } from "../model.js";
|
|
2
3
|
import type { RunLaunch } from "../run-launch.js";
|
|
3
4
|
import type { SealedKeys } from "../store/store.js";
|
|
4
5
|
import type { Revision } from "../agent-rows.js";
|
|
@@ -24,6 +25,11 @@ export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision,
|
|
|
24
25
|
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
25
26
|
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
26
27
|
export declare function learnedDecisionKeys(deps: ClaimSecretsDeps, workflows: readonly Pick<LearnedWorkflow, "workflow">[], allowed: (provider: string) => boolean): Promise<Record<string, string>>;
|
|
28
|
+
/** The model keys the host's models of `tiers` need (model.ts modelKeys: each one's provider's, or the gateway's), read as
|
|
29
|
+
* claimSecrets reads a run's (the runner's environment first, then the key saved in Settings → Model keys), for a run's
|
|
30
|
+
* learned workflow nodes of those tiers (adapter-run-spec.ts learnedTierRoutes): claimSecrets opens only the run's own
|
|
31
|
+
* model's. For the tiers' routes alone, through withModelKeys (never enumerable), never onto a tool's environment. */
|
|
32
|
+
export declare function tierModelKeys(deps: ClaimSecretsDeps, tiers: readonly Tier[]): Promise<NodeJS.ProcessEnv>;
|
|
27
33
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
28
34
|
export declare const MODEL_KEY_NAMES: readonly string[];
|
|
29
35
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// one runner never see each other's keys: each claim reads its own, into its own environment. (MCP credentials are the
|
|
8
8
|
// other per-claim secret; they come through mcp-claim.ts, which already opens them from the store under the claim.)
|
|
9
9
|
import { decisionKeysFor, providersNamed } from "../decisions.js";
|
|
10
|
-
import { GATEWAY_KEY_ENV, PROVIDER_KEYS, workflowNodes } from "../model.js";
|
|
10
|
+
import { GATEWAY_KEY_ENV, modelKeys, PROVIDER_KEYS, workflowNodes } from "../model.js";
|
|
11
11
|
import { keysFor, needsOf, RUN_SECRETS } from "../run-secrets.js";
|
|
12
12
|
import { DECISION_KEYS, withoutSecrets } from "../secrets.js";
|
|
13
13
|
import { getSealedKey } from "../server-keys.js";
|
|
@@ -78,6 +78,20 @@ export async function learnedDecisionKeys(deps, workflows, allowed) {
|
|
|
78
78
|
return {};
|
|
79
79
|
return decisionKeysFor(await workingEnv(deps), { providers, parallelWeb: false });
|
|
80
80
|
}
|
|
81
|
+
/** The model keys the host's models of `tiers` need (model.ts modelKeys: each one's provider's, or the gateway's), read as
|
|
82
|
+
* claimSecrets reads a run's (the runner's environment first, then the key saved in Settings → Model keys), for a run's
|
|
83
|
+
* learned workflow nodes of those tiers (adapter-run-spec.ts learnedTierRoutes): claimSecrets opens only the run's own
|
|
84
|
+
* model's. For the tiers' routes alone, through withModelKeys (never enumerable), never onto a tool's environment. */
|
|
85
|
+
export async function tierModelKeys(deps, tiers) {
|
|
86
|
+
if (!tiers.length)
|
|
87
|
+
return {};
|
|
88
|
+
const working = await workingEnv(deps);
|
|
89
|
+
const out = {};
|
|
90
|
+
for (const name of modelKeys(working, undefined, tiers))
|
|
91
|
+
if (working[name] !== undefined)
|
|
92
|
+
out[name] = working[name];
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
81
95
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
82
96
|
export const MODEL_KEY_NAMES = [...new Set([...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV])];
|
|
83
97
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -9,6 +9,16 @@ export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./
|
|
|
9
9
|
export type CliSpecDeps = AdapterSpecDeps;
|
|
10
10
|
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
11
11
|
export declare const cliRefusesKind: (kind: string) => string | undefined;
|
|
12
|
+
/** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
|
|
13
|
+
* name), as main listed a CLI run's tools to its harness: each granted tool where its grant is, and a tool the grant
|
|
14
|
+
* does not name (one a granted tool or the run's computer brings beside it) right after the tool listed before it. Ties
|
|
15
|
+
* keep the order given. */
|
|
16
|
+
export declare function inGrantOrder<T extends {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
}>(tools: readonly T[], granted: readonly string[]): T[];
|
|
19
|
+
/** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
|
|
20
|
+
* laid things in since (a follow-up's) stays, with what is in it. */
|
|
21
|
+
export declare function sweepScratch(dir: string, parents: readonly string[]): Promise<void>;
|
|
12
22
|
/**
|
|
13
23
|
* One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
|
|
14
24
|
*
|