@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34
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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -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/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -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 +92 -50
- 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/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- 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.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +30 -2
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- 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 +0 -2
- package/dist/errors.js +6 -9
- 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/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- 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/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/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- 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 +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- 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 +6 -6
- 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 +6 -7
- package/dist/model.js +43 -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 +121 -47
- 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 +25 -60
- package/dist/propose.js +83 -39
- 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 +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- 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.js +118 -8
- 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.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +20 -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 +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +133 -9
- 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 +56 -10
- 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-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- 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 +1 -80
- 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 +16 -38
- package/dist/server.js +145 -106
- 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/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- 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 +18 -2
- package/dist/store/postgres/connection.js +156 -32
- 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 +49 -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 +93 -17
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +53 -18
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- 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 +274 -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-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- 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 +14 -42
- 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 +30 -18
- package/dist/tools.js +97 -107
- 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.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -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/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- 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/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// The computer janitor of this server: at the runner's start, then every JANITOR_EVERY_MS, each computer this server made
|
|
2
|
+
// that is past its deadline is ended. A run's release ends its computer; the janitor is for the ones a crashed runner
|
|
3
|
+
// left, on a provider whose vendor never ends them itself (capabilities().lifetime "janitor": Docker, Orgo).
|
|
4
|
+
//
|
|
5
|
+
// Which computers it may end:
|
|
6
|
+
// - a provider's whose keys this server has (saved, or in its environment); Docker takes none, so it is always asked;
|
|
7
|
+
// - one whose agentrun.run label names a run in this server's store (or, where the provider keeps only the run's hash,
|
|
8
|
+
// agentrun.run.hash is the hash of one): a vendor account or a Docker host shared with another server lists that
|
|
9
|
+
// server's computers too, and they are never touched;
|
|
10
|
+
// - never one a claim holds, at the computer's own epoch: whether a claim holds the run now is the store's to say
|
|
11
|
+
// (runs.heldAt), by its own clock, never this process's. A claim that ran out holds nothing, so a run a crashed runner
|
|
12
|
+
// left parked under its name still has its computer swept at the deadline;
|
|
13
|
+
// - past its deadline, by the computer package's sweep (janitor.ts): the deadline label, or over the provider's cap.
|
|
14
|
+
// What a computer leaves outside itself (Docker's egress parts) goes with its release; the provider's sweepLeftovers is
|
|
15
|
+
// not asked, since it reads labels alone and can't tell this server's parts from another's.
|
|
16
|
+
//
|
|
17
|
+
// A provider whose sweep fails is logged, once per distinct failure, and the others are swept. It runs only where its
|
|
18
|
+
// start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
|
|
19
|
+
// close cuts a sweep under way and waits for it on a bound of its own (JANITOR_CLOSE_MS), so a stuck vendor call never
|
|
20
|
+
// holds up the runner's stop.
|
|
21
|
+
import { epochOf, ok, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
|
|
22
|
+
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
23
|
+
import { FAUX_ENV } from "../model.js";
|
|
24
|
+
import { storeLedger } from "./computer-ledger.js";
|
|
25
|
+
import { providerKeys } from "./resolve-computer.js";
|
|
26
|
+
/** How often the janitor sweeps after its first sweep at the runner's start. */
|
|
27
|
+
export const JANITOR_EVERY_MS = 10 * 60_000;
|
|
28
|
+
/** The longest close() waits for a sweep it cut: a vendor call that ignores the cut is left to finish on its own. */
|
|
29
|
+
export const JANITOR_CLOSE_MS = 5_000;
|
|
30
|
+
/** The longest one provider's sweep may take: past it the sweep is cut and left, said as a timeout, and the next provider
|
|
31
|
+
* is swept, so a stuck vendor (a Docker command has no timeout of its own) never stops the others or later sweeps. */
|
|
32
|
+
export const JANITOR_PROVIDER_MS = 5 * 60_000;
|
|
33
|
+
const runsByHash = (store) => {
|
|
34
|
+
let read;
|
|
35
|
+
return () => (read ??= store.runs.list({}).then((rows) => new Map(rows.map((row) => [runHash(row.id), row.id]))));
|
|
36
|
+
};
|
|
37
|
+
/** Whether a listed computer is this server's and no claim holds it: its run (by its label, or its hash's) is in this
|
|
38
|
+
* store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's. */
|
|
39
|
+
async function sweepable(store, labels, byHash) {
|
|
40
|
+
const named = labels[RUN_LABEL];
|
|
41
|
+
const hash = labels[RUN_HASH_LABEL];
|
|
42
|
+
const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
|
|
43
|
+
if (runId === undefined)
|
|
44
|
+
return false;
|
|
45
|
+
const run = await store.runs.get(runId);
|
|
46
|
+
// No such run here: another server's computer.
|
|
47
|
+
if (!run)
|
|
48
|
+
return false;
|
|
49
|
+
const held = await store.runs.heldAt(run.id);
|
|
50
|
+
if (held === undefined)
|
|
51
|
+
return true;
|
|
52
|
+
// A claim holds its own epoch's computer; one of an older epoch is a lost claim's (releaseOlder's too).
|
|
53
|
+
const epoch = epochOf(labels);
|
|
54
|
+
return epoch.ok && epoch.value < held;
|
|
55
|
+
}
|
|
56
|
+
/** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and no leftovers pass.
|
|
57
|
+
* Each call goes to the provider itself, so its own state is used as it is. */
|
|
58
|
+
function thisServers(provider, store, byHash) {
|
|
59
|
+
return {
|
|
60
|
+
id: provider.id,
|
|
61
|
+
version: provider.version,
|
|
62
|
+
capabilities: () => provider.capabilities(),
|
|
63
|
+
check: (spec) => provider.check(spec),
|
|
64
|
+
create: (spec, context) => provider.create(spec, context),
|
|
65
|
+
attach: (target, context) => provider.attach(target, context),
|
|
66
|
+
network: (ref, policy, context) => provider.network(ref, policy, context),
|
|
67
|
+
connect: (ref) => provider.connect(ref),
|
|
68
|
+
release: (ref, how) => provider.release(ref, how),
|
|
69
|
+
async list(labels, context) {
|
|
70
|
+
const listed = await provider.list(labels, context);
|
|
71
|
+
if (!listed.ok)
|
|
72
|
+
return listed;
|
|
73
|
+
const kept = [];
|
|
74
|
+
for (const info of listed.value)
|
|
75
|
+
if (await sweepable(store, info.labels, byHash))
|
|
76
|
+
kept.push(info);
|
|
77
|
+
return ok(kept);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** `work` given a signal cut at `ms` (or with `signal`), answered at the cut whether or not `work` heeds it: a call that
|
|
82
|
+
* ignores it is left to finish on its own, and the answer is a timeout (or aborted) in words. */
|
|
83
|
+
async function bounded(ms, signal, work) {
|
|
84
|
+
const timer = AbortSignal.timeout(ms);
|
|
85
|
+
const cut = signal ? AbortSignal.any([signal, timer]) : timer;
|
|
86
|
+
let stop = () => { };
|
|
87
|
+
const given = new Promise((resolve) => {
|
|
88
|
+
stop = () => resolve(timer.aborted ? { ok: false, error: { code: "timeout", message: `its sweep took longer than ${ms / 1000} s and was left` } } : { ok: false, error: { code: "aborted", message: "the sweep was cut" } });
|
|
89
|
+
cut.addEventListener("abort", stop, { once: true });
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
return await Promise.race([work(cut), given]);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
cut.removeEventListener("abort", stop);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** One sweep of every provider this server can list: each provider whose keys it has and whose computers the janitor
|
|
99
|
+
* ends, its computers past their deadline that are this server's and unheld ended. A provider that fails is answered
|
|
100
|
+
* in its words; nothing throws. */
|
|
101
|
+
export async function sweepServerComputers(deps, signal) {
|
|
102
|
+
const { store, computers } = deps;
|
|
103
|
+
const at = (deps.now ?? Date.now)();
|
|
104
|
+
const keysOf = providerKeys(computers.kinds, computers.keyOf ?? (async () => undefined));
|
|
105
|
+
const byHash = runsByHash(store);
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const entry of computers.kinds.PROVIDERS) {
|
|
108
|
+
if (signal?.aborted)
|
|
109
|
+
break;
|
|
110
|
+
const make = Object.hasOwn(computers.providers, entry.id) ? computers.providers[entry.id] : undefined;
|
|
111
|
+
if (!make)
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
// Its keys not here: nothing of this server's can be listed there. A key that can't be read is this provider's
|
|
115
|
+
// failure alone.
|
|
116
|
+
const options = providerOptions(entry.id, await keysOf(entry.id), computers.settings ?? {}, computers.keyTable ?? KEY_TABLE);
|
|
117
|
+
if (!options.ok)
|
|
118
|
+
continue;
|
|
119
|
+
const provider = await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) });
|
|
120
|
+
// A vendor that ends its own computers needs no janitor.
|
|
121
|
+
if (provider.capabilities().lifetime !== "janitor")
|
|
122
|
+
continue;
|
|
123
|
+
out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash), { now: new Date(at), signal: cut })) });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
/** The janitor: one sweep now, then one every `everyMs`, never two at once. `close()` stops it, cuts a sweep under way
|
|
132
|
+
* and waits for it at most `closeMs`. Under --faux it does nothing. */
|
|
133
|
+
export function startJanitor(deps) {
|
|
134
|
+
if (deps.env[FAUX_ENV])
|
|
135
|
+
return { first: Promise.resolve(), close: async () => { } };
|
|
136
|
+
/** The last failure said per provider: a failure is said once, until it changes or the provider sweeps again. */
|
|
137
|
+
const said = new Map();
|
|
138
|
+
const cut = new AbortController();
|
|
139
|
+
let running;
|
|
140
|
+
const once = () => (running ??= (async () => {
|
|
141
|
+
try {
|
|
142
|
+
for (const { provider, swept } of await sweepServerComputers(deps, cut.signal)) {
|
|
143
|
+
// A sweep the close cut says nothing more.
|
|
144
|
+
if (cut.signal.aborted)
|
|
145
|
+
break;
|
|
146
|
+
if (!swept.ok) {
|
|
147
|
+
const words = `${swept.error.code}: ${swept.error.message}`;
|
|
148
|
+
if (said.get(provider) !== words)
|
|
149
|
+
deps.log(`the computer janitor could not sweep ${provider}'s computers: ${swept.error.message}`);
|
|
150
|
+
said.set(provider, words);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
said.delete(provider);
|
|
154
|
+
if (swept.value.deleted.length > 0)
|
|
155
|
+
deps.log(`the computer janitor ended ${provider}'s computers past their deadline: ${swept.value.deleted.join(", ")}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (!cut.signal.aborted)
|
|
160
|
+
deps.log(`the computer janitor's sweep failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
running = undefined;
|
|
164
|
+
}
|
|
165
|
+
})());
|
|
166
|
+
const first = once();
|
|
167
|
+
const timer = setInterval(() => void (cut.signal.aborted || running || once()), deps.everyMs ?? JANITOR_EVERY_MS);
|
|
168
|
+
timer.unref();
|
|
169
|
+
return {
|
|
170
|
+
first,
|
|
171
|
+
async close() {
|
|
172
|
+
cut.abort();
|
|
173
|
+
clearInterval(timer);
|
|
174
|
+
if (!running)
|
|
175
|
+
return;
|
|
176
|
+
// A vendor call that ignores the cut (a release takes no signal) is left to finish on its own after this bound.
|
|
177
|
+
let bound;
|
|
178
|
+
await Promise.race([running, new Promise((resolve) => (bound = setTimeout(resolve, deps.closeMs ?? JANITOR_CLOSE_MS)))]);
|
|
179
|
+
clearTimeout(bound);
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export type GrepJob = {
|
|
2
2
|
readonly dir: string;
|
|
3
|
+
/** `dir`'s path below the root (or the file's, with `only`): each match's path starts with it. */
|
|
3
4
|
readonly rel: string;
|
|
5
|
+
/** Whether `dir` is /proc/self/fd/<fd> (Linux): else a path, and every entry is opened by `rel` below `root`. */
|
|
6
|
+
readonly procFd: boolean;
|
|
7
|
+
/** The workspace's root, its real path. */
|
|
8
|
+
readonly root: string;
|
|
4
9
|
readonly only?: string;
|
|
5
10
|
readonly pattern: string;
|
|
6
11
|
readonly glob?: string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// LocalWorkspace's grep, in a worker thread: the caller's regex runs here, so one that backtracks without end blocks
|
|
2
2
|
// this thread, never the runner's, and local.ts terminates it at the deadline. It searches the folder `dir` names (on
|
|
3
3
|
// Linux, /proc/self/fd/<fd> of a folder local.ts holds open for it), or the one file `only` in it, opening every entry
|
|
4
|
-
// with O_NOFOLLOW: a link is skipped, never followed.
|
|
5
|
-
// `
|
|
4
|
+
// with O_NOFOLLOW: a link is skipped, never followed. Off /proc/self/fd (macOS), where `dir` is a path the box can swap
|
|
5
|
+
// for a link mid-search, each entry is opened by its path below `root` through no link anywhere on the way (beneath.ts:
|
|
6
|
+
// macOS's O_NOFOLLOW_ANY), so a link swapped in fails the open and the entry is skipped: no byte from outside is read.
|
|
7
|
+
// Each match is posted as it is found; the last message is `{ done: false | "max" }`.
|
|
6
8
|
import { closeSync, constants, fstatSync, openSync, readdirSync, readSync } from "node:fs";
|
|
7
9
|
import { parentPort, workerData } from "node:worker_threads";
|
|
10
|
+
import { openBeneathSync } from "./beneath.js";
|
|
8
11
|
import { globRegex } from "./glob.js";
|
|
9
12
|
const { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } = constants;
|
|
10
|
-
const LINUX = process.platform === "linux";
|
|
11
13
|
const sorted = (names) => names.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
12
14
|
function run(job, post) {
|
|
13
15
|
const regex = new RegExp(job.pattern);
|
|
@@ -43,11 +45,12 @@ function run(job, post) {
|
|
|
43
45
|
post({ matches: [match] });
|
|
44
46
|
}
|
|
45
47
|
};
|
|
46
|
-
/** Entry `name` of folder `dir
|
|
48
|
+
/** Entry `name` of folder `dir` (`rel` below the root), opened without following a link (off /proc/self/fd, none on
|
|
49
|
+
* the way either), searched if it is a file or a folder. */
|
|
47
50
|
const searchEntry = (dir, name, rel) => {
|
|
48
51
|
let fd;
|
|
49
52
|
try {
|
|
50
|
-
fd = openSync(`${dir}/${name}`, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
53
|
+
fd = job.procFd ? openSync(`${dir}/${name}`, O_RDONLY | O_NOFOLLOW | O_NONBLOCK) : openBeneathSync(job.root, rel, O_RDONLY | O_NONBLOCK);
|
|
51
54
|
}
|
|
52
55
|
catch {
|
|
53
56
|
return;
|
|
@@ -55,7 +58,7 @@ function run(job, post) {
|
|
|
55
58
|
try {
|
|
56
59
|
const stats = fstatSync(fd);
|
|
57
60
|
if (stats.isDirectory())
|
|
58
|
-
searchDir(
|
|
61
|
+
searchDir(job.procFd ? `/proc/self/fd/${fd}` : `${dir}/${name}`, rel);
|
|
59
62
|
else if (stats.isFile())
|
|
60
63
|
searchFile(fd, stats.size, rel, name);
|
|
61
64
|
}
|
|
@@ -13,11 +13,12 @@ export { readOnlyWorkspace, SERVER_READS_ONLY, serverRunWorkspace, type ServerRu
|
|
|
13
13
|
export { type LedgerEntry, type PhoneLedger, type PhoneLedgerEntry, phoneLedger, type ProviderLedger, storeLedger } from "./computer-ledger.js";
|
|
14
14
|
export { type LearningPlace, type LearningWorkspace, learningWorkspace, type LearningWorkspaceOptions } from "./learning-workspace.js";
|
|
15
15
|
export { ARCHIL_MAX_EXEC_S, type Hands, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
|
|
16
|
-
export { type
|
|
16
|
+
export { type RunComputer, type RunHold, runTools, type RunTools, withKindTools } from "./run-tools.js";
|
|
17
17
|
export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
|
|
18
18
|
export { type ClaimSide, computerReadiness, type ComputerSetting, type ComputerSettingKind, type KindCapabilities, type KindRegistry, type LaunchedComputer, type Port, type ProviderEntry, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
|
|
19
19
|
export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
|
|
20
20
|
export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
|
21
|
-
export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ImageWait, type OpenComputerView, type ProviderMakers,
|
|
21
|
+
export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
|
|
22
|
+
export { JANITOR_EVERY_MS, type JanitorDeps, type ProviderSweep, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
|
22
23
|
export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
|
|
23
24
|
export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind } from "./kind-skills.js";
|
package/dist/workspace/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// The Workspace port (workspace.ts), its folder layout (paths.ts), attach to a computer (attach.ts), where a run's
|
|
2
|
-
// tools run (place.ts), the local backend and the Archil one.
|
|
3
|
-
// that moves every writer onto it.
|
|
2
|
+
// tools run (place.ts), the local backend and the Archil one.
|
|
4
3
|
export * from "./workspace.js";
|
|
5
4
|
export { attachedWorkspace, checkReadBack, COMPUTER_CHUNK, NO_COMPUTER, noProcesses, } from "./attach.js";
|
|
6
5
|
export { agentDirName, agentFolder, agentHomeFolder, agentLearningFolder, COMPUTER_ROOT, DISK_DIR, homeKey, learningKey, portPath, relativePath, relativeSegments, runFolder, runKey, scratchFolder, } from "./paths.js";
|
|
@@ -20,6 +19,7 @@ export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
|
|
|
20
19
|
export { computerReadiness, resolveComputer, runShellOf, shellPlaceOf, } from "./resolve-computer.js";
|
|
21
20
|
export { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
22
21
|
export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
|
23
|
-
export { computerForClaim
|
|
22
|
+
export { computerForClaim } from "./computer-for-claim.js";
|
|
23
|
+
export { JANITOR_EVERY_MS, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
|
24
24
|
export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
|
|
25
25
|
export { KIND_SKILLS, kindSkillOf } from "./kind-skills.js";
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { type Workspace } from "./workspace.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type LocalWorkspaceOptions = {
|
|
3
|
+
/** A name below a held folder resolves through /proc/self/fd/<fd> (default: on Linux, where it is there). false takes
|
|
4
|
+
* the branch every other platform (macOS) takes, which resolves paths again and checks each one (the file's head). */
|
|
5
|
+
readonly procFd?: boolean;
|
|
6
|
+
/** A test's hook: called each time a folder below the root is held, with its path, before anything is done in it:
|
|
7
|
+
* where another process's swap of that folder for a link would land. */
|
|
8
|
+
readonly onHeld?: (abs: string) => void | Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
/** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
|
|
11
|
+
* `options` are a test's: the path-resolving branch forced, and a hook where a swap would land. */
|
|
12
|
+
export declare const localWorkspace: (root: string, options?: LocalWorkspaceOptions) => Workspace;
|
|
4
13
|
/** `work` as a Workspace: a folder of this machine, by its path, becomes its LocalWorkspace. For the callers that still
|
|
5
14
|
* hand a run's folder by its path (the run's start and its process), until they hand the run's Workspace. */
|
|
6
15
|
export declare const workspaceAt: (work: string | Workspace) => Workspace;
|