@parcha/agentrun-serve 0.1.0-beta.61 → 0.1.0-beta.63
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 +113 -0
- package/README.md +128 -20
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/api-only.d.ts +4 -0
- package/dist/api-only.js +5 -1
- package/dist/archil-settings.d.ts +9 -0
- package/dist/archil-settings.js +8 -1
- package/dist/bash-read-only.d.ts +3 -0
- package/dist/bash-read-only.js +6 -3
- package/dist/chatgpt-plan.d.ts +33 -8
- package/dist/chatgpt-plan.js +141 -24
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +19 -8
- package/dist/composio-triggers.d.ts +9 -3
- package/dist/computers.d.ts +3 -0
- package/dist/computers.js +2 -1
- package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/cut-pool.d.ts +14 -0
- package/dist/cut-pool.js +98 -0
- package/dist/cut-worker.d.ts +14 -0
- package/dist/cut-worker.js +16 -0
- package/dist/decisions.d.ts +4 -0
- package/dist/decisions.js +9 -1
- package/dist/env-switch.d.ts +3 -0
- package/dist/env-switch.js +3 -0
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/harness-table.d.ts +7 -0
- package/dist/harness-table.js +6 -3
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learned-nodes.d.ts +2 -1
- package/dist/learned-nodes.js +2 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-servers-store.d.ts +7 -10
- package/dist/mcp-servers-store.js +15 -9
- package/dist/native/cli.js +5 -1
- package/dist/ollama-provider.d.ts +10 -3
- package/dist/ollama-provider.js +17 -7
- package/dist/openapi.js +51 -20
- package/dist/otel/tracer.d.ts +6 -3
- package/dist/otel/tracer.js +24 -6
- package/dist/page.d.ts +7 -0
- package/dist/page.js +17 -4
- package/dist/place.d.ts +25 -9
- package/dist/place.js +37 -11
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +26 -6
- package/dist/run-model-key.d.ts +2 -1
- package/dist/run-model-key.js +2 -1
- package/dist/run-reads-over-store.d.ts +7 -0
- package/dist/run-reads-over-store.js +32 -4
- package/dist/run-view.js +9 -3
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +21 -11
- package/dist/runner/adapter-loop.js +95 -28
- package/dist/runner/adapter-run-spec.d.ts +20 -4
- package/dist/runner/adapter-run-spec.js +64 -30
- package/dist/runner/adapters/index.d.ts +6 -0
- package/dist/runner/adapters/index.js +5 -1
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +12 -5
- package/dist/runner/claim-secrets.js +28 -12
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +54 -25
- package/dist/runner/dispatch.js +2 -0
- package/dist/runner/harness-loops.d.ts +5 -0
- package/dist/runner/harness-loops.js +4 -1
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/live-ticker.js +3 -1
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/main.js +2 -0
- package/dist/runner/mcp-run.d.ts +5 -0
- package/dist/runner/mcp-run.js +18 -0
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +5 -3
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/native-loop.js +2 -2
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +65 -41
- package/dist/runner/run-child.js +2 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +158 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-calls.d.ts +4 -3
- package/dist/runner/workflow-calls.js +41 -12
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -1
- package/dist/secret-rules.js +88 -24
- package/dist/server.d.ts +10 -1
- package/dist/server.js +131 -44
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +669 -0
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/suggestions.js +32 -3
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +7 -3
- package/dist/tool-gate.d.ts +25 -9
- package/dist/tool-gate.js +58 -19
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tool-plane.d.ts +1 -0
- package/dist/tool-plane.js +6 -2
- package/dist/tools.js +2 -2
- package/dist/trigger-composio.js +1 -1
- package/dist/webhooks.d.ts +3 -0
- package/dist/webhooks.js +5 -0
- package/dist/workspace/archil-claim.d.ts +7 -3
- package/dist/workspace/archil-claim.js +13 -5
- package/dist/workspace/archil-mount-credential.d.ts +6 -0
- package/dist/workspace/archil-mount-credential.js +11 -0
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/computer-deps.d.ts +5 -3
- package/dist/workspace/computer-deps.js +11 -9
- package/dist/workspace/computer-for-claim.d.ts +6 -2
- package/dist/workspace/computer-for-claim.js +43 -12
- package/dist/workspace/computer-janitor.d.ts +7 -4
- package/dist/workspace/computer-janitor.js +7 -4
- package/dist/workspace/computer-kept.d.ts +7 -1
- package/dist/workspace/computer-kept.js +7 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
- package/dist/workspace/mount-revoke-left.d.ts +16 -4
- package/dist/workspace/mount-revoke-left.js +42 -22
- package/dist/workspace/resolve-computer.d.ts +11 -5
- package/dist/workspace/resolve-computer.js +22 -13
- package/dist/workspace/run-end-computers.js +1 -1
- package/dist/workspace/run-tools.d.ts +10 -3
- package/dist/workspace/run-tools.js +5 -4
- package/dist/wrapped.d.ts +29 -2
- package/dist/wrapped.js +20 -3
- package/launcher/agentrun-serve +1 -1
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/index-BnZV3lvW.js +0 -639
- package/dist/console/assets/share-B1o5mJ56.js +0 -6
- /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
package/dist/runner/runner.js
CHANGED
|
@@ -10,18 +10,21 @@
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { hostname } from "node:os";
|
|
12
12
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
13
|
-
import { COMMAND_KINDS, endedReason } from "./commands.js";
|
|
13
|
+
import { COMMAND_KINDS, endedReason, sendCommand } from "./commands.js";
|
|
14
14
|
import { COMPUTER_CALL } from "../computer-channel.js";
|
|
15
15
|
import { COMPUTER_HAND_BACK, COMPUTER_TAKE_OVER } from "../computer-commands.js";
|
|
16
16
|
import { HELD_COMMANDS } from "../computer-held.js";
|
|
17
17
|
import { HAND_BACK } from "./hand-back.js";
|
|
18
18
|
import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
|
|
19
19
|
import { journalEntries } from "./journal-reader.js";
|
|
20
|
+
import { cliModelWorked, endCostOf, runCostOf } from "./metrics.js";
|
|
21
|
+
import { inLogOrder, isCliRecord } from "../store-reads/journal.js";
|
|
22
|
+
import { bookCutRequests } from "./book-cut.js";
|
|
20
23
|
import { REAL_TIMER } from "./loop.js";
|
|
21
24
|
import { ClaimRefused, stopEnd } from "./loop-contract.js";
|
|
22
25
|
import { FrameTooLarge } from "./run-channel.js";
|
|
23
26
|
import { isFenced } from "./store-port.js";
|
|
24
|
-
import { FINAL_STATES } from "../store/store.js";
|
|
27
|
+
import { FINAL_STATES, RunFinal } from "../store/store.js";
|
|
25
28
|
import { Unanswered } from "../store/postgres/connection.js";
|
|
26
29
|
import { clearWaitEnded } from "../browser-wait-ended.js";
|
|
27
30
|
import { clearBrowserHeld } from "../browser-hold.js";
|
|
@@ -35,6 +38,8 @@ const UNKNOWN_READS = 5;
|
|
|
35
38
|
/** Passes of the sweep after a claim answered Unanswered: the commit may still be on its way when the first read comes back
|
|
36
39
|
* empty, so the read is repeated, waiting twice as long each time, before the lease is left to settle it. */
|
|
37
40
|
const UNKNOWN_SWEEPS = 4;
|
|
41
|
+
/** The longest wait one timer takes (a 32-bit signed count of ms): a longer one fires at once. */
|
|
42
|
+
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
38
43
|
/** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
|
|
39
44
|
/** A final run's status as its end line says it: the store holds a cancel as state 'stopped' with outcome 'cancelled', so
|
|
40
45
|
* the outcome tells a cancel from a person's resumable stop. */
|
|
@@ -86,7 +91,7 @@ const message = (error) => (error instanceof Error ? error.message : String(erro
|
|
|
86
91
|
/** The run states a run patch makes final: a commit that lands one is the run's end, and its release. */
|
|
87
92
|
const FINAL = new Set(["ended", "stopped", "failed"]);
|
|
88
93
|
export function startRunner(options) {
|
|
89
|
-
const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs = RUNNER_LEASE_MS, renewEveryMs = RUNNER_RENEW_EVERY_MS, stopMarginMs = RUNNER_STOP_MARGIN_MS, pollMs = 1_000, commandPollMs = 500, resumeTries = 3, resumeBackoffMs = 5_000, interruptBackoffMs = 1_000, unknownBackoffMs = 200, endWaitMs = 5_000, drainMs = 0, memory, census, censusMs = CENSUS_MS, endRetryBackoffMs = END_RETRY_BACKOFF_MS, endRetryCapMs = END_RETRY_CAP_MS, endRetryAtCap = END_RETRY_AT_CAP, onEvent = () => { }, runEnded, redact: given = processSecretRedactor(), now = Date.now, onBeat = () => { }, clock = { now: () => Date.now(), ...REAL_TIMER }, } = options;
|
|
94
|
+
const { store, createLoop, name = runnerName(), loops = RUNNER_LOOPS, leaseMs = RUNNER_LEASE_MS, renewEveryMs = RUNNER_RENEW_EVERY_MS, stopMarginMs = RUNNER_STOP_MARGIN_MS, pollMs = 1_000, commandPollMs = 500, resumeTries = 3, resumeBackoffMs = 5_000, interruptBackoffMs = 1_000, unknownBackoffMs = 200, endWaitMs = 5_000, drainMs = 0, memory, census, censusMs = CENSUS_MS, endRetryBackoffMs = END_RETRY_BACKOFF_MS, endRetryCapMs = END_RETRY_CAP_MS, endRetryAtCap = END_RETRY_AT_CAP, onEvent = () => { }, runEnded, redact: given = processSecretRedactor(), now = Date.now, learningClock = Date.now, onBeat = () => { }, clock = { now: () => Date.now(), ...REAL_TIMER }, } = options;
|
|
90
95
|
// The one instance every run's loop gets (LoopDeps.redact), able to hold what each claim opens from the store
|
|
91
96
|
// (redact.ts holdClaimed): a stored key is cut wherever a key of the runner's environment is.
|
|
92
97
|
const redact = heldRedactor(given);
|
|
@@ -505,7 +510,7 @@ export function startRunner(options) {
|
|
|
505
510
|
* in its journal, a reopen would find no turn to follow (its next claim would read the run as never started), so it
|
|
506
511
|
* reads as a stop that is over (cancelled), as it read before a stop and a cancel were told apart.
|
|
507
512
|
*/
|
|
508
|
-
const endRun = async (claim, given, take, withdrawnAs = "withdrawn", landed = () => { }) => {
|
|
513
|
+
const endRun = async (claim, given, take, withdrawnAs = "withdrawn", landed = () => { }, cost) => {
|
|
509
514
|
// Why the run ended, as its end and its row say it: cut of every secret the runner holds (an error's text may echo one).
|
|
510
515
|
const data = { ...given, summary: redact(given.summary) };
|
|
511
516
|
// Unknown means it may withdraw: false only once the journal was read and no call of it waits.
|
|
@@ -538,7 +543,7 @@ export function startRunner(options) {
|
|
|
538
543
|
}
|
|
539
544
|
const id = (await journal.mintId());
|
|
540
545
|
writes.push({ type: "entry", value: { id, conversationId, kind: KINDS.end, data: data } });
|
|
541
|
-
journal.stage({ run: { state: data.state, summary: data.summary, ...(data.outcome ? { outcome: data.outcome } : {}), ...(neverSent ? { costUsd: 0 } : {}), ...counted }, effect: id, ...(take.length ? { take: take.map((command) => ({ command, effect: id })) } : {}) });
|
|
546
|
+
journal.stage({ run: { state: data.state, summary: data.summary, ...(data.outcome ? { outcome: data.outcome } : {}), ...(cost ?? (neverSent ? { costUsd: 0 } : {})), ...counted }, effect: id, ...(take.length ? { take: take.map((command) => ({ command, effect: id })) } : {}) });
|
|
542
547
|
const result = await journal.commit([writes], () => { }, BACKGROUND_CONTEXT);
|
|
543
548
|
if (result.stored !== 1)
|
|
544
549
|
throw result.refused ?? new Error("the run's end was not stored");
|
|
@@ -549,7 +554,7 @@ export function startRunner(options) {
|
|
|
549
554
|
throw error;
|
|
550
555
|
if (mayWithdraw)
|
|
551
556
|
throw new EndNotWithdrawn(claim.runId, error);
|
|
552
|
-
await store.runs.update(claim, { state: data.state, summary: data.summary, ...(data.outcome === "cancelled" ? { outcome: data.outcome } : {}), ...counted }, take.length ? { take } : undefined);
|
|
557
|
+
await store.runs.update(claim, { state: data.state, summary: data.summary, ...(data.outcome === "cancelled" ? { outcome: data.outcome } : {}), ...cost, ...counted }, take.length ? { take } : undefined);
|
|
553
558
|
landed();
|
|
554
559
|
}
|
|
555
560
|
// An ended run's Screen has no ended-while-waiting state to keep (browser-wait-ended.ts): its row goes with the end.
|
|
@@ -561,16 +566,16 @@ export function startRunner(options) {
|
|
|
561
566
|
};
|
|
562
567
|
/** Ends the run under `claim` stopped on its untaken `stop` (or cancel) row (endRun). False when that end may withdraw a
|
|
563
568
|
* call and the journal would not take it or could not be read: the refusal is then the run's (endRefused). */
|
|
564
|
-
const endStopped = async (claim, stop, landed) => {
|
|
569
|
+
const endStopped = async (claim, stop, landed, cost) => {
|
|
565
570
|
try {
|
|
566
571
|
const end = stopEnd(stop.kind === "cancel");
|
|
567
|
-
await endRun(claim, end, [stop.id], stop.kind === "cancel" ? "canceled" : "withdrawn", landed);
|
|
572
|
+
await endRun(claim, end, [stop.id], stop.kind === "cancel" ? "canceled" : "withdrawn", landed, cost);
|
|
568
573
|
return true;
|
|
569
574
|
}
|
|
570
575
|
catch (error) {
|
|
571
576
|
if (!(error instanceof EndNotWithdrawn))
|
|
572
577
|
throw error;
|
|
573
|
-
await endRefused(claim, stop, error, landed);
|
|
578
|
+
await endRefused(claim, stop, error, landed, cost);
|
|
574
579
|
return false;
|
|
575
580
|
}
|
|
576
581
|
};
|
|
@@ -597,14 +602,14 @@ export function startRunner(options) {
|
|
|
597
602
|
* 11 tries at the cap): 6 growing waits (5 s to 160 s, 315 s in all), then 11 of 5 min, so about an hour (3,615 s) of
|
|
598
603
|
* retries, and the 18th refusal gives up.
|
|
599
604
|
*/
|
|
600
|
-
const endRefused = async (claim, stop, refused, landed) => {
|
|
605
|
+
const endRefused = async (claim, stop, refused, landed, cost) => {
|
|
601
606
|
const tries = await store.retry(claim, stop.id);
|
|
602
607
|
const why = message(refused.cause);
|
|
603
608
|
if (tries >= endRetryCapFrom + endRetryAtCap) {
|
|
604
609
|
emit({ type: "error", runId: claim.runId, step: "end", message: `run ${claim.runId} ended without withdrawing: journal unreadable or refusing (after ${tries} tries; the last: ${why})` });
|
|
605
610
|
// On its row alone, so no outcome 'stopped' (endRun): a run whose journal never took its end is never reopened.
|
|
606
611
|
const end = stopEnd(stop.kind === "cancel");
|
|
607
|
-
await store.runs.update(claim, { state: end.state, summary: redact(end.summary), ...(end.outcome === "cancelled" ? { outcome: end.outcome } : {}), ...(await censusFor(claim.runId)) }, { take: [stop.id] });
|
|
612
|
+
await store.runs.update(claim, { state: end.state, summary: redact(end.summary), ...(end.outcome === "cancelled" ? { outcome: end.outcome } : {}), ...cost, ...(await censusFor(claim.runId)) }, { take: [stop.id] });
|
|
608
613
|
landed();
|
|
609
614
|
await releaseStopped(claim, stop);
|
|
610
615
|
return;
|
|
@@ -647,16 +652,33 @@ export function startRunner(options) {
|
|
|
647
652
|
return true;
|
|
648
653
|
}
|
|
649
654
|
};
|
|
655
|
+
/** What the run under `claim` booked in its journal, as an end stores its cost (metrics.ts endCostOf, the rule every end
|
|
656
|
+
* stores by, over its booking as learning-end.ts reads it): a figure, or a bound when a cut request's hold is counted
|
|
657
|
+
* in it. A request an earlier claim left out is booked first, cut at its hold, as a loop's booking books it before it
|
|
658
|
+
* sends anything (book-cut.ts). Undefined when the journal cannot be read: the end then stores no cost, as it did. */
|
|
659
|
+
const bookedOf = async (claim) => {
|
|
660
|
+
try {
|
|
661
|
+
await bookCutRequests(store.journal(claim), BACKGROUND_CONTEXT, () => store.flush());
|
|
662
|
+
const entries = inLogOrder(await journalEntries(store.journal(claim), BACKGROUND_CONTEXT));
|
|
663
|
+
return endCostOf(runCostOf(entries, { unbooked: isCliRecord(entries) && cliModelWorked(entries) }));
|
|
664
|
+
}
|
|
665
|
+
catch {
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
668
|
+
};
|
|
650
669
|
/** A claim of a run whose stopped end was refused (its untaken stop row has tries): it only ends the run, with no loop,
|
|
651
|
-
* so no turn, model request or tool runs on a run that is stopping.
|
|
652
|
-
|
|
670
|
+
* so no turn, model request or tool runs on a run that is stopping. `booked`: a learning child past its deadline, which
|
|
671
|
+
* an earlier claim's loop may have spent on before its runner went (its spend booked in its journal): its end stores
|
|
672
|
+
* that booking as its cost (bookedOf), so what it spent stays its run's, never an unknown no read heals. */
|
|
673
|
+
const endRetried = async (claim, stop, booked = false) => {
|
|
653
674
|
// Renewed with the held claims (renewAll) until its end lands: its end waits for the run's census too.
|
|
654
675
|
const only = { claim, landed: false, renewing: false };
|
|
655
676
|
endOnly.add(only);
|
|
656
677
|
try {
|
|
657
678
|
// A run stopped before any loop started still has its one start line, ahead of its end.
|
|
658
679
|
await announceStart(claim);
|
|
659
|
-
|
|
680
|
+
const cost = booked ? await bookedOf(claim) : undefined;
|
|
681
|
+
if (await endStopped(claim, stop, () => (only.landed = true), cost))
|
|
660
682
|
await releaseStopped(claim, stop);
|
|
661
683
|
}
|
|
662
684
|
catch (error) {
|
|
@@ -671,6 +693,7 @@ export function startRunner(options) {
|
|
|
671
693
|
const stoppedBefore = held.stopping;
|
|
672
694
|
held.ending = true;
|
|
673
695
|
clock.clearTimeout(held.deadline);
|
|
696
|
+
clearTimeout(held.learningTimer);
|
|
674
697
|
const { claim } = held;
|
|
675
698
|
// The runner's own end of the run, once its write lands: the claim is renewed until then (renewAll), no further.
|
|
676
699
|
const landed = () => {
|
|
@@ -743,8 +766,11 @@ export function startRunner(options) {
|
|
|
743
766
|
// A run let go unfinished says why on its claim's attempt (run_attempts cut): a runner's close drained it, or its
|
|
744
767
|
// loop ended interrupted on its own and the run is tried again. The next claim works its turn again.
|
|
745
768
|
const cut = end.state !== "interrupted" ? undefined : closedItself ? "retry" : held.stoppedFor === "shutdown" ? "drain" : undefined;
|
|
769
|
+
const wakeAt = end.state === "parked" ? parkedWake(held, end.wakeAt) : undefined;
|
|
746
770
|
await release(claim, {
|
|
747
|
-
|
|
771
|
+
// Parked again with nothing written (LoopEnd `again`): the release parks the row, its words left as they stood.
|
|
772
|
+
...(end.state === "parked" && end.again ? { state: "parked" } : {}),
|
|
773
|
+
...(wakeAt !== undefined ? { wakeAt }
|
|
748
774
|
: inARow > 0 ? { backoffUntil: now() + interruptBackoffMs * 2 ** Math.min(inARow - 1, 6) }
|
|
749
775
|
: {}),
|
|
750
776
|
...(cut ? { cut } : {}),
|
|
@@ -768,10 +794,18 @@ export function startRunner(options) {
|
|
|
768
794
|
}
|
|
769
795
|
}
|
|
770
796
|
};
|
|
797
|
+
/** When parked run `held` wakes: its loop's `wakeAt`, or a learning child's deadline when sooner, so a child parked
|
|
798
|
+
* (for an approval, a raise) is claimed again at its deadline and ends there (claimMore's overdue claim), never left
|
|
799
|
+
* parked past it holding its copy of its run's key, its run's learning_work running. The learning clock is the store's
|
|
800
|
+
* but in a test. */
|
|
801
|
+
const parkedWake = (held, wakeAt) => held.learningDeadline === undefined ? wakeAt : wakeAt === undefined ? held.learningDeadline : Math.min(wakeAt, held.learningDeadline);
|
|
771
802
|
/** A parked run's resume that threw: one more try on the row that woke it, released parked with a backoff; after
|
|
772
|
-
* `resumeTries`, that row refused with why and the run released parked with nothing to wake it
|
|
803
|
+
* `resumeTries`, that row refused with why and the run released parked with nothing to wake it but a learning child's
|
|
804
|
+
* deadline (parkedWake). */
|
|
773
805
|
const resumeFailed = async (held, why) => {
|
|
774
806
|
const { claim } = held;
|
|
807
|
+
const wake = parkedWake(held, undefined);
|
|
808
|
+
const wakeAt = wake === undefined ? {} : { wakeAt: wake };
|
|
775
809
|
const untaken = (await store.commands(claim.runId, 0)).filter((row) => row.takenAt === null);
|
|
776
810
|
const stop = endingRow(untaken);
|
|
777
811
|
const woke = untaken[0];
|
|
@@ -790,22 +824,26 @@ export function startRunner(options) {
|
|
|
790
824
|
await store.take(claim, woke.id, "refused", reason);
|
|
791
825
|
emit({ type: "refused", runId: claim.runId, commandId: woke.id, reason });
|
|
792
826
|
await store.flush();
|
|
793
|
-
await release(claim, { state: "parked" });
|
|
827
|
+
await release(claim, { state: "parked", ...wakeAt });
|
|
794
828
|
}
|
|
795
829
|
else {
|
|
796
830
|
await store.flush();
|
|
797
|
-
await release(claim, { state: "parked", backoffUntil: now() + resumeBackoffMs * 2 ** (tries - 1) });
|
|
831
|
+
await release(claim, { state: "parked", ...wakeAt, backoffUntil: now() + resumeBackoffMs * 2 ** (tries - 1) });
|
|
798
832
|
}
|
|
799
833
|
}
|
|
800
834
|
else {
|
|
801
835
|
await store.flush();
|
|
802
|
-
await release(claim, { state: "parked" });
|
|
836
|
+
await release(claim, { state: "parked", ...wakeAt });
|
|
803
837
|
}
|
|
804
838
|
emit({ type: "released", runId: claim.runId, epoch: claim.epoch, end: "parked" });
|
|
805
839
|
};
|
|
806
|
-
|
|
840
|
+
/** Holds `claim` and starts its loop. `learningDeadline`: a learning child's deadline, read at its claim
|
|
841
|
+
* (learningDeadlinesOf), at which its loop sends no model request more and the runner cancels it if still at work
|
|
842
|
+
* (cancelOverdue). */
|
|
843
|
+
const hold = (claim, sentAt, mib = 0, learningDeadline) => {
|
|
807
844
|
const fence = { lost: false };
|
|
808
845
|
const abort = new AbortController();
|
|
846
|
+
const pastDeadline = learningDeadline === undefined ? undefined : new AbortController();
|
|
809
847
|
let firstDelivered;
|
|
810
848
|
const delivered = new Promise((resolve) => (firstDelivered = resolve));
|
|
811
849
|
// Set below, once held is made: the loop's end commit lands only after start(), well after.
|
|
@@ -819,6 +857,7 @@ export function startRunner(options) {
|
|
|
819
857
|
journal: (forClaim) => fenced(store.journal(forClaim), fence, forClaim.runId, () => ending()),
|
|
820
858
|
flush: () => store.flush(),
|
|
821
859
|
signal: abort.signal,
|
|
860
|
+
...(pastDeadline ? { pastDeadline: pastDeadline.signal } : {}),
|
|
822
861
|
delivered,
|
|
823
862
|
// A delivery under way first (its rows are the loop's already), then one more read of the run's new rows.
|
|
824
863
|
deliverNow: async () => {
|
|
@@ -829,16 +868,18 @@ export function startRunner(options) {
|
|
|
829
868
|
},
|
|
830
869
|
redact,
|
|
831
870
|
});
|
|
832
|
-
const held = { passed: new Set(), claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, landed: false, sealed: false, renewing: false, delivering: false, deliverAgain: false, mib };
|
|
871
|
+
const held = { passed: new Set(), claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, landed: false, sealed: false, renewing: false, delivering: false, deliverAgain: false, mib, ...(learningDeadline !== undefined && pastDeadline ? { learningDeadline, pastDeadline } : {}) };
|
|
833
872
|
heldNow = held;
|
|
834
873
|
// The loop's own end landed: the run is ending from here, its teardown included (no renew, no lost claim).
|
|
835
874
|
ending = () => {
|
|
836
875
|
held.ending = true;
|
|
837
876
|
held.landed = true;
|
|
838
877
|
clock.clearTimeout(held.deadline);
|
|
878
|
+
clearTimeout(held.learningTimer);
|
|
839
879
|
};
|
|
840
880
|
runs.set(claim.runId, held);
|
|
841
881
|
armDeadline(held, deadlineOf(claim, sentAt));
|
|
882
|
+
armLearningDeadline(held);
|
|
842
883
|
emit({ type: "claimed", claim });
|
|
843
884
|
void announceStart(claim);
|
|
844
885
|
held.done = (async () => {
|
|
@@ -977,13 +1018,41 @@ export function startRunner(options) {
|
|
|
977
1018
|
// One read of those claims' rows, made only when the batch has a queued or a released run.
|
|
978
1019
|
const reread = claims.filter((claim) => claim.from === "queued" || claim.from === "running" || claim.from === "parked");
|
|
979
1020
|
const rows = reread.length ? await store.commandsOf(reread.map((claim) => ({ runId: claim.runId, after: 0 }))) : new Map();
|
|
1021
|
+
// The learning children's deadlines among the batch, one read for all of it (learningDeadlinesOf), before any loop
|
|
1022
|
+
// starts on one: a batch whose read failed is given back whole, for a later claim to read again; a child at or past
|
|
1023
|
+
// its deadline on the learning clock only ends, cancelled as a person's cancel ends an unstarted run, so nothing of it
|
|
1024
|
+
// spends past the bound its run's caller was promised (learning_work.deadline_at).
|
|
1025
|
+
const deadlines = await learningDeadlinesOf(claims);
|
|
980
1026
|
for (const claim of claims) {
|
|
981
|
-
|
|
982
|
-
|
|
1027
|
+
if (!(deadlines instanceof Map)) {
|
|
1028
|
+
emit({ type: "error", runId: claim.runId, step: "learning deadline", message: deadlines.unread });
|
|
1029
|
+
await release(claim, {}).then(() => emit({ type: "handed-back", runId: claim.runId, epoch: claim.epoch, cause: "give_back" }), () => { });
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
const deadline = deadlines.get(claim.runId);
|
|
1033
|
+
const overdue = deadline !== undefined && learningClock() >= deadline;
|
|
1034
|
+
let stop = endingRow((rows.get(claim.runId) ?? []).filter((row) => row.takenAt === null));
|
|
1035
|
+
if (overdue && stop?.kind !== "cancel") {
|
|
1036
|
+
emit({ type: "learning-deadline", runId: claim.runId });
|
|
1037
|
+
const cancelled = await sendCommand(store, claim.runId, { kind: "cancel", body: {} }).then(() => true, (error) => {
|
|
1038
|
+
emit({ type: "error", runId: claim.runId, step: "learning deadline", message: message(error) });
|
|
1039
|
+
return false;
|
|
1040
|
+
});
|
|
1041
|
+
if (!cancelled) {
|
|
1042
|
+
await release(claim, {}).catch(() => { });
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
stop = endingRow((await store.commands(claim.runId, 0)).filter((row) => row.takenAt === null));
|
|
1046
|
+
if (!stop) {
|
|
1047
|
+
await release(claim, {}).catch(() => { });
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const endsOnly = stop !== undefined && (overdue || claim.from === "queued" || stop.tries > 0 || (claim.from === "running" && (await neverStarted(claim))) || (claim.from === "parked" && (await keptElsewhere(claim))));
|
|
983
1052
|
if (stop && endsOnly && !closed && !killed && !runs.has(claim.runId)) {
|
|
984
1053
|
const key = `${claim.runId}:${claim.epoch}`;
|
|
985
1054
|
endingClaims.add(key);
|
|
986
|
-
const ending = endRetried(claim, stop);
|
|
1055
|
+
const ending = endRetried(claim, stop, overdue);
|
|
987
1056
|
endings.add(ending);
|
|
988
1057
|
void ending.finally(() => {
|
|
989
1058
|
endings.delete(ending);
|
|
@@ -1005,7 +1074,7 @@ export function startRunner(options) {
|
|
|
1005
1074
|
replaced.add(before);
|
|
1006
1075
|
void before.done.finally(() => replaced.delete(before));
|
|
1007
1076
|
}
|
|
1008
|
-
hold(claim, sentAt, weights.get(claim.runId) ?? 0);
|
|
1077
|
+
hold(claim, sentAt, weights.get(claim.runId) ?? 0, deadline);
|
|
1009
1078
|
}
|
|
1010
1079
|
catch (error) {
|
|
1011
1080
|
// The loop could not be made: the run fails here, so it is not claimed again and again.
|
|
@@ -1089,12 +1158,76 @@ export function startRunner(options) {
|
|
|
1089
1158
|
let claiming;
|
|
1090
1159
|
/** A run was queued while a poll was in flight (claimNow): one more poll follows that poll's end at once. */
|
|
1091
1160
|
let pollAgain = false;
|
|
1161
|
+
/** The learning deadlines of the learning children among a poll's `claims` (a check's replay, an audit's shadow: each
|
|
1162
|
+
* its launch's, learning-work.ts LEARNING_CHILD_MS), in one read for the whole batch (store.runs.learningDeadlines),
|
|
1163
|
+
* before any loop starts on one: a run that is no learning child is absent, and a store without that read or without
|
|
1164
|
+
* commands (a test's) has none. `{ unread }` when the read failed: the batch is given back for a later claim to read
|
|
1165
|
+
* again. */
|
|
1166
|
+
const learningDeadlinesOf = async (claims) => {
|
|
1167
|
+
if (claims.length === 0 || !store.runs.learningDeadlines || !store.command)
|
|
1168
|
+
return new Map();
|
|
1169
|
+
try {
|
|
1170
|
+
return await store.runs.learningDeadlines(claims.map((claim) => claim.runId));
|
|
1171
|
+
}
|
|
1172
|
+
catch (error) {
|
|
1173
|
+
return { unread: message(error) };
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
/** Held learning child `held` at its deadline on the learning clock: its loop sends no model request more (its
|
|
1177
|
+
* pastDeadline signal, which its request gate reads before each), and it is cancelled as a person's cancel is (a cancel
|
|
1178
|
+
* row, its loop's ordinary stop: its spend booked once at its end, its copy of a key erased by that end's write), that
|
|
1179
|
+
* row handed to its loop at once, never at the next command tick. Serve has no run deadline, so this is what bounds a
|
|
1180
|
+
* learning child's spend on its run's key (learning_work.deadline_at). A cancel not written is tried again at the next
|
|
1181
|
+
* poll (endOverdue); its gate stays shut meanwhile. */
|
|
1182
|
+
const cancelOverdue = (held) => {
|
|
1183
|
+
if (held.overdue || held.ending || held.fence.lost)
|
|
1184
|
+
return;
|
|
1185
|
+
held.overdue = true;
|
|
1186
|
+
held.pastDeadline?.abort();
|
|
1187
|
+
emit({ type: "learning-deadline", runId: held.claim.runId });
|
|
1188
|
+
if (!store.command)
|
|
1189
|
+
return;
|
|
1190
|
+
void sendCommand(store, held.claim.runId, { kind: "cancel", body: {} }).then(() => {
|
|
1191
|
+
if (held.sealed || !delivering())
|
|
1192
|
+
return;
|
|
1193
|
+
if (held.delivering)
|
|
1194
|
+
held.deliverAgain = true;
|
|
1195
|
+
else
|
|
1196
|
+
void deliver(held);
|
|
1197
|
+
}, (error) => {
|
|
1198
|
+
// Final already: it ended on its own.
|
|
1199
|
+
if (error instanceof RunFinal)
|
|
1200
|
+
return;
|
|
1201
|
+
held.overdue = false;
|
|
1202
|
+
emit({ type: "error", runId: held.claim.runId, step: "learning deadline", message: message(error) });
|
|
1203
|
+
});
|
|
1204
|
+
};
|
|
1205
|
+
/** Held learning child `held`'s deadline, on the learning clock: cancelOverdue at it, by a timer on its own (re-armed
|
|
1206
|
+
* while the deadline is past a timer's longest wait), so neither waits for a poll. */
|
|
1207
|
+
const armLearningDeadline = (held) => {
|
|
1208
|
+
if (held.learningDeadline === undefined || held.ending || held.sealed)
|
|
1209
|
+
return;
|
|
1210
|
+
const wait = held.learningDeadline - learningClock();
|
|
1211
|
+
if (wait <= 0)
|
|
1212
|
+
return cancelOverdue(held);
|
|
1213
|
+
// Unref'd: a runner killed with the child held (a crash) leaves nothing that keeps its process up.
|
|
1214
|
+
held.learningTimer = setTimeout(() => armLearningDeadline(held), Math.min(wait, MAX_TIMER_MS)).unref();
|
|
1215
|
+
};
|
|
1216
|
+
/** Every held learning child at its deadline on the learning clock (cancelOverdue), swept at each poll: the timer's
|
|
1217
|
+
* backstop, and a cancel that was not written tried again. */
|
|
1218
|
+
const endOverdue = () => {
|
|
1219
|
+
const at = learningClock();
|
|
1220
|
+
for (const held of runs.values())
|
|
1221
|
+
if (held.learningDeadline !== undefined && at >= held.learningDeadline)
|
|
1222
|
+
cancelOverdue(held);
|
|
1223
|
+
};
|
|
1092
1224
|
const poll = () => {
|
|
1093
1225
|
if (closed || killed)
|
|
1094
1226
|
return;
|
|
1095
1227
|
clearTimeout(pollTimer);
|
|
1096
1228
|
pollAgain = false;
|
|
1097
1229
|
beat();
|
|
1230
|
+
endOverdue();
|
|
1098
1231
|
const claimed = claimMore();
|
|
1099
1232
|
claiming = claimed;
|
|
1100
1233
|
void claimed.finally(() => {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type Store } from "../store/store.js";
|
|
2
2
|
export type RunnerStore = Pick<Store, "leaseClock" | "claim" | "renew" | "renewMany" | "release" | "journal" | "flush" | "commands" | "commandsOf" | "take" | "retry" | "watchCommands"> & {
|
|
3
|
-
readonly runs: Pick<Store["runs"], "claimMany" | "claimable" | "claimsOf" | "update"> & Partial<Pick<Store["runs"], "launch" | "get">>;
|
|
3
|
+
readonly runs: Pick<Store["runs"], "claimMany" | "claimable" | "claimsOf" | "update"> & Partial<Pick<Store["runs"], "launch" | "get" | "learningDeadlines">>;
|
|
4
4
|
/** The revision's kind, read for a run's start line (runner.ts). A store without it (a test's) says no start or end line. */
|
|
5
5
|
readonly agents?: Pick<Store["agents"], "revision">;
|
|
6
|
+
/** Writes a command row: the cancel of a learning child at its deadline (runner.ts cancelOverdue). A store without
|
|
7
|
+
* it (a test's) cancels none. */
|
|
8
|
+
readonly command?: Store["command"];
|
|
6
9
|
/** The runs' live view (run_live): the runner's live ticker writes each run's held state there. A store without it (a
|
|
7
10
|
* test's) has no live view. */
|
|
8
11
|
readonly live?: Store["live"];
|
|
@@ -6,7 +6,8 @@ import type { EntryLike } from "../timeline/index.js";
|
|
|
6
6
|
* platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
|
|
7
7
|
* crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
|
|
8
8
|
* before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
|
|
9
|
-
* call id (bookedUnder)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* call id (bookedUnder) and every attempt of it its gate let go was closed by a refusal (openAttempts); one an attempt
|
|
10
|
+
* ran or spent under (a crash cut it, and its rerun was refused: at its gate, at runLearned's check of its call nodes'
|
|
11
|
+
* tools, or the platform's at serveFirst) is `failed`, at what it booked (callUsdOf: null on a shared or unpriced
|
|
12
|
+
* window, and null for an attempt cut past its record). A record that names no digest or caller is left out. */
|
|
12
13
|
export declare function workflowCallsOf(entries: readonly EntryLike[]): WorkflowCall[];
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// read: a run the platform served first counts on that workflow's served side alone, one only the agent called on the
|
|
6
6
|
// side of each workflow it ran (workflow-first.ts costLineOf), and a call refused before any node ran on none.
|
|
7
7
|
import { WORKFLOW_CALLERS } from "../learning-cost.js";
|
|
8
|
-
import { learnedCallEntries } from "../learned-nodes.js";
|
|
8
|
+
import { LEARNED_ALLOWED, LEARNED_NODES, learnedCallEntries } from "../learned-nodes.js";
|
|
9
9
|
import { KINDS } from "./journal-kinds.js";
|
|
10
10
|
import { callCostOf, callTurnsOf } from "./metrics.js";
|
|
11
11
|
import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
@@ -128,11 +128,35 @@ function callUsdOf(entries, callId, recordAt) {
|
|
|
128
128
|
const window = callWindowOf(entries, callId, recordAt);
|
|
129
129
|
return window ? callCostOf(entries, callId, window.from, window.to) : null;
|
|
130
130
|
}
|
|
131
|
-
/** Whether anything was booked under call `callId` (runner/metrics.ts callTurnsOf): a request named under it,
|
|
132
|
-
* host work in its window while that window is its alone. */
|
|
131
|
+
/** Whether anything was booked under call `callId` (runner/metrics.ts callTurnsOf, as proof): a request named under it,
|
|
132
|
+
* or one of host work in its window while that window is its alone, never the harness's own side request there. */
|
|
133
133
|
function bookedUnder(entries, callId, recordAt) {
|
|
134
134
|
const window = callWindowOf(entries, callId, recordAt);
|
|
135
|
-
return callTurnsOf(entries, callId, window?.from ?? -1, window?.to ?? -1).size > 0;
|
|
135
|
+
return callTurnsOf(entries, callId, window?.from ?? -1, window?.to ?? -1, true).size > 0;
|
|
136
|
+
}
|
|
137
|
+
/** The attempts of an agent's learned_workflow call `callId` its gate let go (each allow mark, LEARNED_ALLOWED) that no
|
|
138
|
+
* refused record of it closed. A mark is closed by the call's next record before its next mark when that record is
|
|
139
|
+
* `refused` (refused at runLearned's check: it ran nothing); a record that says it ran, a next mark first (a crash cut
|
|
140
|
+
* the attempt before it kept a record) or none at all leaves it open: that attempt may have run and spent. `open`:
|
|
141
|
+
* any is. `cut`: the newest is open with no record after it, so what it spent lies past every record's window. The
|
|
142
|
+
* marks need no window, so this holds where a sibling call shares the call's window and its model nodes' spend, booked
|
|
143
|
+
* under a host label and no call id, can't be told for its own. */
|
|
144
|
+
function openAttempts(entries, callId) {
|
|
145
|
+
let open = false;
|
|
146
|
+
let pending = false;
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
if (dataOf(entry).call !== callId)
|
|
149
|
+
continue;
|
|
150
|
+
if (entry.kind === LEARNED_ALLOWED) {
|
|
151
|
+
open ||= pending;
|
|
152
|
+
pending = true;
|
|
153
|
+
}
|
|
154
|
+
else if (entry.kind === LEARNED_NODES && pending) {
|
|
155
|
+
open ||= dataOf(entry).refused !== true;
|
|
156
|
+
pending = false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { open: open || pending, cut: pending };
|
|
136
160
|
}
|
|
137
161
|
/** Each learned workflow call run `entries` show (every conversation's, in log order: store-reads/journal.ts runEntries),
|
|
138
162
|
* in the order the calls first kept a record, from the record that counts for each (a call run again after a park or a
|
|
@@ -140,9 +164,10 @@ function bookedUnder(entries, callId, recordAt) {
|
|
|
140
164
|
* platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
|
|
141
165
|
* crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
|
|
142
166
|
* before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
|
|
143
|
-
* call id (bookedUnder)
|
|
144
|
-
*
|
|
145
|
-
*
|
|
167
|
+
* call id (bookedUnder) and every attempt of it its gate let go was closed by a refusal (openAttempts); one an attempt
|
|
168
|
+
* ran or spent under (a crash cut it, and its rerun was refused: at its gate, at runLearned's check of its call nodes'
|
|
169
|
+
* tools, or the platform's at serveFirst) is `failed`, at what it booked (callUsdOf: null on a shared or unpriced
|
|
170
|
+
* window, and null for an attempt cut past its record). A record that names no digest or caller is left out. */
|
|
146
171
|
export function workflowCallsOf(entries) {
|
|
147
172
|
// The record that counts for each call (learned-nodes.ts learnedCallEntries): a rerun refused before any node ran leaves
|
|
148
173
|
// the attempt that ran standing, as the call's timeline row does.
|
|
@@ -153,12 +178,16 @@ export function workflowCallsOf(entries) {
|
|
|
153
178
|
const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && ["answered", "handed_back"].includes(String(entry.data?.outcome)))?.data;
|
|
154
179
|
const calls = [...newest].map(([call, at]) => {
|
|
155
180
|
const data = dataOf(entries[at]);
|
|
156
|
-
// Refused before any node ran (its record's `refused`) with nothing booked under its id
|
|
157
|
-
// run did after. Refused with something booked
|
|
158
|
-
|
|
181
|
+
// Refused before any node ran (its record's `refused`) with nothing booked under its id and every attempt its gate let
|
|
182
|
+
// go closed by a refusal: it ran nothing, whatever the run did after. Refused with something booked, or with an
|
|
183
|
+
// attempt left open (openAttempts): that attempt ran and may have spent, so it failed.
|
|
184
|
+
const attempts = data.refused === true ? openAttempts(entries, call) : { open: false, cut: false };
|
|
185
|
+
const refused = data.refused === true && !bookedUnder(entries, call, at) && !attempts.open;
|
|
159
186
|
const outcome = refused ? "refused" : data.refused === true ? "failed" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
|
|
160
|
-
// A refused call ran nothing: its $ is 0, never a shared window's unknown (two denied calls in one pi answer).
|
|
161
|
-
|
|
187
|
+
// A refused call ran nothing: its $ is 0, never a shared window's unknown (two denied calls in one pi answer). One an
|
|
188
|
+
// attempt cut past its record failed at a cost its record's window can't hold: unknown.
|
|
189
|
+
const usd = refused ? 0 : attempts.cut ? null : callUsdOf(entries, call, at);
|
|
190
|
+
return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd };
|
|
162
191
|
});
|
|
163
192
|
if (served && !newest.has(WORKFLOW_FIRST_CALL) && typeof served.workflow === "string" && typeof served.digest === "string") {
|
|
164
193
|
calls.unshift({ workflow: served.workflow, digest: served.digest, caller: "platform", outcome: served.outcome, usd: null });
|
|
@@ -391,15 +391,16 @@ export function pathMetrics(launch, classified, entries = [], choice) {
|
|
|
391
391
|
const chose = choice ? { first_choice: choice } : {};
|
|
392
392
|
if (launch.replay) {
|
|
393
393
|
// A replay run (runner/promotion.ts): path `replay`, whatever its workflow did, so the money rule and the agent's
|
|
394
|
-
// by-hand cost never read it; how its workflow ended, for the replay's score (learn/promote.ts ReplayRow)
|
|
395
|
-
|
|
394
|
+
// by-hand cost never read it; how its workflow ended, for the replay's score (learn/promote.ts ReplayRow); and the run
|
|
395
|
+
// whose own key it spent on (`paid_by`), whose learning its cost is (learn/ledger.ts record).
|
|
396
|
+
const { of, workflow: name, digest: at, paidBy } = launch.replay;
|
|
396
397
|
// Handed back when the workflow ended escalated (an escalate node: the workflow knowing its limits), however
|
|
397
398
|
// many of its nodes failed on the way and were recovered (a map's collected item); a workflow that itself ended failed
|
|
398
399
|
// (a credential or tool the replay ran without, a step's output off its schema), or was refused, is failed: no
|
|
399
400
|
// evidence. Skipped when a write it needed is not in the graded run's recording (learn/replay-calls.ts): never run.
|
|
400
401
|
const skipped = replaySkippedIn(entries);
|
|
401
402
|
const outcome = skipped ? "skipped_write" : path === "workflow" && workflow === name ? "answered" : path === "handed_back" && workflow === name && endedIn(entries, name) === "escalated" ? "handed_back" : "failed";
|
|
402
|
-
return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, ...chose, replay: { of, outcome, ...(skipped ? { skipped } : {}), ...verdict } };
|
|
403
|
+
return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, ...chose, replay: { of, ...(paidBy ? { paid_by: paidBy } : {}), outcome, ...(skipped ? { skipped } : {}), ...verdict } };
|
|
403
404
|
}
|
|
404
405
|
// A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
|
|
405
406
|
const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
|
|
@@ -133,7 +133,10 @@ function workflowLoop(specOf, deps) {
|
|
|
133
133
|
takingDone = true;
|
|
134
134
|
if (raising.takes.length === 0)
|
|
135
135
|
return;
|
|
136
|
-
|
|
136
|
+
// The pause the raises answered: the one the newest raise was checked against (lastRaise), as the agentic loop records
|
|
137
|
+
// it. A retry of a raise taken before changes nothing, so it names that raise's pause, never a pause the run stands at
|
|
138
|
+
// since, which would read as answered and let the held step run into the same cap again.
|
|
139
|
+
const data = { capUsd: raising.capUsd ?? raising.state?.capUsd ?? 0, takes: raising.takes, ...(raising.state?.lastRaise?.pause ? { pause: raising.state.lastRaise.pause } : {}) };
|
|
137
140
|
await append(journal, context, KINDS.raise, data, { ...(raising.resumes ? { run: { summary: null } } : {}), take: raising.takes });
|
|
138
141
|
};
|
|
139
142
|
/** Whether the run is paused by its journal: its newest pause entry has no resume entry after it. */
|
|
@@ -230,6 +233,15 @@ function workflowLoop(specOf, deps) {
|
|
|
230
233
|
// A paused run (or one a pause row woke) parks again here, before any step runs; a resume goes on.
|
|
231
234
|
if (await takePauses(claim, deps.journal(claim), BACKGROUND_CONTEXT))
|
|
232
235
|
return { state: "parked" };
|
|
236
|
+
// Paused at its cap by its journal, and no raise of this claim resumed it (each refused, or a retry of one before): its
|
|
237
|
+
// pause stands, its budget entry unanswered, so it parks again on that entry with nothing written, before any step
|
|
238
|
+
// runs. Run, the held step would meet the same cap and write a second budget entry at it. Whatever the row said at the
|
|
239
|
+
// claim: a woken claim lost before its release leaves the row running with the pause unanswered. A person's stop goes
|
|
240
|
+
// on to end the run. A run whose root is not made yet (its first claim) has no pause to read.
|
|
241
|
+
const paused = async (journal) => Boolean(await journal.conversation(ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT)) && (await raiseStateOf(journal, BACKGROUND_CONTEXT)).pause !== undefined;
|
|
242
|
+
if ((claim.from === "parked" || spec?.cap !== undefined) && !raising.resumes && stopReason === undefined && (await paused(deps.journal(claim)))) {
|
|
243
|
+
return { state: "parked", again: true };
|
|
244
|
+
}
|
|
233
245
|
const hooks = {
|
|
234
246
|
park: (refusal) => { heldRefusal ??= refusal; parkController.abort(); },
|
|
235
247
|
paused: pauseInForce,
|
|
@@ -280,7 +280,7 @@ export function workflowSpecOf(deps) {
|
|
|
280
280
|
const nodeTools = new Map();
|
|
281
281
|
for (const [name, binding] of nodeBindings) {
|
|
282
282
|
const booked = bookedNodeTools(binding, () => paidTools, parkAt);
|
|
283
|
-
const tools =
|
|
283
|
+
const tools = booked.tools.map((tool) => answersCutInside(tool, redact));
|
|
284
284
|
nodeTools.set(name, { tools, extensions: [defineExtension({ name: `node-tool-${name}`, tools: tools })] });
|
|
285
285
|
}
|
|
286
286
|
const nodePolicy = callPolicyOf(deps.store, claim.runId, claimed);
|
package/dist/secret-cut.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ export type ScrubOptions = {
|
|
|
43
43
|
/** The shell command whose output `text` is, when the caller knows it (a tool call's, ruling LVI): a command that reads
|
|
44
44
|
* one file alone (`cat ~/.pgpass`) gives `path` when none is given, and an env command's output is a dump. */
|
|
45
45
|
readonly command?: string;
|
|
46
|
+
/** `text` is lines flattened onto one, every run of blanks made a space (a run's title: runs-over-store.ts
|
|
47
|
+
* prepareLaunch): a prompt inside the line opens a command as a line's start would, and an env command's output
|
|
48
|
+
* runs on after it to the next prompt (env-dump). */
|
|
49
|
+
readonly flattened?: boolean;
|
|
46
50
|
/** The homes the caller holds (rulings E, VII): a bare `/home/<user>` with no segment after it, or a Claude project
|
|
47
51
|
* folder's `-home-<user>-` outside `.claude/projects/`, is cut only for one of these. When not given, this process's
|
|
48
52
|
* user's home and $HOME. */
|
package/dist/secret-cut.js
CHANGED
|
@@ -374,7 +374,7 @@ export function processHomes() {
|
|
|
374
374
|
* finds in the view (one pass a view, on first ask). */
|
|
375
375
|
function contextOf(view, opts) {
|
|
376
376
|
let lint;
|
|
377
|
-
return { held: heldOf(opts), source: view.source, homes: opts.homes ?? processHomes(), path: opts.path ?? commandReadPath(opts.command), command: opts.command, lint: () => (lint ??= lintFinds(view.text)), lines: lineBounds(view.text, ...view.decodedStrings, view.strings) };
|
|
377
|
+
return { held: heldOf(opts), source: view.source, homes: opts.homes ?? processHomes(), path: opts.path ?? commandReadPath(opts.command), command: opts.command, flattened: opts.flattened === true, lint: () => (lint ??= lintFinds(view.text)), lines: lineBounds(view.text, ...view.decodedStrings, view.strings) };
|
|
378
378
|
}
|
|
379
379
|
/** Whether a cut text holds nothing the scrub must cut: no known format the format rules still find in any view of any
|
|
380
380
|
* chunk of it (each marker read as a blank, so a marker is never one), and no held value in any form (valueMatcher:
|
package/dist/secret-rules.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export type ScrubContext = {
|
|
|
32
32
|
/** The shell command whose output the text is, when the caller knows it (ruling LVI): an env command's output is a
|
|
33
33
|
* dump though the command stands in no line of the text. */
|
|
34
34
|
readonly command?: string;
|
|
35
|
+
/** The text is lines flattened onto one (a run's title): a prompt mid-line opens a command (flatDumps). */
|
|
36
|
+
readonly flattened?: boolean;
|
|
35
37
|
readonly lint: () => Promise<readonly LintFind[]>;
|
|
36
38
|
/** Where the line holding an offset starts and ends: a line break, or a JSON string's own quote the view decoded
|
|
37
39
|
* (ruling XXVIII). Absent: line breaks alone. */
|
|
@@ -143,7 +145,6 @@ export declare const envFilePath: (path: string) => boolean;
|
|
|
143
145
|
/** A path under a .ssh folder. */
|
|
144
146
|
export declare const sshFilePath: (path: string) => boolean;
|
|
145
147
|
export declare const credentialFilePath: (path: string) => boolean;
|
|
146
|
-
export declare const commandPaths: (command: string | undefined) => string[];
|
|
147
148
|
export declare const SCRUB_RULES: readonly ScrubRule[];
|
|
148
149
|
/** Every module-level pattern the rules read, by name: secret-scrub.test.mjs walks each (redact/match.ts SECRET_SHAPES are scanners, linear by construction)
|
|
149
150
|
* and fails on an unbounded quantifier outside its allowlist, and fails on a module-level pattern missing here. */
|