MCPcopy Create free account
hub / github.com/Noumena-Network/code / readMemoriesForSurfacing

Function readMemoriesForSurfacing

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

Source from the content-addressed store, hash-verified

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