@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
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 +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- 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 +90 -8
- package/dist/archil-settings.js +150 -14
- 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/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- 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 +2 -2
- package/dist/browser-cost.js +6 -4
- 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 +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- 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-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- 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 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- 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 +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -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 +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -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 +76 -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 +411 -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/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- 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/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- 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/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- 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 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- 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/templates/code-review/rules/REVIEW.md +0 -41
package/dist/learned-workflow.js
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
// learned_workflow: a run of an agent that learned a workflow runs it as one tool call, on any harness. The tool is the
|
|
2
|
+
// run's when its pin names a learned workflow (learning.ts: one whose README sets no status, or `active`; a pending or
|
|
3
|
+
// retired one is never named), with no edit of the agent's definition; its description names each one and what it does,
|
|
4
|
+
// so the model needs no hint. A call checks the workflow again against the agent's own tools as its run has them (S1's
|
|
5
|
+
// checker, draftProblems, as at learn time: a call node on a tool the agent was not granted or its run resolves
|
|
6
|
+
// unavailable, a model node that names any tool, a code node or a shell or executor call is refused before any node
|
|
7
|
+
// runs, never after earlier ones spent), then runs it with the workflow DSL's runWorkflow:
|
|
8
|
+
// - a model node (agent, decide, extract, report) on the run's model of its tier, else the run's own model (the one
|
|
9
|
+
// model the run was made with and handed the key of: app.ts), in a fresh session of its own (the host
|
|
10
|
+
// runner, workflow/host-session.ts), with no tool of its own;
|
|
11
|
+
// - a call node `via: "tool"` on the tool table's effect, as a workflow revision's (app.ts), for a tool the agent has,
|
|
12
|
+
// its paid requests booked under the tool's call (paid-calls.ts), each node's under a call of its own; web_search
|
|
13
|
+
// where it resolves native on the provider's hosted search through the run's models (hosted-search.ts), on a harness
|
|
14
|
+
// whose own search it is too (harness-app.ts gives that harness no host tool of the name).
|
|
15
|
+
// Each model request is a request on the run's one route, so what the workflow spends is the run's cost, under its cap:
|
|
16
|
+
// on pi the run's models, as a side request (request-start.ts, cap.ts: marked, and costed on the run's timeline as
|
|
17
|
+
// `learned_workflow`); on another harness the session's model proxy, under a side key (port-models.ts): the harness's
|
|
18
|
+
// own policy, provider, key and price, booked on the session's records labelled `learned_workflow`. A call a crash cut
|
|
19
|
+
// off is never run again (`replay: "never"`): it is answered interrupted.
|
|
20
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
21
|
+
import { defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
22
|
import { registerLabel, registerOutcome } from "./timeline/index.js";
|
|
3
23
|
import { sideRequests } from "./cap.js";
|
|
24
|
+
import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
|
|
4
25
|
import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
|
|
5
26
|
import { workflowLine } from "./learning.js";
|
|
6
27
|
import { ledgerOf } from "./paid-calls.js";
|
|
28
|
+
import { PORT_PROVIDER } from "./port-models.js";
|
|
7
29
|
import { forModel } from "./result.js";
|
|
8
30
|
import { ARGS_PREVIEW_BYTES, deniedText } from "./tool-gate.js";
|
|
9
31
|
import { allows, CALL_TOOLS, learnedDraftTools, toolOf, workflowTools } from "./tools.js";
|
|
@@ -59,40 +81,45 @@ export const LEARNED_WORKFLOW_TOOL = "learned_workflow";
|
|
|
59
81
|
/** The most of a learned workflow's output its result line shows, and the longest value it shows as written. */
|
|
60
82
|
const LINE_MAX = 120;
|
|
61
83
|
const VALUE_MAX = 60;
|
|
62
|
-
/** One line of a learned workflow's output for its row: an object's fields as `name value`,
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
84
|
+
/** One line of a learned workflow's output for its row: an object's fields as `name value`, and a text output (learnedOutput
|
|
85
|
+
* hands one back as it is, #2412) its lines, each value or line whole or, when longer than VALUE_MAX, only as its size,
|
|
86
|
+
* and whole ones only until LINE_MAX. Nothing is ever cut inside a value or a line: the timeline redacts the line as it
|
|
87
|
+
* says it (its summary's words), and its redactor matches a held value only whole, so a cut one could leave a prefix it
|
|
88
|
+
* would not find. Newlines are flattened, so the one line it keeps holds every part. An output already cut for the
|
|
89
|
+
* model (learnedText) says so. */
|
|
67
90
|
export function outputLine(text) {
|
|
68
91
|
const clipped = /\n\[the workflow's output is cut at (\d+) of (\d+) characters\]$/.exec(text);
|
|
69
92
|
if (clipped)
|
|
70
93
|
return `its output is long, cut at ${clipped[1]} of ${clipped[2]} characters`;
|
|
94
|
+
const said = (value) => {
|
|
95
|
+
const flat = (typeof value === "string" ? value : JSON.stringify(value) ?? String(value)).replace(/\s+/g, " ").trim();
|
|
96
|
+
return flat.length > VALUE_MAX ? `(${flat.length} characters)` : flat;
|
|
97
|
+
};
|
|
98
|
+
/** `parts` whole, joined by `by`, until LINE_MAX: then an ellipsis. */
|
|
99
|
+
const joined = (parts, by) => {
|
|
100
|
+
const kept = [];
|
|
101
|
+
let length = 0;
|
|
102
|
+
for (const part of parts) {
|
|
103
|
+
if (kept.length && length + by.length + part.length > LINE_MAX) {
|
|
104
|
+
kept.push("…");
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
kept.push(part);
|
|
108
|
+
length += (kept.length > 1 ? by.length : 0) + part.length;
|
|
109
|
+
}
|
|
110
|
+
return kept.length ? kept.join(by) : undefined;
|
|
111
|
+
};
|
|
71
112
|
let output;
|
|
72
113
|
try {
|
|
73
114
|
output = JSON.parse(text);
|
|
74
115
|
}
|
|
75
116
|
catch {
|
|
76
|
-
|
|
117
|
+
// Text, as it is: its lines that hold words.
|
|
118
|
+
return joined(text.split("\n").filter((line) => line.trim()).map(said), " / ");
|
|
77
119
|
}
|
|
78
|
-
const said = (value) => {
|
|
79
|
-
const flat = (typeof value === "string" ? value : JSON.stringify(value) ?? String(value)).replace(/\s+/g, " ").trim();
|
|
80
|
-
return flat.length > VALUE_MAX ? `(${flat.length} characters)` : flat;
|
|
81
|
-
};
|
|
82
120
|
if (!output || typeof output !== "object" || Array.isArray(output))
|
|
83
121
|
return said(output);
|
|
84
|
-
|
|
85
|
-
let length = 0;
|
|
86
|
-
for (const [key, value] of Object.entries(output)) {
|
|
87
|
-
const field = `${key} ${said(value)}`;
|
|
88
|
-
if (fields.length && length + 2 + field.length > LINE_MAX) {
|
|
89
|
-
fields.push("…");
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
fields.push(field);
|
|
93
|
-
length += (fields.length > 1 ? 2 : 0) + field.length;
|
|
94
|
-
}
|
|
95
|
-
return fields.length ? fields.join(", ") : undefined;
|
|
122
|
+
return joined(Object.entries(output).map(([key, value]) => `${key} ${said(value)}`), ", ");
|
|
96
123
|
}
|
|
97
124
|
// The timeline's words for a learned workflow's call: the workflow it ran (its name), and, once it returns, its output.
|
|
98
125
|
registerLabel(LEARNED_WORKFLOW_TOOL, (a) => (typeof a.name === "string" && a.name ? `Ran the learned workflow ${a.name}` : "Ran a learned workflow"), undefined, { name: "Run a learned workflow" });
|
|
@@ -103,7 +130,7 @@ registerOutcome(LEARNED_WORKFLOW_TOOL, (result) => {
|
|
|
103
130
|
/** The most characters of a learned workflow's output its answer holds, monid's bound (monid.ts CLIP): within the
|
|
104
131
|
* host's result bound, which each CLI is told to pass whole (host-bounds.test). */
|
|
105
132
|
export const LEARNED_CLIP = 60_000;
|
|
106
|
-
/** `text`, a learned workflow's output as
|
|
133
|
+
/** `text`, a learned workflow's output as its tool hands it back (learnedOutput), cut at LEARNED_CLIP characters (never inside a surrogate pair), saying
|
|
107
134
|
* so. */
|
|
108
135
|
export function learnedText(text) {
|
|
109
136
|
if (text.length <= LEARNED_CLIP)
|
|
@@ -116,12 +143,26 @@ export function learnedText(text) {
|
|
|
116
143
|
export const NODE_TOOLS_REFUSED = "a learned workflow's model node runs without tools here";
|
|
117
144
|
/** The tool's description, sent with every model request of the run, so it holds what a model needs to call it right and
|
|
118
145
|
* no more: one line of what the tool does (one call, by name, a JSON input with the listed fields, `*` marking a required
|
|
119
|
-
* one; what it answers
|
|
120
|
-
*
|
|
146
|
+
* one; what it answers: a text output as it is, to reply with unchanged, since a model handed it otherwise writes its own
|
|
147
|
+
* reply around it and a format the workflow's last node wrote is lost, #2412), then each workflow on a line of its own
|
|
148
|
+
* (workflowLine): its name, its input's fields and the line its README says what it does with. */
|
|
121
149
|
export const learnedWorkflowDescription = (workflows) => [
|
|
122
|
-
"Runs
|
|
150
|
+
"Runs a learned workflow in one call, by name, on a JSON input: fields below (* required). Text output: reply with it unchanged. Else JSON, or why it did not run.",
|
|
123
151
|
...workflows.map(workflowLine),
|
|
124
152
|
].join("\n");
|
|
153
|
+
/** A learned workflow's output as its tool hands it back: its text when it is text, a string or an object of one string
|
|
154
|
+
* field (a node's record of one field, as a last node that writes the answer gives it), so the lines its last node wrote
|
|
155
|
+
* reach the model as lines; else JSON. */
|
|
156
|
+
export function learnedOutput(output) {
|
|
157
|
+
if (typeof output === "string")
|
|
158
|
+
return output;
|
|
159
|
+
if (output && typeof output === "object" && !Array.isArray(output)) {
|
|
160
|
+
const values = Object.values(output);
|
|
161
|
+
if (values.length === 1 && typeof values[0] === "string")
|
|
162
|
+
return values[0];
|
|
163
|
+
}
|
|
164
|
+
return JSON.stringify(output ?? null);
|
|
165
|
+
}
|
|
125
166
|
/** One model request as a pi-ai event stream, sent through `models.completeSimple` as the run's own request, under its
|
|
126
167
|
* cap: on pi marked and costed on the run's timeline under `learned_workflow` (sideRequests), on another harness booked
|
|
127
168
|
* by the session's proxy, labelled by the side key it goes under. */
|
|
@@ -169,15 +210,31 @@ export function learnedWorkflowTool(run) {
|
|
|
169
210
|
const flow = run.workflows.find((workflow) => workflow.name === name);
|
|
170
211
|
if (!flow)
|
|
171
212
|
return forModel(`No learned workflow of this agent is named ${JSON.stringify(name)}. Its workflows: ${names.join(", ")}.`, { isError: true });
|
|
172
|
-
const
|
|
213
|
+
const ledger = ledgerOf(api, context);
|
|
214
|
+
// Which of its nodes ran, kept beside the call in the run's journal (LEARNED_NODES), for its timeline row; a trace
|
|
215
|
+
// that can't be kept never fails the call. A call stopped part way keeps the nodes that ended before it stopped,
|
|
216
|
+
// written outside the stopped call's context, and still ends as a stop.
|
|
217
|
+
const trace = [];
|
|
218
|
+
const keep = (signal) => (trace.length ? api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace } })), signal).catch(() => undefined) : undefined);
|
|
219
|
+
let said;
|
|
220
|
+
try {
|
|
221
|
+
said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
await keep(BACKGROUND_CONTEXT);
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
await keep(context);
|
|
173
228
|
return forModel(said.text, { isError: said.isError });
|
|
174
229
|
},
|
|
175
230
|
});
|
|
176
231
|
}
|
|
177
|
-
/** `flow` run on `input` for `run`: its output as
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
232
|
+
/** `flow` run on `input` for `run`: its output as its tool hands it back (learnedOutput), or why it did not run, and each of its nodes that ran (at most
|
|
233
|
+
* LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
|
|
234
|
+
* which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
|
|
235
|
+
* added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
|
|
236
|
+
export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
|
|
237
|
+
const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true, nodes });
|
|
181
238
|
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
182
239
|
return refuse("its input must be a JSON object");
|
|
183
240
|
const dsl = await import("@parcha/agentrun-dsl");
|
|
@@ -206,9 +263,8 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
206
263
|
if (problems.length)
|
|
207
264
|
return refuse(problems.map(({ detail }) => detail).join("; "));
|
|
208
265
|
const doc = JSON.parse(flow.workflow);
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
const { createPiHostRunner } = await import("@parcha/agentrun-pi");
|
|
266
|
+
// The host runner loads @earendil-works/pi-coding-agent and pi-agent-core, serve's own dependencies (package.json).
|
|
267
|
+
const { createPiHostRunner } = await import("./workflow/host-session.js");
|
|
212
268
|
const runners = new Map();
|
|
213
269
|
const runnerFor = async (tier) => {
|
|
214
270
|
const known = runners.get(tier ?? "default");
|
|
@@ -225,9 +281,17 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
225
281
|
runners.set(tier ?? "default", runner);
|
|
226
282
|
return runner;
|
|
227
283
|
};
|
|
284
|
+
// Each model node's model and tier by its execution path, as it runs: its node.end (the same path) puts them on its
|
|
285
|
+
// trace. Never by its label, which a workflow may repeat. Only a model node runs here: a call node never has one.
|
|
286
|
+
const ranOn = new Map();
|
|
228
287
|
const runNode = async (request) => {
|
|
229
288
|
if (request.tools?.length)
|
|
230
289
|
throw new Error(`${NODE_TOOLS_REFUSED}: its node "${request.label}" names ${request.tools.join(", ")}`);
|
|
290
|
+
const tier = typeof request.tier === "string" ? request.tier : undefined;
|
|
291
|
+
const ref = run.modelOf(tier);
|
|
292
|
+
const model = !ref ? undefined : ref.provider === PORT_PROVIDER ? (run.modelName?.(tier) ?? undefined) : ref.modelId;
|
|
293
|
+
if (model && typeof request.executionPath === "string")
|
|
294
|
+
ranOn.set(request.executionPath, { model, ...(tier ? { tier } : {}) });
|
|
231
295
|
// Its own signal, which the DSL ties to the call's (a sibling's failure, a deadline, the call's stop).
|
|
232
296
|
return (await runnerFor(request.tier))(request);
|
|
233
297
|
};
|
|
@@ -275,15 +339,23 @@ export async function runLearned(run, flow, input, signal, ledger) {
|
|
|
275
339
|
const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
|
|
276
340
|
return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
|
|
277
341
|
};
|
|
342
|
+
// Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
|
|
343
|
+
const onEvent = (event) => {
|
|
344
|
+
if (event.type !== "node.end" || nodes.length >= LEARNED_NODES_MAX)
|
|
345
|
+
return;
|
|
346
|
+
const detail = (event.detail ?? {});
|
|
347
|
+
const ran = typeof event.executionPath === "string" ? ranOn.get(event.executionPath) : undefined;
|
|
348
|
+
nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0, ...ran });
|
|
349
|
+
};
|
|
278
350
|
try {
|
|
279
|
-
const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, ...(signal ? { signal } : {}) });
|
|
351
|
+
const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...(signal ? { signal } : {}) });
|
|
280
352
|
if (result.status !== "complete")
|
|
281
353
|
return refuse(`it ended ${result.status}`);
|
|
282
|
-
return { text: learnedText(
|
|
354
|
+
return { text: learnedText(learnedOutput(result.output)), isError: false, nodes };
|
|
283
355
|
}
|
|
284
356
|
catch (error) {
|
|
285
357
|
if (signal?.aborted)
|
|
286
358
|
throw error;
|
|
287
|
-
return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true };
|
|
359
|
+
return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true, nodes };
|
|
288
360
|
}
|
|
289
361
|
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// An agent's cost per run, run after run (GET /agents/{id}/learning/cost): what each run of its cost, what learning added
|
|
2
|
+
// for it, and the path it took, so a person sees the cost fall once a learned workflow does the job, and by how much.
|
|
3
|
+
// Aggregates only: no run's input, answer or tool text. The store's reader (store-reads/learning.ts agentCostOverStore)
|
|
4
|
+
// gives each run's figures and its path (runner/learning-end.ts runPathOf); this module sums its learning and says what the
|
|
5
|
+
// series shows (costSummary), the rule the console, the CLI and the CSV all read. It imports only the errors, so the API
|
|
6
|
+
// document reads its words.
|
|
7
|
+
import { ApiError } from "./errors.js";
|
|
8
|
+
/** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
|
|
9
|
+
* calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
|
|
10
|
+
* to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
|
|
11
|
+
* went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
|
|
12
|
+
export const RUN_PATHS = ["agent", "handed_back", "workflow"];
|
|
13
|
+
const usd = (value) => Math.round(value * 1e6) / 1e6;
|
|
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 function runCostOf(rowUsd, looked, gradeUsd = 0) {
|
|
24
|
+
const answered = looked?.answered_at !== undefined;
|
|
25
|
+
const asAnswered = answered ? (looked.job_cost_usd ?? null) : rowUsd;
|
|
26
|
+
const back = answered ? (looked.look_back_usd ?? null) : 0;
|
|
27
|
+
// What the row holds past the answer and its look-back is a later turn's spend, unknown once the row's cost is; with the
|
|
28
|
+
// look-back's cost unknown the two can't be told apart, and the job is what it had cost when it answered.
|
|
29
|
+
const job = !answered || asAnswered === null || back === null ? asAnswered : rowUsd === null ? null : Math.max(asAnswered, rowUsd - back);
|
|
30
|
+
const spent = back === null || gradeUsd === null ? null : back + gradeUsd;
|
|
31
|
+
return { cost_usd: job === null ? null : usd(job), learning_usd: spent === null ? null : usd(spent), total_usd: job === null || spent === null ? null : usd(job + spent) };
|
|
32
|
+
}
|
|
33
|
+
/** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
|
|
34
|
+
export const CHEAPER_AFTER_RUNS = 20;
|
|
35
|
+
/** The latest runs the route answers by default, and at most. */
|
|
36
|
+
export const COST_RUNS_DEFAULT = 1000;
|
|
37
|
+
export const COST_RUNS_MAX = 10_000;
|
|
38
|
+
export function costSummary(runs) {
|
|
39
|
+
const first = runs.findIndex((run) => run.path === "workflow");
|
|
40
|
+
const mean = (values) => (values.length ? { runs: values.length, mean_usd: usd(values.reduce((a, b) => a + b, 0) / values.length) } : null);
|
|
41
|
+
const before = mean((first < 0 ? runs : runs.slice(0, first)).flatMap((run) => (run.path === "agent" && run.cost_usd !== null ? [run.cost_usd] : [])));
|
|
42
|
+
const after = first < 0 ? null : mean(runs.slice(first).flatMap((run) => (run.total_usd === null ? [] : [run.total_usd])));
|
|
43
|
+
const times = before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
|
|
44
|
+
return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times };
|
|
45
|
+
}
|
|
46
|
+
/** 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
|
|
47
|
+
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
48
|
+
* it opens as the text it is. */
|
|
49
|
+
export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
|
|
50
|
+
export function costCsv(runs) {
|
|
51
|
+
const cell = (value) => {
|
|
52
|
+
const raw = value === null || value === undefined ? "" : String(value);
|
|
53
|
+
const text = typeof value === "string" && /^[=+\-@\t\r]/.test(raw) ? `'${raw}` : raw;
|
|
54
|
+
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
55
|
+
};
|
|
56
|
+
return [COST_CSV_COLUMNS.join(","), ...runs.map((run) => COST_CSV_COLUMNS.map((column) => cell(run[column])).join(","))].map((line) => `${line}\r\n`).join("");
|
|
57
|
+
}
|
|
58
|
+
/** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
|
|
59
|
+
* and `format`, `json` (the default) or `csv`. Anything else is 400. */
|
|
60
|
+
export function learningCostQuery(url) {
|
|
61
|
+
const limitText = url.searchParams.get("limit");
|
|
62
|
+
const limit = limitText === null ? COST_RUNS_DEFAULT : /^[1-9]\d*$/.test(limitText) ? Number(limitText) : NaN;
|
|
63
|
+
if (!(limit >= 1 && limit <= COST_RUNS_MAX))
|
|
64
|
+
throw new ApiError("bad_request", `limit is a whole number from 1 to ${COST_RUNS_MAX}`);
|
|
65
|
+
const format = url.searchParams.get("format") ?? "json";
|
|
66
|
+
if (format !== "json" && format !== "csv")
|
|
67
|
+
throw new ApiError("bad_request", "format is json or csv");
|
|
68
|
+
return { limit, csv: format === "csv" };
|
|
69
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { DraftAsk } from "./learn/skills.js";
|
|
1
2
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
3
|
import { type ItemStatus, type Learning, type NoteRuns, type Shown } from "./learning.js";
|
|
3
4
|
import type { Impact } from "./learning-run.js";
|
|
5
|
+
import { type LearnedUse } from "./store-reads/learning.js";
|
|
4
6
|
import type { Store } from "./store/store.js";
|
|
5
7
|
type Page<T> = {
|
|
6
8
|
items: T[];
|
|
@@ -25,9 +27,15 @@ type NoteView = {
|
|
|
25
27
|
};
|
|
26
28
|
};
|
|
27
29
|
/** When a retired note, skill or draft was retired, and by whom: a person (its retire's commit), else a run. */
|
|
30
|
+
/** Who retired a retired item, and when, and `from`, the status its restore gives back; or, for a skill or draft that
|
|
31
|
+
* reads retired only because its file can't be read (its front matter reads no way: unclearFront, read from its file as
|
|
32
|
+
* the view is made), that no one did: the host could not read it (`why`), with no `from`, since its restore waits for
|
|
33
|
+
* the file to be fixed. One closed shape. */
|
|
28
34
|
type Retired = {
|
|
29
35
|
at: string;
|
|
30
|
-
by: "person" | "run";
|
|
36
|
+
by: "person" | "run" | "host";
|
|
37
|
+
from?: "active" | "pending";
|
|
38
|
+
why?: "unreadable";
|
|
31
39
|
};
|
|
32
40
|
/** The newest change to a note, skill or draft (its file: the note, a SKILL.md, a draft's README.md): what it was, by
|
|
33
41
|
* whom and when. A person's is named by its commit (`learning: <kind> by a person: <file>`); a run's merge is `learned`. */
|
|
@@ -141,6 +149,8 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
141
149
|
draftTools?: () => Promise<{
|
|
142
150
|
tools: string[];
|
|
143
151
|
gated: Record<string, string>;
|
|
152
|
+
deniedBy?: Record<string, "agent" | "server" | "default">;
|
|
153
|
+
ask?: DraftAsk;
|
|
144
154
|
}>;
|
|
145
155
|
}): Promise<{
|
|
146
156
|
status: 200 | 201;
|
|
@@ -148,6 +158,30 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
148
158
|
text: string;
|
|
149
159
|
etag: string;
|
|
150
160
|
}>;
|
|
161
|
+
/** A learned workflow as a promotion makes it into an agent of its own: its folder's name, its README's description,
|
|
162
|
+
* its workflow.json parsed, and the tools its call nodes call. */
|
|
163
|
+
export type Promotable = {
|
|
164
|
+
name: string;
|
|
165
|
+
description: string;
|
|
166
|
+
workflow: Record<string, unknown>;
|
|
167
|
+
calls: string[];
|
|
168
|
+
};
|
|
169
|
+
/** POST /agents/{id}/learning/workflows/{name}/promote's read of the learned workflow `raw` (percent-encoded) on agent
|
|
170
|
+
* `agentId`'s main: an active one alone, as every later run is given it. One that waits for its owner's OK, or that a
|
|
171
|
+
* person retired, is 409 learned_not_active: a promotion never runs what the owner has not let every run use. Each of
|
|
172
|
+
* its files is checked again as a restore checks it (unstorable: a secret's shape, the host's values as they are now,
|
|
173
|
+
* a hidden character), and its workflow.json as the learning checker checks a run's draft against the agent's tools and
|
|
174
|
+
* its gate (draftProblems: the DSL's validation with no code run, no code node, no shell or executor call, no call node
|
|
175
|
+
* on a tool the agent does not have or the gate holds to ask or deny). Any of those is 400 with `problems`, printable.
|
|
176
|
+
* Reads only: the folder is never written. */
|
|
177
|
+
export declare function promotable(data: string, agentId: string, raw: string, input: {
|
|
178
|
+
refuse: readonly string[];
|
|
179
|
+
draftTools: () => Promise<{
|
|
180
|
+
tools: string[];
|
|
181
|
+
gated: Record<string, string>;
|
|
182
|
+
deniedBy?: Record<string, "agent" | "server" | "default">;
|
|
183
|
+
}>;
|
|
184
|
+
}): Promise<Promotable>;
|
|
151
185
|
/** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
|
|
152
186
|
* settled: the one shape, read from the one store (store-reads/learning.ts
|
|
153
187
|
* runLearningOverStore). */
|
|
@@ -156,6 +190,7 @@ export declare function runLearningBody(input: {
|
|
|
156
190
|
readonly learning: Learning;
|
|
157
191
|
readonly seed: string | null;
|
|
158
192
|
readonly settled: boolean;
|
|
193
|
+
readonly used?: LearnedUse;
|
|
159
194
|
}, shown: Shown, secrets: readonly string[]): {
|
|
160
195
|
seed: string | null;
|
|
161
196
|
merged: string | null;
|
|
@@ -186,6 +221,17 @@ export declare function runLearningBody(input: {
|
|
|
186
221
|
tokens: {
|
|
187
222
|
grade: import("./learning.js").Tokens | null;
|
|
188
223
|
};
|
|
224
|
+
used: {
|
|
225
|
+
skills: {
|
|
226
|
+
name: string;
|
|
227
|
+
read: boolean;
|
|
228
|
+
}[];
|
|
229
|
+
workflows: {
|
|
230
|
+
name: string;
|
|
231
|
+
calls: number;
|
|
232
|
+
failed: number;
|
|
233
|
+
}[];
|
|
234
|
+
};
|
|
189
235
|
given?: import("./learning.js").NoteUsed[];
|
|
190
236
|
read?: import("./learning.js").NoteUsed[];
|
|
191
237
|
learned?: import("./learning.js").NoteLearned[];
|
|
@@ -193,7 +239,7 @@ export declare function runLearningBody(input: {
|
|
|
193
239
|
workflows?: import("./learning.js").LearnedFile[];
|
|
194
240
|
run: string;
|
|
195
241
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
196
|
-
reason: "
|
|
242
|
+
reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
197
243
|
detail: string | null;
|
|
198
244
|
at: string;
|
|
199
245
|
};
|