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

Function buildMemoryPrompt

src/memdir/memdir.ts:271–315  ·  view source on GitHub ↗
(params: {
  displayName: string
  memoryDir: string
  extraGuidelines?: string[]
})

Source from the content-addressed store, hash-verified

269 * Used by agent memory (which has no getClaudeMds() equivalent).
270 */
271export function buildMemoryPrompt(params: {
272 displayName: string
273 memoryDir: string
274 extraGuidelines?: string[]
275}): string {
276 const { displayName, memoryDir, extraGuidelines } = params
277 const fs = getFsImplementation()
278 const entrypoint = memoryDir + ENTRYPOINT_NAME
279
280 // Directory creation is the caller's responsibility (loadMemoryPrompt /
281 // loadAgentMemoryPrompt). Builders only read, they don't mkdir.
282
283 // Read existing memory entrypoint (sync: prompt building is synchronous)
284 let entrypointContent = ''
285 try {
286 // eslint-disable-next-line custom-rules/no-sync-fs
287 entrypointContent = fs.readFileSync(entrypoint, { encoding: 'utf-8' })
288 } catch {
289 // No memory file yet
290 }
291
292 const lines = buildMemoryLines(displayName, memoryDir, extraGuidelines)
293
294 if (entrypointContent.trim()) {
295 const t = truncateEntrypointContent(entrypointContent)
296 const memoryType = displayName === AUTO_MEM_DISPLAY_NAME ? 'auto' : 'agent'
297 logMemoryDirCounts(memoryDir, {
298 content_length: t.byteCount,
299 line_count: t.lineCount,
300 was_truncated: t.wasLineTruncated,
301 was_byte_truncated: t.wasByteTruncated,
302 memory_type:
303 memoryType as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
304 })
305 lines.push(`## ${ENTRYPOINT_NAME}`, '', t.content)
306 } else {
307 lines.push(
308 `## ${ENTRYPOINT_NAME}`,
309 '',
310 `Your ${ENTRYPOINT_NAME} is currently empty. When you save new memories, they will appear here.`,
311 )
312 }
313
314 return lines.join('\n')
315}
316
317/**
318 * Assistant-mode daily-log prompt. Gated behind feature('KAIROS').

Callers 1

loadAgentMemoryPromptFunction · 0.85

Calls 4

getFsImplementationFunction · 0.85
buildMemoryLinesFunction · 0.85
logMemoryDirCountsFunction · 0.85

Tested by

no test coverage detected