@@ -66,6 +66,9 @@ export const webviewMessageHandler = async (
6666 const updateGlobalState = async < K extends keyof GlobalState > ( key : K , value : GlobalState [ K ] ) =>
6767 await provider . contextProxy . setValue ( key , value )
6868
69+ const getCurrentCwd = ( ) => {
70+ return provider . getCurrentCline ( ) ?. cwd
71+ }
6972 /**
7073 * Shared utility to find message indices based on timestamp
7174 */
@@ -800,8 +803,8 @@ export const webviewMessageHandler = async (
800803 return
801804 }
802805
803- const workspaceFolder = vscode . workspace . workspaceFolders [ 0 ]
804- const rooDir = path . join ( workspaceFolder . uri . fsPath , ".roo" )
806+ const workspaceFolder = getCurrentCwd ( ) || provider . cwd || vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath
807+ const rooDir = path . join ( workspaceFolder , ".roo" )
805808 const mcpPath = path . join ( rooDir , "mcp.json" )
806809
807810 try {
@@ -2406,7 +2409,7 @@ export const webviewMessageHandler = async (
24062409 case "requestCommands" : {
24072410 try {
24082411 const { getCommands } = await import ( "../../services/command/commands" )
2409- const commands = await getCommands ( provider . cwd || "" )
2412+ const commands = await getCommands ( getCurrentCwd ( ) || provider . cwd || "" )
24102413
24112414 // Convert to the format expected by the frontend
24122415 const commandList = commands . map ( ( command ) => ( {
@@ -2435,7 +2438,7 @@ export const webviewMessageHandler = async (
24352438 try {
24362439 if ( message . text ) {
24372440 const { getCommand } = await import ( "../../services/command/commands" )
2438- const command = await getCommand ( provider . cwd || "" , message . text )
2441+ const command = await getCommand ( getCurrentCwd ( ) || provider . cwd || "" , message . text )
24392442
24402443 if ( command && command . filePath ) {
24412444 openFile ( command . filePath )
@@ -2455,7 +2458,7 @@ export const webviewMessageHandler = async (
24552458 try {
24562459 if ( message . text && message . values ?. source ) {
24572460 const { getCommand } = await import ( "../../services/command/commands" )
2458- const command = await getCommand ( provider . cwd || "" , message . text )
2461+ const command = await getCommand ( getCurrentCwd ( ) || provider . cwd || "" , message . text )
24592462
24602463 if ( command && command . filePath ) {
24612464 // Delete the command file
@@ -2487,8 +2490,13 @@ export const webviewMessageHandler = async (
24872490 const globalConfigDir = path . join ( os . homedir ( ) , ".roo" )
24882491 commandsDir = path . join ( globalConfigDir , "commands" )
24892492 } else {
2493+ if ( ! vscode . workspace . workspaceFolders ?. length ) {
2494+ vscode . window . showErrorMessage ( t ( "common:errors.no_workspace" ) )
2495+ return
2496+ }
24902497 // Project commands
2491- const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
2498+ const workspaceRoot =
2499+ getCurrentCwd ( ) || provider . cwd || vscode . workspace . workspaceFolders [ 0 ] ?. uri ?. fsPath
24922500 if ( ! workspaceRoot ) {
24932501 vscode . window . showErrorMessage ( t ( "common:errors.no_workspace_for_project_command" ) )
24942502 break
0 commit comments