| ... | ... | @@ -24,16 +24,6 @@ function tokenStartForCursor(text: string, cursor: number): number { |
| 24 | 24 | return index + 1; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | | function dedupePaths(paths: string[]): string[] { |
| 28 | | const unique = new Set<string>(); |
| 29 | | for (const rawPath of paths) { |
| 30 | | const normalized = rawPath.trim(); |
| 31 | | if (!normalized) continue; |
| 32 | | unique.add(normalized); |
| 33 | | } |
| 34 | | return [...unique]; |
| 35 | | } |
| 36 | | |
| 37 | 27 | export function detectComposerTrigger(text: string, cursorInput: number): ComposerTrigger | null { |
| 38 | 28 | const cursor = clampCursor(text, cursorInput); |
| 39 | 29 | const lineStart = text.lastIndexOf("\n", Math.max(0, cursor - 1)) + 1; |
| ... | ... | @@ -98,31 +88,3 @@ export function replaceTextRange( |
| 98 | 88 | const nextText = `${text.slice(0, safeStart)}${replacement}${text.slice(safeEnd)}`; |
| 99 | 89 | return { text: nextText, cursor: safeStart + replacement.length }; |
| 100 | 90 | } |
| 101 | | |
| 102 | | export function buildPromptInput(text: string, taggedPaths: string[]): string { |
| 103 | | const trimmedPrompt = text.trim(); |
| 104 | | const normalizedPaths = dedupePaths(taggedPaths); |
| 105 | | if (normalizedPaths.length === 0) { |
| 106 | | return trimmedPrompt; |
| 107 | | } |
| 108 | | |
| 109 | | const tagBlock = `Referenced paths:\n${normalizedPaths.map((entry) => `- ${entry}`).join("\n")}`; |
| 110 | | if (!trimmedPrompt) { |
| 111 | | return tagBlock; |
| 112 | | } |
| 113 | | return `${trimmedPrompt}\n\n${tagBlock}`; |
| 114 | | } |
| 115 | | |
| 116 | | export function buildUserVisiblePrompt(text: string, taggedPaths: string[]): string { |
| 117 | | const trimmedPrompt = text.trim(); |
| 118 | | const normalizedPaths = dedupePaths(taggedPaths); |
| 119 | | if (normalizedPaths.length === 0) { |
| 120 | | return trimmedPrompt; |
| 121 | | } |
| 122 | | |
| 123 | | const tagsSummary = normalizedPaths.map((entry) => `@${entry}`).join(" "); |
| 124 | | if (!trimmedPrompt) { |
| 125 | | return tagsSummary; |
| 126 | | } |
| 127 | | return `${trimmedPrompt}\n\n${tagsSummary}`; |
| 128 | | } |