@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { Models } from "@earendil-works/pi-ai";
|
|
3
3
|
import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
|
|
4
|
-
import type
|
|
4
|
+
import { type AgentAdapter, type SessionIO, type SessionPort, type Wire } from "@parcha/agentrun-kernel";
|
|
5
5
|
import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
|
|
6
|
-
import { CALL_REFUSED } from "
|
|
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 {
|
|
9
9
|
readonly harness: Harness;
|
|
@@ -16,6 +16,15 @@ 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
|
+
/** A call a running tool made (pi's nested call), part of a call already let through: the cap's wrap-up never refuses
|
|
26
|
+
* one (tool-budget.ts), so a tool in flight is never cut short. */
|
|
27
|
+
readonly nested?: true;
|
|
19
28
|
}
|
|
20
29
|
/** 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
30
|
export type PreIntentAnswer = "allow" | {
|
|
@@ -66,9 +75,28 @@ export interface PiAdapterOptions {
|
|
|
66
75
|
* claim's Harness. Their tools pass the session's gate (its beforeTool hook), and every conversation they open takes
|
|
67
76
|
* its model from the root's agent, through this session's proxy and its booking. */
|
|
68
77
|
readonly extensions?: readonly Extension[];
|
|
78
|
+
/** The run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST,
|
|
79
|
+
* AGENT_MODEL_STRONG), by tier, each a model route as the session's is: read when the session opens, each on a proxy of
|
|
80
|
+
* its own beside the session's (its origin, credential, price and fetch), on the session's booking (io.models), so its
|
|
81
|
+
* requests are the run's, under its one cap, each priced at its own model. Reached through `port(label, tier)`. */
|
|
82
|
+
readonly tiers?: ReadonlyMap<string, TierModel>;
|
|
69
83
|
}
|
|
70
84
|
/** pi as an AgentAdapter for one claim's run. */
|
|
71
85
|
export declare function piAdapter(options: PiAdapterOptions): AgentAdapter;
|
|
86
|
+
/** A tier's model as its proxy takes it: its route's provider, model, catalog entry, price and fetch (model-route.ts). */
|
|
87
|
+
export type TierModel = Pick<PiAdapterOptions, "provider" | "model" | "like" | "price" | "fetch">;
|
|
88
|
+
/** The tier proxies a session holds (openTierProxies): each tier's port for a side request under `label`, and their close. */
|
|
89
|
+
export interface TierProxies {
|
|
90
|
+
port(label: string, tier: string): SessionPort | undefined;
|
|
91
|
+
close(): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
/** A run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST, AGENT_MODEL_STRONG),
|
|
94
|
+
* each on a proxy of its own beside the session's, on the session's booking (`hooks`, io.models): the one way every
|
|
95
|
+
* harness serves them, pi's session and a CLI harness's (cli-run-spec.ts). Only the host's own requests reach them (side
|
|
96
|
+
* keys, AdapterSession.port's `tier`), sent by pi-ai's client of the tier model's own wire (port-models.ts), so a tier
|
|
97
|
+
* proxy speaks its model's route (model-route.ts routeOf, its translation fetch for a model of neither wire), never the
|
|
98
|
+
* harness's. One that fails to start closes those started. */
|
|
99
|
+
export declare function openTierProxies(tiers: ReadonlyMap<string, TierModel>, hooks: SessionIO["models"], redact?: (text: string) => string): Promise<TierProxies>;
|
|
72
100
|
/** The session proxy's policy on Messages: claude-agent's (no fork), with pi's tools, the host's own names (`tools`), as
|
|
73
101
|
* the names its client offers by themselves (its builtins). The CLI's own `mcp__hands__` prefix is not pi's: under it
|
|
74
102
|
* every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
|
|
@@ -101,3 +129,13 @@ export declare function refusalWords(): {
|
|
|
101
129
|
} | undefined;
|
|
102
130
|
readonly held: number;
|
|
103
131
|
};
|
|
132
|
+
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
133
|
+
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
134
|
+
* 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
|
|
135
|
+
* go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
|
|
136
|
+
* continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
|
|
137
|
+
* Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
|
|
138
|
+
export declare const HOST_TOOL_OUTPUT: Readonly<{
|
|
139
|
+
maxLines: number;
|
|
140
|
+
maxBytes: number;
|
|
141
|
+
}>;
|
|
@@ -2,12 +2,14 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
|
|
|
2
2
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
3
|
import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
|
|
4
4
|
import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
|
|
5
|
+
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
5
6
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
6
7
|
import { randomBytes } from "node:crypto";
|
|
7
8
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
8
9
|
import { sessionProvider } from "../../port-models.js";
|
|
9
10
|
import { KINDS } from "../journal-kinds.js";
|
|
10
|
-
import { CALL_REFUSED } from "
|
|
11
|
+
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
12
|
+
import { countCalls } from "../../tool-budget.js";
|
|
11
13
|
const PROVIDER = "agentrun-session";
|
|
12
14
|
const INPUT_REQUEST = "agentrun:input";
|
|
13
15
|
/** pi as an AgentAdapter for one claim's run. */
|
|
@@ -29,27 +31,66 @@ async function openPi(options, spec, io) {
|
|
|
29
31
|
const context = withAbortSignal(io.signal, BACKGROUND_CONTEXT);
|
|
30
32
|
// The session's route: pi-ai's requests reach the provider only through this proxy, which admits and books each one
|
|
31
33
|
// through the runner's booking (io.models).
|
|
32
|
-
const proxy = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
origin: options.provider.origin,
|
|
37
|
-
credential: async () => (await options.provider.credential()) ?? "",
|
|
38
|
-
...(options.price ? { price: options.price } : {}),
|
|
39
|
-
...(options.provider.headers ? { headers: options.provider.headers } : {}),
|
|
40
|
-
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
41
|
-
...(options.redact ? { redact: options.redact } : {}),
|
|
42
|
-
}, randomBytes(32).toString("base64url"));
|
|
43
|
-
// An open that fails from here (the claim lost while the session opened) closes the proxy: its server would hold the
|
|
44
|
-
// runner's process open.
|
|
34
|
+
const proxy = await routeProxy(options, io.models, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)], options.redact);
|
|
35
|
+
// An open that fails from here (the claim lost while the session opened) closes the proxies: their servers would hold
|
|
36
|
+
// the runner's process open.
|
|
37
|
+
let tiers;
|
|
45
38
|
try {
|
|
46
|
-
|
|
39
|
+
tiers = await openTierProxies(options.tiers ?? new Map(), io.models, options.redact);
|
|
40
|
+
return await sessionOn(proxy, options, spec, io, context, tiers);
|
|
47
41
|
}
|
|
48
42
|
catch (error) {
|
|
49
43
|
await proxy.close().catch(() => undefined);
|
|
44
|
+
await tiers?.close();
|
|
50
45
|
throw error;
|
|
51
46
|
}
|
|
52
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) {
|
|
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, [], redact, tier), route });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
await close();
|
|
84
|
+
throw error;
|
|
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
|
+
close,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
53
94
|
/** The session proxy's policy on Messages: claude-agent's (no fork), with pi's tools, the host's own names (`tools`), as
|
|
54
95
|
* the names its client offers by themselves (its builtins). The CLI's own `mcp__hands__` prefix is not pi's: under it
|
|
55
96
|
* every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
|
|
@@ -70,7 +111,7 @@ export async function policyFor(provider, model, tools) {
|
|
|
70
111
|
return codexPolicy({ model, tools });
|
|
71
112
|
}
|
|
72
113
|
/** 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. */
|
|
73
|
-
async function sessionOn(proxy, options, spec, io, context) {
|
|
114
|
+
async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
74
115
|
const { run, model, like } = options;
|
|
75
116
|
const { api } = options.provider;
|
|
76
117
|
const models = createModels();
|
|
@@ -82,7 +123,11 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
82
123
|
// A session tool whose name a native extension already owns is run by that extension (pi's own tool task), so it is not
|
|
83
124
|
// piTool-wrapped here too: one tool by that name on the agent, offered once.
|
|
84
125
|
const owned = new Set(nativeToolNames(options));
|
|
85
|
-
|
|
126
|
+
// The calls the gate let through in this session, before their intent. pi runs a call's beforeTool only before its
|
|
127
|
+
// intent: a call it runs with no pass here is one it reruns after a crash (a replay-safe call whose intent an earlier
|
|
128
|
+
// attempt stored), told to the host tool as an attempt above 0, so the loop asks the gate about it again.
|
|
129
|
+
const passed = new Set();
|
|
130
|
+
const tools = spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined)));
|
|
86
131
|
// A refused call's words (the gate's deny, main's), by call: its result is those words alone, as main gives them.
|
|
87
132
|
const refusals = refusalWords();
|
|
88
133
|
const extension = defineExtension({
|
|
@@ -90,12 +135,17 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
90
135
|
tools,
|
|
91
136
|
hooks: [
|
|
92
137
|
hook(ToolTask, {
|
|
93
|
-
beforeTool: async (call,
|
|
138
|
+
beforeTool: async (call, api, hookContext) => {
|
|
94
139
|
if (!io.gate)
|
|
95
140
|
return undefined;
|
|
96
|
-
|
|
97
|
-
|
|
141
|
+
// A model-issued call's count, read only when the gate holds a budget: a nested call (one a tool made) is its
|
|
142
|
+
// parent's part, and is marked so (the cap's wrap-up lets it through).
|
|
143
|
+
const counted = call.parent === undefined ? { callsBefore: (upTo) => callsBefore(api, call.id, upTo, hookContext) } : { nested: true };
|
|
144
|
+
const answer = await io.gate({ callId: call.id, tool: call.name, args: (call.arguments ?? {}), ...counted }, hookContext);
|
|
145
|
+
if (answer === "allow") {
|
|
146
|
+
passed.add(call.id);
|
|
98
147
|
return undefined;
|
|
148
|
+
}
|
|
99
149
|
if ("deny" in answer) {
|
|
100
150
|
refusals.refuse(call.id, answer.deny);
|
|
101
151
|
return { block: answer.deny };
|
|
@@ -138,7 +188,8 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
138
188
|
// session's tools and the run's native extensions, on every open. A conversation a native tool opens takes this agent's
|
|
139
189
|
// model (pi copies its owner's), so its requests go through this session's proxy.
|
|
140
190
|
const instructions = spec.system.join("\n\n");
|
|
141
|
-
|
|
191
|
+
// Its thinking level, the session's (the run's effort), on every open; none leaves pi's default.
|
|
192
|
+
const agent = { model: { provider: PROVIDER, modelId: model }, extensions: [extension, ...native], ...(instructions ? { instructions } : {}), ...(spec.thinking ? { thinkingLevel: spec.thinking } : {}) };
|
|
142
193
|
const root = await run.harness.root(context, { agent });
|
|
143
194
|
await root.configure(agent, context);
|
|
144
195
|
// The run's input submission, if one was placed: its state says where the session is. Answered: idle. Open, or settled
|
|
@@ -198,11 +249,17 @@ async function sessionOn(proxy, options, spec, io, context) {
|
|
|
198
249
|
async close() {
|
|
199
250
|
closed = true;
|
|
200
251
|
await proxy.close().catch(() => undefined);
|
|
252
|
+
await tiers.close();
|
|
201
253
|
},
|
|
202
254
|
// The session's own model route for a request the host sends beside pi's (a learned workflow's model node): its proxy
|
|
203
255
|
// with a side key minted for `label`, pi's model and the provider's wire (never a literal), so the request goes through
|
|
204
|
-
// the same policy, origin, credential, price and booking as pi's own, labelled.
|
|
205
|
-
|
|
256
|
+
// the same policy, origin, credential, price and booking as pi's own, labelled. `tier`: that tier's proxy and model
|
|
257
|
+
// instead (options.tiers), on the same booking; none for a tier the session has no proxy of. None once closed.
|
|
258
|
+
port: (label, tier) => {
|
|
259
|
+
if (closed)
|
|
260
|
+
return undefined;
|
|
261
|
+
return tier === undefined ? { url: proxy.url, key: proxy.sideKey(label), model, api } : tiers.port(label, tier);
|
|
262
|
+
},
|
|
206
263
|
// A steer: pi places it in the turn in flight, at its next boundary. `id`: its request id (the command's), so the
|
|
207
264
|
// commit that places it is the one that takes its row. `origin` (a trigger's message): its input is the host's user
|
|
208
265
|
// entry (KINDS.input) with that origin, in the same submission, so the attribution lands with the message or not at all.
|
|
@@ -237,23 +294,49 @@ export function refusalWords() {
|
|
|
237
294
|
},
|
|
238
295
|
};
|
|
239
296
|
}
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
|
|
243
|
-
|
|
297
|
+
/** The tool calls a hook's conversation made before `callId`, at most `upTo`: its committed entries read oldest first, a
|
|
298
|
+
* page at a time, only as far as the count needs (tool-budget.ts countCalls). */
|
|
299
|
+
async function callsBefore(api, callId, upTo, context) {
|
|
300
|
+
let counted = { count: 0, done: upTo <= 0 };
|
|
301
|
+
let cursor;
|
|
302
|
+
while (!counted.done) {
|
|
303
|
+
const page = await api.entries({ order: "ascending" }, 100, cursor, context);
|
|
304
|
+
counted = countCalls(page.items, callId, upTo, counted.count);
|
|
305
|
+
cursor = page.next;
|
|
306
|
+
if (cursor === undefined)
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
return counted.count;
|
|
310
|
+
}
|
|
311
|
+
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
312
|
+
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
313
|
+
* 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
|
|
314
|
+
* go on: an MCP answer's "[cut at ...; the whole answer is in the run's files at <path>]", a read's "Use offset=<n> to
|
|
315
|
+
* continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
|
|
316
|
+
* Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
|
|
317
|
+
export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS + 1, maxBytes: HOST_RESULT_MAX_CHARS * 3 });
|
|
318
|
+
/** 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
|
|
319
|
+
* whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
|
|
320
|
+
* agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
|
|
321
|
+
* and pi's output stream (the running tool's live slot); and its attempt (`attemptOf`: above 0 for a call the gate did
|
|
322
|
+
* not pass in this session, pi's rerun after a crash). */
|
|
323
|
+
function piTool(tool, io, attemptOf = () => undefined) {
|
|
244
324
|
return defineTool({
|
|
245
325
|
name: tool.name,
|
|
246
326
|
description: tool.description,
|
|
247
327
|
parameters: tool.inputSchema,
|
|
248
328
|
replay: tool.replay === "safe" ? "safe" : "unsafe",
|
|
329
|
+
outputLimits: HOST_TOOL_OUTPUT,
|
|
249
330
|
execute: async (args, api, toolContext) => {
|
|
250
331
|
io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
|
|
332
|
+
const attempt = attemptOf(api.callId);
|
|
251
333
|
const ref = (await api.agent(toolContext)).model;
|
|
252
334
|
const model = ref === undefined ? undefined : api.models.getModel(ref.provider, ref.modelId);
|
|
253
335
|
const answer = await tool.call(args ?? {}, {
|
|
254
336
|
callId: api.callId, signal: toolContext.abortSignal ?? io.signal,
|
|
255
337
|
...(model ? { model } : {}),
|
|
256
338
|
output: (chunk) => api.output(chunk),
|
|
339
|
+
...(attempt === undefined ? {} : { attempt }),
|
|
257
340
|
});
|
|
258
341
|
io.onEvent({ type: "tool_end", callId: api.callId, name: tool.name, isError: Boolean(answer.isError), result: answer.text });
|
|
259
342
|
const images = (answer.images ?? []).map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }));
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -1,12 +1,47 @@
|
|
|
1
|
+
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
2
|
+
export declare const DRAIN_TIMEOUT = "30s";
|
|
3
|
+
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
4
|
+
* number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
|
|
5
|
+
* memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
|
|
6
|
+
* before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
|
|
7
|
+
export declare function besideRunnerOptions(serve: {
|
|
8
|
+
maxRuns?: number;
|
|
9
|
+
drainTimeout?: string;
|
|
10
|
+
}, env: NodeJS.ProcessEnv): {
|
|
11
|
+
loops: number;
|
|
12
|
+
drainMs: number;
|
|
13
|
+
};
|
|
14
|
+
/** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
|
|
15
|
+
* and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
|
|
16
|
+
* the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
|
|
17
|
+
export declare function besideStopping(server: {
|
|
18
|
+
runs: number;
|
|
19
|
+
boundMs: number;
|
|
20
|
+
}, held: number, drainMs: number): {
|
|
21
|
+
runs: number;
|
|
22
|
+
boundMs: number;
|
|
23
|
+
};
|
|
1
24
|
/** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
|
|
2
25
|
* its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
|
|
3
26
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
4
|
-
* caller hands its own: the template eval's in-process server, its faux's).
|
|
5
|
-
*
|
|
6
|
-
|
|
27
|
+
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
28
|
+
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
29
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
|
|
30
|
+
* closes its store. */
|
|
31
|
+
export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor }?: {
|
|
7
32
|
loops?: number;
|
|
33
|
+
drainMs?: number;
|
|
8
34
|
env?: NodeJS.ProcessEnv;
|
|
35
|
+
janitor?: boolean;
|
|
9
36
|
}): Promise<{
|
|
10
37
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
11
38
|
close: () => Promise<void>;
|
|
12
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
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
// A runner beside a server on the same data directory: the CLI start's server-and-runner, the `runner` subcommand and
|
|
2
2
|
// the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
|
|
3
|
+
import { maxRunsOf } from "../host.js";
|
|
4
|
+
import { durationMs } from "../print.js";
|
|
5
|
+
import { runnerCloseBoundMs } from "./runner.js";
|
|
6
|
+
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
7
|
+
export const DRAIN_TIMEOUT = "30s";
|
|
8
|
+
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
9
|
+
* number maxRunsOf gives the capabilities' max_concurrent_runs: AGENTRUN_MAX_RUNS, else as many pi runs as this host's
|
|
10
|
+
* memory holds), and on its close lets each held run finish its turn for up to --drain-timeout (default DRAIN_TIMEOUT)
|
|
11
|
+
* before it stops the rest to resume. The server has checked both by the time this reads them (startServe). */
|
|
12
|
+
export function besideRunnerOptions(serve, env) {
|
|
13
|
+
const drainTimeout = serve.drainTimeout ?? DRAIN_TIMEOUT;
|
|
14
|
+
const drainMs = durationMs(drainTimeout);
|
|
15
|
+
if (drainMs === undefined)
|
|
16
|
+
throw new Error(`the drain timeout ${drainTimeout} is not a duration such as 8s`);
|
|
17
|
+
return { loops: maxRunsOf(env, serve.maxRuns), drainMs };
|
|
18
|
+
}
|
|
19
|
+
/** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
|
|
20
|
+
* and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
|
|
21
|
+
* the stop of the loops left: runnerCloseBoundMs), so the stop's deadline never cuts a run's end and release short. */
|
|
22
|
+
export function besideStopping(server, held, drainMs) {
|
|
23
|
+
return { runs: server.runs + held, boundMs: Math.max(server.boundMs, runnerCloseBoundMs(drainMs)) };
|
|
24
|
+
}
|
|
3
25
|
/** A runner beside the server on the same data directory (the CLI start's server-and-runner, and the `runner` subcommand):
|
|
4
26
|
* its own store handle (role runner), and the runner's dispatch (dispatch.ts) for each claimed run — pi on the kernel's
|
|
5
27
|
* adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
|
|
6
|
-
* caller hands its own: the template eval's in-process server, its faux's).
|
|
7
|
-
*
|
|
8
|
-
|
|
28
|
+
* caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
|
|
29
|
+
* (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
|
|
30
|
+
* too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
|
|
31
|
+
* closes its store. */
|
|
32
|
+
export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {}) {
|
|
9
33
|
const { startRunner } = await import("./runner.js");
|
|
10
34
|
const { dispatchRunner } = await import("./harness-loops.js");
|
|
11
35
|
const { routeOf } = await import("./model-route.js");
|
|
@@ -36,6 +60,31 @@ export async function runnerBeside(dataDir, { loops, env } = {}) {
|
|
|
36
60
|
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
37
61
|
const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
|
|
38
62
|
const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
// It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
|
|
64
|
+
const { runnerMemory } = await import("./memory-claim.js");
|
|
65
|
+
const runner = startRunner({ store, createLoop, memory: runnerMemory(store), ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
66
|
+
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
67
|
+
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
68
|
+
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
69
|
+
const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
|
|
70
|
+
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
71
|
+
return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
|
|
72
|
+
}
|
|
73
|
+
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
74
|
+
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
75
|
+
* server's runs reach its fakes. For a launcher that starts serve in-process (a demo, a smoke): a server alone leaves
|
|
76
|
+
* every run queued. close() stops both. */
|
|
77
|
+
export async function serveWithRunner(options) {
|
|
78
|
+
const { fauxEnvOf, startServe } = await import("../server.js");
|
|
79
|
+
const { besideRunEnv } = await import("./main.js");
|
|
80
|
+
const { loops, drainMs } = besideRunnerOptions(options, process.env);
|
|
81
|
+
const serve = await startServe(options);
|
|
82
|
+
const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)) }).catch(async (error) => {
|
|
83
|
+
await serve.close();
|
|
84
|
+
throw error;
|
|
85
|
+
});
|
|
86
|
+
// Once: a second call (a SIGTERM and a SIGINT both) is the first one's promise, so the runner's store is never closed
|
|
87
|
+
// under a run still finishing.
|
|
88
|
+
let closing;
|
|
89
|
+
return { serve, close: () => (closing ??= Promise.all([beside.close(), serve.close()]).then(() => undefined)) };
|
|
41
90
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { LearnedWorkflow } from "../learning.js";
|
|
2
|
+
import { type Tier } from "../model.js";
|
|
1
3
|
import type { RunLaunch } from "../run-launch.js";
|
|
2
4
|
import type { SealedKeys } from "../store/store.js";
|
|
3
|
-
import type { Revision } from "
|
|
5
|
+
import type { Revision } from "../agent-rows.js";
|
|
4
6
|
/** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
|
|
5
7
|
* environment (its own, with no server secret in it: those are the store's). */
|
|
6
8
|
export interface ClaimSecretsDeps {
|
|
@@ -15,6 +17,19 @@ export interface ClaimSecretsDeps {
|
|
|
15
17
|
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
16
18
|
* decision provider keys. A fresh object per claim, so no run's keys reach another's. */
|
|
17
19
|
export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
|
|
20
|
+
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
21
|
+
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
22
|
+
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
23
|
+
* run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
|
|
24
|
+
* lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
|
|
25
|
+
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
26
|
+
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
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>;
|
|
18
33
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
19
34
|
export declare const MODEL_KEY_NAMES: readonly string[];
|
|
20
35
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// key), never from this process's environment or a pipe (the old per-run process read its own over a pipe; the runner is
|
|
3
3
|
// one process for many runs). Scoped to the run as the old per-run environment was: the keys its revision's tools unlock
|
|
4
4
|
// and its model needs (runs.ts keysFor/needsOf), and its decision provider keys (decisions.ts decisionKeysFor, Parallel's
|
|
5
|
-
// where a web tool resolves there), and no other
|
|
5
|
+
// where a web tool resolves there), and no other; an agentic run's learned workflows add the keys of the decision
|
|
6
|
+
// providers they name, read once the claim's seed lay chose them (learnedDecisionKeys). So a run that names no monid never gets the monid key, and two runs on
|
|
6
7
|
// one runner never see each other's keys: each claim reads its own, into its own environment. (MCP credentials are the
|
|
7
8
|
// other per-claim secret; they come through mcp-claim.ts, which already opens them from the store under the claim.)
|
|
8
|
-
import { decisionKeysFor } from "../decisions.js";
|
|
9
|
-
import { GATEWAY_KEY_ENV, PROVIDER_KEYS } from "../model.js";
|
|
9
|
+
import { decisionKeysFor, providersNamed } from "../decisions.js";
|
|
10
|
+
import { GATEWAY_KEY_ENV, modelKeys, PROVIDER_KEYS, workflowNodes } from "../model.js";
|
|
10
11
|
import { keysFor, needsOf, RUN_SECRETS } from "../run-secrets.js";
|
|
11
12
|
import { DECISION_KEYS, withoutSecrets } from "../secrets.js";
|
|
12
13
|
import { getSealedKey } from "../server-keys.js";
|
|
@@ -19,17 +20,7 @@ const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
|
|
|
19
20
|
* decision provider keys. A fresh object per claim, so no run's keys reach another's. */
|
|
20
21
|
export async function claimSecrets(deps, revision, launch) {
|
|
21
22
|
const base = withoutSecrets(deps.env ?? {});
|
|
22
|
-
|
|
23
|
-
// put on the environment its tools run under. The server process's own environment value wins over the store's by the same
|
|
24
|
-
// name (the secrets rule 4: env always overrides a pasted value), so a key set where the server starts is not shadowed by a
|
|
25
|
-
// stale one saved in the store.
|
|
26
|
-
const working = { ...base };
|
|
27
|
-
// A name present with no value (`-e NAME`, an empty optional secret) is not a key: the store's saved one stands.
|
|
28
|
-
for (const name of CANDIDATES) {
|
|
29
|
-
const value = deps.env?.[name] || (deps.sealKey ? await getSealedKey(deps.store, deps.sealKey, name) : undefined);
|
|
30
|
-
if (value !== undefined)
|
|
31
|
-
working[name] = value;
|
|
32
|
-
}
|
|
23
|
+
const working = await workingEnv(deps);
|
|
33
24
|
const needs = await needsOf(revision);
|
|
34
25
|
// An agentic run's model keys are its PINNED model's (the launch's, chosen at its start), the one its route sends, never
|
|
35
26
|
// the host's default now: a key saved since the run started (another provider's, now first) would otherwise be opened
|
|
@@ -44,6 +35,63 @@ export async function claimSecrets(deps, revision, launch) {
|
|
|
44
35
|
env[name] = value;
|
|
45
36
|
return env;
|
|
46
37
|
}
|
|
38
|
+
/** Every candidate secret in a working environment over the runner's base, read for one claim and scoped by its caller, so
|
|
39
|
+
* a key the run does not need is never put on the environment its tools run under. The server process's own environment
|
|
40
|
+
* value wins over the store's by the same name (the secrets rule 4: env always overrides a pasted value), so a key set
|
|
41
|
+
* where the server starts is not shadowed by a stale one saved in the store. */
|
|
42
|
+
async function workingEnv(deps) {
|
|
43
|
+
const working = { ...withoutSecrets(deps.env ?? {}) };
|
|
44
|
+
// A name present with no value (`-e NAME`, an empty optional secret) is not a key: the store's saved one stands.
|
|
45
|
+
for (const name of CANDIDATES) {
|
|
46
|
+
const value = deps.env?.[name] || (deps.sealKey ? await getSealedKey(deps.store, deps.sealKey, name) : undefined);
|
|
47
|
+
if (value !== undefined)
|
|
48
|
+
working[name] = value;
|
|
49
|
+
}
|
|
50
|
+
return working;
|
|
51
|
+
}
|
|
52
|
+
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
53
|
+
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
54
|
+
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
55
|
+
* run's gate), read as claimSecrets reads its keys and scoped by decisionKeysFor. `workflows`: those the claim's seed
|
|
56
|
+
* lay chose for the run's learned_workflow tool (runner/learning-seed.ts), so this read comes after the lay. A
|
|
57
|
+
* workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
|
|
58
|
+
* no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
|
|
59
|
+
export async function learnedDecisionKeys(deps, workflows, allowed) {
|
|
60
|
+
if (!workflows.length)
|
|
61
|
+
return {};
|
|
62
|
+
const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
|
|
63
|
+
const named = new Set();
|
|
64
|
+
for (const { workflow } of workflows) {
|
|
65
|
+
let nodes;
|
|
66
|
+
try {
|
|
67
|
+
const doc = JSON.parse(workflow);
|
|
68
|
+
nodes = workflowNodes(doc, inspectWorkflow(doc));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
for (const id of providersNamed(nodes))
|
|
74
|
+
named.add(id);
|
|
75
|
+
}
|
|
76
|
+
const providers = [...named].filter((id) => allowed(id));
|
|
77
|
+
if (!providers.length)
|
|
78
|
+
return {};
|
|
79
|
+
return decisionKeysFor(await workingEnv(deps), { providers, parallelWeb: false });
|
|
80
|
+
}
|
|
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
|
+
}
|
|
47
95
|
/** Every model key a model route reads by name: each of pi-ai's providers' (model.ts PROVIDER_KEYS) and the gateway's. */
|
|
48
96
|
export const MODEL_KEY_NAMES = [...new Set([...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV])];
|
|
49
97
|
/** `env` for a model route (model-route.ts routeOf, a CLI's providerFor): the runner's own environment, its secrets kept
|
|
@@ -7,6 +7,11 @@ export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./
|
|
|
7
7
|
/** What the runner hands the CLI spec builder: the same deps the pi spec takes (computerForClaim, computerDeps and
|
|
8
8
|
* makeArchilDisk are on AdapterSpecDeps, shared by both). One per runner. */
|
|
9
9
|
export type CliSpecDeps = AdapterSpecDeps;
|
|
10
|
+
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
11
|
+
export declare const cliRefusesKind: (kind: string) => string | undefined;
|
|
12
|
+
/** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
|
|
13
|
+
* laid things in since (a follow-up's) stays, with what is in it. */
|
|
14
|
+
export declare function sweepScratch(dir: string, parents: readonly string[]): Promise<void>;
|
|
10
15
|
/**
|
|
11
16
|
* One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
|
|
12
17
|
*
|