@william_jin/autobrowse 0.8.26 → 0.8.27

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.
@@ -170,7 +170,7 @@ kbd{display:inline-flex;align-items:center;justify-content:center;min-width:18px
170
170
  /* the entry fade on first style, not on a frame callback: a covered window runs none, and a pane made there stayed clear */
171
171
  @starting-style{.pane.in{opacity:0}}
172
172
  .pane.off{visibility:hidden;pointer-events:none}
173
- /* §Hub windows: each run in Grid or Split is a window: frame, shadow, a raised title bar over the darker desk */
173
+ /* §Hub windows: each run among others is a window: frame, shadow, a raised title bar over the darker desk */
174
174
  .grid .pane,.single .pane.hug{border-radius:var(--win-r);box-shadow:var(--frame)}
175
175
  .pane::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:inset 0 0 0 1.5px var(--ring);pointer-events:none;opacity:0;transition:opacity .15s}
176
176
  .pane.cur::after{opacity:1}
@@ -266,9 +266,8 @@ kbd{display:inline-flex;align-items:center;justify-content:center;min-width:18px
266
266
  <span id="segs">
267
267
  <button type="button" class="nb" id="unmax" title="Restore the layout (⌘⇧↩)" tabindex="-1"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><path d="M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5l4-4M6.5 9.5l-4 4"/></svg>Restore</button>
268
268
  <fieldset id="seg" aria-label="Layout">
269
- <button type="button" data-l="focus" title="Focus: one pane (⌃⌘1)" aria-label="Focus: one pane" aria-pressed="true"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="2"/></svg></button>
270
- <button type="button" data-l="split" title="Split: two panes (⌃⌘2)" aria-label="Split: two panes" aria-pressed="false"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="2"/><path d="M8 3v10"/></svg></button>
271
- <button type="button" data-l="grid" title="Grid: up to 9 panes (⌃⌘3)" aria-label="Grid: up to 9 panes" aria-pressed="false"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="2"/><path d="M8 3v10M2 8h12"/></svg></button>
269
+ <button type="button" data-l="focus" title="Focus: one run; ⌘-click rows for more (⌃⌘1)" aria-label="Focus: one run, ⌘-click rows for more" aria-pressed="true"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="2"/></svg></button>
270
+ <button type="button" data-l="grid" title="Grid: up to 9 panes (⌃⌘2)" aria-label="Grid: up to 9 panes" aria-pressed="false"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="2"/><path d="M8 3v10M2 8h12"/></svg></button>
272
271
  </fieldset></span>
273
272
  <button type="button" class="nb" id="pauseall" title="Pause every agent (⌘⇧P)" disabled>Pause all</button>
274
273
  <button type="button" class="nb" id="keysbtn" title="Keys" aria-label="Keys" aria-expanded="false"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><rect x="1.5" y="4" width="13" height="8.5" rx="1.8"/><path d="M4.5 7h.01M7 7h.01M9.5 7h.01M12 7h.01M5 10h6"/></svg></button>
@@ -298,7 +297,8 @@ const stuckIO = new IntersectionObserver((es) => {
298
297
  }, { root: list, rootMargin: '-3px 0px 0px 0px', threshold: [1] });
299
298
  const app = (m) => { try { window.webkit.messageHandlers.ipc.postMessage(JSON.stringify(m)); } catch {} };
300
299
  const store = { get(k, d) { try { return localStorage.getItem(k) ?? d; } catch { return d; } }, set(k, v) { try { localStorage.setItem(k, v); } catch {} } };
301
- const CAP = { focus: 1, split: 2, grid: 9 };
300
+ /** most panes: Grid fills them all; Focus holds only the runs picked (one by default, ⌘-click adds) */
301
+ const CAP = { focus: 9, grid: 9 };
302
302
  const ICON = {
303
303
  pause: '<rect x="4.25" y="3.25" width="2.6" height="9.5" rx=".9"/><rect x="9.15" y="3.25" width="2.6" height="9.5" rx=".9"/>',
304
304
  play: '<path d="M5 3.3v9.4a.7.7 0 0 0 1.07.6l7.3-4.7a.7.7 0 0 0 0-1.2L6.07 2.7A.7.7 0 0 0 5 3.3z"/>',
@@ -320,9 +320,9 @@ const ICON = {
320
320
  const FILLED = new Set(['pause', 'play']);
321
321
  const icon = (n) => `<svg class="ic${FILLED.has(n) ? ' fill' : ''}" viewBox="0 0 16 16" aria-hidden="true">${ICON[n]}</svg>`;
322
322
  /** the hub's keys: this sheet, and a group in each pane's ⌘/ sheet */
323
- const HUB_KEYS = [['Sidebar: full or collapsed', ['⌘', '\\']], ['Focus, Split, Grid', ['⌃', '⌘', '1–3']], ['Next pane', ['⌘', '⌥', '←→↑↓']], ['Maximize a pane', ['⌘', '⇧', '↩']], ['Session by row', ['⌘', '⌥', '1–9']], ['Sessions list', ['⌘', '⌥', '0']], ['Own window, dock back', ['⌘', '⇧', 'T']], ['Pause or resume all', ['⌘', '⇧', 'P']]];
324
- /** a pane this wide or wider sizes its page; a narrower one scales it (pages under this go phone layout) */
325
- const SIZE_MIN = 480;
323
+ const HUB_KEYS = [['Sidebar: full or collapsed', ['⌘', '\\']], ['Focus, Grid', ['⌃', '⌘', '1–2']], ['Focus one more run, or one fewer', ['⌘', 'click']], ['Next pane', ['⌘', '⌥', '←→↑↓']], ['Maximize a pane', ['⌘', '⇧', '↩']], ['Session by row', ['⌘', '⌥', '1–9']], ['Sessions list', ['⌘', '⌥', '0']], ['Own window, dock back', ['⌘', '⇧', 'T']], ['Pause or resume all', ['⌘', '⇧', 'P']]];
324
+ /** the smallest page a pane sizes, CSS px: under it on either side the page keeps this, in the pane's shape, scaled down */
325
+ const SIZE_MIN = { w: 480, h: 600 };
326
326
 
327
327
  // --- state ------------------------------------------------------------------------
328
328
  /** id → row from the app; plus `ended` (ms) once the session left */
@@ -340,18 +340,23 @@ const paceNext = (k) => PACES[(PACES.indexOf(k) + 1) % PACES.length] ?? 1;
340
340
  const isOff = (v) => v === false || /^(false|0|no|off)$/i.test(String(v ?? ''));
341
341
  const autoOn = () => !isOff(prefs.hubAutoOpen);
342
342
  const motionOn = () => !isOff(prefs.hubMotion);
343
- /** the file's layout wins at launch and when it changes; ⌃1–3 lasts until then */
343
+ /** the file's layout wins at launch and when it changes; ⌃⌘1–2 lasts until then */
344
344
  function takePrefs(p, first) {
345
345
  const was = prefs.hubLayout;
346
346
  prefs = p && typeof p === 'object' ? p : {};
347
347
  const n = Math.round(Number(prefs.hubMaxPanes));
348
348
  const most = n >= 1 && n <= 9 ? n : 9;
349
- CAP.grid = most; CAP.split = Math.min(2, most);
349
+ CAP.grid = most; CAP.focus = most;
350
350
  const g = document.querySelector('#seg [data-l=grid]');
351
- if (g) { g.title = `Grid: up to ${most} panes (⌃⌘3)`; g.setAttribute('aria-label', `Grid: up to ${most} panes`); }
351
+ if (g) { g.title = `Grid: up to ${most} panes (⌃⌘2)`; g.setAttribute('aria-label', `Grid: up to ${most} panes`); }
352
352
  document.documentElement.classList.toggle('still', !motionOn());
353
353
  const l = prefs.hubLayout;
354
- if (CAP[l] && (first || l !== was)) { layout = l; max = false; }
354
+ if (CAP[l] && (first || l !== was)) { switchLayout(l); max = false; }
355
+ }
356
+ /** into a layout; Focus from Grid keeps the pane in front, alone */
357
+ function switchLayout(l) {
358
+ if (l === 'focus' && layout !== 'focus' && cells[cur]) { cells = [cells[cur]]; cur = 0; }
359
+ layout = l;
355
360
  }
356
361
  /** placed panes, by key (`id`, or `id#own` for a second view of one session) */
357
362
  let cells = [];
@@ -419,7 +424,7 @@ function put(r) {
419
424
  if (r.url || r.ended || was?.ended) { auto.delete(r.id); askedAt.delete(r.id); }
420
425
  if (was?.ended) opening.delete(r.id);
421
426
  // a lazy run's live view just came up because a person opened it: show it
422
- if (was && !was.url && r.url && opening.has(r.id)) { opening.delete(r.id); show(r.id); }
427
+ if (was && !was.url && r.url && opening.has(r.id)) { opening.delete(r.id); show(r.id, adding.delete(r.id)); }
423
428
  // a session's viewer moved: its panes reload on the new address
424
429
  if (was?.url && r.url && was.url !== r.url) for (const [k, p] of panes) if (idOf(k) === r.id) drop(k);
425
430
  if (!placeable(r.id)) cells = cells.filter((k) => idOf(k) !== r.id);
@@ -444,25 +449,25 @@ function end(id) {
444
449
  }
445
450
 
446
451
  // --- layout --------------------------------------------------------------------------
447
- /** fill free cells with sessions not on screen, in row order */
452
+ /** fill free cells with sessions not on screen, in row order: Grid every pane, Focus one when none is picked */
448
453
  function fill() {
449
454
  cells = cells.filter((k) => placeable(idOf(k)));
450
- const cap = CAP[layout];
455
+ const cap = CAP[layout], want = layout === 'focus' ? 1 : cap;
451
456
  if (cells.length > cap) cells = cells.slice(0, cap);
452
457
  for (const id of sorted()) {
453
- if (cells.length >= cap) break;
458
+ if (cells.length >= want) break;
454
459
  if (placeable(id) && !cells.some((k) => idOf(k) === id)) cells.push(id);
455
460
  }
456
461
  cur = Math.min(cur, Math.max(0, cells.length - 1));
457
462
  if (max && !cells[cur]) max = false;
458
- autoOpen(cap);
463
+ autoOpen(want);
459
464
  }
460
465
  /** lazy runs asked to watch by themselves; on arrival fill places them, never taking cur or focus */
461
466
  const auto = new Set();
462
467
  /** when each ask went out. An ask is asked once: the run holds it and answers with its `url` when its
463
468
  * view is up, however late (a busy page). No re-ask, no poll. */
464
469
  const askedAt = new Map();
465
- /** an ask this old stops holding a pane: the next run may take it (a silent run never starves Focus or Split) */
470
+ /** an ask this old stops holding a pane: the next run may take it (a silent run never starves Focus) */
466
471
  const AUTO_MS = 20_000;
467
472
  function ask(id) {
468
473
  askedAt.set(id, Date.now());
@@ -486,7 +491,7 @@ function autoOpen(cap) {
486
491
  }
487
492
  function setLayout(l) {
488
493
  if (!CAP[l]) return;
489
- layout = l; max = false; store.set('hub.layout', l);
494
+ switchLayout(l); max = false; store.set('hub.layout', l);
490
495
  fill(); render();
491
496
  }
492
497
  /** bento cells, in fractions of the stage */
@@ -541,7 +546,7 @@ function pageArea([, , w, h], pg) {
541
546
  const s = fitScale(w, rh, pg);
542
547
  return s * s * pg.w * pg.h;
543
548
  }
544
- /** the arrangements to weigh: Split side by side or stacked; Grid the bento, its stacked twin, 1 to 5 columns */
549
+ /** the arrangements to weigh: the bento, its stacked twin, 1 to 5 columns (two panes: side by side or stacked) */
545
550
  function arrangements(n) {
546
551
  const out = [];
547
552
  if (n === 3) out.push(['bento', [[0, 0, .6, 1], [.6, 0, .4, .5], [.6, .5, .4, .5]]], ['bento-stack', [[0, 0, 1, .6], [0, .6, .5, .4], [.5, .6, .5, .4]]]);
@@ -672,16 +677,15 @@ function packRows(items, gap) {
672
677
  }
673
678
  return items;
674
679
  }
675
- /** what a pane's viewer needs: tiles scale frames; one full pane sets the viewport; a narrow first pane zooms out */
680
+ /** what a pane's viewer needs: tiles scale frames; one full pane or a session's first pane sets the viewport, never under SIZE_MIN */
676
681
  function embedOf(key) {
677
682
  const i = cells.indexOf(key), single = max ? i === cur : cells.length === 1 && layout === 'focus';
678
- // a session's first pane, wide enough, sizes its page as a split browser does; a second view of it only scales
683
+ // a session's first pane sizes its page as a split browser does; a second view of it only scales
679
684
  const first = !key.includes('#') && cells.findIndex((k) => idOf(k) === idOf(key)) === i;
680
685
  const w = panes.get(key)?.w ?? 0, owns = i >= 0 && !max && first && w > 0;
681
- const sizes = i >= 0 && (single || (owns && w >= SIZE_MIN));
682
- // under SIZE_MIN: page at SIZE_MIN wide, the pane's shape, scaled down (no phone layout, no bands)
683
- const zoom = owns && w < SIZE_MIN ? SIZE_MIN : 0;
684
- return { t: 'embed', tile: !sizes, zoom, bare: !single, on: hubOn && i >= 0 && (!max || i === cur), keys: HUB_KEYS };
686
+ const sizes = i >= 0 && (single || owns);
687
+ // the viewer knows its stage: under SIZE_MIN on either side it zooms out (no phone layout, no cut form, no bands)
688
+ return { t: 'embed', tile: !sizes, zoom: sizes ? SIZE_MIN : 0, bare: !single, on: hubOn && i >= 0 && (!max || i === cur), keys: HUB_KEYS };
685
689
  }
686
690
 
687
691
  // --- panes -------------------------------------------------------------------------
@@ -972,7 +976,7 @@ function rowEl(id) {
972
976
  const b = e.target.closest('button');
973
977
  if (b?.dataset.more) { if (allTabs.has(id)) allTabs.delete(id); else allTabs.add(id); renderRows(); return; }
974
978
  if (b?.dataset.tab) { show(id); app({ t: 'tab', id, tab: Number(b.dataset.tab) }); return; }
975
- if (b?.dataset.a) act(id, b.dataset.a, b.dataset); else show(id);
979
+ if (b?.dataset.a) act(id, b.dataset.a, b.dataset); else show(id, e.metaKey || e.shiftKey);
976
980
  });
977
981
  el.addEventListener('keydown', (e) => { if (e.key === 'Enter' && e.target === el) enter(id); });
978
982
  el.addEventListener('dragstart', (e) => { e.dataTransfer.setData('text/plain', `row:${id}`); e.dataTransfer.effectAllowed = 'move'; });
@@ -1217,6 +1221,8 @@ setInterval(() => {
1217
1221
 
1218
1222
  // --- actions -------------------------------------------------------------------------
1219
1223
  const opening = new Set();
1224
+ /** asked with ⌘-click in Focus: placed beside the others when its view comes up */
1225
+ const adding = new Set();
1220
1226
  function act(id, a, d = {}) {
1221
1227
  const r = rows.get(id);
1222
1228
  if (!r) return;
@@ -1232,15 +1238,25 @@ function act(id, a, d = {}) {
1232
1238
  else if (a === 'pause') app({ t: 'pause', id, held: !r.state?.held });
1233
1239
  else if (a === 'back') app({ t: 'back', id });
1234
1240
  }
1235
- /** put a session in front: its torn window, its pane, or a pane it takes over */
1236
- function show(id) {
1241
+ /**
1242
+ * put a session in front: its torn window, its pane, or a pane it takes over. Focus: that run alone;
1243
+ * `more` (⌘- or ⇧-click) adds it beside the others, or drops it when it is already there
1244
+ */
1245
+ function show(id, more = false) {
1237
1246
  const r = rows.get(id);
1238
1247
  if (!r || r.ended) return;
1239
1248
  if (r.torn) return app({ t: 'tear', id });
1240
- if (r.lazy && !r.url) return act(id, 'watch');
1249
+ if (r.lazy && !r.url) { if (more) adding.add(id); else adding.delete(id); return act(id, 'watch'); }
1241
1250
  if (!placeable(id)) return;
1242
1251
  const at = cells.findIndex((k) => idOf(k) === id);
1243
- if (at >= 0) cur = at;
1252
+ if (layout === 'focus' && !more) { cells = cells.filter((k) => idOf(k) === id); if (!cells.length) cells = [id]; cur = 0; }
1253
+ else if (layout === 'focus' && at >= 0 && cells.length > 1) {
1254
+ cells = cells.filter((k) => idOf(k) !== id);
1255
+ cur = Math.min(cur, cells.length - 1);
1256
+ max = false;
1257
+ render();
1258
+ return focusPane();
1259
+ } else if (at >= 0) cur = at;
1244
1260
  else if (cells.length < CAP[layout]) { cells.push(id); cur = cells.length - 1; }
1245
1261
  else cells[cur] = id;
1246
1262
  if (max) max = cells[cur] === id;
@@ -1273,7 +1289,7 @@ function move(code) {
1273
1289
  function key(k) {
1274
1290
  const { code, shift, alt, ctrl } = k;
1275
1291
  if (!shift && !alt && !ctrl && code === 'Backslash') { toggleSide(); return true; }
1276
- if (ctrl && !alt && !shift && /^Digit[1-3]$/.test(code)) { setLayout(['focus', 'split', 'grid'][Number(code.slice(5)) - 1]); return true; }
1292
+ if (ctrl && !alt && !shift && /^Digit[12]$/.test(code)) { setLayout(['focus', 'grid'][Number(code.slice(5)) - 1]); return true; }
1277
1293
  if (alt && !ctrl && !shift && /^Arrow/.test(code)) { move(code); return true; }
1278
1294
  if (alt && !ctrl && !shift && code === 'Digit0') { focusList(); return true; }
1279
1295
  if (alt && !ctrl && !shift && /^Digit[1-9]$/.test(code)) { const id = shown()[Number(code.slice(5)) - 1]?.dataset.id; if (id) show(id); return true; }
@@ -1281,6 +1297,8 @@ function key(k) {
1281
1297
  if (shift && !alt && !ctrl && code === 'Enter') { toggleMax(); return true; }
1282
1298
  if (shift && !alt && !ctrl && code === 'KeyT') { const id = cells[cur] && idOf(cells[cur]); if (id) app({ t: 'tear', id }); return true; }
1283
1299
  if (shift && !alt && !ctrl && code === 'KeyP') { app({ t: 'pause-all' }); return true; }
1300
+ // ⌘J from the hub's own chrome: the current pane's Claude terminal
1301
+ if (!shift && !alt && !ctrl && code === 'KeyJ') { const p = panes.get(cells[cur]); p?.frame.contentWindow?.postMessage({ hub: { t: 'term' } }, '*'); return !!p; }
1284
1302
  return false;
1285
1303
  }
1286
1304
  addEventListener('keydown', (e) => {