MCPcopy
hub / github.com/codeaashu/claude-code / readMemoriesForSurfacing

Function readMemoriesForSurfacing

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

Source from the content-addressed store, hash-verified

2277 * Exported for direct testing without mocking the ranker + GB gates.
2278 */
2279export async function readMemoriesForSurfacing(
2280 selected: ReadonlyArray<{ path: string; mtimeMs: number }>,
2281 signal?: AbortSignal,
2282): Promise<
2283 Array<{
2284 path: string
2285 content: string
2286 mtimeMs: number
2287 header: string
2288 limit?: number
2289 }>
2290> {
2291 const results = await Promise.all(
2292 selected.map(async ({ path: filePath, mtimeMs }) => {
2293 try {
2294 const result = await readFileInRange(
2295 filePath,
2296 0,
2297 MAX_MEMORY_LINES,
2298 MAX_MEMORY_BYTES,
2299 signal,
2300 { truncateOnByteLimit: true },
2301 )
2302 const truncated =
2303 result.totalLines > MAX_MEMORY_LINES || result.truncatedByBytes
2304 const content = truncated
2305 ? result.content +
2306 `\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}`
2307 : result.content
2308 return {
2309 path: filePath,
2310 content,
2311 mtimeMs,
2312 header: memoryHeader(filePath, mtimeMs),
2313 limit: truncated ? result.lineCount : undefined,
2314 }
2315 } catch {
2316 return null
2317 }
2318 }),
2319 )
2320 return results.filter(r => r !== null)
2321}
2322
2323/**
2324 * 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