@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
|
@@ -10,7 +10,7 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
10
10
|
import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
11
11
|
import { claimFence, storeNow } from "../fence.js";
|
|
12
12
|
import { RunStorage } from "../journal/storage.js";
|
|
13
|
-
import { COMMANDS_ONE_ANSWER, DDL, SCHEMA_VERSION } from "../schema.js";
|
|
13
|
+
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, REVISIONS_MCP_PIN, SCHEMA_VERSION } from "../schema.js";
|
|
14
14
|
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, } from "../store.js";
|
|
15
15
|
/** The seq a run-change cursor names (Runs.changedSince): only a cursor this store handed back, a whole number. */
|
|
16
16
|
const seqOf = (cursor) => {
|
|
@@ -54,7 +54,7 @@ function triggerSet(patch, at) {
|
|
|
54
54
|
return { set: pairs.map(([column]) => `${column} = ?`).join(", "), params: pairs.map(([, value]) => value) };
|
|
55
55
|
}
|
|
56
56
|
const AGENT_COLUMNS = "id, name, description, current_revision, created_at, archived_at, external_ref";
|
|
57
|
-
const REVISION_COLUMNS = "id, agent_id, parent_id, kind, body, skills, note, package, created_at, external_version";
|
|
57
|
+
const REVISION_COLUMNS = "id, agent_id, parent_id, kind, body, skills, note, package, created_at, external_version, mcp_pin";
|
|
58
58
|
const COMMAND_COLUMNS = "id, run_id, kind, body, created_at, taken_at, refused, tries";
|
|
59
59
|
const TRIGGER_COLUMNS = "id, agent_id, name, enabled, source, target, next_at, last_run_id, catchup_window_s, failures_in_a_row, disabled, max_active_runs, created_at, updated_at";
|
|
60
60
|
const FINAL = FINAL_STATES.map((state) => `'${state}'`).join(", ");
|
|
@@ -97,6 +97,7 @@ const agentOf = (r) => ({ id: r.id, name: r.name, description: r.description, cu
|
|
|
97
97
|
const revisionOf = (r) => ({
|
|
98
98
|
id: r.id, agentId: r.agent_id, parent: r.parent_id, kind: r.kind, body: JSON.parse(r.body), skills: r.skills === null ? null : JSON.parse(r.skills),
|
|
99
99
|
note: r.note, package: r.package === null ? null : JSON.parse(r.package), createdAt: r.created_at, externalVersion: r.external_version,
|
|
100
|
+
mcpPin: r.mcp_pin === null ? null : JSON.parse(r.mcp_pin),
|
|
100
101
|
});
|
|
101
102
|
const commandOf = (r) => ({ id: r.id, runId: r.run_id, kind: r.kind, body: JSON.parse(r.body), createdAt: r.created_at, takenAt: r.taken_at, refused: r.refused, tries: r.tries });
|
|
102
103
|
const triggerOf = (r) => ({
|
|
@@ -105,6 +106,8 @@ const triggerOf = (r) => ({
|
|
|
105
106
|
createdAt: r.created_at, updatedAt: r.updated_at,
|
|
106
107
|
});
|
|
107
108
|
const json = (value) => JSON.stringify(value ?? null);
|
|
109
|
+
/** A revision's MCP pin as its column keeps it: JSON, or null for none. */
|
|
110
|
+
const pinText = (pin) => (pin === undefined || pin === null ? null : JSON.stringify(pin));
|
|
108
111
|
const removedOf = (r) => r && { url: r.url, sealed: r.sealed === null ? null : Uint8Array.from(r.sealed) };
|
|
109
112
|
const MCP_SERVER_COLUMNS = "name, url, auth, protocol, tools, prices, server_info, instructions, sealed, refresh_holder, refresh_until, created_at, updated_at, listed_at, credential_changed_at, token_until";
|
|
110
113
|
/** The columns of an MCP server row read at the deadlines' clock `n` (fence.ts storeNow) in the same statement: `read_at`,
|
|
@@ -122,7 +125,7 @@ const mcpServerOf = (r, at = Number(r.read_at)) => ({
|
|
|
122
125
|
tokenUntil: r.token_until === null ? null : Number(r.token_until),
|
|
123
126
|
createdAt: r.created_at, updatedAt: r.updated_at, listedAt: r.listed_at, credentialChangedAt: r.credential_changed_at,
|
|
124
127
|
});
|
|
125
|
-
const mcpPinOf = (r) => ({ runId: r.run_id, body: JSON.parse(r.
|
|
128
|
+
const mcpPinOf = (r) => ({ runId: r.run_id, body: JSON.parse(r.mcp_pin), pinnedAt: Number(r.created_at) });
|
|
126
129
|
const settingOf = (r) => ({ key: r.key, value: JSON.parse(r.value), updatedAt: r.updated_at });
|
|
127
130
|
const sealedKeyOf = (r) => ({ name: r.name, sealed: Uint8Array.from(r.sealed), updatedAt: r.updated_at });
|
|
128
131
|
const ledgerRowOf = (r) => ({ provider: r.provider, sessionId: r.session_id, labels: JSON.parse(r.labels), detail: JSON.parse(r.detail), updatedAt: r.updated_at });
|
|
@@ -249,12 +252,20 @@ export async function openSqliteStore(options) {
|
|
|
249
252
|
// counted refused answers: the server rebuilds it, so a second answer to one approval is refused on every store. A
|
|
250
253
|
// store such a build left may hold two unrefused answers to one approval: the earliest stands (the one the runner
|
|
251
254
|
// acted on) and each later one is refused in the same write, before the index, so the store opens. None is deleted.
|
|
255
|
+
// An earlier build of this version pinned each run's MCP tools at its first claim (mcp_pins) and kept no pin on a
|
|
256
|
+
// revision: the server adds revisions.mcp_pin (schema.ts REVISIONS_MCP_PIN) and drops mcp_pins. A revision saved
|
|
257
|
+
// before has no pin until its first run here pins it (Agents.pinOnce); no run's pin moves to a revision.
|
|
252
258
|
if (role === "server") {
|
|
259
|
+
const pinned = await connection.get("SELECT name FROM pragma_table_info('revisions') WHERE name = 'mcp_pin'");
|
|
253
260
|
await connection.write([
|
|
261
|
+
...(pinned ? [] : [{ sql: REVISIONS_MCP_PIN }]),
|
|
262
|
+
{ sql: "DROP TABLE IF EXISTS mcp_pins" },
|
|
254
263
|
{ sql: "DROP TABLE IF EXISTS browser_viewers" },
|
|
255
264
|
{ sql: SECOND_ANSWERS_REFUSED, params: [(options.now ?? Date.now)()] },
|
|
256
265
|
{ sql: "DROP INDEX IF EXISTS commands_one_answer" },
|
|
257
266
|
{ sql: COMMANDS_ONE_ANSWER },
|
|
267
|
+
// An earlier build of this version kept no imported template packages (schema.ts IMPORTED_TEMPLATES).
|
|
268
|
+
{ sql: IMPORTED_TEMPLATES },
|
|
258
269
|
], { full: true });
|
|
259
270
|
}
|
|
260
271
|
}
|
|
@@ -333,6 +344,7 @@ class SqliteStore {
|
|
|
333
344
|
sealedKeys;
|
|
334
345
|
computerLedger;
|
|
335
346
|
pairedComputers;
|
|
347
|
+
importedTemplates;
|
|
336
348
|
triggerSettings;
|
|
337
349
|
channels;
|
|
338
350
|
mcpOauth;
|
|
@@ -374,7 +386,7 @@ class SqliteStore {
|
|
|
374
386
|
throw new StoreConstraint(`no agent ${agentId}`);
|
|
375
387
|
if (ifCurrent !== undefined && agent.current_revision !== ifCurrent)
|
|
376
388
|
throw new RevisionMoved(agentId, agent.current_revision);
|
|
377
|
-
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", revision.id, agentId, agent.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, revision.package === undefined ? null : json(revision.package), at);
|
|
389
|
+
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, created_at, mcp_pin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revision.id, agentId, agent.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, revision.package === undefined ? null : json(revision.package), at, pinText(revision.mcpPin));
|
|
378
390
|
await tx.run("UPDATE agents SET current_revision = ? WHERE id = ?", revision.id, agentId);
|
|
379
391
|
};
|
|
380
392
|
const writeScopes = async (tx, triggerId, scopes) => {
|
|
@@ -433,6 +445,10 @@ class SqliteStore {
|
|
|
433
445
|
return row && agentOf(row);
|
|
434
446
|
},
|
|
435
447
|
hasExternalVersion: async (agentId, version) => (await db.get("SELECT id FROM revisions WHERE agent_id = ? AND external_version = ?", agentId, version)) !== undefined,
|
|
448
|
+
externalRevision: async (agentId, version) => {
|
|
449
|
+
const row = await db.get(`SELECT ${REVISION_COLUMNS} FROM revisions WHERE agent_id = ? AND external_version = ?`, agentId, version);
|
|
450
|
+
return row && revisionOf(row);
|
|
451
|
+
},
|
|
436
452
|
list: async ({ archived = false } = {}) => (await db.all(`SELECT ${AGENT_COLUMNS} FROM agents WHERE archived_at IS ${archived ? "NOT NULL" : "NULL"} ORDER BY created_at, id`)).map(agentOf),
|
|
437
453
|
archive: async (id, archived, why) => db.transaction(async (tx) => {
|
|
438
454
|
const at = now();
|
|
@@ -458,6 +474,15 @@ class SqliteStore {
|
|
|
458
474
|
return row && revisionOf(row);
|
|
459
475
|
},
|
|
460
476
|
revisions: async (agentId) => (await db.all(`SELECT ${REVISION_COLUMNS} FROM revisions WHERE agent_id = ? ORDER BY created_at, id`, agentId)).map(revisionOf),
|
|
477
|
+
// Written only while the revision has none (the one place a revision changes after its save), then read back in the
|
|
478
|
+
// same transaction: the pin that stood, this one or another first run's.
|
|
479
|
+
pinOnce: async (revisionId, pin) => {
|
|
480
|
+
const row = await db.transaction(async (tx) => {
|
|
481
|
+
await tx.run("UPDATE revisions SET mcp_pin = ? WHERE id = ? AND mcp_pin IS NULL", pinText(pin), revisionId);
|
|
482
|
+
return tx.get("SELECT mcp_pin FROM revisions WHERE id = ?", revisionId);
|
|
483
|
+
});
|
|
484
|
+
return row?.mcp_pin == null ? null : JSON.parse(row.mcp_pin);
|
|
485
|
+
},
|
|
461
486
|
};
|
|
462
487
|
this.templates = {
|
|
463
488
|
apply: async (agent, revision, triggers, idempotencyKey) => db.transaction(async (tx) => {
|
|
@@ -699,7 +724,7 @@ class SqliteStore {
|
|
|
699
724
|
await writeScopes(tx, triggerId, []);
|
|
700
725
|
});
|
|
701
726
|
},
|
|
702
|
-
fire: async (firing, run, { launch } = {}) => db.transaction(async (tx) => {
|
|
727
|
+
fire: async (firing, run, { launch } = {}) => this.#queued(await db.transaction(async (tx) => {
|
|
703
728
|
const at = now();
|
|
704
729
|
await d.lockRow(tx, "triggers", "id", firing.triggerId);
|
|
705
730
|
// Never a run of an archived agent: the archive's commit is read here, in the transaction that would start it.
|
|
@@ -717,7 +742,7 @@ class SqliteStore {
|
|
|
717
742
|
if ((await tx.runCounted("UPDATE triggers SET last_run_id = ?, failures_in_a_row = 0, updated_at = ? WHERE id = ?", run.id, at, firing.triggerId)) === 0)
|
|
718
743
|
throw new StoreConstraint(`no trigger ${firing.triggerId}`);
|
|
719
744
|
return runOf(row);
|
|
720
|
-
}),
|
|
745
|
+
})),
|
|
721
746
|
};
|
|
722
747
|
this.runs = {
|
|
723
748
|
create: async ({ id, agentId, revisionId, origin }, launch) => {
|
|
@@ -726,7 +751,7 @@ class SqliteStore {
|
|
|
726
751
|
if (origin || launch) {
|
|
727
752
|
// The run, its origin and its launch row in one transaction: the key -> run link holds even if the kept response
|
|
728
753
|
// never lands, and a run never exists without the launch it was started with.
|
|
729
|
-
return db.transaction(async (tx) => {
|
|
754
|
+
return this.#queued(await db.transaction(async (tx) => {
|
|
730
755
|
const at = now();
|
|
731
756
|
const row = await tx.get(insert, id, agentId, revisionId, at);
|
|
732
757
|
if (origin)
|
|
@@ -734,14 +759,14 @@ class SqliteStore {
|
|
|
734
759
|
if (launch)
|
|
735
760
|
await writeLaunch(tx, id, launch, at);
|
|
736
761
|
return runOf(row);
|
|
737
|
-
});
|
|
762
|
+
}));
|
|
738
763
|
}
|
|
739
764
|
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, now()] }]);
|
|
740
|
-
return runOf(result.rows[0]);
|
|
765
|
+
return this.#queued(runOf(result.rows[0]));
|
|
741
766
|
},
|
|
742
767
|
createInline: async ({ agent, revision, run, launch }) => {
|
|
743
768
|
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
744
|
-
|
|
769
|
+
const made = await db.transaction(async (tx) => {
|
|
745
770
|
const at = now();
|
|
746
771
|
// Hold the external reference, so two first uses of the same expert serialize (SQLite's one writer already does).
|
|
747
772
|
await d.lockKey(tx, `external:${agent.ref}`);
|
|
@@ -759,7 +784,7 @@ class SqliteStore {
|
|
|
759
784
|
}
|
|
760
785
|
else {
|
|
761
786
|
revisionId = revision.id;
|
|
762
|
-
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, external_version, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revisionId, mapped.id, mapped.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, null, revision.version, at);
|
|
787
|
+
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, external_version, created_at, mcp_pin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revisionId, mapped.id, mapped.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, null, revision.version, at, pinText(revision.mcpPin));
|
|
763
788
|
await tx.run("UPDATE agents SET current_revision = ?, name = ?, description = ? WHERE id = ?", revisionId, agent.name, agent.description ?? null, mapped.id);
|
|
764
789
|
}
|
|
765
790
|
// The run, its origin and its launch, in the same transaction as the agent and the revision.
|
|
@@ -769,6 +794,7 @@ class SqliteStore {
|
|
|
769
794
|
await writeLaunch(tx, run.id, launch, at);
|
|
770
795
|
return runOf(row);
|
|
771
796
|
});
|
|
797
|
+
return this.#queued(made);
|
|
772
798
|
},
|
|
773
799
|
get: async (id) => {
|
|
774
800
|
const row = await db.get(`SELECT ${RUN_COLUMNS} FROM runs WHERE id = ?`, id);
|
|
@@ -973,16 +999,11 @@ class SqliteStore {
|
|
|
973
999
|
const row = await db.get(`SELECT url, auth, credential_changed_at, token_until, ${at.sql} AS read_at FROM mcp_servers WHERE name = ?`, ...at.params, name);
|
|
974
1000
|
return row && { url: row.url, auth: row.auth, credentialChangedAt: row.credential_changed_at === null ? null : Number(row.credential_changed_at), tokenLeftMs: row.token_until === null ? null : Number(row.token_until) - Number(row.read_at), tokenUntil: row.token_until === null ? null : Number(row.token_until) };
|
|
975
1001
|
},
|
|
1002
|
+
// The run's revision's, as its save pinned it: one row read, by the run's revision.
|
|
976
1003
|
pin: async (runId) => {
|
|
977
|
-
const row = await db.get("SELECT run_id,
|
|
1004
|
+
const row = await db.get("SELECT runs.id AS run_id, revisions.mcp_pin, revisions.created_at FROM runs JOIN revisions ON revisions.id = runs.revision_id WHERE runs.id = ? AND revisions.mcp_pin IS NOT NULL", runId);
|
|
978
1005
|
return row && mcpPinOf(row);
|
|
979
1006
|
},
|
|
980
|
-
pinOnce: (claim, body) => db.transaction(async (tx) => {
|
|
981
|
-
// Under the claim's epoch and its lease: a runner paused past its lease pins nothing.
|
|
982
|
-
await underClaim(tx, claim, now);
|
|
983
|
-
await tx.run("INSERT INTO mcp_pins (run_id, body, pinned_at) VALUES (?, ?, ?) ON CONFLICT (run_id) DO NOTHING", claim.runId, json(body), now());
|
|
984
|
-
return mcpPinOf((await tx.get("SELECT run_id, body, pinned_at FROM mcp_pins WHERE run_id = ?", claim.runId)));
|
|
985
|
-
}),
|
|
986
1007
|
// The credential as read is compared by its bytes (`sealed IS ?`, NULL included): updated_at can repeat within a ms.
|
|
987
1008
|
leaseRefresh: async (name, { seen, holder, ms = MCP_REFRESH_LEASE_MS }) => {
|
|
988
1009
|
if (!(Number.isFinite(ms) && ms > MCP_REFRESH_CALL_MS)) {
|
|
@@ -1229,6 +1250,21 @@ class SqliteStore {
|
|
|
1229
1250
|
return (result?.changes ?? 0) === 1;
|
|
1230
1251
|
},
|
|
1231
1252
|
};
|
|
1253
|
+
this.importedTemplates = {
|
|
1254
|
+
list: async () => (await db.all("SELECT id, source, sha, publisher, files, imported_at FROM imported_templates ORDER BY id")).map((row) => ({
|
|
1255
|
+
id: row.id, source: row.source, sha: row.sha, publisher: row.publisher, files: JSON.parse(row.files), importedAt: row.imported_at,
|
|
1256
|
+
})),
|
|
1257
|
+
put: async ({ id, source, sha, publisher, files }) => {
|
|
1258
|
+
await db.write([{
|
|
1259
|
+
sql: "INSERT INTO imported_templates (id, source, sha, publisher, files, imported_at) VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (id) DO UPDATE SET source = excluded.source, sha = excluded.sha, publisher = excluded.publisher, files = excluded.files, imported_at = excluded.imported_at",
|
|
1260
|
+
params: [id, source, sha, publisher, JSON.stringify(files), now()],
|
|
1261
|
+
}]);
|
|
1262
|
+
},
|
|
1263
|
+
remove: async (id) => {
|
|
1264
|
+
const [result] = await db.write([{ sql: "DELETE FROM imported_templates WHERE id = ?", params: [id] }]);
|
|
1265
|
+
return (result?.changes ?? 0) === 1;
|
|
1266
|
+
},
|
|
1267
|
+
};
|
|
1232
1268
|
this.triggerSettings = {
|
|
1233
1269
|
get: async (adapter) => (await db.all("SELECT adapter, scope, field, sealed, updated_at FROM trigger_settings WHERE adapter = ? ORDER BY scope, field", adapter)).map(triggerSettingOf),
|
|
1234
1270
|
put: async ({ adapter, scope, field, sealed }) => {
|
|
@@ -1584,6 +1620,11 @@ class SqliteStore {
|
|
|
1584
1620
|
watchCommands(listener) {
|
|
1585
1621
|
return watchCommandsAt(this.where, listener);
|
|
1586
1622
|
}
|
|
1623
|
+
/** `run`, just committed queued: this process's runners are told it is claimable now (watchCommands' "queued"). */
|
|
1624
|
+
#queued(run) {
|
|
1625
|
+
wakeCommands(this.where, { runId: run.id, what: "queued" });
|
|
1626
|
+
return run;
|
|
1627
|
+
}
|
|
1587
1628
|
async answerOf(runId, commandId) {
|
|
1588
1629
|
// Read and cleared in one transaction, so two readers never both get it. A refused row never holds one.
|
|
1589
1630
|
const text = await this.#db.transaction(async (tx) => {
|
package/dist/store/store.d.ts
CHANGED
|
@@ -50,14 +50,13 @@ export interface AgentRow {
|
|
|
50
50
|
* agent with a reference is read-only from here: it is written on the first run that names it and never edited. */
|
|
51
51
|
readonly externalRef: string | null;
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
53
|
+
/** The template package an agent was applied from, kept on the revision the apply made (its first): the package's id
|
|
54
|
+
* (a bundled one's name, an imported one's `github:<owner>/<repo>[/<path>]`), its SemVer version, and the commit SHA it
|
|
55
|
+
* was imported at (null for a bundled one, which is the server's own build). */
|
|
54
56
|
export interface TemplatePackage {
|
|
55
|
-
readonly
|
|
57
|
+
readonly id: string;
|
|
56
58
|
readonly version: string;
|
|
57
|
-
readonly
|
|
58
|
-
readonly ref?: string;
|
|
59
|
-
readonly sha?: string;
|
|
60
|
-
readonly parameters?: unknown;
|
|
59
|
+
readonly sha: string | null;
|
|
61
60
|
}
|
|
62
61
|
export interface NewRevision {
|
|
63
62
|
readonly id: string;
|
|
@@ -71,6 +70,9 @@ export interface NewRevision {
|
|
|
71
70
|
readonly package?: TemplatePackage;
|
|
72
71
|
/** The version this revision maps in an externally owned agent, set only on an inline-agent run's revision. */
|
|
73
72
|
readonly externalVersion?: string;
|
|
73
|
+
/** The MCP tools the revision grants, pinned as their servers listed them when it was saved (mcp-gateway.ts McpPin), which
|
|
74
|
+
* every run of it calls; none when it grants none. */
|
|
75
|
+
readonly mcpPin?: unknown;
|
|
74
76
|
}
|
|
75
77
|
export interface RevisionRow {
|
|
76
78
|
readonly id: string;
|
|
@@ -88,6 +90,8 @@ export interface RevisionRow {
|
|
|
88
90
|
readonly createdAt: number;
|
|
89
91
|
/** The version this revision maps in the agent's owning system (one revision per version), or null for one committed here. */
|
|
90
92
|
readonly externalVersion: string | null;
|
|
93
|
+
/** Its MCP pin as its save made it (NewRevision.mcpPin), or null for a revision that grants no MCP tool. */
|
|
94
|
+
readonly mcpPin: unknown;
|
|
91
95
|
}
|
|
92
96
|
/** How a run ended, beside its state. An ended run (state 'ended'): 'escalated' (it finished its work and waits for a
|
|
93
97
|
* person, which the v2 status reads as completed with a review) or 'completed'. A stopped run (state 'stopped'): 'stopped'
|
|
@@ -588,6 +592,8 @@ export interface Agents {
|
|
|
588
592
|
byExternal(ref: string): Promise<AgentRow | undefined>;
|
|
589
593
|
/** Whether the agent already has the revision that maps `version` of its owning system (one row looked up, no bodies read). */
|
|
590
594
|
hasExternalVersion(agentId: string, version: string): Promise<boolean>;
|
|
595
|
+
/** The revision that maps `version` of its owning system, or undefined before that version's first run. */
|
|
596
|
+
externalRevision(agentId: string, version: string): Promise<RevisionRow | undefined>;
|
|
591
597
|
list(options?: {
|
|
592
598
|
archived?: boolean;
|
|
593
599
|
}): Promise<AgentRow[]>;
|
|
@@ -611,6 +617,10 @@ export interface Agents {
|
|
|
611
617
|
setCurrent(agentId: string, revisionId: string): Promise<void>;
|
|
612
618
|
revision(id: string): Promise<RevisionRow | undefined>;
|
|
613
619
|
revisions(agentId: string): Promise<RevisionRow[]>;
|
|
620
|
+
/** Pins a revision saved with no MCP pin (before pins were made at save) at its first run: `pin` is written only while
|
|
621
|
+
* the revision still has none, and the pin it has then is the answer, so two first runs at once agree on one. Null when
|
|
622
|
+
* there is no such revision. */
|
|
623
|
+
pinOnce(revisionId: string, pin: unknown): Promise<unknown>;
|
|
614
624
|
}
|
|
615
625
|
export interface Templates {
|
|
616
626
|
/** A template applied: the agent, its first revision (with the package) and its triggers, in one transaction, all or
|
|
@@ -754,6 +764,7 @@ export interface Runs {
|
|
|
754
764
|
body: unknown;
|
|
755
765
|
skills?: unknown;
|
|
756
766
|
note?: string;
|
|
767
|
+
mcpPin?: unknown;
|
|
757
768
|
};
|
|
758
769
|
run: {
|
|
759
770
|
id: string;
|
|
@@ -908,7 +919,8 @@ export interface McpServerStamp {
|
|
|
908
919
|
* claim that opened the row at one end knows the token it holds is not the row's once this differs. */
|
|
909
920
|
readonly tokenUntil: number | null;
|
|
910
921
|
}
|
|
911
|
-
/** A run's MCP pin: what it may call, per granted server (url, tools, prices),
|
|
922
|
+
/** A run's MCP pin: what it may call, per granted server (url, tools, prices), as its revision's save pinned it
|
|
923
|
+
* (RevisionRow.mcpPin); `pinnedAt` is when that revision was saved. */
|
|
912
924
|
export interface McpPinRow {
|
|
913
925
|
readonly runId: string;
|
|
914
926
|
readonly body: unknown;
|
|
@@ -994,12 +1006,8 @@ export interface Mcp {
|
|
|
994
1006
|
* (runner/mcp-claim.ts) to see its credential removed, replaced or moved, or its access token near its end. Undefined
|
|
995
1007
|
* when it is no longer saved. */
|
|
996
1008
|
stamp(name: string): Promise<McpServerStamp | undefined>;
|
|
997
|
-
/** The run's pin,
|
|
1009
|
+
/** The run's pin: its revision's, as the revision's save made it; none for a run whose revision grants no MCP tool. */
|
|
998
1010
|
pin(runId: string): Promise<McpPinRow | undefined>;
|
|
999
|
-
/** Writes the run's pin under `claim` unless it has one, in one transaction with the claim's epoch fence, and answers the
|
|
1000
|
-
* pin as stored: never rewritten, so a second call (or a later claim's) reads the first. Fenced, writing nothing, on a
|
|
1001
|
-
* stale claim. */
|
|
1002
|
-
pinOnce(claim: Claim, body: unknown): Promise<McpPinRow>;
|
|
1003
1011
|
/** One refresh at a time per server (a provider that rotates refresh tokens spends the old one at each refresh): the lease
|
|
1004
1012
|
* is granted to `holder` for `ms` (MCP_REFRESH_LEASE_MS by default) only while the credential is still the one it read
|
|
1005
1013
|
* (`seen`: the sealed bytes, null for none) and no live lease is held. Not granted: the current row comes back, and the
|
|
@@ -1171,6 +1179,27 @@ export interface PairedComputers {
|
|
|
1171
1179
|
/** Removes the computer: its token dials no more. False when it was not paired (unknown, or removed already). */
|
|
1172
1180
|
revoke(id: string): Promise<boolean>;
|
|
1173
1181
|
}
|
|
1182
|
+
/** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
|
|
1183
|
+
* (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
|
|
1184
|
+
* its files as they were read, by path, base64. The server checks them again (templates.ts readPackage) as it loads them
|
|
1185
|
+
* at its start, so a package this build no longer takes is never served. */
|
|
1186
|
+
export interface ImportedTemplateRow {
|
|
1187
|
+
readonly id: string;
|
|
1188
|
+
readonly source: string;
|
|
1189
|
+
readonly sha: string;
|
|
1190
|
+
readonly publisher: string;
|
|
1191
|
+
readonly files: Readonly<Record<string, string>>;
|
|
1192
|
+
/** When it was last imported (stamped by the store). */
|
|
1193
|
+
readonly importedAt: number;
|
|
1194
|
+
}
|
|
1195
|
+
export interface ImportedTemplates {
|
|
1196
|
+
/** Every imported package, by id. */
|
|
1197
|
+
list(): Promise<ImportedTemplateRow[]>;
|
|
1198
|
+
/** Keeps the package under its id, in place of the one there (a re-import at a new SHA replaces it). */
|
|
1199
|
+
put(row: Omit<ImportedTemplateRow, "importedAt">): Promise<void>;
|
|
1200
|
+
/** Removes the package: false when none had that id. */
|
|
1201
|
+
remove(id: string): Promise<boolean>;
|
|
1202
|
+
}
|
|
1174
1203
|
/** A trigger source's sealed setting as a row (store schema `trigger_settings`): its adapter, scope ("server" for the one
|
|
1175
1204
|
* server-wide set, or a trigger's id for its own), field, and the value sealed (store/seal.ts) under AAD
|
|
1176
1205
|
* trigger_settings|<adapter>|<scope>|<field>: TEXT the store never opens. */
|
|
@@ -1386,6 +1415,8 @@ export interface Store {
|
|
|
1386
1415
|
readonly computerLedger: ComputerLedger;
|
|
1387
1416
|
/** The people's own machines paired with this server, and the codes that pair them (spec/computer/attach.md). */
|
|
1388
1417
|
readonly pairedComputers: PairedComputers;
|
|
1418
|
+
/** The template packages imported from GitHub, their files kept as read. */
|
|
1419
|
+
readonly importedTemplates: ImportedTemplates;
|
|
1389
1420
|
/** Each trigger source's sealed settings (design 2.1): a value per adapter, scope and field. */
|
|
1390
1421
|
readonly triggerSettings: TriggerSettings;
|
|
1391
1422
|
/** The outbox of a channel the server sends itself, its tries and what it told each run. */
|
|
@@ -1470,12 +1501,13 @@ export interface Store {
|
|
|
1470
1501
|
readonly value: unknown;
|
|
1471
1502
|
} | undefined>;
|
|
1472
1503
|
/** Tells `listener` when a command of a run in this store is written ("written", after command() commits) or taken,
|
|
1473
|
-
* refused or answered ("answered": a take, a run update that takes, a journal commit that takes or ends the run)
|
|
1504
|
+
* refused or answered ("answered": a take, a run update that takes, a journal commit that takes or ends the run), and
|
|
1505
|
+
* when a run is queued ("queued": runs.create, runs.createInline or a trigger's fire committed it, claimable now).
|
|
1474
1506
|
* A hint to read now, for handles in this process only: a row another process writes wakes nothing here, the reader's
|
|
1475
1507
|
* poll finds it. Called after the commit, asynchronously; a listener's throw is swallowed. Answers the unsubscribe. */
|
|
1476
1508
|
watchCommands(listener: (event: {
|
|
1477
1509
|
readonly runId: string;
|
|
1478
|
-
readonly what: "written" | "answered";
|
|
1510
|
+
readonly what: "written" | "answered" | "queued";
|
|
1479
1511
|
}) => void): () => void;
|
|
1480
1512
|
/** Counts a failed resume on the untaken command that woke the run, under the claim, and answers its tries; the command
|
|
1481
1513
|
* stays untaken. Fenced on a stale claim; StoreConstraint when the command is taken or not the run's. */
|
|
@@ -10,6 +10,12 @@ export declare function runEntries(store: Store, runId: string, context: Context
|
|
|
10
10
|
* `after`, the entry before its input, and `until`, the run's end entry once written; `earlier`, each earlier round's (a
|
|
11
11
|
* follow-up opened the run again after it). Undefined for a run that asked none. */
|
|
12
12
|
export declare function runReflect(store: Store, runId: string, context: Context): Promise<Pick<Reflect, "after" | "until" | "earlier"> | undefined>;
|
|
13
|
+
/** The CLI record (a harness whose own records are resume log only, record "loop": adapter-loop.ts openCliRecord) as the
|
|
14
|
+
* pi-shaped entries the timeline renderer reads: a model message is an assistant turn, a person message a user turn, and a
|
|
15
|
+
* tool call its assistant tool-call and its result. So a claude-agent / codex / opencode run reads the same rows, words
|
|
16
|
+
* and final answer as a pi run of the same conversation. A run's own pi entries and its end-of-run turn (already model
|
|
17
|
+
* shaped) pass through unchanged, so a pi run is untouched. */
|
|
18
|
+
export declare function piShaped(entries: readonly EntryLike[]): EntryLike[];
|
|
13
19
|
/** The paid tool charges a run booked, read back from its paid-tools session (the kernel cap's TOOL_SESSION) as the
|
|
14
20
|
* TOOL_COST entries the timeline renders, which the file-backed path had on the run's root (the paid-call ledger). Each
|
|
15
21
|
* paid request's runner.request names its tool (its model "paid:<name>") and the call it ran under (`call`, written by the
|
|
@@ -19,8 +25,26 @@ export declare function runReflect(store: Store, runId: string, context: Context
|
|
|
19
25
|
* given back unused shows nothing. Each charge is placed right after its call's result, joined by `call`, as the ledger
|
|
20
26
|
* wrote it there. A run with no paid-tools session reads unchanged. */
|
|
21
27
|
export declare function withPaidCosts(entries: readonly EntryLike[]): EntryLike[];
|
|
22
|
-
/** Whether `entries` are a CLI harness's record (its loop's calls and messages).
|
|
28
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). A nested call's (`<callId>/<key>`, a
|
|
29
|
+
* script's or tools_call's) is the record of whichever harness made the call it nests in: on pi, the loop keeps it
|
|
30
|
+
* beside pi's own record (adapter-loop.ts nestedGate), so it makes no run a CLI's. */
|
|
23
31
|
export declare const isCliRecord: (entries: readonly EntryLike[]) => boolean;
|
|
32
|
+
/** The call a run's turn ended on waiting for a person (timeline endedOnTurnEndingTool), over its root's entries as the
|
|
33
|
+
* run keeps them: a CLI harness's record read as pi's (piShaped), as its Timeline and its view read it, so the runner's
|
|
34
|
+
* loop parks a CLI run on exactly the question the view calls waiting, as it does a pi run. */
|
|
35
|
+
export declare const turnEndedOnAsk: (entries: readonly EntryLike[]) => string | undefined;
|
|
36
|
+
/** A grade's feedback round's words (runner/feedback-round.ts, KINDS.feedback) as the reviewer's message: a host's
|
|
37
|
+
* user entry, which the Timeline shows and pi never reads (the entry on the journal carries no model message). */
|
|
38
|
+
export declare function withFeedback(entries: readonly EntryLike[]): EntryLike[];
|
|
39
|
+
/** The job's turns: a run's timeline `rows` (runTimeline's) with every grade's feedback round left out, from its words'
|
|
40
|
+
* row (FEEDBACK_SUFFIX) up to the run's next message. A round asks the agent no turn of the job's, so what the job did is
|
|
41
|
+
* what is left (a follow-up's turns, a person's, included). The one view every reader of what the job's turns said
|
|
42
|
+
* reads (the answer, the path, nothing new, a run's trace). */
|
|
43
|
+
export declare function withoutFeedbackRounds<Row extends {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly kind: string;
|
|
46
|
+
readonly origin?: string;
|
|
47
|
+
}>(rows: readonly Row[]): Row[];
|
|
24
48
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
25
49
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
26
50
|
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
// its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
|
|
4
4
|
// The renderer and the hearing keep their words; only where the entries come from changes.
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
import { CALL_REFUSED, CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
|
|
6
|
+
import { CALL_REFUSED, CAPS, costLabel, endedOnTurnEndingTool, FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, timelineOf, TOOL_COST, toolCallWords } from "../timeline/index.js";
|
|
7
7
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
8
8
|
import { wireName } from "../catalog.js";
|
|
9
9
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
10
10
|
import { Hearing } from "../heard.js";
|
|
11
11
|
import { redactedAnswer } from "../key-refusal.js";
|
|
12
12
|
import { LEARNED_NODES, LEARNED_NODES_MAX } from "../learned-nodes.js";
|
|
13
|
-
import { computerCallsOf } from "../computer-calls.js";
|
|
13
|
+
import { computerCallsOf, shownName } from "../computer-calls.js";
|
|
14
14
|
import { labelled, reflects } from "../reflect-range.js";
|
|
15
15
|
import { reflectRanges } from "../runner/end-of-run.js";
|
|
16
16
|
import { journalEntries, journalRecords, recordOf } from "../runner/journal-reader.js";
|
|
17
17
|
import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
|
|
18
18
|
import { bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
|
|
19
|
-
import { waitingText } from "../tool-gate.js";
|
|
20
19
|
import { Turns } from "../turns.js";
|
|
21
20
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
22
21
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
@@ -44,41 +43,9 @@ function reflectOf(records) {
|
|
|
44
43
|
* tool call its assistant tool-call and its result. So a claude-agent / codex / opencode run reads the same rows, words
|
|
45
44
|
* and final answer as a pi run of the same conversation. A run's own pi entries and its end-of-run turn (already model
|
|
46
45
|
* shaped) pass through unchanged, so a pi run is untouched. */
|
|
47
|
-
|
|
48
|
-
* and no end. */
|
|
49
|
-
function parkedUnsent(entries) {
|
|
50
|
-
const parked = new Set();
|
|
51
|
-
const past = new Set();
|
|
52
|
-
for (const entry of entries) {
|
|
53
|
-
const callId = entry.data?.callId;
|
|
54
|
-
if (typeof callId !== "string")
|
|
55
|
-
continue;
|
|
56
|
-
const start = entry.data;
|
|
57
|
-
if (entry.kind === KINDS.callStart && start.parked === true && start.bridge !== true)
|
|
58
|
-
parked.add(callId);
|
|
59
|
-
else if (entry.kind === KINDS.callSent || entry.kind === KINDS.callEnd)
|
|
60
|
-
past.add(callId);
|
|
61
|
-
}
|
|
62
|
-
for (const callId of past)
|
|
63
|
-
parked.delete(callId);
|
|
64
|
-
return parked;
|
|
65
|
-
}
|
|
66
|
-
function piShaped(entries) {
|
|
67
|
-
const waiting = parkedUnsent(entries);
|
|
46
|
+
export function piShaped(entries) {
|
|
68
47
|
return entries.flatMap((entry) => {
|
|
69
48
|
const data = (entry.data ?? {});
|
|
70
|
-
// A call through a CLI's own MCP client that its gate parked (adapter-loop.ts park): the CLI was answered the gate's
|
|
71
|
-
// waiting words (mcp-run.ts), which the record never keeps as the call's end, since an end is its outcome and the call
|
|
72
|
-
// is answered from it. While the call is parked and unsent, those words show as its result row from its ask on, as pi's
|
|
73
|
-
// parked call shows them; its sent mark or its end (run, refused, withdrawn) ends that.
|
|
74
|
-
// Once per call, at its first ask: a call asked again (a resume, a raise while it waits) shows one waiting result.
|
|
75
|
-
if (entry.kind === KINDS.ask && typeof data.callId === "string" && waiting.delete(data.callId)) {
|
|
76
|
-
const tool = typeof data.tool === "string" ? data.tool : "tool";
|
|
77
|
-
const timestamp = typeof data.requestedAt === "string" && Number.isFinite(Date.parse(data.requestedAt)) ? { timestamp: Date.parse(data.requestedAt) } : {};
|
|
78
|
-
// Its own id (the ask's, marked), so the renderer never takes it for the ask entry seen twice.
|
|
79
|
-
const result = { ...entry, id: `${String(entry.id)}:parked`, kind: "pi.tool-result", data: {}, model: [{ role: "tool", toolCallId: data.callId, content: waitingText(tool), ...timestamp }] };
|
|
80
|
-
return [entry, result];
|
|
81
|
-
}
|
|
82
49
|
// When the record's entry was written (`at`), as pi's own message carries its timestamp: the Timeline dates the row by it.
|
|
83
50
|
const timestamp = typeof data.at === "number" ? { timestamp: data.at } : {};
|
|
84
51
|
if (entry.kind === KINDS.message) {
|
|
@@ -95,8 +62,9 @@ function piShaped(entries) {
|
|
|
95
62
|
const text = typeof data.text === "string" ? data.text : "";
|
|
96
63
|
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "stop", content: [{ type: "text", text }] }] };
|
|
97
64
|
}
|
|
65
|
+
// A call: shown as a model's call, never counted as a model request (the booking counts those: bookedUsage).
|
|
98
66
|
if (entry.kind === KINDS.callStart) {
|
|
99
|
-
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
|
|
67
|
+
return { ...entry, kind: "pi.assistant", recordedCall: true, model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
|
|
100
68
|
}
|
|
101
69
|
if (entry.kind === KINDS.callEnd) {
|
|
102
70
|
// A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text. One
|
|
@@ -181,14 +149,53 @@ export function withPaidCosts(entries) {
|
|
|
181
149
|
}
|
|
182
150
|
return out;
|
|
183
151
|
}
|
|
184
|
-
/** Whether `entries` are a CLI harness's record (its loop's calls and messages).
|
|
185
|
-
|
|
152
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). A nested call's (`<callId>/<key>`, a
|
|
153
|
+
* script's or tools_call's) is the record of whichever harness made the call it nests in: on pi, the loop keeps it
|
|
154
|
+
* beside pi's own record (adapter-loop.ts nestedGate), so it makes no run a CLI's. */
|
|
155
|
+
export const isCliRecord = (entries) => entries.some((entry) => entry.kind === KINDS.message || ((entry.kind === KINDS.callStart || entry.kind === KINDS.callEnd) && !String(entry.data?.callId ?? "").includes("/")));
|
|
156
|
+
/** The call a run's turn ended on waiting for a person (timeline endedOnTurnEndingTool), over its root's entries as the
|
|
157
|
+
* run keeps them: a CLI harness's record read as pi's (piShaped), as its Timeline and its view read it, so the runner's
|
|
158
|
+
* loop parks a CLI run on exactly the question the view calls waiting, as it does a pi run. */
|
|
159
|
+
export const turnEndedOnAsk = (entries) => endedOnTurnEndingTool(isCliRecord(entries) ? piShaped(entries) : entries);
|
|
186
160
|
/** A path as a run's rows name it, for a harness working in `cwd`: one under `cwd` by its name there (`hello.md`), any
|
|
187
161
|
* other as given. */
|
|
188
162
|
const inWorkspace = (cwd) => (path) => {
|
|
189
163
|
const root = cwd.replace(/\/+$/, "");
|
|
190
164
|
return path.startsWith(`${root}/`) && path.length > root.length + 1 ? path.slice(root.length + 1) : path;
|
|
191
165
|
};
|
|
166
|
+
/** A grade's feedback round's words (runner/feedback-round.ts, KINDS.feedback) as the reviewer's message: a host's
|
|
167
|
+
* user entry, which the Timeline shows and pi never reads (the entry on the journal carries no model message). */
|
|
168
|
+
export function withFeedback(entries) {
|
|
169
|
+
return entries.map((entry) => {
|
|
170
|
+
if (entry.kind !== KINDS.feedback)
|
|
171
|
+
return entry;
|
|
172
|
+
const data = (entry.data ?? {});
|
|
173
|
+
return { ...entry, model: [{ role: "user", content: typeof data.text === "string" ? data.text : "", ...(typeof data.at === "number" ? { timestamp: data.at } : {}) }] };
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** `rows` (rendered over `entries`) with each grade's words' row (withFeedback's: the row of a FEEDBACK entry) marked
|
|
177
|
+
* FEEDBACK_SUFFIX: shown as the reviewer's message, and never a message a turn of the job's took (isMessageRow passes
|
|
178
|
+
* over it), so no reader of the rows (the answer, the path, the messages a stop stands after) reads a grade as one. */
|
|
179
|
+
function feedbackMarked(rows, entries) {
|
|
180
|
+
const words = new Set(entries.filter((entry) => entry.kind === KINDS.feedback && entry.id !== undefined).map((entry) => `:${entry.id}`));
|
|
181
|
+
if (!words.size)
|
|
182
|
+
return [...rows];
|
|
183
|
+
return rows.map((row) => (row.kind === "user_message" && words.has(row.id.slice(row.id.lastIndexOf(":"))) ? { ...row, id: `${row.id}${FEEDBACK_SUFFIX}` } : row));
|
|
184
|
+
}
|
|
185
|
+
/** The job's turns: a run's timeline `rows` (runTimeline's) with every grade's feedback round left out, from its words'
|
|
186
|
+
* row (FEEDBACK_SUFFIX) up to the run's next message. A round asks the agent no turn of the job's, so what the job did is
|
|
187
|
+
* what is left (a follow-up's turns, a person's, included). The one view every reader of what the job's turns said
|
|
188
|
+
* reads (the answer, the path, nothing new, a run's trace). */
|
|
189
|
+
export function withoutFeedbackRounds(rows) {
|
|
190
|
+
let inRound = false;
|
|
191
|
+
return rows.filter((row) => {
|
|
192
|
+
if (isFeedbackRow(row))
|
|
193
|
+
inRound = true;
|
|
194
|
+
else if (isMessageRow(row))
|
|
195
|
+
inRound = false;
|
|
196
|
+
return !inRound;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
192
199
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
193
200
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
194
201
|
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
@@ -209,9 +216,12 @@ export async function runTimeline(store, runId, context, options = {}) {
|
|
|
209
216
|
// session's proxy sees its upstream end). Its cost reads that turn the same way, the request it cut a charge with no
|
|
210
217
|
// price, never one in flight: never the known sum as its cost while the run reads stopped.
|
|
211
218
|
const read = { ...options, ...(cwd ? { path: inWorkspace(cwd.cwd) } : {}), ...(!options.settled && turnCutOf(records, reflect) ? { turnCut: true } : {}) };
|
|
212
|
-
|
|
219
|
+
// Shaped on pi too: its own entries pass through as they are, and the calls its tools nested (on the loop's record) read
|
|
220
|
+
// as a CLI's calls do. A grade's feedback round's words read as the reviewer's message (withFeedback), marked as no
|
|
221
|
+
// message of the job's (feedbackMarked).
|
|
222
|
+
const rendered = feedbackMarked(timelineOf(withPaidCosts(withFeedback(piShaped(entries))), read), entries);
|
|
213
223
|
const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : withSideUsage(rendered, entries);
|
|
214
|
-
return labelled(reflect, withComputerCalls(withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact), entries));
|
|
224
|
+
return labelled(reflect, withComputerCalls(withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact), entries, options.redact));
|
|
215
225
|
}
|
|
216
226
|
/** Whether the run's newest turn is over, cut (turns.ts: no message of the run's open, the newest one's end interrupted),
|
|
217
227
|
* its end-of-run turn's entries apart, as the run's view reads its status. */
|
|
@@ -222,15 +232,17 @@ function turnCutOf(records, reflect) {
|
|
|
222
232
|
}
|
|
223
233
|
/** `rows` with each tool call's result row carrying the computer protocol calls it made (`computer_calls`, and
|
|
224
234
|
* `computer_calls_dropped` past the record's bound), from the COMPUTER_CALLS entry the adapter loop kept beside the call
|
|
225
|
-
* (computer-calls.ts), joined by the call's id. A record holds no
|
|
226
|
-
*
|
|
227
|
-
|
|
235
|
+
* (computer-calls.ts), joined by the call's id. A record holds no typed or set value and no answer's bytes; the names of
|
|
236
|
+
* the elements its steps acted on (words on the screen) go through `redact` when given (the run's cut), as every text a
|
|
237
|
+
* row shows, whole, and are cut for the row after (shownName). Rows of a run whose tools made none are as they were. */
|
|
238
|
+
function withComputerCalls(rows, entries, redact) {
|
|
228
239
|
const made = computerCallsOf(entries);
|
|
229
240
|
if (!made.size)
|
|
230
241
|
return rows;
|
|
242
|
+
const cut = (calls) => calls.map((call) => (call.steps?.some((step) => step.on?.name) ? { ...call, steps: call.steps.map((step) => (step.on?.name ? { ...step, on: { ...step.on, name: shownName(step.on.name, redact) } } : step)) } : call));
|
|
231
243
|
return rows.map((row) => {
|
|
232
244
|
const kept = row.kind === "tool_result" && row.tool_use_id ? made.get(row.tool_use_id) : undefined;
|
|
233
|
-
return kept ? { ...row, computer_calls: kept.calls, ...(kept.dropped > 0 ? { computer_calls_dropped: kept.dropped } : {}) } : row;
|
|
245
|
+
return kept ? { ...row, computer_calls: cut(kept.calls), ...(kept.dropped > 0 ? { computer_calls_dropped: kept.dropped } : {}) } : row;
|
|
234
246
|
});
|
|
235
247
|
}
|
|
236
248
|
/** `rows` with each learned_workflow call's result row carrying the nodes its workflow ran (`learned_nodes`), from the
|
|
@@ -304,11 +316,13 @@ function bookedUsage(rows, entries, options) {
|
|
|
304
316
|
const unpriced = model.unpriced + paid.unpriced + (unbooked ? 1 : 0);
|
|
305
317
|
const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
|
|
306
318
|
const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
|
|
307
|
-
|
|
319
|
+
// Its tool calls with no price as the renderer counted them from the journal (TOOL_UNMETERED), as on a pi run's row.
|
|
320
|
+
const notMetered = at >= 0 ? (rows[at].usage?.not_metered ?? 0) : 0;
|
|
321
|
+
const calls = toolCallWords(paid.requests, notMetered);
|
|
308
322
|
const summary = unbooked
|
|
309
|
-
? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${
|
|
310
|
-
: `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${
|
|
311
|
-
const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
|
|
323
|
+
? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${calls}`
|
|
324
|
+
: `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${calls}`;
|
|
325
|
+
const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}), ...(notMetered ? { not_metered: notMetered } : {}) };
|
|
312
326
|
const last = rows[rows.length - 1];
|
|
313
327
|
const base = at >= 0 ? rows[at] : {
|
|
314
328
|
...last, id: `${last?.conversation_id ?? 0}:usage`, agent_label: null, text: null,
|