@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.43
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 +21 -0
- package/README.md +8 -7
- package/dist/console/assets/index-BrcDSBD8.css +1 -0
- package/dist/console/assets/{index-DYJ_wj27.js → index-Bz6IWncl.js} +186 -186
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/import-sources.js +25 -5
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +86 -200
- package/dist/learn/promote.js +57 -183
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.js +2 -4
- package/dist/learn/workflow-nodes.d.ts +1 -2
- package/dist/learn/workflow-nodes.js +2 -3
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +11 -4
- package/dist/learning-cost.js +4 -2
- package/dist/learning-routes.js +1 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/openapi.js +95 -55
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +17 -2
- package/dist/runner/adapter-run-spec.js +16 -5
- package/dist/runner/audit.d.ts +64 -0
- package/dist/runner/audit.js +338 -0
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +15 -5
- package/dist/runner/feedback-round.js +1 -4
- package/dist/runner/harness-loops.js +1 -15
- package/dist/runner/journal-kinds.d.ts +0 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +52 -13
- package/dist/runner/learning-end.js +124 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/main.js +1 -1
- package/dist/runner/promotion.d.ts +50 -54
- package/dist/runner/promotion.js +191 -583
- package/dist/runner/reflect-hook.d.ts +10 -0
- package/dist/runner/reflect-hook.js +6 -0
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/server.js +61 -16
- package/dist/store/sqlite/store.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/learning.d.ts +17 -6
- package/dist/store-reads/learning.js +36 -23
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-view.js +12 -2
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +9 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { LearningProposal } from "../store/store.js";
|
|
2
|
-
import { type GeneralScores, type GeneralSource } from "../learn/general.js";
|
|
3
2
|
import { type IndexEntry, type NoteText, type Verdict } from "../learn/grade.js";
|
|
4
3
|
import type { LearnedFile, NoteLearned, Tokens } from "../learning.js";
|
|
5
4
|
import type { Journal, Loop, LoopDeps } from "./loop-contract.js";
|
|
@@ -66,14 +65,6 @@ export declare class GradeOverCap extends Error {
|
|
|
66
65
|
/** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
|
|
67
66
|
constructor(message: string, forGood: boolean, booked?: GradeBooked | undefined);
|
|
68
67
|
}
|
|
69
|
-
/** A generality check its learning run's cap refused before any of its requests left (learning-dispatch.ts general: its
|
|
70
|
-
* worst case over the cap left): nothing of it was sent or spent, and it is skipped as `unchecked` "no_budget"
|
|
71
|
-
* (GENERAL_NO_BUDGET), said so, the grader then judged against the cap on its own. `forGood`: no room could ever send it
|
|
72
|
-
* (its provider's price unknown here), not only none now. */
|
|
73
|
-
export declare class GeneralOverCap extends Error {
|
|
74
|
-
readonly forGood: boolean;
|
|
75
|
-
constructor(message: string, forGood: boolean);
|
|
76
|
-
}
|
|
77
68
|
/** The grade's own records after an ask (learning-ask.ts bookedAsk: its session's booking): what every grade request of
|
|
78
69
|
* the learning run spent, an earlier attempt's included (null: unknown, as a cut one's), and how many left. What the
|
|
79
70
|
* grade ends with is read from these, never summed in memory alone: a runner that restarted before the grade was saved
|
|
@@ -162,13 +153,10 @@ export interface LearningLoopDeps {
|
|
|
162
153
|
readMain(ws: unknown, proposal: KeptProposal): Promise<GradeMain | {
|
|
163
154
|
readonly problems: readonly Problem[];
|
|
164
155
|
}>;
|
|
165
|
-
/** One grader call, through the kernel's model proxy and the cap, booked to the agent's learning meter.
|
|
166
|
-
* the grade spent outside its records, at most (the generality check's dollars, else its worst case), which the cap's
|
|
167
|
-
* room for the call leaves out. */
|
|
156
|
+
/** One grader call, through the kernel's model proxy and the cap, booked to the agent's learning meter. */
|
|
168
157
|
ask(request: {
|
|
169
158
|
readonly prompt: string;
|
|
170
159
|
readonly maxTokens: number;
|
|
171
|
-
readonly beside?: number;
|
|
172
160
|
}, signal: AbortSignal, run: GraderRun): Promise<{
|
|
173
161
|
readonly text: unknown;
|
|
174
162
|
readonly usd: number | null;
|
|
@@ -188,30 +176,18 @@ export interface LearningLoopDeps {
|
|
|
188
176
|
} | undefined>;
|
|
189
177
|
/** The clock (epoch ms), for a parked run's wake. */
|
|
190
178
|
now?(): number;
|
|
191
|
-
/** The generality pre-check (learn/general.ts): each proposed note's Jev probability that it holds for inputs other
|
|
192
|
-
* than the one it came from, by file, and what it cost. Undefined, or one that answers undefined (no Jev key on this
|
|
193
|
-
* host), skips it: every note goes to the grader. One that throws (Jev down) skips it too: what it spent is unknown, and
|
|
194
|
-
* the skip is kept on the grade's entry (`unchecked`) and said in the log. `sending` is called once, before its first
|
|
195
|
-
* paid request leaves, with their worst case under a cap (`held`): the loop marks the check sent there, durably
|
|
196
|
-
* (journal-kinds.ts learningGeneralSent). Under a cap, `before` is what an earlier attempt's cut check may have spent
|
|
197
|
-
* (its worst case), which the room for this one leaves out; one that doesn't fit throws GeneralOverCap, sending nothing. */
|
|
198
|
-
general?(notes: readonly NoteText[], source: GeneralSource, signal: AbortSignal, run: string, sending?: (held?: number) => Promise<void>, before?: number): Promise<GeneralScores | undefined>;
|
|
199
|
-
/** The bar a note's score must reach to go on to the grader (default GENERAL_THRESHOLD). */
|
|
200
|
-
generalThreshold?: number;
|
|
201
179
|
/** One line of the runner's log. */
|
|
202
180
|
log?(line: string): void;
|
|
203
181
|
}
|
|
204
182
|
/** The journal's learning entries' data (journal-kinds.ts learningGraded, learningDropped, learningMerged), as the reader
|
|
205
183
|
* of a run's learning end reads them (store-reads/learning.ts). What a grade spent: its dollars and tokens, each null when
|
|
206
|
-
* any ask's are unknown.
|
|
207
|
-
* every note; the run's learning end says the check was skipped. */
|
|
184
|
+
* any ask's are unknown. */
|
|
208
185
|
export type GradedData = {
|
|
209
186
|
readonly source: string;
|
|
210
187
|
readonly verdict: Verdict;
|
|
211
188
|
readonly usd: number | null;
|
|
212
189
|
readonly tokens?: Tokens | null;
|
|
213
190
|
readonly graded: Readonly<Record<string, string>>;
|
|
214
|
-
readonly unchecked?: string;
|
|
215
191
|
};
|
|
216
192
|
export type DroppedData = {
|
|
217
193
|
readonly source: string;
|
|
@@ -220,7 +196,6 @@ export type DroppedData = {
|
|
|
220
196
|
readonly problems?: readonly Problem[];
|
|
221
197
|
readonly usd?: number | null;
|
|
222
198
|
readonly tokens?: Tokens | null;
|
|
223
|
-
readonly unchecked?: string;
|
|
224
199
|
};
|
|
225
200
|
/** `verdict`: each item's final decision once the merge settled it (takenOnMain's and the commit's left-out notes dropped,
|
|
226
201
|
* with their words), which the run's learning end reads in place of the grade's (store-reads/learning.ts). */
|
|
@@ -232,17 +207,6 @@ export type MergedData = {
|
|
|
232
207
|
readonly detail: string;
|
|
233
208
|
readonly verdict: Verdict;
|
|
234
209
|
};
|
|
235
|
-
/** The generality check's end (journal-kinds.ts learningGeneral): its scores, or why it could not run (GENERAL_NO_BUDGET:
|
|
236
|
-
* no room under the cap), and what it spent (null once unknown: a request that failed, or one an earlier attempt sent and
|
|
237
|
-
* a restart cut). `held`: under a cap, the most every attempt's requests may have spent (each sent mark's worst case), the
|
|
238
|
-
* bound the grader's room leaves out when `usd` is unknown. */
|
|
239
|
-
export type GeneralData = {
|
|
240
|
-
readonly source: string;
|
|
241
|
-
readonly scores?: Readonly<Record<string, number>>;
|
|
242
|
-
readonly unchecked?: string;
|
|
243
|
-
readonly usd: number | null;
|
|
244
|
-
readonly held?: number;
|
|
245
|
-
};
|
|
246
210
|
/** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
|
|
247
211
|
* and the rest of what the run learned merges. */
|
|
248
212
|
export declare const NOTE_NAME_TAKEN: (name: string) => string;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
// merge's call merges once.
|
|
14
14
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
15
15
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
16
|
-
import { GENERAL_NO_BUDGET, GENERAL_THRESHOLD, ONE_CASE } from "../learn/general.js";
|
|
17
16
|
import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
|
|
18
17
|
import { mergedNote, parseNoteFile, ruleOf } from "../learn/notes.js";
|
|
19
18
|
import { learnedPlace } from "../learn/skills.js";
|
|
@@ -41,18 +40,6 @@ export class GradeOverCap extends Error {
|
|
|
41
40
|
this.name = "GradeOverCap";
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
/** A generality check its learning run's cap refused before any of its requests left (learning-dispatch.ts general: its
|
|
45
|
-
* worst case over the cap left): nothing of it was sent or spent, and it is skipped as `unchecked` "no_budget"
|
|
46
|
-
* (GENERAL_NO_BUDGET), said so, the grader then judged against the cap on its own. `forGood`: no room could ever send it
|
|
47
|
-
* (its provider's price unknown here), not only none now. */
|
|
48
|
-
export class GeneralOverCap extends Error {
|
|
49
|
-
forGood;
|
|
50
|
-
constructor(message, forGood) {
|
|
51
|
-
super(message);
|
|
52
|
-
this.forGood = forGood;
|
|
53
|
-
this.name = "GeneralOverCap";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
43
|
const ROOT = ROOT_CONVERSATION_ID;
|
|
57
44
|
/** The graded item a proposal's file is judged as (grade.ts itemOf): a draft's README.md with its workflow.json, every
|
|
58
45
|
* other file as itself. */
|
|
@@ -352,106 +339,12 @@ export function createLearningLoop(learning) {
|
|
|
352
339
|
// added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
|
|
353
340
|
let usd = 0;
|
|
354
341
|
let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
|
|
355
|
-
// What the generality pre-check's Jev requests spent (its kept dollars, null once unknown), outside the
|
|
356
|
-
// grader's records, and the most they may have spent (`beside`: those dollars, else their worst case), which
|
|
357
|
-
// each grader call's room under the cap leaves out. The grade ends with both: Jev's and the grader's.
|
|
358
|
-
let checkUsd = 0;
|
|
359
|
-
let beside = 0;
|
|
360
|
-
const spent = () => (checkUsd === null || usd === null ? null : checkUsd + usd);
|
|
361
|
-
// The generality pre-check: a note Jev scores under the bar rests on its one input, and is dropped before the
|
|
362
|
-
// grader reads it, its why said with the grader's items. Jev down or not set up here: every note is graded.
|
|
363
|
-
let screened = false;
|
|
364
|
-
// Why the check could not run, kept on the grade's (or the drop's) entry: never a silent skip.
|
|
365
|
-
let unchecked;
|
|
366
|
-
if (grading.length && learning.general) {
|
|
367
|
-
const threshold = learning.generalThreshold ?? GENERAL_THRESHOLD;
|
|
368
|
-
const input = proposal.asked?.[0] ?? proposal.triggered?.[0]?.text;
|
|
369
|
-
// The check is paid and Jev dedupes none, so it is made durable as the grade's ask is (learning-ask.ts
|
|
370
|
-
// bookedAsk): marked sent before its requests leave, and its end kept before the grader starts. A restart
|
|
371
|
-
// reuses a check that ended, paying nothing again; one an earlier attempt sent with no end after it was cut,
|
|
372
|
-
// what it spent is unknown (null, as a cut grade request is booked before it is asked again), and it is
|
|
373
|
-
// asked again with that unknown kept.
|
|
374
|
-
let ended = [...entries].reverse().find((entry) => entry.kind === KINDS.learningGeneral)?.data;
|
|
375
|
-
if (!ended) {
|
|
376
|
-
const sentMarks = entries.filter((entry) => entry.kind === KINDS.learningGeneralSent);
|
|
377
|
-
const cut = sentMarks.length > 0;
|
|
378
|
-
if (cut)
|
|
379
|
-
learning.log?.(`learning run ${claim.runId}: a generality check an earlier attempt sent was cut, so what it spent is unknown; it is asked again`);
|
|
380
|
-
// Under a cap: the most the cut attempts' requests may have spent (each mark's worst case), and this one's.
|
|
381
|
-
const cutHeld = sentMarks.reduce((sum, entry) => sum + (entry.data?.held ?? 0), 0);
|
|
382
|
-
let sentHeld = 0;
|
|
383
|
-
let checked;
|
|
384
|
-
let failed;
|
|
385
|
-
let overCap;
|
|
386
|
-
try {
|
|
387
|
-
checked = await learning.general(grading, { ...(source.instructions ? { job: source.instructions } : {}), ...(input !== undefined ? { input } : {}) }, AbortSignal.any([deps.signal, stopAsk.signal]), source.runId, async (held) => {
|
|
388
|
-
sentHeld += held ?? 0;
|
|
389
|
-
await append(KINDS.learningGeneralSent, { source: source.runId, ...(held !== undefined ? { held } : {}) });
|
|
390
|
-
await deps.flush();
|
|
391
|
-
}, cutHeld);
|
|
392
|
-
}
|
|
393
|
-
catch (error) {
|
|
394
|
-
// Cut by a stop, a lost claim or a shutdown: what it sent spent what nobody knows. A stop row ends the run
|
|
395
|
-
// stopped with that unknown; otherwise nothing more is written, and the next attempt finds it sent with no
|
|
396
|
-
// end, books it unknown and asks again.
|
|
397
|
-
if (stopped || deps.signal.aborted) {
|
|
398
|
-
spend = null;
|
|
399
|
-
return (await halted()) ?? { state: "interrupted" };
|
|
400
|
-
}
|
|
401
|
-
// No room under the run's cap for its worst case: nothing sent, skipped, said so (never silent), and the
|
|
402
|
-
// grader judged against the cap on its own.
|
|
403
|
-
if (error instanceof GeneralOverCap)
|
|
404
|
-
overCap = error;
|
|
405
|
-
else {
|
|
406
|
-
// Its requests were sent and one failed: what they spent is unknown, never 0 (as an ask that fails is).
|
|
407
|
-
// Its error is kept and logged cut of the runner's secrets (LoopDeps.redact).
|
|
408
|
-
const message = error?.message ?? String(error);
|
|
409
|
-
failed = deps.redact ? deps.redact(message) : message;
|
|
410
|
-
learning.log?.(`learning run ${claim.runId}: the generality check could not run, so the grader reads every note: ${failed}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const held = cutHeld + sentHeld;
|
|
414
|
-
const bound = held > 0 ? { held } : {};
|
|
415
|
-
if (checked)
|
|
416
|
-
ended = { source: source.runId, scores: checked.scores, usd: cut ? null : checked.usd, ...bound };
|
|
417
|
-
else if (overCap) {
|
|
418
|
-
learning.log?.(`learning run ${claim.runId}: the generality check has no room under the cap (${overCap.message}), so the grader reads every note`);
|
|
419
|
-
ended = { source: source.runId, unchecked: GENERAL_NO_BUDGET, usd: cut ? null : 0, ...bound };
|
|
420
|
-
}
|
|
421
|
-
else if (failed !== undefined)
|
|
422
|
-
ended = { source: source.runId, unchecked: failed, usd: null, ...bound };
|
|
423
|
-
else if (cut)
|
|
424
|
-
ended = { source: source.runId, unchecked: "no Jev is set up on this host now", usd: null, ...bound };
|
|
425
|
-
// Kept, durably, before the grader starts: a restart from here on asks Jev nothing.
|
|
426
|
-
if (ended) {
|
|
427
|
-
await append(KINDS.learningGeneral, ended);
|
|
428
|
-
await deps.flush();
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (ended) {
|
|
432
|
-
checkUsd = ended.usd;
|
|
433
|
-
beside = ended.usd ?? ended.held ?? 0;
|
|
434
|
-
if (ended.unchecked !== undefined)
|
|
435
|
-
unchecked = ended.unchecked;
|
|
436
|
-
if (ended.scores) {
|
|
437
|
-
screened = true;
|
|
438
|
-
const scores = ended.scores;
|
|
439
|
-
const below = grading.filter(({ file }) => typeof scores[file] === "number" && scores[file] < threshold);
|
|
440
|
-
settledItems.push(...below.map(({ file }) => ({ file, keep: false, question: "General", why: ONE_CASE(scores[file], threshold) })));
|
|
441
|
-
grading = grading.filter((note) => !below.includes(note));
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
342
|
// The notes the graded ones supersede, of those main gave: a dropped note's are not the grade's.
|
|
446
343
|
const replacing = new Set(grading.flatMap((note) => { const parsed = parseNoteFile(note.file, note.text); return Array.isArray(parsed) ? [] : parsed.supersedes; }));
|
|
447
344
|
const superseded = main.superseded.filter(({ file }) => replacing.has(file));
|
|
448
345
|
if (!grading.length && !proposal.files?.length) {
|
|
449
|
-
const verdict = { merge: false, reason:
|
|
450
|
-
|
|
451
|
-
// spent) before it is dropped, so the run's learning reads why each note was left out.
|
|
452
|
-
if (screened)
|
|
453
|
-
await append(KINDS.learningGraded, { source: source.runId, verdict, usd: spent(), tokens, graded: main.graded });
|
|
454
|
-
await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)), usd: spent(), tokens }, "ended");
|
|
346
|
+
const verdict = { merge: false, reason: "Every new note is named like one the agent holds now.", items: settledItems };
|
|
347
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)), usd, tokens }, "ended");
|
|
455
348
|
return { state: "ended" };
|
|
456
349
|
}
|
|
457
350
|
const items = gradedItems(grading, (proposal.files ?? []));
|
|
@@ -466,8 +359,7 @@ export function createLearningLoop(learning) {
|
|
|
466
359
|
catch (error) {
|
|
467
360
|
// A full native policy can fill the remaining prompt budget. Refuse the whole proposal visibly;
|
|
468
361
|
// no grader was called and no standing instruction or proposal is silently omitted.
|
|
469
|
-
|
|
470
|
-
await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: error instanceof Error ? error.message : "The grading evidence exceeds the supported prompt budget.", usd: spent(), tokens, ...(unchecked !== undefined ? { unchecked } : {}) }, "ended");
|
|
362
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: error instanceof Error ? error.message : "The grading evidence exceeds the supported prompt budget.", usd, tokens }, "ended");
|
|
471
363
|
return { state: "ended" };
|
|
472
364
|
}
|
|
473
365
|
/** The asks of this attempt that answered: the records holding more requests than these is an earlier attempt's. */
|
|
@@ -490,7 +382,7 @@ export function createLearningLoop(learning) {
|
|
|
490
382
|
const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
|
|
491
383
|
let answer;
|
|
492
384
|
try {
|
|
493
|
-
answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS
|
|
385
|
+
answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
|
|
494
386
|
}
|
|
495
387
|
catch (error) {
|
|
496
388
|
// A call the cap refused was never sent: it spent nothing, and what the grade spent before it stands, as its
|
|
@@ -527,23 +419,23 @@ export function createLearningLoop(learning) {
|
|
|
527
419
|
catch (error) {
|
|
528
420
|
// What the asks spent (and the check before them): a cut one's unknown (null), kept on a stopped run's row as
|
|
529
421
|
// on a dropped one's.
|
|
530
|
-
spend =
|
|
422
|
+
spend = usd;
|
|
531
423
|
const end = await halted();
|
|
532
424
|
if (end)
|
|
533
425
|
return end;
|
|
534
426
|
// No room under the run's cap for the grade (a call the cap refused): skipped, said so, with what it spent
|
|
535
427
|
// before (an earlier ask's), never a failure and never past the cap.
|
|
536
428
|
if (error instanceof GradeOverCap) {
|
|
537
|
-
await append(KINDS.learningDropped, { source: source.runId, reason: "no_budget", detail: error.forGood ? said.gradeUncapped : said.noRoomToGrade, usd
|
|
429
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "no_budget", detail: error.forGood ? said.gradeUncapped : said.noRoomToGrade, usd, tokens }, "ended");
|
|
538
430
|
return { state: "ended" };
|
|
539
431
|
}
|
|
540
|
-
await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd
|
|
432
|
+
await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd, tokens }, "ended");
|
|
541
433
|
void error;
|
|
542
434
|
return { state: "ended" };
|
|
543
435
|
}
|
|
544
436
|
if (settledItems.length)
|
|
545
437
|
verdict = { ...verdict, items: [...verdict.items, ...settledItems] };
|
|
546
|
-
graded = { source: source.runId, verdict, usd
|
|
438
|
+
graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
|
|
547
439
|
spend = graded.usd;
|
|
548
440
|
await append(KINDS.learningGraded, graded);
|
|
549
441
|
// The verdict is durable before the merge, its side effect.
|
package/dist/runner/main.js
CHANGED
|
@@ -135,7 +135,7 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
135
135
|
const deps = {
|
|
136
136
|
env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
|
|
137
137
|
computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
|
|
138
|
-
// A run's log lines (a
|
|
138
|
+
// A run's log lines (a sweep that failed) on the runner's stderr, as its
|
|
139
139
|
// warnings are.
|
|
140
140
|
log: (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`),
|
|
141
141
|
// An MCP server on loopback: reached only when this process's own operator set AGENTRUN_MCP_ALLOW_LOOPBACK=1
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { LearnedWorkflow } from "../learning.js";
|
|
3
|
-
import type { GuardRow } from "../learned-nodes.js";
|
|
4
3
|
import { type RunLaunch } from "../run-launch.js";
|
|
5
4
|
import { type Store } from "../store/store.js";
|
|
6
5
|
import { type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
|
|
@@ -18,26 +17,20 @@ export declare const REPLAY_LAUNCH_GRACE_MS: number;
|
|
|
18
17
|
export interface PromotionDeps {
|
|
19
18
|
readonly store: Store;
|
|
20
19
|
readonly agentId: string;
|
|
21
|
-
/** The run being claimed: never one of its own
|
|
20
|
+
/** The run being claimed: never one of its own check's inputs. Absent: no run is claimed (a person's replay, and its
|
|
22
21
|
* read): no run served first to keep, none whose per_run MCP credentials a replay is handed. */
|
|
23
22
|
readonly runId?: string;
|
|
24
23
|
/** The revision the claimed run runs: its replay runs run it too. */
|
|
25
24
|
readonly revisionId: string;
|
|
26
|
-
/** The claimed run's launch: a replay run's is this one with the
|
|
25
|
+
/** The claimed run's launch: a replay run's is this one with the agent run's input. */
|
|
27
26
|
readonly launch: RunLaunch;
|
|
28
27
|
readonly context: Context;
|
|
29
28
|
readonly log: (line: string) => void;
|
|
30
|
-
/** Writes a refit's new workflow text onto the agent's learning folder (a merge as `id`, from the claim's seed); the
|
|
31
|
-
* learning commit it landed as, or null when it did not. Absent: no refit is written. */
|
|
32
|
-
readonly commit?: (files: {
|
|
33
|
-
path: string;
|
|
34
|
-
text: string;
|
|
35
|
-
}[], reason: string, id: string) => Promise<string | null>;
|
|
36
29
|
/** The learned workflow `name` as the learning folder held it active at `commit` (a champion's text), or undefined when
|
|
37
30
|
* it held none by that name. Absent: no champion serves. */
|
|
38
31
|
readonly champion?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>;
|
|
39
32
|
/** The digest of the learned workflow `name` the learning folder's main holds now (the newest revision), or undefined
|
|
40
|
-
* when it holds none by that name. Absent:
|
|
33
|
+
* when it holds none by that name. Absent: every revision is the newest. */
|
|
41
34
|
readonly newest?: (name: string) => Promise<string | undefined>;
|
|
42
35
|
/** The learned workflow an earlier claim of this run served first (its WORKFLOW_FIRST entry, answered or handed back:
|
|
43
36
|
* workflow-first.ts servedOf), or undefined for a run no claim served yet: a run already executing keeps its revision
|
|
@@ -54,11 +47,10 @@ export interface PromotionDeps {
|
|
|
54
47
|
* they are shortened (decideCheck). */
|
|
55
48
|
readonly shown: () => Promise<Shown>;
|
|
56
49
|
}
|
|
57
|
-
/** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
export declare function claimPromotion(deps: Omit<PromotionDeps, "commit" | "champion" | "kept"> & {
|
|
50
|
+
/** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a champion read
|
|
51
|
+
* from it at its record's commit, cut of the server's secrets (`shown`) as the claim's lay is; and the workflow an earlier
|
|
52
|
+
* claim of this run served (`kept`, from its journal: none on a first claim). */
|
|
53
|
+
export declare function claimPromotion(deps: Omit<PromotionDeps, "champion" | "kept"> & {
|
|
62
54
|
readonly folder: () => LearningFolder;
|
|
63
55
|
}): PromotionDeps;
|
|
64
56
|
/** A replay run's claim (launch.replay) of run `runId`, once its first choice is made: refused (ClaimRefused: the run ends
|
|
@@ -68,25 +60,23 @@ export declare function claimPromotion(deps: Omit<PromotionDeps, "commit" | "cha
|
|
|
68
60
|
* replay's leftover once its revision replays again; one whose workflow is not laid at its digest (the seed could not be
|
|
69
61
|
* read, the folder moved on) never falls to the agent's path. Any other run: nothing to check. */
|
|
70
62
|
export declare function replayClaimed(store: Pick<Store, "settings">, agentId: string, runId: string, launch: RunLaunch, choice: FirstChoice): Promise<void>;
|
|
71
|
-
/** The workflows a replay run's claim lays (`laid`, the seed lay's): the one it replays
|
|
72
|
-
*
|
|
73
|
-
* the laid one is not the digest it replays (the replay then fails, never scoring another revision). Any other run's,
|
|
74
|
-
* as laid. */
|
|
63
|
+
/** The workflows a replay run's claim lays (`laid`, the seed lay's): the one it replays, or none by that name when the
|
|
64
|
+
* laid one is not the digest it replays (the replay then fails, never scoring another revision). Any other run's, as laid. */
|
|
75
65
|
export declare function replayLaid(launch: RunLaunch, laid: readonly LearnedWorkflow[]): LearnedWorkflow[];
|
|
76
66
|
/** The learned workflows a run's learned_workflow tool runs, once its first choice is made: what serves, never a
|
|
77
67
|
* revision its promotion has not promoted. The one its first choice served or the money rule stopped (laidFor: its
|
|
78
68
|
* champion in place of the laid revision) as chosen; any other the records name, its champion (championOf: the laid
|
|
79
69
|
* text when that is the champion, else its text at its record's commit), and none while nothing of it serves (none
|
|
80
|
-
* promoted yet, or the champion held): a revision replaying,
|
|
81
|
-
*
|
|
82
|
-
*
|
|
70
|
+
* promoted yet, or the champion held): a revision replaying, held or never decided is never handed to the agent to run
|
|
71
|
+
* in its place. One the records never named (no run's input fit it, so no claim asked) runs as laid. A replay run's as
|
|
72
|
+
* laid (replayLaid). The records unread: only the chosen one, as the gate leaves a run to its agent. */
|
|
83
73
|
export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
|
|
84
74
|
/** The gate workflowFirstOf asks (its `promoted`), at every run's claim, a queued run's included: the workflow that serves
|
|
85
75
|
* this run first. A run already executing keeps the revision an earlier claim of it served (keptFor). Else the laid
|
|
86
|
-
* revision (`workflow` at `digest`, the folder's revision as the run's seed holds it) has its
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
76
|
+
* revision (`workflow` at `digest`, the folder's revision as the run's seed holds it) has its check moved on (decide:
|
|
77
|
+
* started, or settled once its runs ended), and then servingNow alone says who serves: the champion (championOf), the
|
|
78
|
+
* laid text when it is the champion, its own text read from its record's commit when not; undefined when none serves
|
|
79
|
+
* (the agent takes the run). A digest's own record never says it serves. */
|
|
90
80
|
export declare const promotionGate: (deps: PromotionDeps) => Promoted;
|
|
91
81
|
/** The words a stopped check's record starts with when it had nothing to check its draft on. */
|
|
92
82
|
export declare const NOTHING_TO_CHECK = "nothing to check it on";
|
|
@@ -100,23 +90,31 @@ type CheckRow = {
|
|
|
100
90
|
readonly agent: string | null;
|
|
101
91
|
readonly outcome: ReplayOutcome;
|
|
102
92
|
readonly answer: string | null;
|
|
103
|
-
readonly guards: readonly GuardRow[];
|
|
104
93
|
readonly escalated?: string;
|
|
105
94
|
readonly skipped?: Skipped;
|
|
106
95
|
readonly unstarted?: true;
|
|
107
96
|
};
|
|
108
97
|
/** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
|
|
109
|
-
* with the agent's recorded answer (learn/promote.ts sameAnswer), alone when it answered it with no escalate
|
|
110
|
-
* step
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
98
|
+
* with the agent's recorded answer (learn/promote.ts sameAnswer), alone when it answered it with no escalate and no
|
|
99
|
+
* failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
|
|
100
|
+
* agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
|
|
101
|
+
* nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
|
|
102
|
+
* (the one write: of two claims at once, one decides). */
|
|
114
103
|
export declare function decideCheck(deps: PromotionDeps, name: string, digest: string, bar: CheckBar, read: {
|
|
115
104
|
rows: readonly CheckRow[];
|
|
116
105
|
cost: number | null;
|
|
117
106
|
outcomes: ReplayOutcomes;
|
|
118
107
|
unstarted: number;
|
|
119
|
-
},
|
|
108
|
+
}, still: (was: PromotionRecord | undefined) => boolean, extra: Partial<PromotionRecord>): Promise<import("../learn/promote.js").Recorded>;
|
|
109
|
+
/** A run's final answer row, its text whole (its last final answer row that is not its end-of-run turn's), or null: none,
|
|
110
|
+
* or its record could not be read. `turn`: the row of that id instead (the answer an audit is of, runner/audit.ts), so an
|
|
111
|
+
* answer a follow-up gave since is never read for it. */
|
|
112
|
+
export declare function answerRowOf(store: PromotionDeps["store"], runId: string, context: Context, turn?: string): Promise<{
|
|
113
|
+
id: string;
|
|
114
|
+
text: string;
|
|
115
|
+
} | null>;
|
|
116
|
+
/** A run's final answer, whole (answerRowOf's text; `turn`: that row's), or null. */
|
|
117
|
+
export declare const answerOf: (store: PromotionDeps["store"], runId: string, context: Context, turn?: string) => Promise<string | null>;
|
|
120
118
|
/** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
|
|
121
119
|
* replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
|
|
122
120
|
export declare class ReplayRefused extends Error {
|
|
@@ -125,7 +123,7 @@ export declare class ReplayRefused extends Error {
|
|
|
125
123
|
}
|
|
126
124
|
/** What a person's replay reads and writes through (POST and GET .../revisions/{digest}/replays): the claim's ports, with
|
|
127
125
|
* no claimed run. `launchOf`: a run's launch of the agent on `input` as its start makes one now, and the revision it runs
|
|
128
|
-
* on: a replay run's is this one with its
|
|
126
|
+
* on: a replay run's is this one with its agent run's input (startReplay), at the revision's learning commit. */
|
|
129
127
|
export interface ReplayAsk {
|
|
130
128
|
readonly store: Store;
|
|
131
129
|
readonly agentId: string;
|
|
@@ -139,26 +137,24 @@ export interface ReplayAsk {
|
|
|
139
137
|
}>;
|
|
140
138
|
readonly now?: () => number;
|
|
141
139
|
}
|
|
142
|
-
/** A
|
|
143
|
-
* the
|
|
144
|
-
* the agent's newest that many (each a
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* only hold it: settle scores none of it), refused before anything is reserved; an agent that does not learn here. The
|
|
150
|
-
* replay's id and its inputs. */
|
|
140
|
+
/** A check of `name` at `digest` a person asked for: the claim path's check (reserve, startReplay), on `inputs`: `held`,
|
|
141
|
+
* the agent runs its last check ran on (else, with none, the agent's last compile_after completed runs), or a number,
|
|
142
|
+
* the agent's newest that many (each a completed run of its own the workflow fits). Its runs end as a claim's do, and it
|
|
143
|
+
* is decided by settleCheck: at a claim that lays the revision, or at its read (replayView). Refused (ReplayRefused): no
|
|
144
|
+
* such workflow or revision; one replaying already, or another revision of it replaying (one at a time); a promoted one
|
|
145
|
+
* (it serves already); no input it fits (nothing is reserved); an agent that does not learn here. The replay's id and
|
|
146
|
+
* its inputs. */
|
|
151
147
|
export declare function askReplay(ask: ReplayAsk, name: string, digest: string, inputs: "held" | number): Promise<{
|
|
152
148
|
replay: string;
|
|
153
149
|
inputs: number;
|
|
154
150
|
}>;
|
|
155
151
|
/** A replay as its read answers it (GET .../replays/{replay_id}). `status`: `running` while its record says replaying,
|
|
156
152
|
* `done` once promoted or held, `failed` when none of its runs started by its deadline (nothing was replayed; held, its
|
|
157
|
-
* `reason` says so).
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* the
|
|
161
|
-
* is unknown (replayCost). */
|
|
153
|
+
* `reason` says so). `outcomes`: what its own runs did (outcomesOf), so far while it runs, and once decided as its
|
|
154
|
+
* record kept them. `score`: the decided check's numbers in the replay's shape with the agent's own answers as the label
|
|
155
|
+
* (`agree` the inputs the draft answered alone as the agent did, `agent_acc` 1, `wf_acc` those plus the ones handed back,
|
|
156
|
+
* a hand-back being the agent's answer, over the inputs it ran on), zero while it runs. `cost_usd` the decided record's,
|
|
157
|
+
* else the runs ended so far, and null while a run's cost is unknown (replayCost). */
|
|
162
158
|
type ReplayView = {
|
|
163
159
|
readonly replay: string;
|
|
164
160
|
readonly workflow: string;
|
|
@@ -171,14 +167,14 @@ type ReplayView = {
|
|
|
171
167
|
readonly decided?: "promote" | "hold";
|
|
172
168
|
readonly reason?: string;
|
|
173
169
|
};
|
|
174
|
-
/** Reads replay `id` of `name` at `digest`, settling it first as a claim of its revision would (
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
170
|
+
/** Reads replay `id` of `name` at `digest`, settling it first as a claim of its revision would (settleCheck) once its runs
|
|
171
|
+
* ended or its deadline passed: it writes only the decision. A read never starts a run: a replay whose launch was
|
|
172
|
+
* interrupted (reserved runs never created) reads running until its deadline, then is decided held, read as failed, its
|
|
173
|
+
* reason saying none of its runs started and to start it again with POST. So a replay of a revision no claim lays (an
|
|
174
|
+
* older, held one) is decided too, and never running forever. Once decided, it reads only its record. Refused
|
|
179
175
|
* (missing) when the agent has no such replay. */
|
|
180
176
|
export declare function replayView(ask: ReplayAsk, name: string, digest: string, id: string): Promise<ReplayView>;
|
|
181
|
-
/** A replay run's call nodes (launch.replay; learn/replay-calls.ts): the
|
|
177
|
+
/** A replay run's call nodes (launch.replay; learn/replay-calls.ts): the agent run's recorded calls, read from its journal
|
|
182
178
|
* (a CLI's record shaped as pi's), and each tool classed by the claim's MCP pin (`runId`'s, its servers' annotations as
|
|
183
179
|
* they listed them) or the built-in list. Undefined for any other run. A recording that cannot be read is an empty one:
|
|
184
180
|
* every write is then skipped, never run. */
|