@sema-agent/core 7.61.0 → 7.62.0
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 +312 -0
- package/dist/agents/cascade.d.ts +11 -3
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-session-drain.js +13 -3
- package/dist/agents/subagent.d.ts +6 -1
- package/dist/agents/subagent.js +66 -12
- package/dist/agents/suspend-guard.d.ts +38 -16
- package/dist/agents/suspend-guard.js +9 -4
- package/dist/agents/verify.js +4 -3
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-requirements.d.ts +9 -2
- package/dist/core/checkpoint-requirements.js +9 -4
- package/dist/core/checkpoint-row-verdict.d.ts +99 -0
- package/dist/core/checkpoint-row-verdict.js +225 -0
- package/dist/core/checkpoint-store.d.ts +55 -745
- package/dist/core/checkpoint-store.js +39 -141
- package/dist/core/engine-notice.d.ts +19 -3
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/gate-fold.js +2 -2
- package/dist/core/governance-codes.d.ts +3 -1
- package/dist/core/governance-codes.js +3 -0
- package/dist/core/hooks.d.ts +13 -0
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +1 -1
- package/dist/core/locked-config.d.ts +2 -2
- package/dist/core/mcp-host-seat.js +6 -1
- package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/mode-policy.js +1 -1
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +32 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +13 -10
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +4 -1
- package/dist/core/mods/session-append.js +7 -0
- package/dist/core/mods/session-receive.js +12 -15
- package/dist/core/mods/stations.d.ts +51 -6
- package/dist/core/mods/stations.js +124 -0
- package/dist/core/own-property-receipt.d.ts +7 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/runner/compact-session.js +5 -2
- package/dist/core/runner/contracts.d.ts +18 -8
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
- package/dist/core/runner/permission-rule-lanes.js +2 -2
- package/dist/core/runner/person-path-rows.d.ts +15 -0
- package/dist/core/runner/person-path-rows.js +26 -3
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +1 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +3 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +1 -1
- package/dist/core/runner/prepare-hands-readface.js +28 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +2 -0
- package/dist/core/runner/prepare-inherited-gate.js +7 -3
- package/dist/core/runner/prepare-task.js +10 -7
- package/dist/core/runner/resume-admission.d.ts +3 -3
- package/dist/core/runner/resume-admission.js +6 -3
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +11 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +4 -1
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +3 -2
- package/dist/core/runner/run-leg.js +24 -7
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-turn-boundary.js +7 -4
- package/dist/core/runner/runtask.js +6 -6
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-steer-verb.js +8 -0
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/turn-attachments.d.ts +5 -0
- package/dist/core/runner/turn-attachments.js +1 -1
- package/dist/core/runner-deps.d.ts +2 -2
- package/dist/core/secret-env.d.ts +8 -5
- package/dist/core/secret-env.js +37 -18
- package/dist/core/session-store.d.ts +1 -1
- package/dist/core/session-store.js +5 -1
- package/dist/core/session.d.ts +14 -4
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +68 -0
- package/dist/core/store-contracts/session-store-contract.js +22 -8
- package/dist/core/task-event.d.ts +7 -1
- package/dist/core/task-notification.js +2 -1
- package/dist/core/task-registry-agent.d.ts +27 -7
- package/dist/core/task-registry-agent.js +12 -5
- package/dist/core/task-registry-shared.d.ts +7 -0
- package/dist/core/task-registry-workflow.js +4 -3
- package/dist/core/task-registry.d.ts +13 -2
- package/dist/core/task-registry.js +11 -4
- package/dist/core/task-result.d.ts +5 -5
- package/dist/core/task-spec.d.ts +1 -1
- package/dist/core/terminal-cause.d.ts +6 -6
- package/dist/core/tool-face.d.ts +6 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-policy.d.ts +2 -1
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +4 -0
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.js +1 -1
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +12 -5
- package/dist/engine/harness/types.d.ts +11 -0
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.js +1 -1
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/index.d.ts +9 -8
- package/dist/index.js +4 -4
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/orchestration/run-workflow-tool.d.ts +3 -0
- package/dist/orchestration/run-workflow-tool.js +27 -11
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +2 -7
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +7 -6
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +2 -9
- package/dist/stores/file/index.js +2 -4
- package/dist/stores/file/session-store.d.ts +13 -7
- package/dist/stores/file/session-store.js +40 -17
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +7 -7
- package/dist/tools/fs/removal-targets.js +2 -2
- package/dist/tools/fs/shell-read-argv.d.ts +4 -2
- package/dist/tools/fs/shell-read-argv.js +14 -3
- package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
- package/dist/tools/fs/shell-read-bindings.js +148 -68
- package/dist/tools/fs/shell-read-check.js +20 -4
- package/dist/tools/fs/shell-read-establish.js +22 -8
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +8 -0
- package/dist/tools/fs/shell-read-plan.js +47 -30
- package/dist/tools/fs/shell-read-start.d.ts +66 -13
- package/dist/tools/fs/shell-read-start.js +89 -17
- package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
- package/dist/tools/fs/shell-read-workdir.js +31 -8
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +21 -33
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { ExecutionEnv, ReadFloor } from "../../internal/harness-types.js";
|
|
1
|
+
import type { AgentMessage, ExecutionEnv, ReadFloor } from "../../internal/harness-types.js";
|
|
2
|
+
import type { TaskAccess, TaskRegistry } from "../task-registry.js";
|
|
3
|
+
import type { SessionMeasureSeat } from "./lifecycle-stations.js";
|
|
2
4
|
import type { AssistantMessage, Message, Model, Usage } from "../../internal/llm.js";
|
|
3
5
|
import type { CwdRef } from "../../tools/fs/fs-shared.js";
|
|
4
6
|
import { type PermissionResult, type ToolCallRequest } from "../tool-policy.js";
|
|
@@ -11,7 +13,7 @@ import { type ModAnswerCheck, type ModAnswerRanks, type ModBus, type ModCallEntr
|
|
|
11
13
|
import { type SourcedOverlay } from "../../prompt-assembly/overlay.js";
|
|
12
14
|
import type { BandId } from "../../prompt-assembly/catalog/schema.js";
|
|
13
15
|
import type { ModParticipant } from "./kernel/dispatch.js";
|
|
14
|
-
import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView } from "./dollar.js";
|
|
16
|
+
import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView, type SessionUsage, type SessionVersion } from "./dollar.js";
|
|
15
17
|
import type { SkillSpec } from "../agent-definition.js";
|
|
16
18
|
import { type SkillScopes } from "./spec-seats.js";
|
|
17
19
|
/**
|
|
@@ -203,9 +205,13 @@ export declare function observePermissionDenied(input: {
|
|
|
203
205
|
readonly signal: AbortSignal | undefined;
|
|
204
206
|
readonly onHostObserverFailure: (err: Error) => void;
|
|
205
207
|
}): Promise<void>;
|
|
206
|
-
/** What a
|
|
208
|
+
/** What a prompt's screen came to, as the four entrances read it: `text` is what the entrance delivers (the prompt as it
|
|
209
|
+
* came, or as `prompt.submit` handed it on — `rewrittenBy` then names who changed it, in the order they did); `block` the
|
|
210
|
+
* refusal (a `prompt.submit` drop, or `classic.UserPromptSubmit`'s block). */
|
|
207
211
|
export type PromptScreen = {
|
|
208
212
|
readonly kind: "answered";
|
|
213
|
+
readonly text: string;
|
|
214
|
+
readonly rewrittenBy?: readonly string[];
|
|
209
215
|
readonly block?: string;
|
|
210
216
|
readonly additionalContext?: string;
|
|
211
217
|
} | Extract<ModDispatchOutcome, {
|
|
@@ -213,10 +219,31 @@ export type PromptScreen = {
|
|
|
213
219
|
}> | {
|
|
214
220
|
readonly kind: "aborted";
|
|
215
221
|
};
|
|
222
|
+
/** Who changed a text a chain carried, read off the chain as it runs (a station's `checkHandOn` and `checkAnswer` feed it). */
|
|
223
|
+
export interface TextChanges {
|
|
224
|
+
/** A handler handed `text` on (down): it changed the text when that differs from what the previous hand-on (or the
|
|
225
|
+
* original) carried. */
|
|
226
|
+
handedOn(by: string, text: string): void;
|
|
227
|
+
/** A handler answered `text` (up): it changed the text when that differs from what its `next` answered (`below`) or, when
|
|
228
|
+
* it answered without one, from the text it was handed. */
|
|
229
|
+
answered(by: string, text: string, handed: string, below: string | undefined): void;
|
|
230
|
+
/** The handlers that changed the text, in the order they did (down before up), each named once. */
|
|
231
|
+
rewrittenBy(): readonly string[];
|
|
232
|
+
}
|
|
233
|
+
/** The one reading of who changed a text, for every station whose answer is a rewritten text (`session.receive`,
|
|
234
|
+
* `prompt.submit`): a handler is named for the change it made — handing a different text on, or answering a different text
|
|
235
|
+
* than the one that came up to it — never for carrying another handler's change up. */
|
|
236
|
+
export declare function textChanges(original: string): TextChanges;
|
|
237
|
+
/** The four entrances' one predicate: does the leg hear a prompt's screen — `prompt.submit`, or `classic.UserPromptSubmit`
|
|
238
|
+
* raised in its bottom? */
|
|
239
|
+
export declare function promptScreenHasHandlers(bus: LegModBus): boolean;
|
|
216
240
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
241
|
+
* A prompt's screen at one of the four entrances (objective, live steer, a wake's message before its claim, a parked steer
|
|
242
|
+
* redelivered): `prompt.submit` over `e` with the prompt as `text`, its bottom raising `classic.UserPromptSubmit` on the text
|
|
243
|
+
* handed down; `undefined` (nothing raised) when neither is heard ({@link promptScreenHasHandlers}). A decision event: a
|
|
244
|
+
* handler that throws, runs past its budget or breaks the site's contract ends the screen `failed`, and every entrance fails
|
|
245
|
+
* closed on it; a cancelled screen ends `aborted` at once; a dispatch the engine could not run is `failed` too. What the
|
|
246
|
+
* classic screen refused (its block, failure or cancel) is final — a `prompt.submit` handler above it does not undo it.
|
|
220
247
|
*/
|
|
221
248
|
export declare function screenUserPrompt(bus: LegModBus, e: UserPromptSubmitEvent, signal: AbortSignal | undefined): Promise<PromptScreen | undefined>;
|
|
222
249
|
/**
|
|
@@ -299,6 +326,11 @@ export interface LegFacadeSeats {
|
|
|
299
326
|
root(): string;
|
|
300
327
|
model(): string;
|
|
301
328
|
messages(): readonly Message[];
|
|
329
|
+
/** `$.session.messages({ agentId })`'s read ({@link agentRowsOf}). */
|
|
330
|
+
agentMessages(agentId: string): Promise<readonly AgentMessage[]>;
|
|
331
|
+
turns(): Promise<number>;
|
|
332
|
+
usage(): SessionUsage;
|
|
333
|
+
version(): SessionVersion;
|
|
302
334
|
now(): number;
|
|
303
335
|
tools(): readonly string[];
|
|
304
336
|
agents(): readonly string[];
|
|
@@ -360,6 +392,13 @@ export interface LegFacadeInput {
|
|
|
360
392
|
readonly lastBrainContext: () => {
|
|
361
393
|
readonly messages: readonly Message[];
|
|
362
394
|
} | undefined;
|
|
395
|
+
/** Where the leg's subagents' transcripts are read ({@link agentRowsOf}); `undefined` ⇒ there is no task list (a
|
|
396
|
+
* session-level pass), and the read refuses saying so. */
|
|
397
|
+
readonly agentSessions: AgentSessionsSeat | undefined;
|
|
398
|
+
/** The session's prompt count, read at the call (`promptCountOf` over its branch, `session-append.ts`). */
|
|
399
|
+
readonly turns: () => Promise<number>;
|
|
400
|
+
/** The leg's measurement seat (`measureSession` writes it at each turn boundary). */
|
|
401
|
+
readonly measure: SessionMeasureSeat;
|
|
363
402
|
readonly activeTools: ReadonlySet<string>;
|
|
364
403
|
readonly agentListing: {
|
|
365
404
|
readonly entries: ReadonlyArray<{
|
|
@@ -384,6 +423,12 @@ export interface LegFacadeInput {
|
|
|
384
423
|
/** `$.session.compact`'s host entry, over the leg's compaction station. */
|
|
385
424
|
readonly sessionCompact: ModCallEntry;
|
|
386
425
|
}
|
|
426
|
+
/** The seat a leg reads its subagents' transcripts through: its task list, only the rows its own access reaches. Each row
|
|
427
|
+
* carries the store its child's session lives in, so no store of the leg's own is read. */
|
|
428
|
+
export interface AgentSessionsSeat {
|
|
429
|
+
readonly registry: Pick<TaskRegistry, "anchoredSession">;
|
|
430
|
+
readonly access: TaskAccess;
|
|
431
|
+
}
|
|
387
432
|
/** The engine facade's seats over a prepared leg — each one a seat the leg already has (no new capability). */
|
|
388
433
|
export declare function legFacadeSeats(input: LegFacadeInput): LegFacadeSeats;
|
|
389
434
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
|
+
import { engineVersion } from "../version.js";
|
|
2
3
|
import { resolveModel } from "../roles.js";
|
|
3
4
|
import { brainToRuntime } from "../runtime.js";
|
|
4
5
|
import { deliverEngineNotice } from "../engine-notice.js";
|
|
@@ -200,7 +201,101 @@ export async function observePermissionDenied(input) {
|
|
|
200
201
|
await observeClassic(own, "classic.PermissionDenied", e, input.signal);
|
|
201
202
|
}
|
|
202
203
|
const USER_PROMPT_RANKS = Object.freeze({ of: (a) => (stringMembersOf(a, ["block"]).block ? 1 : 0), top: 1 });
|
|
204
|
+
export function textChanges(original) {
|
|
205
|
+
const changers = [];
|
|
206
|
+
const note = (by) => {
|
|
207
|
+
if (!changers.includes(by))
|
|
208
|
+
changers.push(by);
|
|
209
|
+
};
|
|
210
|
+
let before = original;
|
|
211
|
+
return {
|
|
212
|
+
handedOn: (by, text) => {
|
|
213
|
+
if (text !== before)
|
|
214
|
+
note(by);
|
|
215
|
+
before = text;
|
|
216
|
+
},
|
|
217
|
+
answered: (by, text, handed, below) => {
|
|
218
|
+
if (text !== (below ?? handed))
|
|
219
|
+
note(by);
|
|
220
|
+
},
|
|
221
|
+
rewrittenBy: () => Object.freeze([...changers]),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export function promptScreenHasHandlers(bus) {
|
|
225
|
+
return bus.hasHandlers("prompt.submit") || bus.hasHandlers("classic.UserPromptSubmit");
|
|
226
|
+
}
|
|
227
|
+
const PROMPT_SUBMIT_FORM = "prompt.submit takes { text } (a string) or { drop: <reason> }";
|
|
228
|
+
function readSubmitAnswer(a) {
|
|
229
|
+
if (!isPlainRecord(a))
|
|
230
|
+
return { why: PROMPT_SUBMIT_FORM };
|
|
231
|
+
const keys = Object.keys(a);
|
|
232
|
+
if (keys.length === 1 && keys[0] === "drop") {
|
|
233
|
+
const r = a["drop"];
|
|
234
|
+
return typeof r === "string" && r.trim() !== "" ? { drop: r } : { why: "a drop that is not a reason (a non-empty string)" };
|
|
235
|
+
}
|
|
236
|
+
if (keys.length === 1 && keys[0] === "text") {
|
|
237
|
+
const t = a["text"];
|
|
238
|
+
return typeof t === "string" ? { text: t } : { why: "a text that is not a string" };
|
|
239
|
+
}
|
|
240
|
+
return { why: PROMPT_SUBMIT_FORM };
|
|
241
|
+
}
|
|
242
|
+
const PROMPT_SUBMIT_RANKS = Object.freeze({ of: (a) => (isPlainRecord(a) && Object.hasOwn(a, "drop") ? 1 : 0), top: 1 });
|
|
203
243
|
export async function screenUserPrompt(bus, e, signal) {
|
|
244
|
+
if (!promptScreenHasHandlers(bus))
|
|
245
|
+
return undefined;
|
|
246
|
+
const { prompt, ...facts } = e;
|
|
247
|
+
const changes = textChanges(prompt);
|
|
248
|
+
const checkHandOn = (handed, by) => {
|
|
249
|
+
const t = handed["text"];
|
|
250
|
+
if (typeof t !== "string")
|
|
251
|
+
return "next() handed on a text that is not a string";
|
|
252
|
+
changes.handedOn(by.plugin, t);
|
|
253
|
+
return undefined;
|
|
254
|
+
};
|
|
255
|
+
const seen = {};
|
|
256
|
+
const bottom = async (handed) => {
|
|
257
|
+
const text = handed["text"];
|
|
258
|
+
const classic = await screenClassicPrompt(bus, { ...e, prompt: text }, signal);
|
|
259
|
+
if (classic !== undefined)
|
|
260
|
+
seen.classic = classic;
|
|
261
|
+
if (classic === undefined || (classic.kind === "answered" && !classic.block))
|
|
262
|
+
return Object.freeze({ text });
|
|
263
|
+
return Object.freeze({ drop: classic.kind === "answered" ? classic.block : "the classic.UserPromptSubmit screen did not clear the prompt" });
|
|
264
|
+
};
|
|
265
|
+
const checkAnswer = (a, handed, by, below) => {
|
|
266
|
+
const read = readSubmitAnswer(a);
|
|
267
|
+
if ("why" in read)
|
|
268
|
+
return read.why;
|
|
269
|
+
if ("text" in read) {
|
|
270
|
+
const up = below.length > 0 ? readSubmitAnswer(below[below.length - 1]) : undefined;
|
|
271
|
+
changes.answered(by.plugin, read.text, handed["text"], up !== undefined && "text" in up ? up.text : undefined);
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
};
|
|
275
|
+
let outcome;
|
|
276
|
+
try {
|
|
277
|
+
outcome = await bus.dispatch("prompt.submit", { ...facts, text: prompt }, { bottom, checkAnswer, checkHandOn, ranks: PROMPT_SUBMIT_RANKS, ...(signal !== undefined ? { signal } : {}) });
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
return { kind: "failed", registration: "engine", cause: "threw", reason: `could not raise the screen: ${describeThrown(err)}`, skipped: [] };
|
|
281
|
+
}
|
|
282
|
+
const classic = seen.classic;
|
|
283
|
+
if (classic !== undefined && (classic.kind !== "answered" || classic.block))
|
|
284
|
+
return classic.kind === "answered" ? { ...classic, text: prompt } : classic;
|
|
285
|
+
if (outcome.kind !== "answered")
|
|
286
|
+
return outcome;
|
|
287
|
+
const read = readSubmitAnswer(outcome.answer);
|
|
288
|
+
const by = outcome.answeredBy ?? "engine";
|
|
289
|
+
const context = classic?.kind === "answered" && classic.additionalContext !== undefined ? { additionalContext: classic.additionalContext } : {};
|
|
290
|
+
if ("drop" in read)
|
|
291
|
+
return { kind: "answered", text: prompt, block: read.drop };
|
|
292
|
+
if ("why" in read)
|
|
293
|
+
return { kind: "failed", registration: by, cause: "violation", reason: read.why, skipped: [] };
|
|
294
|
+
if (read.text === prompt)
|
|
295
|
+
return { kind: "answered", text: prompt, ...context };
|
|
296
|
+
return { kind: "answered", text: read.text, rewrittenBy: changes.rewrittenBy(), ...context };
|
|
297
|
+
}
|
|
298
|
+
async function screenClassicPrompt(bus, e, signal) {
|
|
204
299
|
let outcome;
|
|
205
300
|
try {
|
|
206
301
|
outcome = await dispatchClassic(bus, "classic.UserPromptSubmit", e, {
|
|
@@ -387,6 +482,10 @@ function lateView() {
|
|
|
387
482
|
root: () => need("session.root").root(),
|
|
388
483
|
model: () => need("session.model").model(),
|
|
389
484
|
messages: () => need("session.messages").messages(),
|
|
485
|
+
agentMessages: (agentId) => need("session.messages").agentMessages(agentId),
|
|
486
|
+
turns: () => need("session.turns").turns(),
|
|
487
|
+
usage: () => need("session.usage").usage(),
|
|
488
|
+
version: () => need("session.version").version(),
|
|
390
489
|
},
|
|
391
490
|
now: () => need("clock.now").now(),
|
|
392
491
|
tools: () => need("tool.list").tools(),
|
|
@@ -425,6 +524,27 @@ export async function admitLegMods(input) {
|
|
|
425
524
|
ADMITTED_CHAINS.set(standing, chain);
|
|
426
525
|
return { bus, standing, chain, skillScopes, report, bindFacade: late.bind };
|
|
427
526
|
}
|
|
527
|
+
async function agentRowsOf(seat, agentId) {
|
|
528
|
+
const refused = (why) => new Error(`session.messages: agent ${agentId}: ${why}`);
|
|
529
|
+
if (seat === undefined)
|
|
530
|
+
throw refused("there is no task list here — a session-level pass has no run, so no subagents");
|
|
531
|
+
const anchor = seat.registry.anchoredSession(agentId, seat.access);
|
|
532
|
+
if (anchor === undefined)
|
|
533
|
+
throw refused("not one of this leg's subagents (no task list row this leg reaches has that id)");
|
|
534
|
+
if (anchor === null)
|
|
535
|
+
throw refused("its row names no session — not a subagent's row, or its session is not bound yet or was released");
|
|
536
|
+
const store = anchor.store;
|
|
537
|
+
if (store === undefined)
|
|
538
|
+
throw refused("its session was bound without the store that holds it");
|
|
539
|
+
let branch;
|
|
540
|
+
try {
|
|
541
|
+
branch = await (await store.acquire(anchor.sessionId, { requireExisting: true })).session.getBranch();
|
|
542
|
+
}
|
|
543
|
+
catch (err) {
|
|
544
|
+
throw refused(`its session could not be read (${describeThrown(err)})`);
|
|
545
|
+
}
|
|
546
|
+
return branch.flatMap((e) => (e.type === "message" ? [e.message] : []));
|
|
547
|
+
}
|
|
428
548
|
function replyText(reply) {
|
|
429
549
|
return reply.content.flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
|
|
430
550
|
}
|
|
@@ -461,6 +581,10 @@ export function legFacadeSeats(input) {
|
|
|
461
581
|
root: () => input.taskRoot,
|
|
462
582
|
model: () => input.model.id,
|
|
463
583
|
messages: () => input.lastBrainContext()?.messages ?? [],
|
|
584
|
+
agentMessages: (agentId) => agentRowsOf(input.agentSessions, agentId),
|
|
585
|
+
turns: () => input.turns(),
|
|
586
|
+
usage: () => Object.freeze(input.measure.context !== undefined ? { context: input.measure.context } : {}),
|
|
587
|
+
version: () => Object.freeze({ version: engineVersion() }),
|
|
464
588
|
now: () => (input.deps.now ?? Date.now)(),
|
|
465
589
|
tools: () => [...input.activeTools],
|
|
466
590
|
agents: () => (input.agentListing?.entries ?? []).map((e) => e.name),
|
|
@@ -74,6 +74,13 @@ export interface StrayMembers {
|
|
|
74
74
|
* {@link refuseStrayMembers} or {@link receiveMembers}.
|
|
75
75
|
*/
|
|
76
76
|
export declare function strayMembersOf(given: object, words: OwnPropertyReceiptWords, keys: readonly string[]): StrayMembers | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* THE MEMBER'S PRESENCE (module note): `name` is a member of `record` exactly when its value there is not `undefined` — an
|
|
79
|
+
* own key holding `undefined` and a missing key are one absence; `null`, `0`, `""` and `false` are values. The engine's one
|
|
80
|
+
* reading of whether a record carries a member; the names a caller handed over are the name judgment's question
|
|
81
|
+
* ({@link strayMembersOf}), not this one's.
|
|
82
|
+
*/
|
|
83
|
+
export declare function memberPresent(record: object, name: string): boolean;
|
|
77
84
|
/**
|
|
78
85
|
* THE NAME-ONLY DOOR — the receipt's admission (not a Proxy, a plain record), then {@link strayMembersOf}: every own member
|
|
79
86
|
* `keys` does not name is refused, all of them in one sentence, and no getter runs. For an object the door must judge but
|
|
@@ -28,6 +28,9 @@ export function strayMembersOf(given, words, keys) {
|
|
|
28
28
|
const names = Reflect.ownKeys(given).filter((k) => typeof k === "symbol" || !keys.includes(k));
|
|
29
29
|
return names.length === 0 ? undefined : Object.freeze({ names: Object.freeze(names), sentence: strayMembersSentence(words, names, keys) });
|
|
30
30
|
}
|
|
31
|
+
export function memberPresent(record, name) {
|
|
32
|
+
return Reflect.get(record, name) !== undefined;
|
|
33
|
+
}
|
|
31
34
|
export function refuseStrayMembers(given, words, keys, refusal = receiptRefusal) {
|
|
32
35
|
admitPlainRecord(given, words);
|
|
33
36
|
const stray = strayMembersOf(given, words, keys);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPlainRecord, safeDataValue } from "./checkpoint-
|
|
1
|
+
import { isPlainRecord, safeDataValue } from "./checkpoint-features.js";
|
|
2
2
|
import { validatePath } from "./effective-path-target.js";
|
|
3
3
|
export { READ_ROOT_CANDIDATE_DIR_MAX } from "./effective-path-target.js";
|
|
4
4
|
export function normalizeReadRootCandidate(value) {
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* · `environment` — the leg's infrastructure failed (the workspace restore, an abort): the decision is
|
|
10
10
|
* untouched, and a retry replays it;
|
|
11
11
|
* · `session_gone` — the resumed agent's transcript session is missing;
|
|
12
|
-
* · `transcript_corrupt` — the resumed agent's transcript session is THERE but cannot be read as a session
|
|
13
|
-
* has no header its store wrote
|
|
14
|
-
* entry that is not in the log
|
|
15
|
-
*
|
|
12
|
+
* · `transcript_corrupt` — the resumed agent's transcript session is THERE but cannot be read as a session
|
|
13
|
+
* (`corrupt_session`): its log has no header its store wrote, or its entry tree does not hold together — a leaf,
|
|
14
|
+
* a parent or the entry its checkpoint was cut at that is not in the log, a parent chain that loops. A store outside
|
|
15
|
+
* this package that answers the same fact `invalid_session` reads the same way. Distinct from `session_gone`: the
|
|
16
|
+
* bytes exist, so deleting or restoring the transcript is the remedy, not re-creating a session;
|
|
16
17
|
* · `tool_unavailable` — the approved tool is not available to the resumed leg (gone, replaced by a
|
|
17
18
|
* different contract, or an inherited tool the drive cannot hand over): this approval cannot run, and a
|
|
18
19
|
* fresh decision resolves it;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { convertToLlm, uuidv7 } from "../../internal/harness.js";
|
|
2
2
|
import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent } from "../auto-compaction.js";
|
|
3
3
|
import { contextOverlayFor } from "../context-settings.js";
|
|
4
|
-
import { createRowSeat } from "../mods/session-append.js";
|
|
4
|
+
import { createRowSeat, promptCountOf } from "../mods/session-append.js";
|
|
5
5
|
import { createCompactStation } from "../mods/session-compact.js";
|
|
6
6
|
import { admitLegMods, legFacadeSeats } from "../mods/stations.js";
|
|
7
7
|
import { malformedPricingField } from "../pricing.js";
|
|
@@ -73,7 +73,7 @@ async function compactOnSession(req, deps, session, resolved, named, legMods) {
|
|
|
73
73
|
const compactionModel = compactionSummaryIsDerived(req.compactionModel !== undefined, named) ? await compactionSummaryFallback({ derived: named, primary: resolved.model, brain: deps.brain, getApiKeyAndHeaders: req.getApiKeyAndHeaders, onNotice: deps.onNotice, sessionId }) : named;
|
|
74
74
|
const branch = await session.getBranch();
|
|
75
75
|
const contextMessages = convertToLlm((await session.buildContext()).messages);
|
|
76
|
-
bindSessionFacade(legMods, { deps, req, model: resolved.model, messages: contextMessages, book });
|
|
76
|
+
bindSessionFacade(legMods, { deps, req, model: resolved.model, messages: contextMessages, book, turns: async () => promptCountOf(await session.getBranch()) });
|
|
77
77
|
const rowSeat = createRowSeat();
|
|
78
78
|
rowSeat.bind({ bus: legMods.bus, identity: undefined, report: legMods.report });
|
|
79
79
|
const compactStation = createCompactStation();
|
|
@@ -142,6 +142,9 @@ function bindSessionFacade(legMods, input) {
|
|
|
142
142
|
taskRoot: "",
|
|
143
143
|
cwdRef: undefined,
|
|
144
144
|
lastBrainContext: () => ({ messages: input.messages }),
|
|
145
|
+
agentSessions: undefined,
|
|
146
|
+
turns: input.turns,
|
|
147
|
+
measure: {},
|
|
145
148
|
activeTools: new Set(),
|
|
146
149
|
agentListing: undefined,
|
|
147
150
|
book: (answeredBy, reply) => input.book("mod", answeredBy, reply),
|
|
@@ -568,6 +568,8 @@ export interface Prepared {
|
|
|
568
568
|
/** The leg's `session.compact` station and its `$.session.compact` window (`session-compact.ts`): every compaction lane runs
|
|
569
569
|
* its pass through it. */
|
|
570
570
|
compactStation: import("../mods/session-compact.js").CompactStation;
|
|
571
|
+
/** The leg's latest context measurement (`lifecycle-stations.ts`): each turn boundary writes it, `$.session.usage` reads it. */
|
|
572
|
+
sessionMeasure: import("../mods/lifecycle-stations.js").SessionMeasureSeat;
|
|
571
573
|
/**
|
|
572
574
|
* This session's DURABLE box, present iff this leg mounted the session-box drain (a top-level leg
|
|
573
575
|
* over a cross-process-safe mailbox with a grammatical session id). The notification lane binds it
|
|
@@ -2058,6 +2060,11 @@ export interface RunInternals {
|
|
|
2058
2060
|
* after a restart those intermediate sessions are dead ends, and a recovery face enumerating
|
|
2059
2061
|
* "everything under this host session" needs the root anchor, not an alias walk. */
|
|
2060
2062
|
rootSessionId?: string;
|
|
2063
|
+
/** The delegation tree's owner seat ({@link import("./delegation-owner.js").DelegationOwnerSeat}): a fixed point like
|
|
2064
|
+
* {@link rootSessionId} — the spawning run hands its own seat down by reference (the delegation and workflow lanes), so the tree
|
|
2065
|
+
* reads its root row's owner once. Absent ⇒ this run is nobody's child here (a top-level run, a revival, a resumed park) and its
|
|
2066
|
+
* prepare mints a seat over the row it acquired. TRUSTED run-scoped channel (never a {@link TaskSpec} field). */
|
|
2067
|
+
delegationOwner?: import("./delegation-owner.js").DelegationOwnerSeat;
|
|
2061
2068
|
/**
|
|
2062
2069
|
* The run tree's PLACEMENT root: the fixed point a target-bound env factory keys
|
|
2063
2070
|
* its placement lookup on ({@link import("../remote-env.js").ExecutionEnvFactoryContext.placementRootSessionId}).
|
|
@@ -2677,15 +2684,15 @@ export interface RunState {
|
|
|
2677
2684
|
};
|
|
2678
2685
|
}
|
|
2679
2686
|
/**
|
|
2680
|
-
* Config
|
|
2681
|
-
*
|
|
2682
|
-
*
|
|
2683
|
-
*
|
|
2684
|
-
*
|
|
2687
|
+
* Config handed to {@link Runner.resume}: the {@link TaskSpec} members the resumed leg runs with. `sessionId` comes from the checkpoint;
|
|
2688
|
+
* a resume sends no new human message, so it takes no objective, `userAttachments` or `runOrigin` (either present is refused before the
|
|
2689
|
+
* claim; a wake states its leg's word on the input it hands over). The row records no tool, hand band or server list: `tools`, `mcp`,
|
|
2690
|
+
* `a2a` and the `skills` specs are the deployment's CURRENT ones as this resume hands them (the leg dials these lists as the config doors
|
|
2691
|
+
* judge them; absent declares none) — a host replaying the parked run's lists re-dials a server its user removed. The parked call is
|
|
2692
|
+
* judged against what this resume mounts: its server no longer declared ⇒ `resume.tool_unavailable` (never dialed, not run, the row
|
|
2693
|
+
* reopened `pending`); a replacement ⇒ `resume.tool_contract_mismatch`; a moved face or declaration ⇒ `resume.target_moved`. Identity is
|
|
2694
|
+
* kept instead: a contradicting `principal` is refused (`resume.principal_mismatch`), an absent one inherits the row's.
|
|
2685
2695
|
*/
|
|
2686
|
-
/** A resume continues the suspended leg: it sends no new human message, so it takes neither an objective nor the
|
|
2687
|
-
* objective's attachments nor the objective's run origin (a config that carries `userAttachments` or `runOrigin` anyway is
|
|
2688
|
-
* refused before the claim; a wake states its leg's word on the input it hands over). */
|
|
2689
2696
|
export type ResumeTaskConfig = Omit<TaskSpec, "objective" | "sessionId" | "userAttachments" | "runOrigin">;
|
|
2690
2697
|
/**
|
|
2691
2698
|
* A composition leg's identity ({@link RunInternals.compositionLeg}, `CheckpointState.compositionLeg`): which entry handed the
|
|
@@ -2753,6 +2760,9 @@ export interface ResumeRun {
|
|
|
2753
2760
|
* §4.3-3 reserves for the cross-process parked leg). Present only when a wake message passed a
|
|
2754
2761
|
* screen that supplied context. */
|
|
2755
2762
|
wakeMessageHookContext?: string;
|
|
2763
|
+
/** Who rewrote {@link wakeMessage}'s text at that screen (`prompt.submit`), in the order they did — its applied
|
|
2764
|
+
* `human_input` account names them. Absent ⇒ nobody rewrote it. */
|
|
2765
|
+
wakeMessageRewrittenBy?: readonly string[];
|
|
2756
2766
|
/** The resumed leg's bus when the wake-message screen admitted it before the claim — prepare adopts it. */
|
|
2757
2767
|
legMods?: LegMods;
|
|
2758
2768
|
/** The claim's reversal, bound to THIS resume's token and scope by `resumeStream` — REQUIRED, as the store's
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SessionStore } from "../session.js";
|
|
2
|
+
/**
|
|
3
|
+
* The delegation tree's owner as one run binds it: `bound` with the owner (`null` = the tree root's row is anonymous), or `unbound`
|
|
4
|
+
* when the row this run acquired no longer stands under its id (deleted, or deleted and created again for another occupant) the first
|
|
5
|
+
* time the owner is asked for — a child placed on that answer would record whoever holds the id now, not this tree's owner. `reason` is
|
|
6
|
+
* the engine's sentence; a read that threw carries what it threw in `fault` (the host's to read, never the model's text).
|
|
7
|
+
*/
|
|
8
|
+
export type DelegationOwnerReading = {
|
|
9
|
+
readonly bound: true;
|
|
10
|
+
readonly owner: string | null;
|
|
11
|
+
} | {
|
|
12
|
+
readonly bound: false;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
readonly fault?: unknown;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The delegation tree's owner: the owner cell of the tree root's row, as the root run read it — once. A run spawned by another run
|
|
18
|
+
* holds its spawner's seat (by reference, so the whole tree shares one reading); a run nobody spawned (a top-level run, a revived
|
|
19
|
+
* child, a parked child resumed on its own) holds a seat over the row it acquired itself ({@link ownRowDelegationOwner}). The first
|
|
20
|
+
* answer that binds or refuses is the answer for every later call; a read fault rejects and binds nothing.
|
|
21
|
+
*/
|
|
22
|
+
export interface DelegationOwnerSeat {
|
|
23
|
+
read(): Promise<DelegationOwnerReading>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The seat of a run nobody spawned: the owner of the row it acquired, read by id through its own store's {@link SessionStore.headOf}
|
|
27
|
+
* and taken only while the row's occupant is the one acquired — the head's `incarnation` equals the acquired session's metadata's
|
|
28
|
+
* (both absent = a row written before occupants were minted, taken as it reads). A store without a by-id read has no owner to read:
|
|
29
|
+
* the reading is `null`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ownRowDelegationOwner(sessions: Pick<SessionStore, "headOf">, sessionId: string, acquiredIncarnation: () => Promise<string | undefined>): DelegationOwnerSeat;
|
|
32
|
+
/** The refusal of a delegation whose tree owner does not bind ({@link DelegationOwnerReading}): the child is not started and no row is
|
|
33
|
+
* created for it. */
|
|
34
|
+
export declare const DELEGATION_OWNER_UNBOUND = "delegation.owner_unbound";
|
|
35
|
+
export declare function delegationOwnerUnbound(reason: string): Error & {
|
|
36
|
+
code: typeof DELEGATION_OWNER_UNBOUND;
|
|
37
|
+
};
|
|
38
|
+
/** The owner a seat binds, or `null` where no seat rides (a tool driven with no run around it has no tree root to read). */
|
|
39
|
+
export declare function delegationOwnerOf(seat: DelegationOwnerSeat | undefined): Promise<DelegationOwnerReading>;
|
|
40
|
+
/** A revived child's tree owner: the owner its own row records, read by id through the store it lives in (`null` where the store has
|
|
41
|
+
* no by-id read, or holds no row for the id — a revival of a missing row re-opens nothing). A row whose owner cell is not a name or
|
|
42
|
+
* `null` does not bind, as in the seat of a run nobody spawned. */
|
|
43
|
+
export declare function rowOwnerReading(sessions: Pick<SessionStore, "headOf">, sessionId: string | undefined): Promise<DelegationOwnerReading>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function ownerCellReading(sessionId, head) {
|
|
2
|
+
const owner = head.owner;
|
|
3
|
+
if (owner === null || typeof owner === "string")
|
|
4
|
+
return { bound: true, owner };
|
|
5
|
+
return { bound: false, reason: `the session ${sessionId}'s row answers an owner that is neither a name nor anonymous (${owner === undefined ? "none" : typeof owner})` };
|
|
6
|
+
}
|
|
7
|
+
export function ownRowDelegationOwner(sessions, sessionId, acquiredIncarnation) {
|
|
8
|
+
let settled;
|
|
9
|
+
let inFlight;
|
|
10
|
+
const bind = async () => {
|
|
11
|
+
const headOf = sessions.headOf;
|
|
12
|
+
if (typeof headOf !== "function")
|
|
13
|
+
return { bound: true, owner: null };
|
|
14
|
+
const [head, acquired] = await Promise.all([headOf.call(sessions, sessionId), acquiredIncarnation()]);
|
|
15
|
+
if (head === undefined)
|
|
16
|
+
return { bound: false, reason: `the session ${sessionId} this run acquired has no row any more` };
|
|
17
|
+
if (head.incarnation !== acquired)
|
|
18
|
+
return { bound: false, reason: `the session ${sessionId} this run acquired now holds another occupant` };
|
|
19
|
+
return ownerCellReading(sessionId, head);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
read() {
|
|
23
|
+
if (settled !== undefined)
|
|
24
|
+
return Promise.resolve(settled);
|
|
25
|
+
inFlight ??= bind().then((reading) => {
|
|
26
|
+
settled = reading;
|
|
27
|
+
return reading;
|
|
28
|
+
}, (err) => {
|
|
29
|
+
inFlight = undefined;
|
|
30
|
+
throw err;
|
|
31
|
+
});
|
|
32
|
+
return inFlight;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export const DELEGATION_OWNER_UNBOUND = "delegation.owner_unbound";
|
|
37
|
+
export function delegationOwnerUnbound(reason) {
|
|
38
|
+
return Object.assign(new Error(`the delegation tree's owner does not bind: ${reason}`), { code: DELEGATION_OWNER_UNBOUND });
|
|
39
|
+
}
|
|
40
|
+
async function settled(read) {
|
|
41
|
+
try {
|
|
42
|
+
return await read();
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return { bound: false, reason: "the row that names it could not be read", fault: err };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function delegationOwnerOf(seat) {
|
|
49
|
+
return seat === undefined ? Promise.resolve({ bound: true, owner: null }) : settled(() => seat.read());
|
|
50
|
+
}
|
|
51
|
+
export function rowOwnerReading(sessions, sessionId) {
|
|
52
|
+
return settled(async () => {
|
|
53
|
+
const headOf = sessions.headOf;
|
|
54
|
+
if (typeof headOf !== "function" || sessionId === undefined)
|
|
55
|
+
return { bound: true, owner: null };
|
|
56
|
+
const head = await headOf.call(sessions, sessionId);
|
|
57
|
+
return head === undefined ? { bound: true, owner: null } : ownerCellReading(sessionId, head);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run continues a session whose log lost records: the leg's view of the session's storage tells the run what the replay that loaded the
|
|
3
|
+
* log dropped (`SessionStorage.getReplayLoss`), at the first branch read of the run. Two findings, one notice a leg:
|
|
4
|
+
*
|
|
5
|
+
* - the branch read broke at a parent the log does not hold, and the replay dropped records (the {@link LineageBreak}'s `replayLoss`) —
|
|
6
|
+
* the evidence that the missing parent may be one of them: the branch ends at the entry that names it, the entries that survive below
|
|
7
|
+
* the break are the conversation the run continues, and the finding is a `break`;
|
|
8
|
+
* - the branch is whole but the replay dropped records (the log's last records were unreadable and its head fell back to the last one
|
|
9
|
+
* still readable, or the damage sat off the branch): the finding is the count and the head the run continues from.
|
|
10
|
+
*
|
|
11
|
+
* The stop is the walk's own floor stop (`pathToRoot` with the break's child as the floor), so no second walk exists. A break the
|
|
12
|
+
* replay cannot account for (it dropped nothing: a log written with a parent it never held) is refused as it was — `corrupt_session` —
|
|
13
|
+
* and so is every reader outside a run (a fork, an export, the store kit), which gets no announcement and so no re-root.
|
|
14
|
+
*/
|
|
15
|
+
import { type SessionStorage } from "../../internal/harness.js";
|
|
16
|
+
import type { NoticeSeatInput } from "./notice-seat-input.js";
|
|
17
|
+
/** What a branch read found of the records the log's replay dropped: the replay's count, the head the branch was read from (`null` = nothing
|
|
18
|
+
* of the log is readable) and the branch's length. */
|
|
19
|
+
export interface BranchLoss {
|
|
20
|
+
readonly recordsDropped: number;
|
|
21
|
+
readonly recordsTotal: number;
|
|
22
|
+
readonly leaf: string | null;
|
|
23
|
+
readonly entriesOnPath: number;
|
|
24
|
+
}
|
|
25
|
+
/** What one re-rooted branch read found besides: the parent the log does not hold, the entry the branch now starts at, and how many entries
|
|
26
|
+
* of the log do not descend from that entry (the history above the break, and its side branches). */
|
|
27
|
+
export interface LineageReroot extends BranchLoss {
|
|
28
|
+
readonly leaf: string;
|
|
29
|
+
readonly missingParentId: string;
|
|
30
|
+
readonly rootedAt: string;
|
|
31
|
+
readonly entriesCut: number;
|
|
32
|
+
}
|
|
33
|
+
/** What a branch read found: the branch broke (and was ended at the break), or it is whole and the replay dropped records. */
|
|
34
|
+
export type ReplayLossFinding = ({
|
|
35
|
+
readonly break: false;
|
|
36
|
+
} & BranchLoss) | ({
|
|
37
|
+
readonly break: true;
|
|
38
|
+
} & LineageReroot);
|
|
39
|
+
/** The leg's view of `storage`: every member as the storage answers it, but a branch read that breaks at a replay-proven loss ends at the
|
|
40
|
+
* break, and a branch read in a log whose replay dropped records is reported to `found` (`leaf` = the entry the read started from). */
|
|
41
|
+
export declare function viewThroughReplayLoss(storage: SessionStorage, found: (finding: ReplayLossFinding) => void): SessionStorage;
|
|
42
|
+
/** The leg's account of what the log's replay dropped (`session.lineage_rerooted`): one a leg for a whole branch, one a break for a broken one
|
|
43
|
+
* (whichever read met it first), and a broken branch's notice already carries the count, so a whole branch read after it says nothing more. */
|
|
44
|
+
export declare function replayLossSeat(ids: Pick<NoticeSeatInput, "onNotice" | "runId">): (finding: ReplayLossFinding, sessionId: string) => void;
|
|
45
|
+
/** One leg's reading of what the log's replay dropped. The acquire phase reads again after a lost write race and keeps only the attempt
|
|
46
|
+
* that holds, so what an attempt found is held until the phase settles on one and said then (a break before a whole branch, so the break's
|
|
47
|
+
* notice is the leg's only one); reads after that are said as they are made. */
|
|
48
|
+
export interface ReplayLossLeg {
|
|
49
|
+
/** `storage` as this leg reads it, naming the session its findings are about. */
|
|
50
|
+
view(storage: SessionStorage, sessionId: string): SessionStorage;
|
|
51
|
+
/** The attempt that found what is held is discarded: none of it is said. */
|
|
52
|
+
discard(): void;
|
|
53
|
+
/** The attempt that holds is known: say what it found. */
|
|
54
|
+
settle(): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function replayLossLeg(ids: Pick<NoticeSeatInput, "onNotice" | "runId">): ReplayLossLeg;
|