@william_jin/autobrowse 0.8.25 → 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 = [];
@@ -415,9 +420,11 @@ function put(r) {
415
420
  if (was && r.state && !('icons' in r.state)) r.state = { ...r.state, icon: was.state?.icon, icons: was.state?.icons };
416
421
  if (!was) order.push(r.id);
417
422
  rows.set(r.id, r);
418
- if (r.url || r.ended) auto.delete(r.id);
423
+ // the run answered, ended, or joined again (a new link: an ask on the old one is lost)
424
+ if (r.url || r.ended || was?.ended) { auto.delete(r.id); askedAt.delete(r.id); }
425
+ if (was?.ended) opening.delete(r.id);
419
426
  // a lazy run's live view just came up because a person opened it: show it
420
- 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)); }
421
428
  // a session's viewer moved: its panes reload on the new address
422
429
  if (was?.url && r.url && was.url !== r.url) for (const [k, p] of panes) if (idOf(k) === r.id) drop(k);
423
430
  if (!placeable(r.id)) cells = cells.filter((k) => idOf(k) !== r.id);
@@ -433,7 +440,7 @@ function end(id) {
433
440
  el?.classList.add('out');
434
441
  setTimeout(() => {
435
442
  if (!rows.get(id)?.ended) return;
436
- rows.delete(id); pageBy.delete(id); order = order.filter((x) => x !== id); auto.delete(id); autoFailed.delete(id);
443
+ rows.delete(id); pageBy.delete(id); order = order.filter((x) => x !== id); auto.delete(id); askedAt.delete(id);
437
444
  cells = cells.filter((k) => idOf(k) !== id);
438
445
  for (const k of [...panes.keys()]) if (idOf(k) === id) drop(k);
439
446
  fill(); render();
@@ -442,48 +449,49 @@ function end(id) {
442
449
  }
443
450
 
444
451
  // --- layout --------------------------------------------------------------------------
445
- /** 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 */
446
453
  function fill() {
447
454
  cells = cells.filter((k) => placeable(idOf(k)));
448
- const cap = CAP[layout];
455
+ const cap = CAP[layout], want = layout === 'focus' ? 1 : cap;
449
456
  if (cells.length > cap) cells = cells.slice(0, cap);
450
457
  for (const id of sorted()) {
451
- if (cells.length >= cap) break;
458
+ if (cells.length >= want) break;
452
459
  if (placeable(id) && !cells.some((k) => idOf(k) === id)) cells.push(id);
453
460
  }
454
461
  cur = Math.min(cur, Math.max(0, cells.length - 1));
455
462
  if (max && !cells[cur]) max = false;
456
- autoOpen(cap);
463
+ autoOpen(want);
457
464
  }
458
465
  /** lazy runs asked to watch by themselves; on arrival fill places them, never taking cur or focus */
459
466
  const auto = new Set();
460
- /** asked, never came up: when to ask again (a busy page answers late; every run opens by itself) */
461
- const autoFailed = new Map();
467
+ /** when each ask went out. An ask is asked once: the run holds it and answers with its `url` when its
468
+ * view is up, however late (a busy page). No re-ask, no poll. */
469
+ const askedAt = new Map();
470
+ /** an ask this old stops holding a pane: the next run may take it (a silent run never starves Focus) */
462
471
  const AUTO_MS = 20_000;
463
- const AUTO_RETRY_MS = 30_000;
472
+ function ask(id) {
473
+ askedAt.set(id, Date.now());
474
+ app({ t: 'watch', id });
475
+ setTimeout(() => { if (rows.has(id) && !rows.get(id).url) { fill(); render(); } }, AUTO_MS + 50);
476
+ }
477
+ const asked = (id) => auto.has(id) || opening.has(id);
464
478
  /** a pane free: watch lazy runs, in row order, one per free pane. Off screen too: a run streams no frame
465
479
  * while the hub is hidden, and a switch to the hub then shows it in ~0.3 s, not ~1.5 s (WA-1500) */
466
480
  function autoOpen(cap) {
467
481
  if (!autoOn()) return;
468
- const asked = (id) => auto.has(id) || opening.has(id);
469
- let free = cap - cells.length - [...rows.keys()].filter((id) => asked(id) && !rows.get(id).url).length;
482
+ const now = Date.now();
483
+ let free = cap - cells.length - [...rows.keys()].filter((id) => asked(id) && !rows.get(id).url && now - (askedAt.get(id) ?? 0) < AUTO_MS).length;
470
484
  for (const id of sorted()) {
471
485
  if (free <= 0) return;
472
486
  const r = rows.get(id);
473
- if (!r.lazy || r.url || r.ended || r.torn || r.moved || asked(id) || (autoFailed.get(id) ?? 0) > Date.now()) continue;
474
- autoFailed.delete(id);
487
+ if (!r.lazy || r.url || r.ended || r.torn || r.moved || asked(id)) continue;
475
488
  auto.add(id); free--;
476
- app({ t: 'watch', id });
477
- setTimeout(() => {
478
- if (!auto.delete(id) || rows.get(id)?.url) return;
479
- autoFailed.set(id, Date.now() + AUTO_RETRY_MS); fill(); render();
480
- setTimeout(() => { if (rows.has(id)) { fill(); render(); } }, AUTO_RETRY_MS + 50);
481
- }, AUTO_MS);
489
+ ask(id);
482
490
  }
483
491
  }
484
492
  function setLayout(l) {
485
493
  if (!CAP[l]) return;
486
- layout = l; max = false; store.set('hub.layout', l);
494
+ switchLayout(l); max = false; store.set('hub.layout', l);
487
495
  fill(); render();
488
496
  }
489
497
  /** bento cells, in fractions of the stage */
@@ -538,7 +546,7 @@ function pageArea([, , w, h], pg) {
538
546
  const s = fitScale(w, rh, pg);
539
547
  return s * s * pg.w * pg.h;
540
548
  }
541
- /** 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) */
542
550
  function arrangements(n) {
543
551
  const out = [];
544
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]]]);
@@ -669,16 +677,15 @@ function packRows(items, gap) {
669
677
  }
670
678
  return items;
671
679
  }
672
- /** 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 */
673
681
  function embedOf(key) {
674
682
  const i = cells.indexOf(key), single = max ? i === cur : cells.length === 1 && layout === 'focus';
675
- // 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
676
684
  const first = !key.includes('#') && cells.findIndex((k) => idOf(k) === idOf(key)) === i;
677
685
  const w = panes.get(key)?.w ?? 0, owns = i >= 0 && !max && first && w > 0;
678
- const sizes = i >= 0 && (single || (owns && w >= SIZE_MIN));
679
- // under SIZE_MIN: page at SIZE_MIN wide, the pane's shape, scaled down (no phone layout, no bands)
680
- const zoom = owns && w < SIZE_MIN ? SIZE_MIN : 0;
681
- 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 };
682
689
  }
683
690
 
684
691
  // --- panes -------------------------------------------------------------------------
@@ -969,7 +976,7 @@ function rowEl(id) {
969
976
  const b = e.target.closest('button');
970
977
  if (b?.dataset.more) { if (allTabs.has(id)) allTabs.delete(id); else allTabs.add(id); renderRows(); return; }
971
978
  if (b?.dataset.tab) { show(id); app({ t: 'tab', id, tab: Number(b.dataset.tab) }); return; }
972
- 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);
973
980
  });
974
981
  el.addEventListener('keydown', (e) => { if (e.key === 'Enter' && e.target === el) enter(id); });
975
982
  el.addEventListener('dragstart', (e) => { e.dataTransfer.setData('text/plain', `row:${id}`); e.dataTransfer.effectAllowed = 'move'; });
@@ -1214,6 +1221,8 @@ setInterval(() => {
1214
1221
 
1215
1222
  // --- actions -------------------------------------------------------------------------
1216
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();
1217
1226
  function act(id, a, d = {}) {
1218
1227
  const r = rows.get(id);
1219
1228
  if (!r) return;
@@ -1225,19 +1234,29 @@ function act(id, a, d = {}) {
1225
1234
  soon();
1226
1235
  return;
1227
1236
  }
1228
- if (a === 'watch') { opening.add(id); app({ t: 'watch', id }); }
1237
+ if (a === 'watch') { opening.add(id); ask(id); }
1229
1238
  else if (a === 'pause') app({ t: 'pause', id, held: !r.state?.held });
1230
1239
  else if (a === 'back') app({ t: 'back', id });
1231
1240
  }
1232
- /** put a session in front: its torn window, its pane, or a pane it takes over */
1233
- 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) {
1234
1246
  const r = rows.get(id);
1235
1247
  if (!r || r.ended) return;
1236
1248
  if (r.torn) return app({ t: 'tear', id });
1237
- 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'); }
1238
1250
  if (!placeable(id)) return;
1239
1251
  const at = cells.findIndex((k) => idOf(k) === id);
1240
- 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;
1241
1260
  else if (cells.length < CAP[layout]) { cells.push(id); cur = cells.length - 1; }
1242
1261
  else cells[cur] = id;
1243
1262
  if (max) max = cells[cur] === id;
@@ -1270,7 +1289,7 @@ function move(code) {
1270
1289
  function key(k) {
1271
1290
  const { code, shift, alt, ctrl } = k;
1272
1291
  if (!shift && !alt && !ctrl && code === 'Backslash') { toggleSide(); return true; }
1273
- 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; }
1274
1293
  if (alt && !ctrl && !shift && /^Arrow/.test(code)) { move(code); return true; }
1275
1294
  if (alt && !ctrl && !shift && code === 'Digit0') { focusList(); return true; }
1276
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; }
@@ -1278,6 +1297,8 @@ function key(k) {
1278
1297
  if (shift && !alt && !ctrl && code === 'Enter') { toggleMax(); return true; }
1279
1298
  if (shift && !alt && !ctrl && code === 'KeyT') { const id = cells[cur] && idOf(cells[cur]); if (id) app({ t: 'tear', id }); return true; }
1280
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; }
1281
1302
  return false;
1282
1303
  }
1283
1304
  addEventListener('keydown', (e) => {