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

Function buildMemoryPrompt

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

Source from the content-addressed store, hash-verified

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

Callers 1

loadAgentMemoryPromptFunction · 0.85

Calls 5

getFsImplementationFunction · 0.85
buildMemoryLinesFunction · 0.85
logMemoryDirCountsFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected