Skip to content

Commit 2c8b8ea

Browse files
committed
fix(remote): always show main agent terminal on mobile
Add isShell flag to PTY session metadata so buildAgentList() can filter out shell/standalone terminals from the mobile agent list. Previously, when the main agent exited while a shell sub-terminal was still running, the shell would replace the main agent.
1 parent 0858ebf commit 2c8b8ea

5 files changed

Lines changed: 14 additions & 3 deletions

File tree

electron/ipc/pty.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface PtySession {
99
channelId: string;
1010
taskId: string;
1111
agentId: string;
12+
isShell: boolean;
1213
flushTimer: ReturnType<typeof setTimeout> | null;
1314
subscribers: Set<(encoded: string) => void>;
1415
scrollback: RingBuffer;
@@ -86,6 +87,7 @@ export function spawnAgent(
8687
env: Record<string, string>;
8788
cols: number;
8889
rows: number;
90+
isShell?: boolean;
8991
onOutput: { __CHANNEL_ID__: string };
9092
},
9193
): void {
@@ -150,6 +152,7 @@ export function spawnAgent(
150152
channelId,
151153
taskId: args.taskId,
152154
agentId: args.agentId,
155+
isShell: args.isShell ?? false,
153156
flushTimer: null,
154157
subscribers: new Set(),
155158
scrollback: new RingBuffer(),
@@ -316,9 +319,11 @@ export function getActiveAgentIds(): string[] {
316319
}
317320

318321
/** Return metadata for a specific agent, or null if not found. */
319-
export function getAgentMeta(agentId: string): { taskId: string; agentId: string } | null {
322+
export function getAgentMeta(
323+
agentId: string,
324+
): { taskId: string; agentId: string; isShell: boolean } | null {
320325
const s = sessions.get(agentId);
321-
return s ? { taskId: s.taskId, agentId: s.agentId } : null;
326+
return s ? { taskId: s.taskId, agentId: s.agentId, isShell: s.isShell } : null;
322327
}
323328

324329
/** Return the current column width of an agent's PTY. */

electron/remote/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function getNetworkIps(): { wifi: string | null; tailscale: string | null } {
6060
return { wifi, tailscale };
6161
}
6262

63-
/** Build the agent list, deduplicated by taskId (keeps latest agent per task). */
63+
/** Build the agent list, deduplicated by taskId (keeps main agent per task). */
6464
function buildAgentList(
6565
getTaskName: (taskId: string) => string,
6666
getAgentStatus: (agentId: string) => {
@@ -73,6 +73,8 @@ function buildAgentList(
7373
for (const agentId of getActiveAgentIds()) {
7474
const meta = getAgentMeta(agentId);
7575
if (!meta) continue;
76+
// Skip shell/sub-terminals — mobile should only show the main agent
77+
if (meta.isShell) continue;
7678
const info = getAgentStatus(agentId);
7779
const agent: RemoteAgent = {
7880
agentId,

src/components/TaskPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ export function TaskPanel(props: TaskPanelProps) {
754754
<TerminalView
755755
taskId={props.task.id}
756756
agentId={shellId}
757+
isShell
757758
isFocused={
758759
props.isActive && store.focusedPanel[props.task.id] === `shell:${i()}`
759760
}

src/components/TerminalPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function TerminalPanel(props: TerminalPanelProps) {
142142
<TerminalView
143143
taskId={props.terminal.id}
144144
agentId={props.terminal.agentId}
145+
isShell
145146
isFocused={props.isActive && store.focusedPanel[props.terminal.id] === 'terminal'}
146147
command=""
147148
args={['-l']}

src/components/TerminalView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface TerminalViewProps {
4444
args: string[];
4545
cwd: string;
4646
env?: Record<string, string>;
47+
isShell?: boolean;
4748
onExit?: (exitInfo: {
4849
exit_code: number | null;
4950
signal: string | null;
@@ -380,6 +381,7 @@ export function TerminalView(props: TerminalViewProps) {
380381
env: props.env ?? {},
381382
cols: term.cols,
382383
rows: term.rows,
384+
isShell: props.isShell,
383385
onOutput,
384386
// eslint-disable-next-line solid/reactivity -- promise catch handler reads current prop values intentionally
385387
}).catch((err) => {

0 commit comments

Comments
 (0)