@@ -328,7 +328,45 @@ export async function processFullResponseActions(
328328 let terminalType : "frontend" | "backend" = "backend" ; // default
329329 let cwd = cmdTag . cwd ? path . join ( appPath , cmdTag . cwd ) : appPath ;
330330
331- if ( chatMode === "ask" ) {
331+ // Check if this is a Python command - always route to backend
332+ const isPythonCommand = cleanCommand . toLowerCase ( ) . includes ( "python" ) ||
333+ cleanCommand . toLowerCase ( ) . includes ( "pip" ) ||
334+ cleanCommand . toLowerCase ( ) . includes ( "conda" ) ||
335+ cleanCommand . toLowerCase ( ) . includes ( "venv" ) ||
336+ cleanCommand . toLowerCase ( ) . includes ( "py " ) ;
337+
338+ // Check if this is a Node.js command - always route to frontend
339+ const isNodeCommand = cleanCommand . toLowerCase ( ) . includes ( "npm" ) ||
340+ cleanCommand . toLowerCase ( ) . includes ( "yarn" ) ||
341+ cleanCommand . toLowerCase ( ) . includes ( "pnpm" ) ||
342+ cleanCommand . toLowerCase ( ) . includes ( "node" ) ||
343+ cleanCommand . toLowerCase ( ) . includes ( "npx" ) ||
344+ cleanCommand . toLowerCase ( ) . includes ( "vite" ) ||
345+ cleanCommand . toLowerCase ( ) . includes ( "next" ) ||
346+ cleanCommand . toLowerCase ( ) . includes ( "react" ) ||
347+ cleanCommand . toLowerCase ( ) . includes ( "webpack" ) ;
348+
349+ if ( isPythonCommand ) {
350+ terminalType = "backend" ;
351+ if ( ! cmdTag . cwd ) {
352+ cwd = path . join ( appPath , "backend" ) ;
353+ // Ensure backend directory exists for Python commands
354+ if ( ! fs . existsSync ( cwd ) ) {
355+ fs . mkdirSync ( cwd , { recursive : true } ) ;
356+ logger . log ( `Created backend directory: ${ cwd } for Python command execution` ) ;
357+ }
358+ }
359+ } else if ( isNodeCommand ) {
360+ terminalType = "frontend" ;
361+ if ( ! cmdTag . cwd ) {
362+ cwd = path . join ( appPath , "frontend" ) ;
363+ // Ensure frontend directory exists for Node.js commands
364+ if ( ! fs . existsSync ( cwd ) ) {
365+ fs . mkdirSync ( cwd , { recursive : true } ) ;
366+ logger . log ( `Created frontend directory: ${ cwd } for Node.js command execution` ) ;
367+ }
368+ }
369+ } else if ( chatMode === "ask" ) {
332370 // For ask mode, route to frontend terminal (most common for general commands)
333371 terminalType = "frontend" ;
334372 if ( ! cmdTag . cwd ) {
@@ -341,12 +379,8 @@ export async function processFullResponseActions(
341379 cwd = path . join ( appPath , "backend" ) ;
342380 }
343381 } else if ( chatMode === "fullstack" ) {
344- // For fullstack mode, try to determine based on command content or default to backend
345- // Commands related to frontend development go to frontend terminal
346- const frontendCommands = [ "npm" , "yarn" , "pnpm" , "vite" , "next" , "react" , "webpack" ] ;
347- const isFrontendCommand = frontendCommands . some ( cmd => cleanCommand . toLowerCase ( ) . includes ( cmd ) ) ;
348-
349- if ( isFrontendCommand ) {
382+ // For fullstack mode, check for Node.js commands first, then default to backend
383+ if ( isNodeCommand ) {
350384 terminalType = "frontend" ;
351385 if ( ! cmdTag . cwd ) {
352386 cwd = path . join ( appPath , "frontend" ) ;
0 commit comments