@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/packs.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { EFFORTS, THINKING_LEVELS } from "./model.js";
|
|
2
|
-
import { isObject } from "./validate.js";
|
|
3
|
-
/** A pack's name. */
|
|
4
|
-
export const PACK_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
5
|
-
/** An output type: a key of a pack's `outputs`. */
|
|
6
|
-
export const OUTPUT_TYPE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
7
|
-
/** A skill name a pack names: the name rule Agent Skills and the Claude adapter use. */
|
|
8
|
-
export const PACK_SKILL = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
9
|
-
/** The most skills one list of a pack names. */
|
|
10
|
-
export const MAX_PACK_SKILLS = 32;
|
|
11
|
-
/** The most output types one pack names. */
|
|
12
|
-
export const MAX_PACK_OUTPUTS = 32;
|
|
13
|
-
/** The longest output file: the same cap serve applies to a skill path. */
|
|
14
|
-
export const MAX_OUTPUT_FILE = 512;
|
|
15
|
-
const PACK_FIELDS = ["version", "name", "effort", "outputs", "default_output"];
|
|
16
|
-
const EFFORT_FIELDS = ["skills", "thinking"];
|
|
17
|
-
const OUTPUT_FIELDS = ["skills", "file", "effort"];
|
|
18
|
-
const OVERRIDE_FIELDS = ["skills"];
|
|
19
|
-
const issue = (field, reason, message, fix) => ({ field, reason, message, ...(fix ? { fix } : {}) });
|
|
20
|
-
/** `key` under `at`; at the top of a pack with no `at`, the key alone. */
|
|
21
|
-
const under = (at, key) => (at ? `${at}.${key}` : key);
|
|
22
|
-
/** `value`'s own property `key`, never one it inherits (an output type may be named `constructor`). */
|
|
23
|
-
const own = (value, key) => (Object.hasOwn(value, key) ? value[key] : undefined);
|
|
24
|
-
/** Each key of `value` not in `fields` refused. */
|
|
25
|
-
function onlyFields(value, fields, at, out) {
|
|
26
|
-
for (const key of Object.keys(value)) {
|
|
27
|
-
if (!fields.includes(key))
|
|
28
|
-
out.push(issue(under(at, key), "not_allowed", `${at || "the pack"} keeps no field ${key}: it keeps ${fields.join(", ")}`, `Remove ${under(at, key)}.`));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/** A list of skill names: each one PACK_SKILL takes, none twice, at most MAX_PACK_SKILLS. Over the limit, the first
|
|
32
|
-
* MAX_PACK_SKILLS are still checked and the rest are not. */
|
|
33
|
-
function skillList(value, at, out) {
|
|
34
|
-
if (value === undefined)
|
|
35
|
-
return void out.push(issue(at, "missing", `${at} is required`));
|
|
36
|
-
if (!Array.isArray(value))
|
|
37
|
-
return void out.push(issue(at, "wrong_type", `${at} is not a list of skill names`));
|
|
38
|
-
if (value.length > MAX_PACK_SKILLS)
|
|
39
|
-
out.push(issue(at, "too_many", `${at} names ${value.length} skills, more than ${MAX_PACK_SKILLS}`));
|
|
40
|
-
const seen = new Set();
|
|
41
|
-
value.slice(0, MAX_PACK_SKILLS).forEach((name, i) => {
|
|
42
|
-
const field = `${at}[${i}]`;
|
|
43
|
-
if (typeof name !== "string")
|
|
44
|
-
out.push(issue(field, "wrong_type", `${field} is not a skill name`));
|
|
45
|
-
else if (!PACK_SKILL.test(name))
|
|
46
|
-
out.push(issue(field, "bad_format", `${field} is not a skill name: ${JSON.stringify(name)} must match ${PACK_SKILL.source}`));
|
|
47
|
-
else if (seen.has(name))
|
|
48
|
-
out.push(issue(field, "duplicate", `${field} names ${name} again`, `Remove ${field}.`));
|
|
49
|
-
else
|
|
50
|
-
seen.add(name);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** An object with `skills` and only `fields`, or undefined after its issue. */
|
|
54
|
-
function skillsRow(value, fields, at, out) {
|
|
55
|
-
if (value === undefined)
|
|
56
|
-
return void out.push(issue(at, "missing", `${at} is required`));
|
|
57
|
-
if (!isObject(value))
|
|
58
|
-
return void out.push(issue(at, "wrong_type", `${at} is not an object`));
|
|
59
|
-
onlyFields(value, fields, at, out);
|
|
60
|
-
skillList(value.skills, under(at, "skills"), out);
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
/** An object keyed by effort, each row checked by `row`; `every` asks for all three. */
|
|
64
|
-
function byEffort(value, at, every, out, row) {
|
|
65
|
-
if (value === undefined)
|
|
66
|
-
return void out.push(issue(at, "missing", `${at} is required`));
|
|
67
|
-
if (!isObject(value))
|
|
68
|
-
return void out.push(issue(at, "wrong_type", `${at} is not an object of efforts`));
|
|
69
|
-
for (const key of Object.keys(value)) {
|
|
70
|
-
if (!EFFORTS.includes(key))
|
|
71
|
-
out.push(issue(under(at, key), "not_allowed", `${key} is not an effort: an effort is one of ${EFFORTS.join(", ")}`, `Remove ${under(at, key)}.`));
|
|
72
|
-
}
|
|
73
|
-
for (const effort of EFFORTS)
|
|
74
|
-
if (every || Object.hasOwn(value, effort))
|
|
75
|
-
row(own(value, effort), under(at, effort));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* A file a run writes in its workspace, as the run's file route reads it back: relative, `/` between segments, no
|
|
79
|
-
* segment empty or starting with `.` (`.`, `..` and dot-named entries are the run's own), no backslash or NUL.
|
|
80
|
-
*/
|
|
81
|
-
function fileIssue(file, at, out) {
|
|
82
|
-
if (typeof file !== "string")
|
|
83
|
-
out.push(issue(at, "wrong_type", `${at} is not a path`));
|
|
84
|
-
else if (file.length > MAX_OUTPUT_FILE)
|
|
85
|
-
out.push(issue(at, "too_long", `${at} is longer than ${MAX_OUTPUT_FILE} characters`));
|
|
86
|
-
else if (file.includes("\\") || file.includes("\0") || file.split("/").some((part) => part === "" || part.startsWith("."))) {
|
|
87
|
-
out.push(issue(at, "bad_format", `${at} is not a plain relative path in the run's workspace: no leading /, no empty segment, none starting with ., no backslash or NUL`));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Every issue with `value` as a version 1 pack, none if it is one. Fields are paths into the pack
|
|
92
|
-
* (`effort.low.skills[0]`), under `at` when given (`profile.effort.low.skills[0]`); the pack itself is `at`. A skill
|
|
93
|
-
* list or `outputs` over its limit is `too_many`, and its items up to the limit are checked as any others; items past
|
|
94
|
-
* the limit are not checked, so an oversized pack makes a bounded number of issues.
|
|
95
|
-
*/
|
|
96
|
-
export function packIssues(value, { at = "" } = {}) {
|
|
97
|
-
if (!isObject(value))
|
|
98
|
-
return [issue(at, value === undefined ? "missing" : "wrong_type", `${at || "the pack"} is not an object`)];
|
|
99
|
-
const out = [];
|
|
100
|
-
onlyFields(value, PACK_FIELDS, at, out);
|
|
101
|
-
const version = under(at, "version");
|
|
102
|
-
if (value.version === undefined)
|
|
103
|
-
out.push(issue(version, "missing", `${version} is required`));
|
|
104
|
-
else if (typeof value.version !== "number")
|
|
105
|
-
out.push(issue(version, "wrong_type", `${version} is not a number`));
|
|
106
|
-
else if (value.version !== 1)
|
|
107
|
-
out.push(issue(version, "not_an_option", `${version} is 1: this server reads version 1 packs`));
|
|
108
|
-
const name = under(at, "name");
|
|
109
|
-
if (value.name === undefined)
|
|
110
|
-
out.push(issue(name, "missing", `${name} is required`));
|
|
111
|
-
else if (typeof value.name !== "string")
|
|
112
|
-
out.push(issue(name, "wrong_type", `${name} is not a string`));
|
|
113
|
-
else if (!PACK_NAME.test(value.name))
|
|
114
|
-
out.push(issue(name, "bad_format", `${name} must match ${PACK_NAME.source}`));
|
|
115
|
-
byEffort(value.effort, under(at, "effort"), true, out, (row, field) => {
|
|
116
|
-
const checked = skillsRow(row, EFFORT_FIELDS, field, out);
|
|
117
|
-
if (checked?.thinking !== undefined && !THINKING_LEVELS.includes(checked.thinking)) {
|
|
118
|
-
out.push(issue(under(field, "thinking"), "not_an_option", `${under(field, "thinking")} is one of ${THINKING_LEVELS.join(", ")}: thinking is never off`));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const outputs = under(at, "outputs");
|
|
122
|
-
if (value.outputs === undefined)
|
|
123
|
-
out.push(issue(outputs, "missing", `${outputs} is required`));
|
|
124
|
-
else if (!isObject(value.outputs))
|
|
125
|
-
out.push(issue(outputs, "wrong_type", `${outputs} is not an object of output types`));
|
|
126
|
-
else {
|
|
127
|
-
const entries = Object.entries(value.outputs);
|
|
128
|
-
if (entries.length > MAX_PACK_OUTPUTS)
|
|
129
|
-
out.push(issue(outputs, "too_many", `${outputs} names ${entries.length} output types, more than ${MAX_PACK_OUTPUTS}`));
|
|
130
|
-
for (const [type, output] of entries.slice(0, MAX_PACK_OUTPUTS)) {
|
|
131
|
-
const field = under(outputs, type);
|
|
132
|
-
if (!OUTPUT_TYPE.test(type))
|
|
133
|
-
out.push(issue(field, "bad_format", `the output type ${JSON.stringify(type)} must match ${OUTPUT_TYPE.source}`));
|
|
134
|
-
const checked = skillsRow(output, OUTPUT_FIELDS, field, out);
|
|
135
|
-
if (checked?.file !== undefined)
|
|
136
|
-
fileIssue(checked.file, under(field, "file"), out);
|
|
137
|
-
if (checked?.effort !== undefined)
|
|
138
|
-
byEffort(checked.effort, under(field, "effort"), false, out, (row, place) => void skillsRow(row, OVERRIDE_FIELDS, place, out));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const fallback = under(at, "default_output");
|
|
142
|
-
if (value.default_output !== undefined) {
|
|
143
|
-
if (typeof value.default_output !== "string")
|
|
144
|
-
out.push(issue(fallback, "wrong_type", `${fallback} is not an output type`));
|
|
145
|
-
else if (isObject(value.outputs) && !Object.hasOwn(value.outputs, value.default_output)) {
|
|
146
|
-
const types = Object.keys(value.outputs);
|
|
147
|
-
out.push(issue(fallback, "not_an_option", `${fallback} is one of the pack's output types: ${types.length ? types.join(", ") : "it names none"}`, `Name a key of ${outputs}, or remove ${fallback}.`));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return out;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* `pack` (one packIssues finds nothing wrong with) read for a run at `effort` asked for `output`: the effort row's
|
|
154
|
-
* skills, then the output's writer skills (its skills at that effort if it names some there, else its own), each skill
|
|
155
|
-
* once at its first place. With no output asked, the pack's default_output; with neither, no output and no writer.
|
|
156
|
-
* `thinking` is there only when the effort row sets one, so the caller keeps its own level otherwise. An effort that is
|
|
157
|
-
* not one, or an output type the pack does not name, is an issue on `effort` or `output`.
|
|
158
|
-
*/
|
|
159
|
-
export function resolvePack(pack, { effort = "medium", output } = {}) {
|
|
160
|
-
const issues = [];
|
|
161
|
-
if (!EFFORTS.includes(effort))
|
|
162
|
-
issues.push(issue("effort", "not_an_option", `effort is one of ${EFFORTS.join(", ")}`));
|
|
163
|
-
if (output !== undefined && (typeof output !== "string" || !Object.hasOwn(pack.outputs, output))) {
|
|
164
|
-
const types = Object.keys(pack.outputs);
|
|
165
|
-
const options = types.length ? `the pack ${pack.name} names ${types.join(", ")}` : `the pack ${pack.name} names no output type`;
|
|
166
|
-
issues.push(issue("output", typeof output === "string" ? "not_an_option" : "wrong_type", `output is an output type of the pack: ${options}`));
|
|
167
|
-
}
|
|
168
|
-
if (issues.length)
|
|
169
|
-
return { issues };
|
|
170
|
-
const row = pack.effort[effort];
|
|
171
|
-
const type = output ?? pack.default_output;
|
|
172
|
-
const writer = type === undefined ? undefined : pack.outputs[type];
|
|
173
|
-
const writers = writer ? (writer.effort?.[effort]?.skills ?? writer.skills) : [];
|
|
174
|
-
return {
|
|
175
|
-
effort,
|
|
176
|
-
...(row.thinking !== undefined ? { thinking: row.thinking } : {}),
|
|
177
|
-
skills: [...new Set([...row.skills, ...writers])],
|
|
178
|
-
...(type !== undefined && writer ? { output: { type, ...(writer.file !== undefined ? { file: writer.file } : {}) } } : {}),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ApiError } from "./errors.js";
|
|
2
|
-
/** What an adapter keeps sealed, and where: `server`, one set for the server; `trigger`, one set per trigger, by its id.
|
|
3
|
-
* A field with `mint` is a Standard Webhooks secret this server makes (standard-webhooks.ts), shown once; any other is
|
|
4
|
-
* given (set). `minBytes`: the fewest bytes its value may hold (standard-webhooks.ts keyBytes), MIN_KEY_BYTES for a key
|
|
5
|
-
* a request is verified with. `public`: a value that is no secret (an app's id, its name), kept with the rest but never
|
|
6
|
-
* in the list of the server's secrets, so no run's text is cut of it, and of any length. `format: "pem"`: a PEM private
|
|
7
|
-
* key, whose lines each are listed as secrets. */
|
|
8
|
-
export type SettingsSpec = {
|
|
9
|
-
scope: "server" | "trigger";
|
|
10
|
-
fields: Record<string, {
|
|
11
|
-
mint?: true;
|
|
12
|
-
minBytes?: number;
|
|
13
|
-
public?: true;
|
|
14
|
-
format?: "pem";
|
|
15
|
-
}>;
|
|
16
|
-
};
|
|
17
|
-
/** The scope of a server-scoped adapter's settings. */
|
|
18
|
-
export declare const SERVER_SCOPE = "server";
|
|
19
|
-
export declare const settingsFile: (adapterId: string) => string;
|
|
20
|
-
export declare class SealedSettings {
|
|
21
|
-
private readonly adapterId;
|
|
22
|
-
private readonly spec;
|
|
23
|
-
private readonly key;
|
|
24
|
-
private readonly file;
|
|
25
|
-
private sealed;
|
|
26
|
-
/** Opened, by scope and field: read once at the start, then kept with every write. */
|
|
27
|
-
private readonly opened;
|
|
28
|
-
/** The values this store held open and no longer does, rotated or removed: in memory alone, for this process's life. */
|
|
29
|
-
private readonly retired;
|
|
30
|
-
/** The PEM keys this store held open and no longer does: in memory alone, listed by pemValues. */
|
|
31
|
-
private readonly retiredPem;
|
|
32
|
-
/** Why the file does not read: nothing is made, rotated or removed, nothing it holds is read, and it is never written over. */
|
|
33
|
-
private readonly unreadable?;
|
|
34
|
-
constructor(data: string, adapterId: string, spec: SettingsSpec, key: Buffer, say: (fields: Record<string, string>) => void);
|
|
35
|
-
/** A new secret for `scope`'s `field` (one the spec mints), written sealed before it is answered: its only showing. */
|
|
36
|
-
mint(scope: string, field: string): string;
|
|
37
|
-
/** A given value for `scope`'s `field` (a sender's signing secret, a bot's token), written sealed. One under its
|
|
38
|
-
* field's `minBytes` is refused, 422, before anything is written. */
|
|
39
|
-
set(scope: string, field: string, value: string): void;
|
|
40
|
-
private put;
|
|
41
|
-
/** `scope`'s `field`, opened; undefined when it is not set, or does not open here. */
|
|
42
|
-
get(scope: string, field: string): string | undefined;
|
|
43
|
-
/** A scope's settings gone (a deleted trigger's); with the file unreadable they stay in it, unread. */
|
|
44
|
-
remove(scope: string): void;
|
|
45
|
-
/** Every value held open, and every one rotated or removed since this store opened, for the server's list of its own
|
|
46
|
-
* secrets (server-secrets.ts): a run that echoes a secret after its rotation is cut all the same. */
|
|
47
|
-
values(): string[];
|
|
48
|
-
/** What of `field`'s `value` is a secret to list with a floor (server-secrets.ts): none for a public field or a PEM key
|
|
49
|
-
* (pemValues lists that), else the value. */
|
|
50
|
-
private secretsOf;
|
|
51
|
-
/** Every PEM key held open, or rotated or removed since this store opened: each whole and each of its base64 lines,
|
|
52
|
-
* the short last one too, listed with no floor (server-secrets.ts `whole`). */
|
|
53
|
-
pemValues(): string[];
|
|
54
|
-
private retire;
|
|
55
|
-
/** Why nothing can be written here (a file that does not read), as the refusal a write would throw;
|
|
56
|
-
* undefined when one can be. */
|
|
57
|
-
unwritable(): ApiError | undefined;
|
|
58
|
-
private writable;
|
|
59
|
-
private write;
|
|
60
|
-
}
|
package/dist/sealed-settings.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
// A trigger source's sealed settings (trigger-adapter.ts `settings`): the trigger kernel's one store of them. One file
|
|
2
|
-
// per adapter, DIR/trigger-settings-<adapter>.json, holding each scope's fields (the server's, or one trigger's, by its
|
|
3
|
-
// id) sealed under the seal key (tool-keys.ts), each bound to its adapter, scope and field by its AAD. There is always a
|
|
4
|
-
// seal key (seal-key.ts), so none is kept in the clear. A file that does not read is never written over: nothing is made or removed until
|
|
5
|
-
// it is fixed. A value that does not open under this server's seal key is said once, kept sealed as it is, and reads as
|
|
6
|
-
// unset.
|
|
7
|
-
import { readFileSync } from "node:fs";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { seal, unseal } from "@parcha/pi-durable-agent";
|
|
10
|
-
import { ApiError, invalid } from "./errors.js";
|
|
11
|
-
import { writeDurableSync } from "./files.js";
|
|
12
|
-
import { keyBytes, MIN_KEY_BYTES, mintSecret, SECRET_PREFIX } from "./standard-webhooks.js";
|
|
13
|
-
import { SEAL_KEY_ENV } from "./tool-keys.js";
|
|
14
|
-
import { isObject } from "./validate.js";
|
|
15
|
-
/** A PEM private key, whole: its BEGIN line, its base64 lines, its END line. */
|
|
16
|
-
const PEM = /^-----BEGIN ((?:[A-Z]+ )*)PRIVATE KEY-----\r?\n[A-Za-z0-9+/=\r\n]+-----END \1PRIVATE KEY-----\s*$/;
|
|
17
|
-
/** The scope of a server-scoped adapter's settings. */
|
|
18
|
-
export const SERVER_SCOPE = "server";
|
|
19
|
-
export const settingsFile = (adapterId) => `trigger-settings-${adapterId}.json`;
|
|
20
|
-
const aad = (adapterId, scope, field) => `trigger-settings|${adapterId}|${scope}|${field}`;
|
|
21
|
-
/** The sealed values `file` keeps, by scope and field: none when there is no file, and why not when it does not read. */
|
|
22
|
-
function sealedIn(file) {
|
|
23
|
-
let text;
|
|
24
|
-
try {
|
|
25
|
-
text = readFileSync(file, "utf8");
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
return error.code === "ENOENT" ? { sealed: {} } : { unreadable: error.message };
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const doc = JSON.parse(text);
|
|
32
|
-
const whole = isObject(doc) && doc.v === 1 && isObject(doc.values) && Object.values(doc.values).every((fields) => isObject(fields) && Object.values(fields).every((v) => typeof v === "string"));
|
|
33
|
-
return whole ? { sealed: doc.values } : { unreadable: "not a trigger settings file of version 1" };
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
return { unreadable: error.message };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export class SealedSettings {
|
|
40
|
-
adapterId;
|
|
41
|
-
spec;
|
|
42
|
-
key;
|
|
43
|
-
file;
|
|
44
|
-
sealed = {};
|
|
45
|
-
/** Opened, by scope and field: read once at the start, then kept with every write. */
|
|
46
|
-
opened = {};
|
|
47
|
-
/** The values this store held open and no longer does, rotated or removed: in memory alone, for this process's life. */
|
|
48
|
-
retired = new Set();
|
|
49
|
-
/** The PEM keys this store held open and no longer does: in memory alone, listed by pemValues. */
|
|
50
|
-
retiredPem = [];
|
|
51
|
-
/** Why the file does not read: nothing is made, rotated or removed, nothing it holds is read, and it is never written over. */
|
|
52
|
-
unreadable;
|
|
53
|
-
constructor(data, adapterId, spec, key, say) {
|
|
54
|
-
this.adapterId = adapterId;
|
|
55
|
-
this.spec = spec;
|
|
56
|
-
this.key = key;
|
|
57
|
-
this.file = join(data, settingsFile(adapterId));
|
|
58
|
-
const read = sealedIn(this.file);
|
|
59
|
-
if ("unreadable" in read) {
|
|
60
|
-
this.unreadable = read.unreadable;
|
|
61
|
-
say({ condition: "trigger_settings_unreadable", adapter: adapterId, file: this.file, error: read.unreadable });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.sealed = read.sealed;
|
|
65
|
-
for (const [scope, fields] of Object.entries(this.sealed)) {
|
|
66
|
-
for (const [field, value] of Object.entries(fields)) {
|
|
67
|
-
try {
|
|
68
|
-
(this.opened[scope] ??= {})[field] = unseal(this.key, Buffer.from(value, "base64"), aad(adapterId, scope, field)).toString("utf8");
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
say({ condition: "trigger_setting_unopened", adapter: adapterId, scope, field, file: this.file, effect: `it does not open under ${SEAL_KEY_ENV}: unset until it is set again` });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** A new secret for `scope`'s `field` (one the spec mints), written sealed before it is answered: its only showing. */
|
|
77
|
-
mint(scope, field) {
|
|
78
|
-
if (!this.spec.fields[field]?.mint)
|
|
79
|
-
throw new Error(`${this.adapterId}'s settings mint no ${field}`);
|
|
80
|
-
const secret = mintSecret();
|
|
81
|
-
this.put(scope, field, secret);
|
|
82
|
-
return secret;
|
|
83
|
-
}
|
|
84
|
-
/** A given value for `scope`'s `field` (a sender's signing secret, a bot's token), written sealed. One under its
|
|
85
|
-
* field's `minBytes` is refused, 422, before anything is written. */
|
|
86
|
-
set(scope, field, value) {
|
|
87
|
-
const spec = this.spec.fields[field];
|
|
88
|
-
if (!spec)
|
|
89
|
-
throw new Error(`${this.adapterId}'s settings keep no ${field}`);
|
|
90
|
-
if (spec.format === "pem" && !PEM.test(value))
|
|
91
|
-
throw invalid([{ field, reason: "invalid", message: `${field} is a PEM private key` }]);
|
|
92
|
-
// A value the list of the server's secrets would pass over (server-secrets.ts: whitespace, under 8 bytes) would be
|
|
93
|
-
// left out of every redaction: none is kept. A public one is no secret; a PEM key is listed by its lines.
|
|
94
|
-
if (!spec.public && spec.format !== "pem" && (/\s/.test(value) || Buffer.byteLength(value, "utf8") < 8))
|
|
95
|
-
throw invalid([{ field, reason: "invalid", message: `${field} is at least 8 bytes, with no whitespace` }]);
|
|
96
|
-
// A verification key is kept only as the spec writes one, or every request it checks would be refused.
|
|
97
|
-
if (spec.minBytes === MIN_KEY_BYTES && !value.startsWith(SECRET_PREFIX))
|
|
98
|
-
throw invalid([{ field, reason: "invalid", message: `${field} is a Standard Webhooks secret: whsec_ and its key in base64` }]);
|
|
99
|
-
if (spec.minBytes !== undefined && keyBytes(value) < spec.minBytes)
|
|
100
|
-
throw invalid([{ field, reason: "too_short", message: `${field} holds at least ${spec.minBytes} bytes` }]);
|
|
101
|
-
this.put(scope, field, value);
|
|
102
|
-
}
|
|
103
|
-
put(scope, field, value) {
|
|
104
|
-
this.writable();
|
|
105
|
-
this.write({ ...this.sealed, [scope]: { ...this.sealed[scope], [field]: seal(this.key, Buffer.from(value, "utf8"), aad(this.adapterId, scope, field)).toString("base64") } });
|
|
106
|
-
const was = this.opened[scope]?.[field];
|
|
107
|
-
if (was !== undefined && was !== value)
|
|
108
|
-
this.retire(field, was);
|
|
109
|
-
(this.opened[scope] ??= {})[field] = value;
|
|
110
|
-
}
|
|
111
|
-
/** `scope`'s `field`, opened; undefined when it is not set, or does not open here. */
|
|
112
|
-
get(scope, field) {
|
|
113
|
-
return this.opened[scope]?.[field];
|
|
114
|
-
}
|
|
115
|
-
/** A scope's settings gone (a deleted trigger's); with the file unreadable they stay in it, unread. */
|
|
116
|
-
remove(scope) {
|
|
117
|
-
if (this.unreadable || !(scope in this.sealed))
|
|
118
|
-
return;
|
|
119
|
-
const { [scope]: _, ...rest } = this.sealed;
|
|
120
|
-
this.write(rest);
|
|
121
|
-
for (const [field, value] of Object.entries(this.opened[scope] ?? {}))
|
|
122
|
-
this.retire(field, value);
|
|
123
|
-
delete this.opened[scope];
|
|
124
|
-
}
|
|
125
|
-
/** Every value held open, and every one rotated or removed since this store opened, for the server's list of its own
|
|
126
|
-
* secrets (server-secrets.ts): a run that echoes a secret after its rotation is cut all the same. */
|
|
127
|
-
values() {
|
|
128
|
-
return [...Object.values(this.opened).flatMap((fields) => Object.entries(fields).flatMap(([field, value]) => this.secretsOf(field, value))), ...this.retired];
|
|
129
|
-
}
|
|
130
|
-
/** What of `field`'s `value` is a secret to list with a floor (server-secrets.ts): none for a public field or a PEM key
|
|
131
|
-
* (pemValues lists that), else the value. */
|
|
132
|
-
secretsOf(field, value) {
|
|
133
|
-
const spec = this.spec.fields[field];
|
|
134
|
-
if (spec?.public || spec?.format === "pem")
|
|
135
|
-
return [];
|
|
136
|
-
return [value];
|
|
137
|
-
}
|
|
138
|
-
/** Every PEM key held open, or rotated or removed since this store opened: each whole and each of its base64 lines,
|
|
139
|
-
* the short last one too, listed with no floor (server-secrets.ts `whole`). */
|
|
140
|
-
pemValues() {
|
|
141
|
-
const pem = (field) => this.spec.fields[field]?.format === "pem";
|
|
142
|
-
const forms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("-----"))];
|
|
143
|
-
return [...Object.values(this.opened).flatMap((fields) => Object.entries(fields).filter(([field]) => pem(field)).flatMap(([, value]) => forms(value))), ...this.retiredPem.flatMap(forms)];
|
|
144
|
-
}
|
|
145
|
-
retire(field, value) {
|
|
146
|
-
if (this.spec.fields[field]?.format === "pem")
|
|
147
|
-
this.retiredPem.push(value);
|
|
148
|
-
else
|
|
149
|
-
for (const secret of this.secretsOf(field, value))
|
|
150
|
-
this.retired.add(secret);
|
|
151
|
-
}
|
|
152
|
-
/** Why nothing can be written here (a file that does not read), as the refusal a write would throw;
|
|
153
|
-
* undefined when one can be. */
|
|
154
|
-
unwritable() {
|
|
155
|
-
try {
|
|
156
|
-
this.writable();
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
return error;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
writable() {
|
|
164
|
-
if (this.unreadable)
|
|
165
|
-
throw new ApiError("store_unreadable", `${settingsFile(this.adapterId)} in the data directory does not read (${this.unreadable}); it is never written over, so no ${this.adapterId} trigger's secret is made or rotated. Fix it or move it away, then restart.`);
|
|
166
|
-
}
|
|
167
|
-
write(sealed) {
|
|
168
|
-
writeDurableSync(this.file, `${JSON.stringify({ v: 1, values: sealed }, null, 2)}\n`);
|
|
169
|
-
this.sealed = sealed;
|
|
170
|
-
}
|
|
171
|
-
}
|
package/dist/sessions.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import { type Harness } from "@earendil-works/pi-durable";
|
|
3
|
-
import { type SessionStore } from "@parcha/agentrun-kernel";
|
|
4
|
-
import { type SyncTarget } from "@parcha/pi-durable-disk";
|
|
5
|
-
/** `store`: the run's store, which the sessions' barrier syncs (a kernel effect's start, before it runs). */
|
|
6
|
-
export declare function durableSessions(harness: Harness, context: Context, store?: SyncTarget): SessionStore;
|
package/dist/sessions.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
|
-
import { SessionFenced } from "@parcha/agentrun-kernel";
|
|
3
|
-
import { BARRIER, FencedError, syncNow } from "@parcha/pi-durable-disk";
|
|
4
|
-
const SESSION_KEY = "session.key";
|
|
5
|
-
const PAGE = 500;
|
|
6
|
-
/** `store`: the run's store, which the sessions' barrier syncs (a kernel effect's start, before it runs). */
|
|
7
|
-
export function durableSessions(harness, context, store) {
|
|
8
|
-
const holders = new Map();
|
|
9
|
-
const known = new Map();
|
|
10
|
-
// One creation per key at a time: two first opens at once share it, so a key names one conversation.
|
|
11
|
-
const creating = new Map();
|
|
12
|
-
const scan = async (id, each) => {
|
|
13
|
-
const conversation = await harness.conversation(id, context);
|
|
14
|
-
if (!conversation)
|
|
15
|
-
return;
|
|
16
|
-
for (let cursor;;) {
|
|
17
|
-
const page = await conversation.entries({ order: "ascending" }, PAGE, cursor, context);
|
|
18
|
-
for (const entry of page.items)
|
|
19
|
-
each(entry);
|
|
20
|
-
if (page.next === undefined)
|
|
21
|
-
return;
|
|
22
|
-
cursor = page.next;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const find = async (key) => {
|
|
26
|
-
if (!known.has(key)) {
|
|
27
|
-
await scan(ROOT_CONVERSATION_ID, (entry) => {
|
|
28
|
-
const data = entry.data;
|
|
29
|
-
// The first entry of a key names its conversation.
|
|
30
|
-
if (entry.kind === SESSION_KEY && typeof data?.key === "string" && data.conversation != null && !known.has(data.key))
|
|
31
|
-
known.set(data.key, data.conversation);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return known.get(key);
|
|
35
|
-
};
|
|
36
|
-
const read = async (key) => {
|
|
37
|
-
const id = await find(key);
|
|
38
|
-
const out = [];
|
|
39
|
-
if (id)
|
|
40
|
-
await scan(id, (entry) => out.push({ kind: entry.kind, data: (entry.data ?? null) }));
|
|
41
|
-
return out;
|
|
42
|
-
};
|
|
43
|
-
/** One commit, refused as SessionFenced once the run is fenced. */
|
|
44
|
-
const commit = async (key, change) => {
|
|
45
|
-
try {
|
|
46
|
-
return await harness.commit(change, context);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
// The fence's refusal can come as the cause of the Harness's own error.
|
|
50
|
-
for (let at = error; at; at = at.cause)
|
|
51
|
-
if (at instanceof FencedError || at instanceof SessionFenced)
|
|
52
|
-
throw new SessionFenced(key);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const create = (key) => {
|
|
57
|
-
let made = creating.get(key);
|
|
58
|
-
if (!made) {
|
|
59
|
-
made = (async () => {
|
|
60
|
-
// The root holds the key's entry; a run's agent made it already, and one that has none gets it here.
|
|
61
|
-
await harness.root(context);
|
|
62
|
-
const id = await commit(key, async (tx) => {
|
|
63
|
-
// Read again in the commit: a key another process named meanwhile keeps its conversation.
|
|
64
|
-
for (let cursor;;) {
|
|
65
|
-
const page = await tx.scanEntries({ conversationId: ROOT_CONVERSATION_ID, order: "ascending" }, PAGE, cursor);
|
|
66
|
-
const named = page.items.find((entry) => entry.kind === SESSION_KEY && entry.data?.key === key);
|
|
67
|
-
if (named)
|
|
68
|
-
return named.data.conversation;
|
|
69
|
-
if (page.next === undefined)
|
|
70
|
-
break;
|
|
71
|
-
cursor = page.next;
|
|
72
|
-
}
|
|
73
|
-
const conversation = await tx.createConversation({ ownership: { kind: "ownerless" } });
|
|
74
|
-
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: SESSION_KEY, data: { key, conversation: conversation.id } });
|
|
75
|
-
return conversation.id;
|
|
76
|
-
});
|
|
77
|
-
known.set(key, id);
|
|
78
|
-
return id;
|
|
79
|
-
})().finally(() => creating.delete(key));
|
|
80
|
-
creating.set(key, made);
|
|
81
|
-
}
|
|
82
|
-
return made;
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
read,
|
|
86
|
-
async open(key) {
|
|
87
|
-
const holder = (holders.get(key) ?? 0) + 1;
|
|
88
|
-
holders.set(key, holder);
|
|
89
|
-
const conversation = (await find(key)) ?? (await create(key));
|
|
90
|
-
const writer = {
|
|
91
|
-
key,
|
|
92
|
-
read: () => read(key),
|
|
93
|
-
// Every record appended so far is durable when this resolves: the kernel calls it after an effect's start record
|
|
94
|
-
// and before the effect runs (drive.ts), so a lost box never runs it twice.
|
|
95
|
-
sync: () => syncNow(store, BARRIER.kernelEffectIntent),
|
|
96
|
-
async append(records) {
|
|
97
|
-
await commit(key, async (tx) => {
|
|
98
|
-
// Checked in the commit: an open that resolved before it fences this writer, whatever its own timing.
|
|
99
|
-
if (holders.get(key) !== holder)
|
|
100
|
-
throw new SessionFenced(key);
|
|
101
|
-
for (const record of records)
|
|
102
|
-
await tx.appendEntry(conversation, { kind: record.kind, data: record.data });
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
return writer;
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** The kind registry's servingRefusals (the computer package's, or --faux's), by its shape. */
|
|
2
|
-
export type ServingRefusals = (capabilities: {
|
|
3
|
-
readonly kind: string;
|
|
4
|
-
readonly groups: readonly string[];
|
|
5
|
-
}, kind: string) => string[];
|
|
6
|
-
/** The groups the computer declares, when it serves `kind`; else a refusal thrown in the registry's words. A hello that
|
|
7
|
-
* declares no groups (absent, or not a list) declares none, and one that names no machine kind names none: the registry
|
|
8
|
-
* refuses either in words, never a TypeError. */
|
|
9
|
-
export declare function servedGroups(said: {
|
|
10
|
-
readonly kind?: unknown;
|
|
11
|
-
readonly groups?: unknown;
|
|
12
|
-
}, kind: string, refusals: ServingRefusals): readonly string[];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// What a started computer says it is (its hello: machine kind and groups), read against the computer module's kind
|
|
2
|
-
// registry for the run's setting kind: the one check every path that starts a run's computer makes (the runner's Docker
|
|
3
|
-
// computer, runner/computer.ts; computerForClaim for every other provider), so a computer that does not serve the kind
|
|
4
|
-
// is refused in the registry's words, and its caller releases it, never hands it on.
|
|
5
|
-
/** The groups the computer declares, when it serves `kind`; else a refusal thrown in the registry's words. A hello that
|
|
6
|
-
* declares no groups (absent, or not a list) declares none, and one that names no machine kind names none: the registry
|
|
7
|
-
* refuses either in words, never a TypeError. */
|
|
8
|
-
export function servedGroups(said, kind, refusals) {
|
|
9
|
-
const groups = Array.isArray(said.groups) ? said.groups.filter((group) => typeof group === "string") : [];
|
|
10
|
-
const machine = typeof said.kind === "string" ? said.kind : "unknown";
|
|
11
|
-
const why = refusals({ kind: machine, groups }, kind);
|
|
12
|
-
if (why.length > 0)
|
|
13
|
-
throw new Error(`the run's computer can't serve a ${kind}: ${why.join("; ")}`);
|
|
14
|
-
return groups;
|
|
15
|
-
}
|