Skip to content

Commit 64f37fc

Browse files
committed
feat: add persistContextReferences setting to maintain context across conversations
- Added new VSCode setting 'roo-cline.persistContextReferences' (default: false) - When enabled, @mentions and /commands persist in the input field after sending messages - Extracts and preserves context references when clearing the input field - Maintains backward compatibility with default behavior (clearing context) - Addresses issue #8439 for improved workflow efficiency
1 parent 9bcd991 commit 64f37fc

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export const globalSettingsSchema = z.object({
152152
hasOpenedModeSelector: z.boolean().optional(),
153153
lastModeExportPath: z.string().optional(),
154154
lastModeImportPath: z.string().optional(),
155+
persistContextReferences: z.boolean().optional(),
155156
})
156157

157158
export type GlobalSettings = z.infer<typeof globalSettingsSchema>

src/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@
423423
"default": false,
424424
"description": "%settings.newTaskRequireTodos.description%"
425425
},
426+
"roo-cline.persistContextReferences": {
427+
"type": "boolean",
428+
"default": false,
429+
"description": "%settings.persistContextReferences.description%"
430+
},
426431
"roo-cline.codeIndex.embeddingBatchSize": {
427432
"type": "number",
428433
"default": 60,

src/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
"settings.useAgentRules.description": "Enable loading of AGENTS.md files for agent-specific rules (see https://agent-rules.org/)",
4343
"settings.apiRequestTimeout.description": "Maximum time in seconds to wait for API responses (0 = no timeout, 1-3600s, default: 600s). Higher values are recommended for local providers like LM Studio and Ollama that may need more processing time.",
4444
"settings.newTaskRequireTodos.description": "Require todos parameter when creating new tasks with the new_task tool",
45+
"settings.persistContextReferences.description": "Keep context references (@mentions) in the input field after sending a message, allowing them to persist across conversations in the same task",
4546
"settings.codeIndex.embeddingBatchSize.description": "The batch size for embedding operations during code indexing. Adjust this based on your API provider's limits. Default is 60."
4647
}

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export type ExtensionState = Pick<
288288
| "openRouterImageGenerationSelectedModel"
289289
| "includeTaskHistoryInEnhance"
290290
| "reasoningBlockCollapsed"
291+
| "persistContextReferences"
291292
> & {
292293
version: string
293294
clineMessages: ClineMessage[]

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { AudioType } from "@roo/WebviewMessage"
2424
import { getAllModes } from "@roo/modes"
2525
import { ProfileValidator } from "@roo/ProfileValidator"
2626
import { getLatestTodo } from "@roo/todo"
27+
import { mentionRegexGlobal, commandRegexGlobal } from "@roo/context-mentions"
2728

2829
import { vscode } from "@src/utils/vscode"
2930
import {
@@ -123,6 +124,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
123124
soundVolume,
124125
cloudIsAuthenticated,
125126
messageQueue = [],
127+
persistContextReferences,
126128
} = useExtensionState()
127129

128130
const messagesRef = useRef(messages)
@@ -563,6 +565,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
563565
}
564566
}, [])
565567

568+
/**
569+
* Extracts mentions from text
570+
* @param text - The text to extract mentions from
571+
* @returns The extracted mentions as a string
572+
*/
573+
const extractMentions = useCallback((text: string): string => {
574+
// Extract all @mentions and /commands from the text
575+
const mentionMatches = text.match(mentionRegexGlobal) || []
576+
const commandMatches = text.match(commandRegexGlobal) || []
577+
578+
// Combine and deduplicate
579+
const allMentions = [...new Set([...mentionMatches, ...commandMatches])]
580+
581+
// Return as space-separated string
582+
return allMentions.join(" ")
583+
}, [])
584+
566585
const handleChatReset = useCallback(() => {
567586
// Clear any pending auto-approval timeout
568587
if (autoApproveTimeoutRef.current) {
@@ -573,7 +592,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
573592
userRespondedRef.current = false
574593

575594
// Only reset message-specific state, preserving mode.
576-
setInputValue("")
595+
// If persistContextReferences is enabled, extract and preserve mentions
596+
if (persistContextReferences && inputValueRef.current) {
597+
const mentions = extractMentions(inputValueRef.current)
598+
setInputValue(mentions)
599+
} else {
600+
setInputValue("")
601+
}
577602
setSendingDisabled(true)
578603
setSelectedImages([])
579604
setClineAsk(undefined)
@@ -582,7 +607,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
582607
// setPrimaryButtonText(undefined)
583608
// setSecondaryButtonText(undefined)
584609
disableAutoScrollRef.current = false
585-
}, [])
610+
}, [persistContextReferences, extractMentions])
586611

587612
/**
588613
* Handles sending messages to the extension
@@ -598,7 +623,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
598623
try {
599624
console.log("queueMessage", text, images)
600625
vscode.postMessage({ type: "queueMessage", text, images })
601-
setInputValue("")
626+
// If persistContextReferences is enabled, preserve mentions
627+
if (persistContextReferences) {
628+
const mentions = extractMentions(inputValueRef.current)
629+
setInputValue(mentions)
630+
} else {
631+
setInputValue("")
632+
}
602633
setSelectedImages([])
603634
} catch (error) {
604635
console.error(
@@ -650,7 +681,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
650681
handleChatReset()
651682
}
652683
},
653-
[handleChatReset, markFollowUpAsAnswered, sendingDisabled], // messagesRef and clineAskRef are stable
684+
[handleChatReset, markFollowUpAsAnswered, sendingDisabled, persistContextReferences, extractMentions], // messagesRef and clineAskRef are stable
654685
)
655686

656687
const handleSetChatBoxMessage = useCallback(

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { convertTextMateToHljs } from "@src/utils/textMateToHljs"
2727

2828
export interface ExtensionStateContextType extends ExtensionState {
2929
historyPreviewCollapsed?: boolean // Add the new state property
30+
persistContextReferences?: boolean // Add property for persisting context references
3031
didHydrateState: boolean
3132
showWelcome: boolean
3233
theme: any
@@ -158,6 +159,7 @@ export interface ExtensionStateContextType extends ExtensionState {
158159
setMaxDiagnosticMessages: (value: number) => void
159160
includeTaskHistoryInEnhance?: boolean
160161
setIncludeTaskHistoryInEnhance: (value: boolean) => void
162+
setPersistContextReferences: (value: boolean) => void
161163
}
162164

163165
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -559,6 +561,10 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
559561
},
560562
includeTaskHistoryInEnhance,
561563
setIncludeTaskHistoryInEnhance,
564+
persistContextReferences: state.persistContextReferences ?? false,
565+
setPersistContextReferences: (value) => {
566+
setState((prevState) => ({ ...prevState, persistContextReferences: value }))
567+
},
562568
}
563569

564570
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>

0 commit comments

Comments
 (0)