@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { LearningLoopDeps } from "./learning-loop.js";
|
|
3
|
+
/** How long the ask waits, once the grade answered, for the proxy to book its request: the proxy books a request after its
|
|
4
|
+
* client has the whole answer (when the provider's stream ends, which can come later), so the spend is read once it is
|
|
5
|
+
* booked. One booked later than this reads unknown (null), never $0. */
|
|
6
|
+
export declare const GRADE_BOOKING_WAIT_MS = 10000;
|
|
3
7
|
/** The session the grader's requests are booked under, in the learning run's journal. */
|
|
4
8
|
export declare const GRADE_SESSION = "learning.grade";
|
|
5
9
|
/** Where the grader's request goes: the route's wire (`api`, Anthropic's Messages or OpenAI's Responses) at `origin`, for
|
|
@@ -13,6 +13,10 @@ import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
|
13
13
|
import { sessionProvider } from "../port-models.js";
|
|
14
14
|
import { policyFor } from "./adapters/pi.js";
|
|
15
15
|
import { journalSessions } from "./sessions.js";
|
|
16
|
+
/** How long the ask waits, once the grade answered, for the proxy to book its request: the proxy books a request after its
|
|
17
|
+
* client has the whole answer (when the provider's stream ends, which can come later), so the spend is read once it is
|
|
18
|
+
* booked. One booked later than this reads unknown (null), never $0. */
|
|
19
|
+
export const GRADE_BOOKING_WAIT_MS = 10_000;
|
|
16
20
|
/** The session the grader's requests are booked under, in the learning run's journal. */
|
|
17
21
|
export const GRADE_SESSION = "learning.grade";
|
|
18
22
|
const PROVIDER = "agentrun-grade";
|
|
@@ -40,6 +44,8 @@ export function bookedAsk(options) {
|
|
|
40
44
|
// The cap is the learning run's: asked with every session of the run summed, never this one's alone.
|
|
41
45
|
const hostCheck = options.beforeRequest ? runBooking(sessions, options.beforeRequest) : undefined;
|
|
42
46
|
let refused;
|
|
47
|
+
// Told once the grade's own request is booked (its request_end), never by a cut request booked before it.
|
|
48
|
+
let booked;
|
|
43
49
|
const booking = await modelPortFor(writer, {
|
|
44
50
|
key: GRADE_SESSION,
|
|
45
51
|
label: "grade",
|
|
@@ -53,11 +59,14 @@ export function bookedAsk(options) {
|
|
|
53
59
|
onEvent: async (event) => {
|
|
54
60
|
if (event.type === "request_start")
|
|
55
61
|
await run.flush();
|
|
62
|
+
if (event.type === "request_end")
|
|
63
|
+
booked?.();
|
|
56
64
|
},
|
|
57
65
|
});
|
|
58
66
|
// A grade request an earlier attempt sent and a crash cut is booked first, at its held figure.
|
|
59
67
|
await booking.bookCut();
|
|
60
68
|
const before = booking.spentUsd();
|
|
69
|
+
const bookedOnce = new Promise((resolve) => (booked = () => resolve(true)));
|
|
61
70
|
// The policy of the route's wire, as pi's session takes it (pi.ts policyFor: claude-agent's on Messages, codex's on
|
|
62
71
|
// Responses, no fork); the grade offers no tool.
|
|
63
72
|
const proxy = await startModelProxy({
|
|
@@ -81,7 +90,12 @@ export function bookedAsk(options) {
|
|
|
81
90
|
if (answer.stopReason === "error" || answer.stopReason === "aborted")
|
|
82
91
|
throw new Error(`the grade's request failed: ${answer.errorMessage ?? answer.stopReason}`);
|
|
83
92
|
const text = answer.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("");
|
|
84
|
-
|
|
93
|
+
// The spend once the proxy booked this request: read before, it is the spend without it ($0 for the grade). Not
|
|
94
|
+
// booked within the wait: unknown.
|
|
95
|
+
let timer;
|
|
96
|
+
const inTime = await Promise.race([bookedOnce, new Promise((resolve) => (timer = setTimeout(() => resolve(false), GRADE_BOOKING_WAIT_MS)))]);
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
const after = inTime ? booking.spentUsd() : null;
|
|
85
99
|
const usd = before === null || after === null ? null : after - before;
|
|
86
100
|
// pi-ai counts cache reads and writes apart from input, as the grade's tokens do.
|
|
87
101
|
const used = answer.usage;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TimelineEvent } from "../timeline/index.js";
|
|
2
|
+
import { type LearningFolder } from "../learn/folder.js";
|
|
2
3
|
import { type RunLaunch } from "../run-launch.js";
|
|
3
4
|
import { type SignInReader } from "../run-view.js";
|
|
4
5
|
import type { Store } from "../store/store.js";
|
|
@@ -23,9 +24,23 @@ export interface LearningEndDeps {
|
|
|
23
24
|
/** Every secret the server keeps sealed, read once at the run's end (store-secrets.ts storeSecrets over the store, the
|
|
24
25
|
* seal key and the data directory), never learned. A throw is a list that can't be read: the run learns nothing. */
|
|
25
26
|
readonly stored?: () => Promise<readonly string[]>;
|
|
26
|
-
/** The grade model the server names (learning.ts gradeModelOf); none, from `env` as the server reads it. */
|
|
27
|
-
readonly gradeModel?: string;
|
|
28
27
|
}
|
|
29
28
|
/** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
|
|
30
29
|
* does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
|
|
31
30
|
export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
|
|
31
|
+
/** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
|
|
32
|
+
* nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
|
|
33
|
+
* its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
|
|
34
|
+
* came in. Anything else is asked its end-of-run turn. */
|
|
35
|
+
export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
|
|
36
|
+
/** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
|
|
37
|
+
* no repeated job. */
|
|
38
|
+
export declare const DRAFT_SCAN_RUNS = 200;
|
|
39
|
+
/** The learned skill whose job the end-of-run turn asks for as a workflow draft: of the skills run `runId` was offered
|
|
40
|
+
* (its launch's learning start), the first in the seed's order (the one changed last first) offered to DRAFT_AFTER_RUNS
|
|
41
|
+
* or more runs of agent `agentId` started before it (each run's launch says what it was offered; its latest
|
|
42
|
+
* DRAFT_SCAN_RUNS runs are read newest first, those after `runId` in that order counted, only until every skill has its
|
|
43
|
+
* count), with no learned workflow of its name on the agent's main, active or waiting for
|
|
44
|
+
* its owner's OK (the folder's snapshot). One at most: a turn keeps one workflow draft. None when no skill qualifies, or
|
|
45
|
+
* when the folder can't be read: a read that fails asks for nothing, never a draft that may be there already. */
|
|
46
|
+
export declare function draftForOf(deps: Pick<LearningEndDeps, "store" | "learningFolder">, agentId: string, runId: string, offered: readonly string[]): Promise<string[]>;
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
// once at the run's start. A spec builder gives the adapter loop `endOfRun: learningEndOfRun(launch, deps)`. Each of the
|
|
4
4
|
// hook's reads is the server's own rule, over the store in place of the run's directory:
|
|
5
5
|
// - whether it looks back (learning-run.ts reflectSkip): its cap and its spend so far, read as its view reads them;
|
|
6
|
-
// - its prompt's facts: how many notes its seed held (launch seedNotes)
|
|
7
|
-
// (learning-run.ts draftTools);
|
|
6
|
+
// - its prompt's facts: how many notes its seed held (launch seedNotes), the tools a workflow draft may name
|
|
7
|
+
// (learning-run.ts draftTools), and the learned skill whose job it asks for as a workflow draft (draftForOf);
|
|
8
8
|
// - what the person said in the run and a trigger's input (heard.ts Hearing over its entries, the end-of-run turn's
|
|
9
9
|
// own left out), as learning-run.ts turnOf reads them;
|
|
10
|
+
// - whether the job gave nothing new to look back on (onlyLearnedWorkflows over its timeline): a run whose only tool
|
|
11
|
+
// work was its learned workflows, each answering, is not asked;
|
|
10
12
|
// - the checks: propose.ts proposeRun against the seed it started from, the server's one rule, which keeps the
|
|
11
13
|
// proposal the hook stores beside the run's end (learning_proposals);
|
|
12
14
|
// - what the run must never learn (learning-run.ts refused, the server's serverSecrets as far as the runner reads
|
|
@@ -21,14 +23,19 @@ import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
|
21
23
|
import { tmpdir } from "node:os";
|
|
22
24
|
import { join } from "node:path";
|
|
23
25
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
26
|
+
import { isMessageRow } from "../timeline/index.js";
|
|
24
27
|
import { Hearing } from "../heard.js";
|
|
28
|
+
import { readSnapshot } from "../learn/folder.js";
|
|
29
|
+
import { DRAFT_AFTER_RUNS } from "../learn/reflect.js";
|
|
30
|
+
import { SKILL_NAME } from "../learn/skills.js";
|
|
25
31
|
import { handedValuesOf } from "../handed-values.js";
|
|
26
32
|
import { MIN_SECRET } from "../learn/secrets.js";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
33
|
+
import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
|
|
34
|
+
import { LEARNING_LABEL, PROPOSAL } from "../learning.js";
|
|
35
|
+
import { reflects } from "../reflect-range.js";
|
|
29
36
|
import { said, STOPPED } from "../learning-words.js";
|
|
30
37
|
import { proposeRun } from "../propose.js";
|
|
31
|
-
import { learningStartOf } from "../run-launch.js";
|
|
38
|
+
import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
32
39
|
import { costOf } from "../run-view.js";
|
|
33
40
|
import { runEntries, runReflect, runTimeline } from "../store-reads/journal.js";
|
|
34
41
|
import { createReflectHook } from "./reflect-hook.js";
|
|
@@ -40,7 +47,8 @@ export function learningEndOfRun(launch, deps) {
|
|
|
40
47
|
if (!start)
|
|
41
48
|
return undefined;
|
|
42
49
|
const env = deps.env ?? process.env;
|
|
43
|
-
|
|
50
|
+
// The grade model the server named at the run's start (its learning start's), none: the agent's own grades it.
|
|
51
|
+
const gradeModel = start.gradeModel;
|
|
44
52
|
const capUsd = launch.maxCostUsd;
|
|
45
53
|
const hookFor = (runId) => createReflectHook({
|
|
46
54
|
// reflectSkip's facts: a run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be
|
|
@@ -49,7 +57,15 @@ export function learningEndOfRun(launch, deps) {
|
|
|
49
57
|
const costUsd = costOf(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false }));
|
|
50
58
|
return { learns: true, costUsd, ...(capUsd !== undefined ? { capUsd, capReached: costUsd !== null && costUsd >= capUsd } : {}) };
|
|
51
59
|
},
|
|
52
|
-
|
|
60
|
+
nothingNew: async (runId) => onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
|
|
61
|
+
// A draft asked for or not never stops the turn: a count that can't be read asks for none.
|
|
62
|
+
promptFacts: async (runId, agentId) => {
|
|
63
|
+
const { tools } = await draftTools(deps, runId);
|
|
64
|
+
const draftFor = await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
|
|
65
|
+
// With a draft asked for, what each tool its call nodes may run takes and gives, in the server's own words.
|
|
66
|
+
const described = draftFor.length ? await describedOf(tools) : [];
|
|
67
|
+
return { active: start.seedNotes ?? start.given.length, tools, draftFor, described };
|
|
68
|
+
},
|
|
53
69
|
asked: async (runId) => {
|
|
54
70
|
const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
|
|
55
71
|
const hearing = new Hearing();
|
|
@@ -85,14 +101,100 @@ export function learningEndOfRun(launch, deps) {
|
|
|
85
101
|
...(gradeModel ? { gradeModel } : {}),
|
|
86
102
|
});
|
|
87
103
|
return async (input) => {
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
// No seed, no end-of-run turn (seedFailed): a run that started from no commit of main has nothing to propose against,
|
|
105
|
+
// so it is never asked to look back (no model request). Why, as its start recorded it: a folder that could not be
|
|
106
|
+
// read, or a start that could not be made from it; a start that records none names no reason.
|
|
107
|
+
if (seedFailed(start)) {
|
|
108
|
+
const failed = start.seedFailed;
|
|
109
|
+
const why = failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : STOPPED.noSeed;
|
|
110
|
+
return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "seed_failed", detail: said.stopped(why) } } }] };
|
|
92
111
|
}
|
|
93
112
|
return hookFor(input.runId)(input);
|
|
94
113
|
};
|
|
95
114
|
}
|
|
115
|
+
/** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
|
|
116
|
+
* A harness that names it another way reads as another tool, so its run is asked as before. */
|
|
117
|
+
const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
|
|
118
|
+
/** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
|
|
119
|
+
* nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
|
|
120
|
+
* its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
|
|
121
|
+
* came in. Anything else is asked its end-of-run turn. */
|
|
122
|
+
export function onlyLearnedWorkflows(rows) {
|
|
123
|
+
const own = rows.filter((row) => row.agent_label !== LEARNING_LABEL);
|
|
124
|
+
if (own.some((row) => row.kind === "error" || row.kind === "tool_approval_requested" || row.kind === "waiting"))
|
|
125
|
+
return false;
|
|
126
|
+
if (own.filter(isMessageRow).length !== 1)
|
|
127
|
+
return false;
|
|
128
|
+
const calls = own.filter((row) => row.kind === "tool_use" && !row.parent_tool_use_id);
|
|
129
|
+
if (!calls.length || calls.some((row) => !LEARNED_NAMES.has(row.tool_name ?? "")))
|
|
130
|
+
return false;
|
|
131
|
+
const results = own.filter((row) => row.kind === "tool_result");
|
|
132
|
+
if (results.some((row) => row.tool_status !== "success"))
|
|
133
|
+
return false;
|
|
134
|
+
const answered = new Set(results.filter((row) => !row.parent_tool_use_id).map((row) => row.tool_use_id));
|
|
135
|
+
return calls.every((row) => answered.has(row.tool_use_id));
|
|
136
|
+
}
|
|
137
|
+
/** What each of `tools` takes and gives a workflow's call node, in the server's own words for it (tools.ts ToolEntry's
|
|
138
|
+
* summary): the draft ask's `describe`. */
|
|
139
|
+
async function describedOf(tools) {
|
|
140
|
+
const { toolOf } = await import("../tools.js");
|
|
141
|
+
return tools.flatMap((name) => {
|
|
142
|
+
const does = toolOf(name)?.summary;
|
|
143
|
+
return does ? [{ name, does }] : [];
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
|
|
147
|
+
* no repeated job. */
|
|
148
|
+
export const DRAFT_SCAN_RUNS = 200;
|
|
149
|
+
/** The learned skill whose job the end-of-run turn asks for as a workflow draft: of the skills run `runId` was offered
|
|
150
|
+
* (its launch's learning start), the first in the seed's order (the one changed last first) offered to DRAFT_AFTER_RUNS
|
|
151
|
+
* or more runs of agent `agentId` started before it (each run's launch says what it was offered; its latest
|
|
152
|
+
* DRAFT_SCAN_RUNS runs are read newest first, those after `runId` in that order counted, only until every skill has its
|
|
153
|
+
* count), with no learned workflow of its name on the agent's main, active or waiting for
|
|
154
|
+
* its owner's OK (the folder's snapshot). One at most: a turn keeps one workflow draft. None when no skill qualifies, or
|
|
155
|
+
* when the folder can't be read: a read that fails asks for nothing, never a draft that may be there already. */
|
|
156
|
+
export async function draftForOf(deps, agentId, runId, offered) {
|
|
157
|
+
// Only a skill's name reaches the prompt (reflectPrompt refuses anything else).
|
|
158
|
+
const served = new Map(offered.filter((name) => SKILL_NAME.test(name)).map((name) => [name, 0]));
|
|
159
|
+
if (!served.size)
|
|
160
|
+
return [];
|
|
161
|
+
// The list is newest first: only the runs after the ending one in it started before it, and count. A run started
|
|
162
|
+
// later (a long job's newer runs) never does, and an ending run past the latest DRAFT_SCAN_RUNS + 1 counts none.
|
|
163
|
+
let earlier = false;
|
|
164
|
+
for (const run of await deps.store.runs.list({ agentId, limit: DRAFT_SCAN_RUNS + 1 })) {
|
|
165
|
+
if (run.id === runId) {
|
|
166
|
+
earlier = true;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (!earlier || run.agentId !== agentId)
|
|
170
|
+
continue;
|
|
171
|
+
const row = await deps.store.runs.launch(run.id).catch(() => undefined);
|
|
172
|
+
const launch = row ? readLaunchBody(row.body) : undefined;
|
|
173
|
+
for (const name of (launch && learningStartOf(launch)?.skills) ?? [])
|
|
174
|
+
if (served.has(name))
|
|
175
|
+
served.set(name, served.get(name) + 1);
|
|
176
|
+
// Enough runs read once every skill has served its count.
|
|
177
|
+
if ([...served.values()].every((count) => count >= DRAFT_AFTER_RUNS))
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
const due = [...served].filter(([, count]) => count >= DRAFT_AFTER_RUNS);
|
|
181
|
+
if (!due.length)
|
|
182
|
+
return [];
|
|
183
|
+
let drafted;
|
|
184
|
+
const folder = deps.learningFolder(agentId);
|
|
185
|
+
try {
|
|
186
|
+
const snapshot = await readSnapshot(folder.workspace);
|
|
187
|
+
drafted = new Set((snapshot?.workflows ?? []).filter(({ status }) => status === "active" || status === "pending").map(({ name }) => name));
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
await folder.end().catch(() => undefined);
|
|
194
|
+
}
|
|
195
|
+
const open = due.find(([name]) => !drafted.has(name));
|
|
196
|
+
return open ? [open[0]] : [];
|
|
197
|
+
}
|
|
96
198
|
/** The tools a workflow draft may name (learning-run.ts draftTools): the revision's own, as its run's gate reads them
|
|
97
199
|
* with the server's settings (from the store) and the agent's; none for a workflow revision. */
|
|
98
200
|
async function draftTools(deps, runId) {
|
|
@@ -12,6 +12,11 @@ export declare const UNAVAILABLE_BACKOFF_MS: readonly [30000, 120000, 600000, 18
|
|
|
12
12
|
export interface KeptProposal {
|
|
13
13
|
readonly notes: readonly NoteText[];
|
|
14
14
|
readonly files?: readonly NoteText[];
|
|
15
|
+
/** Each kept draft's dry run, by its workflow.json's path (learn/skills.ts draftDryRun), which the grader is told. */
|
|
16
|
+
readonly dryRuns?: Readonly<Record<string, {
|
|
17
|
+
readonly status: string;
|
|
18
|
+
readonly detail?: string;
|
|
19
|
+
}>>;
|
|
15
20
|
readonly asked?: readonly string[];
|
|
16
21
|
readonly triggered?: readonly {
|
|
17
22
|
readonly source: string;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// merge's call merges once.
|
|
14
14
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
15
15
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
16
|
-
import { gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
|
|
16
|
+
import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
|
|
17
17
|
import { mergedNote, parseNoteFile } from "../learn/notes.js";
|
|
18
18
|
import { learnedPlace } from "../learn/skills.js";
|
|
19
19
|
import { notKept, said, STOPPED } from "../learning-words.js";
|
|
@@ -101,16 +101,23 @@ export function createLearningLoop(learning) {
|
|
|
101
101
|
const context = withAbortSignal(deps.signal, BACKGROUND_CONTEXT);
|
|
102
102
|
const journal = deps.journal(claim);
|
|
103
103
|
let rooted = false;
|
|
104
|
+
/** What the grade spent, as the run's learning end reads it (store-reads/learning.ts runLearningEnd): the graded
|
|
105
|
+
* entry's, a failed or cut grade's (null: unknown), else nothing graded, 0. Kept as the learning run's cost when it
|
|
106
|
+
* ends ended, failed or stopped, so what learning spent reads from the run rows alone (store learning.spend): a
|
|
107
|
+
* stop seen after a paid grade never hides it. */
|
|
108
|
+
let spend = 0;
|
|
104
109
|
/** One entry on the root, committed; `end` stages the run's state with it (keyed to this entry, its effect), and
|
|
105
|
-
* `take` the stop row it applies. */
|
|
110
|
+
* `take` the stop row it applies. An end that ends, fails or stops the run keeps what the grade spent as its cost. */
|
|
106
111
|
const append = async (kind, data, end, take) => {
|
|
107
112
|
const writes = [];
|
|
113
|
+
if (kind === KINDS.learningDropped && data !== null && typeof data === "object" && "usd" in data)
|
|
114
|
+
spend = data.usd ?? null;
|
|
108
115
|
if (!rooted && !(await journal.conversation(ROOT, context)))
|
|
109
116
|
writes.push({ type: "conversation", value: { id: ROOT } });
|
|
110
117
|
const id = await journal.mintId();
|
|
111
118
|
writes.push({ type: "entry", value: { id, conversationId: ROOT, kind, data } });
|
|
112
119
|
if (end)
|
|
113
|
-
journal.stage({ run: { state: end }, effect: id, ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
|
|
120
|
+
journal.stage({ run: { state: end, ...(end === "parked" ? {} : { costUsd: spend }) }, effect: id, ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
|
|
114
121
|
const result = await journal.commit([writes], () => { }, context);
|
|
115
122
|
if (result.stored === 0)
|
|
116
123
|
throw result.refused;
|
|
@@ -152,6 +159,8 @@ export function createLearningLoop(learning) {
|
|
|
152
159
|
const unavailable = entries.filter((entry) => entry.kind === KINDS.learningUnavailable).length;
|
|
153
160
|
// The grade: once. A verdict already in the journal is the one the merge goes on.
|
|
154
161
|
let graded = entries.find((entry) => entry.kind === KINDS.learningGraded)?.data;
|
|
162
|
+
if (graded)
|
|
163
|
+
spend = graded.usd;
|
|
155
164
|
if (!graded) {
|
|
156
165
|
const main = await learning.readMain(ws, proposal);
|
|
157
166
|
if ("problems" in main) {
|
|
@@ -161,17 +170,18 @@ export function createLearningLoop(learning) {
|
|
|
161
170
|
const items = gradedItems(proposal.notes, (proposal.files ?? []));
|
|
162
171
|
const prompt = gradePrompt({
|
|
163
172
|
run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded: main.superseded, proposed: proposal.notes,
|
|
164
|
-
...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}),
|
|
173
|
+
...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}),
|
|
165
174
|
});
|
|
166
175
|
// What the grade spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
|
|
167
176
|
// added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
|
|
168
177
|
let usd = 0;
|
|
169
178
|
let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
|
|
170
|
-
|
|
179
|
+
// `again`: what the grade is told after its last answer, below the same prompt.
|
|
180
|
+
const ask = async (again) => {
|
|
171
181
|
const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
|
|
172
182
|
let answer;
|
|
173
183
|
try {
|
|
174
|
-
answer = await learning.ask({ prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
|
|
184
|
+
answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
|
|
175
185
|
}
|
|
176
186
|
catch (error) {
|
|
177
187
|
usd = null;
|
|
@@ -189,8 +199,17 @@ export function createLearningLoop(learning) {
|
|
|
189
199
|
// An answer the host cannot read is asked once more, as the server's grade did.
|
|
190
200
|
if (verdict.reason === UNREADABLE_REASON && !verdict.items.length)
|
|
191
201
|
verdict = parseVerdict(await ask(), items);
|
|
202
|
+
// One that kept every item and said no merge contradicts itself: asked once more, the contradiction named. A
|
|
203
|
+
// second contradiction stands as no merge, said in the host's words as twice (learning-words.ts notKept); a
|
|
204
|
+
// contradiction after an unreadable answer is one, and is said so.
|
|
205
|
+
else if (verdict.reason === CONTRADICTED_REASON) {
|
|
206
|
+
const again = parseVerdict(await ask(CONTRADICTION_ASK), items);
|
|
207
|
+
verdict = again.reason === CONTRADICTED_REASON ? { ...again, reason: CONTRADICTED_TWICE_REASON } : again;
|
|
208
|
+
}
|
|
192
209
|
}
|
|
193
210
|
catch (error) {
|
|
211
|
+
// What the asks spent: a cut one's unknown (null), kept on a stopped run's row as on a dropped one's.
|
|
212
|
+
spend = usd;
|
|
194
213
|
const end = await halted();
|
|
195
214
|
if (end)
|
|
196
215
|
return end;
|
|
@@ -199,6 +218,7 @@ export function createLearningLoop(learning) {
|
|
|
199
218
|
return { state: "ended" };
|
|
200
219
|
}
|
|
201
220
|
graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
|
|
221
|
+
spend = usd;
|
|
202
222
|
await append(KINDS.learningGraded, graded);
|
|
203
223
|
// The verdict is durable before the merge, its side effect.
|
|
204
224
|
await deps.flush();
|
|
@@ -12,7 +12,7 @@ export interface LiveTicker {
|
|
|
12
12
|
/** Stops ticking at once and writes nothing more, what is pending included: a runner killed (a crash) lets nothing go. */
|
|
13
13
|
stop(): void;
|
|
14
14
|
}
|
|
15
|
-
/** Wraps `createLoop` so its loops' held states reach run_live, batched per tick. */
|
|
15
|
+
/** Wraps `createLoop` so its loops' held states reach run_live, batched per tick, cut by each loop's redactor. */
|
|
16
16
|
export declare function withLiveTicker(store: {
|
|
17
17
|
readonly live: Live;
|
|
18
18
|
}, createLoop: LoopFactory, options?: LiveTickerOptions): LiveTicker;
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { redactedAnswer, redactedLive, redactedOutput } from "../key-refusal.js";
|
|
2
|
+
/** A run's held state as the live view keeps it, under `values`, every secret value the run's one redactor holds. A
|
|
3
|
+
* running tool's id and name are cut whole (redactedAnswer). Its args by a workflow output's rule (redactedOutput): every
|
|
4
|
+
* string, property names included; a number whose digits hold a held value or that equals one, withheld; an object two of
|
|
5
|
+
* whose names come out the same once cut, withheld whole, never one value dropped over the other. What is still
|
|
6
|
+
* streaming (the tool's output, the partial answer) by redactedLive: a tail as long as a held value's widest form is held
|
|
7
|
+
* back, so a secret half streamed at a tick shows none of itself; the settled record replaces it whole once it ends. */
|
|
8
|
+
function cutHeld(state, values) {
|
|
9
|
+
if (values.length === 0)
|
|
10
|
+
return state;
|
|
11
|
+
const tools = state.tools.map((tool) => ({
|
|
12
|
+
callId: redactedAnswer(tool.callId, values),
|
|
13
|
+
name: redactedAnswer(tool.name, values),
|
|
14
|
+
...(tool.args !== undefined ? { args: redactedOutput(tool.args, values) } : {}),
|
|
15
|
+
...(tool.output !== undefined ? { output: redactedLive(tool.output, values) } : {}),
|
|
16
|
+
}));
|
|
17
|
+
return { tools, ...(state.partial ? { partial: { text: redactedLive(state.partial.text, values) } } : {}) };
|
|
18
|
+
}
|
|
19
|
+
/** Wraps `createLoop` so its loops' held states reach run_live, batched per tick, cut by each loop's redactor. */
|
|
2
20
|
export function withLiveTicker(store, createLoop, options = {}) {
|
|
3
21
|
const tickMs = options.tickMs ?? 250;
|
|
4
22
|
/** The newest held-state reader of each run since the last tick, with the claim it was reported under. */
|
|
23
|
+
// Each with its loop's redactor's values (LoopDeps.redact, the runner's one), read at each tick: a claim can hold more.
|
|
5
24
|
const changed = new Map();
|
|
6
25
|
/** The ticker's writes, one after another: a run's drop never lands before a put already on its way. */
|
|
7
26
|
let writing = Promise.resolve();
|
|
@@ -22,7 +41,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
|
|
|
22
41
|
writing = writing.then(async () => {
|
|
23
42
|
if (stopped)
|
|
24
43
|
return;
|
|
25
|
-
const rows = [...changed.values()].map(({ claim, read }) => ({ claim, state: stateOf(read) }));
|
|
44
|
+
const rows = [...changed.values()].map(({ claim, read, values }) => ({ claim, state: cutHeld(stateOf(read), values()) }));
|
|
26
45
|
changed.clear();
|
|
27
46
|
if (rows.length > 0)
|
|
28
47
|
await store.live.put(rows).catch(() => undefined);
|
|
@@ -43,12 +62,17 @@ export function withLiveTicker(store, createLoop, options = {}) {
|
|
|
43
62
|
changed.delete(claim.runId);
|
|
44
63
|
};
|
|
45
64
|
deps.signal.addEventListener("abort", onAbort, { once: true });
|
|
65
|
+
// The run's one redactor: a running tool's args and output and a partial answer can quote a secret the runner holds
|
|
66
|
+
// (a key its claim opened), and the live view is read by people and consoles. A loop given none (never one the runner
|
|
67
|
+
// makes) has no live view: its held state is never written uncut. Nor has a loop whose redactor does not know its
|
|
68
|
+
// values (a bare function): a value still streaming, a number or an object's names cannot be cut by text alone.
|
|
69
|
+
const values = deps.redact?.heldValues;
|
|
46
70
|
const loop = createLoop({
|
|
47
71
|
...deps,
|
|
48
72
|
live: (read) => {
|
|
49
|
-
if (!claim || closed || deps.signal.aborted)
|
|
73
|
+
if (!claim || closed || deps.signal.aborted || values === undefined)
|
|
50
74
|
return;
|
|
51
|
-
changed.set(claim.runId, { claim, read });
|
|
75
|
+
changed.set(claim.runId, { claim, read, values });
|
|
52
76
|
},
|
|
53
77
|
});
|
|
54
78
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AlsoRow, Claim, Command, Journal } from "../store/store.js";
|
|
2
|
+
import type { Redact } from "./redact.js";
|
|
2
3
|
export type { AlsoRow, Claim, Command, Journal };
|
|
3
4
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
4
5
|
* answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
|
|
@@ -134,8 +135,8 @@ export interface LoopDeps {
|
|
|
134
135
|
* journal. Absent: not reported. */
|
|
135
136
|
live?: (read: () => HeldState | undefined) => void;
|
|
136
137
|
/** The runner's one redactor (redact.ts): an error's text the loop writes to its run's end goes through it, so no
|
|
137
|
-
* secret the runner holds is stored. Absent: none cut. */
|
|
138
|
-
redact?:
|
|
138
|
+
* secret the runner holds is stored, and its values cut the run's live view (live-ticker.ts). Absent: none cut. */
|
|
139
|
+
redact?: Redact;
|
|
139
140
|
}
|
|
140
141
|
/** A run's held state: what pi shows before it stores it. The live view (live/stream.ts) streams it beside the stored
|
|
141
142
|
* commits' events, in the door's vocabulary (a running tool's tool_execution_start, a partial's message_update). */
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { type Store } from "../store/index.js";
|
|
2
|
+
import { type ComputerDeps } from "../workspace/computer-deps.js";
|
|
2
3
|
import type { LoopFactory } from "./loop-contract.js";
|
|
3
|
-
import { type Runner, type RunnerEvent } from "./runner.js";
|
|
4
|
+
import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
|
|
4
5
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
5
6
|
export interface RunnerProcessOptions {
|
|
6
7
|
/** The data directory (--data): the store is the store module's file in it; the runner never names it. */
|
|
7
8
|
dataDir: string;
|
|
8
9
|
/** Most runs held at once (--loops). */
|
|
9
10
|
loops?: number;
|
|
11
|
+
/** How long close() lets each busy run finish its turn (--drain-timeout; RunnerOptions.drainMs). Default 0. */
|
|
12
|
+
drainMs?: number;
|
|
13
|
+
/** Its memory budget and its runs' weights (RunnerOptions.memory). Default: this host's memory, each run weighed by its
|
|
14
|
+
* harness (memory-claim.ts runnerMemory). */
|
|
15
|
+
memory?: RunnerMemory;
|
|
10
16
|
/** This runner's name in the runs it claims, its lines and its heartbeat. Default runner.ts runnerName(). */
|
|
11
17
|
name?: string;
|
|
12
|
-
/** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop). */
|
|
13
|
-
createLoop?: LoopFactory | ((store: Store) => LoopFactory);
|
|
18
|
+
/** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed. */
|
|
19
|
+
createLoop?: LoopFactory | ((store: Store, sealKey: Buffer) => LoopFactory | RunnerParts);
|
|
20
|
+
/** Run the computer janitor (workspace/computer-janitor.ts) over the computers createLoop composed: at the start, then
|
|
21
|
+
* on its interval. Only the runner subcommand asks for it; a test that does not ask runs none. */
|
|
22
|
+
janitor?: boolean;
|
|
14
23
|
onEvent?: (event: RunnerEvent) => void;
|
|
15
24
|
/** For tests: the clock the heartbeat is written by. Default Date.now. */
|
|
16
25
|
now?: () => number;
|
|
@@ -49,10 +58,23 @@ export declare function openRunnerStore(dataDir: string, env: NodeJS.ProcessEnv,
|
|
|
49
58
|
* but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
|
|
50
59
|
* a spread of the object or a spawn given it carries none. */
|
|
51
60
|
export declare function runEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
61
|
+
/** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
|
|
62
|
+
* process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
|
|
63
|
+
* run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
|
|
64
|
+
* enabled (server.ts fauxEnvOf). Deleted from runEnv's result, never spread: its secrets are non-enumerable and a spread
|
|
65
|
+
* drops them. */
|
|
66
|
+
export declare function besideRunEnv(env: NodeJS.ProcessEnv, switches: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
52
67
|
/** The runner's loop for every run: the dispatch over the store (createDispatchLoop), each run's harness loop picked by
|
|
53
68
|
* its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
|
|
54
|
-
* journal, the seal key and the model route.
|
|
55
|
-
|
|
69
|
+
* journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
|
|
70
|
+
* this process's, as it was handed or booted). Refused in words with no seal key. */
|
|
71
|
+
export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): RunnerParts;
|
|
72
|
+
/** A runner's loop factory with the run's computers it composed and the runs' environment: what the janitor sweeps with. */
|
|
73
|
+
export type RunnerParts = {
|
|
74
|
+
readonly createLoop: LoopFactory;
|
|
75
|
+
readonly computers: ComputerDeps;
|
|
76
|
+
readonly env: NodeJS.ProcessEnv;
|
|
77
|
+
};
|
|
56
78
|
/** Where runner `name` writes its heartbeat in `dataDir`. */
|
|
57
79
|
export declare const heartbeatFile: (dataDir: string, name: string) => string;
|
|
58
80
|
/** Whether runner `name`'s heartbeat in `dataDir` is fresh: younger than twice the renew interval. */
|
|
@@ -69,13 +91,33 @@ export declare function checkRunner(options: {
|
|
|
69
91
|
/** Opens the store as a runner and starts claiming runs. */
|
|
70
92
|
export declare function startRunnerProcess(options: RunnerProcessOptions): Promise<RunnerProcess>;
|
|
71
93
|
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
|
|
72
|
-
export declare function ofStore(make: (store: Store) =>
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
94
|
+
export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer) => Made): (store: Store, sealKey: Buffer) => Made;
|
|
95
|
+
/** How long a runner process lets each busy run finish its turn on SIGTERM, unless --drain-timeout or
|
|
96
|
+
* AGENTRUN_DRAIN_TIMEOUT says: the image's server drain (its CMD's --drain-timeout 6s), so a runner beside a --no-runner
|
|
97
|
+
* server drains as the server's own runner would.
|
|
98
|
+
* BOUND: this drain plus the stuck-loop stop after it (runner.ts runnerCloseBoundMs: the claim's lease less its margin,
|
|
99
|
+
* 30 s - 5 s = 25 s) is 6 + 25 = 31 s, inside deploy/compose.yaml's 35 s stop_grace_period for its runners
|
|
100
|
+
* (runner-beside-flags.test.mjs pins it). Raise this default only with that grace. */
|
|
101
|
+
export declare const RUNNER_DRAIN_TIMEOUT = "6s";
|
|
102
|
+
/** The environment's drain for a runner process when --drain-timeout gives none. */
|
|
103
|
+
export declare const RUNNER_DRAIN_ENV = "AGENTRUN_DRAIN_TIMEOUT";
|
|
104
|
+
/** What a runner process holds, from its arguments and `env`: --loops, else the server's --max-runs default
|
|
105
|
+
* (AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds; maxRunsOf); --drain-timeout, else
|
|
106
|
+
* AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT. A bad AGENTRUN_MAX_RUNS or AGENTRUN_DRAIN_TIMEOUT is RunnerRefused. */
|
|
107
|
+
export declare function runnerHolds(args: {
|
|
108
|
+
loops?: number;
|
|
109
|
+
drainMs?: number;
|
|
110
|
+
}, env: NodeJS.ProcessEnv): {
|
|
111
|
+
loops: number;
|
|
112
|
+
drainMs: number;
|
|
113
|
+
};
|
|
114
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N]`, or `--check --data D [--name
|
|
115
|
+
* N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts with "-"
|
|
116
|
+
* so, never read as an option); an empty one is refused like a missing one. */
|
|
76
117
|
export declare function runnerArgs(argv: readonly string[]): {
|
|
77
118
|
dataDir: string;
|
|
78
119
|
loops?: number;
|
|
120
|
+
drainMs?: number;
|
|
79
121
|
name?: string;
|
|
80
122
|
check?: true;
|
|
81
123
|
};
|
|
@@ -83,7 +125,19 @@ export declare function runnerArgs(argv: readonly string[]): {
|
|
|
83
125
|
* says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
|
|
84
126
|
* that came before the handlers would end the process unclosed. */
|
|
85
127
|
export declare function runUntilSignalled(process: RunnerProcess, signals?: readonly NodeJS.Signals[], ready?: () => void): Promise<void>;
|
|
128
|
+
/** The runner process's last resort (runnerMain installs it for unhandledRejection and uncaughtException): says what
|
|
129
|
+
* went wrong, in the runner's name with its stack, then exits 1 at once, closing nothing. A runner that went on after
|
|
130
|
+
* an error nothing handled could keep renewing the claim of a run whose loop is dead, and that run would hang claimed
|
|
131
|
+
* by a live runner. Exiting lets the claim lapse: another runner (or this one, started again) takes the run back at the
|
|
132
|
+
* next epoch, and the fence refuses the dead loop's late writes. The line is written to stderr synchronously
|
|
133
|
+
* (writeSync), so a pipe's slow reader still gets the whole stack before the exit. Exported for its test. */
|
|
134
|
+
export declare function lastResort(name: string, write?: (line: string) => void, exit?: (code: number) => void): (reason: unknown) => void;
|
|
86
135
|
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
|
|
87
136
|
* set up yet); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names
|
|
88
137
|
* it when --name does not. */
|
|
89
|
-
export declare function runnerMain(argv: readonly string[], env?: NodeJS.ProcessEnv): Promise<number>;
|
|
138
|
+
export declare function runnerMain(argv: readonly string[], env?: NodeJS.ProcessEnv, hooks?: RunnerMainHooks): Promise<number>;
|
|
139
|
+
/** A test's hooks into runnerMain: `started`, awaited once the runner has started claiming and before its stop handlers
|
|
140
|
+
* take over from the ones its start listened on (the window a stop must not fall through). */
|
|
141
|
+
export type RunnerMainHooks = {
|
|
142
|
+
readonly started?: (process: RunnerProcess) => void | Promise<void>;
|
|
143
|
+
};
|