File size: 21,204 Bytes
5b5da0e
 
 
 
 
fd0a8b6
8897bd5
5b5da0e
 
 
4e43f1d
 
 
 
 
 
 
 
 
5b5da0e
4e43f1d
5b5da0e
5017021
585ab8a
5b5da0e
 
 
 
 
fd0a8b6
4e43f1d
5b5da0e
 
 
4e43f1d
fd0a8b6
5b5da0e
 
 
 
 
 
91768fa
5b5da0e
 
585ab8a
 
 
 
5b5da0e
5017021
585ab8a
5017021
 
585ab8a
 
 
4e43f1d
 
5b5da0e
cae0460
088085b
5b5da0e
 
 
 
 
 
 
 
a699cda
4e43f1d
5b5da0e
91768fa
585ab8a
 
088085b
4e43f1d
585ab8a
4e43f1d
 
 
5017021
 
744d9e5
5017021
 
 
744d9e5
 
 
5017021
 
 
 
744d9e5
 
 
5017021
744d9e5
5017021
 
088085b
 
fd0a8b6
4e43f1d
088085b
5b5da0e
 
 
 
 
 
 
 
 
 
 
 
 
91768fa
5b5da0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585ab8a
5b5da0e
 
 
 
fd0a8b6
5b5da0e
 
4e43f1d
5b5da0e
 
 
 
 
 
 
 
 
 
 
4e43f1d
5b5da0e
088b27a
 
 
604c3c1
5b5da0e
 
 
 
 
 
 
 
 
 
 
4e43f1d
 
5b5da0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
088b27a
5b5da0e
a699cda
604c3c1
5b5da0e
 
 
 
744d9e5
 
5b5da0e
 
 
 
 
 
 
 
a699cda
4e43f1d
a699cda
 
5b5da0e
5017021
8897bd5
5017021
744d9e5
8897bd5
a699cda
 
5b5da0e
 
 
5017021
 
 
 
 
 
 
744d9e5
5017021
 
744d9e5
 
 
5017021
744d9e5
 
 
 
 
 
 
 
 
 
 
 
 
5017021
744d9e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5017021
 
 
 
744d9e5
4e43f1d
 
744d9e5
4e43f1d
 
744d9e5
 
 
 
 
 
 
4e43f1d
 
5b5da0e
4e43f1d
 
 
7d9aec4
 
3c13663
7d9aec4
3c13663
7d9aec4
4e43f1d
088b27a
3c13663
4e43f1d
7d9aec4
 
 
5b5da0e
 
4e43f1d
5b5da0e
585ab8a
 
 
 
 
 
 
69f4d93
 
 
 
 
 
585ab8a
 
 
 
 
5b5da0e
 
bcfec39
d5d1801
bcfec39
d5d1801
bcfec39
 
cae0460
bcfec39
 
 
 
5b5da0e
 
585ab8a
5b5da0e
585ab8a
 
 
 
 
 
 
5b5da0e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import { useMemo, useState } from 'react';
import type { Cli, MoveTarget, Group, Session, Tree } from '../types';
import { STATE_LABEL } from '../types';
import Logo from './Logo';
import NewSession from './NewSession';
import FolderPicker from './FolderPicker';
import { SlidersGlyph, SunGlyph, MoonGlyph, CloseGlyph, PencilGlyph, StopGlyph, PlayGlyph, GridGlyph, PlusGlyph, AmMark } from './icons';

type Zone = 'before' | 'after' | 'on';

const fmtAgo = (ts?: number) => {
  if (!ts) return '';
  const m = Math.round((Date.now() - ts) / 60000);
  if (m < 1) return 'now';
  if (m < 60) return `${m}m`;
  if (m < 48 * 60) return `${Math.round(m / 60)}h`;
  return `${Math.round(m / 1440)}d`;
};

export default function Sidebar({
  clis, tree, activeRef, focusedId, defaultPath, ages,
  onActivate, onOpenSession, onNewSession, onNewGroup, onRenameGroup, onRenameSession, onDeleteGroup,
  onStopSession, onDeleteSession, onMove, onDragState, onOpenSettings, theme, onToggleTheme, onQuickStart,
  archived, showArchived, onToggleArchived,
}: {
  clis: Cli[];
  tree: Tree;
  activeRef: string | null;
  focusedId: string | null;
  defaultPath: string;
  ages?: Record<string, number>; // session id -> last activity ts (ms)
  onActivate: (ref: string) => void;
  onOpenSession: (sessionId: string, groupId?: string) => void;
  onOpenSettings: () => void;
  onNewSession: (name: string, cli: string, path: string, groupId?: string) => void;
  onNewGroup: (name: string, cart?: { cli: string; count: number }[], path?: string) => void;
  onRenameGroup: (id: string, name: string) => void;
  onRenameSession: (id: string, name: string) => void;
  onDeleteGroup: (id: string) => void;
  onStopSession: (id: string) => void;
  onDeleteSession: (id: string) => void;
  onMove: (ref: string, to: MoveTarget) => void;
  onDragState?: (ref: string | null) => void; // lets the stage offer per-tile drop targets
  theme: 'light' | 'dark';
  onToggleTheme: () => void;
  onQuickStart: (cli: string, prompt: string, name?: string, path?: string) => void;
  archived: Set<string>;
  showArchived: boolean;
  onToggleArchived: () => void;
}) {
  const [panel, setPanel] = useState<'none' | 'create' | 'quick'>('none');
  const [quickMode, setQuickMode] = useState<'agent' | 'group'>('agent');
  const [quickCli, setQuickCli] = useState<string | null>(null);
  const [quickPrompt, setQuickPrompt] = useState('');
  const [quickMore, setQuickMore] = useState(false); // reveals name + folder
  const [quickName, setQuickName] = useState('');
  const [quickLoc, setQuickLoc] = useState('.');
  // When creation was launched from a group's + the new agent lands there.
  const [createTarget, setCreateTarget] = useState<string | null>(null);
  const [groupName, setGroupName] = useState('');
  const [groupLoc, setGroupLoc] = useState(defaultPath || '.');
  const [cart, setCart] = useState<Record<string, number>>({});
  const [editRef, setEditRef] = useState<string | null>(null);
  const [editName, setEditName] = useState('');
  const [collapsed, setCollapsed] = useState<Set<string>>(new Set());
  const [dragRef, setDragRef] = useState<string | null>(null);
  const [drop, setDrop] = useState<{ ref: string; zone: Zone } | null>(null);

  const sessById = useMemo(() => Object.fromEntries(tree.sessions.map((s) => [s.id, s])), [tree.sessions]);
  const groupById = useMemo(() => Object.fromEntries(tree.groups.map((g) => [g.id, g])), [tree.groups]);
  const colorOf = useMemo(() => Object.fromEntries(clis.map((c) => [c.id, c.color])), [clis]);
  const waiting = tree.sessions.filter((s) => s.state === 'waiting').length;

  const clearDrag = () => { setDragRef(null); setDrop(null); onDragState?.(null); };
  // Archived sessions vanish from the tree unless the legend checkbox is on.
  const isHidden = (id: string) => !showArchived && archived.has(id);
  const bump = (id: string, d: number) => setCart((c) => ({ ...c, [id]: Math.max(0, (c[id] || 0) + d) }));
  const closePanel = () => { setPanel('none'); setCreateTarget(null); };
  const openCreate = (target: string | null = null) => {
    setCreateTarget(target);
    setPanel('create');
  };
  // Quickstart: one harness pick + one prompt, agent launches in workspace/.
  // Every agent harness is shown; ones not installed here are greyed out.
  // "More options" adds a name + folder; the group tile flips to group creation.
  const quickable = clis.filter((c) => c.id !== 'shell' && c.id !== 'files');
  const openQuick = () => {
    setQuickCli((q) => q ?? (quickable.find((c) => c.available && c.ready)?.id || quickable.find((c) => c.available)?.id || null));
    setQuickMode('agent');
    setQuickLoc(defaultPath || '.');
    setGroupLoc(defaultPath || '.');
    setPanel('quick');
  };
  const submitQuick = () => {
    const p = quickPrompt.trim();
    if (!quickCli) return;
    if (!p && !quickMore) return; // the bare quick path needs a prompt
    onQuickStart(quickCli, p, quickMore ? quickName.trim() : '', quickMore ? quickLoc : '.');
    setQuickPrompt('');
    setQuickName('');
    closePanel();
  };
  const submitGroup = () => {
    const items = Object.entries(cart).filter(([, n]) => n > 0).map(([cli, count]) => ({ cli, count }));
    onNewGroup(groupName.trim() || 'Group', items, groupLoc);
    setGroupName(''); setCart({}); closePanel();
  };
  const startEdit = (ref: string, name: string) => { setEditRef(ref); setEditName(name); };
  const commitEdit = () => {
    if (editRef) {
      const id = editRef.slice(2);
      if (editRef.startsWith('g:')) onRenameGroup(id, editName);
      else onRenameSession(id, editName);
    }
    setEditRef(null);
  };

  // shared drag-and-drop wiring for any row
  const dndProps = (ref: string, kind: 'group' | 'session', nested: boolean) => ({
    draggable: editRef !== ref,
    onDragStart: (e: React.DragEvent) => { e.dataTransfer.setData('text/plain', ref); e.dataTransfer.effectAllowed = 'move'; setDragRef(ref); onDragState?.(ref); },
    onDragEnd: clearDrag,
    onDragOver: (e: React.DragEvent) => {
      if (!dragRef || dragRef === ref) return;
      const draggingGroup = dragRef.startsWith('g:');
      if (nested && draggingGroup) return; // can't nest a group
      e.preventDefault(); e.stopPropagation();
      const rect = e.currentTarget.getBoundingClientRect();
      const y = e.clientY - rect.top;
      let zone: Zone;
      if (draggingGroup) zone = y < rect.height / 2 ? 'before' : 'after';
      else { const th = rect.height / 3; zone = y < th ? 'before' : y > 2 * th ? 'after' : 'on'; }
      setDrop({ ref, zone });
    },
    onDrop: (e: React.DragEvent) => {
      if (!dragRef || dragRef === ref) { clearDrag(); return; }
      e.preventDefault(); e.stopPropagation();
      const zone = drop && drop.ref === ref ? drop.zone : 'after';
      const id = ref.slice(2);
      if (zone === 'on') {
        if (kind === 'group') onMove(dragRef, { kind: 'into', groupId: id });
        else onMove(dragRef, { kind: 'pair', sessionId: id });
      } else {
        onMove(dragRef, { kind: zone, ref });
      }
      clearDrag();
    },
    className: drop && drop.ref === ref ? ` drop-${drop.zone}` : '',
  });

  const SessionRow = (s: Session, groupId?: string) => {
    const ref = `s:${s.id}`;
    const nested = !!groupId;
    const dnd = dndProps(ref, 'session', nested);
    const editing = editRef === ref;
    // nested agents are highlighted as a whole group (see GroupBlock); loose ones individually
    const active = !nested && activeRef === ref;
    return (
      <div
        key={s.id}
        className={`row session${active ? ' active' : ''}${nested ? ' nested' : ''}${archived.has(s.id) ? ' archived' : ''}${dragRef === ref ? ' dragging' : ''}${dnd.className}`}
        draggable={dnd.draggable}
        onDragStart={dnd.onDragStart} onDragEnd={dnd.onDragEnd} onDragOver={dnd.onDragOver} onDrop={dnd.onDrop}
        onClick={() => onOpenSession(s.id, groupId)}
        onDoubleClick={(e) => { e.stopPropagation(); startEdit(ref, s.name); }}
        title={s.path ? `${s.name} · ${s.path}` : s.name}
      >
        <span className={`status ${s.state}`} title={STATE_LABEL[s.state]} />
        <Logo cli={s.cli} size={12} tint={colorOf[s.cli]} />
        {editing ? (
          <input
            autoFocus className="rename" value={editName}
            onClick={(e) => e.stopPropagation()}
            onChange={(e) => setEditName(e.target.value)}
            onBlur={commitEdit}
            onKeyDown={(e) => { if (e.key === 'Enter') commitEdit(); if (e.key === 'Escape') setEditRef(null); }}
          />
        ) : (
          <span className="name">{s.name}</span>
        )}
        <span className="age">{fmtAgo(ages?.[s.id])}</span>
        <span className="row-actions">
          {s.running
            ? <button className="mini-btn" title="Stop" onClick={(e) => { e.stopPropagation(); onStopSession(s.id); }}><StopGlyph /></button>
            : <button className="mini-btn" title="Start" onClick={(e) => { e.stopPropagation(); onOpenSession(s.id, groupId); }}><PlayGlyph /></button>}
          <button className="mini-btn" title="Delete" onClick={(e) => { e.stopPropagation(); onDeleteSession(s.id); }}><CloseGlyph /></button>
        </span>
      </div>
    );
  };

  const GroupBlock = (g: Group) => {
    const ref = `g:${g.id}`;
    const dnd = dndProps(ref, 'group', false);
    const open = !collapsed.has(g.id);
    const editing = editRef === ref;
    return (
      <div key={g.id} className={`group${activeRef === ref ? ' active' : ''}${!open ? ' closed' : ''}${drop && drop.ref === ref && drop.zone === 'on' ? ' drop-into' : ''}`}>
        {/* the group's name rides its frame — still the drag handle / click target */}
        <div
          className={`row group-head${dragRef === ref ? ' dragging' : ''}${dnd.className}`}
          draggable={dnd.draggable}
          onDragStart={dnd.onDragStart} onDragEnd={dnd.onDragEnd} onDragOver={dnd.onDragOver} onDrop={dnd.onDrop}
          onClick={() => onActivate(ref)}
          onDoubleClick={(e) => { e.stopPropagation(); startEdit(ref, g.name); }}
        >
          <button className="caret" onClick={(e) => { e.stopPropagation(); setCollapsed((c) => { const n = new Set(c); n.has(g.id) ? n.delete(g.id) : n.add(g.id); return n; }); }}>{open ? '▾' : '▸'}</button>
          {editing ? (
            <input
              autoFocus className="rename" value={editName}
              onClick={(e) => e.stopPropagation()}
              onChange={(e) => setEditName(e.target.value)}
              onBlur={commitEdit}
              onKeyDown={(e) => { if (e.key === 'Enter') commitEdit(); if (e.key === 'Escape') setEditRef(null); }}
            />
          ) : (
            <>
              <span className="name">{g.name}</span>
              {!open && <span className="count">{g.sessionIds.length}</span>}
              <span className="row-actions">
                <button className="mini-btn" title="Rename" onClick={(e) => { e.stopPropagation(); startEdit(ref, g.name); }}><PencilGlyph /></button>
                <button className="mini-btn" title="Delete group" onClick={(e) => { e.stopPropagation(); onDeleteGroup(g.id); }}><CloseGlyph /></button>
              </span>
            </>
          )}
        </div>
        <button className="g-add" title={`New agent in ${g.name}`} onClick={(e) => { e.stopPropagation(); openCreate(g.id); }}><PlusGlyph /></button>
        {open && g.sessionIds.map((sid) => sessById[sid]).filter(Boolean).filter((s) => !isHidden((s as Session).id)).map((s) => SessionRow(s as Session, g.id))}
        {open && g.sessionIds.length === 0 && <div className="empty-hint nested">Drag agents here</div>}
      </div>
    );
  };

  return (
    <aside className="sidebar">
      <div className="brand">
        <div className="logo">
          <AmMark className="am-mark" />
          <h1>Agent Manager</h1>
        </div>
        <div className="brand-actions">
          <button
            className={`icon-btn add-btn bolt-btn${panel === 'quick' ? ' on' : ''}`}
            onClick={() => (panel === 'quick' ? closePanel() : openQuick())}
            title="New agent or group"
          ><PlusGlyph /></button>
          <button className="icon-btn" onClick={onOpenSettings} title="Settings"><SlidersGlyph /></button>
          <button className="icon-btn" onClick={onToggleTheme} title="Toggle light / dark">{theme === 'dark' ? <MoonGlyph /> : <SunGlyph />}</button>
        </div>
      </div>

      {panel === 'quick' && (
        <div className="controls">
          <div className="widget quick">
            <div className="quick-clis">
              {quickable.map((c) => (
                <button
                  key={c.id}
                  className={`quick-cli${quickMode === 'agent' && quickCli === c.id ? ' on' : ''}${c.available ? '' : ' off'}`}
                  title={c.available ? c.label : `${c.label} (not installed)`}
                  disabled={!c.available}
                  style={quickMode === 'agent' && quickCli === c.id ? { borderColor: c.color } : undefined}
                  onClick={() => { setQuickMode('agent'); setQuickCli(c.id); }}
                ><Logo cli={c.id} size={14} /></button>
              ))}
              <span className="quick-sep" />
              <button
                className={`quick-cli quick-grp${quickMode === 'group' ? ' on' : ''}`}
                title="New group"
                onClick={() => setQuickMode('group')}
              >
                <span className="grp-mini">
                  <Logo cli="claude" size={8} />
                  <Logo cli="codex" size={8} />
                  <Logo cli="hermes" size={8} />
                  <Logo cli="openclaw" size={8} />
                </span>
              </button>
            </div>

            {quickMode === 'agent' ? (
              <>
                <textarea
                  autoFocus
                  rows={1}
                  className="quick-prompt"
                  placeholder={quickCli ? `prompt for ${clis.find((c) => c.id === quickCli)?.label ?? quickCli}…` : 'prompt…'}
                  value={quickPrompt}
                  onChange={(e) => { setQuickPrompt(e.target.value); e.currentTarget.style.height = 'auto'; e.currentTarget.style.height = `${e.currentTarget.scrollHeight}px`; }}
                  onKeyDown={(e) => {
                    if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submitQuick(); }
                    if (e.key === 'Escape') closePanel();
                  }}
                />
                {quickMore && (
                  <>
                    <input
                      placeholder="Name (optional)"
                      value={quickName}
                      onChange={(e) => setQuickName(e.target.value)}
                      onKeyDown={(e) => { if (e.key === 'Enter') submitQuick(); if (e.key === 'Escape') closePanel(); }}
                    />
                    <FolderPicker value={quickLoc} onChange={setQuickLoc} />
                    <div className="widget-actions">
                      <button className="btn-primary" onClick={submitQuick}>Create{quickPrompt.trim() ? ' & send' : ''}</button>
                      <button className="btn-ghost" onClick={closePanel}>Cancel</button>
                    </div>
                  </>
                )}
                <div className="quick-foot">
                  <button className="quick-more" onClick={() => setQuickMore((v) => !v)}>{quickMore ? '▴ less' : '▾ more options'}</button>
                  <span className="quick-hint mono">↵ launch · ⇧↵ newline</span>
                </div>
              </>
            ) : (
              <>
                <input autoFocus placeholder="Group name" value={groupName}
                  onChange={(e) => setGroupName(e.target.value)}
                  onKeyDown={(e) => { if (e.key === 'Enter') submitGroup(); if (e.key === 'Escape') closePanel(); }} />
                <FolderPicker value={groupLoc} onChange={setGroupLoc} />
                <div className="cart">
                  {/* every agent harness is offered; uninstalled ones are inert */}
                  {clis.filter((c) => c.available || (c.id !== 'shell' && c.id !== 'files')).map((c) => {
                    const n = cart[c.id] || 0;
                    return (
                      <div key={c.id} className={`cart-row${n > 0 ? ' has' : ''}${c.available ? '' : ' off'}`} title={c.available ? c.label : `${c.label} (not installed)`}>
                        <div className="stepper">
                          <button onClick={() => bump(c.id, -1)} disabled={n === 0} aria-label="Fewer">−</button>
                          <span className="stepper-n">{n}</span>
                          <button onClick={() => bump(c.id, 1)} disabled={!c.available} aria-label="More">+</button>
                        </div>
                        <Logo cli={c.id} size={13} />
                        <span className="cart-name">{c.label}</span>
                      </div>
                    );
                  })}
                </div>
                <div className="widget-actions">
                  <button className="btn-primary" onClick={submitGroup}>Create group</button>
                  <button className="btn-ghost" onClick={() => { setCart({}); closePanel(); }}>Cancel</button>
                </div>
              </>
            )}
          </div>
        </div>
      )}

      {/* contextual creation into a specific group (a group row's + button) */}
      {panel === 'create' && (
        <div className="controls">
          {createTarget && groupById[createTarget] && (
            <div className="create-hint mono">into {groupById[createTarget].name}</div>
          )}
          <NewSession
            clis={clis}
            sessions={tree.sessions}
            defaultPath={defaultPath}
            onCreate={(n, c, p) => { onNewSession(n, c, p, createTarget ?? undefined); closePanel(); }}
            onCancel={closePanel}
          />
        </div>
      )}

      {/* Overview: pinned above the tree with the row anatomy (tile · name ·
          right slot) so it reads as clickable; the right slot counts agents
          waiting on you. */}
      <div className="ov-fixed">
        <div
          className={`row session ov-row${activeRef === 'overview' ? ' active' : ''}`}
          onClick={() => onActivate('overview')}
          title="All agents: digests, states, replies"
        >
          <span className="status ov-spacer" />
          <span className="ov-tile"><GridGlyph /></span>
          <span className="name">overview</span>
          {waiting > 0 && <span className="ov-wait">{waiting} waiting</span>}
        </div>
      </div>

      <div className="tree" onDragEnd={clearDrag}>
        {tree.order.length === 0 && (
          <div className="empty-hint">Nothing yet. Add an agent with the + above.<br />Drag an agent onto another to group them.</div>
        )}
        {tree.order.map((ref) => {
          if (ref.startsWith('s:')) {
            const s = sessById[ref.slice(2)];
            return s && !isHidden(s.id) ? SessionRow(s) : null;
          }
          const g = groupById[ref.slice(2)];
          if (!g) return null;
          // A group whose AGENTS are all archived disappears with them — a
          // leftover shell/file viewer alone doesn't keep it on screen.
          // Groups with no agent members at all (pure utility) stay.
          const members = g.sessionIds.map((sid) => sessById[sid]).filter(Boolean) as Session[];
          const agents = members.filter((s) => s.cli !== 'shell' && s.cli !== 'files');
          const anyVisible = agents.length === 0 || agents.some((s) => !isHidden(s.id));
          return anyVisible ? GroupBlock(g) : null;
        })}
        {!showArchived && archived.size > 0 && (
          <div className="arch-note">not showing {archived.size} archived session{archived.size === 1 ? '' : 's'}</div>
        )}
      </div>

      {/* Quick-add utilities: created instantly with a default name (double-
          click to rename afterwards). Both open at the workspaces root. */}
      <div className="quick-add">
        <button className="btn-ghost" title="New shell at the workspaces root" onClick={() => onNewSession('', 'shell', '.')}>
          <Logo cli="shell" size={14} /> Shell
        </button>
        <button className="btn-ghost" title="New file browser (whole workspace)" onClick={() => onNewSession('', 'files', '.')}>
          <Logo cli="files" size={14} /> Files
        </button>
      </div>

      <div className="legend">
        <span><span className="status working" /> working</span>
        <span><span className="status waiting" /> idle</span>
        <span><span className="status stopped" /> stopped</span>
        {archived.size > 0 && (
          <label className="legend-arch" title="Sessions with no activity beyond the archive window (Settings)">
            <input type="checkbox" checked={showArchived} onChange={onToggleArchived} />
            <span className="lbox" />
            archived
          </label>
        )}
      </div>
    </aside>
  );
}