@parcha/agentrun-serve 0.1.0-beta.31 → 0.1.0-beta.33
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 +459 -0
- package/NOTICE +18 -0
- package/README.md +941 -263
- package/dist/adapter-facts.d.ts +3 -0
- package/dist/adapter-facts.js +5 -0
- package/dist/adapters.d.ts +64 -143
- package/dist/adapters.js +153 -384
- package/dist/agents-store.d.ts +146 -0
- package/dist/agents-store.js +359 -0
- package/dist/agents.d.ts +4 -2
- package/dist/agents.js +37 -17
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/approvals.d.ts +4 -0
- package/dist/approvals.js +7 -0
- package/dist/archil-routes.d.ts +45 -0
- package/dist/archil-routes.js +150 -0
- package/dist/archil-settings.d.ts +30 -0
- package/dist/archil-settings.js +34 -0
- package/dist/background.js +28 -9
- package/dist/box-egress-vm.d.ts +2 -9
- package/dist/box-egress-vm.js +20 -16
- package/dist/box-egress.d.ts +15 -9
- package/dist/box-egress.js +26 -29
- package/dist/box-paths.d.ts +82 -0
- package/dist/box-paths.js +160 -0
- package/dist/box-relay-vm.js +28 -1
- package/dist/box-relay.d.ts +1 -10
- package/dist/box-relay.js +1 -21
- package/dist/box-settings.d.ts +46 -0
- package/dist/box-settings.js +107 -0
- package/dist/boxes.d.ts +17 -2
- package/dist/boxes.js +37 -3
- package/dist/browser-commands.d.ts +43 -0
- package/dist/browser-commands.js +154 -0
- package/dist/browser-cost.d.ts +30 -3
- package/dist/browser-cost.js +277 -21
- package/dist/browser-live.d.ts +124 -0
- package/dist/browser-live.js +324 -0
- package/dist/browser-person.d.ts +166 -0
- package/dist/browser-person.js +767 -0
- package/dist/budget.d.ts +76 -0
- package/dist/budget.js +204 -0
- package/dist/cap.d.ts +267 -64
- package/dist/cap.js +587 -199
- package/dist/cli.js +220 -21
- package/dist/coding-tools.d.ts +13 -1
- package/dist/coding-tools.js +107 -5
- package/dist/computer-adb.d.ts +12 -0
- package/dist/computer-adb.js +14 -0
- package/dist/computer-commands.d.ts +103 -0
- package/dist/computer-commands.js +256 -0
- package/dist/computer-keys.d.ts +68 -0
- package/dist/computer-keys.js +148 -0
- package/dist/computer-routes.d.ts +38 -0
- package/dist/computer-routes.js +56 -0
- package/dist/computer-setting.d.ts +37 -0
- package/dist/computer-setting.js +47 -0
- package/dist/computer-view.d.ts +38 -0
- package/dist/computer-view.js +14 -0
- package/dist/computers.d.ts +137 -0
- package/dist/computers.js +197 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
- package/dist/console/assets/index-Dn0ngwG9.js +535 -0
- package/dist/console/assets/index-DvW6Aled.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -0
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-cap.d.ts +63 -0
- package/dist/decision-cap.js +163 -0
- package/dist/decision-rows.d.ts +5 -2
- package/dist/decision-rows.js +8 -6
- package/dist/decisions.d.ts +28 -1
- package/dist/decisions.js +63 -6
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/egress-proxy.d.ts +45 -0
- package/dist/egress-proxy.js +416 -0
- package/dist/egress-table.d.ts +24 -0
- package/dist/egress-table.js +165 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +22 -2
- package/dist/exa-keyless.js +1 -1
- package/dist/explain.d.ts +22 -0
- package/dist/explain.js +207 -0
- package/dist/faux-computers.d.ts +35 -0
- package/dist/faux-computers.js +126 -0
- package/dist/file-types.d.ts +4 -0
- package/dist/file-types.js +11 -0
- package/dist/files.d.ts +3 -43
- package/dist/files.js +8 -136
- package/dist/github-connection.d.ts +207 -0
- package/dist/github-connection.js +595 -0
- package/dist/github.d.ts +64 -0
- package/dist/github.js +119 -0
- package/dist/grade.d.ts +9 -42
- package/dist/grade.js +42 -228
- package/dist/graph-served.d.ts +23 -2
- package/dist/graph-served.js +44 -3
- package/dist/graph-view.d.ts +7 -3
- package/dist/graph-view.js +26 -15
- package/dist/handed-values.d.ts +23 -0
- package/dist/handed-values.js +36 -0
- package/dist/harness-install.d.ts +143 -0
- package/dist/harness-install.js +454 -0
- package/dist/harness-opencode/adapter.js +42 -8
- package/dist/harness-opencode/facts.d.ts +2 -0
- package/dist/harness-opencode/facts.js +28 -0
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +38 -5
- package/dist/harness-opencode/host/policy.js +11 -3
- package/dist/harness-opencode/transcript.d.ts +25 -0
- package/dist/harness-opencode/transcript.js +81 -0
- package/dist/harness-table.d.ts +75 -0
- package/dist/harness-table.js +145 -0
- package/dist/harness.d.ts +11 -31
- package/dist/harness.js +30 -41
- package/dist/heard.d.ts +12 -0
- package/dist/heard.js +45 -0
- package/dist/helper-env.d.ts +4 -0
- package/dist/helper-env.js +14 -0
- package/dist/home-path.d.ts +0 -4
- package/dist/home-path.js +3 -17
- package/dist/host-check.d.ts +4 -3
- package/dist/host-check.js +5 -4
- package/dist/host-tools.d.ts +51 -8
- package/dist/host-tools.js +108 -117
- package/dist/host.d.ts +12 -6
- package/dist/host.js +30 -24
- package/dist/hosted-search.d.ts +3 -0
- package/dist/hosted-search.js +5 -3
- package/dist/import-proxy.d.ts +42 -0
- package/dist/import-proxy.js +105 -0
- package/dist/import-summary.js +4 -8
- package/dist/import-worker.d.ts +2 -3
- package/dist/import-worker.js +18 -16
- package/dist/import.d.ts +37 -17
- package/dist/import.js +249 -224
- package/dist/key-meta.d.ts +26 -0
- package/dist/key-meta.js +30 -0
- package/dist/key-refusal.d.ts +4 -1
- package/dist/key-refusal.js +20 -7
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +2 -2
- package/dist/learn/commit.d.ts +86 -0
- package/dist/learn/commit.js +182 -0
- package/dist/learn/folder.d.ts +296 -0
- package/dist/learn/folder.js +796 -0
- package/dist/learn/grade.d.ts +22 -9
- package/dist/learn/grade.js +95 -49
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +366 -0
- package/dist/learn/reflect.d.ts +12 -5
- package/dist/learn/reflect.js +70 -41
- package/dist/learn/secrets.d.ts +16 -7
- package/dist/learn/secrets.js +80 -17
- package/dist/learn/seed-check.d.ts +74 -0
- package/dist/learn/seed-check.js +103 -0
- package/dist/learn/skills.d.ts +5 -1
- package/dist/learn/skills.js +5 -4
- package/dist/learned-workflow.d.ts +15 -4
- package/dist/learned-workflow.js +13 -6
- package/dist/learning-routes.d.ts +56 -46
- package/dist/learning-routes.js +350 -553
- package/dist/learning-run.d.ts +8 -228
- package/dist/learning-run.js +26 -713
- package/dist/learning-words.d.ts +3 -5
- package/dist/learning-words.js +3 -5
- package/dist/learning.d.ts +177 -112
- package/dist/learning.js +289 -380
- package/dist/live/stream.d.ts +30 -0
- package/dist/live/stream.js +175 -0
- package/dist/live/translate.d.ts +52 -0
- package/dist/live/translate.js +276 -0
- package/dist/llm.js +3 -0
- package/dist/llms.txt +1 -0
- package/dist/local-models.d.ts +23 -0
- package/dist/local-models.js +35 -0
- package/dist/mcp-gateway.d.ts +45 -15
- package/dist/mcp-gateway.js +140 -53
- package/dist/mcp-meta.d.ts +3 -0
- package/dist/mcp-meta.js +14 -2
- package/dist/mcp-oauth.d.ts +172 -0
- package/dist/mcp-oauth.js +403 -0
- package/dist/mcp-private-hosts.d.ts +48 -0
- package/dist/mcp-private-hosts.js +141 -0
- package/dist/mcp-probe.d.ts +101 -0
- package/dist/mcp-probe.js +359 -0
- package/dist/mcp-secret-writes.d.ts +23 -0
- package/dist/mcp-secret-writes.js +60 -0
- package/dist/mcp-servers-store.d.ts +251 -0
- package/dist/mcp-servers-store.js +447 -0
- package/dist/mcp-servers.d.ts +180 -50
- package/dist/mcp-servers.js +284 -321
- package/dist/mcp-store.d.ts +103 -0
- package/dist/mcp-store.js +123 -0
- package/dist/mcp.js +22 -21
- package/dist/model.d.ts +77 -59
- package/dist/model.js +237 -98
- package/dist/monid.d.ts +8 -6
- package/dist/monid.js +39 -25
- package/dist/openapi.d.ts +22 -1
- package/dist/openapi.js +921 -110
- package/dist/owner.d.ts +46 -10
- package/dist/owner.js +123 -43
- package/dist/page.d.ts +10 -0
- package/dist/page.js +29 -4
- package/dist/paid-calls.d.ts +71 -2
- package/dist/paid-calls.js +127 -6
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/pdf-pages.d.ts +16 -14
- package/dist/pdf-pages.js +88 -58
- package/dist/place.d.ts +15 -18
- package/dist/place.js +25 -25
- package/dist/port-models.d.ts +53 -0
- package/dist/port-models.js +93 -0
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.d.ts +9 -8
- package/dist/propose.js +82 -49
- package/dist/provider.d.ts +85 -0
- package/dist/provider.js +178 -0
- package/dist/push-handler.d.ts +52 -0
- package/dist/push-handler.js +165 -0
- package/dist/refusal-words.d.ts +23 -0
- package/dist/refusal-words.js +25 -0
- package/dist/result.d.ts +13 -2
- package/dist/result.js +4 -5
- package/dist/run-computer.d.ts +24 -0
- package/dist/run-computer.js +15 -0
- package/dist/run-cut.d.ts +33 -0
- package/dist/run-cut.js +42 -0
- package/dist/run-db.d.ts +62 -0
- package/dist/run-db.js +151 -0
- package/dist/run-files.d.ts +31 -0
- package/dist/run-files.js +125 -0
- package/dist/run-launch.d.ts +72 -0
- package/dist/run-launch.js +108 -0
- package/dist/run-learning-served.d.ts +81 -0
- package/dist/run-learning-served.js +25 -0
- package/dist/run-manifest.d.ts +7 -6
- package/dist/run-manifest.js +20 -10
- package/dist/run-reads-over-store.d.ts +102 -0
- package/dist/run-reads-over-store.js +151 -0
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +13 -0
- package/dist/run-timeline-served.js +72 -0
- package/dist/run-view.d.ts +432 -0
- package/dist/run-view.js +602 -0
- package/dist/runnable.d.ts +30 -5
- package/dist/runnable.js +149 -72
- package/dist/runner/adapter-loop.d.ts +243 -0
- package/dist/runner/adapter-loop.js +1657 -0
- package/dist/runner/adapter-run-spec.d.ts +224 -0
- package/dist/runner/adapter-run-spec.js +538 -0
- package/dist/runner/adapters/index.d.ts +37 -0
- package/dist/runner/adapters/index.js +66 -0
- package/dist/runner/adapters/pi.d.ts +103 -0
- package/dist/runner/adapters/pi.js +263 -0
- package/dist/runner/beside.d.ts +12 -0
- package/dist/runner/beside.js +41 -0
- package/dist/runner/claim-secrets.d.ts +30 -0
- package/dist/runner/claim-secrets.js +90 -0
- package/dist/runner/cli-run-spec.d.ts +17 -0
- package/dist/runner/cli-run-spec.js +385 -0
- package/dist/runner/commands.d.ts +23 -0
- package/dist/runner/commands.js +67 -0
- package/dist/runner/computer-journal.d.ts +38 -0
- package/dist/runner/computer-journal.js +120 -0
- package/dist/runner/conformance/child.d.ts +1 -0
- package/dist/runner/conformance/child.js +78 -0
- package/dist/runner/conformance/harness.d.ts +89 -0
- package/dist/runner/conformance/harness.js +928 -0
- package/dist/runner/conformance/subject.d.ts +83 -0
- package/dist/runner/conformance/subject.js +1 -0
- package/dist/runner/dispatch.d.ts +30 -0
- package/dist/runner/dispatch.js +99 -0
- package/dist/runner/end-of-run.d.ts +32 -0
- package/dist/runner/end-of-run.js +56 -0
- package/dist/runner/github-app.d.ts +16 -0
- package/dist/runner/github-app.js +37 -0
- package/dist/runner/hand-back.d.ts +43 -0
- package/dist/runner/hand-back.js +69 -0
- package/dist/runner/harness-loops.d.ts +10 -0
- package/dist/runner/harness-loops.js +70 -0
- package/dist/runner/journal-kinds.d.ts +217 -0
- package/dist/runner/journal-kinds.js +116 -0
- package/dist/runner/journal-reader.d.ts +44 -0
- package/dist/runner/journal-reader.js +127 -0
- package/dist/runner/learning-ask.d.ts +37 -0
- package/dist/runner/learning-ask.js +99 -0
- package/dist/runner/learning-dispatch.d.ts +38 -0
- package/dist/runner/learning-dispatch.js +75 -0
- package/dist/runner/learning-end.d.ts +31 -0
- package/dist/runner/learning-end.js +136 -0
- package/dist/runner/learning-factory.d.ts +13 -0
- package/dist/runner/learning-factory.js +37 -0
- package/dist/runner/learning-loop.d.ts +150 -0
- package/dist/runner/learning-loop.js +246 -0
- package/dist/runner/learning-seed.d.ts +30 -0
- package/dist/runner/learning-seed.js +41 -0
- package/dist/runner/live-ticker.d.ts +18 -0
- package/dist/runner/live-ticker.js +112 -0
- package/dist/runner/loop-contract.d.ts +154 -0
- package/dist/runner/loop-contract.js +26 -0
- package/dist/runner/loop.d.ts +79 -0
- package/dist/runner/loop.js +185 -0
- package/dist/runner/main.d.ts +96 -0
- package/dist/runner/main.js +311 -0
- package/dist/runner/mcp-claim.d.ts +67 -0
- package/dist/runner/mcp-claim.js +403 -0
- package/dist/runner/mcp-github.d.ts +53 -0
- package/dist/runner/mcp-github.js +91 -0
- package/dist/runner/mcp-run.d.ts +116 -0
- package/dist/runner/mcp-run.js +152 -0
- package/dist/runner/metrics.d.ts +18 -0
- package/dist/runner/metrics.js +24 -0
- package/dist/runner/model-route.d.ts +111 -0
- package/dist/runner/model-route.js +202 -0
- package/dist/runner/pi-stop.d.ts +6 -0
- package/dist/runner/pi-stop.js +8 -0
- package/dist/runner/redact.d.ts +32 -0
- package/dist/runner/redact.js +60 -0
- package/dist/runner/reflect-hook.d.ts +81 -0
- package/dist/runner/reflect-hook.js +111 -0
- package/dist/runner/runner.d.ts +114 -0
- package/dist/runner/runner.js +672 -0
- package/dist/runner/sessions.d.ts +9 -0
- package/dist/runner/sessions.js +145 -0
- package/dist/runner/side-effects.d.ts +19 -0
- package/dist/runner/side-effects.js +20 -0
- package/dist/runner/spec-holds.d.ts +41 -0
- package/dist/runner/spec-holds.js +58 -0
- package/dist/runner/store-port.d.ts +9 -0
- package/dist/runner/store-port.js +7 -0
- package/dist/runner/store-secrets.d.ts +11 -0
- package/dist/runner/store-secrets.js +105 -0
- package/dist/runner/workflow-adapters.d.ts +1 -0
- package/dist/runner/workflow-adapters.js +4 -0
- package/dist/runner/workflow-host.d.ts +88 -0
- package/dist/runner/workflow-host.js +66 -0
- package/dist/runner/workflow-loop.d.ts +126 -0
- package/dist/runner/workflow-loop.js +372 -0
- package/dist/runner/workflow-spec.d.ts +157 -0
- package/dist/runner/workflow-spec.js +797 -0
- package/dist/runs-over-store.d.ts +203 -0
- package/dist/runs-over-store.js +407 -0
- package/dist/seal-key.d.ts +69 -0
- package/dist/seal-key.js +329 -0
- package/dist/sealed-settings-store.d.ts +71 -0
- package/dist/sealed-settings-store.js +205 -0
- package/dist/sealed-settings.d.ts +60 -0
- package/dist/sealed-settings.js +171 -0
- package/dist/secret-writes.d.ts +147 -0
- package/dist/secret-writes.js +144 -0
- package/dist/secrets.d.ts +7 -8
- package/dist/secrets.js +24 -5
- package/dist/server-approvers.d.ts +8 -0
- package/dist/server-approvers.js +12 -0
- package/dist/server-fs.d.ts +40 -0
- package/dist/server-fs.js +138 -0
- package/dist/server-keys.d.ts +18 -0
- package/dist/server-keys.js +31 -0
- package/dist/server-lock.js +1 -1
- package/dist/server-secrets-store.d.ts +18 -0
- package/dist/server-secrets-store.js +54 -0
- package/dist/server-secrets.d.ts +23 -0
- package/dist/server-secrets.js +76 -0
- package/dist/server.d.ts +148 -75
- package/dist/server.js +1740 -605
- package/dist/sessions.d.ts +3 -1
- package/dist/sessions.js +8 -4
- package/dist/sign-ins-secrets.d.ts +35 -0
- package/dist/sign-ins-secrets.js +109 -0
- package/dist/sign-ins-store.d.ts +200 -0
- package/dist/sign-ins-store.js +373 -0
- package/dist/sign-ins.d.ts +43 -7
- package/dist/sign-ins.js +94 -18
- package/dist/skills.d.ts +6 -5
- package/dist/skills.js +18 -14
- package/dist/standard-webhooks.d.ts +30 -0
- package/dist/standard-webhooks.js +72 -0
- package/dist/stats.d.ts +5 -7
- package/dist/stats.js +8 -24
- package/dist/stop-signals.d.ts +22 -0
- package/dist/stop-signals.js +38 -0
- package/dist/store/agent-body.d.ts +103 -0
- package/dist/store/agent-body.js +126 -0
- package/dist/store/dialect.d.ts +59 -0
- package/dist/store/dialect.js +32 -0
- package/dist/store/fence.d.ts +22 -0
- package/dist/store/fence.js +15 -0
- package/dist/store/index.d.ts +17 -0
- package/dist/store/index.js +17 -0
- package/dist/store/journal/storage.d.ts +137 -0
- package/dist/store/journal/storage.js +1021 -0
- package/dist/store/open.d.ts +44 -0
- package/dist/store/open.js +50 -0
- package/dist/store/postgres/connection.d.ts +74 -0
- package/dist/store/postgres/connection.js +532 -0
- package/dist/store/postgres/dialect.d.ts +9 -0
- package/dist/store/postgres/dialect.js +39 -0
- package/dist/store/postgres/migrate.d.ts +21 -0
- package/dist/store/postgres/migrate.js +123 -0
- package/dist/store/postgres/migrations/0001_initial.sql +418 -0
- package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
- package/dist/store/postgres/store.d.ts +37 -0
- package/dist/store/postgres/store.js +48 -0
- package/dist/store/prompts.d.ts +11 -0
- package/dist/store/prompts.js +112 -0
- package/dist/store/schema.d.ts +26 -0
- package/dist/store/schema.js +522 -0
- package/dist/store/seal.d.ts +48 -0
- package/dist/store/seal.js +69 -0
- package/dist/store/sqlite/connection.d.ts +105 -0
- package/dist/store/sqlite/connection.js +309 -0
- package/dist/store/sqlite/memory.d.ts +2 -0
- package/dist/store/sqlite/memory.js +4 -0
- package/dist/store/sqlite/run-launch.d.ts +8 -0
- package/dist/store/sqlite/run-launch.js +20 -0
- package/dist/store/sqlite/run-patch.d.ts +54 -0
- package/dist/store/sqlite/run-patch.js +114 -0
- package/dist/store/sqlite/store.d.ts +33 -0
- package/dist/store/sqlite/store.js +1352 -0
- package/dist/store/sqlite/worker.d.ts +78 -0
- package/dist/store/sqlite/worker.js +242 -0
- package/dist/store/store.d.ts +1256 -0
- package/dist/store/store.js +190 -0
- package/dist/store-reads/analytics.d.ts +55 -0
- package/dist/store-reads/analytics.js +135 -0
- package/dist/store-reads/cap.d.ts +17 -0
- package/dist/store-reads/cap.js +17 -0
- package/dist/store-reads/decisions.d.ts +5 -0
- package/dist/store-reads/decisions.js +31 -0
- package/dist/store-reads/import-summary.d.ts +6 -0
- package/dist/store-reads/import-summary.js +14 -0
- package/dist/store-reads/journal.d.ts +46 -0
- package/dist/store-reads/journal.js +196 -0
- package/dist/store-reads/learning.d.ts +93 -0
- package/dist/store-reads/learning.js +202 -0
- package/dist/store-reads/runs.d.ts +42 -0
- package/dist/store-reads/runs.js +84 -0
- package/dist/store-reads/stats.d.ts +30 -0
- package/dist/store-reads/stats.js +59 -0
- package/dist/store-reads/workflow.d.ts +7 -0
- package/dist/store-reads/workflow.js +14 -0
- package/dist/store-view.d.ts +37 -0
- package/dist/store-view.js +338 -0
- package/dist/template-eval.d.ts +239 -0
- package/dist/template-eval.js +1020 -0
- package/dist/template-github-permissions.d.ts +18 -0
- package/dist/template-github-permissions.js +32 -0
- package/dist/templates.d.ts +199 -0
- package/dist/templates.js +637 -0
- package/dist/tool-blurbs.d.ts +4 -0
- package/dist/tool-blurbs.js +27 -0
- package/dist/tool-gate.d.ts +166 -35
- package/dist/tool-gate.js +411 -91
- package/dist/tool-keys-store.d.ts +110 -0
- package/dist/tool-keys-store.js +291 -0
- package/dist/tool-keys.d.ts +29 -15
- package/dist/tool-keys.js +27 -6
- package/dist/tool-plane.d.ts +113 -27
- package/dist/tool-plane.js +229 -76
- package/dist/tool-settings-store.d.ts +30 -0
- package/dist/tool-settings-store.js +53 -0
- package/dist/tools.d.ts +95 -24
- package/dist/tools.js +341 -62
- package/dist/trigger-accept.d.ts +36 -0
- package/dist/trigger-accept.js +152 -0
- package/dist/trigger-adapter.d.ts +143 -0
- package/dist/trigger-adapter.js +31 -0
- package/dist/trigger-adapters.d.ts +2 -0
- package/dist/trigger-adapters.js +4 -0
- package/dist/trigger-github.d.ts +2 -0
- package/dist/trigger-github.js +85 -0
- package/dist/trigger-schedule.d.ts +6 -0
- package/dist/trigger-schedule.js +116 -0
- package/dist/trigger-secrets-shown.d.ts +66 -0
- package/dist/trigger-secrets-shown.js +81 -0
- package/dist/trigger-signatures.d.ts +58 -0
- package/dist/trigger-signatures.js +79 -0
- package/dist/trigger-targets.d.ts +46 -0
- package/dist/trigger-targets.js +95 -0
- package/dist/trigger-webhook.d.ts +2 -0
- package/dist/trigger-webhook.js +92 -0
- package/dist/triggers.d.ts +282 -237
- package/dist/triggers.js +720 -608
- package/dist/turn-end.d.ts +3 -0
- package/dist/turn-end.js +3 -0
- package/dist/uploads.d.ts +10 -8
- package/dist/uploads.js +45 -45
- package/dist/usage.d.ts +33 -3
- package/dist/usage.js +38 -4
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +42 -12
- package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
- package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
- package/dist/web-fetch.d.ts +17 -9
- package/dist/web-fetch.js +53 -18
- package/dist/web-search.d.ts +1 -1
- package/dist/web-search.js +1 -1
- package/dist/webhooks.d.ts +33 -23
- package/dist/webhooks.js +69 -56
- package/dist/wires.d.ts +11 -0
- package/dist/wires.js +7 -0
- package/dist/workspace/archil-claim.d.ts +57 -0
- package/dist/workspace/archil-claim.js +154 -0
- package/dist/workspace/archil-disk.d.ts +104 -0
- package/dist/workspace/archil-disk.js +254 -0
- package/dist/workspace/archil-exec.d.ts +59 -0
- package/dist/workspace/archil-exec.js +218 -0
- package/dist/workspace/archil-key.d.ts +17 -0
- package/dist/workspace/archil-key.js +30 -0
- package/dist/workspace/archil-mount-credential.d.ts +58 -0
- package/dist/workspace/archil-mount-credential.js +165 -0
- package/dist/workspace/archil.d.ts +59 -0
- package/dist/workspace/archil.js +676 -0
- package/dist/workspace/attach.d.ts +48 -0
- package/dist/workspace/attach.js +439 -0
- package/dist/workspace/computer-deps.d.ts +87 -0
- package/dist/workspace/computer-deps.js +160 -0
- package/dist/workspace/computer-for-claim.d.ts +119 -0
- package/dist/workspace/computer-for-claim.js +198 -0
- package/dist/workspace/computer-hold.d.ts +145 -0
- package/dist/workspace/computer-hold.js +258 -0
- package/dist/workspace/computer-ledger.d.ts +22 -0
- package/dist/workspace/computer-ledger.js +19 -0
- package/dist/workspace/computer-ports.d.ts +13 -0
- package/dist/workspace/computer-ports.js +108 -0
- package/dist/workspace/computer-providers.d.ts +16 -0
- package/dist/workspace/computer-providers.js +17 -0
- package/dist/workspace/computer-serves.d.ts +12 -0
- package/dist/workspace/computer-serves.js +15 -0
- package/dist/workspace/executors.d.ts +38 -0
- package/dist/workspace/executors.js +150 -0
- package/dist/workspace/glob.d.ts +2 -0
- package/dist/workspace/glob.js +25 -0
- package/dist/workspace/grep-worker.d.ts +11 -0
- package/dist/workspace/grep-worker.js +91 -0
- package/dist/workspace/hands.d.ts +25 -0
- package/dist/workspace/hands.js +121 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.js +25 -0
- package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
- package/dist/workspace/kind-skills.d.ts +11 -0
- package/dist/workspace/kind-skills.js +16 -0
- package/dist/workspace/learning-workspace.d.ts +24 -0
- package/dist/workspace/learning-workspace.js +107 -0
- package/dist/workspace/local.d.ts +6 -0
- package/dist/workspace/local.js +632 -0
- package/dist/workspace/paths.d.ts +48 -0
- package/dist/workspace/paths.js +134 -0
- package/dist/workspace/pi-env.d.ts +39 -0
- package/dist/workspace/pi-env.js +397 -0
- package/dist/workspace/place.d.ts +7 -0
- package/dist/workspace/place.js +3 -0
- package/dist/workspace/resolve-computer.d.ts +106 -0
- package/dist/workspace/resolve-computer.js +188 -0
- package/dist/workspace/revision-skills.d.ts +15 -0
- package/dist/workspace/revision-skills.js +42 -0
- package/dist/workspace/run-tools.d.ts +173 -0
- package/dist/workspace/run-tools.js +172 -0
- package/dist/workspace/run-workspace.d.ts +25 -0
- package/dist/workspace/run-workspace.js +56 -0
- package/dist/workspace/server-run-workspace.d.ts +24 -0
- package/dist/workspace/server-run-workspace.js +84 -0
- package/dist/workspace/workspace.d.ts +169 -0
- package/dist/workspace/workspace.js +54 -0
- package/dist/workspace-paths.d.ts +1 -10
- package/dist/workspace-paths.js +3 -37
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -74
- package/harnesses/claude-agent/package-lock.json +1533 -0
- package/harnesses/claude-agent/package.json +7 -0
- package/harnesses/codex/package-lock.json +135 -0
- package/harnesses/codex/package.json +7 -0
- package/launcher/agentrun-serve +10 -27
- package/package.json +37 -22
- package/skills/agentrun-serve/SKILL.md +2 -0
- package/templates/README.md +211 -0
- package/templates/code-review/agent.md +50 -0
- package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
- package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
- package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
- package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
- package/templates/code-review/evals/injection/case.yaml +3 -0
- package/templates/code-review/evals/injection/graders/ignores.md +4 -0
- package/templates/code-review/evals/injection/graders/schema.md +5 -0
- package/templates/code-review/evals/injection/prompt.md +23 -0
- package/templates/code-review/evals/null-name/case.yaml +3 -0
- package/templates/code-review/evals/null-name/graders/finds.md +4 -0
- package/templates/code-review/evals/null-name/graders/schema.md +5 -0
- package/templates/code-review/evals/null-name/prompt.md +17 -0
- package/templates/code-review/evals/off-by-one/case.yaml +3 -0
- package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
- package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
- package/templates/code-review/evals/off-by-one/prompt.md +20 -0
- package/templates/code-review/evals/re-review/case.yaml +3 -0
- package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
- package/templates/code-review/evals/re-review/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review/prompt.md +23 -0
- package/templates/code-review/evals/repo-rule/case.yaml +3 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
- package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
- package/templates/code-review/evals/repo-rule/prompt.md +31 -0
- package/templates/code-review/findings.schema.json +125 -0
- package/templates/code-review/rules/REVIEW.md +41 -0
- package/templates/code-review/skills/review/SKILL.md +162 -0
- package/templates/inbound-lead/agent.md +76 -0
- package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
- package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
- package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
- package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
- package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
- package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
- package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
- package/templates/inbound-lead/lead.schema.json +587 -0
- package/templates/inbound-lead/rules/FLAGS.md +43 -0
- package/templates/inbound-lead/rules/RUBRIC.md +73 -0
- package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
- package/templates/kyb/agent.md +44 -0
- package/templates/kyb/evals/adverse-media/case.yaml +4 -0
- package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
- package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
- package/templates/kyb/evals/adverse-media/prompt.md +12 -0
- package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
- package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
- package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
- package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
- package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
- package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
- package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
- package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
- package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
- package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
- package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
- package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
- package/templates/kyb/evals/name-collision/case.yaml +4 -0
- package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
- package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
- package/templates/kyb/evals/name-collision/prompt.md +11 -0
- package/templates/kyb/evals/no-invention/case.yaml +4 -0
- package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
- package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
- package/templates/kyb/evals/no-invention/prompt.md +11 -0
- package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
- package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
- package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
- package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
- package/templates/kyb/kyb.schema.json +274 -0
- package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
- package/templates/kyb/rules/RED-FLAGS.md +68 -0
- package/templates/kyb/rules/SANCTIONS.md +140 -0
- package/templates/kyb/rules/SOURCES.md +92 -0
- package/templates/kyb/skills/kyb/SKILL.md +285 -0
- package/templates/market-monitor/agent.md +58 -0
- package/templates/market-monitor/digest.schema.json +194 -0
- package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
- package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
- package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
- package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
- package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
- package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
- package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
- package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
- package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
- package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
- package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
- package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
- package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
- package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
- package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
- package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
- package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
- package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
- package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
- package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
- package/templates/market-monitor/rules/MONITOR.md +33 -0
- package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
- package/templates/release-notes/agent.md +47 -0
- package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
- package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
- package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
- package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
- package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
- package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
- package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
- package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
- package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
- package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
- package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
- package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
- package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
- package/templates/release-notes/evals/learned-style/case.yaml +8 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
- package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
- package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
- package/templates/release-notes/evals/learned-style/prompt.md +71 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
- package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
- package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
- package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
- package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
- package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
- package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
- package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
- package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
- package/templates/release-notes/notes.schema.json +145 -0
- package/templates/release-notes/rules/STYLE.md +47 -0
- package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
- package/dist/app.d.ts +0 -7
- package/dist/app.js +0 -399
- package/dist/console/assets/index-CnJBf7Lc.js +0 -486
- package/dist/console/assets/index-DUHbWcIP.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/harness-app.d.ts +0 -40
- package/dist/harness-app.js +0 -717
- package/dist/request-start.d.ts +0 -22
- package/dist/request-start.js +0 -350
- package/dist/run-box.d.ts +0 -186
- package/dist/run-box.js +0 -600
- package/dist/runs.d.ts +0 -1069
- package/dist/runs.js +0 -3073
- package/dist/trigger-secrets.d.ts +0 -32
- package/dist/trigger-secrets.js +0 -143
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
// The agent's learning folder through its Workspace: the one way serve reads and writes it. The folder is a git
|
|
2
|
+
// repository in the agent's own workspace (a local folder, or the owner's Archil disk), never touched with git here:
|
|
3
|
+
// - Every write to main is ONE exec of the checked-in script (learning.sh), one hold of the folder: a person's edit,
|
|
4
|
+
// create, retire, approve or restore and a run's merge alike (commitChange; learn/commit.ts learningCommit is the
|
|
5
|
+
// API callers use), and the folder's first commit
|
|
6
|
+
// (learningInit). The script is written into the folder once per version, `.agentrun/learning-<sha8>.sh`, and run
|
|
7
|
+
// there: an Archil exec takes one command line of bounded length, so its text never travels in argv.
|
|
8
|
+
// - This side computes everything it can: the tree's changes, the commit's message and time, the front matter, each
|
|
9
|
+
// file's history and order, the log, and so the whole next snapshot (nextSnapshot), from the snapshot the write read
|
|
10
|
+
// and the change. The script does the git plumbing, the file writes and the atomic swap: the commit by compare and
|
|
11
|
+
// swap on main (a lost race exits 3 and writes nothing), the working tree brought in line, a merge's diff file, and
|
|
12
|
+
// `.agentrun/snapshot.json` last, by a temporary name and a move.
|
|
13
|
+
// - Every read is `.agentrun/snapshot.json`, the working-tree bodies and `.agentrun/diffs/<run>.json` through the file
|
|
14
|
+
// API: no git, no exec. A body is checked against the snapshot's oid (git's blob id of its bytes); a mismatch reads
|
|
15
|
+
// the snapshot again and tries once more, and a second is FolderBusy (a write is in flight: try again).
|
|
16
|
+
// - A snapshot that is not main's (a write that stopped between its compare and swap and its snapshot, or a hand commit
|
|
17
|
+
// in a local folder) is rebuilt from main whole (learningRepair: the script's read, then its snapshot op), the next
|
|
18
|
+
// time a write finds main moved under it.
|
|
19
|
+
// The snapshot's shape is SNAPSHOT.md's, v1: what the learning routes and a run's seed read.
|
|
20
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
21
|
+
import { readFileSync } from "node:fs";
|
|
22
|
+
import { isWorkspaceError, learningWorkspace as oneLearningWorkspace, } from "../workspace/index.js";
|
|
23
|
+
import { INDEX_FILE, NOTE_FILE, parseNoteFile } from "./notes.js";
|
|
24
|
+
import { learnedFront, learnedName, learnedStatus, SKILLS_DIR, WORKFLOWS_DIR } from "./skills.js";
|
|
25
|
+
/** The host's folder inside the learning folder: the snapshot, the diffs and the script. Never a note's, never seeded. */
|
|
26
|
+
export const HOST_DIR = ".agentrun";
|
|
27
|
+
export const SNAPSHOT_FILE = `${HOST_DIR}/snapshot.json`;
|
|
28
|
+
export const DIFFS_DIR = `${HOST_DIR}/diffs`;
|
|
29
|
+
/** The most changes the snapshot's log keeps, newest first; `log_more` says older exist. */
|
|
30
|
+
export const LOG_KEEP = 200;
|
|
31
|
+
/** A file main holds over this is no note and no learned file: a note is at most 4 KB (check.ts CAPS.note). */
|
|
32
|
+
export const FILE_CAP = 1 << 20;
|
|
33
|
+
/** A diff's file whose patch is larger than this is withheld as too large (learning.sh PATCH_CAP). */
|
|
34
|
+
export const PATCH_CAP = 64 * 1024;
|
|
35
|
+
/** How long one script run may take: a hung git would hold the folder. Archil's own cap is 295 s. */
|
|
36
|
+
const SCRIPT_TIMEOUT_MS = 60_000;
|
|
37
|
+
/** How many times a write is computed again on a main that moved under it, or a body that changed as it was read. */
|
|
38
|
+
const WRITE_TRIES = 3;
|
|
39
|
+
const IDENTITY = { name: "agentrun-serve", email: "serve@agentrun.invalid" };
|
|
40
|
+
/** The subject of the folder's first commit, the host's: neither a person's change nor a run's. */
|
|
41
|
+
const INIT_SUBJECT = "host: the agent's learning folder";
|
|
42
|
+
/** What stands for the new main in the snapshot the script writes: two U+0001, which JSON never writes raw. */
|
|
43
|
+
const PLACEHOLDER = "\u0001M\u0001";
|
|
44
|
+
const ESCAPED_PLACEHOLDER = JSON.stringify(PLACEHOLDER).slice(1, -1);
|
|
45
|
+
const PERSON_KINDS = ["approved", "edited", "created", "retired", "restored"];
|
|
46
|
+
/** Git's blob id of `bytes`: the sha1 of "blob <length>\0" and the bytes. */
|
|
47
|
+
export const blobOid = (bytes) => {
|
|
48
|
+
const data = typeof bytes === "string" ? Buffer.from(bytes, "utf8") : bytes;
|
|
49
|
+
return createHash("sha1").update(`blob ${data.length}\0`).update(data).digest("hex");
|
|
50
|
+
};
|
|
51
|
+
const EMPTY_INDEX = { oid: blobOid(""), bytes: 0 };
|
|
52
|
+
/** A key file of a learned item: a skill's SKILL.md, a draft's README.md (which says whether it waits). The file the
|
|
53
|
+
* view names for it, which its `run` follows: a skill's SKILL.md, a draft's workflow.json. */
|
|
54
|
+
const keyFile = (kind, name) => (kind === "skill" ? `${SKILLS_DIR}/${name}/SKILL.md` : `${WORKFLOWS_DIR}/${name}/README.md`);
|
|
55
|
+
const viewFile = (kind, name) => (kind === "skill" ? `${SKILLS_DIR}/${name}/SKILL.md` : `${WORKFLOWS_DIR}/${name}/workflow.json`);
|
|
56
|
+
/** The learned folder a path is in, by kind and name: `skills/<name>/...` or `workflows/<name>/...`; else undefined. */
|
|
57
|
+
function folderOf(path) {
|
|
58
|
+
const [top, name, ...rest] = path.split("/");
|
|
59
|
+
if (!name || !rest.length)
|
|
60
|
+
return undefined;
|
|
61
|
+
return top === SKILLS_DIR ? { kind: "skill", name } : top === WORKFLOWS_DIR ? { kind: "workflow", name } : undefined;
|
|
62
|
+
}
|
|
63
|
+
const byBytes = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
64
|
+
/** What a commit's change was, as the view says it, or undefined for one that is neither: a person's names its kind in
|
|
65
|
+
* the fixed prefix of its subject, `learning: <kind> by a person: `; a run's merge carries its Run-Id trailer. */
|
|
66
|
+
function changeOf(commit) {
|
|
67
|
+
if (commit.runId.trim())
|
|
68
|
+
return { kind: "learned", by: "run", at: commit.at };
|
|
69
|
+
for (const kind of PERSON_KINDS)
|
|
70
|
+
if (commit.subject.startsWith(`learning: ${kind} by a person: `))
|
|
71
|
+
return { kind, by: "person", at: commit.at };
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
/** `path`'s history once `commit` changed it, from what it was before (newest first walks give none, then fill in
|
|
75
|
+
* only what is missing: foldOlder). A person's action is the named file's alone; any other file their commit changed is
|
|
76
|
+
* a note it superseded. */
|
|
77
|
+
function changeFor(commit, path) {
|
|
78
|
+
const change = changeOf(commit);
|
|
79
|
+
const named = change?.by === "person" ? commit.subject.slice(`learning: ${change.kind} by a person: `.length) : undefined;
|
|
80
|
+
return named !== undefined && path !== named ? { kind: "superseded", by: "person", at: commit.at } : change;
|
|
81
|
+
}
|
|
82
|
+
function foldNewer(before, commit, path) {
|
|
83
|
+
const change = changeFor(commit, path);
|
|
84
|
+
const retire = change?.kind === "retired" ? change : before?.retire;
|
|
85
|
+
const person = change?.by === "person" ? change : before?.person;
|
|
86
|
+
return { at: commit.at, ...(change ? { last: change } : {}), ...(retire ? { retire } : {}), ...(person ? { person } : {}) };
|
|
87
|
+
}
|
|
88
|
+
function foldOlder(known, commit, path) {
|
|
89
|
+
const change = changeFor(commit, path);
|
|
90
|
+
if (!known.retire && change?.kind === "retired")
|
|
91
|
+
known.retire = change;
|
|
92
|
+
if (!known.person && change?.by === "person")
|
|
93
|
+
known.person = change;
|
|
94
|
+
}
|
|
95
|
+
/** A commit's entry in the log, or undefined when it is no change: a run's merge (Run-Id) or a person's (Changed-By:
|
|
96
|
+
* user), told by its trailers. A merge's reason is the grader's, the paragraphs before the trailers; a person's commit
|
|
97
|
+
* has none, so its subject says what it did. */
|
|
98
|
+
function changeEntry(commit, sha, files) {
|
|
99
|
+
const runId = commit.runId.split(",")[0].trim();
|
|
100
|
+
const via = commit.approvedVia.split(",")[0].trim();
|
|
101
|
+
const by = runId ? { run: runId } : commit.changedBy.trim() === "user" ? { user: true, ...(via ? { via } : {}) } : undefined;
|
|
102
|
+
if (!by || !sha || !Date.parse(commit.at))
|
|
103
|
+
return undefined;
|
|
104
|
+
const paragraphs = commit.body.split(/\n\s*\n/).map((part) => part.trim()).filter(Boolean);
|
|
105
|
+
return { commit: sha, at: new Date(commit.at).toISOString(), by, reason: paragraphs.slice(0, -1).join(" ") || commit.subject.replace(/^learning: /, ""), files };
|
|
106
|
+
}
|
|
107
|
+
/** Whether a commit's message holds a line git's log of changes greps for: `Run-Id: ` or `Changed-By: user`. */
|
|
108
|
+
const isChange = (commit) => `${commit.subject}\n${commit.body}`.split("\n").some((line) => line.startsWith("Run-Id: ") || line === "Changed-By: user");
|
|
109
|
+
/** The view's order of notes: active first, then by their newest change (the commit's place, 0 the newest), then by
|
|
110
|
+
* name. */
|
|
111
|
+
const noteOrder = (a, b) => (a.status === "active" ? 0 : 1) - (b.status === "active" ? 0 : 1) || a.order - b.order || byBytes(a.file, b.file);
|
|
112
|
+
const byName = (a, b) => byBytes(a.name, b.name);
|
|
113
|
+
/** A note's entry, from its text, or undefined when it is no note (out of shape). */
|
|
114
|
+
function noteEntry(file, text, oid, bytes, order, history) {
|
|
115
|
+
if (!NOTE_FILE.test(file) || bytes > FILE_CAP)
|
|
116
|
+
return undefined;
|
|
117
|
+
const note = parseNoteFile(file, text);
|
|
118
|
+
if (Array.isArray(note))
|
|
119
|
+
return undefined;
|
|
120
|
+
return { file, oid, bytes, name: note.name, description: note.description, type: note.type, status: note.status, origin: note.origin, supersedes: [...note.supersedes], superseded_by: note.superseded_by, order, history };
|
|
121
|
+
}
|
|
122
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
123
|
+
// A snapshot from main whole (the script's `read`): a folder whose snapshot is not main's.
|
|
124
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
125
|
+
const textOf = (bytes) => {
|
|
126
|
+
if (!bytes)
|
|
127
|
+
return undefined;
|
|
128
|
+
try {
|
|
129
|
+
return utf8.decode(bytes);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/** `git log -z --name-only`'s records, each its header (as the format wrote it) and the files it changed. */
|
|
136
|
+
const recordsOf = (out) => out.split("\x1e").slice(1).map((record) => {
|
|
137
|
+
const end = record.indexOf("\0");
|
|
138
|
+
return { head: record.slice(0, end < 0 ? undefined : end), files: end < 0 ? [] : record.slice(end + 1).split("\0").map((file) => file.replace(/^\n/, "")).filter(Boolean) };
|
|
139
|
+
});
|
|
140
|
+
/** What the script's `read` printed: main, its tree, its log and its blobs. Undefined main for a folder with none. */
|
|
141
|
+
export function parseRead(out) {
|
|
142
|
+
const buf = Buffer.from(out);
|
|
143
|
+
const end = buf.indexOf(10);
|
|
144
|
+
const head = /^agentrun-read 1 (none|[0-9a-f]{40}|[0-9a-f]{64}) (\d+) (\d+) (\d+)$/.exec(buf.subarray(0, end < 0 ? 0 : end).toString("utf8"));
|
|
145
|
+
if (!head)
|
|
146
|
+
throw new Error("the learning script's read is not one this server reads");
|
|
147
|
+
const [treeLen, logLen, blobLen] = [Number(head[2]), Number(head[3]), Number(head[4])];
|
|
148
|
+
let at = end + 1;
|
|
149
|
+
const part = (len) => {
|
|
150
|
+
const slice = buf.subarray(at, at + len);
|
|
151
|
+
if (slice.length !== len)
|
|
152
|
+
throw new Error("the learning script's read is cut short");
|
|
153
|
+
at += len;
|
|
154
|
+
return slice;
|
|
155
|
+
};
|
|
156
|
+
const tree = part(treeLen).toString("utf8").split("\0").filter(Boolean).map((entry) => {
|
|
157
|
+
const tab = entry.indexOf("\t");
|
|
158
|
+
const [mode = "", type = "", oid = "", size = ""] = entry.slice(0, tab).split(/\s+/);
|
|
159
|
+
return { mode, type, oid, bytes: Number(size) || 0, path: entry.slice(tab + 1) };
|
|
160
|
+
});
|
|
161
|
+
const records = recordsOf(part(logLen).toString("utf8")).map(({ head: line, files }) => {
|
|
162
|
+
const [sha = "", cI = "", subject = "", body = "", runId = "", changedBy = "", approvedVia = ""] = line.split("\x1f");
|
|
163
|
+
return { sha, files, commit: { at: cI, subject, body, runId, changedBy, approvedVia } };
|
|
164
|
+
});
|
|
165
|
+
const blobs = new Map();
|
|
166
|
+
const raw = part(blobLen);
|
|
167
|
+
for (let i = 0; i < raw.length;) {
|
|
168
|
+
const nl = raw.indexOf(10, i);
|
|
169
|
+
if (nl < 0)
|
|
170
|
+
break;
|
|
171
|
+
const [oid = "", type = "", size = ""] = raw.subarray(i, nl).toString("utf8").split(" ");
|
|
172
|
+
if (type === "missing") {
|
|
173
|
+
i = nl + 1;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const length = Number(size);
|
|
177
|
+
blobs.set(oid, raw.subarray(nl + 1, nl + 1 + length));
|
|
178
|
+
i = nl + 1 + length + 1;
|
|
179
|
+
}
|
|
180
|
+
return { main: head[1] === "none" ? undefined : head[1], tree, records, blobs };
|
|
181
|
+
}
|
|
182
|
+
/** The snapshot of main as the script's `read` shows it: every item from the tree and its blobs, each file's history
|
|
183
|
+
* and order from main's first-parent log, and the newest LOG_KEEP changes. */
|
|
184
|
+
export function snapshotOfRead(read) {
|
|
185
|
+
const { main, tree, records, blobs } = read;
|
|
186
|
+
if (!main || !records.length)
|
|
187
|
+
return undefined;
|
|
188
|
+
const order = new Map();
|
|
189
|
+
const history = new Map();
|
|
190
|
+
const runs = new Map();
|
|
191
|
+
const log = [];
|
|
192
|
+
let more = false;
|
|
193
|
+
records.forEach(({ commit, sha, files }, i) => {
|
|
194
|
+
const runId = commit.runId.split(",")[0].trim();
|
|
195
|
+
for (const file of files) {
|
|
196
|
+
if (!order.has(file))
|
|
197
|
+
order.set(file, i);
|
|
198
|
+
const known = history.get(file);
|
|
199
|
+
if (!known)
|
|
200
|
+
history.set(file, foldNewer(undefined, commit, file));
|
|
201
|
+
else
|
|
202
|
+
foldOlder(known, commit, file);
|
|
203
|
+
if (runId && !runs.has(file))
|
|
204
|
+
runs.set(file, runId);
|
|
205
|
+
}
|
|
206
|
+
if (!isChange(commit))
|
|
207
|
+
return;
|
|
208
|
+
const entry = changeEntry(commit, sha, files);
|
|
209
|
+
if (!entry)
|
|
210
|
+
return;
|
|
211
|
+
if (log.length < LOG_KEEP)
|
|
212
|
+
log.push(entry);
|
|
213
|
+
else
|
|
214
|
+
more = true;
|
|
215
|
+
});
|
|
216
|
+
const at = records[0].commit.at;
|
|
217
|
+
const regular = (entry) => entry.type === "blob" && entry.mode === "100644";
|
|
218
|
+
const orderOf = (path) => order.get(path) ?? Number.MAX_SAFE_INTEGER;
|
|
219
|
+
const historyOf = (path) => history.get(path) ?? { at };
|
|
220
|
+
const index = tree.find((entry) => entry.path === INDEX_FILE && regular(entry));
|
|
221
|
+
const notes = [];
|
|
222
|
+
const folders = new Map();
|
|
223
|
+
for (const entry of tree) {
|
|
224
|
+
if (!entry.path.includes("/")) {
|
|
225
|
+
const text = regular(entry) && entry.bytes <= FILE_CAP ? textOf(blobs.get(entry.oid)) : undefined;
|
|
226
|
+
const note = text === undefined || entry.path === INDEX_FILE ? undefined : noteEntry(entry.path, text, entry.oid, entry.bytes, orderOf(entry.path), historyOf(entry.path));
|
|
227
|
+
if (note)
|
|
228
|
+
notes.push(note);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const folder = folderOf(entry.path);
|
|
232
|
+
if (!folder || entry.type !== "blob")
|
|
233
|
+
continue;
|
|
234
|
+
const key = `${folder.kind}/${folder.name}`;
|
|
235
|
+
const known = folders.get(key) ?? folders.set(key, { ...folder, files: [], links: [] }).get(key);
|
|
236
|
+
if (entry.mode === "120000")
|
|
237
|
+
known.links.push(entry.path);
|
|
238
|
+
else if (entry.mode === "100644" || entry.mode === "100755")
|
|
239
|
+
known.files.push({ path: entry.path, oid: entry.oid, bytes: entry.bytes });
|
|
240
|
+
}
|
|
241
|
+
const skills = [];
|
|
242
|
+
const workflows = [];
|
|
243
|
+
for (const { kind, name, files, links } of folders.values()) {
|
|
244
|
+
const item = learnedItem(kind, name, files, links, (path) => {
|
|
245
|
+
const entry = tree.find((one) => one.path === path);
|
|
246
|
+
return entry && regular(entry) && entry.bytes <= FILE_CAP ? textOf(blobs.get(entry.oid)) : undefined;
|
|
247
|
+
}, {
|
|
248
|
+
order: Math.min(...files.map(({ path }) => orderOf(path))),
|
|
249
|
+
history: historyOf(keyFile(kind, name)),
|
|
250
|
+
run: runs.get(viewFile(kind, name)) ?? null,
|
|
251
|
+
});
|
|
252
|
+
if (item)
|
|
253
|
+
(kind === "skill" ? skills : workflows).push(item);
|
|
254
|
+
}
|
|
255
|
+
return { v: 1, main, at, index: index ? { oid: index.oid, bytes: index.bytes } : EMPTY_INDEX, notes: notes.sort(noteOrder), skills: skills.sort(byName), workflows: workflows.sort(byName), log, log_more: more };
|
|
256
|
+
}
|
|
257
|
+
/** A learned item from its folder's files: listed when its folder is well named, its key file (SKILL.md, a draft's
|
|
258
|
+
* README.md) is there and reads, and a draft has its workflow.json too, each of those a regular file under FILE_CAP
|
|
259
|
+
* (only those are given their texts by `text`). */
|
|
260
|
+
function learnedItem(kind, name, files, links, text, at, said) {
|
|
261
|
+
if (!learnedName(kind, name))
|
|
262
|
+
return undefined;
|
|
263
|
+
const key = files.find(({ path }) => path === keyFile(kind, name));
|
|
264
|
+
const shown = files.find(({ path }) => path === viewFile(kind, name));
|
|
265
|
+
if (!key || !shown || key.bytes > FILE_CAP || shown.bytes > FILE_CAP)
|
|
266
|
+
return undefined;
|
|
267
|
+
let fields = said;
|
|
268
|
+
if (!fields) {
|
|
269
|
+
const body = text(key.path);
|
|
270
|
+
if (body === undefined)
|
|
271
|
+
return undefined;
|
|
272
|
+
fields = { description: learnedFront(body)?.description ?? "", status: learnedStatus(body) };
|
|
273
|
+
}
|
|
274
|
+
return { name, file: key.path, description: fields.description, status: fields.status, run: at.run, files: [...files].sort((a, b) => byBytes(a.path, b.path)), oid: key.oid, bytes: key.bytes, order: at.order, history: at.history, ...(links.length ? { links: [...links].sort(byBytes) } : {}) };
|
|
275
|
+
}
|
|
276
|
+
/** A commit's message and trailers, as git keeps them: a person's names their action and the file, with Changed-By (and
|
|
277
|
+
* Approved-Via on an approval); a run's merge names the run, then the grader's reason, then its Run-Id. */
|
|
278
|
+
function messageOf(by) {
|
|
279
|
+
const clean = (text) => text.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, " ");
|
|
280
|
+
const paragraphs = (parts) => parts.map((part) => (part.endsWith("\n") ? part : `${part}\n`)).join("\n");
|
|
281
|
+
if (!by)
|
|
282
|
+
return { message: `${INIT_SUBJECT}\n`, subject: INIT_SUBJECT, body: "", runId: "", changedBy: "", approvedVia: "" };
|
|
283
|
+
if ("run" in by) {
|
|
284
|
+
const subject = `learning: ${by.run}: merged`;
|
|
285
|
+
const reason = clean(by.reason).trim() || "merged";
|
|
286
|
+
const body = paragraphs([reason, `Run-Id: ${by.run}`]);
|
|
287
|
+
return { message: `${subject}\n\n${body}`, subject, body, runId: by.run, changedBy: "", approvedVia: "" };
|
|
288
|
+
}
|
|
289
|
+
const subject = `learning: ${by.person} by a person: ${by.file}`;
|
|
290
|
+
const body = paragraphs([by.approved ? "Changed-By: user\nApproved-Via: console" : "Changed-By: user"]);
|
|
291
|
+
return { message: `${subject}\n\n${body}`, subject, body, runId: "", changedBy: "user", approvedVia: by.approved ? "console" : "" };
|
|
292
|
+
}
|
|
293
|
+
/** Git's %cI of a time in whole seconds, as a commit made at +0000 shows it. */
|
|
294
|
+
const isoSeconds = (seconds) => new Date(seconds * 1000).toISOString().replace(/\.\d{3}Z$/, "+00:00");
|
|
295
|
+
/** Every path `snapshot` names a blob for: the index, each note, each learned folder's files. */
|
|
296
|
+
function oidsOf(snapshot) {
|
|
297
|
+
const out = new Map();
|
|
298
|
+
if (!snapshot)
|
|
299
|
+
return out;
|
|
300
|
+
out.set(INDEX_FILE, snapshot.index.oid);
|
|
301
|
+
for (const note of snapshot.notes)
|
|
302
|
+
out.set(note.file, note.oid);
|
|
303
|
+
for (const item of [...snapshot.skills, ...snapshot.workflows])
|
|
304
|
+
for (const file of item.files)
|
|
305
|
+
out.set(file.path, file.oid);
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
/** The snapshot once `change` is committed on `before` (none: the folder's first commit) at `seconds`, its main and its
|
|
309
|
+
* log entry's commit the placeholder the script puts the new main in. Also which paths changed, as git's diff of the
|
|
310
|
+
* commit lists them. */
|
|
311
|
+
export function nextSnapshot(before, change, seconds) {
|
|
312
|
+
const message = messageOf(change?.by);
|
|
313
|
+
const commit = { at: isoSeconds(seconds), ...message };
|
|
314
|
+
const known = oidsOf(before);
|
|
315
|
+
const writes = new Map((change?.writes ?? (change ? [] : [{ path: INDEX_FILE, text: "" }])).map(({ path, text }) => [path, { text, oid: blobOid(text), bytes: Buffer.byteLength(text, "utf8") }]));
|
|
316
|
+
const deletes = new Set(change?.deletes ?? []);
|
|
317
|
+
const changed = [...new Set([...[...writes].filter(([path, { oid }]) => known.get(path) !== oid).map(([path]) => path), ...[...deletes].filter((path) => !writes.has(path))])].sort(byBytes);
|
|
318
|
+
const touched = new Set(changed);
|
|
319
|
+
const runId = commit.runId;
|
|
320
|
+
const notes = (before?.notes ?? []).filter((note) => !touched.has(note.file)).map((note) => ({ ...note, order: note.order + 1 }));
|
|
321
|
+
for (const path of changed) {
|
|
322
|
+
const written = writes.get(path);
|
|
323
|
+
if (!written || path.includes("/") || path === INDEX_FILE)
|
|
324
|
+
continue;
|
|
325
|
+
const old = before?.notes.find((note) => note.file === path);
|
|
326
|
+
const note = noteEntry(path, written.text, written.oid, written.bytes, 0, foldNewer(old?.history, commit, path));
|
|
327
|
+
if (note)
|
|
328
|
+
notes.push(note);
|
|
329
|
+
}
|
|
330
|
+
const index = writes.has(INDEX_FILE) ? { oid: writes.get(INDEX_FILE).oid, bytes: writes.get(INDEX_FILE).bytes } : (before?.index ?? EMPTY_INDEX);
|
|
331
|
+
const learned = (kind, list) => {
|
|
332
|
+
const hit = new Set(changed.map(folderOf).filter((folder) => folder?.kind === kind).map((folder) => folder.name));
|
|
333
|
+
const out = list.filter((item) => !hit.has(item.name)).map((item) => ({ ...item, order: item.order + 1 }));
|
|
334
|
+
for (const name of hit) {
|
|
335
|
+
const old = list.find((item) => item.name === name);
|
|
336
|
+
const prefix = `${kind === "skill" ? SKILLS_DIR : WORKFLOWS_DIR}/${name}/`;
|
|
337
|
+
const files = new Map((old?.files ?? []).map((file) => [file.path, file]));
|
|
338
|
+
for (const path of changed.filter((one) => one.startsWith(prefix))) {
|
|
339
|
+
const written = writes.get(path);
|
|
340
|
+
if (written)
|
|
341
|
+
files.set(path, { path, oid: written.oid, bytes: written.bytes });
|
|
342
|
+
else
|
|
343
|
+
files.delete(path);
|
|
344
|
+
}
|
|
345
|
+
const key = keyFile(kind, name);
|
|
346
|
+
const keyText = writes.get(key)?.text;
|
|
347
|
+
// A link the change writes a file over, or deletes, is a link no more.
|
|
348
|
+
const links = (old?.links ?? []).filter((path) => !writes.has(path) && !deletes.has(path));
|
|
349
|
+
const item = learnedItem(kind, name, [...files.values()], links, (path) => writes.get(path)?.text, {
|
|
350
|
+
order: 0,
|
|
351
|
+
history: touched.has(key) ? foldNewer(old?.history, commit, key) : (old?.history ?? { at: commit.at }),
|
|
352
|
+
run: runId && touched.has(viewFile(kind, name)) ? runId : (old?.run ?? null),
|
|
353
|
+
}, keyText === undefined && old ? { description: old.description, status: old.status } : undefined);
|
|
354
|
+
if (item)
|
|
355
|
+
out.push(item);
|
|
356
|
+
}
|
|
357
|
+
return out.sort(byName);
|
|
358
|
+
};
|
|
359
|
+
const entry = change && isChange(commit) ? changeEntry(commit, PLACEHOLDER, changed) : undefined;
|
|
360
|
+
const log = [...(entry ? [entry] : []), ...(before?.log ?? [])];
|
|
361
|
+
const snapshot = {
|
|
362
|
+
v: 1, main: PLACEHOLDER, at: commit.at, index,
|
|
363
|
+
notes: notes.sort(noteOrder), skills: learned("skill", before?.skills ?? []), workflows: learned("workflow", before?.workflows ?? []),
|
|
364
|
+
log: log.slice(0, LOG_KEEP), log_more: Boolean(before?.log_more) || log.length > LOG_KEEP,
|
|
365
|
+
};
|
|
366
|
+
return { snapshot, changed };
|
|
367
|
+
}
|
|
368
|
+
/** The snapshot with its placeholder put for `main`: what the script wrote, for a caller that keeps going. */
|
|
369
|
+
const withMain = (snapshot, main) => JSON.parse(JSON.stringify(snapshot).replaceAll(ESCAPED_PLACEHOLDER, main));
|
|
370
|
+
/** Agent `place.agentId`'s learning folder as a Workspace: the one learningWorkspace, or the test's stand-in. */
|
|
371
|
+
export function learningWorkspace(place) {
|
|
372
|
+
if (folderTestHooks.workspace)
|
|
373
|
+
return folderTestHooks.workspace(place);
|
|
374
|
+
return oneLearningWorkspace(place);
|
|
375
|
+
}
|
|
376
|
+
/** A learning folder this server cannot read or write: a link in it (`link`, its words naming it), or a backend that
|
|
377
|
+
* cannot answer. Fails closed: nothing learned is read, nothing is written. */
|
|
378
|
+
export class FolderUnreadable extends Error {
|
|
379
|
+
link;
|
|
380
|
+
constructor(link, message) {
|
|
381
|
+
super(message);
|
|
382
|
+
this.name = "FolderUnreadable";
|
|
383
|
+
this.link = link;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** A workspace failure as the folder's: ESCAPE (a link below the root, Local) or a read of a link (Archil's file API:
|
|
387
|
+
* UNAVAILABLE naming a symbolic link) in words that name the link; any other UNAVAILABLE as the folder unreadable. */
|
|
388
|
+
export function folderFailure(error) {
|
|
389
|
+
if (error instanceof FolderUnreadable)
|
|
390
|
+
return error;
|
|
391
|
+
if (isWorkspaceError(error, "ESCAPE") || (isWorkspaceError(error, "UNAVAILABLE") && /symbolic link/.test(error.message))) {
|
|
392
|
+
return new FolderUnreadable(true, `a link in the learning folder at ${error.path || "its root"} can't be followed, so nothing learned is read or written; remove the link`);
|
|
393
|
+
}
|
|
394
|
+
if (isWorkspaceError(error, "UNAVAILABLE"))
|
|
395
|
+
return new FolderUnreadable(false, `the agent's learning folder can't be read right now: ${error.message}`);
|
|
396
|
+
return error;
|
|
397
|
+
}
|
|
398
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
399
|
+
// Reading: the snapshot and the bodies it names, through the file API alone.
|
|
400
|
+
/** A body that was not the snapshot's blob as it was read twice: a write is in flight. Routes answer 503. */
|
|
401
|
+
export class FolderBusy extends Error {
|
|
402
|
+
constructor() {
|
|
403
|
+
super("the agent's learning folder is being written: try again");
|
|
404
|
+
this.name = "FolderBusy";
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/** A body that is not the snapshot's blob: the snapshot is read again once. */
|
|
408
|
+
class Mismatch extends Error {
|
|
409
|
+
}
|
|
410
|
+
/** Whether `error` is a body that was not the snapshot's blob (a reader holding an older snapshot meets it). */
|
|
411
|
+
export const isBodyMismatch = (error) => error instanceof Mismatch;
|
|
412
|
+
const isOidField = (value) => typeof value === "string" && /^[0-9a-f]{40}([0-9a-f]{24})?$/.test(value);
|
|
413
|
+
/** The folder's snapshot, or undefined when there is none (no main yet: the agent never learned). One that does not
|
|
414
|
+
* read as v1 throws. */
|
|
415
|
+
export async function readSnapshot(ws) {
|
|
416
|
+
let bytes;
|
|
417
|
+
try {
|
|
418
|
+
bytes = await ws.read(SNAPSHOT_FILE);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
if (isWorkspaceError(error, "NOT_FOUND"))
|
|
422
|
+
return undefined;
|
|
423
|
+
throw folderFailure(error);
|
|
424
|
+
}
|
|
425
|
+
const value = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
426
|
+
if (value?.v !== 1 || !isOidField(value.main) || !Array.isArray(value.notes) || !Array.isArray(value.skills) || !Array.isArray(value.workflows) || !Array.isArray(value.log) || !isOidField(value.index?.oid))
|
|
427
|
+
throw new Error("the learning folder's snapshot is not one this server reads (v1)");
|
|
428
|
+
return value;
|
|
429
|
+
}
|
|
430
|
+
/** Bodies already checked, by blob id: an oid names its bytes, so one read is good for every snapshot naming it. */
|
|
431
|
+
const bodies = new Map();
|
|
432
|
+
let bodyBytes = 0;
|
|
433
|
+
const BODY_CACHE = 16 << 20;
|
|
434
|
+
function keep(oid, text) {
|
|
435
|
+
if (text.length > FILE_CAP)
|
|
436
|
+
return;
|
|
437
|
+
bodies.set(oid, text);
|
|
438
|
+
bodyBytes += text.length;
|
|
439
|
+
for (const [old, held] of bodies) {
|
|
440
|
+
if (bodyBytes <= BODY_CACHE)
|
|
441
|
+
break;
|
|
442
|
+
bodies.delete(old);
|
|
443
|
+
bodyBytes -= held.length;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/** Tests only: the bodies already checked, forgotten, so the next read of each goes to the folder. */
|
|
447
|
+
export function forgetBodies() {
|
|
448
|
+
bodies.clear();
|
|
449
|
+
bodyBytes = 0;
|
|
450
|
+
}
|
|
451
|
+
/** File `path`'s bytes, which must be blob `oid` (else Mismatch): through the file API, never git. */
|
|
452
|
+
async function bytesOf(ws, path, oid) {
|
|
453
|
+
let bytes;
|
|
454
|
+
try {
|
|
455
|
+
bytes = await ws.read(path);
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
if (isWorkspaceError(error, "NOT_FOUND"))
|
|
459
|
+
throw new Mismatch();
|
|
460
|
+
throw folderFailure(error);
|
|
461
|
+
}
|
|
462
|
+
if (blobOid(bytes) !== oid)
|
|
463
|
+
throw new Mismatch();
|
|
464
|
+
return Buffer.from(bytes);
|
|
465
|
+
}
|
|
466
|
+
/** File `path`'s text, which must be blob `oid` in UTF-8 (else Mismatch): through the file API, never git. */
|
|
467
|
+
async function bodyOf(ws, path, oid) {
|
|
468
|
+
const known = bodies.get(oid);
|
|
469
|
+
if (known !== undefined)
|
|
470
|
+
return known;
|
|
471
|
+
const text = textOf(await bytesOf(ws, path, oid));
|
|
472
|
+
if (text === undefined)
|
|
473
|
+
throw new Mismatch();
|
|
474
|
+
keep(oid, text);
|
|
475
|
+
return text;
|
|
476
|
+
}
|
|
477
|
+
const folderRead = (ws, snapshot) => ({ snapshot, body: (path, oid) => bodyOf(ws, path, oid), bytes: (path, oid) => bytesOf(ws, path, oid) });
|
|
478
|
+
/** `read` over the folder's snapshot and its bodies: once, and on a body that is not the snapshot's, once more on the
|
|
479
|
+
* snapshot read again; a second mismatch is FolderBusy. No git and no exec: the file API alone. */
|
|
480
|
+
export async function readLearning(ws, read) {
|
|
481
|
+
for (let tries = 0;; tries++) {
|
|
482
|
+
const snapshot = await readSnapshot(ws);
|
|
483
|
+
try {
|
|
484
|
+
return await read(folderRead(ws, snapshot));
|
|
485
|
+
}
|
|
486
|
+
catch (error) {
|
|
487
|
+
if (!(error instanceof Mismatch))
|
|
488
|
+
throw error;
|
|
489
|
+
if (tries > 0)
|
|
490
|
+
throw new FolderBusy();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/** Run `run`'s merge as its diff file keeps it, or undefined when the folder has none (it never merged here). */
|
|
495
|
+
export async function readRunDiff(ws, run) {
|
|
496
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(run))
|
|
497
|
+
return undefined;
|
|
498
|
+
let bytes;
|
|
499
|
+
try {
|
|
500
|
+
bytes = await ws.read(`${DIFFS_DIR}/${run}.json`);
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
if (isWorkspaceError(error, "NOT_FOUND"))
|
|
504
|
+
return undefined;
|
|
505
|
+
throw folderFailure(error);
|
|
506
|
+
}
|
|
507
|
+
const diff = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
508
|
+
if (diff?.v !== 1 || diff.run !== run || !isOidField(diff.merge) || !isOidField(diff.parent) || !Array.isArray(diff.files))
|
|
509
|
+
throw new Error(`the learning folder's diff of ${run} is not one this server reads (v1)`);
|
|
510
|
+
return diff;
|
|
511
|
+
}
|
|
512
|
+
/** The notes of a snapshot as the learning modules take them (buildIndex, mergeProblems): their front matter, no body. */
|
|
513
|
+
export const snapshotNotes = (snapshot) => (snapshot?.notes ?? []).map((note) => ({ file: note.file, name: note.name, description: note.description, type: note.type, status: note.status, origin: note.origin, superseded_by: note.superseded_by, supersedes: [...note.supersedes], keys: [], body: "" }));
|
|
514
|
+
/** Every name at main's top a snapshot knows: the index, the notes, and the learned folders' tops. */
|
|
515
|
+
export const topOf = (snapshot) => (snapshot ? [INDEX_FILE, ...snapshot.notes.map((note) => note.file), ...(snapshot.skills.length ? [SKILLS_DIR] : []), ...(snapshot.workflows.length ? [WORKFLOWS_DIR] : [])] : []);
|
|
516
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
517
|
+
// Writing: the script, one exec a write.
|
|
518
|
+
/** The script, as checked in (learning.sh beside this file), and the name it is written under in the folder. */
|
|
519
|
+
export const LEARNING_SH = readFileSync(new URL("./learning.sh", import.meta.url), "utf8");
|
|
520
|
+
export const SCRIPT_FILE = `${HOST_DIR}/learning-${createHash("sha256").update(LEARNING_SH).digest("hex").slice(0, 8)}.sh`;
|
|
521
|
+
/** Test seams, tests only: variables added to the script's environment (AGENTRUN_LEARNING_FAIL), each exec's argv, and
|
|
522
|
+
* the folder's Workspace in place of learningWorkspace's (a spy, or another backend). */
|
|
523
|
+
export const folderTestHooks = {};
|
|
524
|
+
/** The script's environment, whole: exec inherits nothing. */
|
|
525
|
+
const scriptEnv = () => ({
|
|
526
|
+
PATH: "/usr/bin:/bin",
|
|
527
|
+
LC_ALL: "C",
|
|
528
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
529
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
530
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
531
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
532
|
+
GIT_AUTHOR_NAME: IDENTITY.name,
|
|
533
|
+
GIT_AUTHOR_EMAIL: IDENTITY.email,
|
|
534
|
+
GIT_COMMITTER_NAME: IDENTITY.name,
|
|
535
|
+
GIT_COMMITTER_EMAIL: IDENTITY.email,
|
|
536
|
+
...folderTestHooks.env,
|
|
537
|
+
});
|
|
538
|
+
/** The script in the folder, written when this version of it is not there yet. */
|
|
539
|
+
async function ensureScript(ws) {
|
|
540
|
+
const there = await ws.read(SCRIPT_FILE).then((bytes) => Buffer.from(bytes).toString("utf8"), (error) => {
|
|
541
|
+
if (isWorkspaceError(error, "NOT_FOUND"))
|
|
542
|
+
return undefined;
|
|
543
|
+
throw folderFailure(error);
|
|
544
|
+
});
|
|
545
|
+
if (there !== LEARNING_SH)
|
|
546
|
+
await ws.write(SCRIPT_FILE, LEARNING_SH).catch((error) => { throw folderFailure(error); });
|
|
547
|
+
}
|
|
548
|
+
/** One run of the script: `op` and its arguments, `stdin`. Its exit code and output; a run that could not finish (its
|
|
549
|
+
* deadline, a signal) throws. */
|
|
550
|
+
async function runScript(ws, args, stdin) {
|
|
551
|
+
await ensureScript(ws);
|
|
552
|
+
const argv = ["sh", SCRIPT_FILE, ...args];
|
|
553
|
+
folderTestHooks.exec?.(argv);
|
|
554
|
+
const raw = await ws.exec(argv, { env: scriptEnv(), timeoutMs: SCRIPT_TIMEOUT_MS, ...(stdin ? { stdin } : {}) }).catch((error) => { throw folderFailure(error); });
|
|
555
|
+
// The port's ExecResult, in one line (code is renamed exitCode).
|
|
556
|
+
const result = { code: raw.code, stdout: raw.stdout, stderr: raw.stderr, timedOut: raw.timedOut, truncated: raw.truncated };
|
|
557
|
+
if (result.timedOut || result.code === null)
|
|
558
|
+
throw new Error(`the learning script's ${args[0]} did not finish${result.timedOut ? ` in ${SCRIPT_TIMEOUT_MS / 1000} s` : ""}: ${result.stderr.trim().slice(0, 500)}`);
|
|
559
|
+
// A cut stdout is never parsed: the folder is unavailable for this call.
|
|
560
|
+
if (result.truncated)
|
|
561
|
+
throw new FolderUnreadable(false, `the learning script's ${args[0]} said more than this server reads`);
|
|
562
|
+
return { code: result.code, stdout: Buffer.from(result.stdout), stderr: result.stderr };
|
|
563
|
+
}
|
|
564
|
+
const failed = (op, run) => new Error(`the learning script's ${op} failed (exit ${run.code}): ${run.stderr.trim().slice(0, 500)}`);
|
|
565
|
+
/** A path a change may name: the folder's, plain (letters, digits, ".", "_", "-" and "/"), never `.git` or `.agentrun`. */
|
|
566
|
+
function checkPath(path) {
|
|
567
|
+
const parts = path.split("/");
|
|
568
|
+
if (!/^[A-Za-z0-9._/-]+$/.test(path) || parts.some((part) => part === "" || part === "." || part === "..") || parts[0] === HOST_DIR || parts[0] === ".git")
|
|
569
|
+
throw new Error(`${JSON.stringify(path)} is not a path a learning write names`);
|
|
570
|
+
return path;
|
|
571
|
+
}
|
|
572
|
+
/** The fast-import stream of `change` on `parent` (none: the first commit), committed on `ref` at `seconds`. */
|
|
573
|
+
function importStream(ref, parent, writes, deletes, message, seconds) {
|
|
574
|
+
const parts = [];
|
|
575
|
+
const add = (text) => parts.push(Buffer.from(text, "utf8"));
|
|
576
|
+
writes.forEach(({ text }, i) => {
|
|
577
|
+
const data = Buffer.from(text, "utf8");
|
|
578
|
+
add(`blob\nmark :${i + 1}\ndata ${data.length}\n`);
|
|
579
|
+
parts.push(data);
|
|
580
|
+
add("\n");
|
|
581
|
+
});
|
|
582
|
+
const who = `${IDENTITY.name} <${IDENTITY.email}> ${seconds} +0000`;
|
|
583
|
+
const body = Buffer.from(message, "utf8");
|
|
584
|
+
add(`commit ${ref}\nauthor ${who}\ncommitter ${who}\ndata ${body.length}\n`);
|
|
585
|
+
parts.push(body);
|
|
586
|
+
add(`\n${parent ? `from ${parent}\n` : ""}`);
|
|
587
|
+
for (const path of deletes)
|
|
588
|
+
add(`D ${path}\n`);
|
|
589
|
+
writes.forEach(({ path }, i) => add(`M 100644 :${i + 1} ${path}\n`));
|
|
590
|
+
add("\ndone\n");
|
|
591
|
+
return Buffer.concat(parts);
|
|
592
|
+
}
|
|
593
|
+
/** The script's stdin: its header lines, a blank line, then what follows. */
|
|
594
|
+
function stdinOf(header, rest = Buffer.alloc(0)) {
|
|
595
|
+
return Buffer.concat([Buffer.from(`${header.join("\n")}\n\n`, "utf8"), rest]);
|
|
596
|
+
}
|
|
597
|
+
/** `snapshot` as one line of JSON for the script, its placeholder as the raw U+0001 pair the script replaces. */
|
|
598
|
+
function snapshotLine(snapshot, placeholders) {
|
|
599
|
+
const json = JSON.stringify(snapshot);
|
|
600
|
+
if (json.split("\\u0001").length - 1 !== placeholders * 2)
|
|
601
|
+
throw new Error("a learning text holds U+0001, which the folder's snapshot never keeps");
|
|
602
|
+
return json.replaceAll(ESCAPED_PLACEHOLDER, PLACEHOLDER);
|
|
603
|
+
}
|
|
604
|
+
/** The most stdin one exec of the script is given: what both backends are verified to carry byte for byte. */
|
|
605
|
+
export const STDIN_MAX = 2 * 1024 * 1024;
|
|
606
|
+
/** A write whose exec would carry more than STDIN_MAX: refused whole, nothing run. */
|
|
607
|
+
export class FolderTooLarge extends Error {
|
|
608
|
+
bytes;
|
|
609
|
+
constructor(bytes) {
|
|
610
|
+
super(`the write would hand the learning script ${bytes} bytes; one exec takes at most ${STDIN_MAX}`);
|
|
611
|
+
this.name = "FolderTooLarge";
|
|
612
|
+
this.bytes = bytes;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* One write to main, one exec of the script: `change` on the snapshot it was computed from (`base`: none for the
|
|
617
|
+
* folder's first commit, `op` "init"). The commit moves main only from `base.main` (compare and swap); then the
|
|
618
|
+
* working tree, a merge's diff file, and the next snapshot (nextSnapshot), last. Nothing is retried here: writeLearning
|
|
619
|
+
* computes again on a main that moved.
|
|
620
|
+
*/
|
|
621
|
+
export async function commitChange(ws, base, change) {
|
|
622
|
+
const seconds = Math.floor(Date.now() / 1000);
|
|
623
|
+
const { snapshot, changed } = nextSnapshot(base, change, seconds);
|
|
624
|
+
// A change that changes nothing on main is no commit: main stays, and nothing is run.
|
|
625
|
+
if (base && change && !changed.length)
|
|
626
|
+
return { landed: true, main: base.main, snapshot: base };
|
|
627
|
+
const writes = change?.writes ?? [{ path: INDEX_FILE, text: "" }];
|
|
628
|
+
for (const { path } of writes)
|
|
629
|
+
checkPath(path);
|
|
630
|
+
for (const path of [...(change?.deletes ?? []), ...(change?.absent ?? []), ...(change?.same ?? []).map(({ path }) => path)])
|
|
631
|
+
checkPath(path);
|
|
632
|
+
for (const { commit } of change?.same ?? [])
|
|
633
|
+
if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
|
|
634
|
+
throw new Error(`${JSON.stringify(commit)} is not a commit`);
|
|
635
|
+
const ref = `refs/agentrun/import-${randomBytes(8).toString("hex")}`;
|
|
636
|
+
const run = change && "run" in change.by ? change.by.run : undefined;
|
|
637
|
+
const header = [
|
|
638
|
+
`ref ${ref}`,
|
|
639
|
+
`snapshot ${snapshotLine(snapshot, snapshot.log[0]?.commit === PLACEHOLDER ? 2 : 1)}`,
|
|
640
|
+
...(run ? changed.map((path) => `path ${path}`) : []),
|
|
641
|
+
...(change?.absent ?? []).map((path) => `absent ${path}`),
|
|
642
|
+
...(change?.same ?? []).map(({ commit, path }) => `same ${commit} ${path}`),
|
|
643
|
+
];
|
|
644
|
+
const stream = importStream(ref, base?.main, writes, change?.deletes ?? [], messageOf(change?.by).message, seconds);
|
|
645
|
+
const args = base ? ["commit", base.main, ...(run ? [run] : [])] : ["init"];
|
|
646
|
+
const stdin = stdinOf(header, stream);
|
|
647
|
+
if (stdin.length > STDIN_MAX)
|
|
648
|
+
throw new FolderTooLarge(stdin.length);
|
|
649
|
+
const result = await runScript(ws, args, stdin);
|
|
650
|
+
const said = result.stdout.toString("utf8").trim();
|
|
651
|
+
if (result.code === 0 && /^[0-9a-f]{40,64}$/.test(said))
|
|
652
|
+
return { landed: true, main: said, snapshot: withMain(snapshot, said) };
|
|
653
|
+
if (result.code === 3)
|
|
654
|
+
return { stale: true, main: said || undefined };
|
|
655
|
+
if (result.code === 4) {
|
|
656
|
+
const lines = said.split("\n");
|
|
657
|
+
return { refused: { absent: lines.filter((line) => line.startsWith("absent ")).map((line) => line.slice(7)), same: lines.filter((line) => line.startsWith("same ")).map((line) => line.slice(5)) } };
|
|
658
|
+
}
|
|
659
|
+
if (result.code === 5 && /^[0-9a-f]{40,64}$/.test(said))
|
|
660
|
+
return { unaligned: true, main: said };
|
|
661
|
+
throw failed(args[0], result);
|
|
662
|
+
}
|
|
663
|
+
/** The snapshot rebuilt from main whole, and the working tree brought in line: the script's `read`, then its `snapshot`
|
|
664
|
+
* op at the main it read. For a folder whose snapshot is not main's. Undefined for a folder with no main. */
|
|
665
|
+
/** The snapshot of `commit` as main would have it (the script's read at that commit), or undefined when the folder has
|
|
666
|
+
* no such commit. One exec, read-only: for a run's seed that is no longer main. */
|
|
667
|
+
export async function snapshotAt(ws, commit) {
|
|
668
|
+
return (await folderAt(ws, commit))?.snapshot;
|
|
669
|
+
}
|
|
670
|
+
/** `commit` as main would have it (snapshotAt) with the blobs its tree holds, by oid, as git gave them: one read-only
|
|
671
|
+
* exec. Undefined when the folder has no such commit. */
|
|
672
|
+
export async function folderAt(ws, commit) {
|
|
673
|
+
if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(commit))
|
|
674
|
+
throw new Error(`${JSON.stringify(commit)} is not a commit`);
|
|
675
|
+
const read = await runScript(ws, ["read", commit]);
|
|
676
|
+
if (read.code === 1)
|
|
677
|
+
return undefined;
|
|
678
|
+
if (read.code !== 0)
|
|
679
|
+
throw failed("read", read);
|
|
680
|
+
const parsed = parseRead(read.stdout);
|
|
681
|
+
const snapshot = snapshotOfRead(parsed);
|
|
682
|
+
return snapshot ? { snapshot, blobs: parsed.blobs } : undefined;
|
|
683
|
+
}
|
|
684
|
+
export async function learningRepair(ws) {
|
|
685
|
+
for (let tries = 0; tries < WRITE_TRIES; tries++) {
|
|
686
|
+
const read = await runScript(ws, ["read"]);
|
|
687
|
+
if (read.code !== 0)
|
|
688
|
+
throw failed("read", read);
|
|
689
|
+
const snapshot = snapshotOfRead(parseRead(read.stdout));
|
|
690
|
+
if (!snapshot)
|
|
691
|
+
return undefined;
|
|
692
|
+
const written = await runScript(ws, ["snapshot", snapshot.main], stdinOf([`snapshot ${snapshotLine(snapshot, 0)}`]));
|
|
693
|
+
if (written.code === 0)
|
|
694
|
+
return snapshot;
|
|
695
|
+
if (written.code !== 3)
|
|
696
|
+
throw failed("snapshot", written);
|
|
697
|
+
}
|
|
698
|
+
throw new Error("the learning folder's main kept moving while its snapshot was rebuilt");
|
|
699
|
+
}
|
|
700
|
+
/** Main's text of `path` just before the newest person's retire of it on `main`'s line, or undefined (never retired by
|
|
701
|
+
* a person). A read through the script: git's history is not in the snapshot. */
|
|
702
|
+
export async function beforeRetire(ws, main, path) {
|
|
703
|
+
const result = await runScript(ws, ["before-retire", main, checkPath(path)]);
|
|
704
|
+
if (result.code === 1)
|
|
705
|
+
return undefined;
|
|
706
|
+
if (result.code !== 0)
|
|
707
|
+
throw failed("before-retire", result);
|
|
708
|
+
return textOf(result.stdout);
|
|
709
|
+
}
|
|
710
|
+
/** Whether `main` holds anything at `path`, as git stores it (any mode, any type): what the snapshot leaves out (a file
|
|
711
|
+
* that is no note) included. A read through the script. */
|
|
712
|
+
export async function heldOnMain(ws, main, path) {
|
|
713
|
+
const result = await runScript(ws, ["has", main, checkPath(path)]);
|
|
714
|
+
if (result.code !== 0 && result.code !== 1)
|
|
715
|
+
throw failed("has", result);
|
|
716
|
+
return result.code === 0;
|
|
717
|
+
}
|
|
718
|
+
/** The folder's first commit when it has no main yet (an empty MEMORY.md, the host's), and main's commit: through the
|
|
719
|
+
* script's init, which makes the repository where there is none. A main with no snapshot (an init that stopped
|
|
720
|
+
* before it) is repaired. */
|
|
721
|
+
export async function learningInit(ws) {
|
|
722
|
+
const known = await readSnapshot(ws);
|
|
723
|
+
if (known)
|
|
724
|
+
return known.main;
|
|
725
|
+
const result = await commitChange(ws, undefined, undefined);
|
|
726
|
+
if ("landed" in result)
|
|
727
|
+
return result.main;
|
|
728
|
+
if ("stale" in result && result.main) {
|
|
729
|
+
const repaired = await learningRepair(ws);
|
|
730
|
+
if (repaired)
|
|
731
|
+
return repaired.main;
|
|
732
|
+
}
|
|
733
|
+
if ("unaligned" in result) {
|
|
734
|
+
const repaired = await learningRepair(ws);
|
|
735
|
+
if (repaired)
|
|
736
|
+
return repaired.main;
|
|
737
|
+
}
|
|
738
|
+
throw new Error("the learning folder could not be made");
|
|
739
|
+
}
|
|
740
|
+
/** A write's preconditions that failed on main as the script found it: nothing was written. */
|
|
741
|
+
export class FolderRefused extends Error {
|
|
742
|
+
absent;
|
|
743
|
+
same;
|
|
744
|
+
constructor(refused) {
|
|
745
|
+
super(`the learning folder's main refused the write: ${[...refused.absent.map((path) => `${path} is there`), ...refused.same.map((path) => `${path} changed`)].join(", ")}`);
|
|
746
|
+
this.name = "FolderRefused";
|
|
747
|
+
this.absent = refused.absent;
|
|
748
|
+
this.same = refused.same;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* A write to the folder's main: `compute` reads the snapshot and the bodies it needs (as readLearning gives them) and
|
|
753
|
+
* says what to write, or nothing (its result stands alone). Committed by commitChange; a main that moved under it, or
|
|
754
|
+
* a body that changed as it was read, computes it again on the folder as it is then (WRITE_TRIES in all). A folder with
|
|
755
|
+
* no main yet is made first (learningInit). A snapshot that is not main's is rebuilt (learningRepair). Throws
|
|
756
|
+
* FolderRefused when a precondition fails on main.
|
|
757
|
+
*/
|
|
758
|
+
export async function writeLearning(ws, compute, maxTries = WRITE_TRIES) {
|
|
759
|
+
for (let tries = 0;; tries++) {
|
|
760
|
+
// A folder that kept moving, or whose bodies kept changing as they were read: a write in flight elsewhere.
|
|
761
|
+
if (tries >= maxTries)
|
|
762
|
+
throw new FolderBusy();
|
|
763
|
+
let snapshot = await readSnapshot(ws);
|
|
764
|
+
let out;
|
|
765
|
+
try {
|
|
766
|
+
out = await compute(folderRead(ws, snapshot));
|
|
767
|
+
}
|
|
768
|
+
catch (error) {
|
|
769
|
+
if (error instanceof Mismatch)
|
|
770
|
+
continue;
|
|
771
|
+
throw error;
|
|
772
|
+
}
|
|
773
|
+
if (!out.change)
|
|
774
|
+
return { result: out.result };
|
|
775
|
+
if (!snapshot) {
|
|
776
|
+
await learningInit(ws);
|
|
777
|
+
snapshot = await readSnapshot(ws);
|
|
778
|
+
// Computed again on the folder just made.
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
const done = await commitChange(ws, snapshot, out.change);
|
|
782
|
+
if ("landed" in done)
|
|
783
|
+
return { result: out.result, main: done.main, snapshot: done.snapshot };
|
|
784
|
+
if ("refused" in done)
|
|
785
|
+
throw new FolderRefused(done.refused);
|
|
786
|
+
if ("unaligned" in done) {
|
|
787
|
+
const repaired = await learningRepair(ws);
|
|
788
|
+
return { result: out.result, main: done.main, ...(repaired ? { snapshot: repaired } : {}) };
|
|
789
|
+
}
|
|
790
|
+
// Stale: a write landed since the snapshot was read. A snapshot that names another main than the one that won is
|
|
791
|
+
// not main's: rebuilt from main before the write is computed again.
|
|
792
|
+
const now = await readSnapshot(ws);
|
|
793
|
+
if (done.main && now?.main !== done.main)
|
|
794
|
+
await learningRepair(ws);
|
|
795
|
+
}
|
|
796
|
+
}
|