@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35
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 +135 -0
- package/README.md +84 -16
- package/dist/adapters.d.ts +3 -0
- package/dist/adapters.js +7 -0
- package/dist/agent-rows.d.ts +1 -0
- package/dist/agents-store.js +17 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +6 -3
- package/dist/cap.js +7 -4
- package/dist/cli.js +32 -5
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-setting.d.ts +6 -5
- package/dist/computer-setting.js +54 -26
- package/dist/computers.d.ts +9 -4
- package/dist/computers.js +4 -2
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/explain.js +3 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.js +5 -2
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +3 -3
- package/dist/learn/folder.d.ts +6 -3
- package/dist/learn/folder.js +7 -16
- package/dist/learn/grade.d.ts +4 -1
- package/dist/learn/grade.js +43 -5
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.js +5 -3
- package/dist/learn/skills.d.ts +48 -5
- package/dist/learn/skills.js +97 -21
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +9 -5
- package/dist/learned-workflow.js +53 -9
- package/dist/learning-routes.d.ts +41 -0
- package/dist/learning-routes.js +94 -26
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning.d.ts +0 -22
- package/dist/learning.js +0 -16
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +3 -0
- package/dist/model.js +8 -0
- package/dist/openapi.js +37 -13
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +1 -10
- package/dist/run-launch.d.ts +5 -3
- package/dist/run-launch.js +6 -5
- package/dist/run-learning-served.d.ts +11 -0
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-timeline-served.js +12 -2
- package/dist/run-view.d.ts +30 -14
- package/dist/run-view.js +60 -32
- package/dist/runnable.d.ts +4 -1
- package/dist/runnable.js +14 -2
- package/dist/runner/adapter-loop.d.ts +30 -4
- package/dist/runner/adapter-loop.js +253 -29
- package/dist/runner/adapter-run-spec.d.ts +21 -0
- package/dist/runner/adapter-run-spec.js +104 -28
- package/dist/runner/adapters/pi.d.ts +29 -1
- package/dist/runner/adapters/pi.js +95 -23
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +18 -0
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +3 -0
- package/dist/runner/cli-run-spec.js +123 -34
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +5 -5
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +23 -0
- package/dist/runner/journal-kinds.d.ts +38 -2
- package/dist/runner/journal-kinds.js +23 -0
- package/dist/runner/learning-end.js +88 -16
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +13 -5
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +26 -11
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +14 -1
- package/dist/runner/metrics.js +72 -1
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/runner.js +90 -8
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +4 -1
- package/dist/runner/workflow-loop.js +8 -2
- package/dist/runner/workflow-spec.d.ts +3 -0
- package/dist/runner/workflow-spec.js +156 -78
- package/dist/runs-over-store.d.ts +7 -1
- package/dist/runs-over-store.js +42 -11
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +21 -18
- package/dist/server.js +183 -34
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +5 -1
- package/dist/store/agent-body.js +11 -5
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +55 -9
- package/dist/store/sqlite/connection.js +3 -38
- package/dist/store-reads/journal.js +39 -4
- package/dist/store-reads/learning.d.ts +58 -2
- package/dist/store-reads/learning.js +172 -7
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +45 -12
- package/dist/templates.d.ts +9 -4
- package/dist/templates.js +14 -9
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +6 -2
- package/dist/tool-gate.js +8 -5
- package/dist/tool-plane.d.ts +9 -10
- package/dist/tools.d.ts +37 -7
- package/dist/tools.js +73 -12
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -1
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +9 -10
- package/dist/workspace/computer-deps.js +53 -40
- package/dist/workspace/computer-for-claim.d.ts +5 -3
- package/dist/workspace/computer-for-claim.js +28 -16
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +8 -3
- package/dist/workspace/resolve-computer.js +28 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +9 -3
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +1 -14
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +2 -2
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
|
@@ -13,19 +13,20 @@
|
|
|
13
13
|
// Shared with the pi spec: the run's Workspace and its uploaded files, a sandbox run's computer, the kernel registry's
|
|
14
14
|
// hands on them (runTools), the gate from the store's tool settings, the system prompt (environment line, instructions
|
|
15
15
|
// with what the agent learned and its skills, effort guidance), the first message, the end's metrics and the release.
|
|
16
|
-
import { mkdir } from "node:fs/promises";
|
|
16
|
+
import { mkdir, rm, rmdir } from "node:fs/promises";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
19
19
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
20
|
import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
21
|
-
import {
|
|
21
|
+
import { noNewPrivsPrefix } from "@parcha/pi-durable-disk/internals";
|
|
22
|
+
import { confineOf, thinkingFor } from "../adapters.js";
|
|
22
23
|
import { installDirOf, installingWords, installSettled } from "../harness-install.js";
|
|
23
24
|
import { HarnessUnavailable } from "../provider.js";
|
|
24
25
|
import { effortGuidance } from "../effort-guidance.js";
|
|
25
26
|
import { environmentLine } from "../environment.js";
|
|
26
27
|
import { harnessOf } from "../harness-table.js";
|
|
27
28
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
28
|
-
import { layLearningSeed } from "./learning-seed.js";
|
|
29
|
+
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
29
30
|
import { learningWorkspace } from "../learn/folder.js";
|
|
30
31
|
import { learningEndOfRun } from "./learning-end.js";
|
|
31
32
|
import { providerModels, runModels } from "../model.js";
|
|
@@ -33,7 +34,7 @@ import { firstMessage } from "../run-manifest.js";
|
|
|
33
34
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
34
35
|
import { readsFiles, systemOf } from "../skills.js";
|
|
35
36
|
import { DATA_ENV } from "../server-fs.js";
|
|
36
|
-
import {
|
|
37
|
+
import { copyRunFiles } from "../uploads.js";
|
|
37
38
|
import { isObject } from "../validate.js";
|
|
38
39
|
import { runFolder, scratchFolder } from "../workspace/paths.js";
|
|
39
40
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
@@ -43,19 +44,21 @@ import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
|
|
|
43
44
|
import { loadArchilSettings } from "../archil-settings.js";
|
|
44
45
|
import { imageWaitWords } from "../workspace/computer-deps.js";
|
|
45
46
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
46
|
-
import { adapterRunGate, answersCut, buildToolHost, hostToolCtxOf, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, webHostTools, webToolNames } from "./adapter-run-spec.js";
|
|
47
|
+
import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools, webToolNames } from "./adapter-run-spec.js";
|
|
48
|
+
import { openTierProxies } from "./adapters/pi.js";
|
|
47
49
|
import { signInReads } from "../sign-ins-store.js";
|
|
48
|
-
import { claimSecrets, learnedDecisionKeys, withModelKeys } from "./claim-secrets.js";
|
|
50
|
+
import { claimSecrets, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
49
51
|
import { mcpForClaim } from "./mcp-run.js";
|
|
50
52
|
import { TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
51
53
|
import { resolveHarness } from "./adapters/index.js";
|
|
52
54
|
import { entriesOf } from "./loop.js";
|
|
53
|
-
import { bookedSpend,
|
|
55
|
+
import { bookedSpend, cliRunMetrics } from "./metrics.js";
|
|
54
56
|
import { journalEntries } from "./journal-reader.js";
|
|
55
57
|
import { specBuilt } from "./spec-holds.js";
|
|
56
58
|
import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
|
|
57
59
|
import { githubAppAccess } from "./github-app.js";
|
|
58
60
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
61
|
+
import { bashPolicyOf } from "../bash-read-only.js";
|
|
59
62
|
/** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
|
|
60
63
|
export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
|
|
61
64
|
/** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
|
|
@@ -102,6 +105,22 @@ function cliRunEnv(env, data, claimed = {}) {
|
|
|
102
105
|
Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
|
|
103
106
|
return out;
|
|
104
107
|
}
|
|
108
|
+
/** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
|
|
109
|
+
* laid things in since (a follow-up's) stays, with what is in it. */
|
|
110
|
+
export async function sweepScratch(dir, parents) {
|
|
111
|
+
await rm(dir, { recursive: true, force: true });
|
|
112
|
+
for (const parent of parents) {
|
|
113
|
+
try {
|
|
114
|
+
await rmdir(parent);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
const code = error.code;
|
|
118
|
+
if (code === "ENOTEMPTY" || code === "EEXIST" || code === "ENOENT")
|
|
119
|
+
return;
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
105
124
|
/**
|
|
106
125
|
* One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
|
|
107
126
|
*
|
|
@@ -137,7 +156,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
137
156
|
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
|
|
138
157
|
// credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
|
|
139
158
|
// First, before the session opens: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its words.
|
|
140
|
-
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, deps.githubApi ? { api: deps.githubApi } : {}),
|
|
159
|
+
const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold: (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
|
|
160
|
+
redact.hold(values); } }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
|
|
141
161
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
142
162
|
holds.hold({ passed: mcp });
|
|
143
163
|
// The harness: the launch's, else the revision's. Its table entry (facts, model choice, adapter, skill check), read from
|
|
@@ -172,13 +192,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
172
192
|
? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
|
|
173
193
|
: await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
|
|
174
194
|
holds.hold({ ws });
|
|
175
|
-
if (launch.files?.length)
|
|
176
|
-
|
|
177
|
-
if (!copied) {
|
|
178
|
-
const uploads = new Uploads(join(deps.data, UPLOADS_DIR));
|
|
179
|
-
await uploads.copyInto(ws.workspace, await uploads.readyFiles(launch.files));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
195
|
+
if (launch.files?.length)
|
|
196
|
+
await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
|
|
182
197
|
// The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
|
|
183
198
|
// It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
|
|
184
199
|
const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
|
|
@@ -188,16 +203,29 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
188
203
|
// whose computer is a browser is refused in words at its claim, before anything is made.
|
|
189
204
|
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)) } : {}) });
|
|
190
205
|
holds.hold({ computer });
|
|
191
|
-
// The CLI works in the run's scratch folder on this machine (its working directory,
|
|
192
|
-
//
|
|
193
|
-
// folder for the run's file tools: a path the CLI builds from its working directory lands in the run's folder, and
|
|
194
|
-
// other absolute path is refused (workspace/paths.ts portPath).
|
|
206
|
+
// The CLI works in the run's scratch folder on this machine (its working directory), its own files (home, state, the
|
|
207
|
+
// skills laid for it) in this claim's private folder inside it, never on the run's disk. The scratch is an alias of the
|
|
208
|
+
// run's folder for the run's file tools: a path the CLI builds from its working directory lands in the run's folder, and
|
|
209
|
+
// any other absolute path is refused (workspace/paths.ts portPath).
|
|
210
|
+
// The private folder is swept at the spec's release, the claim's end, then the scratch folder if nothing else is in it:
|
|
211
|
+
// the next claim, here or on another runner, lays its own, its harness's session coming back from the run's journal.
|
|
212
|
+
// Its own per claim (by the claim's epoch), so a run reopened while this claim still lets go (its release follows the
|
|
213
|
+
// run's end commit) never has the next claim's folder swept from under it.
|
|
195
214
|
const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
|
|
196
|
-
const
|
|
197
|
-
|
|
215
|
+
const harnesses = join(scratch, "harness");
|
|
216
|
+
const dir = join(harnesses, String(claim.epoch));
|
|
217
|
+
holds.hold({ scratch: { sweep: () => sweepScratch(dir, [harnesses, scratch]) } });
|
|
218
|
+
// Made again once if a parent went as it was made (the last claim's sweep removing the then empty scratch folder).
|
|
219
|
+
await mkdir(dir, { recursive: true, mode: 0o700 }).catch(async (error) => {
|
|
220
|
+
if (error.code !== "ENOENT")
|
|
221
|
+
throw error;
|
|
222
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
223
|
+
});
|
|
198
224
|
// The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
|
|
199
225
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
200
|
-
|
|
226
|
+
// Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv), as the pi spec does.
|
|
227
|
+
const bashPolicy = bashPolicyOf(body.toolSettings);
|
|
228
|
+
const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }) });
|
|
201
229
|
holds.hold({ tools });
|
|
202
230
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
203
231
|
// The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
|
|
@@ -247,20 +275,50 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
247
275
|
if (typeof settled === "object")
|
|
248
276
|
throw new HarnessUnavailable(settled.failed, "install");
|
|
249
277
|
}
|
|
250
|
-
|
|
278
|
+
// The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
|
|
279
|
+
// (pi-durable-disk's noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
|
|
280
|
+
// or a command it runs reaches grants nothing; none on macOS. Where setpriv is not usable the run is refused, in pi's words.
|
|
281
|
+
const confine = confineOf(noNewPrivsPrefix());
|
|
282
|
+
const built = await entry.adapter(env, { model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}) });
|
|
251
283
|
// The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
|
|
252
284
|
// every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
|
|
253
285
|
// the CLI's own error names the harness first, as main words it (harness-app.ts: `<harness>: <error>`), so the run's
|
|
254
286
|
// error and its Timeline row say which CLI said it.
|
|
287
|
+
// The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
|
|
288
|
+
// lay chose the workflows, below): each on a proxy of its own beside the CLI session's (openTierProxies, pi's), on the
|
|
289
|
+
// session's booking, reached through the session's port with a `tier`. The CLI never sees them.
|
|
290
|
+
const tierRoutes = new Map();
|
|
255
291
|
const adapter = {
|
|
256
292
|
...built,
|
|
257
293
|
open: async (spec, io) => {
|
|
258
294
|
const session = await built.open(spec, { ...io, dir, cwd: scratch });
|
|
295
|
+
let tiers;
|
|
296
|
+
try {
|
|
297
|
+
tiers = await openTierProxies(tierRoutes, io.models, cut);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
await session.close().catch(() => undefined);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
io.signal.addEventListener("abort", () => void tiers.close(), { once: true });
|
|
259
304
|
const turnEnd = session.turnEnd.bind(session);
|
|
260
|
-
|
|
305
|
+
const close = session.close.bind(session);
|
|
306
|
+
const port = session.port?.bind(session);
|
|
307
|
+
return Object.assign(session, {
|
|
308
|
+
turnEnd: async () => {
|
|
261
309
|
const end = await turnEnd();
|
|
262
310
|
return end.error ? { ...end, error: `${name}: ${end.error}` } : end;
|
|
263
|
-
}
|
|
311
|
+
},
|
|
312
|
+
close: async () => {
|
|
313
|
+
await close();
|
|
314
|
+
await tiers.close();
|
|
315
|
+
},
|
|
316
|
+
// The session's port; with a `tier`, that tier's proxy, while the session's own port is up (none once closed).
|
|
317
|
+
port: (label, tier) => {
|
|
318
|
+
const own = port?.(label);
|
|
319
|
+
return tier === undefined || own === undefined ? own : tiers.port(label, tier);
|
|
320
|
+
},
|
|
321
|
+
});
|
|
264
322
|
},
|
|
265
323
|
};
|
|
266
324
|
// The run's cap (its launch's maxCostUsd): the kernel's check before each paid request, at the catalog price of the
|
|
@@ -274,8 +332,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
274
332
|
// kernel runCap from these over the run's own sessions; the spec carries no beforeRequest of its own.
|
|
275
333
|
const runCap = {
|
|
276
334
|
capUsd: () => launch.maxCostUsd,
|
|
277
|
-
// One model per CLI session: every request it sends is the run's model, whatever id its provider names it by.
|
|
278
|
-
|
|
335
|
+
// One model per CLI session: every request it sends is the run's model, whatever id its provider names it by. A
|
|
336
|
+
// learned node's request on a tier's proxy names its tier (ModelRequest.route) and is priced as that route books it,
|
|
337
|
+
// even under an id the run's model shares.
|
|
338
|
+
modelOf: (id, by) => {
|
|
339
|
+
if (by === undefined)
|
|
340
|
+
return capModel;
|
|
341
|
+
const tierRoute = tierRoutes.get(by);
|
|
342
|
+
return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
|
|
343
|
+
},
|
|
279
344
|
...(launch.capMode === "strict" ? { mode: "strict" } : {}),
|
|
280
345
|
};
|
|
281
346
|
const cap = capUsd === undefined
|
|
@@ -337,10 +402,27 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
337
402
|
webTools = await webHostTools(host, granted, ctx);
|
|
338
403
|
}
|
|
339
404
|
if (learns) {
|
|
405
|
+
// A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
|
|
406
|
+
// keys, pi's wires, since pi-ai's client sends these, never the CLI); one refused fails its node in its words.
|
|
407
|
+
// Their models' keys (tierModelKeys: a saved one too, which claimSecrets opened only for the run's own model), held by
|
|
408
|
+
// the redactors, on the tiers' route env alone (withModelKeys, never enumerable), never on the tools' (toolEnv).
|
|
409
|
+
const tierKeys = await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
410
|
+
for (const redact of new Set([held, cut]))
|
|
411
|
+
holdClaimed(redact, tierKeys);
|
|
412
|
+
const modelEnv = withModelKeys(deps.env, { ...claimed, ...tierKeys });
|
|
413
|
+
const tiers = new Map();
|
|
414
|
+
for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
|
|
415
|
+
if ("why" in routed)
|
|
416
|
+
tiers.set(tier, { why: routed.why });
|
|
417
|
+
else {
|
|
418
|
+
tierRoutes.set(tier, routed);
|
|
419
|
+
tiers.set(tier, { model: routed.model });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
340
422
|
// The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
|
|
341
423
|
// own MCP as the loop wraps it.
|
|
342
424
|
gate.learn(workflows);
|
|
343
|
-
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, ...(mcp ? { mcp } : {}) });
|
|
425
|
+
learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}) });
|
|
344
426
|
}
|
|
345
427
|
}
|
|
346
428
|
const session = {
|
|
@@ -386,19 +468,26 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
386
468
|
...(mcp ? { mcp } : {}),
|
|
387
469
|
// The run's end-of-run step, when it learns (the spec's, preferred over the loop's deps': adapter-loop.ts stepOf).
|
|
388
470
|
...(endOfRun ? { endOfRun } : {}),
|
|
471
|
+
...(start ? { learningLaid: laidOf(seedLaid) } : {}),
|
|
389
472
|
// The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
|
|
390
473
|
...(life ? { lifecycle: life } : {}),
|
|
391
474
|
agentId: runRow.agentId,
|
|
392
475
|
workRoot: root,
|
|
393
|
-
//
|
|
394
|
-
//
|
|
395
|
-
|
|
476
|
+
// Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
|
|
477
|
+
// against on the run's rows.
|
|
478
|
+
cwd: scratch,
|
|
479
|
+
// The end's metrics: its tools from the run's record, its tokens and model requests its booking's, at its model
|
|
480
|
+
// (metrics.ts cliRunMetrics). Its cost is its booking's too: the harness's own record carries no per-request cost or
|
|
481
|
+
// usage, so its model requests are counted at what the run's model proxy booked them at (bookedSpend over every
|
|
482
|
+
// session of its journal), as a pi run's are at its answers' costs and tokens.
|
|
396
483
|
endPatch: async () => {
|
|
397
484
|
const entries = await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context);
|
|
398
|
-
|
|
399
|
-
//
|
|
485
|
+
// Its tokens and model requests, and its model requests' cost, from one read of its booking (cliRunMetrics); its
|
|
486
|
+
// decisions (a learned workflow's) at what they were booked at too.
|
|
400
487
|
const all = (await journalEntries(deps.journal(claim), context));
|
|
401
|
-
const
|
|
488
|
+
const booked = bookedSpend(all, "model");
|
|
489
|
+
const metrics = cliRunMetrics(entries, booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}` });
|
|
490
|
+
const model = booked.usd;
|
|
402
491
|
const decisions = bookedSpend(all, "decisions").usd;
|
|
403
492
|
const costUsd = model === null || decisions === null ? null : model + decisions;
|
|
404
493
|
// Its paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own
|
|
@@ -26,6 +26,7 @@ export declare function suiteTools(countFile?: string): {
|
|
|
26
26
|
letSlowGo: () => void;
|
|
27
27
|
slowStarted: Promise<void>;
|
|
28
28
|
};
|
|
29
|
+
/** A store in a data directory of its own, one queued run, and runners started on it (each its own connection). */
|
|
29
30
|
/** The stores' clock skew a runner process reads (child.ts): the file holds the milliseconds the clock moved, so the
|
|
30
31
|
* process's store moves with the case's (runOut). */
|
|
31
32
|
export declare const storeClockOf: (file: string | undefined) => (() => number);
|
|
@@ -129,9 +129,6 @@ const STORE_URLS = new WeakMap();
|
|
|
129
129
|
* today. */
|
|
130
130
|
const POSTGRES_PENDING = {};
|
|
131
131
|
/** A store in a data directory of its own, one queued run, and runners started on it (each its own connection). */
|
|
132
|
-
/** The suite's short lease, for the crash cases: a crashed runner's claim must run out for the second runner to take
|
|
133
|
-
* the run over. */
|
|
134
|
-
const TAKEOVER = {};
|
|
135
132
|
/** The stores' clock skew a runner process reads (child.ts): the file holds the milliseconds the clock moved, so the
|
|
136
133
|
* process's store moves with the case's (runOut). */
|
|
137
134
|
export const storeClockOf = (file) => {
|
|
@@ -787,10 +784,13 @@ const CASES = [
|
|
|
787
784
|
await sendCommand(w.server, RUN, { kind: "deny", body: { approval: callId, note: "not on a Friday" } });
|
|
788
785
|
await w.ended("ended");
|
|
789
786
|
assert.equal(ran.asked, 0, "denied, it never ran");
|
|
790
|
-
const { answers, messages } = await w.read();
|
|
787
|
+
const { answers, messages, calls } = await w.read();
|
|
791
788
|
// The fields this case is about; its time is the loop's clock's (adapter-pi-approval-entries pins it).
|
|
792
789
|
assert.deepEqual(answers.map(({ callId: id, approved, decision, note }) => ({ callId: id, approved, decision, note })), [{ callId, approved: false, decision: "deny", note: "not on a Friday" }], "the answer is a deny that keeps the note");
|
|
793
|
-
|
|
790
|
+
// What the model said after the asked call: its answer to the refusal. What it said with the call, before the gate
|
|
791
|
+
// asked (a CLI's "Calling asked."), is on the record before the call's row, as pi keeps a call's text in its message.
|
|
792
|
+
const asked = calls.find((call) => call.callId === callId);
|
|
793
|
+
const said = messages.filter((message) => message.role === "model" && message.entry > (asked?.startEntry ?? -1)).map((message) => message.text);
|
|
794
794
|
assert.equal(said.length, 1, `the model answered once: ${JSON.stringify(messages)}`);
|
|
795
795
|
// Main's words for a call a person denied (tool-gate.ts refusedText), the note with them. The harness may frame a
|
|
796
796
|
// refusal its own way (pi: a blocked call's error) around them.
|
|
@@ -7,10 +7,15 @@ export type GithubAppAccessAt = GithubAppAccess & {
|
|
|
7
7
|
/** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
|
|
8
8
|
* server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
|
|
9
9
|
* with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
|
|
10
|
-
* runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
|
|
10
|
+
* runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
|
|
11
|
+
* `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
|
|
12
|
+
* the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
|
|
13
|
+
* joins the run's redactor (its `cut`), the first and every one after. */
|
|
11
14
|
export declare function githubAppAccess(store: {
|
|
12
15
|
readonly triggerSettings: Pick<TriggerSettings, "get">;
|
|
13
|
-
}, sealKey: Buffer | undefined, firstInput: unknown, { api, now }?: {
|
|
16
|
+
}, sealKey: Buffer | undefined, firstInput: unknown, { api, now, fromGitHub, hold }?: {
|
|
14
17
|
api?: string;
|
|
15
18
|
now?: () => number;
|
|
19
|
+
fromGitHub?: boolean;
|
|
20
|
+
hold?: (values: string[]) => void;
|
|
16
21
|
}): Promise<GithubAppAccessAt | undefined>;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// The runner's side of a github_app MCP server (runner/mcp-github.ts): the server's GitHub App, read from the store at each
|
|
2
|
-
// claim, bound into the mint the claim step calls, with the run's repository. The App's id and
|
|
3
|
-
// server sealed in trigger_settings (adapter "github", scope "server", AAD
|
|
4
|
-
// sealed-settings-store.ts writes them), opened here with the runner's seal key
|
|
2
|
+
// claim and again before each mint, bound into the mint the claim step calls, with the run's repository. The App's id and
|
|
3
|
+
// private key are the rows the server sealed in trigger_settings (adapter "github", scope "server", AAD
|
|
4
|
+
// trigger_settings|github|server|<field>, as sealed-settings-store.ts writes them), opened here with the runner's seal key.
|
|
5
5
|
// No App (never connected, disconnected, or rows that do not open under this key): no access, and such a server's calls
|
|
6
|
-
// are refused in words (GITHUB_UNUSABLE.noAccess).
|
|
6
|
+
// are refused in words (GITHUB_UNUSABLE.noAccess). An App disconnected or replaced while a run holds a token: its next
|
|
7
|
+
// mint is refused as disconnected, and the claim step drops and revokes the token it holds.
|
|
7
8
|
import { unseal } from "../sealing.js";
|
|
8
|
-
import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubTargetOf, mintInstallationToken } from "../github.js";
|
|
9
|
+
import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubCall, githubTargetOf, mintInstallationToken } from "../github.js";
|
|
9
10
|
import { isObject } from "../validate.js";
|
|
10
11
|
const ADAPTER = "github";
|
|
11
12
|
const aad = (field) => `trigger_settings|${ADAPTER}|${GITHUB_SCOPE}|${field}`;
|
|
12
|
-
/** The
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
* runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it. */
|
|
16
|
-
export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now } = {}) {
|
|
17
|
-
if (!sealKey)
|
|
18
|
-
return undefined;
|
|
13
|
+
/** The server's App as the store holds it now, opened with `sealKey`: its id and private key, or undefined when there is none
|
|
14
|
+
* this key opens. */
|
|
15
|
+
async function appOf(store, sealKey) {
|
|
19
16
|
const rows = (await store.triggerSettings.get(ADAPTER)).filter((row) => row.scope === GITHUB_SCOPE);
|
|
20
17
|
const open = (field) => {
|
|
21
18
|
const row = rows.find((r) => r.field === field);
|
|
@@ -30,8 +27,42 @@ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB
|
|
|
30
27
|
};
|
|
31
28
|
const appId = open(GITHUB_FIELDS.appId);
|
|
32
29
|
const pem = open(GITHUB_FIELDS.privateKey);
|
|
33
|
-
|
|
30
|
+
return appId && pem ? { appId, pem } : undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
|
|
33
|
+
* server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
|
|
34
|
+
* with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
|
|
35
|
+
* runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
|
|
36
|
+
* `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
|
|
37
|
+
* the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
|
|
38
|
+
* joins the run's redactor (its `cut`), the first and every one after. */
|
|
39
|
+
export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold } = {}) {
|
|
40
|
+
if (!sealKey)
|
|
41
|
+
return undefined;
|
|
42
|
+
const app = await appOf(store, sealKey);
|
|
43
|
+
if (!app)
|
|
34
44
|
return undefined;
|
|
35
|
-
const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput);
|
|
36
|
-
return {
|
|
45
|
+
const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput, { payload: fromGitHub });
|
|
46
|
+
return {
|
|
47
|
+
api,
|
|
48
|
+
target,
|
|
49
|
+
// The App read again before each mint: one disconnected or replaced since the claim makes no token for this run.
|
|
50
|
+
mint: async (to) => {
|
|
51
|
+
// A read that fails throws on: the step's github_failed path keeps the token held until it expires, never a disconnect.
|
|
52
|
+
const still = await appOf(store, sealKey);
|
|
53
|
+
if (!still || still.appId !== app.appId || still.pem !== app.pem)
|
|
54
|
+
return { ok: false, reason: "disconnected", message: "the GitHub App was disconnected or replaced on this server" };
|
|
55
|
+
const minted = await mintInstallationToken(api, app.appId, app.pem, to, now());
|
|
56
|
+
if (minted.ok)
|
|
57
|
+
hold?.([minted.token]);
|
|
58
|
+
return minted;
|
|
59
|
+
},
|
|
60
|
+
// Before each call: the App as the store holds it now, the same id and key, or the run's token stops.
|
|
61
|
+
same: async () => {
|
|
62
|
+
const still = await appOf(store, sealKey);
|
|
63
|
+
return Boolean(still && still.appId === app.appId && still.pem === app.pem);
|
|
64
|
+
},
|
|
65
|
+
// An installation token revokes itself (DELETE /installation/token, the token its own credential): no App needed.
|
|
66
|
+
revoke: async (token) => void (await githubCall(api, "/installation/token", { method: "DELETE", jwt: token }).catch(() => undefined)),
|
|
67
|
+
};
|
|
37
68
|
}
|
|
@@ -2,7 +2,12 @@ import type { RunLaunch } from "../run-launch.js";
|
|
|
2
2
|
import { type AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
3
3
|
import { type GradeRouteAsk } from "./learning-dispatch.js";
|
|
4
4
|
import type { GraderRoute } from "./learning-ask.js";
|
|
5
|
-
import type
|
|
5
|
+
import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
|
|
6
|
+
/** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
|
|
7
|
+
* refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
|
|
8
|
+
export declare class NeverFits extends ClaimRefused {
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
6
11
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
7
12
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
8
13
|
export declare function resolveRunnerLoop(deps: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
// The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
|
|
2
|
+
// and the harness its launch names. The runner holds one dispatch loop (dispatch.ts) for every run; at the claim the
|
|
3
|
+
// dispatch reads the launch and asks this switch for the run's inner loop:
|
|
4
|
+
// - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
|
|
5
|
+
// harness is pi), so the revision is read here to tell it from an agentic pi run;
|
|
6
|
+
// - a built-in learning run (its launch names harness "learning") runs on the learning loop;
|
|
7
|
+
// - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch);
|
|
8
|
+
// - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
|
|
9
|
+
// - anything else fails the run in words (the dispatch's UnknownHarness).
|
|
10
|
+
import { hostMemory, neverFits } from "../host.js";
|
|
1
11
|
import { resolveHarness } from "./adapters/index.js";
|
|
2
12
|
import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
|
|
3
13
|
import { createAdapterLoop } from "./adapter-loop.js";
|
|
@@ -5,8 +15,14 @@ import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
|
5
15
|
import { createDispatchLoop } from "./dispatch.js";
|
|
6
16
|
import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
|
|
7
17
|
import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
|
|
18
|
+
import { ClaimRefused } from "./loop-contract.js";
|
|
8
19
|
import { createWorkflowLoop, isWorkflowRevision } from "./workflow-loop.js";
|
|
9
20
|
import { workflowSpecOf } from "./workflow-spec.js";
|
|
21
|
+
/** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
|
|
22
|
+
* refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
|
|
23
|
+
export class NeverFits extends ClaimRefused {
|
|
24
|
+
name = "NeverFits";
|
|
25
|
+
}
|
|
10
26
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
11
27
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
12
28
|
export function resolveRunnerLoop(deps) {
|
|
@@ -49,6 +65,13 @@ export function resolveRunnerLoop(deps) {
|
|
|
49
65
|
// runs the pi spec (adapterRunSpecFromLaunch). A harness with no entry is unknown here: the dispatch fails it in words.
|
|
50
66
|
const runner = resolveHarness(harness);
|
|
51
67
|
if (runner) {
|
|
68
|
+
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
69
|
+
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
70
|
+
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
71
|
+
// the host's memory and its OOM kill would take every run on it.
|
|
72
|
+
const tooBig = neverFits(harness, hostMemory());
|
|
73
|
+
if (tooBig)
|
|
74
|
+
throw new NeverFits(tooBig);
|
|
52
75
|
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
53
76
|
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
54
77
|
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { MessageOrigin } from "../timeline/index.js";
|
|
2
|
+
/** The session (sessions.ts journalSessions) a workflow run's call nodes log their effects on (KINDS.nodeEffect). */
|
|
3
|
+
export declare const NODE_LOG_SESSION = "node-log";
|
|
2
4
|
/** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
|
|
3
5
|
* sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
|
|
4
6
|
* other. */
|
|
@@ -47,11 +49,23 @@ export declare const KINDS: {
|
|
|
47
49
|
/** The resume of a paused workflow run (a `resume` row), taken: the workflow goes on from its journal. Neither a call nor
|
|
48
50
|
* a message, so the reader passes over it. */
|
|
49
51
|
readonly resume: "agentrun.resume";
|
|
52
|
+
/** A paid call the cap refused for room, kept at its refusal (the Refusal): its pause lands at the model's next request
|
|
53
|
+
* (adapter-loop.ts pauseFor), and a claim lost before that restores it from here (pendingPauseOf). No run patch, and
|
|
54
|
+
* neither a call nor a message, so the reader passes over it. */
|
|
55
|
+
readonly pausePending: "agentrun.pause.pending";
|
|
56
|
+
/** A workflow call node's effect, as it starts and as it ends (pause.ts NodeLine: its path, item, tool, label, input,
|
|
57
|
+
* then its status and output or error), on the run's node-log session (NODE_LOG_SESSION): the run's graph lists its
|
|
58
|
+
* effects from these. Written as the effect runs, never for one the driver answers from its receipt. */
|
|
59
|
+
readonly nodeEffect: "agentrun.node.effect";
|
|
50
60
|
/** A CLI run's end-of-run turn (the loop's record): its prompt (`role: "person"`) and its answer (`role: "model"`, the
|
|
51
61
|
* text in `model` as pi's answer carries it), the entry and the answer of the submission its request id names, the
|
|
52
62
|
* same submission pi's adapter writes, so the step reads both alike. Neither a call nor a message: the reader passes
|
|
53
63
|
* over it, and the turn is never on the run's visible record. */
|
|
54
64
|
readonly endOfRunTurn: "agentrun.end-of-run.turn";
|
|
65
|
+
/** What a learning run's claim laid of its seed: the learned skills it was given (`skills`, by name) and the learned
|
|
66
|
+
* workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
|
|
67
|
+
* what the run was given. Neither a call nor a message. */
|
|
68
|
+
readonly learningLaid: "agentrun.learning.laid";
|
|
55
69
|
/** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
|
|
56
70
|
readonly learningGraded: "agentrun.learning.graded";
|
|
57
71
|
/** A learning run's merge: the new main and its commit, with the run's end. */
|
|
@@ -107,6 +121,13 @@ export interface RaiseData {
|
|
|
107
121
|
readonly capUsd: number;
|
|
108
122
|
readonly takes: readonly number[];
|
|
109
123
|
}
|
|
124
|
+
/** The cap a run is held to now, from its journal: its newest raise's (a KINDS.raise entry above 0), else its launch's;
|
|
125
|
+
* none for a run launched with no cap. The one figure every reader of the run's cap takes: each request's admission
|
|
126
|
+
* (adapter-loop.ts capNow), the run's view, and its end-of-run look back (learning-end.ts). */
|
|
127
|
+
export declare function capNowOf(launchCapUsd: number | undefined, entries: readonly {
|
|
128
|
+
readonly kind: string;
|
|
129
|
+
readonly data?: unknown;
|
|
130
|
+
}[]): number | undefined;
|
|
110
131
|
/** What a run parked at its cap waits on (the kernel cap's parkOf): its cap, what the cap counted as taken, the least the
|
|
111
132
|
* refused request needs, the least cap that sends it and the raise offered, in the run's money units (dollars). */
|
|
112
133
|
export interface BudgetData {
|
|
@@ -130,9 +151,15 @@ export interface CallStartData {
|
|
|
130
151
|
readonly input: unknown;
|
|
131
152
|
/** May run again after a crash (it changes nothing outside the run): the tool registry's own flag. */
|
|
132
153
|
readonly replaySafe: boolean;
|
|
133
|
-
/** Written as the call reached its gate through a CLI's own MCP client,
|
|
134
|
-
* agentrun.call.sent mark (KINDS.callSent). */
|
|
154
|
+
/** Written as the call reached its gate through a CLI's own MCP client, or its tool bridge's gate asked about it, before
|
|
155
|
+
* any answer: nothing is sent until its agentrun.call.sent mark (KINDS.callSent). */
|
|
135
156
|
readonly parked?: true;
|
|
157
|
+
/** Parked in its CLI's tool bridge (adapter-loop.ts bridgeGate), not at an MCP door: the bridge holds the call and hands
|
|
158
|
+
* the CLI nothing while it waits, so no waiting result shows for it (store-reads/journal.ts piShaped), as on pi. */
|
|
159
|
+
readonly bridge?: true;
|
|
160
|
+
/** The harness's working directory (a CLI's), which an absolute path in `input` is built from: the run's rows name a
|
|
161
|
+
* path under it by its name in the workspace (store-reads/journal.ts runTimeline). */
|
|
162
|
+
readonly cwd?: string;
|
|
136
163
|
/** When it was written (ms, the loop's clock): the Timeline dates the call's row by it. */
|
|
137
164
|
readonly at?: number;
|
|
138
165
|
}
|
|
@@ -225,6 +252,15 @@ export interface EndData {
|
|
|
225
252
|
/** A completed workflow run's output: the value at its workflow's output path (readWorkflowRun's `output`, null when it
|
|
226
253
|
* has none), kept at its end as main's server kept it on the run (runs.ts workflowEnd), and served as result.output. */
|
|
227
254
|
readonly output?: unknown;
|
|
255
|
+
/** An escalated workflow run's review (outcome escalated): why it waits for a person, as its escalate node said it. */
|
|
256
|
+
readonly review?: EndReview;
|
|
257
|
+
}
|
|
258
|
+
/** An escalated workflow run's review as its end keeps it: the escalation's kind, the escalate node's label (else the node
|
|
259
|
+
* it escalated at), and its summary (else the run's). Served as the run's `review`, `at` its end. */
|
|
260
|
+
export interface EndReview {
|
|
261
|
+
readonly kind: string | null;
|
|
262
|
+
readonly node: string | null;
|
|
263
|
+
readonly reason: string;
|
|
228
264
|
}
|
|
229
265
|
export interface SessionKeyData {
|
|
230
266
|
readonly key: string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
|
|
2
|
+
/** The session (sessions.ts journalSessions) a workflow run's call nodes log their effects on (KINDS.nodeEffect). */
|
|
3
|
+
export const NODE_LOG_SESSION = "node-log";
|
|
2
4
|
/** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
|
|
3
5
|
* sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
|
|
4
6
|
* other. */
|
|
@@ -47,11 +49,23 @@ export const KINDS = {
|
|
|
47
49
|
/** The resume of a paused workflow run (a `resume` row), taken: the workflow goes on from its journal. Neither a call nor
|
|
48
50
|
* a message, so the reader passes over it. */
|
|
49
51
|
resume: "agentrun.resume",
|
|
52
|
+
/** A paid call the cap refused for room, kept at its refusal (the Refusal): its pause lands at the model's next request
|
|
53
|
+
* (adapter-loop.ts pauseFor), and a claim lost before that restores it from here (pendingPauseOf). No run patch, and
|
|
54
|
+
* neither a call nor a message, so the reader passes over it. */
|
|
55
|
+
pausePending: "agentrun.pause.pending",
|
|
56
|
+
/** A workflow call node's effect, as it starts and as it ends (pause.ts NodeLine: its path, item, tool, label, input,
|
|
57
|
+
* then its status and output or error), on the run's node-log session (NODE_LOG_SESSION): the run's graph lists its
|
|
58
|
+
* effects from these. Written as the effect runs, never for one the driver answers from its receipt. */
|
|
59
|
+
nodeEffect: "agentrun.node.effect",
|
|
50
60
|
/** A CLI run's end-of-run turn (the loop's record): its prompt (`role: "person"`) and its answer (`role: "model"`, the
|
|
51
61
|
* text in `model` as pi's answer carries it), the entry and the answer of the submission its request id names, the
|
|
52
62
|
* same submission pi's adapter writes, so the step reads both alike. Neither a call nor a message: the reader passes
|
|
53
63
|
* over it, and the turn is never on the run's visible record. */
|
|
54
64
|
endOfRunTurn: "agentrun.end-of-run.turn",
|
|
65
|
+
/** What a learning run's claim laid of its seed: the learned skills it was given (`skills`, by name) and the learned
|
|
66
|
+
* workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
|
|
67
|
+
* what the run was given. Neither a call nor a message. */
|
|
68
|
+
learningLaid: "agentrun.learning.laid",
|
|
55
69
|
/** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
|
|
56
70
|
learningGraded: "agentrun.learning.graded",
|
|
57
71
|
/** A learning run's merge: the new main and its commit, with the run's end. */
|
|
@@ -79,6 +93,15 @@ export const ASK_PERSON_WAITING = "Waiting for your reply";
|
|
|
79
93
|
export const HANDOVER_WAITING = "Waiting for you in the browser";
|
|
80
94
|
/** The summaries of a run held in its claim while it waits on its person: the server tells run.needs_input by them. */
|
|
81
95
|
export const HELD_WAITS = new Set([ASK_PERSON_WAITING, HANDOVER_WAITING]);
|
|
96
|
+
/** The cap a run is held to now, from its journal: its newest raise's (a KINDS.raise entry above 0), else its launch's;
|
|
97
|
+
* none for a run launched with no cap. The one figure every reader of the run's cap takes: each request's admission
|
|
98
|
+
* (adapter-loop.ts capNow), the run's view, and its end-of-run look back (learning-end.ts). */
|
|
99
|
+
export function capNowOf(launchCapUsd, entries) {
|
|
100
|
+
if (launchCapUsd === undefined)
|
|
101
|
+
return undefined;
|
|
102
|
+
const raised = entries.findLast((entry) => entry.kind === KINDS.raise && typeof entry.data?.capUsd === "number" && entry.data.capUsd > 0);
|
|
103
|
+
return raised ? raised.data.capUsd : launchCapUsd;
|
|
104
|
+
}
|
|
82
105
|
/** What a call that already ended answers when it is asked for again (a parked call's resume, a CLI's re-issue of its id):
|
|
83
106
|
* its recorded output; for one a crash cut with none, the kernel's words for an outcome not known (INTERRUPTED_TEXT);
|
|
84
107
|
* else that `tool`'s call ended so. An error unless it ended done. */
|