injectOperativePinCarriers function
Injects the pinned-operative carrier into the OUTGOING request window (never the transcript): ONE verbatim block placed immediately after the LAST renumbering boundary in the window — outside the summarized range (gh-1409 AC2). No boundary in the window → the list is returned unchanged (E6: pre-boundary the body is still in context; no duplication). No pins → unchanged (E1).
onNotice receives every non-silent event: budget drops (P6), P4/P5
lifecycle changes (diffed against lastOperativePinRegistry, the
previous window's registry), and repairs (a pin absent from the whole
window text — its carrier line is the repair from the registry, AC3).
Returns the SAME list instance when there is nothing to inject, so pin-free sessions pay nothing.
Implementation
List<Message> injectOperativePinCarriers(
List<Message> messages, {
required List<Skill> skills,
int? budgetChars,
void Function(String notice)? onNotice,
}) {
if (!operativePinConfig.enabled || messages.isEmpty) {
return messages;
}
if (skills.isEmpty) {
// The everything-gone-at-once corner (round 3): the last batch of pin
// drops must still be reported (P4) — diff the previous baseline
// against an empty registry and reset it. The `enabled` kill switch
// and an empty window stay fully inert by contract (an empty window
// has nothing to report against).
_reportAllPinsGone(onNotice);
return messages;
}
final registry = _buildRegistry(
skills,
readSkillPathsInWindow(messages, skills),
budgetChars,
onNotice,
);
if (registry.isEmpty) return messages; // E1: no pins → no carrier.
final boundary = _lastRenumberingBoundary(messages);
if (boundary < 0) return messages; // E6: no fold yet → no carrier.
return _insertCarrier(
messages,
registry,
boundary,
_repairProbe(messages, registry, onNotice),
);
}