From b61aba948353c69ffeabb0d4a7eb487699a91ec0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Feb 2026 21:23:10 +0000 Subject: [PATCH] Wire buildPromptInput and buildUserVisiblePrompt into onSend flow Add extractTaggedPaths helper to parse @path tokens from prompt text. In the onSend handler, use buildPromptInput for the model input (structured 'Referenced paths' block) and buildUserVisiblePrompt for the user-visible message display. --- apps/web/src/components/ChatView.tsx | 12 +++++++++--- apps/web/src/composer-logic.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 4a5788e0c6..433e921605 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -36,7 +36,10 @@ import { isElectron } from "../env"; import { buildBootstrapInput } from "../historyBootstrap"; import { type ComposerTriggerKind, + buildPromptInput, + buildUserVisiblePrompt, detectComposerTrigger, + extractTaggedPaths, replaceTextRange, } from "../composer-logic"; import { @@ -1056,6 +1059,9 @@ export default function ChatView() { e.preventDefault(); if (!api || !activeThread || isSending || isConnecting) return; const trimmed = prompt.trim(); + const { cleanText, paths: taggedPaths } = extractTaggedPaths(trimmed); + const userVisibleText = buildUserVisiblePrompt(cleanText, taggedPaths); + const modelText = buildPromptInput(cleanText, taggedPaths); if (!trimmed && composerImages.length === 0) return; if (!activeProject) return; const composerImagesSnapshot = [...composerImages]; @@ -1120,7 +1126,7 @@ export default function ChatView() { type: "PUSH_USER_MESSAGE", threadId: activeThread.id, id: crypto.randomUUID(), - text: trimmed, + text: userVisibleText, ...(messageAttachments.length > 0 ? { attachments: messageAttachments } : {}), }); const previousMessages = activeThread.messages; @@ -1148,14 +1154,14 @@ export default function ChatView() { const shouldBootstrap = previousMessages.length > 0 && (sessionInfo.continuityState === "new" || sessionInfo.continuityState === "fallback_new"); - const latestPromptForBootstrap = trimmed || IMAGE_ONLY_BOOTSTRAP_PROMPT; + const latestPromptForBootstrap = modelText || IMAGE_ONLY_BOOTSTRAP_PROMPT; const input = shouldBootstrap ? buildBootstrapInput( previousMessages, latestPromptForBootstrap, PROVIDER_SEND_TURN_MAX_INPUT_CHARS, ).text - : trimmed || undefined; + : modelText || undefined; await api.providers.sendTurn({ sessionId: sessionInfo.sessionId, ...(input ? { input } : {}), diff --git a/apps/web/src/composer-logic.ts b/apps/web/src/composer-logic.ts index db6ae79b7f..bbfde9f49b 100644 --- a/apps/web/src/composer-logic.ts +++ b/apps/web/src/composer-logic.ts @@ -99,6 +99,18 @@ export function replaceTextRange( return { text: nextText, cursor: safeStart + replacement.length }; } +export function extractTaggedPaths(text: string): { cleanText: string; paths: string[] } { + const paths: string[] = []; + const cleanText = text.replace(/@(\S+)/g, (_match, path: string) => { + paths.push(path); + return ""; + }); + if (paths.length === 0) { + return { cleanText: text.trim(), paths: [] }; + } + return { cleanText: cleanText.replace(/ {2,}/g, " ").trim(), paths }; +} + export function buildPromptInput(text: string, taggedPaths: string[]): string { const trimmedPrompt = text.trim(); const normalizedPaths = dedupePaths(taggedPaths);