@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.45
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 +131 -5
- package/README.md +371 -300
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +52 -16
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +87 -102
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +13 -1
- package/dist/learn/promote.js +9 -0
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +268 -316
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +16 -8
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +63 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +8 -6
- package/dist/runner/promotion.js +19 -12
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +685 -320
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +60 -5
- package/dist/triggers.js +123 -18
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
|
@@ -1,49 +1,31 @@
|
|
|
1
|
-
import type { LearningFolder } from "../learn/folder.js";
|
|
2
1
|
import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
|
|
3
|
-
import type {
|
|
2
|
+
import type { LearningFolder } from "../learn/folder.js";
|
|
3
|
+
/** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
|
|
4
|
+
* the read and ended after it), the server's secrets as cuts (`shown`), its log, and `workflows: false` for a run that
|
|
5
|
+
* takes none (an SDK run with no workflow binding). */
|
|
4
6
|
export interface LearningSeedLay {
|
|
5
|
-
/** The run's Workspace: its work, where `.learning/` and `.agents/skills/` are. */
|
|
6
|
-
readonly work: Workspace;
|
|
7
|
-
/** The commit the run's learning start pinned (null: the folder had no main yet, an empty seed). */
|
|
8
7
|
readonly seed: string | null;
|
|
9
|
-
/** The agent's learning folder where the run's place keeps it, opened for this one read and ended after it. */
|
|
10
8
|
readonly folder: () => LearningFolder;
|
|
11
|
-
/** The revision's own skill files, by their paths under `.agents/skills/` (laid already): a learned skill named like
|
|
12
|
-
* one of them is the revision's and is not laid. */
|
|
13
|
-
readonly own: readonly string[];
|
|
14
|
-
/** The server's secrets as a reader cuts them, read at the claim. */
|
|
15
9
|
readonly shown: () => Promise<Shown>;
|
|
16
|
-
/** One line of the run's log. */
|
|
17
10
|
readonly log: (line: string) => void;
|
|
18
|
-
/** False for a run of a revision that says `learning: "notes"`: its notes and skills are laid, never a learned workflow. */
|
|
19
11
|
readonly workflows?: false;
|
|
20
|
-
/** The notes its # Learned section names in no way, over the learning budget (the launch's `notesLeftOut`), by file:
|
|
21
|
-
* said in the run's log, so a run that read only some of what its agent learned says which it did not. */
|
|
22
|
-
readonly notesLeftOut?: readonly string[];
|
|
23
12
|
}
|
|
24
|
-
/**
|
|
25
|
-
export declare const LEFT_OUT_NAMED = 100;
|
|
26
|
-
/** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
|
|
27
|
-
export declare const notesLeftOutLine: (files: readonly string[] | undefined) => string | undefined;
|
|
28
|
-
/** What the claim laid of the run's seed: the seed it read, the learned skills' files it laid, by their paths under
|
|
29
|
-
* `.agents/skills/`, for the skill list the run's harness is handed beside the revision's own, and the learned workflows
|
|
30
|
-
* the run's learned_workflow tool runs, cut of the server's secrets as the skills are (none of either when the lay
|
|
31
|
-
* failed part way and was taken back). */
|
|
13
|
+
/** What a claim read of a run's seed: the seed, and the learned workflows the run's learned_workflow tool runs. */
|
|
32
14
|
export type LaidSeed = {
|
|
33
15
|
readonly seed: Seed;
|
|
34
|
-
readonly skills: readonly string[];
|
|
35
16
|
readonly workflows: readonly LearnedWorkflow[];
|
|
36
17
|
};
|
|
37
|
-
/** What a claim
|
|
38
|
-
*
|
|
18
|
+
/** What a claim handed a run of its seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
|
|
19
|
+
* workflow it handed the tool; none when nothing was read. */
|
|
39
20
|
export declare const laidOf: (laid: LaidSeed | undefined) => {
|
|
40
|
-
skills: string[];
|
|
41
21
|
workflows: string[];
|
|
42
22
|
};
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
23
|
+
/** The run's seed and its learned workflows. Undefined when the seed could not be read: the run starts with none. A
|
|
24
|
+
* secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
|
|
25
|
+
* throws: a learning fault never stops a run. */
|
|
45
26
|
export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed | undefined>;
|
|
46
|
-
/** The learned workflows the folder held active at `commit`, as a claim's
|
|
47
|
-
* (chooseWorkflows
|
|
48
|
-
* is
|
|
49
|
-
|
|
27
|
+
/** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
|
|
28
|
+
* (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
|
|
29
|
+
* what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
|
|
30
|
+
* commit is gone. */
|
|
31
|
+
export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown">, commit: string | null): Promise<LearnedWorkflow[]>;
|
|
@@ -1,71 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const more = files.length > LEFT_OUT_NAMED ? `, and ${files.length - LEFT_OUT_NAMED} more` : "";
|
|
10
|
-
return `starts without ${files.length} of the notes its agent learned in its # Learned section, over the learning budget (the notes that bear most on it are given whole; the rest stay in ${LEARNED_DIR}/): ${named}${more}`;
|
|
11
|
-
};
|
|
1
|
+
// A claim's read of a run's learning seed: the learned workflows its learning folder held active at the commit the run
|
|
2
|
+
// started from, which the run's learned_workflow tool runs and workflow-first serves (learning.ts chooseWorkflows: within
|
|
3
|
+
// the tool's budget, none holding a host secret). Nothing is laid in the run's work: its corrections reach it in its
|
|
4
|
+
// instructions (learning.ts laidLearned, from the launch's learning start).
|
|
5
|
+
import { chooseWorkflows, seedAt } from "../learning.js";
|
|
6
|
+
/** What a claim handed a run of its seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
|
|
7
|
+
* workflow it handed the tool; none when nothing was read. */
|
|
8
|
+
export const laidOf = (laid) => ({ workflows: (laid?.workflows ?? []).map(({ name }) => name) });
|
|
12
9
|
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
skills: [...new Set((laid?.skills ?? []).map((path) => path.split("/")[0]))],
|
|
17
|
-
workflows: (laid?.workflows ?? []).map(({ name }) => name),
|
|
18
|
-
});
|
|
19
|
-
/** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
|
|
20
|
-
* Never throws. */
|
|
10
|
+
/** The run's seed and its learned workflows. Undefined when the seed could not be read: the run starts with none. A
|
|
11
|
+
* secrets read (or a choice) that fails after the seed was read answers the seed with no learned workflow. Never
|
|
12
|
+
* throws: a learning fault never stops a run. */
|
|
21
13
|
export async function layLearningSeed(lay) {
|
|
22
14
|
let seed;
|
|
23
15
|
const folder = lay.folder();
|
|
24
16
|
try {
|
|
25
|
-
seed = await
|
|
17
|
+
seed = await seedAt(folder.workspace, lay.seed);
|
|
26
18
|
}
|
|
27
19
|
catch (error) {
|
|
28
|
-
lay.log(`the run starts with
|
|
20
|
+
lay.log(`the run starts with no learned workflow: ${message(error)}`);
|
|
29
21
|
return undefined;
|
|
30
22
|
}
|
|
31
23
|
finally {
|
|
32
24
|
await folder.end().catch(() => undefined);
|
|
33
25
|
}
|
|
34
|
-
|
|
26
|
+
if (lay.workflows === false)
|
|
27
|
+
return { seed, workflows: [] };
|
|
35
28
|
try {
|
|
36
|
-
const
|
|
37
|
-
await layLearned(lay.work, seed, shown);
|
|
38
|
-
const { taken, left } = await chooseSkills(lay.work, seed, lay.own, shown);
|
|
39
|
-
await laySkills(lay.work, taken, made);
|
|
40
|
-
for (const path of seed.skipped)
|
|
41
|
-
lay.log(`its learning folder's ${path} was not read`);
|
|
42
|
-
const leftOut = notesLeftOutLine(lay.notesLeftOut);
|
|
43
|
-
if (leftOut)
|
|
44
|
-
lay.log(leftOut);
|
|
29
|
+
const { flows, left } = chooseWorkflows(seed, await lay.shown());
|
|
45
30
|
for (const name of left)
|
|
46
|
-
lay.log(`starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
|
|
47
|
-
const workflows = lay.workflows === false ? { flows: [], left: [] } : chooseWorkflows(seed, shown);
|
|
48
|
-
for (const name of workflows.left)
|
|
49
31
|
lay.log(`starts without the learned workflow ${name} its agent learned: it is over what is left of the learned workflows' budget, or holds a secret`);
|
|
50
|
-
return { seed,
|
|
32
|
+
return { seed, workflows: flows };
|
|
51
33
|
}
|
|
52
34
|
catch (error) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
await lay.work.remove(LEARNED_DIR, { recursive: true, force: true }).catch(() => undefined);
|
|
56
|
-
await takeSkills(lay.work, made).catch(() => undefined);
|
|
57
|
-
lay.log(`the run starts with nothing learned laid in its work: ${message(error)}`);
|
|
58
|
-
return { seed, skills: [], workflows: [] };
|
|
35
|
+
lay.log(`the run starts with no learned workflow: ${message(error)}`);
|
|
36
|
+
return { seed, workflows: [] };
|
|
59
37
|
}
|
|
60
38
|
}
|
|
61
|
-
/** The learned workflows the folder held active at `commit`, as a claim's
|
|
62
|
-
* (chooseWorkflows
|
|
63
|
-
* is
|
|
39
|
+
/** The learned workflows the folder held active at `commit`, as a claim's read hands them to the learned_workflow tool
|
|
40
|
+
* (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
|
|
41
|
+
* what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
|
|
42
|
+
* commit is gone. */
|
|
64
43
|
export async function workflowsAt(read, commit) {
|
|
65
44
|
const folder = read.folder();
|
|
66
45
|
let seed;
|
|
67
46
|
try {
|
|
68
|
-
seed = await
|
|
47
|
+
seed = await seedAt(folder.workspace, commit);
|
|
69
48
|
}
|
|
70
49
|
finally {
|
|
71
50
|
await folder.end().catch(() => undefined);
|
|
@@ -30,9 +30,8 @@ export type EndOfRunAnswer = ({
|
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* The end-of-run step (the learning lane's end-of-run turn): asked once, after the job's last turn ended and before the
|
|
33
|
-
* loop writes the run's end. `ask` sends one more turn through the run's own session
|
|
34
|
-
*
|
|
35
|
-
* `deadlineMs`. The rows it returns are staged into the end commit, so they land in that commit's one transaction or not
|
|
33
|
+
* loop writes the run's end. `ask` sends one more turn through the run's own session (the compile turn's attempts),
|
|
34
|
+
* its origin `reflect`, aborted at `deadlineMs`. The rows it returns are staged into the end commit, so they land in that commit's one transaction or not
|
|
36
35
|
* at all. A stop or a lost claim aborts `signal`: no end is written, and the next claim asks again (the turn's request
|
|
37
36
|
* id is one per run, so its model is asked once).
|
|
38
37
|
*/
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type HostedDial } from "@parcha/agentrun-computer";
|
|
1
2
|
import { type Store } from "../store/index.js";
|
|
2
3
|
import { type KeyEnv } from "../key-meta.js";
|
|
3
4
|
import { type ComputerDeps, type ComputerDepsOptions } from "../workspace/computer-deps.js";
|
|
4
5
|
import type { LoopFactory } from "./loop-contract.js";
|
|
6
|
+
import { type RunIsolation } from "./run-child-host.js";
|
|
5
7
|
import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
|
|
6
8
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
7
9
|
export interface RunnerProcessOptions {
|
|
@@ -14,10 +16,14 @@ export interface RunnerProcessOptions {
|
|
|
14
16
|
/** Its memory budget and its runs' weights (RunnerOptions.memory). Default: this host's memory, each run weighed by its
|
|
15
17
|
* harness (memory-claim.ts runnerMemory). */
|
|
16
18
|
memory?: RunnerMemory;
|
|
19
|
+
/** With the default memory: what each run's own process weighs beside its harness's run (memory-claim.ts
|
|
20
|
+
* RUN_PROCESS_MIB), for a runner whose runs are each a process of their own. Default 0. */
|
|
21
|
+
processMib?: number;
|
|
17
22
|
/** This runner's name in the runs it claims, its lines and its heartbeat. Default runner.ts runnerName(). */
|
|
18
23
|
name?: string;
|
|
19
|
-
/** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed.
|
|
20
|
-
|
|
24
|
+
/** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed.
|
|
25
|
+
* A factory of the store is given the runner's dial too, where it has a relay (dial-relay.ts). */
|
|
26
|
+
createLoop?: LoopFactory | ((store: Store, sealKey: Buffer, dial?: HostedDial) => LoopFactory | RunnerParts);
|
|
21
27
|
/** Run the computer janitor (workspace/computer-janitor.ts) over the computers createLoop composed: at the start, then
|
|
22
28
|
* on its interval. Only the runner subcommand asks for it; a test that does not ask runs none. */
|
|
23
29
|
janitor?: boolean;
|
|
@@ -83,7 +89,7 @@ export declare function besideRunEnv(env: NodeJS.ProcessEnv, switches: NodeJS.Pr
|
|
|
83
89
|
* its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
|
|
84
90
|
* journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
|
|
85
91
|
* this process's, as it was handed or booted). Refused in words with no seal key. */
|
|
86
|
-
export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): RunnerParts;
|
|
92
|
+
export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer, isolation?: RunIsolation, dial?: HostedDial): RunnerParts;
|
|
87
93
|
/** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
|
|
88
94
|
* (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
|
|
89
95
|
* process runs on, its container's in a container), never at `own`: the port a server listens on unless --port says
|
|
@@ -116,8 +122,8 @@ export declare function checkRunner(options: {
|
|
|
116
122
|
};
|
|
117
123
|
/** Opens the store as a runner and starts claiming runs. */
|
|
118
124
|
export declare function startRunnerProcess(options: RunnerProcessOptions): Promise<RunnerProcess>;
|
|
119
|
-
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
|
|
120
|
-
export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer) => Made): (store: Store, sealKey: Buffer) => Made;
|
|
125
|
+
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens, and its relay's dial). */
|
|
126
|
+
export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer, dial?: HostedDial) => Made): (store: Store, sealKey: Buffer, dial?: HostedDial) => Made;
|
|
121
127
|
/** How long a runner process lets each busy run finish its turn on SIGTERM, unless --drain-timeout or
|
|
122
128
|
* AGENTRUN_DRAIN_TIMEOUT says: the image's server drain (its CMD's --drain-timeout 6s), so a runner beside a --no-runner
|
|
123
129
|
* server drains as the server's own runner would.
|
|
@@ -138,16 +144,18 @@ export declare function runnerHolds(args: {
|
|
|
138
144
|
loops: number;
|
|
139
145
|
drainMs: number;
|
|
140
146
|
};
|
|
141
|
-
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or
|
|
142
|
-
* [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
|
|
143
|
-
* with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
|
|
144
|
-
* test switch, as the server's own --faux; the only way a runner loads one.
|
|
147
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]]`, or
|
|
148
|
+
* `--check --data D [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
|
|
149
|
+
* directory that starts with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
|
|
150
|
+
* faux model module, a test switch, as the server's own --faux; the only way a runner loads one. `--faux-browser`: the
|
|
151
|
+
* fake browser's module, with --faux only, as the server's. */
|
|
145
152
|
export declare function runnerArgs(argv: readonly string[]): {
|
|
146
153
|
dataDir: string;
|
|
147
154
|
loops?: number;
|
|
148
155
|
drainMs?: number;
|
|
149
156
|
name?: string;
|
|
150
157
|
faux?: string;
|
|
158
|
+
fauxBrowser?: string;
|
|
151
159
|
check?: true;
|
|
152
160
|
harnessModules?: string[];
|
|
153
161
|
};
|
package/dist/runner/main.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
14
14
|
import { join, resolve } from "node:path";
|
|
15
15
|
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
16
|
+
import { startRunnerRelay } from "../dial-relay.js";
|
|
16
17
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
17
18
|
import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
|
|
18
19
|
import { dockerPathsForRuns } from "../box-paths.js";
|
|
@@ -28,6 +29,7 @@ import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
|
28
29
|
import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
|
|
29
30
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
30
31
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
32
|
+
import { FAUX_BROWSER_ENV } from "../tools.js";
|
|
31
33
|
import { claimViewOpener } from "../computer-live.js";
|
|
32
34
|
import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
|
|
33
35
|
import { LOOPBACK } from "../mcp-oauth.js";
|
|
@@ -41,7 +43,8 @@ import { runEndComputers } from "../workspace/run-end-computers.js";
|
|
|
41
43
|
import { createDispatchLoop } from "./dispatch.js";
|
|
42
44
|
import { resolveRunnerLoop } from "./harness-loops.js";
|
|
43
45
|
import { routeOf } from "./model-route.js";
|
|
44
|
-
import { runnerMemory } from "./memory-claim.js";
|
|
46
|
+
import { RUN_PROCESS_MIB, runnerMemory } from "./memory-claim.js";
|
|
47
|
+
import { childLoops, isolationLoops, RunIsolationRefused, runIsolationOf } from "./run-child-host.js";
|
|
45
48
|
import { sweepEndedScratch } from "./scratch-sweep.js";
|
|
46
49
|
import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
|
|
47
50
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
@@ -119,7 +122,7 @@ export function besideRunEnv(env, switches) {
|
|
|
119
122
|
* its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
|
|
120
123
|
* journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
|
|
121
124
|
* this process's, as it was handed or booted). Refused in words with no seal key. */
|
|
122
|
-
export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
125
|
+
export function runnerLoop(store, dataDir, env = process.env, booted, isolation, dial) {
|
|
123
126
|
const sealKey = booted ?? sealKeyOf(secret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV]);
|
|
124
127
|
if (!sealKey)
|
|
125
128
|
throw new RunnerRefused(`A runner needs the server's seal key (${SEAL_KEY_ENV}): start it through the server's launcher, which hands it over.`);
|
|
@@ -127,8 +130,9 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
127
130
|
// The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
|
|
128
131
|
// agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
|
|
129
132
|
// mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
|
|
130
|
-
// view opened with it.
|
|
131
|
-
|
|
133
|
+
// view opened with it. A machine that dials goes to this runner's own hub, through the server's relay (`dial`, its
|
|
134
|
+
// relay's: dial-relay.ts); with none, its provider refuses.
|
|
135
|
+
const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(dial ? { dial } : {}) });
|
|
132
136
|
const loopback = runnerLoopback(env);
|
|
133
137
|
if (loopback)
|
|
134
138
|
process.stderr.write(`agentrun-serve runner: ${MCP_ALLOW_LOOPBACK_ENV}=1: this runner's runs may reach an MCP server on this machine's loopback, never at ${loopback.own.join(" or ")} nor where its server listens\n`);
|
|
@@ -143,7 +147,10 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
143
147
|
// The server's own addresses, as it kept them in the store at its last start, are read at each claim beside these.
|
|
144
148
|
...(loopback ? { mcpLoopback: true, mcpOwn: loopback.own, mcpOwnOf: () => serverOwn(store) } : {}),
|
|
145
149
|
};
|
|
146
|
-
|
|
150
|
+
// `isolation`: each run a process of its own (run-child-host.ts), as the runner subcommand runs them; none, in this one
|
|
151
|
+
// (a test's runner).
|
|
152
|
+
const createLoop = isolation ? childLoops({ deps, isolation, log: deps.log }) : createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) });
|
|
153
|
+
return { createLoop, computers: computers.computerDeps, env: runs };
|
|
147
154
|
}
|
|
148
155
|
/** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
|
|
149
156
|
* (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
|
|
@@ -179,7 +186,7 @@ function heartbeat(dataDir, name, now) {
|
|
|
179
186
|
}
|
|
180
187
|
catch {
|
|
181
188
|
mkdirSync(dataDir, { recursive: true });
|
|
182
|
-
writeFileSync(file, `${name}\n
|
|
189
|
+
writeFileSync(file, `${name}\n`, { mode: 0o600 });
|
|
183
190
|
utimesSync(file, seconds, seconds);
|
|
184
191
|
}
|
|
185
192
|
};
|
|
@@ -205,10 +212,11 @@ export async function startRunnerProcess(options) {
|
|
|
205
212
|
const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
|
|
206
213
|
const env = options.env ?? process.env;
|
|
207
214
|
const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
|
|
208
|
-
const memory = options.memory ?? runnerMemory(store, undefined, env);
|
|
215
|
+
const memory = options.memory ?? runnerMemory(store, undefined, env, options.processMib ?? 0);
|
|
209
216
|
let runner;
|
|
210
217
|
let seal;
|
|
211
218
|
let janitor;
|
|
219
|
+
let relay;
|
|
212
220
|
try {
|
|
213
221
|
// The server's seal key, booted the one way the server boots it (seal-key.ts): the one handed over, else the one in
|
|
214
222
|
// this data directory, checked against what the store records. A runner on a store whose secrets another key sealed
|
|
@@ -216,9 +224,12 @@ export async function startRunnerProcess(options) {
|
|
|
216
224
|
// or records a key.
|
|
217
225
|
seal = await bootSealKey(store, options.dataDir, { given: handedSecret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV], role: "runner" });
|
|
218
226
|
const name = options.name ?? runnerName();
|
|
219
|
-
|
|
227
|
+
// Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
|
|
228
|
+
// server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
|
|
229
|
+
relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, env, log: warn });
|
|
230
|
+
const made = options.createLoop ?? ofStore((opened, sealKey, dial) => runnerLoop(opened, options.dataDir, undefined, sealKey, undefined, dial));
|
|
220
231
|
// A factory of the store (marked by ofStore) is given the store; a loop factory is used as is.
|
|
221
|
-
const parts = isStoreFactory(made) ? made(store, seal.key) : made;
|
|
232
|
+
const parts = isStoreFactory(made) ? made(store, seal.key, relay?.dial) : made;
|
|
222
233
|
const createLoop = typeof parts === "function" ? parts : parts.createLoop;
|
|
223
234
|
// The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
|
|
224
235
|
// warnings, said where the runner says its others (warn: stderr unless a test gives its own).
|
|
@@ -242,12 +253,14 @@ export async function startRunnerProcess(options) {
|
|
|
242
253
|
}
|
|
243
254
|
catch (error) {
|
|
244
255
|
await janitor?.close();
|
|
256
|
+
await relay?.close();
|
|
245
257
|
seal?.release();
|
|
246
258
|
await store.close();
|
|
247
259
|
throw error;
|
|
248
260
|
}
|
|
249
261
|
let closing;
|
|
250
262
|
const held = seal;
|
|
263
|
+
const relayed = relay;
|
|
251
264
|
return {
|
|
252
265
|
runner,
|
|
253
266
|
store: { kind, schema },
|
|
@@ -255,6 +268,8 @@ export async function startRunnerProcess(options) {
|
|
|
255
268
|
close: () => (closing ??= (async () => {
|
|
256
269
|
// The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
|
|
257
270
|
await Promise.all([janitor?.close(), runner.close()]);
|
|
271
|
+
// Its relay after its runs: a run's release revokes its machine's token through it.
|
|
272
|
+
await relayed?.close();
|
|
258
273
|
// A first-use install its claims started, stopped as they let go: its npm ends before this process can.
|
|
259
274
|
await claimInstallsStopped();
|
|
260
275
|
await store.close();
|
|
@@ -263,7 +278,7 @@ export async function startRunnerProcess(options) {
|
|
|
263
278
|
};
|
|
264
279
|
}
|
|
265
280
|
const storeFactories = new WeakSet();
|
|
266
|
-
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
|
|
281
|
+
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens, and its relay's dial). */
|
|
267
282
|
export function ofStore(make) {
|
|
268
283
|
storeFactories.add(make);
|
|
269
284
|
return make;
|
|
@@ -309,21 +324,23 @@ export function runnerHolds(args, env) {
|
|
|
309
324
|
}
|
|
310
325
|
return { loops, drainMs };
|
|
311
326
|
}
|
|
312
|
-
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or
|
|
313
|
-
* [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
|
|
314
|
-
* with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
|
|
315
|
-
* test switch, as the server's own --faux; the only way a runner loads one.
|
|
327
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]]`, or
|
|
328
|
+
* `--check --data D [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
|
|
329
|
+
* directory that starts with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
|
|
330
|
+
* faux model module, a test switch, as the server's own --faux; the only way a runner loads one. `--faux-browser`: the
|
|
331
|
+
* fake browser's module, with --faux only, as the server's. */
|
|
316
332
|
export function runnerArgs(argv) {
|
|
317
333
|
let dataDir;
|
|
318
334
|
let loops;
|
|
319
335
|
let drainMs;
|
|
320
336
|
let name;
|
|
321
337
|
let faux;
|
|
338
|
+
let fauxBrowser;
|
|
322
339
|
let check = false;
|
|
323
340
|
const harnessModules = [];
|
|
324
341
|
for (let i = 0; i < argv.length; i++) {
|
|
325
342
|
const given = argv[i];
|
|
326
|
-
const equals = /^(--(?:data|loops|drain-timeout|name|faux|harness-module))=(.*)$/s.exec(given);
|
|
343
|
+
const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module))=(.*)$/s.exec(given);
|
|
327
344
|
const arg = equals ? equals[1] : given;
|
|
328
345
|
const value = () => {
|
|
329
346
|
const next = equals ? equals[2] : argv[++i];
|
|
@@ -349,16 +366,20 @@ export function runnerArgs(argv) {
|
|
|
349
366
|
name = value();
|
|
350
367
|
else if (arg === "--faux")
|
|
351
368
|
faux = value();
|
|
369
|
+
else if (arg === "--faux-browser")
|
|
370
|
+
fauxBrowser = value();
|
|
352
371
|
else if (arg === "--harness-module")
|
|
353
372
|
harnessModules.push(value());
|
|
354
373
|
else if (arg === "--check")
|
|
355
374
|
check = true;
|
|
356
375
|
else
|
|
357
|
-
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M] [--harness-module M ...], or --check --data D [--name N]`);
|
|
376
|
+
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]] [--harness-module M ...], or --check --data D [--name N]`);
|
|
358
377
|
}
|
|
359
378
|
if (!dataDir)
|
|
360
379
|
throw new RunnerRefused("a runner needs its data directory: --data D");
|
|
361
|
-
|
|
380
|
+
if (fauxBrowser !== undefined && faux === undefined)
|
|
381
|
+
throw new RunnerRefused("--faux-browser goes with --faux");
|
|
382
|
+
return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
|
|
362
383
|
}
|
|
363
384
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
364
385
|
* says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
|
|
@@ -425,7 +446,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
425
446
|
}
|
|
426
447
|
// A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
|
|
427
448
|
// inherited (AGENTRUN_SERVE_FAUX*, the harness table, left in an operator's shell or a platform's settings) never loads
|
|
428
|
-
// a module or decides what a run answers. --faux sets the faux model's.
|
|
449
|
+
// a module or decides what a run answers. --faux sets the faux model's, --faux-browser the fake browser's.
|
|
429
450
|
// The owner's harness modules are this start's too: --harness-module, else AGENTRUN_SERVE_HARNESS_MODULES, as the
|
|
430
451
|
// server reads them, so a runner apart from the server runs the harnesses its table adds. Each is loaded and checked
|
|
431
452
|
// here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
|
|
@@ -440,7 +461,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
440
461
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
441
462
|
return 2;
|
|
442
463
|
}
|
|
443
|
-
const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
|
|
464
|
+
const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}), ...(args.fauxBrowser ? { [FAUX_BROWSER_ENV]: resolve(args.fauxBrowser) } : {}) };
|
|
444
465
|
const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
|
|
445
466
|
if (args.check) {
|
|
446
467
|
if (!name) {
|
|
@@ -469,6 +490,24 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
469
490
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
470
491
|
return 2;
|
|
471
492
|
}
|
|
493
|
+
// Each run a process of its own, as a user of its own where the image's helper can switch: a helper that cannot is
|
|
494
|
+
// refused here in words that name the setting (run-child-host.ts runIsolationOf), before any run is claimed. The slots
|
|
495
|
+
// the helper reaches bound the runs held at once: a number it was told (--loops, AGENTRUN_MAX_RUNS) past them is
|
|
496
|
+
// refused, and its memory's count is cut to them, said on its log.
|
|
497
|
+
let isolation;
|
|
498
|
+
const told = args.loops !== undefined || Boolean(env.AGENTRUN_MAX_RUNS);
|
|
499
|
+
try {
|
|
500
|
+
isolation = await runIsolationOf(env, told ? holds.loops : undefined, (line) => void console.error(`agentrun-serve runner: ${line}`));
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
if (!(error instanceof RunIsolationRefused))
|
|
504
|
+
throw error;
|
|
505
|
+
console.error(`agentrun-serve runner: ${error.message}`);
|
|
506
|
+
return 2;
|
|
507
|
+
}
|
|
508
|
+
if (isolation.kind === "uid" && holds.loops > isolation.slots)
|
|
509
|
+
console.error(`agentrun-serve runner: each run runs as a user of its own, and the helper reaches ${isolation.slots} slots from slot ${isolation.first}: this runner holds at most ${isolation.slots} runs at once`);
|
|
510
|
+
holds = { ...holds, loops: isolationLoops(isolation, holds.loops) };
|
|
472
511
|
let started;
|
|
473
512
|
const runnerOf = name ?? runnerName();
|
|
474
513
|
// The last resort, in this process only (never the library, the server's CLI or the runner beside a server): an error
|
|
@@ -495,7 +534,11 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
495
534
|
env,
|
|
496
535
|
loops: holds.loops,
|
|
497
536
|
drainMs: holds.drainMs,
|
|
498
|
-
|
|
537
|
+
// Each run a process of its own (`isolation`); its computer, with this runner's relay's dial, held here in the
|
|
538
|
+
// runner, which the run's process asks for it over its channel (run-child-host.ts, held.ts computer).
|
|
539
|
+
createLoop: ofStore((store, sealKey, dial) => runnerLoop(store, args.dataDir, env, sealKey, isolation, dial)),
|
|
540
|
+
// Each run's own process weighed beside its harness's run (memory-claim.ts RUN_PROCESS_MIB).
|
|
541
|
+
processMib: RUN_PROCESS_MIB,
|
|
499
542
|
// The runner subcommand ends what a crashed runner of this server left (never under --faux).
|
|
500
543
|
janitor: true,
|
|
501
544
|
onEvent: (event) => {
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Store, TriggerSettings } from "../store/index.js";
|
|
|
6
6
|
import { type ApprovalPrice, type ToolEffect } from "../tool-gate.js";
|
|
7
7
|
import type { Claim } from "./loop-contract.js";
|
|
8
8
|
import type { GithubAppAccess, GithubTimer } from "./mcp-github.js";
|
|
9
|
+
import { type HeldMcp } from "./held.js";
|
|
9
10
|
/** The GitHub App access for a claim (runner/github-app.ts githubAppAccess, tl-triggers'): the server's App, read from
|
|
10
11
|
* the store with the runner's seal key, bound to the repository the run's launch input names. */
|
|
11
12
|
export type GithubAppAccessOf = (store: {
|
|
@@ -89,3 +90,13 @@ export declare function catalogSessionNames(catalog: Pick<ClaimMcp, "tools" | "c
|
|
|
89
90
|
* claim lost while a refresh was awaited: the loop ends interrupted). A builder calls it before it takes anything it
|
|
90
91
|
* would have to let go, since a throw here leaves its spec unbuilt and its release uncalled. */
|
|
91
92
|
export declare function mcpForClaim(options: McpForClaimOptions): Promise<ClaimMcp | undefined>;
|
|
93
|
+
/** A claim's MCP as the runner hands it to the run's own process (held.ts HeldMcp): what the gate reads of each tool,
|
|
94
|
+
* read now, and each call made here, its answer and its error cut by `cut` (the runner's redactor) before they cross. */
|
|
95
|
+
export declare function heldMcpOf(mcp: ClaimMcp, cut: (text: string) => string): HeldMcp;
|
|
96
|
+
/** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
|
|
97
|
+
export declare function claimMcpOfHeld(held: HeldMcp): ClaimMcp;
|
|
98
|
+
/** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
|
|
99
|
+
* record of each call appended to the run's root through this process's own harness. */
|
|
100
|
+
export declare function mcpWhereHeld(options: Omit<McpForClaimOptions, "sealKey"> & {
|
|
101
|
+
readonly sealKey: Buffer | undefined;
|
|
102
|
+
}): Promise<ClaimMcp | undefined>;
|
package/dist/runner/mcp-run.js
CHANGED
|
@@ -7,6 +7,8 @@ import { mcpNameOf } from "../tool-names.js";
|
|
|
7
7
|
import { mcpToolName, permissionKeys, pinnedEffect } from "../tool-gate.js";
|
|
8
8
|
import { mcpClaim } from "./mcp-claim.js";
|
|
9
9
|
import { registryListing } from "../mcp-pin-first.js";
|
|
10
|
+
import { heldOrThrow } from "./held.js";
|
|
11
|
+
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
10
12
|
/** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
|
|
11
13
|
export function catalogSessionNames(catalog, grant) {
|
|
12
14
|
const given = (catalog?.tools ?? []).flatMap((tool) => (permissionKeys(catalog.catalogOf(tool.name) ?? "").includes(grant) ? [tool.name] : []));
|
|
@@ -110,3 +112,68 @@ export async function mcpForClaim(options) {
|
|
|
110
112
|
release: () => held.abort(),
|
|
111
113
|
};
|
|
112
114
|
}
|
|
115
|
+
/** A claim's MCP as the runner hands it to the run's own process (held.ts HeldMcp): what the gate reads of each tool,
|
|
116
|
+
* read now, and each call made here, its answer and its error cut by `cut` (the runner's redactor) before they cross. */
|
|
117
|
+
export function heldMcpOf(mcp, cut) {
|
|
118
|
+
return {
|
|
119
|
+
tools: mcp.tools.map((tool) => {
|
|
120
|
+
const catalog = mcp.catalogOf(tool.name) ?? tool.name;
|
|
121
|
+
const declared = mcp.argumentsOf(catalog);
|
|
122
|
+
const price = mcp.priceOf(catalog);
|
|
123
|
+
const effect = mcp.effectOf(catalog);
|
|
124
|
+
return {
|
|
125
|
+
name: tool.name,
|
|
126
|
+
description: tool.description,
|
|
127
|
+
inputSchema: tool.inputSchema,
|
|
128
|
+
catalog,
|
|
129
|
+
...(declared ? { arguments: [...declared] } : {}),
|
|
130
|
+
...(price !== undefined ? { price } : {}),
|
|
131
|
+
...(effect !== undefined ? { effect } : {}),
|
|
132
|
+
call: async (args, context) => {
|
|
133
|
+
try {
|
|
134
|
+
const answer = await tool.call(args, { ...(context.signal ? { signal: context.signal } : {}), ...(context.callId ? { callId: context.callId } : {}) });
|
|
135
|
+
return { text: cut(answer.text), ...(answer.isError ? { isError: true } : {}) };
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw Object.assign(new Error(cut(error instanceof Error ? error.message : String(error))), { name: error instanceof Error ? error.name : "Error" });
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}),
|
|
143
|
+
fresh: () => mcp.fresh(),
|
|
144
|
+
release: async () => mcp.release(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
|
|
148
|
+
export function claimMcpOfHeld(held) {
|
|
149
|
+
const byWire = new Map(held.tools.map((tool) => [tool.name, tool]));
|
|
150
|
+
const byCatalog = new Map(held.tools.map((tool) => [tool.catalog, tool]));
|
|
151
|
+
return {
|
|
152
|
+
tools: held.tools.map((tool) => ({
|
|
153
|
+
name: tool.name,
|
|
154
|
+
description: tool.description,
|
|
155
|
+
inputSchema: tool.inputSchema,
|
|
156
|
+
replay: "never",
|
|
157
|
+
call: (args, context) => tool.call(args, { ...(context.signal ? { signal: context.signal } : {}), ...(context.callId ? { callId: context.callId } : {}) }),
|
|
158
|
+
})),
|
|
159
|
+
catalogOf: (tool) => byWire.get(tool)?.catalog,
|
|
160
|
+
argumentsOf: (name) => {
|
|
161
|
+
const declared = byCatalog.get(name)?.arguments;
|
|
162
|
+
return declared ? new Set(declared) : undefined;
|
|
163
|
+
},
|
|
164
|
+
priceOf: (name) => byCatalog.get(name)?.price,
|
|
165
|
+
effectOf: (name) => byCatalog.get(name)?.effect,
|
|
166
|
+
fresh: () => held.fresh(),
|
|
167
|
+
release: () => void held.release().catch(() => undefined),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
|
|
171
|
+
* record of each call appended to the run's root through this process's own harness. */
|
|
172
|
+
export async function mcpWhereHeld(options) {
|
|
173
|
+
if (options.sealKey)
|
|
174
|
+
return mcpForClaim({ ...options, sealKey: options.sealKey });
|
|
175
|
+
const at = heldOrThrow("a run's MCP");
|
|
176
|
+
const appendRoot = (entry) => options.harness.commit((async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, entry))), BACKGROUND_CONTEXT);
|
|
177
|
+
const given = await at.mcp({ appendRoot });
|
|
178
|
+
return given ? claimMcpOfHeld(given) : undefined;
|
|
179
|
+
}
|
|
@@ -2,11 +2,16 @@ import type { Store } from "../store/store.js";
|
|
|
2
2
|
import type { RunnerMemory } from "./runner.js";
|
|
3
3
|
/** What a run launched on `harness` weighs: its entry's run size on the owner's table of `env` (harness-table.ts
|
|
4
4
|
* ownerHarness: a built-in's, or what a harness module declares; a test's stand-in weighs as the built-in it stands in
|
|
5
|
-
* for), or a pi run's for a run on no harness of that table (a learning run,
|
|
6
|
-
* pi run does). */
|
|
5
|
+
* for), or a pi run's for a run on no harness of that table (a learning run, whose loop is a pi run's). */
|
|
7
6
|
export declare function claimMibOf(harness: string, env?: NodeJS.ProcessEnv): number;
|
|
7
|
+
/** What a run's own process weighs beside its harness's run (run-child-host.ts: a runner whose runs are each a process of
|
|
8
|
+
* their own): a Node with the server's modules loaded, which a run in the runner's own process shared with every other.
|
|
9
|
+
* As measured: a run's process at its first turn, its resident set (224 MiB on the faux model, test/run-isolation.test.mjs
|
|
10
|
+
* says it) less the harness's own (pi's 128). */
|
|
11
|
+
export declare const RUN_PROCESS_MIB = 96;
|
|
8
12
|
/** The runner's memory budget over `store`: `memory` bytes (default the host's, hostMemory) less the server's own, each
|
|
9
13
|
* waiting run weighed by the harness its launch names (store.runs.launch) on the owner's table of `env` (the runner's run
|
|
10
|
-
* environment, which names its harness modules)
|
|
11
|
-
*
|
|
12
|
-
|
|
14
|
+
* environment, which names its harness modules), and `processMib` more for a run that is a process of its own
|
|
15
|
+
* (RUN_PROCESS_MIB; 0 for a runner whose runs share its process). A run whose launch cannot be read weighs a pi run: its
|
|
16
|
+
* claim fails it at once (dispatch.ts), holding nothing for long. */
|
|
17
|
+
export declare function runnerMemory(store: Pick<Store, "runs">, memory?: number, env?: NodeJS.ProcessEnv, processMib?: number): RunnerMemory;
|