@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37
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 +298 -0
- package/README.md +417 -219
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +12 -57
- package/dist/cap.js +20 -160
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +17 -26
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +24 -2
- package/dist/computer-view.js +51 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +79 -12
- package/dist/computers.js +147 -28
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +56 -24
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +3 -1
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +36 -2
- package/dist/host-tools.d.ts +9 -10
- package/dist/host-tools.js +7 -7
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +11 -2
- package/dist/learn/check.js +124 -6
- package/dist/learn/commit.d.ts +43 -7
- package/dist/learn/commit.js +166 -22
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +37 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +22 -1
- package/dist/learn/grade.js +107 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +14 -2
- package/dist/learn/reflect.js +54 -30
- package/dist/learn/skills.d.ts +37 -5
- package/dist/learn/skills.js +60 -7
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +43 -9
- package/dist/learned-workflow.js +128 -37
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +32 -4
- package/dist/learning-routes.js +48 -12
- package/dist/learning-words.d.ts +9 -0
- package/dist/learning-words.js +12 -2
- package/dist/learning.d.ts +39 -19
- package/dist/learning.js +88 -46
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +27 -3
- package/dist/mcp-probe.js +106 -29
- package/dist/mcp-secret-writes.js +8 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +120 -23
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.d.ts +5 -5
- package/dist/model.js +29 -16
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +586 -64
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +96 -0
- package/dist/place-offers.js +202 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +21 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +16 -9
- package/dist/print.js +15 -17
- package/dist/propose.d.ts +4 -0
- package/dist/propose.js +34 -11
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-launch.d.ts +28 -3
- package/dist/run-launch.js +14 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +8 -5
- package/dist/run-view.js +18 -10
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +39 -8
- package/dist/runner/adapter-loop.js +770 -83
- package/dist/runner/adapter-run-spec.d.ts +36 -7
- package/dist/runner/adapter-run-spec.js +171 -37
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +20 -7
- package/dist/runner/adapters/pi.js +111 -26
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +26 -12
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +27 -3
- package/dist/runner/cli-run-spec.js +198 -74
- package/dist/runner/commands.d.ts +8 -2
- package/dist/runner/commands.js +31 -6
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +87 -18
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +6 -4
- package/dist/runner/harness-loops.js +16 -2
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +35 -6
- package/dist/runner/journal-kinds.js +20 -1
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +37 -1
- package/dist/runner/learning-end.js +115 -14
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +15 -5
- package/dist/runner/learning-loop.d.ts +139 -7
- package/dist/runner/learning-loop.js +369 -32
- package/dist/runner/learning-seed.d.ts +9 -0
- package/dist/runner/learning-seed.js +14 -1
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +16 -1
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +10 -2
- package/dist/runner/loop.js +22 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +38 -6
- package/dist/runner/mcp-claim.d.ts +11 -4
- package/dist/runner/mcp-claim.js +140 -23
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +1 -8
- package/dist/runner/mcp-run.d.ts +6 -4
- package/dist/runner/mcp-run.js +16 -3
- package/dist/runner/metrics.d.ts +15 -2
- package/dist/runner/metrics.js +21 -2
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +60 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +19 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +231 -27
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +7 -2
- package/dist/runner/store-secrets.js +21 -4
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +190 -0
- package/dist/runner/workflow-host.d.ts +24 -3
- package/dist/runner/workflow-host.js +24 -4
- package/dist/runner/workflow-loop.d.ts +6 -3
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +39 -15
- package/dist/runner/workflow-spec.js +143 -40
- package/dist/runs-over-store.d.ts +16 -6
- package/dist/runs-over-store.js +145 -29
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +75 -63
- package/dist/server.js +712 -316
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/deadline.js +9 -5
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +4 -4
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +15 -6
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +85 -13
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +25 -7
- package/dist/store/sqlite/run-patch.js +58 -14
- package/dist/store/sqlite/store.js +331 -59
- package/dist/store/store.d.ts +330 -21
- package/dist/store/store.js +34 -2
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +2 -4
- package/dist/store-reads/cap.js +16 -7
- package/dist/store-reads/decisions.d.ts +3 -3
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +118 -27
- package/dist/store-reads/learning.d.ts +34 -4
- package/dist/store-reads/learning.js +137 -23
- package/dist/store-reads/runs.d.ts +7 -5
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +70 -29
- package/dist/template-eval.js +8 -5
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +30 -1
- package/dist/timeline/timeline.js +29 -13
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +27 -7
- package/dist/tool-budget.js +21 -9
- package/dist/tool-gate.d.ts +23 -10
- package/dist/tool-gate.js +60 -44
- package/dist/tool-plane.d.ts +46 -28
- package/dist/tool-plane.js +73 -31
- package/dist/tools.d.ts +31 -38
- package/dist/tools.js +117 -74
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +26 -6
- package/dist/trigger-signatures.js +44 -8
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +10 -6
- package/dist/triggers.js +37 -7
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/turns.js +16 -1
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +41 -4
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +147 -103
- package/dist/webhooks.js +564 -324
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +113 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +89 -0
- package/dist/workflow/node.js +101 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +32 -0
- package/dist/workflow/pi-versions.js +65 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +77 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +412 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow-run.d.ts +2 -2
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +32 -17
- package/dist/workspace/computer-deps.js +37 -14
- package/dist/workspace/computer-for-claim.d.ts +58 -13
- package/dist/workspace/computer-for-claim.js +267 -26
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +5 -1
- package/dist/workspace/computer-ledger.js +11 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +7 -4
- package/dist/workspace/index.js +4 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +45 -11
- package/dist/workspace/resolve-computer.js +72 -14
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +35 -18
- package/dist/workspace/run-tools.js +24 -29
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +19 -21
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/templates/market-monitor/agent.md +1 -1
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// Learn from a CSV: a learning batch (POST /agents/{id}/learning/batches). A person gives rows, which columns are the input
|
|
2
|
+
// and which the answer, and a cap; the server runs the agent on each row in order with learning on, and after each run tells
|
|
3
|
+
// it the reference answer next to its own, the hindsight review the learning bench sends (learn-bench's follow-up: a message
|
|
4
|
+
// to the finished run, which looks back again). The batch's progress is the store's, never the browser's: a header per batch
|
|
5
|
+
// and one key per row in the server's settings (no table). The batch and each row are one machine (BATCH_MOVES, ROW_MOVES):
|
|
6
|
+
// every move is one write, in an order where a stop between any two writes leaves a state the next start takes up, and every
|
|
7
|
+
// side effect (a run's start, its review) is keyed so a move taken again finds it done. One row at a time, since what a row
|
|
8
|
+
// teaches is what the next one is given.
|
|
9
|
+
// Nothing here knows a job: the input is the chosen columns as {column: value}, the match is structural equality (a display,
|
|
10
|
+
// not a judge: the learning grade is the judge), and the words of the review are generic.
|
|
11
|
+
import { randomBytes } from "node:crypto";
|
|
12
|
+
import { ApiError, invalid } from "./errors.js";
|
|
13
|
+
import { EFFORTS } from "./model.js";
|
|
14
|
+
import { isObject, unknownFields } from "./validate.js";
|
|
15
|
+
/** The most rows a batch holds, and the longest a cell, in characters (the whole body is under the server's body limit). */
|
|
16
|
+
export const BATCH_ROWS_MAX = 500;
|
|
17
|
+
export const BATCH_CELL_MAX = 8_000;
|
|
18
|
+
const COLUMNS_MAX = 40;
|
|
19
|
+
/** The row machine. pending -> started: its run started under the row's key (a start the server stopped before this write
|
|
20
|
+
* is found again by the key); started -> answered: the run's first end, its answer, right or wrong and the review's words
|
|
21
|
+
* written once; answered -> reviewed: the review sent (a resume finds it in the run's commands and sends none); reviewed ->
|
|
22
|
+
* done: the review's turn completed and its learning settled. Every other ending is failed, and a live row (started,
|
|
23
|
+
* answered, reviewed) moves to failed only once its run has stopped (cancelled, waited for with its grade, then booked). */
|
|
24
|
+
export const ROW_MOVES = { pending: ["started", "failed"], started: ["answered", "failed"], answered: ["reviewed", "failed"], reviewed: ["done", "failed"], done: [], failed: [] };
|
|
25
|
+
const LIVE = new Set(["started", "answered", "reviewed"]);
|
|
26
|
+
export const stageOf = (row) => (row.state !== "running" ? row.state : row.reviewed ? "reviewed" : row.right !== undefined ? "answered" : "started");
|
|
27
|
+
/** The batch machine, in its header: made (the agent's index, then the rows, then the header, so a header is never saved
|
|
28
|
+
* where a read can't find it) -> running -> ending (one write: `ending`) -> completed, cancelled or stopped (one write, once
|
|
29
|
+
* no row is live). A start takes up every header still running: a running one at its first unfinished row, an ending one
|
|
30
|
+
* where its ending stands. */
|
|
31
|
+
export const BATCH_MOVES = { running: ["ending"], ending: ["completed", "cancelled", "stopped"], completed: [], cancelled: [], stopped: [] };
|
|
32
|
+
/** A run's figures from its cost (costRunOf) and the end of each round its learning kept, in order (the job's, then each
|
|
33
|
+
* follow-up's, a review's): what every round learned, each name once; the last merge's commit; and each round that merged
|
|
34
|
+
* workflows as a revision of its own, with its own commit (a round dropped is none, and moves no other round's commit). */
|
|
35
|
+
export function figuresOf(cost, ends) {
|
|
36
|
+
const names = (pick) => [...new Set(ends.flatMap((e) => (e ? (pick(e) ?? []).map((x) => x.name) : [])))];
|
|
37
|
+
const revisions = ends.flatMap((e) => (e?.workflows?.length ? [{ commit: e.merged ?? null, workflows: [...new Set(e.workflows.map((w) => w.name))] }] : []));
|
|
38
|
+
const merged = [...ends].reverse().find((e) => e?.merged)?.merged ?? null;
|
|
39
|
+
return { path: cost.path, cost_usd: cost.cost_usd, learning_usd: cost.learning_usd, total_usd: cost.total_usd, merged, revisions, learned: { notes: names((e) => e.learned), skills: names((e) => e.skills), workflows: names((e) => e.workflows) } };
|
|
40
|
+
}
|
|
41
|
+
const ANSWER_SHOWN = 2_000;
|
|
42
|
+
/** The least cap a run can take a step under (cap.ts: the next step needs at least a cent). */
|
|
43
|
+
export const RUN_CAP_MIN_USD = 0.01;
|
|
44
|
+
const HEAD = (id) => `learning_batch/${id}`;
|
|
45
|
+
const ROW = (id, n) => `learning_batch/${id}/row/${n}`;
|
|
46
|
+
const INDEX = (agentId) => `learning_batches/${agentId}`;
|
|
47
|
+
/** The run origin a row's run starts under: one run a row, whatever stops between its start and its row's write. */
|
|
48
|
+
export const ROW_KEY = (id, n) => `learning_batch:${id}:row:${n}`;
|
|
49
|
+
export const BATCH_ID = /^lb_[0-9a-f]{16}$/;
|
|
50
|
+
const text = (value) => (value ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
51
|
+
/** A decimal number's text in one form (no sign on zero, no leading or trailing zeros), never through a float: two numbers
|
|
52
|
+
* are the same when every digit is. Null for text that is no decimal number. */
|
|
53
|
+
const num = (value) => {
|
|
54
|
+
const m = /^([+-]?)(\d+)(?:\.(\d+))?$/.exec(value);
|
|
55
|
+
if (!m)
|
|
56
|
+
return null;
|
|
57
|
+
const whole = m[2].replace(/^0+(?=\d)/, ""), part = (m[3] ?? "").replace(/0+$/, "");
|
|
58
|
+
const sign = m[1] === "-" && !(whole === "0" && part === "") ? "-" : "";
|
|
59
|
+
return `${sign}${whole}${part ? `.${part}` : ""}`;
|
|
60
|
+
};
|
|
61
|
+
/** The answer's field at a dotted path, from the answer text when it is JSON (or holds a fenced json block); the answer as it
|
|
62
|
+
* is when no field is named. A value that is not a scalar, or a path that is not there, is no answer (null). */
|
|
63
|
+
export function answerValue(answer, field) {
|
|
64
|
+
if (answer === null)
|
|
65
|
+
return null;
|
|
66
|
+
if (field === null)
|
|
67
|
+
return answer;
|
|
68
|
+
for (const candidate of [answer, /```(?:json)?\s*\n([\s\S]*?)\n```/.exec(answer)?.[1]]) {
|
|
69
|
+
try {
|
|
70
|
+
let at = JSON.parse(candidate ?? "");
|
|
71
|
+
for (const key of field.split("."))
|
|
72
|
+
at = at !== null && typeof at === "object" ? at[key] : undefined;
|
|
73
|
+
if (typeof at === "string" || typeof at === "number" || typeof at === "boolean")
|
|
74
|
+
return String(at);
|
|
75
|
+
}
|
|
76
|
+
catch { }
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/** Whether an answer is the reference: equal once trimmed, case-folded and whitespace-collapsed, two numbers by value (by
|
|
81
|
+
* every digit: num). */
|
|
82
|
+
export function matches(answer, reference) {
|
|
83
|
+
if (answer === null)
|
|
84
|
+
return false;
|
|
85
|
+
const a = num(answer.trim()), r = num(reference.trim());
|
|
86
|
+
return a !== null && r !== null ? a === r : text(answer) === text(reference);
|
|
87
|
+
}
|
|
88
|
+
/** What a run is given for a row: its one input column's text as it is, or each chosen column on a line, `column: value`, in
|
|
89
|
+
* the order the batch names them (an agent's input is its `content`, a person's words). */
|
|
90
|
+
export const contentOf = (inputs, row) => (inputs.length === 1 ? row[inputs[0]] : inputs.map((column) => `${column}: ${row[column]}`).join("\n"));
|
|
91
|
+
/** The review a run is sent, from its whole answer: the same words right or wrong. An answer past ANSWER_SHOWN characters is
|
|
92
|
+
* quoted to there, and the review says it was cut and where the whole one is (never a prefix passed off as the answer). */
|
|
93
|
+
export const reviewText = (reference, answer) => answer !== null && answer.length > ANSWER_SHOWN
|
|
94
|
+
? `Review: the reference answer is "${reference}"; you answered "${answer.slice(0, ANSWER_SHOWN)}…" (cut here: your answer runs to ${answer.length} characters, and the whole of it is your last answer in this run).`
|
|
95
|
+
: `Review: the reference answer is "${reference}"; you answered "${answer ?? "nothing"}".`;
|
|
96
|
+
/** A create's body, checked: its issues, or the parsed batch. */
|
|
97
|
+
export function checkBatchBody(body) {
|
|
98
|
+
const issues = unknownFields(body, ["inputs", "answer", "rows", "max_cost_usd", "answer_field", "effort"]);
|
|
99
|
+
const columns = (key) => {
|
|
100
|
+
const v = body[key];
|
|
101
|
+
if (!Array.isArray(v) || !v.length || v.length > COLUMNS_MAX || !v.every((c) => typeof c === "string" && c.length > 0 && c.length <= 200) || new Set(v).size !== v.length) {
|
|
102
|
+
issues.push({ field: key, reason: v === undefined ? "missing" : "wrong_type", message: `${key} is the columns the agent is given: 1 to ${COLUMNS_MAX} distinct column names` });
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return v;
|
|
106
|
+
};
|
|
107
|
+
const inputs = columns("inputs");
|
|
108
|
+
const answer = body.answer;
|
|
109
|
+
if (typeof answer !== "string" || !answer || answer.length > 200)
|
|
110
|
+
issues.push({ field: "answer", reason: answer === undefined ? "missing" : "wrong_type", message: "answer is the column that holds the reference answer" });
|
|
111
|
+
else if (inputs?.includes(answer))
|
|
112
|
+
issues.push({ field: "answer", reason: "not_allowed", message: "the answer column is no input column: the agent is never given the answer", fix: `Remove ${answer} from inputs.` });
|
|
113
|
+
const field = body.answer_field;
|
|
114
|
+
if (field !== undefined && (typeof field !== "string" || !/^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/.test(field)))
|
|
115
|
+
issues.push({ field: "answer_field", reason: "wrong_type", message: "answer_field is a dotted path into a JSON answer, such as result.code" });
|
|
116
|
+
const cap = body.max_cost_usd;
|
|
117
|
+
if (!(typeof cap === "number" && Number.isFinite(cap) && cap > 0))
|
|
118
|
+
issues.push({ field: "max_cost_usd", reason: cap === undefined ? "missing" : "wrong_type", message: "max_cost_usd caps what the batch's runs spend (their jobs, look-backs and review turns), a number above 0" });
|
|
119
|
+
// A run's effort as POST /agents/{id}/runs checks it (server.ts runBodyIssues), in its words: a typo is refused here, never
|
|
120
|
+
// a batch whose every row fails.
|
|
121
|
+
if (body.effort !== undefined && !EFFORTS.includes(body.effort))
|
|
122
|
+
issues.push({ field: "effort", reason: "not_an_option", message: `effort is one of ${EFFORTS.join(", ")}` });
|
|
123
|
+
const rows = body.rows;
|
|
124
|
+
const parsed = [];
|
|
125
|
+
if (!Array.isArray(rows) || !rows.length)
|
|
126
|
+
issues.push({ field: "rows", reason: rows === undefined ? "missing" : "wrong_type", message: "rows is a list of rows, each {column: text}" });
|
|
127
|
+
else if (rows.length > BATCH_ROWS_MAX)
|
|
128
|
+
issues.push({ field: "rows", reason: "too_long", message: `a batch holds at most ${BATCH_ROWS_MAX} rows` });
|
|
129
|
+
else if (inputs && typeof answer === "string") {
|
|
130
|
+
rows.forEach((row, i) => {
|
|
131
|
+
const cell = (key) => (isObject(row) && typeof row[key] === "string" && row[key].length <= BATCH_CELL_MAX ? row[key] : null);
|
|
132
|
+
const cells = [];
|
|
133
|
+
for (const key of inputs) {
|
|
134
|
+
const v = cell(key);
|
|
135
|
+
if (v === null)
|
|
136
|
+
return void issues.push({ field: `rows[${i}].${key}`, reason: "wrong_type", message: `row ${i + 1} has no text at ${key} (at most ${BATCH_CELL_MAX} characters)` });
|
|
137
|
+
cells.push([key, v]);
|
|
138
|
+
}
|
|
139
|
+
// Own keys only (a column may be named __proto__: an assignment on {} would drop its text).
|
|
140
|
+
const input = Object.fromEntries(cells);
|
|
141
|
+
const reference = cell(answer);
|
|
142
|
+
if (reference === null || !reference.trim())
|
|
143
|
+
return void issues.push({ field: `rows[${i}].${answer}`, reason: "missing", message: `row ${i + 1} has no reference answer at ${answer}` });
|
|
144
|
+
parsed.push({ input, reference });
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (issues.length || !inputs || typeof answer !== "string")
|
|
148
|
+
return issues;
|
|
149
|
+
return { inputs, answer, answer_field: typeof field === "string" ? field : null, effort: typeof body.effort === "string" ? body.effort : null, max_cost_usd: cap, rows: parsed };
|
|
150
|
+
}
|
|
151
|
+
const usd = (v) => Math.round(v * 1e6) / 1e6;
|
|
152
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
153
|
+
const TERMINAL = new Set(["completed", "failed", "cancelled"]);
|
|
154
|
+
/** A run and its learning have stopped: ended, and its learning over (merged, dropped, none), or never begun on a run that
|
|
155
|
+
* did not complete (one stopped before its end-of-run turn keeps `seeded`: nothing more runs for it). */
|
|
156
|
+
const settled = (s) => TERMINAL.has(s.status) && s.ended_at !== null && (s.learning_state === null || s.learning_state === "merged" || s.learning_state === "dropped" || (s.status !== "completed" && s.learning_state === "seeded"));
|
|
157
|
+
/** How many times in a row a batch's loop may fail on the store (or a run's stop) and be taken up again from what the store
|
|
158
|
+
* holds, before the batch ends stopped on the error's words. */
|
|
159
|
+
const LOOP_TRIES = 5;
|
|
160
|
+
const words = (error) => String(error?.message ?? error).slice(0, 400);
|
|
161
|
+
/** A row as a read shows it: no input (its run holds it), no review words, no revisions (the header's), and every text
|
|
162
|
+
* that can hold a value through `cut` (a lesson's name as the learning routes show one: notesView). */
|
|
163
|
+
const shownLessons = (l, cut) => ({ notes: l.notes.map(cut.text), skills: l.skills.map(cut.name), workflows: l.workflows.map(cut.name) });
|
|
164
|
+
function shownRow({ input: _input, review: _review, revisions: _revisions, ...r }, cut) {
|
|
165
|
+
return {
|
|
166
|
+
...r,
|
|
167
|
+
reference: cut.text(r.reference),
|
|
168
|
+
...(typeof r.answer === "string" ? { answer: cut.text(r.answer) } : {}),
|
|
169
|
+
...(r.learned ? { learned: shownLessons(r.learned, cut) } : {}),
|
|
170
|
+
...(r.error === undefined ? {} : { error: cut.text(r.error) }),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const batchStage = (h) => (h.status !== "running" ? h.status : h.ending ? "ending" : "running");
|
|
174
|
+
/** The batches of one server: its running loops, and the store reads and writes. */
|
|
175
|
+
export class LearningBatches {
|
|
176
|
+
host;
|
|
177
|
+
loops = new Map();
|
|
178
|
+
index = Promise.resolve();
|
|
179
|
+
halting = false;
|
|
180
|
+
constructor(host) {
|
|
181
|
+
this.host = host;
|
|
182
|
+
}
|
|
183
|
+
get settings() { return this.host.settings; }
|
|
184
|
+
get clock() { return this.host.now ?? Date.now; }
|
|
185
|
+
get pollMs() { return this.host.pollMs ?? 1_000; }
|
|
186
|
+
async header(id) { return (await this.settings.get(HEAD(id))); }
|
|
187
|
+
async row(id, n) { return (await this.settings.get(ROW(id, n))); }
|
|
188
|
+
async save(h) { await this.settings.put(HEAD(h.id), h); }
|
|
189
|
+
async saveRow(id, row) { await this.settings.put(ROW(id, row.n), row); }
|
|
190
|
+
ids = async (agentId) => (await this.settings.get(INDEX(agentId))) ?? [];
|
|
191
|
+
/** Makes a batch of agent `agentId` and starts its loop. 409 when the agent does not learn or has a batch running. */
|
|
192
|
+
async create(agentId, body) {
|
|
193
|
+
const checked = checkBatchBody(body);
|
|
194
|
+
if (Array.isArray(checked))
|
|
195
|
+
throw invalid(checked);
|
|
196
|
+
const learns = await this.host.learning(agentId);
|
|
197
|
+
if (!learns.learns)
|
|
198
|
+
throw new ApiError("agent_not_runnable", `The agent ${agentId} does not learn here: ${learns.why}`, { details: { learning: false } });
|
|
199
|
+
// A batch whose progress would be withheld is never started.
|
|
200
|
+
await this.host.shown(agentId);
|
|
201
|
+
let made;
|
|
202
|
+
// The index and the running check are one step, so two creates never both start (one process: a queue, not a lock).
|
|
203
|
+
const step = this.index.then(async () => {
|
|
204
|
+
const ids = await this.ids(agentId);
|
|
205
|
+
for (const other of ids.slice(-5))
|
|
206
|
+
if ((await this.header(other))?.status === "running")
|
|
207
|
+
throw new ApiError("agent_not_runnable", `The agent ${agentId} has a learning batch running (${other}): learning is ordered, so one batch runs at a time. Cancel it, or wait for it.`, { details: { batch_id: other } });
|
|
208
|
+
const id = `lb_${randomBytes(8).toString("hex")}`;
|
|
209
|
+
const now = new Date(this.clock()).toISOString();
|
|
210
|
+
made = { id, agent_id: agentId, created_at: now, ended_at: null, status: "running", stopped: null, inputs: checked.inputs, answer: checked.answer, answer_field: checked.answer_field, effort: checked.effort, max_cost_usd: checked.max_cost_usd, total: checked.rows.length, finished: 0, right: 0, wrong: 0, failed: 0, spent_usd: 0, unknown_cost_rows: 0, paths: { agent: 0, handed_back: 0, workflow: 0 }, lessons: { notes: [], skills: [], workflows: [] }, revisions: [] };
|
|
211
|
+
// The index first, the header last: a batch is made (and runs, and a start takes it up) only once its header is
|
|
212
|
+
// saved, and by then the list and the running check find it. A stop before that leaves an id with no header, which
|
|
213
|
+
// nothing shows, runs or counts.
|
|
214
|
+
await this.settings.put(INDEX(agentId), [...ids, id]);
|
|
215
|
+
for (const [i, r] of checked.rows.entries())
|
|
216
|
+
await this.saveRow(id, { n: i + 1, state: "pending", input: r.input, reference: r.reference });
|
|
217
|
+
await this.save(made);
|
|
218
|
+
});
|
|
219
|
+
this.index = step.catch(() => undefined);
|
|
220
|
+
await step;
|
|
221
|
+
this.arm(made.id);
|
|
222
|
+
return made;
|
|
223
|
+
}
|
|
224
|
+
/** The server started: every batch still running takes up where it stopped (an ending one, where its ending stands). */
|
|
225
|
+
async resume() {
|
|
226
|
+
let n = 0;
|
|
227
|
+
for (const { key, value } of await this.settings.all()) {
|
|
228
|
+
if (!/^learning_batch\/lb_[0-9a-f]{16}$/.test(key))
|
|
229
|
+
continue;
|
|
230
|
+
if (value.status === "running") {
|
|
231
|
+
this.arm(value.id);
|
|
232
|
+
n++;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return n;
|
|
236
|
+
}
|
|
237
|
+
/** A batch whole as progress: its header, what is under way and what it costs now, and its rows (no input: the run holds
|
|
238
|
+
* it), every text through the agent's cut now (host.shown). The cost now is the finished rows' and the live row's figures
|
|
239
|
+
* so far, by the function that books it (figures). */
|
|
240
|
+
async read(agentId, id) {
|
|
241
|
+
const h = await this.need(agentId, id);
|
|
242
|
+
const cut = await this.host.shown(agentId);
|
|
243
|
+
const rows = [];
|
|
244
|
+
for (let n = 1; n <= h.total; n++)
|
|
245
|
+
rows.push(await this.row(id, n));
|
|
246
|
+
const live = rows.find((r) => LIVE.has(stageOf(r)) && r.run_id);
|
|
247
|
+
const inflight = live?.run_id ? ((await this.host.figures(live.run_id).catch(() => undefined))?.total_usd ?? null) : 0;
|
|
248
|
+
return { ...this.shown(h, cut), current: live?.n ?? null, cost_usd: inflight === null || h.unknown_cost_rows ? null : usd(h.spent_usd + inflight), rows: rows.map((r) => shownRow(r, cut)) };
|
|
249
|
+
}
|
|
250
|
+
/** A batch as the header says it, for a list (no rows), its text through `cut`. A finished row whose cost is not known
|
|
251
|
+
* makes the cost, and what is left of the cap, unknown (null): the known part is never shown as the whole. */
|
|
252
|
+
shown(h, cut) {
|
|
253
|
+
const { ending: _ending, error, ...shown } = h;
|
|
254
|
+
const known = h.unknown_cost_rows === 0;
|
|
255
|
+
return {
|
|
256
|
+
...shown,
|
|
257
|
+
inputs: h.inputs.map(cut.name),
|
|
258
|
+
answer: cut.name(h.answer),
|
|
259
|
+
answer_field: h.answer_field === null ? null : cut.name(h.answer_field),
|
|
260
|
+
lessons: shownLessons(h.lessons, cut),
|
|
261
|
+
revisions: h.revisions.map((r) => ({ ...r, workflows: r.workflows.map(cut.name) })),
|
|
262
|
+
...(error === undefined ? {} : { error: cut.text(error) }),
|
|
263
|
+
cost_usd: known ? h.spent_usd : null,
|
|
264
|
+
remaining_usd: known ? usd(Math.max(0, h.max_cost_usd - h.spent_usd)) : null,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
async list(agentId) {
|
|
268
|
+
const cut = await this.host.shown(agentId);
|
|
269
|
+
const out = [];
|
|
270
|
+
for (const id of (await this.ids(agentId)).slice(-20).reverse()) {
|
|
271
|
+
const h = await this.header(id);
|
|
272
|
+
if (h)
|
|
273
|
+
out.push(this.shown(h, cut));
|
|
274
|
+
}
|
|
275
|
+
return { batches: out };
|
|
276
|
+
}
|
|
277
|
+
/** A person's cancel: the batch's loop ends it cancelled, its live row's run stopped and booked first; answers once it has,
|
|
278
|
+
* as a read does. The cancel stands even when its answer is withheld (a 403 from the cut): stopping spend never waits on
|
|
279
|
+
* a sign-in. */
|
|
280
|
+
async cancel(agentId, id) {
|
|
281
|
+
const h = await this.need(agentId, id);
|
|
282
|
+
if (h.status === "running" && !this.halting) {
|
|
283
|
+
const loop = this.arm(id);
|
|
284
|
+
loop.cancelled = true;
|
|
285
|
+
await loop.done;
|
|
286
|
+
}
|
|
287
|
+
return this.read(agentId, id);
|
|
288
|
+
}
|
|
289
|
+
/** The server is stopping: every loop lets go where it stands, its batch still running (resume takes it up). */
|
|
290
|
+
async halt() {
|
|
291
|
+
this.halting = true;
|
|
292
|
+
const all = [...this.loops.values()];
|
|
293
|
+
for (const loop of all)
|
|
294
|
+
loop.halted = true;
|
|
295
|
+
await Promise.all(all.map((loop) => loop.done));
|
|
296
|
+
}
|
|
297
|
+
/** Waits for a batch's loop to end (a test's and a shutdown's). */
|
|
298
|
+
async idle(id) { await this.loops.get(id)?.done; }
|
|
299
|
+
async need(agentId, id) {
|
|
300
|
+
const h = BATCH_ID.test(id) ? await this.header(id) : undefined;
|
|
301
|
+
if (!h || h.agent_id !== agentId)
|
|
302
|
+
throw new ApiError("not_found", `no learning batch ${id} of agent ${agentId}`);
|
|
303
|
+
return h;
|
|
304
|
+
}
|
|
305
|
+
/** The batch's loop in this process, started if it has none. A loop that fails (the store, a run's stop) is taken up again
|
|
306
|
+
* from what the store holds, LOOP_TRIES times, then ends its batch stopped on the error's words: never by letting the
|
|
307
|
+
* batch go with its row's run still going (the batch stays running, and owned, until its ending has stopped that run). */
|
|
308
|
+
arm(id) {
|
|
309
|
+
const had = this.loops.get(id);
|
|
310
|
+
if (had)
|
|
311
|
+
return had;
|
|
312
|
+
const loop = { cancelled: false, halted: this.halting, failed: null, done: Promise.resolve() };
|
|
313
|
+
this.loops.set(id, loop);
|
|
314
|
+
loop.done = (async () => {
|
|
315
|
+
for (let tries = 1;; tries++) {
|
|
316
|
+
try {
|
|
317
|
+
return await this.loop(id, loop);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (loop.halted)
|
|
321
|
+
return;
|
|
322
|
+
if (tries >= LOOP_TRIES)
|
|
323
|
+
loop.failed ??= words(error);
|
|
324
|
+
await sleep(Math.min(30_000, this.pollMs * 2 ** tries));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
})().finally(() => void this.loops.delete(id));
|
|
328
|
+
return loop;
|
|
329
|
+
}
|
|
330
|
+
/** The batch machine from where the store has it: a running batch takes its rows in order until one of them, or the cap,
|
|
331
|
+
* the agent's learning, a cancel or a failure, ends it (`ending`); an ending batch stops its live row and ends. */
|
|
332
|
+
async loop(id, loop) {
|
|
333
|
+
// The header's figures folded from the rows as saved (a server that stopped between a row's write and its header's
|
|
334
|
+
// books it here, once).
|
|
335
|
+
let h = await this.tally((await this.header(id)));
|
|
336
|
+
if (batchStage(h) !== "running" && batchStage(h) !== "ending")
|
|
337
|
+
return;
|
|
338
|
+
if (loop.failed && !h.ending)
|
|
339
|
+
h = await this.ending(h, { status: "stopped", stopped: null, error: loop.failed });
|
|
340
|
+
// A row booked with its cost unknown stops the batch, read from the rows: a stop between that row's write and the
|
|
341
|
+
// batch's ending is no batch that runs on, or completes.
|
|
342
|
+
if (h.unknown_cost_rows && !h.ending)
|
|
343
|
+
h = await this.ending(h, { status: "stopped", stopped: "cost_unknown" });
|
|
344
|
+
for (let n = 1; n <= h.total && !h.ending; n++) {
|
|
345
|
+
if (loop.halted)
|
|
346
|
+
return;
|
|
347
|
+
if (loop.cancelled)
|
|
348
|
+
break;
|
|
349
|
+
let row = await this.row(id, n);
|
|
350
|
+
const stage = stageOf(row);
|
|
351
|
+
if (stage === "done" || stage === "failed")
|
|
352
|
+
continue;
|
|
353
|
+
if (stage === "pending") {
|
|
354
|
+
// A run started under the row's key before its row kept the id is that row's run: never a second.
|
|
355
|
+
const found = await this.host.find(ROW_KEY(id, n));
|
|
356
|
+
if (found)
|
|
357
|
+
row = await this.move(id, row, "started", { run_id: found });
|
|
358
|
+
else {
|
|
359
|
+
const room = this.room(h);
|
|
360
|
+
if (room !== true) {
|
|
361
|
+
h = await this.ending(h, { status: "stopped", stopped: room });
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
// Learning is checked again before every row: an agent (or a server) that stopped learning runs no row unlearned.
|
|
365
|
+
const learns = await this.host.learning(h.agent_id);
|
|
366
|
+
if (!learns.learns) {
|
|
367
|
+
h = await this.ending(h, { status: "stopped", stopped: "learning_off", error: `The agent does not learn here: ${learns.why}` });
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
h = await this.runRow(h, row, loop);
|
|
373
|
+
if (loop.halted)
|
|
374
|
+
return;
|
|
375
|
+
if (h.unknown_cost_rows && !loop.cancelled) {
|
|
376
|
+
h = await this.ending(h, { status: "stopped", stopped: "cost_unknown" });
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (loop.halted)
|
|
381
|
+
return;
|
|
382
|
+
if (!h.ending)
|
|
383
|
+
h = await this.ending(h, loop.cancelled ? { status: "cancelled", stopped: null } : { status: "completed", stopped: null });
|
|
384
|
+
await this.finish(h, loop);
|
|
385
|
+
}
|
|
386
|
+
/** Whether another row may start: the cap's room covers the mean total of the rows done, and a run's own smallest cap (a
|
|
387
|
+
* run capped under a cent cannot take a step: cap.ts), so a row's run is never started to pause at its cap. */
|
|
388
|
+
room(h) {
|
|
389
|
+
if (h.unknown_cost_rows)
|
|
390
|
+
return "cost_unknown";
|
|
391
|
+
const left = usd(h.max_cost_usd - h.spent_usd);
|
|
392
|
+
const done = h.finished - h.unknown_cost_rows;
|
|
393
|
+
const typical = done > 0 ? usd(h.spent_usd / done) : 0;
|
|
394
|
+
return left >= Math.max(typical, RUN_CAP_MIN_USD) ? true : "cap";
|
|
395
|
+
}
|
|
396
|
+
/** running -> ending: how the batch ends, one write, before its live row is stopped. */
|
|
397
|
+
async ending(h, ending) {
|
|
398
|
+
if (batchStage(h) !== "running")
|
|
399
|
+
throw new Error(`batch ${h.id} cannot end from ${batchStage(h)}`);
|
|
400
|
+
const next = { ...h, ending };
|
|
401
|
+
await this.save(next);
|
|
402
|
+
return next;
|
|
403
|
+
}
|
|
404
|
+
/** ending -> completed, cancelled or stopped: every live row's run stopped and booked failed (on the ending's words), then
|
|
405
|
+
* the header's one write. A server stopping meanwhile leaves the batch ending, for the next start to finish. */
|
|
406
|
+
async finish(h, loop) {
|
|
407
|
+
const ending = h.ending;
|
|
408
|
+
const why = ending.error ?? (ending.status === "cancelled" ? "the batch was cancelled" : "the batch stopped before this row ended");
|
|
409
|
+
for (let n = 1; n <= h.total; n++) {
|
|
410
|
+
const row = await this.row(h.id, n);
|
|
411
|
+
if (!LIVE.has(stageOf(row)))
|
|
412
|
+
continue;
|
|
413
|
+
h = await this.fail(h, row, why, loop);
|
|
414
|
+
if (loop.halted)
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const { ending: _ending, ...rest } = await this.tally(h);
|
|
418
|
+
if (!BATCH_MOVES.ending.includes(ending.status))
|
|
419
|
+
throw new Error(`batch ${h.id} cannot end ${ending.status}`);
|
|
420
|
+
await this.save({ ...rest, status: ending.status, stopped: ending.stopped, ...(ending.error ? { error: ending.error } : {}), ended_at: new Date(this.clock()).toISOString() });
|
|
421
|
+
}
|
|
422
|
+
/** One row's move: allowed by ROW_MOVES, one write of its record. */
|
|
423
|
+
async move(id, row, to, patch) {
|
|
424
|
+
const from = stageOf(row);
|
|
425
|
+
if (!ROW_MOVES[from].includes(to))
|
|
426
|
+
throw new Error(`row ${row.n} of batch ${id} cannot go from ${from} to ${to}`);
|
|
427
|
+
const next = { ...row, ...patch, state: to === "done" || to === "failed" ? to : "running" };
|
|
428
|
+
if (stageOf(next) !== to)
|
|
429
|
+
throw new Error(`row ${row.n} of batch ${id} wrote ${stageOf(next)} for ${to}`);
|
|
430
|
+
await this.saveRow(id, next);
|
|
431
|
+
return next;
|
|
432
|
+
}
|
|
433
|
+
/** Waits until `until` holds of the run's view. A view that fails is looked at again (a read is no ending); a cancel or a
|
|
434
|
+
* halt ends the wait ("stop": the row stays live, for the batch's ending or the next start), and so does the row's time. */
|
|
435
|
+
async wait(runId, until, loop) {
|
|
436
|
+
const started = this.clock();
|
|
437
|
+
for (;;) {
|
|
438
|
+
if (loop.cancelled || loop.halted)
|
|
439
|
+
return "stop";
|
|
440
|
+
const s = await this.host.view(runId).catch(() => undefined);
|
|
441
|
+
if (s && until(s))
|
|
442
|
+
return s;
|
|
443
|
+
if (this.clock() - started > (this.host.rowTimeoutMs ?? 30 * 60_000))
|
|
444
|
+
return "timeout";
|
|
445
|
+
await sleep(this.pollMs);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/** A row's every move from where its record stands: its run (started under the row's key), its answer (written once), the
|
|
449
|
+
* review (sent once), the review's turn and look-back, the booking. Returns the header folded once the row ended; a cancel
|
|
450
|
+
* or a halt leaves it live (the batch's ending stops it, or the next start takes it up). */
|
|
451
|
+
async runRow(h, row, loop) {
|
|
452
|
+
if (stageOf(row) === "pending") {
|
|
453
|
+
const key = ROW_KEY(h.id, row.n);
|
|
454
|
+
let runId;
|
|
455
|
+
try {
|
|
456
|
+
// Capped at what the batch has left, strict (cap.ts: every input token priced uncached), so no request of the run, a
|
|
457
|
+
// cache miss included, passes it: the batch's cap holds its runs, whatever the agent's own cap_mode.
|
|
458
|
+
runId = await this.host.start(h.agent_id, { input: { content: contentOf(h.inputs, row.input) }, max_cost_usd: usd(h.max_cost_usd - h.spent_usd), cap_mode: "strict", ...(h.effort ? { effort: h.effort } : {}) }, key);
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
// A start that failed after its run was made is that run's start: found by the key, the row is its.
|
|
462
|
+
runId = await this.host.find(key);
|
|
463
|
+
if (!runId)
|
|
464
|
+
return this.fail(h, row, `the run did not start: ${words(error)}`, loop);
|
|
465
|
+
}
|
|
466
|
+
row = await this.move(h.id, row, "started", { run_id: runId });
|
|
467
|
+
}
|
|
468
|
+
const runId = row.run_id;
|
|
469
|
+
if (loop.cancelled || loop.halted)
|
|
470
|
+
return h;
|
|
471
|
+
// Its answer: its end, and its learning's. A person's wait (a question, a paused cap) is a failed row.
|
|
472
|
+
if (stageOf(row) === "started") {
|
|
473
|
+
const snap = await this.wait(runId, (s) => s.status === "input_required" || settled(s), loop);
|
|
474
|
+
if (snap === "stop")
|
|
475
|
+
return h;
|
|
476
|
+
if (snap === "timeout")
|
|
477
|
+
return this.fail(h, row, "the run did not end in time", loop);
|
|
478
|
+
if (snap.status === "input_required")
|
|
479
|
+
return this.fail(h, row, "the run waits on a person: a batch's runs ask no one", loop);
|
|
480
|
+
if (snap.status !== "completed")
|
|
481
|
+
return this.fail(h, row, snap.error ?? `the run ${snap.status}`, loop);
|
|
482
|
+
const whole = answerValue(snap.answer, h.answer_field);
|
|
483
|
+
// The path is the job's, read now, before the review's message is in the run (the run's answer is the job's).
|
|
484
|
+
const job = await this.host.figures(runId);
|
|
485
|
+
row = await this.move(h.id, row, "answered", { answer: whole === null ? null : whole.slice(0, ANSWER_SHOWN), right: matches(whole, row.reference), review_after: snap.ended_at, review: reviewText(row.reference, whole), ...(job ? { path: job.path } : {}) });
|
|
486
|
+
}
|
|
487
|
+
// The review: once (a resume finds it in the run's commands), to a completed run whose learning has settled.
|
|
488
|
+
if (stageOf(row) === "answered") {
|
|
489
|
+
const review = row.review;
|
|
490
|
+
try {
|
|
491
|
+
if (!(await this.host.sent(runId, review)))
|
|
492
|
+
await this.host.message(runId, review);
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
return this.fail(h, row, `the review was not sent: ${words(error)}`, loop);
|
|
496
|
+
}
|
|
497
|
+
row = await this.move(h.id, row, "reviewed", { reviewed: true });
|
|
498
|
+
}
|
|
499
|
+
// The review's turn, its new end and the look-back it makes: a row is done only once that turn completed and its run
|
|
500
|
+
// learned from the reference.
|
|
501
|
+
const after = row.review_after ?? null;
|
|
502
|
+
const back = await this.wait(runId, (s) => s.status === "input_required" || (settled(s) && s.ended_at !== after), loop);
|
|
503
|
+
if (back === "stop")
|
|
504
|
+
return h;
|
|
505
|
+
if (back === "timeout")
|
|
506
|
+
return this.fail(h, row, "the review's turn did not end in time", loop);
|
|
507
|
+
if (back.status === "input_required")
|
|
508
|
+
return this.fail(h, row, "the run waits on a person after its review: a batch's runs ask no one", loop);
|
|
509
|
+
if (back.status !== "completed")
|
|
510
|
+
return this.fail(h, row, `the review's turn ${back.status === "cancelled" ? "was cancelled" : "failed"}${back.error ? `: ${back.error}` : ""}`, loop);
|
|
511
|
+
const f = await this.host.figures(runId);
|
|
512
|
+
await this.move(h.id, row, "done", f ? { cost_usd: f.cost_usd, learning_usd: f.learning_usd, total_usd: f.total_usd, learned: f.learned, merged: f.merged, revisions: f.revisions } : {});
|
|
513
|
+
return this.tally(h);
|
|
514
|
+
}
|
|
515
|
+
/** A row ends failed: a live row's run is asked to stop (nothing to one that ended; a stop that fails is the loop's
|
|
516
|
+
* failure, so the row stays live and owned) and waited for, with its grade, before its figures are read; one that does not
|
|
517
|
+
* stop within settleMs leaves the row's cost unknown. A halt meanwhile leaves the row as it is, for the next start. */
|
|
518
|
+
async fail(h, row, error, loop) {
|
|
519
|
+
const runId = row.run_id;
|
|
520
|
+
let known = true;
|
|
521
|
+
if (runId) {
|
|
522
|
+
const now = await this.host.view(runId).catch(() => undefined);
|
|
523
|
+
if (!now || !settled(now))
|
|
524
|
+
await this.host.cancel(runId);
|
|
525
|
+
const started = this.clock();
|
|
526
|
+
for (let s = now; !(s && settled(s));) {
|
|
527
|
+
if (loop.halted)
|
|
528
|
+
return h;
|
|
529
|
+
if (this.clock() - started > (this.host.settleMs ?? 10 * 60_000)) {
|
|
530
|
+
known = false;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
await sleep(this.pollMs);
|
|
534
|
+
s = await this.host.view(runId).catch(() => undefined);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
const f = runId && known ? await this.host.figures(runId).catch(() => undefined) : undefined;
|
|
538
|
+
await this.move(h.id, row, "failed", { error: error.slice(0, 400), total_usd: runId ? (f?.total_usd ?? null) : 0, ...(f ? { path: row.path ?? f.path, cost_usd: f.cost_usd, learning_usd: f.learning_usd, learned: f.learned, merged: f.merged, revisions: f.revisions } : {}) });
|
|
539
|
+
return this.tally(h);
|
|
540
|
+
}
|
|
541
|
+
/** The header's figures folded from its rows as saved, then saved: counts, $, paths, lessons and the merges that touched
|
|
542
|
+
* workflows, each row once. Never added to, so a stop between a row's write and this one loses nothing. */
|
|
543
|
+
async tally(h) {
|
|
544
|
+
const next = { ...h, finished: 0, right: 0, wrong: 0, failed: 0, spent_usd: 0, unknown_cost_rows: 0, paths: { agent: 0, handed_back: 0, workflow: 0 }, lessons: { notes: [], skills: [], workflows: [] }, revisions: [] };
|
|
545
|
+
let spent = 0;
|
|
546
|
+
for (let n = 1; n <= h.total; n++) {
|
|
547
|
+
const row = await this.row(h.id, n);
|
|
548
|
+
if (row.state !== "done" && row.state !== "failed")
|
|
549
|
+
continue;
|
|
550
|
+
next.finished++;
|
|
551
|
+
if (row.state === "failed")
|
|
552
|
+
next.failed++;
|
|
553
|
+
else if (row.right)
|
|
554
|
+
next.right++;
|
|
555
|
+
else if (row.right === false)
|
|
556
|
+
next.wrong++;
|
|
557
|
+
if (row.run_id && (row.total_usd === null || row.total_usd === undefined))
|
|
558
|
+
next.unknown_cost_rows++;
|
|
559
|
+
spent += row.total_usd ?? 0;
|
|
560
|
+
if (row.path)
|
|
561
|
+
next.paths[row.path]++;
|
|
562
|
+
for (const kind of ["notes", "skills", "workflows"])
|
|
563
|
+
for (const name of row.learned?.[kind] ?? [])
|
|
564
|
+
if (!next.lessons[kind].includes(name))
|
|
565
|
+
next.lessons[kind].push(name);
|
|
566
|
+
for (const r of row.revisions ?? [])
|
|
567
|
+
next.revisions.push({ row: row.n, commit: r.commit, workflows: r.workflows });
|
|
568
|
+
}
|
|
569
|
+
next.spent_usd = usd(spent);
|
|
570
|
+
if (h.status === "running")
|
|
571
|
+
await this.save(next);
|
|
572
|
+
return next;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
|
|
2
|
+
* calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
|
|
3
|
+
* to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
|
|
4
|
+
* went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
|
|
5
|
+
export declare const RUN_PATHS: readonly ["agent", "handed_back", "workflow"];
|
|
6
|
+
export type RunPath = (typeof RUN_PATHS)[number];
|
|
7
|
+
/** What a run that looked back kept of its costs as it answered (runner/reflect-hook.ts: store-reads/learning.ts
|
|
8
|
+
* answeredOf): when the job answered, what it had cost by then and what looking back cost after it. */
|
|
9
|
+
export type CostLooked = {
|
|
10
|
+
answered_at?: string;
|
|
11
|
+
job_cost_usd?: number | null;
|
|
12
|
+
look_back_usd?: number | null;
|
|
13
|
+
};
|
|
14
|
+
/** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
|
|
15
|
+
* person asked of it after), what it kept as it answered (`looked`, none for a run that did not look back) and what its
|
|
16
|
+
* grade spent (`gradeUsd`: its learning run's cost once that run ended, stopped or failed, 0 while it runs or when there
|
|
17
|
+
* is none, null when unknown):
|
|
18
|
+
* - `cost_usd`: the job's own $: its row's cost less its look-back, never under what it had cost when it answered (a
|
|
19
|
+
* later turn's spend is the job's too); its row's cost for a run that did not look back;
|
|
20
|
+
* - `learning_usd`: what learning cost for it: its look-back and its grade, 0 for a run that does not learn; null when
|
|
21
|
+
* either is unknown (a grade that failed or was stopped mid-ask spent what no one knows);
|
|
22
|
+
* - `total_usd`: their sum, the run's all-in $; null when either is. */
|
|
23
|
+
export declare function runCostOf(rowUsd: number | null, looked: CostLooked | null, gradeUsd?: number | null): {
|
|
24
|
+
cost_usd: number | null;
|
|
25
|
+
learning_usd: number | null;
|
|
26
|
+
total_usd: number | null;
|
|
27
|
+
};
|
|
28
|
+
/** One run of the series, in the order the agent's runs started: `n` its number among them (1 the first). */
|
|
29
|
+
export type CostRun = {
|
|
30
|
+
n: number;
|
|
31
|
+
run_id: string;
|
|
32
|
+
started_at: string;
|
|
33
|
+
path: RunPath;
|
|
34
|
+
/** The learned workflow its job called last, by name; null when it called none. */
|
|
35
|
+
workflow: string | null;
|
|
36
|
+
/** The commit of the agent's learning folder the run started from (its learning start's seed): the learned revision
|
|
37
|
+
* that served it. Null for a run that does not learn. */
|
|
38
|
+
learned_revision: string | null;
|
|
39
|
+
cost_usd: number | null;
|
|
40
|
+
learning_usd: number | null;
|
|
41
|
+
total_usd: number | null;
|
|
42
|
+
};
|
|
43
|
+
/** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
|
|
44
|
+
export declare const CHEAPER_AFTER_RUNS = 20;
|
|
45
|
+
/** The latest runs the route answers by default, and at most. */
|
|
46
|
+
export declare const COST_RUNS_DEFAULT = 1000;
|
|
47
|
+
export declare const COST_RUNS_MAX = 10000;
|
|
48
|
+
/** What the series shows: `takeover`, its first `workflow` run, null before one; `before`, the mean of the job's own $
|
|
49
|
+
* (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known;
|
|
50
|
+
* `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known; and
|
|
51
|
+
* `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more, else null. The
|
|
52
|
+
* before side leaves learning out and the after side keeps it in, so the figure never flatters learning. */
|
|
53
|
+
export type CostSummary = {
|
|
54
|
+
takeover: {
|
|
55
|
+
n: number;
|
|
56
|
+
run_id: string;
|
|
57
|
+
} | null;
|
|
58
|
+
before: {
|
|
59
|
+
runs: number;
|
|
60
|
+
mean_usd: number;
|
|
61
|
+
} | null;
|
|
62
|
+
after: {
|
|
63
|
+
runs: number;
|
|
64
|
+
mean_usd: number;
|
|
65
|
+
} | null;
|
|
66
|
+
times_cheaper: number | null;
|
|
67
|
+
};
|
|
68
|
+
export declare function costSummary(runs: readonly CostRun[]): CostSummary;
|
|
69
|
+
/** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
|
|
70
|
+
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
71
|
+
* it opens as the text it is. */
|
|
72
|
+
export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
|
|
73
|
+
export declare function costCsv(runs: readonly CostRun[]): string;
|
|
74
|
+
/** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
|
|
75
|
+
* and `format`, `json` (the default) or `csv`. Anything else is 400. */
|
|
76
|
+
export declare function learningCostQuery(url: URL): {
|
|
77
|
+
limit: number;
|
|
78
|
+
csv: boolean;
|
|
79
|
+
};
|