@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/runner/metrics.js
CHANGED
|
@@ -11,6 +11,7 @@ import { runMetricsWithDecisions, timelineOf } from "../timeline/index.js";
|
|
|
11
11
|
import { answeredUnpriced, RUNNER_RECORDS, sessionSpendOf } from "@parcha/agentrun-kernel";
|
|
12
12
|
import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
13
13
|
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
14
|
+
import { anthropicModelId } from "../provider.js";
|
|
14
15
|
/** The conversation each of the run's sessions books in, by its key: the first `agentrun.session.key` entry naming it. */
|
|
15
16
|
function sessionConversations(entries) {
|
|
16
17
|
const out = new Map();
|
|
@@ -40,16 +41,27 @@ export function bookedSpend(entries, which) {
|
|
|
40
41
|
const chosen = (e) => (which === "paid" ? conv(e) === paidConv : which === "decisions" ? conv(e) === decisionsConv : conv(e) !== paidConv && conv(e) !== decisionsConv);
|
|
41
42
|
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
42
43
|
const answered = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.turn && chosen(e)).map(turnOf));
|
|
44
|
+
// The model each request was sent on, by its turn (its runner.request's `model`).
|
|
45
|
+
const sentOn = new Map(entries.filter((e) => e.kind === RUNNER_RECORDS.request && chosen(e)).map((e) => [turnOf(e), e.data?.model]));
|
|
46
|
+
const models = {};
|
|
47
|
+
const count = (e) => {
|
|
48
|
+
const model = sentOn.get(turnOf(e));
|
|
49
|
+
const name = typeof model === "string" ? model : "";
|
|
50
|
+
models[name] = (models[name] ?? 0) + 1;
|
|
51
|
+
};
|
|
43
52
|
let known = 0;
|
|
44
53
|
let unpriced = 0;
|
|
45
54
|
let requests = 0;
|
|
55
|
+
let unmetered = 0;
|
|
46
56
|
const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
47
57
|
for (const e of entries) {
|
|
48
58
|
if (!chosen(e))
|
|
49
59
|
continue;
|
|
50
60
|
if (e.kind === RUNNER_RECORDS.request && !answered.has(turnOf(e))) {
|
|
51
61
|
requests += 1;
|
|
62
|
+
count(e);
|
|
52
63
|
unpriced += 1;
|
|
64
|
+
unmetered += 1;
|
|
53
65
|
continue;
|
|
54
66
|
}
|
|
55
67
|
if (e.kind !== RUNNER_RECORDS.turn)
|
|
@@ -58,17 +70,30 @@ export function bookedSpend(entries, which) {
|
|
|
58
70
|
if (d.givenBack === true || d.unsent === true)
|
|
59
71
|
continue;
|
|
60
72
|
requests += 1;
|
|
73
|
+
count(e);
|
|
61
74
|
// An answer with no price of its own was booked at its hold for the cap (answeredUnpriced): as a cost it is unknown.
|
|
62
75
|
const usd = answeredUnpriced(d) ? null : typeof d.bookedUsd === "number" && Number.isFinite(d.bookedUsd) ? d.bookedUsd : typeof d.usd === "number" && Number.isFinite(d.usd) ? d.usd : null;
|
|
63
76
|
if (usd === null)
|
|
64
77
|
unpriced += 1;
|
|
65
78
|
else
|
|
66
79
|
known += usd;
|
|
80
|
+
// The booking keeps a request's usage only when it reported some (runner.ts tokensOf): one with none is unmetered.
|
|
81
|
+
if (d.usage === undefined)
|
|
82
|
+
unmetered += 1;
|
|
67
83
|
for (const key of Object.keys(tokens))
|
|
68
84
|
if (typeof d.usage?.[key] === "number")
|
|
69
85
|
tokens[key] += d.usage[key];
|
|
70
86
|
}
|
|
71
|
-
return { usd: unpriced ? null : known, known, unpriced, requests, tokens };
|
|
87
|
+
return { usd: unpriced ? null : known, known, unpriced, requests, unmetered, models, tokens };
|
|
88
|
+
}
|
|
89
|
+
/** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
|
|
90
|
+
* its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
|
|
91
|
+
* past its model proxy) spent what no booking read: its cost is unknown, never $0. */
|
|
92
|
+
export function cliModelWorked(entries) {
|
|
93
|
+
return entries.some((e) => {
|
|
94
|
+
const role = e.data?.role;
|
|
95
|
+
return e.kind === KINDS.callStart || ((e.kind === KINDS.message || e.kind === KINDS.endOfRunTurn) && role === "model");
|
|
96
|
+
});
|
|
72
97
|
}
|
|
73
98
|
/** Whether a run's record carries no cost of its own, so its usage row and its live spend are its booking's: a CLI
|
|
74
99
|
* harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
|
|
@@ -92,6 +117,36 @@ export function bookedCapSpend(entries) {
|
|
|
92
117
|
}
|
|
93
118
|
return spent;
|
|
94
119
|
}
|
|
120
|
+
/** The bound of a run's requests since its spend last fit under `capUsd`, as the kernel's overCapOf reads it: each model
|
|
121
|
+
* request, in each model session's order, at the figure the cap counts it at, after what the paid tools and decisions
|
|
122
|
+
* spent; reset to 0 whenever the spend fits, else grown by each request's bound. What its over-cap row (run-view.ts
|
|
123
|
+
* withOverCap) reads to tell a cache miss within that bound from a run that spent past its cap. 0 when nothing ran. */
|
|
124
|
+
export function overCapBound(entries, capUsd) {
|
|
125
|
+
const keyed = sessionConversations(entries);
|
|
126
|
+
const paidConv = keyed.get(TOOL_SESSION);
|
|
127
|
+
const decisionsConv = keyed.get(DECISION_SESSION);
|
|
128
|
+
const others = [paidConv, decisionsConv].reduce((sum, conversation) => {
|
|
129
|
+
if (conversation === undefined)
|
|
130
|
+
return sum;
|
|
131
|
+
const read = sessionSpendOf(recordsIn(entries, conversation)).spentUsd;
|
|
132
|
+
return sum + (read ?? 0);
|
|
133
|
+
}, 0);
|
|
134
|
+
const booking = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn).map((e) => Number(e.conversationId)));
|
|
135
|
+
let running = others;
|
|
136
|
+
let bound = 0;
|
|
137
|
+
for (const conversation of booking) {
|
|
138
|
+
if (conversation === paidConv || conversation === decisionsConv)
|
|
139
|
+
continue;
|
|
140
|
+
const read = sessionSpendOf(recordsIn(entries, conversation));
|
|
141
|
+
for (const { turn, usd } of read.figures) {
|
|
142
|
+
running += usd ?? 0;
|
|
143
|
+
bound = running <= capUsd ? 0 : bound + (read.bounds.get(turn) ?? 0);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return bound;
|
|
147
|
+
}
|
|
148
|
+
/** The booking records of `conversation`, as the kernel's session readers take them. */
|
|
149
|
+
const recordsIn = (entries, conversation) => entries.filter((e) => Number(e.conversationId) === conversation && e.kind !== KINDS.sessionKey).map((e) => ({ kind: e.kind, data: (e.data ?? null) }));
|
|
95
150
|
/** The run's metrics and cost from its journal `entries`. `decisions`: a workflow run's receipts (none for pi).
|
|
96
151
|
* `effort`/`model`: the enrichment the old storedMetrics added. `costUsd` is the usage row's cost: null when a
|
|
97
152
|
* response's cost is unknown, 0 before any request (costOf). */
|
|
@@ -106,3 +161,28 @@ export function runMetrics(entries, options = {}) {
|
|
|
106
161
|
costUsd,
|
|
107
162
|
};
|
|
108
163
|
}
|
|
164
|
+
/** A CLI harness's run (its record the loop's: claude-agent, codex, opencode): its metrics from `rootEntries`, its root
|
|
165
|
+
* conversation's record (its tools), with its tokens and model requests those of `booked`, its booking's (bookedSpend
|
|
166
|
+
* "model", which the caller reads once for the run's cost too: what its model proxy booked each request at,
|
|
167
|
+
* runner.turn's usage), since the harness's own record carries none; each request counted at `model`, the model its
|
|
168
|
+
* run chose. Tokens are not a price: a request answered at no known price, with its usage, is metered all the same. */
|
|
169
|
+
/** `byModel` (a booking's requests by the model each was sent on) under the names a run's metrics use: the run's own
|
|
170
|
+
* model, and a request that names none, as `run` (the model it chose, `provider/model`, through OpenRouter or dotted
|
|
171
|
+
* too); any other (a learned node's tier, the hosted search's model) as its request names it. A booked name is the run's
|
|
172
|
+
* when it is one model by the router's match: its last segment, dots as dashes (provider.ts anthropicModelId: the
|
|
173
|
+
* booking names Anthropic's id, claude-haiku-4-5, for a run that chose openrouter/anthropic/claude-haiku-4.5). */
|
|
174
|
+
function modelsOf(byModel, run) {
|
|
175
|
+
const same = (name) => anthropicModelId({ provider: "anthropic", modelId: name.slice(name.lastIndexOf("/") + 1) });
|
|
176
|
+
const own = same(run);
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const [model, n] of Object.entries(byModel)) {
|
|
179
|
+
const name = model === "" || same(model) === own ? run : model;
|
|
180
|
+
out[name] = (out[name] ?? 0) + n;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
export function cliRunMetrics(rootEntries, booked, options) {
|
|
185
|
+
const { metrics: counted } = runMetrics(rootEntries, options);
|
|
186
|
+
const { tokens } = booked;
|
|
187
|
+
return { ...counted, input: tokens.input, output: tokens.output, cacheRead: tokens.cacheRead, cacheWrite: tokens.cacheWrite, requests: booked.requests, unmetered: booked.unmetered, models: modelsOf(booked.models, options.model) };
|
|
188
|
+
}
|
|
@@ -36,6 +36,9 @@ export interface ModelRoute {
|
|
|
36
36
|
readonly auth?: "bearer" | "x-api-key";
|
|
37
37
|
};
|
|
38
38
|
readonly model: string;
|
|
39
|
+
/** The model as the run names it (`provider/model-id`, chooseModel's): what the `llm` tool's answer says it ran on,
|
|
40
|
+
* never the session provider the runner reaches it through. */
|
|
41
|
+
readonly named?: string;
|
|
39
42
|
/** The catalog's entry for the model, as pi-ai's model of it takes it: on every wire, what it takes as input (whether it
|
|
40
43
|
* takes images) and its input limits (an image's most size), which pi's session and its read size an image by; on a
|
|
41
44
|
* wire that carries its reasoning (Responses), also whether it reasons, its window and its output ceiling. */
|
|
@@ -52,6 +55,9 @@ export interface ModelRoute {
|
|
|
52
55
|
readonly fetch?: typeof fetch;
|
|
53
56
|
/** The catalog's cost of the model, tiers included: what the cap prices a request at before it leaves. */
|
|
54
57
|
readonly cost?: RouteCost;
|
|
58
|
+
/** True when serve has no price for the model (runModels' `unpriced`): `cost` is then a placeholder of zeros, which the
|
|
59
|
+
* cap never reads as a price (capModelOf: price unknown, never $0). */
|
|
60
|
+
readonly unpriced?: boolean;
|
|
55
61
|
/** The model's most output tokens (its catalog ceiling): the cap's output bound, null when the catalog names none. */
|
|
56
62
|
readonly outputCeiling?: number | null;
|
|
57
63
|
}
|
|
@@ -33,7 +33,10 @@ export async function routeOf(model, env = process.env, tier = "default", wires
|
|
|
33
33
|
const chosen = await chooseModel(env, model, tier);
|
|
34
34
|
if ("why" in chosen)
|
|
35
35
|
throw new Error(chosen.why);
|
|
36
|
-
|
|
36
|
+
// A tier's own model, when one is named (a subagent's model_tiers), is the one registered, at the tier's price: a gateway
|
|
37
|
+
// lists only the models it is given, so the host's model for the tier in its place would leave this one unknown.
|
|
38
|
+
const named = tier !== "default" && typeof model === "string" ? { [tier]: model } : {};
|
|
39
|
+
const { models, unpriced } = await runModels(env, tier === "default" ? model : undefined, [tier], undefined, named);
|
|
37
40
|
const target = models.getModel(chosen.model.provider, chosen.model.modelId);
|
|
38
41
|
if (!target)
|
|
39
42
|
throw new Error(`no model ${chosen.model.provider}/${chosen.model.modelId} here`);
|
|
@@ -43,7 +46,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
|
|
|
43
46
|
// What the model takes as input and its input limits, on every wire: pi's session sends a model that takes no images
|
|
44
47
|
// pi-ai's placeholder in place of one, and pi's read holds an image to the model's limits (port-models.ts sessionModel).
|
|
45
48
|
const sees = { ...(target.input ? { input: target.input } : {}), ...(target.inputLimits ? { inputLimits: target.inputLimits } : {}) };
|
|
46
|
-
const route = { model: chosen.model.modelId, price, cost: target.cost, outputCeiling: target.maxTokens ?? null, like: sees };
|
|
49
|
+
const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
|
|
47
50
|
// An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
|
|
48
51
|
if (chosen.model.provider === "anthropic") {
|
|
49
52
|
return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Workspace } from "../workspace/workspace.js";
|
|
2
|
+
import type { GithubAppMint } from "./mcp-github.js";
|
|
3
|
+
import type { AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
4
|
+
/** What an agent's revision keeps of its definition's `checkout` (validate.ts CHECKOUTS; `none` keeps nothing). */
|
|
5
|
+
export type Checkout = "pull_request";
|
|
6
|
+
/** The folder, in the run's own, the checkout lands in. */
|
|
7
|
+
export declare const CHECKOUT_DIR = "repo";
|
|
8
|
+
/** How long the whole checkout may take: inside Archil's exec bound, on either mode. */
|
|
9
|
+
export declare const CHECKOUT_MS = 295000;
|
|
10
|
+
/** What the checkout gives the run's claim: the line its system prompt carries, and its removal. */
|
|
11
|
+
export interface PrCheckout {
|
|
12
|
+
/** One line for the run's system prompt: where the checkout is and what it holds, or why there is none. */
|
|
13
|
+
readonly note: string;
|
|
14
|
+
/** The checkout removed from the run's folder: at the claim's release. A failure throws, for the release to log. */
|
|
15
|
+
end(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface PrCheckoutOptions {
|
|
18
|
+
/** The run's Workspace, whose exec runs the fetch. */
|
|
19
|
+
readonly workspace: Workspace;
|
|
20
|
+
/** The run's first input (its launch's): its payload tag names the pull request. */
|
|
21
|
+
readonly input: unknown;
|
|
22
|
+
/** Whether a github trigger started the run (its launch's inputOrigin): only then is its payload tag the server's own,
|
|
23
|
+
* and read. Anyone may write the tag's text into a run of their own. */
|
|
24
|
+
readonly fromGitHub?: boolean;
|
|
25
|
+
/** The server's GitHub App mint, when it has an App the runner can open: none, the fetch is anonymous. */
|
|
26
|
+
readonly mint?: GithubAppMint;
|
|
27
|
+
/** The token revoked at GitHub once the fetch is done: best effort, a failure leaves it to its hour. */
|
|
28
|
+
readonly revoke?: (token: string) => Promise<void>;
|
|
29
|
+
/** Each secret the checkout holds (the token, its header), handed to the run's redactor before it is used. */
|
|
30
|
+
readonly hold?: (secrets: readonly string[]) => void;
|
|
31
|
+
/** GitHub's site, where the repository is fetched from: a test's own (a folder of bare repositories, or a git server
|
|
32
|
+
* on loopback). Absent, https://github.com. */
|
|
33
|
+
readonly web?: string;
|
|
34
|
+
/** Ends the fetch at once: the claim's signal, aborted by a person's stop too. The checkout's removal is handed to
|
|
35
|
+
* `held` before the fetch starts, so a fetch cut short leaves its folder to the claim's release. */
|
|
36
|
+
readonly signal?: AbortSignal;
|
|
37
|
+
/** The checkout's removal, given the moment the fetch starts (the spec's holds), so whatever ends the claim removes it. */
|
|
38
|
+
readonly held?: (part: {
|
|
39
|
+
end(): Promise<void>;
|
|
40
|
+
}) => void;
|
|
41
|
+
readonly timeoutMs?: number;
|
|
42
|
+
}
|
|
43
|
+
/** The pull request `options.input` names, checked out in the run's folder at its head. Never throws for a checkout that
|
|
44
|
+
* could not be made: the run is told why, and reads the change some other way. */
|
|
45
|
+
export declare function prCheckout(options: PrCheckoutOptions): Promise<PrCheckout>;
|
|
46
|
+
/** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
|
|
47
|
+
* MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
|
|
48
|
+
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. */
|
|
49
|
+
export declare function prCheckoutForClaim(deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "githubApi" | "githubWeb">, workspace: Workspace, launch: {
|
|
50
|
+
readonly input: unknown;
|
|
51
|
+
readonly inputOrigin?: {
|
|
52
|
+
readonly kind: string;
|
|
53
|
+
readonly source?: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
}, redact: {
|
|
56
|
+
hold(values: readonly string[]): void;
|
|
57
|
+
}, signal?: AbortSignal, held?: (part: {
|
|
58
|
+
end(): Promise<void>;
|
|
59
|
+
}) => void): Promise<PrCheckout>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// A run's checkout of the pull request it was started for, made by the server before the first turn when the agent's
|
|
2
|
+
// definition says `checkout: pull_request` (a template's manifest sets it). The agent then starts with the repository at
|
|
3
|
+
// the pull request's head in `repo/` of its folder, its base and their merge base fetched beside it, and never holds a
|
|
4
|
+
// GitHub token: the fetch is the server's own, one exec on the run's Workspace (Mode 1 a process on this machine, Mode 2
|
|
5
|
+
// Archil's serverless exec over the run's folder), never a command of the agent's.
|
|
6
|
+
//
|
|
7
|
+
// What it reads of the run: its first message's payload tag alone (github.ts githubPullOf), which the server wrote from a
|
|
8
|
+
// signed GitHub delivery: the repository, the pull request's number, its head and its base. Nothing else names a
|
|
9
|
+
// repository to fetch.
|
|
10
|
+
//
|
|
11
|
+
// The credential: an installation token of the server's GitHub App, minted for that one repository with
|
|
12
|
+
// {contents: "read"} alone, handed to the exec on its stdin (Archil's: a spill file deleted on every path), turned there
|
|
13
|
+
// into an Authorization header in git's environment (GIT_CONFIG_COUNT), scoped to GitHub's site. It is never in argv,
|
|
14
|
+
// .git/config, the remote's URL, the run's folder, an env the agent's commands get, or the log (it joins the run's
|
|
15
|
+
// redactor). No App, or one not installed on the repository: the fetch is anonymous, which a public repository answers.
|
|
16
|
+
// The token is revoked once the fetch is done (GitHub's DELETE /installation/token), and is never kept.
|
|
17
|
+
//
|
|
18
|
+
// Git there reads no system or global config (no filter, textconv or fsmonitor a machine's config could attach), fetches
|
|
19
|
+
// no tags and no submodules, and checks out with the repository's own config alone, which this exec wrote.
|
|
20
|
+
//
|
|
21
|
+
// What the run is told: one line in its system prompt, the checkout's facts, or why there is none and that the GitHub
|
|
22
|
+
// tools can read the change instead. The checkout is removed when the claim lets go (spec-holds.ts), and made again by
|
|
23
|
+
// the next claim of the same run.
|
|
24
|
+
import { randomUUID } from "node:crypto";
|
|
25
|
+
import { GITHUB_WEB, githubPullOf } from "../github.js";
|
|
26
|
+
import { isObject } from "../validate.js";
|
|
27
|
+
import { COMMAND_MAX_MS } from "../workspace/archil-exec.js";
|
|
28
|
+
import { shellEnv } from "../workspace/hands.js";
|
|
29
|
+
import { githubAppAccess } from "./github-app.js";
|
|
30
|
+
/** The folder, in the run's own, the checkout lands in. */
|
|
31
|
+
export const CHECKOUT_DIR = "repo";
|
|
32
|
+
/** How long the whole checkout may take: inside Archil's exec bound, on either mode. */
|
|
33
|
+
export const CHECKOUT_MS = COMMAND_MAX_MS;
|
|
34
|
+
/** The commits each side is first fetched with, then deepened by (doubling) until the merge base is in: about 3,200
|
|
35
|
+
* commits back at most, past which the run is told there is no merge base and the base's diff is the two-dot one. A merge
|
|
36
|
+
* base found is taken only when no shallow edge lies outside its ancestry: a history cut short can show an older common
|
|
37
|
+
* commit (a long branch that merged an old side branch) while the path to the true merge base is cut off, so the fetch
|
|
38
|
+
* deepens until every edge is at or behind the merge base it found. Each fetch runs with git's auto maintenance off: a
|
|
39
|
+
* fetch otherwise starts a detached gc that writes into .git/objects while the checkout's removal deletes it. */
|
|
40
|
+
const DEPTH = 50;
|
|
41
|
+
const DEEPENS = 6;
|
|
42
|
+
/** The file in the checkout's .git naming the claim that made it: a removal takes only its own claim's checkout. */
|
|
43
|
+
const OWNER_FILE = "agentrun-claim";
|
|
44
|
+
/** The exec's script: $1 the remote's URL (no credential), $2 the head, $3 the base (or empty), $4 the folder, $5 the
|
|
45
|
+
* URL prefix the header is for, $6 this claim's checkout id (written to .git/${OWNER_FILE}). Its stdin's first line is
|
|
46
|
+
* an Authorization header, or empty for an anonymous fetch. Its exit codes name the step that failed (10 the folder, 11 the fetch, 12 the checkout); on success it prints the merge
|
|
47
|
+
* base, empty when none was found. */
|
|
48
|
+
const SCRIPT = `set -u
|
|
49
|
+
url=$1 head=$2 base=$3 dir=$4 scope=$5 claim=$6
|
|
50
|
+
IFS= read -r auth || true
|
|
51
|
+
export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null
|
|
52
|
+
if [ -n "\${auth:-}" ]; then export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.$scope.extraheader" GIT_CONFIG_VALUE_0="$auth"; fi
|
|
53
|
+
auth=
|
|
54
|
+
rm -rf "\${dir:?}"
|
|
55
|
+
git init -q "$dir" >/dev/null 2>&1 && cd "$dir" && printf '%s\\n' "$claim" > .git/${OWNER_FILE} && git remote add origin "$url" || exit 10
|
|
56
|
+
fetch() { git -c maintenance.auto=false -c gc.auto=0 fetch -q --no-tags --no-recurse-submodules origin "$@" "$head" \${base:+"$base"}; }
|
|
57
|
+
fetch --depth=${DEPTH} || exit 11
|
|
58
|
+
mb=
|
|
59
|
+
settled() {
|
|
60
|
+
[ -n "$mb" ] || return 1
|
|
61
|
+
[ -s .git/shallow ] || return 0
|
|
62
|
+
while IFS= read -r edge; do git merge-base --is-ancestor "$edge" "$mb" 2>/dev/null || return 1; done < .git/shallow
|
|
63
|
+
}
|
|
64
|
+
if [ -n "$base" ]; then
|
|
65
|
+
n=${DEPTH} i=0
|
|
66
|
+
while :; do
|
|
67
|
+
mb=$(git merge-base "$base" "$head" 2>/dev/null) || mb=
|
|
68
|
+
settled && break
|
|
69
|
+
[ "$i" -lt ${DEEPENS} ] || { mb=; break; }
|
|
70
|
+
fetch --deepen=$n || exit 11
|
|
71
|
+
n=$((n * 2)) i=$((i + 1))
|
|
72
|
+
done
|
|
73
|
+
fi
|
|
74
|
+
git update-ref refs/pr/head "$head" || exit 12
|
|
75
|
+
if [ -n "$base" ]; then git update-ref refs/pr/base "$base" || exit 12; fi
|
|
76
|
+
if [ -n "$mb" ]; then git update-ref refs/pr/merge-base "$mb" || exit 12; fi
|
|
77
|
+
git -c advice.detachedHead=false checkout -q --detach "$head" || exit 12
|
|
78
|
+
printf '%s\\n' "$mb"
|
|
79
|
+
`;
|
|
80
|
+
const noCheckout = (note) => ({ note, end: async () => { } });
|
|
81
|
+
/** The words of a failed exec, with the secrets cut and its last lines kept. */
|
|
82
|
+
const tail = (text, secrets) => {
|
|
83
|
+
let cut = text;
|
|
84
|
+
for (const secret of secrets)
|
|
85
|
+
cut = cut.split(secret).join("[redacted]");
|
|
86
|
+
const lines = cut.trim().split("\n").filter(Boolean);
|
|
87
|
+
return lines.slice(-3).join(" / ").slice(0, 400);
|
|
88
|
+
};
|
|
89
|
+
/** The pull request `options.input` names, checked out in the run's folder at its head. Never throws for a checkout that
|
|
90
|
+
* could not be made: the run is told why, and reads the change some other way. */
|
|
91
|
+
export async function prCheckout(options) {
|
|
92
|
+
const { workspace } = options;
|
|
93
|
+
const pull = githubPullOf(isObject(options.input) ? options.input.content : options.input, { payload: options.fromGitHub === true });
|
|
94
|
+
if (!pull)
|
|
95
|
+
return noCheckout("No checkout was made: this run was not started by a GitHub pull request event, so there is no repo/ folder. Read the change through the GitHub tools if you have them.");
|
|
96
|
+
const web = (options.web ?? GITHUB_WEB).replace(/\/+$/, "");
|
|
97
|
+
const name = `${pull.repo}#${pull.number}`;
|
|
98
|
+
// The token: the App's, for this repository alone, contents read alone. None (no App, not installed, GitHub said no):
|
|
99
|
+
// the fetch is anonymous, and the words say which, in case the repository turns out to be private.
|
|
100
|
+
let token;
|
|
101
|
+
let anonymous = "";
|
|
102
|
+
if (options.mint) {
|
|
103
|
+
try {
|
|
104
|
+
const got = await options.mint({ repo: pull.repo, ...(pull.installation !== undefined ? { installation: pull.installation } : {}) }, { contents: "read" });
|
|
105
|
+
if (got.ok)
|
|
106
|
+
token = got.token;
|
|
107
|
+
else
|
|
108
|
+
anonymous = got.reason === "not_installed" ? `the GitHub App is not installed on ${pull.repo}` : got.message;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
anonymous = `GitHub did not make a token (${error?.message ?? error})`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
anonymous = "this server has no GitHub App";
|
|
116
|
+
const header = token ? `Authorization: Basic ${Buffer.from(`x-access-token:${token}`, "utf8").toString("base64")}` : "";
|
|
117
|
+
const secrets = token ? [token, header, header.slice("Authorization: Basic ".length)] : [];
|
|
118
|
+
if (secrets.length)
|
|
119
|
+
options.hold?.(secrets);
|
|
120
|
+
// This claim's checkout, by an id of its own: a claim that lost its lease and lets go late removes only the folder it
|
|
121
|
+
// made, never the one a later claim of the run is fetching or reading (that claim's fetch replaces a stale one itself).
|
|
122
|
+
const claim = randomUUID();
|
|
123
|
+
const removal = async () => {
|
|
124
|
+
const result = await workspace.exec(["sh", "-c", `[ "$(cat "\${1:?}/.git/${OWNER_FILE}" 2>/dev/null)" = "$2" ] || exit 0; rm -rf -- "\${1:?}"`, "sh", CHECKOUT_DIR, claim], { env: shellEnv(), timeoutMs: CHECKOUT_MS });
|
|
125
|
+
if (result.code !== 0)
|
|
126
|
+
throw new Error(`the run's ${CHECKOUT_DIR}/ checkout could not be removed (exit ${result.code ?? result.signal}): ${tail(result.stderr, secrets)}`);
|
|
127
|
+
};
|
|
128
|
+
const failed = async (why) => {
|
|
129
|
+
// What a failed fetch left (a half folder) goes now: the run is told there is none.
|
|
130
|
+
await removal().catch(() => { });
|
|
131
|
+
return noCheckout(`The pull request ${name} could not be checked out (${why}), so there is no ${CHECKOUT_DIR}/ folder: read the change through the GitHub tools (its diff, and each file at the head sha ${pull.head}).`);
|
|
132
|
+
};
|
|
133
|
+
// From here a folder may exist: its removal is the claim's to run, whatever ends it.
|
|
134
|
+
options.held?.({ end: removal });
|
|
135
|
+
let result;
|
|
136
|
+
try {
|
|
137
|
+
result = await workspace.exec(["sh", "-c", SCRIPT, "sh", `${web}/${pull.repo}.git`, pull.head, pull.base ?? "", CHECKOUT_DIR, `${web}/`, claim], { env: shellEnv(), stdin: Buffer.from(`${header}\n`, "utf8"), timeoutMs: options.timeoutMs ?? CHECKOUT_MS, ...(options.signal ? { signal: options.signal } : {}) });
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
// Cut short (a stop, a lost claim): the claim's release removes what the fetch made (`held`).
|
|
141
|
+
if (options.signal?.aborted)
|
|
142
|
+
throw error;
|
|
143
|
+
return failed(`the fetch could not run: ${tail(String(error?.message ?? error), secrets)}`);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
// The fetch is the token's one use: it goes now, not in an hour.
|
|
147
|
+
if (token && options.revoke)
|
|
148
|
+
await options.revoke(token).catch(() => { });
|
|
149
|
+
}
|
|
150
|
+
if (result.timedOut)
|
|
151
|
+
return failed(`the fetch took more than ${Math.round((options.timeoutMs ?? CHECKOUT_MS) / 1000)} s`);
|
|
152
|
+
if (result.code !== 0) {
|
|
153
|
+
const step = result.code === 10 ? "its folder could not be made" : result.code === 11 ? `${web}/${pull.repo} did not give its commits${token ? "" : `, fetched with no token: ${anonymous}`}` : result.code === 12 ? "its head could not be checked out" : `git ended with ${result.code ?? result.signal}`;
|
|
154
|
+
const said = tail(result.stderr, secrets);
|
|
155
|
+
return failed(said ? `${step}: ${said}` : step);
|
|
156
|
+
}
|
|
157
|
+
const mergeBase = Buffer.from(result.stdout).toString("utf8").trim();
|
|
158
|
+
return { note: checkoutNote(pull, /^[0-9a-f]{40}$/.test(mergeBase) ? mergeBase : undefined), end: removal };
|
|
159
|
+
}
|
|
160
|
+
/** The line a run with a checkout is told. */
|
|
161
|
+
function checkoutNote(pull, mergeBase) {
|
|
162
|
+
const base = pull.base === undefined
|
|
163
|
+
? "Its base was not named by the event, so only the head is there."
|
|
164
|
+
: mergeBase === undefined
|
|
165
|
+
? `Its base ${pull.base} is fetched too (ref pr/base), but no merge base was found within ${DEPTH * 2 ** DEEPENS} commits: diff against pr/base.`
|
|
166
|
+
: `Its base ${pull.base} (ref pr/base) and their merge base ${mergeBase} (ref pr/merge-base) are fetched too: read the change with \`git diff pr/merge-base pr/head\`.`;
|
|
167
|
+
return `The pull request ${pull.repo}#${pull.number} is checked out in ${CHECKOUT_DIR}/, detached at its head ${pull.head} (ref pr/head), by the server before this run began. ${base} It is a shallow clone, and no credential is kept in it.`;
|
|
168
|
+
}
|
|
169
|
+
/** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
|
|
170
|
+
* MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
|
|
171
|
+
* moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. */
|
|
172
|
+
export async function prCheckoutForClaim(deps, workspace, launch, redact, signal, held) {
|
|
173
|
+
const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
|
|
174
|
+
const access = await githubAppAccess(deps.store, deps.sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, hold: (values) => redact.hold(values) });
|
|
175
|
+
return prCheckout({ workspace, input: launch.input, fromGitHub, ...(access ? { mint: access.mint } : {}), ...(access?.revoke ? { revoke: access.revoke } : {}), hold: (secrets) => redact.hold(secrets), ...(deps.githubWeb ? { web: deps.githubWeb } : {}), ...(signal ? { signal } : {}), ...(held ? { held } : {}) });
|
|
176
|
+
}
|
|
@@ -60,6 +60,7 @@ export interface ReflectDeps {
|
|
|
60
60
|
readonly name: string;
|
|
61
61
|
readonly does: string;
|
|
62
62
|
}[];
|
|
63
|
+
workflows?: false;
|
|
63
64
|
}>;
|
|
64
65
|
/** What the person said in the run, and a trigger's input, as the checks and the grader read them. */
|
|
65
66
|
readonly asked: (runId: string) => Promise<{
|
|
@@ -76,10 +76,10 @@ export function createReflectHook(deps) {
|
|
|
76
76
|
const close = async (rows) => ({ also: (await looked({ also: rows })).also.map((row) => cutRow(row, refuse)) });
|
|
77
77
|
if (read === "unreadable")
|
|
78
78
|
return close([droppedRow(null, "propose_failed", said.stopped(STOPPED.refuseUnread))]);
|
|
79
|
-
const { active, tools, draftFor, described } = await deps.promptFacts(input.runId, input.agentId);
|
|
79
|
+
const { active, tools, draftFor, described, workflows } = await deps.promptFacts(input.runId, input.agentId);
|
|
80
80
|
const deadlineMs = deps.deadlineMs ?? REFLECT_TIMEOUT_MS;
|
|
81
81
|
const started = now();
|
|
82
|
-
const end = await input.ask(reflectPrompt({ dir: LEARNED_DIR, active, tools, ...(draftFor?.length ? { draftFor, ...(described?.length ? { described } : {}) } : {}) }), { origin: "reflect", deadlineMs });
|
|
82
|
+
const end = await input.ask(reflectPrompt({ dir: LEARNED_DIR, active, tools, ...(workflows === false ? { workflows: false } : draftFor?.length ? { draftFor, ...(described?.length ? { described } : {}) } : {}) }), { origin: "reflect", deadlineMs });
|
|
83
83
|
// closeLearning: how the turn ended.
|
|
84
84
|
if ("timedOut" in end)
|
|
85
85
|
return close([droppedRow(null, "reflect_timeout", said.stopped(STOPPED.timedOut))]);
|
|
@@ -104,7 +104,7 @@ export function createReflectHook(deps) {
|
|
|
104
104
|
// within the turn's own deadline; a re-ask that times out or fails leaves the first answer's drop.
|
|
105
105
|
if (checked.state === "dropped" && checked.reason === "unparsed") {
|
|
106
106
|
const left = deadlineMs - (now() - started);
|
|
107
|
-
const again = left > 0 ? await input.ask(reflectAgain(checked.detail), { origin: "reflect", deadlineMs: left, again: true }) : undefined;
|
|
107
|
+
const again = left > 0 ? await input.ask(reflectAgain(checked.detail, ...(workflows === false ? [false] : [])), { origin: "reflect", deadlineMs: left, again: true }) : undefined;
|
|
108
108
|
if (again && "ended" in again) {
|
|
109
109
|
turn = turnOf(again.answer);
|
|
110
110
|
checked = await checkOf(turn);
|