Skip to content

Commit 92cdc1e

Browse files
committed
Route bash commands to system terminal and combine backend with system
- Modified command routing to send basic bash commands (ls, cd, etc.) to main system terminal - Combined backend terminal output with system terminal using [BACKEND] prefix - Updated terminal output handlers to support the new routing - Maintained separate backend terminal view for detailed backend logs - Updated Console component to handle combined backend/system terminal display
1 parent 04f9e7e commit 92cdc1e

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

src/components/preview_panel/Console.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,18 @@ export const Console = () => {
100100

101101
// Terminals are visible if they have content OR if the app has the corresponding folder
102102
const hasFrontend = hasFrontendOutput || hasFrontendFolder;
103-
const hasBackend = hasBackendOutput || hasBackendFolder;
103+
// Backend terminal shows if it has output OR if there's backend folder AND main terminal has backend-prefixed content
104+
const hasBackend = hasBackendOutput || (hasBackendFolder && appOutput.some(output => output.message.includes('[BACKEND]')));
105+
// Main (System) terminal shows if it has any content (including combined backend output)
106+
const hasSystem = hasMain;
104107

105108
// Show all terminals if any terminal has content (to ensure Frontend is visible when Backend/System have content)
106-
const totalTerminals = (hasFrontend ? 1 : 0) + (hasBackend ? 1 : 0) + (hasMain ? 1 : 0);
109+
const totalTerminals = (hasFrontend ? 1 : 0) + (hasBackend ? 1 : 0) + (hasSystem ? 1 : 0);
107110
const showAllTerminals = totalTerminals > 0;
108111

109112
// Count active terminals
110113
const activeTerminals = [
111-
(hasMain || showAllTerminals) && "main",
114+
(hasSystem || showAllTerminals) && "main",
112115
(hasFrontend || showAllTerminals) && "frontend",
113116
(hasBackend || showAllTerminals) && "backend"
114117
].filter(Boolean);
@@ -160,6 +163,9 @@ export const Console = () => {
160163
if (hasBackend) {
161164
return <TerminalPanel title="Backend" outputs={backendTerminalOutput} color="orange" />;
162165
}
166+
if (hasSystem) {
167+
return <TerminalPanel title="System" outputs={appOutput} color="blue" />;
168+
}
163169
return <TerminalPanel title="System" outputs={appOutput} color="blue" />;
164170
}
165171

@@ -179,7 +185,7 @@ export const Console = () => {
179185
</ResizableContainer>
180186
);
181187
}
182-
if (hasMain && hasFrontend) {
188+
if (hasSystem && hasFrontend) {
183189
// System and Frontend side by side
184190
return (
185191
<ResizableContainer>
@@ -193,7 +199,7 @@ export const Console = () => {
193199
</ResizableContainer>
194200
);
195201
}
196-
if (hasMain && hasBackend) {
202+
if (hasSystem && hasBackend) {
197203
// System and Backend side by side
198204
return (
199205
<ResizableContainer>

src/ipc/handlers/terminal_handlers.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { safeSend } from "../utils/safe_sender";
2-
import { frontendTerminalOutputAtom, backendTerminalOutputAtom, activeTerminalAtom } from "../../atoms/appAtoms";
2+
import { frontendTerminalOutputAtom, backendTerminalOutputAtom, activeTerminalAtom, appOutputAtom } from "../../atoms/appAtoms";
33
import { getDefaultStore } from "jotai";
44
import log from "electron-log";
55

@@ -10,7 +10,7 @@ export function registerTerminalHandlers() {
1010
}
1111

1212
// Function to add output to a specific terminal
13-
export function addTerminalOutput(appId: number, terminal: "frontend" | "backend", message: string, type: "command" | "output" | "success" | "error" = "output") {
13+
export function addTerminalOutput(appId: number, terminal: "main" | "frontend" | "backend", message: string, type: "command" | "output" | "success" | "error" = "output") {
1414
const store = getDefaultStore();
1515

1616
// Format message with timestamp and type indicator
@@ -47,7 +47,16 @@ export function addTerminalOutput(appId: number, terminal: "frontend" | "backend
4747
appId
4848
};
4949

50-
if (terminal === "frontend") {
50+
if (terminal === "main") {
51+
// Main (system) terminal - add to the general app output
52+
const currentOutput = store.get(appOutputAtom);
53+
store.set(appOutputAtom, [...currentOutput, outputItem]);
54+
55+
// Auto-switch to main terminal if it's empty
56+
if (currentOutput.length === 0) {
57+
store.set(activeTerminalAtom, "main");
58+
}
59+
} else if (terminal === "frontend") {
5160
const currentOutput = store.get(frontendTerminalOutputAtom);
5261
store.set(frontendTerminalOutputAtom, [...currentOutput, outputItem]);
5362

@@ -56,12 +65,22 @@ export function addTerminalOutput(appId: number, terminal: "frontend" | "backend
5665
store.set(activeTerminalAtom, "frontend");
5766
}
5867
} else if (terminal === "backend") {
59-
const currentOutput = store.get(backendTerminalOutputAtom);
60-
store.set(backendTerminalOutputAtom, [...currentOutput, outputItem]);
68+
// Backend terminal - combine with main (system) terminal
69+
const currentOutput = store.get(appOutputAtom);
70+
const backendMessage = `[BACKEND] ${formattedMessage}`; // Prefix backend messages
71+
const backendOutputItem = {
72+
...outputItem,
73+
message: backendMessage
74+
};
75+
store.set(appOutputAtom, [...currentOutput, backendOutputItem]);
76+
77+
// Also keep in separate backend atom for backward compatibility if needed
78+
const backendCurrent = store.get(backendTerminalOutputAtom);
79+
store.set(backendTerminalOutputAtom, [...backendCurrent, outputItem]);
6180

62-
// Auto-switch to backend terminal if it's empty
81+
// Auto-switch to main terminal (where backend output appears)
6382
if (currentOutput.length === 0) {
64-
store.set(activeTerminalAtom, "backend");
83+
store.set(activeTerminalAtom, "main");
6584
}
6685
}
6786

src/ipc/processors/response_processor.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export async function processFullResponseActions(
356356

357357
try {
358358
// Determine which terminal to route to based on command content and chat mode
359-
let terminalType: "frontend" | "backend" = "frontend"; // default to frontend for simple commands
359+
let terminalType: "main" | "frontend" | "backend" = "main"; // default to main (system) for simple bash commands
360360
let cwd = cmdTag.cwd ? path.join(appPath, cmdTag.cwd) : appPath;
361361

362362
// Enhanced command detection with better patterns
@@ -383,7 +383,7 @@ export async function processFullResponseActions(
383383

384384
// Priority-based routing: explicit tech detection first, then general command patterns
385385
if (isPythonCommand || isGoCommand || isRustCommand) {
386-
terminalType = "backend";
386+
terminalType = "backend"; // Backend commands go to backend terminal (which will be combined with main)
387387
if (!cmdTag.cwd) {
388388
cwd = path.join(appPath, "backend");
389389
if (!fs.existsSync(cwd)) {
@@ -403,7 +403,7 @@ export async function processFullResponseActions(
403403
}
404404
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to FRONTEND terminal (Node.js command)`);
405405
} else if (isBackendCommand && !isFrontendCommand) {
406-
terminalType = "backend";
406+
terminalType = "backend"; // Backend commands go to backend terminal (combined with main)
407407
if (!cmdTag.cwd) {
408408
cwd = path.join(appPath, "backend");
409409
}
@@ -415,29 +415,9 @@ export async function processFullResponseActions(
415415
}
416416
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to FRONTEND terminal (frontend-related command)`);
417417
} else {
418-
// Fallback based on chat mode
419-
if (chatMode === "ask") {
420-
terminalType = "frontend";
421-
if (!cmdTag.cwd) {
422-
cwd = path.join(appPath, "frontend");
423-
}
424-
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to FRONTEND terminal (ask mode default)`);
425-
} else if (chatMode === "backend") {
426-
terminalType = "backend";
427-
if (!cmdTag.cwd) {
428-
cwd = path.join(appPath, "backend");
429-
}
430-
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to BACKEND terminal (backend mode)`);
431-
} else if (chatMode === "fullstack") {
432-
// For fullstack, default to backend for unknown commands
433-
terminalType = "backend";
434-
if (!cmdTag.cwd) {
435-
cwd = path.join(appPath, "backend");
436-
}
437-
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to BACKEND terminal (fullstack default)`);
438-
} else {
439-
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to ${terminalType.toUpperCase()} terminal (fallback default)`);
440-
}
418+
// Fallback: basic bash commands (ls, cd, mkdir, etc.) go to main system terminal
419+
terminalType = "main";
420+
logger.info(`[CHAT_COMMAND_ROUTING] Chat ${chatId} - Routing to MAIN/SYSTEM terminal (basic bash command)`);
441421
}
442422

443423
logger.log(`Executing general terminal command: ${cleanCommand} in ${cwd} (routing to ${terminalType} terminal) - isPython: ${isPythonCommand}, isNode: ${isNodeCommand}`);

0 commit comments

Comments
 (0)