MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / saveMemoryFile

Function saveMemoryFile

tools/claw-launcher-ui/memory.mjs:249–267  ·  view source on GitHub ↗
(workspaceDir, filename, content, frontmatter = {})

Source from the content-addressed store, hash-verified

247 * Save a memory file with frontmatter.
248 */
249export async function saveMemoryFile(workspaceDir, filename, content, frontmatter = {}) {
250 if (!workspaceDir || !filename) throw new Error('Missing workspaceDir or filename')
251 const safe = basename(filename)
252 if (!safe.endsWith('.md')) throw new Error('Filename must end with .md')
253
254 const topicsPath = join(memoryDir(workspaceDir), TOPICS_DIR)
255 await mkdir(topicsPath, { recursive: true })
256
257 // Build content with frontmatter
258 const fm = frontmatter
259 const fmBlock = `---\nname: ${fm.name || safe.replace('.md', '')}\ndescription: ${fm.description || ''}\ntype: ${fm.type || 'project'}\n---\n\n`
260 const fullContent = content.startsWith('---') ? content : fmBlock + content
261
262 await writeFile(join(topicsPath, safe), fullContent, 'utf8')
263
264 // Update MEMORY.md index
265 await updateMemoryIndex(workspaceDir)
266 return { ok: true }
267}
268
269/**
270 * Delete a memory file.

Callers 1

server.mjsFile · 0.90

Calls 3

memoryDirFunction · 0.85
writeFileFunction · 0.85
updateMemoryIndexFunction · 0.85

Tested by

no test coverage detected