ai-agentmanager 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.38.0 (2026-11-11)
4
+
5
+ - **The top bar fits the window.** View buttons that don't fit go, in order, into a **More ▾** menu at the end of the row (with a dot when one of them has a count); the filter gives up its room first, and below 1100px the title and connection text step aside for the logo and a coloured dot. **+ New agents** and your menu always stay in view.
6
+ - **Split screen: one session in two views.** When a session shows in more than one place (the main panel, a group, another window), the view you type in or click sets its size; the others show it at that size with the font scaled to fit, instead of wrapping oddly.
7
+ - **Split screen keys**, also from inside a terminal: **Cmd+\\** on a Mac or **Ctrl+Shift+\\** splits right (add Shift on a Mac, or Alt, to split down), **Ctrl+Shift+1…6** goes to a group, **Ctrl+Shift+X** closes the active one. They're listed under **?**.
8
+ - Fixed: plain **Ctrl+\\** in a terminal split the screen *and* reached the agent as Ctrl+\\, a quit key. It now only goes to the terminal.
9
+ - Fixed: a terminal reconnecting in the main panel took the keyboard away from the split-screen group you were working in.
10
+ - Tests now drive the page in headless Chrome (`test/browser.test.js`, skipped without Chrome): the top bar at several widths, and the split screen end to end.
11
+
3
12
  ## 1.37.0 (2026-11-10)
4
13
 
5
14
  - **Split screen, as in VS Code.** The area beside the agents list splits right or down into groups, each showing an agent's session or one of its shells, next to the usual panel with the agent's details. Split with **⊞ Split screen** in the terminal bar, **Ctrl+\\** (Ctrl+Shift+\\ splits down) or the buttons on a group; up to six groups. Load a session into a group by dragging an agent onto it (onto its right or bottom edge to split there), from the group's menu (open sessions first), or by clicking an agent in the list while that group is active. In a group you can switch to its shells or open a new one, resume a closed session, or move it to the main panel. Dividers resize; the layout and what each group shows are kept per browser. Narrow screens show the main panel only.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.37.0",
3
+ "version": "1.38.0",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
package/public/app.js CHANGED
@@ -26,7 +26,8 @@ import { initSupport } from '/support.js';
26
26
  import { initCode } from '/code.js';
27
27
  import { initMachine } from '/machine.js';
28
28
  import { initWatch } from '/watch.js';
29
- import { initGroups } from '/groups.js';
29
+ import { initGroups, followSize, scaleToFit, leadSize } from '/groups.js';
30
+ import { initTopNav } from '/topnav.js';
30
31
  import { initStandup } from '/standup.js';
31
32
  import { initIssues } from '/issues.js';
32
33
  import { initActions } from '/actions.js';
@@ -2449,10 +2450,12 @@ const term = {
2449
2450
  // answers are stale, and the program would get them as typing.
2450
2451
  if (this.replaying) return;
2451
2452
  lastTyped = Date.now();
2453
+ this.lead();
2452
2454
  this.send({ t: 'i', d });
2453
2455
  });
2454
- this.xterm.onResize(({ cols, rows }) => this.send({ t: 'r', cols, rows }));
2455
- new ResizeObserver(() => this.refit()).observe($('#terminal'));
2456
+ // Shown in a split-screen group too (or another window): the view typed in sets the size.
2457
+ this.xterm.onResize(({ cols, rows }) => !this.follow && this.send({ t: 'r', cols, rows }));
2458
+ new ResizeObserver(() => (this.follow ? scaleToFit(this, $('#terminal')) : this.refit())).observe($('#terminal'));
2456
2459
  touchScroll($('#terminal'), this.xterm);
2457
2460
  },
2458
2461
 
@@ -2460,8 +2463,13 @@ const term = {
2460
2463
  this.conn?.send(msg);
2461
2464
  },
2462
2465
 
2466
+ follow: false,
2467
+ lead() {
2468
+ leadSize(this, () => this.fit.fit(), (m) => this.send(m));
2469
+ },
2470
+
2463
2471
  refit() {
2464
- if (!this.agentId) return;
2472
+ if (!this.agentId || this.follow) return;
2465
2473
  try {
2466
2474
  this.fit.fit();
2467
2475
  } catch {}
@@ -2489,6 +2497,8 @@ const term = {
2489
2497
  this.agentId = id;
2490
2498
  this.kind = kind;
2491
2499
  this.shellExited = false;
2500
+ this.follow = false;
2501
+ this.xterm.options.fontSize = 13;
2492
2502
  this.xterm.reset();
2493
2503
  this.syncOverlay();
2494
2504
  requestAnimationFrame(() => this.refit());
@@ -2519,7 +2529,10 @@ const term = {
2519
2529
  this.xterm.reset();
2520
2530
  this.replaying = true;
2521
2531
  this.xterm.write(msg.backlog, () => (this.replaying = false));
2522
- if (!matchMedia('(pointer: coarse)').matches) this.xterm.focus();
2532
+ // Not while you work in a split-screen group: it would take the keyboard from there.
2533
+ if (!matchMedia('(pointer: coarse)').matches && !groupsUi?.activeSplit()) this.xterm.focus();
2534
+ } else if (msg.t === 'size') {
2535
+ return followSize(this, msg.cols, msg.rows, $('#terminal'));
2523
2536
  } else if (msg.t === 'error') {
2524
2537
  toast(`Terminal unavailable: ${msg.error}`, 5000);
2525
2538
  } else if (msg.t === 'o') {
@@ -4359,13 +4372,13 @@ function connectEvents() {
4359
4372
  { events: true },
4360
4373
  {
4361
4374
  onOpen: () => {
4362
- $('#conn').textContent = REMOTE ? 'connected (remote)' : 'daemon connected';
4375
+ $('#conn').textContent = $('#conn').title = REMOTE ? 'connected (remote)' : 'daemon connected';
4363
4376
  $('#conn').className = 'conn ok';
4364
4377
  reloadIfUpdated();
4365
4378
  },
4366
4379
  onMessage: handleEvent,
4367
4380
  onClose: async () => {
4368
- $('#conn').textContent = 'daemon offline, retrying…';
4381
+ $('#conn').textContent = $('#conn').title = 'daemon offline, retrying…';
4369
4382
  $('#conn').className = 'conn bad';
4370
4383
  if (REMOTE && !(await sessionOk())) return showLogin();
4371
4384
  setTimeout(connectEvents, 2000);
@@ -4975,8 +4988,11 @@ groupsUi = initGroups({
4975
4988
  if (kind !== 'claude' || agents.get(id)?.runtime.running) term.open(id, kind);
4976
4989
  },
4977
4990
  refitMain: () => term.refit(),
4991
+ mainActive: () => term.xterm && term.lead(),
4992
+ focusMain: () => (term.agentId && !$('#term-wrap').hidden ? term.xterm.focus() : $('#detail').focus?.()),
4978
4993
  });
4979
4994
  $('#group-split').onclick = () => groupsUi.split('row');
4995
+ initTopNav({ $ });
4980
4996
 
4981
4997
  boot();
4982
4998
  setInterval(renderDetail, 30_000); // keep "x ago" labels fresh
package/public/groups.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // Split screen, like editor groups in VS Code: the area beside the agents list splits right or
2
2
  // down into groups, each showing one agent's session (its Claude session or a shell). The main
3
3
  // group is the usual panel (the agent's details and terminal); the others are terminals.
4
+ // Keys: Cmd+\ or Ctrl+Shift+\ splits, Ctrl+Shift+1…6 focuses a group, Ctrl+Shift+X closes one.
4
5
  // Load a session into a group by dragging an agent onto it (onto its right or bottom edge to split
5
6
  // there), with the group's picker, or by clicking an agent in the list while that group is active.
6
7
  // The layout and what each group shows are kept per browser.
@@ -11,8 +12,42 @@ const MAX_GROUPS = 6;
11
12
  const REPLY = /^(\x1b\[[\d;?>]*[IOcRnt]|\x1b\][\d;]*[^\x07\x1b]*(\x07|\x1b\\))+$/;
12
13
  const EDGE = 0.25; // a drop this close to a group's right or bottom edge splits it
13
14
  const isShell = (k) => /^shell(:\d+)?$/.test(k ?? '');
15
+ const FONT = 13;
16
+
17
+ // One session, several views (the main panel, groups, another window): the view you type in or
18
+ // click sets the session's size; the others show it at that size, the font scaled to fit, until
19
+ // you type in or click one of them. `v` is { xterm, follow }.
20
+
21
+ /** Another view resized the session: show it at that size. */
22
+ export function followSize(v, cols, rows, box) {
23
+ if (!(cols > 0 && rows > 0) || (cols === v.xterm.cols && rows === v.xterm.rows)) return;
24
+ v.follow = true;
25
+ v.xterm.resize(cols, rows);
26
+ requestAnimationFrame(() => scaleToFit(v, box));
27
+ }
28
+
29
+ /** While following: the font that fits the session's size into the panel. */
30
+ export function scaleToFit(v, box) {
31
+ const screen = box.querySelector('.xterm-screen');
32
+ if (!v.follow || !screen?.offsetWidth || !box.clientWidth) return;
33
+ const f = v.xterm.options.fontSize;
34
+ const ratio = Math.min(box.clientWidth / screen.offsetWidth, box.clientHeight / screen.offsetHeight);
35
+ const next = Math.max(6, Math.min(FONT, Math.floor(f * ratio * 10) / 10));
36
+ if (Math.abs(next - f) > 0.05) v.xterm.options.fontSize = next;
37
+ }
38
+
39
+ /** This view sets the size again: its own font, fitted to its panel, sent to the session. */
40
+ export function leadSize(v, fit, send) {
41
+ if (!v.follow) return;
42
+ v.follow = false;
43
+ v.xterm.options.fontSize = FONT;
44
+ try {
45
+ fit();
46
+ } catch {}
47
+ send({ t: 'r', cols: v.xterm.cols, rows: v.xterm.rows });
48
+ }
14
49
 
15
- export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api, upsert, toast, statusOf, pillText, engineLabel, dragged, openInMain, refitMain }) {
50
+ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api, upsert, toast, statusOf, pillText, engineLabel, dragged, openInMain, refitMain, mainActive, focusMain }) {
16
51
  const root = $('#groups');
17
52
  const detail = $('#detail');
18
53
  // A layout is a tree: { leaf: id } or { dir: 'row' | 'col', a, b, size } (the first part's share, %).
@@ -43,9 +78,9 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
43
78
  <select class="gkind" aria-label="Session" hidden></select>
44
79
  <span class="spacer"></span>
45
80
  <select class="gpick" aria-label="Open a session in this group" title="Open a session in this group"></select>
46
- <button class="ghost small" data-g="right" title="Split right (Ctrl+\\)">◫</button>
47
- <button class="ghost small" data-g="down" title="Split down">⬓</button>
48
- <button class="ghost small" data-g="close" title="Close this group (the agent keeps running)">✕</button>
81
+ <button class="ghost small" data-g="right" title="Split right (Cmd+\\ on a Mac, or Ctrl+Shift+\\)">◫</button>
82
+ <button class="ghost small" data-g="down" title="Split down (Cmd+Shift+\\ on a Mac, or Ctrl+Alt+Shift+\\)">⬓</button>
83
+ <button class="ghost small" data-g="close" title="Close this group; the agent keeps running (Ctrl+Shift+X)">✕</button>
49
84
  </div>
50
85
  <div class="gbody">
51
86
  <div class="gterm"></div>
@@ -55,27 +90,30 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
55
90
  const xterm = new Terminal({
56
91
  cursorBlink: true,
57
92
  fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
58
- fontSize: 13,
93
+ fontSize: FONT,
59
94
  scrollback: 10000,
60
95
  theme: { background: '#0f1117' },
61
96
  allowProposedApi: true,
62
97
  });
63
98
  const fit = new FitAddon();
64
99
  xterm.loadAddon(fit);
65
- const p = { el, xterm, fit, conn: null, agentId: null, kind: 'claude', replaying: false, exited: false, opened: false };
100
+ const p = { el, xterm, fit, conn: null, agentId: null, kind: 'claude', replaying: false, exited: false, opened: false, follow: false };
66
101
  xterm.onData((d) => {
67
102
  if (p.replaying || REPLY.test(d)) return;
103
+ lead(p);
68
104
  p.conn?.send({ t: 'i', d });
69
105
  });
70
- xterm.onResize(({ cols, rows }) => p.conn?.send({ t: 'r', cols, rows }));
71
- new ResizeObserver(() => refit(p)).observe(el.querySelector('.gterm'));
106
+ xterm.onResize(({ cols, rows }) => !p.follow && p.conn?.send({ t: 'r', cols, rows }));
107
+ new ResizeObserver(() => (p.follow ? scaleToFit(p, el.querySelector('.gterm')) : refit(p))).observe(el.querySelector('.gterm'));
72
108
  panes.set(id, p);
73
109
  if (show.agentId) load(id, show.agentId, show.kind);
74
110
  return p;
75
111
  }
76
112
 
113
+ const lead = (p) => leadSize(p, () => p.fit.fit(), (m) => p.conn?.send(m));
114
+
77
115
  function refit(p) {
78
- if (!p.opened || !p.agentId || !p.el.isConnected) return;
116
+ if (!p.opened || !p.agentId || !p.el.isConnected || p.follow) return;
79
117
  try {
80
118
  p.fit.fit();
81
119
  } catch {}
@@ -104,6 +142,8 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
104
142
  p.opened = true;
105
143
  }
106
144
  p.failed = false;
145
+ p.follow = false;
146
+ p.xterm.options.fontSize = FONT;
107
147
  p.xterm.reset();
108
148
  const conn = openStream(
109
149
  { agentId: p.agentId, kind: p.kind },
@@ -119,7 +159,8 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
119
159
  p.xterm.reset();
120
160
  p.replaying = true;
121
161
  p.xterm.write(msg.backlog ?? '', () => (p.replaying = false));
122
- } else if (msg.t === 'error') toast(`Terminal unavailable: ${msg.error}`, 5000);
162
+ } else if (msg.t === 'size') followSize(p, msg.cols, msg.rows, p.el.querySelector('.gterm'));
163
+ else if (msg.t === 'error') toast(`Terminal unavailable: ${msg.error}`, 5000);
123
164
  else if (msg.t === 'exit') {
124
165
  if (isShell(p.kind)) p.exited = true;
125
166
  else p.xterm.write(`\r\n\x1b[2m[session exited with code ${msg.code}; session kept]\x1b[0m\r\n`);
@@ -322,12 +363,17 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
322
363
  p.xterm.dispose();
323
364
  p.el.remove();
324
365
  panes.delete(id);
325
- if (active === id) active = 'main';
366
+ if (active === id) {
367
+ active = 'main';
368
+ mainActive();
369
+ }
326
370
  layout();
327
371
  save();
328
372
  }
329
373
 
330
374
  function activate(id) {
375
+ if (id === 'main') mainActive();
376
+ else if (panes.get(id)) lead(panes.get(id));
331
377
  if (active === id) return;
332
378
  active = id;
333
379
  detail.classList.toggle('gactive', id === 'main' && Boolean(tree.dir) && !narrow());
@@ -448,13 +494,33 @@ export function initGroups({ $, esc, agents, Terminal, FitAddon, openStream, api
448
494
  });
449
495
  document.addEventListener('dragend', clearDrop);
450
496
 
451
- // Ctrl+\ (Cmd+\ on a Mac), as in VS Code: split the active group to the right.
497
+ // Keys, taken before a focused terminal gets them (plain Ctrl+\ stays the terminal's: it's "quit").
498
+ // Cmd+\ (Mac) or Ctrl+Shift+\: split right; with Shift (Mac) or Alt: split down.
499
+ // Ctrl+Shift+1…6: focus group 1…6 (left to right, top to bottom). Ctrl+Shift+X: close the active group.
452
500
  document.addEventListener('keydown', (e) => {
453
- if ((e.ctrlKey || e.metaKey) && !e.altKey && e.code === 'Backslash') {
454
- e.preventDefault();
455
- split(active, e.shiftKey ? 'col' : 'row');
456
- }
457
- });
501
+ const mac = e.metaKey && !e.ctrlKey;
502
+ const ctrl = e.ctrlKey && e.shiftKey && !e.metaKey;
503
+ let act = null;
504
+ if (e.code === 'Backslash' && mac && !e.altKey) act = () => split(active, e.shiftKey ? 'col' : 'row');
505
+ else if (e.code === 'Backslash' && ctrl) act = () => split(active, e.altKey ? 'col' : 'row');
506
+ else if (ctrl && !e.altKey && /^Digit[1-6]$/.test(e.code)) act = () => focusGroup(Number(e.code.slice(5)));
507
+ else if (ctrl && !e.altKey && e.code === 'KeyX' && active !== 'main' && tree.dir) act = () => close(active);
508
+ if (!act) return;
509
+ e.preventDefault();
510
+ e.stopPropagation();
511
+ act();
512
+ }, true);
513
+
514
+ function focusGroup(n) {
515
+ if (!tree.dir || narrow()) return;
516
+ const id = leaves()[n - 1];
517
+ if (!id) return;
518
+ activate(id);
519
+ if (id === 'main') return focusMain();
520
+ const p = panes.get(id);
521
+ if (p.opened) p.xterm.focus();
522
+ else p.el.querySelector('.gpick').focus();
523
+ }
458
524
  matchMedia('(max-width: 760px)').addEventListener('change', () => layout());
459
525
 
460
526
  // Restore the last layout.
package/public/index.html CHANGED
@@ -29,6 +29,7 @@
29
29
  </div>
30
30
  <div class="top-actions">
31
31
  <input id="filter" type="search" placeholder="Filter agents" aria-label="Filter agents" />
32
+ <nav class="top-nav" id="top-nav" aria-label="Views">
32
33
  <button id="today-btn" title="Today: what needs you, from every list, most pressing first, and why (y)">Today <span id="today-count" class="badge ready"></span></button>
33
34
  <button id="assistant-btn" title="An always-on session that finds new work and starts agents for it">Assistant <span id="assistant-dot" class="assistant-dot" hidden></span></button>
34
35
  <button id="spend-btn" title="Results across agents (merge rate, time to PR, cost per merged PR), what they cost, and spending limits">Results <span id="spend-today" class="spend-today"></span></button>
@@ -43,6 +44,11 @@
43
44
  <button id="watch-btn" title="Running agents' sessions side by side, live: follow them all without clicking from one to the next">Watch</button>
44
45
  <button id="machine-btn" title="A terminal on this computer (your home folder), from any device you're signed in on">Terminal</button>
45
46
  <button id="ask-btn" title="A general session with no repo or folder, on Claude Code or another engine you have (Codex, Muse Code, …)">Ask Agent</button>
47
+ <div class="menu-wrap top-more" id="top-more" hidden>
48
+ <button id="top-more-btn" type="button" aria-haspopup="menu" aria-expanded="false">More ▾</button>
49
+ <div id="top-more-menu" class="menu" role="menu" hidden></div>
50
+ </div>
51
+ </nav>
46
52
  <button id="new-btn" class="primary">+ New agents</button>
47
53
  <div class="menu-wrap">
48
54
  <button id="menu-btn" class="menu-btn" type="button" aria-haspopup="menu" aria-expanded="false" title="Settings and preferences">
@@ -139,7 +145,7 @@
139
145
  <input type="file" id="term-file" multiple hidden>
140
146
  <button id="term-fit" class="ghost small" title="Refit the terminal to the panel">Fit</button>
141
147
  <button id="term-split-btn" class="ghost small desk-only" title="Split: the terminal on the left, and Code, Docs (diagrams) or Changes on the right">◫ Split</button>
142
- <button id="group-split" class="ghost small desk-only" title="Split the screen: a group to the right for another agent's session, as in VS Code (Ctrl+\; Ctrl+Shift+\ splits down). Or drag an agent from the list onto the right or bottom edge">⊞ Split screen</button>
148
+ <button id="group-split" class="ghost small desk-only" title="Split the screen: a group to the right for another agent's session, as in VS Code (Cmd+\ on a Mac, or Ctrl+Shift+\; add Shift on a Mac, or Alt, to split down). Or drag an agent from the list onto the right or bottom edge">⊞ Split screen</button>
143
149
  <button id="term-max" class="ghost small desk-only" title="Expand to fill the window (Ctrl+Shift+E)">⤢ Expand</button>
144
150
  <button id="term-full" class="ghost small desk-only" title="Full screen (Esc to leave)">⛶ Full screen</button>
145
151
  <button id="term-close" class="ghost small" title="Hide the terminal (the agent keeps running)">Hide terminal</button>
package/public/keys.js CHANGED
@@ -59,6 +59,12 @@ export const SHORTCUTS = [
59
59
  [['Ctrl+Shift+L'], 'Leave the terminal (then the keys above work)', 'leave'],
60
60
  [['Ctrl+Shift+E'], 'Expand or shrink the terminal', null],
61
61
  ]],
62
+ ['Split screen (also from a terminal)', [
63
+ [['Cmd+\\', 'Ctrl+Shift+\\'], 'Split the active group to the right', null],
64
+ [['Cmd+Shift+\\', 'Ctrl+Alt+Shift+\\'], 'Split it down', null],
65
+ [['Ctrl+Shift+1…6'], 'Go to group 1 to 6 (left to right, top to bottom)', null],
66
+ [['Ctrl+Shift+X'], 'Close the active group (its agent keeps running)', null],
67
+ ]],
62
68
  ];
63
69
 
64
70
  // A single key, as an event names it, to its action.
package/public/style.css CHANGED
@@ -88,8 +88,25 @@ a:hover { text-decoration: underline; }
88
88
  .about-list .sep { grid-column: 1 / -1; border-top: 1px solid var(--border); margin: 4px 0; }
89
89
  .conn.ok::before { content: '● '; color: var(--green); }
90
90
  .conn.bad::before { content: '● '; color: var(--red); }
91
- .top-actions { display: flex; gap: 8px; }
92
- .top-actions input { width: 220px; }
91
+ /* Below 1100px the title and connection text step aside for the view buttons: the logo and a dot stay. */
92
+ @media (max-width: 1100px) {
93
+ .brand { gap: 6px; }
94
+ .brand h1 { display: none; }
95
+ .conn { font-size: 0; }
96
+ .conn::before { font-size: 12px; }
97
+ .about-btn { padding: 2px 6px; }
98
+ }
99
+ .top-actions { display: flex; gap: 8px; flex: 1 1 auto; min-width: 0; justify-content: flex-end; }
100
+ .top-actions > * { flex-shrink: 0; }
101
+ /* The filter gives up its room first, then the view buttons go into More (topnav.js). */
102
+ .top-actions > input { width: 220px; flex: 0 1000 220px; min-width: 120px; }
103
+ .top-nav { display: flex; gap: 8px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
104
+ .top-nav > * { flex: none; }
105
+ .top-actions > .top-nav { flex-shrink: 1; }
106
+ .top-more { position: static; }
107
+ #top-more-btn.has-news::after { content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
108
+ #top-more-menu { position: fixed; top: auto; right: 16px; margin-top: 6px; min-width: 200px; }
109
+ #top-more-menu > button { display: flex; align-items: center; gap: 8px; }
93
110
 
94
111
  /* ---------- controls */
95
112
  button {
@@ -501,6 +518,7 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
501
518
  html, body { overflow-x: hidden; max-width: 100vw; }
502
519
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
503
520
  .top-actions { width: 100%; flex-wrap: wrap; }
521
+ .top-actions > .top-nav { flex: 1 1 100%; order: 1; }
504
522
  .top-actions input { flex: 1 1 140px; width: auto; min-width: 0; }
505
523
  .d-head, .d-actions { min-width: 0; }
506
524
  .d-actions button { flex: 1 1 auto; }
@@ -0,0 +1,75 @@
1
+ // The top bar's view buttons fit the window: the ones that don't fit move, in order, into a
2
+ // "More" menu at the end of the row (as VS Code does with tabs). The buttons themselves move, so
3
+ // their handlers, counts and shortcuts keep working; a count on a moved one shows as a dot on More.
4
+
5
+ export function initTopNav({ $ }) {
6
+ const nav = $('#top-nav');
7
+ const wrap = $('#top-more');
8
+ const btn = $('#top-more-btn');
9
+ const menu = $('#top-more-menu');
10
+ const order = [...nav.querySelectorAll(':scope > button')];
11
+ let fitting = false;
12
+
13
+ const counted = (b) => [...b.querySelectorAll('.badge')].some((x) => x.textContent.trim()) || Boolean(b.querySelector('.assistant-dot:not([hidden])'));
14
+
15
+ function fit() {
16
+ if (fitting) return;
17
+ fitting = true;
18
+ observer.disconnect();
19
+ // Everything back in the row, in order; then move the last ones out until the row fits.
20
+ for (const b of order) nav.insertBefore(b, wrap);
21
+ wrap.hidden = false;
22
+ const moved = [];
23
+ while (nav.scrollWidth > nav.clientWidth + 1) {
24
+ const last = order.filter((b) => b.parentElement === nav && !b.hidden).pop();
25
+ if (!last) break;
26
+ moved.unshift(last);
27
+ menu.prepend(last);
28
+ }
29
+ wrap.hidden = moved.length === 0;
30
+ if (!moved.length) close();
31
+ btn.classList.toggle('has-news', moved.some(counted));
32
+ btn.title = moved.length ? `More: ${moved.map((b) => b.firstChild?.textContent?.trim()).filter(Boolean).join(', ')}` : '';
33
+ observe();
34
+ fitting = false;
35
+ }
36
+
37
+ let queued = false;
38
+ const later = () => {
39
+ if (queued) return;
40
+ queued = true;
41
+ requestAnimationFrame(() => {
42
+ queued = false;
43
+ fit();
44
+ });
45
+ };
46
+ // Counts change the buttons' widths; the window and the rest of the bar change the room.
47
+ const observer = new MutationObserver(later);
48
+ const observe = () => {
49
+ for (const b of order) observer.observe(b, { childList: true, characterData: true, subtree: true, attributes: true, attributeFilter: ['hidden', 'class'] });
50
+ };
51
+ new ResizeObserver(later).observe(nav.parentElement);
52
+ addEventListener('resize', later);
53
+
54
+ function close() {
55
+ menu.hidden = true;
56
+ btn.setAttribute('aria-expanded', 'false');
57
+ }
58
+ btn.addEventListener('click', (e) => {
59
+ e.stopPropagation();
60
+ menu.hidden = !menu.hidden;
61
+ btn.setAttribute('aria-expanded', String(!menu.hidden));
62
+ });
63
+ // A button in the menu does its own thing (its handler is unchanged); then the menu closes.
64
+ menu.addEventListener('click', () => setTimeout(close));
65
+ document.addEventListener('click', (e) => {
66
+ if (!menu.hidden && !wrap.contains(e.target)) close();
67
+ });
68
+ document.addEventListener('keydown', (e) => {
69
+ if (e.key === 'Escape' && !menu.hidden) close();
70
+ });
71
+
72
+ fit();
73
+ document.fonts?.ready.then(later);
74
+ return { fit };
75
+ }