( agentType: string, scope: AgentMemoryScope, snapshotTimestamp: string, )
| 162 | * Replace local agent memory with the snapshot. |
| 163 | */ |
| 164 | export async function replaceFromSnapshot( |
| 165 | agentType: string, |
| 166 | scope: AgentMemoryScope, |
| 167 | snapshotTimestamp: string, |
| 168 | ): Promise<void> { |
| 169 | logForDebugging( |
| 170 | `Replacing agent memory for ${agentType} with project snapshot`, |
| 171 | ) |
| 172 | // Remove existing .md files before copying to avoid orphans |
| 173 | const localMemDir = getAgentMemoryDir(agentType, scope) |
| 174 | try { |
| 175 | const existing = await readdir(localMemDir, { withFileTypes: true }) |
| 176 | for (const dirent of existing) { |
| 177 | if (dirent.isFile() && dirent.name.endsWith('.md')) { |
| 178 | await unlink(join(localMemDir, dirent.name)) |
| 179 | } |
| 180 | } |
| 181 | } catch { |
| 182 | // Directory may not exist yet |
| 183 | } |
| 184 | await copySnapshotToLocal(agentType, scope) |
| 185 | await saveSyncedMeta(agentType, scope, snapshotTimestamp) |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Mark the current snapshot as synced without changing local memory. |
nothing calls this directly
no test coverage detected