@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.39
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 +700 -0
- package/README.md +441 -177
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +1 -3
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +48 -23
- 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/bash-read-only.js +2 -1
- package/dist/browser-cost.js +52 -93
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -400
- package/dist/cap.js +6 -942
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +2 -6
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +25 -0
- package/dist/composio-preset.js +51 -8
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.d.ts +36 -24
- package/dist/computer-calls.js +110 -27
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +12 -2
- package/dist/computer-live.js +21 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +18 -2
- package/dist/computer-view.js +21 -6
- package/dist/computer-viewer.js +40 -13
- package/dist/computers.d.ts +8 -2
- package/dist/computers.js +18 -8
- package/dist/console/assets/index-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/decisions.js +4 -0
- package/dist/email/account.d.ts +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/faux-computers.js +4 -2
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -22
- package/dist/harness-opencode/facts.js +5 -4
- package/dist/harness-opencode/host/policy.d.ts +4 -5
- package/dist/harness-opencode/host/policy.js +14 -33
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +8 -7
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/host-tools.d.ts +1 -5
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +3 -3
- package/dist/hosted-search.js +51 -32
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +24 -4
- package/dist/learn/check.js +340 -7
- package/dist/learn/commit.d.ts +10 -0
- package/dist/learn/commit.js +18 -4
- package/dist/learn/compile.d.ts +250 -0
- package/dist/learn/compile.js +507 -0
- package/dist/learn/general.d.ts +3 -0
- package/dist/learn/general.js +4 -2
- package/dist/learn/grade.d.ts +5 -1
- package/dist/learn/grade.js +11 -7
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +308 -0
- package/dist/learn/promote.js +321 -0
- package/dist/learn/refit.d.ts +48 -0
- package/dist/learn/refit.js +264 -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 +19 -16
- package/dist/learn/skills.js +157 -53
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +58 -2
- package/dist/learned-nodes.js +68 -5
- package/dist/learned-workflow.d.ts +58 -32
- package/dist/learned-workflow.js +215 -77
- package/dist/learning-batch.d.ts +2 -2
- package/dist/learning-batch.js +4 -4
- package/dist/learning-cost.d.ts +41 -11
- package/dist/learning-cost.js +31 -13
- package/dist/learning-routes.d.ts +12 -2
- package/dist/learning-routes.js +34 -6
- package/dist/learning-words.d.ts +8 -1
- package/dist/learning-words.js +11 -1
- package/dist/learning.d.ts +26 -1
- package/dist/learning.js +7 -4
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/llm.js +0 -3
- package/dist/local-models.d.ts +33 -2
- package/dist/local-models.js +43 -5
- 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 +113 -0
- package/dist/mcp-probe.d.ts +8 -9
- package/dist/mcp-probe.js +16 -33
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +102 -26
- package/dist/mcp-servers-store.js +151 -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-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +39 -6
- package/dist/model.js +171 -32
- package/dist/monid.d.ts +50 -29
- package/dist/monid.js +234 -143
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +705 -126
- package/dist/paid-calls.d.ts +34 -32
- package/dist/paid-calls.js +52 -104
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +7 -2
- package/dist/port-models.js +5 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +8 -3
- package/dist/propose.js +28 -7
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +17 -2
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/reflect-range.js +2 -1
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +23 -1
- package/dist/run-launch.js +17 -4
- package/dist/run-learning-served.d.ts +84 -0
- package/dist/run-manifest.d.ts +8 -0
- package/dist/run-manifest.js +33 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-secrets.js +2 -3
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +12 -10
- package/dist/run-view.d.ts +59 -41
- package/dist/run-view.js +128 -64
- package/dist/runnable.d.ts +13 -8
- package/dist/runnable.js +77 -60
- package/dist/runner/adapter-loop.d.ts +60 -15
- package/dist/runner/adapter-loop.js +1406 -464
- package/dist/runner/adapter-run-spec.d.ts +45 -14
- package/dist/runner/adapter-run-spec.js +200 -116
- package/dist/runner/adapters/pi.d.ts +40 -7
- package/dist/runner/adapters/pi.js +149 -38
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +150 -66
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +5 -3
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +149 -5
- package/dist/runner/conformance/subject.d.ts +11 -4
- package/dist/runner/end-of-run.d.ts +8 -5
- package/dist/runner/end-of-run.js +11 -6
- package/dist/runner/feedback-round.d.ts +79 -0
- package/dist/runner/feedback-round.js +127 -0
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +55 -13
- package/dist/runner/journal-kinds.js +19 -0
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +58 -19
- package/dist/runner/learning-end.js +316 -115
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +21 -1
- package/dist/runner/learning-loop.js +24 -6
- 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 +34 -1
- package/dist/runner/loop.js +55 -1
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-claim.d.ts +5 -1
- package/dist/runner/mcp-claim.js +66 -50
- package/dist/runner/mcp-run.d.ts +20 -53
- package/dist/runner/mcp-run.js +22 -88
- package/dist/runner/meta-tools.d.ts +44 -0
- package/dist/runner/meta-tools.js +344 -0
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +128 -42
- package/dist/runner/model-route.d.ts +12 -3
- package/dist/runner/model-route.js +149 -19
- package/dist/runner/monid-run.d.ts +18 -0
- package/dist/runner/monid-run.js +170 -0
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +146 -0
- package/dist/runner/promotion.js +803 -0
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.d.ts +36 -21
- package/dist/runner/reflect-hook.js +147 -49
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +34 -8
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/sessions.d.ts +8 -3
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +7 -12
- package/dist/runner/workflow-first.d.ts +226 -0
- package/dist/runner/workflow-first.js +293 -0
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +32 -19
- package/dist/runner/workflow-spec.d.ts +5 -1
- package/dist/runner/workflow-spec.js +63 -48
- package/dist/runs-over-store.d.ts +41 -4
- package/dist/runs-over-store.js +64 -22
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +108 -20
- package/dist/server.js +874 -157
- package/dist/settings-wake.d.ts +8 -6
- package/dist/settings-wake.js +13 -7
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +22 -7
- package/dist/store/agent-body.js +23 -14
- package/dist/store/command-wake.d.ts +3 -2
- package/dist/store/command-wake.js +4 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- 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/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.js +3 -0
- package/dist/store/schema.d.ts +16 -0
- package/dist/store/schema.js +47 -8
- package/dist/store/sqlite/connection.d.ts +2 -2
- package/dist/store/sqlite/connection.js +2 -2
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +33 -10
- package/dist/store/sqlite/store.js +184 -28
- package/dist/store/store.d.ts +98 -21
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +30 -1
- package/dist/store-reads/journal.js +141 -83
- package/dist/store-reads/learning.d.ts +179 -13
- package/dist/store-reads/learning.js +230 -68
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +3 -2
- package/dist/store-view.js +109 -37
- package/dist/template-eval.d.ts +87 -16
- package/dist/template-eval.js +605 -120
- 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 +274 -52
- package/dist/templates.js +670 -201
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +7 -5
- package/dist/timeline/index.js +7 -5
- package/dist/timeline/labels.d.ts +11 -4
- package/dist/timeline/labels.js +122 -8
- package/dist/timeline/origin.d.ts +20 -6
- package/dist/timeline/origin.js +13 -6
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +76 -20
- package/dist/timeline/timeline.js +184 -39
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +103 -76
- package/dist/tool-gate.js +200 -127
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +29 -0
- package/dist/tool-list.js +50 -0
- package/dist/tool-names.d.ts +76 -0
- package/dist/tool-names.js +101 -0
- package/dist/tool-plane.d.ts +34 -28
- package/dist/tool-plane.js +72 -37
- package/dist/tools.d.ts +59 -15
- package/dist/tools.js +46 -42
- package/dist/trigger-adapter.d.ts +85 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +228 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +94 -9
- package/dist/triggers.js +263 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +91 -50
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +6 -8
- package/dist/web-fetch.js +10 -53
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +25 -9
- package/dist/workspace/computer-deps.js +82 -38
- package/dist/workspace/computer-for-claim.d.ts +60 -4
- package/dist/workspace/computer-for-claim.js +203 -45
- package/dist/workspace/computer-hold.js +7 -1
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +31 -11
- package/dist/workspace/kind-skills/phone/SKILL.md +29 -14
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +33 -1
- package/dist/workspace/resolve-computer.js +37 -16
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +40 -23
- package/dist/workspace/run-tools.js +46 -19
- package/dist/wrap-up.d.ts +35 -0
- package/dist/wrap-up.js +48 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +220 -60
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +46 -16
- 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 +3 -3
- 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/off-by-one/graders/no-repo-reads.md +2 -1
- 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/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -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 +5 -4
- package/templates/code-review/skills/review/REVIEWER.md +5 -4
- package/templates/code-review/skills/review/SKILL.md +11 -6
- 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 +5 -4
- 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 +5 -4
- 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/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -7
- package/dist/runner/adapters/pi-computer.js +0 -43
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.d.ts +0 -38
- package/dist/tool-budget.js +0 -62
- package/dist/workspace/computer-script.d.ts +0 -37
- package/dist/workspace/computer-script.js +0 -138
- 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
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { RemoteConnectors, checkedPrepared, openRemoteSession, remoteResult } from '../native/remote.js';
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { nativeEnvironment } from "../native/environment.js";
|
|
5
|
+
// A native job participates in the existing claim/journal/end-of-run contract. Native side effects are never replayed
|
|
6
|
+
// after an uncertain send. The original directory/configuration is untouched; pinned saved instructions and learned context are additive.
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { BACKGROUND_CONTEXT, withAbortSignal } from '@earendil-works/chord/context';
|
|
11
|
+
import { ROOT_CONVERSATION_ID } from '@earendil-works/pi-durable';
|
|
12
|
+
import { learningFolderOf, readerOf, seedFrom, secretsShown, chooseSkills } from '../learning.js';
|
|
13
|
+
import { nativeOf, nativeModelOverrides, nativeExecutionOverrides, NATIVE_MODEL_SETTINGS_UNSUPPORTED, NATIVE_EXECUTION_SETTINGS_UNSUPPORTED, NATIVE_TOOL_BUDGET_UNSUPPORTED } from '../native/binding.js';
|
|
14
|
+
import { launchNative } from '../native/connection.js';
|
|
15
|
+
import { openNativeSession } from '../native/runtime.js';
|
|
16
|
+
import { discoverNative } from '../native/discovery.js';
|
|
17
|
+
import { nativeSkillContext } from '../native/context.js';
|
|
18
|
+
import { snapshotNativeInstructions, withSavedNativeInstructions } from '../native/instructions.js';
|
|
19
|
+
import { isNativeRuntime, NATIVE_RUNTIME_FACTS } from '../native/runtimes.js';
|
|
20
|
+
import { inputMessage } from '../run-manifest.js';
|
|
21
|
+
import { outputContract, outputMiss, outputRetryWords } from '../answer-json.js';
|
|
22
|
+
import { cutStrings, redactedOutput } from '../key-refusal.js';
|
|
23
|
+
import { learningEndOfRun } from './learning-end.js';
|
|
24
|
+
import { learningLoopFactory } from './learning-factory.js';
|
|
25
|
+
import { pathMetrics } from './workflow-first.js';
|
|
26
|
+
import { reflectRequestId } from './end-of-run.js';
|
|
27
|
+
import { journalEntries } from './journal-reader.js';
|
|
28
|
+
import { HOST_PHASE } from '../timeline/index.js';
|
|
29
|
+
import { KINDS } from './journal-kinds.js';
|
|
30
|
+
import { bookedSpend, cliRunMetrics } from './metrics.js';
|
|
31
|
+
import { stopEnd } from './loop-contract.js';
|
|
32
|
+
import { END_PATCH_MS, END_PATCH_UNKNOWN } from './loop.js';
|
|
33
|
+
import { storeSecrets } from './store-secrets.js';
|
|
34
|
+
import { runnerSecrets, heldRedactor, processSecretRedactor } from './redact.js';
|
|
35
|
+
import { secretRedactor } from './redact.js';
|
|
36
|
+
const ROOT = ROOT_CONVERSATION_ID;
|
|
37
|
+
const MARK = 'agentrun.native';
|
|
38
|
+
const pendingProjects = new Set();
|
|
39
|
+
class NativeProjectBusy extends Error {
|
|
40
|
+
}
|
|
41
|
+
/** One source directory at a time, across this runner's claims and other local runner processes. A stale process's
|
|
42
|
+
* lock is not stolen: uncertain native side effects require the owner to inspect the source project first. */
|
|
43
|
+
async function lockProject(data, target, runId) {
|
|
44
|
+
const key = createHash('sha256').update(target.remote ? `${target.remote.connector_id}:${target.machine_id}:${target.project}` : target.project).digest('hex');
|
|
45
|
+
if (pendingProjects.has(key))
|
|
46
|
+
throw new NativeProjectBusy('Another native run is using this project.');
|
|
47
|
+
pendingProjects.add(key);
|
|
48
|
+
const root = join(data, 'native-locks');
|
|
49
|
+
const path = join(root, key);
|
|
50
|
+
try {
|
|
51
|
+
await mkdir(root, { recursive: true });
|
|
52
|
+
await mkdir(path);
|
|
53
|
+
await writeFile(join(path, 'owner.json'), JSON.stringify({ pid: process.pid, run_id: runId }));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
pendingProjects.delete(key);
|
|
57
|
+
if (error.code === 'EEXIST') {
|
|
58
|
+
try {
|
|
59
|
+
const owner = JSON.parse(await readFile(join(path, 'owner.json'), 'utf8'));
|
|
60
|
+
process.kill(owner.pid, 0);
|
|
61
|
+
throw new NativeProjectBusy('Another native run is using this project.');
|
|
62
|
+
}
|
|
63
|
+
catch (held) {
|
|
64
|
+
if (held instanceof NativeProjectBusy)
|
|
65
|
+
throw held;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw new Error('The source project is locked by another native run. Wait for it; after a runner crash inspect the project and remove its stale native-locks entry before starting again.', { cause: error });
|
|
69
|
+
}
|
|
70
|
+
return async () => { pendingProjects.delete(key); await rm(path, { recursive: true, force: true }); };
|
|
71
|
+
}
|
|
72
|
+
async function contextFor(data, agentId, runId, launch, refuse, nativeSkills) {
|
|
73
|
+
if (!launch.learning)
|
|
74
|
+
return { skills: [] };
|
|
75
|
+
const folder = learningFolderOf(data, agentId);
|
|
76
|
+
try {
|
|
77
|
+
const seed = await seedFrom(launch.learning.seed, readerOf(folder.workspace));
|
|
78
|
+
// Use the same budgets/checks as the managed seed. Reads only; no files in the source project are laid or replaced.
|
|
79
|
+
const selected = await chooseSkills(folder.workspace, { ...seed, skills: seed.skills?.filter(skill => !nativeSkills.includes(skill.name)) }, [], secretsShown(refuse, { local: true }));
|
|
80
|
+
if (launch.native?.remote) {
|
|
81
|
+
const taken = [], left = [];
|
|
82
|
+
for (const skill of selected.taken) {
|
|
83
|
+
if (Object.keys(skill.files ?? {}).length > 128) {
|
|
84
|
+
left.push(`${skill.name} (more than 128 remote skill files)`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (taken.length >= 64) {
|
|
88
|
+
left.push(`${skill.name} (64 remote skills already selected)`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
taken.push(skill);
|
|
92
|
+
}
|
|
93
|
+
return { text: launch.learning.section, skills: taken.map(skill => skill.name), remoteSkills: taken, left };
|
|
94
|
+
}
|
|
95
|
+
const skills = selected.taken.map(s => s.name);
|
|
96
|
+
const offered = await nativeSkillContext(join(data, 'native-context', runId, 'skills'), selected.taken);
|
|
97
|
+
return { text: [launch.learning.section, offered].filter(Boolean).join('\n\n'), skills };
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
await folder.end();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function createNativeLoop(launch, host) {
|
|
104
|
+
return deps => {
|
|
105
|
+
const held = heldRedactor(deps.redact ?? processSecretRedactor());
|
|
106
|
+
let stopped;
|
|
107
|
+
const abort = new AbortController();
|
|
108
|
+
let session;
|
|
109
|
+
let settled;
|
|
110
|
+
const signal = AbortSignal.any([deps.signal, abort.signal]);
|
|
111
|
+
return {
|
|
112
|
+
command: async () => ({ refused: 'Native jobs support stop and cancel. Start a new run for another task; in-session steering and approvals are unavailable.' }),
|
|
113
|
+
stop: async (reason) => { stopped = reason; abort.abort(new Error('Native run stopped')); await session?.close(); await settled?.catch(() => { }); },
|
|
114
|
+
start(claim) {
|
|
115
|
+
const work = async () => {
|
|
116
|
+
const journal = deps.journal(claim);
|
|
117
|
+
const ctx = withAbortSignal(deps.signal, BACKGROUND_CONTEXT);
|
|
118
|
+
let rooted = false;
|
|
119
|
+
let sequence = Promise.resolve();
|
|
120
|
+
const append = (kind, data, patch, also, take) => {
|
|
121
|
+
const write = async () => {
|
|
122
|
+
const writes = [];
|
|
123
|
+
if (!rooted && !(await journal.conversation(ROOT, ctx)))
|
|
124
|
+
writes.push({ type: 'conversation', value: { id: ROOT } });
|
|
125
|
+
const id = await journal.mintId();
|
|
126
|
+
writes.push({ type: 'entry', value: { id, conversationId: ROOT, kind, data, ...((kind === KINDS.message || kind === KINDS.endOfRunTurn) && data?.role === 'person' ? { model: [{ role: 'user', content: data.text, timestamp: Date.now() }] } : {}) } });
|
|
127
|
+
if (patch || also || take !== undefined)
|
|
128
|
+
journal.stage({ effect: id, ...(patch ? { run: patch } : {}), ...(also ? { also } : {}), ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
|
|
129
|
+
const result = await journal.commit([writes], () => { }, ctx);
|
|
130
|
+
if (!result.stored)
|
|
131
|
+
throw result.refused;
|
|
132
|
+
rooted = true;
|
|
133
|
+
};
|
|
134
|
+
const written = sequence.then(write);
|
|
135
|
+
sequence = written;
|
|
136
|
+
return written;
|
|
137
|
+
};
|
|
138
|
+
const source = await host.store.runs.get(claim.runId);
|
|
139
|
+
if (!source)
|
|
140
|
+
throw new Error('Native run no longer exists.');
|
|
141
|
+
const agentId = source.agentId;
|
|
142
|
+
const revision = (await host.store.agents.revision(source.revisionId))?.body;
|
|
143
|
+
const outputSchema = revision?.outputSchema;
|
|
144
|
+
const savedInstructions = revision?.instructions ?? '';
|
|
145
|
+
const previous = await journalEntries(journal, ctx);
|
|
146
|
+
if (previous.some(e => e.kind === KINDS.end))
|
|
147
|
+
return { state: 'ended' };
|
|
148
|
+
if (previous.some(e => e.kind === `${MARK}.sending`)) {
|
|
149
|
+
await append(KINDS.end, { state: 'failed', error: 'Native execution was interrupted after dispatch. Its effects are unknown; it was not sent again.' }, { state: 'failed', outcome: null, summary: 'Native execution outcome unknown; inspect the source project.', costUsd: null });
|
|
150
|
+
return { state: 'failed', error: { code: 'native_outcome_unknown', message: 'Native execution interrupted after dispatch; no automatic replay.' } };
|
|
151
|
+
}
|
|
152
|
+
let unlock;
|
|
153
|
+
let reflect = false;
|
|
154
|
+
let automaticLearningUnavailable = false;
|
|
155
|
+
let nativeSessionId;
|
|
156
|
+
let turn = 0;
|
|
157
|
+
let partialText = '';
|
|
158
|
+
let pendingUsage;
|
|
159
|
+
const liveTools = new Map();
|
|
160
|
+
const live = () => deps.live?.(() => ({ tools: [...liveTools.values()], ...(partialText ? { partial: { text: partialText } } : {}) }));
|
|
161
|
+
let openedSecrets = [];
|
|
162
|
+
const redact = (text) => held(text);
|
|
163
|
+
const redactData = (value) => cutStrings(redactedOutput(value, [...new Set([...(held.heldValues?.() ?? []), ...openedSecrets])]), redact);
|
|
164
|
+
const onEvent = async (event) => {
|
|
165
|
+
if (event.type === 'session') {
|
|
166
|
+
nativeSessionId = event.sessionId;
|
|
167
|
+
await append(`${MARK}.session`, { session_id: event.sessionId });
|
|
168
|
+
}
|
|
169
|
+
else if (event.type === 'text') {
|
|
170
|
+
partialText += event.text;
|
|
171
|
+
live();
|
|
172
|
+
}
|
|
173
|
+
else if (event.type === 'usage') {
|
|
174
|
+
pendingUsage = event.usage;
|
|
175
|
+
}
|
|
176
|
+
else if (event.type === 'tool') {
|
|
177
|
+
if (event.status === 'started')
|
|
178
|
+
liveTools.set(event.id, { callId: event.id, name: event.name, args: event.input });
|
|
179
|
+
else
|
|
180
|
+
liveTools.delete(event.id);
|
|
181
|
+
live();
|
|
182
|
+
if (event.status === 'started')
|
|
183
|
+
await append(KINDS.callStart, { callId: event.id, tool: event.name, input: redactData(event.input ?? {}), replaySafe: false, cwd: launch.native?.project });
|
|
184
|
+
else
|
|
185
|
+
await append(KINDS.callEnd, { callId: event.id, tool: event.name, status: event.status === 'completed' ? 'done' : 'failed', output: redactData(event.output ?? '') });
|
|
186
|
+
}
|
|
187
|
+
else if (event.type === 'approval') {
|
|
188
|
+
await append(`${MARK}.approval`, { id: event.id, tool: event.tool, status: 'unavailable', message: 'This native tool needs interactive permission. Run it in your native CLI; AgentRun did not approve it.' });
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const recordResult = async (result, label) => {
|
|
192
|
+
const usage = result.usage;
|
|
193
|
+
const input = nativeInput(usage, launch.native?.runtime);
|
|
194
|
+
await append('runner.turn', { turn, usd: usage.cost_usd, usage: { ...(input === null ? {} : { input }), ...(usage.output_tokens === null ? {} : { output: usage.output_tokens }), ...(usage.cache_read_tokens === null ? {} : { cacheRead: usage.cache_read_tokens }), ...(usage.cache_write_tokens === null ? {} : { cacheWrite: usage.cache_write_tokens }) }, aggregate: true });
|
|
195
|
+
await append(`${MARK}.usage`, { phase: label, session_id: result.sessionId, model: result.model ?? null, usage });
|
|
196
|
+
};
|
|
197
|
+
const send = async (prompt, label, timeoutMs = 180_000) => {
|
|
198
|
+
turn++;
|
|
199
|
+
partialText = '';
|
|
200
|
+
pendingUsage = undefined;
|
|
201
|
+
live();
|
|
202
|
+
await append('runner.request', { turn, model: launch.native?.model ?? launch.native?.runtime, aggregate: true });
|
|
203
|
+
await deps.flush();
|
|
204
|
+
let result;
|
|
205
|
+
try {
|
|
206
|
+
result = await session.send(prompt, { signal, reflection: label === 'reflection', timeoutMs });
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (pendingUsage)
|
|
210
|
+
await recordResult({ sessionId: nativeSessionId ?? '', answer: '', usage: pendingUsage }, label);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
await sequence;
|
|
214
|
+
if (nativeSessionId && result.sessionId !== nativeSessionId)
|
|
215
|
+
throw new Error('Native session identity changed during the run.');
|
|
216
|
+
nativeSessionId = result.sessionId;
|
|
217
|
+
await recordResult(result, label);
|
|
218
|
+
partialText = '';
|
|
219
|
+
live();
|
|
220
|
+
return result;
|
|
221
|
+
};
|
|
222
|
+
let also;
|
|
223
|
+
const interrupted = () => deps.signal.aborted || stopped?.kind === 'claim-lost' || stopped?.kind === 'shutdown';
|
|
224
|
+
let endPatch;
|
|
225
|
+
const readEndPatch = async (model, runtime, usage) => {
|
|
226
|
+
if (endPatch !== undefined)
|
|
227
|
+
return endPatch;
|
|
228
|
+
let timer;
|
|
229
|
+
const late = new Promise(resolve => { timer = setTimeout(() => resolve(END_PATCH_UNKNOWN), END_PATCH_MS); });
|
|
230
|
+
try {
|
|
231
|
+
// Only reads race the deadline. A late result never writes a patch or changes the chosen end.
|
|
232
|
+
const read = async () => {
|
|
233
|
+
const entries = await journalEntries(journal, ctx);
|
|
234
|
+
const spend = bookedSpend(entries, 'model');
|
|
235
|
+
return { costUsd: spend.usd, metrics: { ...nativeMetrics(launch, entries, spend, model, turn, runtime), native_session_id: nativeSessionId, ...(usage ? { native_usage: usage } : {}) } };
|
|
236
|
+
};
|
|
237
|
+
endPatch = await Promise.race([read(), late]);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
endPatch = END_PATCH_UNKNOWN;
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
}
|
|
245
|
+
return endPatch;
|
|
246
|
+
};
|
|
247
|
+
try {
|
|
248
|
+
// Older queued revisions may predate the API guard. Never silently run past their pinned limit.
|
|
249
|
+
if ((revision?.maxToolCalls ?? 0) > 0)
|
|
250
|
+
throw new Error(NATIVE_TOOL_BUDGET_UNSUPPORTED);
|
|
251
|
+
if (nativeModelOverrides(revision).length)
|
|
252
|
+
throw new Error(NATIVE_MODEL_SETTINGS_UNSUPPORTED);
|
|
253
|
+
if (nativeExecutionOverrides(revision).length)
|
|
254
|
+
throw new Error(NATIVE_EXECUTION_SETTINGS_UNSUPPORTED);
|
|
255
|
+
// Recheck current binding to make disconnect win over queued starts and to reject another machine's claims.
|
|
256
|
+
const current = await host.store.agents.revision((await host.store.agents.get(agentId))?.currentRevision ?? '');
|
|
257
|
+
const binding = nativeOf(current?.body);
|
|
258
|
+
if (!binding)
|
|
259
|
+
throw new Error('The native binding was removed.');
|
|
260
|
+
const broker = binding.remote ? new RemoteConnectors(host.store) : undefined;
|
|
261
|
+
const prepared = broker ? checkedPrepared(binding, await broker.request(binding, 'prepare', {}, { signal, timeoutMs: 30_000 })) : undefined;
|
|
262
|
+
const target = prepared?.target ?? await launchNative(binding);
|
|
263
|
+
if (target.state !== 'ready' || !target.capabilities.launch)
|
|
264
|
+
throw new Error(target.issues.join(' ') || 'The remote native sign-in is not ready.');
|
|
265
|
+
unlock = await lockProject(host.data, target, claim.runId);
|
|
266
|
+
signal.throwIfAborted();
|
|
267
|
+
const refuse = runnerSecrets(process.env, await storeSecrets(host.store, host.sealKey, host.data));
|
|
268
|
+
openedSecrets = refuse;
|
|
269
|
+
held.hold(refuse);
|
|
270
|
+
const instructions = withSavedNativeInstructions(prepared?.instructions ?? await snapshotNativeInstructions(target, secretRedactor(refuse)), savedInstructions, redact);
|
|
271
|
+
await append(`${MARK}.instructions`, instructions);
|
|
272
|
+
// Preparation can withdraw learning after this launch was queued. The final
|
|
273
|
+
// saved-policy snapshot can also newly exceed the evidence limit. Keep task
|
|
274
|
+
// context/use intact, but refuse the reflection before it reaches the source.
|
|
275
|
+
if (launch.learning && !launch.learning.use && (instructions.incomplete || instructions.truncated || !target.capabilities.notes && !target.capabilities.skills)) {
|
|
276
|
+
automaticLearningUnavailable = true;
|
|
277
|
+
const why = instructions.incomplete || (instructions.truncated ? 'the combined source and saved policy exceeds the grading evidence limit.' : 'the prepared source does not support notes or skills.');
|
|
278
|
+
const detail = redact(`Self-improvement skipped: ${why} A new run must capture complete policy evidence before automatic learning.`);
|
|
279
|
+
// An unasked drop settles both learning views atomically with the task end;
|
|
280
|
+
// it queues no learning run and keeps an unavailable run from staying seeded.
|
|
281
|
+
also = [{ table: 'learning_proposals', row: { turn: null, proposal: { state: 'dropped', reason: 'checker', detail } } }];
|
|
282
|
+
await append(HOST_PHASE, { summary: detail });
|
|
283
|
+
}
|
|
284
|
+
// A reclaimed claim before the durable dispatch marker can safely replace only its own additive files.
|
|
285
|
+
await rm(join(host.data, 'native-context', claim.runId), { recursive: true, force: true });
|
|
286
|
+
const learned = await contextFor(host.data, agentId, claim.runId, launch, refuse, target.skills);
|
|
287
|
+
if (learned.left?.length)
|
|
288
|
+
await append(HOST_PHASE, { summary: redact(`Learned skills left out of this remote run: ${learned.left.join('; ')}.`) });
|
|
289
|
+
await append(`${MARK}.configuration`, { ...target, learning_revision: launch.learning?.seed ?? null });
|
|
290
|
+
if (launch.learning)
|
|
291
|
+
await append(KINDS.learningLaid, { skills: learned.skills, workflows: [] });
|
|
292
|
+
const content = inputMessage(launch.input);
|
|
293
|
+
await append(KINDS.message, { role: 'person', text: content, at: Date.now(), ...(launch.inputOrigin ? { origin: launch.inputOrigin } : {}) });
|
|
294
|
+
await append(`${MARK}.sending`, { phase: 'task' });
|
|
295
|
+
await deps.flush();
|
|
296
|
+
const context = [savedInstructions, learned.text, outputContract(outputSchema)].filter(Boolean).join('\n\n');
|
|
297
|
+
session = broker ? await openRemoteSession(broker, target, { context: context || undefined, skills: learned.remoteSkills, runId: claim.runId, signal, onEvent }) : await openNativeSession({ target, context: context || undefined, signal, onEvent, env: nativeEnvironment() });
|
|
298
|
+
const task = async (prompt) => {
|
|
299
|
+
const result = await send(prompt, 'task');
|
|
300
|
+
await append(KINDS.message, { role: 'model', text: redact(result.answer), at: Date.now() });
|
|
301
|
+
if (result.permission_denials?.length)
|
|
302
|
+
throw new Error(`Native permission required: ${result.permission_denials.join(', ')}. This connection cannot answer interactive approvals.`);
|
|
303
|
+
return result;
|
|
304
|
+
};
|
|
305
|
+
let result = await task(content);
|
|
306
|
+
const miss = outputSchema === undefined ? undefined : outputMiss(result.answer, outputSchema);
|
|
307
|
+
if (miss) {
|
|
308
|
+
const retry = outputRetryWords(redact(miss));
|
|
309
|
+
await append(KINDS.message, { role: 'person', text: retry, at: Date.now(), origin: { kind: 'server', reason: 'output_retry' } });
|
|
310
|
+
result = await task(retry);
|
|
311
|
+
}
|
|
312
|
+
const end = automaticLearningUnavailable ? undefined : learningEndOfRun(launch, { store: host.store, data: host.data, learningFolder: id => learningFolderOf(host.data, id), env: process.env, stored: () => storeSecrets(host.store, host.sealKey, host.data) });
|
|
313
|
+
if (end) {
|
|
314
|
+
reflect = true;
|
|
315
|
+
also = (await end({ runId: claim.runId, agentId, claim, outcome: 'completed', signal, ask: async (prompt, opts) => {
|
|
316
|
+
const requestId = reflectRequestId(claim.runId, opts.again);
|
|
317
|
+
await append(KINDS.endOfRunTurn, { role: 'person', text: prompt, requestId });
|
|
318
|
+
try {
|
|
319
|
+
const answer = await send(prompt, 'reflection', opts.deadlineMs);
|
|
320
|
+
await append(KINDS.endOfRunTurn, { role: 'model', text: redact(answer.answer), requestId });
|
|
321
|
+
return { ended: true, answer: answer.answer };
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
return signal.aborted ? { timedOut: true } : { failed: { code: 'native_reflect_failed', message: redact(String(error)) } };
|
|
325
|
+
}
|
|
326
|
+
} }))?.also;
|
|
327
|
+
}
|
|
328
|
+
signal.throwIfAborted();
|
|
329
|
+
const patch = await readEndPatch(result.model ?? target.model ?? target.runtime, target.runtime, result.usage);
|
|
330
|
+
signal.throwIfAborted();
|
|
331
|
+
await append(KINDS.end, { state: 'ended', answer: redact(result.answer) }, { state: 'ended', outcome: 'completed', ...patch }, also);
|
|
332
|
+
return { state: 'ended' };
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
if (interrupted())
|
|
336
|
+
return { state: 'interrupted' };
|
|
337
|
+
const message = redact(error instanceof Error ? error.message : String(error));
|
|
338
|
+
const partial = await readEndPatch(launch.native?.model ?? launch.native?.runtime ?? 'native', launch.native?.runtime);
|
|
339
|
+
if (interrupted())
|
|
340
|
+
return { state: 'interrupted' };
|
|
341
|
+
if (stopped?.kind === 'command') {
|
|
342
|
+
const stoppedEnd = stopEnd(stopped.cancel);
|
|
343
|
+
await append(KINDS.end, stoppedEnd, { ...stoppedEnd, ...partial }, undefined, stopped.commandId);
|
|
344
|
+
return { state: 'stopped' };
|
|
345
|
+
}
|
|
346
|
+
// A waiting run may receive its cancel before the source owner releases the lock. Its stop is final even while
|
|
347
|
+
// the project is busy; parking it again would keep the optimistic cancelled view unsettled indefinitely.
|
|
348
|
+
if (error instanceof NativeProjectBusy) {
|
|
349
|
+
await append(`${MARK}.waiting`, { project: launch.native?.project }, { state: 'parked', summary: 'Waiting for the other native job in this source project.' });
|
|
350
|
+
return { state: 'parked', wakeAt: Date.now() + 1000 };
|
|
351
|
+
}
|
|
352
|
+
const hook = automaticLearningUnavailable ? undefined : learningEndOfRun(launch, { store: host.store, data: host.data, learningFolder: id => learningFolderOf(host.data, id) });
|
|
353
|
+
if (hook && !also)
|
|
354
|
+
also = (await hook({ runId: claim.runId, agentId, claim, outcome: 'failed', cut: reflect ? 'stopped-looking' : 'faulted', signal, ask: async () => ({ failed: { code: 'native_failed', message } }) }))?.also;
|
|
355
|
+
await append(KINDS.end, { state: 'failed', error: message }, { state: 'failed', outcome: null, summary: message, ...partial }, also);
|
|
356
|
+
return { state: 'failed', error: { code: 'native_failed', message } };
|
|
357
|
+
}
|
|
358
|
+
finally {
|
|
359
|
+
await session?.close();
|
|
360
|
+
await unlock?.();
|
|
361
|
+
await rm(join(host.data, 'native-context', claim.runId), { recursive: true, force: true });
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
const run = work();
|
|
365
|
+
settled = run;
|
|
366
|
+
return run;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
// Codex's input counter includes both cache components; Claude already reports uncached input.
|
|
372
|
+
function nativeInput(usage, runtime) {
|
|
373
|
+
if (runtime !== 'codex')
|
|
374
|
+
return usage.input_tokens;
|
|
375
|
+
return usage.input_tokens === null || usage.cache_read_tokens === null || usage.cache_write_tokens === null ? null : Math.max(0, usage.input_tokens - usage.cache_read_tokens - usage.cache_write_tokens);
|
|
376
|
+
}
|
|
377
|
+
function nativeMetrics(launch, entries, spend, model, turns, runtime) {
|
|
378
|
+
const counted = cliRunMetrics(entries, spend, { model });
|
|
379
|
+
const usage = entries.filter(e => e.kind === `${MARK}.usage`).map(e => e.data.usage);
|
|
380
|
+
const count = (native, key) => usage.length < turns || usage.some(u => u[native] === null) ? null : counted[key];
|
|
381
|
+
// Native tasks always run their agent: this lane never serves or calls an AgentRun learned workflow.
|
|
382
|
+
return { ...counted, ...pathMetrics(launch, { path: 'agent', workflow: null }, entries), input: usage.some(u => nativeInput(u, runtime) === null) ? null : count('input_tokens', 'input'), output: count('output_tokens', 'output'), cacheRead: count('cache_read_tokens', 'cacheRead'), cacheWrite: count('cache_write_tokens', 'cacheWrite'), requests: null, unmetered: null, models: {}, native_model_requests: null, native_turns: turns };
|
|
383
|
+
}
|
|
384
|
+
/** The ordinary checked/graded/atomic learning lane, using a distinct native signed-in session for its policy model.
|
|
385
|
+
* A separate empty directory prevents the source project's answer-format instructions from becoming grader policy. */
|
|
386
|
+
export function nativeLearningLoop(host, target) {
|
|
387
|
+
return learningLoopFactory({ store: host.store, data: host.data, sourceInstructions: runId => nativeSourceInstructions(host.store, runId), ask: async (request, signal) => {
|
|
388
|
+
if (target.remote) {
|
|
389
|
+
const result = remoteResult(await new RemoteConnectors(host.store).request(target, 'grade', { prompt: request.prompt, timeout_ms: 180_000 }, { signal, timeoutMs: 185_000 }));
|
|
390
|
+
const u = result.usage;
|
|
391
|
+
return { text: result.answer, usd: u.cost_usd, tokens: u.input_tokens === null || u.output_tokens === null || u.cache_read_tokens === null || u.cache_write_tokens === null ? null : { input: nativeInput(u, target.runtime), output: u.output_tokens, cache_read: u.cache_read_tokens, cache_write: u.cache_write_tokens } };
|
|
392
|
+
}
|
|
393
|
+
const dir = join(host.data, 'native-grader');
|
|
394
|
+
await mkdir(dir, { recursive: true });
|
|
395
|
+
await promisify(execFile)('git', ['init', '--quiet', dir], { timeout: 10_000 });
|
|
396
|
+
const graderTarget = (await discoverNative({ project: dir, runtime: target.runtime, env: nativeEnvironment() })).targets.find(value => value.selector.kind === 'project');
|
|
397
|
+
if (!graderTarget)
|
|
398
|
+
throw new Error('The native grading runtime is unavailable.');
|
|
399
|
+
const grader = await openNativeSession({ target: graderTarget, signal, env: nativeEnvironment() });
|
|
400
|
+
try {
|
|
401
|
+
const result = await grader.send(request.prompt, { signal, reflection: true, timeoutMs: 180_000 });
|
|
402
|
+
const u = result.usage;
|
|
403
|
+
return { text: result.answer, usd: u.cost_usd, tokens: u.input_tokens === null || u.output_tokens === null || u.cache_read_tokens === null || u.cache_write_tokens === null ? null : { input: nativeInput(u, target.runtime), output: u.output_tokens, cache_read: u.cache_read_tokens, cache_write: u.cache_write_tokens } };
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
await grader.close();
|
|
407
|
+
}
|
|
408
|
+
} });
|
|
409
|
+
}
|
|
410
|
+
/** Reuse the last policy snapshot before durable task dispatch, never an abandoned attempt or mutable source files. */
|
|
411
|
+
export async function nativeSourceInstructions(store, runId) {
|
|
412
|
+
const entries = await journalEntries(store.readJournal(runId), BACKGROUND_CONTEXT);
|
|
413
|
+
const sent = entries.findIndex(entry => entry.kind === `${MARK}.sending` && entry.data?.phase === 'task');
|
|
414
|
+
// A reclaimed pre-dispatch attempt can leave a snapshot behind. Only the last snapshot before the durable task
|
|
415
|
+
// dispatch belongs to the native session whose work is being graded; later unbound evidence cannot replace it.
|
|
416
|
+
const row = sent < 0 ? undefined : entries.slice(0, sent).findLast(entry => entry.kind === `${MARK}.instructions`);
|
|
417
|
+
const configuration = sent < 0 ? undefined : entries.slice(0, sent).findLast(entry => entry.kind === `${MARK}.configuration`);
|
|
418
|
+
const runtime = configuration?.data?.runtime;
|
|
419
|
+
const protocol = isNativeRuntime(runtime) ? NATIVE_RUNTIME_FACTS[runtime].protocol : undefined;
|
|
420
|
+
if (!row)
|
|
421
|
+
throw new Error('Native learning lacks its immutable source instruction snapshot; no proposal was promoted.');
|
|
422
|
+
if (!protocol)
|
|
423
|
+
throw new Error('Native standing instruction evidence is incomplete: the dispatched native runtime was not recorded. No proposal was promoted; a new source run must capture complete policy evidence before automatic learning.');
|
|
424
|
+
if (protocol === 'codex-json' && row?.data?.codexConfigurationChecked !== true)
|
|
425
|
+
throw new Error('Native standing instruction evidence is incomplete: this older Codex snapshot did not inspect custom policy configuration. No proposal was promoted; a new source run must capture complete policy evidence before automatic learning.');
|
|
426
|
+
if (protocol === 'claude-json' && row?.data?.claudeConfigurationChecked !== true)
|
|
427
|
+
throw new Error('Native standing instruction evidence is incomplete: this older Claude snapshot did not preserve source settings precedence. No proposal was promoted; a new source run must capture complete policy evidence before automatic learning.');
|
|
428
|
+
if (protocol === 'claude-json' && row?.data?.claudePolicySourcesChecked !== true)
|
|
429
|
+
throw new Error('Native standing instruction evidence is incomplete: this older Claude snapshot did not check imported or additional policy files. No proposal was promoted; a new source run must capture complete policy evidence before automatic learning.');
|
|
430
|
+
if (row?.data?.incomplete)
|
|
431
|
+
throw new Error(`Native standing instruction evidence is incomplete: ${row.data.incomplete} No proposal was promoted; automatic learning requires a complete source policy snapshot.`);
|
|
432
|
+
if (row?.data?.truncated)
|
|
433
|
+
throw new Error('Native standing instructions exceed the grading evidence limit; no proposal was promoted. Reduce or explicitly configure the grading context before enabling automatic learning.');
|
|
434
|
+
const text = row?.data?.text;
|
|
435
|
+
if (typeof text !== 'string')
|
|
436
|
+
throw new Error('Native learning lacks its immutable source instruction snapshot; no proposal was promoted.');
|
|
437
|
+
return text;
|
|
438
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { LearnedWorkflow } from "../learning.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
4
|
+
import { type Store } from "../store/store.js";
|
|
5
|
+
import { type ReplayCalls } from "../learn/replay-calls.js";
|
|
6
|
+
import { type Json } from "../validate.js";
|
|
7
|
+
import { type PromotionRecord, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
|
|
8
|
+
import { type FirstChoice, type Promoted } from "./workflow-first.js";
|
|
9
|
+
import type { LearningFolder } from "../learn/folder.js";
|
|
10
|
+
import type { Shown } from "../learning.js";
|
|
11
|
+
/** A replay run still not ended this long after its replay started counts as failed (no evidence), and is cancelled once
|
|
12
|
+
* the replay is decided without it. */
|
|
13
|
+
export declare const REPLAY_DEADLINE_MS: number;
|
|
14
|
+
/** A reserved replay run still not created this long after its record was reserved is a launch that was interrupted (the
|
|
15
|
+
* reserving claim crashed, or its create failed): the next claim creates it (relaunch). Before then it is pending. */
|
|
16
|
+
export declare const REPLAY_LAUNCH_GRACE_MS: number;
|
|
17
|
+
export interface PromotionDeps {
|
|
18
|
+
readonly store: Store;
|
|
19
|
+
readonly agentId: string;
|
|
20
|
+
/** The run being claimed: never one of its own replay's inputs. Absent: no run is claimed (a person's replay, and its
|
|
21
|
+
* read): no run served first to keep, none whose per_run MCP credentials a replay is handed. */
|
|
22
|
+
readonly runId?: string;
|
|
23
|
+
/** The revision the claimed run runs: its replay runs run it too. */
|
|
24
|
+
readonly revisionId: string;
|
|
25
|
+
/** The claimed run's launch: a replay run's is this one with the graded run's input. */
|
|
26
|
+
readonly launch: RunLaunch;
|
|
27
|
+
readonly context: Context;
|
|
28
|
+
readonly log: (line: string) => void;
|
|
29
|
+
/** Writes a refit's new workflow text onto the agent's learning folder (a merge as `id`, from the claim's seed); the
|
|
30
|
+
* learning commit it landed as, or null when it did not. Absent: no refit is written. */
|
|
31
|
+
readonly commit?: (files: {
|
|
32
|
+
path: string;
|
|
33
|
+
text: string;
|
|
34
|
+
}[], reason: string, id: string) => Promise<string | null>;
|
|
35
|
+
/** The learned workflow `name` as the learning folder held it active at `commit` (a champion's text), or undefined when
|
|
36
|
+
* it held none by that name. Absent: no champion serves. */
|
|
37
|
+
readonly champion?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>;
|
|
38
|
+
/** The digest of the learned workflow `name` the learning folder's main holds now (the newest revision), or undefined
|
|
39
|
+
* when it holds none by that name. Absent: no revision supersedes another. */
|
|
40
|
+
readonly newest?: (name: string) => Promise<string | undefined>;
|
|
41
|
+
/** The learned workflow an earlier claim of this run served first (its WORKFLOW_FIRST entry, answered or handed back:
|
|
42
|
+
* workflow-first.ts servedOf), or undefined for a run no claim served yet: a run already executing keeps its revision
|
|
43
|
+
* (keptFor). Absent: none kept. */
|
|
44
|
+
readonly kept?: () => Promise<{
|
|
45
|
+
readonly workflow: string;
|
|
46
|
+
readonly digest?: string;
|
|
47
|
+
} | undefined>;
|
|
48
|
+
/** The server's seal key: a replay run is handed the per_run MCP credentials the claimed run was handed, sealed for it
|
|
49
|
+
* (startReplay). Absent: a replay run is handed none (a per_run server's calls are refused unsent, the input failed). */
|
|
50
|
+
readonly sealKey?: Buffer;
|
|
51
|
+
readonly now?: () => number;
|
|
52
|
+
}
|
|
53
|
+
/** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a refit's revision
|
|
54
|
+
* written on it as a merge from the claim's seed (a workflow.json changed on main since is a conflict, never written over),
|
|
55
|
+
* and a champion read from it at its record's commit, cut of the server's secrets (`shown`) as the claim's lay is; and
|
|
56
|
+
* the workflow an earlier claim of this run served (`kept`, from its journal: none on a first claim). */
|
|
57
|
+
export declare function claimPromotion(deps: Omit<PromotionDeps, "commit" | "champion" | "kept"> & {
|
|
58
|
+
readonly folder: () => LearningFolder;
|
|
59
|
+
readonly shown: () => Promise<Shown>;
|
|
60
|
+
}): PromotionDeps;
|
|
61
|
+
/** A replay run's claim (launch.replay) of run `runId`, once its first choice is made: refused (ClaimRefused: the run ends
|
|
62
|
+
* failed, no agent turn, nothing sent) unless its revision's record still says replaying and names it among its runs (it
|
|
63
|
+
* is reserved before its runs are created), or has none (trimmed), and the claim laid that revision to serve it. A
|
|
64
|
+
* superseded, promoted or held revision's replay run never runs (a cancel that never reached it included), nor an older
|
|
65
|
+
* replay's leftover once its revision replays again; one whose workflow is not laid at its digest (the seed could not be
|
|
66
|
+
* read, the folder moved on) never falls to the agent's path. Any other run: nothing to check. */
|
|
67
|
+
export declare function replayClaimed(store: Pick<Store, "settings">, agentId: string, runId: string, launch: RunLaunch, choice: FirstChoice): Promise<void>;
|
|
68
|
+
/** The workflows a replay run's claim lays (`laid`, the seed lay's): the one it replays record-only (learn/promote.ts
|
|
69
|
+
* recordOnly: every guard at the least threshold the DSL takes, so each step's p is read and none hands back on it), or none by that name when
|
|
70
|
+
* the laid one is not the digest it replays (the replay then fails, never scoring another revision). Any other run's,
|
|
71
|
+
* as laid. */
|
|
72
|
+
export declare function replayLaid(launch: RunLaunch, laid: readonly LearnedWorkflow[]): LearnedWorkflow[];
|
|
73
|
+
/** The gate workflowFirstOf asks (its `promoted`), at every run's claim, a queued run's included: the workflow that serves
|
|
74
|
+
* this run first. A run already executing keeps the revision an earlier claim of it served (keptFor). Else the laid
|
|
75
|
+
* revision (`workflow` at `digest`, the folder's revision as the run's seed holds it) has its promotion moved on (decide:
|
|
76
|
+
* a replay started, settled or superseded, a dry-run promote), and then servingNow alone says who serves: the champion
|
|
77
|
+
* (championOf), the laid text when it is the champion, its own text read from its record's commit when not; undefined
|
|
78
|
+
* when none serves (the agent takes the run). A digest's own record never says it serves. */
|
|
79
|
+
export declare const promotionGate: (deps: PromotionDeps) => Promoted;
|
|
80
|
+
/** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
|
|
81
|
+
* replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
|
|
82
|
+
export declare class ReplayRefused extends Error {
|
|
83
|
+
readonly kind: "missing" | "conflict";
|
|
84
|
+
constructor(kind: "missing" | "conflict", message: string);
|
|
85
|
+
}
|
|
86
|
+
/** What a person's replay reads and writes through (POST and GET .../revisions/{digest}/replays): the claim's ports, with
|
|
87
|
+
* no claimed run. `launchOf`: a run's launch of the agent on `input` as its start makes one now, and the revision it runs
|
|
88
|
+
* on: a replay run's is this one with its graded run's input (startReplay), at the revision's learning commit. */
|
|
89
|
+
export interface ReplayAsk {
|
|
90
|
+
readonly store: Store;
|
|
91
|
+
readonly agentId: string;
|
|
92
|
+
readonly context: Context;
|
|
93
|
+
readonly log: (line: string) => void;
|
|
94
|
+
readonly folder: () => LearningFolder;
|
|
95
|
+
readonly shown: () => Promise<Shown>;
|
|
96
|
+
readonly launchOf: (input: Json) => Promise<{
|
|
97
|
+
readonly launch: RunLaunch;
|
|
98
|
+
readonly revisionId: string;
|
|
99
|
+
}>;
|
|
100
|
+
readonly now?: () => number;
|
|
101
|
+
}
|
|
102
|
+
/** A replay of `name` at `digest` a person asked for: the claim path's replay (reserve, startReplay), on `inputs`: `held`,
|
|
103
|
+
* the graded runs its last replay or hold was decided on (else, with none, the agent's newest REPLAY_INPUTS), or a number,
|
|
104
|
+
* the agent's newest that many (each a graded input the workflow fits); with either, the served runs graded wrong it was
|
|
105
|
+
* held on (heldOn), which it promotes only once it answered on: the claim's picker (inputsFor). Its runs end as a claim's
|
|
106
|
+
* do, and it is decided by the claim path's settle: at a claim that lays the revision, or at its read (replayView).
|
|
107
|
+
* Refused (ReplayRefused): no such workflow or revision; one replaying already, or another revision of it replaying (one
|
|
108
|
+
* at a time); a promoted one (it serves already); fewer than REPLAY_MIN graded inputs it fits (a replay on fewer could
|
|
109
|
+
* only hold it: settle scores none of it), refused before anything is reserved; an agent that does not learn here. The
|
|
110
|
+
* replay's id and its inputs. */
|
|
111
|
+
export declare function askReplay(ask: ReplayAsk, name: string, digest: string, inputs: "held" | number): Promise<{
|
|
112
|
+
replay: string;
|
|
113
|
+
inputs: number;
|
|
114
|
+
}>;
|
|
115
|
+
/** A replay as its read answers it (GET .../replays/{replay_id}). `status`: `running` while its record says replaying,
|
|
116
|
+
* `done` once promoted or held, `failed` when superseded (its runs cancelled) or when none of its runs started by its
|
|
117
|
+
* deadline (nothing was replayed; held, its `reason` says so). `outcomes`: what its own runs did (outcomesOf), so far
|
|
118
|
+
* while it runs, and once decided as its record kept them, whatever the agent's grades kept now; never the thresholds'
|
|
119
|
+
* reading (a run answered under its guard's threshold stays answered: `score` hands it back). `score` and `cost_usd`
|
|
120
|
+
* the decided record's, else the runs ended so far at the revision's serving thresholds, and null while a run's cost
|
|
121
|
+
* is unknown (replayCost). */
|
|
122
|
+
type ReplayView = {
|
|
123
|
+
readonly replay: string;
|
|
124
|
+
readonly workflow: string;
|
|
125
|
+
readonly digest: string;
|
|
126
|
+
readonly status: "running" | "done" | "failed";
|
|
127
|
+
readonly inputs: number;
|
|
128
|
+
readonly outcomes: ReplayOutcomes;
|
|
129
|
+
readonly score: ReplayScore;
|
|
130
|
+
readonly cost_usd: number | null;
|
|
131
|
+
readonly decided?: PromotionRecord["decided"];
|
|
132
|
+
readonly reason?: string;
|
|
133
|
+
};
|
|
134
|
+
/** Reads replay `id` of `name` at `digest`, settling it first as a claim of its revision would (the claim path's settle)
|
|
135
|
+
* once its runs ended or its deadline passed: it writes only the decision. A read never starts a run: a replay whose
|
|
136
|
+
* launch was interrupted (reserved runs never created) reads running until its deadline, then is decided held, read as
|
|
137
|
+
* failed, its reason saying none of its runs started and to start it again with POST. So a replay of a revision no claim
|
|
138
|
+
* lays (an older, held one) is decided too, and never running forever. Once decided, it reads only its record. Refused
|
|
139
|
+
* (missing) when the agent has no such replay. */
|
|
140
|
+
export declare function replayView(ask: ReplayAsk, name: string, digest: string, id: string): Promise<ReplayView>;
|
|
141
|
+
/** A replay run's call nodes (launch.replay; learn/replay-calls.ts): the graded run's recorded calls, read from its journal
|
|
142
|
+
* (a CLI's record shaped as pi's), and each tool classed by the claim's MCP pin (`runId`'s, its servers' annotations as
|
|
143
|
+
* they listed them) or the built-in list. Undefined for any other run. A recording that cannot be read is an empty one:
|
|
144
|
+
* every write is then skipped, never run. */
|
|
145
|
+
export declare function replayCallsFor(store: Store, runId: string, launch: RunLaunch, context: Context): Promise<ReplayCalls | undefined>;
|
|
146
|
+
export {};
|