@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- 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 +62 -19
- 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-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -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/import.d.ts +10 -0
- package/dist/import.js +28 -8
- 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 +89 -104
- 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 +23 -5
- package/dist/learn/promote.js +40 -2
- 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 +21 -10
- package/dist/learning-setting.js +47 -11
- 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 +273 -319
- 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 +30 -13
- 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 +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- 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 +82 -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 +12 -8
- package/dist/runner/promotion.js +37 -28
- 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 +1230 -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 +689 -322
- 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 +8 -4
- package/dist/templates.js +44 -6
- 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 +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- 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 +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- 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/kyb/agent.md +2 -1
- 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
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
// its turn for up to --drain-timeout (default AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT), then every loop left is stopped where it can resume
|
|
10
10
|
// and its run handed back for another runner (a loop that never stops is given up when its claim would run out, and its
|
|
11
11
|
// run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store schema it does not know 3, anything else 1.
|
|
12
|
+
// A run isolation it cannot give (run-child-host.ts runIsolationOf) is said, and it stays up claiming nothing until a stop: 0.
|
|
12
13
|
// An error nothing handles exits 1 at once, said with its stack (lastResort).
|
|
13
14
|
import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
14
15
|
import { join, resolve } from "node:path";
|
|
15
16
|
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
17
|
+
import { startRunnerRelay } from "../dial-relay.js";
|
|
16
18
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
17
19
|
import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
|
|
18
20
|
import { dockerPathsForRuns } from "../box-paths.js";
|
|
@@ -28,6 +30,7 @@ import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
|
28
30
|
import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
|
|
29
31
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
30
32
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
33
|
+
import { FAUX_BROWSER_ENV } from "../tools.js";
|
|
31
34
|
import { claimViewOpener } from "../computer-live.js";
|
|
32
35
|
import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
|
|
33
36
|
import { LOOPBACK } from "../mcp-oauth.js";
|
|
@@ -41,7 +44,8 @@ import { runEndComputers } from "../workspace/run-end-computers.js";
|
|
|
41
44
|
import { createDispatchLoop } from "./dispatch.js";
|
|
42
45
|
import { resolveRunnerLoop } from "./harness-loops.js";
|
|
43
46
|
import { routeOf } from "./model-route.js";
|
|
44
|
-
import { runnerMemory } from "./memory-claim.js";
|
|
47
|
+
import { RUN_PROCESS_MIB, runnerMemory } from "./memory-claim.js";
|
|
48
|
+
import { childLoops, isolationLoops, RunIsolationRefused, runIsolationOf } from "./run-child-host.js";
|
|
45
49
|
import { sweepEndedScratch } from "./scratch-sweep.js";
|
|
46
50
|
import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
|
|
47
51
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
@@ -119,7 +123,7 @@ export function besideRunEnv(env, switches) {
|
|
|
119
123
|
* its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
|
|
120
124
|
* journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
|
|
121
125
|
* 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) {
|
|
126
|
+
export function runnerLoop(store, dataDir, env = process.env, booted, isolation, dial) {
|
|
123
127
|
const sealKey = booted ?? sealKeyOf(secret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV]);
|
|
124
128
|
if (!sealKey)
|
|
125
129
|
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 +131,9 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
127
131
|
// The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
|
|
128
132
|
// agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
|
|
129
133
|
// 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
|
-
|
|
134
|
+
// view opened with it. A machine that dials goes to this runner's own hub, through the server's relay (`dial`, its
|
|
135
|
+
// relay's: dial-relay.ts); with none, its provider refuses.
|
|
136
|
+
const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(dial ? { dial } : {}) });
|
|
132
137
|
const loopback = runnerLoopback(env);
|
|
133
138
|
if (loopback)
|
|
134
139
|
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 +148,10 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
143
148
|
// The server's own addresses, as it kept them in the store at its last start, are read at each claim beside these.
|
|
144
149
|
...(loopback ? { mcpLoopback: true, mcpOwn: loopback.own, mcpOwnOf: () => serverOwn(store) } : {}),
|
|
145
150
|
};
|
|
146
|
-
|
|
151
|
+
// `isolation`: each run a process of its own (run-child-host.ts), as the runner subcommand runs them; none, in this one
|
|
152
|
+
// (a test's runner).
|
|
153
|
+
const createLoop = isolation ? childLoops({ deps, isolation, log: deps.log }) : createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) });
|
|
154
|
+
return { createLoop, computers: computers.computerDeps, env: runs };
|
|
147
155
|
}
|
|
148
156
|
/** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
|
|
149
157
|
* (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
|
|
@@ -179,7 +187,7 @@ function heartbeat(dataDir, name, now) {
|
|
|
179
187
|
}
|
|
180
188
|
catch {
|
|
181
189
|
mkdirSync(dataDir, { recursive: true });
|
|
182
|
-
writeFileSync(file, `${name}\n
|
|
190
|
+
writeFileSync(file, `${name}\n`, { mode: 0o600 });
|
|
183
191
|
utimesSync(file, seconds, seconds);
|
|
184
192
|
}
|
|
185
193
|
};
|
|
@@ -205,10 +213,11 @@ export async function startRunnerProcess(options) {
|
|
|
205
213
|
const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
|
|
206
214
|
const env = options.env ?? process.env;
|
|
207
215
|
const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
|
|
208
|
-
const memory = options.memory ?? runnerMemory(store, undefined, env);
|
|
216
|
+
const memory = options.memory ?? runnerMemory(store, undefined, env, options.processMib ?? 0);
|
|
209
217
|
let runner;
|
|
210
218
|
let seal;
|
|
211
219
|
let janitor;
|
|
220
|
+
let relay;
|
|
212
221
|
try {
|
|
213
222
|
// 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
223
|
// this data directory, checked against what the store records. A runner on a store whose secrets another key sealed
|
|
@@ -216,9 +225,12 @@ export async function startRunnerProcess(options) {
|
|
|
216
225
|
// or records a key.
|
|
217
226
|
seal = await bootSealKey(store, options.dataDir, { given: handedSecret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV], role: "runner" });
|
|
218
227
|
const name = options.name ?? runnerName();
|
|
219
|
-
|
|
228
|
+
// Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
|
|
229
|
+
// server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
|
|
230
|
+
relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, env, log: warn });
|
|
231
|
+
const made = options.createLoop ?? ofStore((opened, sealKey, dial) => runnerLoop(opened, options.dataDir, undefined, sealKey, undefined, dial));
|
|
220
232
|
// 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;
|
|
233
|
+
const parts = isStoreFactory(made) ? made(store, seal.key, relay?.dial) : made;
|
|
222
234
|
const createLoop = typeof parts === "function" ? parts : parts.createLoop;
|
|
223
235
|
// The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
|
|
224
236
|
// warnings, said where the runner says its others (warn: stderr unless a test gives its own).
|
|
@@ -242,12 +254,14 @@ export async function startRunnerProcess(options) {
|
|
|
242
254
|
}
|
|
243
255
|
catch (error) {
|
|
244
256
|
await janitor?.close();
|
|
257
|
+
await relay?.close();
|
|
245
258
|
seal?.release();
|
|
246
259
|
await store.close();
|
|
247
260
|
throw error;
|
|
248
261
|
}
|
|
249
262
|
let closing;
|
|
250
263
|
const held = seal;
|
|
264
|
+
const relayed = relay;
|
|
251
265
|
return {
|
|
252
266
|
runner,
|
|
253
267
|
store: { kind, schema },
|
|
@@ -255,6 +269,8 @@ export async function startRunnerProcess(options) {
|
|
|
255
269
|
close: () => (closing ??= (async () => {
|
|
256
270
|
// The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
|
|
257
271
|
await Promise.all([janitor?.close(), runner.close()]);
|
|
272
|
+
// Its relay after its runs: a run's release revokes its machine's token through it.
|
|
273
|
+
await relayed?.close();
|
|
258
274
|
// A first-use install its claims started, stopped as they let go: its npm ends before this process can.
|
|
259
275
|
await claimInstallsStopped();
|
|
260
276
|
await store.close();
|
|
@@ -263,7 +279,7 @@ export async function startRunnerProcess(options) {
|
|
|
263
279
|
};
|
|
264
280
|
}
|
|
265
281
|
const storeFactories = new WeakSet();
|
|
266
|
-
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
|
|
282
|
+
/** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens, and its relay's dial). */
|
|
267
283
|
export function ofStore(make) {
|
|
268
284
|
storeFactories.add(make);
|
|
269
285
|
return make;
|
|
@@ -309,21 +325,23 @@ export function runnerHolds(args, env) {
|
|
|
309
325
|
}
|
|
310
326
|
return { loops, drainMs };
|
|
311
327
|
}
|
|
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.
|
|
328
|
+
/** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M [--faux-browser M]]`, or
|
|
329
|
+
* `--check --data D [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data
|
|
330
|
+
* directory that starts with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the
|
|
331
|
+
* faux model module, a test switch, as the server's own --faux; the only way a runner loads one. `--faux-browser`: the
|
|
332
|
+
* fake browser's module, with --faux only, as the server's. */
|
|
316
333
|
export function runnerArgs(argv) {
|
|
317
334
|
let dataDir;
|
|
318
335
|
let loops;
|
|
319
336
|
let drainMs;
|
|
320
337
|
let name;
|
|
321
338
|
let faux;
|
|
339
|
+
let fauxBrowser;
|
|
322
340
|
let check = false;
|
|
323
341
|
const harnessModules = [];
|
|
324
342
|
for (let i = 0; i < argv.length; i++) {
|
|
325
343
|
const given = argv[i];
|
|
326
|
-
const equals = /^(--(?:data|loops|drain-timeout|name|faux|harness-module))=(.*)$/s.exec(given);
|
|
344
|
+
const equals = /^(--(?:data|loops|drain-timeout|name|faux|faux-browser|harness-module))=(.*)$/s.exec(given);
|
|
327
345
|
const arg = equals ? equals[1] : given;
|
|
328
346
|
const value = () => {
|
|
329
347
|
const next = equals ? equals[2] : argv[++i];
|
|
@@ -349,16 +367,20 @@ export function runnerArgs(argv) {
|
|
|
349
367
|
name = value();
|
|
350
368
|
else if (arg === "--faux")
|
|
351
369
|
faux = value();
|
|
370
|
+
else if (arg === "--faux-browser")
|
|
371
|
+
fauxBrowser = value();
|
|
352
372
|
else if (arg === "--harness-module")
|
|
353
373
|
harnessModules.push(value());
|
|
354
374
|
else if (arg === "--check")
|
|
355
375
|
check = true;
|
|
356
376
|
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]`);
|
|
377
|
+
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
378
|
}
|
|
359
379
|
if (!dataDir)
|
|
360
380
|
throw new RunnerRefused("a runner needs its data directory: --data D");
|
|
361
|
-
|
|
381
|
+
if (fauxBrowser !== undefined && faux === undefined)
|
|
382
|
+
throw new RunnerRefused("--faux-browser goes with --faux");
|
|
383
|
+
return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(fauxBrowser === undefined ? {} : { fauxBrowser }), ...(check ? { check: true } : {}) };
|
|
362
384
|
}
|
|
363
385
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
364
386
|
* 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 +447,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
425
447
|
}
|
|
426
448
|
// A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
|
|
427
449
|
// 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.
|
|
450
|
+
// a module or decides what a run answers. --faux sets the faux model's, --faux-browser the fake browser's.
|
|
429
451
|
// The owner's harness modules are this start's too: --harness-module, else AGENTRUN_SERVE_HARNESS_MODULES, as the
|
|
430
452
|
// server reads them, so a runner apart from the server runs the harnesses its table adds. Each is loaded and checked
|
|
431
453
|
// here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
|
|
@@ -440,7 +462,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
440
462
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
441
463
|
return 2;
|
|
442
464
|
}
|
|
443
|
-
const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
|
|
465
|
+
const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}), ...(args.fauxBrowser ? { [FAUX_BROWSER_ENV]: resolve(args.fauxBrowser) } : {}) };
|
|
444
466
|
const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
|
|
445
467
|
if (args.check) {
|
|
446
468
|
if (!name) {
|
|
@@ -469,6 +491,27 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
469
491
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
470
492
|
return 2;
|
|
471
493
|
}
|
|
494
|
+
// 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
|
|
495
|
+
// refused here in words that name the setting (run-child-host.ts runIsolationOf), before any run is claimed. The slots
|
|
496
|
+
// the helper reaches bound the runs held at once: a number it was told (--loops, AGENTRUN_MAX_RUNS) past them is
|
|
497
|
+
// refused, and its memory's count is cut to them, said on its log.
|
|
498
|
+
let isolation;
|
|
499
|
+
const told = args.loops !== undefined || Boolean(env.AGENTRUN_MAX_RUNS);
|
|
500
|
+
try {
|
|
501
|
+
isolation = await runIsolationOf(env, told ? holds.loops : undefined, (line) => void console.error(`agentrun-serve runner: ${line}`));
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
if (!(error instanceof RunIsolationRefused))
|
|
505
|
+
throw error;
|
|
506
|
+
// Said, then up and claiming nothing until a stop: in the image's server-and-runner either process's exit stops the
|
|
507
|
+
// container, which a platform that restarts it (Render, Railway) would loop on, the refusal lost in the restarts.
|
|
508
|
+
console.error(`agentrun-serve runner: ${error.message}`);
|
|
509
|
+
await untilSignalled(RUNNER_SIGNALS);
|
|
510
|
+
return 0;
|
|
511
|
+
}
|
|
512
|
+
if (isolation.kind === "uid" && holds.loops > isolation.slots)
|
|
513
|
+
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`);
|
|
514
|
+
holds = { ...holds, loops: isolationLoops(isolation, holds.loops) };
|
|
472
515
|
let started;
|
|
473
516
|
const runnerOf = name ?? runnerName();
|
|
474
517
|
// The last resort, in this process only (never the library, the server's CLI or the runner beside a server): an error
|
|
@@ -495,7 +538,11 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
495
538
|
env,
|
|
496
539
|
loops: holds.loops,
|
|
497
540
|
drainMs: holds.drainMs,
|
|
498
|
-
|
|
541
|
+
// Each run a process of its own (`isolation`); its computer, with this runner's relay's dial, held here in the
|
|
542
|
+
// runner, which the run's process asks for it over its channel (run-child-host.ts, held.ts computer).
|
|
543
|
+
createLoop: ofStore((store, sealKey, dial) => runnerLoop(store, args.dataDir, env, sealKey, isolation, dial)),
|
|
544
|
+
// Each run's own process weighed beside its harness's run (memory-claim.ts RUN_PROCESS_MIB).
|
|
545
|
+
processMib: RUN_PROCESS_MIB,
|
|
499
546
|
// The runner subcommand ends what a crashed runner of this server left (never under --faux).
|
|
500
547
|
janitor: true,
|
|
501
548
|
onEvent: (event) => {
|
|
@@ -531,3 +578,18 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
531
578
|
}
|
|
532
579
|
/** The signals that stop a runner process. */
|
|
533
580
|
const RUNNER_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
581
|
+
/** Holds the process up, with nothing else to do, until one of `signals`. */
|
|
582
|
+
function untilSignalled(signals) {
|
|
583
|
+
return new Promise((resolve) => {
|
|
584
|
+
// A signal's listener alone does not keep Node's loop alive.
|
|
585
|
+
const alive = setInterval(() => { }, 2 ** 30);
|
|
586
|
+
const onSignal = () => {
|
|
587
|
+
for (const signal of signals)
|
|
588
|
+
process.off(signal, onSignal);
|
|
589
|
+
clearInterval(alive);
|
|
590
|
+
resolve();
|
|
591
|
+
};
|
|
592
|
+
for (const signal of signals)
|
|
593
|
+
process.on(signal, onSignal);
|
|
594
|
+
});
|
|
595
|
+
}
|
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
|
+
}
|