( agentType: string, scope: AgentMemoryScope, )
| 110 | * Check if a snapshot exists and whether it's newer than what we last synced. |
| 111 | */ |
| 112 | export async function checkAgentMemorySnapshot( |
| 113 | agentType: string, |
| 114 | scope: AgentMemoryScope, |
| 115 | ): Promise<{ |
| 116 | action: 'none' | 'initialize' | 'prompt-update' |
| 117 | snapshotTimestamp?: string |
| 118 | }> { |
| 119 | const snapshotMeta = await readJsonFile( |
| 120 | getSnapshotJsonPath(agentType), |
| 121 | snapshotMetaSchema(), |
| 122 | ) |
| 123 | |
| 124 | if (!snapshotMeta) { |
| 125 | return { action: 'none' } |
| 126 | } |
| 127 | |
| 128 | const localMemDir = getAgentMemoryDir(agentType, scope) |
| 129 | |
| 130 | let hasLocalMemory = false |
| 131 | try { |
| 132 | const dirents = await readdir(localMemDir, { withFileTypes: true }) |
| 133 | hasLocalMemory = dirents.some(d => d.isFile() && d.name.endsWith('.md')) |
| 134 | } catch { |
| 135 | // Directory doesn't exist |
| 136 | } |
| 137 | |
| 138 | if (!hasLocalMemory) { |
| 139 | return { action: 'initialize', snapshotTimestamp: snapshotMeta.updatedAt } |
| 140 | } |
| 141 | |
| 142 | const syncedMeta = await readJsonFile( |
| 143 | getSyncedJsonPath(agentType, scope), |
| 144 | syncedMetaSchema(), |
| 145 | ) |
| 146 | |
| 147 | if ( |
| 148 | !syncedMeta || |
| 149 | new Date(snapshotMeta.updatedAt) > new Date(syncedMeta.syncedFrom) |
| 150 | ) { |
| 151 | return { |
| 152 | action: 'prompt-update', |
| 153 | snapshotTimestamp: snapshotMeta.updatedAt, |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return { action: 'none' } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Initialize local agent memory from a snapshot (first-time setup). |
no test coverage detected