@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +90 -8
- package/dist/archil-settings.js +150 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// A fake GitHub for a server started with --faux and --faux-github: an App already connected, served by GitHub's API as an
|
|
2
|
+
// in-process server on loopback, so the console's GitHub flows (Settings → GitHub connected, a github trigger made, a
|
|
3
|
+
// signed delivery fired) run in a real browser with nothing sent to GitHub. It answers the API calls the server makes of
|
|
4
|
+
// the App (github.ts, github-connection.ts): the App's installations, one installation's read, an installation token's
|
|
5
|
+
// mint narrowed to the repositories asked, that token's read of the repositories it covers and its revoke, and which
|
|
6
|
+
// installation covers a repository. The App, its private key and its webhook secret are made fresh at each start; a test
|
|
7
|
+
// signs a delivery with the webhook secret, kept beside the data (FAUX_GITHUB_FILE). Never on a server without --faux.
|
|
8
|
+
import { generateKeyPairSync, randomBytes } from "node:crypto";
|
|
9
|
+
import { createServer } from "node:http";
|
|
10
|
+
/** The file beside the data that tells a test the fake App's webhook secret, installation and repositories. */
|
|
11
|
+
export const FAUX_GITHUB_FILE = "faux-github.json";
|
|
12
|
+
/** The fake App's one installation and the repositories it covers. */
|
|
13
|
+
export const FAUX_GITHUB = { appId: "1", slug: "agentrun-faux", installation: 1, account: "faux-org", repositories: ["faux-org/demo"] };
|
|
14
|
+
const TOKEN_MS = 60 * 60_000;
|
|
15
|
+
/** Starts the fake GitHub API on loopback, with its App. */
|
|
16
|
+
export async function startFauxGitHub() {
|
|
17
|
+
const { privateKey } = generateKeyPairSync("rsa", { modulusLength: 2048, privateKeyEncoding: { type: "pkcs1", format: "pem" }, publicKeyEncoding: { type: "spki", format: "pem" } });
|
|
18
|
+
const app = { id: FAUX_GITHUB.appId, slug: FAUX_GITHUB.slug, clientId: `Iv1.faux${randomBytes(6).toString("hex")}`, pem: privateKey, webhookSecret: randomBytes(24).toString("hex"), settingsUrl: `https://github.com/organizations/${FAUX_GITHUB.account}/settings/apps/${FAUX_GITHUB.slug}` };
|
|
19
|
+
const installation = { id: FAUX_GITHUB.installation, account: { login: FAUX_GITHUB.account, type: "Organization" }, app_id: Number(FAUX_GITHUB.appId), suspended_at: null };
|
|
20
|
+
/** Each token minted, by its value: the repositories it was narrowed to (by name), or every one the installation covers. */
|
|
21
|
+
const tokens = new Map();
|
|
22
|
+
const covered = (names) => FAUX_GITHUB.repositories.filter((full) => !names || names.includes(full.split("/")[1]));
|
|
23
|
+
const answer = (res, status, doc) => {
|
|
24
|
+
res.writeHead(status, doc === undefined ? {} : { "content-type": "application/json" });
|
|
25
|
+
res.end(doc === undefined ? undefined : JSON.stringify(doc));
|
|
26
|
+
};
|
|
27
|
+
const handle = (req, res, body) => {
|
|
28
|
+
const path = (req.url ?? "/").split("?")[0];
|
|
29
|
+
if (req.method === "GET" && path === "/app/installations")
|
|
30
|
+
return answer(res, 200, [installation]);
|
|
31
|
+
if (req.method === "GET" && path === `/app/installations/${installation.id}`)
|
|
32
|
+
return answer(res, 200, installation);
|
|
33
|
+
if (req.method === "POST" && path === `/app/installations/${installation.id}/access_tokens`) {
|
|
34
|
+
let asked = {};
|
|
35
|
+
try {
|
|
36
|
+
asked = JSON.parse(body || "{}");
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return answer(res, 400, { message: "Problems parsing JSON" });
|
|
40
|
+
}
|
|
41
|
+
const names = Array.isArray(asked.repositories) ? asked.repositories.filter((name) => typeof name === "string") : undefined;
|
|
42
|
+
if (names && covered(names).length !== names.length)
|
|
43
|
+
return answer(res, 422, { message: "There is at least one repository that does not exist or is not accessible to the parent installation." });
|
|
44
|
+
const token = `faux-installation-token-${randomBytes(16).toString("hex")}`;
|
|
45
|
+
tokens.set(token, names);
|
|
46
|
+
return answer(res, 201, { token, expires_at: new Date(Date.now() + TOKEN_MS).toISOString(), permissions: { metadata: "read", contents: "read", pull_requests: "write", issues: "read" }, repository_selection: "selected" });
|
|
47
|
+
}
|
|
48
|
+
const bearer = String(req.headers.authorization ?? "").replace(/^Bearer /, "");
|
|
49
|
+
if (req.method === "GET" && path === "/installation/repositories") {
|
|
50
|
+
if (!tokens.has(bearer))
|
|
51
|
+
return answer(res, 401, { message: "Bad credentials" });
|
|
52
|
+
const full = covered(tokens.get(bearer));
|
|
53
|
+
return answer(res, 200, { total_count: full.length, repositories: full.map((name) => ({ name: name.split("/")[1], full_name: name })) });
|
|
54
|
+
}
|
|
55
|
+
if (req.method === "DELETE" && path === "/installation/token") {
|
|
56
|
+
if (!tokens.delete(bearer))
|
|
57
|
+
return answer(res, 401, { message: "Bad credentials" });
|
|
58
|
+
return answer(res, 204);
|
|
59
|
+
}
|
|
60
|
+
const repo = /^\/repos\/([^/]+)\/([^/]+)\/installation$/.exec(path);
|
|
61
|
+
if (req.method === "GET" && repo)
|
|
62
|
+
return FAUX_GITHUB.repositories.includes(`${repo[1]}/${repo[2]}`) ? answer(res, 200, installation) : answer(res, 404, { message: "Not Found" });
|
|
63
|
+
return answer(res, 404, { message: "Not Found" });
|
|
64
|
+
};
|
|
65
|
+
const server = createServer((req, res) => {
|
|
66
|
+
let body = "";
|
|
67
|
+
req.setEncoding("utf8").on("data", (chunk) => (body += chunk)).on("end", () => handle(req, res, body));
|
|
68
|
+
});
|
|
69
|
+
const host = "127.0.0.1";
|
|
70
|
+
await new Promise((resolve, reject) => server.once("error", reject).listen(0, host, () => resolve()));
|
|
71
|
+
return {
|
|
72
|
+
url: `http://${host}:${server.address().port}`,
|
|
73
|
+
app,
|
|
74
|
+
close: () => new Promise((resolve) => (server.close(() => resolve()), server.closeAllConnections())),
|
|
75
|
+
};
|
|
76
|
+
}
|
package/dist/github.d.ts
CHANGED
|
@@ -24,15 +24,19 @@ export declare function githubCall(api: string, path: string, options?: {
|
|
|
24
24
|
json: unknown;
|
|
25
25
|
headers: Headers;
|
|
26
26
|
}>;
|
|
27
|
+
/** Permissions an installation token is narrowed to (GitHub's access_tokens `permissions`), each at most what the App has:
|
|
28
|
+
* none given, the App's own. A checkout's is {contents: "read"} alone. */
|
|
29
|
+
export type GithubPermissions = Readonly<Record<string, "read" | "write">>;
|
|
27
30
|
/** An installation token of the App `appId` (its private key `pem`) for one repository: `target.installation`, or the
|
|
28
31
|
* installation GitHub says covers `target.repo` (GET /repos/{owner}/{repo}/installation, asked with the App's JWT); then
|
|
29
|
-
* POST /app/installations/{id}/access_tokens narrowed to that one repository, with the App's permissions
|
|
32
|
+
* POST /app/installations/{id}/access_tokens narrowed to that one repository, with the App's permissions or the narrower
|
|
33
|
+
* `permissions` given. Pure apart
|
|
30
34
|
* from the calls to GitHub at `api`: serve's launch path mints with it today, and a runner can tomorrow; the run never
|
|
31
35
|
* sees the key. `expires_at` in ms. */
|
|
32
36
|
export declare function mintInstallationToken(api: string, appId: string, pem: string, target: {
|
|
33
37
|
installation?: number;
|
|
34
38
|
repo: string;
|
|
35
|
-
}, nowMs?: number): Promise<{
|
|
39
|
+
}, nowMs?: number, permissions?: GithubPermissions): Promise<{
|
|
36
40
|
ok: true;
|
|
37
41
|
token: string;
|
|
38
42
|
expires_at: number;
|
|
@@ -57,8 +61,28 @@ export declare const GITHUB_FIELDS: {
|
|
|
57
61
|
export declare const GITHUB_SCOPE = "server";
|
|
58
62
|
/** The repository a run is about, from its first message: the GitHub event it was started for (the server's own payload
|
|
59
63
|
* tag, the first one, with its installation and repository), else the first https://github.com/<owner>/<repo> its owner's
|
|
60
|
-
* words name, before any payload (a sender's text is never read for it). Undefined when it names none.
|
|
61
|
-
|
|
64
|
+
* words name, before any payload (a sender's text is never read for it). Undefined when it names none. The tag is read only
|
|
65
|
+
* for a run a github trigger started (`payload`, from its launch's inputOrigin): anyone may write the tag's text into a
|
|
66
|
+
* run of their own, and it names an installation. */
|
|
67
|
+
export declare function githubTargetOf(content: unknown, { payload }?: {
|
|
68
|
+
payload?: boolean;
|
|
69
|
+
}): {
|
|
62
70
|
installation?: number;
|
|
63
71
|
repo: string;
|
|
64
72
|
} | undefined;
|
|
73
|
+
/** A pull request as a run's GitHub event names it: its repository (owner/name), the installation that sent it, its
|
|
74
|
+
* number, its head sha and, when the event carries one, its base sha. */
|
|
75
|
+
export type GithubPull = {
|
|
76
|
+
readonly repo: string;
|
|
77
|
+
readonly installation?: number;
|
|
78
|
+
readonly number: number;
|
|
79
|
+
readonly head: string;
|
|
80
|
+
readonly base?: string;
|
|
81
|
+
};
|
|
82
|
+
/** The pull request a run was started for: read from its first message's payload tag alone (the server's, made from a
|
|
83
|
+
* signed GitHub delivery: trigger-signatures.ts attrsOf), never from anyone's words, and only for a run a github trigger
|
|
84
|
+
* started (`payload`, from its launch's inputOrigin, as githubTargetOf reads it). Undefined when the run was not started
|
|
85
|
+
* by a GitHub event about a pull request with a head (a comment event has none). */
|
|
86
|
+
export declare function githubPullOf(content: unknown, { payload }?: {
|
|
87
|
+
payload?: boolean;
|
|
88
|
+
}): GithubPull | undefined;
|
package/dist/github.js
CHANGED
|
@@ -58,10 +58,11 @@ export async function githubCall(api, path, options = {}) {
|
|
|
58
58
|
}
|
|
59
59
|
/** An installation token of the App `appId` (its private key `pem`) for one repository: `target.installation`, or the
|
|
60
60
|
* installation GitHub says covers `target.repo` (GET /repos/{owner}/{repo}/installation, asked with the App's JWT); then
|
|
61
|
-
* POST /app/installations/{id}/access_tokens narrowed to that one repository, with the App's permissions
|
|
61
|
+
* POST /app/installations/{id}/access_tokens narrowed to that one repository, with the App's permissions or the narrower
|
|
62
|
+
* `permissions` given. Pure apart
|
|
62
63
|
* from the calls to GitHub at `api`: serve's launch path mints with it today, and a runner can tomorrow; the run never
|
|
63
64
|
* sees the key. `expires_at` in ms. */
|
|
64
|
-
export async function mintInstallationToken(api, appId, pem, target, nowMs) {
|
|
65
|
+
export async function mintInstallationToken(api, appId, pem, target, nowMs, permissions) {
|
|
65
66
|
const [owner, name, extra] = target.repo.split("/");
|
|
66
67
|
if (!owner || !name || extra !== undefined || !/^[A-Za-z0-9-]{1,39}$/.test(owner) || !/^[A-Za-z0-9._-]{1,100}$/.test(name))
|
|
67
68
|
return { ok: false, reason: "no_repo", message: "No GitHub repository was named for this run: a GitHub event's run has one; another run names it in its input as https://github.com/<owner>/<repo>." };
|
|
@@ -78,7 +79,7 @@ export async function mintInstallationToken(api, appId, pem, target, nowMs) {
|
|
|
78
79
|
return { ok: false, reason: "github_failed", message: `GitHub did not say which installation covers ${owner}/${name} (HTTP ${found.status}).` };
|
|
79
80
|
installation = id;
|
|
80
81
|
}
|
|
81
|
-
const answer = await githubCall(api, `/app/installations/${installation}/access_tokens`, { method: "POST", jwt, body: { repositories: [name] } });
|
|
82
|
+
const answer = await githubCall(api, `/app/installations/${installation}/access_tokens`, { method: "POST", jwt, body: { repositories: [name], ...(permissions ? { permissions } : {}) } });
|
|
82
83
|
const minted = (typeof answer.json === "object" && answer.json !== null ? answer.json : {});
|
|
83
84
|
if (answer.status === 404 || answer.status === 422)
|
|
84
85
|
return notInstalled;
|
|
@@ -99,21 +100,56 @@ export const GITHUB_FIELDS = { appId: "app_id", slug: "slug", clientId: "client_
|
|
|
99
100
|
export const GITHUB_SCOPE = "server";
|
|
100
101
|
const unescapeAttr = (value) => value.replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
101
102
|
const REPO_URL = /https:\/\/github\.com\/([A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38})\/([A-Za-z0-9._-]{1,100})/;
|
|
103
|
+
/** The attributes of the first payload tag in `content` (the server's own, triggers.ts inputOf: each value escaped), or
|
|
104
|
+
* undefined when it has none. */
|
|
105
|
+
function payloadAttrs(content) {
|
|
106
|
+
const at = content.indexOf("<trigger-payload ");
|
|
107
|
+
if (at < 0)
|
|
108
|
+
return undefined;
|
|
109
|
+
const tag = content.slice(at, content.indexOf(">", at) + 1);
|
|
110
|
+
return { at, attrs: Object.fromEntries([...tag.matchAll(/ ([a-z][a-z0-9_-]*)="([^"]*)"/g)].map((m) => [m[1], unescapeAttr(m[2])])) };
|
|
111
|
+
}
|
|
102
112
|
/** The repository a run is about, from its first message: the GitHub event it was started for (the server's own payload
|
|
103
113
|
* tag, the first one, with its installation and repository), else the first https://github.com/<owner>/<repo> its owner's
|
|
104
|
-
* words name, before any payload (a sender's text is never read for it). Undefined when it names none.
|
|
105
|
-
|
|
114
|
+
* words name, before any payload (a sender's text is never read for it). Undefined when it names none. The tag is read only
|
|
115
|
+
* for a run a github trigger started (`payload`, from its launch's inputOrigin): anyone may write the tag's text into a
|
|
116
|
+
* run of their own, and it names an installation. */
|
|
117
|
+
export function githubTargetOf(content, { payload = false } = {}) {
|
|
106
118
|
if (typeof content !== "string")
|
|
107
119
|
return undefined;
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
111
|
-
const attrs = Object.fromEntries([...tag.matchAll(/ ([a-z][a-z0-9_-]*)="([^"]*)"/g)].map((m) => [m[1], unescapeAttr(m[2])]));
|
|
120
|
+
const tag = payloadAttrs(content);
|
|
121
|
+
if (tag && payload) {
|
|
122
|
+
const { attrs } = tag;
|
|
112
123
|
if (attrs.source === "github" && typeof attrs.repo === "string" && /^[^/\s]+\/[^/\s]+$/.test(attrs.repo))
|
|
113
124
|
return { repo: attrs.repo, ...(/^\d{1,15}$/.test(attrs.installation ?? "") ? { installation: Number(attrs.installation) } : {}) };
|
|
114
125
|
}
|
|
115
|
-
const own =
|
|
126
|
+
const own = tag ? content.slice(0, tag.at) : content;
|
|
116
127
|
const url = REPO_URL.exec(own);
|
|
117
128
|
// The repository's name ends where the sentence does: trailing punctuation, then a .git, are not part of it.
|
|
118
129
|
return url ? { repo: `${url[1]}/${url[2].replace(/[.,;:)!?]+$/, "").replace(/\.git$/, "")}` } : undefined;
|
|
119
130
|
}
|
|
131
|
+
const SHA = /^[0-9a-f]{40}$/;
|
|
132
|
+
const OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
|
|
133
|
+
const NAME = /^[A-Za-z0-9._-]{1,100}$/;
|
|
134
|
+
/** The pull request a run was started for: read from its first message's payload tag alone (the server's, made from a
|
|
135
|
+
* signed GitHub delivery: trigger-signatures.ts attrsOf), never from anyone's words, and only for a run a github trigger
|
|
136
|
+
* started (`payload`, from its launch's inputOrigin, as githubTargetOf reads it). Undefined when the run was not started
|
|
137
|
+
* by a GitHub event about a pull request with a head (a comment event has none). */
|
|
138
|
+
export function githubPullOf(content, { payload = false } = {}) {
|
|
139
|
+
if (typeof content !== "string" || !payload)
|
|
140
|
+
return undefined;
|
|
141
|
+
const attrs = payloadAttrs(content)?.attrs;
|
|
142
|
+
if (!attrs || attrs.source !== "github")
|
|
143
|
+
return undefined;
|
|
144
|
+
const [owner, name, extra] = (attrs.repo ?? "").split("/");
|
|
145
|
+
if (!owner || !name || extra !== undefined || !OWNER.test(owner) || !NAME.test(name) || name === "." || name === "..")
|
|
146
|
+
return undefined;
|
|
147
|
+
const number = Number(attrs.number);
|
|
148
|
+
if (!/^\d{1,15}$/.test(attrs.number ?? "") || number < 1 || !SHA.test(attrs.head_sha ?? ""))
|
|
149
|
+
return undefined;
|
|
150
|
+
return {
|
|
151
|
+
repo: `${owner}/${name}`, number, head: attrs.head_sha,
|
|
152
|
+
...(SHA.test(attrs.base_sha ?? "") ? { base: attrs.base_sha } : {}),
|
|
153
|
+
...(/^\d{1,15}$/.test(attrs.installation ?? "") ? { installation: Number(attrs.installation) } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type GpuCapability, type GpuSpec } from "@parcha/agentrun-computer";
|
|
2
|
+
/** What a run's sandbox on `label` can't have when its GPU computer can't mount the run's folder, why, and what to use. */
|
|
3
|
+
export declare const gpuNoFolder: (label: string, unmounted: GpuCapability["unmounted"]) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Why `asked` can't be had from a provider declaring `offered`, with the run's folder as `mount`: checkGpu's words for
|
|
6
|
+
* the GPU itself, `folder: false`; gpuNoFolder's when only the folder's mount is refused, `folder: true`; undefined when
|
|
7
|
+
* it can be had.
|
|
8
|
+
*/
|
|
9
|
+
export declare function gpuRefused(asked: GpuSpec | unknown, offered: GpuCapability | undefined, mount: {
|
|
10
|
+
kind: string;
|
|
11
|
+
}, label: string): {
|
|
12
|
+
words: string;
|
|
13
|
+
folder: boolean;
|
|
14
|
+
} | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Why a sandbox's GPUs can't be had here, in one place for every serve answer that says so: the save's warning and the
|
|
2
|
+
// run's start (resolve-computer.ts), the claim (computers.ts), and Settings' gpu.why. checkGpu's words for the GPU
|
|
3
|
+
// itself (a type or a count the provider doesn't give); for the run's folder, the provider's own reason, from its
|
|
4
|
+
// descriptor (GpuCapability.unmounted), so serve names no vendor: no GPU computer mounts the folder yet, and the
|
|
5
|
+
// library's GPU computers work without it.
|
|
6
|
+
import { checkGpu } from "@parcha/agentrun-computer";
|
|
7
|
+
/** What a run's sandbox on `label` can't have when its GPU computer can't mount the run's folder, why, and what to use. */
|
|
8
|
+
export const gpuNoFolder = (label, unmounted) => `A ${label} GPU computer can't mount this run's folder${unmounted?.yet === false ? "" : " yet"}${unmounted ? `: ${unmounted.why}` : ""}. Use a GPU computer from the library, or this sandbox without a GPU.`;
|
|
9
|
+
/**
|
|
10
|
+
* Why `asked` can't be had from a provider declaring `offered`, with the run's folder as `mount`: checkGpu's words for
|
|
11
|
+
* the GPU itself, `folder: false`; gpuNoFolder's when only the folder's mount is refused, `folder: true`; undefined when
|
|
12
|
+
* it can be had.
|
|
13
|
+
*/
|
|
14
|
+
export function gpuRefused(asked, offered, mount, label) {
|
|
15
|
+
const declared = offered ? { gpu: offered } : {};
|
|
16
|
+
const [itself] = checkGpu(asked, declared);
|
|
17
|
+
if (itself)
|
|
18
|
+
return { words: itself.message, folder: false };
|
|
19
|
+
const [withFolder] = checkGpu(asked, declared, mount);
|
|
20
|
+
return withFolder ? { words: gpuNoFolder(label, offered?.unmounted), folder: true } : undefined;
|
|
21
|
+
}
|
package/dist/graph-served.d.ts
CHANGED
|
@@ -19,9 +19,11 @@ export declare const graphWalks: {
|
|
|
19
19
|
* - its nodes, each decision and each call through servedPart (a map item's label and an error cut short after);
|
|
20
20
|
* - every other top-level field (its run, its workflow, its structure `graph`, which echoes the workflow's nodes and their
|
|
21
21
|
* words, its totals, and any field added later) through redactedOutput, each by itself, its keys included;
|
|
22
|
-
* - `read_at`, which moves with every read
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* - `read_at`, which moves with every read: the server's clock as toISOString writes it, served as it is, never kept;
|
|
23
|
+
* anything else under the name is cut each read.
|
|
24
|
+
* Each part and each field, its name and its value, scalar or not, is cut once per content and held set and kept in
|
|
25
|
+
* `cache` as cut (never as read), so a poll that reads the same graph with the same values cuts nothing again, and a key
|
|
26
|
+
* saved since makes a new set, cut on the next read. What holds no held value (ids, times,
|
|
25
27
|
* statuses) comes through as it was. */
|
|
26
28
|
export declare function servedGraphView<T extends {
|
|
27
29
|
nodes: unknown;
|
package/dist/graph-served.js
CHANGED
|
@@ -38,14 +38,18 @@ export function servedPart(kind, value, values) {
|
|
|
38
38
|
* nothing, with no clock. */
|
|
39
39
|
export const graphWalks = { part: 0, rest: 0 };
|
|
40
40
|
const isRecordOrArray = (value) => typeof value === "object" && value !== null;
|
|
41
|
+
/** A time as Date's toISOString writes it, and nothing else: digits, its fixed separators and Z. */
|
|
42
|
+
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
41
43
|
/** A graph view as GET /runs/{id}/graph serves it with `values` held, every field of it cut by the one rule (redactedOutput
|
|
42
44
|
* over the same values), the parts by the file path's rule on top:
|
|
43
45
|
* - its nodes, each decision and each call through servedPart (a map item's label and an error cut short after);
|
|
44
46
|
* - every other top-level field (its run, its workflow, its structure `graph`, which echoes the workflow's nodes and their
|
|
45
47
|
* words, its totals, and any field added later) through redactedOutput, each by itself, its keys included;
|
|
46
|
-
* - `read_at`, which moves with every read
|
|
47
|
-
*
|
|
48
|
-
*
|
|
48
|
+
* - `read_at`, which moves with every read: the server's clock as toISOString writes it, served as it is, never kept;
|
|
49
|
+
* anything else under the name is cut each read.
|
|
50
|
+
* Each part and each field, its name and its value, scalar or not, is cut once per content and held set and kept in
|
|
51
|
+
* `cache` as cut (never as read), so a poll that reads the same graph with the same values cuts nothing again, and a key
|
|
52
|
+
* saved since makes a new set, cut on the next read. What holds no held value (ids, times,
|
|
49
53
|
* statuses) comes through as it was. */
|
|
50
54
|
export function servedGraphView(view, values, cache) {
|
|
51
55
|
const digest = (value) => createHash("sha256").update(JSON.stringify(value) ?? "").digest("hex");
|
|
@@ -62,11 +66,15 @@ export function servedGraphView(view, values, cache) {
|
|
|
62
66
|
const { nodes, decisions, effects, read_at: readAt, ...rest } = view;
|
|
63
67
|
const fields = {};
|
|
64
68
|
for (const [name, value] of Object.entries(rest)) {
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
// A field's name and its value, scalar or not, each cut once per content and held set: a poll walks none again.
|
|
70
|
+
// (graphWalks.rest counts the walks of a field that holds more than one value, as before.)
|
|
71
|
+
const cutName = kept(`name:${keys}:${digest(name)}`, () => redactedOutput(name, values));
|
|
72
|
+
fields[cutName] = kept(`field:${keys}:${digest(name)}:${digest(value)}`, () => (isRecordOrArray(value) && graphWalks.rest++, redactedOutput(value, values)));
|
|
67
73
|
}
|
|
68
74
|
return {
|
|
69
|
-
|
|
75
|
+
// The read's own time, the server's clock as toISOString writes it, holds nothing of the run: served as it is. Any other
|
|
76
|
+
// value under the name is cut, each read, as before.
|
|
77
|
+
...(readAt === undefined ? {} : { read_at: typeof readAt === "string" && ISO_TIME.test(readAt) ? readAt : redactedOutput(readAt, values) }),
|
|
70
78
|
...fields,
|
|
71
79
|
nodes: part("nodes", nodes),
|
|
72
80
|
decisions: decisions.map((value) => part("decision", value)),
|
package/dist/graph-view.d.ts
CHANGED
package/dist/graph-view.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { llmAnswers, readLiveView
|
|
1
|
+
import { llmAnswers, readLiveView } from "./pause.js";
|
|
2
|
+
import { KINDS } from "./runner/journal-kinds.js";
|
|
3
|
+
/** The model nodes (graph.ts's model kinds): each runs on its tier's model, else the run's own. */
|
|
4
|
+
const MODEL_KINDS = new Set(["agent", "decide", "extract", "report"]);
|
|
2
5
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
6
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
7
|
const at = (state, path) => path.split(".").reduce((value, key) => (isObject(value) ? value[key] : undefined), state);
|
|
@@ -49,7 +52,10 @@ export async function runGraph(given) {
|
|
|
49
52
|
readAt = live.at;
|
|
50
53
|
view = { status: nodeStatus(graph, { pin: pin, result: null }) };
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
// The call nodes' effects, as the runner logged each one's start and end on the run's journal (KINDS.nodeEffect).
|
|
56
|
+
const { runEntries } = await import("./store-reads/journal.js");
|
|
57
|
+
const entries = await runEntries(given.store, id, given.context);
|
|
58
|
+
const lines = entries.filter((entry) => entry.kind === KINDS.nodeEffect).map((entry) => entry.data);
|
|
53
59
|
const nodeAt = (path) => (typeof path === "string" ? (graphNodeOf(graph, path)?.path ?? (graph.nodes.some((n) => n.path === path) ? path : undefined)) : undefined);
|
|
54
60
|
const kinds = new Map(graph.nodes.map((node) => [node.path, node.kind]));
|
|
55
61
|
// Each node's state, `not-run` read as pending until the run ends.
|
|
@@ -205,6 +211,27 @@ export async function runGraph(given) {
|
|
|
205
211
|
const calls = llmAnswers(lines).slice(given.llmRead ?? 0).map((line) => (isObject(line.output) && typeof line.output.cost_usd === "number" ? line.output.cost_usd : null));
|
|
206
212
|
const costs = [...decisions.map((d) => d.cost_usd), ...calls, given.modelCost];
|
|
207
213
|
const cost = costs.some((c) => c === null) ? null : Math.round(costs.reduce((a, b) => a + b, 0) * 1e8) / 1e8;
|
|
214
|
+
// Each model node's model: what its own execution ran on, as the runner kept it before running it (KINDS.nodeModel, by
|
|
215
|
+
// execution path), with the tier it asked for; a node a map runs once per item reads its newest execution's. A resumed
|
|
216
|
+
// claim keeps its own executions', so it never rewrites what an earlier node ran on. A decision node's model is its
|
|
217
|
+
// provider's, from its newest receipt. Any other node has none.
|
|
218
|
+
for (const entry of entries) {
|
|
219
|
+
const data = (entry.data ?? {});
|
|
220
|
+
if (entry.kind !== KINDS.nodeModel || typeof data.model !== "string")
|
|
221
|
+
continue;
|
|
222
|
+
const path = nodeAt(data.path);
|
|
223
|
+
const own = path ? nodes[path] : undefined;
|
|
224
|
+
if (!path || !own || !MODEL_KINDS.has(kinds.get(path) ?? ""))
|
|
225
|
+
continue;
|
|
226
|
+
own.model = data.model;
|
|
227
|
+
if (typeof data.tier === "string")
|
|
228
|
+
own.tier = data.tier;
|
|
229
|
+
else
|
|
230
|
+
delete own.tier;
|
|
231
|
+
}
|
|
232
|
+
for (const decision of decisions)
|
|
233
|
+
if (typeof decision.node === "string" && typeof decision.model === "string" && nodes[decision.node])
|
|
234
|
+
nodes[decision.node].model = decision.model;
|
|
208
235
|
const startedMs = Date.parse(given.run.startedAt);
|
|
209
236
|
const endMs = given.run.endedAt ? Date.parse(given.run.endedAt) : Date.now();
|
|
210
237
|
return {
|
package/dist/handed-values.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { RunRow, Store } from "./store/store.js";
|
|
|
4
4
|
/** The run's launch body read back, or undefined when it has none (an old run, or one not started with one). */
|
|
5
5
|
export declare function launchOf(store: Pick<Store, "runs">, runId: string): Promise<RunLaunch | undefined>;
|
|
6
6
|
/** The pointers a run was handed, as its row kept them (never the pointers, their SHA-256), read by the one rule a
|
|
7
|
-
*
|
|
7
|
+
* the stored mark is read by (run-view.ts handedMark): a column that is absent or null is no mark; a non-empty array
|
|
8
8
|
* of SHA-256 hashes is the mark; anything else (`true`, an object, a string, an empty array, which no writer writes, or
|
|
9
9
|
* an array holding anything but a hash) is MALFORMED, which handedPointers reads as unreadable: fails closed. */
|
|
10
10
|
export declare const handedOf: (runRow: RunRow) => Handed | undefined;
|
package/dist/handed-values.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function launchOf(store, runId) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
/** The pointers a run was handed, as its row kept them (never the pointers, their SHA-256), read by the one rule a
|
|
21
|
-
*
|
|
21
|
+
* the stored mark is read by (run-view.ts handedMark): a column that is absent or null is no mark; a non-empty array
|
|
22
22
|
* of SHA-256 hashes is the mark; anything else (`true`, an object, a string, an empty array, which no writer writes, or
|
|
23
23
|
* an array holding anything but a hash) is MALFORMED, which handedPointers reads as unreadable: fails closed. */
|
|
24
24
|
export const handedOf = (runRow) => (runRow.signInHanded === null || runRow.signInHanded === undefined ? undefined : handedMark(runRow.signInHanded));
|
|
@@ -31,8 +31,13 @@ export declare const installingWords: (label: string) => string;
|
|
|
31
31
|
* as it was. */
|
|
32
32
|
export declare function installLine(dir: string, lock: string): string;
|
|
33
33
|
/** Where `specifier` (a package, or a file of one) resolves from `dir`'s node_modules, only when it is that package's own
|
|
34
|
-
* file there: undefined when the package is not in `dir`, or its file resolves outside it (a
|
|
35
|
-
*
|
|
34
|
+
* file there: undefined when the package is not in `dir`, does not export it, or its file resolves outside it (a link to
|
|
35
|
+
* a file elsewhere). A package linked into `dir` counts by where its link points. Its real path, as Node's resolver gives.
|
|
36
|
+
*
|
|
37
|
+
* Read from the tree as it is now, never through Node's resolver: a long-lived process (a runner) keeps what that
|
|
38
|
+
* resolver read for its whole life (its path cache, and the real path of each link it walked), so a package once linked
|
|
39
|
+
* into the tree, then replaced at the same path by an install, would read as the link's old target until the process
|
|
40
|
+
* restarts. The package's own package.json is read here, and real paths taken with no cache. */
|
|
36
41
|
export declare function inTree(dir: string, specifier: string): string | undefined;
|
|
37
42
|
/** The Claude Agent SDK's package. */
|
|
38
43
|
export declare const CLAUDE_SDK = "@anthropic-ai/claude-agent-sdk";
|
|
@@ -111,8 +116,42 @@ export declare function installSettled(entry: HarnessInstallEntry, dir: string,
|
|
|
111
116
|
}): Promise<"installed" | "none" | {
|
|
112
117
|
failed: string;
|
|
113
118
|
}>;
|
|
119
|
+
/** The file an installer holds while it installs into `dir`, beside the install's mark: made exclusively, so of every
|
|
120
|
+
* process on this data (the server, a runner beside it, one of its own) one installs at a time, and the others wait for
|
|
121
|
+
* that install. npm's staging directories beside `dir` are each install's own, and an install removes what an earlier one
|
|
122
|
+
* left there, so two at once would undo each other. */
|
|
123
|
+
export declare const installHoldOf: (dir: string) => string;
|
|
124
|
+
/** Process `pid`'s identity beyond its pid, where this system shows one (Linux's /proc): the boot it runs in and its start
|
|
125
|
+
* time in clock ticks since that boot. A pid reused by another process (a restarted container's, which may well be
|
|
126
|
+
* given the same one) never reads as the one that wrote a hold. Undefined where it can't be read (no such process, or
|
|
127
|
+
* no /proc). */
|
|
128
|
+
/** This process's pid namespace, where this system shows one (Linux's /proc/self/ns/pid: `pid:[<inode>]`): two
|
|
129
|
+
* containers on one data directory may share a hostname but not their pids, so a pid is asked of this process table only
|
|
130
|
+
* for a hold written in this namespace. Undefined where it can't be read. */
|
|
131
|
+
export declare function pidNamespace(): string | undefined;
|
|
132
|
+
export declare function processIdentity(pid: number): string | undefined;
|
|
133
|
+
/** Takes the hold on installs into `dir` for this process: its token when it holds it now, undefined while another
|
|
134
|
+
* installer does. One of this host's (and of this pid namespace, where it names one) is held while the process that wrote it lives, whatever its age (its npm may still
|
|
135
|
+
* be stopping): its pid alive and, where the system shows it, the same process (processIdentity), so a pid another
|
|
136
|
+
* process was given since never keeps it; where the identity can't be read, while its pid lives within INSTALL_TIMEOUT_MS
|
|
137
|
+
* and the time npm takes to stop (HOLD_STOP_MS). Another host's, whose process can't be asked, within that bound. The hold
|
|
138
|
+
* is written whole beside its place and linked into it, which fails when a hold is there, so no reader sees one part
|
|
139
|
+
* way. A hold its installer left (gone, or past that bound, or unreadable and older than HOLD_WRITING_MS) is taken over
|
|
140
|
+
* by one taker alone: the one that links it to a name of that very file's removes it, and only while it is still that
|
|
141
|
+
* file, so a hold another taker made meanwhile is never removed. */
|
|
142
|
+
export declare function takeHold(dir: string, { isAlive, identity, host, pidns, timeoutMs }?: {
|
|
143
|
+
isAlive?: (pid: number) => boolean;
|
|
144
|
+
identity?: (pid: number) => string | undefined;
|
|
145
|
+
host?: string;
|
|
146
|
+
pidns?: string;
|
|
147
|
+
timeoutMs?: number;
|
|
148
|
+
}): Promise<string | undefined>;
|
|
149
|
+
/** Lets go of the hold on installs into `dir` that `token` took; a hold of another's (one that took over this one past
|
|
150
|
+
* its bound) stays. */
|
|
151
|
+
export declare function releaseHold(dir: string, token: string): Promise<void>;
|
|
114
152
|
/** The server's one installer of a harness into `dir`: `ensure()` resolves once it is installed whole, installing it first
|
|
115
|
-
* when it is not, and every caller while an install runs waits for that one.
|
|
153
|
+
* when it is not, and every caller while an install runs waits for that one. While another process installs it (it holds
|
|
154
|
+
* installHoldOf), this one waits for that install instead of starting its own. A failed install is not kept: the next call
|
|
116
155
|
* tries again. `stop()` stops an install that runs (its npm) and waits, bounded, for it to end. `onInstalled` hears of an
|
|
117
156
|
* install this server made, and how long it took. */
|
|
118
157
|
export declare class HarnessInstall {
|
|
@@ -135,3 +174,21 @@ export declare class HarnessInstall {
|
|
|
135
174
|
/** Stops an install that runs (its npm gets SIGTERM, then SIGKILL) and waits for it to end; none starts after. */
|
|
136
175
|
stop(): Promise<void>;
|
|
137
176
|
}
|
|
177
|
+
/** Where a run's claim stands on the install into `dir`, as installSettled says, except that an install this process's
|
|
178
|
+
* claims run (installForClaim) is never waited on from outside: it reads "none", so the claim joins it by installForClaim
|
|
179
|
+
* and counts among those that wait for it. Waited on from outside, it would stop once the claim that started it let go,
|
|
180
|
+
* though this one still needed it, and start again. An install the server runs is waited on as before. */
|
|
181
|
+
export declare function claimSettled(entry: HarnessInstallEntry, dir: string, pins: HarnessPins, options?: Parameters<typeof installSettled>[3]): ReturnType<typeof installSettled>;
|
|
182
|
+
/** Installs `entry` into `dir` for a run's claim when nothing installs it (no install runs, or the last one failed before
|
|
183
|
+
* this claim): the claim installs it itself, by `lock` (default the one AgentRun ships), or waits for the install this
|
|
184
|
+
* process or another runs for it already; it resolves once it is in and rejects with the install's own words when it
|
|
185
|
+
* fails. `signal` aborted (the run stopped, its claim lost, the runner closing): this claim stops waiting at once, and the
|
|
186
|
+
* install's npm is stopped once no claim waits for it. `install`: what runs the install in place of npm (a test's). */
|
|
187
|
+
export declare function installForClaim(entry: HarnessInstallEntry, dir: string, pins: () => Promise<HarnessPins>, { lock, signal, install }?: {
|
|
188
|
+
lock?: string;
|
|
189
|
+
signal?: AbortSignal;
|
|
190
|
+
install?: (entry: HarnessInstallEntry, dir: string, pins: HarnessPins, signal: AbortSignal) => Promise<void>;
|
|
191
|
+
}): Promise<void>;
|
|
192
|
+
/** Resolves once every install a claim let go of has stopped (its npm ended, SIGTERM then SIGKILL past its grace, its
|
|
193
|
+
* staging directory and hold gone): a runner's close waits for it before the process can end, so no npm outlives it. */
|
|
194
|
+
export declare function claimInstallsStopped(): Promise<void>;
|