Skip to content

The agent that grows with you

feat(desktop): add 'Open in terminal' to the session menu

Brooklyn Nicholson3d34b1916dac
diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
index b43a860f2a9..82faefb85bf 100644
--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
@@ -65,6 +65,7 @@ vi.mock('@/store/projects', () => ({
}))
vi.mock('@/store/session', () => ({
$activeSessionId: atom<null | string>(null),
+ $connection: atom<null | { mode: string }>(null),
$selectedStoredSessionId: atom<null | string>(null),
$sessions: atom<unknown[]>([]),
sessionMatchesStoredId: vi.fn(() => false),
@@ -80,8 +81,10 @@ vi.mock('@/store/session-states', () => ({
openSessionTile: vi.fn()
}))
vi.mock('@/store/windows', () => ({
+ canOpenSessionInTerminal: () => false,
canOpenSessionWindow: () => false,
- openSessionInNewWindow: vi.fn()
+ openSessionInNewWindow: vi.fn(),
+ openSessionInTerminal: vi.fn()
}))
function renderMenu() {
diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
index 2787b329f47..59ba882afc7 100644
--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
@@ -33,6 +33,7 @@ import { notify, notifyError } from '@/store/notifications'
import { $projectTree, moveSessionToProject, projectIdForCwd, projectRootCwd } from '@/store/projects'
import {
$activeSessionId,
+ $connection,
$selectedStoredSessionId,
$sessions,
sessionMatchesStoredId,
@@ -41,7 +42,7 @@ import {
} from '@/store/session'
import { $sessionColorOverrides, setSessionColorOverride } from '@/store/session-color'
import { $sessionTiles } from '@/store/session-states'
-import { canOpenSessionWindow } from '@/store/windows'
+import { canOpenSessionInTerminal, canOpenSessionWindow, openSessionInTerminal } from '@/store/windows'
import type { SessionTitleResponse } from '../../types'
@@ -199,6 +200,7 @@ function useSessionActions({
const suppressCloseFocusRef = useRef(false)
const tiles = useStore($sessionTiles)
const selectedStoredSessionId = useStore($selectedStoredSessionId)
+ const isRemote = useStore($connection)?.mode === 'remote'
// Already showing as a tab somewhere (a tile, or loaded in main — main IS
// a tab): offering "Open in new tab" again is noise.
@@ -237,6 +239,26 @@ function useSessionActions({
}
})
]
+ : []),
+ // The user's OWN terminal, not the in-app pane: resumes the session in the
+ // TUI. Hidden on a remote connection — the emulator we'd open runs on this
+ // machine while the session (and its runtime) lives on the remote host.
+ ...(canOpenSessionInTerminal() && !isRemote
+ ? [
+ spec({
+ disabled: !sessionId,
+ icon: 'terminal',
+ label: r.openInTerminal,
+ onSelect: () => {
+ triggerHaptic('selection')
+ // Read the row lazily: subscribing every row's menu to $sessions
+ // would re-render the whole sidebar on each session update.
+ const cwd = $sessions.get().find(s => sessionMatchesStoredId(s, sessionId))?.cwd?.trim() || undefined
+
+ void openSessionInTerminal(sessionId, { cwd, profile })
+ }
+ })
+ ]
: [])
]
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 6650b683f45..1c9db271937 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -1647,6 +1647,7 @@ export const ar = defineLocale({
rename: 'إعادة تسمية',
archive: 'أرشفة',
newWindow: 'فتح في نافذة جديدة',
+ openInTerminal: 'فتح في الطرفية',
copyIdFailed: 'فشل نسخ المعرف',
sessionActions: 'إجراءات الجلسة',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 10599349352..b38cfb88dcf 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -1977,6 +1977,7 @@ export const en: Translations = {
rename: 'Rename',
archive: 'Archive',
newWindow: 'New window',
+ openInTerminal: 'Open in terminal',
hideTabBar: 'Hide tab bar',
openInNewTab: 'Open in new tab',
openInSplit: 'Open in split',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 1d3eb000a94..a59bed41c2f 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -1794,6 +1794,7 @@ export const ja = defineLocale({
rename: '名前を変更',
archive: 'アーカイブ',
newWindow: '新しいウィンドウ',
+ openInTerminal: 'ターミナルで開く',
copyIdFailed: 'セッション ID をコピーできませんでした',
sessionActions: 'セッションアクション',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 72a1b4e4fc6..c314d85a9a0 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -1664,6 +1664,7 @@ export interface Translations {
rename: string
archive: string
newWindow: string
+ openInTerminal: string
hideTabBar: string
openInNewTab: string
openInSplit: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 1ffcf912760..8efe69eba86 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -1736,6 +1736,7 @@ export const zhHant = defineLocale({
rename: '重新命名',
archive: '封存',
newWindow: '新視窗',
+ openInTerminal: '在終端機中開啟',
copyIdFailed: '無法複製工作階段 ID',
sessionActions: '工作階段動作',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index b3e4ae92b25..f5931a06adc 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -2166,6 +2166,7 @@ export const zh: Translations = {
rename: '重命名',
archive: '归档',
newWindow: '新窗口',
+ openInTerminal: '在终端中打开',
hideTabBar: '隐藏标签栏',
openInNewTab: '在新标签页中打开',
openInSplit: '在分屏中打开',
diff --git a/apps/desktop/src/store/windows.ts b/apps/desktop/src/store/windows.ts
index 7f23c1cdea7..3549ce4186d 100644
--- a/apps/desktop/src/store/windows.ts
+++ b/apps/desktop/src/store/windows.ts
@@ -110,6 +110,13 @@ export function canOpenNewWindow(): boolean {
return typeof window !== 'undefined' && typeof window.hermesDesktop?.openWindow === 'function'
}
+// True when the shell can hand a session to the user's own terminal emulator.
+// Desktop-only, and a REMOTE connection is excluded by the caller: the terminal
+// we'd open is on this machine, but the session lives on the remote host.
+export function canOpenSessionInTerminal(): boolean {
+ return typeof window !== 'undefined' && typeof window.hermesDesktop?.openSessionInTerminal === 'function'
+}
+
type WindowOpenResult = { ok: boolean; error?: string } | undefined
// Run a window-open bridge call, surfacing any failure as a toast. Shared by the
@@ -149,3 +156,20 @@ export async function openNewWindow(): Promise<void> {
await runWindowOpen(() => window.hermesDesktop.openWindow(), 'Could not open a new window')
}
+
+// Resume a session in the user's own terminal emulator, running the TUI there.
+// `cwd` starts the shell in the session's workspace; `profile` pins the runtime
+// to the profile that owns the session. No-ops gracefully outside Electron.
+export async function openSessionInTerminal(
+ sessionId: string,
+ opts?: { cwd?: string; profile?: string }
+): Promise<void> {
+ if (!sessionId || !canOpenSessionInTerminal()) {
+ return
+ }
+
+ await runWindowOpen(
+ () => window.hermesDesktop.openSessionInTerminal(sessionId, opts),
+ 'Could not open chat in a terminal'
+ )
+}