Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(claude): foundation — status store, sendText, notify/focus IPC

enesd698ad8431ee
diff --git a/src/main/index.ts b/src/main/index.ts
index dde9d7817..309022daa 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -2,7 +2,7 @@ import { join } from 'path'
import { promises as fs } from 'fs'
import { execFile } from 'child_process'
import { promisify } from 'util'
-import { app, BrowserWindow, dialog, ipcMain, shell } from 'electron'
+import { app, BrowserWindow, dialog, ipcMain, Notification, shell } from 'electron'
import { IPC } from '../shared/ipc'
import { PtyManager } from './pty-manager'
import { WorkspaceStore } from './workspace-store'
@@ -17,6 +17,10 @@ const ptyManager = new PtyManager()
const workspaceStore = new WorkspaceStore()
const gitService = new GitService()
+// The single app window — kept at module scope so IPC handlers (e.g. notifications)
+// can check focus and route clicks back to the renderer.
+let mainWin: BrowserWindow | null = null
+
function createWindow(): BrowserWindow {
const win = new BrowserWindow({
width: 1400,
@@ -89,6 +93,22 @@ app.whenReady().then(() => {
ipcMain.on(IPC.appCloseWindow, () => BrowserWindow.getFocusedWindow()?.close())
+ // Show an OS notification — but only when the window is in the background. Clicking it
+ // brings the app forward and asks the renderer to focus the originating node.
+ ipcMain.handle(IPC.appNotify, (_e, payload: { title: string; body: string; nodeId: string }) => {
+ if (!mainWin || mainWin.isFocused() || !Notification.isSupported()) return false
+ const n = new Notification({ title: payload.title, body: payload.body })
+ n.on('click', () => {
+ if (!mainWin) return
+ if (mainWin.isMinimized()) mainWin.restore()
+ mainWin.show()
+ mainWin.focus()
+ mainWin.webContents.send(IPC.appFocusNode, payload.nodeId)
+ })
+ n.show()
+ return true
+ })
+
ipcMain.handle(IPC.announcementsFetch, () => fetchAnnouncements())
ipcMain.on(IPC.shellReveal, (_e, p: string) => {
@@ -174,6 +194,7 @@ app.whenReady().then(() => {
})
const win = createWindow()
+ mainWin = win
initUpdater(win)
app.on('activate', () => {
diff --git a/src/main/pty-manager.ts b/src/main/pty-manager.ts
index 59b315da1..f0eb0240b 100644
--- a/src/main/pty-manager.ts
+++ b/src/main/pty-manager.ts
@@ -97,6 +97,9 @@ export class PtyManager {
)
ipcMain.on(IPC.ptyKill, (_event, sessionId: string) => this.kill(sessionId))
ipcMain.on(IPC.ptyDestroy, (_event, persistKey: string) => this.destroySession(persistKey))
+ ipcMain.handle(IPC.ptySendText, (_event, persistKey: string, text: string) =>
+ this.sendText(persistKey, text)
+ )
}
private create(webContentsId: number, options: PtyCreateOptions): string {
@@ -198,6 +201,27 @@ export class PtyManager {
}
}
+ /**
+ * Send literal text followed by Enter into a node's tmux session (e.g. a slash command).
+ * Works whether or not a client is attached. Returns false if tmux is unavailable or the
+ * session doesn't exist yet.
+ */
+ sendText(persistKey: string, text: string): boolean {
+ if (!this.tmuxPath) return false
+ const target = sessionName(persistKey)
+ try {
+ execFileSync(this.tmuxPath, ['-L', TMUX_SOCKET, 'send-keys', '-t', target, '-l', text], {
+ stdio: 'ignore'
+ })
+ execFileSync(this.tmuxPath, ['-L', TMUX_SOCKET, 'send-keys', '-t', target, 'Enter'], {
+ stdio: 'ignore'
+ })
+ return true
+ } catch {
+ return false
+ }
+ }
+
/** Permanently end a node's persistent tmux session (called when the user closes it). */
destroySession(persistKey: string): void {
if (!this.tmuxPath) return
diff --git a/src/preload/index.ts b/src/preload/index.ts
index a2a9d938d..b27a7fb35 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -16,6 +16,7 @@ const api: NodeTerminalApi = {
destroy: (persistKey) => ipcRenderer.send(IPC.ptyDestroy, persistKey),
generateName: (persistKey, cwd) => ipcRenderer.invoke(IPC.ptyGenerateName, persistKey, cwd),
capture: (persistKey) => ipcRenderer.invoke(IPC.ptyCapture, persistKey),
+ sendText: (persistKey, text) => ipcRenderer.invoke(IPC.ptySendText, persistKey, text),
onData: (sessionId, listener) => {
const channel = IPC.ptyData(sessionId)
const handler = (_e: unknown, data: string) => listener(data)
@@ -101,7 +102,13 @@ const api: NodeTerminalApi = {
ipcRenderer.on(IPC.appCloseNode, handler)
return () => ipcRenderer.removeListener(IPC.appCloseNode, handler)
},
- closeWindow: () => ipcRenderer.send(IPC.appCloseWindow)
+ closeWindow: () => ipcRenderer.send(IPC.appCloseWindow),
+ notify: (payload) => ipcRenderer.invoke(IPC.appNotify, payload),
+ onFocusNode: (listener) => {
+ const handler = (_e: unknown, nodeId: string) => listener(nodeId)
+ ipcRenderer.on(IPC.appFocusNode, handler)
+ return () => ipcRenderer.removeListener(IPC.appFocusNode, handler)
+ }
}
contextBridge.exposeInMainWorld('nodeTerminal', api)
diff --git a/src/renderer/state/claudeStatus.ts b/src/renderer/state/claudeStatus.ts
new file mode 100644
index 000000000..751d34926
--- /dev/null
+++ b/src/renderer/state/claudeStatus.ts
@@ -0,0 +1,73 @@
+import { create } from 'zustand'
+
+/**
+ * Transient per-node status for Claude Code terminals — busy/working, unread, and the
+ * Claude session name. Deliberately NOT persisted (kept out of workspace.json); it resets
+ * on reload / project switch, which is the desired "clean layout file" behavior.
+ */
+export interface ClaudeNodeStatus {
+ /** Claude is actively processing a turn. */
+ busy: boolean
+ /** A turn finished while the user wasn't looking; cleared on focus/select. */
+ unread: boolean
+ /** Claude's own session name/title, shown alongside the terminal title. */
+ session?: string
+ /** Timestamp of the last busy→idle transition. */
+ finishedAt?: number
+}
+
+interface ClaudeStatusState {
+ byId: Record<string, ClaudeNodeStatus>
+ setBusy(id: string, busy: boolean): void
+ setSession(id: string, session: string): void
+ markUnread(id: string): void
+ clearUnread(id: string): void
+ remove(id: string): void
+}
+
+const EMPTY: ClaudeNodeStatus = { busy: false, unread: false }
+
+export const useClaudeStatus = create<ClaudeStatusState>((set) => ({
+ byId: {},
+
+ setBusy: (id, busy) =>
+ set((s) => {
+ const prev = s.byId[id] ?? EMPTY
+ if (prev.busy === busy) return s
+ return {
+ byId: {
+ ...s.byId,
+ [id]: { ...prev, busy, finishedAt: busy ? prev.finishedAt : Date.now() }
+ }
+ }
+ }),
+
+ setSession: (id, session) =>
+ set((s) => {
+ const prev = s.byId[id] ?? EMPTY
+ if (prev.session === session) return s
+ return { byId: { ...s.byId, [id]: { ...prev, session } } }
+ }),
+
+ markUnread: (id) =>
+ set((s) => {
+ const prev = s.byId[id] ?? EMPTY
+ if (prev.unread) return s
+ return { byId: { ...s.byId, [id]: { ...prev, unread: true } } }
+ }),
+
+ clearUnread: (id) =>
+ set((s) => {
+ const prev = s.byId[id]
+ if (!prev?.unread) return s
+ return { byId: { ...s.byId, [id]: { ...prev, unread: false } } }
+ }),
+
+ remove: (id) =>
+ set((s) => {
+ if (!(id in s.byId)) return s
+ const next = { ...s.byId }
+ delete next[id]
+ return { byId: next }
+ })
+}))
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 9f27491ed..c6add9f97 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -8,9 +8,12 @@ export const IPC = {
ptyDestroy: 'pty:destroy',
ptyGenerateName: 'pty:generate-name',
ptyCapture: 'pty:capture',
+ ptySendText: 'pty:send-text',
appToggleMarkdown: 'app:toggle-markdown',
appCloseNode: 'app:close-node',
appCloseWindow: 'app:close-window',
+ appNotify: 'app:notify',
+ appFocusNode: 'app:focus-node',
appUpdateAvailable: 'app:update-available',
appUpdateDownloaded: 'app:update-downloaded',
appRestartToUpdate: 'app:restart-to-update',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 26d62c47f..371ac331e 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -98,6 +98,8 @@ export interface PtyApi {
generateName(persistKey: string, cwd: string): Promise<GitResult>
/** Capture a terminal session's recent visible output as text. */
capture(persistKey: string): Promise<string>
+ /** Send literal text + Enter into a session (e.g. a slash command). Returns false if unavailable. */
+ sendText(persistKey: string, text: string): Promise<boolean>
/** Listens for PTY output. Returns an unsubscribe function. */
onData(sessionId: string, listener: (data: string) => void): () => void
/** Fires when the PTY process exits. Returns an unsubscribe function. */
@@ -168,6 +170,10 @@ export interface Settings {
commitExtraPrompt: string
/** Whether the shortcuts overlay has been shown on first launch. */
seenShortcuts: boolean
+ /** Notify (OS notification) when a Claude Code turn finishes while the app is in the background. */
+ notifyOnClaudeDone: boolean
+ /** Whether the one-time notification consent prompt has been shown. */
+ notifyConsentAsked: boolean
}
export const DEFAULT_SETTINGS: Settings = {
@@ -185,7 +191,9 @@ export const DEFAULT_SETTINGS: Settings = {
commitAgent: 'claude',
commitAgentCommand: '',
commitExtraPrompt: '',
- seenShortcuts: false
+ seenShortcuts: false,
+ notifyOnClaudeDone: true,
+ notifyConsentAsked: false
}
export interface SettingsApi {
@@ -288,6 +296,13 @@ export interface AnnouncementsApi {
fetch(): Promise<Announcement[]>
}
+export interface NotifyPayload {
+ title: string
+ body: string
+ /** Node to focus/center when the notification is clicked. */
+ nodeId: string
+}
+
export interface NodeTerminalApi {
pty: PtyApi
workspace: WorkspaceApi
@@ -305,4 +320,8 @@ export interface NodeTerminalApi {
onCloseNode(listener: () => void): () => void
/** Close the application window (Cmd/Ctrl+W fallback when no node is selected). */
closeWindow(): void
+ /** Show an OS notification (main suppresses it if the window is focused). Returns whether shown. */
+ notify(payload: NotifyPayload): Promise<boolean>
+ /** Fires when a notification is clicked, asking the renderer to focus a node. Returns unsubscribe. */
+ onFocusNode(listener: (nodeId: string) => void): () => void
}