* Find a file entry in the most recent file-snapshot system message in the transcript. * Scans backwards to find the latest snapshot.
( messages: LogOption['messages'], key: string, )
| 330 | * Scans backwards to find the latest snapshot. |
| 331 | */ |
| 332 | function findFileSnapshotEntry( |
| 333 | messages: LogOption['messages'], |
| 334 | key: string, |
| 335 | ): { key: string; path: string; content: string } | undefined { |
| 336 | for (let i = messages.length - 1; i >= 0; i--) { |
| 337 | const msg = messages[i] |
| 338 | if ( |
| 339 | msg?.type === 'system' && |
| 340 | 'subtype' in msg && |
| 341 | msg.subtype === 'file_snapshot' && |
| 342 | 'snapshotFiles' in msg |
| 343 | ) { |
| 344 | const files = msg.snapshotFiles as Array<{ |
| 345 | key: string |
| 346 | path: string |
| 347 | content: string |
| 348 | }> |
| 349 | return files.find(f => f.key === key) |
| 350 | } |
| 351 | } |
| 352 | return undefined |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Persist a snapshot of session files (plan, todos) to the transcript. |