@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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { Storage } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { Workflow } from "@parcha/agentrun-dsl";
|
|
4
|
+
import type { GraphDiff, NodeState, WorkflowGraph } from "@parcha/agentrun-dsl/graph";
|
|
5
|
+
import type { createWorkflowExtension, WorkflowCaller, WorkflowOutcome } from "@parcha/agentrun-pi/durable";
|
|
6
|
+
/** A workflow run that can't be read here, in words. */
|
|
7
|
+
export declare class WorkflowRunUnread extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export type { GraphDiff, NodeState, WorkflowGraph, WorkflowOutcome };
|
|
11
|
+
/** A workflow revision's body, as a store keeps it: the workflow, the tools it may call, and its skills by path. */
|
|
12
|
+
export type WorkflowBody = {
|
|
13
|
+
workflow: Workflow;
|
|
14
|
+
tools?: string[];
|
|
15
|
+
skills?: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
/** The reads a workflow run's view needs from its journal in the one store, as a pi `Storage` serves them (read with no
|
|
18
|
+
* claim). */
|
|
19
|
+
export type WorkflowStorage = Pick<Storage, "findDocument" | "document" | "task">;
|
|
20
|
+
/** A started run of a workflow revision: `storage`, the run's journal in the one store, which `readWorkflowRun` and
|
|
21
|
+
* `workflowCarry` read; the durable runner (`startWorkflowRevision`) does not. */
|
|
22
|
+
export type WorkflowRunStart = {
|
|
23
|
+
runId: string;
|
|
24
|
+
storage?: WorkflowStorage;
|
|
25
|
+
agentId: string;
|
|
26
|
+
revision: {
|
|
27
|
+
id: string;
|
|
28
|
+
kind: "workflow";
|
|
29
|
+
body: WorkflowBody;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** One thing wrong with a workflow, at its JSON Pointer path (empty for its root). */
|
|
33
|
+
export type WorkflowIssue = {
|
|
34
|
+
path: string;
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Every issue a save of `workflow` as a workflow revision listing `tools` would refuse, and the DSL's warnings: the DSL's
|
|
40
|
+
* structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in `tools`
|
|
41
|
+
* (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step (only
|
|
42
|
+
* once the DSL found nothing). It writes nothing.
|
|
43
|
+
*/
|
|
44
|
+
export declare function workflowIssues(workflow: unknown, tools?: readonly string[]): Promise<{
|
|
45
|
+
issues: WorkflowIssue[];
|
|
46
|
+
warnings: string[];
|
|
47
|
+
}>;
|
|
48
|
+
/** How a run of a workflow revision ended, as the store's `carryBack` takes it. */
|
|
49
|
+
export type RunState = "completed" | "failed" | "stopped" | "escalated";
|
|
50
|
+
type WorkflowStarter = Pick<ReturnType<typeof createWorkflowExtension>, "start">;
|
|
51
|
+
type RunOptions = {
|
|
52
|
+
harness: WorkflowCaller;
|
|
53
|
+
workflows: WorkflowStarter;
|
|
54
|
+
context: Parameters<WorkflowStarter["start"]>[2];
|
|
55
|
+
run: WorkflowRunStart;
|
|
56
|
+
input: Record<string, unknown>;
|
|
57
|
+
tools: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Starts a workflow revision's run as one durable workflow task and waits for its outcome. It refuses with no task when
|
|
61
|
+
* the workflow uses a tool not in `tools` or does not take `input`. The run's id is its key, and the agent and the
|
|
62
|
+
* revision are bound beside the workflow, so the run reopened under another revision is refused
|
|
63
|
+
* (`RUN_STORE_BINDING_MISMATCH`) and nothing runs; reopened as itself, it resumes, or answers its outcome when it ended.
|
|
64
|
+
* It does not read the store file.
|
|
65
|
+
*/
|
|
66
|
+
export declare function startWorkflowRevision(options: RunOptions): Promise<WorkflowOutcome>;
|
|
67
|
+
/**
|
|
68
|
+
* What the store's `carryBack` takes for a run whose workflow ended in `outcome` (its `status`, and a refusal's `code`
|
|
69
|
+
* and `message`): the state, and the labels of the nodes that completed, in graph order (chains aside), then `failed at
|
|
70
|
+
* <label>` for each deepest node that failed and `escalated at <label>` for the node a gate fired at; with none of
|
|
71
|
+
* these, `<state> before any node completed`. A refusal before any task is `refused: <message>`. It reads the run with
|
|
72
|
+
* `readWorkflowRun` over the run's journal.
|
|
73
|
+
*/
|
|
74
|
+
export declare function workflowCarry(run: Pick<WorkflowRunStart, "runId" | "storage" | "revision">, outcome: Pick<WorkflowOutcome, "status"> & {
|
|
75
|
+
code?: string;
|
|
76
|
+
message?: string;
|
|
77
|
+
}, options?: {
|
|
78
|
+
context?: Context;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
state: RunState;
|
|
81
|
+
summary: string;
|
|
82
|
+
}>;
|
|
83
|
+
/** A node's state in a run: the DSL's, and `stopped` for a node an ended run interrupted. */
|
|
84
|
+
export type RunNodeState = NodeState | "stopped";
|
|
85
|
+
/** A workflow run as its store shows it: the workflow's graph and each node's state; once the run ended, how it ended,
|
|
86
|
+
* the node it escalated at (its path in the graph and its label), the escalation's kind, label and summary as its
|
|
87
|
+
* escalate node wrote them, and the workflow's output when it completed. */
|
|
88
|
+
export type WorkflowRunView = {
|
|
89
|
+
graph: WorkflowGraph;
|
|
90
|
+
status: Record<string, RunNodeState>;
|
|
91
|
+
outcome?: RunState;
|
|
92
|
+
escalatedAt?: {
|
|
93
|
+
path: string;
|
|
94
|
+
label: string;
|
|
95
|
+
};
|
|
96
|
+
escalation?: {
|
|
97
|
+
kind: string | null;
|
|
98
|
+
label: string | null;
|
|
99
|
+
summary: string | null;
|
|
100
|
+
};
|
|
101
|
+
output?: unknown;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Reads a workflow run from its journal in the one store (`storage`), read-only: it never writes and takes no claim. The
|
|
105
|
+
* nodes' states come from the run's journal and its task's terminal result. Working means live: an ended run's
|
|
106
|
+
* interrupted nodes read stopped; in a failed run, every node still running at the end is drawn failed; with parallel
|
|
107
|
+
* branches, that can include branches that were only interrupted. A run in the driver's keyed layout keeps its map items
|
|
108
|
+
* apart and is refused here (WorkflowRunUnread).
|
|
109
|
+
*/
|
|
110
|
+
export declare function readWorkflowRun(run: Pick<WorkflowRunStart, "runId" | "storage" | "revision"> & {
|
|
111
|
+
state?: RunState | "running";
|
|
112
|
+
}, options?: {
|
|
113
|
+
context?: Context;
|
|
114
|
+
}): Promise<WorkflowRunView>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/** A workflow run that can't be read here, in words. */
|
|
2
|
+
export class WorkflowRunUnread extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "WorkflowRunUnread";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
/**
|
|
10
|
+
* Every issue a save of `workflow` as a workflow revision listing `tools` would refuse, and the DSL's warnings: the DSL's
|
|
11
|
+
* structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in `tools`
|
|
12
|
+
* (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step (only
|
|
13
|
+
* once the DSL found nothing). It writes nothing.
|
|
14
|
+
*/
|
|
15
|
+
export async function workflowIssues(workflow, tools) {
|
|
16
|
+
if (!isRecord(workflow))
|
|
17
|
+
return { issues: [{ path: "", code: "NODE_FIELD_INVALID", message: "the workflow must be an object" }], warnings: [] };
|
|
18
|
+
const { inspectWorkflow, validateWorkflow } = await import("@parcha/agentrun-dsl");
|
|
19
|
+
const checked = validateWorkflow(workflow, { executeCode: false });
|
|
20
|
+
const issues = checked.ok ? [] : checked.issues.map(({ path, code, message }) => ({ path, code, message }));
|
|
21
|
+
const warnings = [...(checked.warnings ?? [])];
|
|
22
|
+
if (issues.length)
|
|
23
|
+
return { issues, warnings };
|
|
24
|
+
if (tools) {
|
|
25
|
+
for (const entry of inspectWorkflow(workflow).nodes) {
|
|
26
|
+
if (entry.kind !== "call")
|
|
27
|
+
continue;
|
|
28
|
+
const node = entry.path.split("/").slice(1).reduce((at, part) => at?.[part.replace(/~1/g, "/").replace(/~0/g, "~")], workflow);
|
|
29
|
+
if (node?.via === "tool" && !tools.includes(node.tool))
|
|
30
|
+
issues.push({ path: entry.path, code: "TOOL_NOT_LISTED", message: `call node "${node.label}" uses the tool ${node.tool}, which the revision does not list in its tools` });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// What the durable runner refuses before any step (each label once), asked of the runner itself on a memory store.
|
|
34
|
+
const { memoryStore, openRecovery } = await import("@parcha/agentrun-dsl/recovery");
|
|
35
|
+
const driver = await openRecovery(memoryStore(), workflow, { key: "check" });
|
|
36
|
+
const refusal = driver.preStepRefusal;
|
|
37
|
+
await driver.close();
|
|
38
|
+
if (refusal)
|
|
39
|
+
issues.push(refusal.kind === "duplicate_label" ? { path: "", code: "DUPLICATE_LABEL", message: refusal.message } : { path: "", code: `DURABLE_${refusal.code}`, message: refusal.message });
|
|
40
|
+
return { issues, warnings };
|
|
41
|
+
}
|
|
42
|
+
/** A run's DSL outcome as the store's run state: a refusal or a failure is `failed`, a cancel `stopped`. */
|
|
43
|
+
const stateOf = (outcome) => outcome.status === "complete" ? "completed" : outcome.status === "stopped" ? "stopped" : outcome.status === "escalated" ? "escalated" : "failed";
|
|
44
|
+
/** The two refusals `startWorkflowRevision` makes before any task: no task, so no journal for `workflowCarry` to read. */
|
|
45
|
+
const BEFORE_ANY_TASK = new Set(["TOOL_NOT_REGISTERED", "INPUT_NOT_TAKEN"]);
|
|
46
|
+
/**
|
|
47
|
+
* Starts a workflow revision's run as one durable workflow task and waits for its outcome. It refuses with no task when
|
|
48
|
+
* the workflow uses a tool not in `tools` or does not take `input`. The run's id is its key, and the agent and the
|
|
49
|
+
* revision are bound beside the workflow, so the run reopened under another revision is refused
|
|
50
|
+
* (`RUN_STORE_BINDING_MISMATCH`) and nothing runs; reopened as itself, it resumes, or answers its outcome when it ended.
|
|
51
|
+
* It does not read the store file.
|
|
52
|
+
*/
|
|
53
|
+
export async function startWorkflowRevision(options) {
|
|
54
|
+
const { run, input } = options;
|
|
55
|
+
const workflow = run.revision.body.workflow;
|
|
56
|
+
const { inspectWorkflow, validateWorkflow } = await import("@parcha/agentrun-dsl");
|
|
57
|
+
const refuse = (code, message) => ({ status: "refused", code, message });
|
|
58
|
+
const unregistered = inspectWorkflow(workflow).requires.tools.filter((tool) => !options.tools.includes(tool));
|
|
59
|
+
if (unregistered.length)
|
|
60
|
+
return refuse("TOOL_NOT_REGISTERED", `the workflow uses ${unregistered.length} tool(s) this host does not register`);
|
|
61
|
+
const fits = validateWorkflow(workflow, { executeCode: false, input });
|
|
62
|
+
if (!fits.ok)
|
|
63
|
+
return refuse("INPUT_NOT_TAKEN", `the workflow does not take this input: ${fits.issues[0]?.code ?? "invalid"} at ${fits.issues[0]?.path || "its root"}`);
|
|
64
|
+
const request = { key: run.runId, workflow, input, bind: { agent: run.agentId, revision: run.revision.id } };
|
|
65
|
+
return (await options.workflows.start(options.harness, request, options.context, { background: true })).wait(options.context);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What the store's `carryBack` takes for a run whose workflow ended in `outcome` (its `status`, and a refusal's `code`
|
|
69
|
+
* and `message`): the state, and the labels of the nodes that completed, in graph order (chains aside), then `failed at
|
|
70
|
+
* <label>` for each deepest node that failed and `escalated at <label>` for the node a gate fired at; with none of
|
|
71
|
+
* these, `<state> before any node completed`. A refusal before any task is `refused: <message>`. It reads the run with
|
|
72
|
+
* `readWorkflowRun` over the run's journal.
|
|
73
|
+
*/
|
|
74
|
+
export async function workflowCarry(run, outcome, options = {}) {
|
|
75
|
+
if (outcome.status === "refused" && outcome.code !== undefined && BEFORE_ANY_TASK.has(outcome.code))
|
|
76
|
+
return { state: "failed", summary: `refused: ${outcome.message ?? outcome.code}` };
|
|
77
|
+
const view = await readWorkflowRun(run, options);
|
|
78
|
+
// The nodes that completed (chains, pure sequence, aside), then each deepest node that failed (a container failed only
|
|
79
|
+
// through a node in it is not named again), then the node the run escalated at.
|
|
80
|
+
const inState = (state) => view.graph.nodes.filter((node) => view.status[node.path] === state);
|
|
81
|
+
const done = inState("done").filter((node) => node.kind !== "chain").map((node) => node.label);
|
|
82
|
+
const failed = inState("failed").filter((node, _, all) => !all.some((other) => other.path.startsWith(`${node.path}/`))).map((node) => node.label);
|
|
83
|
+
const summary = [done.join(", "), failed.length ? `failed at ${failed.join(", ")}` : "", view.escalatedAt ? `escalated at ${view.escalatedAt.label}` : ""];
|
|
84
|
+
// The store refuses an empty summary: a run with none of the three still says how it ended.
|
|
85
|
+
const state = stateOf(outcome);
|
|
86
|
+
return { state, summary: summary.filter(Boolean).join("; ") || `${state} before any node completed` };
|
|
87
|
+
}
|
|
88
|
+
const text = (value) => (typeof value === "string" ? value : null);
|
|
89
|
+
/** A session document's value from a pi Storage: the current incarnation of `kind`'s member `key`, materialized
|
|
90
|
+
* (findDocument, then document), or undefined when there is none. The run view reads the run's task and its driver journal
|
|
91
|
+
* from the one store this way. */
|
|
92
|
+
async function sessionDoc(storage, kind, key, context) {
|
|
93
|
+
const record = await storage.findDocument({ kind, scope: { kind: "session" }, key }, "current", context);
|
|
94
|
+
if (!record)
|
|
95
|
+
return undefined;
|
|
96
|
+
return (await storage.document(record.id, "current", context))?.value;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads a workflow run from its journal in the one store (`storage`), read-only: it never writes and takes no claim. The
|
|
100
|
+
* nodes' states come from the run's journal and its task's terminal result. Working means live: an ended run's
|
|
101
|
+
* interrupted nodes read stopped; in a failed run, every node still running at the end is drawn failed; with parallel
|
|
102
|
+
* branches, that can include branches that were only interrupted. A run in the driver's keyed layout keeps its map items
|
|
103
|
+
* apart and is refused here (WorkflowRunUnread).
|
|
104
|
+
*/
|
|
105
|
+
export async function readWorkflowRun(run, options = {}) {
|
|
106
|
+
const { graphNodeOf, nodeStatus, workflowGraph } = await import("@parcha/agentrun-dsl/graph");
|
|
107
|
+
const graph = workflowGraph(run.revision.body.workflow);
|
|
108
|
+
// The run's task holds how it ended, and the driver's journal holds each node's frame: the task is read before the
|
|
109
|
+
// journal, so a task found terminal means the journal read after it is final.
|
|
110
|
+
let ended;
|
|
111
|
+
const { storage } = run;
|
|
112
|
+
const context = options.context;
|
|
113
|
+
if (!storage || !context)
|
|
114
|
+
throw new WorkflowRunUnread("reading a workflow run needs its journal in the store and a context");
|
|
115
|
+
const task = (await sessionDoc(storage, "agentrun.task", run.runId, context))?.task;
|
|
116
|
+
if (typeof task === "number") {
|
|
117
|
+
const record = await storage.task(task, context);
|
|
118
|
+
const taskState = record?.state;
|
|
119
|
+
if (taskState?.status === "terminal")
|
|
120
|
+
ended = taskState.outcome;
|
|
121
|
+
}
|
|
122
|
+
const state = (await sessionDoc(storage, "agentrun.driver", run.runId, context))?.state;
|
|
123
|
+
// A completed task holds the run's result (complete or escalated); an aborted one was cancelled; any other failed.
|
|
124
|
+
const result = ended?.status === "completed" ? ended.result : undefined;
|
|
125
|
+
if (state?.schema === "agentrun.frozen_run.v4")
|
|
126
|
+
throw new WorkflowRunUnread("a run in the keyed layout is not read here");
|
|
127
|
+
const status = nodeStatus(graph, { pin: state?.pin ?? {}, result: result ?? null });
|
|
128
|
+
const outcome = ended && (result ? stateOf(result) : ended.status === "aborted" ? "stopped" : "failed");
|
|
129
|
+
// An ended run leaves the nodes it was running `working`. They were interrupted: stopped, or failed in a failed run,
|
|
130
|
+
// since the journal keeps no mark for a call that failed.
|
|
131
|
+
if (outcome)
|
|
132
|
+
for (const node of graph.nodes)
|
|
133
|
+
if (status[node.path] === "working")
|
|
134
|
+
status[node.path] = outcome === "failed" ? "failed" : "stopped";
|
|
135
|
+
const at = typeof result?.escalation?.executionPath === "string" ? graphNodeOf(graph, result.escalation.executionPath)?.path : undefined;
|
|
136
|
+
const fired = graph.nodes.find((node) => node.path === at);
|
|
137
|
+
return {
|
|
138
|
+
graph, status,
|
|
139
|
+
...(outcome ? { outcome } : {}),
|
|
140
|
+
...(fired ? { escalatedAt: { path: fired.path, label: fired.label } } : {}),
|
|
141
|
+
...(result?.escalation ? { escalation: { kind: text(result.escalation.kind), label: text(result.escalation.label), summary: text(result.escalation.summary) } } : {}),
|
|
142
|
+
...(result?.status === "complete" ? { output: result.output } : {}),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -41,8 +41,8 @@ export interface ArchilClaim {
|
|
|
41
41
|
readonly disk: ArchilDisk;
|
|
42
42
|
/** The disk's region (a computer's mount names it). */
|
|
43
43
|
readonly region: string;
|
|
44
|
-
/** The exec image, pinned by digest
|
|
45
|
-
readonly image: ArchilImage
|
|
44
|
+
/** The exec image, pinned by digest: the saved one, else DEFAULT_ARCHIL_EXEC_IMAGE. */
|
|
45
|
+
readonly image: ArchilImage;
|
|
46
46
|
/** The run's mount credential's token, minted the first time a mount asks (once per claim), held in memory only. */
|
|
47
47
|
token(): Promise<string>;
|
|
48
48
|
/** Removes the run's mount credential at Archil by its identifier (the computer's release, the run's end). Idempotent:
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The Archil claim step: once per claim in Mode 2, before the run's loop starts, the claim's Archil disk is made from the
|
|
2
2
|
// server's Archil settings (archil-settings.ts, the store's one settings row) and its keys come from the store's
|
|
3
3
|
// sealed_keys rows under archil-settings.ts's names, opened with the runner's seal key. A saved exec image must be pinned
|
|
4
|
-
// by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read.
|
|
4
|
+
// by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read. With none saved, the exec runs
|
|
5
|
+
// in DEFAULT_ARCHIL_EXEC_IMAGE, never Archil's own default (its git is older than a bash policy's floor).
|
|
5
6
|
//
|
|
6
7
|
// One row: "archil.api_key", the account API key the disk's file API and serverless exec take (archil-disk.ts asks for
|
|
7
8
|
// it on every call, and gets it from this step's memory). The disk token a computer's mount takes
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
// refused. A row that is missing, or that does not open under the seal key (sealed under another key, or for another
|
|
15
16
|
// row), refuses in words that name the row and never hold a value. Nothing here reads the environment: the settings,
|
|
16
17
|
// the store's sealed keys and the seal key are handed in.
|
|
17
|
-
import { ARCHIL_API_KEY_ROW } from "../archil-settings.js";
|
|
18
|
+
import { ARCHIL_API_KEY_ROW, DEFAULT_ARCHIL_EXEC_IMAGE } from "../archil-settings.js";
|
|
18
19
|
import { archilApiKey } from "./archil-key.js";
|
|
19
20
|
import { archilDisk, pinnedImage } from "./archil-disk.js";
|
|
20
21
|
import { mintMountToken, nicknameOf, removeMountToken, removeOlderMountTokens, removeRunMountTokens } from "./archil-mount-credential.js";
|
|
@@ -39,7 +40,7 @@ export async function archilClaim(options) {
|
|
|
39
40
|
}
|
|
40
41
|
let image;
|
|
41
42
|
try {
|
|
42
|
-
image =
|
|
43
|
+
image = pinnedImage({ baseImage: settings.image ?? DEFAULT_ARCHIL_EXEC_IMAGE });
|
|
43
44
|
}
|
|
44
45
|
catch (error) {
|
|
45
46
|
throw new ArchilClaimRefused(`This server's Archil exec image ${JSON.stringify(settings.image)} can't be used: ${error.message}`, { cause: error });
|
|
@@ -37,14 +37,23 @@ export type ArchilImage = {
|
|
|
37
37
|
};
|
|
38
38
|
/** `image` checked as an ArchilImage pinned by digest, and copied: only its own fields, nothing else it carries. */
|
|
39
39
|
export declare function pinnedImage(image: unknown): ArchilImage;
|
|
40
|
+
/** An exec's network: its egress denied, so the container reaches nothing but the disk's own mounts. */
|
|
41
|
+
export type ArchilExecNetwork = {
|
|
42
|
+
readonly egress: {
|
|
43
|
+
readonly default: "deny";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** The one network an exec is given: no egress. */
|
|
47
|
+
export declare const DENY_EGRESS: ArchilExecNetwork;
|
|
40
48
|
/** One exec: `command` runs with each folder of `mounts` (mount name → folder of the disk), and nothing else of the
|
|
41
49
|
* disk, at /mnt/archil/<name>, each held for the line (waiting up to queueMs for another client's hold), in `image` or
|
|
42
|
-
* Archil's default. */
|
|
50
|
+
* Archil's default, with `network` (absent: Archil's default, egress open). */
|
|
43
51
|
export type ArchilExecRequest = {
|
|
44
52
|
readonly mounts: Readonly<Record<string, string>>;
|
|
45
53
|
readonly queueMs: number;
|
|
46
54
|
readonly command: string;
|
|
47
55
|
readonly image?: ArchilImage;
|
|
56
|
+
readonly network?: ArchilExecNetwork;
|
|
48
57
|
};
|
|
49
58
|
export type ArchilExecAnswer = {
|
|
50
59
|
readonly exitCode: number;
|
|
@@ -14,6 +14,8 @@ export function pinnedImage(image) {
|
|
|
14
14
|
return refuse();
|
|
15
15
|
return { imageId, digest };
|
|
16
16
|
}
|
|
17
|
+
/** The one network an exec is given: no egress. */
|
|
18
|
+
export const DENY_EGRESS = Object.freeze({ egress: Object.freeze({ default: "deny" }) });
|
|
17
19
|
const LOOPBACK = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule names loopback hosts to allow plain http only to them, in tests
|
|
18
20
|
/** The S3 endpoint, checked: https on an Archil host whose name carries the region ("aws-us-east-1" → "….us-east-1.aws.
|
|
19
21
|
* …archil.com"), or, when the control plane is a loopback one too (a test), http(s) to this machine's loopback. */
|
|
@@ -244,6 +246,8 @@ class SdkArchilDisk {
|
|
|
244
246
|
}
|
|
245
247
|
const answer = await client.exec({
|
|
246
248
|
...(image === undefined ? {} : "baseImage" in image ? { baseImage: image.baseImage } : { imageId: image.imageId }),
|
|
249
|
+
// The network's one field, picked by name, as the image's are.
|
|
250
|
+
...(request.network === undefined ? {} : { network: { egress: { default: request.network.egress.default } } }),
|
|
247
251
|
command: request.command,
|
|
248
252
|
disks: Object.fromEntries(Object.entries(request.mounts).map(([name, subdirectory]) => [name, { disk: this.id, subdirectory, queueMs: request.queueMs }])),
|
|
249
253
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArchilDisk, ArchilImage } from "./archil-disk.js";
|
|
2
|
-
import { type ExecResult } from "./workspace.js";
|
|
1
|
+
import type { ArchilDisk, ArchilExecNetwork, ArchilImage } from "./archil-disk.js";
|
|
2
|
+
import { type ExecResult, WorkspaceError } from "./workspace.js";
|
|
3
3
|
/** Archil cuts an exec call at 300 s. */
|
|
4
4
|
export declare const MAX_EXEC_MS = 300000;
|
|
5
5
|
/** The longest deadline a command may ask for: 5 s of the 300 are the line's own (its walk, its drains, its answer).
|
|
@@ -38,7 +38,17 @@ export type ExecJob = {
|
|
|
38
38
|
readonly maxOutput: number;
|
|
39
39
|
readonly queueMs: number;
|
|
40
40
|
readonly image?: ArchilImage;
|
|
41
|
+
/** The container's network (DENY_EGRESS); absent, Archil's default, egress open. */
|
|
42
|
+
readonly network?: ArchilExecNetwork;
|
|
41
43
|
};
|
|
44
|
+
/** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
|
|
45
|
+
export declare class ArchilEgressRefused extends WorkspaceError {
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
/** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
|
|
49
|
+
* whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
|
|
50
|
+
* names no network (a refused key, the exec allowance spent) stays what it is. */
|
|
51
|
+
export declare function refusesNetwork(error: unknown): boolean;
|
|
42
52
|
/** The shell line one exec call runs (POSIX sh; GNU timeout, perl, mkfifo, head and mktemp in the image). `mark` is
|
|
43
53
|
* this call's marker: the line's answer is found by it, whatever else the call's stdout holds. */
|
|
44
54
|
export declare function execLine(job: ExecJob, mark: string): string;
|
|
@@ -55,6 +55,17 @@ export const quote = (text) => `'${text.replace(/'/g, `'\\''`)}'`;
|
|
|
55
55
|
export const spillName = () => `x${randomBytes(8).toString("hex")}`;
|
|
56
56
|
/** The keys of one exec's files, in spill folder `folder`. */
|
|
57
57
|
export const spillKeys = (folder, name) => ({ in: `${folder}/${name}.in`, out: `${folder}/${name}.out`, err: `${folder}/${name}.err` });
|
|
58
|
+
/** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
|
|
59
|
+
export class ArchilEgressRefused extends WorkspaceError {
|
|
60
|
+
name = "ArchilEgressRefused";
|
|
61
|
+
}
|
|
62
|
+
/** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
|
|
63
|
+
* whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
|
|
64
|
+
* names no network (a refused key, the exec allowance spent) stays what it is. */
|
|
65
|
+
export function refusesNetwork(error) {
|
|
66
|
+
const { status, code, message } = (error ?? {});
|
|
67
|
+
return (status === 402 || status === 403) && /network|egress/i.test(`${typeof code === "string" ? code : ""} ${typeof message === "string" ? message : ""}`);
|
|
68
|
+
}
|
|
58
69
|
/** The program's runner: stderr to the file in its first argument, the program run, its raw wait status written to the
|
|
59
70
|
* file in its second, and the same exit a shell would give. No single quote in it: it rides in one. */
|
|
60
71
|
const RUNNER = [
|
|
@@ -158,6 +169,7 @@ export async function archilExec(disk, job) {
|
|
|
158
169
|
const request = {
|
|
159
170
|
mounts: { [EXEC_MOUNT]: job.root, [SPILL_MOUNT]: job.spill }, queueMs: job.queueMs, command: execLine(job, mark),
|
|
160
171
|
...(job.image === undefined ? {} : { image: job.image }),
|
|
172
|
+
...(job.network === undefined ? {} : { network: job.network }),
|
|
161
173
|
};
|
|
162
174
|
answer = await Promise.race([disk.exec(request), gaveUp]);
|
|
163
175
|
}
|
|
@@ -165,6 +177,10 @@ export async function archilExec(disk, job) {
|
|
|
165
177
|
if (error instanceof WorkspaceError)
|
|
166
178
|
throw error;
|
|
167
179
|
const status = error?.status;
|
|
180
|
+
if (job.network !== undefined && refusesNetwork(error)) {
|
|
181
|
+
const code = error.code;
|
|
182
|
+
throw new ArchilEgressRefused("REFUSED", `Archil refused the exec's network policy (${status}${typeof code === "string" ? ` ${code}` : ""}): ${describe(error)}`, { path, cause: error });
|
|
183
|
+
}
|
|
168
184
|
// A 400 is a mount Archil refused (a folder missing, or held by another client past the queue's wait): its own
|
|
169
185
|
// words say which.
|
|
170
186
|
const why = status === 400 ? "Archil refused to mount the exec's folders"
|
|
@@ -9,8 +9,8 @@ export type ArchilWorkspaceOptions = {
|
|
|
9
9
|
readonly queueMs?: number;
|
|
10
10
|
/** The image every exec runs in, the same for every workspace serve makes (a run's or a learning folder's), pinned by
|
|
11
11
|
* digest (an image given without one is refused): a public image `<name>@sha256:…`, or one built through Archil's
|
|
12
|
-
* images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than
|
|
13
|
-
*
|
|
12
|
+
* images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than a
|
|
13
|
+
* bash policy's floor; serve's claim always names one (archil-settings.ts DEFAULT_ARCHIL_EXEC_IMAGE). */
|
|
14
14
|
readonly image?: ArchilImage;
|
|
15
15
|
/** Told when an exec's cleanup leaves spill files behind (a failed delete, tried twice), with the keys and why; the
|
|
16
16
|
* exec's own result stands. Default: a process warning. */
|
package/dist/workspace/archil.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { pinnedImage } from "./archil-disk.js";
|
|
2
|
-
import { archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
|
|
1
|
+
import { DENY_EGRESS, pinnedImage } from "./archil-disk.js";
|
|
2
|
+
import { ArchilEgressRefused, archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
|
|
3
3
|
import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
|
|
4
4
|
import { globRegex } from "./glob.js";
|
|
5
5
|
import { relativeSegments } from "./paths.js";
|
|
@@ -64,6 +64,8 @@ class ArchilWorkspace {
|
|
|
64
64
|
#mountToken;
|
|
65
65
|
/** The last exec asked for, settled either way: the next exec, and every write, starts after it. */
|
|
66
66
|
#execs = Promise.resolve();
|
|
67
|
+
/** Why Archil refused an exec's network policy, once it has: an exec asking for no network then runs with it open. */
|
|
68
|
+
#egressOpen;
|
|
67
69
|
#rooted = false;
|
|
68
70
|
constructor(disk, root, options = {}) {
|
|
69
71
|
if (relativeSegments(root).length === 0)
|
|
@@ -551,13 +553,31 @@ class ArchilWorkspace {
|
|
|
551
553
|
const stdin = options.stdin;
|
|
552
554
|
await this.#settle("", () => this.#disk.putObject(files.in, stdin)).catch((error) => { throw failed(error, "", "exec's stdin"); });
|
|
553
555
|
}
|
|
554
|
-
const
|
|
556
|
+
const job = {
|
|
555
557
|
root: this.#root, spill: this.#spill, name, cwd, argv, env, timeoutMs, maxOutput: readBack, queueMs: this.#queueMs,
|
|
556
558
|
stdin: options.stdin !== undefined, ...(this.#image === undefined ? {} : { image: this.#image }),
|
|
557
|
-
}
|
|
559
|
+
};
|
|
560
|
+
const deny = options.network === "deny";
|
|
561
|
+
let read;
|
|
562
|
+
if (deny && this.#egressOpen === undefined) {
|
|
563
|
+
try {
|
|
564
|
+
read = await archilExec(this.#disk, { ...job, network: DENY_EGRESS });
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
// Archil's plan takes no network policy: nothing ran, so the command runs again with the network open.
|
|
568
|
+
if (!(error instanceof ArchilEgressRefused))
|
|
569
|
+
throw error;
|
|
570
|
+
this.#egressOpen = error.message;
|
|
571
|
+
// The caller gave up while Archil answered: the command it no longer waits for is not started now.
|
|
572
|
+
if (signal?.aborted)
|
|
573
|
+
throw abortError(signal);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
read ??= await archilExec(this.#disk, job);
|
|
558
577
|
// Archil answers once the command has ended: each stream once, whole. An error the caller's callback throws is
|
|
559
578
|
// not the call's.
|
|
560
|
-
const
|
|
579
|
+
const warning = deny && this.#egressOpen !== undefined ? `agentrun: this command ran with the network open. ${this.#egressOpen}\n` : "";
|
|
580
|
+
const stderr = Buffer.from(`${warning}${read.stderr}`, "utf8");
|
|
561
581
|
for (const chunk of [{ stream: "stdout", data: read.stdout }, { stream: "stderr", data: stderr }]) {
|
|
562
582
|
try {
|
|
563
583
|
options.onOutput?.(chunk);
|
package/dist/workspace/attach.js
CHANGED
|
@@ -339,6 +339,8 @@ export function attachedWorkspace(base, computer, options = {}) {
|
|
|
339
339
|
async exec(argv, options) {
|
|
340
340
|
if (options.stdin !== undefined)
|
|
341
341
|
throw new WorkspaceError("REFUSED", "exec with stdin runs on the run's folder, not in a computer: a computer's exec takes no stdin");
|
|
342
|
+
if (options.network !== undefined)
|
|
343
|
+
throw new WorkspaceError("REFUSED", "a command in a computer has the computer's own network: its exec takes no network of its own, and nothing ran");
|
|
342
344
|
const { timeoutMs, signal } = options;
|
|
343
345
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
344
346
|
throw new WorkspaceError("REFUSED", "exec's timeoutMs is a number above 0");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type FileHandle } from "node:fs/promises";
|
|
2
|
+
/** The no-link flags of a platform: O_NOFOLLOW (a link at the last name), O_NOFOLLOW_ANY (macOS: a link anywhere). */
|
|
3
|
+
export interface NoLinkFlags {
|
|
4
|
+
readonly O_NOFOLLOW: number;
|
|
5
|
+
readonly O_NOFOLLOW_ANY: number;
|
|
6
|
+
}
|
|
7
|
+
/** macOS's own values (sys/fcntl.h). node names no O_NOFOLLOW_ANY, so its bit is passed as it is. */
|
|
8
|
+
export declare const DARWIN_NO_LINK: NoLinkFlags;
|
|
9
|
+
/**
|
|
10
|
+
* The flags an open below the root passes on `platform`, from the caller's `flags`. On darwin O_NOFOLLOW_ANY in place
|
|
11
|
+
* of O_NOFOLLOW: the kernel refuses the two together (EINVAL), and O_NOFOLLOW_ANY covers the last name too. Elsewhere
|
|
12
|
+
* O_NOFOLLOW added, for the last name of Linux's walk. `noLink` holds the platform's values: this process's O_NOFOLLOW
|
|
13
|
+
* and macOS's O_NOFOLLOW_ANY by default; a test on Linux passes DARWIN_NO_LINK to compute macOS's.
|
|
14
|
+
*/
|
|
15
|
+
export declare function beneathFlags(flags: number, platform: NodeJS.Platform, noLink?: NoLinkFlags): number;
|
|
16
|
+
/** `root`/`below` opened with `flags` (O_NOFOLLOW added), through no link anywhere below `root` (else ELOOP). */
|
|
17
|
+
export declare function openBeneath(root: string, below: string, flags: number, mode?: number): Promise<FileHandle>;
|
|
18
|
+
/** openBeneath, synchronous (grep's worker): the descriptor. */
|
|
19
|
+
export declare function openBeneathSync(root: string, below: string, flags: number, mode?: number): number;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Opening a name below a trusted folder through no symbolic link anywhere on the way: how local.ts and grep-worker.ts
|
|
2
|
+
// open a file or folder where there is no /proc/self/fd (macOS), so that what is opened is under the root at the open
|
|
3
|
+
// itself, whatever the path is swapped to before or after.
|
|
4
|
+
//
|
|
5
|
+
// On macOS that is the kernel's O_NOFOLLOW_ANY (macOS 11; sys/fcntl.h): the open fails ELOOP at a link anywhere in the
|
|
6
|
+
// path, not only at its end. The kernel walks the path folder by folder, each lookup made in the folder before it, so a
|
|
7
|
+
// handle it returns was reached from the root through real folders only. node names no such flag; the bit is passed
|
|
8
|
+
// as it is, and node 24 runs on no macOS without it. On Linux, where local.ts takes this branch only when a test
|
|
9
|
+
// forces it, the same answer comes from a walk from the root: each folder opened with O_NOFOLLOW through
|
|
10
|
+
// /proc/self/fd/<fd> of the one before, and a link met on the way is ELOOP, as on macOS. No other platform has a way
|
|
11
|
+
// to refuse a link on the way, so there the open fails.
|
|
12
|
+
import { closeSync, constants, lstatSync, openSync } from "node:fs";
|
|
13
|
+
import { lstat, open } from "node:fs/promises";
|
|
14
|
+
const { O_DIRECTORY, O_NOFOLLOW, O_RDONLY } = constants;
|
|
15
|
+
/** macOS's own values (sys/fcntl.h). node names no O_NOFOLLOW_ANY, so its bit is passed as it is. */
|
|
16
|
+
export const DARWIN_NO_LINK = { O_NOFOLLOW: 0x100, O_NOFOLLOW_ANY: 0x20000000 };
|
|
17
|
+
/**
|
|
18
|
+
* The flags an open below the root passes on `platform`, from the caller's `flags`. On darwin O_NOFOLLOW_ANY in place
|
|
19
|
+
* of O_NOFOLLOW: the kernel refuses the two together (EINVAL), and O_NOFOLLOW_ANY covers the last name too. Elsewhere
|
|
20
|
+
* O_NOFOLLOW added, for the last name of Linux's walk. `noLink` holds the platform's values: this process's O_NOFOLLOW
|
|
21
|
+
* and macOS's O_NOFOLLOW_ANY by default; a test on Linux passes DARWIN_NO_LINK to compute macOS's.
|
|
22
|
+
*/
|
|
23
|
+
export function beneathFlags(flags, platform, noLink = { O_NOFOLLOW, O_NOFOLLOW_ANY: DARWIN_NO_LINK.O_NOFOLLOW_ANY }) {
|
|
24
|
+
if (platform === "darwin")
|
|
25
|
+
return (flags & ~noLink.O_NOFOLLOW) | noLink.O_NOFOLLOW_ANY;
|
|
26
|
+
return flags | noLink.O_NOFOLLOW;
|
|
27
|
+
}
|
|
28
|
+
const DIR_FLAGS = O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
|
|
29
|
+
const DARWIN = process.platform === "darwin";
|
|
30
|
+
const LINUX = process.platform === "linux";
|
|
31
|
+
const errno = (error) => error?.code;
|
|
32
|
+
const failure = (code, message) => Object.assign(new Error(`${code}: ${message}`), { code });
|
|
33
|
+
/** The names of `below` ("" is the root itself, else names joined by "/", none of them "", "." or ".."). */
|
|
34
|
+
function namesOf(below) {
|
|
35
|
+
const names = below === "" ? [] : below.split("/");
|
|
36
|
+
if (names.some((name) => name === "" || name === "." || name === ".."))
|
|
37
|
+
throw failure("EINVAL", `${JSON.stringify(below)} is not a path below the root`);
|
|
38
|
+
return names;
|
|
39
|
+
}
|
|
40
|
+
/** A link on the way as macOS has it: a folder opened with O_DIRECTORY | O_NOFOLLOW that is a link fails ENOTDIR on
|
|
41
|
+
* Linux, ELOOP with O_NOFOLLOW_ANY. */
|
|
42
|
+
const asLoop = (error, at, link) => errno(error) === "ENOTDIR" && link ? failure("ELOOP", `a symbolic link on the way, open '${at}'`) : error;
|
|
43
|
+
/** `root`/`below` opened with `flags` (O_NOFOLLOW added), through no link anywhere below `root` (else ELOOP). */
|
|
44
|
+
export async function openBeneath(root, below, flags, mode) {
|
|
45
|
+
const names = namesOf(below);
|
|
46
|
+
const how = beneathFlags(flags, process.platform);
|
|
47
|
+
if (DARWIN)
|
|
48
|
+
return open(names.length === 0 ? root : `${root}/${below}`, how, mode);
|
|
49
|
+
if (!LINUX)
|
|
50
|
+
throw failure("ENOSYS", `no open on ${process.platform} refuses a symbolic link on the way`);
|
|
51
|
+
if (names.length === 0)
|
|
52
|
+
return open(root, how, mode);
|
|
53
|
+
const step = async (dir, name, how, made) => {
|
|
54
|
+
const at = `/proc/self/fd/${dir.fd}/${name}`;
|
|
55
|
+
try {
|
|
56
|
+
return await open(at, how, made);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw asLoop(error, at, await lstat(at).then((stats) => stats.isSymbolicLink(), () => false));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
let dir = await open(root, DIR_FLAGS);
|
|
63
|
+
try {
|
|
64
|
+
for (const name of names.slice(0, -1)) {
|
|
65
|
+
const above = dir;
|
|
66
|
+
dir = await step(dir, name, DIR_FLAGS);
|
|
67
|
+
await above.close();
|
|
68
|
+
}
|
|
69
|
+
return await step(dir, names.at(-1), how, mode);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await dir.close().catch(() => undefined);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** openBeneath, synchronous (grep's worker): the descriptor. */
|
|
76
|
+
export function openBeneathSync(root, below, flags, mode) {
|
|
77
|
+
const names = namesOf(below);
|
|
78
|
+
const how = beneathFlags(flags, process.platform);
|
|
79
|
+
if (DARWIN)
|
|
80
|
+
return openSync(names.length === 0 ? root : `${root}/${below}`, how, mode);
|
|
81
|
+
if (!LINUX)
|
|
82
|
+
throw failure("ENOSYS", `no open on ${process.platform} refuses a symbolic link on the way`);
|
|
83
|
+
if (names.length === 0)
|
|
84
|
+
return openSync(root, how, mode);
|
|
85
|
+
const step = (dir, name, how, made) => {
|
|
86
|
+
const at = `/proc/self/fd/${dir}/${name}`;
|
|
87
|
+
try {
|
|
88
|
+
return openSync(at, how, made);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw asLoop(error, at, lstatSync(at, { throwIfNoEntry: false })?.isSymbolicLink() ?? false);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
let dir = openSync(root, DIR_FLAGS);
|
|
95
|
+
try {
|
|
96
|
+
for (const name of names.slice(0, -1)) {
|
|
97
|
+
const above = dir;
|
|
98
|
+
dir = step(dir, name, DIR_FLAGS);
|
|
99
|
+
closeSync(above);
|
|
100
|
+
}
|
|
101
|
+
return step(dir, names.at(-1), how, mode);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
closeSync(dir);
|
|
105
|
+
}
|
|
106
|
+
}
|