@parcha/agentrun-serve 0.1.0-beta.42 → 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 +126 -0
- package/README.md +221 -31
- 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/decisions.js +0 -4
- 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-sources.js +25 -5
- 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/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- 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.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- 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 +111 -4
- package/dist/learning-cost.js +120 -3
- 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 +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- 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 +203 -87
- 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-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- 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 +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- 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 +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -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 +55 -13
- package/dist/runner/learning-end.js +128 -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/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 +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- 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 +516 -134
- 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 +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- 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/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- 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
|
@@ -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.
|
|
@@ -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
|
}
|
|
@@ -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
|
|
@@ -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
|
}
|