@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.38
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 +282 -0
- package/README.md +155 -92
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +39 -14
- package/dist/answer-json.d.ts +34 -1
- package/dist/answer-json.js +91 -9
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/browser-cost.js +52 -93
- package/dist/cap.d.ts +0 -390
- package/dist/cap.js +4 -937
- package/dist/catalog.js +1 -1
- package/dist/composio-preset.d.ts +17 -0
- package/dist/composio-preset.js +43 -1
- package/dist/computer-calls.d.ts +36 -24
- package/dist/computer-calls.js +110 -27
- package/dist/computer-live.d.ts +5 -0
- package/dist/computer-live.js +12 -0
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +3 -2
- package/dist/computer-view.js +5 -4
- package/dist/computer-viewer.js +26 -12
- package/dist/computers.d.ts +4 -1
- package/dist/computers.js +12 -6
- package/dist/console/assets/index-CjqQirbo.css +1 -0
- package/dist/console/assets/index-b6-XY5A9.js +576 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +3 -0
- package/dist/decisions.js +4 -0
- package/dist/faux-computers.js +4 -2
- package/dist/harness-opencode/adapter.js +7 -3
- package/dist/harness-opencode/facts.js +0 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -5
- package/dist/harness-opencode/host/policy.js +8 -32
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +0 -2
- package/dist/host-tools.d.ts +1 -5
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +0 -2
- package/dist/hosted-search.js +0 -21
- package/dist/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +6 -1
- package/dist/learn/check.js +12 -4
- package/dist/learn/commit.d.ts +10 -0
- package/dist/learn/commit.js +18 -4
- package/dist/learn/compile.d.ts +243 -0
- package/dist/learn/compile.js +471 -0
- package/dist/learn/general.d.ts +3 -0
- package/dist/learn/general.js +4 -2
- package/dist/learn/grade.d.ts +1 -1
- package/dist/learn/grade.js +7 -6
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +253 -0
- package/dist/learn/promote.js +428 -0
- package/dist/learn/refit.d.ts +39 -0
- package/dist/learn/refit.js +236 -0
- package/dist/learn/reflect.d.ts +5 -25
- package/dist/learn/reflect.js +14 -131
- package/dist/learn/replay-calls.d.ts +63 -0
- package/dist/learn/replay-calls.js +158 -0
- package/dist/learn/skills.d.ts +17 -9
- package/dist/learn/skills.js +132 -42
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +50 -2
- package/dist/learned-nodes.js +41 -2
- package/dist/learned-workflow.d.ts +19 -3
- package/dist/learned-workflow.js +105 -26
- package/dist/learning-batch.d.ts +2 -2
- package/dist/learning-batch.js +1 -1
- package/dist/learning-cost.d.ts +18 -6
- package/dist/learning-cost.js +15 -7
- package/dist/learning-routes.d.ts +14 -2
- package/dist/learning-routes.js +14 -3
- package/dist/learning-words.d.ts +7 -0
- package/dist/learning-words.js +7 -0
- package/dist/learning.d.ts +31 -6
- package/dist/learning.js +7 -4
- package/dist/llm.js +0 -3
- package/dist/mcp-gateway.d.ts +12 -20
- package/dist/mcp-gateway.js +16 -44
- package/dist/mcp-oauth.d.ts +5 -0
- package/dist/mcp-oauth.js +1 -1
- package/dist/mcp-pin-first.d.ts +37 -0
- package/dist/mcp-pin-first.js +107 -0
- package/dist/mcp-probe.d.ts +8 -9
- package/dist/mcp-probe.js +16 -33
- package/dist/mcp-servers-store.d.ts +89 -22
- package/dist/mcp-servers-store.js +131 -25
- package/dist/mcp-sources.d.ts +39 -0
- package/dist/mcp-sources.js +74 -0
- package/dist/mcp-store.d.ts +11 -0
- package/dist/mcp-store.js +16 -2
- package/dist/mcp-wire.d.ts +22 -0
- package/dist/mcp-wire.js +36 -0
- package/dist/mcp.js +3 -3
- package/dist/meta-tool-names.d.ts +1 -0
- package/dist/meta-tool-names.js +3 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +46 -15
- package/dist/monid.d.ts +51 -25
- package/dist/monid.js +226 -140
- package/dist/openapi.js +336 -66
- package/dist/paid-calls.d.ts +26 -29
- package/dist/paid-calls.js +46 -102
- package/dist/propose.d.ts +7 -1
- package/dist/propose.js +18 -6
- package/dist/provider.js +9 -2
- package/dist/reflect-range.js +2 -1
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +13 -0
- package/dist/run-launch.js +6 -0
- package/dist/run-learning-served.d.ts +13 -2
- package/dist/run-manifest.d.ts +5 -0
- package/dist/run-manifest.js +20 -0
- package/dist/run-secrets.js +2 -3
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +17 -6
- package/dist/run-view.js +51 -22
- package/dist/runnable.d.ts +0 -3
- package/dist/runnable.js +37 -29
- package/dist/runner/adapter-loop.d.ts +24 -10
- package/dist/runner/adapter-loop.js +852 -314
- package/dist/runner/adapter-run-spec.d.ts +12 -6
- package/dist/runner/adapter-run-spec.js +97 -46
- package/dist/runner/adapters/pi-computer.d.ts +3 -1
- package/dist/runner/adapters/pi-computer.js +13 -5
- package/dist/runner/adapters/pi.d.ts +16 -7
- package/dist/runner/adapters/pi.js +94 -33
- package/dist/runner/cli-run-spec.js +67 -27
- package/dist/runner/computer-channel.js +2 -1
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +145 -4
- package/dist/runner/conformance/subject.d.ts +11 -4
- package/dist/runner/end-of-run.d.ts +6 -5
- package/dist/runner/end-of-run.js +9 -6
- package/dist/runner/feedback-round.d.ts +52 -0
- package/dist/runner/feedback-round.js +79 -0
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +15 -0
- package/dist/runner/learning-end.d.ts +54 -19
- package/dist/runner/learning-end.js +272 -99
- package/dist/runner/learning-loop.d.ts +19 -1
- package/dist/runner/learning-loop.js +5 -2
- package/dist/runner/learning-seed.d.ts +4 -0
- package/dist/runner/learning-seed.js +14 -0
- package/dist/runner/loop-contract.d.ts +19 -3
- package/dist/runner/loop.d.ts +16 -1
- package/dist/runner/loop.js +21 -1
- package/dist/runner/mcp-claim.d.ts +5 -1
- package/dist/runner/mcp-claim.js +66 -50
- package/dist/runner/mcp-run.d.ts +16 -52
- package/dist/runner/mcp-run.js +12 -84
- package/dist/runner/meta-tools.d.ts +37 -0
- package/dist/runner/meta-tools.js +268 -0
- package/dist/runner/metrics.js +14 -3
- package/dist/runner/model-route.js +12 -3
- package/dist/runner/monid-run.d.ts +16 -0
- package/dist/runner/monid-run.js +96 -0
- package/dist/runner/promotion.d.ts +80 -0
- package/dist/runner/promotion.js +562 -0
- package/dist/runner/reflect-hook.d.ts +36 -21
- package/dist/runner/reflect-hook.js +138 -49
- package/dist/runner/runner.js +26 -4
- package/dist/runner/sessions.d.ts +8 -3
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +7 -12
- package/dist/runner/workflow-first.d.ts +216 -0
- package/dist/runner/workflow-first.js +303 -0
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +1 -0
- package/dist/runner/workflow-spec.js +7 -3
- package/dist/runs-over-store.d.ts +11 -2
- package/dist/runs-over-store.js +21 -11
- package/dist/server.d.ts +88 -16
- package/dist/server.js +380 -87
- package/dist/settings-wake.d.ts +8 -6
- package/dist/settings-wake.js +13 -7
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/command-wake.d.ts +3 -2
- package/dist/store/command-wake.js +4 -4
- package/dist/store/postgres/connection.js +3 -1
- package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
- package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +28 -8
- package/dist/store/sqlite/connection.d.ts +2 -2
- package/dist/store/sqlite/connection.js +2 -2
- package/dist/store/sqlite/run-patch.js +19 -7
- package/dist/store/sqlite/store.js +59 -18
- package/dist/store/store.d.ts +46 -14
- package/dist/store-reads/journal.d.ts +25 -1
- package/dist/store-reads/journal.js +63 -49
- package/dist/store-reads/learning.d.ts +101 -15
- package/dist/store-reads/learning.js +195 -61
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-view.d.ts +3 -2
- package/dist/store-view.js +35 -17
- package/dist/template-eval.d.ts +18 -9
- package/dist/template-eval.js +91 -66
- package/dist/template-github-permissions.d.ts +2 -2
- package/dist/template-github-permissions.js +2 -1
- package/dist/template-import.d.ts +31 -0
- package/dist/template-import.js +121 -0
- package/dist/template-source.d.ts +51 -0
- package/dist/template-source.js +371 -0
- package/dist/templates.d.ts +218 -46
- package/dist/templates.js +493 -181
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +4 -3
- package/dist/timeline/index.js +4 -3
- package/dist/timeline/labels.d.ts +6 -2
- package/dist/timeline/labels.js +93 -2
- package/dist/timeline/origin.d.ts +19 -5
- package/dist/timeline/origin.js +11 -4
- package/dist/timeline/timeline.d.ts +11 -17
- package/dist/timeline/timeline.js +24 -9
- package/dist/tool-gate.d.ts +73 -46
- package/dist/tool-gate.js +133 -66
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +26 -0
- package/dist/tool-list.js +43 -0
- package/dist/tool-names.d.ts +71 -0
- package/dist/tool-names.js +99 -0
- package/dist/tool-plane.d.ts +29 -27
- package/dist/tool-plane.js +65 -37
- package/dist/tools.d.ts +22 -6
- package/dist/tools.js +24 -20
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +91 -44
- package/dist/web-fetch.d.ts +1 -7
- package/dist/web-fetch.js +2 -22
- package/dist/workspace/computer-deps.d.ts +3 -0
- package/dist/workspace/computer-deps.js +5 -2
- package/dist/workspace/computer-for-claim.d.ts +6 -0
- package/dist/workspace/computer-for-claim.js +32 -14
- package/dist/workspace/computer-hold.js +7 -1
- package/dist/workspace/computer-script.d.ts +23 -7
- package/dist/workspace/computer-script.js +48 -14
- package/dist/workspace/index.d.ts +2 -2
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +21 -1
- package/dist/workspace/resolve-computer.js +32 -14
- package/dist/workspace/run-tools.d.ts +28 -10
- package/dist/workspace/run-tools.js +39 -11
- package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
- package/dist/wrap-up.js +21 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +9 -9
- package/templates/README.md +111 -45
- package/templates/code-review/agent.md +30 -14
- package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
- package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
- package/templates/code-review/evals/injection/case.yaml +2 -1
- package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
- package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
- package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
- package/templates/code-review/evals/never-flag/case.yaml +2 -1
- package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
- package/templates/code-review/evals/null-name/case.yaml +2 -1
- package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
- package/templates/code-review/evals/off-by-one/case.yaml +2 -1
- package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/case.yaml +16 -0
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
- package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/code-review/evals/other-repo/prompt.md +10 -0
- package/templates/code-review/evals/re-review/case.yaml +2 -1
- package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
- package/templates/code-review/evals/re-review-open/case.yaml +2 -1
- package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
- package/templates/code-review/evals/repo-rule/case.yaml +2 -1
- package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
- package/templates/code-review/evals/two-defects/case.yaml +2 -1
- package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
- package/templates/code-review/rules/CODEREVIEW.md +1 -1
- package/templates/code-review/skills/review/DEEP.md +3 -2
- package/templates/code-review/skills/review/REVIEWER.md +3 -2
- package/templates/code-review/skills/review/SKILL.md +4 -3
- package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
- package/templates/inbound-lead/agent.md +26 -16
- package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
- package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
- package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
- package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
- package/templates/kyb/agent.md +15 -5
- package/templates/kyb/evals/adverse-media/prompt.md +2 -7
- package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
- package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
- package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
- package/templates/kyb/evals/name-collision/prompt.md +2 -6
- package/templates/kyb/evals/no-invention/prompt.md +2 -6
- package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
- package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
- package/templates/kyb/kyb.schema.json +8 -7
- package/templates/kyb/skills/kyb/SKILL.md +9 -6
- package/templates/market-monitor/agent.md +19 -12
- package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +32 -10
- package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/learned-style/case.yaml +2 -1
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
- package/templates/release-notes/evals/other-repo/case.yaml +24 -0
- package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
- package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
- package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/release-notes/evals/other-repo/prompt.md +32 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
- package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
- package/templates/release-notes/notes.schema.json +1 -1
- package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
- package/dist/console/assets/index-Cn6JX1uH.js +0 -563
- package/dist/console/assets/index-DRN62V5v.css +0 -1
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.js +0 -62
- package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
- package/templates/code-review/evals/injection/graders/schema.md +0 -5
- package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
- package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
- package/templates/code-review/evals/null-name/graders/schema.md +0 -5
- package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
- package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
- package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
- package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
- package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
- package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
- package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
- package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
- package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
- package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
- package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
2
2
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
3
|
import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
|
|
4
|
-
import { anthropicPolicy,
|
|
4
|
+
import { anthropicPolicy, withWebSearches } from "@parcha/agentrun-harness-claude";
|
|
5
5
|
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
6
|
-
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
6
|
+
import { NATIVE_SEARCH_USD, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
8
|
import { DEFAULT_HARNESS } from "../../harness.js";
|
|
9
9
|
import { durableWait } from "../../workflow/pi-versions.js";
|
|
@@ -11,15 +11,35 @@ import { HOSTED_SEARCH_ALLOWANCE_TOKENS } from "../../hosted-search.js";
|
|
|
11
11
|
import { sessionProvider, tierProvider } from "../../port-models.js";
|
|
12
12
|
import { KINDS } from "../journal-kinds.js";
|
|
13
13
|
import { CALL_REFUSED } from "../../timeline/index.js";
|
|
14
|
-
import {
|
|
14
|
+
import { recordingCalls } from "../../computer-calls.js";
|
|
15
|
+
/** `extension` with each of its tools run inside recordingCalls, its calls kept by `keep` under the call's id. A call pi
|
|
16
|
+
* runs again after a restart keeps what that attempt makes: a code mode script's replay hands back the results of the
|
|
17
|
+
* calls its earlier attempt made, never making them again, so none is kept twice. The earlier attempt's own record goes
|
|
18
|
+
* with it, as a host tool's cut attempt's does: the shutdown seals the journal before its call ends. */
|
|
19
|
+
function recordingExtension(extension, keep) {
|
|
20
|
+
if (!extension.tools?.length)
|
|
21
|
+
return extension;
|
|
22
|
+
return {
|
|
23
|
+
...extension,
|
|
24
|
+
tools: extension.tools.map((tool) => ({
|
|
25
|
+
...tool,
|
|
26
|
+
execute: (args, api, context) => recordingCalls(async () => tool.execute(args, api, context), (calls, dropped) => keep(api.callId, calls, dropped)),
|
|
27
|
+
})),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
15
30
|
const PROVIDER = "agentrun-session";
|
|
31
|
+
/** A host tool's value (HostTool's `structured`) in its pi result's details, which the model never reads: what a call
|
|
32
|
+
* nested in tools_call or a script reads (piNested). */
|
|
33
|
+
const HOST_VALUE = "agentrun.value";
|
|
16
34
|
const INPUT_REQUEST = "agentrun:input";
|
|
17
35
|
/** pi as an AgentAdapter for one claim's run. */
|
|
18
36
|
export function piAdapter(options) {
|
|
19
37
|
return {
|
|
20
38
|
// pi is the default harness: its id is the harness table's, never a literal of its own.
|
|
21
39
|
id: DEFAULT_HARNESS,
|
|
22
|
-
|
|
40
|
+
// Its native tools (the subagent tool, the browser's): the host's tools_search lists them, and tools_call or a script
|
|
41
|
+
// calls one as pi's own nested tool task (piNested).
|
|
42
|
+
ownTools: [...(options.extensions ?? []).flatMap((extension) => extension.tools ?? []), ...(options.tools ?? [])].map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.parameters })),
|
|
23
43
|
check: () => [],
|
|
24
44
|
open: (spec, io) => openPi(options, spec, io),
|
|
25
45
|
};
|
|
@@ -108,7 +128,7 @@ export function piPolicy(model, tools, auth, webSearch = false) {
|
|
|
108
128
|
return policy;
|
|
109
129
|
// The hosted search's fees held with its tokens: each use its tool's max_uses allows, at the search's fee. One with no
|
|
110
130
|
// max_uses has no bound, and its worst case is unknown (the proxy's feeMaxUsd).
|
|
111
|
-
return { ...policy, feeMaxUsd: (body) => searchesAllowed(body, (tool) => typeof tool.type === "string" && tool.type.startsWith("web_search_"), "max_uses") *
|
|
131
|
+
return { ...policy, feeMaxUsd: (body) => searchesAllowed(body, (tool) => typeof tool.type === "string" && tool.type.startsWith("web_search_"), "max_uses") * NATIVE_SEARCH_USD };
|
|
112
132
|
}
|
|
113
133
|
/** The most searches `body` allows its hosted search tool (the one `isSearch` picks): its `limit` (the tool's own key, or
|
|
114
134
|
* the body's on Responses), Infinity when it states none, 0 when the body offers no search. */
|
|
@@ -203,7 +223,12 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
203
223
|
// intent: a call it runs with no pass here is one it reruns after a crash (a replay-safe call whose intent an earlier
|
|
204
224
|
// attempt stored), told to the host tool as an attempt above 0, so the loop asks the gate about it again.
|
|
205
225
|
const passed = new Set();
|
|
206
|
-
|
|
226
|
+
// The calls asked at the gate or run in this session: a nested call among them is fresh (NestedResult), not one its
|
|
227
|
+
// record answered.
|
|
228
|
+
const touched = new Set();
|
|
229
|
+
// A refused nested call's words, by its id (pi's nested result keeps none of a refused call's output).
|
|
230
|
+
const nestedRefusals = new Map();
|
|
231
|
+
const tools = [...spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined), touched, nestedRefusals)), ...(options.tools ?? [])];
|
|
207
232
|
// A refused call's words (the gate's deny, main's), by call: its result is those words alone, as main gives them.
|
|
208
233
|
const refusals = refusalWords();
|
|
209
234
|
const extension = defineExtension({
|
|
@@ -212,18 +237,20 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
212
237
|
hooks: [
|
|
213
238
|
hook(ToolTask, {
|
|
214
239
|
beforeTool: async (call, api, hookContext) => {
|
|
240
|
+
touched.add(call.id);
|
|
215
241
|
if (!io.gate)
|
|
216
242
|
return undefined;
|
|
217
|
-
// A
|
|
218
|
-
|
|
219
|
-
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 };
|
|
220
|
-
const answer = await io.gate({ callId: call.id, tool: call.name, args: (call.arguments ?? {}), ...counted }, hookContext);
|
|
243
|
+
// A nested call (one a tool made) is marked so: the cap's wrap-up lets it through, as its parent's part.
|
|
244
|
+
const answer = await io.gate({ callId: call.id, tool: call.name, args: (call.arguments ?? {}), ...(call.parent === undefined ? {} : { nested: true }) }, hookContext);
|
|
221
245
|
if (answer === "allow") {
|
|
222
246
|
passed.add(call.id);
|
|
223
247
|
return undefined;
|
|
224
248
|
}
|
|
225
249
|
if ("deny" in answer) {
|
|
226
250
|
refusals.refuse(call.id, answer.deny);
|
|
251
|
+
// A nested call's words for the tool that made it: pi keeps no output of a refused nested call.
|
|
252
|
+
if (call.parent !== undefined)
|
|
253
|
+
nestedRefusals.set(call.id, answer.deny);
|
|
227
254
|
return { block: answer.deny };
|
|
228
255
|
}
|
|
229
256
|
// Parked: held until pi closes the Session, so the call never reaches its intent in this process.
|
|
@@ -236,7 +263,7 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
236
263
|
},
|
|
237
264
|
// A call the gate refused: its result is main's words alone, an error, never pi's framing of a blocked call (its
|
|
238
265
|
// diagnostic, which the model reads as "<harness>[error] Tool call blocked: ..."). Every other result is pi's.
|
|
239
|
-
afterTool: async (call, result) => refusals.resultOf(call.id, result),
|
|
266
|
+
afterTool: async (call, result) => refusals.resultOf(call.id, result, call.parent !== undefined),
|
|
240
267
|
}),
|
|
241
268
|
// An answer's cost is the runner's booking of its request, never pi's $0 for a model it has no price for: set on
|
|
242
269
|
// the answer before pi stores it, so the answer, pi.usage and the live timeline carry it; unknown stays unknown.
|
|
@@ -255,8 +282,9 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
|
|
|
255
282
|
],
|
|
256
283
|
});
|
|
257
284
|
run.registry.install(extension);
|
|
258
|
-
// The run's pi-native extensions (options.extensions), in the claim's registry beside the session's
|
|
259
|
-
|
|
285
|
+
// The run's pi-native extensions (options.extensions), in the claim's registry beside the session's: each tool's computer
|
|
286
|
+
// calls recorded on its row (io.keepCalls), as the loop records its host tools'.
|
|
287
|
+
const native = (options.extensions ?? []).map((each) => (io.keepCalls ? recordingExtension(each, io.keepCalls) : each));
|
|
260
288
|
for (const each of native)
|
|
261
289
|
run.registry.install(each);
|
|
262
290
|
// The root conversation may exist already (the loop's session records live beside it, under it): its agent is set here,
|
|
@@ -363,7 +391,7 @@ export function refusalWords() {
|
|
|
363
391
|
refuse(callId, text) {
|
|
364
392
|
words.set(callId, text);
|
|
365
393
|
},
|
|
366
|
-
resultOf(callId, result) {
|
|
394
|
+
resultOf(callId, result, nested = false) {
|
|
367
395
|
const text = words.get(callId);
|
|
368
396
|
// Let go on every result: the call has its one result now, whatever it is.
|
|
369
397
|
words.delete(callId);
|
|
@@ -371,28 +399,15 @@ export function refusalWords() {
|
|
|
371
399
|
if (text === undefined || !blocked)
|
|
372
400
|
return undefined;
|
|
373
401
|
// Marked refused in its details (which the model never reads): its Timeline rows say it was refused, never that it
|
|
374
|
-
// ran and failed.
|
|
375
|
-
|
|
402
|
+
// ran and failed. A nested call's words ride its error diagnostic too, which a script's failed call reads (pi's code
|
|
403
|
+
// mode throws its message): never "Tool <name> failed".
|
|
404
|
+
return { output: [{ type: "text", text }], isError: true, details: { [CALL_REFUSED]: true }, ...(nested ? { diagnostics: [{ severity: "error", code: "blocked", message: text }] } : {}) };
|
|
376
405
|
},
|
|
377
406
|
get held() {
|
|
378
407
|
return words.size;
|
|
379
408
|
},
|
|
380
409
|
};
|
|
381
410
|
}
|
|
382
|
-
/** The tool calls a hook's conversation made before `callId`, at most `upTo`: its committed entries read oldest first, a
|
|
383
|
-
* page at a time, only as far as the count needs (tool-budget.ts countCalls). */
|
|
384
|
-
async function callsBefore(api, callId, upTo, context) {
|
|
385
|
-
let counted = { count: 0, done: upTo <= 0 };
|
|
386
|
-
let cursor;
|
|
387
|
-
while (!counted.done) {
|
|
388
|
-
const page = await api.entries({ order: "ascending" }, 100, cursor, context);
|
|
389
|
-
counted = countCalls(page.items, callId, upTo, counted.count);
|
|
390
|
-
cursor = page.next;
|
|
391
|
-
if (cursor === undefined)
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
return counted.count;
|
|
395
|
-
}
|
|
396
411
|
/** pi's output limits for a host tool, from the host's result bound: a result within it holds at most that many
|
|
397
412
|
* characters (UTF-16 units), so at most that many lines plus one, and three bytes of UTF-8 to a character. pi's own
|
|
398
413
|
* 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
|
|
@@ -400,19 +415,61 @@ async function callsBefore(api, callId, upTo, context) {
|
|
|
400
415
|
* continue". Each CLI adapter is told the same bound (harness-opencode/config.ts TOOL_OUTPUT, Claude's maxResultSizeChars,
|
|
401
416
|
* Codex's tool_output_token_limit); each host tool keeps its own answer within it (test/host-bounds.test.mjs). */
|
|
402
417
|
export const HOST_TOOL_OUTPUT = Object.freeze({ maxLines: HOST_RESULT_MAX_CHARS + 1, maxBytes: HOST_RESULT_MAX_CHARS * 3 });
|
|
418
|
+
/** pi's nested calls as a host tool's (NestedCalls): each the session's tool by its name, run as pi's own nested tool task
|
|
419
|
+
* (`executeTool`, its call id `<callId>/<key>`), whose ToolTask hooks ask the gate as the tool itself (`nested`), and
|
|
420
|
+
* whose rerun by the same key gets the recorded call back, finished or still running, never a second one. Fresh: asked
|
|
421
|
+
* at the gate or run in this session (`touched`). A refused one is the gate's words (CALL_REFUSED, from refusalWords).
|
|
422
|
+
* Each one's end goes to the host (`ended`: PiSessionIO.nestedEnded), which keeps it on the run's record. */
|
|
423
|
+
function piNested(api, context, touched, refusals, ended) {
|
|
424
|
+
return {
|
|
425
|
+
async call(name, args, key) {
|
|
426
|
+
const result = await api.executeTool(name, args, context, { key });
|
|
427
|
+
const callId = `${api.callId}/${key}`;
|
|
428
|
+
const codes = result.diagnostics.map((one) => one.code);
|
|
429
|
+
const refused = result.details?.[CALL_REFUSED] === true || codes.includes("blocked") || codes.includes("tool_unavailable");
|
|
430
|
+
const interrupted = codes.some((code) => code === "interrupted" || code === "abandoned" || code === "restart_limit");
|
|
431
|
+
// A schema-less tool's output for programs is its output parts: its text, and the images it shows.
|
|
432
|
+
const value = result.structuredOutput;
|
|
433
|
+
const parts = Array.isArray(value) ? value : [];
|
|
434
|
+
const said = typeof value === "string" ? value : parts.map((part) => (part && typeof part === "object" && "text" in part ? String(part.text) : "")).join("");
|
|
435
|
+
const images = parts.flatMap((part) => (part?.type === "image" && typeof part.data === "string" && typeof part.mimeType === "string" ? [{ data: part.data, mimeType: part.mimeType }] : []));
|
|
436
|
+
// A host tool's value rides its result's details (piTool), recorded with it: a script's call is answered it.
|
|
437
|
+
const structured = result.details?.[HOST_VALUE];
|
|
438
|
+
// A refusal in the gate's words (this session's), or, answered from an earlier session's record, said so.
|
|
439
|
+
const words = refused ? (refusals.get(callId) ?? `${name} was refused (the run's tool settings or a person's answer), and it did not run.`) : undefined;
|
|
440
|
+
const text = words ?? (said || result.diagnostics.map((one) => one.message).join("\n"));
|
|
441
|
+
await ended?.(callId, refused ? "refused" : interrupted ? "interrupted" : result.isError ? "failed" : "done", text);
|
|
442
|
+
return {
|
|
443
|
+
text,
|
|
444
|
+
...(result.isError ? { isError: true } : {}),
|
|
445
|
+
...(!refused && images.length ? { images } : {}),
|
|
446
|
+
...(!refused && structured !== undefined ? { structured } : {}),
|
|
447
|
+
...(refused ? { refused: true } : {}),
|
|
448
|
+
...(interrupted ? { interrupted: true } : {}),
|
|
449
|
+
fresh: touched.has(callId),
|
|
450
|
+
};
|
|
451
|
+
},
|
|
452
|
+
memo: (key, value) => api.memo(`nested:${key}`, value, context),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
403
455
|
/** 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
|
|
404
456
|
* whole within the host's bound (HOST_TOOL_OUTPUT). Each call gets what pi's own tool task gives a tool: the calling
|
|
405
457
|
* agent's model, resolved in the session's models (its input and input limits, which a file read sizes an image by),
|
|
406
458
|
* and pi's output stream (the running tool's live slot); and its attempt (`attemptOf`: above 0 for a call the gate did
|
|
407
459
|
* not pass in this session, pi's rerun after a crash). */
|
|
408
|
-
function piTool(tool, io, attemptOf = () => undefined) {
|
|
460
|
+
function piTool(tool, io, attemptOf = () => undefined, touched = new Set(), nestedRefusals = new Map()) {
|
|
409
461
|
return defineTool({
|
|
410
462
|
name: tool.name,
|
|
411
463
|
description: tool.description,
|
|
412
464
|
parameters: tool.inputSchema,
|
|
413
|
-
|
|
465
|
+
// A tool that nests calls runs again after a crash: its nested calls are pi's own tool tasks, each answered from its
|
|
466
|
+
// record by its key (executeTool), never run twice.
|
|
467
|
+
replay: tool.replay === "safe" || tool.nests ? "safe" : "unsafe",
|
|
414
468
|
outputLimits: HOST_TOOL_OUTPUT,
|
|
469
|
+
// A catalog tool the run defers: pi never offers it, and a nested call (tools_call, a script) runs it by its name.
|
|
470
|
+
...(tool.deferred ? { deferred: true } : {}),
|
|
415
471
|
execute: async (args, api, toolContext) => {
|
|
472
|
+
touched.add(api.callId);
|
|
416
473
|
io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
|
|
417
474
|
const attempt = attemptOf(api.callId);
|
|
418
475
|
const ref = (await api.agent(toolContext)).model;
|
|
@@ -422,10 +479,14 @@ function piTool(tool, io, attemptOf = () => undefined) {
|
|
|
422
479
|
...(model ? { model } : {}),
|
|
423
480
|
output: (chunk) => api.output(chunk),
|
|
424
481
|
...(attempt === undefined ? {} : { attempt }),
|
|
482
|
+
...(tool.nests ? { nested: piNested(api, toolContext, touched, nestedRefusals, io.nestedEnded) } : {}),
|
|
425
483
|
});
|
|
426
484
|
io.onEvent({ type: "tool_end", callId: api.callId, name: tool.name, isError: Boolean(answer.isError), result: answer.text });
|
|
427
485
|
const images = (answer.images ?? []).map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }));
|
|
428
|
-
|
|
486
|
+
// A nested call's (its id `<callId>/<key>`) value in the result's details (which the model never reads), recorded
|
|
487
|
+
// with it: what tools_call or a script reads (piNested). A call the model made itself keeps its result as it was.
|
|
488
|
+
const value = answer.structured !== undefined && api.callId.includes("/") ? { details: { [HOST_VALUE]: answer.structured } } : {};
|
|
489
|
+
return { output: [{ type: "text", text: answer.text }, ...images], ...(answer.isError ? { isError: true } : {}), ...value };
|
|
429
490
|
},
|
|
430
491
|
});
|
|
431
492
|
}
|
|
@@ -22,6 +22,7 @@ import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.
|
|
|
22
22
|
import { claimSettled, installDirOf, installForClaim, installingWords } from "../harness-install.js";
|
|
23
23
|
import { HarnessUnavailable } from "../provider.js";
|
|
24
24
|
import { effortGuidance } from "../effort-guidance.js";
|
|
25
|
+
import { outputContract } from "../answer-json.js";
|
|
25
26
|
import { wireName } from "../catalog.js";
|
|
26
27
|
import { environmentLine } from "../environment.js";
|
|
27
28
|
import { harnessOf } from "../harness-table.js";
|
|
@@ -30,24 +31,26 @@ import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
|
30
31
|
import { learningWorkspace } from "../learn/folder.js";
|
|
31
32
|
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
32
33
|
import { providerModels, runModels } from "../model.js";
|
|
33
|
-
import { firstMessage } from "../run-manifest.js";
|
|
34
|
+
import { firstMessage, inputMessage } from "../run-manifest.js";
|
|
34
35
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
35
36
|
import { readsFiles, systemOf } from "../skills.js";
|
|
36
37
|
import { DATA_ENV } from "../server-fs.js";
|
|
37
38
|
import { copyRunFiles } from "../uploads.js";
|
|
38
|
-
import { isObject } from "../validate.js";
|
|
39
39
|
import { runFolder, scratchFolder } from "../workspace/paths.js";
|
|
40
40
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
41
41
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
42
42
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
43
43
|
import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
44
44
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
45
|
-
import { computerReadyWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
45
|
+
import { computerReadyWords, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
|
|
46
46
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
47
|
-
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools
|
|
47
|
+
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
|
|
48
48
|
import { openTierProxies } from "./adapters/pi.js";
|
|
49
49
|
import { signInReads } from "../sign-ins-store.js";
|
|
50
50
|
import { mcpServersOf } from "../tool-gate.js";
|
|
51
|
+
import { isWebHostTool } from "../tool-list.js";
|
|
52
|
+
import { hostToolOf } from "../host-tools.js";
|
|
53
|
+
import { ASK_TOOL, askPerson } from "../tools.js";
|
|
51
54
|
import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
52
55
|
import { mcpForClaim } from "./mcp-run.js";
|
|
53
56
|
import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
@@ -56,6 +59,9 @@ import { resolveHarness } from "./adapters/index.js";
|
|
|
56
59
|
import { entriesOf } from "./loop.js";
|
|
57
60
|
import { bookedSpend, cliModelWorked, cliRunMetrics, runEndCost } from "./metrics.js";
|
|
58
61
|
import { journalEntries } from "./journal-reader.js";
|
|
62
|
+
import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid } from "./promotion.js";
|
|
63
|
+
import { laidFor, pathMetrics, workflowFirstOf } from "./workflow-first.js";
|
|
64
|
+
import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
|
|
59
65
|
import { specBuilt } from "./spec-holds.js";
|
|
60
66
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
61
67
|
import { heldSpecOf } from "./held-run.js";
|
|
@@ -64,6 +70,7 @@ import { githubAppAccess } from "./github-app.js";
|
|
|
64
70
|
import { prCheckoutForClaim } from "./pr-checkout.js";
|
|
65
71
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
66
72
|
import { bashPolicyOf } from "../bash-read-only.js";
|
|
73
|
+
import { monidForClaim, withMonid } from "./monid-run.js";
|
|
67
74
|
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
68
75
|
export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
|
|
69
76
|
/** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
|
|
@@ -274,9 +281,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
274
281
|
});
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
|
-
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin
|
|
284
|
+
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
|
|
278
285
|
// credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
|
|
279
|
-
// Before the session opens: a refusal (a pin
|
|
286
|
+
// Before the session opens: a refusal (a granted tool its pin does not hold, a pinned meta tool) ends the run in its words.
|
|
280
287
|
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
|
|
281
288
|
const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
|
|
282
289
|
redact.hold(values); };
|
|
@@ -317,7 +324,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
317
324
|
// what became of the agent's own computer said on the run's timeline.
|
|
318
325
|
// A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
|
|
319
326
|
// whose computer is a browser is refused in words at its claim, before anything is made.
|
|
320
|
-
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
327
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
321
328
|
holds.hold({ computer });
|
|
322
329
|
const loopComputer = loopComputerOf(computer.computer, computer.held);
|
|
323
330
|
const heldComputer = heldSpecOf(launch, loopComputer);
|
|
@@ -347,7 +354,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
347
354
|
// The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
|
|
348
355
|
// learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning folder), its
|
|
349
356
|
// own skills through systemOf with the harness's own check (a harness that loads skills itself keeps in the prompt only
|
|
350
|
-
// those it would refuse, and is handed the rest),
|
|
357
|
+
// those it would refuse, and is handed the rest), the output schema it answers in (answer-json.ts outputContract, as the
|
|
358
|
+
// pi spec gives it), then the effort guidance.
|
|
351
359
|
const start = learningStartOf(launch);
|
|
352
360
|
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
353
361
|
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
|
|
@@ -356,13 +364,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
356
364
|
await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: launch.computer?.kind });
|
|
357
365
|
// A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
|
|
358
366
|
// the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
|
|
367
|
+
const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
|
|
368
|
+
const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
|
|
359
369
|
const seedLaid = start && !seedFailed(start)
|
|
360
370
|
? await layLearningSeed({
|
|
361
371
|
work: ws.workspace,
|
|
362
372
|
seed: start.seed,
|
|
363
|
-
folder:
|
|
373
|
+
folder: learningFolder,
|
|
364
374
|
own: Object.keys(revisionRow.skills ?? {}),
|
|
365
|
-
shown
|
|
375
|
+
shown,
|
|
366
376
|
log,
|
|
367
377
|
...(start.notesOnly ? { workflows: false } : {}),
|
|
368
378
|
...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
|
|
@@ -466,12 +476,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
466
476
|
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
467
477
|
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's. The run's MCP servers
|
|
468
478
|
// (mcpServersOf its grants) hold a harness's own name for an MCP tool to that tool's settings.
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
});
|
|
479
|
+
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
480
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted), mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {});
|
|
481
|
+
// What a script's shell and files are held to: this gate's settings, decided as on the run's computer (gate.script), so a
|
|
482
|
+
// denied bash or write holds inside computer_script too.
|
|
483
|
+
tools.computer?.guard.install(gate.script);
|
|
475
484
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
476
485
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
477
486
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -486,14 +495,34 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
486
495
|
// The runner's one redactor (the loop's), else this spec's log cut: the claim's keys join it, and the answers of the tools
|
|
487
496
|
// that run on them pass it.
|
|
488
497
|
const held = run.redact ? heldRedactor(run.redact) : cut;
|
|
489
|
-
|
|
498
|
+
// The run's monid endpoints (monid-run.ts), one host tool each from its revision's pin, on the claim's keys and beside
|
|
499
|
+
// its MCP tools in the loop's one catalog seam; their answers pass the redactors as the web tools' do.
|
|
500
|
+
const monid = monidForClaim(body.monidPin, { ...claimed }, () => ws.workspace, claim.runId);
|
|
501
|
+
const catalog = withMonid(mcp, monid && { ...monid, tools: monid.tools.map((tool) => answersCut(tool, held)) });
|
|
502
|
+
const webNames = granted.filter(isWebHostTool);
|
|
490
503
|
let learnedTool;
|
|
491
504
|
let webTools = [];
|
|
492
505
|
let life;
|
|
493
506
|
// The keys the claim hands the run (its web tools and its learned workflow's call nodes run on them): never learned
|
|
494
507
|
// (learningEndOfRun).
|
|
495
508
|
let handedKeys = [];
|
|
496
|
-
|
|
509
|
+
// A replay run lays the workflow it replays record-only (runner/promotion.ts replayLaid).
|
|
510
|
+
const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
|
|
511
|
+
// The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
|
|
512
|
+
// chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
|
|
513
|
+
// serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
|
|
514
|
+
// five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
|
|
515
|
+
// (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the run asks for its revision.
|
|
516
|
+
const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(claimPromotion({
|
|
517
|
+
store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
|
|
518
|
+
})), revision.body.outputSchema) : {};
|
|
519
|
+
// A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
|
|
520
|
+
await replayClaimed(deps.store, runRow.agentId, launch, firstChoice);
|
|
521
|
+
// A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
|
|
522
|
+
// answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
|
|
523
|
+
const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
|
|
524
|
+
const { serve: workflowFirst, revise: workflowRevise } = firstChoice;
|
|
525
|
+
const workflows = laidFor(laidFlows, firstChoice);
|
|
497
526
|
const learns = learnsWorkflows(revision.kind, workflows);
|
|
498
527
|
if (webNames.length || learns) {
|
|
499
528
|
// The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
|
|
@@ -538,25 +567,30 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
538
567
|
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
|
|
539
568
|
// own MCP as the loop wraps it. Its model nodes run on the session's one model: what each node's trace says it ran on.
|
|
540
569
|
gate.learn(workflows);
|
|
541
|
-
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(
|
|
570
|
+
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(catalog ? { mcp: catalog } : {}), workspace: ws.workspace, modelName: () => chosen.model.modelId, ...(replay ? { replay } : {}) });
|
|
542
571
|
}
|
|
543
572
|
}
|
|
573
|
+
// ask_person, when granted: pi's own tool (tools.ts askPerson), bound as a host tool the way the web tools are. Its call
|
|
574
|
+
// answers what pi's does; the loop then cuts the CLI's turn at the question (adapter-loop.ts, turn-ending host tools),
|
|
575
|
+
// so the run parks on the person or waits for them in its claim exactly as a pi run does.
|
|
576
|
+
const askTool = granted.includes(ASK_TOOL) ? hostToolOf(ASK_TOOL, askPerson, ctx) : undefined;
|
|
544
577
|
const session = {
|
|
545
578
|
key: `run:${claim.runId}`,
|
|
546
579
|
label: runRow.agentId,
|
|
547
|
-
system: [environmentLine(), checkout?.note, instructions, guidance].filter((line) => Boolean(line)),
|
|
580
|
+
system: [environmentLine(), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
|
|
548
581
|
// The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
|
|
549
582
|
// redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
|
|
550
|
-
tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
|
|
583
|
+
tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
|
|
551
584
|
context: "fresh",
|
|
552
585
|
...(thinking ? { thinking } : {}),
|
|
553
586
|
};
|
|
554
|
-
|
|
555
|
-
const input = await firstMessage(
|
|
587
|
+
// A typed input's other fields follow its content as one json block (inputMessage).
|
|
588
|
+
const input = await firstMessage(inputMessage(launch.input), ws.workspace);
|
|
556
589
|
// The run's end-of-run step, when it learns, the same as the pi spec's: the reflect-and-propose turn over the run's
|
|
557
590
|
// store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this claim's
|
|
558
591
|
// Archil disk — so the proposal is checked against the seed in the run's own Workspace, never this machine's local path.
|
|
559
|
-
|
|
592
|
+
// A replay run asks nothing at its end: it is the promotion's, never the agent's to learn from.
|
|
593
|
+
const endOfRun = launch.replay ? undefined : learningEndOfRun(launch, {
|
|
560
594
|
store: deps.store,
|
|
561
595
|
data: deps.data,
|
|
562
596
|
...(deps.env ? { env: deps.env } : {}),
|
|
@@ -566,6 +600,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
566
600
|
signIns: signInReads(deps.store, deps.sealKey),
|
|
567
601
|
handed: handedKeys,
|
|
568
602
|
stored: () => storeSecrets(deps.store, deps.sealKey, deps.data),
|
|
603
|
+
log,
|
|
569
604
|
// A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
|
|
570
605
|
decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
|
|
571
606
|
learningFolder: archil === undefined
|
|
@@ -581,12 +616,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
581
616
|
...(runner.record ? { record: runner.record } : {}),
|
|
582
617
|
gate,
|
|
583
618
|
runCap,
|
|
619
|
+
// The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry), as on pi.
|
|
620
|
+
...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
|
|
584
621
|
...(cap ? { cap } : {}),
|
|
585
|
-
// The run's MCP for a harness with its own client (mcp-run.ts),
|
|
586
|
-
|
|
622
|
+
// The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
|
|
623
|
+
// the catalog tools the session mounts; absent when none.
|
|
624
|
+
...(catalog ? { mcp: catalog } : {}),
|
|
587
625
|
// The run's end-of-run step, when it learns (the spec's, preferred over the loop's deps': adapter-loop.ts stepOf).
|
|
588
626
|
...(endOfRun ? { endOfRun } : {}),
|
|
589
627
|
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
628
|
+
...(workflowFirst ? { workflowFirst } : {}),
|
|
629
|
+
...(workflowRevise ? { workflowRevise } : {}),
|
|
590
630
|
// The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
|
|
591
631
|
...(life ? { lifecycle: life } : {}),
|
|
592
632
|
agentId: runRow.agentId,
|
|
@@ -616,7 +656,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
616
656
|
// session, and its decisions (a learned workflow's decision nodes) are the run's cost too, as the pi spec's.
|
|
617
657
|
const total = runEndCost({ model, paid: run.ledger?.paid ? run.ledger.paid.spentUsd() : 0, decisions: bookedSpend(all, "decisions").usd });
|
|
618
658
|
// An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
|
|
619
|
-
return { costUsd: total, metrics };
|
|
659
|
+
return { costUsd: total, metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries) } };
|
|
620
660
|
},
|
|
621
661
|
// A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
|
|
622
662
|
...(heldComputer ? { held: heldComputer } : {}),
|
|
@@ -39,6 +39,7 @@ const words = (error) => (error instanceof Error ? error.message : String(error)
|
|
|
39
39
|
*/
|
|
40
40
|
export async function runChannelCall(computer, call, signal, now = Date.now) {
|
|
41
41
|
const started = performance.now();
|
|
42
|
+
const startedAt = now();
|
|
42
43
|
let answer;
|
|
43
44
|
let leave;
|
|
44
45
|
try {
|
|
@@ -57,5 +58,5 @@ export async function runChannelCall(computer, call, signal, now = Date.now) {
|
|
|
57
58
|
finally {
|
|
58
59
|
leave?.();
|
|
59
60
|
}
|
|
60
|
-
return { answer, record: callRecordOf(call.method, call.params, answer, performance.now() - started), at: now() };
|
|
61
|
+
return { answer, record: callRecordOf(call.method, call.params, answer, performance.now() - started, startedAt), at: now() };
|
|
61
62
|
}
|
|
@@ -26,6 +26,9 @@ export declare function suiteTools(countFile?: string): {
|
|
|
26
26
|
letSlowGo: () => void;
|
|
27
27
|
slowStarted: Promise<void>;
|
|
28
28
|
};
|
|
29
|
+
/** Catalog tools (an MCP server's, by wire name) that do nothing, enough of them to pass DEFER_CATALOG_OVER: a run with that
|
|
30
|
+
* many has its catalog deferred (not listed) and is offered tools_search and tools_call, which the meta cases need. */
|
|
31
|
+
export declare function fillerTools(count?: number): Record<string, SuiteTool>;
|
|
29
32
|
/** A store in a data directory of its own, one queued run, and runners started on it (each its own connection). */
|
|
30
33
|
/** The stores' clock skew a runner process reads (child.ts): the file holds the milliseconds the clock moved, so the
|
|
31
34
|
* process's store moves with the case's (runOut). */
|