MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / readMemoriesForSurfacing

Function readMemoriesForSurfacing

src/utils/attachments.ts:2337–2379  ·  view source on GitHub ↗
(
  selected: ReadonlyArray<{ path: string; mtimeMs: number }>,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

2335 * Exported for direct testing without mocking the ranker + GB gates.
2336 */
2337export async function readMemoriesForSurfacing(
2338 selected: ReadonlyArray<{ path: string; mtimeMs: number }>,
2339 signal?: AbortSignal,
2340): Promise<
2341 Array<{
2342 path: string
2343 content: string
2344 mtimeMs: number
2345 header: string
2346 limit?: number
2347 }>
2348> {
2349 const results = await Promise.all(
2350 selected.map(async ({ path: filePath, mtimeMs }) => {
2351 try {
2352 const result = await readFileInRange(
2353 filePath,
2354 0,
2355 MAX_MEMORY_LINES,
2356 MAX_MEMORY_BYTES,
2357 signal,
2358 { truncateOnByteLimit: true },
2359 )
2360 const truncated =
2361 result.totalLines > MAX_MEMORY_LINES || result.truncatedByBytes
2362 const content = truncated
2363 ? result.content +
2364 `\n\n> This memory file was truncated (${result.truncatedByBytes ? `${MAX_MEMORY_BYTES} byte limit` : `first ${MAX_MEMORY_LINES} lines`}). Use the ${FILE_READ_TOOL_NAME} tool to view the complete file at: ${filePath}`
2365 : result.content
2366 return {
2367 path: filePath,
2368 content,
2369 mtimeMs,
2370 header: memoryHeader(filePath, mtimeMs),
2371 limit: truncated ? result.lineCount : undefined,
2372 }
2373 } catch {
2374 return null
2375 }
2376 }),
2377 )
2378 return results.filter(r => r !== null)
2379}
2380
2381/**
2382 * Header string for a relevant-memory block. Exported so messages.ts

Callers 1

Calls 2

readFileInRangeFunction · 0.85
memoryHeaderFunction · 0.85

Tested by

no test coverage detected