@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
44 lines • 1.97 kB
JavaScript
import { FixedRing, ScalarScanner } from "../stream-utils.js";
import { createLineCycleState, updateLineCycles } from "./collapse-lines.js";
import { createNearDuplicateState, updateNearDuplicates } from "./collapse-near-duplicates.js";
import { createParagraphRepeatState, updateParagraphRepeats, } from "./collapse-paragraphs.js";
import { createShortPeriodState, updateShortPeriods } from "./collapse-periods.js";
import { createDominantRunState, createWhitespaceFloodState, updateDominantRun, updateWhitespaceFlood, } from "./collapse-scalars.js";
export const TAIL_RING_CAPACITY = 512;
export function createCollapseState() {
return {
scanner: new ScalarScanner(),
tailRing: new FixedRing(TAIL_RING_CAPACITY),
run: createDominantRunState(),
whitespace: createWhitespaceFloodState(),
periods: createShortPeriodState(),
lines: createLineCycleState(),
paragraphs: createParagraphRepeatState(),
nearDuplicates: createNearDuplicateState(),
latched: null,
};
}
function checkDelta(state, delta, context) {
if (state.latched !== null)
return state.latched;
const watchParagraphs = context.source !== "tool";
for (const entry of state.scanner.push(delta)) {
state.tailRing.push(entry);
const match = updateDominantRun(state.run, entry) ??
updateWhitespaceFlood(state.whitespace, entry) ??
updateShortPeriods(state.periods, entry, state.tailRing) ??
updateLineCycles(state.lines, entry) ??
(watchParagraphs ? updateParagraphRepeats(state.paragraphs, entry) : null) ??
(watchParagraphs ? updateNearDuplicates(state.nearDuplicates, entry) : null);
if (match !== null) {
state.latched = match;
return match;
}
}
return null;
}
export const collapseDetector = {
createState: createCollapseState,
checkDelta,
};
//# sourceMappingURL=collapse.js.map