@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
package/dist/tool-gate.js
CHANGED
|
@@ -347,14 +347,17 @@ export class RunGate {
|
|
|
347
347
|
* the deny (with where it was set, and that nothing was sent or charged), a pin, bash's policy (policyRefusal), then
|
|
348
348
|
* the allow, then the ask, so an allow that approvals "never" made is decided
|
|
349
349
|
* only after every refusal. Where no one can approve (accounts off: the store's approvers row a runner reads at each
|
|
350
|
-
* claim, server-approvers.ts), the ask is refused at once in words, never parked, as `enter` refuses it.
|
|
351
|
-
|
|
350
|
+
* claim, server-approvers.ts), the ask is refused at once in words, never parked, as `enter` refuses it. `replayed`:
|
|
351
|
+
* the call is run again after an earlier attempt that may have been sent (a replay-safe call rerun after a crash), so a
|
|
352
|
+
* refusal says whether it took effect is not known, never that nothing was sent. */
|
|
353
|
+
async decide(name, args, options = {}) {
|
|
352
354
|
const key = settingsKeyOf(this.where.harness ?? DEFAULT_HARNESS, name, this.where.mcpServers) ?? name;
|
|
353
355
|
const tool = this.askedAs(name);
|
|
356
|
+
const ran = options.replayed ? "unknown" : "no";
|
|
354
357
|
const verdict = this.policy(name);
|
|
355
358
|
if (verdict === "deny")
|
|
356
|
-
return { deny: deniedText(tool, key, this.denyFrom(name),
|
|
357
|
-
const pinned = this.pinned(key, args,
|
|
359
|
+
return { deny: deniedText(tool, key, this.denyFrom(name), ran) };
|
|
360
|
+
const pinned = this.pinned(key, args, ran);
|
|
358
361
|
if (pinned)
|
|
359
362
|
return { deny: pinned.text };
|
|
360
363
|
const policed = this.policyRefusal(key, name, args);
|
|
@@ -362,7 +365,7 @@ export class RunGate {
|
|
|
362
365
|
return { deny: policed };
|
|
363
366
|
if (verdict === "allow")
|
|
364
367
|
return "allow";
|
|
365
|
-
return this.approvers ? "ask" : { deny: noApproverText(tool,
|
|
368
|
+
return this.approvers ? "ask" : { deny: noApproverText(tool, ran) };
|
|
366
369
|
}
|
|
367
370
|
/** The name a call is asked about by, as main's request names it (enter's `tool`): its settings key, a shell tool its
|
|
368
371
|
* own name; a name nothing maps, as it came. */
|
package/dist/tool-plane.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { type BashPolicy } from "./bash-read-only.js";
|
|
|
10
10
|
* never does), and a catalog's tools (`monid.*`, `mcp:<server>/<tool>`: catalog tools, which their catalog grants).
|
|
11
11
|
*/
|
|
12
12
|
export declare const CAPABILITIES: readonly ["read", "write", "edit", "web_search", "web_fetch", "browser", "ask_person"];
|
|
13
|
-
export type Capability = (typeof CAPABILITIES)[number];
|
|
14
13
|
/** The providers a user may pick for each capability that has a choice, its default first: `auto`, the native search
|
|
15
14
|
* where there is one (never on claude-agent, where Claude's own search is picked as `native`), else Parallel where the
|
|
16
15
|
* server holds its key, else keyless Exa; `native`, the harness's own tool or its model provider's hosted one, and
|
|
@@ -38,9 +37,9 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
|
|
|
38
37
|
* give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
|
|
39
38
|
* those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
|
|
40
39
|
export declare const serverGate: (name: string, settings: ToolSettingsMap) => {
|
|
41
|
-
permission: "deny" | "
|
|
42
|
-
default_permission: "deny" | "
|
|
43
|
-
permissions: ("deny" | "
|
|
40
|
+
permission: "deny" | "allow" | "ask";
|
|
41
|
+
default_permission: "deny" | "allow" | "ask";
|
|
42
|
+
permissions: ("deny" | "allow" | "ask")[];
|
|
44
43
|
};
|
|
45
44
|
/** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
|
|
46
45
|
* workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL). */
|
|
@@ -269,10 +268,10 @@ export declare function saveToolSettings(store: {
|
|
|
269
268
|
* provider choice the provider in force and where it came from, the one that applies when the agent sets none, and what
|
|
270
269
|
* it resolves to on the agent's harness and model. */
|
|
271
270
|
export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[]): ({
|
|
272
|
-
permission: "deny" | "
|
|
271
|
+
permission: "deny" | "allow" | "ask";
|
|
273
272
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
274
|
-
default_permission: "deny" | "
|
|
275
|
-
permissions: ("deny" | "
|
|
273
|
+
default_permission: "deny" | "allow" | "ask";
|
|
274
|
+
permissions: ("deny" | "allow" | "ask")[];
|
|
276
275
|
blurb?: string | undefined;
|
|
277
276
|
name: string;
|
|
278
277
|
} | {
|
|
@@ -280,10 +279,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
|
|
|
280
279
|
provider_from: string;
|
|
281
280
|
default_provider: string;
|
|
282
281
|
resolved: Resolution;
|
|
283
|
-
permission: "deny" | "
|
|
282
|
+
permission: "deny" | "allow" | "ask";
|
|
284
283
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
285
|
-
default_permission: "deny" | "
|
|
286
|
-
permissions: ("deny" | "
|
|
284
|
+
default_permission: "deny" | "allow" | "ask";
|
|
285
|
+
permissions: ("deny" | "allow" | "ask")[];
|
|
287
286
|
blurb?: string | undefined;
|
|
288
287
|
name: string;
|
|
289
288
|
})[];
|
package/dist/tools.d.ts
CHANGED
|
@@ -153,6 +153,18 @@ export declare const evidenceIn: (work: Workspace) => {
|
|
|
153
153
|
bodyLine?: undefined;
|
|
154
154
|
}>;
|
|
155
155
|
};
|
|
156
|
+
/** What browser_upload may choose: a file of the run's Workspace, the one its read opens, by a path relative to it. The
|
|
157
|
+
* Workspace refuses a path that would leave it (absolute, "..", a link anywhere on the way), so nothing outside the run's
|
|
158
|
+
* folder is ever read; a file must be a regular one of at most `maxBytes`. `mime` names its media type by its name. */
|
|
159
|
+
export declare const uploadsFrom: (work: Workspace, maxBytes: number, mime: (name: string) => string) => {
|
|
160
|
+
resolve(rel: string): Promise<{
|
|
161
|
+
bytes: Uint8Array;
|
|
162
|
+
name: string;
|
|
163
|
+
mime: string;
|
|
164
|
+
} | {
|
|
165
|
+
refused: string;
|
|
166
|
+
}>;
|
|
167
|
+
};
|
|
156
168
|
/** The Browserbase contexts a run's browser may open: its agent's saved sign-in's alone, by its profile name, never one
|
|
157
169
|
* made here (nothing a run makes is kept for its agent). */
|
|
158
170
|
export declare const keptContexts: (ref: string | undefined) => {
|
|
@@ -209,17 +221,35 @@ export declare const CALL_TOOLS: readonly string[];
|
|
|
209
221
|
/** Whether `name` is one of `allowed`. */
|
|
210
222
|
export declare const allows: (allowed: readonly string[], name: string) => boolean;
|
|
211
223
|
/** The tools a run's learned workflow may name (learn/check.ts at learn time, learned-workflow.ts at a call): those of the
|
|
212
|
-
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS
|
|
224
|
+
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
|
|
225
|
+
* skills.ts LEARNED_MCP_TOOL: a wildcard is read against its server's listing first, mcpGrantsListed), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name does not run either). A
|
|
213
226
|
* learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
|
|
214
227
|
* exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
|
|
215
|
-
export declare const learnedWorkflowTools: (granted: readonly string[], plane?: Plane) => string[];
|
|
228
|
+
export declare const learnedWorkflowTools: (granted: readonly string[], plane?: Plane, options?: LearnedMcp) => string[];
|
|
229
|
+
/** `mcp: true` at learn time (the end-of-run step's draft tools, a person's write): an MCP tool the revision grants by its
|
|
230
|
+
* own name may be named. Without it (the runtime's read at a call, learned-workflow.ts), none is: the run's MCP tools are
|
|
231
|
+
* its pin's, which the runtime reads apart and holds to the gate itself (#2424). `approvers`: whether anyone can answer
|
|
232
|
+
* an ask here (server-approvers.ts). Only then is an MCP tool set to ask offered: with no one, #2424 refuses the
|
|
233
|
+
* learned call's ask at once, so offering it would only teach a workflow that never runs. Not said: no one. */
|
|
234
|
+
export type LearnedMcp = {
|
|
235
|
+
readonly mcp?: boolean;
|
|
236
|
+
readonly approvers?: boolean;
|
|
237
|
+
};
|
|
238
|
+
/** `granted` with each MCP server's wildcard (`mcp:<server>/*`) read as the tools its server lists now (`listed`, by the
|
|
239
|
+
* server's name: none for a server not saved), each `mcp:<server>/<tool>`, in place; every other name as it is, each
|
|
240
|
+
* once. What a revision grants under a wildcard is every tool of its server, so a learned draft may name each one
|
|
241
|
+
* (learnedWorkflowTools), its gate holding it as any tool (learnedDraftTools: the wildcard's setting, or the tool's own).
|
|
242
|
+
* At proposal time there is no run and no pin: whether the run's pin has the tool is the runtime's to check at the call,
|
|
243
|
+
* in the gate's words (learned-workflow.ts). */
|
|
244
|
+
export declare function mcpGrantsListed(granted: readonly string[], listed: (server: string) => readonly string[]): string[];
|
|
216
245
|
/** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
|
|
217
246
|
* tool to now (tool-gate.ts permissionOf, or the run's gate's policy), by its settings key. One set to ask or deny is left out of `tools`, so the end-of-run prompt never offers it, and named
|
|
218
247
|
* in `gated` with its setting, which the checker and a learned workflow's check before it runs refuse a draft for. */
|
|
219
|
-
export declare const learnedDraftTools: (granted: readonly string[], permission: (name: string) => string, plane?: Plane, from?: (name: string) => SettingFrom) => {
|
|
248
|
+
export declare const learnedDraftTools: (granted: readonly string[], permission: (name: string) => string, plane?: Plane, from?: (name: string) => SettingFrom, options?: LearnedMcp) => {
|
|
220
249
|
tools: string[];
|
|
221
250
|
gated: Record<string, string>;
|
|
222
251
|
deniedBy: Record<string, DenyFrom>;
|
|
252
|
+
asked: string[];
|
|
223
253
|
};
|
|
224
254
|
/** The tools a workflow names (`nodes` from workflowNodes): on its model nodes (`tools`), and on its `call` nodes
|
|
225
255
|
* `via: "tool"` (`tool`). */
|
|
@@ -263,14 +293,14 @@ export declare function toolRefusal(names: readonly string[], env: NodeJS.Proces
|
|
|
263
293
|
* saying that. Each tool also gives its permission under the server's settings (tool-gate.ts), the owner's default
|
|
264
294
|
* and the permissions it may be set to. */
|
|
265
295
|
export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettingsMap, noBox?: string, refused?: Readonly<Record<string, string>>, runnerShell?: ReadonlySet<string>) => {
|
|
266
|
-
providers?: ("auto" | "native" | "parallel" | "
|
|
296
|
+
providers?: ("auto" | "native" | "parallel" | "off" | "kernel" | "browserbase" | "exa-keyless" | "chrome")[] | undefined;
|
|
267
297
|
provider?: string | undefined;
|
|
268
298
|
default_provider?: "auto" | "kernel" | undefined;
|
|
269
299
|
resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
|
|
270
300
|
why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
|
|
271
|
-
permission: "deny" | "
|
|
272
|
-
default_permission: "deny" | "
|
|
273
|
-
permissions: ("deny" | "
|
|
301
|
+
permission: "deny" | "allow" | "ask";
|
|
302
|
+
default_permission: "deny" | "allow" | "ask";
|
|
303
|
+
permissions: ("deny" | "allow" | "ask")[];
|
|
274
304
|
harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
|
|
275
305
|
missing?: string[] | undefined;
|
|
276
306
|
reason?: string | undefined;
|
package/dist/tools.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// run's folder or its computer. `bash` and the background tools may be named only by an agent whose place is a box
|
|
6
6
|
// (runnable.ts).
|
|
7
7
|
import { blurbOf } from "./tool-blurbs.js";
|
|
8
|
+
import { LEARNED_MCP_TOOL } from "./learn/skills.js";
|
|
8
9
|
import { appendFileSync } from "node:fs";
|
|
9
10
|
import { pathToFileURL } from "node:url";
|
|
10
11
|
import { defineExtension, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
@@ -14,6 +15,7 @@ import { isWorkspaceError, localWorkspace } from "./workspace/index.js";
|
|
|
14
15
|
import { fetchOptions, HTML_READ_CHARS, TEXT_CAP } from "./web-fetch-direct.js";
|
|
15
16
|
import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
|
|
16
17
|
import { REPLAY } from "./host-tools.js";
|
|
18
|
+
import { localFolderOf } from "./workspace/local.js";
|
|
17
19
|
import { LLM_TOOL } from "./llm.js";
|
|
18
20
|
import { DOCUMENTS_ENV, PDF_PAGES_TOOL, pdfPages } from "./pdf-pages.js";
|
|
19
21
|
import { monidTool } from "./monid.js";
|
|
@@ -146,6 +148,35 @@ export const evidenceIn = (work) => {
|
|
|
146
148
|
},
|
|
147
149
|
};
|
|
148
150
|
};
|
|
151
|
+
/** What browser_upload may choose: a file of the run's Workspace, the one its read opens, by a path relative to it. The
|
|
152
|
+
* Workspace refuses a path that would leave it (absolute, "..", a link anywhere on the way), so nothing outside the run's
|
|
153
|
+
* folder is ever read; a file must be a regular one of at most `maxBytes`. `mime` names its media type by its name. */
|
|
154
|
+
export const uploadsFrom = (work, maxBytes, mime) => ({
|
|
155
|
+
async resolve(rel) {
|
|
156
|
+
if (typeof rel !== "string" || !rel.trim())
|
|
157
|
+
return { refused: "path must name a file in the workspace" };
|
|
158
|
+
const refusal = (error) => (isWorkspaceError(error, "ESCAPE") ? `${rel} resolves outside the workspace` : isWorkspaceError(error, "NOT_FOUND") ? `no file at ${rel} in the workspace` : `${rel} cannot be opened`);
|
|
159
|
+
try {
|
|
160
|
+
const info = await work.stat(rel);
|
|
161
|
+
if (!info)
|
|
162
|
+
return { refused: `no file at ${rel} in the workspace` };
|
|
163
|
+
if (info.kind !== "file")
|
|
164
|
+
return { refused: `${rel} is not a regular file` };
|
|
165
|
+
if (info.size > maxBytes)
|
|
166
|
+
return { refused: `${rel} is ${info.size} bytes, over the ${maxBytes}-byte limit` };
|
|
167
|
+
// The file as its stat sized it, and nothing past that: one that shrank, or grew before or while it was read, is
|
|
168
|
+
// refused, never chosen in part.
|
|
169
|
+
const bytes = await work.read(rel, { length: info.size });
|
|
170
|
+
if (bytes.byteLength !== info.size || (await work.read(rel, { offset: info.size, length: 1 })).byteLength > 0)
|
|
171
|
+
return { refused: `${rel} changed while it was read; try again` };
|
|
172
|
+
const name = rel.split("/").at(-1) ?? rel;
|
|
173
|
+
return { bytes, name, mime: mime(name) };
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return { refused: refusal(error) };
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
});
|
|
149
180
|
/** The Browserbase contexts a run's browser may open: its agent's saved sign-in's alone, by its profile name, never one
|
|
150
181
|
* made here (nothing a run makes is kept for its agent). */
|
|
151
182
|
export const keptContexts = (ref) => ({
|
|
@@ -230,10 +261,10 @@ const browserTool = {
|
|
|
230
261
|
// (its reconcile, its release and drain, its live view hang off that run's lifecycle). A node naming it is refused when
|
|
231
262
|
// its definition is saved (runnable.ts), never accepted and then failed at its run.
|
|
232
263
|
nodes: false,
|
|
233
|
-
// Its downloads
|
|
264
|
+
// Its downloads go into work/ by path (pi-browser), which a box's command could turn through a link.
|
|
234
265
|
runnerOnly: true,
|
|
235
266
|
bind: async (host) => {
|
|
236
|
-
const [{ BACKGROUND_CONTEXT: context }, { createBrowserExtension }, { DEFAULT_BROWSER_POLICY, BrowserFailureError, browserFailure,
|
|
267
|
+
const [{ BACKGROUND_CONTEXT: context }, { createBrowserExtension }, { DEFAULT_BROWSER_POLICY, BrowserFailureError, browserFailure, MAX_UPLOAD_BYTES, uploadMime }, { createDrivingGates, createLiveView, liveViewProvider }, live, person] = await Promise.all([
|
|
237
268
|
import("@earendil-works/chord/context"),
|
|
238
269
|
import("@parcha/pi-browser/durable"),
|
|
239
270
|
import("@parcha/pi-browser"),
|
|
@@ -347,10 +378,15 @@ const browserTool = {
|
|
|
347
378
|
// On the runner, the run's ledger (host.ledger): each call held and settled on its booking, and a session's release one
|
|
348
379
|
// more request there, never this process's own spend. Undefined on the old per-run process: browserSpend's own then.
|
|
349
380
|
const spend = browserSpend(providerName, price, DEFAULT_BROWSER_POLICY.idleReleaseS, (conversation, at) => browser.release(conversation, "close", at), undefined, { paid: host.ledger?.paid, pause: host.ledger?.pause, flush: host.ledger?.flush });
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
const
|
|
353
|
-
|
|
381
|
+
// The run's own Workspace, the one its read opens (on the runner: Mode 1's local folder, Mode 2's folder on the run's
|
|
382
|
+
// disk): the browser files its evidence there, and browser_upload chooses from it.
|
|
383
|
+
const work = host.workspace ?? localWorkspace(host.where.work);
|
|
384
|
+
// browser_downloads copies into a folder by its local path (pi-browser fetchDownloads), so it is listed only where the
|
|
385
|
+
// run's Workspace is a folder of this machine (never on Mode 2's disk, where the run's read would not find what it
|
|
386
|
+
// copied), and only for a provider that keeps a session's downloads (Browserbase's; Kernel's keeps none).
|
|
387
|
+
const folder = localFolderOf(work);
|
|
388
|
+
const keepsDownloads = typeof parts.provider?.downloads === "object";
|
|
389
|
+
const files = { files: uploadsFrom(work, MAX_UPLOAD_BYTES, uploadMime), ...(folder !== undefined && keepsDownloads ? { workspace: () => folder } : {}) };
|
|
354
390
|
// A session that saved to the sign-in, let go: its time, for the sign-in's verified_at when the run's lease ends.
|
|
355
391
|
// On the runner, the store's verified_at under the run's claim (runSignInSaved), never a mark in the run's directory.
|
|
356
392
|
const verify = kept?.save && host.claim && host.store && host.sealKey ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
|
|
@@ -371,7 +407,7 @@ const browserTool = {
|
|
|
371
407
|
// vendor's refusal can quote it, as pi-browser's one-saver rule names Kernel's profile.
|
|
372
408
|
// A run handed its agent's sign-in tells the model its browser keeps it (`run`'s description): one with none claims
|
|
373
409
|
// cookies across pages only.
|
|
374
|
-
const browser = createBrowserExtension({ provider, driver: parts.driver, evidence: evidenceIn(
|
|
410
|
+
const browser = createBrowserExtension({ provider, driver: parts.driver, evidence: evidenceIn(work), ...files, gates, handoff: hands.handoff, onSession: onSessions, signIns: kept !== undefined, beforeCreate: spend.opening, redact: { values: () => [...runnerSecrets(host.env), ...(kept ? [kept.ref] : [])] }, prices: { sessionUsdPerHour: price.usdPerHour, sessionMinimumS: price.minimumS }, onCharge: spend.onCharge });
|
|
375
411
|
// On the runner, every answer the browser's tools give passes the run's one redactor inside the call, so what pi stores
|
|
376
412
|
// (its result record) and what the model reads hold no value the runner or the claim holds.
|
|
377
413
|
const tools = browser.tools.map(spend.capped).map((tool) => (host.redact ? answersCutInside(tool, host.redact) : tool));
|
|
@@ -514,28 +550,53 @@ export const CALL_TOOLS = Object.keys(TOOLS).filter((name) => TOOLS[name].effect
|
|
|
514
550
|
/** Whether `name` is one of `allowed`. */
|
|
515
551
|
export const allows = (allowed, name) => allowed.includes(name);
|
|
516
552
|
/** The tools a run's learned workflow may name (learn/check.ts at learn time, learned-workflow.ts at a call): those of the
|
|
517
|
-
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS
|
|
553
|
+
* agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
|
|
554
|
+
* skills.ts LEARNED_MCP_TOOL: a wildcard is read against its server's listing first, mcpGrantsListed), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name does not run either). A
|
|
518
555
|
* learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
|
|
519
556
|
* exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
|
|
520
|
-
export const learnedWorkflowTools = (granted, plane) => [...new Set(granted.filter((name) => allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name])))];
|
|
557
|
+
export const learnedWorkflowTools = (granted, plane, options = {}) => [...new Set(granted.filter((name) => (options.mcp === true && LEARNED_MCP_TOOL.test(name)) || (allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name]))))];
|
|
558
|
+
/** `granted` with each MCP server's wildcard (`mcp:<server>/*`) read as the tools its server lists now (`listed`, by the
|
|
559
|
+
* server's name: none for a server not saved), each `mcp:<server>/<tool>`, in place; every other name as it is, each
|
|
560
|
+
* once. What a revision grants under a wildcard is every tool of its server, so a learned draft may name each one
|
|
561
|
+
* (learnedWorkflowTools), its gate holding it as any tool (learnedDraftTools: the wildcard's setting, or the tool's own).
|
|
562
|
+
* At proposal time there is no run and no pin: whether the run's pin has the tool is the runtime's to check at the call,
|
|
563
|
+
* in the gate's words (learned-workflow.ts). */
|
|
564
|
+
export function mcpGrantsListed(granted, listed) {
|
|
565
|
+
const out = new Set();
|
|
566
|
+
for (const name of granted) {
|
|
567
|
+
const wildcard = /^mcp:([^/]+)\/\*$/.exec(name);
|
|
568
|
+
if (!wildcard)
|
|
569
|
+
out.add(name);
|
|
570
|
+
else
|
|
571
|
+
for (const tool of listed(wildcard[1]))
|
|
572
|
+
out.add(`mcp:${wildcard[1]}/${tool}`);
|
|
573
|
+
}
|
|
574
|
+
return [...out];
|
|
575
|
+
}
|
|
521
576
|
/** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
|
|
522
577
|
* tool to now (tool-gate.ts permissionOf, or the run's gate's policy), by its settings key. One set to ask or deny is left out of `tools`, so the end-of-run prompt never offers it, and named
|
|
523
578
|
* in `gated` with its setting, which the checker and a learned workflow's check before it runs refuse a draft for. */
|
|
524
|
-
export const learnedDraftTools = (granted, permission, plane, from) => {
|
|
579
|
+
export const learnedDraftTools = (granted, permission, plane, from, options = {}) => {
|
|
525
580
|
const gated = {};
|
|
581
|
+
// The MCP tools offered because they ask: the ones a learned call's approval card names (#2424).
|
|
582
|
+
const asked = [];
|
|
526
583
|
// Where each deny was set (this agent's settings or this server's), so the refusal names it.
|
|
527
584
|
const deniedBy = {};
|
|
528
|
-
const tools = learnedWorkflowTools(granted, plane).filter((name) => {
|
|
585
|
+
const tools = learnedWorkflowTools(granted, plane, options).filter((name) => {
|
|
529
586
|
const setting = permission(name);
|
|
587
|
+
// An MCP tool set to ask is offered where someone can answer: its learned_workflow call asks once, naming its MCP
|
|
588
|
+
// tools, before any node runs (#2424). A table tool set to ask is not: its call node can't wait for an approval.
|
|
530
589
|
if (setting === "allow")
|
|
531
590
|
return true;
|
|
591
|
+
if (setting === "ask" && options.approvers === true && LEARNED_MCP_TOOL.test(name))
|
|
592
|
+
return (asked.push(name), true);
|
|
532
593
|
gated[name] = setting;
|
|
533
594
|
// A deny comes from a layer or the default, never from approvals, which only ever allows.
|
|
534
595
|
if (setting === "deny" && from)
|
|
535
596
|
deniedBy[name] = from(name);
|
|
536
597
|
return false;
|
|
537
598
|
});
|
|
538
|
-
return { tools, gated, deniedBy };
|
|
599
|
+
return { tools, gated, deniedBy, asked };
|
|
539
600
|
};
|
|
540
601
|
/** The tools a workflow names (`nodes` from workflowNodes): on its model nodes (`tools`), and on its `call` nodes
|
|
541
602
|
* `via: "tool"` (`tool`). */
|
package/dist/uploads.d.ts
CHANGED
|
@@ -98,9 +98,32 @@ export declare class Uploads {
|
|
|
98
98
|
/** A run's `file_ids`: each a file that is ready, none twice, at most MAX_FILES_PER_RUN, or 422 at `file_ids`. */
|
|
99
99
|
readyFiles(ids: readonly unknown[]): Promise<UploadedFile[]>;
|
|
100
100
|
/** Copies `files` into the run's `inputs/` through its Workspace, each at its `path` with its folders, in order, before
|
|
101
|
-
* the run's
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
|
|
101
|
+
* the run's first turn: a name taken already (the same path twice, a file where another's folder goes, or what the
|
|
102
|
+
* folder held before) gets the next free suffix (`notes-2.txt`, `docs-2/`), the same for the same files in the same
|
|
103
|
+
* order. Each copy is a new file written whole by the Workspace, never a link to the upload; a link on the way fails
|
|
104
|
+
* the copy (ESCAPE), and nothing is written through it. `bytesOf`: where each file's bytes are read (its upload's own,
|
|
105
|
+
* or the run's hold of them, `held`). */
|
|
106
|
+
copyInto(work: Workspace | string, files: readonly UploadedFile[], bytesOf?: (file: UploadedFile) => string): Promise<void>;
|
|
107
|
+
/** At a run's start, before its row is written: each of its files (`ids`, ready) held for it under
|
|
108
|
+
* `<root>/.held/<run id>/`, its record and its bytes (a hard link to the upload's, which never change once ready; a
|
|
109
|
+
* copy where the disk links none). The run's claim copies from the hold (heldFiles), so a file deleted after the start
|
|
110
|
+
* and before the claim is still the run's: a started run keeps the files it was started with. In turn with each file's
|
|
111
|
+
* delete, so a hold either has the bytes or the start fails at that file (422, as readyFiles words it). */
|
|
112
|
+
hold(runId: string, ids: readonly string[]): Promise<void>;
|
|
113
|
+
/** The files run `runId` holds (hold), in `ids`' order: a file with no hold (a run started before holds, or one whose
|
|
114
|
+
* hold went) read as it is now (readyFiles). With where each one's bytes are. */
|
|
115
|
+
heldFiles(runId: string, ids: readonly string[]): Promise<{
|
|
116
|
+
files: UploadedFile[];
|
|
117
|
+
bytesOf: (file: UploadedFile) => string;
|
|
118
|
+
}>;
|
|
119
|
+
/** Lets go of run `runId`'s hold: once its files are in its workspace, or when it ends without them (released). */
|
|
120
|
+
release(runId: string): Promise<void>;
|
|
121
|
+
/** The run ids that hold files here (hold), for a start's sweep of the holds of runs that ended. */
|
|
122
|
+
holders(): Promise<string[]>;
|
|
106
123
|
}
|
|
124
|
+
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
125
|
+
export declare const notCopied: (why: string) => string;
|
|
126
|
+
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
127
|
+
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
128
|
+
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
|
129
|
+
export declare function copyRunFiles(data: string, runId: string, workspace: Workspace, ids: readonly string[]): Promise<void>;
|
package/dist/uploads.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Uploads: a file reserved (POST /v2/files) and its bytes sent (PUT /v2/files/{file_id}), or sent in one call (POST
|
|
2
|
-
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`)
|
|
3
|
-
// into its workspace
|
|
2
|
+
// /v2/files?path=..., the bytes the body); listed, read and deleted; and the ready files a run names (`file_ids`) held
|
|
3
|
+
// for it at its start and copied into its workspace at its claim. Each file is `<data>/files/<file_id>/`: its bytes
|
|
4
4
|
// (`bytes`) and its record (`file.json`, the contract's File), both 0600, the record written whole. A ready file's bytes
|
|
5
5
|
// never change, and a run gets a copy of them through its Workspace, never a link: nothing a run does reaches the upload.
|
|
6
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
7
|
-
import { lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
7
|
+
import { copyFile, link, lstat, mkdir, open, readdir, readFile, rename, rm, unlink } from "node:fs/promises";
|
|
8
8
|
import { DISK_DIR } from "./server-fs.js";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { ApiError, invalid } from "./errors.js";
|
|
@@ -22,6 +22,9 @@ export const INPUTS_DIR = "inputs";
|
|
|
22
22
|
export const UPLOADS_DIR = "files";
|
|
23
23
|
const RECORD = "file.json";
|
|
24
24
|
const BYTES = "bytes";
|
|
25
|
+
/** Under the root: each started run's hold of its files until its claim copies them (Uploads.hold). A dot-name, never a
|
|
26
|
+
* file id (ID starts with a letter or digit), so the files' list and the sweep pass it by. */
|
|
27
|
+
const HELD_DIR = ".held";
|
|
25
28
|
/** The `upload.expires_at` the answer to a reservation gives, which the contract requires: advisory, not enforced in this
|
|
26
29
|
* release. A later PUT is still taken, and nothing deletes an upload. */
|
|
27
30
|
const UPLOAD_WINDOW_MS = 86_400_000;
|
|
@@ -423,11 +426,12 @@ export class Uploads {
|
|
|
423
426
|
return files;
|
|
424
427
|
}
|
|
425
428
|
/** Copies `files` into the run's `inputs/` through its Workspace, each at its `path` with its folders, in order, before
|
|
426
|
-
* the run's
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
|
|
429
|
+
* the run's first turn: a name taken already (the same path twice, a file where another's folder goes, or what the
|
|
430
|
+
* folder held before) gets the next free suffix (`notes-2.txt`, `docs-2/`), the same for the same files in the same
|
|
431
|
+
* order. Each copy is a new file written whole by the Workspace, never a link to the upload; a link on the way fails
|
|
432
|
+
* the copy (ESCAPE), and nothing is written through it. `bytesOf`: where each file's bytes are read (its upload's own,
|
|
433
|
+
* or the run's hold of them, `held`). */
|
|
434
|
+
async copyInto(work, files, bytesOf = (file) => join(this.root, file.file_id, BYTES)) {
|
|
431
435
|
const workspace = workspaceAt(work);
|
|
432
436
|
await uploadTestHooks.beforeCopy?.(workspace);
|
|
433
437
|
const names = takenNames(workspace);
|
|
@@ -437,9 +441,78 @@ export class Uploads {
|
|
|
437
441
|
for (const segment of segments.slice(0, -1))
|
|
438
442
|
dir = `${dir}/${free(await names(dir), segment, "dir")}`;
|
|
439
443
|
const name = free(await names(dir), segments.at(-1), "file");
|
|
440
|
-
await workspace.write(`${dir}/${name}`, await readFile(
|
|
444
|
+
await workspace.write(`${dir}/${name}`, await readFile(bytesOf(file)));
|
|
441
445
|
}
|
|
442
446
|
}
|
|
447
|
+
/** At a run's start, before its row is written: each of its files (`ids`, ready) held for it under
|
|
448
|
+
* `<root>/.held/<run id>/`, its record and its bytes (a hard link to the upload's, which never change once ready; a
|
|
449
|
+
* copy where the disk links none). The run's claim copies from the hold (heldFiles), so a file deleted after the start
|
|
450
|
+
* and before the claim is still the run's: a started run keeps the files it was started with. In turn with each file's
|
|
451
|
+
* delete, so a hold either has the bytes or the start fails at that file (422, as readyFiles words it). */
|
|
452
|
+
async hold(runId, ids) {
|
|
453
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
454
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
455
|
+
for (const [i, id] of ids.entries()) {
|
|
456
|
+
await this.exclusive(id, async () => {
|
|
457
|
+
const file = await this.get(id);
|
|
458
|
+
if (file?.status !== "ready")
|
|
459
|
+
throw invalid([{ field: `file_ids[${i}]`, reason: "not_an_option", message: `There is no file ${id}: reserve it with POST /v2/files.` }]);
|
|
460
|
+
const bytes = join(dir, `${id}.${BYTES}`);
|
|
461
|
+
await link(join(this.root, id, BYTES), bytes).catch(async (error) => {
|
|
462
|
+
if (error.code !== "EEXIST")
|
|
463
|
+
await copyFile(join(this.root, id, BYTES), bytes);
|
|
464
|
+
});
|
|
465
|
+
await writeDurable(join(dir, `${id}.json`), `${JSON.stringify(file)}\n`);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/** The files run `runId` holds (hold), in `ids`' order: a file with no hold (a run started before holds, or one whose
|
|
470
|
+
* hold went) read as it is now (readyFiles). With where each one's bytes are. */
|
|
471
|
+
async heldFiles(runId, ids) {
|
|
472
|
+
const dir = join(this.root, HELD_DIR, runId);
|
|
473
|
+
const held = new Map();
|
|
474
|
+
for (const id of ids) {
|
|
475
|
+
const record = ID.test(id) ? await readJson(join(dir, `${id}.json`)) : null;
|
|
476
|
+
if (isFile(record) && record.file_id === id && (await lstat(join(dir, `${id}.${BYTES}`)).catch(() => null))?.isFile())
|
|
477
|
+
held.set(id, record);
|
|
478
|
+
}
|
|
479
|
+
const live = await this.readyFiles(ids.filter((id) => !held.has(id)));
|
|
480
|
+
const now = new Map(live.map((file) => [file.file_id, file]));
|
|
481
|
+
return {
|
|
482
|
+
files: ids.map((id) => held.get(id) ?? now.get(id)),
|
|
483
|
+
bytesOf: (file) => (held.has(file.file_id) ? join(dir, `${file.file_id}.${BYTES}`) : join(this.root, file.file_id, BYTES)),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Lets go of run `runId`'s hold: once its files are in its workspace, or when it ends without them (released). */
|
|
487
|
+
async release(runId) {
|
|
488
|
+
await rm(join(this.root, HELD_DIR, runId), { recursive: true, force: true });
|
|
489
|
+
}
|
|
490
|
+
/** The run ids that hold files here (hold), for a start's sweep of the holds of runs that ended. */
|
|
491
|
+
async holders() {
|
|
492
|
+
return (await readdir(join(this.root, HELD_DIR)).catch(() => [])).filter((name) => ID.test(name));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
496
|
+
export const notCopied = (why) => `The run's files could not be copied into its workspace: ${why}`;
|
|
497
|
+
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
498
|
+
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
499
|
+
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
|
500
|
+
export async function copyRunFiles(data, runId, workspace, ids) {
|
|
501
|
+
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
502
|
+
const copied = await workspace.list(INPUTS_DIR).then(() => true, () => false);
|
|
503
|
+
if (!copied) {
|
|
504
|
+
try {
|
|
505
|
+
const { files, bytesOf } = await uploads.heldFiles(runId, ids);
|
|
506
|
+
await uploads.copyInto(workspace, files, bytesOf);
|
|
507
|
+
}
|
|
508
|
+
catch (error) {
|
|
509
|
+
// The run ends failed on this: its hold goes with it.
|
|
510
|
+
await uploads.release(runId).catch(() => undefined);
|
|
511
|
+
const why = error instanceof ApiError ? error.extra.fields?.map((issue) => issue.message).join("; ") || error.message : error.message;
|
|
512
|
+
throw new Error(notCopied(why), { cause: error });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
await uploads.release(runId);
|
|
443
516
|
}
|
|
444
517
|
/** The names in each folder of `workspace`, by its path, each read once from its listing (none for a folder not there
|
|
445
518
|
* yet) and kept up to date with what the copy takes. */
|
package/dist/usage.d.ts
CHANGED
|
@@ -1,57 +1,11 @@
|
|
|
1
|
-
import { type Learning, type LearningReason, type Tokens } from "./learning.js";
|
|
2
|
-
/** On a line written since they were kept (learning.ts Learning): `seed_notes`, how many notes the run started from;
|
|
3
|
-
* `answered_at` and `job_cost_usd`, when its job's answer was final and what it had cost then, once it looked back;
|
|
4
|
-
* `look_back_usd`, what looking back cost (0 when it did not; null when unknown). */
|
|
5
|
-
export type Outcome = {
|
|
6
|
-
run: string;
|
|
7
|
-
agent: string;
|
|
8
|
-
state: "merged" | "dropped";
|
|
9
|
-
reason: LearningReason | null;
|
|
10
|
-
at: string;
|
|
11
|
-
cost: number | null;
|
|
12
|
-
tokens: Tokens | null;
|
|
13
|
-
seed_notes?: number;
|
|
14
|
-
given?: string[];
|
|
15
|
-
read?: string[];
|
|
16
|
-
answered_at?: string;
|
|
17
|
-
job_cost_usd?: number | null;
|
|
18
|
-
look_back_usd?: number | null;
|
|
19
|
-
};
|
|
20
|
-
/** A run's files as they are now, once its line is written: the latest one per run is what its line says. */
|
|
21
|
-
export type NotesLine = {
|
|
22
|
-
run: string;
|
|
23
|
-
agent: string;
|
|
24
|
-
notes: true;
|
|
25
|
-
given?: string[];
|
|
26
|
-
read?: string[];
|
|
27
|
-
};
|
|
28
|
-
type Ended = Learning & {
|
|
29
|
-
state: "merged" | "dropped";
|
|
30
|
-
};
|
|
31
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
32
|
-
export declare const ended: (learning: Learning | undefined | null) => learning is Ended;
|
|
33
1
|
/** The files of the notes a run was given and read; a list left with none is absent. */
|
|
34
2
|
export type NoteFiles = {
|
|
35
3
|
given?: string[];
|
|
36
4
|
read?: string[];
|
|
37
5
|
};
|
|
38
6
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
39
|
-
* shape never stops a reader
|
|
7
|
+
* shape never stops a reader. */
|
|
40
8
|
export declare const notesOf: (learning: {
|
|
41
9
|
given?: unknown;
|
|
42
10
|
read?: unknown;
|
|
43
11
|
}) => NoteFiles;
|
|
44
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
45
|
-
export declare const lineNotesOf: (line: {
|
|
46
|
-
given?: unknown;
|
|
47
|
-
read?: unknown;
|
|
48
|
-
}) => NoteFiles;
|
|
49
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
50
|
-
export declare const outcomeOf: (run: string, agent: string, learning: Ended) => Outcome;
|
|
51
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
52
|
-
* or out of shape, is skipped. */
|
|
53
|
-
export declare function outcomes(data: string): Promise<Map<string, Outcome>>;
|
|
54
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
55
|
-
* nothing after it. */
|
|
56
|
-
export declare const record: (data: string, line: Outcome | NotesLine) => Promise<void>;
|
|
57
|
-
export {};
|