(cwd: string)
| 53 | |
| 54 | /** DB → MD: regenerate both memory files from the store. Best-effort; never throws. */ |
| 55 | export async function exportMemory(cwd: string): Promise<{ user: string; project: string }> { |
| 56 | const paths = memoryPaths(cwd); |
| 57 | try { |
| 58 | const store = getSessionStore(); |
| 59 | const userFacts = store.getFactsByScope('user', cwd, 1000); |
| 60 | const projFacts = store.getFactsByScope('project', cwd, 1000); |
| 61 | await fs.mkdir(path.dirname(paths.user), { recursive: true }).catch(() => {}); |
| 62 | await fs.mkdir(path.dirname(paths.project), { recursive: true }).catch(() => {}); |
| 63 | await fs.writeFile(paths.user, serializeMemory(userFacts, 'user (global)')); |
| 64 | await fs.writeFile(paths.project, serializeMemory(projFacts, projectTitle(cwd))); |
| 65 | } catch { /* mirror is best-effort — a failed write never breaks a fact write */ } |
| 66 | return paths; |
| 67 | } |
| 68 | |
| 69 | /** MD → DB: add any bullet present in a mirror file but missing from the store. Returns the count |
| 70 | * added per scope. Additive only (removing a line won't delete a fact — use `/memory forget`). */ |
no test coverage detected