@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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 +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -27,7 +27,7 @@ const outputRetried = (entries) => {
|
|
|
27
27
|
return at >= 0 && entries.slice(at + 1).some((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
|
|
28
28
|
};
|
|
29
29
|
import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
|
|
30
|
-
import {
|
|
30
|
+
import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
|
|
31
31
|
import { ADAPTER_API } from "../turn-end.js";
|
|
32
32
|
import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
|
|
33
33
|
import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
|
|
@@ -62,12 +62,11 @@ export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool
|
|
|
62
62
|
export const AGENTIC_PAUSE_REFUSED = "Only a workflow run pauses here: an agentic run's turn is stopped with POST /runs/{id}/stop.";
|
|
63
63
|
/** An asked call's card: the gate's own fields (`shown`) first, so a card cut at its preview's bound (ARGS_PREVIEW_BYTES)
|
|
64
64
|
* still names them whatever the input's size, then the call's input, which the model wrote, without any field of
|
|
65
|
-
* theirs; a learned_workflow call's card fields (LEARNED_CARD_FIELDS) are only ever the gate's
|
|
66
|
-
* call its setting allows asks anyway (ASKED_BECAUSE). */
|
|
65
|
+
* theirs; a learned_workflow call's card fields (LEARNED_CARD_FIELDS) are only ever the gate's. */
|
|
67
66
|
function cardOf(tool, shown, args) {
|
|
68
|
-
if (!shown && tool !== LEARNED_WORKFLOW_TOOL
|
|
67
|
+
if (!shown && tool !== LEARNED_WORKFLOW_TOOL)
|
|
69
68
|
return args;
|
|
70
|
-
return { ...shown, ...Object.fromEntries(Object.entries(args ?? {}).filter(([key]) => !(shown && Object.hasOwn(shown, key)) &&
|
|
69
|
+
return { ...shown, ...Object.fromEntries(Object.entries(args ?? {}).filter(([key]) => !(shown && Object.hasOwn(shown, key)) && !(tool === LEARNED_WORKFLOW_TOOL && LEARNED_CARD_FIELDS.has(key)))) };
|
|
71
70
|
}
|
|
72
71
|
/** The request ids of the person's messages placed as turns (loop.ts commandRequest). */
|
|
73
72
|
const COMMAND_REQUEST_PREFIX = commandRequest(0).replace(/0$/, "");
|
|
@@ -1101,13 +1100,19 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1101
1100
|
return { later: "the run is waiting on a person: the message runs as a turn of its own after the answer" };
|
|
1102
1101
|
// A grade's feedback round (feedback-round.ts): the run opened again on the grade's words, which are never a turn of
|
|
1103
1102
|
// the job's. Kept on the root as a FEEDBACK entry, whose commit takes the row; the claim goes to its end-of-run turn.
|
|
1103
|
+
// The same commit keeps the end the run had when the grade opened it as its job's end (KINDS.jobEnd): from the taking
|
|
1104
|
+
// on, the round is a look-back with its job's end kept, which every reader serves and its claim ends on (jobEndKept).
|
|
1104
1105
|
const fed = reopen && !reopen.sent && (session.state === "idle" || session.state === "new") ? feedbackOf(command.body) : undefined;
|
|
1105
1106
|
if (fed && reopen && harness && root) {
|
|
1106
1107
|
const [on, theRoot, mine] = [harness, root, reopen];
|
|
1107
1108
|
const taken = gate.expect(writesEntry(KINDS.feedback, (data) => data.requestId === requestId), { take: [command.id] });
|
|
1108
1109
|
taken.catch(() => undefined);
|
|
1109
|
-
|
|
1110
|
-
mine.
|
|
1110
|
+
const { kept: { endedAt, ...end }, ...round } = fed;
|
|
1111
|
+
mine.feedback = round;
|
|
1112
|
+
mine.sent = on.commit(async (tx) => {
|
|
1113
|
+
await tx.appendEntry(theRoot.id, { kind: KINDS.feedback, data: { ...round, requestId, at: now() } });
|
|
1114
|
+
await tx.appendEntry(theRoot.id, { kind: KINDS.jobEnd, data: jobEndOf(end, undefined, endedAt) });
|
|
1115
|
+
}, context).then(() => undefined);
|
|
1111
1116
|
mine.placed?.();
|
|
1112
1117
|
try {
|
|
1113
1118
|
await mine.sent;
|
|
@@ -1997,6 +2002,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1997
2002
|
return { text: given.deny, isError: true };
|
|
1998
2003
|
// An ask with its card's own fields is an ask, its card as the gate shows it.
|
|
1999
2004
|
const shown = typeof given === "object" ? given.ask : undefined;
|
|
2005
|
+
const because = typeof given === "object" ? given.because : undefined;
|
|
2000
2006
|
const now = shown ? "ask" : given;
|
|
2001
2007
|
// Set to ask since (or asked, and answered before the crash): asked as any call is, as main's gate parked a
|
|
2002
2008
|
// replayed call as a request of its own. Its answer stands; else the run parks on it, the call held unrun until
|
|
@@ -2004,7 +2010,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2004
2010
|
// the setting at allow now: the setting answers the ask (allowedBySetting).
|
|
2005
2011
|
const bySetting = now === "allow" && (await askStands(toolContext.callId));
|
|
2006
2012
|
if (now === "ask" || bySetting) {
|
|
2007
|
-
const call = { callId: toolContext.callId, tool: name, args: cardOf(name, shown, (args ?? {})) };
|
|
2013
|
+
const call = { callId: toolContext.callId, tool: name, args: cardOf(name, shown, (args ?? {})), ...(because !== undefined ? { because } : {}) };
|
|
2008
2014
|
const price = mcp?.priceOf(name) ?? null;
|
|
2009
2015
|
const answer = bySetting ? await allowedBySetting(call, price, asked) : await answerOf(call, price, asked);
|
|
2010
2016
|
if (answer === "park")
|
|
@@ -2756,16 +2762,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2756
2762
|
let parkOn;
|
|
2757
2763
|
/** The ask_person call the run waits on in its claim, while it does. */
|
|
2758
2764
|
let waitingOn;
|
|
2759
|
-
/** When the job's end was, once it is kept (keepJobEnd
|
|
2760
|
-
*
|
|
2765
|
+
/** When the job's end was, once it is kept (keepJobEnd; a grade's round's, by its steer's taking): the look-back
|
|
2766
|
+
* after it never moves it, and its end is written at that time. */
|
|
2761
2767
|
let keptAt;
|
|
2762
|
-
if (alone && lookingBack)
|
|
2768
|
+
if (alone && (lookingBack || feedbackNow))
|
|
2763
2769
|
({ end: data, failedWith, endedAt: keptAt } = await jobEndKept(root));
|
|
2764
|
-
else if (alone && feedbackNow?.kept) {
|
|
2765
|
-
const { endedAt, ...end } = feedbackNow.kept;
|
|
2766
|
-
data = end;
|
|
2767
|
-
keptAt = endedAt;
|
|
2768
|
-
}
|
|
2769
2770
|
else if (alone)
|
|
2770
2771
|
data = { state: "ended" };
|
|
2771
2772
|
else
|
|
@@ -3001,15 +3002,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3001
3002
|
// takes the run past its cap is the learning's (askEndOfRun reads overCap after each of its turns), never the run's.
|
|
3002
3003
|
// That end is kept before the step's first ask, so a claim that finds its turn open ends the run on it (jobEndKept).
|
|
3003
3004
|
// Kept with its time: from then on every reader serves it, and the run's end is written at it (writeEnd `keptAt`).
|
|
3004
|
-
if (!lookingBack)
|
|
3005
|
-
keptAt = await keepJobEnd(harness, root, spec, data, failedWith
|
|
3005
|
+
if (!lookingBack && !feedbackNow)
|
|
3006
|
+
keptAt = await keepJobEnd(harness, root, spec, data, failedWith);
|
|
3006
3007
|
const step = await endOfRunStep(claim, spec, data.state === "failed" ? "failed" : "completed", overCap, keptAt);
|
|
3007
3008
|
// A stop or cancel the runner took during the step (one that raced the read refusing it, its row written while the
|
|
3008
3009
|
// run still read as going on) cuts the look-back alone: the run ends on its job's end, the row taken by that end.
|
|
3009
|
-
|
|
3010
|
-
return await writeEnd(harness, root, gate, data, [step.commandId], await cutRows(claim, spec, "stopped-looking"), failedWith, keptAt);
|
|
3010
|
+
// A step that runs always has its job's end kept (`keptAt`), so a stop there never ends the run stopped.
|
|
3011
3011
|
if (step.kind === "stopped")
|
|
3012
|
-
return await writeEnd(harness, root, gate,
|
|
3012
|
+
return await writeEnd(harness, root, gate, data, [step.commandId], await cutRows(claim, spec, "stopped-looking"), failedWith, keptAt);
|
|
3013
3013
|
if (step.kind === "interrupted")
|
|
3014
3014
|
return await interrupted(stopReason?.kind ?? "its claim's signal aborted");
|
|
3015
3015
|
return await writeEnd(harness, root, gate, data, [], step.also, failedWith, keptAt);
|
|
@@ -3066,8 +3066,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3066
3066
|
// A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
|
|
3067
3067
|
const replayed = call.replayed === true;
|
|
3068
3068
|
const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf })) ?? "allow";
|
|
3069
|
-
// An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape)
|
|
3069
|
+
// An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape), or
|
|
3070
|
+
// with the reason a call its setting allows asks anyway (`because`).
|
|
3070
3071
|
const shown = typeof given === "object" && "ask" in given ? given.ask : undefined;
|
|
3072
|
+
const because = typeof given === "object" && "ask" in given ? given.because : undefined;
|
|
3071
3073
|
let decision = shown ? "ask" : given;
|
|
3072
3074
|
// A call nested in a learned_workflow call a person approved, of an MCP tool that call's card named: its ask is
|
|
3073
3075
|
// answered by that approval, as the card they saw named it (never one built again now). Any other asks for itself.
|
|
@@ -3113,7 +3115,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3113
3115
|
// Marked destructive when the tool is, or when any MCP tool the one allow lets run is (the card's `mcp_calls`, a
|
|
3114
3116
|
// learned workflow's MCP actions set to ask): that allow takes the second confirm too.
|
|
3115
3117
|
const destructive = [asked, ...learnedApprovedTools(shown)].some((name) => mcp?.effectOf(name) === "destructive");
|
|
3116
|
-
const
|
|
3118
|
+
const card = { ...call, tool, args, ...(because !== undefined ? { because } : {}) };
|
|
3119
|
+
const answer = bySetting ? await allowedBySetting(card, price, asked) : await answerOf(card, price, asked, destructive);
|
|
3117
3120
|
if (answer === "park")
|
|
3118
3121
|
return { park: true };
|
|
3119
3122
|
if (answer.approved)
|
|
@@ -3152,7 +3155,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3152
3155
|
// run's pending approval, its approval row, an "always" answer pinned by it) has the one name main gives it.
|
|
3153
3156
|
// An MCP tool its run's pin marks destructive (ClaimMcp.effectOf), or a call whose allow covers one (`destructive`):
|
|
3154
3157
|
// its card asks a second confirm of an allow.
|
|
3155
|
-
const ask = first ?? { callId: call.callId, tool: asked, args: call.args ?? null, requestedAt: isoNow(), price, ...(destructive ? { destructive: true } : {}) };
|
|
3158
|
+
const ask = first ?? { callId: call.callId, tool: asked, args: call.args ?? null, ...(call.because !== undefined ? { because: call.because } : {}), requestedAt: isoNow(), price, ...(destructive ? { destructive: true } : {}) };
|
|
3156
3159
|
const entryLands = (kind, data, staged) => landEntry(conversation, kind, data, staged);
|
|
3157
3160
|
if (first === undefined) {
|
|
3158
3161
|
// Asked and parked; or held as the parked call is, when another call of the round parked the run first.
|
|
@@ -3396,20 +3399,23 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3396
3399
|
return turnOfRequest(on, conversation, last.requestId);
|
|
3397
3400
|
}
|
|
3398
3401
|
/** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
|
|
3399
|
-
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf).
|
|
3400
|
-
*
|
|
3401
|
-
|
|
3402
|
-
async function keepJobEnd(on, conversation, spec, data, failedWith, at) {
|
|
3402
|
+
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf). Kept with
|
|
3403
|
+
* its time, now, which it answers; with no step to ask, nothing is kept. */
|
|
3404
|
+
async function keepJobEnd(on, conversation, spec, data, failedWith) {
|
|
3403
3405
|
if (!stepOf(spec))
|
|
3404
|
-
return
|
|
3405
|
-
const
|
|
3406
|
-
const endedAt = at ?? now();
|
|
3407
|
-
const kept = { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
|
|
3406
|
+
return undefined;
|
|
3407
|
+
const kept = jobEndOf(data, failedWith, now());
|
|
3408
3408
|
await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
|
|
3409
|
-
return endedAt;
|
|
3409
|
+
return kept.endedAt;
|
|
3410
|
+
}
|
|
3411
|
+
/** A job's end as KINDS.jobEnd keeps it: its summary cut of every secret the runner holds, as every summary is when
|
|
3412
|
+
* served. */
|
|
3413
|
+
function jobEndOf(data, failedWith, endedAt) {
|
|
3414
|
+
const end = data.summary !== undefined && deps.redact ? { ...data, summary: deps.redact(data.summary) } : data;
|
|
3415
|
+
return { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
|
|
3410
3416
|
}
|
|
3411
|
-
/** The job's end for a claim that found the end-of-run turn open (lookingBackOpen)
|
|
3412
|
-
* follow-up's round keeps its own), never worked out again. */
|
|
3417
|
+
/** The job's end for a claim that found the end-of-run turn open (lookingBackOpen), or a grade's round (its steer's
|
|
3418
|
+
* taking kept it): the newest one kept (a follow-up's round keeps its own), never worked out again. */
|
|
3413
3419
|
async function jobEndKept(conversation) {
|
|
3414
3420
|
const kept = (await entriesOf(gate.journal, conversation.id, context)).filter((entry) => entry.kind === KINDS.jobEnd).at(-1);
|
|
3415
3421
|
if (!kept)
|
|
@@ -186,7 +186,7 @@ export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>)
|
|
|
186
186
|
export declare function graderRouteOf(body: {
|
|
187
187
|
readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
|
|
188
188
|
readonly learning?: unknown;
|
|
189
|
-
}, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[]): Promise<ModelRoute | undefined>;
|
|
189
|
+
}, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[], claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<ModelRoute | undefined>;
|
|
190
190
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
191
191
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
192
192
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -14,7 +14,7 @@ import { dirname, join } from "node:path";
|
|
|
14
14
|
import { stopRunWith } from "../paid-calls.js";
|
|
15
15
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
16
16
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
17
|
-
import { checkRaise, followUpOf,
|
|
17
|
+
import { checkRaise, followUpOf, freeRequestLimitOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
18
|
import { inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
19
19
|
import { factsOf } from "../harness-table.js";
|
|
20
20
|
import { decisionProvidersIn } from "../decisions.js";
|
|
@@ -24,7 +24,6 @@ import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes }
|
|
|
24
24
|
import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
|
|
25
25
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
26
26
|
import { isWebHostTool } from "../tool-list.js";
|
|
27
|
-
import { ASKED_BECAUSE } from "../refusal-words.js";
|
|
28
27
|
import { deniedText, noApproverText, runGate } from "../tool-gate.js";
|
|
29
28
|
import { DECISION_PROVIDER_KEYS, loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
|
|
30
29
|
import { readApprovers } from "../server-approvers.js";
|
|
@@ -46,14 +45,14 @@ import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
|
46
45
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
47
46
|
import { COMPUTER_ROOT, recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
|
|
48
47
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
49
|
-
import { placeRunInputs } from "../uploads.js";
|
|
48
|
+
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
50
49
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
51
50
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
52
51
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
53
52
|
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
54
53
|
import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
|
|
55
54
|
import { agreeOnOf } from "../learning-setting.js";
|
|
56
|
-
import { catalogSessionNames, mcpWhereHeld } from "./mcp-run.js";
|
|
55
|
+
import { catalogSessionNames, mcpWhereHeld, mediaForClaim } from "./mcp-run.js";
|
|
57
56
|
import { held as runnerSeam, heldOrThrow, heldSignInReads } from "./held.js";
|
|
58
57
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
59
58
|
import { RUNNER_HARNESSES } from "./adapters/index.js";
|
|
@@ -132,13 +131,14 @@ const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
|
|
|
132
131
|
* holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone. A run with its
|
|
133
132
|
* own model key carries that key, and no saved key is read. Undefined when there is no fast model, the revision names
|
|
134
133
|
* agree_on, or no route can be made (logged: the pair is then compared whole). */
|
|
135
|
-
export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut]) {
|
|
134
|
+
export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut], claim) {
|
|
136
135
|
if (agreeOnOf(body.learning)?.length)
|
|
137
136
|
return undefined;
|
|
138
137
|
const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
|
|
139
138
|
for (const redact of new Set(holds))
|
|
140
139
|
holdClaimed(redact, savedKeys);
|
|
141
|
-
|
|
140
|
+
// The claim's run, turn and attempt on its grader's requests too (request-metadata.ts): they spend on the run's cap.
|
|
141
|
+
const env = claimModelEnv(deps.env, { ...savedKeys, ...claimed }, runKey, claim);
|
|
142
142
|
if (body.modelTiers?.fast === undefined && tierModelOf(env, "fast") === undefined)
|
|
143
143
|
return undefined;
|
|
144
144
|
try {
|
|
@@ -204,7 +204,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
|
|
|
204
204
|
const asksOf = decision === "allow" && host && options.ran ? toolOf(call.tool)?.asks : undefined;
|
|
205
205
|
const because = asksOf ? await askedOne(call, asksOf, host, options.ran) : undefined;
|
|
206
206
|
if (because !== undefined)
|
|
207
|
-
return approvers ? { ask: {
|
|
207
|
+
return approvers ? { ask: {}, because } : { deny: noApproverText(gate.askedAs(call.tool, call.args), options.replayed ? "unknown" : "no", because) };
|
|
208
208
|
// A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings: one set to deny refuses the
|
|
209
209
|
// whole call in the gate's words before any node runs, nothing sent; the actions set to ask are put to a person on the
|
|
210
210
|
// call's one card, up front, each with its arguments' shape (learnedAskShown), and the person's allow passes the
|
|
@@ -311,7 +311,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
311
311
|
// a copy that fails ends the run failed, saying why. A run's own process copies nothing: its runner placed them before
|
|
312
312
|
// the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
|
|
313
313
|
if (!(deps.sealKey === undefined && runnerSeam()))
|
|
314
|
-
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch
|
|
314
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
315
315
|
// The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
|
|
316
316
|
// turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
|
|
317
317
|
// there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
|
|
@@ -344,7 +344,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
344
344
|
// words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
|
|
345
345
|
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
|
|
346
346
|
const hold = (values) => cut.hold(values);
|
|
347
|
-
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
|
|
347
|
+
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: () => launch.maxCostUsd !== undefined, media: mediaForClaim(deps.env, deps.evalFakes?.(runRow.agentId)?.web, deps.saveSlots) });
|
|
348
348
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
349
349
|
holds.hold({ passed: mcp });
|
|
350
350
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
@@ -397,7 +397,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
397
397
|
holdClaimed(cut, toolEnv);
|
|
398
398
|
// The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
|
|
399
399
|
// saved in Settings → Model keys runs the next run with no restart (withModelKeys). A run with its own key: that key.
|
|
400
|
-
const modelEnv = claimModelEnv(deps.env, toolEnv, runKey);
|
|
400
|
+
const modelEnv = claimModelEnv(deps.env, toolEnv, runKey, claim);
|
|
401
401
|
const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
|
|
402
402
|
await planBeforeRun(modelEnv, route.provider.plan ? { provider: PLAN_PROVIDER } : undefined);
|
|
403
403
|
// The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
|
|
@@ -429,7 +429,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
429
429
|
// A run with its own model key: its subagents' models carry that key too, and no saved key is read.
|
|
430
430
|
const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
|
|
431
431
|
holdClaimed(cut, savedKeys);
|
|
432
|
-
const tierEnv = claimModelEnv(deps.env, { ...savedKeys, ...toolEnv }, runKey);
|
|
432
|
+
const tierEnv = claimModelEnv(deps.env, { ...savedKeys, ...toolEnv }, runKey, claim);
|
|
433
433
|
for (const tier of SUBAGENT_TIERS) {
|
|
434
434
|
if (body.modelTiers?.[tier] === undefined && tierModelOf(tierEnv, tier) === undefined)
|
|
435
435
|
continue;
|
|
@@ -498,8 +498,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
498
498
|
},
|
|
499
499
|
// What its audit's shadow took beside it, read by every gate with its own sessions (none: it starts none).
|
|
500
500
|
...(besideOf ? { beside: besideOf } : {}),
|
|
501
|
-
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
|
|
502
|
-
freeRequests:
|
|
501
|
+
// The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
|
|
502
|
+
freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
|
|
503
503
|
};
|
|
504
504
|
// The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
|
|
505
505
|
// has a cap. A park names the cap the loop holds the run to then (a raise's, else this one).
|
|
@@ -554,7 +554,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
554
554
|
// A run with its own model key: its learned nodes' tiers carry that key too, and no saved key is read.
|
|
555
555
|
const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
|
|
556
556
|
holdClaimed(cut, tierKeys);
|
|
557
|
-
const tierEnv = claimModelEnv(deps.env, { ...toolEnv, ...tierKeys }, runKey);
|
|
557
|
+
const tierEnv = claimModelEnv(deps.env, { ...toolEnv, ...tierKeys }, runKey, claim);
|
|
558
558
|
for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
|
|
559
559
|
if ("why" in routed)
|
|
560
560
|
tierUnreachable.set(tier, routed.why);
|
|
@@ -567,7 +567,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
567
567
|
}
|
|
568
568
|
// A replay run's or a shadow's grader (runner/compare-end.ts), on a route of its own beside the session's, on the
|
|
569
569
|
// session's booking under the run's one cap. None: the pair is compared whole, in words saying so.
|
|
570
|
-
const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps) : undefined;
|
|
570
|
+
const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps, [cut], claim) : undefined;
|
|
571
571
|
if (graderRoute)
|
|
572
572
|
tierRoutes.set(GRADER, graderRoute);
|
|
573
573
|
// The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
|
package/dist/runner/audit.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare function agreeOnOfRevision(store: Pick<Store, "agents">, revision
|
|
|
37
37
|
export declare function auditedAnswerOf(deps: Pick<AuditDeps, "store" | "context" | "folder">, shadowRun: string): Promise<string | null>;
|
|
38
38
|
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
39
39
|
* started them): what the promotions read counts beside the audit line. */
|
|
40
|
-
export declare function notAuditableOf(store: Pick<Store, "runs">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
|
40
|
+
export declare function notAuditableOf(store: Pick<Store, "runs" | "settings">, agentId: string, workflow: string, digest: string, loop: Pick<AuditLoop, "stop_window">): Promise<number>;
|
|
41
41
|
/** The words a shadow run ends failed with where it would wait on a person (AdapterRunSpec.neverWaits: an approval, a
|
|
42
42
|
* raise of its cap, which is what its served run's cap left, a question), what it would wait on after them: its row is
|
|
43
43
|
* `parked`, with no verdict. */
|
|
@@ -58,7 +58,9 @@ export declare function withAudit(step: EndOfRunTurn | undefined, deps: AuditDep
|
|
|
58
58
|
* spend past the served run's cap; with less than a run's smallest cap left (or a spend not known), no shadow is started
|
|
59
59
|
* and its row says `skipped: "no allowance"`. Its started line is appended first: a shadow is created only once the
|
|
60
60
|
* ledger names it (settlement finds it there, never in a window of runs), and one whose line could not be written is
|
|
61
|
-
* never created. Idempotent: one line and one shadow per run.
|
|
61
|
+
* never created. Idempotent: one line and one shadow per run. A run the agent's learning reads no more starts none, as
|
|
62
|
+
* it adds no grade row (gradeRow): one before its learning's reset (sinceReset), ended again after it by a follow-up,
|
|
63
|
+
* or one on a named disk (learn/learning-of.ts). */
|
|
62
64
|
export declare function startAudit(deps: AuditDeps & {
|
|
63
65
|
readonly runId: string;
|
|
64
66
|
readonly launch: RunLaunch;
|
|
@@ -71,5 +73,8 @@ export declare function startAudit(deps: AuditDeps & {
|
|
|
71
73
|
export declare function settleAudits(deps: AuditDeps): Promise<void>;
|
|
72
74
|
/** The row an owner's grade of served run `run` writes (source grade, agreed = the grade, counted for the digest's
|
|
73
75
|
* promotion now), then the hold rule: only for a run the workflow answered alone (its answer is the workflow's).
|
|
74
|
-
* Nothing else: no round, no compile by itself.
|
|
76
|
+
* Nothing else: no round, no compile by itself. A run before the agent's learning reset (sinceReset) adds no row: its
|
|
77
|
+
* grade is kept, but a promotion of the same digest after the reset is never held by what came before it. A run on a
|
|
78
|
+
* named disk adds none either (learn/learning-of.ts): the hold rule would copy its answers into the promotion's
|
|
79
|
+
* disagreements, and the agent's compile reads those. */
|
|
75
80
|
export declare function gradeRow(deps: AuditDeps, run: RunRow, correct: boolean): Promise<void>;
|
package/dist/runner/audit.js
CHANGED
|
@@ -34,7 +34,7 @@ import { FINAL_STATES, StoreConstraint } from "../store/store.js";
|
|
|
34
34
|
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
35
35
|
import { isObject } from "../validate.js";
|
|
36
36
|
import { auditableLaunch, auditChange, auditEveryOf, auditDrawn, auditsOffWords, auditWriterOf, holdOf, ledgerOf, lineKey, openAudits, rowsOf, shadowRunId } from "../learn/audit.js";
|
|
37
|
-
import { lastRunsOf } from "../learn/compile.js";
|
|
37
|
+
import { lastRunsOf, sinceReset } from "../learn/compile.js";
|
|
38
38
|
import { readLearning, writeLearning } from "../learn/folder.js";
|
|
39
39
|
import { CHECK_TEXT_MAX, compareAnswers, comparedOf, promotionOf, promotionsOf, promotionStartOf, recordPromotion, servingOf } from "../learn/promote.js";
|
|
40
40
|
import { excerptShown } from "../learn/secrets.js";
|
|
@@ -79,9 +79,13 @@ export async function auditedAnswerOf(deps, shadowRun) {
|
|
|
79
79
|
const open = openAudits(await readLedger(deps)).find((line) => line.shadow_run === shadowRun);
|
|
80
80
|
return open ? auditedAnswer(deps, open) : null;
|
|
81
81
|
}
|
|
82
|
-
/** The served runs of `workflow` (at `digest` when given) that `keep` keeps too, the
|
|
83
|
-
* shadows and the agent's own runs among them never push one out
|
|
84
|
-
|
|
82
|
+
/** The served runs of `workflow` (at `digest` when given) that `keep` keeps too, since the agent's learning's reset
|
|
83
|
+
* (sinceReset), the newest `n` of them (lastRunsOf: the shadows and the agent's own runs among them never push one out
|
|
84
|
+
* of the read). */
|
|
85
|
+
const servedRuns = async (store, agentId, n, workflow, digest, keep = () => true) => {
|
|
86
|
+
const since = await sinceReset(store, agentId);
|
|
87
|
+
return lastRunsOf(store, agentId, n, (row) => served(row) && metricsOf(row).workflow === workflow && (digest === undefined || metricsOf(row).workflow_digest === digest) && keep(row) && since(row));
|
|
88
|
+
};
|
|
85
89
|
/** How many of the newest stop_window runs `workflow` at `digest` served were not auditable (auditableLaunch: a trigger
|
|
86
90
|
* started them): what the promotions read counts beside the audit line. */
|
|
87
91
|
export async function notAuditableOf(store, agentId, workflow, digest, loop) {
|
|
@@ -134,7 +138,9 @@ async function auditAtEnd(deps, runId) {
|
|
|
134
138
|
* spend past the served run's cap; with less than a run's smallest cap left (or a spend not known), no shadow is started
|
|
135
139
|
* and its row says `skipped: "no allowance"`. Its started line is appended first: a shadow is created only once the
|
|
136
140
|
* ledger names it (settlement finds it there, never in a window of runs), and one whose line could not be written is
|
|
137
|
-
* never created. Idempotent: one line and one shadow per run.
|
|
141
|
+
* never created. Idempotent: one line and one shadow per run. A run the agent's learning reads no more starts none, as
|
|
142
|
+
* it adds no grade row (gradeRow): one before its learning's reset (sinceReset), ended again after it by a follow-up,
|
|
143
|
+
* or one on a named disk (learn/learning-of.ts). */
|
|
138
144
|
export async function startAudit(deps, serve) {
|
|
139
145
|
const { store, agentId, runId, launch, log } = deps;
|
|
140
146
|
if (!serve || serve.replay || launch.replay || launch.audit || !launch.learning || !auditableLaunch(launch))
|
|
@@ -145,6 +151,10 @@ export async function startAudit(deps, serve) {
|
|
|
145
151
|
if (off)
|
|
146
152
|
return void log(`workflow-first: ${off}`);
|
|
147
153
|
try {
|
|
154
|
+
// The run is there at its end (its end commits after this step).
|
|
155
|
+
const row = await store.runs.get(runId);
|
|
156
|
+
if (row && ((row.disk ?? null) !== null || !(await sinceReset(store, agentId))(row)))
|
|
157
|
+
return;
|
|
148
158
|
// Read after the claim pinned the revision's MCP tools (mcp-claim.ts pinFirst): the pin a revision saved without one
|
|
149
159
|
// takes at its first run is what its tools are classed by.
|
|
150
160
|
const revision = await store.agents.revision(deps.revisionId);
|
|
@@ -268,11 +278,16 @@ export async function settleAudits(deps) {
|
|
|
268
278
|
}
|
|
269
279
|
/** The row an owner's grade of served run `run` writes (source grade, agreed = the grade, counted for the digest's
|
|
270
280
|
* promotion now), then the hold rule: only for a run the workflow answered alone (its answer is the workflow's).
|
|
271
|
-
* Nothing else: no round, no compile by itself.
|
|
281
|
+
* Nothing else: no round, no compile by itself. A run before the agent's learning reset (sinceReset) adds no row: its
|
|
282
|
+
* grade is kept, but a promotion of the same digest after the reset is never held by what came before it. A run on a
|
|
283
|
+
* named disk adds none either (learn/learning-of.ts): the hold rule would copy its answers into the promotion's
|
|
284
|
+
* disagreements, and the agent's compile reads those. */
|
|
272
285
|
export async function gradeRow(deps, run, correct) {
|
|
273
286
|
const m = metricsOf(run);
|
|
274
287
|
if (m.path !== "workflow" || typeof m.workflow !== "string" || typeof m.workflow_digest !== "string")
|
|
275
288
|
return;
|
|
289
|
+
if ((run.disk ?? null) !== null || !(await sinceReset(deps.store, deps.agentId))(run))
|
|
290
|
+
return;
|
|
276
291
|
const promoted = promotionStartOf(await promotionsOf(deps.store.settings, deps.agentId), m.workflow, m.workflow_digest);
|
|
277
292
|
// The answer graded: the run's newest now, kept by its row's id (as a shadow's audit keeps its turn).
|
|
278
293
|
const turn = turnOf((await answerRowOf(deps.store, run.id, deps.context))?.id);
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RunnerEvent } from "./runner.js";
|
|
1
2
|
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
2
3
|
export declare const DRAIN_TIMEOUT = "30s";
|
|
3
4
|
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
@@ -51,6 +52,18 @@ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainM
|
|
|
51
52
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
52
53
|
close: () => Promise<void>;
|
|
53
54
|
}>;
|
|
55
|
+
/** The lines runner `name` beside a server says for `event`, in order, each with whether it goes to stderr (`error`): its
|
|
56
|
+
* metric line (runner-metrics.ts metricLine: a claim, a hand-back by cause, a lost claim, the drain), then its trouble
|
|
57
|
+
* (main.ts troubleLine: a lost claim, an error) or else its run's start or end (print.ts runLine). A lost claim says
|
|
58
|
+
* both its metric and its trouble. The three are handed in, as runnerBeside imports them on its start. */
|
|
59
|
+
export declare function besideLines(name: string, event: RunnerEvent, say: {
|
|
60
|
+
metricLine: (name: string, event: RunnerEvent) => string | undefined;
|
|
61
|
+
troubleLine: (name: string, event: RunnerEvent) => string | undefined;
|
|
62
|
+
runLine: (event: RunnerEvent) => string | undefined;
|
|
63
|
+
}): {
|
|
64
|
+
line: string;
|
|
65
|
+
error: boolean;
|
|
66
|
+
}[];
|
|
54
67
|
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
55
68
|
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
56
69
|
* server's runs reach its fakes. For a launcher that starts serve in-process (a demo, a smoke): a server alone leaves
|
package/dist/runner/beside.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
|
|
3
3
|
import { maxRunsOf } from "../host.js";
|
|
4
4
|
import { durationMs } from "../print.js";
|
|
5
|
-
import { runnerCloseBoundMs } from "./runner.js";
|
|
5
|
+
import { RUNNER_LOOPS, runnerCloseBoundMs } from "./runner.js";
|
|
6
6
|
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
7
7
|
export const DRAIN_TIMEOUT = "30s";
|
|
8
8
|
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
@@ -107,14 +107,11 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
107
107
|
// are said in its name as the runner subcommand says them (main.ts troubleLine: a lost claim on stdout, an error on
|
|
108
108
|
// stderr), so a lapse of its claims shows its cause.
|
|
109
109
|
const { runLine } = await import("../print.js");
|
|
110
|
+
const { metricLine, startRunnerGauge } = await import("./runner-metrics.js");
|
|
110
111
|
const name = runnerName();
|
|
111
112
|
const said = (event) => {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
return void (onLine ?? (event.type === "error" ? console.error : console.log))(trouble);
|
|
115
|
-
const line = runLine(event);
|
|
116
|
-
if (line)
|
|
117
|
-
(onLine ?? console.log)(line);
|
|
113
|
+
for (const { line, error } of besideLines(name, event, { metricLine, troubleLine, runLine }))
|
|
114
|
+
(onLine ?? (error ? console.error : console.log))(line);
|
|
118
115
|
// The server's anonymous counts (telemetry.ts) hear a run's end: its state alone, never which run or agent.
|
|
119
116
|
if (event.type === "ended")
|
|
120
117
|
onRunEnded?.(event.status);
|
|
@@ -130,7 +127,29 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
130
127
|
// Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
|
|
131
128
|
const { claimInstallsStopped } = await import("../harness-install.js");
|
|
132
129
|
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
133
|
-
|
|
130
|
+
// Its gauge (runner-metrics.ts): the runs it holds of its loops, and the process's memory (the server's with it), every
|
|
131
|
+
// minute until its close.
|
|
132
|
+
const gauge = startRunnerGauge({ runner: name, held: () => runner.held().length, slots: held ?? RUNNER_LOOPS, write: (line) => (onLine ?? console.log)(line) });
|
|
133
|
+
return { runner, close: async () => { gauge.stop(); await Promise.all([swept?.close(), runner.close()]); await claimInstallsStopped(); await store.close(); seal.release(); } };
|
|
134
|
+
}
|
|
135
|
+
/** The lines runner `name` beside a server says for `event`, in order, each with whether it goes to stderr (`error`): its
|
|
136
|
+
* metric line (runner-metrics.ts metricLine: a claim, a hand-back by cause, a lost claim, the drain), then its trouble
|
|
137
|
+
* (main.ts troubleLine: a lost claim, an error) or else its run's start or end (print.ts runLine). A lost claim says
|
|
138
|
+
* both its metric and its trouble. The three are handed in, as runnerBeside imports them on its start. */
|
|
139
|
+
export function besideLines(name, event, say) {
|
|
140
|
+
const lines = [];
|
|
141
|
+
const metric = say.metricLine(name, event);
|
|
142
|
+
if (metric)
|
|
143
|
+
lines.push({ line: metric, error: false });
|
|
144
|
+
const trouble = say.troubleLine(name, event);
|
|
145
|
+
if (trouble)
|
|
146
|
+
lines.push({ line: trouble, error: event.type === "error" });
|
|
147
|
+
else {
|
|
148
|
+
const line = say.runLine(event);
|
|
149
|
+
if (line)
|
|
150
|
+
lines.push({ line, error: false });
|
|
151
|
+
}
|
|
152
|
+
return lines;
|
|
134
153
|
}
|
|
135
154
|
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
136
155
|
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
@@ -6,6 +6,7 @@ import type { Revision } from "../agent-rows.js";
|
|
|
6
6
|
import type { HeldRedact } from "./redact.js";
|
|
7
7
|
import { type HeldModelKey } from "../run-model-key.js";
|
|
8
8
|
import { type RunModelKey } from "../store/seal.js";
|
|
9
|
+
import { type Claim } from "../store/store.js";
|
|
9
10
|
/** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
|
|
10
11
|
* environment (its own, with no server secret in it: those are the store's). */
|
|
11
12
|
export interface ClaimSecretsDeps {
|
|
@@ -109,7 +110,7 @@ export declare function claimSpendOff(deps: ClaimSecretsDeps, runKey: ClaimModel
|
|
|
109
110
|
/** The env a claimed run's model routes read: the run's own key alone where the claim opened one (withRunModelKey); else
|
|
110
111
|
* the runner's environment with the keys `opened` for it (withModelKeys), whose gateway variables read the run's key
|
|
111
112
|
* once a message hands it one (withRunModelKeyLater). */
|
|
112
|
-
export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: NodeJS.ProcessEnv, runKey: ClaimModelKey | undefined): NodeJS.ProcessEnv;
|
|
113
|
+
export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: NodeJS.ProcessEnv, runKey: ClaimModelKey | undefined, claim?: Pick<Claim, "runId" | "turn" | "attempt">): NodeJS.ProcessEnv;
|
|
113
114
|
/** `toolEnv` with no model key in it, for a run that holds its own: a tool's environment never carries a model key the
|
|
114
115
|
* run's model routes do not send. The decision providers' keys stay (DECISION_KEY_NAMES): a keyed workflow's judge,
|
|
115
116
|
* pick, sift, route and ask nodes run on them as any run's do. */
|
|
@@ -18,6 +18,7 @@ import { savedGatewayIn } from "../model-gateway.js";
|
|
|
18
18
|
import { noServerKeyWords, runKeyEndedFor, runModelOrigin, withRunModelKey, withRunModelKeyLater } from "../run-model-key.js";
|
|
19
19
|
import { openRunLaunch } from "../store/seal.js";
|
|
20
20
|
import { StoreLaunchMissing } from "../store/store.js";
|
|
21
|
+
import { withRequestMetadata } from "../request-metadata.js";
|
|
21
22
|
/** Every server secret a run might be handed (runs.ts RUN_SECRETS is the tool and model keys; the decision keys go beside
|
|
22
23
|
* them). Read from the store into a working environment, then scoped to the run below. */
|
|
23
24
|
const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
|
|
@@ -285,10 +286,11 @@ export async function claimSpendOff(deps, runKey) {
|
|
|
285
286
|
/** The env a claimed run's model routes read: the run's own key alone where the claim opened one (withRunModelKey); else
|
|
286
287
|
* the runner's environment with the keys `opened` for it (withModelKeys), whose gateway variables read the run's key
|
|
287
288
|
* once a message hands it one (withRunModelKeyLater). */
|
|
288
|
-
export function claimModelEnv(env, opened, runKey) {
|
|
289
|
+
export function claimModelEnv(env, opened, runKey, claim) {
|
|
290
|
+
// The claim's run, turn and attempt, which each request on serve's gateway names (request-metadata.ts).
|
|
289
291
|
if (!runKey)
|
|
290
|
-
return withModelKeys(env, opened);
|
|
291
|
-
return keyedAtClaim(runKey) ? withRunModelKey(env, runKey) : withRunModelKeyLater(withModelKeys(env, opened), runKey);
|
|
292
|
+
return withRequestMetadata(withModelKeys(env, opened), claim);
|
|
293
|
+
return withRequestMetadata(keyedAtClaim(runKey) ? withRunModelKey(env, runKey) : withRunModelKeyLater(withModelKeys(env, opened), runKey), claim);
|
|
292
294
|
}
|
|
293
295
|
/** The decision providers' own keys (decisions.ts: Jev's TypeSafe key, OpenRouter's, Parallel's): some are also pi-ai
|
|
294
296
|
* provider names, but a run's model key never replaces them, so withoutModelKeys keeps them. */
|
|
@@ -51,7 +51,7 @@ export declare function cliCapModel(entry: HarnessEntry & {
|
|
|
51
51
|
* run whose plane resolves it to native gets the harness's own search (#2458), this run's alone; whatever the runner's
|
|
52
52
|
* own environment says of a plane is never the run's. Whether each search runs is the tool's setting at that search
|
|
53
53
|
* (SessionIO.permission, the gate), never this plane, which is frozen when the run is made. */
|
|
54
|
-
export declare function cliRunEnv(env: NodeJS.ProcessEnv | undefined, data: string, claimed?: NodeJS.ProcessEnv, plane?: RunLaunch["plane"], runKey?: ClaimModelKey): NodeJS.ProcessEnv;
|
|
54
|
+
export declare function cliRunEnv(env: NodeJS.ProcessEnv | undefined, data: string, claimed?: NodeJS.ProcessEnv, plane?: RunLaunch["plane"], runKey?: ClaimModelKey, claim?: Pick<Claim, "runId" | "turn" | "attempt">): NodeJS.ProcessEnv;
|
|
55
55
|
/** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
|
|
56
56
|
* name), as main listed a CLI run's tools to its harness: each granted tool where its grant is, and a tool the grant
|
|
57
57
|
* does not name (one a granted tool or the run's computer brings beside it) right after the tool listed before it. Ties
|