MCPcopy Create free account
hub / github.com/codeaashu/claude-code / flushSessionSection

Function flushSessionSection

src/services/SessionMemory/prompts.ts:298–324  ·  view source on GitHub ↗
(
  sectionHeader: string,
  sectionLines: string[],
  maxCharsPerSection: number,
)

Source from the content-addressed store, hash-verified

296}
297
298function flushSessionSection(
299 sectionHeader: string,
300 sectionLines: string[],
301 maxCharsPerSection: number,
302): { lines: string[]; wasTruncated: boolean } {
303 if (!sectionHeader) {
304 return { lines: sectionLines, wasTruncated: false }
305 }
306
307 const sectionContent = sectionLines.join('\n')
308 if (sectionContent.length <= maxCharsPerSection) {
309 return { lines: [sectionHeader, ...sectionLines], wasTruncated: false }
310 }
311
312 // Truncate at a line boundary near the limit
313 let charCount = 0
314 const keptLines: string[] = [sectionHeader]
315 for (const line of sectionLines) {
316 if (charCount + line.length + 1 > maxCharsPerSection) {
317 break
318 }
319 keptLines.push(line)
320 charCount += line.length + 1
321 }
322 keptLines.push('\n[... section truncated for length ...]')
323 return { lines: keptLines, wasTruncated: true }
324}
325

Callers 1

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected