@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/uploads.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Uploads: a file reserved (POST /v2/files) and its bytes sent (PUT /v2/files/{file_id}), or sent in one call (POST
|
|
2
|
-
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`)
|
|
3
|
-
// into its workspace
|
|
2
|
+
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`) held
|
|
3
|
+
// for it at its start and copied into its workspace at its claim. Each file is `<data>/files/<file_id>/`: its bytes
|
|
4
4
|
// (`bytes`) and its record (`file.json`, the contract's File), both 0600, the record written whole. A ready file's bytes
|
|
5
5
|
// never change, and a run gets a copy of them through its Workspace, never a link: nothing a run does reaches the upload.
|
|
6
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
7
|
-
import { lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
7
|
+
import { copyFile, link, lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
8
8
|
import { DISK_DIR } from "./server-fs.js";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { ApiError, invalid } from "./errors.js";
|
|
@@ -22,6 +22,9 @@ export const INPUTS_DIR = "inputs";
|
|
|
22
22
|
export const UPLOADS_DIR = "files";
|
|
23
23
|
const RECORD = "file.json";
|
|
24
24
|
const BYTES = "bytes";
|
|
25
|
+
/** Under the root: each started run's hold of its files until its claim copies them (Uploads.hold). A dot-name, never a
|
|
26
|
+
* file id (ID starts with a letter or digit), so the files' list and the sweep pass it by. */
|
|
27
|
+
const HELD_DIR = ".held";
|
|
25
28
|
/** The `upload.expires_at` the answer to a reservation gives, which the contract requires: advisory, not enforced in this
|
|
26
29
|
* release. A later PUT is still taken, and nothing deletes an upload. */
|
|
27
30
|
const UPLOAD_WINDOW_MS = 86_400_000;
|
|
@@ -423,11 +426,12 @@ export class Uploads {
|
|
|
423
426
|
return files;
|
|
424
427
|
}
|
|
425
428
|
/** Copies `files` into the run's `inputs/` through its Workspace, each at its `path` with its folders, in order, before
|
|
426
|
-
* the run's
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
|
|
429
|
+
* the run's first turn: a name taken already (the same path twice, a file where another's folder goes, or what the
|
|
430
|
+
* folder held before) gets the next free suffix (`notes-2.txt`, `docs-2/`), the same for the same files in the same
|
|
431
|
+
* order. Each copy is a new file written whole by the Workspace, never a link to the upload; a link on the way fails
|
|
432
|
+
* the copy (ESCAPE), and nothing is written through it. `bytesOf`: where each file's bytes are read (its upload's own,
|
|
433
|
+
* or the run's hold of them, `held`). */
|
|
434
|
+
async copyInto(work, files, bytesOf = (file) => join(this.root, file.file_id, BYTES)) {
|
|
431
435
|
const workspace = workspaceAt(work);
|
|
432
436
|
await uploadTestHooks.beforeCopy?.(workspace);
|
|
433
437
|
const names = takenNames(workspace);
|
|
@@ -437,9 +441,78 @@ export class Uploads {
|
|
|
437
441
|
for (const segment of segments.slice(0, -1))
|
|
438
442
|
dir = `${dir}/${free(await names(dir), segment, "dir")}`;
|
|
439
443
|
const name = free(await names(dir), segments.at(-1), "file");
|
|
440
|
-
await workspace.write(`${dir}/${name}`, await readFile(
|
|
444
|
+
await workspace.write(`${dir}/${name}`, await readFile(bytesOf(file)));
|
|
441
445
|
}
|
|
442
446
|
}
|
|
447
|
+
/** At a run's start, before its row is written: each of its files (`ids`, ready) held for it under
|
|
448
|
+
* `<root>/.held/<run id>/`, its record and its bytes (a hard link to the upload's, which never change once ready; a
|
|
449
|
+
* copy where the disk links none). The run's claim copies from the hold (heldFiles), so a file deleted after the start
|
|
450
|
+
* and before the claim is still the run's: a started run keeps the files it was started with. In turn with each file's
|
|
451
|
+
* delete, so a hold either has the bytes or the start fails at that file (422, as readyFiles words it). */
|
|
452
|
+
async hold(runId, ids) {
|
|
453
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
454
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
455
|
+
for (const [i, id] of ids.entries()) {
|
|
456
|
+
await this.exclusive(id, async () => {
|
|
457
|
+
const file = await this.get(id);
|
|
458
|
+
if (file?.status !== "ready")
|
|
459
|
+
throw invalid([{ field: `file_ids[${i}]`, reason: "not_an_option", message: `There is no file ${id}: reserve it with POST /v2/files.` }]);
|
|
460
|
+
const bytes = join(dir, `${id}.${BYTES}`);
|
|
461
|
+
await link(join(this.root, id, BYTES), bytes).catch(async (error) => {
|
|
462
|
+
if (error.code !== "EEXIST")
|
|
463
|
+
await copyFile(join(this.root, id, BYTES), bytes);
|
|
464
|
+
});
|
|
465
|
+
await writeDurable(join(dir, `${id}.json`), `${JSON.stringify(file)}\n`);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/** The files run `runId` holds (hold), in `ids`' order: a file with no hold (a run started before holds, or one whose
|
|
470
|
+
* hold went) read as it is now (readyFiles). With where each one's bytes are. */
|
|
471
|
+
async heldFiles(runId, ids) {
|
|
472
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
473
|
+
const held = new Map();
|
|
474
|
+
for (const id of ids) {
|
|
475
|
+
const record = ID.test(id) ? await readJson(join(dir, `${id}.json`)) : null;
|
|
476
|
+
if (isFile(record) && record.file_id === id && (await lstat(join(dir, `${id}.${BYTES}`)).catch(() => null))?.isFile())
|
|
477
|
+
held.set(id, record);
|
|
478
|
+
}
|
|
479
|
+
const live = await this.readyFiles(ids.filter((id) => !held.has(id)));
|
|
480
|
+
const now = new Map(live.map((file) => [file.file_id, file]));
|
|
481
|
+
return {
|
|
482
|
+
files: ids.map((id) => held.get(id) ?? now.get(id)),
|
|
483
|
+
bytesOf: (file) => (held.has(file.file_id) ? join(dir, `${file.file_id}.${BYTES}`) : join(this.root, file.file_id, BYTES)),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Lets go of run `runId`'s hold: once its files are in its workspace, or when it ends without them (released). */
|
|
487
|
+
async release(runId) {
|
|
488
|
+
await rm(join(this.root, HELD_DIR, runId), { recursive: true, force: true });
|
|
489
|
+
}
|
|
490
|
+
/** The run ids that hold files here (hold), for a start's sweep of the holds of runs that ended. */
|
|
491
|
+
async holders() {
|
|
492
|
+
return (await readdir(join(this.root, HELD_DIR)).catch(() => [])).filter((name) => ID.test(name));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
496
|
+
export const notCopied = (why) => `The run's files could not be copied into its workspace: ${why}`;
|
|
497
|
+
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
498
|
+
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
499
|
+
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
|
500
|
+
export async function copyRunFiles(data, runId, workspace, ids) {
|
|
501
|
+
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
502
|
+
const copied = await workspace.list(INPUTS_DIR).then(() => true, () => false);
|
|
503
|
+
if (!copied) {
|
|
504
|
+
try {
|
|
505
|
+
const { files, bytesOf } = await uploads.heldFiles(runId, ids);
|
|
506
|
+
await uploads.copyInto(workspace, files, bytesOf);
|
|
507
|
+
}
|
|
508
|
+
catch (error) {
|
|
509
|
+
// The run ends failed on this: its hold goes with it.
|
|
510
|
+
await uploads.release(runId).catch(() => undefined);
|
|
511
|
+
const why = error instanceof ApiError ? error.extra.fields?.map((issue) => issue.message).join("; ") || error.message : error.message;
|
|
512
|
+
throw new Error(notCopied(why), { cause: error });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
await uploads.release(runId);
|
|
443
516
|
}
|
|
444
517
|
/** The names in each folder of `workspace`, by its path, each read once from its listing (none for a folder not there
|
|
445
518
|
* yet) and kept up to date with what the copy takes. */
|
package/dist/usage-lines.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** A run's meters, from
|
|
1
|
+
/** A run's meters, from the one store (store-reads/cap.ts metersOverStore) or its live rows: each null when one of its charges is unknown. */
|
|
2
2
|
export type RunMeters = {
|
|
3
3
|
tools: number | null;
|
|
4
4
|
tokens: number | null;
|
package/dist/usage.d.ts
CHANGED
|
@@ -1,57 +1,11 @@
|
|
|
1
|
-
import { type Learning, type LearningReason, type Tokens } from "./learning.js";
|
|
2
|
-
/** On a line written since they were kept (learning.ts Learning): `seed_notes`, how many notes the run started from;
|
|
3
|
-
* `answered_at` and `job_cost_usd`, when its job's answer was final and what it had cost then, once it looked back;
|
|
4
|
-
* `look_back_usd`, what looking back cost (0 when it did not; null when unknown). */
|
|
5
|
-
export type Outcome = {
|
|
6
|
-
run: string;
|
|
7
|
-
agent: string;
|
|
8
|
-
state: "merged" | "dropped";
|
|
9
|
-
reason: LearningReason | null;
|
|
10
|
-
at: string;
|
|
11
|
-
cost: number | null;
|
|
12
|
-
tokens: Tokens | null;
|
|
13
|
-
seed_notes?: number;
|
|
14
|
-
given?: string[];
|
|
15
|
-
read?: string[];
|
|
16
|
-
answered_at?: string;
|
|
17
|
-
job_cost_usd?: number | null;
|
|
18
|
-
look_back_usd?: number | null;
|
|
19
|
-
};
|
|
20
|
-
/** A run's files as they are now, once its line is written: the latest one per run is what its line says. */
|
|
21
|
-
export type NotesLine = {
|
|
22
|
-
run: string;
|
|
23
|
-
agent: string;
|
|
24
|
-
notes: true;
|
|
25
|
-
given?: string[];
|
|
26
|
-
read?: string[];
|
|
27
|
-
};
|
|
28
|
-
type Ended = Learning & {
|
|
29
|
-
state: "merged" | "dropped";
|
|
30
|
-
};
|
|
31
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
32
|
-
export declare const ended: (learning: Learning | undefined | null) => learning is Ended;
|
|
33
1
|
/** The files of the notes a run was given and read; a list left with none is absent. */
|
|
34
2
|
export type NoteFiles = {
|
|
35
3
|
given?: string[];
|
|
36
4
|
read?: string[];
|
|
37
5
|
};
|
|
38
6
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
39
|
-
* shape never stops a reader
|
|
7
|
+
* shape never stops a reader. */
|
|
40
8
|
export declare const notesOf: (learning: {
|
|
41
9
|
given?: unknown;
|
|
42
10
|
read?: unknown;
|
|
43
11
|
}) => NoteFiles;
|
|
44
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
45
|
-
export declare const lineNotesOf: (line: {
|
|
46
|
-
given?: unknown;
|
|
47
|
-
read?: unknown;
|
|
48
|
-
}) => NoteFiles;
|
|
49
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
50
|
-
export declare const outcomeOf: (run: string, agent: string, learning: Ended) => Outcome;
|
|
51
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
52
|
-
* or out of shape, is skipped. */
|
|
53
|
-
export declare function outcomes(data: string): Promise<Map<string, Outcome>>;
|
|
54
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
55
|
-
* nothing after it. */
|
|
56
|
-
export declare const record: (data: string, line: Outcome | NotesLine) => Promise<void>;
|
|
57
|
-
export {};
|
package/dist/usage.js
CHANGED
|
@@ -1,90 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// /usage's `learning` meter reads from it what learning spent outside any run, so neither opens a run's files. A line
|
|
4
|
-
// holds the run, its agent, how its learning ended and when, how many notes it started from, when its answer was final
|
|
5
|
-
// and what its job and its look-back cost (GET /v2/agents/{id}/learning's `impact` reads these), and what its grade
|
|
6
|
-
// spent on the host after the run (the
|
|
7
|
-
// grader on the agent's model, and the injection screen when Jev is its judge), which is in no run's journal and no
|
|
8
|
-
// run's total: `cost` in dollars and `tokens`, each null when unknown, never 0, and 0 when nothing was graded. A run's
|
|
9
|
-
// learning ends once and never moves again, so a line is read once per run: one written again (a restart that found
|
|
10
|
-
// its run's end saved and its line maybe missing) is not counted twice. The notes a run was given and read are the one
|
|
11
|
-
// part that moves after (a follow-up reads another note): a `notes` line, the run's and its files only, says them anew,
|
|
12
|
-
// and the latest one wins; it never counts the run or its costs.
|
|
13
|
-
import { appendFile, readFile } from "node:fs/promises";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
import { LEARNING_REASONS, NO_TOKENS } from "./learning.js";
|
|
1
|
+
// A learning's notes as files: the notes a run was given and read (learning.ts Learning), each by its file, as the store's
|
|
2
|
+
// learning reads (store-reads/learning.ts) and a learning run (learning-run.ts) count them.
|
|
16
3
|
import { isObject } from "./validate.js";
|
|
17
|
-
const ledger = (data) => join(data, "learning-usage.jsonl");
|
|
18
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
19
|
-
export const ended = (learning) => learning?.state === "merged" || learning?.state === "dropped";
|
|
20
4
|
const filesOf = (source, fileOf) => {
|
|
21
5
|
const files = (list) => (Array.isArray(list) ? list.flatMap((entry) => { const file = fileOf(entry); return typeof file === "string" ? [file] : []; }) : []);
|
|
22
6
|
const [given, read] = [files(source.given), files(source.read)];
|
|
23
7
|
return { ...(given.length ? { given } : {}), ...(read.length ? { read } : {}) };
|
|
24
8
|
};
|
|
25
9
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
26
|
-
* shape never stops a reader
|
|
10
|
+
* shape never stops a reader. */
|
|
27
11
|
export const notesOf = (learning) => filesOf(learning, (entry) => (isObject(entry) ? entry.file : undefined));
|
|
28
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
29
|
-
export const lineNotesOf = (line) => filesOf(line, (entry) => entry);
|
|
30
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
31
|
-
export const outcomeOf = (run, agent, learning) => ({
|
|
32
|
-
run, agent, state: learning.state, reason: learning.reason, at: learning.at,
|
|
33
|
-
...(learning.cost_usd ? { cost: learning.cost_usd.grade, tokens: learning.tokens?.grade ?? null } : { cost: 0, tokens: { ...NO_TOKENS } }),
|
|
34
|
-
...(isCount(learning.seed_notes) ? { seed_notes: learning.seed_notes } : {}),
|
|
35
|
-
// The files of the notes it was given and read (learning.ts Learning), so an agent's notes count their runs after it ends.
|
|
36
|
-
...notesOf(learning),
|
|
37
|
-
...(learning.answered_at === undefined ? { look_back_usd: 0 } : { answered_at: learning.answered_at, job_cost_usd: learning.job_cost_usd ?? null, look_back_usd: learning.look_back_usd ?? null }),
|
|
38
|
-
});
|
|
39
|
-
const isUsd = (value) => value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
|
|
40
|
-
const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
41
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
42
|
-
* or out of shape, is skipped. */
|
|
43
|
-
export async function outcomes(data) {
|
|
44
|
-
const text = await readFile(ledger(data), "utf8").catch((error) => (error.code === "ENOENT" ? "" : Promise.reject(error)));
|
|
45
|
-
const out = new Map();
|
|
46
|
-
const latest = new Map();
|
|
47
|
-
for (const line of text.split("\n")) {
|
|
48
|
-
let entry;
|
|
49
|
-
try {
|
|
50
|
-
entry = JSON.parse(line);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (isObject(entry) && entry.notes === true && typeof entry.run === "string") {
|
|
56
|
-
latest.set(entry.run, lineNotesOf(entry));
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (!isObject(entry) || typeof entry.run !== "string" || typeof entry.agent !== "string" || typeof entry.at !== "string")
|
|
60
|
-
continue;
|
|
61
|
-
if ((entry.state !== "merged" && entry.state !== "dropped") || !(entry.reason === null || LEARNING_REASONS.includes(entry.reason)))
|
|
62
|
-
continue;
|
|
63
|
-
if (!(entry.cost === null || typeof entry.cost === "number"))
|
|
64
|
-
continue;
|
|
65
|
-
if (entry.seed_notes !== undefined && !isCount(entry.seed_notes))
|
|
66
|
-
delete entry.seed_notes;
|
|
67
|
-
for (const key of ["given", "read"])
|
|
68
|
-
if (entry[key] !== undefined && !(Array.isArray(entry[key]) && entry[key].every((file) => typeof file === "string")))
|
|
69
|
-
delete entry[key];
|
|
70
|
-
if (entry.answered_at !== undefined && (typeof entry.answered_at !== "string" || !Date.parse(entry.answered_at)))
|
|
71
|
-
delete entry.answered_at;
|
|
72
|
-
for (const key of ["job_cost_usd", "look_back_usd"])
|
|
73
|
-
if (entry[key] !== undefined && !isUsd(entry[key]))
|
|
74
|
-
delete entry[key];
|
|
75
|
-
if (!out.has(entry.run))
|
|
76
|
-
out.set(entry.run, entry);
|
|
77
|
-
}
|
|
78
|
-
for (const [run, files] of latest) {
|
|
79
|
-
const outcome = out.get(run);
|
|
80
|
-
if (!outcome)
|
|
81
|
-
continue;
|
|
82
|
-
delete outcome.given;
|
|
83
|
-
delete outcome.read;
|
|
84
|
-
Object.assign(outcome, files);
|
|
85
|
-
}
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
89
|
-
* nothing after it. */
|
|
90
|
-
export const record = (data, line) => appendFile(ledger(data), `\n${JSON.stringify(line)}\n`, { mode: 0o600 });
|
package/dist/validate.d.ts
CHANGED
|
@@ -9,10 +9,18 @@ export declare const isObject: (value: unknown) => value is Json;
|
|
|
9
9
|
export declare const IDEMPOTENCY_TTL_S = 86400;
|
|
10
10
|
export declare const stable: (value: unknown) => string;
|
|
11
11
|
export declare const DEFINITION_FIELDS: string[];
|
|
12
|
+
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
13
|
+
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
14
|
+
* `repo/`; `none` clears it on an edit. */
|
|
15
|
+
export declare const CHECKOUTS: readonly ["pull_request", "none"];
|
|
12
16
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
13
17
|
export declare const NOT_KEPT: Record<string, string>;
|
|
18
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
19
|
+
export declare const MAX_TOOL_CALLS = 1000;
|
|
14
20
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
15
21
|
export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
|
|
22
|
+
/** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
|
|
23
|
+
export declare const MODEL_TIER_NAMES: readonly ["fast", "strong"];
|
|
16
24
|
/** `provider/model-id`. */
|
|
17
25
|
export declare const MODEL_REF: RegExp;
|
|
18
26
|
/** A body's fields that `allowed` does not name, each as the 422's not_allowed issue. */
|
package/dist/validate.js
CHANGED
|
@@ -17,13 +17,21 @@ export const isObject = (value) => typeof value === "object" && value !== null &
|
|
|
17
17
|
/** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
|
|
18
18
|
export const IDEMPOTENCY_TTL_S = 86_400;
|
|
19
19
|
export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
|
|
20
|
-
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema"];
|
|
20
|
+
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls", "checkout"];
|
|
21
|
+
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
22
|
+
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
23
|
+
* `repo/`; `none` clears it on an edit. */
|
|
24
|
+
export const CHECKOUTS = ["pull_request", "none"];
|
|
21
25
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
22
26
|
export const NOT_KEPT = {
|
|
23
27
|
input_schema: "The agent store keeps no input_schema: an agentic run takes {content}, and a workflow checks its input against its own schema.",
|
|
24
28
|
};
|
|
29
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
30
|
+
export const MAX_TOOL_CALLS = 1_000;
|
|
25
31
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
26
32
|
export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
|
|
33
|
+
/** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
|
|
34
|
+
export const MODEL_TIER_NAMES = ["fast", "strong"];
|
|
27
35
|
/** `provider/model-id`. */
|
|
28
36
|
export const MODEL_REF = /^[^/\s]+\/\S+$/;
|
|
29
37
|
const SKILL_FILE = "/SKILL.md";
|
|
@@ -77,6 +85,20 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
77
85
|
else if (typeof d.model !== "string" || !MODEL_REF.test(d.model))
|
|
78
86
|
out.push(issue(`${at}.model`, "bad_format", `${at}.model is "provider/model-id"`));
|
|
79
87
|
}
|
|
88
|
+
if (d.model_tiers !== undefined) {
|
|
89
|
+
if (d.workflow !== undefined)
|
|
90
|
+
out.push(issue(`${at}.model_tiers`, "not_allowed", "A workflow revision keeps no model tiers: each model node names its tier, run on this host's model for it.", `Remove ${at}.model_tiers.`));
|
|
91
|
+
else if (!isObject(d.model_tiers) || !Object.keys(d.model_tiers).length)
|
|
92
|
+
out.push(issue(`${at}.model_tiers`, "wrong_type", `${at}.model_tiers is an object of ${MODEL_TIER_NAMES.join(", ")} to "provider/model-id"`));
|
|
93
|
+
else {
|
|
94
|
+
for (const [tier, ref] of Object.entries(d.model_tiers)) {
|
|
95
|
+
if (!MODEL_TIER_NAMES.includes(tier))
|
|
96
|
+
out.push(issue(`${at}.model_tiers.${tier}`, "not_allowed", `${at}.model_tiers names ${MODEL_TIER_NAMES.join(" and ")} alone`, `Remove ${at}.model_tiers.${tier}.`));
|
|
97
|
+
else if (typeof ref !== "string" || !MODEL_REF.test(ref))
|
|
98
|
+
out.push(issue(`${at}.model_tiers.${tier}`, "bad_format", `${at}.model_tiers.${tier} is "provider/model-id"`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
80
102
|
if (d.harness !== undefined && !HARNESSES.includes(d.harness))
|
|
81
103
|
out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${HARNESSES.join(", ")}`));
|
|
82
104
|
if (d.place !== undefined)
|
|
@@ -92,8 +114,8 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
92
114
|
if (d.learning !== undefined) {
|
|
93
115
|
if (d.workflow !== undefined)
|
|
94
116
|
out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
|
|
95
|
-
else if (typeof d.learning !== "boolean")
|
|
96
|
-
out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true or
|
|
117
|
+
else if (typeof d.learning !== "boolean" && d.learning !== "notes")
|
|
118
|
+
out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true, false or "notes": true learns notes, skills and workflows, "notes" notes and skills alone`));
|
|
97
119
|
}
|
|
98
120
|
// An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
|
|
99
121
|
// completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
|
|
@@ -130,6 +152,21 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
130
152
|
if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
|
|
131
153
|
out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
|
|
132
154
|
}
|
|
155
|
+
// The server's checkout before each run's first turn: kept by an edit that leaves it out, cleared by `none`.
|
|
156
|
+
if (d.checkout !== undefined) {
|
|
157
|
+
if (d.workflow !== undefined)
|
|
158
|
+
out.push(issue(`${at}.checkout`, "not_allowed", "A workflow revision keeps no checkout: only an agentic run starts in a checkout.", `Remove ${at}.checkout.`));
|
|
159
|
+
else if (!CHECKOUTS.includes(d.checkout))
|
|
160
|
+
out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
|
|
161
|
+
}
|
|
162
|
+
// The tool calls each conversation of an agentic run may make (tool-budget.ts): above 0 sets the budget, 0 clears it, and
|
|
163
|
+
// an edit that leaves it out keeps the agent's, as the default cap is kept.
|
|
164
|
+
if (d.max_tool_calls !== undefined) {
|
|
165
|
+
if (d.workflow !== undefined)
|
|
166
|
+
out.push(issue(`${at}.max_tool_calls`, "not_allowed", "A workflow revision keeps no tool-call budget: its nodes are its steps.", `Remove ${at}.max_tool_calls.`));
|
|
167
|
+
else if (!(Number.isSafeInteger(d.max_tool_calls) && d.max_tool_calls >= 0 && d.max_tool_calls <= MAX_TOOL_CALLS))
|
|
168
|
+
out.push(issue(`${at}.max_tool_calls`, "wrong_type", `${at}.max_tool_calls is a whole number from 0 to ${MAX_TOOL_CALLS}: above 0, the tool calls each conversation of a run may make before every further call is refused with words that say to answer now; 0 clears it`));
|
|
169
|
+
}
|
|
133
170
|
// How a run's cap prices its requests (cap.ts CapMode): kept, as the default cap is, by an edit that leaves it out.
|
|
134
171
|
if (d.cap_mode !== undefined) {
|
|
135
172
|
if (!CAP_MODES.includes(d.cap_mode))
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export type WebhookSecret = Pick<SealedSettingsOverStore, "get" | "mint" | "remo
|
|
|
58
58
|
export { signatureOf } from "./standard-webhooks.js";
|
|
59
59
|
/** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
|
|
60
60
|
* so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
|
|
61
|
-
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
|
|
61
|
+
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
|
|
62
62
|
* was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
|
|
63
63
|
* row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
|
|
64
64
|
* marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
|
|
@@ -71,6 +71,7 @@ export declare function waitMarkerOf(rows: readonly {
|
|
|
71
71
|
id?: unknown;
|
|
72
72
|
at?: unknown;
|
|
73
73
|
asked_at?: unknown;
|
|
74
|
+
cap_usd?: unknown;
|
|
74
75
|
} | null | undefined, waiting: boolean, learningLabel: string): string | undefined;
|
|
75
76
|
export declare class Webhooks {
|
|
76
77
|
private readonly store;
|
package/dist/webhooks.js
CHANGED
|
@@ -55,7 +55,7 @@ function configOf(value) {
|
|
|
55
55
|
}
|
|
56
56
|
/** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
|
|
57
57
|
* so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
|
|
58
|
-
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
|
|
58
|
+
* asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
|
|
59
59
|
* was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
|
|
60
60
|
* row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
|
|
61
61
|
* marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
|
|
@@ -66,8 +66,11 @@ export function waitMarkerOf(rows, pending, waiting, learningLabel) {
|
|
|
66
66
|
const kind = pending?.kind;
|
|
67
67
|
if (kind === "approval" && typeof pending?.id === "string")
|
|
68
68
|
return `approval:${pending.id}`;
|
|
69
|
+
// A pause at the cap, by when it came and the cap it waits at: waits at one cap are one pause, told once, and a raise that
|
|
70
|
+
// still does not cover the step pauses the run anew at the higher cap, told again (the runner writes no row for the
|
|
71
|
+
// refused step, so its time alone would not move).
|
|
69
72
|
if (kind === "budget" && typeof pending?.at === "string")
|
|
70
|
-
return `budget:${pending.at}`;
|
|
73
|
+
return `budget:${pending.at}${typeof pending.cap_usd === "number" ? `:${pending.cap_usd}` : ""}`;
|
|
71
74
|
if ((kind === "browser" || kind === "computer") && typeof pending?.asked_at === "string")
|
|
72
75
|
return `${kind}:${pending.asked_at}`;
|
|
73
76
|
return rows.findLast((r) => r.kind === "waiting")?.id ?? last();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type DecisionExchange, type DecisionReceipt } from "@parcha/agentrun-dsl";
|
|
2
|
+
import type { DocumentReader } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { WorkflowInvocation } from "./task.js";
|
|
4
|
+
type Context = WorkflowInvocation["context"];
|
|
5
|
+
/** The interpreter's two decision hooks over one invocation of a workflow task. */
|
|
6
|
+
export type DecisionRecovery = {
|
|
7
|
+
/** The interpreter's `recordDecision`: commits the receipt's row after every row recorded before it, and resolves
|
|
8
|
+
* once that commit is durable; a commit that fails rejects this receipt's call. The task's state is untouched. */
|
|
9
|
+
recordDecision(receipt: DecisionReceipt, exchange: DecisionExchange): Promise<void>;
|
|
10
|
+
/** The interpreter's `recovery.decision`: the receipt rebuilt from the last answered row this run recorded under
|
|
11
|
+
* `id`, or undefined when it recorded none (a request that failed, one recorded without its identity, or one another
|
|
12
|
+
* run recorded, is asked again). */
|
|
13
|
+
decision(id: string): Promise<DecisionReceipt | undefined>;
|
|
14
|
+
};
|
|
15
|
+
/** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
|
|
16
|
+
* handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
|
|
17
|
+
* `recovery.decision` beside the driver's recovery hooks. */
|
|
18
|
+
export declare function decisionRecovery(invocation: {
|
|
19
|
+
key: string;
|
|
20
|
+
runtime: Pick<WorkflowInvocation["runtime"], "commit"> & DocumentReader;
|
|
21
|
+
context: Context;
|
|
22
|
+
}): DecisionRecovery;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// A workflow task's decision receipts, durable in its run's Session: each receipt is a row (decisions.ts) committed
|
|
2
|
+
// through the task's own commit before the interpreter acts on its answers, and a resumed run's request is answered
|
|
3
|
+
// from the row its earlier process committed, so the judge is not asked again and the run decides what it decided.
|
|
4
|
+
// Every run in the Session shares the rows' document, and a receipt's id does not name its run, so each row carries
|
|
5
|
+
// the run's key and a run is answered only from its own rows.
|
|
6
|
+
import { DECISION_RECEIPT_VERSION } from "@parcha/agentrun-dsl";
|
|
7
|
+
import { appendDecision, DECISION_ROW_VERSION, readDecisionsFrom } from "./decisions.js";
|
|
8
|
+
/** What a receipt says of its provider beside its answers, each only when present: who answered, the sources, the
|
|
9
|
+
* questions refused, where each confidence came from, the images it carried and the state the judge saw. A replay gives the run all of it again. */
|
|
10
|
+
const kept = (from) => ({
|
|
11
|
+
...(from.provider !== undefined ? { provider: from.provider } : {}),
|
|
12
|
+
...(from.images !== undefined ? { images: from.images } : {}),
|
|
13
|
+
...(from.cost_basis !== undefined ? { cost_basis: from.cost_basis } : {}),
|
|
14
|
+
...(from.state !== undefined ? { state: from.state, state_truncated: from.state_truncated === true } : {}),
|
|
15
|
+
...(from.evidence !== undefined ? { evidence: from.evidence } : {}),
|
|
16
|
+
...(from.refused !== undefined ? { refused: from.refused } : {}),
|
|
17
|
+
...(from.confidence_source !== undefined ? { confidence_source: from.confidence_source } : {}),
|
|
18
|
+
});
|
|
19
|
+
/** A receipt as the row the run `key` stores: the receipt's own fields, its identity, and the request's size. */
|
|
20
|
+
function rowOf(receipt, exchange, key) {
|
|
21
|
+
return {
|
|
22
|
+
v: DECISION_ROW_VERSION, at: receipt.at, node: receipt.node, kind: receipt.kind, item: receipt.item, execution_path: receipt.execution_path,
|
|
23
|
+
request_sha256: receipt.request_sha256,
|
|
24
|
+
request_bytes: Buffer.byteLength(JSON.stringify({ state: exchange.request.state, questions: exchange.request.questions })),
|
|
25
|
+
model: receipt.model, questions: receipt.questions, answers: receipt.answers, rule: receipt.rule, action: receipt.action,
|
|
26
|
+
usage: receipt.usage, cost_usd: receipt.cost_usd, latency_ms: receipt.latency_ms,
|
|
27
|
+
// An error the receipt kept cut says so, and the row keeps saying it: a host holds its tail back (serve graph-served.ts).
|
|
28
|
+
...(receipt.error !== undefined ? { error: receipt.error, ...(receipt.error_truncated === true ? { error_truncated: true } : {}) } : {}),
|
|
29
|
+
status: receipt.status, ...kept(receipt),
|
|
30
|
+
decision_id: receipt.id, request: receipt.request, state_sha256: receipt.state_sha256, run_key: key,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The receipt the run `key`'s last answered row under `id` is: a rule is set only on an answered receipt, and an
|
|
34
|
+
* answered one carries no error. */
|
|
35
|
+
function answeredReceipt(rows, id, key) {
|
|
36
|
+
const row = rows.findLast((stored) => stored.run_key === key && stored.decision_id === id && stored.rule !== null && stored.error === undefined
|
|
37
|
+
&& stored.request !== undefined && stored.state_sha256 !== undefined && stored.execution_path !== null);
|
|
38
|
+
if (!row)
|
|
39
|
+
return undefined;
|
|
40
|
+
return {
|
|
41
|
+
v: DECISION_RECEIPT_VERSION, id, at: row.at, node: row.node, kind: row.kind, item: row.item, execution_path: row.execution_path,
|
|
42
|
+
request: row.request, status: "answered", state_sha256: row.state_sha256,
|
|
43
|
+
questions: row.questions, answers: row.answers, rule: row.rule, action: row.action,
|
|
44
|
+
model: row.model, usage: row.usage, cost_usd: row.cost_usd, request_sha256: row.request_sha256, latency_ms: row.latency_ms,
|
|
45
|
+
...kept(row),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
|
|
49
|
+
* handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
|
|
50
|
+
* `recovery.decision` beside the driver's recovery hooks. */
|
|
51
|
+
export function decisionRecovery(invocation) {
|
|
52
|
+
const { key, runtime, context } = invocation;
|
|
53
|
+
const harness = {
|
|
54
|
+
commit: async (change) => {
|
|
55
|
+
let result;
|
|
56
|
+
await runtime.commit(async (tx) => { result = await change(tx); return undefined; }, context);
|
|
57
|
+
return result;
|
|
58
|
+
},
|
|
59
|
+
// The form the store holds is settled once per invocation, from this reader: the run's open.
|
|
60
|
+
snapshot: ((...args) => runtime.snapshot(...args)),
|
|
61
|
+
};
|
|
62
|
+
// The run's rows as read so far: a resumed process reads the store once, and each later answer reads only the rows after them.
|
|
63
|
+
const known = [];
|
|
64
|
+
let next = 0;
|
|
65
|
+
let chain = Promise.resolve();
|
|
66
|
+
return {
|
|
67
|
+
recordDecision(receipt, exchange) {
|
|
68
|
+
const row = rowOf(receipt, exchange, key);
|
|
69
|
+
const committed = chain.then(() => appendDecision(harness, row, context));
|
|
70
|
+
chain = committed.catch(() => undefined);
|
|
71
|
+
return committed;
|
|
72
|
+
},
|
|
73
|
+
async decision(id) {
|
|
74
|
+
const read = await readDecisionsFrom(harness, next, context);
|
|
75
|
+
known.push(...read.rows);
|
|
76
|
+
next = read.next;
|
|
77
|
+
return answeredReceipt(known, id, key);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|