@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/main.d.ts
CHANGED
|
@@ -38,6 +38,9 @@ export interface RunnerProcess {
|
|
|
38
38
|
readonly kind: string;
|
|
39
39
|
readonly schema: number;
|
|
40
40
|
};
|
|
41
|
+
/** What its runs may hold, in MiB (RunnerMemory.budgetMib): its host's memory, or its container's limit, less the
|
|
42
|
+
* server's own. Said once at its start, after the ready line. */
|
|
43
|
+
readonly memoryMib: number;
|
|
41
44
|
/** Closes the runner (its loops stopped, its runs released), then its store connection. */
|
|
42
45
|
close(): Promise<void>;
|
|
43
46
|
}
|
|
@@ -111,14 +114,16 @@ export declare function runnerHolds(args: {
|
|
|
111
114
|
loops: number;
|
|
112
115
|
drainMs: number;
|
|
113
116
|
};
|
|
114
|
-
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N]`, or `--check --data D
|
|
115
|
-
* N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
|
|
116
|
-
* so, never read as an option); an empty one is refused like a missing one.
|
|
117
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
|
|
118
|
+
* [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
|
|
119
|
+
* with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
|
|
120
|
+
* test switch, as the server's own --faux; the only way a runner loads one. */
|
|
117
121
|
export declare function runnerArgs(argv: readonly string[]): {
|
|
118
122
|
dataDir: string;
|
|
119
123
|
loops?: number;
|
|
120
124
|
drainMs?: number;
|
|
121
125
|
name?: string;
|
|
126
|
+
faux?: string;
|
|
122
127
|
check?: true;
|
|
123
128
|
};
|
|
124
129
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
@@ -135,7 +140,7 @@ export declare function lastResort(name: string, write?: (line: string) => void,
|
|
|
135
140
|
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
|
|
136
141
|
* set up yet); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names
|
|
137
142
|
* it when --name does not. */
|
|
138
|
-
export declare function runnerMain(argv: readonly string[],
|
|
143
|
+
export declare function runnerMain(argv: readonly string[], given?: NodeJS.ProcessEnv, hooks?: RunnerMainHooks): Promise<number>;
|
|
139
144
|
/** A test's hooks into runnerMain: `started`, awaited once the runner has started claiming and before its stop handlers
|
|
140
145
|
* take over from the ones its start listened on (the window a stop must not fall through). */
|
|
141
146
|
export type RunnerMainHooks = {
|
package/dist/runner/main.js
CHANGED
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
// run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store schema it does not know 3, anything else 1.
|
|
12
12
|
// An error nothing handles exits 1 at once, said with its stack (lastResort).
|
|
13
13
|
import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
14
|
-
import { join } from "node:path";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
16
|
+
import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
|
|
15
17
|
import { dockerPathsForRuns } from "../box-paths.js";
|
|
18
|
+
import { hostCommandRefusals } from "../computers.js";
|
|
16
19
|
import { hostAddressesOnce } from "../docker-host-addresses.js";
|
|
20
|
+
import { claimInstallsStopped } from "../harness-install.js";
|
|
17
21
|
import { HARNESS_TABLE_ENV } from "../harness-table.js";
|
|
18
22
|
import { maxRunsOf } from "../host.js";
|
|
19
|
-
import { FAUX_PREFIX } from "../model.js";
|
|
23
|
+
import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
20
24
|
import { durationMs } from "../print.js";
|
|
21
25
|
import { bootSealKey } from "../seal-key.js";
|
|
22
26
|
import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
@@ -104,7 +108,7 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
104
108
|
// The run's computer at its claim, composed once (workspace/computer-deps.ts): none for the runner's place, a box's
|
|
105
109
|
// computer by the agent's setting, its keys read from the run environment first, then the store's sealed rows; a
|
|
106
110
|
// Docker computer's mounts by where this process's Docker has the data directory (box-paths.ts), read once.
|
|
107
|
-
const computers = computerDepsFrom({ env: runs, store, sealKey, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
|
|
111
|
+
const computers = computerDepsFrom({ env: runs, store, sealKey, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
|
|
108
112
|
const deps = {
|
|
109
113
|
env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
|
|
110
114
|
computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
|
|
@@ -154,6 +158,7 @@ export async function startRunnerProcess(options) {
|
|
|
154
158
|
const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
|
|
155
159
|
const env = options.env ?? process.env;
|
|
156
160
|
const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
|
|
161
|
+
const memory = options.memory ?? runnerMemory(store);
|
|
157
162
|
let runner;
|
|
158
163
|
let seal;
|
|
159
164
|
let janitor;
|
|
@@ -178,7 +183,7 @@ export async function startRunnerProcess(options) {
|
|
|
178
183
|
name,
|
|
179
184
|
...(options.loops ? { loops: options.loops } : {}),
|
|
180
185
|
...(options.drainMs ? { drainMs: options.drainMs } : {}),
|
|
181
|
-
memory
|
|
186
|
+
memory,
|
|
182
187
|
...(options.onEvent ? { onEvent: options.onEvent } : {}),
|
|
183
188
|
onBeat: heartbeat(options.dataDir, name, options.now ?? Date.now),
|
|
184
189
|
});
|
|
@@ -194,9 +199,12 @@ export async function startRunnerProcess(options) {
|
|
|
194
199
|
return {
|
|
195
200
|
runner,
|
|
196
201
|
store: { kind, schema },
|
|
202
|
+
memoryMib: memory.budgetMib,
|
|
197
203
|
close: () => (closing ??= (async () => {
|
|
198
204
|
// The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
|
|
199
205
|
await Promise.all([janitor?.close(), runner.close()]);
|
|
206
|
+
// A first-use install its claims started, stopped as they let go: its npm ends before this process can.
|
|
207
|
+
await claimInstallsStopped();
|
|
200
208
|
await store.close();
|
|
201
209
|
held.release();
|
|
202
210
|
})()),
|
|
@@ -240,18 +248,20 @@ export function runnerHolds(args, env) {
|
|
|
240
248
|
}
|
|
241
249
|
return { loops, drainMs };
|
|
242
250
|
}
|
|
243
|
-
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N]`, or `--check --data D
|
|
244
|
-
* N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
|
|
245
|
-
* so, never read as an option); an empty one is refused like a missing one.
|
|
251
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
|
|
252
|
+
* [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
|
|
253
|
+
* with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
|
|
254
|
+
* test switch, as the server's own --faux; the only way a runner loads one. */
|
|
246
255
|
export function runnerArgs(argv) {
|
|
247
256
|
let dataDir;
|
|
248
257
|
let loops;
|
|
249
258
|
let drainMs;
|
|
250
259
|
let name;
|
|
260
|
+
let faux;
|
|
251
261
|
let check = false;
|
|
252
262
|
for (let i = 0; i < argv.length; i++) {
|
|
253
263
|
const given = argv[i];
|
|
254
|
-
const equals = /^(--(?:data|loops|drain-timeout|name))=(.*)$/s.exec(given);
|
|
264
|
+
const equals = /^(--(?:data|loops|drain-timeout|name|faux))=(.*)$/s.exec(given);
|
|
255
265
|
const arg = equals ? equals[1] : given;
|
|
256
266
|
const value = () => {
|
|
257
267
|
const next = equals ? equals[2] : argv[++i];
|
|
@@ -275,14 +285,16 @@ export function runnerArgs(argv) {
|
|
|
275
285
|
}
|
|
276
286
|
else if (arg === "--name")
|
|
277
287
|
name = value();
|
|
288
|
+
else if (arg === "--faux")
|
|
289
|
+
faux = value();
|
|
278
290
|
else if (arg === "--check")
|
|
279
291
|
check = true;
|
|
280
292
|
else
|
|
281
|
-
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N], or --check --data D [--name N]`);
|
|
293
|
+
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M], or --check --data D [--name N]`);
|
|
282
294
|
}
|
|
283
295
|
if (!dataDir)
|
|
284
296
|
throw new RunnerRefused("a runner needs its data directory: --data D");
|
|
285
|
-
return { dataDir, ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(check ? { check: true } : {}) };
|
|
297
|
+
return { dataDir, ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(check ? { check: true } : {}) };
|
|
286
298
|
}
|
|
287
299
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
288
300
|
* says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
|
|
@@ -326,7 +338,7 @@ function said(name, event) {
|
|
|
326
338
|
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
|
|
327
339
|
* set up yet); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names
|
|
328
340
|
* it when --name does not. */
|
|
329
|
-
export async function runnerMain(argv,
|
|
341
|
+
export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
330
342
|
let args;
|
|
331
343
|
try {
|
|
332
344
|
args = runnerArgs(argv);
|
|
@@ -337,6 +349,10 @@ export async function runnerMain(argv, env = process.env, hooks = {}) {
|
|
|
337
349
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
338
350
|
return 2;
|
|
339
351
|
}
|
|
352
|
+
// A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
|
|
353
|
+
// inherited (AGENTRUN_SERVE_FAUX*, the harness table, left in an operator's shell or a platform's settings) never loads
|
|
354
|
+
// a module or decides what a run answers. --faux sets the faux model's.
|
|
355
|
+
const env = { ...withoutFaux(given), ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
|
|
340
356
|
const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
|
|
341
357
|
if (args.check) {
|
|
342
358
|
if (!name) {
|
|
@@ -354,9 +370,13 @@ export async function runnerMain(argv, env = process.env, hooks = {}) {
|
|
|
354
370
|
let holds;
|
|
355
371
|
try {
|
|
356
372
|
holds = runnerHolds(args, env);
|
|
373
|
+
// The Archil settings an operator sets, read by every run's claim here as the server reads them (archil-settings.ts):
|
|
374
|
+
// one of the region and S3 URL without the other, or a value the server would refuse, stops this start as it stops
|
|
375
|
+
// the server's.
|
|
376
|
+
archilSettingsFromEnv(env);
|
|
357
377
|
}
|
|
358
378
|
catch (error) {
|
|
359
|
-
if (!(error instanceof RunnerRefused))
|
|
379
|
+
if (!(error instanceof RunnerRefused) && !(error instanceof ArchilSettingsEnvInvalid))
|
|
360
380
|
throw error;
|
|
361
381
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
362
382
|
return 2;
|
|
@@ -413,7 +433,12 @@ export async function runnerMain(argv, env = process.env, hooks = {}) {
|
|
|
413
433
|
return 0;
|
|
414
434
|
}
|
|
415
435
|
// Ready is said once SIGTERM and SIGINT are handled, so a stop sent on reading it always closes the runner.
|
|
416
|
-
|
|
436
|
+
// Then its memory budget, a line of its own (the ready line's shape is read by deploy checks): what a container's limit
|
|
437
|
+
// gave it is seen where it runs.
|
|
438
|
+
await runUntilSignalled(started, RUNNER_SIGNALS, () => {
|
|
439
|
+
console.log(`Runner ${started.runner.name} ready: store ${started.store.kind} schema v${started.store.schema}, ${holds.loops} loops`);
|
|
440
|
+
console.log(`Runner ${started.runner.name} memory: ${started.memoryMib} MiB for runs, each weighed by its harness`);
|
|
441
|
+
});
|
|
417
442
|
return 0;
|
|
418
443
|
}
|
|
419
444
|
/** The signals that stop a runner process. */
|
|
@@ -33,6 +33,10 @@ export interface McpClaimOptions {
|
|
|
33
33
|
/** For tests only (no environment or CLI flag maps onto it): the one origin a github_app server may have, a fake for
|
|
34
34
|
* GitHub's hosted MCP (GITHUB_MCP_ORIGIN). */
|
|
35
35
|
githubMcpOrigin?: string;
|
|
36
|
+
/** Each credential value a per_run server's handed headers carry (each header's value, and a Bearer's bare token),
|
|
37
|
+
* handed to the run's redactors as the claim opens them: at the claim, and at each fresh() after a message hands the
|
|
38
|
+
* run a new one, before any call carries it. */
|
|
39
|
+
hold?: (values: string[]) => void;
|
|
36
40
|
/** For tests: the timer a github_app token's refresh and expiry are armed on. */
|
|
37
41
|
githubTimer?: GithubTimer;
|
|
38
42
|
/** For tests: the timer a wait on another claim's refresh lease, and its next read of the row, are armed on. */
|
|
@@ -53,6 +57,9 @@ export interface McpClaimStep {
|
|
|
53
57
|
fresh(): Promise<void>;
|
|
54
58
|
/** Drop every credential held: the loop ended, or the claim is lost. */
|
|
55
59
|
release(): void;
|
|
60
|
+
/** Before each call of `server` (the gateway's beforeCall): a github_app token whose App was disconnected or replaced
|
|
61
|
+
* since it was minted is dropped, revoked, and the call refused in words. */
|
|
62
|
+
beforeCall(server: string, signal: AbortSignal): Promise<void>;
|
|
56
63
|
}
|
|
57
64
|
/** The MCP step of `options.claim`: its pin made or read and checked, its credentials opened (refreshed as due). */
|
|
58
65
|
export declare function mcpClaim(options: McpClaimOptions): Promise<McpClaimStep>;
|
package/dist/runner/mcp-claim.js
CHANGED
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
// (signedOut), a refresh that got no answer (silent), an address the check refuses (blocked). A runner never starts
|
|
17
17
|
// without the seal key (seal-key.ts bootSealKey), so a claim always has one.
|
|
18
18
|
//
|
|
19
|
+
// A per_run server keeps no credential: the run's caller hands one with the run or a message (mcp_auth), sealed in the
|
|
20
|
+
// run's launch row for the run's life (store/seal.ts sealRunMcpAuth) and erased by the write that ends it. Each fresh()
|
|
21
|
+
// opens it again, so a message's new credential reaches the run's next model request; a run handed none gets its calls
|
|
22
|
+
// refused unsent (UNUSABLE.perRunMissing).
|
|
23
|
+
//
|
|
19
24
|
// fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
|
|
20
25
|
// expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
|
|
21
26
|
// only when it provably never left: a refused or unmade connection, an address check out of time; one request that left
|
|
@@ -41,7 +46,7 @@ import { githubTokens } from "./mcp-github.js";
|
|
|
41
46
|
import { ClaimRefused } from "./loop-contract.js";
|
|
42
47
|
import { REFRESH_MARGIN_MS, UNKNOWN_EXPIRY_MS, UNUSABLE } from "../mcp-probe.js";
|
|
43
48
|
import { tokenLeftOf } from "../mcp-probe.js";
|
|
44
|
-
import { openMcpCredential, sealMcpCredential } from "../store/seal.js";
|
|
49
|
+
import { openMcpCredential, openRunMcpAuth, sealMcpCredential } from "../store/seal.js";
|
|
45
50
|
import { Fenced, MCP_REFRESH_CALL_MS } from "../store/index.js";
|
|
46
51
|
/** Whether two sealed credentials are the same bytes (none equals none). */
|
|
47
52
|
const sameSealed = (a, b) => (a === null || b === null ? a === b : Buffer.from(a).equals(Buffer.from(b)));
|
|
@@ -170,6 +175,10 @@ export async function mcpClaim(options) {
|
|
|
170
175
|
// after it), kept fresh mid-run, and never stored.
|
|
171
176
|
if (row.auth === "github_app")
|
|
172
177
|
return await github.open(name, entry), { awaited: true };
|
|
178
|
+
// A per_run server keeps none either: its credential is the one the run's caller handed it (mcp_auth), sealed in the
|
|
179
|
+
// run's launch, read again at every fresh() so a message's new one reaches the run's next request.
|
|
180
|
+
if (row.auth === "per_run")
|
|
181
|
+
return entry(await perRun(name, row.url)), { awaited: false };
|
|
173
182
|
if (row.sealed === null)
|
|
174
183
|
return entry({}), { awaited: false };
|
|
175
184
|
// A seal problem first: no refresh is ever sent for a credential this runner cannot open.
|
|
@@ -287,9 +296,28 @@ export async function mcpClaim(options) {
|
|
|
287
296
|
await settle(signal);
|
|
288
297
|
return { awaited: true };
|
|
289
298
|
};
|
|
299
|
+
/** The run's handed MCP credentials, opened from its launch: read once per fresh() (perRunRead), not once per server. */
|
|
300
|
+
let perRunRead;
|
|
301
|
+
/** A per_run server's headers for this run, from its launch; or why there are none. Only for the origin its url had
|
|
302
|
+
* when they were handed: a server moved since gets none. */
|
|
303
|
+
const perRun = async (name, url) => {
|
|
304
|
+
perRunRead ??= store.runs.launch(claim.runId).then((launch) => openRunMcpAuth(sealKey, claim.runId, launch.sealed));
|
|
305
|
+
const handed = await perRunRead;
|
|
306
|
+
if (handed === undefined)
|
|
307
|
+
return { unopened: UNUSABLE.damaged };
|
|
308
|
+
const given = Object.hasOwn(handed, name) ? handed[name] : undefined;
|
|
309
|
+
if (!given)
|
|
310
|
+
return { unopened: UNUSABLE.perRunMissing };
|
|
311
|
+
if (given.origin !== new URL(url).origin)
|
|
312
|
+
return { unopened: UNUSABLE.damaged };
|
|
313
|
+
const values = Object.values(given.headers).flatMap((value) => [value, ...(/^Bearer\s+(.+)$/i.exec(value)?.slice(1) ?? [])]);
|
|
314
|
+
options.hold?.(values);
|
|
315
|
+
return { headers: { ...given.headers } };
|
|
316
|
+
};
|
|
290
317
|
const fresh = async () => {
|
|
291
318
|
if (!pin || released)
|
|
292
319
|
return;
|
|
320
|
+
perRunRead = undefined;
|
|
293
321
|
let awaited = false;
|
|
294
322
|
for (const [name, pinned] of Object.entries(pin))
|
|
295
323
|
if ((await open(name, pinned.url)).awaited)
|
|
@@ -299,7 +327,12 @@ export async function mcpClaim(options) {
|
|
|
299
327
|
await confirm(store, claim);
|
|
300
328
|
};
|
|
301
329
|
await fresh();
|
|
302
|
-
|
|
330
|
+
const beforeCall = async (server, signal) => {
|
|
331
|
+
signal.throwIfAborted();
|
|
332
|
+
if (!released)
|
|
333
|
+
await github.check(server);
|
|
334
|
+
};
|
|
335
|
+
return { pin, credentials, secrets, fresh, release, beforeCall };
|
|
303
336
|
}
|
|
304
337
|
/** The run's pin: read, and checked against the meta tools known now; or made at its first claim and written once. */
|
|
305
338
|
async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN }) {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import type { GithubPermissions } from "../github.js";
|
|
2
|
+
/** The App's answer for one repository: a token and when it expires (ms), or why not. `permissions` narrows the token
|
|
3
|
+
* below the App's own (a checkout's: contents read alone). */
|
|
2
4
|
export type GithubAppMint = (target: {
|
|
3
5
|
installation?: number;
|
|
4
6
|
repo: string;
|
|
5
|
-
}) => Promise<{
|
|
7
|
+
}, permissions?: GithubPermissions) => Promise<{
|
|
6
8
|
ok: true;
|
|
7
9
|
token: string;
|
|
8
10
|
expires_at: number;
|
|
9
11
|
} | {
|
|
10
12
|
ok: false;
|
|
11
|
-
reason: "not_installed" | "no_repo" | "github_failed";
|
|
13
|
+
reason: "not_installed" | "no_repo" | "github_failed" | "disconnected";
|
|
12
14
|
message: string;
|
|
13
15
|
}>;
|
|
14
16
|
/** What the runner gives the step for a run's github_app servers: the bound mint, and the run's repository (from its
|
|
@@ -19,6 +21,11 @@ export interface GithubAppAccess {
|
|
|
19
21
|
readonly installation?: number;
|
|
20
22
|
readonly repo: string;
|
|
21
23
|
} | undefined;
|
|
24
|
+
/** Revokes an installation token this access minted (best effort): one dropped at release or on a disconnect. */
|
|
25
|
+
readonly revoke?: (token: string) => Promise<void>;
|
|
26
|
+
/** Whether the App is still the one this access mints with (its id and key): read before each call, so a disconnect
|
|
27
|
+
* or a new App stops a run's token at its next call, not at its next mint. */
|
|
28
|
+
readonly same?: () => Promise<boolean>;
|
|
22
29
|
}
|
|
23
30
|
/** A timer the step arms: the refresh before expiry, the expiry itself. */
|
|
24
31
|
export type GithubTimer = (fire: () => void, ms: number) => {
|
|
@@ -33,6 +40,7 @@ export declare const GITHUB_UNUSABLE: {
|
|
|
33
40
|
notInstalled: (repo: string) => string;
|
|
34
41
|
failed: (message: string) => string;
|
|
35
42
|
expired: (message: string) => string;
|
|
43
|
+
disconnected: string;
|
|
36
44
|
};
|
|
37
45
|
type Entry = {
|
|
38
46
|
headers?: Record<string, string>;
|
|
@@ -47,7 +55,10 @@ export declare function githubTokens(access: GithubAppAccess | undefined, { now,
|
|
|
47
55
|
/** `name`'s token: the one held while it has more than REFRESH_BEFORE_MS left (a claim's fresh() again mints
|
|
48
56
|
* nothing), else a new one. */
|
|
49
57
|
open(name: string, put: (entry: Entry) => void): Promise<void>;
|
|
50
|
-
/**
|
|
58
|
+
/** Before a call of `name`: the token held for it, when the App it was minted under is gone or replaced, is dropped
|
|
59
|
+
* and revoked, and the server's calls refused in words. */
|
|
60
|
+
check(name: string): Promise<void>;
|
|
61
|
+
/** Every token dropped and revoked, and every timer stopped: the loop ended, or the claim is lost. */
|
|
51
62
|
release(): void;
|
|
52
63
|
};
|
|
53
64
|
export {};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// A github_app MCP server's credential for one run (the runner's MCP claim step, runner/mcp-claim.ts): an installation
|
|
2
|
-
// token the server's GitHub App mints (github.ts mintInstallationToken, given here as `mint`, its App id and key bound by
|
|
3
|
-
// the runner), narrowed to the run's repository. It is minted at every launch (each claim), held in the step's memory
|
|
4
|
-
// only (never sealed into mcp_servers, the journal or run_live: it lasts an hour and is minted again at will), joins the
|
|
5
|
-
// redaction set, and is minted again with REFRESH_BEFORE_MS left, mid-run, so a long run's calls never carry an expired
|
|
6
|
-
// token. A token that could not be renewed answers its calls in words once it expires, never a crash. One claim per run
|
|
7
|
-
// mints for itself: there is no stored token to share, so no refresh lease.
|
|
8
1
|
/** How long before its expiry a token is minted again: GitHub's tokens last an hour, so at 55 minutes. */
|
|
9
2
|
export const REFRESH_BEFORE_MS = 5 * 60_000;
|
|
10
3
|
/** Why a github_app server's calls are refused unsent, in the words the gateway gives the model. */
|
|
@@ -14,6 +7,7 @@ export const GITHUB_UNUSABLE = {
|
|
|
14
7
|
notInstalled: (repo) => `the GitHub App is not installed on ${repo}: install it from Settings → GitHub`,
|
|
15
8
|
failed: (message) => `GitHub did not make a token for this run (${message})`,
|
|
16
9
|
expired: (message) => `its GitHub App token expired and a new one could not be made (${message})`,
|
|
10
|
+
disconnected: "the GitHub App this run's token came from was disconnected or replaced on this server (Settings → GitHub)",
|
|
17
11
|
};
|
|
18
12
|
const REAL_TIMER = (fire, ms) => {
|
|
19
13
|
const timer = setTimeout(fire, Math.min(Math.max(0, ms), 2 ** 31 - 1));
|
|
@@ -24,12 +18,33 @@ const REAL_TIMER = (fire, ms) => {
|
|
|
24
18
|
* hands its entry to `put`, then keeps it fresh until `release`. */
|
|
25
19
|
export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {}) {
|
|
26
20
|
const held = new Map();
|
|
21
|
+
/** The tokens a refresh replaced, by server, until they expire: a call already sent may still carry one, so it is not
|
|
22
|
+
* revoked at the refresh, only when its server's access ends (drop) or the run's does (release). */
|
|
23
|
+
const replaced = new Map();
|
|
27
24
|
let released = false;
|
|
25
|
+
/** Each server's access epoch: a drop ends it, so a mint that was out across the drop (a refresh while check() found
|
|
26
|
+
* the App gone) installs nothing; its token is revoked. */
|
|
27
|
+
const epochs = new Map();
|
|
28
|
+
const epochOf = (name) => epochs.get(name) ?? 0;
|
|
28
29
|
const clear = (name) => {
|
|
29
30
|
for (const timer of held.get(name)?.timers ?? [])
|
|
30
31
|
timer.clear();
|
|
31
32
|
held.delete(name);
|
|
32
33
|
};
|
|
34
|
+
const revoke = (token) => void access?.revoke?.(token).catch(() => undefined);
|
|
35
|
+
/** `name`'s tokens, the one held and every one a refresh replaced that has not expired, revoked at GitHub as they are
|
|
36
|
+
* dropped: never left live past its run or its App. */
|
|
37
|
+
const drop = (name) => {
|
|
38
|
+
epochs.set(name, epochOf(name) + 1);
|
|
39
|
+
const token = held.get(name)?.token;
|
|
40
|
+
clear(name);
|
|
41
|
+
if (token)
|
|
42
|
+
revoke(token);
|
|
43
|
+
for (const old of replaced.get(name) ?? [])
|
|
44
|
+
if (old.expiresAt > now())
|
|
45
|
+
revoke(old.token);
|
|
46
|
+
replaced.delete(name);
|
|
47
|
+
};
|
|
33
48
|
/** A token minted for `name` and put; its refresh and its expiry armed. On a refresh that fails, the token held keeps
|
|
34
49
|
* working until it expires, then the server's calls are refused in words. */
|
|
35
50
|
const mint = async (name, put, refreshing) => {
|
|
@@ -37,6 +52,7 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
|
|
|
37
52
|
return put({ unopened: GITHUB_UNUSABLE.noAccess });
|
|
38
53
|
if (!access.target)
|
|
39
54
|
return put({ unopened: GITHUB_UNUSABLE.noRepo });
|
|
55
|
+
const epoch = epochOf(name);
|
|
40
56
|
let got;
|
|
41
57
|
try {
|
|
42
58
|
got = await access.mint(access.target);
|
|
@@ -44,8 +60,18 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
|
|
|
44
60
|
catch (error) {
|
|
45
61
|
got = { ok: false, reason: "github_failed", message: String(error?.message ?? error) };
|
|
46
62
|
}
|
|
47
|
-
|
|
63
|
+
// A mint that came back after the run's access ended, or the server's (its token dropped meanwhile, its calls
|
|
64
|
+
// refused): its token is revoked at once, never held, and the refusal stands.
|
|
65
|
+
if (released || epochOf(name) !== epoch) {
|
|
66
|
+
if (got.ok)
|
|
67
|
+
revoke(got.token);
|
|
48
68
|
return;
|
|
69
|
+
}
|
|
70
|
+
// The App disconnected or replaced since the claim: the token held stops now, revoked, never used to its expiry.
|
|
71
|
+
if (!got.ok && got.reason === "disconnected") {
|
|
72
|
+
drop(name);
|
|
73
|
+
return put({ unopened: GITHUB_UNUSABLE.disconnected });
|
|
74
|
+
}
|
|
49
75
|
if (!got.ok) {
|
|
50
76
|
const why = got.reason === "not_installed" ? GITHUB_UNUSABLE.notInstalled(access.target.repo) : got.reason === "no_repo" ? GITHUB_UNUSABLE.noRepo : GITHUB_UNUSABLE.failed(got.message);
|
|
51
77
|
const kept = held.get(name);
|
|
@@ -64,6 +90,9 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
|
|
|
64
90
|
clear(name);
|
|
65
91
|
return put({ unopened: why });
|
|
66
92
|
}
|
|
93
|
+
const previous = held.get(name);
|
|
94
|
+
if (previous && previous.token !== got.token)
|
|
95
|
+
replaced.set(name, [...(replaced.get(name) ?? []).filter((old) => old.expiresAt > now()), { token: previous.token, expiresAt: previous.expiresAt }]);
|
|
67
96
|
clear(name);
|
|
68
97
|
const entry = { token: got.token, expiresAt: got.expires_at, timers: [], put };
|
|
69
98
|
held.set(name, entry);
|
|
@@ -81,11 +110,26 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
|
|
|
81
110
|
}
|
|
82
111
|
await mint(name, put, false);
|
|
83
112
|
},
|
|
84
|
-
/**
|
|
113
|
+
/** Before a call of `name`: the token held for it, when the App it was minted under is gone or replaced, is dropped
|
|
114
|
+
* and revoked, and the server's calls refused in words. */
|
|
115
|
+
async check(name) {
|
|
116
|
+
const kept = held.get(name);
|
|
117
|
+
// A read that fails throws on: the gateway refuses the call unsent, the token kept (fail closed, never dropped).
|
|
118
|
+
if (!kept || !access?.same || (await access.same()))
|
|
119
|
+
return;
|
|
120
|
+
if (released)
|
|
121
|
+
return;
|
|
122
|
+
// The App is gone or replaced: whatever is held now (a refresh may have replaced the token while the read waited)
|
|
123
|
+
// is dropped and revoked, and the server's calls refused, never sent on the replacement.
|
|
124
|
+
const now_ = held.get(name) ?? kept;
|
|
125
|
+
drop(name);
|
|
126
|
+
now_.put({ unopened: GITHUB_UNUSABLE.disconnected });
|
|
127
|
+
},
|
|
128
|
+
/** Every token dropped and revoked, and every timer stopped: the loop ended, or the claim is lost. */
|
|
85
129
|
release() {
|
|
86
130
|
released = true;
|
|
87
|
-
for (const name of [...held.keys()])
|
|
88
|
-
|
|
131
|
+
for (const name of new Set([...held.keys(), ...replaced.keys()]))
|
|
132
|
+
drop(name);
|
|
89
133
|
},
|
|
90
134
|
};
|
|
91
135
|
}
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface McpForClaimOptions {
|
|
|
48
48
|
connectMs?: number;
|
|
49
49
|
};
|
|
50
50
|
readonly githubTimer?: GithubTimer;
|
|
51
|
+
/** Each credential value the claim opens for a per_run server, for the run's redactors (mcp-claim.ts `hold`). */
|
|
52
|
+
readonly hold?: (values: string[]) => void;
|
|
51
53
|
}
|
|
52
54
|
/** A call as the loop's gate is asked about it: the tool by its catalog name. */
|
|
53
55
|
export type McpGateCall = {
|
package/dist/runner/mcp-run.js
CHANGED
|
@@ -29,6 +29,7 @@ export async function mcpForClaim(options) {
|
|
|
29
29
|
...(githubApp ? { githubApp } : {}),
|
|
30
30
|
...(options.githubMcpOrigin ? { githubMcpOrigin: options.githubMcpOrigin } : {}),
|
|
31
31
|
...(options.githubTimer ? { githubTimer: options.githubTimer } : {}),
|
|
32
|
+
...(options.hold ? { hold: options.hold } : {}),
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
catch (error) {
|
|
@@ -43,6 +44,7 @@ export async function mcpForClaim(options) {
|
|
|
43
44
|
const gateway = mcpGateway({
|
|
44
45
|
pin,
|
|
45
46
|
credentials: step.credentials,
|
|
47
|
+
beforeCall: step.beforeCall,
|
|
46
48
|
work: options.work,
|
|
47
49
|
commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
|
|
48
50
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
package/dist/runner/metrics.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { type DecisionLike, type EntryLike, type RunMetrics } from "../timeline/index.js";
|
|
2
2
|
/** What a run's booking says one of its sessions spent: its requests (a hold given back unused is none), their known
|
|
3
|
-
* sum, how many have no known cost, and
|
|
3
|
+
* sum, how many have no known cost, their tokens, and how many of the requests have no known tokens (`unmetered`: booked
|
|
4
|
+
* with no usage, or sent and never answered), in no token sum; and its requests by the model each was sent on (`models`:
|
|
5
|
+
* its runner.request's model, "" for one that names none). */
|
|
4
6
|
export type BookedSpend = {
|
|
5
7
|
readonly usd: number | null;
|
|
6
8
|
readonly known: number;
|
|
7
9
|
readonly unpriced: number;
|
|
8
10
|
readonly requests: number;
|
|
11
|
+
readonly unmetered: number;
|
|
12
|
+
readonly models: Readonly<Record<string, number>>;
|
|
9
13
|
readonly tokens: {
|
|
10
14
|
input: number;
|
|
11
15
|
output: number;
|
|
@@ -23,6 +27,10 @@ export type BookedSpend = {
|
|
|
23
27
|
* a workflow's model nodes (pi-ai's $0 for a model it has no price for): their model requests' cost is this, the
|
|
24
28
|
* booking's. */
|
|
25
29
|
export declare function bookedSpend(entries: readonly EntryLike[], which: "model" | "paid" | "decisions"): BookedSpend;
|
|
30
|
+
/** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
|
|
31
|
+
* its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
|
|
32
|
+
* past its model proxy) spent what no booking read: its cost is unknown, never $0. */
|
|
33
|
+
export declare function cliModelWorked(entries: readonly EntryLike[]): boolean;
|
|
26
34
|
/** 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
|
|
27
35
|
* harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
|
|
28
36
|
* booking (adapters/pi.ts afterResponse). */
|
|
@@ -31,6 +39,11 @@ export declare function costIsBooked(entries: readonly EntryLike[], cli: boolean
|
|
|
31
39
|
* out at its hold and bound), for a run whose cost is its booking: the runs list's figure while it runs. Null when one
|
|
32
40
|
* session's is unknown, never 0 for it. */
|
|
33
41
|
export declare function bookedCapSpend(entries: readonly EntryLike[]): number | null;
|
|
42
|
+
/** The bound of a run's requests since its spend last fit under `capUsd`, as the kernel's overCapOf reads it: each model
|
|
43
|
+
* request, in each model session's order, at the figure the cap counts it at, after what the paid tools and decisions
|
|
44
|
+
* spent; reset to 0 whenever the spend fits, else grown by each request's bound. What its over-cap row (run-view.ts
|
|
45
|
+
* withOverCap) reads to tell a cache miss within that bound from a run that spent past its cap. 0 when nothing ran. */
|
|
46
|
+
export declare function overCapBound(entries: readonly EntryLike[], capUsd: number): number;
|
|
34
47
|
/** A run's metrics as the end commit writes them (the StoredMetrics JSON on the run row): the timeline's count, with the
|
|
35
48
|
* effort the run ran at and, on a harness other than pi, the model its revision named. */
|
|
36
49
|
export type RunMetricsStored = RunMetrics & {
|
|
@@ -48,3 +61,7 @@ export declare function runMetrics(entries: readonly EntryLike[], options?: {
|
|
|
48
61
|
metrics: RunMetricsStored;
|
|
49
62
|
costUsd: number | null;
|
|
50
63
|
};
|
|
64
|
+
export declare function cliRunMetrics(rootEntries: readonly EntryLike[], booked: BookedSpend, options: {
|
|
65
|
+
readonly effort?: string;
|
|
66
|
+
readonly model: string;
|
|
67
|
+
}): RunMetricsStored;
|