@@ -69,6 +69,9 @@ export const webviewMessageHandler = async (
6969 const updateGlobalState = async < K extends keyof GlobalState > ( key : K , value : GlobalState [ K ] ) =>
7070 await provider . contextProxy . setValue ( key , value )
7171
72+ const getCurrentCwd = ( ) => {
73+ return provider . getCurrentTask ( ) ?. cwd || provider . cwd
74+ }
7275 /**
7376 * Shared utility to find message indices based on timestamp
7477 */
@@ -912,10 +915,14 @@ export const webviewMessageHandler = async (
912915 saveImage ( message . dataUri ! )
913916 break
914917 case "openFile" :
915- openFile ( message . text ! , message . values as { create ?: boolean ; content ?: string ; line ?: number } )
918+ let filePath : string = message . text !
919+ if ( ! path . isAbsolute ( filePath ) ) {
920+ filePath = path . join ( getCurrentCwd ( ) , filePath )
921+ }
922+ openFile ( filePath , message . values as { create ?: boolean ; content ?: string ; line ?: number } )
916923 break
917924 case "openMention" :
918- openMention ( message . text )
925+ openMention ( getCurrentCwd ( ) , message . text )
919926 break
920927 case "openExternal" :
921928 if ( message . url ) {
@@ -1010,8 +1017,8 @@ export const webviewMessageHandler = async (
10101017 return
10111018 }
10121019
1013- const workspaceFolder = vscode . workspace . workspaceFolders [ 0 ]
1014- const rooDir = path . join ( workspaceFolder . uri . fsPath , ".roo" )
1020+ const workspaceFolder = getCurrentCwd ( )
1021+ const rooDir = path . join ( workspaceFolder , ".roo" )
10151022 const mcpPath = path . join ( rooDir , "mcp.json" )
10161023
10171024 try {
@@ -1660,7 +1667,7 @@ export const webviewMessageHandler = async (
16601667 }
16611668 break
16621669 case "searchCommits" : {
1663- const cwd = provider . cwd
1670+ const cwd = getCurrentCwd ( )
16641671 if ( cwd ) {
16651672 try {
16661673 const commits = await searchCommits ( message . query || "" , cwd )
@@ -1678,7 +1685,7 @@ export const webviewMessageHandler = async (
16781685 break
16791686 }
16801687 case "searchFiles" : {
1681- const workspacePath = getWorkspacePath ( )
1688+ const workspacePath = getCurrentCwd ( )
16821689
16831690 if ( ! workspacePath ) {
16841691 // Handle case where workspace path is not available
@@ -2662,7 +2669,7 @@ export const webviewMessageHandler = async (
26622669 case "requestCommands" : {
26632670 try {
26642671 const { getCommands } = await import ( "../../services/command/commands" )
2665- const commands = await getCommands ( provider . cwd || "" )
2672+ const commands = await getCommands ( getCurrentCwd ( ) )
26662673
26672674 // Convert to the format expected by the frontend
26682675 const commandList = commands . map ( ( command ) => ( {
@@ -2691,7 +2698,7 @@ export const webviewMessageHandler = async (
26912698 try {
26922699 if ( message . text ) {
26932700 const { getCommand } = await import ( "../../services/command/commands" )
2694- const command = await getCommand ( provider . cwd || "" , message . text )
2701+ const command = await getCommand ( getCurrentCwd ( ) , message . text )
26952702
26962703 if ( command && command . filePath ) {
26972704 openFile ( command . filePath )
@@ -2711,7 +2718,7 @@ export const webviewMessageHandler = async (
27112718 try {
27122719 if ( message . text && message . values ?. source ) {
27132720 const { getCommand } = await import ( "../../services/command/commands" )
2714- const command = await getCommand ( provider . cwd || "" , message . text )
2721+ const command = await getCommand ( getCurrentCwd ( ) , message . text )
27152722
27162723 if ( command && command . filePath ) {
27172724 // Delete the command file
@@ -2743,8 +2750,12 @@ export const webviewMessageHandler = async (
27432750 const globalConfigDir = path . join ( os . homedir ( ) , ".roo" )
27442751 commandsDir = path . join ( globalConfigDir , "commands" )
27452752 } else {
2753+ if ( ! vscode . workspace . workspaceFolders ?. length ) {
2754+ vscode . window . showErrorMessage ( t ( "common:errors.no_workspace" ) )
2755+ return
2756+ }
27462757 // Project commands
2747- const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
2758+ const workspaceRoot = getCurrentCwd ( )
27482759 if ( ! workspaceRoot ) {
27492760 vscode . window . showErrorMessage ( t ( "common:errors.no_workspace_for_project_command" ) )
27502761 break
@@ -2824,7 +2835,7 @@ export const webviewMessageHandler = async (
28242835
28252836 // Refresh commands list
28262837 const { getCommands } = await import ( "../../services/command/commands" )
2827- const commands = await getCommands ( provider . cwd || "" )
2838+ const commands = await getCommands ( getCurrentCwd ( ) || "" )
28282839 const commandList = commands . map ( ( command ) => ( {
28292840 name : command . name ,
28302841 source : command . source ,
0 commit comments