@@ -52,7 +52,7 @@ import { parseMentions } from "./mentions"
5252import { AssistantMessageContent , parseAssistantMessage , ToolParamName , ToolUseName } from "./assistant-message"
5353import { formatResponse } from "./prompts/responses"
5454import { SYSTEM_PROMPT } from "./prompts/system"
55- import { modes , defaultModeSlug , getModeBySlug } from "../shared/modes"
55+ import { modes , defaultModeSlug , getModeBySlug , parseSlashCommand } from "../shared/modes"
5656import { truncateHalfConversation } from "./sliding-window"
5757import { ClineProvider , GlobalFileNames } from "./webview/ClineProvider"
5858import { detectCodeOmission } from "../integrations/editor/detect-omission"
@@ -77,6 +77,29 @@ export class Cline {
7777 private terminalManager : TerminalManager
7878 private urlContentFetcher : UrlContentFetcher
7979 private browserSession : BrowserSession
80+
81+ /**
82+ * Processes a message for slash commands and handles mode switching if needed.
83+ * @param message The message to process
84+ * @returns The processed message with slash command removed if one was present
85+ */
86+ private async handleSlashCommand ( message : string ) : Promise < string > {
87+ if ( ! message ) return message
88+
89+ const { customModes } = ( await this . providerRef . deref ( ) ?. getState ( ) ) ?? { }
90+ const slashCommand = parseSlashCommand ( message , customModes )
91+
92+ if ( slashCommand ) {
93+ // Switch mode before processing the remaining message
94+ const provider = this . providerRef . deref ( )
95+ if ( provider ) {
96+ await provider . handleModeSwitch ( slashCommand . modeSlug )
97+ return slashCommand . remainingMessage
98+ }
99+ }
100+
101+ return message
102+ }
80103 private didEditFile : boolean = false
81104 customInstructions ?: string
82105 diffStrategy ?: DiffStrategy
@@ -355,6 +378,11 @@ export class Cline {
355378 }
356379
357380 async handleWebviewAskResponse ( askResponse : ClineAskResponse , text ?: string , images ?: string [ ] ) {
381+ // Process slash command if present
382+ if ( text ) {
383+ text = await this . handleSlashCommand ( text )
384+ }
385+
358386 this . askResponse = askResponse
359387 this . askResponseText = text
360388 this . askResponseImages = images
@@ -437,6 +465,22 @@ export class Cline {
437465 this . apiConversationHistory = [ ]
438466 await this . providerRef . deref ( ) ?. postStateToWebview ( )
439467
468+ // Check for slash command if task is provided
469+ if ( task ) {
470+ const { customModes } = ( await this . providerRef . deref ( ) ?. getState ( ) ) ?? { }
471+ const slashCommand = parseSlashCommand ( task , customModes )
472+
473+ if ( slashCommand ) {
474+ // Switch mode before processing the remaining message
475+ const provider = this . providerRef . deref ( )
476+ if ( provider ) {
477+ await provider . handleModeSwitch ( slashCommand . modeSlug )
478+ // Update task to be just the remaining message
479+ task = slashCommand . remainingMessage
480+ }
481+ }
482+ }
483+
440484 await this . say ( "text" , task , images )
441485
442486 let imageBlocks : Anthropic . ImageBlockParam [ ] = formatResponse . imageBlocks ( images )
0 commit comments