UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

54 lines • 2.84 kB
import { entryFamily, familyId, memberId } from "./compact-catalog-registry.js"; import { literalFields, literalSteps, objectSteps, } from "./compact-catalog-steps.js"; import { baseRow, textComponent } from "./compact-catalog-transcript.js"; import { emptyComponent, stepsComponent } from "./compact-catalog-writer.js"; import { protocolId } from "./compact-recovery-ids.js"; const SOURCE = familyId("source"); const BASE = protocolId("base"); /** * The source-metadata family (R4.B2, RULING-61 Q2): one `entry-<index>` member per accepted entry of this epoch whose * engine kind the registry maps to `source` (custom and custom_message payloads, compaction and branch summaries, * context edits, labels, model and configuration changes, usage), carrying its ancestry, the message it joined in * this epoch, and its exact retained line while the tail holds it (`null` once persistence covers it: S11 streams * those bytes). A loaded base's source members are rows of the base stream, which the family names with its `base` * member (S11c); it is explicitly empty only when its producer is complete and no base exists. The tail is held for * the whole walk, so an entry it holds streams to the end even if persistence releases it meanwhile. */ export async function* sourceComponents(reader, transcript, producers, settled) { let count = 0; const accepted = transcript.unavailable === null ? transcript.accepted : []; const hold = transcript.tail.hold(transcript.count, transcript.base?.count ?? 0); try { for (const { index, id, kind, parentId } of accepted) { reader.valid(); if (entryFamily(kind) !== "source") continue; const head = { index, id, parentId, kind, messageId: await settled.messageOf(id) }; const steps = objectSteps([ ...literalFields(head), ["entry", hold.has(index) ? rawSteps(hold.chunks(index, reader.valid)) : literalSteps(null)], ]); yield* stepsComponent(reader.store, SOURCE, memberId("entry", index), steps); count += 1; } } finally { hold.release(); } const base = baseRow(transcript); if (base !== undefined) yield* textComponent(reader.store, SOURCE, BASE, base); else if (count === 0 && producers.source === "complete") yield emptyComponent("source"); } /** Stored JSON text spliced in as one raw value: every piece but the last says more follows. */ async function* rawSteps(chunks) { let previous; for await (const chunk of chunks) { if (previous !== undefined) yield { kind: "raw", text: previous, more: true }; previous = chunk; } yield { kind: "raw", text: previous ?? "", more: false }; } //# sourceMappingURL=compact-catalog-source.js.map