diff --git a/packages/types/src/task.ts b/packages/types/src/task.ts index 405b7a5fb2..56a1acf828 100644 --- a/packages/types/src/task.ts +++ b/packages/types/src/task.ts @@ -81,6 +81,16 @@ export type TaskProviderEvents = { [RooCodeEventName.ProviderProfileChanged]: [config: { name: string; provider?: string }] } +/** + * Selection context captured from the editor + */ +export interface SelectionContext { + selectedText: string + selectionFilePath: string + selectionStartLine: number + selectionEndLine: number +} + /** * TaskLike */ @@ -92,12 +102,7 @@ export interface CreateTaskOptions { consecutiveMistakeLimit?: number experiments?: Record initialTodos?: TodoItem[] - selectionContext?: { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - } + selectionContext?: SelectionContext } export enum TaskStatus { diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 589cc2e2cb..c77089ad5b 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -24,6 +24,7 @@ import { type ToolProgressStatus, type HistoryItem, type CreateTaskOptions, + type SelectionContext, RooCodeEventName, TelemetryEventName, TaskStatus, @@ -142,12 +143,7 @@ export interface TaskOptions extends CreateTaskOptions { onCreated?: (task: Task) => void initialTodos?: TodoItem[] workspacePath?: string - selectionContext?: { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - } + selectionContext?: SelectionContext } export class Task extends EventEmitter implements TaskLike { @@ -163,12 +159,7 @@ export class Task extends EventEmitter implements TaskLike { // Temporary storage for selection context during message processing // This is cleared after being used in getEnvironmentDetails - private _currentSelectionContext?: { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - } + private _currentSelectionContext?: SelectionContext readonly rootTask: Task | undefined = undefined readonly parentTask: Task | undefined = undefined @@ -469,14 +460,7 @@ export class Task extends EventEmitter implements TaskLike { * Get and clear the current selection context. * This ensures selection context is only used once and doesn't persist. */ - public getAndClearSelectionContext(): - | { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - } - | undefined { + public getAndClearSelectionContext(): SelectionContext | undefined { const context = this._currentSelectionContext this._currentSelectionContext = undefined return context @@ -1001,12 +985,7 @@ export class Task extends EventEmitter implements TaskLike { askResponse: ClineAskResponse, text?: string, images?: string[], - selectionContext?: { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - }, + selectionContext?: SelectionContext, ) { this.askResponse = askResponse this.askResponseText = text @@ -1290,16 +1269,7 @@ export class Task extends EventEmitter implements TaskLike { // Lifecycle // Start / Resume / Abort / Dispose - private async startTask( - task?: string, - images?: string[], - selectionContext?: { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - }, - ): Promise { + private async startTask(task?: string, images?: string[], selectionContext?: SelectionContext): Promise { if (this.enableBridge) { try { await BridgeOrchestrator.subscribeToTask(this) diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index bc93fbca42..4e5ee0cf91 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -11,6 +11,7 @@ import { type ClineMessage, type TelemetrySetting, type UserSettingsConfig, + type SelectionContext, TelemetryEventName, RooCodeSettings, Experiments, @@ -428,14 +429,7 @@ export const webviewMessageHandler = async ( } // Helper function to capture current editor selection - const captureSelectionContext = (): - | { - selectedText: string - selectionFilePath: string - selectionStartLine: number - selectionEndLine: number - } - | undefined => { + const captureSelectionContext = (): SelectionContext | undefined => { const editor = vscode.window.activeTextEditor if (editor && !editor.selection.isEmpty) { const selection = editor.selection