@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
37 lines • 2.32 kB
JavaScript
import { toolcallIndex } from "./compact-call-identity.js";
import { callIdentity } from "./compact-call-model.js";
import { COMPONENT_RECORDS } from "./compact-current-components.js";
/**
* One accepted transcript transition: its owned join, then the cold flow and persistence it carries. Returns the
* message an append joined, the id its `join-<n>` member records.
*/
export function foldCompactTransition({ settled, current }, transition, transcriptAvailable, epoch) {
const owner = transition.kind === "append" && transcriptAvailable ? settled.append(transition) : undefined;
current.transcript(transition, settled, epoch);
return owner;
}
/**
* The compact side of one accepted record: canonical and component folds, its terminal, its persistence. The call
* records fold before the lane commits this sequence (RULING-13 Q9), so they are not here. Returns the identity the
* settled store recorded for this record's message (RULING-120), or the call a live call record belongs to: the one its
* fold changed, or for a `toolcall_*` update the call owning the streamed block once it folded (RULING-123); undefined
* when there is none.
*/
export function foldCompactRecord({ settled, current }, { record, type, carrier, canonical, sequence, turnId, call }) {
if (canonical)
current.fold(canonical, sequence, turnId);
if (COMPONENT_RECORDS.has(type))
current.foldComponent(record, sequence);
const ended = type === "message_end" ? settled.end(record, carrier, sequence, turnId, call?.projection) : undefined;
const failed = type === "transcript_write_failed"
? settled.fail(carrier, String(Reflect.get(record, "errorMessage")))
: undefined;
// A failed write, or a terminal whose committed entry the lane accepted, settles its compact persistence too.
const status = type === "transcript_write_failed" ? "failed" : ended?.joined ? "appended" : undefined;
if (status && settled.valid(carrier))
current.status(carrier.messageId, status);
const block = toolcallIndex(record);
const streamed = block !== undefined && carrier ? callIdentity(current.callOwning(carrier.messageId, block)) : undefined;
return ended?.identity ?? failed ?? call?.identity ?? streamed;
}
//# sourceMappingURL=session-acceptance-compact.js.map