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

Function turnsToTrim

apps/kimi-code/src/tui/utils/transcript-window.ts:92–109  ·  view source on GitHub ↗
(
  turns: readonly TranscriptTurn[],
  maxTurns: number,
  hysteresis: number,
)

Source from the content-addressed store, hash-verified

90 * turn is never removed (it is the active / just-finished turn).
91 */
92export function turnsToTrim(
93 turns: readonly TranscriptTurn[],
94 maxTurns: number,
95 hysteresis: number,
96): Set<TranscriptEntry> {
97 const toRemove = new Set<TranscriptEntry>();
98
99 if (turns.length <= maxTurns + hysteresis) return toRemove;
100
101 let remaining = turns.length;
102 // `turns.length - 1` keeps the most recent turn off-limits.
103 for (let i = 0; i < turns.length - 1 && remaining > maxTurns; i++) {
104 const turn = turns[i]!;
105 for (const entry of turn.entries) toRemove.add(entry);
106 remaining--;
107 }
108 return toRemove;
109}

Callers 2

trimTranscriptWindowMethod · 0.90

Calls 1

addMethod · 0.65

Tested by

no test coverage detected