@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.44
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 +105 -0
- package/README.md +213 -24
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.js +1 -1
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +8 -4
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +17 -1
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +28 -9
- package/dist/learning-cost.d.ts +100 -0
- package/dist/learning-cost.js +116 -1
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +17 -0
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +115 -39
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +6 -0
- package/dist/runner/adapter-loop.js +9 -2
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +70 -23
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +4 -0
- package/dist/runner/audit.js +15 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +5 -2
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +32 -13
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +7 -3
- package/dist/runner/harness-loops.js +30 -8
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learning-end.d.ts +3 -0
- package/dist/runner/learning-end.js +4 -0
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +24 -7
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +5 -0
- package/dist/runner/promotion.js +46 -7
- package/dist/runner/reflect-hook.d.ts +4 -0
- package/dist/runner/reflect-hook.js +22 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +457 -120
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +118 -16
- package/dist/store/store.d.ts +38 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +41 -2
- package/dist/store-reads/learning.js +158 -5
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -11
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/package.json +10 -9
- package/dist/console/assets/index-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.js +0 -711
|
@@ -8,14 +8,17 @@ import { nativeOf } from "../native/binding.js";
|
|
|
8
8
|
// - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
|
|
9
9
|
// harness is pi), so the revision is read here to tell it from an agentic pi run;
|
|
10
10
|
// - a built-in learning run (its launch names harness "learning") runs on the learning loop;
|
|
11
|
-
// - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch)
|
|
11
|
+
// - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch), and so does a harness a
|
|
12
|
+
// module adds with no adapter facts of its own, on its runner's adapter;
|
|
12
13
|
// - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
|
|
13
14
|
// - anything else fails the run in words (the dispatch's UnknownHarness).
|
|
15
|
+
import { harnessOf } from "../harness-table.js";
|
|
14
16
|
import { hostMemory, neverFits } from "../host.js";
|
|
15
17
|
import { resolveHarness } from "./adapters/index.js";
|
|
16
18
|
import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
|
|
17
19
|
import { createAdapterLoop } from "./adapter-loop.js";
|
|
18
20
|
import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
|
|
21
|
+
import { noServerKeyFor } from "../run-model-key.js";
|
|
19
22
|
import { createDispatchLoop } from "./dispatch.js";
|
|
20
23
|
import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
|
|
21
24
|
import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
|
|
@@ -45,7 +48,14 @@ export function resolveRunnerLoop(deps) {
|
|
|
45
48
|
if (harness !== "learning" && launch.sdk)
|
|
46
49
|
return createSdkLoop(launch, deps, async () => {
|
|
47
50
|
const base = deps.env ?? process.env;
|
|
51
|
+
// An SDK run's look-back runs after its backend reported it complete, on no run's key: on a server that holds no
|
|
52
|
+
// gateway key it is skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
48
53
|
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
54
|
+
const off = noServerKeyFor(env, "An SDK run's look-back");
|
|
55
|
+
if (off) {
|
|
56
|
+
deps.log?.(off);
|
|
57
|
+
throw new Error(off);
|
|
58
|
+
}
|
|
49
59
|
return gradeRouteFor({ model: launch.learning.gradeModel, agentId: run.agentId }, env, deps.routeOf);
|
|
50
60
|
});
|
|
51
61
|
if (harness !== "learning" && launch.native)
|
|
@@ -70,32 +80,44 @@ export function resolveRunnerLoop(deps) {
|
|
|
70
80
|
// at each grade, so a key saved with no restart grades the next learning run.
|
|
71
81
|
routeOf: async (grade) => {
|
|
72
82
|
const base = deps.env ?? process.env;
|
|
83
|
+
// A learning run grades after its source run's turn ended, on no run's key (a run that brought its own queues no
|
|
84
|
+
// grade: learning-end.ts spendOff): on a server that holds no gateway key it is skipped in words
|
|
85
|
+
// (run-model-key.ts noServerKeyFor). Nothing is sent; the learning run ends dropped.
|
|
73
86
|
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
87
|
+
const off = noServerKeyFor(env, "A learning run's grade");
|
|
88
|
+
if (off) {
|
|
89
|
+
deps.log?.(off);
|
|
90
|
+
throw new Error(off);
|
|
91
|
+
}
|
|
74
92
|
return gradeRouteFor(grade, env, deps.routeOf);
|
|
75
93
|
},
|
|
76
94
|
...(deps.log ? { log: deps.log } : {}),
|
|
77
95
|
...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
|
|
78
96
|
});
|
|
79
97
|
}
|
|
80
|
-
// The harness's own entry decides which spec builds the run, by the entry
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
|
|
98
|
+
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
99
|
+
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
100
|
+
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
101
|
+
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
102
|
+
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
103
|
+
const env = deps.env ?? process.env;
|
|
104
|
+
const runner = resolveHarness(harness, env);
|
|
84
105
|
if (runner) {
|
|
85
106
|
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
86
107
|
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
87
108
|
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
88
109
|
// the host's memory and its OOM kill would take every run on it.
|
|
89
|
-
const tooBig = neverFits(harness, hostMemory());
|
|
110
|
+
const tooBig = neverFits(harness, hostMemory(), env);
|
|
90
111
|
if (tooBig)
|
|
91
112
|
throw new NeverFits(tooBig);
|
|
113
|
+
const entry = harnessOf(env, harness);
|
|
92
114
|
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
93
115
|
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
94
116
|
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
95
117
|
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
96
|
-
return createAdapterLoop((claim, adapterRun) =>
|
|
118
|
+
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
97
119
|
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
98
|
-
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim), deps.modelRetry ?? {});
|
|
120
|
+
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
99
121
|
}
|
|
100
122
|
return undefined;
|
|
101
123
|
};
|
|
@@ -240,6 +240,11 @@ export interface MessageData {
|
|
|
240
240
|
* answer's output tokens when known. The loop reads it as pi's stopReason (loop.ts cutLast). */
|
|
241
241
|
readonly stopReason?: "length";
|
|
242
242
|
readonly outputTokens?: number;
|
|
243
|
+
/** The limit it was cut at was the run's cap's (turn_end's capCut): the cap, and the least cap that finishes it. */
|
|
244
|
+
readonly capCut?: {
|
|
245
|
+
readonly capUsd: number;
|
|
246
|
+
readonly raiseToUsd: number;
|
|
247
|
+
};
|
|
243
248
|
/** When it was written (ms, the loop's clock): the Timeline dates the message's row by it. */
|
|
244
249
|
readonly at?: number;
|
|
245
250
|
}
|
|
@@ -35,6 +35,9 @@ export interface LearningEndDeps {
|
|
|
35
35
|
} | undefined>;
|
|
36
36
|
/** The runner's log: what the compile turn left out for holding a secret, by name and count, never a value. */
|
|
37
37
|
readonly log?: (line: string) => void;
|
|
38
|
+
/** Why model spend beside the run is skipped (claim-secrets.ts claimSpendOff): its learning run's grade, which runs after
|
|
39
|
+
* the run's turn ended, is not queued then, in these words. Absent: it is queued. */
|
|
40
|
+
readonly spendOff?: (what: string) => string | undefined;
|
|
38
41
|
}
|
|
39
42
|
/** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
|
|
40
43
|
* does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
|
|
@@ -71,8 +71,12 @@ export function learningEndOfRun(launch, deps) {
|
|
|
71
71
|
const env = deps.env ?? process.env;
|
|
72
72
|
// The grade model the server named at the run's start (its learning start's), none: the agent's own grades it.
|
|
73
73
|
const gradeModel = start.gradeModel;
|
|
74
|
+
// The learning run's grade runs after the run's turn ended: never on a run's own key (erased with that end), and never
|
|
75
|
+
// on none.
|
|
76
|
+
const gradeOff = deps.spendOff ? () => deps.spendOff?.("The learning run's grade") : undefined;
|
|
74
77
|
const hookFor = (runId, round, before) => createReflectHook({
|
|
75
78
|
round,
|
|
79
|
+
...(gradeOff ? { gradeOff } : {}),
|
|
76
80
|
...(before ? { before } : {}),
|
|
77
81
|
// reflectSkip's facts: a run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be
|
|
78
82
|
// kept within it. The cap is the run's now (capNowOf: its newest raise's, else its launch's), the one its requests
|
|
@@ -4,6 +4,12 @@ export type { AlsoRow, Claim, Command, Journal };
|
|
|
4
4
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
5
5
|
* answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
|
|
6
6
|
export declare const cutAtLimit: (tokens?: number) => string;
|
|
7
|
+
/** Why a run ends failed when the answer it would end on was cut at the output its cap limited it to (a CLI's turn_end
|
|
8
|
+
* capCut): the cap stopped it, not the model, so the words name the cap and the least cap that lets it finish. */
|
|
9
|
+
export declare const cutByCap: (cut: {
|
|
10
|
+
capUsd: number;
|
|
11
|
+
raiseToUsd: number;
|
|
12
|
+
}, tokens?: number) => string;
|
|
7
13
|
/** What the step keeps with its end-of-run turn as the turn is first asked (EndOfRunTurn ask's `keep`): written with the
|
|
8
14
|
* turn's prompt, durable before the turn's first request leaves. */
|
|
9
15
|
export type EndOfRunKept = Readonly<Record<string, string | number | boolean | null>>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// The contract between a runner and the loop that runs one claimed run (design: "Runners carry many loops"). The runner
|
|
2
2
|
// claims, renews, delivers command rows and releases; the loop runs the harness on the run's journal. B2's loop.ts
|
|
3
3
|
// implements `Loop` for pi and the CLI adapters; the runner knows nothing about harnesses.
|
|
4
|
+
import { money } from "@parcha/agentrun-kernel/kernel/cap";
|
|
4
5
|
import { refusedText } from "../refusal-words.js";
|
|
5
6
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
6
7
|
* answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
|
|
7
8
|
export const cutAtLimit = (tokens) => `the model stopped at its output limit${tokens !== undefined && Number.isSafeInteger(tokens) && tokens > 0 ? ` (${tokens} tokens)` : ""} before finishing its answer`;
|
|
9
|
+
/** Why a run ends failed when the answer it would end on was cut at the output its cap limited it to (a CLI's turn_end
|
|
10
|
+
* capCut): the cap stopped it, not the model, so the words name the cap and the least cap that lets it finish. */
|
|
11
|
+
export const cutByCap = (cut, tokens) => `the run's ${money(cut.capUsd)} cap stopped the model${tokens !== undefined && Number.isSafeInteger(tokens) && tokens > 0 ? ` at ${tokens} tokens` : ""} before it finished its answer: raise the cap to at least $${cut.raiseToUsd.toFixed(2)} to let it finish`;
|
|
8
12
|
/** A claim its spec builder refuses before anything of the run runs (a handed sign-in that won't read back, an MCP pin
|
|
9
13
|
* that can't be made): the loop ends the run failed in these words, with nothing sent. Its message names no secret. */
|
|
10
14
|
export class ClaimRefused extends Error {
|
package/dist/runner/loop.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
2
|
import { KINDS } from "./journal-kinds.js";
|
|
3
|
-
import { cutAtLimit } from "./loop-contract.js";
|
|
3
|
+
import { cutAtLimit, cutByCap } from "./loop-contract.js";
|
|
4
4
|
import { PI_STOP } from "./pi-stop.js";
|
|
5
5
|
/** pi's own default restart limit (pi-durable 1.5.0 agent settings). */
|
|
6
6
|
export const DEFAULT_RESTART_LIMIT = 5;
|
|
@@ -193,7 +193,11 @@ export function cutLast(entries) {
|
|
|
193
193
|
const last = [...entries].reverse().find((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
|
|
194
194
|
if (last?.kind === KINDS.message) {
|
|
195
195
|
const said = last.data;
|
|
196
|
-
|
|
196
|
+
if (said.stopReason !== "length")
|
|
197
|
+
return undefined;
|
|
198
|
+
// Cut at the output the run's cap limited it to: the cap's cut, named with the cap that lets it finish.
|
|
199
|
+
const { capUsd, raiseToUsd } = said.capCut ?? {};
|
|
200
|
+
return typeof capUsd === "number" && Number.isFinite(capUsd) && typeof raiseToUsd === "number" && Number.isFinite(raiseToUsd) ? cutByCap({ capUsd, raiseToUsd }, said.outputTokens) : cutAtLimit(said.outputTokens);
|
|
197
201
|
}
|
|
198
202
|
const message = last?.model?.[0];
|
|
199
203
|
return message?.stopReason === PI_STOP.length ? cutAtLimit(message.usage?.output) : undefined;
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -149,6 +149,7 @@ export declare function runnerArgs(argv: readonly string[]): {
|
|
|
149
149
|
name?: string;
|
|
150
150
|
faux?: string;
|
|
151
151
|
check?: true;
|
|
152
|
+
harnessModules?: string[];
|
|
152
153
|
};
|
|
153
154
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
154
155
|
* says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
|
package/dist/runner/main.js
CHANGED
|
@@ -19,7 +19,7 @@ import { dockerPathsForRuns } from "../box-paths.js";
|
|
|
19
19
|
import { hostCommandRefusals } from "../computers.js";
|
|
20
20
|
import { hostAddressesOnce } from "../docker-host-addresses.js";
|
|
21
21
|
import { claimInstallsStopped } from "../harness-install.js";
|
|
22
|
-
import { HARNESS_TABLE_ENV } from "../harness-table.js";
|
|
22
|
+
import { HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessModulesEnv, harnessModulesOf, harnessTable } from "../harness-table.js";
|
|
23
23
|
import { DEFAULT_PORT, maxRunsOf } from "../host.js";
|
|
24
24
|
import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
25
25
|
import { durationMs, runLine } from "../print.js";
|
|
@@ -111,7 +111,7 @@ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runner
|
|
|
111
111
|
export function besideRunEnv(env, switches) {
|
|
112
112
|
const out = runEnv(env);
|
|
113
113
|
for (const name of Object.keys(out))
|
|
114
|
-
if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV)
|
|
114
|
+
if (name.startsWith(FAUX_PREFIX) || name === HARNESS_TABLE_ENV || name === HARNESS_MODULES_ENV)
|
|
115
115
|
delete out[name];
|
|
116
116
|
return Object.assign(out, switches);
|
|
117
117
|
}
|
|
@@ -205,7 +205,7 @@ export async function startRunnerProcess(options) {
|
|
|
205
205
|
const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
|
|
206
206
|
const env = options.env ?? process.env;
|
|
207
207
|
const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
|
|
208
|
-
const memory = options.memory ?? runnerMemory(store);
|
|
208
|
+
const memory = options.memory ?? runnerMemory(store, undefined, env);
|
|
209
209
|
let runner;
|
|
210
210
|
let seal;
|
|
211
211
|
let janitor;
|
|
@@ -320,9 +320,10 @@ export function runnerArgs(argv) {
|
|
|
320
320
|
let name;
|
|
321
321
|
let faux;
|
|
322
322
|
let check = false;
|
|
323
|
+
const harnessModules = [];
|
|
323
324
|
for (let i = 0; i < argv.length; i++) {
|
|
324
325
|
const given = argv[i];
|
|
325
|
-
const equals = /^(--(?:data|loops|drain-timeout|name|faux))=(.*)$/s.exec(given);
|
|
326
|
+
const equals = /^(--(?:data|loops|drain-timeout|name|faux|harness-module))=(.*)$/s.exec(given);
|
|
326
327
|
const arg = equals ? equals[1] : given;
|
|
327
328
|
const value = () => {
|
|
328
329
|
const next = equals ? equals[2] : argv[++i];
|
|
@@ -348,14 +349,16 @@ export function runnerArgs(argv) {
|
|
|
348
349
|
name = value();
|
|
349
350
|
else if (arg === "--faux")
|
|
350
351
|
faux = value();
|
|
352
|
+
else if (arg === "--harness-module")
|
|
353
|
+
harnessModules.push(value());
|
|
351
354
|
else if (arg === "--check")
|
|
352
355
|
check = true;
|
|
353
356
|
else
|
|
354
|
-
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M], or --check --data D [--name N]`);
|
|
357
|
+
throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M] [--harness-module M ...], or --check --data D [--name N]`);
|
|
355
358
|
}
|
|
356
359
|
if (!dataDir)
|
|
357
360
|
throw new RunnerRefused("a runner needs its data directory: --data D");
|
|
358
|
-
return { dataDir, ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(check ? { check: true } : {}) };
|
|
361
|
+
return { dataDir, ...(harnessModules.length ? { harnessModules } : {}), ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(check ? { check: true } : {}) };
|
|
359
362
|
}
|
|
360
363
|
/** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
|
|
361
364
|
* says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
|
|
@@ -423,7 +426,21 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
423
426
|
// A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
|
|
424
427
|
// inherited (AGENTRUN_SERVE_FAUX*, the harness table, left in an operator's shell or a platform's settings) never loads
|
|
425
428
|
// a module or decides what a run answers. --faux sets the faux model's.
|
|
426
|
-
|
|
429
|
+
// The owner's harness modules are this start's too: --harness-module, else AGENTRUN_SERVE_HARNESS_MODULES, as the
|
|
430
|
+
// server reads them, so a runner apart from the server runs the harnesses its table adds. Each is loaded and checked
|
|
431
|
+
// here, as the server's start checks them (harness-table.ts harnessTable), before the runner opens the store or claims a
|
|
432
|
+
// run: a module that names a built-in, repeats an id, gives an id the API does not carry or lacks a member refuses the
|
|
433
|
+
// start in words naming the module and the id, never failing every run the runner would claim.
|
|
434
|
+
let modules;
|
|
435
|
+
try {
|
|
436
|
+
modules = harnessModulesEnv(harnessModulesOf(args.harnessModules, given), args.dataDir);
|
|
437
|
+
harnessTable(modules);
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
console.error(`agentrun-serve runner: ${error.message}`);
|
|
441
|
+
return 2;
|
|
442
|
+
}
|
|
443
|
+
const env = { ...withoutFaux(given), ...modules, ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
|
|
427
444
|
const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
|
|
428
445
|
if (args.check) {
|
|
429
446
|
if (!name) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Store } from "../store/store.js";
|
|
2
2
|
import type { RunnerMemory } from "./runner.js";
|
|
3
|
-
/** What a run launched on `harness` weighs: its
|
|
4
|
-
*
|
|
5
|
-
|
|
3
|
+
/** What a run launched on `harness` weighs: its entry's run size on the owner's table of `env` (harness-table.ts
|
|
4
|
+
* ownerHarness: a built-in's, or what a harness module declares; a test's stand-in weighs as the built-in it stands in
|
|
5
|
+
* for), or a pi run's for a run on no harness of that table (a learning run, which runs in the runner's own process as a
|
|
6
|
+
* pi run does). */
|
|
7
|
+
export declare function claimMibOf(harness: string, env?: NodeJS.ProcessEnv): number;
|
|
6
8
|
/** The runner's memory budget over `store`: `memory` bytes (default the host's, hostMemory) less the server's own, each
|
|
7
|
-
* waiting run weighed by the harness its launch names (store.runs.launch)
|
|
8
|
-
*
|
|
9
|
-
|
|
9
|
+
* waiting run weighed by the harness its launch names (store.runs.launch) on the owner's table of `env` (the runner's run
|
|
10
|
+
* environment, which names its harness modules). A run whose launch cannot be read weighs a pi run: its claim fails it at
|
|
11
|
+
* once (dispatch.ts), holding nothing for long. */
|
|
12
|
+
export declare function runnerMemory(store: Pick<Store, "runs">, memory?: number, env?: NodeJS.ProcessEnv): RunnerMemory;
|
|
@@ -4,22 +4,25 @@
|
|
|
4
4
|
// (--max-runs, by default as many pi runs as fit) would let a 2 GB host take 15 claude-agent runs, about 3.2 GB as
|
|
5
5
|
// measured, and the host's OOM kill would take every run on it; by weight it holds 6 and the rest wait queued.
|
|
6
6
|
import { DEFAULT_HARNESS, harnessOfBody } from "../harness.js";
|
|
7
|
-
import { builtinHarness } from "../harness-table.js";
|
|
7
|
+
import { builtinHarness, ownerHarness } from "../harness-table.js";
|
|
8
8
|
import { hostMemory, runsMemoryMib } from "../host.js";
|
|
9
|
-
/** What a run launched on `harness` weighs: its
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/** What a run launched on `harness` weighs: its entry's run size on the owner's table of `env` (harness-table.ts
|
|
10
|
+
* ownerHarness: a built-in's, or what a harness module declares; a test's stand-in weighs as the built-in it stands in
|
|
11
|
+
* for), or a pi run's for a run on no harness of that table (a learning run, which runs in the runner's own process as a
|
|
12
|
+
* pi run does). */
|
|
13
|
+
export function claimMibOf(harness, env = {}) {
|
|
14
|
+
return (ownerHarness(env, harness) ?? builtinHarness(DEFAULT_HARNESS)).runMib;
|
|
13
15
|
}
|
|
14
16
|
/** The runner's memory budget over `store`: `memory` bytes (default the host's, hostMemory) less the server's own, each
|
|
15
|
-
* waiting run weighed by the harness its launch names (store.runs.launch)
|
|
16
|
-
*
|
|
17
|
-
|
|
17
|
+
* waiting run weighed by the harness its launch names (store.runs.launch) on the owner's table of `env` (the runner's run
|
|
18
|
+
* environment, which names its harness modules). A run whose launch cannot be read weighs a pi run: its claim fails it at
|
|
19
|
+
* once (dispatch.ts), holding nothing for long. */
|
|
20
|
+
export function runnerMemory(store, memory = hostMemory(), env = {}) {
|
|
18
21
|
return {
|
|
19
22
|
budgetMib: runsMemoryMib(memory),
|
|
20
23
|
weigh: async (runIds) => new Map(await Promise.all(runIds.map(async (runId) => {
|
|
21
24
|
const harness = await store.runs.launch(runId).then((row) => harnessOfBody((row.body ?? {})), () => DEFAULT_HARNESS);
|
|
22
|
-
return [runId, claimMibOf(harness)];
|
|
25
|
+
return [runId, claimMibOf(harness, env)];
|
|
23
26
|
}))),
|
|
24
27
|
};
|
|
25
28
|
}
|
|
@@ -16,6 +16,9 @@ export declare const REPLAY_DEADLINE_MS: number;
|
|
|
16
16
|
export declare const REPLAY_LAUNCH_GRACE_MS: number;
|
|
17
17
|
export interface PromotionDeps {
|
|
18
18
|
readonly store: Store;
|
|
19
|
+
/** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff): a replay check starts runs with
|
|
20
|
+
* no caller's key. Absent: it runs. */
|
|
21
|
+
readonly spendOff?: (what: string) => string | undefined;
|
|
19
22
|
readonly agentId: string;
|
|
20
23
|
/** The run being claimed: never one of its own check's inputs. Absent: no run is claimed (a person's replay, and its
|
|
21
24
|
* read): no run served first to keep, none whose per_run MCP credentials a replay is handed. */
|
|
@@ -78,6 +81,8 @@ export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentI
|
|
|
78
81
|
* laid text when it is the champion, its own text read from its record's commit when not; undefined when none serves
|
|
79
82
|
* (the agent takes the run). A digest's own record never says it serves. */
|
|
80
83
|
export declare const promotionGate: (deps: PromotionDeps) => Promoted;
|
|
84
|
+
/** The words a hold of a serving revision this release's workflow DSL refuses starts with (holdRefused). */
|
|
85
|
+
export declare const DSL_REFUSES = "this release's workflow DSL refuses it";
|
|
81
86
|
/** The words a stopped check's record starts with when it had nothing to check its draft on. */
|
|
82
87
|
export declare const NOTHING_TO_CHECK = "nothing to check it on";
|
|
83
88
|
/** One input a check ran its draft on: the agent's run (`of`) and its input, the agent's recorded answer, and what the
|
package/dist/runner/promotion.js
CHANGED
|
@@ -15,6 +15,7 @@ import { ClaimRefused } from "./loop-contract.js";
|
|
|
15
15
|
import { readSnapshot } from "../learn/folder.js";
|
|
16
16
|
import { fits, laidFor, servedOf, workflowDigest } from "./workflow-first.js";
|
|
17
17
|
import { excerptShown } from "../learn/secrets.js";
|
|
18
|
+
import { dslRefusalOf } from "../learn/skills.js";
|
|
18
19
|
import { workflowsAt } from "./learning-seed.js";
|
|
19
20
|
/** A replay run still not ended this long after its replay started counts as failed (no evidence), and is cancelled once
|
|
20
21
|
* the replay is decided without it. */
|
|
@@ -134,7 +135,7 @@ export const promotionGate = (deps) => {
|
|
|
134
135
|
if (kept)
|
|
135
136
|
return { workflow: kept };
|
|
136
137
|
await decide(deps, workflow, digest);
|
|
137
|
-
return await servingNow(deps, workflow, digest, true);
|
|
138
|
+
return await holdRefused(deps, await servingNow(deps, workflow, digest, true));
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
141
|
return failed(workflow, error);
|
|
@@ -144,7 +145,7 @@ export const promotionGate = (deps) => {
|
|
|
144
145
|
const champion = async (workflow, digest) => {
|
|
145
146
|
try {
|
|
146
147
|
const kept = await keptFor(deps, workflow, digest);
|
|
147
|
-
return kept ? { workflow: kept } : await servingNow(deps, workflow, digest, false);
|
|
148
|
+
return kept ? { workflow: kept } : await holdRefused(deps, await servingNow(deps, workflow, digest, false));
|
|
148
149
|
}
|
|
149
150
|
catch (error) {
|
|
150
151
|
return failed(workflow, error);
|
|
@@ -178,6 +179,35 @@ async function servingNow(deps, workflow, digest, laid) {
|
|
|
178
179
|
deps.log(`workflow-first: ${workflow.name}'s champion at ${champion.digest} serves this run while ${digest} ${own?.decided === "promote" ? "is a revision promoted before it" : "is not promoted"}`);
|
|
179
180
|
return { workflow: text };
|
|
180
181
|
}
|
|
182
|
+
/** The words a hold of a serving revision this release's workflow DSL refuses starts with (holdRefused). */
|
|
183
|
+
export const DSL_REFUSES = "this release's workflow DSL refuses it";
|
|
184
|
+
/** `serving` as it serves this run, once a serving revision this release's workflow DSL refuses is held. The refusal is of
|
|
185
|
+
* the text alone (learn/skills.ts dslRefusalOf: the DSL's own validation, no tool list), never of a host setting (a tool
|
|
186
|
+
* gated, denied or missing, no adapter), which the run's own check still refuses as before. The hold is a promotion
|
|
187
|
+
* record of its digest, `hold` by its reason alone ("this release's workflow DSL refuses it: <code> at <path>: <its
|
|
188
|
+
* words>", cut of the host's secrets as a check's texts are), written only while the digest's newest record is still the
|
|
189
|
+
* promotion this claim read: of two claims at once one writes it, and a later claim finds it (nothing serves). The run
|
|
190
|
+
* still runs it, refused before any node runs, and hands back as before: the agent answers. The hold follows compile
|
|
191
|
+
* once as a check's does: the agent's next due run asks the one recompile with the reason as data (learn/compile.ts
|
|
192
|
+
* heldNamesOf), and that revision's check is the compile's second (attemptOf). */
|
|
193
|
+
async function holdRefused(deps, serving) {
|
|
194
|
+
if (!serving)
|
|
195
|
+
return serving;
|
|
196
|
+
const refused = dslRefusalOf(await import("@parcha/agentrun-dsl"), serving.workflow.workflow);
|
|
197
|
+
if (refused === undefined)
|
|
198
|
+
return serving;
|
|
199
|
+
const { name } = serving.workflow;
|
|
200
|
+
const digest = workflowDigest(serving.workflow);
|
|
201
|
+
const current = promotionOf(await promotionsOf(deps.store.settings, deps.agentId), name, digest);
|
|
202
|
+
if (current?.decided !== "promote")
|
|
203
|
+
return serving;
|
|
204
|
+
const reason = excerptShown(`${DSL_REFUSES}: ${refused}`, await deps.shown(), CHECK_TEXT_MAX);
|
|
205
|
+
const record = { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, ...(current.commit ? { commit: current.commit } : {}) };
|
|
206
|
+
const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
|
|
207
|
+
if (kept.won)
|
|
208
|
+
deps.log(`workflow-first: ${name} at ${digest} is held: ${reason}; the agent's next run recompiles it once`);
|
|
209
|
+
return serving;
|
|
210
|
+
}
|
|
181
211
|
/** A run already executing keeps its revision: when an earlier claim of it served `workflow` first (its WORKFLOW_FIRST
|
|
182
212
|
* entry, answered or handed back: `deps.kept`), a re-claim serves the same digest, whoever the champion is now (the loop
|
|
183
213
|
* recovers that outcome as it is, never runs it again). The laid text at that digest, else its text at its record's
|
|
@@ -230,17 +260,19 @@ async function loopOfRevision(deps) {
|
|
|
230
260
|
}
|
|
231
261
|
}
|
|
232
262
|
/** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
|
|
233
|
-
* check's hold
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* compile's recompile too. */
|
|
263
|
+
* check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
|
|
264
|
+
* first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
|
|
265
|
+
* (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first revision after a first compile
|
|
266
|
+
* whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
|
|
237
267
|
function attemptOf(records, name, digest) {
|
|
238
268
|
const before = records.findLast((one) => one.workflow === name && one.digest !== digest);
|
|
239
269
|
if (!before)
|
|
240
270
|
return newCompileAttempt(records.filter((one) => one.digest !== digest));
|
|
241
271
|
if (before.decided !== "hold")
|
|
242
272
|
return 1;
|
|
243
|
-
|
|
273
|
+
if (before.audit)
|
|
274
|
+
return before.audit.stopped ? 1 : 2;
|
|
275
|
+
return !before.check || (before.check.attempt === 1 && !before.check.stopped) ? 2 : 1;
|
|
244
276
|
}
|
|
245
277
|
/** The shadow runs a recompile's check runs on beside the agent's last runs: the disagreeing audit rows the workflow's
|
|
246
278
|
* newest audit hold names (a grade's row has no answer of the agent's to check against), when that hold is the
|
|
@@ -291,6 +323,11 @@ async function checkInputs(deps, workflow, pick, audited = []) {
|
|
|
291
323
|
* it fits), it is decided at once: never promoted, it stops with nothing checked (stopUnchecked). */
|
|
292
324
|
async function startCheck(deps, workflow, digest) {
|
|
293
325
|
const { store, agentId, log } = deps;
|
|
326
|
+
// Its replay runs are runs the runner starts, on no caller's key: skipped where the claimed run brought its own key or
|
|
327
|
+
// the server holds none (claimSpendOff).
|
|
328
|
+
const off = deps.spendOff?.("A learned workflow's replay check");
|
|
329
|
+
if (off)
|
|
330
|
+
return void log(`workflow-first: ${off} ${workflow.name} at ${digest} is not checked and does not serve this run`);
|
|
294
331
|
// Only the learning folder's newest revision is checked: a run pinned to an older commit lays an older text.
|
|
295
332
|
const newest = deps.newest ? await deps.newest(workflow.name) : undefined;
|
|
296
333
|
if (newest !== undefined && newest !== digest) {
|
|
@@ -578,6 +615,8 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
|
|
|
578
615
|
* this claim created. */
|
|
579
616
|
async function relaunch(deps, workflow, digest, record) {
|
|
580
617
|
const { store } = deps;
|
|
618
|
+
if (deps.spendOff?.("A replay"))
|
|
619
|
+
return 0;
|
|
581
620
|
const since = (deps.now ?? Date.now)() - Date.parse(record.at);
|
|
582
621
|
const launch = record.launch;
|
|
583
622
|
if (!launch || since <= REPLAY_LAUNCH_GRACE_MS || since > REPLAY_DEADLINE_MS)
|
|
@@ -38,6 +38,10 @@ export type Checked = {
|
|
|
38
38
|
};
|
|
39
39
|
/** What the hook reads of the run and the host. */
|
|
40
40
|
export interface ReflectDeps {
|
|
41
|
+
/** Why no grade is queued for what the run proposes, asked when it would be (a grade runs after the run's turn, with no
|
|
42
|
+
* key to spend: learning-end spendOff): its proposal is dropped `grade_failed` in these words, nothing spent. Absent, or
|
|
43
|
+
* undefined: a grade is queued. */
|
|
44
|
+
readonly gradeOff?: () => string | undefined;
|
|
41
45
|
/** Whether the run's job gave nothing new to look back on: its only tool work was its learned workflows, each of them
|
|
42
46
|
* answering, with no error, no refused call, no approval and nothing said after its first message. Such a run is not
|
|
43
47
|
* asked its end-of-run turn (no model request, nothing spent looking back), and its learning is dropped `empty` in
|
|
@@ -57,11 +57,19 @@ export function createReflectHook(deps) {
|
|
|
57
57
|
// its look-back's), unknown when any is.
|
|
58
58
|
const earlier = deps.before;
|
|
59
59
|
const followUp = () => (round === 1 ? {} : { follow_up_usd: job === null || typeof earlier?.job_cost_usd !== "number" || typeof earlier.look_back_usd !== "number" ? null : Math.max(0, Math.round((job - earlier.job_cost_usd - earlier.look_back_usd) * 1e9) / 1e9) });
|
|
60
|
+
/** Where the compile turn began, once one is asked: the run's spend as its first attempt was asked (an earlier claim's,
|
|
61
|
+
* kept with that ask, after a restart), unknown when unread; `alone` when the compile is the round's only ask (the
|
|
62
|
+
* whole look-back). Its turn's spend joins the revision it drafts (learning-cost.ts amortize), never the run's own. */
|
|
63
|
+
let compileFrom;
|
|
64
|
+
const cents = (usd) => Math.max(0, Math.round(usd * 1e9) / 1e9);
|
|
60
65
|
// closeLearning: what looking back cost, the run's spend once the turn closed (its re-ask included) less the job's,
|
|
61
|
-
// unknown when either is. Kept with every end the turn reaches from here, beside when the job answered and its cost
|
|
66
|
+
// unknown when either is. Kept with every end the turn reaches from here, beside when the job answered and its cost;
|
|
67
|
+
// with a compile asked, what of it the compile turn spent (`compile_usd`), from its first ask to the close.
|
|
62
68
|
const looked = async (rows) => {
|
|
63
69
|
const total = (await deps.facts(input.runId)).costUsd;
|
|
64
|
-
const
|
|
70
|
+
const lookBack = total === null || job === null ? null : cents(total - job);
|
|
71
|
+
const compileUsd = compileFrom === undefined ? {} : { compile_usd: compileFrom === "alone" ? lookBack : total === null || compileFrom.usd === null ? null : cents(total - compileFrom.usd) };
|
|
72
|
+
const answered = { answered_at: answeredAt, job_cost_usd: job, look_back_usd: lookBack, ...compileUsd, ...followUp() };
|
|
65
73
|
return { also: rows.also.map((row) => (row.table === "learning_proposals" ? { ...row, row: { ...row.row, proposal: { ...row.row.proposal, ...answered } } } : row)) };
|
|
66
74
|
};
|
|
67
75
|
// A run cut or skipped here asks nothing: its drop alone, or with looked's figures when its look-back had started.
|
|
@@ -195,14 +203,21 @@ export function createReflectHook(deps) {
|
|
|
195
203
|
let revised = compile.mode === "revise" && compile.base ? { workflow: compile.workflow, base: compile.base } : undefined;
|
|
196
204
|
/** An attempt the cap refused, or whose spend took the run past it: the learning is dropped as the look-back's is. */
|
|
197
205
|
let capped = false;
|
|
206
|
+
// Where the compile turn begins (the run's spend now), kept with each attempt as the job's figures are: a later claim
|
|
207
|
+
// answers with the earlier one's, so what it spent compiling stays the compile's.
|
|
208
|
+
compileFrom = alone ? "alone" : { usd: (await deps.facts(input.runId)).costUsd };
|
|
198
209
|
const result = await compileTurn({
|
|
199
210
|
ask: async (prompt, attempt, left) => {
|
|
200
|
-
const
|
|
211
|
+
const from = compileFrom !== "alone" && compileFrom !== undefined ? { compile_from_usd: compileFrom.usd } : {};
|
|
212
|
+
const keep = { ...(alone ? { answered_at: answeredAt, job_cost_usd: job } : {}), ...from, ...(revised ? { compile_base: revised.base } : {}) };
|
|
201
213
|
const said_ = await input.ask(prompt, { ...ask, deadlineMs: left, step: `compile-${attempt}`, ...(Object.keys(keep).length ? { keep } : {}) });
|
|
202
214
|
if ("failed" in said_ && CAP_REFUSAL.test(said_.failed.message))
|
|
203
215
|
capped = true;
|
|
204
216
|
if (alone)
|
|
205
217
|
firstAsk(said_.kept);
|
|
218
|
+
const keptFrom = said_.kept?.compile_from_usd;
|
|
219
|
+
if (!alone && (typeof keptFrom === "number" || keptFrom === null))
|
|
220
|
+
compileFrom = { usd: keptFrom };
|
|
206
221
|
const base = said_.kept?.compile_base;
|
|
207
222
|
if (revised && typeof base === "string")
|
|
208
223
|
revised = { ...revised, base };
|
|
@@ -253,6 +268,10 @@ export function createReflectHook(deps) {
|
|
|
253
268
|
// The learning run's cap: what the run's cap leaves now its look-back is spent, read after the checks. A spend under
|
|
254
269
|
// the cap that is unknown (or a read that fails, never no cap) queues no grade: none could be kept within the cap, and
|
|
255
270
|
// the words say the spend is unknown, never that the cap has no room (learning-end.ts capSpendOf's rule).
|
|
271
|
+
// Asked here, at the end: a key a message handed during the run counts as one the run brought.
|
|
272
|
+
const gradeOff = deps.gradeOff?.();
|
|
273
|
+
if (gradeOff)
|
|
274
|
+
return close([droppedRow(turn, "grade_failed", gradeOff, compiledFields)]);
|
|
256
275
|
const capUsd = deps.gradeCap ? await deps.gradeCap(input.runId).catch(() => null) : undefined;
|
|
257
276
|
if (capUsd === null)
|
|
258
277
|
return close([droppedRow(turn, "unknown_cost", said.gradeUnknownSpend)]);
|