Skip to content

The agent that grows with you

feat(desktop): expose openSessionInTerminal over the capability bridge

Brooklyn Nicholson867eb1a38120
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index a4593d9336e..ed8ae0188f3 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -96,6 +96,13 @@ import {
import { describeDevCdpDecision, resolveDevCdpPort } from './dev-cdp'
import { installEmbedReferer } from './embed-referer'
import { createEventDeduper } from './event-dedupe'
+import {
+ buildTerminalScript,
+ resolveTerminalLaunch,
+ terminalScriptEnv,
+ terminalScriptExtension,
+ tuiResumeArgs
+} from './external-terminal'
import { findGitBash as _findGitBash } from './find-git-bash'
import { installFoundInPageForwarder, performFind, stopFind } from './find-in-page'
import { createFirstRunSetupGate } from './first-run-setup-gate'
@@ -10102,6 +10109,70 @@ ipcMain.handle('hermes:window:openInstance', async () => {
return { ok: true }
})
+
+// Hand a session to the user's OWN terminal emulator, running the TUI against
+// it (`hermes --tui --resume <id>`). Not the in-app terminal pane: the point is
+// to continue the chat in the terminal they already live in.
+//
+// The desktop's runtime is usually a venv Python invoked as
+// `python -m hermes_cli.main`, so we resolve the SAME backend the app itself
+// launches and carry its argv + PYTHONPATH into a launcher script rather than
+// hoping a `hermes` exists on the user's interactive PATH. Resolution only —
+// never ensureRuntime(), which would kick off a first-run install from a menu
+// click; an unresolved runtime is reported instead.
+ipcMain.handle('hermes:window:openInTerminal', async (_event, sessionId, opts) => {
+ if (typeof sessionId !== 'string' || !sessionId.trim()) {
+ return { ok: false, error: 'invalid-session-id' }
+ }
+
+ try {
+ const profile = typeof opts?.profile === 'string' ? opts.profile.trim() : ''
+ const backend = resolveHermesBackend(tuiResumeArgs(sessionId.trim(), profile || undefined))
+
+ if (!backend.command) {
+ return { ok: false, error: 'Hermes is not installed yet' }
+ }
+
+ const { cwd } = sanitizeWorkspaceCwd(opts?.cwd)
+ const scriptDir = path.join(app.getPath('userData'), 'open-in-terminal')
+ fs.mkdirSync(scriptDir, { recursive: true })
+
+ const scriptPath = path.join(
+ scriptDir,
+ `hermes-${crypto.randomBytes(6).toString('hex')}${terminalScriptExtension()}`
+ )
+
+ fs.writeFileSync(
+ scriptPath,
+ buildTerminalScript({
+ args: backend.args,
+ command: backend.command,
+ cwd,
+ env: terminalScriptEnv(backend.env, HERMES_HOME)
+ }),
+ { mode: 0o700 }
+ )
+
+ const launch = resolveTerminalLaunch({ findOnPath, scriptPath })
+
+ if (!launch) {
+ return { ok: false, error: 'No terminal emulator found' }
+ }
+
+ rememberLog(`[terminal] opening session ${sessionId} via ${launch.command}`)
+
+ // Detached + unref'd: the terminal window outlives the desktop app, and
+ // never inherits our stdio (a closed pipe would kill the TUI).
+ const child = spawn(launch.command, launch.args, { detached: true, stdio: 'ignore' })
+ child.unref()
+
+ return { ok: true }
+ } catch (error) {
+ rememberLog(`[terminal] open in terminal failed: ${error.message}`)
+
+ return { ok: false, error: error.message }
+ }
+})
ipcMain.handle('hermes:wake-indicator:get', () => wakeIndicatorController.getState())
ipcMain.on('hermes:wake-indicator:set', (_event, state) => {
wakeIndicatorController.setState(state)
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index ffa8ffa7e00..0c0ec40c8c3 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -6,6 +6,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
touchBackend: profile => ipcRenderer.invoke('hermes:backend:touch', profile),
getGatewayWsUrl: profile => ipcRenderer.invoke('hermes:gateway:ws-url', profile),
openSessionWindow: (sessionId, opts) => ipcRenderer.invoke('hermes:window:openSession', sessionId, opts),
+ openSessionInTerminal: (sessionId, opts) => ipcRenderer.invoke('hermes:window:openInTerminal', sessionId, opts),
openWindow: () => ipcRenderer.invoke('hermes:window:openInstance'),
claimAmbientCue: key => ipcRenderer.invoke('hermes:ambient:claim', key),
wakeIndicator: {
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index fdce5560787..6d383b98ca6 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -35,6 +35,12 @@ declare global {
// a spectator window (lazy resume — no agent build) for live-streaming
// a running subagent's session.
openSessionWindow: (sessionId: string, opts?: { watch?: boolean }) => Promise<{ ok: boolean; error?: string }>
+ // Resume this session in the user's own terminal emulator (`hermes --tui
+ // --resume <id>`) — the external terminal, not the in-app pane.
+ openSessionInTerminal: (
+ sessionId: string,
+ opts?: { cwd?: string; profile?: string }
+ ) => Promise<{ ok: boolean; error?: string }>
// Open a new full-chrome app window — a peer instance of the primary that
// renders the complete app against the shared backend, so the user can run
// multiple GUI windows at once.