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