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.

fix(context): keep node's persisted sessionId across project switch (meter no longer vanishes)

enes4cccdfdb6de5
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index f191abdd6..918f4ef8e 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -841,8 +841,12 @@ export function Canvas() {
(ids: string[]) => {
const set = new Set(ids)
nodesRef.current.forEach((n) => {
+ if (!set.has(n.id)) return
// Remote terminals have no local persistent session — only destroy local ones.
- if (set.has(n.id) && n.type === 'terminal' && !n.data.remote) transport.destroy(n.id)
+ if (n.type === 'terminal' && !n.data.remote) transport.destroy(n.id)
+ // Permanent deletion → drop the node's persisted agent status (sessionId/session/
+ // unread). Node unmount no longer does this, so deletion must.
+ useAgentStatus.getState().remove(n.id)
})
// Tear down relay connections owned solely by the deleted remote node(s). The model is
// N:1 (one connection per remote node), but dedupe defensively: only disconnect a
@@ -1573,9 +1577,11 @@ export function Canvas() {
(id: string) => {
const store = useProjects.getState()
if (id === store.activeProjectId) commitActiveToStore()
- // End the tmux sessions of every terminal in the deleted project.
+ // End the tmux sessions of every terminal in the deleted project, and drop their
+ // persisted agent status (node unmount no longer removes it).
store.getProject(id)?.nodes.forEach((n) => {
if ((n.kind ?? 'terminal') === 'terminal') transport.destroy(n.id)
+ useAgentStatus.getState().remove(n.id)
})
store.deleteProject(id)
void writeDisk()
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 73f33bf4a..e632f605a 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -279,7 +279,12 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
if (dwellRef.current) clearTimeout(dwellRef.current)
cleanups.forEach((fn) => fn())
useAgentStatus.getState().setActive(id, false)
- useAgentStatus.getState().remove(id)
+ // Unmount happens on a project switch (a detach — the tmux session keeps running) as
+ // well as on real deletion, and we can't tell them apart here. Don't wipe the node's
+ // persisted status (that would drop the sessionId the context meter looks up on remount,
+ // making the meter vanish when you switch projects); only clear the live state. Real
+ // deletion drops the entry in Canvas.deleteNodes.
+ useAgentStatus.getState().setState(id, undefined)
useAgentNodes.getState().clearForParent(id)
if (sessionId) transport.kill(sessionId)
term.dispose()