Skip to content

Commit 4b08f6a

Browse files
committed
feat(terminal): surface agent-created PTY sessions in Desktop UI
- Subscribe to pty.created events in TerminalContext - Add deduplication to avoid duplicate sessions - Auto-open terminal panel when agent creates a PTY session - Set agent session as active tab when created Closes Phase 2 of anomalyco#23449
1 parent d8a2087 commit 4b08f6a

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎packages/app/src/context/terminal.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ function createWorkspaceTerminalSession(sdk: ReturnType<typeof useSDK>, dir: str
185185
})
186186
onCleanup(unsub)
187187

188+
const unsubCreated = sdk.event.on("pty.created", (event: { properties: { info: LocalPTY } }) => {
189+
const { info } = event.properties
190+
if (store.all.findIndex((x) => x.id === info.id) >= 0) return
191+
const newTerminal = {
192+
id: info.id,
193+
title: info.title,
194+
titleNumber: info.titleNumber ?? numberFromTitle(info.title) ?? 0,
195+
}
196+
setStore("all", store.all.length, newTerminal)
197+
})
198+
onCleanup(unsubCreated)
199+
188200
const update = (client: ReturnType<typeof useSDK>["client"], pty: Partial<LocalPTY> & { id: string }) => {
189201
const index = store.all.findIndex((x) => x.id === pty.id)
190202
const previous = index >= 0 ? store.all[index] : undefined

‎packages/app/src/pages/session/terminal-panel.tsx‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,28 @@ export function TerminalPanel() {
6565
setStore("autoCreated", true)
6666
})
6767

68+
// Auto-open terminal panel when agent creates a new PTY session
6869
createEffect(
6970
on(
7071
() => terminal.all().length,
7172
(count, prevCount) => {
72-
if (prevCount === undefined || prevCount <= 0 || count !== 0) return
73-
if (!opened()) return
74-
close()
73+
if (prevCount === undefined || count <= prevCount) return
74+
const all = terminal.all()
75+
const last = all[all.length - 1]
76+
if (!last?.title.startsWith("Agent:")) return
77+
if (!opened()) view().terminal.open()
78+
terminal.open(last.id)
79+
},
80+
),
81+
)
82+
83+
createEffect(
84+
on(
85+
() => [opened(), terminal.active()] as const,
86+
([next, id]) => {
87+
if (!next || !id) return
88+
const stop = focus(id)
89+
onCleanup(stop)
7590
},
7691
),
7792
)

0 commit comments

Comments
 (0)