MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / buildMemoryPrompt

Function buildMemoryPrompt

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

Source from the content-addressed store, hash-verified

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