MCPcopy
hub / github.com/codeaashu/claude-code / replaceFromSnapshot

Function replaceFromSnapshot

src/tools/AgentTool/agentMemorySnapshot.ts:164–186  ·  view source on GitHub ↗
(
  agentType: string,
  scope: AgentMemoryScope,
  snapshotTimestamp: string,
)

Source from the content-addressed store, hash-verified

162 * Replace local agent memory with the snapshot.
163 */
164export 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.

Callers

nothing calls this directly

Calls 6

logForDebuggingFunction · 0.85
getAgentMemoryDirFunction · 0.85
readdirFunction · 0.85
unlinkFunction · 0.85
copySnapshotToLocalFunction · 0.85
saveSyncedMetaFunction · 0.85

Tested by

no test coverage detected