| 2518 | * from any iteration. |
| 2519 | */ |
| 2520 | export function filterDuplicateMemoryAttachments( |
| 2521 | attachments: Attachment[], |
| 2522 | readFileState: FileStateCache, |
| 2523 | ): Attachment[] { |
| 2524 | return attachments |
| 2525 | .map(attachment => { |
| 2526 | if (attachment.type !== 'relevant_memories') return attachment |
| 2527 | const filtered = attachment.memories.filter( |
| 2528 | m => !readFileState.has(m.path), |
| 2529 | ) |
| 2530 | for (const m of filtered) { |
| 2531 | readFileState.set(m.path, { |
| 2532 | content: m.content, |
| 2533 | timestamp: m.mtimeMs, |
| 2534 | offset: undefined, |
| 2535 | limit: m.limit, |
| 2536 | }) |
| 2537 | } |
| 2538 | return filtered.length > 0 ? { ...attachment, memories: filtered } : null |
| 2539 | }) |
| 2540 | .filter((a): a is Attachment => a !== null) |
| 2541 | } |
| 2542 | |
| 2543 | /** |
| 2544 | * Processes skill directories that were discovered during file operations. |