UNPKG

@code-yeongyu/senpi

Version:

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

77 lines • 3.79 kB
import { entryFamily, familyId, memberId } from "./compact-catalog-registry.js"; import { writtenComponent } from "./compact-catalog-writer.js"; import { protocolId } from "./compact-recovery-ids.js"; const TRANSCRIPT = familyId("transcript"); const OPAQUE = familyId("opaque"); const BASE = protocolId("base"); /** The base row's text when the root has a non-empty loaded base, else undefined. */ export function baseRow(transcript) { if (transcript.unavailable !== null || !transcript.base || transcript.base.count === 0) return undefined; const row = { source: "file", first: 0, count: transcript.base.count, idFingerprint: transcript.base.idFingerprint, }; return JSON.stringify(row); } /** * The transcript and opaque families (R4.B2, RULING-60 Q1, RULING-61) from what the frozen S04 root owns: its * descriptor, the loaded base as a file range, then one ancestry row per accepted entry of the epoch. An entry whose * kind the engine union does not know is also an `opaque` member: its exact retained line while the tail holds it, * else its ancestry row naming the file as its source. With a loaded base the opaque family names the base stream * too; it is explicitly empty only when its producer is complete and no base exists, and a partial one with no * member of this epoch emits nothing. An unavailable root is an explicit descriptor with its typed reason and no rows. * The tail is held for the whole walk: one consistent cut of it, its entries readable to the end even if persistence * releases them meanwhile. */ export async function* transcriptComponents(store, transcript, producers, valid) { const hold = transcript.tail.hold(transcript.count, transcript.base?.count ?? 0); try { yield* heldComponents(store, transcript, hold, producers, valid); } finally { hold.release(); } } async function* heldComponents(store, transcript, hold, producers, valid) { const descriptor = { historyVersion: transcript.historyVersion, leafId: transcript.leafId, count: transcript.count, base: transcript.base && { count: transcript.base.count, idFingerprint: transcript.base.idFingerprint }, persisted: hold.persistence?.count ?? null, unavailable: transcript.unavailable, }; yield* textComponent(store, TRANSCRIPT, TRANSCRIPT, JSON.stringify(descriptor)); if (transcript.unavailable !== null) return; const base = baseRow(transcript); if (base !== undefined) yield* textComponent(store, TRANSCRIPT, BASE, base); let opaque = 0; for (const { index, id, kind, parentId } of transcript.accepted) { valid(); const tail = hold.has(index); const family = entryFamily(kind); const row = { index, id, source: tail ? "tail" : "file", parentId, kind, family }; const line = JSON.stringify(row); yield* textComponent(store, TRANSCRIPT, memberId("entry", index), line); if (family !== "opaque") continue; opaque += 1; yield* tail ? writtenComponent(store, OPAQUE, memberId("entry", index), async (writer) => { for await (const chunk of hold.chunks(index, valid)) writer.push(chunk); }) : textComponent(store, OPAQUE, memberId("entry", index), line); } if (base !== undefined) yield* textComponent(store, OPAQUE, BASE, base); else if (opaque === 0 && producers.opaque === "complete") yield { kind: OPAQUE, id: OPAQUE, leaves: [], owner: 0 }; } export const textComponent = (store, kind, id, text) => writtenComponent(store, kind, id, (writer) => writer.push(text)); //# sourceMappingURL=compact-catalog-transcript.js.map