@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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { configure, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
|
+
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
3
|
+
import { ASK_TOOL } from "../tools.js";
|
|
4
|
+
import { HOST_TOOL_OUTPUT } from "./adapters/pi.js";
|
|
5
|
+
import { cutAtLimit } from "./loop-contract.js";
|
|
6
|
+
import { PI_STOP } from "./pi-stop.js";
|
|
7
|
+
import { budgetOf, ConversationToolBudget } from "../tool-budget.js";
|
|
8
|
+
export const SUBAGENT_TOOL = "subagent";
|
|
9
|
+
/** The tiers a call may name for its child (its definition's model_tiers, else this server's tier); a call that names
|
|
10
|
+
* none runs its child on the agent's own model. */
|
|
11
|
+
export const SUBAGENT_TIERS = ["fast", "strong"];
|
|
12
|
+
/** How many of a run's children work at once; a call past it waits for a slot. */
|
|
13
|
+
export const SUBAGENT_PARALLEL = 4;
|
|
14
|
+
/** Tools no child is given: a subagent of its own (depth 1), and the person, whom only the run's own conversation asks. */
|
|
15
|
+
const NEVER_GIVEN = [SUBAGENT_TOOL, ASK_TOOL];
|
|
16
|
+
/** A child's instructions: the call's prompt is its whole task. Nothing of the parent's prompt is carried over. */
|
|
17
|
+
export const SUBAGENT_INSTRUCTIONS = "You are a subagent. The message you are given is your whole task: do it with the tools you have, then answer. Your last message is returned, as it is, to the agent that called you.";
|
|
18
|
+
/** The thinking levels a call may give its child (`effort`); absent, the child thinks at the agent's own level. */
|
|
19
|
+
export const SUBAGENT_EFFORTS = ["low", "medium", "high"];
|
|
20
|
+
/** One counter of free slots for the run's children (SUBAGENT_PARALLEL), handed out in call order. */
|
|
21
|
+
function slots(count) {
|
|
22
|
+
let free = count;
|
|
23
|
+
const waiting = [];
|
|
24
|
+
return {
|
|
25
|
+
async take(signal) {
|
|
26
|
+
if (free > 0)
|
|
27
|
+
free -= 1;
|
|
28
|
+
else {
|
|
29
|
+
await new Promise((resolve, reject) => {
|
|
30
|
+
const go = () => {
|
|
31
|
+
signal?.removeEventListener("abort", stop);
|
|
32
|
+
resolve();
|
|
33
|
+
};
|
|
34
|
+
const stop = () => {
|
|
35
|
+
const at = waiting.indexOf(go);
|
|
36
|
+
if (at >= 0)
|
|
37
|
+
waiting.splice(at, 1);
|
|
38
|
+
reject(signal?.reason ?? new Error("aborted"));
|
|
39
|
+
};
|
|
40
|
+
waiting.push(go);
|
|
41
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
let given = false;
|
|
45
|
+
return () => {
|
|
46
|
+
if (given)
|
|
47
|
+
return;
|
|
48
|
+
given = true;
|
|
49
|
+
const next = waiting.shift();
|
|
50
|
+
if (next)
|
|
51
|
+
next();
|
|
52
|
+
else
|
|
53
|
+
free += 1;
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The text of an assistant message: its text parts, joined. */
|
|
59
|
+
const textOf = (message) => Array.isArray(message?.content) ? message.content.map((part) => (part?.type === "text" ? (part.text ?? "") : "")).join("") : typeof message?.content === "string" ? message.content : "";
|
|
60
|
+
/** `text` within the host's bound on a tool result (HOST_RESULT_MAX_CHARS), saying where it was cut. */
|
|
61
|
+
export function boundedAnswer(text) {
|
|
62
|
+
if (text.length <= HOST_RESULT_MAX_CHARS)
|
|
63
|
+
return text;
|
|
64
|
+
const note = `\n[the subagent's answer was cut at ${HOST_RESULT_MAX_CHARS.toLocaleString("en-US")} of its ${text.length.toLocaleString("en-US")} characters]`;
|
|
65
|
+
return text.slice(0, HOST_RESULT_MAX_CHARS - note.length) + note;
|
|
66
|
+
}
|
|
67
|
+
/** The catalog names of `asked` (each a catalog or session name of a granted tool) and the session names the child gets,
|
|
68
|
+
* or what is wrong with them. A catalog name gives every session name of its tool (`browser`: each browser tool); a
|
|
69
|
+
* session name gives that one alone (`browser_read`: never the rest of the browser's). */
|
|
70
|
+
export function chosenTools(asked, options) {
|
|
71
|
+
const catalog = [];
|
|
72
|
+
const names = [];
|
|
73
|
+
const offered = options.granted.filter((name) => !NEVER_GIVEN.includes(name));
|
|
74
|
+
for (const name of asked) {
|
|
75
|
+
if (NEVER_GIVEN.includes(name))
|
|
76
|
+
return { refused: `subagent: a subagent is never given ${name}${name === SUBAGENT_TOOL ? " (subagents go one level deep)" : " (only the run itself asks its person)"}. Nothing ran.` };
|
|
77
|
+
const found = options.granted.find((granted) => granted === name || options.sessionNames(granted).includes(name));
|
|
78
|
+
if (found === undefined)
|
|
79
|
+
return { refused: `subagent: ${name} is not one of this agent's tools, so no subagent may have it. A subagent may be given ${offered.length ? offered.join(", ") : "no tool here"}. Nothing ran.` };
|
|
80
|
+
if (!catalog.includes(found))
|
|
81
|
+
catalog.push(found);
|
|
82
|
+
for (const session of found === name ? options.sessionNames(found) : [name])
|
|
83
|
+
if (!names.includes(session))
|
|
84
|
+
names.push(session);
|
|
85
|
+
}
|
|
86
|
+
return { catalog, names };
|
|
87
|
+
}
|
|
88
|
+
/** The subagent tool: one of the session's own tools (adapters/pi.ts `tools`), so it needs no extension of its own. */
|
|
89
|
+
export function subagentTool(options) {
|
|
90
|
+
const free = slots(SUBAGENT_PARALLEL);
|
|
91
|
+
return defineTool({
|
|
92
|
+
name: SUBAGENT_TOOL,
|
|
93
|
+
description: `Run a subagent: a fresh conversation that starts with nothing but your prompt, on your own model (or the model tier you name: ${SUBAGENT_TIERS.join(" or ")}), with only the tools you list (a subset of your own), and get its final answer back as text. Write the prompt self-contained: the subagent sees none of your conversation. Several calls in one turn run at once, at most ${SUBAGENT_PARALLEL} at a time; more wait their turn. A subagent cannot start subagents of its own.`,
|
|
94
|
+
parameters: {
|
|
95
|
+
type: "object",
|
|
96
|
+
additionalProperties: false,
|
|
97
|
+
properties: {
|
|
98
|
+
prompt: { type: "string", minLength: 1, description: "The subagent's whole task, self-contained: it sees nothing else." },
|
|
99
|
+
tools: { type: "array", items: { type: "string" }, uniqueItems: true, description: "The tools it may use, each one of your own tools by name. Absent or empty: none." },
|
|
100
|
+
model: { enum: [...SUBAGENT_TIERS], description: "The model tier it runs on, one of this agent's own tiers. Absent: your own model." },
|
|
101
|
+
max_tool_calls: { type: "integer", minimum: 1, description: "The most tool calls it may make. It narrows your own budget for it, never widens it. Absent: your budget." },
|
|
102
|
+
effort: { enum: [...SUBAGENT_EFFORTS], description: "How hard it thinks: low, medium or high. Absent: as you do." },
|
|
103
|
+
},
|
|
104
|
+
required: ["prompt"],
|
|
105
|
+
},
|
|
106
|
+
// A rerun after a crash finds the same child (it is owned by this call's task) and the same submission (its request
|
|
107
|
+
// id), so the child's work is never started twice.
|
|
108
|
+
replay: "safe",
|
|
109
|
+
executionMode: "parallel",
|
|
110
|
+
outputLimits: HOST_TOOL_OUTPUT,
|
|
111
|
+
execute: async (given, api, context) => {
|
|
112
|
+
const args = given;
|
|
113
|
+
const fail = (text) => ({ output: [{ type: "text", text }], isError: true });
|
|
114
|
+
// Depth 1: a child is never offered subagent (its tools are the call's subset, NEVER_GIVEN aside); and only the run's
|
|
115
|
+
// own conversation calls it.
|
|
116
|
+
if (Number(api.conversationId) !== Number(ROOT_CONVERSATION_ID))
|
|
117
|
+
return fail("subagent: a subagent cannot start subagents of its own. Nothing ran.");
|
|
118
|
+
const model = args.model === undefined ? undefined : options.tier(args.model);
|
|
119
|
+
if (model && "why" in model)
|
|
120
|
+
return fail(`subagent: the ${args.model} tier has no model here: ${model.why} Nothing ran.`);
|
|
121
|
+
if (args.max_tool_calls !== undefined && !(Number.isSafeInteger(args.max_tool_calls) && args.max_tool_calls > 0))
|
|
122
|
+
return fail("subagent: max_tool_calls is a whole number above 0. Nothing ran.");
|
|
123
|
+
if (args.effort !== undefined && !SUBAGENT_EFFORTS.includes(args.effort))
|
|
124
|
+
return fail(`subagent: effort is one of ${SUBAGENT_EFFORTS.join(", ")}. Nothing ran.`);
|
|
125
|
+
// The child's own budget: the call's, held under the agent's (never wider); absent, the agent's holds it as it holds
|
|
126
|
+
// every conversation of the run.
|
|
127
|
+
const toolCalls = args.max_tool_calls === undefined ? undefined : budgetOf(options.toolCalls, args.max_tool_calls);
|
|
128
|
+
const chosen = chosenTools(args.tools ?? [], options);
|
|
129
|
+
if ("refused" in chosen)
|
|
130
|
+
return fail(chosen.refused);
|
|
131
|
+
// The registrations the parent's agent enables, by session name: exactly the ones the call named are the child's.
|
|
132
|
+
const names = new Set(chosen.names);
|
|
133
|
+
const parent = await api.agent(context);
|
|
134
|
+
const tools = parent.tools.filter((registration) => names.has(registration.name));
|
|
135
|
+
const missing = [...names].filter((name) => !tools.some((registration) => registration.name === name));
|
|
136
|
+
if (missing.length)
|
|
137
|
+
return fail(`subagent: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not bound in this run, so no subagent may have ${missing.length === 1 ? "it" : "them"}. Nothing ran.`);
|
|
138
|
+
const release = await free.take(context.abortSignal);
|
|
139
|
+
try {
|
|
140
|
+
const child = await api.commit(async (tx) => {
|
|
141
|
+
// The ownership index remembers the child: a rerun of this call reuses it.
|
|
142
|
+
const existing = (await tx.scanConversations({ ownerTaskId: api.taskId }, 1)).items[0];
|
|
143
|
+
if (existing !== undefined)
|
|
144
|
+
return existing.id;
|
|
145
|
+
const created = await tx.createConversation({ ownership: { kind: "task", taskId: api.taskId } });
|
|
146
|
+
await configure(tx, created.id, {
|
|
147
|
+
// The tier's model, else the parent's own (its route through the session's proxy and booking).
|
|
148
|
+
// The child keeps the session's extension (its gate); its tools are exactly the call's subset.
|
|
149
|
+
model: model?.ref ?? parent.model,
|
|
150
|
+
// The call's effort, else the agent's own level (a task-owned conversation copies its owner's agent).
|
|
151
|
+
...(args.effort ? { thinkingLevel: args.effort } : {}),
|
|
152
|
+
tools: tools,
|
|
153
|
+
modelTools: null,
|
|
154
|
+
instructions: [options.preamble, SUBAGENT_INSTRUCTIONS].filter(Boolean).join("\n\n"),
|
|
155
|
+
});
|
|
156
|
+
if (toolCalls !== undefined)
|
|
157
|
+
Object.assign(await tx.doc(ConversationToolBudget, created.id), { toolCalls });
|
|
158
|
+
return created.id;
|
|
159
|
+
}, context);
|
|
160
|
+
// The call's details name its child: the run's timeline nests the child's rows under this call.
|
|
161
|
+
const details = { conversationId: Number(child), ...(args.model ? { model: args.model } : {}), tools: chosen.catalog, ...(toolCalls !== undefined ? { max_tool_calls: toolCalls } : {}), ...(args.effort ? { effort: args.effort } : {}) };
|
|
162
|
+
await api.details(details, context);
|
|
163
|
+
const handle = await api.conversation(child, context);
|
|
164
|
+
if (!handle)
|
|
165
|
+
return { ...fail("subagent: its conversation could not be opened. Nothing ran."), details };
|
|
166
|
+
const submission = await handle.submit({ type: "input", content: args.prompt, requestId: `subagent:${String(api.taskId)}` }, context);
|
|
167
|
+
const settled = await submission.wait(context);
|
|
168
|
+
if (settled.status === "done" && settled.answer !== undefined) {
|
|
169
|
+
const answer = await api.commit((tx) => tx.entry(settled.answer), context);
|
|
170
|
+
const message = answer?.model?.findLast((each) => each.role === "assistant");
|
|
171
|
+
const text = textOf(message);
|
|
172
|
+
// An answer cut at the model's output limit is unfinished (as the run's own is: loop.ts cutLast): an error the
|
|
173
|
+
// parent reads, with what the child said before the cut.
|
|
174
|
+
if (message?.stopReason === PI_STOP.length)
|
|
175
|
+
return { ...fail(boundedAnswer(`subagent: its answer is unfinished: ${cutAtLimit(message.usage?.output)}${text ? `\nWhat it wrote before the cut:\n${text}` : ""}`)), details };
|
|
176
|
+
return { output: [{ type: "text", text: boundedAnswer(text || "(the subagent answered with no text)") }], details };
|
|
177
|
+
}
|
|
178
|
+
// Unanswered: its own words for why (a request the cap refused, a provider's error), from its last answer.
|
|
179
|
+
const last = await api.commit(async (tx) => (await tx.scanEntries({ conversationId: child, order: "descending" }, 20)).items.flatMap((entry) => entry.model ?? []).find((each) => each.role === "assistant"), context);
|
|
180
|
+
const why = last?.errorMessage ?? settled.reason ?? "it stopped";
|
|
181
|
+
return { ...fail(boundedAnswer(`subagent: it stopped before it answered: ${why}`)), details };
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
release();
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Extension } from "@earendil-works/pi-durable";
|
|
2
|
-
import { type WorkflowTaskHost } from "
|
|
2
|
+
import { type WorkflowTaskHost } from "../workflow/task.js";
|
|
3
3
|
/** A model node's tier, as the DSL names it. */
|
|
4
4
|
export type NodeTier = string | undefined;
|
|
5
5
|
/** A node tool's bindings for a model node's agent (its pi extensions and tools), as the node-tool table binds them. */
|
|
@@ -30,6 +30,8 @@ export interface DecisionDriver {
|
|
|
30
30
|
decisionRequests(): Record<string, {
|
|
31
31
|
status: string;
|
|
32
32
|
}>;
|
|
33
|
+
/** Resolves once the driver's commits so far are durable (a request it ended, before the run parks on it). */
|
|
34
|
+
flush(): Promise<void>;
|
|
33
35
|
}
|
|
34
36
|
/** The run's spend cap over the workflow's adapters (app.ts's budget: stepped/failing/capStopped and the decision cap),
|
|
35
37
|
* injected so this module holds no money of its own. Each wrapper is applied to its adapter where app.ts applied it; a run
|
|
@@ -38,11 +40,18 @@ export interface DecisionDriver {
|
|
|
38
40
|
export interface WorkflowCap {
|
|
39
41
|
/** stepped(gate(capStopped(·)), true): a model node, counted in flight, failing as a cap stop where no raise fixes it. */
|
|
40
42
|
node<F>(fn: F): F;
|
|
41
|
-
/** stepped(failing(·)): a call node,
|
|
43
|
+
/** stepped(failing(·)): a call node, before the driver admits its effect: it waits for a raise on a held effect and
|
|
44
|
+
* goes again. */
|
|
42
45
|
effect<F>(fn: F): F;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
46
|
+
/** A call node's effect once the driver has admitted it: held through the kernel cap, run, and settled. Absent: the
|
|
47
|
+
* effect runs as given. */
|
|
48
|
+
admittedEffect?<F>(fn: F): F;
|
|
49
|
+
/** A decision, before the driver admits its request: priced, or parked by a pause. The driver tells a replayed request,
|
|
50
|
+
* which holds nothing. */
|
|
45
51
|
judge<F>(fn: F, driver?: DecisionDriver): F;
|
|
52
|
+
/** A decision's judge once the driver has admitted its request: held through the kernel cap, sent, and settled. Absent:
|
|
53
|
+
* the judge runs as given. */
|
|
54
|
+
admitted?<F>(fn: F): F;
|
|
46
55
|
/** A call node's wait on a raise (deps.held), left out of its deadline. */
|
|
47
56
|
held?(path: string): number;
|
|
48
57
|
}
|
|
@@ -54,6 +63,12 @@ export interface WorkflowHostDeps {
|
|
|
54
63
|
readonly provider: string;
|
|
55
64
|
readonly modelId: string;
|
|
56
65
|
};
|
|
66
|
+
/** Told as each model node's execution starts, before it runs: its execution path and the tier it asked for (the graph
|
|
67
|
+
* keeps what each execution ran on). Absent: nothing told. */
|
|
68
|
+
readonly onModelNode?: (node: {
|
|
69
|
+
readonly executionPath: string;
|
|
70
|
+
readonly tier?: string;
|
|
71
|
+
}) => Promise<void>;
|
|
57
72
|
/** The thinking level every node agent runs at. */
|
|
58
73
|
readonly thinkingLevel?: unknown;
|
|
59
74
|
/** The extensions every model node's agent shares (the coding extension and the gate), installed in the registry too. */
|
|
@@ -75,6 +90,12 @@ export interface WorkflowHostDeps {
|
|
|
75
90
|
readonly flush: () => Promise<void>;
|
|
76
91
|
/** The node log's node.start/node.end lines; absent: no log. */
|
|
77
92
|
readonly log?: (line: Record<string, unknown>) => void;
|
|
93
|
+
/** Told each workflow step's start and end, by its label (the workflow's node.start/node.end): what a cap's pause reads
|
|
94
|
+
* to name the node whose step it held (workflow-spec.ts openSteps). */
|
|
95
|
+
readonly steps?: {
|
|
96
|
+
start(label: string): void;
|
|
97
|
+
end(label: string): void;
|
|
98
|
+
};
|
|
78
99
|
/** What a decision's receipt is shown as, as it is recorded (the live view); absent: not shown. */
|
|
79
100
|
readonly onReceipt?: (receipt: Record<string, unknown>) => void;
|
|
80
101
|
/** The run's spend cap over the adapters; absent: the workflow runs with no cap. */
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { decisionRecovery
|
|
1
|
+
import { decisionRecovery } from "../workflow/decision-recovery.js";
|
|
2
|
+
import { nodeRunner } from "../workflow/node-runner.js";
|
|
3
|
+
import { taskScope } from "../workflow/node.js";
|
|
2
4
|
import { judgeFromProviders } from "@parcha/agentrun-dsl";
|
|
3
5
|
import { withRecovery, workspaceFiles } from "@parcha/agentrun-dsl/recovery";
|
|
4
6
|
const identityCap = { node: (fn) => fn, effect: (fn) => fn, judge: (fn) => fn };
|
|
7
|
+
/** `runNode` that tells `told` of each model node's execution (its path and tier) before it runs it. */
|
|
8
|
+
function withModelNode(runNode, told) {
|
|
9
|
+
if (!told)
|
|
10
|
+
return runNode;
|
|
11
|
+
return async (params) => {
|
|
12
|
+
if (typeof params.executionPath === "string")
|
|
13
|
+
await told({ executionPath: params.executionPath, ...(typeof params.tier === "string" ? { tier: params.tier } : {}) });
|
|
14
|
+
return runNode(params);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
5
17
|
/** The workflow task's host and the extensions to install before the Harness opens, as the per-run process built them.
|
|
6
18
|
* Pass the result to createWorkflowLoop's spec.build. */
|
|
7
19
|
export function workflowHost(deps) {
|
|
8
20
|
const cap = deps.cap ?? identityCap;
|
|
21
|
+
const admitted = (fn) => (cap.admitted ? cap.admitted(fn) : fn);
|
|
9
22
|
/** A model node's agent: its tier's model, the tools it names, and the extensions they come from (app.ts nodeAgent). */
|
|
10
23
|
const nodeAgent = (node) => {
|
|
11
24
|
const bindings = (node.tools ?? []).flatMap((name) => deps.nodeTool(name) ?? []);
|
|
@@ -19,6 +32,13 @@ export function workflowHost(deps) {
|
|
|
19
32
|
const nodes = nodeRunner({ agent: (node) => nodeAgent(node) });
|
|
20
33
|
/** The node log's starts and ends, from the workflow's events (app.ts onEvent). */
|
|
21
34
|
const onEvent = (event) => {
|
|
35
|
+
// A nested `workflow` step stays open while its own steps run and sends no request itself: the steps open are the ones
|
|
36
|
+
// that can, so a pause inside it names its step, never nothing.
|
|
37
|
+
const enclosing = event.detail?.kind === "workflow";
|
|
38
|
+
if (typeof event.label === "string" && event.type === "node.start" && !enclosing)
|
|
39
|
+
deps.steps?.start(event.label);
|
|
40
|
+
if (typeof event.label === "string" && event.type === "node.end" && !enclosing)
|
|
41
|
+
deps.steps?.end(event.label);
|
|
22
42
|
if (!deps.log || (event.type !== "node.start" && event.type !== "node.end") || typeof event.executionPath !== "string")
|
|
23
43
|
return;
|
|
24
44
|
const detail = (event.detail ?? {});
|
|
@@ -36,9 +56,11 @@ export function workflowHost(deps) {
|
|
|
36
56
|
run: ({ key, runtime, context, driver }) => {
|
|
37
57
|
const decisions = decisionRecovery({ key, runtime: runtime, context });
|
|
38
58
|
const recovered = withRecovery(driver, {
|
|
39
|
-
runNode: nodes.on(taskScope(runtime), context).runNode,
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
runNode: withModelNode(nodes.on(taskScope(runtime), context).runNode, deps.onModelNode),
|
|
60
|
+
// The effect the driver runs once it has admitted it: the cap holds and settles a paid call there (admittedEffect).
|
|
61
|
+
runEffect: (cap.admittedEffect ? cap.admittedEffect(deps.runEffect) : deps.runEffect),
|
|
62
|
+
// The judge the driver asks once it has admitted a request: the cap holds, sends and settles it there (admitted).
|
|
63
|
+
...(deps.decisionProviders ? { runJudge: admitted(judgeFromProviders({ ...deps.decisionProviders, loadImage: deps.loadImage })), decisionProviders: deps.decisionProviders } : {}),
|
|
42
64
|
recordDecision: async (receipt, exchange) => {
|
|
43
65
|
await decisions.recordDecision(receipt, exchange);
|
|
44
66
|
deps.onReceipt?.(receipt);
|
|
@@ -2,15 +2,18 @@ import type { Context } from "@earendil-works/chord";
|
|
|
2
2
|
import { type Extension, Harness } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { Models } from "@earendil-works/pi-ai";
|
|
4
4
|
import type { Workflow } from "@parcha/agentrun-dsl";
|
|
5
|
-
import { type WorkflowTaskHost } from "
|
|
5
|
+
import { type WorkflowTaskHost } from "../workflow/task.js";
|
|
6
6
|
import { type BudgetData, type EndData } from "./journal-kinds.js";
|
|
7
|
-
import { type Claim, type LoopFactory } from "./loop-contract.js";
|
|
7
|
+
import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
|
|
8
8
|
/** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
|
|
9
9
|
* via the spec, so flat or tiered pricing is the cap's, not this loop's). */
|
|
10
|
+
/** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
|
|
11
|
+
* decision), which the run's pending budget names; absent when the step's node is not known. */
|
|
10
12
|
export type CapRefusal = {
|
|
11
13
|
readonly message: string;
|
|
12
14
|
readonly forGood: boolean;
|
|
13
15
|
readonly figures?: unknown;
|
|
16
|
+
readonly node?: string;
|
|
14
17
|
};
|
|
15
18
|
/** A raise's state as the cap's checkRaise reads it (the kernel cap's RaiseState). */
|
|
16
19
|
export type RaiseState = {
|
|
@@ -105,7 +108,7 @@ export interface WorkflowRunSpec {
|
|
|
105
108
|
export interface WorkflowHostHooks {
|
|
106
109
|
/** A step the cap holds for a raise lets go here, with the cap's refusal: the loop parks the run (parkOf's pending
|
|
107
110
|
* budget, in the cap's words) and a later claim resumes the workflow from its journal (the held step was never admitted,
|
|
108
|
-
* so nothing is half done), with the raised cap. The caller must let the node's signal, which the loop aborts, end the
|
|
111
|
+
* or ended held with nothing sent, so nothing is half done), with the raised cap. The caller must let the node's signal, which the loop aborts, end the
|
|
109
112
|
* step's wait. */
|
|
110
113
|
park(refusal: CapRefusal): void;
|
|
111
114
|
/** Whether a person's pause is in force (POST /runs/{id}/pause: a `pause` command taken with no `resume` after it). The
|
|
@@ -127,6 +130,9 @@ export declare const isWorkflowRevision: (revision: {
|
|
|
127
130
|
* the claim opens from the store (redact.ts holdClaimed). */
|
|
128
131
|
export interface WorkflowSpecRun {
|
|
129
132
|
readonly redact?: (text: string) => string;
|
|
133
|
+
/** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
|
|
134
|
+
* cost): a fresh one, since the Harness closes its own before the end is written. */
|
|
135
|
+
readonly journal?: () => Journal;
|
|
130
136
|
}
|
|
131
137
|
/** Loops for workflow runs: `spec(claim)` gives each claim's run what it runs (its workflow, input, models and host). */
|
|
132
138
|
export declare function createWorkflowLoop(specOf: (claim: Claim, run: WorkflowSpecRun) => WorkflowRunSpec | Promise<WorkflowRunSpec>): LoopFactory;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The workflow loop on the runner (design: "Runners carry many loops"; the lead's ruling, workflow agents keep running
|
|
2
2
|
// after the cutover). A run of a workflow revision, which the runner claims like any run: this loop is its driver, so the
|
|
3
3
|
// claim, the fence, a cancel and the end commit are its. The DSL's durable runner (workflow-run.ts
|
|
4
|
-
// startWorkflowRevision over
|
|
4
|
+
// startWorkflowRevision over the workflow task, workflow/task.ts) runs the revision's workflow UNCHANGED — the same nodes,
|
|
5
5
|
// decisions, call tools and cap it ran with in the per-run process — on the run's journal in the one store (A,
|
|
6
6
|
// deps.journal(claim)) in place of a per-run store file. The interpreter's host (model nodes on the run's models, call
|
|
7
7
|
// nodes on the tool table, decisions, the cap) is built by the caller (WorkflowRunSpec.build), exactly as the per-run
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
// shutdown writes nothing more and the next claim resumes.
|
|
20
20
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
21
21
|
import { createRegistry, Harness, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
22
|
-
import { createWorkflowExtension } from "
|
|
22
|
+
import { createWorkflowExtension } from "../workflow/task.js";
|
|
23
23
|
import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
|
|
24
24
|
import { KINDS } from "./journal-kinds.js";
|
|
25
|
-
import {
|
|
25
|
+
import { stopEnd } from "./loop-contract.js";
|
|
26
26
|
/** The most the end's patch (cost and metrics) may take before the end is written without it (the pi loop's CUT_STEP_MS). */
|
|
27
27
|
const CUT_STEP_MS = 2_000;
|
|
28
28
|
/** A paused run's words, its row's summary while it waits for a resume. */
|
|
@@ -213,7 +213,7 @@ function workflowLoop(specOf, deps) {
|
|
|
213
213
|
const parkController = new AbortController();
|
|
214
214
|
let heldRefusal;
|
|
215
215
|
const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
|
|
216
|
-
spec = await specOf(claim, deps.redact ? { redact: deps.redact } : {});
|
|
216
|
+
spec = await specOf(claim, { ...(deps.redact ? { redact: deps.redact } : {}), journal: () => deps.journal(claim) });
|
|
217
217
|
claimNow = claim;
|
|
218
218
|
specReady();
|
|
219
219
|
const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };
|
|
@@ -270,10 +270,10 @@ function workflowLoop(specOf, deps) {
|
|
|
270
270
|
await closeHarness();
|
|
271
271
|
const endJournal = deps.journal(claim);
|
|
272
272
|
// A person stopped or cancelled: the run ends stopped whatever the workflow's own outcome (its last node may have
|
|
273
|
-
// completed as the stop landed, since the engine cancels by aborting the task), in the words that say
|
|
274
|
-
// with the stop row taken in the end commit.
|
|
273
|
+
// completed as the stop landed, since the engine cancels by aborting the task), in the words and the outcome that say
|
|
274
|
+
// which (stopEnd), with the stop row taken in the end commit. A workflow run is never reopened, either way.
|
|
275
275
|
if (stopReason?.kind === "command")
|
|
276
|
-
return await writeEnd(endJournal, context,
|
|
276
|
+
return await writeEnd(endJournal, context, stopEnd(stopReason.cancel));
|
|
277
277
|
const carry = await workflowCarry({ runId: claim.runId, storage: endJournal, revision }, outcome, { context });
|
|
278
278
|
// A completed run's output, read as main's server read it once the workflow completed (runs.ts workflowEnd:
|
|
279
279
|
// readWorkflowRun's `output`, null when it has none), kept on its end for result.output.
|
|
@@ -281,6 +281,12 @@ function workflowLoop(specOf, deps) {
|
|
|
281
281
|
const { output } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
282
282
|
return await writeEnd(endJournal, context, { ...carry, output: output ?? null });
|
|
283
283
|
}
|
|
284
|
+
// An escalated run's review, as main's server kept it (runs.ts): the escalation's kind, the escalate node's label (else
|
|
285
|
+
// the node it escalated at), and its summary (else the run's), kept on its end for the run's `review`.
|
|
286
|
+
if (carry.state === "escalated") {
|
|
287
|
+
const { escalation, escalatedAt } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
288
|
+
return await writeEnd(endJournal, context, { ...carry, review: { kind: escalation?.kind ?? null, node: escalation?.label ?? escalatedAt?.label ?? null, reason: escalation?.summary ?? carry.summary } });
|
|
289
|
+
}
|
|
284
290
|
return await writeEnd(endJournal, context, carry);
|
|
285
291
|
}
|
|
286
292
|
finally {
|
|
@@ -298,14 +304,15 @@ function workflowLoop(specOf, deps) {
|
|
|
298
304
|
return { state: "interrupted" };
|
|
299
305
|
if (parked.outcome === "failed")
|
|
300
306
|
return await writeEnd(journal, BACKGROUND_CONTEXT, { state: "failed", summary: parked.error });
|
|
301
|
-
|
|
307
|
+
// A workflow's pause names the node whose step waits at the cap (null when it is not known), as its pending budget shows.
|
|
308
|
+
const budget = { pending: parked.pending, words: parked.words, node: refusal.node ?? null };
|
|
302
309
|
await append(journal, BACKGROUND_CONTEXT, KINDS.budget, budget, { run: { state: "parked", summary: parked.words } });
|
|
303
310
|
return { state: "parked" };
|
|
304
311
|
}
|
|
305
312
|
async function writeEnd(journal, context, carry) {
|
|
306
313
|
const state = carry.state === "failed" ? "failed" : carry.state === "stopped" ? "stopped" : "ended";
|
|
307
|
-
const outcome = carry.state === "escalated" ? "escalated" : undefined;
|
|
308
|
-
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}) };
|
|
314
|
+
const outcome = carry.state === "escalated" ? "escalated" : carry.state === "stopped" ? carry.outcome : undefined;
|
|
315
|
+
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}), ...(carry.review ? { review: carry.review } : {}) };
|
|
309
316
|
const patch = await endPatchOf(spec, base);
|
|
310
317
|
const data = { ...base, ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}) };
|
|
311
318
|
const runPatch = {
|
|
@@ -11,16 +11,14 @@ import { type ModelRoute } from "./model-route.js";
|
|
|
11
11
|
import { type CapRefusal, type WorkflowHostHooks, type WorkflowRunSpec, type WorkflowSpecRun } from "./workflow-loop.js";
|
|
12
12
|
import { type WorkflowCap } from "./workflow-host.js";
|
|
13
13
|
import type { Store } from "../store/store.js";
|
|
14
|
-
/** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
|
|
15
|
-
* @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
|
|
16
|
-
* does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
|
|
17
|
-
export declare const SUBMIT_TOOL = "submit";
|
|
18
14
|
/** How a tier's model is reached and priced, resolved by the caller for each tier the workflow names: the proxy's provider
|
|
19
15
|
* (its API, origin, credential and policy), the catalog price the proxy books an answered request at (calculateCost,
|
|
20
16
|
* tiered), and the cap's model (its price the catalog's cost as given). A test gives a scripted origin and fetch. */
|
|
21
17
|
export interface WorkflowProvider {
|
|
22
18
|
/** The model id the node asks for (the tier's model). */
|
|
23
19
|
readonly modelId: string;
|
|
20
|
+
/** The model as the run names it (`provider/model-id`): what an `llm` call's answer says it ran on. Absent: `modelId`. */
|
|
21
|
+
readonly named?: string;
|
|
24
22
|
/** The wire the proxy forwards on, and pi-ai's client of it speaks to the proxy (port-models.ts sessionProvider). */
|
|
25
23
|
readonly api: Wire;
|
|
26
24
|
/** The catalog's entry for the model (whether it reasons, its window), as pi's session takes it (model-route.ts). */
|
|
@@ -85,7 +83,15 @@ export declare function workflowSpecOf(deps: WorkflowSpecDeps): (claim: {
|
|
|
85
83
|
/** The run's rule with a park on a refusal: `before` (runCap's one rule for the model session) is asked, and on a refusal
|
|
86
84
|
* the run parks through the loop's hook (parkOf decides room vs for good from the refusal), the same as the pi adapter's
|
|
87
85
|
* parkAtCap. It still returns the refusal, so the proxy refuses the request and the node's turn ends. */
|
|
88
|
-
export declare function parkOnRefusal(before: BeforeRequest, hooks: Pick<WorkflowHostHooks, "park" | "paused" | "pause">, flight?: EffectsInFlight): BeforeRequest;
|
|
86
|
+
export declare function parkOnRefusal(before: BeforeRequest, hooks: Pick<WorkflowHostHooks, "park" | "paused" | "pause">, flight?: EffectsInFlight, steps?: OpenSteps): BeforeRequest;
|
|
87
|
+
/** The workflow's steps under way, by label (the workflow's node.start/node.end, through the host): `only` is the label
|
|
88
|
+
* of the one step open, else undefined (none, or several at once). */
|
|
89
|
+
export interface OpenSteps {
|
|
90
|
+
start(label: string): void;
|
|
91
|
+
end(label: string): void;
|
|
92
|
+
only(): string | undefined;
|
|
93
|
+
}
|
|
94
|
+
export declare function openSteps(): OpenSteps;
|
|
89
95
|
/** How many call nodes' effects are in flight (pauseAtEffects counts them; parkOnRefusal reads it). */
|
|
90
96
|
export interface EffectsInFlight {
|
|
91
97
|
count: number;
|
|
@@ -99,7 +105,7 @@ export declare function pauseAtEffects(cap: WorkflowCap, hooks: Pick<WorkflowHos
|
|
|
99
105
|
/** A call node `via: "tool"`: the node-tool table's effect (toolOf(tool).effect) with the run's ctx, as app.ts ran it. Its
|
|
100
106
|
* paid requests (its `llm` call) book through the run's models under the cap. A cap-held request ends the effect held
|
|
101
107
|
* (CAP_HELD), a tool failure as the tool's own (TOOL_FAILED); the loop's `failing` reads both. */
|
|
102
|
-
/** What a call node's request may cost at most, judged
|
|
108
|
+
/** What a call node's request may cost at most, judged once the engine has admitted it (holdAtEffects): a Parallel search's
|
|
103
109
|
* or extract's fee as paidRequest prices it (a fixed fee, what it may charge at most); an `llm` call's request at the
|
|
104
110
|
* cap's worst price for it (its model's tiered rates over an input bound of one token per UTF-8 byte of its prompt and
|
|
105
111
|
* system plus LLM_FRAMING_BYTES for the request's own framing, and the output it asks for, else its model's most);
|
|
@@ -119,16 +125,25 @@ export declare const LLM_FRAMING_BYTES = 2048;
|
|
|
119
125
|
/** The output an `llm` call that names none is sent asking for at most (port-models.ts sessionModel's maxTokens). */
|
|
120
126
|
export declare const LLM_DEFAULT_OUTPUT = 32000;
|
|
121
127
|
export declare function callHoldOf(tool: string, input: Record<string, unknown>, env: NodeJS.ProcessEnv, modelOfTier: (tier: string | undefined) => CapModel | undefined): CallHold;
|
|
122
|
-
/** `cap` with each call node's most cost held on the run's one ledger
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
+
/** `cap` with each call node's most cost held on the run's one ledger, in two halves around the DSL driver's admission of
|
|
129
|
+
* its effect (dsl recovery/driver.ts wrapEffect: the effect is committed admitted before it is dispatched, and one
|
|
130
|
+
* admitted and never completed is never dispatched again):
|
|
131
|
+
* - `admittedEffect`, the effect the driver runs once it has admitted it: the call is priced (`holdOf`) and its hold
|
|
132
|
+
* taken (its record made durable before anything is sent), so a hold is never kept for an effect the driver did not
|
|
133
|
+
* admit: a process that dies before the admission leaves nothing for the next claim to count beside running the call
|
|
134
|
+
* again, and one that dies after it leaves the effect admitted, which the next claim never runs again, under the one
|
|
135
|
+
* hold it counts. Held, the effect runs with the hold as its reservation; what is not taken is given back at its end.
|
|
136
|
+
* A hold the cap refuses ends the effect completed with nothing sent: refused for room, as held (CAP_HELD); refused
|
|
137
|
+
* for good, as the call's failure in the cap's words (TOOL_FAILED). So does the net: a call whose answer cost more
|
|
138
|
+
* than its hold (an `llm` answer priced at its usage).
|
|
139
|
+
* - `effect`, outside the driver: an effect this process ended held parks the run (`park`, as a model request's refusal
|
|
140
|
+
* does) once that end is durable (`flush`), and waits on the node's signal. One an earlier claim ended held (its
|
|
141
|
+
* receipt, replayed) is the park that claim made: the call goes again, a new effect judged at this claim's cap. */
|
|
128
142
|
export declare function holdAtEffects(cap: WorkflowCap, deps: {
|
|
129
143
|
readonly paid: () => RunTools | undefined;
|
|
130
144
|
readonly holdOf: (tool: string, input: Record<string, unknown>) => CallHold;
|
|
131
145
|
readonly park: (refusal: CapRefusal) => void;
|
|
146
|
+
readonly flush: () => Promise<void>;
|
|
132
147
|
}): WorkflowCap;
|
|
133
148
|
/** The reservation of the call node this request runs under, given back as the request is judged on its own (an `llm`
|
|
134
149
|
* call's model request): its hold is the request's from here. */
|
|
@@ -169,7 +184,7 @@ type GatedExecute = (args: never, api: never, context: never) => Promise<unknown
|
|
|
169
184
|
* was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
|
|
170
185
|
* (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
|
|
171
186
|
export declare function gatedNodeCall(name: string, policy: CallPolicy, execute: GatedExecute): GatedExecute;
|
|
172
|
-
/** The tool names a workflow's model node offers its model: the node's `submit` (
|
|
187
|
+
/** The tool names a workflow's model node offers its model: the node's `submit` (SUBMIT_TOOL) and every tool the
|
|
173
188
|
* workflow's model nodes name. */
|
|
174
189
|
export declare function nodeOffer(workflow: Workflow): string[];
|
|
175
190
|
export { BACKGROUND_CONTEXT };
|