@tangle-network/agent-runtime 0.271.0 → 0.273.3

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.
Files changed (67) hide show
  1. package/dist/{activation-DGbFPGR3.js → activation-Cx2dKA_l.js} +2 -2
  2. package/dist/{activation-DGbFPGR3.js.map → activation-Cx2dKA_l.js.map} +1 -1
  3. package/dist/{activation-BrJmwTLB.d.ts → activation-IfDlhR3J.d.ts} +2 -2
  4. package/dist/agent.d.ts +2 -2
  5. package/dist/agent.js +2 -2
  6. package/dist/candidate-execution/index.js +2 -2
  7. package/dist/{coordination-driver-iBGMKDvB.js → coordination-driver-CkcW4dxU.js} +155 -80
  8. package/dist/coordination-driver-CkcW4dxU.js.map +1 -0
  9. package/dist/{delegate-DOqUvaIz.js → delegate-Dvb1-mE-.js} +2 -2
  10. package/dist/{delegate-DOqUvaIz.js.map → delegate-Dvb1-mE-.js.map} +1 -1
  11. package/dist/durable.d.ts +3 -572
  12. package/dist/durable.js +92 -18
  13. package/dist/durable.js.map +1 -1
  14. package/dist/{graph-DnMcepkN.js → graph-C69Uxtzt.js} +14 -8
  15. package/dist/graph-C69Uxtzt.js.map +1 -0
  16. package/dist/{improvement-cycle-1IyRJo5h.js → improvement-cycle-CO2HRCQq.js} +4 -4
  17. package/dist/{improvement-cycle-1IyRJo5h.js.map → improvement-cycle-CO2HRCQq.js.map} +1 -1
  18. package/dist/{index-CL1dduJd.d.ts → index-D2ipSqkP.d.ts} +4318 -3102
  19. package/dist/index.d.ts +6 -450
  20. package/dist/index.js +14 -11
  21. package/dist/index.js.map +1 -1
  22. package/dist/intelligence.d.ts +3 -3
  23. package/dist/intelligence.js +5 -5
  24. package/dist/kernel.d.ts +4 -4
  25. package/dist/kernel.js +9 -9
  26. package/dist/{loop-runner-bin-BPZ9tt1W.js → loop-runner-bin-B9MIq9O7.js} +3 -3
  27. package/dist/{loop-runner-bin-BPZ9tt1W.js.map → loop-runner-bin-B9MIq9O7.js.map} +1 -1
  28. package/dist/{loop-runner-bin-O_vM1w8Y.d.ts → loop-runner-bin-ThlwVkvo.d.ts} +3 -3
  29. package/dist/loop-runner-bin.d.ts +1 -1
  30. package/dist/loop-runner-bin.js +1 -1
  31. package/dist/mcp/bin.js +3 -3
  32. package/dist/mcp/index.d.ts +5 -5
  33. package/dist/mcp/index.js +4 -4
  34. package/dist/{openai-tools-DWHxpwx2.d.ts → openai-tools-Bb0mAr5z.d.ts} +2 -2
  35. package/dist/{prepare-oHUQdC5-.js → prepare-DVlvGP7V.js} +2 -2
  36. package/dist/{prepare-oHUQdC5-.js.map → prepare-DVlvGP7V.js.map} +1 -1
  37. package/dist/profiles.d.ts +2 -2
  38. package/dist/{protected-model-port-DqF0qDU6.js → protected-model-port-BrWgsCnl.js} +2 -2
  39. package/dist/{protected-model-port-DqF0qDU6.js.map → protected-model-port-BrWgsCnl.js.map} +1 -1
  40. package/dist/{protected-redaction--F3v1oo8.js → protected-redaction-DylCC_ot.js} +14 -20
  41. package/dist/protected-redaction-DylCC_ot.js.map +1 -0
  42. package/dist/{provision-supervisor-Cy8pqE95.js → provision-supervisor-BKAvsDtP.js} +3 -3
  43. package/dist/{provision-supervisor-Cy8pqE95.js.map → provision-supervisor-BKAvsDtP.js.map} +1 -1
  44. package/dist/{runtime-DVjIH1eo.js → runtime-CHxXrUeZ.js} +2079 -1441
  45. package/dist/runtime-CHxXrUeZ.js.map +1 -0
  46. package/dist/{server-CN9vzbSe.js → server-2OeFrEVG.js} +3 -3
  47. package/dist/{server-CN9vzbSe.js.map → server-2OeFrEVG.js.map} +1 -1
  48. package/dist/{stream-agent-turn-DbEsKgb_.d.ts → stream-agent-turn-ewm3BZAp.d.ts} +15 -16
  49. package/dist/{structural-rollout-I92sIfNl.js → structural-rollout-DCUprNpH.js} +2 -2
  50. package/dist/{structural-rollout-I92sIfNl.js.map → structural-rollout-DCUprNpH.js.map} +1 -1
  51. package/dist/{substrate-CbC03Vzo.d.ts → substrate-VKjmrksz.d.ts} +2 -2
  52. package/dist/{supervise-DJ_1i9vj.js → supervise-Dej5aSDa.js} +211 -48
  53. package/dist/supervise-Dej5aSDa.js.map +1 -0
  54. package/dist/{supervisor-Cvd5mf7x.js → supervisor-DdKPGluv.js} +952 -221
  55. package/dist/supervisor-DdKPGluv.js.map +1 -0
  56. package/dist/testing.d.ts +2 -2
  57. package/dist/testing.js +60 -60
  58. package/dist/tui/index.d.ts +1 -1
  59. package/dist/tui/index.js +1 -1
  60. package/dist/{types-Bo7z5aG5.d.ts → types-DMRc3jru.d.ts} +356 -64
  61. package/package.json +5 -5
  62. package/dist/coordination-driver-iBGMKDvB.js.map +0 -1
  63. package/dist/graph-DnMcepkN.js.map +0 -1
  64. package/dist/protected-redaction--F3v1oo8.js.map +0 -1
  65. package/dist/runtime-DVjIH1eo.js.map +0 -1
  66. package/dist/supervise-DJ_1i9vj.js.map +0 -1
  67. package/dist/supervisor-Cvd5mf7x.js.map +0 -1
package/dist/durable.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { Fn as RetainedPendingCause, I as ProviderModelExecutionEvidence, J as RootStreamReceipt, P as ProfileMaterializationReceipt, U as RetainedExecutionState, at as SpendGap, i as Budget, j as NodeId, l as ExecutionBindingReceipt, lt as SupervisedResult, n as AgentExecutionRef, o as BudgetViolation, rt as Spend, xt as WorkerTraceEvidence, y as ExecutorProgressEvent } from "./types-Bo7z5aG5.js";
2
- import { Eo as SupervisorProfile, Qa as SuperviseOptions, no as supervise } from "./index-CL1dduJd.js";
3
- import { l as RuntimeHooks, o as RuntimeHookEvent, r as RuntimeDecisionPoint } from "./runtime-hooks-Bj6wJHlH.js";
4
- import { AgentCandidateLineage, AgentProfile, AgentProfileDiff, Sha256Digest } from "@tangle-network/agent-interface";
1
+ import { J as RootStreamReceipt, j as NodeId, lt as SupervisedResult, y as ExecutorProgressEvent } from "./types-DMRc3jru.js";
2
+ import { $s as VersionJudge, Bs as JudgedPursuitVersion, Cc as createFileObserverHooks, Dc as PursuitFork, Ec as FORK_PARENT_UNCERTAIN_NODES_KEY, Gs as PursuitVersionParent, Hs as NextPursuitVersionInput, Js as PursuitVersions, Ks as PursuitVersionStop, Oc as RUN_FORK_CORRELATION_KEYS, Qs as SettledPursuitVersion, Sc as ObserverRecordKind, Tc as verifyObserverRecords, Us as PURSUIT_VERSIONS_FILE, Vs as NextPursuitVersion, Ws as PreparedPursuitVersion, Xs as REVIEW_DIR, Ys as PursuitVersionsRecord, Zs as RunPursuitVersion, _c as PursuitStatus, ac as SupervisedPursuitResult, bc as ObserverJournal, cc as PursuitNodeCost, dc as PursuitNodeProjection, ec as VersionVerdict, fc as PursuitNodeTiming, gc as PursuitRunTotals, hc as PursuitRunProjection, ic as SupervisePursuitOptions, lc as PursuitNodePlacement, mc as PursuitProjection, nc as pursuitVersionRun, oc as supervisePursuit, pc as PursuitNodeUsage, qs as PursuitVersionStopReason, rc as SupervisePursuitError, sc as PursuitCostProvenance, tc as assertPursuitVersions, uc as PursuitNodePlatform, vc as projectPursuit, wc as observerRecordDigest, xc as ObserverRecord, yc as FileObserverJournal } from "./index-D2ipSqkP.js";
5
3
  //#region src/runtime/supervise/root-stream.d.ts
6
4
  /** The root stream: one JSONL line per progress event the root's executor observed. */
7
5
  declare const ROOT_STREAM_FILE = "root-stream.jsonl";
@@ -167,573 +165,6 @@ declare function deriveExecutionId(input: {
167
165
  turnIndex: number;
168
166
  }): string;
169
167
  //#endregion
170
- //#region src/durable/observer-journal.d.ts
171
- type ObserverRecordKind = 'event' | 'decision';
172
- /**
173
- * One immutable record in the observer plane. `sequence` is journal order, not
174
- * execution order; causal/runtime order remains available on the underlying event.
175
- * `previousDigest` + `digest` make deletion, reordering, or mutation detectable.
176
- */
177
- interface ObserverRecord {
178
- readonly schemaVersion: 1;
179
- readonly pursuitId: string;
180
- readonly sequence: number;
181
- readonly kind: ObserverRecordKind;
182
- readonly observedAt: number;
183
- readonly previousDigest?: string;
184
- readonly event?: RuntimeHookEvent;
185
- readonly decision?: RuntimeDecisionPoint;
186
- readonly digest: string;
187
- }
188
- interface ObserverJournal {
189
- appendEvent(event: RuntimeHookEvent): Promise<ObserverRecord>;
190
- appendDecision(point: RuntimeDecisionPoint): Promise<ObserverRecord>;
191
- read(): Promise<readonly ObserverRecord[]>;
192
- hooks(): RuntimeHooks;
193
- }
194
- /**
195
- * Durable, append-only third-person history for one concrete Runtime execution.
196
- * It consumes Runtime's existing hook stream and does not participate in execution
197
- * decisions. A broken observer therefore cannot change what an agent is allowed to do.
198
- *
199
- * The write discipline deliberately matches `FileSpawnJournal`: serialized appends,
200
- * torn-tail recovery, short-write handling, and fsync before acknowledgement. One
201
- * execution owns one journal file; higher-level pursuit aggregation joins isolated
202
- * journals by `pursuitId` instead of making independent processes share a write head.
203
- */
204
- declare class FileObserverJournal implements ObserverJournal {
205
- readonly path: string;
206
- readonly pursuitId: string;
207
- private tail;
208
- private initialized;
209
- private sequence;
210
- private previousDigest;
211
- private appendFailure;
212
- constructor(path: string, pursuitId: string);
213
- hooks(): RuntimeHooks;
214
- appendEvent(event: RuntimeHookEvent): Promise<ObserverRecord>;
215
- appendDecision(point: RuntimeDecisionPoint): Promise<ObserverRecord>;
216
- read(): Promise<readonly ObserverRecord[]>;
217
- private enqueue;
218
- private initialize;
219
- private readExistingUnsafe;
220
- private writeRecord;
221
- private assertComplete;
222
- }
223
- /** Verify identity, monotonic sequence, payload shape, and the complete digest chain. */
224
- declare function verifyObserverRecords(records: readonly ObserverRecord[], pursuitId?: string): readonly ObserverRecord[];
225
- /** Compute the canonical SHA-256 digest for an unsigned observer record. */
226
- declare function observerRecordDigest(record: Omit<ObserverRecord, 'digest'>): string;
227
- /** Build the canonical durable observer hook in one call. */
228
- declare function createFileObserverHooks(path: string, pursuitId: string): {
229
- readonly journal: FileObserverJournal;
230
- readonly hooks: RuntimeHooks;
231
- };
232
- //#endregion
233
- //#region src/durable/observer-projection.d.ts
234
- /**
235
- * One settled projection status, shared by runs and nodes. `down` is the journal's own word for a
236
- * failure (a settlement is journaled as `kind: 'down'`, cancellation included), so a consumer can
237
- * join run rows to node rows on `status` and read one failure population instead of two.
238
- */
239
- type PursuitStatus = 'running' | 'done' | 'down';
240
- /**
241
- * Where a node's dollar figure came from. `reported` = a provider billed all of it; `estimated` =
242
- * a model catalog priced all of it; `partial` = a provider billed part and a catalog priced the
243
- * rest; `unknown` = nothing priced it, so `usd` is a floor and never the cost.
244
- */
245
- type PursuitCostProvenance = 'reported' | 'estimated' | 'partial' | 'unknown';
246
- /**
247
- * One node's token usage by class. Cache and reasoning classes are absent when the provider did
248
- * not report them — absence is not zero. `tokensKnown` is `false` when work happened whose token
249
- * count no provider reported, which makes `input`/`output` a floor.
250
- */
251
- interface PursuitNodeUsage {
252
- readonly input: number;
253
- readonly output: number;
254
- readonly cacheRead?: number;
255
- readonly cacheWrite?: number;
256
- readonly reasoning?: number;
257
- readonly tokensKnown: boolean;
258
- }
259
- /**
260
- * One node's PLATFORM consumption — box wall time, the resource a subscription seat really pays.
261
- *
262
- * Kept apart from `PursuitNodeCost` because the two answer different questions and fail
263
- * independently: a seat run reports a truthful `$0` and real minutes, a caller-account run
264
- * reports real dollars and may report no minutes at all. Collapsing them into one "spend known"
265
- * figure hides which one is missing.
266
- *
267
- * Absent on a node that ran no box. `boxMinutes` absent WITH the block present says a box ran and
268
- * nothing measured it — a missing measurement is never a zero.
269
- */
270
- interface PursuitNodePlatform {
271
- readonly boxMinutes?: number;
272
- /** `false` when a box ran whose time could not be closed, so `boxMinutes` is a floor. */
273
- readonly boxMinutesKnown: boolean;
274
- /** `observed` = the platform billed the minutes; `estimated` = Runtime derived them from the box
275
- * lifetime it watched; `uncaptured` = a box ran and nothing measured it. */
276
- readonly provenance: 'observed' | 'estimated' | 'uncaptured';
277
- }
278
- /** One node's dollar cost with the provenance that decides whether it may be compared or summed. */
279
- interface PursuitNodeCost {
280
- readonly usd: number;
281
- readonly usdKnown: boolean;
282
- /** The part of `usd` a model catalog priced because no provider receipt covered it. */
283
- readonly usdEstimated?: number;
284
- readonly provenance: PursuitCostProvenance;
285
- }
286
- /**
287
- * One node's clock. `wallMs` is `settledAt - startedAt` and is deliberately distinct from the
288
- * executor-reported `spent.ms` sums, which under-report and overlap across parallel children.
289
- * `firstTokenAt` stays absent unless a provider reports that instant; it is never inferred from
290
- * `firstOutputAt`, which is when the node first reported usage for a turn.
291
- */
292
- interface PursuitNodeTiming {
293
- readonly startedAt: number;
294
- readonly firstOutputAt?: number;
295
- readonly firstTokenAt?: number;
296
- readonly settledAt?: number;
297
- readonly wallMs?: number;
298
- }
299
- /** Where and how a node's execution was placed, read off its execution-binding receipt. */
300
- type PursuitNodePlacement = Readonly<Record<string, string | number | boolean | null>>;
301
- /**
302
- * One run's spend counted once, and each node's own share of it. `inclusive` and the entries of
303
- * `exclusiveByNode` are the two views a client needs to show a tree without double counting.
304
- */
305
- interface PursuitRunTotals {
306
- /**
307
- * The whole run counted once. A node's settled `spent` already contains the child work its own
308
- * nested tree reported, so summing only the run's top-level nodes plus every node's own
309
- * inference counts each model call exactly once.
310
- */
311
- readonly inclusive: Spend;
312
- /**
313
- * Each node's own share: its reported spend and own inference minus what its direct children
314
- * reported. Keyed by node id, plus the run root when the root itself metered inference. The
315
- * entries sum to `inclusive` by construction.
316
- */
317
- readonly exclusiveByNode: Readonly<Record<string, Spend>>;
318
- }
319
- /**
320
- * One attempt at one concrete Runtime run: the stretch of `agent.run` lifecycle from a `before`
321
- * to the `after` or `error` that settles it. A run whose first attempt threw and whose corrected
322
- * attempt settled is two rows, so `error` names only the attempt that failed.
323
- *
324
- * A `before` observed while an attempt is still open does not open another: it is a process
325
- * that resumed the run after the previous process died without a terminal record, and the row
326
- * counts it in `resumeCount`. The alternative, a row per process start, would leave the killed
327
- * process's row `running` for the rest of history.
328
- */
329
- interface PursuitRunProjection {
330
- readonly runId: string;
331
- /** Zero-based position of this attempt among the run's attempts, in journal order. */
332
- readonly attemptIndex: number;
333
- /** How many times a process resumed this attempt after a predecessor died mid-run. */
334
- readonly resumeCount: number;
335
- readonly status: PursuitStatus;
336
- readonly settledAt?: number;
337
- readonly error?: string;
338
- readonly firstSequence: number;
339
- readonly lastSequence: number;
340
- readonly firstObservedAt: number;
341
- readonly lastObservedAt: number;
342
- readonly eventCount: number;
343
- readonly decisionCount: number;
344
- readonly targets: Readonly<Record<string, number>>;
345
- readonly decisions: Readonly<Record<string, number>>;
346
- readonly totals: PursuitRunTotals;
347
- /** The nodes whose accounting is incomplete. Present exactly when non-empty. */
348
- readonly spendGaps?: ReadonlyArray<SpendGap>;
349
- }
350
- interface PursuitNodeProjection {
351
- readonly id: string;
352
- readonly parentId?: string;
353
- /** Node ids are scoped to this concrete Runtime tree; `(runId,id)` is identity. */
354
- readonly runId: string;
355
- readonly label?: string;
356
- /** The runner that executed this node — the executor's own name, not a harness guess. */
357
- readonly runtime?: string;
358
- readonly depth?: number;
359
- readonly assignmentId?: string;
360
- /** The settled sibling this node replaced, as its manager's spawn named it. Absent on a node
361
- * that replaced nothing. */
362
- readonly successorOf?: string;
363
- readonly identity?: unknown;
364
- readonly budget?: unknown;
365
- readonly status: PursuitStatus;
366
- readonly settledAt?: number;
367
- /** The child work this node reported at settlement. Absent until a terminal record lands. */
368
- readonly spent?: Spend;
369
- /** This node's OWN inference, re-homed from its nested tree. Absent when it drove no turns. */
370
- readonly ownInference?: Spend;
371
- /** Absent until a spend record lands; the run's `spendGaps` then names the node. */
372
- readonly usage?: PursuitNodeUsage;
373
- /** Absent until a spend record lands; the run's `spendGaps` then names the node. */
374
- readonly cost?: PursuitNodeCost;
375
- /** What the node consumed on the PLATFORM. Absent on a node that ran no box. */
376
- readonly platform?: PursuitNodePlatform;
377
- readonly timing?: PursuitNodeTiming;
378
- /** The kernel-minted attempt this node's execution binding is keyed on. */
379
- readonly attemptId?: string;
380
- /** The runner-native execution the node bound to: a request, session, run, process, or tree. */
381
- readonly execution?: {
382
- readonly kind: string;
383
- readonly id: string;
384
- };
385
- /** The model the materialization receipt names, when the runner reported one. */
386
- readonly model?: string;
387
- /** The concrete backend the profile materialized onto. */
388
- readonly backend?: string;
389
- readonly placement?: PursuitNodePlacement;
390
- /** Model-call identifiers this node's own turns reported, in order, deduplicated. */
391
- readonly modelCalls?: ReadonlyArray<string>;
392
- readonly materialization?: ProfileMaterializationReceipt;
393
- readonly executionBindings?: ReadonlyArray<ExecutionBindingReceipt>;
394
- /** What the provider itself reported serving, and why it is unknown when it is. */
395
- readonly providerModel?: ProviderModelExecutionEvidence;
396
- /** Content-addressed pointer to this node's persisted tool trace, or why there is none. */
397
- readonly trace?: WorkerTraceEvidence;
398
- readonly outRef?: string;
399
- readonly score?: number;
400
- readonly valid?: boolean;
401
- readonly reason?: string;
402
- readonly infra?: boolean;
403
- /** Recorded by Runtime on the `agent.child` payload: `'pending'` at a retained child's
404
- * settlement, `'released'` when root settlement destroyed its environment without recovery,
405
- * `'release-unconfirmed'` when a final settlement closed its slot without confirming that.
406
- * The status stays `down` — the split is a sibling fact, not a fourth status. A second
407
- * `agent.child` for one node is already how a live-recovered child flips down→done, so the
408
- * fold overwrites in observed order; that event's `settledAt` is the original settlement, so
409
- * `settledAt` and `timing` do not move. */
410
- readonly retainedExecution?: RetainedExecutionState;
411
- /** Why a retained child has no accepted result; see `RetainedPendingCause`. */
412
- readonly retainedPendingCause?: RetainedPendingCause;
413
- /** When a final settlement closed a retained node's slot; absent while it is `'pending'`. */
414
- readonly releasedAt?: number;
415
- /** Each channel on which the settled spend exceeded the node's reservation. The status is the
416
- * node's own outcome: a `done` node that overspent still delivered its output. */
417
- readonly budgetViolation?: BudgetViolation;
418
- readonly wait?: unknown;
419
- readonly firstSequence: number;
420
- readonly lastSequence: number;
421
- readonly firstObservedAt: number;
422
- readonly lastObservedAt: number;
423
- readonly eventCount: number;
424
- readonly turnCount: number;
425
- }
426
- interface PursuitProjection {
427
- readonly pursuitId: string;
428
- /** Number of records in this concrete execution journal. */
429
- readonly sequence: number;
430
- /** Digest-chain tip for this concrete execution journal. */
431
- readonly chainTip: string;
432
- readonly firstObservedAt: number;
433
- readonly lastObservedAt: number;
434
- readonly runs: readonly PursuitRunProjection[];
435
- readonly nodes: readonly PursuitNodeProjection[];
436
- readonly eventCount: number;
437
- readonly decisionCount: number;
438
- }
439
- /**
440
- * Fold one append-only execution journal into a deterministic operator projection.
441
- *
442
- * This is intentionally a READ model, not another state machine: it does not own
443
- * execution, cannot steer agents, and can be rebuilt from the journal at any time.
444
- * Projection verifies the complete hash chain first, so an operator view can never
445
- * silently render a mutated or reordered observer history as trustworthy state.
446
- *
447
- * Topology comes only from Runtime's canonical `agent.spawn` facts. Terminal node
448
- * state comes only from `agent.child`; concrete run state comes only from the root
449
- * `agent.run` lifecycle emitted by `supervisePursuit`, one row per attempt. Node identity is
450
- * scoped to the concrete Runtime run so independent trees may both contain `root:s0` without
451
- * aliasing, and a node belongs to the attempt that spawned it.
452
- *
453
- * Usage, cost and timing are reported at the class the runtime measured them at. A missing
454
- * class stays ABSENT and the run names the node in `spendGaps`; nothing here converts an
455
- * unmeasured channel into a zero, because a fabricated zero is indistinguishable from free work.
456
- */
457
- declare function projectPursuit(records: readonly ObserverRecord[]): PursuitProjection;
458
- //#endregion
459
- //#region src/durable/run-fork.d.ts
460
- /**
461
- * Start a run as a version of a settled run: the parent's recorded root inputs plus one change.
462
- *
463
- * The call's `profile`, `task` and `budget` must be the parent's, byte for byte, as its sealed
464
- * journal records them. Runtime applies `change` to that profile and runs the result in a new
465
- * run directory. The parent directory is read and never written.
466
- */
467
- interface PursuitFork {
468
- /** The settled parent's run directory. */
469
- readonly runDir: string;
470
- /** The sha256 of the parent's `result.json` bytes: the sealed point the fork starts from. */
471
- readonly settleDigest: Sha256Digest;
472
- /** The one change, applied to the parent's root profile. Its `id` is recorded. */
473
- readonly change: AgentProfileDiff;
474
- /**
475
- * Fork a parent whose journal holds a node without a terminal record, an unbegun owned tree, an
476
- * unconfirmed teardown, or work in flight. Such a node may still act, and a fork never replays
477
- * the parent's children, so it can only duplicate work outside the fork's tree. The root then
478
- * records those node ids as `forkParentUncertainNodes`. Omit it to refuse such a parent.
479
- */
480
- readonly acceptUncertain?: boolean;
481
- }
482
- /**
483
- * The `execution.correlation` keys a fork records on its root. Runtime writes them; a caller that
484
- * supplies one is refused. `lineageRootRunId` is the first run of the chain of parents, so the
485
- * spend of every version of one lineage groups under one id.
486
- */
487
- declare const RUN_FORK_CORRELATION_KEYS: readonly ["forkParentRunId", "forkParentSettleDigest", "forkProfileDiffId", "lineageRootRunId"];
488
- /** The correlation key an accepted uncertain parent adds: its uncertain node ids, comma-joined. */
489
- declare const FORK_PARENT_UNCERTAIN_NODES_KEY = "forkParentUncertainNodes";
490
- //#endregion
491
- //#region src/durable/supervise-pursuit.d.ts
492
- interface SupervisePursuitOptions extends SuperviseOptions {
493
- /** Stable objective identity spanning concrete Runtime runs. */
494
- readonly pursuitId: string;
495
- /**
496
- * One concrete Runtime execution owns one durable directory and observer journal.
497
- * A pursuit spanning several runs reuses `pursuitId` across distinct `runDir`s;
498
- * Intelligence joins those isolated projections without a shared write head.
499
- */
500
- readonly runDir: string;
501
- /**
502
- * Always `'release'`. The settle record refuses re-entry, so no later call resumes a settled
503
- * pursuit and nothing else would release the provider environments its retained children hold.
504
- * `'keep'` is refused rather than ignored.
505
- */
506
- readonly retainedAtSettlement?: 'release';
507
- /**
508
- * Run this pursuit as a version of a settled run: `profile`, `task` and `budget` must equal the
509
- * parent's recorded root, and Runtime executes the parent's profile with `fork.change` applied.
510
- * The root's `execution.correlation` records the parent, its sealed digest, the change and the
511
- * lineage (`RUN_FORK_CORRELATION_KEYS`). The fork's `runDir` must lie outside the parent's, and
512
- * the parent's outside it. The parent's directory is never written, and a refused fork, such as
513
- * one whose parent has an uncertain node, writes nothing.
514
- */
515
- readonly fork?: PursuitFork;
516
- /**
517
- * Continue this pursuit across versions. The first version runs at `runDir` as usual, or is
518
- * read back when that directory already settled. After each version settles, `versions.judge`
519
- * scores it from outside its tree; unless `versions.stop` ends the chain, the next version forks
520
- * from the best version so far with the change `versions.next` returns, at `<runDir>.v<n>` with
521
- * run id `<runId>.v<n>`. `<runDir>.versions/versions.jsonl` records every version, its parent,
522
- * its change, its verdict and its dollars, and the stop. A call on a chain that stopped reads
523
- * that record back; a call on a chain that did not resumes it without re-running or re-judging a
524
- * settled version. The call returns the best version's result with the chain's record.
525
- */
526
- readonly versions?: PursuitVersions;
527
- /** Supervise's name tables, plus the version judges and changes `versions` may name. */
528
- readonly registry?: SuperviseOptions['registry'] & PursuitVersionRegistry;
529
- }
530
- interface SupervisedPursuitResult<Result> {
531
- readonly result: Result;
532
- readonly pursuit: PursuitProjection;
533
- readonly observerPath: string;
534
- /** `runDir/result.json`: `result` as canonical JSON, written once at settle. */
535
- readonly settlePath: string;
536
- /** The version chain's record, when the call set `versions`. */
537
- readonly versions?: PursuitVersionsRecord;
538
- }
539
- /** A failed Runtime execution whose complete third-person projection was retained. */
540
- declare class SupervisePursuitError extends Error {
541
- readonly pursuit: PursuitProjection;
542
- readonly observerPath: string;
543
- /** `runDir/failure.json`: the record of this throw. */
544
- readonly failurePath: string;
545
- constructor(cause: unknown, pursuit: PursuitProjection, observerPath: string, failurePath: string);
546
- }
547
- /**
548
- * One-call durable pursuit execution over the canonical `supervise()` kernel.
549
- *
550
- * This is an adapter, not a second executor: it composes a durable third-person
551
- * observer into Runtime's existing recursive hook stream and then rebuilds the
552
- * operator projection after the same `supervise()` call settles. Agents never
553
- * receive the observer path or projection and their behavior does not depend on it.
554
- *
555
- * Every concrete execution writes only inside its own `runDir`. Cross-run pursuit
556
- * aggregation is therefore lock-free at the observer layer: reuse `pursuitId` across
557
- * run directories and let Intelligence join the independently verified projections.
558
- *
559
- * The directory's terminal state is recorded beside `observer.jsonl`: `result.json` holds the
560
- * returned result once the run settles and `failure.json` the most recent throw. A directory
561
- * whose `result.json` exists refuses re-entry before any compute; a failure record alone does
562
- * not, because a caller can correct its input and drive the same run again. For the life of the
563
- * call the directory is held by `supervise.lock`, so a second process on the same directory
564
- * refuses and names the holder instead of sharing one journal.
565
- * An abandoned `supervise.lock.guard` requires removal after confirming no lock mutation is active.
566
- */
567
- declare function supervisePursuit(profile: SupervisorProfile, task: unknown, opts: SupervisePursuitOptions): Promise<SupervisedPursuitResult<Awaited<ReturnType<typeof supervise>>>>;
568
- //#endregion
569
- //#region src/durable/pursuit-versions.d.ts
570
- /**
571
- * Continue a pursuit across versions: after each version settles, an outside judge scores it, and
572
- * the next version forks from the best version so far with one change, until the stop rule ends
573
- * the chain. Each version is one `supervisePursuit` run in its own directory; the fork records its
574
- * parent, the parent's seal, the change and the lineage root on the version's root.
575
- */
576
- interface PursuitVersions {
577
- /** Scores each settled version from outside its tree. A string names `registry.versionJudges`. */
578
- readonly judge: VersionJudge | string;
579
- /** The change the next version applies to the best version's profile. A string names
580
- * `registry.nextVersions`. */
581
- readonly next: NextPursuitVersion | string;
582
- /** When the chain stops. Every cap is required: a chain without one is refused. */
583
- readonly stop: PursuitVersionStop;
584
- /**
585
- * Where a later version executes. Omit it to run each version in this process through
586
- * `supervisePursuit({ fork })`, the same placement as the first. A caller that places versions
587
- * elsewhere executes exactly `version.profile` on `version.task` under `version.budget`, with
588
- * `version.execution` as the root's attribution, and returns once `version.runDir` holds the
589
- * version's settle record and observer journal. It is called again for the same version after
590
- * a restart, so it must attach to a version it already started rather than start a second one.
591
- */
592
- readonly run?: RunPursuitVersion;
593
- /**
594
- * A version's dollars as the caller measured them, such as the provider's charge to the keys the
595
- * version used. Omit it to use the version's settled `spentTotal.usd`, which is an estimate
596
- * when `usdKnown` is false. `null` means unknown, and stops the chain.
597
- */
598
- readonly usd?: (version: SettledPursuitVersion, signal: AbortSignal) => Promise<number | null>;
599
- }
600
- /** The chain's stop rule. The chain never starts a version once any cap is reached. */
601
- interface PursuitVersionStop {
602
- /** Stop after this many consecutive versions that did not improve on the best score. */
603
- readonly patience: number;
604
- /** At most this many versions, the first included. */
605
- readonly maxVersions: number;
606
- /**
607
- * The chain's total dollars, the first version included, summed from each version's settled
608
- * `spentTotal.usd`. The chain checks it between versions; a version's own budget, or the
609
- * caller's spend watcher, bounds that version in flight. A version whose dollars are not a
610
- * number stops the chain, since the chain can no longer prove it is under the cap.
611
- */
612
- readonly maxUsd: number;
613
- /** The chain's wall clock, from its first version's start. A running version is aborted at it. */
614
- readonly deadlineMs: number;
615
- /** A version improves when its score exceeds the best by more than this. Default 0. */
616
- readonly minImprovement?: number;
617
- }
618
- /** An outside judge. Runtime calls it after a version's settle record exists, never inside the
619
- * version's tree, and gives it no handle into that tree. Place it where you like, such as its own
620
- * sandbox through `runIsolatedCheck({ box })`. */
621
- interface VersionJudge {
622
- /** The sha256 of the judge's code and configuration. Every verdict must carry it, and a chain
623
- * whose ledger was judged under another digest is refused. */
624
- readonly digest: Sha256Digest;
625
- judge(version: SettledPursuitVersion, signal: AbortSignal): Promise<VersionVerdict>;
626
- }
627
- interface VersionVerdict {
628
- /** Higher is better. `null` when the judge could not score the version, which never counts as
629
- * an improvement. */
630
- readonly score: number | null;
631
- /** Must equal `VersionJudge.digest`. */
632
- readonly judgeDigest: Sha256Digest;
633
- /** What the judge measured, retained verbatim in the ledger. JSON values only. */
634
- readonly detail?: unknown;
635
- }
636
- /** A settled version, as the judge and `next` read it. */
637
- interface SettledPursuitVersion {
638
- /** 1 for the first version. */
639
- readonly version: number;
640
- readonly runId: string;
641
- readonly runDir: string;
642
- /** The sha256 of the version's `result.json` bytes. */
643
- readonly settleDigest: Sha256Digest;
644
- readonly result: SupervisedResult<unknown>;
645
- /** The profile the version executed: the first version's, or its parent's plus its change. */
646
- readonly profile: AgentProfile;
647
- readonly parent?: PursuitVersionParent;
648
- readonly change?: AgentProfileDiff;
649
- }
650
- interface PursuitVersionParent {
651
- readonly version: number;
652
- readonly runId: string;
653
- readonly settleDigest: Sha256Digest;
654
- }
655
- interface JudgedPursuitVersion extends SettledPursuitVersion {
656
- readonly verdict: VersionVerdict;
657
- /** Whether its score beat every earlier version's by more than `minImprovement`. */
658
- readonly improved: boolean;
659
- /** The version's dollars: `versions.usd`'s measurement, or its settled `spentTotal.usd`;
660
- * `null` when that is not a number. */
661
- readonly usd: number | null;
662
- /** False when the figure is Runtime's estimate or unknown. */
663
- readonly usdKnown: boolean;
664
- /** Who measured `usd`: the caller's `versions.usd`, or Runtime's settled `spentTotal`. */
665
- readonly usdSource: 'caller' | 'runtime';
666
- /** Where the version came from: its parent run and its change. Absent for a first version that
667
- * is not a fork. */
668
- readonly lineage?: AgentCandidateLineage;
669
- }
670
- interface NextPursuitVersionInput {
671
- /** The version the next one forks from: the highest score, the earliest on a tie. */
672
- readonly best: JudgedPursuitVersion;
673
- readonly last: JudgedPursuitVersion;
674
- readonly versions: readonly JudgedPursuitVersion[];
675
- }
676
- /** Build the one change the next version applies to `best.profile`. Its `id` must be non-empty. */
677
- type NextPursuitVersion = (input: NextPursuitVersionInput, signal: AbortSignal) => AgentProfileDiff | Promise<AgentProfileDiff>;
678
- /** One version, ready to execute. */
679
- interface PreparedPursuitVersion {
680
- readonly version: number;
681
- readonly runId: string;
682
- readonly runDir: string;
683
- readonly pursuitId: string;
684
- /** The profile to execute, the change already applied. */
685
- readonly profile: AgentProfile;
686
- readonly task: unknown;
687
- readonly budget: Budget;
688
- /** The root's attribution, with the fork's parent, seal, change and lineage root. */
689
- readonly execution: AgentExecutionRef;
690
- /** The fork Runtime verified, for a placement that runs `supervisePursuit({ fork })` itself
691
- * with the parent's profile, `parentProfile`. */
692
- readonly fork: PursuitFork;
693
- readonly parentProfile: AgentProfile;
694
- }
695
- type RunPursuitVersion = (version: PreparedPursuitVersion, signal: AbortSignal) => Promise<void>;
696
- type PursuitVersionStopReason = 'no-improvement' | 'max-versions' | 'max-usd' | 'spend-unknown' | 'deadline' | 'aborted';
697
- /** The chain's record, returned beside the best version's result and kept in `versions.jsonl`. */
698
- interface PursuitVersionsRecord {
699
- /** `<runDir>.versions`, beside the first version's directory. */
700
- readonly lineageDir: string;
701
- readonly judgeDigest: Sha256Digest;
702
- readonly stop: PursuitVersionStop;
703
- /** ISO instant the first version started. */
704
- readonly startedAt: string;
705
- readonly versions: readonly JudgedPursuitVersion[];
706
- /** The best version's number. */
707
- readonly best: number;
708
- /** Sum of the versions' `usd`; a floor when any version's dollars are unknown. */
709
- readonly spentUsd: number;
710
- readonly stopped: {
711
- readonly reason: PursuitVersionStopReason;
712
- readonly at: string;
713
- };
714
- }
715
- /** The registry tables `versions.judge` and `versions.next` resolve a name against. */
716
- interface PursuitVersionRegistry {
717
- readonly versionJudges?: {
718
- resolve(name: string): VersionJudge | undefined;
719
- };
720
- readonly nextVersions?: {
721
- resolve(name: string): NextPursuitVersion | undefined;
722
- };
723
- }
724
- /** The ledger file inside the lineage directory. */
725
- declare const PURSUIT_VERSIONS_FILE = "versions.jsonl";
726
- /** The `<runDir>.v<n>` directory and `<runId>.v<n>` id of version `n`, beside the first. */
727
- declare function pursuitVersionRun(runDir: string, runId: string, version: number): {
728
- runDir: string;
729
- runId: string;
730
- };
731
- /**
732
- * Validate a `versions` option before any compute. The same check runs inside `supervisePursuit`;
733
- * a caller that records the option as data can run it at preflight.
734
- */
735
- declare function assertPursuitVersions(versions: unknown): asserts versions is PursuitVersions;
736
- //#endregion
737
168
  //#region src/durable/run-lock.d.ts
738
169
  /** The lock file `supervisePursuit` holds inside a run directory for the life of one call. */
739
170
  declare const RUN_DIRECTORY_LOCK_FILE = "supervise.lock";
@@ -871,5 +302,5 @@ interface DurableSupervisionDiscovery {
871
302
  */
872
303
  declare function discoverDurableSupervisionRun(runDir: string): Promise<DurableSupervisionDiscovery>;
873
304
  //#endregion
874
- export { type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type DurableCoordinationStreamIdentity, type DurableFailureRecord, type DurableSupervisionDiscovery, FAILURE_RECORD_FILE, FORK_PARENT_UNCERTAIN_NODES_KEY, FileObserverJournal, type JudgedPursuitVersion, type NextPursuitVersion, type NextPursuitVersionInput, type ObserverJournal, type ObserverRecord, type ObserverRecordKind, PURSUIT_VERSIONS_FILE, type PreparedPursuitVersion, type PursuitCostProvenance, type PursuitFork, type PursuitNodeCost, type PursuitNodePlacement, type PursuitNodePlatform, type PursuitNodeProjection, type PursuitNodeTiming, type PursuitNodeUsage, type PursuitProjection, type PursuitRunProjection, type PursuitRunTotals, type PursuitStatus, type PursuitVersionParent, type PursuitVersionRegistry, type PursuitVersionStop, type PursuitVersionStopReason, type PursuitVersions, type PursuitVersionsRecord, ROOT_STREAM_FILE, RUN_DIRECTORY_LOCK_FILE, RUN_FORK_CORRELATION_KEYS, type RootStreamReceipt, type RootStreamRecord, type RunChatTurnInput, type RunDirectoryHolderLiveness, type RunDirectoryLock, type RunDirectoryLockHolder, RunDirectoryLockedError, type RunPursuitVersion, SETTLE_RECORD_FILE, type SettledPursuitVersion, SettledRunDirectoryError, SupervisePursuitError, type SupervisePursuitOptions, type SupervisedPursuitResult, type VersionJudge, type VersionVerdict, acquireRunDirectoryLock, assertPursuitVersions, createFileObserverHooks, deriveExecutionId, discoverDurableSupervisionRun, handleChatTurn, observerRecordDigest, projectPursuit, pursuitVersionRun, readFailureRecord, readRootStream, readRootStreamReceipt, readRunDirectoryLock, readSettleRecord, runDirectoryHolderIsLive, settleRecordJson, supervisePursuit, verifyObserverRecords };
305
+ export { type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type DurableCoordinationStreamIdentity, type DurableFailureRecord, type DurableSupervisionDiscovery, FAILURE_RECORD_FILE, FORK_PARENT_UNCERTAIN_NODES_KEY, FileObserverJournal, type JudgedPursuitVersion, type NextPursuitVersion, type NextPursuitVersionInput, type ObserverJournal, type ObserverRecord, type ObserverRecordKind, PURSUIT_VERSIONS_FILE, type PreparedPursuitVersion, type PursuitCostProvenance, type PursuitFork, type PursuitNodeCost, type PursuitNodePlacement, type PursuitNodePlatform, type PursuitNodeProjection, type PursuitNodeTiming, type PursuitNodeUsage, type PursuitProjection, type PursuitRunProjection, type PursuitRunTotals, type PursuitStatus, type PursuitVersionParent, type PursuitVersionStop, type PursuitVersionStopReason, type PursuitVersions, type PursuitVersionsRecord, REVIEW_DIR, ROOT_STREAM_FILE, RUN_DIRECTORY_LOCK_FILE, RUN_FORK_CORRELATION_KEYS, type RootStreamReceipt, type RootStreamRecord, type RunChatTurnInput, type RunDirectoryHolderLiveness, type RunDirectoryLock, type RunDirectoryLockHolder, RunDirectoryLockedError, type RunPursuitVersion, SETTLE_RECORD_FILE, type SettledPursuitVersion, SettledRunDirectoryError, SupervisePursuitError, type SupervisePursuitOptions, type SupervisedPursuitResult, type VersionJudge, type VersionVerdict, acquireRunDirectoryLock, assertPursuitVersions, createFileObserverHooks, deriveExecutionId, discoverDurableSupervisionRun, handleChatTurn, observerRecordDigest, projectPursuit, pursuitVersionRun, readFailureRecord, readRootStream, readRootStreamReceipt, readRunDirectoryLock, readSettleRecord, runDirectoryHolderIsLive, settleRecordJson, supervisePursuit, verifyObserverRecords };
875
306
  //# sourceMappingURL=durable.d.ts.map