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.

Merge origin/main into fix/closed-session-transcript (test file: both suites kept)

enesed2d9c613498
diff --cc src/renderer/lib/closedHistory.test.ts
index ad5a39d1c,0fafa10f5..0de75dd94
--- a/src/renderer/lib/closedHistory.test.ts
+++ b/src/renderer/lib/closedHistory.test.ts
@@@ -1,9 -1,10 +1,11 @@@
import { describe, it, expect } from 'vitest'
import {
buildClosedSessionEntries,
+ closedTranscriptTarget,
- stateToReopenSnapshot,
- mergeClosedHistory
+ filterClosedProjects,
+ mergeClosedHistory,
+ recentlyClosedProjects,
+ stateToReopenSnapshot
} from './closedHistory'
import type { CanvasNode } from '@renderer/state/workspace'
import type { ClosedSessionEntry, Project } from '@shared/types'
@@@ -142,96 -143,56 +144,148 @@@ describe('mergeClosedHistory', () =>
})
})
+// Issue #531: closing a node used to destroy the ONLY pointer to its transcript (the live session
+// id, held in the transient agent-status store), so finished work could never be read back.
+describe('the closed-session transcript pointer', () => {
+ const agentNode = (over: Record<string, unknown> = {}): CanvasNode =>
+ node({
+ id: 'a1',
+ data: { title: 'reviewer', color: '#fff', group: null, cwd: '/repo', agentId: 'claude', ...over }
+ } as Partial<CanvasNode>)
+
+ it('records the LIVE session id at close', () => {
+ const entries = buildClosedSessionEntries(
+ new Set(['a1']),
+ [agentNode()],
+ 1,
+ () => 'e1',
+ (id) => (id === 'a1' ? 'live-sess' : undefined)
+ )
+ expect(entries[0].sessionId).toBe('live-sess')
+ })
+
+ it('falls back to the minted agentSessionId when no hook event ever named a live one', () => {
+ const entries = buildClosedSessionEntries(
+ new Set(['a1']),
+ [agentNode({ agentSessionId: 'minted-sess' })],
+ 1,
+ () => 'e1',
+ () => undefined
+ )
+ expect(entries[0].sessionId).toBe('minted-sess')
+ })
+
+ it('prefers the live id over the minted one — a resume replaces the session that was minted', () => {
+ const entries = buildClosedSessionEntries(
+ new Set(['a1']),
+ [agentNode({ agentSessionId: 'minted-sess' })],
+ 1,
+ () => 'e1',
+ () => 'live-sess'
+ )
+ expect(entries[0].sessionId).toBe('live-sess')
+ })
+
+ it('omits the field entirely when neither id exists, rather than writing undefined', () => {
+ const entries = buildClosedSessionEntries(new Set(['n1']), [node()], 1, () => 'e1')
+ expect('sessionId' in entries[0]).toBe(false)
+ })
+})
+
+describe('closedTranscriptTarget', () => {
+ const entry = (
+ over: Partial<ClosedSessionEntry> = {},
+ nodeOver: Record<string, unknown> = {}
+ ): ClosedSessionEntry =>
+ ({
+ id: 'e1',
+ closedAt: 1,
+ absolutePosition: { x: 0, y: 0 },
+ node: {
+ id: 'a1', kind: 'terminal', position: { x: 0, y: 0 }, title: 'reviewer', color: '#fff',
+ group: null, cwd: '/repo', agentId: 'claude', ...nodeOver
+ },
+ ...over
+ }) as ClosedSessionEntry
+
+ it('hands back exactly the arguments the Cmd+M reader takes', () => {
+ const t = closedTranscriptTarget(entry({ sessionId: 's1' }, { accountId: 'acc-2' }))
+ expect(t).toEqual({
+ ok: true, sessionId: 's1', agentId: 'claude', cwd: '/repo', accountId: 'acc-2', nodeId: 'a1'
+ })
+ })
+
+ it('refuses a node whose agent has no readable transcript, as the kind a surface may hide', () => {
+ expect(closedTranscriptTarget(entry({ sessionId: 's1' }, { agentId: undefined }))).toMatchObject({
+ ok: false, kind: 'no-agent'
+ })
+ })
+
+ it('refuses a REMOTE session by name — its transcript is on the host', () => {
+ expect(closedTranscriptTarget(entry({ sessionId: 's1' }, { sshRemoteTmux: true }))).toMatchObject({
+ ok: false, kind: 'remote'
+ })
+ expect(closedTranscriptTarget(entry({ sessionId: 's1' }, { ssh: { host: 'h', user: 'u' } }))).toMatchObject({
+ ok: false, kind: 'remote'
+ })
+ })
+
+ it('refuses an entry with no recorded id (closed by a pre-#531 build) with its own reason', () => {
+ const t = closedTranscriptTarget(entry())
+ expect(t).toMatchObject({ ok: false, kind: 'no-session-id' })
+ // Not the hideable kind: the user closed a real agent session and the record is genuinely gone.
+ expect(t.ok === false && t.kind !== 'no-agent').toBe(true)
++
+ describe('recentlyClosedProjects — the heading promises recency (issue #506)', () => {
+ type Probe = { id: string; name: string; closed?: boolean; unavailable?: boolean; closedAt?: number }
+ const p = (id: string, over: Partial<Probe> = {}): Probe => ({ id, name: id, ...over })
+
+ it('orders newest-closed first, NOT tab order', () => {
+ // Tab order here is old, new, mid — the project shut most recently must lead regardless.
+ const rows = recentlyClosedProjects([
+ p('old', { closed: true, closedAt: 10 }),
+ p('new', { closed: true, closedAt: 300 }),
+ p('mid', { closed: true, closedAt: 100 })
+ ])
+ expect(rows.map((r) => r.id)).toEqual(['new', 'mid', 'old'])
+ })
+
+ it('drops open and unavailable projects', () => {
+ const rows = recentlyClosedProjects([
+ p('open'),
+ p('gone', { closed: true, unavailable: true, closedAt: 999 }),
+ p('kept', { closed: true, closedAt: 1 })
+ ])
+ expect(rows.map((r) => r.id)).toEqual(['kept'])
+ })
+
+ it('sorts a project closed before the field existed last, never as NaN', () => {
+ const rows = recentlyClosedProjects([p('legacy', { closed: true }), p('known', { closed: true, closedAt: 5 })])
+ expect(rows.map((r) => r.id)).toEqual(['known', 'legacy'])
+ })
+ })
+
+ describe('filterClosedProjects', () => {
+ const rows = [
+ { id: 'a', name: 'Website', cwd: '/repos/site' },
+ { id: 'b', name: 'API', cwd: '/repos/api-server' }
+ ]
+
+ it('matches the project name', () => {
+ expect(filterClosedProjects(rows, 'web').map((r) => r.id)).toEqual(['a'])
+ })
+
+ it('matches the folder, which is what the row already shows as its title', () => {
+ expect(filterClosedProjects(rows, 'api-server').map((r) => r.id)).toEqual(['b'])
+ })
+
+ it('is case-insensitive and returns everything for an empty or blank query', () => {
+ expect(filterClosedProjects(rows, 'WEBSITE').map((r) => r.id)).toEqual(['a'])
+ expect(filterClosedProjects(rows, '')).toHaveLength(2)
+ expect(filterClosedProjects(rows, ' ')).toHaveLength(2)
+ })
+
+ it('returns nothing when nothing matches (the caller says so, it does not fall back)', () => {
+ expect(filterClosedProjects(rows, 'zzz')).toHaveLength(0)
})
})