@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57
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 +261 -0
- package/README.md +228 -45
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +18 -5
- package/dist/adapters.js +23 -9
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +36 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +28 -3
- package/dist/chatgpt-plan.js +182 -21
- package/dist/claude-login.d.ts +101 -14
- package/dist/claude-login.js +232 -49
- package/dist/claude-sign-in.d.ts +46 -0
- package/dist/claude-sign-in.js +93 -0
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +26 -5
- package/dist/key-refusal.js +313 -37
- package/dist/learn/secrets.d.ts +31 -11
- package/dist/learn/secrets.js +152 -191
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +2 -2
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +245 -42
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +101 -0
- package/dist/redact/match.js +1152 -0
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +3 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +14 -0
- package/dist/runner/adapter-loop.js +56 -11
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +154 -29
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +11 -6
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +85 -36
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +15 -6
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +5 -0
- package/dist/runner/run-child-host.js +71 -30
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +18 -3
- package/dist/runner/runner.js +162 -36
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +57 -13
- package/dist/server.js +371 -113
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +76 -16
- package/dist/store/store.d.ts +53 -3
- package/dist/store/store.js +27 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +4 -4
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +22 -11
- package/dist/template-eval.js +124 -41
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +17 -7
- package/dist/timeline/timeline.js +28 -14
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +69 -6
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +3 -1
- package/dist/workspace/computer-deps.js +12 -4
- package/dist/workspace/computer-for-claim.d.ts +19 -2
- package/dist/workspace/computer-for-claim.js +101 -13
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +55 -4
- package/dist/workspace/computer-kept.js +129 -8
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +65 -0
- package/dist/wrapped.js +77 -0
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +38 -15
- package/dist/console/assets/index-DUYLaqiR.js +0 -746
- package/dist/console/assets/index-DYhU4adm.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
package/dist/runner/subagent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { configure, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
2
|
import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
|
|
3
3
|
import { ASK_TOOL } from "../tools.js";
|
|
4
|
+
import { saveSlots } from "../web-save.js";
|
|
4
5
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
5
6
|
import { HOST_TOOL_OUTPUT } from "./adapters/pi.js";
|
|
6
7
|
import { cutAtLimit } from "./loop-contract.js";
|
|
@@ -17,44 +18,6 @@ const NEVER_GIVEN = [SUBAGENT_TOOL, ASK_TOOL];
|
|
|
17
18
|
export const SUBAGENT_INSTRUCTIONS = "You are a subagent. The message you are given is your whole task: do it with the tools you have, then answer. Your last message is returned, as it is, to the agent that called you.";
|
|
18
19
|
/** The thinking levels a call may give its child (`effort`); absent, the child thinks at the agent's own level. */
|
|
19
20
|
export const SUBAGENT_EFFORTS = ["low", "medium", "high"];
|
|
20
|
-
/** One counter of free slots for the run's children (SUBAGENT_PARALLEL), handed out in call order. */
|
|
21
|
-
function slots(count) {
|
|
22
|
-
let free = count;
|
|
23
|
-
const waiting = [];
|
|
24
|
-
return {
|
|
25
|
-
async take(signal) {
|
|
26
|
-
if (free > 0)
|
|
27
|
-
free -= 1;
|
|
28
|
-
else {
|
|
29
|
-
await new Promise((resolve, reject) => {
|
|
30
|
-
const go = () => {
|
|
31
|
-
signal?.removeEventListener("abort", stop);
|
|
32
|
-
resolve();
|
|
33
|
-
};
|
|
34
|
-
const stop = () => {
|
|
35
|
-
const at = waiting.indexOf(go);
|
|
36
|
-
if (at >= 0)
|
|
37
|
-
waiting.splice(at, 1);
|
|
38
|
-
reject(signal?.reason ?? new Error("aborted"));
|
|
39
|
-
};
|
|
40
|
-
waiting.push(go);
|
|
41
|
-
signal?.addEventListener("abort", stop, { once: true });
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
let given = false;
|
|
45
|
-
return () => {
|
|
46
|
-
if (given)
|
|
47
|
-
return;
|
|
48
|
-
given = true;
|
|
49
|
-
const next = waiting.shift();
|
|
50
|
-
if (next)
|
|
51
|
-
next();
|
|
52
|
-
else
|
|
53
|
-
free += 1;
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
21
|
/** The text of an assistant message: its text parts, joined. */
|
|
59
22
|
const textOf = (message) => Array.isArray(message?.content) ? message.content.map((part) => (part?.type === "text" ? (part.text ?? "") : "")).join("") : typeof message?.content === "string" ? message.content : "";
|
|
60
23
|
/** `text` within the host's bound on a tool result (HOST_RESULT_MAX_CHARS), saying where it was cut. */
|
|
@@ -87,7 +50,8 @@ export function chosenTools(asked, options) {
|
|
|
87
50
|
}
|
|
88
51
|
/** The subagent tool: one of the session's own tools (adapters/pi.ts `tools`), so it needs no extension of its own. */
|
|
89
52
|
export function subagentTool(options) {
|
|
90
|
-
|
|
53
|
+
// The run's children's slots (SUBAGENT_PARALLEL), handed out in call order.
|
|
54
|
+
const free = saveSlots(SUBAGENT_PARALLEL);
|
|
91
55
|
return defineTool({
|
|
92
56
|
name: SUBAGENT_TOOL,
|
|
93
57
|
description: `Run a subagent: a fresh conversation that starts with nothing but your prompt, on your own model (or the model tier you name: ${SUBAGENT_TIERS.join(" or ")}), with only the tools you list (a subset of your own), and get its final answer back as text. Write the prompt self-contained: the subagent sees none of your conversation. Several calls in one turn run at once, at most ${SUBAGENT_PARALLEL} at a time; more wait their turn. A subagent cannot start subagents of its own.`,
|
|
@@ -132,7 +96,7 @@ export function subagentTool(options) {
|
|
|
132
96
|
const missing = [...names].filter((name) => !tools.some((registration) => registration.name === name));
|
|
133
97
|
if (missing.length)
|
|
134
98
|
return fail(`subagent: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not bound in this run, so no subagent may have ${missing.length === 1 ? "it" : "them"}. Nothing ran.`);
|
|
135
|
-
const release = await free.take(context.abortSignal);
|
|
99
|
+
const release = await free.take(context.abortSignal ?? new AbortController().signal);
|
|
136
100
|
try {
|
|
137
101
|
const child = await api.commit(async (tx) => {
|
|
138
102
|
// The ownership index remembers the child: a rerun of this call reuses it.
|
|
@@ -54,8 +54,9 @@ export interface Revise {
|
|
|
54
54
|
}
|
|
55
55
|
/** How many of the agent's newest runs the money rule reads (store-reads/learning.ts pastRunsOverStore). */
|
|
56
56
|
export declare const PAST_RUNS = 500;
|
|
57
|
-
/** One of the agent's runs as the money rule reads it: its record's path fields, its all-in cost (
|
|
58
|
-
* cost and every learning round booked for it
|
|
57
|
+
/** One of the agent's runs as the money rule reads it: its record's path fields, its all-in cost (store-reads/learning.ts
|
|
58
|
+
* moneyAllInOf: its booked cost and every learning round booked for it, a run off the served paths less its compile
|
|
59
|
+
* turns; null when any part is unknown), when it started. */
|
|
59
60
|
export type PastRun = {
|
|
60
61
|
readonly metrics: unknown;
|
|
61
62
|
readonly allInUsd: number | null;
|
|
@@ -158,7 +159,9 @@ export declare const workflowDigest: (workflow: Pick<LearnedWorkflow, "workflow"
|
|
|
158
159
|
export declare function workflowFirstOf(kind: string, workflows: readonly LearnedWorkflow[], launch: RunLaunch, log?: (line: string) => void, past?: () => Promise<readonly PastRun[]>, promoted?: Promoted, outputSchema?: unknown): Promise<FirstChoice>;
|
|
159
160
|
/** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
|
|
160
161
|
* promotion it served under (WorkflowFirst.promotion), and whether it answered or handed back; undefined when it served
|
|
161
|
-
* none.
|
|
162
|
+
* none. `cut` on a hand-back the workflow never made itself: its call's end (WORKFLOW_FIRST_CALL) is `interrupted`, a
|
|
163
|
+
* crash or a lost runner cut it and the next claim ended it, never running it again (adapter-loop.ts serveFirst). The
|
|
164
|
+
* run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
|
|
162
165
|
export declare function servedOf(entries: readonly {
|
|
163
166
|
readonly kind: string;
|
|
164
167
|
readonly data?: unknown;
|
|
@@ -167,11 +170,13 @@ export declare function servedOf(entries: readonly {
|
|
|
167
170
|
workflow: string;
|
|
168
171
|
digest?: string;
|
|
169
172
|
promotion?: number;
|
|
173
|
+
cut?: true;
|
|
170
174
|
} | undefined;
|
|
171
175
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
172
176
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
173
177
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
174
|
-
* which its grade keeps),
|
|
178
|
+
* which its grade keeps), `workflow_cut` on a hand-back a restart cut (servedOf `cut`: the workflow handed nothing back
|
|
179
|
+
* itself), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
175
180
|
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
176
181
|
* and workflow from here. None for a run that does not learn. */
|
|
177
182
|
export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
@@ -179,6 +184,7 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
|
179
184
|
workflow: string | null;
|
|
180
185
|
digest?: string;
|
|
181
186
|
promotion?: number;
|
|
187
|
+
cut?: true;
|
|
182
188
|
} | undefined, entries?: readonly {
|
|
183
189
|
readonly kind: string;
|
|
184
190
|
readonly data?: unknown;
|
|
@@ -188,6 +194,7 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
|
|
|
188
194
|
workflow?: string;
|
|
189
195
|
workflow_digest?: string;
|
|
190
196
|
workflow_promotion?: number;
|
|
197
|
+
workflow_cut?: true;
|
|
191
198
|
not_auditable?: true;
|
|
192
199
|
loops?: LoopRow[];
|
|
193
200
|
replay?: ReplayMetrics;
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
// is one sample; a revision is asked only of a workflow its promotion holds), and never keeps the workflow from serving.
|
|
13
13
|
// One money rule does (costLineOf): a workflow
|
|
14
14
|
// serves while its all-in cost a run over its last COST_WINDOW served runs at its digest stays under the agent's by-hand
|
|
15
|
-
// cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first).
|
|
16
|
-
//
|
|
17
|
-
//
|
|
15
|
+
// cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first). Each run is read at its
|
|
16
|
+
// all-in (store-reads/learning.ts moneyAllInOf): its booked cost (the workflow and any handback's agent work together)
|
|
17
|
+
// and every learning round booked for it (its look-backs, its grades, a follow-up's rounds), less, on the by-hand side,
|
|
18
|
+
// its compile turns, which the run view charges to the revision they drafted. A run whose
|
|
18
19
|
// all-in is unknown anywhere is left out of its side's mean and counted, never read as 0. Over that line it stops running
|
|
19
20
|
// first: the agent takes the run, the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
|
|
20
21
|
// needs_revision), and the agent's cost per run shows it stopped. The stop asks for no compile. A new revision of it (a
|
|
@@ -230,17 +231,22 @@ export async function workflowFirstOf(kind, workflows, launch, log, past, promot
|
|
|
230
231
|
}
|
|
231
232
|
/** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
|
|
232
233
|
* promotion it served under (WorkflowFirst.promotion), and whether it answered or handed back; undefined when it served
|
|
233
|
-
* none.
|
|
234
|
+
* none. `cut` on a hand-back the workflow never made itself: its call's end (WORKFLOW_FIRST_CALL) is `interrupted`, a
|
|
235
|
+
* crash or a lost runner cut it and the next claim ended it, never running it again (adapter-loop.ts serveFirst). The
|
|
236
|
+
* run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
|
|
234
237
|
export function servedOf(entries) {
|
|
235
238
|
const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && (entry.data?.outcome === "answered" || entry.data?.outcome === "handed_back"))?.data;
|
|
236
239
|
if (!served || typeof served.workflow !== "string")
|
|
237
240
|
return undefined;
|
|
238
|
-
|
|
241
|
+
const end = entries.findLast((entry) => entry.kind === KINDS.callEnd && entry.data?.callId === WORKFLOW_FIRST_CALL)?.data;
|
|
242
|
+
const cut = served.outcome === "handed_back" && end?.status === "interrupted";
|
|
243
|
+
return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}), ...(cut ? { cut: true } : {}) };
|
|
239
244
|
}
|
|
240
245
|
/** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
|
|
241
246
|
* (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
|
|
242
247
|
* called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
|
|
243
|
-
* which its grade keeps),
|
|
248
|
+
* which its grade keeps), `workflow_cut` on a hand-back a restart cut (servedOf `cut`: the workflow handed nothing back
|
|
249
|
+
* itself), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
|
|
244
250
|
* each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
|
|
245
251
|
* and workflow from here. None for a run that does not learn. */
|
|
246
252
|
export function pathMetrics(launch, classified, entries = []) {
|
|
@@ -252,7 +258,7 @@ export function pathMetrics(launch, classified, entries = []) {
|
|
|
252
258
|
return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest, ...verdict } };
|
|
253
259
|
if (!launch.learning)
|
|
254
260
|
return {};
|
|
255
|
-
const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
|
|
261
|
+
const { path, workflow, digest, promotion, cut } = classified ?? { path: "agent", workflow: null };
|
|
256
262
|
const loops = loopsOf(entries);
|
|
257
263
|
const rows = loops.length ? { loops } : {};
|
|
258
264
|
if (launch.replay) {
|
|
@@ -269,7 +275,7 @@ export function pathMetrics(launch, classified, entries = []) {
|
|
|
269
275
|
}
|
|
270
276
|
// A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
|
|
271
277
|
const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
|
|
272
|
-
return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...rows };
|
|
278
|
+
return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(cut && path === "handed_back" ? { workflow_cut: true } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...rows };
|
|
273
279
|
}
|
|
274
280
|
/** What run `entries` (its root's) say its learned workflow answered alone: the workflow and its answer (the model's
|
|
275
281
|
* message written just before the WORKFLOW_FIRST entry, in its commit); undefined for a run it did not answer. A follow-up that opens such a
|
|
@@ -30,8 +30,9 @@ import { runGate } from "../tool-gate.js";
|
|
|
30
30
|
import { callNodeAskText, deniedText, modelNodeAskText } from "../refusal-words.js";
|
|
31
31
|
import { planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
32
32
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
33
|
+
import { parallelExtractFee, parallelSearchFee, searchArgs } from "@parcha/agentrun-web";
|
|
34
|
+
import { bookedIn } from "../paid-calls.js";
|
|
35
|
+
import { WEB_SEARCH_TOOL } from "../web-search.js";
|
|
35
36
|
import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
36
37
|
import { claimModelEnv, claimModelKey, claimSecrets, holdRunKey, keyedAtClaim, withoutModelKeys } from "./claim-secrets.js";
|
|
37
38
|
import { routeOf } from "./model-route.js";
|
|
@@ -6,7 +6,8 @@ import { ApiError, type InputIssue } from "./errors.js";
|
|
|
6
6
|
import { type LearningMode, type Seed, type Shown } from "./learning.js";
|
|
7
7
|
import { type Place } from "./place.js";
|
|
8
8
|
import { type RepoBinding } from "./run-repo.js";
|
|
9
|
-
import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
|
|
9
|
+
import { type HeldRefusal, type LaunchDisk, type RunLaunch } from "./run-launch.js";
|
|
10
|
+
import { type ModelKeyTarget } from "./run-model-key.js";
|
|
10
11
|
import { type ApprovalDecision, type RunMoment } from "./run-view.js";
|
|
11
12
|
import { type LaunchSealed, type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
|
|
12
13
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
@@ -124,11 +125,13 @@ export interface StartDeps {
|
|
|
124
125
|
/** Marks an input refusal as told from a revision (server.ts told). */
|
|
125
126
|
told(error: ApiError): ApiError;
|
|
126
127
|
/** Refuses a revision this host cannot run, by field (server.ts runnable), each tool key the run carries (`carried`, by
|
|
127
|
-
* name) read as one the host holds.
|
|
128
|
+
* name) read as one the host holds. `held`: the run holds its computer (hold: true), so a refusal for its model alone
|
|
129
|
+
* is returned for its launch instead of thrown (computer-held.ts). */
|
|
128
130
|
runnable(revision: Revision, place: Place, options: {
|
|
129
131
|
capped: boolean;
|
|
130
132
|
carried?: readonly string[];
|
|
131
|
-
|
|
133
|
+
held?: boolean;
|
|
134
|
+
}): Promise<HeldRefusal | undefined>;
|
|
132
135
|
/** The revision a run starts on, its MCP tools pinned: one that grants an MCP tool and was saved with no pin (before
|
|
133
136
|
* pins were made at save, or an inline agent's version stored then) is pinned once, at its first run (server.ts
|
|
134
137
|
* pinFirst); any other as it is. */
|
|
@@ -220,8 +223,9 @@ export interface StartDeps {
|
|
|
220
223
|
export interface StartOptions {
|
|
221
224
|
readonly trigger?: RunTrigger;
|
|
222
225
|
/** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth and model_key, server.ts),
|
|
223
|
-
* given the launch the start prepared
|
|
224
|
-
|
|
226
|
+
* given the launch the start prepared and where its model requests go (run-model-key.ts keyTargetOf), which the sealer
|
|
227
|
+
* may refuse (a model key where the run's model takes none). */
|
|
228
|
+
readonly sealed?: (runId: string, launch: RunLaunch, target: ModelKeyTarget) => Uint8Array | null;
|
|
225
229
|
/** The run's title when its starter names one (a trigger's: "<Source> <name>"), else it is made from its input. */
|
|
226
230
|
readonly title?: string;
|
|
227
231
|
readonly origin?: RunOrigin;
|
|
@@ -229,6 +233,11 @@ export interface StartOptions {
|
|
|
229
233
|
readonly from?: MessageOrigin;
|
|
230
234
|
/** The names of the tool keys the run carries (`keys`, run-keys.ts; their values go only into `sealed`). */
|
|
231
235
|
readonly keys?: readonly string[];
|
|
236
|
+
/** The firing the run starts, in the run's own write (store.runs.create `firing`): a launch hook's host's start. */
|
|
237
|
+
readonly firing?: {
|
|
238
|
+
triggerId: string;
|
|
239
|
+
key: string;
|
|
240
|
+
};
|
|
232
241
|
}
|
|
233
242
|
/** The run's learning start: undefined when the run does not learn (the server's learning off, a workflow revision, or
|
|
234
243
|
* its revision does not say learning), else the seed sha it starts from, its # Learned text (its owner's corrections,
|
|
@@ -250,7 +259,7 @@ export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, rev
|
|
|
250
259
|
* (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
|
|
251
260
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
252
261
|
* starts a second. */
|
|
253
|
-
export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys }?: StartOptions): Promise<RunRow>;
|
|
262
|
+
export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys, firing }?: StartOptions): Promise<RunRow>;
|
|
254
263
|
/** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
255
264
|
* hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
|
|
256
265
|
* lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
|
package/dist/runs-over-store.js
CHANGED
|
@@ -16,7 +16,7 @@ import { launchNative } from "./native/connection.js";
|
|
|
16
16
|
import { randomBytes } from "node:crypto";
|
|
17
17
|
import { externalKey, getAgent, ownedElsewhere } from "./agents-store.js";
|
|
18
18
|
import { CAP_TOLERANCE, money } from "./cap.js";
|
|
19
|
-
import { holdOf } from "./computer-held.js";
|
|
19
|
+
import { heldRefused, holdOf } from "./computer-held.js";
|
|
20
20
|
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
21
21
|
import { ApiError, invalid, unsupported } from "./errors.js";
|
|
22
22
|
import { labelsOf } from "./run-labels.js";
|
|
@@ -28,19 +28,19 @@ import { thinkingLevel } from "./model.js";
|
|
|
28
28
|
import { resolvePlace } from "./place.js";
|
|
29
29
|
import { githubTargetOf } from "./github.js";
|
|
30
30
|
import { repoOf } from "./run-repo.js";
|
|
31
|
-
import { launchBody, sourceProjectOf } from "./run-launch.js";
|
|
31
|
+
import { launchBody, readLaunchBody, sourceProjectOf } from "./run-launch.js";
|
|
32
32
|
import { learningDiskOf } from "./learn/learning-of.js";
|
|
33
|
-
import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
|
|
33
|
+
import { keyTargetOf, modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
|
|
34
34
|
import { raiseFollowUpId } from "./run-view.js";
|
|
35
35
|
import { sendCommand } from "./runner/commands.js";
|
|
36
36
|
import { refuseWhileNoRunner } from "./runner/presence.js";
|
|
37
|
-
import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
|
|
37
|
+
import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, FiringMoved, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
|
|
38
38
|
import { canonical } from "./store/agent-body.js";
|
|
39
39
|
import { sourceSyncOf } from "./source-sync/types.js";
|
|
40
40
|
import { toolingOf } from "./tools.js";
|
|
41
41
|
import { planeFor } from "./tool-plane.js";
|
|
42
42
|
import { declaredKeys, undeclaredKeys, withCarried } from "./run-keys.js";
|
|
43
|
-
import { clip } from "
|
|
43
|
+
import { clip } from "@parcha/agentrun-web";
|
|
44
44
|
import { isObject } from "./validate.js";
|
|
45
45
|
/** Why a message that may not answer a person's question is not sent (runs.ts WAITS_ON_A_PERSON). */
|
|
46
46
|
export const WAITS_ON_A_PERSON = "The run is waiting on a person.";
|
|
@@ -178,6 +178,11 @@ export async function message(store, moment, content, { requestId, answers = tru
|
|
|
178
178
|
throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
|
|
179
179
|
if (nativeOf(launchBody))
|
|
180
180
|
throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
|
|
181
|
+
// A held run its model kept from running at its create never runs its agent: a message would be its first turn (taken at
|
|
182
|
+
// a start, or opening it again once it ended), so it is refused as its start is (computer-held.ts).
|
|
183
|
+
const heldModel = readLaunchBody(launchBody)?.hold?.refused;
|
|
184
|
+
if (heldModel)
|
|
185
|
+
throw heldRefused(heldModel);
|
|
181
186
|
// Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished). Another
|
|
182
187
|
// system's agent is archived only by its delete: said so, as every run of it is refused (AgentDeleting).
|
|
183
188
|
const archivedAgent = moment.archived === "agent" ? await store.agents.get(moment.agentId) : null;
|
|
@@ -444,7 +449,7 @@ export async function learningStartFor(deps, entry, revision, rbody, { use = fal
|
|
|
444
449
|
* (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
|
|
445
450
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
446
451
|
* starts a second. */
|
|
447
|
-
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys } = {}) {
|
|
452
|
+
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys, firing } = {}) {
|
|
448
453
|
if (sourceSyncOf(entry.revision?.body)) {
|
|
449
454
|
// Re-delivery of a firing that already admitted a run is not a new start and needs no new project preparation.
|
|
450
455
|
if (origin) {
|
|
@@ -466,11 +471,12 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
466
471
|
if (entry.revision?.body?.sdk)
|
|
467
472
|
throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
|
|
468
473
|
const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}), ...(keys ? { keys } : {}) });
|
|
469
|
-
|
|
474
|
+
const target = keyTargetOf(deps.planeEnv(), launch, revision);
|
|
475
|
+
keyedOrRefused(deps, target, sealed);
|
|
470
476
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
471
477
|
try {
|
|
472
478
|
const labels = labelsOf(body.labels);
|
|
473
|
-
return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, expectedCurrent: entry.agent.currentRevision, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch,
|
|
479
|
+
return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, expectedCurrent: entry.agent.currentRevision, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}), ...(firing ? { firing } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) }));
|
|
474
480
|
}
|
|
475
481
|
catch (error) {
|
|
476
482
|
if (error instanceof RevisionMoved)
|
|
@@ -487,9 +493,10 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
487
493
|
}
|
|
488
494
|
/** A start with no launch secrets (`sealed`: a trigger's firing, a learning batch's row) whose route goes to the model
|
|
489
495
|
* gateway, on a server that holds no key for it (run-model-key.ts serverKeyMissing): 422 model_key_required, nothing
|
|
490
|
-
* written, never a failure at its first model call. A start with them (the API's) is the sealer's to check.
|
|
491
|
-
|
|
492
|
-
|
|
496
|
+
* written, never a failure at its first model call. A start with them (the API's) is the sealer's to check. `target`:
|
|
497
|
+
* the run's (run-model-key.ts keyTargetOf), a held run's whose model was refused at its create among them. */
|
|
498
|
+
function keyedOrRefused(deps, target, sealed) {
|
|
499
|
+
if (!sealed && serverKeyMissing(deps.planeEnv(), target))
|
|
493
500
|
throw modelKeyRequired(false);
|
|
494
501
|
}
|
|
495
502
|
/** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
@@ -578,8 +585,10 @@ export async function withHeldFiles(store, deps, runId, agentId, revision, launc
|
|
|
578
585
|
knownAbsent = true;
|
|
579
586
|
}
|
|
580
587
|
catch { /* preserve preparation until the admission can be resolved */ }
|
|
588
|
+
// A refusal the store gave in the run's own transaction (a host start whose firing was released meanwhile: FiringMoved)
|
|
589
|
+
// wrote nothing, so the run never exists and its preparation goes.
|
|
581
590
|
if (knownAbsent && (error instanceof StoreConstraint || error instanceof RevisionMoved || error instanceof AgentDeleting
|
|
582
|
-
|| error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof ApiError))
|
|
591
|
+
|| error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof FiringMoved || error instanceof ApiError))
|
|
583
592
|
await undo(true);
|
|
584
593
|
throw error;
|
|
585
594
|
}
|
|
@@ -673,7 +682,8 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
|
|
|
673
682
|
// A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
|
|
674
683
|
// one across.
|
|
675
684
|
const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision), ...(keys ? { keys } : {}) });
|
|
676
|
-
|
|
685
|
+
const target = keyTargetOf(deps.planeEnv(), launch, storedRevision ?? revision);
|
|
686
|
+
keyedOrRefused(deps, target, sealed);
|
|
677
687
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
678
688
|
const labels = labelsOf(body.labels);
|
|
679
689
|
try {
|
|
@@ -681,7 +691,7 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
|
|
|
681
691
|
agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
|
|
682
692
|
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
|
|
683
693
|
run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
|
|
684
|
-
launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch,
|
|
694
|
+
launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) },
|
|
685
695
|
}));
|
|
686
696
|
}
|
|
687
697
|
catch (error) {
|
|
@@ -747,17 +757,18 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
747
757
|
if (refused !== undefined)
|
|
748
758
|
throw new ApiError("runner_refused", refused);
|
|
749
759
|
const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
|
|
750
|
-
// Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
|
|
751
|
-
// its server could not be listed, is refused with the rest (runnable).
|
|
752
|
-
await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried });
|
|
753
760
|
// A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
|
|
754
|
-
// revision's computer, else its place's).
|
|
761
|
+
// revision's computer, else its place's). Read before the run's check, which defers a held run's model refusal.
|
|
755
762
|
const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
|
|
756
763
|
if (hold !== undefined && "field" in hold)
|
|
757
764
|
throw invalid([hold]);
|
|
758
765
|
// A workflow's loop opens no held computer and takes no start or release: its run holds nothing.
|
|
759
766
|
if (hold !== undefined && revision.kind === "workflow")
|
|
760
767
|
throw invalid([{ field: "hold", reason: "not_an_option", message: "hold is for an agent's run: a workflow run does not hold its computer for its owner." }]);
|
|
768
|
+
// Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
|
|
769
|
+
// its server could not be listed, is refused with the rest (runnable). A held run kept from running by its model alone
|
|
770
|
+
// is not refused: those words ride its hold, for its start to answer (computer-held.ts).
|
|
771
|
+
const modelRefused = await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried, held: hold !== undefined });
|
|
761
772
|
// The title shows on the run's page, the runs list and Mission Control: built from its input as shown, each held value
|
|
762
773
|
// redacted before a long one is cut (a cut key could no longer be found).
|
|
763
774
|
const shown = redactedOutput(input, deps.serverSecrets());
|
|
@@ -768,8 +779,9 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
768
779
|
// the run carries resolves a tool as one the host holds would.
|
|
769
780
|
const tooling = await toolingOf(revision);
|
|
770
781
|
const plane = tooling ? planeFor(withCarried(deps.planeEnv(), carried), tooling, deps.toolSettings(), { capped: cap !== undefined, run: true }) : {};
|
|
771
|
-
// The run's model, resolved once, at start (the runner reads launch.model only).
|
|
772
|
-
|
|
782
|
+
// The run's model, resolved once, at start (the runner reads launch.model only). None for a held run whose model was
|
|
783
|
+
// refused: resolving it would throw those words, and its claim takes the stand-in on its revision's model (computer-held.ts).
|
|
784
|
+
const model = modelRefused ? undefined : await deps.modelOf(entry, revision);
|
|
773
785
|
// The run's Archil disk, chosen now and kept in its launch (run-launch.ts archilDisk): the one the body names (a disk per
|
|
774
786
|
// customer), else its agent's when it has one; with neither, its claim makes the agent's.
|
|
775
787
|
const named = isObject(body.archil_disk) && typeof body.archil_disk.disk_id === "string" ? body.archil_disk.disk_id : undefined;
|
|
@@ -815,7 +827,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
815
827
|
...(from ? { inputOrigin: from } : {}),
|
|
816
828
|
...(model ? { model } : {}),
|
|
817
829
|
...(archilDisk ? { archilDisk } : {}),
|
|
818
|
-
...(hold ? { hold } : {}),
|
|
830
|
+
...(hold ? { hold: modelRefused ? { ...hold, refused: modelRefused } : hold } : {}),
|
|
819
831
|
};
|
|
820
832
|
return { launch, revision };
|
|
821
833
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SignInReader } from "./run-view.js";
|
|
2
|
+
import { type Store } from "./store/index.js";
|
|
3
|
+
/** The kinds of cut, in the order they are printed (secret-rules.ts CutKind). */
|
|
4
|
+
export declare const CUT_KINDS: readonly ["format", "held", "dump", "label", "personal", "jev"];
|
|
5
|
+
type Kind = (typeof CUT_KINDS)[number];
|
|
6
|
+
/** The run view's fields a share carries (share-design §1, the `run` allowlist, store-view.ts viewOfRun); every other
|
|
7
|
+
* field is dropped. `imported_from` carries its `source` alone. */
|
|
8
|
+
export declare const SHARE_RUN_FIELDS: readonly ["kind", "status", "state", "title", "created_at", "ended_at", "result", "error", "review", "cost", "stopped_for", "budget_refused_calls", "effort", "approvals"];
|
|
9
|
+
/** The reads a share's text is gathered by: the run's one cut (run-cut.ts runCutValues) and what serves under it. */
|
|
10
|
+
export interface ShareTextDeps {
|
|
11
|
+
readonly serverSecrets: () => string[];
|
|
12
|
+
readonly signIns?: SignInReader;
|
|
13
|
+
/** The store's seal key, undefined when it has none: the run's sealed launch values are read under it (run-cut.ts). */
|
|
14
|
+
readonly sealKey: Buffer | undefined;
|
|
15
|
+
readonly keyEnv: () => NodeJS.ProcessEnv;
|
|
16
|
+
}
|
|
17
|
+
/** Every string in a JSON value, its object keys included (a key can hold a value: a header's name a tool printed, a
|
|
18
|
+
* map keyed by a command line). */
|
|
19
|
+
export declare function stringsOf(value: unknown): string[];
|
|
20
|
+
/** A tool's output with its call's context (ruling LVI): the file the call read whole (`path`) or the shell command it
|
|
21
|
+
* ran (`command`), so the scrubber reads a credential file's or a dump command's output as the dump it is, though the
|
|
22
|
+
* output stands alone in its result's field. A share's export reads the same (secret-cut.ts ScrubOptions). */
|
|
23
|
+
export interface ShareText {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly path?: string;
|
|
26
|
+
readonly command?: string;
|
|
27
|
+
}
|
|
28
|
+
/** What a share of run `runId` would carry, as strings (object keys included: stringsOf), a tool's output with its
|
|
29
|
+
* call's context (ShareText), with the run's cut set read after them (the cut only grows, so the last read holds every
|
|
30
|
+
* value an earlier read cut); `unknown` for a run the store does not hold, `withheld` when its cut can't be read here. */
|
|
31
|
+
export declare function shareTexts(store: Store, runId: string, deps: ShareTextDeps): Promise<{
|
|
32
|
+
kind: string;
|
|
33
|
+
texts: (string | ShareText)[];
|
|
34
|
+
held: string[];
|
|
35
|
+
} | "unknown" | "withheld">;
|
|
36
|
+
/** One rule's line of the count. */
|
|
37
|
+
export interface RuleCount {
|
|
38
|
+
readonly rule: string;
|
|
39
|
+
readonly kind: string;
|
|
40
|
+
readonly restorable: boolean;
|
|
41
|
+
readonly count: number;
|
|
42
|
+
}
|
|
43
|
+
/** The count `scrub` prints: by rule, by kind, the cuts a share would make and how many of them could be restored, and
|
|
44
|
+
* how many `[redacted]` marks the served text holds already (known key formats and held values the server's own cut takes
|
|
45
|
+
* out where it serves the run, run-view.ts shownOf, or keys an import took out before). */
|
|
46
|
+
export interface ShareCount {
|
|
47
|
+
readonly run_id: string;
|
|
48
|
+
readonly kind: string;
|
|
49
|
+
readonly strings: number;
|
|
50
|
+
readonly rules: RuleCount[];
|
|
51
|
+
readonly by_kind: Record<Kind, number>;
|
|
52
|
+
readonly cuts: number;
|
|
53
|
+
readonly restorable: number;
|
|
54
|
+
readonly already_redacted: number;
|
|
55
|
+
/** Whether a share would be refused: cut mode fails closed on one of the strings (its final check finds a held value or
|
|
56
|
+
* a format left once cut), so no share of this run is made until a rule cuts it. */
|
|
57
|
+
readonly blocked: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The scrubber's count over `texts` with `held` as its held values, a ShareText with its call's context: each cut's
|
|
60
|
+
* rule, kind and whether it can be restored, never its value, shape or offsets. */
|
|
61
|
+
export declare function countCuts(runId: string, kind: string, texts: readonly (string | ShareText)[], held: readonly string[]): Promise<ShareCount>;
|
|
62
|
+
/** The count as a table: one line per rule, totals by kind, and the line that says what a share would cut. */
|
|
63
|
+
export declare function countTable(count: ShareCount): string;
|
|
64
|
+
/** The line that says a run could not be counted: the error's own words, cut by the scrubber first with `held` as its
|
|
65
|
+
* held values (a store's error could quote what it read, a held value among it), else withheld. */
|
|
66
|
+
export declare function couldNotCount(runId: string, error: unknown, held: readonly string[]): Promise<string>;
|
|
67
|
+
/** `agentrun-serve scrub RUN [--data DIR] [--json]`: the exit code (the file's head). Output goes to `out`, words about
|
|
68
|
+
* why nothing was counted to `err`. */
|
|
69
|
+
export declare function scrubMain(argv: readonly string[], usage: string, io?: {
|
|
70
|
+
out: (line: string) => void;
|
|
71
|
+
err: (line: string) => void;
|
|
72
|
+
}): Promise<number>;
|
|
73
|
+
export {};
|