@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
package/dist/runner/mcp-run.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
2
|
import { wireName } from "../catalog.js";
|
|
3
|
-
import { mcpGateway
|
|
3
|
+
import { mcpGateway } from "../mcp-gateway.js";
|
|
4
4
|
import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
|
|
5
5
|
import { privateOAuthHosts } from "../mcp-private-hosts.js";
|
|
6
|
-
import {
|
|
7
|
-
import { deniedText } from "./loop-contract.js";
|
|
8
|
-
import { STOPPED_WHILE_WAITING } from "../refusal-words.js";
|
|
9
|
-
import { endedAnswer, KINDS } from "./journal-kinds.js";
|
|
6
|
+
import { mcpToolName, pinnedEffect } from "../tool-gate.js";
|
|
10
7
|
import { mcpClaim } from "./mcp-claim.js";
|
|
11
|
-
|
|
12
|
-
/** The run's MCP for one claim: undefined when it grants no MCP tool. Throws McpClaimRefused (a
|
|
8
|
+
import { registryListing } from "../mcp-pin-first.js";
|
|
9
|
+
/** The run's MCP for one claim: undefined when it grants no MCP tool. Throws McpClaimRefused (a granted tool its pin lacks,
|
|
13
10
|
* a pinned tool that is a meta tool now: the loop ends the run in those words, before its session opens) or Fenced (the
|
|
14
11
|
* claim lost while a refresh was awaited: the loop ends interrupted). A builder calls it before it takes anything it
|
|
15
12
|
* would have to let go, since a throw here leaves its spec unbuilt and its release uncalled. */
|
|
@@ -26,6 +23,8 @@ export async function mcpForClaim(options) {
|
|
|
26
23
|
grants: options.grants,
|
|
27
24
|
sealKey: options.sealKey,
|
|
28
25
|
signal: held.signal,
|
|
26
|
+
// A run whose revision has no pin (one made before the upgrade) pins it here, listing as a save does.
|
|
27
|
+
pinListing: registryListing(options.store, options.sealKey, { loopback: options.loopback === true, ...(options.network ? { network: options.network } : {}), ...(githubApp ? { githubApp } : {}), ...(options.githubMcpOrigin ? { appOrigin: options.githubMcpOrigin } : {}) }),
|
|
29
28
|
...(options.bounds ? { bounds: options.bounds } : {}),
|
|
30
29
|
...(options.network ? { network: options.network } : {}),
|
|
31
30
|
...(options.loopback ? { loopback: true } : {}),
|
|
@@ -64,12 +63,16 @@ export async function mcpForClaim(options) {
|
|
|
64
63
|
...(options.callBounds ? { bounds: options.callBounds } : {}),
|
|
65
64
|
});
|
|
66
65
|
const catalog = new Map();
|
|
66
|
+
const declared = new Map();
|
|
67
67
|
const tools = [];
|
|
68
68
|
for (const [server, pinned] of Object.entries(pin)) {
|
|
69
69
|
for (const tool of pinned.tools) {
|
|
70
70
|
const name = mcpToolName(server, tool.name);
|
|
71
71
|
const wire = wireName(name);
|
|
72
72
|
catalog.set(wire, name);
|
|
73
|
+
const properties = tool.inputSchema?.properties;
|
|
74
|
+
if (typeof properties === "object" && properties !== null && !Array.isArray(properties))
|
|
75
|
+
declared.set(name, new Set(Object.keys(properties)));
|
|
73
76
|
tools.push({
|
|
74
77
|
name: wire,
|
|
75
78
|
description: tool.description || tool.title || `${tool.name}, a tool of the MCP server ${server}.`,
|
|
@@ -86,6 +89,7 @@ export async function mcpForClaim(options) {
|
|
|
86
89
|
return {
|
|
87
90
|
tools,
|
|
88
91
|
catalogOf: (tool) => catalog.get(tool),
|
|
92
|
+
argumentsOf: (name) => declared.get(name),
|
|
89
93
|
priceOf(name) {
|
|
90
94
|
const parsed = /^mcp:([^/]+)\/(.+)$/.exec(name);
|
|
91
95
|
const pinned = parsed && Object.hasOwn(pin, parsed[1]) ? pin[parsed[1]] : undefined;
|
|
@@ -93,84 +97,8 @@ export async function mcpForClaim(options) {
|
|
|
93
97
|
return undefined;
|
|
94
98
|
return pinned.prices && Object.hasOwn(pinned.prices, parsed[2]) ? pinned.prices[parsed[2]] : "not metered";
|
|
95
99
|
},
|
|
96
|
-
|
|
97
|
-
servers: gateway.servers,
|
|
98
|
-
async call(server, tool, args, { signal, callId }) {
|
|
99
|
-
const name = mcpToolName(server, tool);
|
|
100
|
-
const host = wrapped.get(wireName(name));
|
|
101
|
-
if (!host)
|
|
102
|
-
return said(`${tool} is not a tool of the MCP server ${server} in this run.`, true);
|
|
103
|
-
// The gate and the run's record know a call by its id: one without is never sent.
|
|
104
|
-
if (!callId)
|
|
105
|
-
return said(noCallId(name), true);
|
|
106
|
-
const answer = await gate({ callId, tool: name, args });
|
|
107
|
-
if (answer && "refused" in answer)
|
|
108
|
-
return said(answer.refused, true);
|
|
109
|
-
// The run parks on its ask: the CLI reads main's waiting words, and its adapter records the call as one that did not
|
|
110
|
-
// run (McpCallResult.parked); the claim that resumes the run answers it (parkedFollowUp).
|
|
111
|
-
if (answer)
|
|
112
|
-
return { ...said(waitingText(name)), parked: true };
|
|
113
|
-
const result = await host.call(args, { callId, signal });
|
|
114
|
-
return said(result.text, result.isError === true);
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
100
|
+
effectOf: (name) => pinnedEffect(pin, name),
|
|
117
101
|
fresh: () => step.fresh(),
|
|
118
102
|
release: () => held.abort(),
|
|
119
103
|
};
|
|
120
104
|
}
|
|
121
|
-
/** For a harness with its own MCP client, on a claim that finds its MCP calls parked through the door: each asked call's
|
|
122
|
-
* answer acted on once, as main's gate did after a person answered (tool-gate.ts): an allow runs the call through the
|
|
123
|
-
* loop's path (its start and end on the run's record, never sent twice: a call with an end is answered from it), a deny
|
|
124
|
-
* is told in its words; then one message, main's resume message per call (resumeText), the session goes on with.
|
|
125
|
-
* "park": a call still waits (the run parks again, its ask asked again). Undefined: nothing waits. A call a follow-up
|
|
126
|
-
* already answered (its resume message on the record) is not answered again. */
|
|
127
|
-
export async function parkedFollowUp(mcp, options) {
|
|
128
|
-
const said = new Set();
|
|
129
|
-
for (const entry of options.entries) {
|
|
130
|
-
const text = entry.data?.text;
|
|
131
|
-
if (entry.kind === KINDS.message && typeof text === "string" && text.startsWith(RESUME_PREFIX))
|
|
132
|
-
said.add(text);
|
|
133
|
-
}
|
|
134
|
-
const answered = (callId) => [...said].some((text) => text.includes(` call ${callId} `));
|
|
135
|
-
const ended = new Map();
|
|
136
|
-
for (const entry of options.entries)
|
|
137
|
-
if (entry.kind === KINDS.callEnd)
|
|
138
|
-
ended.set(entry.data.callId, entry.data);
|
|
139
|
-
const texts = [];
|
|
140
|
-
const callIds = [];
|
|
141
|
-
const asked = new Set();
|
|
142
|
-
for (const entry of options.entries) {
|
|
143
|
-
if (entry.kind !== KINDS.ask)
|
|
144
|
-
continue;
|
|
145
|
-
const ask = entry.data;
|
|
146
|
-
if (asked.has(ask.callId) || mcp.priceOf(ask.tool) === undefined || answered(ask.callId))
|
|
147
|
-
continue;
|
|
148
|
-
asked.add(ask.callId);
|
|
149
|
-
const call = { callId: ask.callId, tool: ask.tool, args: (ask.args ?? {}) };
|
|
150
|
-
const answer = await options.answer(call, ask.price ?? null);
|
|
151
|
-
if (answer === "park")
|
|
152
|
-
return "park";
|
|
153
|
-
let result;
|
|
154
|
-
if (!answer.approved) {
|
|
155
|
-
// A stop's withdrawal (a reopened run's parked call) reads as one; any other deny in its words.
|
|
156
|
-
result = { text: answer.decision === "withdrawn" ? STOPPED_WHILE_WAITING : deniedText(call.tool, answer.note), isError: true };
|
|
157
|
-
await options.refused?.(call, result.text);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
const done = ended.get(call.callId);
|
|
161
|
-
const denied = done ? undefined : await options.deniedNow(call);
|
|
162
|
-
// A call that already ended is answered from its end (endedAnswer: a crash-cut one in the kernel's words).
|
|
163
|
-
if (done)
|
|
164
|
-
result = endedAnswer(call.tool, done);
|
|
165
|
-
else if (denied !== undefined) {
|
|
166
|
-
result = { text: denied, isError: true };
|
|
167
|
-
await options.refused?.(call, denied);
|
|
168
|
-
}
|
|
169
|
-
else
|
|
170
|
-
result = await options.run(call);
|
|
171
|
-
}
|
|
172
|
-
texts.push(resumeText({ tool: call.tool, call_id: call.callId }, argsPreview(call.args), answer.approved ? "allow" : "deny", { text: result.text, isError: result.isError === true }));
|
|
173
|
-
callIds.push(call.callId);
|
|
174
|
-
}
|
|
175
|
-
return texts.length ? { text: `${texts.join("\n\n")}\n\n${RESUME_GO_ON}`, callIds } : undefined;
|
|
176
|
-
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
2
|
+
import { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH } from "../meta-tool-names.js";
|
|
3
|
+
export { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH };
|
|
4
|
+
/** How many tools a search answers with when its call names no limit, and the most it may name. */
|
|
5
|
+
export declare const SEARCH_DEFAULT_LIMIT = 8;
|
|
6
|
+
export declare const SEARCH_MAX_LIMIT = 25;
|
|
7
|
+
/** A script's whole run, its nested calls' time included, and the memory its VM may take. */
|
|
8
|
+
export declare const CODEMODE_MS = 600000;
|
|
9
|
+
/** A tool as a search answers it: its name, what it does and its input's schema. */
|
|
10
|
+
export interface FoundTool {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
input_schema: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/** The tools of `tools` (the run's own, none of the three here) whose names `granted` holds, ranked for `query`. */
|
|
16
|
+
export declare function searchTools(query: string, tools: readonly HostTool[], granted: (name: string) => Promise<boolean>, limit?: number): Promise<FoundTool[]>;
|
|
17
|
+
/** The run's tool a model's name for it names: its own name, or one a harness gives it on its tool channel (claude-agent's
|
|
18
|
+
* `mcp__hands__<name>`, OpenCode's `hands_<name>`, Codex's `mcp_<server>__<tool>` for an MCP tool). */
|
|
19
|
+
export declare function toolNamed(name: string, tools: readonly HostTool[]): HostTool | undefined;
|
|
20
|
+
/** Why `name` can't be called through tools_call or a script, or undefined: one of the three, or no tool of this run. */
|
|
21
|
+
export declare function refusedName(caller: string, name: string, tools: readonly HostTool[]): string | undefined;
|
|
22
|
+
export interface MetaToolsOptions {
|
|
23
|
+
/** The run's tools as the session gives them, the three left out (each call reads them now). */
|
|
24
|
+
tools: () => readonly HostTool[];
|
|
25
|
+
/** Whether a tool is granted to search: its setting is not deny. */
|
|
26
|
+
granted: (name: string) => Promise<boolean>;
|
|
27
|
+
/** Whether to offer codemode (every harness but Codex, which keeps its own, and not where its setting is deny). */
|
|
28
|
+
codemode: boolean;
|
|
29
|
+
/** Whether to offer tools_search and tools_call: the run's catalog tools are deferred (not listed), so the model finds
|
|
30
|
+
* and calls them through these (tool-deferral.ts; never where the harness defers them itself, or a setting is deny). */
|
|
31
|
+
discovery: {
|
|
32
|
+
search: boolean;
|
|
33
|
+
call: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The three tools for a session: each `nests` (but the search, which calls nothing). */
|
|
37
|
+
export declare function metaTools(options: MetaToolsOptions): HostTool[];
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Three host tools over the run's own tools, on every harness: tools_search finds the run's tools by what they do,
|
|
2
|
+
// tools_call calls one by name, and codemode runs a script that calls them (not on Codex, which keeps its own code mode).
|
|
3
|
+
//
|
|
4
|
+
// None of them is a door around the gate. Each call they make is a call of its own nested in theirs (NestedCalls, which
|
|
5
|
+
// each harness gives a tool that `nests`): asked about at the gate as the tool it calls, by that tool's name, its intent
|
|
6
|
+
// and outcome recorded under `<callId>/<key>`, its paid requests booked under that id as a call the model made would be.
|
|
7
|
+
// A call the record finished answers from the record and never runs twice, across a park, a resume or a crash: a rerun
|
|
8
|
+
// of the calling tool replays them.
|
|
9
|
+
//
|
|
10
|
+
// A script follows Codex's rule for an ask inside it: the nested call the gate parks parks the run; once a person
|
|
11
|
+
// answers, the script runs again from its start, its recorded calls answered from their records, the parked call runs
|
|
12
|
+
// once (or is refused), its outcome is the script's output, and the rest of the script does not run. A refusal of any
|
|
13
|
+
// nested call ends the script with the refusal's words. The script sees the tools and the answers its calls get, nothing
|
|
14
|
+
// else of the run: no environment, no key, no file.
|
|
15
|
+
import { randomBytes } from "node:crypto";
|
|
16
|
+
import { CodemodeSandbox, toCodemodeIdentifier } from "@earendil-works/pi-codemode";
|
|
17
|
+
import { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH } from "../meta-tool-names.js";
|
|
18
|
+
export { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH };
|
|
19
|
+
/** How many tools a search answers with when its call names no limit, and the most it may name. */
|
|
20
|
+
export const SEARCH_DEFAULT_LIMIT = 8;
|
|
21
|
+
export const SEARCH_MAX_LIMIT = 25;
|
|
22
|
+
/** A script's whole run, its nested calls' time included, and the memory its VM may take. */
|
|
23
|
+
export const CODEMODE_MS = 600_000;
|
|
24
|
+
const CODEMODE_MEMORY_BYTES = 256 * 1024 * 1024;
|
|
25
|
+
/** pi-durable's BM25 ranking (its tool_search's and code mode's searchTools'), the same file its own tools rank with: the
|
|
26
|
+
* package exports its tools but not the ranker, so it is read from beside the package's entry. */
|
|
27
|
+
const rankDocuments = (await import(new URL("./search.js", import.meta.resolve("@earendil-works/pi-durable")).href)).rankDocuments;
|
|
28
|
+
/** The words of a tool's schema a search reads beside its description: its arguments' names and their descriptions. */
|
|
29
|
+
function schemaWords(schema) {
|
|
30
|
+
const properties = (schema.properties ?? {});
|
|
31
|
+
return Object.entries(properties).map(([name, property]) => `${name} ${typeof property?.description === "string" ? property.description : ""}`).join(" ");
|
|
32
|
+
}
|
|
33
|
+
/** The tools of `tools` (the run's own, none of the three here) whose names `granted` holds, ranked for `query`. */
|
|
34
|
+
export async function searchTools(query, tools, granted, limit = SEARCH_DEFAULT_LIMIT) {
|
|
35
|
+
const searched = [];
|
|
36
|
+
for (const tool of tools)
|
|
37
|
+
if (!META_TOOLS.has(tool.name) && (await granted(tool.name)))
|
|
38
|
+
searched.push(tool);
|
|
39
|
+
const byName = new Map(searched.map((tool) => [tool.name, tool]));
|
|
40
|
+
const names = rankDocuments(query, searched.map((tool) => ({ name: tool.name, text: `${tool.description} ${schemaWords(tool.inputSchema)}` })), limit);
|
|
41
|
+
return names.flatMap((name) => {
|
|
42
|
+
const tool = byName.get(name);
|
|
43
|
+
return tool ? [{ name: tool.name, description: tool.description, input_schema: tool.inputSchema }] : [];
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** The run's tool a model's name for it names: its own name, or one a harness gives it on its tool channel (claude-agent's
|
|
47
|
+
* `mcp__hands__<name>`, OpenCode's `hands_<name>`, Codex's `mcp_<server>__<tool>` for an MCP tool). */
|
|
48
|
+
export function toolNamed(name, tools) {
|
|
49
|
+
const candidates = [name, name.replace(/^mcp__hands__/, ""), name.replace(/^hands_/, ""), name.replace(/^mcp_(?!_)/, "mcp__")];
|
|
50
|
+
for (const candidate of candidates) {
|
|
51
|
+
const tool = tools.find((one) => one.name === candidate);
|
|
52
|
+
if (tool)
|
|
53
|
+
return tool;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Why `name` can't be called through tools_call or a script, or undefined: one of the three, or no tool of this run. */
|
|
58
|
+
export function refusedName(caller, name, tools) {
|
|
59
|
+
const own = name.replace(/^mcp__hands__/, "").replace(/^hands_/, "");
|
|
60
|
+
if (META_TOOLS.has(own))
|
|
61
|
+
return `${caller} can't call ${own}: ${TOOLS_SEARCH}, ${TOOLS_CALL} and ${CODEMODE} are called by the model itself, never through each other. Nothing was run.`;
|
|
62
|
+
if (!toolNamed(name, tools))
|
|
63
|
+
return `${caller} can't call ${JSON.stringify(name).slice(0, 120)}: this run has no tool by that name. Find the run's tools with ${TOOLS_SEARCH}. Nothing was run.`;
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const NO_NESTED = (caller) => `${caller} can't run here: this harness gives it no way to call the run's tools. Nothing was run.`;
|
|
67
|
+
/** A nested answer as a tool's answer. */
|
|
68
|
+
const answered = (result) => ({ text: result.text, ...(result.isError ? { isError: true } : {}), ...(result.images?.length ? { images: result.images } : {}), ...(result.structured !== undefined ? { structured: result.structured } : {}) });
|
|
69
|
+
/** The three tools for a session: each `nests` (but the search, which calls nothing). */
|
|
70
|
+
export function metaTools(options) {
|
|
71
|
+
const own = () => options.tools().filter((tool) => !META_TOOLS.has(tool.name));
|
|
72
|
+
const search = {
|
|
73
|
+
name: TOOLS_SEARCH,
|
|
74
|
+
description: `This run lists only some of its tools. Search all of them by what they do, and get each match's name, description and input schema, best match first. Call a match with ${options.discovery.call ? TOOLS_CALL : "its name"}${options.codemode ? `, or from a ${CODEMODE} script` : ""}.`,
|
|
75
|
+
inputSchema: { type: "object", properties: { query: { type: "string", description: "What the tool should do, in a few words, or its name." }, limit: { type: "integer", minimum: 1, maximum: SEARCH_MAX_LIMIT, description: `How many tools to answer with (default ${SEARCH_DEFAULT_LIMIT}).` } }, required: ["query"], additionalProperties: false },
|
|
76
|
+
replay: "safe",
|
|
77
|
+
call: async (args) => {
|
|
78
|
+
const { query, limit } = (args ?? {});
|
|
79
|
+
if (typeof query !== "string" || query.trim() === "")
|
|
80
|
+
return { text: `${TOOLS_SEARCH} needs a query: what the tool should do.`, isError: true };
|
|
81
|
+
const most = typeof limit === "number" && Number.isInteger(limit) ? Math.min(Math.max(limit, 1), SEARCH_MAX_LIMIT) : SEARCH_DEFAULT_LIMIT;
|
|
82
|
+
const found = await searchTools(query, own(), options.granted, most);
|
|
83
|
+
return { text: found.length ? JSON.stringify(found) : `No tool of this run matches ${JSON.stringify(query)}.`, structured: found };
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const call = {
|
|
87
|
+
name: TOOLS_CALL,
|
|
88
|
+
description: `Call one of this run's tools by its name (as ${TOOLS_SEARCH} gives it) with its arguments. The call is asked about and recorded as that tool's own: a tool that needs a person's approval waits for it.`,
|
|
89
|
+
inputSchema: { type: "object", properties: { name: { type: "string", description: "The tool's name." }, args: { type: "object", description: "The tool's arguments, as its input schema says.", additionalProperties: true } }, required: ["name"], additionalProperties: false },
|
|
90
|
+
replay: "safe",
|
|
91
|
+
nests: true,
|
|
92
|
+
call: async (args, context) => {
|
|
93
|
+
const { name, args: given } = (args ?? {});
|
|
94
|
+
if (typeof name !== "string" || name === "")
|
|
95
|
+
return { text: `${TOOLS_CALL} needs the name of the tool to call.`, isError: true };
|
|
96
|
+
if (given !== undefined && (given === null || typeof given !== "object" || Array.isArray(given)))
|
|
97
|
+
return { text: `${TOOLS_CALL}'s args must be an object of the tool's arguments.`, isError: true };
|
|
98
|
+
const tools = own();
|
|
99
|
+
const refused = refusedName(TOOLS_CALL, name, tools);
|
|
100
|
+
if (refused)
|
|
101
|
+
return { text: refused, isError: true };
|
|
102
|
+
if (!context.nested)
|
|
103
|
+
return { text: NO_NESTED(TOOLS_CALL), isError: true };
|
|
104
|
+
return answered(await context.nested.call(toolNamed(name, tools).name, (given ?? {}), "call"));
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
// A few of the run's tools as the script writes them (`tools.<name>`): names that resolve, as the model's own tool list
|
|
108
|
+
// may show them under a harness's prefix, which a script's `tools` has no property for.
|
|
109
|
+
const examples = own().slice(0, 3).map((tool) => `\`tools.${toCodemodeIdentifier(tool.name)}\``);
|
|
110
|
+
const codemode = {
|
|
111
|
+
name: CODEMODE,
|
|
112
|
+
description: [
|
|
113
|
+
`Run a JavaScript script (the body of an async function: top-level await and return work) that calls this run's tools as \`await tools.<name>(args)\`; ${options.discovery.search ? `find them with ${TOOLS_SEARCH}, and ` : ""}\`ALL_TOOLS\` lists them. A call answers its value, and a call that fails throws. A tool is called by its own name, exactly as \`ALL_TOOLS\`${options.discovery.search ? ` and ${TOOLS_SEARCH}` : ""} give it${examples.length ? ` (here: ${examples.join(", ")})` : ""}, never by the name your own tool list may show for it with a harness's prefix (\`hands_\`, \`mcp__hands__\`): leave the prefix off.`,
|
|
114
|
+
"The script's text(...) and console output, and its returned value, are the answer. It has no timers, network or files of its own: only the tools.",
|
|
115
|
+
"Each call is asked about and recorded as that tool's own. A call that needs a person's approval stops the script: once they answer, that call runs (or is refused), its outcome is the answer, and the rest of the script does not run. A refused call ends the script with the refusal.",
|
|
116
|
+
].join(" "),
|
|
117
|
+
inputSchema: { type: "object", properties: { script: { type: "string", description: "The script: the body of an async function." } }, required: ["script"], additionalProperties: false },
|
|
118
|
+
replay: "safe",
|
|
119
|
+
nests: true,
|
|
120
|
+
call: async (args, context) => {
|
|
121
|
+
const { script } = (args ?? {});
|
|
122
|
+
if (typeof script !== "string" || script.trim() === "")
|
|
123
|
+
return { text: `${CODEMODE} needs a script: the body of an async function.`, isError: true };
|
|
124
|
+
if (!context.nested)
|
|
125
|
+
return { text: NO_NESTED(CODEMODE), isError: true };
|
|
126
|
+
return runScript(script, own(), context.nested, context.signal);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
return [...(options.discovery.search ? [search] : []), ...(options.discovery.call ? [call] : []), ...(options.codemode ? [codemode] : [])];
|
|
130
|
+
}
|
|
131
|
+
/** One nested call's line in a script's stopped answer, as Codex's code mode words its recovered calls. */
|
|
132
|
+
function lineOf(index, name, result) {
|
|
133
|
+
const said = JSON.stringify(result.text.length > 2_000 ? `${result.text.slice(0, 2_000)}…` : result.text);
|
|
134
|
+
const label = `${index}. ${name}`;
|
|
135
|
+
if (result.refused)
|
|
136
|
+
return `${label} was refused: ${said}. It did not run.`;
|
|
137
|
+
if (result.interrupted)
|
|
138
|
+
return `${label} was started and did not report a result, so it may have taken effect: check before calling it again. It was not run again.`;
|
|
139
|
+
if (result.isError)
|
|
140
|
+
return `${label} failed: ${said}. It was not run again.`;
|
|
141
|
+
return `${label} completed: ${said}. Its effect is done; it was not run again.`;
|
|
142
|
+
}
|
|
143
|
+
/** The script's output and value, as the model reads them, and the images it showed. */
|
|
144
|
+
function shownOf(output, value) {
|
|
145
|
+
const words = [];
|
|
146
|
+
const images = [];
|
|
147
|
+
for (const item of output) {
|
|
148
|
+
if (item.type === "text")
|
|
149
|
+
words.push(item.text);
|
|
150
|
+
else
|
|
151
|
+
images.push({ data: item.data, mimeType: item.mimeType });
|
|
152
|
+
}
|
|
153
|
+
if (value !== undefined)
|
|
154
|
+
words.push(typeof value === "string" ? value : JSON.stringify(value));
|
|
155
|
+
return { text: words.join("\n"), images };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Run `script` deterministically (pi-codemode's `start`: its clock, its randomness and its tools fixed by the call's first
|
|
159
|
+
* run, memoized), each of its tool calls a nested call, answered one at a time in the order the script made them. A rerun
|
|
160
|
+
* of the call (after a park or a crash) makes the same calls: the recorded ones are answered from their records, and the
|
|
161
|
+
* first one that runs now ends the script with its outcome (Codex's rule), as does any refusal or interrupted call.
|
|
162
|
+
*/
|
|
163
|
+
async function runScript(script, tools, nested, signal) {
|
|
164
|
+
const nonce = randomBytes(8).toString("hex");
|
|
165
|
+
const first = await nested.memo("start", { startedAt: Date.now(), seed: randomBytes(4).readUInt32BE(0), nonce, tools: tools.map((tool) => [tool.name, toCodemodeIdentifier(tool.name)]) });
|
|
166
|
+
const start = first;
|
|
167
|
+
const rerun = start.nonce !== nonce;
|
|
168
|
+
const declared = new Map(tools.map((tool) => [tool.name, tool]));
|
|
169
|
+
const stop = new AbortController();
|
|
170
|
+
const sandbox = new CodemodeSandbox({ memoryLimitBytes: CODEMODE_MEMORY_BYTES });
|
|
171
|
+
const calls = [];
|
|
172
|
+
const told = [];
|
|
173
|
+
let ended;
|
|
174
|
+
let failed;
|
|
175
|
+
let wake = () => { };
|
|
176
|
+
try {
|
|
177
|
+
const run = sandbox.start(script, {
|
|
178
|
+
startedAt: start.startedAt,
|
|
179
|
+
seed: start.seed,
|
|
180
|
+
// The tools the first run declared, by the names it gave them, that this run still has.
|
|
181
|
+
tools: start.tools.filter(([name]) => declared.has(name)).map(([name, jsName]) => ({ name, jsName, description: declared.get(name).description })),
|
|
182
|
+
signal: AbortSignal.any([signal, stop.signal]),
|
|
183
|
+
timeoutMs: CODEMODE_MS,
|
|
184
|
+
onCall: (call) => {
|
|
185
|
+
calls.push(call);
|
|
186
|
+
wake();
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
// The calls answered one at a time, in the order the script made them: the same order, and the same keys, in a rerun.
|
|
190
|
+
let seq = 0;
|
|
191
|
+
const answering = (async () => {
|
|
192
|
+
while (!run.finished && !ended) {
|
|
193
|
+
const call = calls.shift();
|
|
194
|
+
if (!call) {
|
|
195
|
+
await new Promise((resolve) => {
|
|
196
|
+
wake = resolve;
|
|
197
|
+
void run.result.then(() => resolve(), () => resolve());
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const tool = toolNamed(call.name, tools);
|
|
202
|
+
const refused = call.target !== "tool" ? `${call.name} is no tool of this run.` : refusedName(CODEMODE, call.name, tools);
|
|
203
|
+
const args = call.args && typeof call.args === "object" && !Array.isArray(call.args) ? call.args : {};
|
|
204
|
+
const result = refused || !tool ? { text: refused ?? `${call.name} is no tool of this run.`, isError: true, refused: true, fresh: true } : await nested.call(tool.name, args, `s${call.id}`);
|
|
205
|
+
told.push({ name: tool?.name ?? call.name, result });
|
|
206
|
+
// A refusal, a call cut by a crash, or (in a rerun) the first call that ran now: the script ends with it.
|
|
207
|
+
if (result.refused || result.interrupted || (rerun && result.fresh)) {
|
|
208
|
+
ended = endedWith(told, result, rerun && result.fresh && !result.refused);
|
|
209
|
+
stop.abort();
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
seq += 1;
|
|
213
|
+
const outcome = result.isError ? { ok: false, message: result.text } : { ok: true, value: scriptValue(result) };
|
|
214
|
+
if (!run.finished)
|
|
215
|
+
run.deliver(seq, start.startedAt, call.id, outcome);
|
|
216
|
+
}
|
|
217
|
+
})().catch((error) => {
|
|
218
|
+
failed = error;
|
|
219
|
+
stop.abort();
|
|
220
|
+
});
|
|
221
|
+
const result = await run.result;
|
|
222
|
+
await answering;
|
|
223
|
+
// A nested call that parked (the session let go) or a drive that halted: the call has no answer here.
|
|
224
|
+
if (failed !== undefined)
|
|
225
|
+
throw failed;
|
|
226
|
+
if (signal.aborted)
|
|
227
|
+
throw signal.reason ?? new Error(`${CODEMODE} was stopped`);
|
|
228
|
+
if (ended)
|
|
229
|
+
return ended;
|
|
230
|
+
const shown = shownOf(result.output, result.ok ? result.value : undefined);
|
|
231
|
+
if (!result.ok) {
|
|
232
|
+
const why = result.error.kind === "timeout" ? `the script ran past ${CODEMODE_MS} ms: ${result.error.message}` : result.error.message;
|
|
233
|
+
return { text: [shown.text, `The script failed: ${why}`].filter(Boolean).join("\n"), isError: true, ...(shown.images.length ? { images: shown.images } : {}) };
|
|
234
|
+
}
|
|
235
|
+
return { text: shown.text || "(the script returned nothing and showed nothing)", ...(shown.images.length ? { images: shown.images } : {}), ...(result.value !== undefined ? { structured: result.value } : {}) };
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
await sandbox.close();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** A nested call's value in a script: its structured value (an MCP result's structuredContent) when it has one; else, when
|
|
242
|
+
* its answer is one text part (no image beside it) whose text parses as a JSON object or array, that value (a Composio
|
|
243
|
+
* answer comes as one); else its text. The text the model reads of the call is its text either way. */
|
|
244
|
+
function scriptValue(result) {
|
|
245
|
+
if (result.structured !== undefined)
|
|
246
|
+
return result.structured;
|
|
247
|
+
const text = result.text.trim();
|
|
248
|
+
if (result.images?.length || !(text.startsWith("{") || text.startsWith("[")))
|
|
249
|
+
return result.text;
|
|
250
|
+
try {
|
|
251
|
+
const value = JSON.parse(text);
|
|
252
|
+
return value !== null && typeof value === "object" ? value : result.text;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return result.text;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** The answer of a script that ended at `last`: a refusal's words, or (`ranNow`: the first call that ran on the script's
|
|
259
|
+
* rerun, after a person's answer or a crash) that call's outcome, with every call before it as recorded. */
|
|
260
|
+
function endedWith(told, last, ranNow) {
|
|
261
|
+
const lines = told.map(({ name, result }, i) => lineOf(i + 1, name, result));
|
|
262
|
+
if (last.refused)
|
|
263
|
+
return { text: `${last.text}\nThe script stopped at this refused call, and nothing after it ran. Its calls, in order:\n${lines.join("\n")}`, isError: true };
|
|
264
|
+
if (!ranNow)
|
|
265
|
+
return { text: `The script stopped at a call cut off before it reported a result, and nothing after it ran. Its calls, in order:\n${lines.join("\n")}`, isError: true };
|
|
266
|
+
const head = `The script was stopped (it waited for a person's answer, or the session stopped), and run again only as far as its next call, which ran once: ${last.isError ? "it failed" : "its outcome is below"}. The rest of the script did not run; run what is still needed again.`;
|
|
267
|
+
return { text: `${head}\nIts calls, in order:\n${lines.join("\n")}`, isError: Boolean(last.isError), ...(last.images?.length ? { images: last.images } : {}) };
|
|
268
|
+
}
|
package/dist/runner/metrics.js
CHANGED
|
@@ -12,6 +12,7 @@ import { answeredUnpriced, RUNNER_RECORDS, sessionSpendOf } from "@parcha/agentr
|
|
|
12
12
|
import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
13
13
|
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
14
14
|
import { anthropicModelId } from "../provider.js";
|
|
15
|
+
import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
15
16
|
/** The conversation each of the run's sessions books in, by its key: the first `agentrun.session.key` entry naming it. */
|
|
16
17
|
function sessionConversations(entries) {
|
|
17
18
|
const out = new Map();
|
|
@@ -100,9 +101,19 @@ export function runEndCost(parts) {
|
|
|
100
101
|
* its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
|
|
101
102
|
* past its model proxy) spent what no booking read: its cost is unknown, never $0. */
|
|
102
103
|
export function cliModelWorked(entries) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
// A run its learned workflow served first and answered (runner/workflow-first.ts, the loop's WORKFLOW_FIRST entry) keeps
|
|
105
|
+
// the step's call and the workflow's answer, as the model's message written with that entry (pi's too: adapter-loop.ts
|
|
106
|
+
// serveFirst): neither took a model request of the run's agent. Only that one message is passed over: a model message
|
|
107
|
+
// after it (a follow-up's answer, its look-back's) is the model at work, so with nothing booked its cost is unknown.
|
|
108
|
+
const roleOf = (e) => e.data?.role;
|
|
109
|
+
const servedAt = entries.findLastIndex((e) => e.kind === WORKFLOW_FIRST && e.data?.outcome === "answered");
|
|
110
|
+
const servedAnswer = servedAt < 0 ? -1 : entries.slice(0, servedAt).findLastIndex((e) => e.kind === KINDS.message && roleOf(e) === "model");
|
|
111
|
+
return entries.some((e, i) => {
|
|
112
|
+
if (e.kind === KINDS.callStart)
|
|
113
|
+
return e.data?.callId !== WORKFLOW_FIRST_CALL;
|
|
114
|
+
if (e.kind === KINDS.message)
|
|
115
|
+
return roleOf(e) === "model" && i !== servedAnswer;
|
|
116
|
+
return e.kind === KINDS.endOfRunTurn && roleOf(e) === "model";
|
|
106
117
|
});
|
|
107
118
|
}
|
|
108
119
|
/** Whether a run's record carries no cost of its own, so its usage row and its live spend are its booking's: a CLI
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// its own key), and a route speaks a wire its caller speaks (`wires`: the pi adapter speaks both of main's, provider.ts,
|
|
4
4
|
// and so do the learning grader and a workflow's model nodes, which take the route's wire as pi does):
|
|
5
5
|
// - an Anthropic model goes to Anthropic itself (its catalog origin, ANTHROPIC_BASE_URL's when set), its key read by
|
|
6
|
-
// name when a request goes, never held by the route;
|
|
6
|
+
// name when a request goes, never held by the route; a Claude model of serve's gateway goes to the gateway on Messages;
|
|
7
7
|
// - a model pi-ai speaks OpenAI's Responses to (OpenAI's own on its key, serve's gateway), for a caller that speaks
|
|
8
8
|
// Responses, goes there itself, where provider.ts providerFor sends it (the origin, the key, the id on the wire);
|
|
9
9
|
// - any other model answers through the route's own fetch: the Messages request runs on pi-ai's model of it (the faux
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// the tier, as its provider bills it), and its cost is that catalog entry, tiers included, for the cap's judgement.
|
|
16
16
|
import { randomUUID } from "node:crypto";
|
|
17
17
|
import { calculateCost } from "@earendil-works/pi-ai";
|
|
18
|
-
import { chooseModel, runModels } from "../model.js";
|
|
18
|
+
import { chooseModel, MODEL_PROVIDER, runModels } from "../model.js";
|
|
19
19
|
import { providerFor } from "../provider.js";
|
|
20
20
|
import { keepText, runnerSecrets, secretRedactor } from "./redact.js";
|
|
21
21
|
import { callsOfText, toolsAsText } from "./text-tools.js";
|
|
@@ -46,18 +46,27 @@ export async function routeOf(model, env = process.env, tier = "default", wires
|
|
|
46
46
|
// What the model takes as input and its input limits, on every wire: pi's session sends a model that takes no images
|
|
47
47
|
// pi-ai's placeholder in place of one, and pi's read holds an image to the model's limits (port-models.ts sessionModel).
|
|
48
48
|
const sees = { ...(target.input ? { input: target.input } : {}), ...(target.inputLimits ? { inputLimits: target.inputLimits } : {}) };
|
|
49
|
+
// The settings serve registered for a gateway model, carried on either wire, so pi's session reads the same model whether
|
|
50
|
+
// it speaks Messages or Responses to the gateway.
|
|
51
|
+
const settings = { ...sees, ...(target.reasoning !== undefined ? { reasoning: target.reasoning } : {}), ...(target.contextWindow ? { contextWindow: target.contextWindow } : {}), ...(target.maxTokens ? { maxTokens: target.maxTokens } : {}) };
|
|
49
52
|
const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
|
|
50
53
|
// An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
|
|
51
54
|
if (chosen.model.provider === "anthropic") {
|
|
52
55
|
return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
|
|
53
56
|
}
|
|
57
|
+
// A Claude model of serve's gateway (model.ts gatewayWire), for a caller that speaks Messages: the gateway itself, on
|
|
58
|
+
// Messages, so the prompt cache marks pi-ai puts on the request reach it (provider.ts).
|
|
59
|
+
if (target.api === "anthropic-messages" && chosen.model.provider === MODEL_PROVIDER && wires.includes("anthropic-messages")) {
|
|
60
|
+
const to = providerFor("anthropic-messages", env, chosen.model, "pi");
|
|
61
|
+
return { ...route, model: to.modelId, provider: { api: "anthropic-messages", origin: to.origin, credential: to.credential, auth: to.auth }, like: settings };
|
|
62
|
+
}
|
|
54
63
|
// A model pi-ai speaks Responses to, for a caller that speaks it: that wire itself, where main sends it (provider.ts).
|
|
55
64
|
if (target.api === "openai-responses" && wires.includes("openai-responses")) {
|
|
56
65
|
const to = providerFor("openai-responses", env, chosen.model, "pi");
|
|
57
66
|
return {
|
|
58
67
|
...route, model: to.modelId,
|
|
59
68
|
provider: { api: "openai-responses", origin: to.origin, credential: to.credential, auth: to.auth },
|
|
60
|
-
like:
|
|
69
|
+
like: settings,
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
return { ...route, provider: { api: "anthropic-messages", origin: ROUTE_ORIGIN, credential: () => "model-route" }, fetch: messagesFetch(models, target, redact ?? secretRedactor(runnerSecrets(env)), upstream) };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MonidPin } from "../monid.js";
|
|
2
|
+
import type { Workspace } from "../workspace/index.js";
|
|
3
|
+
import type { ClaimMcp } from "./mcp-run.js";
|
|
4
|
+
/** The run's monid endpoints, as the loop's catalog seam reads them. */
|
|
5
|
+
export type ClaimMonid = Pick<ClaimMcp, "tools" | "catalogOf" | "priceOf">;
|
|
6
|
+
/** One host tool per endpoint of `pin`, on the claim's environment `env` (its key, and the tests' fake under faux), an
|
|
7
|
+
* answer too long for the model filed in `work()`; undefined when the pin holds none. `runId` names the run in the log. */
|
|
8
|
+
export declare function monidForClaim(pin: MonidPin | undefined, env: NodeJS.ProcessEnv, work: () => Workspace, runId?: string): ClaimMonid | undefined;
|
|
9
|
+
/** The claim's MCP with the run's monid endpoints beside it: the one catalog seam the loop reads (AdapterRunSpec.mcp).
|
|
10
|
+
* Its credentials' hooks are MCP's alone, and so is the closure of a pinned tool's arguments (argumentsOf: the gate's
|
|
11
|
+
* settings pins are on MCP tools; a monid endpoint's input is held to its pinned schema by the harness), and so is each
|
|
12
|
+
* tool's effect (effectOf: Allow reads and the destructive confirm read an MCP tool's annotations; an endpoint has none). */
|
|
13
|
+
export declare function withMonid(mcp: ClaimMcp | undefined, monid: ClaimMonid | undefined): ClaimMcp | undefined;
|
|
14
|
+
/** What a subagent may be given for the grant `grant` (subagent.ts sessionNames): for a provider's wildcard, every endpoint
|
|
15
|
+
* the revision's `pin` holds of that provider, by wire name; undefined for any other grant. */
|
|
16
|
+
export declare function monidSessionNames(grant: string, pin: MonidPin | undefined): string[] | undefined;
|