(workspaceDir, filename, content, frontmatter = {})
| 247 | * Save a memory file with frontmatter. |
| 248 | */ |
| 249 | export 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. |
no test coverage detected