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 ClosedHistorySection component for the sessions sidebar
Mina Samehc50e124d04a3
diff --git a/src/renderer/components/ClosedHistorySection.test.tsx b/src/renderer/components/ClosedHistorySection.test.tsxnew file mode 100644index 000000000..06a04265f--- /dev/null+++ b/src/renderer/components/ClosedHistorySection.test.tsx@@ -0,0 +1,97 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot, type Root } from 'react-dom/client'+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'+import { ClosedHistorySection } from './ClosedHistorySection'+import type { Project } from '@shared/types'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++const projects: Project[] = [+ {+ id: 'p1', name: 'closed-proj', color: '#fff', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [],+ closed: true, closedAt: 100+ },+ {+ id: 'p2', name: 'open-proj', color: '#fff', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [],+ closedSessions: [{+ id: 'e1', closedAt: 200,+ node: { id: 'n1', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 1, height: 1 }, title: 'my shell', color: '#fff', group: null, cwd: '/tmp/x' },+ absolutePosition: { x: 0, y: 0 }+ }]+ }+]++const noop = () => {}+const baseProps = {+ nowMs: 1000, collapsed: false, onToggleCollapse: noop,+ onReopenProject: noop, onDeleteProject: noop, onReopenSession: noop, onDiscardSession: noop+}++describe('ClosedHistorySection', () => {+ let root: Root+ let host: HTMLElement++ beforeEach(() => {+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+ })+ afterEach(() => {+ act(() => root.unmount())+ host.remove()+ })+ const render = async (el: React.ReactElement): Promise<void> => {+ await act(async () => root.render(el))+ }++ it('renders nothing when there is no history', async () => {+ await render(+ <ClosedHistorySection+ {...baseProps}+ projects={[{ id: 'p3', name: 'x', color: '#fff', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [] }]}+ />+ )+ expect(host.innerHTML).toBe('')+ })++ it('renders closed projects and closed sessions, one reopenable row each', async () => {+ await render(<ClosedHistorySection {...baseProps} projects={projects} />)+ const rows = host.querySelectorAll('.sessions-sidebar__history-item')+ expect(rows).toHaveLength(2)+ expect(host.textContent).toContain('my shell')+ expect(host.textContent).toContain('closed-proj')+ })++ it('calls onReopenSession with projectId+entryId on click', async () => {+ const onReopenSession = vi.fn()+ await render(<ClosedHistorySection {...baseProps} projects={projects} onReopenSession={onReopenSession} />)+ const sessionRow = Array.from(host.querySelectorAll('.sessions-sidebar__history-item'))+ .find((el) => el.textContent?.includes('my shell'))+ expect(sessionRow).toBeDefined()+ await act(async () => sessionRow!.dispatchEvent(new MouseEvent('click', { bubbles: true })))+ expect(onReopenSession).toHaveBeenCalledWith('p2', 'e1')+ })++ it('calls onDiscardSession from its × without also triggering reopen', async () => {+ const onReopenSession = vi.fn()+ const onDiscardSession = vi.fn()+ await render(+ <ClosedHistorySection+ {...baseProps} projects={projects}+ onReopenSession={onReopenSession} onDiscardSession={onDiscardSession}+ />+ )+ const del = host.querySelector('.sessions-sidebar__history-del[aria-label="Discard"]') as HTMLElement+ expect(del).toBeTruthy()+ await act(async () => del.dispatchEvent(new MouseEvent('click', { bubbles: true })))+ expect(onDiscardSession).toHaveBeenCalledWith('p2', 'e1')+ expect(onReopenSession).not.toHaveBeenCalled()+ })++ it('collapsed hides the row list but keeps the header', async () => {+ await render(<ClosedHistorySection {...baseProps} projects={projects} collapsed={true} />)+ expect(host.textContent).toContain('Recently closed')+ expect(host.textContent).not.toContain('my shell')+ })+})diff --git a/src/renderer/components/ClosedHistorySection.tsx b/src/renderer/components/ClosedHistorySection.tsxnew file mode 100644index 000000000..3e37a9940--- /dev/null+++ b/src/renderer/components/ClosedHistorySection.tsx@@ -0,0 +1,115 @@+import type { Project } from '@shared/types'+import { mergeClosedHistory } from '../lib/closedHistory'+import { sessionStateAgeLabel } from '../lib/sessionList'+import { ProjectGlyph } from './ProjectGlyph'++export interface ClosedHistorySectionProps {+ projects: readonly Project[]+ nowMs: number+ collapsed: boolean+ onToggleCollapse(): void+ onReopenProject(id: string): void+ onDeleteProject(id: string): void+ onReopenSession(projectId: string, entryId: string): void+ onDiscardSession(projectId: string, entryId: string): void+}++/** Sidebar section listing recently closed projects (tabs) and recently closed sessions+ * (terminal/agent/… nodes deleted from a still-open project), merged by recency. Renders+ * nothing when there's no history at all — an empty "Recently closed" header would be dead+ * chrome on every fresh install. */+export function ClosedHistorySection(props: ClosedHistorySectionProps): JSX.Element | null {+ const rows = mergeClosedHistory(props.projects)+ if (!rows.length) return null++ return (+ <div className="sessions-sidebar__history">+ <div+ className="sessions-sidebar__history-head"+ role="button"+ tabIndex={0}+ onClick={props.onToggleCollapse}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') props.onToggleCollapse()+ }}+ >+ <span className="sessions-sidebar__chevron" aria-hidden="true">+ {props.collapsed ? '▶' : '▼'}+ </span>+ <span className="sessions-sidebar__history-title">Recently closed</span>+ <span className="sessions-sidebar__count">{rows.length}</span>+ </div>+ {!props.collapsed && (+ <div className="sessions-sidebar__history-list">+ {rows.map((row) =>+ row.kind === 'project' ? (+ <div+ key={`project:${row.projectId}`}+ className="sessions-sidebar__history-item"+ role="button"+ tabIndex={0}+ title={row.project.cwd || row.project.name}+ onClick={() => props.onReopenProject(row.projectId)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') props.onReopenProject(row.projectId)+ }}+ >+ <ProjectGlyph+ icon={row.project.icon}+ color={row.project.color}+ name={row.project.name}+ variant="monogram"+ size={15}+ />+ <span className="sessions-sidebar__history-name">{row.project.name}</span>+ <span className="sessions-sidebar__history-age">+ {sessionStateAgeLabel(row.closedAt >= 0 ? row.closedAt : undefined, props.nowMs)}+ </span>+ <button+ className="sessions-sidebar__history-del"+ aria-label="Discard"+ title="Delete permanently (ends its sessions)"+ onClick={(e) => {+ e.stopPropagation()+ props.onDeleteProject(row.projectId)+ }}+ >+ ×+ </button>+ </div>+ ) : (+ <div+ key={`session:${row.entry.id}`}+ className="sessions-sidebar__history-item"+ role="button"+ tabIndex={0}+ title={row.entry.node.cwd || row.entry.node.title}+ onClick={() => props.onReopenSession(row.projectId, row.entry.id)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') props.onReopenSession(row.projectId, row.entry.id)+ }}+ >+ <span className="sessions-sidebar__history-name">+ {row.entry.node.title || row.entry.node.kind}+ </span>+ <span className="sessions-sidebar__history-age">+ {sessionStateAgeLabel(row.closedAt, props.nowMs)}+ </span>+ <button+ className="sessions-sidebar__history-del"+ aria-label="Discard"+ onClick={(e) => {+ e.stopPropagation()+ props.onDiscardSession(row.projectId, row.entry.id)+ }}+ >+ ×+ </button>+ </div>+ )+ )}+ </div>+ )}+ </div>+ )+}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 7859f558e..ca7c4bd98 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -7109,6 +7109,53 @@ button.group-node__setup:disabled {.sessions-sidebar__body { overflow-y: auto; padding: 4px 6px 8px; }.sessions-sidebar__empty { padding: 18px 12px; text-align: center; font-size: 12px; color: var(--muted); }+/* "Recently closed" — merged closed-projects/closed-sessions history at the bottom of the+ sidebar. Same head layout as .sessions-sidebar__head, just smaller/muted (it is a secondary+ section, not the panel's own header). */+.sessions-sidebar__history { border-top: 1px solid var(--border); }+.sessions-sidebar__history-head {+ display: flex;+ align-items: center;+ gap: 6px;+ padding: 8px 10px;+ cursor: pointer;+ border-radius: 6px;+}+.sessions-sidebar__history-head:hover { background: var(--panel-header); }+.sessions-sidebar__history-title { font-size: 11px; font-weight: 600; color: var(--muted); }+.sessions-sidebar__history-list { display: flex; flex-direction: column; padding: 0 6px 6px; }+.sessions-sidebar__history-item {+ display: flex;+ align-items: center;+ gap: 8px;+ padding: 5px 6px;+ border-radius: 6px;+ color: var(--text);+ cursor: pointer;+}+.sessions-sidebar__history-item:hover { background: var(--panel-header); }+.sessions-sidebar__history-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }+.sessions-sidebar__history-age { margin-left: auto; flex: none; font-size: 10.5px; color: var(--muted); }+.sessions-sidebar__history-del {+ flex: none;+ width: 18px;+ height: 18px;+ display: flex;+ align-items: center;+ justify-content: center;+ background: transparent;+ border: none;+ border-radius: 5px;+ color: var(--muted);+ font-size: 14px;+ line-height: 1;+ cursor: pointer;+ opacity: 0;+ transition: opacity 0.12s, background 0.12s, color 0.12s;+}+.sessions-sidebar__history-item:hover .sessions-sidebar__history-del { opacity: 1; }+.sessions-sidebar__history-del:hover { background: rgba(255, 69, 58, 0.15); color: var(--danger); }+.ss-group__head { display: flex; align-items: center; gap: 6px; padding: 6px 6px; cursor: pointer; border-radius: 6px; border: 1px solid transparent; }.ss-group__head:hover { background: var(--panel-header); }/* Project sections read as bands: monogram + heavier head + breathing room between projects. */