@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
92 lines • 4.57 kB
JavaScript
import { callsComponents } from "./compact-catalog-calls.js";
import { activeComponents } from "./compact-catalog-messages.js";
import { assertCoverage, CATALOG_FAMILIES, familyId, familyProducers, familyRegistry, memberId, } from "./compact-catalog-registry.js";
import { identityComponents, settledComponents } from "./compact-catalog-settled.js";
import { sourceComponents } from "./compact-catalog-source.js";
import { textComponent, transcriptComponents } from "./compact-catalog-transcript.js";
import { emptyComponent, stepsComponent } from "./compact-catalog-writer.js";
import { CompactComponentRoots } from "./compact-component-roots.js";
import { CompactReadError } from "./compact-read-lease.js";
import { protocolId } from "./compact-recovery-ids.js";
const FAMILIES = protocolId("families");
const RUN = familyId("run");
const LIFECYCLE = familyId("lifecycle");
const DIALOGS = familyId("dialogs");
/**
* Every component of one frozen root, in schema order (R4.B2): the family registry, then each family's members or
* its explicit empty component. A family with a complete producer is never omitted, and a `partial` one emits only
* the members it enumerated and never an explicit empty, so a reader can tell "no members" from "not enumerated"
* (RULING-60 Q1, RULING-61 Q1). Members stream one at a time: a value goes through `walk` into bounded leaves, a
* collection through `rows`, and each component's leaves are released once the catalog has placed it. The
* completeness gate runs last: a complete producer that emitted nothing refuses the whole catalog (X03). Its return
* value is the registry it emitted as `families/families`, the one source the manifest copies `requiredKinds` from
* (RULING-128).
*/
export async function* checkpointComponents(cut, valid) {
const { store, values, root, settled } = cut;
const current = root.current;
if (!current)
throw new CompactReadError("unavailable");
const reader = { store, values, valid };
const producers = familyProducers(root);
const registry = familyRegistry(producers);
yield* textComponent(store, FAMILIES, FAMILIES, JSON.stringify(registry));
const family = (name) => {
switch (name) {
case "transcript":
return transcriptComponents(store, root.transcript, producers, valid);
case "opaque":
return none();
case "run": {
const { runState, dialogCounts } = current.components;
return textComponent(store, RUN, RUN, JSON.stringify({ runState, dialogCounts }));
}
case "lifecycle": {
const ref = current.components.lifecycle;
return ref ? stepsComponent(store, LIFECYCLE, LIFECYCLE, values.walk(ref, valid)) : one(name);
}
case "dialogs":
return dialogComponents(reader, current.components.dialogs);
case "active":
return activeComponents(reader, current.active);
case "calls":
return callsComponents(reader, current.calls);
case "settled":
return settledComponents(reader, settled);
case "identity":
return identityComponents(reader, root, settled);
case "source":
return sourceComponents(reader, root.transcript, producers, settled);
default:
return assertNever(name);
}
};
const emitted = new Set();
for (const name of CATALOG_FAMILIES)
for await (const component of family(name)) {
emitted.add(component.kind);
yield component;
}
assertCoverage(registry, emitted);
return registry;
}
async function* dialogComponents(reader, ref) {
const dialogs = new CompactComponentRoots(reader.store, () => []);
let count = 0;
for await (const [order, value] of dialogs.rows(ref, reader.valid)) {
const steps = reader.values.walk(value, reader.valid);
yield* stepsComponent(reader.store, DIALOGS, memberId("dialog", Number(order)), steps);
count += 1;
}
if (count === 0)
yield emptyComponent("dialogs");
}
/** The opaque family's members are emitted by the transcript adapter beside their ancestry rows. */
async function* none() { }
async function* one(family) {
yield emptyComponent(family);
}
function assertNever(family) {
throw new Error(`unmapped catalog family: ${JSON.stringify(family)}`);
}
//# sourceMappingURL=compact-catalog-families.js.map