@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -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/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- 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 +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- 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/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- 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 +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- 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/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/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/runner/runner.js
CHANGED
|
@@ -12,16 +12,26 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
12
12
|
import { COMMAND_KINDS, endedReason } from "./commands.js";
|
|
13
13
|
import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
|
|
14
14
|
import { journalEntries } from "./journal-reader.js";
|
|
15
|
-
import { endedBy } from "./loop-contract.js";
|
|
15
|
+
import { ClaimRefused, endedBy } from "./loop-contract.js";
|
|
16
16
|
import { isFenced } from "./store-port.js";
|
|
17
17
|
import { heldRedactor, processSecretRedactor } from "./redact.js";
|
|
18
18
|
import { withLiveTicker } from "./live-ticker.js";
|
|
19
19
|
/** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
|
|
20
20
|
export const RUNNER_LOOPS = 300;
|
|
21
|
+
/** How long a claim lasts unless renewed, unless told (RunnerOptions.leaseMs). */
|
|
22
|
+
export const RUNNER_LEASE_MS = 30_000;
|
|
23
|
+
/** A claim not renewed by its until less this is lost here, unless told (RunnerOptions.stopMarginMs). */
|
|
24
|
+
export const RUNNER_STOP_MARGIN_MS = 5_000;
|
|
25
|
+
/** The longest close() takes with the default lease (Runner.close): the drain, then the loops' stop, which waits for a
|
|
26
|
+
* loop that does not stop until its claim would run out (the lease less its margin, 25 s). A stop deadline that cuts the
|
|
27
|
+
* process sooner cuts a run's end short, and the run waits out its lease before another runner resumes it. */
|
|
28
|
+
export const runnerCloseBoundMs = (drainMs) => drainMs + RUNNER_LEASE_MS - RUNNER_STOP_MARGIN_MS;
|
|
21
29
|
/** How often a runner renews the claims it holds, unless told (RunnerOptions.renewEveryMs). */
|
|
22
30
|
export const RUNNER_RENEW_EVERY_MS = 10_000;
|
|
23
31
|
/** A runner's name when none is given: its host, its process and a part of a random id. */
|
|
24
32
|
export const runnerName = () => `${hostname()}:${process.pid}:${randomUUID().slice(0, 8)}`;
|
|
33
|
+
/** A failed end's code when the claim was refused for good before any loop started (loop-contract's ClaimRefused). */
|
|
34
|
+
const CLAIM_REFUSED = "claim-refused";
|
|
25
35
|
/** The untaken row a run ends on when no loop can: a cancel before a stop (it ends the run for good, in its words). */
|
|
26
36
|
const endingRow = (untaken) => untaken.find((row) => row.kind === "cancel") ?? untaken.find((row) => row.kind === "stop");
|
|
27
37
|
/** A commit by a loop whose claim this runner gave up: refused before it reaches the store. */
|
|
@@ -45,7 +55,7 @@ const message = (error) => (error instanceof Error ? error.message : String(erro
|
|
|
45
55
|
/** The run states a run patch makes final: a commit that lands one is the run's end, and its release. */
|
|
46
56
|
const FINAL = new Set(["ended", "stopped", "failed"]);
|
|
47
57
|
export function startRunner(options) {
|
|
48
|
-
const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs =
|
|
58
|
+
const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs = RUNNER_LEASE_MS, renewEveryMs = RUNNER_RENEW_EVERY_MS, stopMarginMs = RUNNER_STOP_MARGIN_MS, pollMs = 1_000, commandPollMs = 500, resumeTries = 3, resumeBackoffMs = 5_000, interruptBackoffMs = 1_000, endWaitMs = 5_000, drainMs = 0, memory, endRetryBackoffMs = END_RETRY_BACKOFF_MS, endRetryCapMs = END_RETRY_CAP_MS, endRetryAtCap = END_RETRY_AT_CAP, onEvent = () => { }, redact: given = processSecretRedactor(), now = Date.now, onBeat = () => { }, clock = { now: () => Date.now(), setTimeout: (fn, ms) => setTimeout(fn, ms), clearTimeout: (handle) => clearTimeout(handle) }, } = options;
|
|
49
59
|
// The one instance every run's loop gets (LoopDeps.redact), able to hold what each claim opens from the store
|
|
50
60
|
// (redact.ts holdClaimed): a stored key is cut wherever a key of the runner's environment is.
|
|
51
61
|
const redact = heldRedactor(given);
|
|
@@ -286,7 +296,7 @@ export function startRunner(options) {
|
|
|
286
296
|
* so it throws EndNotWithdrawn and the run is left as it stands, not final, its stop untaken (endRefused retries it). A
|
|
287
297
|
* lost claim (Fenced) writes neither.
|
|
288
298
|
*/
|
|
289
|
-
const endRun = async (claim, given, take) => {
|
|
299
|
+
const endRun = async (claim, given, take, withdrawnAs = "withdrawn") => {
|
|
290
300
|
// Why the run ended, as its end and its row say it: cut of every secret the runner holds (an error's text may echo one).
|
|
291
301
|
const data = { ...given, summary: redact(given.summary) };
|
|
292
302
|
// Unknown means it may withdraw: false only once the journal was read and no call of it waits.
|
|
@@ -305,7 +315,7 @@ export function startRunner(options) {
|
|
|
305
315
|
// A stopped end withdraws every call still waiting for its answer (an ask with no answer), in this commit: the
|
|
306
316
|
// approval card of a run whose loop could not start reads answered, never waiting for good.
|
|
307
317
|
if (data.state === "stopped" && root) {
|
|
308
|
-
const withdrawn = withdrawnAnswers(await journalEntries(journal, BACKGROUND_CONTEXT), new Date(now()).toISOString());
|
|
318
|
+
const withdrawn = withdrawnAnswers(await journalEntries(journal, BACKGROUND_CONTEXT), new Date(now()).toISOString(), withdrawnAs);
|
|
309
319
|
mayWithdraw = withdrawn.length > 0;
|
|
310
320
|
for (const answer of withdrawn) {
|
|
311
321
|
const answerId = (await journal.mintId());
|
|
@@ -331,7 +341,7 @@ export function startRunner(options) {
|
|
|
331
341
|
* call and the journal would not take it or could not be read: the refusal is then the run's (endRefused). */
|
|
332
342
|
const endStopped = async (claim, stop) => {
|
|
333
343
|
try {
|
|
334
|
-
await endRun(claim, { state: "stopped", summary: endedBy(stop.kind === "cancel") }, [stop.id]);
|
|
344
|
+
await endRun(claim, { state: "stopped", summary: endedBy(stop.kind === "cancel") }, [stop.id], stop.kind === "cancel" ? "canceled" : "withdrawn");
|
|
335
345
|
return true;
|
|
336
346
|
}
|
|
337
347
|
catch (error) {
|
|
@@ -417,7 +427,8 @@ export function startRunner(options) {
|
|
|
417
427
|
// with why, and a person can raise again or stop it (#1944-5). A claim its spec refuses (ClaimRefused: a handed
|
|
418
428
|
// sign-in that won't read back, an MCP pin refused) never comes here: the loop writes that end itself, final, the run
|
|
419
429
|
// failed in the refusal's words.
|
|
420
|
-
|
|
430
|
+
// A claim refused for good (CLAIM_REFUSED) is no resume to try again: it fails the run below, parked or not.
|
|
431
|
+
if (threw && end.state === "failed" && claim.from === "parked" && end.error.code !== CLAIM_REFUSED)
|
|
421
432
|
return await resumeFailed(held, end.error.message);
|
|
422
433
|
if (threw && end.state === "failed") {
|
|
423
434
|
// A loop that failed with no end written: a person's stop waiting now is the run's end (stopped, its row taken),
|
|
@@ -500,21 +511,31 @@ export function startRunner(options) {
|
|
|
500
511
|
}
|
|
501
512
|
emit({ type: "released", runId: claim.runId, epoch: claim.epoch, end: "parked" });
|
|
502
513
|
};
|
|
503
|
-
const hold = (claim, sentAt) => {
|
|
514
|
+
const hold = (claim, sentAt, mib = 0) => {
|
|
504
515
|
const fence = { lost: false };
|
|
505
516
|
const abort = new AbortController();
|
|
506
517
|
let firstDelivered;
|
|
507
518
|
const delivered = new Promise((resolve) => (firstDelivered = resolve));
|
|
508
519
|
// Set below, once held is made: the loop's end commit lands only after start(), well after.
|
|
509
520
|
let ending = () => { };
|
|
521
|
+
// Set below, once held is made: the loop asks deliverNow only once its first turn has ended, well after.
|
|
522
|
+
let heldNow;
|
|
510
523
|
const loop = loopsOf({
|
|
511
524
|
journal: (forClaim) => fenced(store.journal(forClaim), fence, forClaim.runId, () => ending()),
|
|
512
525
|
flush: () => store.flush(),
|
|
513
526
|
signal: abort.signal,
|
|
514
527
|
delivered,
|
|
528
|
+
// A delivery under way first (its rows are the loop's already), then one more read of the run's new rows.
|
|
529
|
+
deliverNow: async () => {
|
|
530
|
+
if (!heldNow)
|
|
531
|
+
return;
|
|
532
|
+
await heldNow.inFlight?.catch(() => undefined);
|
|
533
|
+
await deliver(heldNow);
|
|
534
|
+
},
|
|
515
535
|
redact,
|
|
516
536
|
});
|
|
517
|
-
const held = { claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false };
|
|
537
|
+
const held = { claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false, mib };
|
|
538
|
+
heldNow = held;
|
|
518
539
|
// The loop's own end landed: the run is ending from here, its teardown included (no renew, no lost claim).
|
|
519
540
|
ending = () => {
|
|
520
541
|
held.ending = true;
|
|
@@ -531,7 +552,9 @@ export function startRunner(options) {
|
|
|
531
552
|
}
|
|
532
553
|
catch (error) {
|
|
533
554
|
threw = true;
|
|
534
|
-
|
|
555
|
+
// A claim refused before any loop could start (the dispatch's ClaimRefused: a harness this host never holds) is
|
|
556
|
+
// for good: the run fails in its words, whatever woke it.
|
|
557
|
+
end = { state: "failed", error: { code: error instanceof ClaimRefused ? CLAIM_REFUSED : "loop-threw", message: message(error) } };
|
|
535
558
|
}
|
|
536
559
|
await finish(held, end, threw);
|
|
537
560
|
})();
|
|
@@ -546,10 +569,12 @@ export function startRunner(options) {
|
|
|
546
569
|
const free = loops - runs.size - replaced.size;
|
|
547
570
|
if (free <= 0)
|
|
548
571
|
return;
|
|
549
|
-
//
|
|
550
|
-
// taking a dead runner's runs over, is one transaction, not 300.
|
|
572
|
+
// By count alone, one store call claims the batch, each run at its own epoch + 1 (store.runs.claimMany): filling 300
|
|
573
|
+
// loops, or taking a dead runner's runs over, is one transaction, not 300. By memory, each run that fits is claimed
|
|
574
|
+
// on its own (claimByMemory).
|
|
551
575
|
const sentAt = clock.now();
|
|
552
|
-
const
|
|
576
|
+
const weights = new Map();
|
|
577
|
+
const claims = memory ? await claimByMemory(memory, free, weights) : await store.runs.claimMany(name, free, { leaseMs });
|
|
553
578
|
// A run whose untaken stop row has tries failed to apply that stop before: its claim only ends it (endRetried). Either
|
|
554
579
|
// source of tries counts: a refused stopped end (endRefused, released running) or a failed resume (resumeFailed's
|
|
555
580
|
// store.retry, released parked). One read of those claims' rows, made only when the batch has a released run.
|
|
@@ -577,7 +602,7 @@ export function startRunner(options) {
|
|
|
577
602
|
replaced.add(before);
|
|
578
603
|
void before.done.finally(() => replaced.delete(before));
|
|
579
604
|
}
|
|
580
|
-
hold(claim, sentAt);
|
|
605
|
+
hold(claim, sentAt, weights.get(claim.runId) ?? 0);
|
|
581
606
|
}
|
|
582
607
|
catch (error) {
|
|
583
608
|
// The loop could not be made: the run fails here, so it is not claimed again and again.
|
|
@@ -595,6 +620,42 @@ export function startRunner(options) {
|
|
|
595
620
|
polling = false;
|
|
596
621
|
}
|
|
597
622
|
};
|
|
623
|
+
/** Up to `free` waiting runs, oldest first, while they fit `memory`'s budget beside what this runner holds (a lost
|
|
624
|
+
* claim's loop still running holds its weight too): each claimed on its own, its weight put in `weights`. The first that
|
|
625
|
+
* does not fit ends the claim, unless the runner holds nothing: then it is claimed alone. */
|
|
626
|
+
const claimByMemory = async (budget, free, weights) => {
|
|
627
|
+
const waiting = await store.runs.claimable({ limit: free });
|
|
628
|
+
if (waiting.length === 0)
|
|
629
|
+
return [];
|
|
630
|
+
const weighed = await budget.weigh(waiting);
|
|
631
|
+
let heldMib = [...runs.values(), ...replaced].reduce((sum, held) => sum + held.mib, 0);
|
|
632
|
+
let holding = runs.size + replaced.size;
|
|
633
|
+
const claims = [];
|
|
634
|
+
for (const runId of waiting) {
|
|
635
|
+
const mib = weighed.get(runId) ?? 0;
|
|
636
|
+
if (holding > 0 && heldMib + mib > budget.budgetMib)
|
|
637
|
+
break;
|
|
638
|
+
if (closed || killed)
|
|
639
|
+
break;
|
|
640
|
+
// Another runner may have taken it since the read: then it is not this one's, and the next is tried. A claim that
|
|
641
|
+
// throws ends this poll's claims, keeping those that landed: they are held below, never left claimed and unstarted.
|
|
642
|
+
let claim;
|
|
643
|
+
try {
|
|
644
|
+
claim = await store.claim(runId, name, { leaseMs });
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
emit({ type: "error", runId, step: "claim", message: message(error) });
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
if (!claim)
|
|
651
|
+
continue;
|
|
652
|
+
claims.push(claim);
|
|
653
|
+
weights.set(runId, mib);
|
|
654
|
+
heldMib += mib;
|
|
655
|
+
holding += 1;
|
|
656
|
+
}
|
|
657
|
+
return claims;
|
|
658
|
+
};
|
|
598
659
|
/** The poll's claim in flight, if any: close() waits for it, so a runner whose close resolved claims nothing after it. */
|
|
599
660
|
let claiming;
|
|
600
661
|
const poll = () => {
|
|
@@ -612,6 +673,52 @@ export function startRunner(options) {
|
|
|
612
673
|
};
|
|
613
674
|
poll();
|
|
614
675
|
commandTimer = setTimeout(deliverAll, commandPollMs);
|
|
676
|
+
/** The untaken stop or cancel row each of `going` ends on (endingRow: a cancel before a stop), past its cursor, by run id:
|
|
677
|
+
* the close's one read of their rows (store.commandsOf), after the deliveries in flight. The whole of it is bounded by
|
|
678
|
+
* the stop margin, so a store that stalls never holds the shutdown: a read that fails or runs past it is said, and those
|
|
679
|
+
* runs are released for a shutdown as before, their rows untaken for the next claim. */
|
|
680
|
+
const closingEnds = async (going) => {
|
|
681
|
+
const ends = new Map();
|
|
682
|
+
if (going.length === 0)
|
|
683
|
+
return ends;
|
|
684
|
+
const read = async () => {
|
|
685
|
+
// A delivery in flight finishes first: it may be handing on that same row.
|
|
686
|
+
await Promise.all(going.map((held) => held.inFlight?.catch(() => undefined)));
|
|
687
|
+
const still = going.filter((held) => !held.stopping && !held.ending && !held.fence.lost);
|
|
688
|
+
if (still.length === 0)
|
|
689
|
+
return ends;
|
|
690
|
+
const rows = await store.commandsOf(still.map((held) => ({ runId: held.claim.runId, after: held.cursor })));
|
|
691
|
+
const found = new Map();
|
|
692
|
+
for (const held of still) {
|
|
693
|
+
const end = endingRow((rows.get(held.claim.runId) ?? []).filter((row) => row.takenAt === null));
|
|
694
|
+
if (end)
|
|
695
|
+
found.set(held.claim.runId, end);
|
|
696
|
+
}
|
|
697
|
+
return found;
|
|
698
|
+
};
|
|
699
|
+
let bound;
|
|
700
|
+
// Within the close's stop window (the lease less its margin), whatever the margin.
|
|
701
|
+
const boundMs = Math.min(stopMarginMs, leaseMs - stopMarginMs);
|
|
702
|
+
const late = new Promise((resolve) => (bound = setTimeout(() => resolve("late"), boundMs)));
|
|
703
|
+
// A read that fails after the bound is never an unhandled rejection: the close has moved on without it.
|
|
704
|
+
const reading = read();
|
|
705
|
+
reading.catch(() => undefined);
|
|
706
|
+
try {
|
|
707
|
+
const found = await Promise.race([reading, late]);
|
|
708
|
+
if (found !== "late")
|
|
709
|
+
return found;
|
|
710
|
+
for (const held of going)
|
|
711
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: `the close's read of its stop rows took longer than ${boundMs} ms: released for the next claim` });
|
|
712
|
+
}
|
|
713
|
+
catch (error) {
|
|
714
|
+
for (const held of going)
|
|
715
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: message(error) });
|
|
716
|
+
}
|
|
717
|
+
finally {
|
|
718
|
+
clearTimeout(bound);
|
|
719
|
+
}
|
|
720
|
+
return ends;
|
|
721
|
+
};
|
|
615
722
|
const stopTimers = () => {
|
|
616
723
|
clearTimeout(pollTimer);
|
|
617
724
|
clearTimeout(commandTimer);
|
|
@@ -643,17 +750,38 @@ export function startRunner(options) {
|
|
|
643
750
|
draining = false;
|
|
644
751
|
clearTimeout(commandTimer);
|
|
645
752
|
const live = [...runs.values()].filter((held) => !held.fence.lost);
|
|
753
|
+
// One window for the stop after the drain, the one runnerCloseBoundMs counts (the lease less its margin): the read
|
|
754
|
+
// below and the loops' stop share it, so the close is never longer than a deployment's stop grace allows for.
|
|
755
|
+
const stopBy = Date.now() + leaseMs - stopMarginMs;
|
|
756
|
+
// A stop or cancel a person sent before the close is the run's end, never a resume: one no delivery has handed on
|
|
757
|
+
// yet (the command poll's tick had not come) is read here, once, for every run still going, and stops its loop as
|
|
758
|
+
// its delivery would. Its end is in the store when the close is done, and the next start never resumes the turn.
|
|
759
|
+
const ends = await closingEnds(live.filter((held) => !held.ending && !held.stopping));
|
|
646
760
|
for (const held of live) {
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
761
|
+
if (held.ending)
|
|
762
|
+
continue;
|
|
763
|
+
const end = ends.get(held.claim.runId);
|
|
764
|
+
if (end && !held.stopping) {
|
|
765
|
+
held.cursor = Math.max(held.cursor, end.id);
|
|
766
|
+
stopLoop(held, { kind: "command", commandId: end.id, ...(end.kind === "cancel" ? { cancel: true } : {}) });
|
|
650
767
|
}
|
|
768
|
+
// A loop a stop or cancel already stops writes that end: it is never cut for the close.
|
|
769
|
+
if (held.stopping)
|
|
770
|
+
continue;
|
|
771
|
+
stopLoop(held, { kind: "shutdown" });
|
|
772
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
651
773
|
}
|
|
652
|
-
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out
|
|
774
|
+
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out (the end
|
|
775
|
+
// of the window the read above began).
|
|
653
776
|
let timeout;
|
|
654
|
-
const late = new Promise((resolve) => (timeout = setTimeout(resolve,
|
|
777
|
+
const late = new Promise((resolve) => (timeout = setTimeout(resolve, Math.max(0, stopBy - Date.now()))));
|
|
655
778
|
await Promise.race([Promise.all([...live.map((held) => held.done), ...endings]), late]);
|
|
656
779
|
clearTimeout(timeout);
|
|
780
|
+
// A loop still going at the window's end (one a stop row stops, whose signal was kept whole for its end) has its
|
|
781
|
+
// signal aborted before its claim is given up: no request of it outlives the close.
|
|
782
|
+
for (const held of live)
|
|
783
|
+
if (!held.ending && !held.abort.signal.aborted)
|
|
784
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
657
785
|
for (const held of runs.values())
|
|
658
786
|
held.fence.lost = true;
|
|
659
787
|
stopTimers();
|
|
@@ -16,6 +16,11 @@ type Held = {
|
|
|
16
16
|
readonly keys?: {
|
|
17
17
|
release(): void;
|
|
18
18
|
} | undefined;
|
|
19
|
+
/** The CLI's files on this machine for this claim (its private folder in the run's scratch), swept once the rest is let
|
|
20
|
+
* go: every claim lays its own again, the harness's state coming back from the run's journal. */
|
|
21
|
+
readonly scratch?: {
|
|
22
|
+
sweep(): Promise<void>;
|
|
23
|
+
} | undefined;
|
|
19
24
|
/** What the spec hands the loop, which lets it go itself (the claim's MCP): let go here only when the build throws. */
|
|
20
25
|
readonly passed?: {
|
|
21
26
|
release(): void;
|
|
@@ -29,8 +34,8 @@ export declare class SpecHolds {
|
|
|
29
34
|
/** `parts`, held from now until the release. */
|
|
30
35
|
hold(parts: Held): void;
|
|
31
36
|
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the computer, the Archil
|
|
32
|
-
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end,
|
|
33
|
-
* where they are held. A second call waits for the first and does nothing more. */
|
|
37
|
+
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end, the CLI's scratch, then
|
|
38
|
+
* the claim's keys where they are held. A second call waits for the first and does nothing more. */
|
|
34
39
|
release(): Promise<void>;
|
|
35
40
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
36
41
|
releasePassed(): void;
|
|
@@ -19,18 +19,19 @@ export class SpecHolds {
|
|
|
19
19
|
this.#held = { ...this.#held, ...parts };
|
|
20
20
|
}
|
|
21
21
|
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the computer, the Archil
|
|
22
|
-
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end,
|
|
23
|
-
* where they are held. A second call waits for the first and does nothing more. */
|
|
22
|
+
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end, the CLI's scratch, then
|
|
23
|
+
* the claim's keys where they are held. A second call waits for the first and does nothing more. */
|
|
24
24
|
release() {
|
|
25
25
|
return (this.#released ??= this.#releaseAll());
|
|
26
26
|
}
|
|
27
27
|
async #releaseAll() {
|
|
28
|
-
const { tools, computer, archil, ws, keys } = this.#held;
|
|
28
|
+
const { tools, computer, archil, ws, scratch, keys } = this.#held;
|
|
29
29
|
const log = this.#log;
|
|
30
30
|
await tools?.end().catch((error) => log(`the run's tools' end failed: ${words(error)}`));
|
|
31
31
|
await computer?.release().catch((error) => log(`the run's computer could not be let go: ${words(error)}`));
|
|
32
32
|
await archil?.revoke().catch((error) => log(`the run's Archil mount credential could not be revoked: ${words(error)}`));
|
|
33
33
|
await ws?.end().catch((error) => log(`the run's workspace end failed: ${words(error)}`));
|
|
34
|
+
await scratch?.sweep().catch((error) => log(`the run's scratch folder could not be swept: ${words(error)}`));
|
|
34
35
|
keys?.release();
|
|
35
36
|
}
|
|
36
37
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Store } from "../store/store.js";
|
|
2
2
|
export type RunnerStore = Pick<Store, "claim" | "renew" | "renewMany" | "release" | "journal" | "flush" | "commands" | "commandsOf" | "take" | "retry"> & {
|
|
3
|
-
readonly runs: Pick<Store["runs"], "claimMany" | "update">;
|
|
3
|
+
readonly runs: Pick<Store["runs"], "claimMany" | "claimable" | "update">;
|
|
4
4
|
/** The runs' live view (run_live): the runner's live ticker writes each run's held state there. A store without it (a
|
|
5
5
|
* test's) has no live view. */
|
|
6
6
|
readonly live?: Store["live"];
|
|
@@ -4,8 +4,8 @@ import type { HeldRedact } from "./redact.js";
|
|
|
4
4
|
/** The store slice the read needs. */
|
|
5
5
|
export type StoreSecretsStore = Pick<Store, "sealedSecrets">;
|
|
6
6
|
/** Every secret the server keeps sealed that `sealKey` opens: the store's (one read across its planes) and, where the runner
|
|
7
|
-
* shares the server's data directory `data`, what it keeps
|
|
8
|
-
export declare function storeSecrets(store: StoreSecretsStore, sealKey: Buffer
|
|
7
|
+
* shares the server's data directory `data`, what it keeps beside the store. */
|
|
8
|
+
export declare function storeSecrets(store: StoreSecretsStore, sealKey: Buffer, data?: string, adapters?: readonly TriggerAdapter[]): Promise<string[]>;
|
|
9
9
|
/** The server's sealed secrets (storeSecrets) held by `redact`, the run's one redactor, before any of the run's text is
|
|
10
10
|
* written. */
|
|
11
|
-
export declare function holdStored(redact: HeldRedact, store: StoreSecretsStore, sealKey: Buffer
|
|
11
|
+
export declare function holdStored(redact: HeldRedact, store: StoreSecretsStore, sealKey: Buffer, data?: string): Promise<void>;
|
|
@@ -5,16 +5,14 @@
|
|
|
5
5
|
// echoes it back. One read of the store across all its planes (store.sealedSecrets): tool, model, computer and Archil keys
|
|
6
6
|
// (sealed_keys); MCP credentials, their headers' values and OAuth tokens and client secret (mcp_servers), and a sign-in in
|
|
7
7
|
// flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
|
|
8
|
-
// and webhook secret among them (trigger_settings), but a field its source marks public; browser sign-in pointers, live
|
|
9
|
-
// and forgotten; live viewer tokens; a launch's sealed part. Beside the store, what the data directory keeps
|
|
10
|
-
//
|
|
11
|
-
// the trigger settings files of a server that keeps them there). Each value in every spelling the server's list has
|
|
8
|
+
// and webhook secret among them, and the outbound webhook's signing secret (trigger_settings), but a field its source marks public; browser sign-in pointers, live
|
|
9
|
+
// and forgotten; live viewer tokens; a launch's sealed part. Beside the store, what the data directory keeps where the
|
|
10
|
+
// runner shares it (server-secrets.ts besideTheStore: the owner's API token and the sign-in session secret). Each value in every spelling the server's list has
|
|
12
11
|
// (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
|
|
13
12
|
// is left out: the store never holds one in the clear, and nothing of this runner can be handed it.
|
|
14
|
-
import { unseal } from "
|
|
15
|
-
import {
|
|
13
|
+
import { unseal } from "../sealing.js";
|
|
14
|
+
import { besideTheStore, ServerSecrets } from "../server-secrets.js";
|
|
16
15
|
import { TRIGGER_ADAPTERS } from "../trigger-adapters.js";
|
|
17
|
-
import { SEAL_KEY_ENV } from "../tool-keys.js";
|
|
18
16
|
/** The keys of a sealed JSON value that hold secrets: OAuth tokens, a client's secret, a PKCE verifier. */
|
|
19
17
|
const JSON_SECRETS = ["access_token", "refresh_token", "id_token", "client_secret", "verifier"];
|
|
20
18
|
/** The secret strings of an opened JSON value: each header's value (a bearer's token alone too), and every string under
|
|
@@ -52,7 +50,7 @@ function jsonSecrets(text) {
|
|
|
52
50
|
walk(value);
|
|
53
51
|
return out;
|
|
54
52
|
}
|
|
55
|
-
/** A PEM key whole, and each of its base64 lines (the short last one too), as the server lists one (sealed-settings.ts). */
|
|
53
|
+
/** A PEM key whole, and each of its base64 lines (the short last one too), as the server lists one (sealed-settings-store.ts). */
|
|
56
54
|
const pemForms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("-----"))];
|
|
57
55
|
/** What of one opened sealed value is a secret to hold, by its plane: `listed` with the server list's floor and spellings,
|
|
58
56
|
* `whole` as it is (a PEM key's lines). */
|
|
@@ -74,10 +72,8 @@ function secretsOf(row, plain, adapters) {
|
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
74
|
/** Every secret the server keeps sealed that `sealKey` opens: the store's (one read across its planes) and, where the runner
|
|
77
|
-
* shares the server's data directory `data`, what it keeps
|
|
75
|
+
* shares the server's data directory `data`, what it keeps beside the store. */
|
|
78
76
|
export async function storeSecrets(store, sealKey, data, adapters = TRIGGER_ADAPTERS) {
|
|
79
|
-
if (!sealKey)
|
|
80
|
-
return [];
|
|
81
77
|
const listed = [];
|
|
82
78
|
const whole = [];
|
|
83
79
|
for (const row of await store.sealedSecrets.all()) {
|
|
@@ -95,7 +91,7 @@ export async function storeSecrets(store, sealKey, data, adapters = TRIGGER_ADAP
|
|
|
95
91
|
const list = new ServerSecrets();
|
|
96
92
|
list.add("store", () => listed);
|
|
97
93
|
list.add("store-whole", () => whole, { whole: true });
|
|
98
|
-
const beside = data ?
|
|
94
|
+
const beside = data ? besideTheStore(data).values() : [];
|
|
99
95
|
return [...list.values(), ...beside];
|
|
100
96
|
}
|
|
101
97
|
/** The server's sealed secrets (storeSecrets) held by `redact`, the run's one redactor, before any of the run's text is
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type Tool = {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
parameters?: unknown;
|
|
5
|
+
};
|
|
6
|
+
type Part = {
|
|
7
|
+
type: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
arguments?: unknown;
|
|
12
|
+
data?: string;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
};
|
|
15
|
+
type Message = {
|
|
16
|
+
role: string;
|
|
17
|
+
content: Part[] | string;
|
|
18
|
+
toolCallId?: string;
|
|
19
|
+
toolName?: string;
|
|
20
|
+
isError?: boolean;
|
|
21
|
+
timestamp?: number;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
/** A pi-ai context, as far as tools as text reads and writes it. */
|
|
25
|
+
export type PiContext = {
|
|
26
|
+
systemPrompt?: string;
|
|
27
|
+
messages: Message[];
|
|
28
|
+
tools?: Tool[];
|
|
29
|
+
};
|
|
30
|
+
/** The system prompt's tools section, in DeepSeek V3.2's own words: how to call, then each tool's schema. */
|
|
31
|
+
export declare function toolsSection(tools: readonly Tool[]): string;
|
|
32
|
+
/** `context` with its tools in its system prompt and every tool call and result in its history written as text. */
|
|
33
|
+
export declare function toolsAsText(context: PiContext): PiContext;
|
|
34
|
+
/** A reply's text read as text and calls: each `<tool_call>` block whose JSON names a tool, in order; the rest is
|
|
35
|
+
* text. A block whose JSON does not parse stays text. */
|
|
36
|
+
export declare function callsOfText(said: string, tools?: readonly Tool[]): {
|
|
37
|
+
text: string;
|
|
38
|
+
calls: {
|
|
39
|
+
name: string;
|
|
40
|
+
arguments: Record<string, unknown>;
|
|
41
|
+
}[];
|
|
42
|
+
broken?: boolean;
|
|
43
|
+
};
|
|
44
|
+
export {};
|