@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +10 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +41 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +9 -4
- package/dist/runner/main.js +12 -6
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.js +1 -1
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
package/dist/runner/beside.js
CHANGED
|
@@ -33,7 +33,7 @@ export function besideStopping(server, held, drainMs) {
|
|
|
33
33
|
* a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
|
|
34
34
|
* and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
|
|
35
35
|
* isolation a number past the helper's slots is refused rather than cut. */
|
|
36
|
-
export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
|
|
36
|
+
export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
|
|
37
37
|
const { runnerName, startRunner } = await import("./runner.js");
|
|
38
38
|
const { dispatchRunner } = await import("./harness-loops.js");
|
|
39
39
|
const { routeOf } = await import("./model-route.js");
|
|
@@ -58,7 +58,11 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
58
58
|
// a --faux server reaches the faux gateway and its computers. The run's claim-time computer is composed once, the one way
|
|
59
59
|
// (main.ts runnerComputers, a desktop's or a phone's live view with it), from that same environment; a Docker computer's
|
|
60
60
|
// mounts by where this process's Docker has the data directory (box-paths.ts), read once.
|
|
61
|
+
// `ollamaHost`: the Ollama the server beside it asks (Serve.ollamaHost), the default address on one owner's own machine
|
|
62
|
+
// that names none, so its runs ask the same one; a runner in its own process asks the one its environment names alone.
|
|
61
63
|
const runs = env ?? runEnv(process.env);
|
|
64
|
+
if (ollamaHost && !runs.OLLAMA_HOST?.trim())
|
|
65
|
+
runs.OLLAMA_HOST = ollamaHost;
|
|
62
66
|
const { dockerPathsForRuns } = await import("../box-paths.js");
|
|
63
67
|
const { hostAddressesOnce } = await import("../docker-host-addresses.js");
|
|
64
68
|
const { PROVIDERS } = await import("@parcha/agentrun-computer");
|
|
@@ -116,15 +120,19 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
116
120
|
if (event.type === "ended")
|
|
117
121
|
onRunEnded?.(event.status);
|
|
118
122
|
};
|
|
119
|
-
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts)
|
|
123
|
+
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts), as
|
|
124
|
+
// the runner beside it (read at each end, once it has started): a computer kept pinned to another runner is that one's.
|
|
120
125
|
const { runEndComputers } = await import("../workspace/run-end-computers.js");
|
|
121
126
|
const { projectRunEnded } = await import("../source-sync/checkpoints.js");
|
|
122
|
-
const
|
|
127
|
+
const self = () => (runner.incarnation ? { runner: name, incarnation: runner.incarnation } : undefined);
|
|
128
|
+
const runEnded = projectRunEnded(store, runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`), self }));
|
|
123
129
|
const runner = startRunner({ store, name, createLoop, memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
124
130
|
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
125
131
|
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
126
132
|
const { startJanitor } = await import("../workspace/computer-janitor.js");
|
|
127
|
-
|
|
133
|
+
// As the runner beside it (its name and its presence's incarnation): a kept computer pinned to another runner still
|
|
134
|
+
// there is that runner's to end (computer-kept.ts sweepKept).
|
|
135
|
+
const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`), ...(runner.incarnation ? { self: { runner: name, incarnation: runner.incarnation } } : {}) }) : undefined;
|
|
128
136
|
// Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
|
|
129
137
|
const { claimInstallsStopped } = await import("../harness-install.js");
|
|
130
138
|
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
@@ -163,7 +171,7 @@ export async function serveWithRunner(options) {
|
|
|
163
171
|
const serve = await startServe(options);
|
|
164
172
|
// Each run a process of its own, as a user of its own where the image's helper can switch, as the CLI's start runs
|
|
165
173
|
// them (cli.ts): the isolation the server's capabilities say (runIsolationOf over the same helper) is the runner's.
|
|
166
|
-
const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
|
|
174
|
+
const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
|
|
167
175
|
await serve.close();
|
|
168
176
|
throw error;
|
|
169
177
|
});
|
|
@@ -20,10 +20,6 @@ export interface ClaimSecretsDeps {
|
|
|
20
20
|
/** The runner's seal key: with none, no saved key is opened, and only the environment's values are read. */
|
|
21
21
|
readonly sealKey: Buffer | undefined;
|
|
22
22
|
readonly env?: NodeJS.ProcessEnv;
|
|
23
|
-
/** The runner's one redactor (redact.ts), for a claim given its run's id: the run's own tool keys it lays are carried
|
|
24
|
-
* there first, cut from the run's journal as it is written, since no one holds them after the turn. A claim with run
|
|
25
|
-
* keys to lay and no redactor lays none, and throws. */
|
|
26
|
-
readonly redact?: HeldRedact;
|
|
27
23
|
}
|
|
28
24
|
/** What reads a run's launch sealed column. */
|
|
29
25
|
type RunLaunchReader = {
|
|
@@ -34,11 +30,12 @@ type RunLaunchReader = {
|
|
|
34
30
|
/** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
|
|
35
31
|
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
36
32
|
* decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
|
|
37
|
-
* server's by the same name. A fresh object per claim, so no run's keys reach another's.
|
|
33
|
+
* server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
|
|
34
|
+
* redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
|
|
35
|
+
* written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
|
|
38
36
|
export declare function claimSecrets(deps: ClaimSecretsDeps & {
|
|
39
|
-
readonly redact: HeldRedact
|
|
40
|
-
}, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId
|
|
41
|
-
export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
|
|
37
|
+
readonly redact: HeldRedact;
|
|
38
|
+
}, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId?: string): Promise<NodeJS.ProcessEnv>;
|
|
42
39
|
/** `keys` (learnedDecisionKeys') laid onto `env`, a claim's environment, where it holds no value of that name: what the
|
|
43
40
|
* claim laid stays, a run's own tool key over the server's above all. A name both read holds the same server key. */
|
|
44
41
|
export declare function underClaimed(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
|
|
@@ -23,6 +23,12 @@ import { withRequestMetadata } from "../request-metadata.js";
|
|
|
23
23
|
/** Every server secret a run might be handed (runs.ts RUN_SECRETS is the tool and model keys; the decision keys go beside
|
|
24
24
|
* them). Read from the store into a working environment, then scoped to the run below. */
|
|
25
25
|
const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
|
|
26
|
+
/** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
|
|
27
|
+
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
28
|
+
* decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
|
|
29
|
+
* server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
|
|
30
|
+
* redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
|
|
31
|
+
* written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
|
|
26
32
|
export async function claimSecrets(deps, revision, launch, runId) {
|
|
27
33
|
const base = withoutSecrets(deps.env ?? {});
|
|
28
34
|
const working = await workingEnv(deps);
|
|
@@ -5,7 +5,7 @@ import { type RunLaunch } from "../run-launch.js";
|
|
|
5
5
|
import { type AdapterRun, type AdapterRunSpec } from "./adapter-loop.js";
|
|
6
6
|
import { type AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
7
7
|
import { type ClaimModelKey } from "./claim-secrets.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type Claim } from "./loop-contract.js";
|
|
9
9
|
/** The shared claim-time computer types live on the base spec (adapter-run-spec.ts), re-exported for this module's API. */
|
|
10
10
|
export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./adapter-run-spec.js";
|
|
11
11
|
/** What the runner hands the CLI spec builder: the same deps the pi spec takes (computerForClaim, computerDeps and
|
|
@@ -18,7 +18,7 @@ import { stopRunWith } from "../paid-calls.js";
|
|
|
18
18
|
import { dirname, join } from "node:path";
|
|
19
19
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
20
20
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
21
|
-
import { checkRaise, followUpOf, freeRequestLimitOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
21
|
+
import { checkRaise, followUpOf, freeRequestLimitOf, maxRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
22
22
|
import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
|
|
23
23
|
import { modelWire } from "../wires.js";
|
|
24
24
|
import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
|
|
@@ -28,14 +28,15 @@ import { effortGuidance } from "../effort-guidance.js";
|
|
|
28
28
|
import { outputContract } from "../answer-json.js";
|
|
29
29
|
import { wireName } from "../catalog.js";
|
|
30
30
|
import { environmentLine, runZone } from "../environment.js";
|
|
31
|
-
import { factsOf, harnessOf } from "../harness-table.js";
|
|
31
|
+
import { factsOf, harnessOf, recipeKeysOf } from "../harness-table.js";
|
|
32
|
+
import { layHarnessKeys, openHarnessKeys, RECIPE_SIGN_IN_PERSON_ONLY, RECIPE_TURN_PERSON_ONLY } from "../harness-keys.js";
|
|
32
33
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
33
34
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
34
35
|
import { learningWorkspace } from "../learn/folder.js";
|
|
35
36
|
import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
|
|
36
|
-
import { providerModels, runModels } from "../model.js";
|
|
37
|
+
import { ollamaTagsOf, providerModels, runModels } from "../model.js";
|
|
37
38
|
import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
|
|
38
|
-
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
39
|
+
import { learningStartOf, personStarted, seedFailed } from "../run-launch.js";
|
|
39
40
|
import { readsFiles, systemOf } from "../skills.js";
|
|
40
41
|
import { DATA_ENV } from "../server-fs.js";
|
|
41
42
|
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
@@ -63,6 +64,7 @@ import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
|
63
64
|
import { decisionProvidersIn } from "../decisions.js";
|
|
64
65
|
import { resolveHarness } from "./adapters/index.js";
|
|
65
66
|
import { entriesOf } from "./loop.js";
|
|
67
|
+
import { ClaimRefused } from "./loop-contract.js";
|
|
66
68
|
import { bookedSpend, cliModelWorked, cliRunMetrics, costBasisOf, endCostOf, runCostOf } from "./metrics.js";
|
|
67
69
|
import { journalEntries } from "./journal-reader.js";
|
|
68
70
|
import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
|
|
@@ -98,7 +100,7 @@ async function modelsOf(entry, env, ref) {
|
|
|
98
100
|
throw new Error(`${entry.id} does not run here.`);
|
|
99
101
|
if ("why" in choice)
|
|
100
102
|
throw new Error(choice.why);
|
|
101
|
-
return { model: choice.model, models: await providerModels(env), unpriced: new Set() };
|
|
103
|
+
return { model: choice.model, models: await providerModels(env, { ollama: ollamaTagsOf([choice.model]) }), unpriced: new Set() };
|
|
102
104
|
}
|
|
103
105
|
const chosen = await runModels(env, ref, ["default"], entry.id);
|
|
104
106
|
if (!chosen.model)
|
|
@@ -335,7 +337,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
335
337
|
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
|
|
336
338
|
const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
|
|
337
339
|
redact.hold(values); };
|
|
338
|
-
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web, slots: deps.saveSlots } });
|
|
340
|
+
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web, slots: deps.saveSlots } });
|
|
339
341
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
340
342
|
holds.hold({ passed: mcp });
|
|
341
343
|
// The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
|
|
@@ -386,7 +388,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
386
388
|
// The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
|
|
387
389
|
// It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
|
|
388
390
|
const claimSignal = run.stopped ?? run.signal;
|
|
389
|
-
const computer = await deps.computerForClaim(
|
|
391
|
+
const computer = await deps.computerForClaim(
|
|
392
|
+
// The runner holding the claim, as the pi spec hands it: a computer kept that only it can reach again is pinned to it.
|
|
393
|
+
{ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(run.incarnation ? { holder: { runner: claim.runner, incarnation: run.incarnation } } : {}) }, deps.store,
|
|
390
394
|
// revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
|
|
391
395
|
// run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
|
|
392
396
|
// what became of the agent's own computer said on the run's timeline.
|
|
@@ -460,6 +464,32 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
460
464
|
// runs on that key, and a run in a sandbox place on the model keys.
|
|
461
465
|
const login = keyed ? undefined : await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, launch.place);
|
|
462
466
|
const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey, claim), login);
|
|
467
|
+
// A plan-billed recipe's keys saved for its harness alone (harness-keys.ts), opened at each claim for this run's harness
|
|
468
|
+
// and no other (a run's own process asks its runner, which opens its claim's own: held.ts harnessKeys), held by the
|
|
469
|
+
// redactors, and laid on the adapter's environment alone, never enumerable (layHarnessKeys): the tools' plane copies
|
|
470
|
+
// `claimed`, never `env`, and no spread or child environment built from `env` carries them. The ACP adapter reads each
|
|
471
|
+
// by name for the agent's start, and only keys laid here take a run onto the keys route (harness-recipe-entry.ts).
|
|
472
|
+
// The run environment copies the runner's own (cliRunEnv), so a key's name the operator's shell exported is dropped
|
|
473
|
+
// first: the agent reads a saved key or none. All or nothing: a claim that opened not every key lays none, and a run
|
|
474
|
+
// no person started (a schedule's, a trigger's, a trigger's turn into a run, a learned workflow's audit shadow or
|
|
475
|
+
// replay: personStarted) is refused then, before any route
|
|
476
|
+
// is chosen, so it never falls to its owner's sign-in (a row counted at its claim may be gone, or not open, by now).
|
|
477
|
+
// A person's claim that laid none keeps its session on the sign-in (or on nothing) for good: a trigger's message the
|
|
478
|
+
// claim takes later is refused in it (personOnly), keys saved since or not, as no new claim opens them.
|
|
479
|
+
const recipeKeys = name === undefined ? undefined : recipeKeysOf(deps.env ?? {}, name);
|
|
480
|
+
let personOnly;
|
|
481
|
+
if (name !== undefined && recipeKeys?.length) {
|
|
482
|
+
for (const key of recipeKeys)
|
|
483
|
+
delete env[key];
|
|
484
|
+
const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, name, recipeKeys) : ((await runnerSeam()?.harnessKeys()) ?? {});
|
|
485
|
+
hold(Object.values(opened));
|
|
486
|
+
if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
|
|
487
|
+
layHarnessKeys(env, opened);
|
|
488
|
+
else if (!personStarted(launch))
|
|
489
|
+
throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
|
|
490
|
+
else
|
|
491
|
+
personOnly = RECIPE_TURN_PERSON_ONLY;
|
|
492
|
+
}
|
|
463
493
|
const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
|
|
464
494
|
await planBeforeRun(env, chosen.model);
|
|
465
495
|
if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
|
|
@@ -542,6 +572,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
542
572
|
...(besideOf ? { beside: besideOf } : {}),
|
|
543
573
|
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
|
|
544
574
|
freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
|
|
575
|
+
// The agent's own limit alone, which a local model's requests count toward too (run-cap.ts maxRequests).
|
|
576
|
+
...(maxRequestsOf(body.maxRequests) === undefined ? {} : { maxRequests: maxRequestsOf(body.maxRequests) }),
|
|
545
577
|
};
|
|
546
578
|
const cap = capUsd === undefined
|
|
547
579
|
? undefined
|
|
@@ -735,6 +767,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
735
767
|
agentId: runRow.agentId,
|
|
736
768
|
// An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
|
|
737
769
|
...(launch.audit ? { neverWaits: AUDIT_PARKED } : {}),
|
|
770
|
+
// A plan-billed recipe's session its claim laid no key on: a trigger's message is refused in it (adapter-loop.ts).
|
|
771
|
+
...(personOnly ? { personOnly } : {}),
|
|
738
772
|
// The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
|
|
739
773
|
...(loopComputer ? { computer: loopComputer } : {}),
|
|
740
774
|
// A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RECIPE_SIGN_IN_PERSON_ONLY } from "../harness-keys.js";
|
|
2
|
+
import type { SealedKeys } from "../store/index.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
2
4
|
import { type AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
3
5
|
import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
|
|
4
6
|
/** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
|
|
@@ -6,15 +8,26 @@ import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
|
|
|
6
8
|
export declare class NeverFits extends ClaimRefused {
|
|
7
9
|
name: string;
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
11
|
+
export { RECIPE_SIGN_IN_PERSON_ONLY };
|
|
12
|
+
/** Refuses at its claim a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
|
|
13
|
+
* personStarted) on a plan-billed recipe's harness (harness-table.ts recipeKeysOf) unless every key it runs on is saved for that harness (harness-keys.ts), on
|
|
14
|
+
* every path a claim takes (run-child-host.ts staysInRunner, and here): the early word, before a process is made. Rows
|
|
15
|
+
* are counted, never opened; the claim's spec opens them and refuses it again if not every one opened, since a row
|
|
16
|
+
* counted here can be gone or not open by then (cli-run-spec.ts). */
|
|
17
|
+
export declare function refuseRecipeTriggerRun(deps: {
|
|
18
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
19
|
+
readonly store: {
|
|
20
|
+
readonly sealedKeys: Pick<SealedKeys, "all">;
|
|
21
|
+
};
|
|
22
|
+
}, harness: string, launch: Pick<RunLaunch, "trigger" | "audit" | "replay">): Promise<void>;
|
|
15
23
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
16
|
-
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words).
|
|
17
|
-
|
|
24
|
+
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words).
|
|
25
|
+
* `keysCounted`: a run's own process (run-child.ts), whose runner counted its harness's key rows before it made the
|
|
26
|
+
* process (run-child-host.ts staysInRunner). The process's store lists no rows (STORE_CALLS has no sealedKeys.all), so
|
|
27
|
+
* it never counts them again; its claim's spec opens the claim's own keys and refuses the run if not every one opened. */
|
|
28
|
+
export declare function resolveRunnerLoop(given: AdapterSpecDeps, options?: {
|
|
29
|
+
readonly keysCounted?: boolean;
|
|
30
|
+
}): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
|
|
18
31
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
19
32
|
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
20
33
|
* start and the test server pass this to startRunner. */
|
|
@@ -13,8 +13,10 @@ import { createNativeLoop } from "./native-loop.js";
|
|
|
13
13
|
// module adds with no adapter facts of its own, on its runner's adapter;
|
|
14
14
|
// - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
|
|
15
15
|
// - anything else fails the run in words (the dispatch's UnknownHarness).
|
|
16
|
-
import { harnessOf,
|
|
16
|
+
import { harnessOf, recipeKeysOf } from "../harness-table.js";
|
|
17
|
+
import { harnessKeysSaved, RECIPE_SIGN_IN_PERSON_ONLY } from "../harness-keys.js";
|
|
17
18
|
import { hostMemory, neverFits } from "../host.js";
|
|
19
|
+
import { personStarted } from "../run-launch.js";
|
|
18
20
|
import { resolveHarness } from "./adapters/index.js";
|
|
19
21
|
import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
|
|
20
22
|
import { createAdapterLoop } from "./adapter-loop.js";
|
|
@@ -32,20 +34,28 @@ import { workflowSpecOf } from "./workflow-spec.js";
|
|
|
32
34
|
export class NeverFits extends ClaimRefused {
|
|
33
35
|
name = "NeverFits";
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
export { RECIPE_SIGN_IN_PERSON_ONLY };
|
|
38
|
+
/** Refuses at its claim a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
|
|
39
|
+
* personStarted) on a plan-billed recipe's harness (harness-table.ts recipeKeysOf) unless every key it runs on is saved for that harness (harness-keys.ts), on
|
|
40
|
+
* every path a claim takes (run-child-host.ts staysInRunner, and here): the early word, before a process is made. Rows
|
|
41
|
+
* are counted, never opened; the claim's spec opens them and refuses it again if not every one opened, since a row
|
|
42
|
+
* counted here can be gone or not open by then (cli-run-spec.ts). */
|
|
43
|
+
export async function refuseRecipeTriggerRun(deps, harness, launch) {
|
|
44
|
+
if (personStarted(launch))
|
|
45
|
+
return;
|
|
46
|
+
const keys = recipeKeysOf(deps.env ?? {}, harness);
|
|
47
|
+
if (keys !== undefined && !(await harnessKeysSaved(deps.store, harness, keys)))
|
|
42
48
|
throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
|
|
43
49
|
}
|
|
44
50
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
45
|
-
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words).
|
|
46
|
-
|
|
51
|
+
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words).
|
|
52
|
+
* `keysCounted`: a run's own process (run-child.ts), whose runner counted its harness's key rows before it made the
|
|
53
|
+
* process (run-child-host.ts staysInRunner). The process's store lists no rows (STORE_CALLS has no sealedKeys.all), so
|
|
54
|
+
* it never counts them again; its claim's spec opens the claim's own keys and refuses the run if not every one opened. */
|
|
55
|
+
export function resolveRunnerLoop(given, options = {}) {
|
|
47
56
|
return async (harness, launch, runId) => {
|
|
48
|
-
|
|
57
|
+
if (!options.keysCounted)
|
|
58
|
+
await refuseRecipeTriggerRun(given, harness, launch);
|
|
49
59
|
// The model gateway saved in the console (model-gateway.ts), read from the store at each claim and laid over the run
|
|
50
60
|
// environment as its variables would be, so a gateway saved or removed since reaches the next run with no restart. A
|
|
51
61
|
// gateway the runner's environment names wins, and nothing saved is read over it.
|
package/dist/runner/held.d.ts
CHANGED
|
@@ -89,6 +89,9 @@ export interface Held {
|
|
|
89
89
|
/** The zone the claim's run's day is told in (environment.ts runZone): its trigger's, read by the runner from the
|
|
90
90
|
* claim's own launch, else the server's. A zone's name, never the trigger's row. */
|
|
91
91
|
runZone(): Promise<string>;
|
|
92
|
+
/** The keys saved for the claim's own harness alone (harness-keys.ts openHarnessKeys), by name, opened by the runner:
|
|
93
|
+
* none unless that harness is a plan-billed recipe. The process lays them on its adapter's environment alone. */
|
|
94
|
+
harnessKeys(): Promise<Record<string, string>>;
|
|
92
95
|
/** The host's keys of the decision providers `providers` (claim-secrets.ts hostDecisionKeys): of the providers the
|
|
93
96
|
* claim's learned workflows' questions name, as the runner chose them (learnedFirst), alone. */
|
|
94
97
|
decisionKeys(providers: readonly string[]): Promise<Record<string, string>>;
|
|
@@ -141,7 +141,7 @@ export declare const draftFailedDigest: (runId: string) => string;
|
|
|
141
141
|
* compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
|
|
142
142
|
* reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
|
|
143
143
|
* writes none. */
|
|
144
|
-
export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log">, input: {
|
|
144
|
+
export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log" | "learningFolder">, input: {
|
|
145
145
|
runId: string;
|
|
146
146
|
agentId: string;
|
|
147
147
|
compile: CompileAsk;
|
|
@@ -44,6 +44,7 @@ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
|
44
44
|
import { FINAL_STATES } from "../store/store.js";
|
|
45
45
|
import { shadowRunId } from "../learn/audit.js";
|
|
46
46
|
import { getMcpServer } from "../mcp-store.js";
|
|
47
|
+
import { purgeGate, refusedIn } from "../purged-workflow.js";
|
|
47
48
|
import { readApprovers } from "../server-approvers.js";
|
|
48
49
|
import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
|
|
49
50
|
import { capNowOf, KINDS } from "./journal-kinds.js";
|
|
@@ -498,7 +499,7 @@ export async function recordDraftFailed(deps, input) {
|
|
|
498
499
|
const failed = input.errors.join("; ").slice(0, CHECK_TEXT_MAX) || "no draft passed";
|
|
499
500
|
const reason = `${DRAFT_FAILED}: ${failed}. ${attempt === 2 ? "It was the recompile, so it stops: nothing compiles again until its owner acts" : "It is not promoted; the next due run compiles it once more"}`;
|
|
500
501
|
const check = { compile_after, agree_min, alone_min, attempt, n: 0, agreed: 0, alone: 0, of: [], ...(attempt === 2 ? { stopped: true } : {}) };
|
|
501
|
-
const kept = await recordPromotion(deps.store.settings, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined);
|
|
502
|
+
const kept = await recordPromotion(deps.store.settings, input.agentId, { workflow, digest, at: new Date().toISOString(), decided: "hold", reason, check }, (was) => was === undefined, refusedIn(() => deps.learningFolder(input.agentId), deps.store, deps.log));
|
|
502
503
|
if (kept.won)
|
|
503
504
|
deps.log?.(`learning: run ${input.runId}: the compile of ${workflow} failed its checks (attempt ${attempt}${attempt === 2 ? ", stopped" : ""})`);
|
|
504
505
|
}
|
|
@@ -552,8 +553,10 @@ export async function compileAskOf(deps, input) {
|
|
|
552
553
|
const { agentId } = input;
|
|
553
554
|
// A revision is asked only of a workflow its promotion holds, once per hold. The workflows whose newest revision other
|
|
554
555
|
// than their champion (learn/promote.ts championOf: it serves while that one is held) is held: the run's own may be one.
|
|
556
|
+
// A record the purge gate refuses is skipped as the champion's readers skip it (purged-workflow.ts refusedOf); a gate
|
|
557
|
+
// that can't be asked skips none, and the text read below is gated again.
|
|
555
558
|
const records = await promotionsOf(deps.store.settings, agentId).catch(() => []);
|
|
556
|
-
const heldNames = heldNamesOf(records);
|
|
559
|
+
const heldNames = heldNamesOf(records, records.length ? await refusedIn(() => deps.learningFolder(agentId), deps.store, deps.log)(records).catch(() => undefined) : undefined);
|
|
557
560
|
// The loop's numbers on the agent's definition (the revision this run runs): the first compile waits for compile_after
|
|
558
561
|
// completed agent runs, the ending one counted.
|
|
559
562
|
const { compile_after: compileAfter } = await loopOfRun(deps.store, input.runId);
|
|
@@ -587,8 +590,10 @@ export async function compileAskOf(deps, input) {
|
|
|
587
590
|
// `main`: the commit the snapshot read is main's at, which `current` was read from.
|
|
588
591
|
let read;
|
|
589
592
|
try {
|
|
593
|
+
// A workflow a purged run wrote is neither counted nor told (purgeGate), on main or at a replayed round's parent.
|
|
590
594
|
const readFrom = async ({ snapshot, body }) => {
|
|
591
|
-
const
|
|
595
|
+
const purged = (await purgeGate(snapshot, deps.store)).workflows;
|
|
596
|
+
const workflows = (snapshot?.workflows ?? []).filter(({ name, status }) => (status === "active" || status === "pending") && !purged.has(name));
|
|
592
597
|
const textOf = async (name) => {
|
|
593
598
|
const file = workflows.find((one) => one.name === name)?.files.find(({ path }) => path.endsWith("/workflow.json"));
|
|
594
599
|
const text = file ? await body(file.path, file.oid) : undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AlsoRow, Claim, Command, Journal } from "../store/store.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { HeldRedact } from "./redact.js";
|
|
3
3
|
import type { Compared, GraderReply } from "../learn/promote.js";
|
|
4
4
|
export type { AlsoRow, Claim, Command, Journal };
|
|
5
5
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
@@ -187,9 +187,14 @@ export interface LoopDeps {
|
|
|
187
187
|
* The ticker writes it to the run's run_live row, one store transaction per tick for all its loops, never into the
|
|
188
188
|
* journal. Absent: not reported. */
|
|
189
189
|
live?: (read: () => HeldState | undefined) => void;
|
|
190
|
-
/** The runner's one redactor (redact.ts): an error's text the loop writes to its run's
|
|
191
|
-
* secret the runner holds is stored,
|
|
192
|
-
|
|
190
|
+
/** The runner's one redactor (redact.ts), the same instance for every loop: an error's text the loop writes to its run's
|
|
191
|
+
* end goes through it, so no secret the runner holds is stored, its values cut the run's live view (live-ticker.ts),
|
|
192
|
+
* and a claim carries the run's own tool keys into it (claim-secrets.ts). */
|
|
193
|
+
redact: HeldRedact;
|
|
194
|
+
/** The incarnation of the runner's word in the store (runner/presence.ts), the claim's runner being the claim's own
|
|
195
|
+
* `runner`: a park that keeps a computer only this runner can reach again pins it to both (workspace/computer-kept.ts
|
|
196
|
+
* pinnedOf), so the claim rule gives the run back to this runner while it is there. Absent: nothing is pinned. */
|
|
197
|
+
incarnation?: string;
|
|
193
198
|
}
|
|
194
199
|
/** A run's held state: what pi shows before it stores it. The live view (live/stream.ts) streams it beside the stored
|
|
195
200
|
* commits' events, in the door's vocabulary (a running tool's tool_execution_start, a partial's message_update). */
|
package/dist/runner/main.js
CHANGED
|
@@ -23,6 +23,7 @@ import { startRunnerRelay } from "../dial-relay.js";
|
|
|
23
23
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
24
24
|
import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
|
|
25
25
|
import { dockerPathsForRuns } from "../box-paths.js";
|
|
26
|
+
import { COMPOSIO_KEY_ENV } from "../composio-made.js";
|
|
26
27
|
import { hostCommandRefusals } from "../computers.js";
|
|
27
28
|
import { hostAddressesOnce } from "../docker-host-addresses.js";
|
|
28
29
|
import { claimInstallsStopped } from "../harness-install.js";
|
|
@@ -94,8 +95,9 @@ export async function openRunnerStore(dataDir, env, warn, url) {
|
|
|
94
95
|
}
|
|
95
96
|
/** The runner's own secrets, which a run never gets, not even in the runner's in-process environment: the server's
|
|
96
97
|
* tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), the store's connection (its URL holds a
|
|
97
|
-
* database password),
|
|
98
|
-
|
|
98
|
+
* database password), the launch hook's signing secret (the server's alone), and the Composio account key, which the
|
|
99
|
+
* runner's claim alone reads (composio-made.ts composioEnvKey) and sends only as a granted Composio server's MCP header. */
|
|
100
|
+
const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name === LAUNCH_HOOK_SECRET_ENV || name === COMPOSIO_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
|
|
99
101
|
/** A run's environment as the runner hands its loops (AdapterSpecDeps.env): this process's, less the runner's own
|
|
100
102
|
* secrets, with every other secret the launcher's pipe handed it (a model key, a tool key, a box key) readable by name
|
|
101
103
|
* but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
|
|
@@ -255,7 +257,8 @@ export async function startRunnerProcess(options) {
|
|
|
255
257
|
// tokens and proofs name the same one, so the server's "restarted since" and the runner's row speak of one process.
|
|
256
258
|
// The presence first, then the relay says where it answers on the presence's row.
|
|
257
259
|
// Its row says this build's version and the most runs it holds (its loops), for the server's capacity read.
|
|
258
|
-
|
|
260
|
+
const incarnation = randomUUID();
|
|
261
|
+
presence = keepPresence(store.runners, name, null, { warn, incarnation, slots: options.loops ?? RUNNER_LOOPS });
|
|
259
262
|
// Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
|
|
260
263
|
// server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
|
|
261
264
|
relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, presence, env, log: warn });
|
|
@@ -265,12 +268,15 @@ export async function startRunnerProcess(options) {
|
|
|
265
268
|
const createLoop = typeof parts === "function" ? parts : parts.createLoop;
|
|
266
269
|
// The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
|
|
267
270
|
// warnings, said where the runner says its others (warn: stderr unless a test gives its own).
|
|
271
|
+
// It sweeps as this runner (its name and its presence's incarnation): a computer kept at a park pinned to another
|
|
272
|
+
// runner still there is that runner's to end (computer-kept.ts sweepKept).
|
|
268
273
|
if (options.janitor && typeof parts !== "function")
|
|
269
|
-
janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
|
|
274
|
+
janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn, self: { runner: name, incarnation } });
|
|
270
275
|
// Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
|
|
271
276
|
await sweepEndedScratch(store, options.dataDir, { log: warn });
|
|
272
|
-
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts)
|
|
273
|
-
|
|
277
|
+
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts), as
|
|
278
|
+
// this runner, as the janitor sweeps: a computer kept pinned to another runner still keeping it is that runner's.
|
|
279
|
+
const runEnded = projectRunEnded(store, typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn, self: () => ({ runner: name, incarnation }) }) : undefined);
|
|
274
280
|
runner = startRunner({
|
|
275
281
|
store,
|
|
276
282
|
createLoop,
|
|
@@ -43,6 +43,9 @@ export interface McpClaimOptions {
|
|
|
43
43
|
/** For tests only (no environment or CLI flag maps onto it): the one origin a github_app server may have, a fake for
|
|
44
44
|
* GitHub's hosted MCP (GITHUB_MCP_ORIGIN). */
|
|
45
45
|
githubMcpOrigin?: string;
|
|
46
|
+
/** For tests only (no environment or CLI flag maps onto it): the one origin a key read from the environment is sent to,
|
|
47
|
+
* a fake for Composio's (COMPOSIO_ORIGIN; composioEnvKey). */
|
|
48
|
+
composioMcpOrigin?: string;
|
|
46
49
|
/** The run's redactors (runner/redact.ts, the spec's `cut`): every credential value this step hands the gateway (each
|
|
47
50
|
* header's value and a Bearer's bare token: a saved one, a refreshed OAuth token, a minted GitHub App token, a per_run
|
|
48
51
|
* server's handed one at the claim and at each fresh()) is held by them as it is handed over, before any call carries
|
package/dist/runner/mcp-claim.js
CHANGED
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
//
|
|
28
28
|
// A per-run Composio server (composio-made.ts composioPerRun) is bound by each run's caller ({composio_user_id,
|
|
29
29
|
// connected_account_id?} in mcp_auth, sealed in its launch): its entry carries them as `query` (mcp-gateway.ts).
|
|
30
|
+
// A Composio server saved with api_key_env (composio-made.ts key_env) seals no key: each open reads the variable's value
|
|
31
|
+
// as the runner was handed it at its start (secrets.ts secret, never its environment), for an address on Composio's origin
|
|
32
|
+
// alone (composioEnvKey), and only for a server the run is granted: the run's process never holds it. Unset, or a row at
|
|
33
|
+
// another address, the claim is refused before the loop starts (pinOf), in words naming it, and nothing is sent.
|
|
30
34
|
//
|
|
31
35
|
// fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
|
|
32
36
|
// expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
|
|
@@ -53,7 +57,7 @@ import { randomUUID } from "node:crypto";
|
|
|
53
57
|
import { EndpointRefused, REFRESH_REQUEST_MS, refreshed, refused, RequestUnsent, systemNetwork } from "../mcp-oauth.js";
|
|
54
58
|
import { pinFirst } from "../mcp-pin-first.js";
|
|
55
59
|
import { mcpNameOf } from "../tool-names.js";
|
|
56
|
-
import { composioMadeKey, composioPerRun } from "../composio-made.js";
|
|
60
|
+
import { composioEnvKey, composioMadeKey, composioPerRun, recordedMade } from "../composio-made.js";
|
|
57
61
|
import { composioRunQuery } from "../composio-preset.js";
|
|
58
62
|
import { META_REASON, metaToolOf } from "../mcp-meta.js";
|
|
59
63
|
import { resourceToolProblem } from "../mcp-resources.js";
|
|
@@ -221,6 +225,13 @@ export async function mcpClaim(options) {
|
|
|
221
225
|
if (account && "unopened" in account)
|
|
222
226
|
return entry({ unopened: account.unopened }), { awaited: false };
|
|
223
227
|
const query = account?.query;
|
|
228
|
+
// Its key named by api_key_env: the value the runner was handed at its start, for an address on Composio's origin
|
|
229
|
+
// alone; else its calls refused unsent, naming why (composioEnvKey).
|
|
230
|
+
const keyEnv = await keyEnvOf(store, name, row);
|
|
231
|
+
if (keyEnv) {
|
|
232
|
+
const got = composioEnvKey(name, row.url, keyEnv, options.composioMcpOrigin);
|
|
233
|
+
return entry("key" in got ? { headers: { "x-api-key": got.key }, ...(query ? { query } : {}) } : { unopened: got.refused }), { awaited: false };
|
|
234
|
+
}
|
|
224
235
|
if (row.sealed === null)
|
|
225
236
|
return entry({ ...(query ? { query } : {}) }), { awaited: false };
|
|
226
237
|
// A seal problem first: no refresh is ever sent for a credential this runner cannot open.
|
|
@@ -451,7 +462,7 @@ export async function mcpClaim(options) {
|
|
|
451
462
|
}
|
|
452
463
|
/** The run's pin: its revision's, as its save made it, held to the run's grants and checked against the meta tools known
|
|
453
464
|
* now; undefined when it grants no MCP tool. A granted tool the pin does not hold refuses the claim in words. */
|
|
454
|
-
async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN, pinListing, signal }) {
|
|
465
|
+
async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN, composioMcpOrigin, pinListing, signal }) {
|
|
455
466
|
// A github_app server anywhere but GitHub's hosted MCP ends the run here, before any token is minted or anything sent:
|
|
456
467
|
// the App's tokens go to GitHub alone (github.ts githubMcpUrl, the one check).
|
|
457
468
|
const offGithub = (server, url, auth) => {
|
|
@@ -509,10 +520,23 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
|
|
|
509
520
|
if (row && metaToolOf(row.url, tool.name))
|
|
510
521
|
throw new McpClaimRefused(`mcp:${server}/${tool.name} can't be granted: ${META_REASON}`);
|
|
511
522
|
offGithub(server, url, row?.auth);
|
|
523
|
+
// A Composio server whose key variable is unset, or whose address is off Composio's origin: the run never starts
|
|
524
|
+
// without its tools, and nothing is sent.
|
|
525
|
+
const keyEnv = row ? await keyEnvOf(store, server, row) : undefined;
|
|
526
|
+
const got = row && keyEnv ? composioEnvKey(server, row.url, keyEnv, composioMcpOrigin) : undefined;
|
|
527
|
+
if (got && "refused" in got)
|
|
528
|
+
throw new McpClaimRefused(`${got.refused} Nothing was sent.`);
|
|
512
529
|
}
|
|
513
530
|
// As plain JSON, as the stored pin reads (the harnesses and the run's directory take it as such).
|
|
514
531
|
return JSON.parse(JSON.stringify(pinned));
|
|
515
532
|
}
|
|
533
|
+
/** The variable a Composio server saved with api_key_env reads its key from (its record's key_env): a headers row that
|
|
534
|
+
* seals none. None for every other row. */
|
|
535
|
+
async function keyEnvOf(store, name, row) {
|
|
536
|
+
if (row.auth !== "headers" || row.sealed !== null)
|
|
537
|
+
return undefined;
|
|
538
|
+
return recordedMade(await store.settings.get(composioMadeKey(name)), row.createdAt)?.key_env;
|
|
539
|
+
}
|
|
516
540
|
/** The claim still the run's: its epoch unchanged, else Fenced. */
|
|
517
541
|
async function confirm(store, claim) {
|
|
518
542
|
const run = await store.runs.get(claim.runId);
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -38,6 +38,9 @@ export interface McpForClaimOptions {
|
|
|
38
38
|
/** A test's fake GitHub MCP origin, handed to the claim step (mcpClaim's githubMcpOrigin): for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP
|
|
39
39
|
* (github.ts GITHUB_MCP_ORIGIN). */
|
|
40
40
|
readonly githubMcpOrigin?: string;
|
|
41
|
+
/** A test's fake Composio MCP origin, handed to the claim step and the pin's listing (mcpClaim's composioMcpOrigin): for
|
|
42
|
+
* tests only: no environment variable, flag or setting maps onto it; absent, Composio's (composio-made.ts COMPOSIO_ORIGIN). */
|
|
43
|
+
readonly composioMcpOrigin?: string;
|
|
41
44
|
/** Whether this runner may reach an MCP server whose URL is on loopback (AdapterSpecDeps.mcpLoopback): the runner
|
|
42
45
|
* beside a local-install server, or a runner in its own process whose own environment opts in. Absent, never. */
|
|
43
46
|
readonly loopback?: boolean;
|
package/dist/runner/mcp-run.js
CHANGED
|
@@ -36,13 +36,14 @@ export async function mcpForClaim(options) {
|
|
|
36
36
|
sealKey: options.sealKey,
|
|
37
37
|
signal: held.signal,
|
|
38
38
|
// A run whose revision has no pin (one made before the upgrade) pins it here, listing as a save does.
|
|
39
|
-
pinListing: registryListing(options.store, options.sealKey, { loopback: options.loopback === true, own: options.own ?? [], ...(options.network ? { network: options.network } : {}), ...(githubApp ? { githubApp } : {}), ...(options.githubMcpOrigin ? { appOrigin: options.githubMcpOrigin } : {}) }),
|
|
39
|
+
pinListing: registryListing(options.store, options.sealKey, { loopback: options.loopback === true, own: options.own ?? [], ...(options.network ? { network: options.network } : {}), ...(githubApp ? { githubApp } : {}), ...(options.githubMcpOrigin ? { appOrigin: options.githubMcpOrigin } : {}), ...(options.composioMcpOrigin ? { composioOrigin: options.composioMcpOrigin } : {}) }),
|
|
40
40
|
...(options.bounds ? { bounds: options.bounds } : {}),
|
|
41
41
|
...(options.network ? { network: options.network } : {}),
|
|
42
42
|
...(options.loopback ? { loopback: true } : {}),
|
|
43
43
|
...(options.own ? { own: options.own } : {}),
|
|
44
44
|
...(githubApp ? { githubApp } : {}),
|
|
45
45
|
...(options.githubMcpOrigin ? { githubMcpOrigin: options.githubMcpOrigin } : {}),
|
|
46
|
+
...(options.composioMcpOrigin ? { composioMcpOrigin: options.composioMcpOrigin } : {}),
|
|
46
47
|
...(options.githubTimer ? { githubTimer: options.githubTimer } : {}),
|
|
47
48
|
...(options.hold ? { hold: options.hold } : {}),
|
|
48
49
|
});
|