MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / groupTurns

Function groupTurns

apps/kimi-code/src/tui/utils/transcript-window.ts:59–84  ·  view source on GitHub ↗
(entries: readonly TranscriptEntry[])

Source from the content-addressed store, hash-verified

57 * following turn) become their own turn.
58 */
59export function groupTurns(entries: readonly TranscriptEntry[]): TranscriptTurn[] {
60 const turns: TranscriptTurn[] = [];
61 let current: TranscriptTurn | undefined;
62 let pendingUndefined: TranscriptEntry[] = [];
63
64 for (const entry of entries) {
65 const turnId = entry.turnId;
66 if (turnId === undefined) {
67 pendingUndefined.push(entry);
68 continue;
69 }
70 if (current !== undefined && current.turnId === turnId) {
71 current.entries.push(entry);
72 } else {
73 current = { turnId, entries: [...pendingUndefined, entry] };
74 pendingUndefined = [];
75 turns.push(current);
76 }
77 }
78
79 if (pendingUndefined.length > 0) {
80 turns.push({ turnId: undefined, entries: pendingUndefined });
81 }
82
83 return turns;
84}
85
86/**
87 * Decide which entries to destroy so the remaining turns fit within

Callers 2

trimTranscriptWindowMethod · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected