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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat: add in-memory reopen-history stack
Mina Sameh6d99487db80e
diff --git a/src/renderer/lib/reopenNode.ts b/src/renderer/lib/reopenNode.tsnew file mode 100644index 000000000..5a82b87f6--- /dev/null+++ b/src/renderer/lib/reopenNode.ts@@ -0,0 +1,6 @@+export interface ReopenNodeSnapshot {+ type: string+ position: { x: number; y: number }+ absolutePosition: { x: number; y: number }+ data: Record<string, unknown>+}diff --git a/src/renderer/state/reopenHistory.test.ts b/src/renderer/state/reopenHistory.test.tsnew file mode 100644index 000000000..b4f68c938--- /dev/null+++ b/src/renderer/state/reopenHistory.test.ts@@ -0,0 +1,36 @@+import { describe, it, expect } from 'vitest'+import { pushEntry, popEntry, HISTORY_CAP, type ReopenEntry } from './reopenHistory'++const proj = (id: string, closedAt: number): ReopenEntry => ({ kind: 'project', projectId: id, closedAt })++describe('pushEntry', () => {+ it('appends to the end (most recent last)', () => {+ const out = pushEntry([proj('a', 1)], proj('b', 2), 10)+ expect(out.map((e) => (e as { projectId: string }).projectId)).toEqual(['a', 'b'])+ })++ it('caps the stack, dropping the OLDEST entries', () => {+ const stack = [proj('a', 1), proj('b', 2)]+ const out = pushEntry(stack, proj('c', 3), 2)+ expect(out.map((e) => (e as { projectId: string }).projectId)).toEqual(['b', 'c'])+ })++ it('HISTORY_CAP is 10', () => {+ expect(HISTORY_CAP).toBe(10)+ })+})++describe('popEntry', () => {+ it('removes and returns the LAST (most recent) entry', () => {+ const stack = [proj('a', 1), proj('b', 2)]+ const { entry, rest } = popEntry(stack)+ expect(entry).toEqual(proj('b', 2))+ expect(rest).toEqual([proj('a', 1)])+ })++ it('returns undefined entry and an empty rest for an empty stack', () => {+ const { entry, rest } = popEntry([])+ expect(entry).toBeUndefined()+ expect(rest).toEqual([])+ })+})diff --git a/src/renderer/state/reopenHistory.ts b/src/renderer/state/reopenHistory.tsnew file mode 100644index 000000000..367902b23--- /dev/null+++ b/src/renderer/state/reopenHistory.ts@@ -0,0 +1,41 @@+import { create } from 'zustand'+import type { ReopenNodeSnapshot } from '@renderer/lib/reopenNode'++/** A single "close" event this session recorded — a project tab close, or a batch of node+ * deletions from one Delete/×/Cmd+W action. In-memory only: unlike closed-project state+ * (`project.closed`), which persists, this history resets on app restart — the same+ * convention a browser's own "reopen closed tab" uses. */+export type ReopenEntry =+ | { kind: 'project'; projectId: string; closedAt: number }+ | { kind: 'nodes'; projectId: string; closedAt: number; nodes: ReopenNodeSnapshot[] }++export const HISTORY_CAP = 10++/** Appends `entry` (most recent last) and drops the oldest entries past `cap`. */+export function pushEntry(stack: ReopenEntry[], entry: ReopenEntry, cap: number): ReopenEntry[] {+ return [...stack, entry].slice(-cap)+}++/** Removes and returns the most recently pushed entry, or `undefined` for an empty stack. */+export function popEntry(stack: ReopenEntry[]): { entry: ReopenEntry | undefined; rest: ReopenEntry[] } {+ if (!stack.length) return { entry: undefined, rest: stack }+ return { entry: stack[stack.length - 1], rest: stack.slice(0, -1) }+}++interface ReopenHistoryState {+ stack: ReopenEntry[]+ push: (entry: ReopenEntry) => void+ /** Pops and returns the most recent entry. Callers that find it stale (project already+ * reopened another way, or permanently deleted) call this again to keep walking back. */+ popNext: () => ReopenEntry | undefined+}++export const useReopenHistory = create<ReopenHistoryState>((set, get) => ({+ stack: [],+ push: (entry) => set((s) => ({ stack: pushEntry(s.stack, entry, HISTORY_CAP) })),+ popNext: () => {+ const { entry, rest } = popEntry(get().stack)+ if (entry) set({ stack: rest })+ return entry+ }+}))