(content: string)
| 2756 | // a feature-gated module so it doesn't leak into external builds. |
| 2757 | |
| 2758 | export function extractAtMentionedFiles(content: string): string[] { |
| 2759 | // Extract filenames mentioned with @ symbol, including line range syntax: @file.txt#L10-20 |
| 2760 | // Also supports quoted paths for files with spaces: @"my/file with spaces.txt" |
| 2761 | // Example: "foo bar @baz moo" would extract "baz" |
| 2762 | // Example: 'check @"my file.txt" please' would extract "my file.txt" |
| 2763 | |
| 2764 | // Two patterns: quoted paths and regular paths |
| 2765 | const quotedAtMentionRegex = /(^|\s)@"([^"]+)"/g |
| 2766 | const regularAtMentionRegex = /(^|\s)@([^\s]+)\b/g |
| 2767 | |
| 2768 | const quotedMatches: string[] = [] |
| 2769 | const regularMatches: string[] = [] |
| 2770 | |
| 2771 | // Extract quoted mentions first (skip agent mentions like @"code-reviewer (agent)") |
| 2772 | let match |
| 2773 | while ((match = quotedAtMentionRegex.exec(content)) !== null) { |
| 2774 | if (match[2] && !match[2].endsWith(' (agent)')) { |
| 2775 | quotedMatches.push(match[2]) // The content inside quotes |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | // Extract regular mentions |
| 2780 | const regularMatchArray: string[] = content.match(regularAtMentionRegex) ?? [] |
| 2781 | regularMatchArray.forEach(match => { |
| 2782 | const filename = match.slice(match.indexOf('@') + 1) |
| 2783 | // Don't include if it starts with a quote (already handled as quoted) |
| 2784 | if (!filename.startsWith('"')) { |
| 2785 | regularMatches.push(filename) |
| 2786 | } |
| 2787 | }) |
| 2788 | |
| 2789 | // Combine and deduplicate |
| 2790 | return uniq([...quotedMatches, ...regularMatches]) |
| 2791 | } |
| 2792 | |
| 2793 | export function extractMcpResourceMentions(content: string): string[] { |
| 2794 | // Extract MCP resources mentioned with @ symbol in format @server:uri |
no test coverage detected