sideby 0.17.0 → 0.19.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.
Files changed (112) hide show
  1. package/README.md +11 -1
  2. package/ai-tasks.json +90 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +9 -1
  5. package/dist/src/cli/commands.js +507 -26
  6. package/dist/src/cli/json-schemas.js +196 -19
  7. package/dist/src/cli/main.js +79 -13
  8. package/dist/src/core/after-install.d.ts +54 -0
  9. package/dist/src/core/after-install.js +78 -0
  10. package/dist/src/core/ask.d.ts +87 -1
  11. package/dist/src/core/ask.js +122 -7
  12. package/dist/src/core/autostart.d.ts +38 -8
  13. package/dist/src/core/autostart.js +85 -39
  14. package/dist/src/core/brand-mark.d.ts +49 -11
  15. package/dist/src/core/brand-mark.js +116 -38
  16. package/dist/src/core/browser-profiles.js +7 -32
  17. package/dist/src/core/config.d.ts +19 -0
  18. package/dist/src/core/config.js +75 -2
  19. package/dist/src/core/desktop-app.d.ts +1 -1
  20. package/dist/src/core/desktop-app.js +2 -2
  21. package/dist/src/core/edit-settings.d.ts +24 -0
  22. package/dist/src/core/edit-settings.js +97 -0
  23. package/dist/src/core/handoff-brief.d.ts +4 -2
  24. package/dist/src/core/handoff-brief.js +6 -1
  25. package/dist/src/core/handoff-chain.d.ts +24 -0
  26. package/dist/src/core/handoff-chain.js +2 -0
  27. package/dist/src/core/handoff-run.d.ts +4 -3
  28. package/dist/src/core/handoff-run.js +14 -9
  29. package/dist/src/core/launch.d.ts +2 -0
  30. package/dist/src/core/launch.js +14 -10
  31. package/dist/src/core/local-build.d.ts +12 -5
  32. package/dist/src/core/local-build.js +49 -31
  33. package/dist/src/core/lock.d.ts +30 -0
  34. package/dist/src/core/lock.js +143 -0
  35. package/dist/src/core/pick-commands.d.ts +42 -0
  36. package/dist/src/core/pick-commands.js +44 -0
  37. package/dist/src/core/quota-levels.d.ts +6 -1
  38. package/dist/src/core/quota-levels.js +16 -5
  39. package/dist/src/core/shell-init.js +3 -1
  40. package/dist/src/core/shell-setup.d.ts +40 -0
  41. package/dist/src/core/shell-setup.js +54 -0
  42. package/dist/src/core/skill-check.d.ts +2 -0
  43. package/dist/src/core/skill-check.js +2 -0
  44. package/dist/src/core/task-spec.d.ts +95 -0
  45. package/dist/src/core/task-spec.js +209 -0
  46. package/dist/src/core/terminal.d.ts +21 -4
  47. package/dist/src/core/terminal.js +155 -10
  48. package/dist/src/core/update.d.ts +27 -16
  49. package/dist/src/core/update.js +69 -95
  50. package/dist/src/core/windows-dirs.d.ts +19 -0
  51. package/dist/src/core/windows-dirs.js +39 -0
  52. package/dist/src/desktop/icon.js +12 -15
  53. package/dist/src/families/claude/ai-task.d.ts +8 -0
  54. package/dist/src/families/claude/ai-task.js +38 -0
  55. package/dist/src/families/claude/handoff-hook.js +4 -4
  56. package/dist/src/families/claude/index.js +3 -0
  57. package/dist/src/families/codex/handoff-hook.js +4 -4
  58. package/dist/src/families/codex/index.js +9 -0
  59. package/dist/src/families/grok/handoff-hook.js +4 -4
  60. package/dist/src/families/grok/index.js +1 -0
  61. package/dist/src/families/pi/index.js +1 -0
  62. package/dist/src/handoff/hook.js +51 -30
  63. package/dist/src/handoff/levels.d.ts +24 -0
  64. package/dist/src/handoff/levels.js +70 -0
  65. package/dist/src/handoff/messages.d.ts +6 -3
  66. package/dist/src/handoff/messages.js +20 -7
  67. package/dist/src/handoff/reader.d.ts +6 -3
  68. package/dist/src/menubar/agent.d.ts +3 -0
  69. package/dist/src/menubar/agent.js +21 -0
  70. package/dist/src/menubar/script.d.ts +8 -0
  71. package/dist/src/menubar/script.js +457 -0
  72. package/dist/src/menubar/snapshot.d.ts +115 -0
  73. package/dist/src/menubar/snapshot.js +255 -0
  74. package/dist/src/menubar/strings.d.ts +87 -0
  75. package/dist/src/menubar/strings.js +88 -0
  76. package/dist/src/panel/background.js +12 -19
  77. package/dist/src/panel/handler.d.ts +30 -0
  78. package/dist/src/panel/handler.js +148 -80
  79. package/dist/src/panel/i18n.d.ts +72 -0
  80. package/dist/src/panel/i18n.js +144 -0
  81. package/dist/src/panel/page-logic.d.ts +105 -0
  82. package/dist/src/panel/page-logic.js +170 -15
  83. package/dist/src/panel/page-script.js +419 -111
  84. package/dist/src/panel/page-styles.js +45 -13
  85. package/dist/src/panel/page.d.ts +7 -0
  86. package/dist/src/panel/page.js +11 -1
  87. package/dist/src/runtime.d.ts +44 -2
  88. package/dist/src/runtime.js +107 -6
  89. package/dist/src/types.d.ts +14 -0
  90. package/package.json +4 -3
  91. package/schemas/alias-list.json +119 -0
  92. package/schemas/alias.json +27 -1
  93. package/schemas/ask-choices.json +168 -0
  94. package/schemas/ask-print.json +87 -0
  95. package/schemas/config.json +28 -1
  96. package/schemas/edit.json +119 -0
  97. package/schemas/error.json +4 -0
  98. package/schemas/families.json +4 -0
  99. package/schemas/list.json +4 -0
  100. package/schemas/local.json +1 -1
  101. package/schemas/menubar-snapshot.json +646 -0
  102. package/schemas/menubar-start.json +112 -0
  103. package/schemas/menubar.json +165 -0
  104. package/schemas/new.json +19 -0
  105. package/schemas/shell-init-setup.json +124 -0
  106. package/skills/sideby/SKILL.md +11 -4
  107. package/skills/sideby/references/accounts.md +10 -0
  108. package/skills/sideby/references/ai-tasks.md +10 -0
  109. package/skills/sideby/references/handoff.md +3 -1
  110. package/skills/sideby/references/panel.md +6 -0
  111. package/skills/sideby/references/setup.md +1 -1
  112. package/skills/sideby/references/update.md +1 -1
@@ -1,8 +1,10 @@
1
1
  // The Panel page's inline script. Plain browser JavaScript in a string (no template literals inside, so String.raw
2
2
  // keeps it verbatim); the pure helpers from page-logic.ts are prepended so the tested code is the code that runs.
3
- import { aiTaskAccounts, aliasArgsOf, aliasIssue, askCopy, attentionReasons, attentionWhy, autostartNote, cacheHitRate, canLeaveLocal, fileSize, fixPrompt, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, menuPlacement, mergeDaily, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaPressure, remoteControlSummary, remoteControlTodo, reorder, rowBadge, sortAccounts, stripSecrets, suggestAlias, suggestName, switchFailure, taskFindings, updatedAge, windowState, withPinned, } from './page-logic.js';
3
+ import { aiTaskAccounts, aliasArgsOf, aliasIssue, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, cacheHitRate, canLeaveLocal, codeSwapOutcome, fileSize, fixPrompt, foldSkips, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, menuPlacement, mergeDaily, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaPressure, remoteControlSummary, remoteControlTodo, reorder, rowBadge, runCodeSwap, sortAccounts, stripSecrets, suggestAlias, suggestName, switchFailure, taskFindings, updatedAge, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
4
4
  const LOGIC = [
5
5
  aiTaskAccounts,
6
+ askBridge,
7
+ askBridged,
6
8
  askCopy,
7
9
  quotaAskable,
8
10
  stripSecrets,
@@ -15,6 +17,7 @@ const LOGIC = [
15
17
  cacheHitRate,
16
18
  fileSize,
17
19
  fixPrompt,
20
+ foldSkips,
18
21
  formatDuration,
19
22
  handoffChangeOf,
20
23
  handoffHintAccount,
@@ -29,6 +32,8 @@ const LOGIC = [
29
32
  newAccountDir,
30
33
  nextReset,
31
34
  canLeaveLocal,
35
+ codeSwapOutcome,
36
+ runCodeSwap,
32
37
  switchFailure,
33
38
  panelFixes,
34
39
  panelHint,
@@ -46,6 +51,8 @@ const LOGIC = [
46
51
  suggestName,
47
52
  updatedAge,
48
53
  pinnedIn,
54
+ widthFollower,
55
+ widthTier,
49
56
  windowState,
50
57
  withPinned,
51
58
  ]
@@ -68,6 +75,9 @@ const MAIN = String.raw `
68
75
  const AUTO_MS = 20000
69
76
  const FAST_MS = 5000
70
77
  const FAST_FOR_MS = 3 * 60000
78
+ // After the layout follows a width into another band, how long the width must hold still before a later crossing
79
+ // in the same gesture is applied (page-logic.ts, widthFollower).
80
+ const WIDTH_SETTLE_MS = 90
71
81
  const S = {
72
82
  state: null, loadError: null, loading: false, loadedAt: 0, history: null,
73
83
  report: null, checking: false, fixing: false, checkError: null, checkRetry: null, fixes: null,
@@ -94,6 +104,7 @@ const MAIN = String.raw `
94
104
  if (raw.hideEmail === true) p.hideEmail = true
95
105
  if (typeof raw.ahHintAt === 'number') p.ahHintAt = raw.ahHintAt
96
106
  if (raw.rcHide === true) p.rcHide = true
107
+ if (raw.mbHintDone === true) p.mbHintDone = true
97
108
  if (raw.cfgDone === true) p.cfgDone = true
98
109
  if (typeof raw.family === 'string') p.family = raw.family
99
110
  if (raw.collapsed && typeof raw.collapsed === 'object')
@@ -292,6 +303,7 @@ const MAIN = String.raw `
292
303
  terminal: 'M4 17l6-5-6-5M12 19h8',
293
304
  key: 'M15 9a3 3 0 1 0-.01 0M12.9 11.1L4 20M7 17l2 2M9.5 14.5l2 2',
294
305
  folder: 'M3 6h6l2 2h10v11H3z',
306
+ file: 'M14 3H6v18h12V7zM14 3v4h4M9 13h6M9 17h6',
295
307
  check: 'M9 12l2 2 4-4M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18z',
296
308
  userPlus: 'M15 19a6 6 0 0 0-12 0M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM19 8v6M16 11h6',
297
309
  x: 'M6 6l12 12M18 6L6 18',
@@ -708,6 +720,26 @@ const MAIN = String.raw `
708
720
  }
709
721
  document.addEventListener('pointerdown', (e) => { if (menu.el && !menu.el.contains(e.target) && !menu.anchor.contains(e.target)) closeMenu() })
710
722
  window.addEventListener('resize', () => closeMenu())
723
+ // Layout bands: the page's narrow-screen rules hang on the root's data-width (set before the first paint by the
724
+ // head script), not on media queries, so a width that slides across a breakpoint (a dragged window, a Portal's
725
+ // sidebar opening around this frame) changes the layout as it crosses, as one short cross-fade, not once per frame.
726
+ function applyWidthTier(tier) {
727
+ const root = document.documentElement
728
+ const set = () => { root.dataset.width = tier }
729
+ if (REDUCED || document.hidden || !document.startViewTransition) return set()
730
+ root.classList.add('vt-width')
731
+ document.startViewTransition(set).finished.finally(() => root.classList.remove('vt-width'))
732
+ }
733
+ let widthFollow = null
734
+ function followWidth(width) {
735
+ if (!widthFollow) {
736
+ const timers = { set: (fn, ms) => setTimeout(fn, ms), clear: (id) => clearTimeout(id) }
737
+ const shown = document.documentElement.dataset.width || widthTier(window.innerWidth)
738
+ widthFollow = widthFollower(shown, widthTier, applyWidthTier, WIDTH_SETTLE_MS, timers)
739
+ }
740
+ widthFollow(width)
741
+ }
742
+ window.addEventListener('resize', () => followWidth(window.innerWidth))
711
743
  // Capture also sees the scroll of an inner scroller (a dialog, a list); the menu's own scroll is left alone.
712
744
  window.addEventListener('scroll', (e) => { if (menu.el && !menu.el.contains(e.target)) placeFloat() }, { passive: true, capture: true })
713
745
 
@@ -728,9 +760,24 @@ const MAIN = String.raw `
728
760
  return [
729
761
  a.modelInfo && a.modelInfo.settable ? { icon: 'terminal', label: t('menu.model'), run: () => openModel(a) } : null,
730
762
  family(a.family).tuning ? { icon: 'check', label: t('menu.tune'), run: () => openTune(a) } : null,
763
+ settingsItem(a),
731
764
  { icon: 'check', label: t('menu.check'), disabled: S.checking || S.fixing || Boolean(ui.checkingRef), run: () => checkAccount(a.ref) },
732
765
  ]
733
766
  }
767
+ // The directory's own Host settings file, opened in the user's editor (spec §3.30); it starts a program, so a
768
+ // read-only Panel has no such item.
769
+ function settingsItem(a) {
770
+ const file = family(a.family).settingsFile
771
+ if (!file || !a.dir || BOOT.readOnly) return null
772
+ return { icon: 'file', label: t('menu.editSettings', { file }), hint: a.dir + '/' + file, run: () => editSettings(a, file) }
773
+ }
774
+ async function editSettings(a, file) {
775
+ try {
776
+ const r = await api('/api/account/edit-settings', { account: a.ref })
777
+ toast(t('edit.opened', { ref: a.ref, file }))
778
+ if (r.sharedWith && r.sharedWith.length) toast(t('edit.shared', { names: r.sharedWith.map(refName).join(', ') }), { kind: 'info', duration: 8000 })
779
+ } catch (e) { toast(t('edit.failed', { ref: a.ref, file, msg: e.message }), { kind: 'fail' }) }
780
+ }
734
781
  // What the login does, whichever directory: the browser, signing in, the email, a new account like it.
735
782
  function loginItems(a) {
736
783
  return [
@@ -860,6 +907,9 @@ const MAIN = String.raw `
860
907
  for (const el of document.querySelectorAll('[data-i18n]')) el.textContent = t(el.getAttribute('data-i18n'))
861
908
  $('refresh').setAttribute('aria-label', t('top.refresh'))
862
909
  $('ask-ai').setAttribute('aria-label', t('ask.button'))
910
+ const repo = $('repo')
911
+ for (const k of ['aria-label', 'title']) repo.setAttribute(k, t('top.repo'))
912
+ if (/^https:\/\/github\.com\//.test(BOOT.repoUrl || '')) { repo.href = BOOT.repoUrl; repo.hidden = false }
863
913
  renderSettingsButton()
864
914
  }
865
915
  function applyTheme() {
@@ -963,7 +1013,7 @@ const MAIN = String.raw `
963
1013
  })
964
1014
  const display = h('button', { class: 'btn tb-display', type: 'button', 'aria-haspopup': 'dialog', 'aria-expanded': 'false', title: t('tb.display') }, icon('sliders'), h('span', null, t('tb.display')))
965
1015
  display.addEventListener('click', () => openPopover(display, 'display', t('tb.display'), displayPanel, 'end'))
966
- const create = BOOT.readOnly ? null : h('button', { class: 'btn btn-primary', type: 'button', 'aria-label': t('tb.new'), onclick: () => openCreate(null) }, icon('plus'), h('span', null, t('tb.new')))
1016
+ const create = BOOT.readOnly ? null : h('button', { class: 'btn btn-primary', type: 'button', 'aria-label': t('tb.new'), title: t('tb.new'), onclick: () => openCreate(null) }, icon('plus'), h('span', null, t('tb.new')))
967
1017
  setKids($('toolbar'), [
968
1018
  h('label', { class: 'search' }, icon('search', 'search-ic'), tb.search, h('kbd', { class: 'kbd', 'aria-hidden': 'true' }, '/')),
969
1019
  h('div', { class: 'tools' }, tb.family, tb.sort, display),
@@ -1081,7 +1131,9 @@ const MAIN = String.raw `
1081
1131
  const via = q.fetched ? t('quota.fetchedFrom', { host: famTitle(a), ago: ago(q.observedAt) }) : null
1082
1132
  const failed = q.fetchError ? t('quota.lastCheckFailed', { why: q.fetchError }) : null
1083
1133
  const title = [from || via || (stale ? null : t('quota.dataFrom', { ago: ago(q.observedAt) })), failed].filter(Boolean).join('\n') || null
1084
- return h('div', { class: 'quota' + (stale ? ' is-stale' : ''), title },
1134
+ // --qr: this row's own number of windows, so a narrow list can split the width between them alone (--qn is the
1135
+ // widest Family's, for the wide list's shared columns).
1136
+ return h('div', { class: 'quota' + (stale ? ' is-stale' : ''), title, css: wins.length ? { '--qr': String(cols.length) } : null },
1085
1137
  wins.length ? cols.map((c) => {
1086
1138
  const w = wins.find((x) => winKey(x) === c)
1087
1139
  return w ? meter(w, now, stale, q.observedAt) : noMeter(winTitle(c))
@@ -1104,9 +1156,14 @@ const MAIN = String.raw `
1104
1156
  h('div', { class: 'u-sub' }, rate === null ? tn('usage.sessions', u.sessions) : t('usage.cache', { n: Math.round(rate * 100) }))),
1105
1157
  u.totalTokens ? spark(u.daily) : null)
1106
1158
  }
1107
- function lastUsed(a) {
1159
+ function lastUsed(a, cls = 'last') {
1108
1160
  const at = a.usage && a.usage.status === 'ok' && a.usage.lastActivityAt
1109
- return h('div', { class: 'last', title: at ? t('last.title', { at: clock(at) }) : t('last.unknown') }, at ? ago(at) : h('span', { class: 'faint' }, '—'))
1161
+ return h('div', { class: cls, title: at ? t('last.title', { at: clock(at) }) : t('last.unknown') }, at ? ago(at) : h('span', { class: 'faint' }, '—'))
1162
+ }
1163
+ // The line under a row's name, with a copy of the last use at its end: the medium-width list shows that copy
1164
+ // instead of the column (the styles show one of the two), so the time stays next to the account it belongs to.
1165
+ function metaLine(line, a) {
1166
+ return h('div', { class: 'ident-meta' }, line, lastUsed(a, 'last-inline'))
1110
1167
  }
1111
1168
  function healthChip(a) {
1112
1169
  const hs = healthOf(a.ref)
@@ -1367,7 +1424,7 @@ const MAIN = String.raw `
1367
1424
  function foldClick(a) { return foldHit(() => toggleRow(a)) }
1368
1425
  function foldHit(run) {
1369
1426
  return (e) => {
1370
- if (e.target.closest('button, a, input, select, textarea, .tip')) return
1427
+ if (foldSkips(e.target)) return
1371
1428
  const dragged = downAt && Math.hypot(e.clientX - downAt.x, e.clientY - downAt.y) > 4
1372
1429
  if (dragged && window.getSelection && String(window.getSelection())) return
1373
1430
  run()
@@ -1479,7 +1536,7 @@ const MAIN = String.raw `
1479
1536
  const open = isOpen(a)
1480
1537
  const email = emailLine(a)
1481
1538
  return withMenu(h('div', { class: 'row fold-hit' + (open ? ' row-open' : '') + (a.error ? ' row-error' : ''), role: 'listitem', 'data-ref': a.ref, 'data-key': a.ref, 'data-sig': rowSig(a), onclick: foldClick(a) },
1482
- h('div', { class: 'ident' }, rowToggle(a), badge(a.family, 'sm'), h('div', { class: 'ident-text' }, nameLine(a), email || subLine(a))),
1539
+ h('div', { class: 'ident' }, rowToggle(a), badge(a.family, 'sm'), h('div', { class: 'ident-text' }, nameLine(a), metaLine(email || subLine(a), a))),
1483
1540
  quotaBlock(a, now, cols),
1484
1541
  lastUsed(a),
1485
1542
  h('div', { class: 'row-end' }, runButton(a), moreButton(a)),
@@ -1518,7 +1575,7 @@ const MAIN = String.raw `
1518
1575
  const open = isOpen(a)
1519
1576
  const email = emailLine(a)
1520
1577
  return withMenu(h('div', { class: 'row row-login fold-hit' + (open ? ' row-open' : '') + (a.error ? ' row-error' : ''), role: 'listitem', 'aria-label': t('login.label', { names: ms.map((m) => m.name).join(', ') }), 'data-ref': a.ref, 'data-key': loginKey(ms.map((m) => m.ref)), 'data-sig': sig(ms.map(rowSig)), onclick: foldClick(a) },
1521
- h('div', { class: 'ident' }, rowToggle(a), badge(a.family, 'sm'), h('div', { class: 'ident-text' }, nameLine(a, ms), email || subLine(a))),
1578
+ h('div', { class: 'ident' }, rowToggle(a), badge(a.family, 'sm'), h('div', { class: 'ident-text' }, nameLine(a, ms), metaLine(email || subLine(a), newestOf(ms)))),
1522
1579
  quotaBlock(a, now, cols),
1523
1580
  lastUsed(newestOf(ms)),
1524
1581
  h('div', { class: 'row-end' }, runButton(a), loginMoreButton(ms)),
@@ -1778,7 +1835,8 @@ const MAIN = String.raw `
1778
1835
  h('span', { class: 'muted small' }, t('quota.turnOnFamilyNote', { host: info.title })),
1779
1836
  h('button', { class: 'btn btn-sm', type: 'button', title: setup.summary, 'aria-label': t('quota.turnOnFamilyLabel', { host: info.title }), onclick: () => openSetup(fam) }, t('quota.turnOnFamily')))
1780
1837
  : null,
1781
- off && setup && setup.plan.status === 'blocked' ? h('span', { class: 'muted small label-tip' }, t('quota.blocked'), tipRaw(t('quota.blocked'), setup.plan.message)) : null))
1838
+ off && setup && setup.plan.status === 'blocked' ? h('span', { class: 'muted small label-tip' }, t('quota.blocked'), tipRaw(t('quota.blocked'), setup.plan.message)) : null,
1839
+ ui.arrange ? null : pickHead(fam)))
1782
1840
  const body = collapsedNow ? null : cards
1783
1841
  ? h('div', { class: 'grid', id: bodyId, 'data-key': 'cards', 'data-patch': '' }, list.map((a) => card(a, now, cols)))
1784
1842
  : h('div', { class: 'rows', id: bodyId, role: 'list', 'data-key': ui.arrange ? 'rows-arrange' : 'rows', 'data-patch': '' }, loginClusters(list).map((x) => Array.isArray(x) ? loginRow(x, now, cols) : row(x, now, cols)))
@@ -2813,6 +2871,7 @@ const MAIN = String.raw `
2813
2871
  r.hookErrors.map((e) => h('span', { class: 'small' }, 'plugin ' + e.plugin + ': ' + e.message))) : null,
2814
2872
  r.account.dir ? h('p', { class: 'small' }, h('span', { class: 'muted' }, t('nf.dir') + ' '), h('code', null, r.account.dir)) : null,
2815
2873
  r.alias && r.alias.added ? h('div', { class: 'small created-alias' }, h('span', { class: 'muted' }, t('nf.alias') + ' '), codeCopy(r.alias.name), h('span', { class: 'muted' }, ' ' + t('nf.aliasNewShell'))) : null,
2874
+ r.alias && r.alias.added ? shellSetupNote() : null,
2816
2875
  r.alias && !r.alias.added ? h('div', { class: 'note note-warn' }, h('b', null, t('nf.aliasNotAdded')), ' ', h('span', { class: 'small' }, r.alias.message || '')) : null,
2817
2876
  (r.shellInitFiles || []).map((f) => f.ok
2818
2877
  ? h('p', { class: 'muted small' }, t(f.action === 'unchanged' ? 'nf.shellFileSame' : 'nf.shellFileUpdated', { file: f.path }))
@@ -3515,7 +3574,9 @@ const MAIN = String.raw `
3515
3574
  const look = []
3516
3575
  if (secs.includes('lang')) look.push(seg(t('set.lang'), [['en', 'English'], ['zh', '中文']], lang, setLang))
3517
3576
  if (secs.includes('theme')) look.push(seg(t('set.theme'), CHOICES.theme.map((v) => [v, t('set.theme.' + v)]), viewPrefs().theme, setTheme))
3518
- const start = [autostartRow()]
3577
+ const start = [autostartRow('autostart')]
3578
+ // The menu bar switch shows only where it works (macOS); while its state loads it waits, unseen.
3579
+ if (li.menubar.status && li.menubar.status.supported) start.push(autostartRow('menubar'))
3519
3580
  if (!BOOT.readOnly) start.push(link(t('term.title'), '', '', openTerminals, true))
3520
3581
  const acct = []
3521
3582
  // The arrange mode (spec §3.25) has a place here too, where people look for "how do I change this".
@@ -3539,6 +3600,10 @@ const MAIN = String.raw `
3539
3600
  h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === c.on), onclick: () => { if (v !== c.on) { leave(false); setCheck(c.family, v) } } }, text)))))
3540
3601
  }
3541
3602
  }
3603
+ if (pickFamilies().length) {
3604
+ const names = Object.keys(S.state.pickCommands || {})
3605
+ acct.push(link(t('pk.title'), names.length ? names.join(', ') : t('pk.noneYet'), names.length ? 'chip-ok' : '', () => openPick(null), true))
3606
+ }
3542
3607
  if (secs.includes('rc')) {
3543
3608
  const sum = rcSummary()
3544
3609
  acct.push(link(t('rc.button'), t('rc.state.' + sum), sum === 'on' ? 'chip-warn' : sum === 'off' ? 'chip-ok' : '', openRc, true))
@@ -3569,7 +3634,7 @@ const MAIN = String.raw `
3569
3634
  }
3570
3635
  // Taller than the window, the popover scrolls inside and ends with "More settings…", the same groups in a dialog.
3571
3636
  function settingsPop() {
3572
- if (!as.status && !as.loading && !as.error) loadAutostart()
3637
+ loadAutostart()
3573
3638
  return [...settingsBody(() => closeMenu()),
3574
3639
  h('button', { class: 'menu-item set-more', type: 'button', hidden: true, onclick: () => { closeMenu(); openSettingsDialog() } }, h('span', { class: 'menu-label' }, t('set.more')), icon('chevron'))]
3575
3640
  }
@@ -3581,7 +3646,7 @@ const MAIN = String.raw `
3581
3646
  more.hidden = !(el.scrollHeight > el.clientHeight + 1)
3582
3647
  }
3583
3648
  function openSettingsDialog() {
3584
- if (!as.status && !as.loading) loadAutostart()
3649
+ loadAutostart()
3585
3650
  showDialog('settings')
3586
3651
  renderSettingsDialog()
3587
3652
  }
@@ -3595,85 +3660,105 @@ const MAIN = String.raw `
3595
3660
  if (dlg.kind === 'settings') renderSettingsDialog()
3596
3661
  }
3597
3662
 
3598
- // ---------- start at login (spec §3.29, ADR-0029) ----------
3599
- // The switch reads its state when the settings open; moving it shows the file and what will run, and only the
3600
- // confirmation writes. A read-only Panel shows the state only.
3601
- const as = { status: null, loading: false, error: null, want: null, plan: null, planning: false, planError: null, busy: false }
3602
- async function loadAutostart() {
3603
- as.loading = true
3604
- try { as.status = await api('/api/autostart'); as.error = null } catch (e) { as.error = e }
3605
- as.loading = false
3663
+ // ---------- start at login (spec §3.29, ADR-0029) and the Menu Bar Item (spec §3.31, ADR-0034) ----------
3664
+ // Each switch reads its state when the settings open; moving it shows the file and what will run, and only the
3665
+ // confirmation writes. A read-only Panel shows the state only. mb.* words override as.* for the menu bar.
3666
+ const liState = () => ({ status: null, loading: false, error: null, want: null, plan: null, planning: false, planError: null, busy: false })
3667
+ const li = { autostart: liState(), menubar: liState() }
3668
+ let liKind = 'autostart'
3669
+ function lt(k, key, vars) {
3670
+ const own = (k === 'menubar' ? 'mb.' : 'as.') + key
3671
+ return t(Object.hasOwn(MESSAGES.en, own) ? own : 'as.' + key, vars)
3672
+ }
3673
+ function loadAutostart() {
3674
+ // A failed read is not retried here: the settings re-render after every read, so a retry would loop.
3675
+ for (const k of Object.keys(li)) if (!li[k].status && !li[k].loading && !li[k].error) loadLoginItem(k)
3676
+ }
3677
+ async function loadLoginItem(k) {
3678
+ const st = li[k]
3679
+ st.loading = true
3680
+ try { st.status = await api('/api/' + k); st.error = null } catch (e) { st.error = e }
3681
+ st.loading = false
3606
3682
  refreshSettings()
3683
+ if (k === 'menubar') renderAll()
3607
3684
  }
3608
- function autostartRow() {
3609
- const s = as.status
3685
+ function autostartRow(k) {
3686
+ const st = li[k]
3687
+ const s = st.status
3610
3688
  const n = autostartNote(s, BOOT.readOnly)
3611
- const label = t('as.label')
3612
- const hint = [as.error ? t('as.failed', { msg: as.error.message }) : t(n.key)]
3613
- if (n.action === 'fix') hint.push(' ', h('button', { class: 'link-btn small', type: 'button', onclick: () => autostartAsk(true) }, t('as.fix')))
3614
- if (s && s.state === 'foreign') hint.push(' ', h('button', { class: 'link-btn small', type: 'button', title: s.path, onclick: () => copyText(s.path) }, t('as.copyPath')))
3689
+ const label = lt(k, 'label')
3690
+ const hint = [st.error ? lt(k, 'failed', { msg: st.error.message }) : lt(k, n.key.slice(3))]
3691
+ if (n.action === 'fix') hint.push(' ', h('button', { class: 'link-btn small', type: 'button', onclick: () => autostartAsk(true, k) }, lt(k, 'fix')))
3692
+ if (s && s.state === 'foreign') hint.push(' ', h('button', { class: 'link-btn small', type: 'button', title: s.path, onclick: () => copyText(s.path) }, lt(k, 'copyPath')))
3615
3693
  let ctl = null
3616
- if (!s) ctl = as.loading ? spinner() : null
3694
+ if (!s) ctl = st.loading ? spinner() : null
3617
3695
  else if (n.toggle) ctl = h('div', { class: 'seg', role: 'group', 'aria-label': label }, [[true, t('ah.on')], [false, t('ah.off')]].map(([v, text]) =>
3618
- h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === n.on), onclick: () => { if (v !== n.on) autostartAsk(v) } }, text)))
3696
+ h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === n.on), onclick: () => { if (v !== n.on) autostartAsk(v, k) } }, text)))
3619
3697
  else if (s.supported && s.state !== 'foreign') ctl = h('span', { class: 'chip chip-sm' + (n.on ? ' chip-ok' : '') }, n.on ? t('ah.on') : t('ah.off'))
3620
3698
  return h('div', { class: 'set-row set-check' },
3621
3699
  h('div', { class: 'set-text' }, h('span', { class: 'set-label' }, label), h('span', { class: 'set-hint' }, hint)), ctl)
3622
3700
  }
3623
- async function autostartAsk(on) {
3701
+ async function autostartAsk(on, k) {
3624
3702
  if (menu.kind === 'settings') closeMenu()
3625
- as.want = on
3626
- as.plan = null
3627
- as.planError = null
3628
- as.planning = true
3703
+ liKind = k
3704
+ const st = li[k]
3705
+ st.want = on
3706
+ st.plan = null
3707
+ st.planError = null
3708
+ st.planning = true
3629
3709
  showDialog('autostart')
3630
3710
  renderAutostart()
3631
- try { as.plan = (await api('/api/autostart', { on })).plan } catch (e) { as.planError = e }
3632
- as.planning = false
3633
- if (dlg.kind === 'autostart') renderAutostart()
3711
+ try { st.plan = (await api('/api/' + k, { on })).plan } catch (e) { st.planError = e }
3712
+ st.planning = false
3713
+ if (dlg.kind === 'autostart' && liKind === k) renderAutostart()
3634
3714
  }
3635
3715
  function renderAutostart() {
3636
- const p = as.plan
3637
- const on = as.want
3716
+ const k = liKind
3717
+ const st = li[k]
3718
+ const p = st.plan
3719
+ const on = st.want
3638
3720
  const body = []
3639
- if (as.planning) body.push(h('p', { class: 'muted' }, spinner(), ' ', t('as.planning')))
3640
- else if (as.planError) body.push(errorNote(as.planError, () => autostartAsk(on)))
3721
+ if (st.planning) body.push(h('p', { class: 'muted' }, spinner(), ' ', lt(k, 'planning')))
3722
+ else if (st.planError) body.push(errorNote(st.planError, () => autostartAsk(on, k)))
3641
3723
  else if (p && p.blocked) {
3642
3724
  const own = 'as.block.' + p.blocked.code
3643
3725
  body.push(h('p', { class: 'note note-fail' }, Object.hasOwn(MESSAGES.en, own) ? t(own) : p.blocked.message))
3644
3726
  if (['npx-cache', 'temp-dir', 'unsafe-path'].includes(p.blocked.code)) body.push(codeCopy('npm i -g sideby'))
3645
3727
  if (p.blocked.code === 'foreign') body.push(codeCopy(p.path))
3646
- } else if (p && !p.changed) body.push(h('p', null, t(on ? 'as.alreadyOn' : 'as.alreadyOff')))
3728
+ } else if (p && !p.changed) body.push(h('p', null, lt(k, on ? 'alreadyOn' : 'alreadyOff')))
3647
3729
  else if (p && on) {
3648
- body.push(h('p', null, t('as.writes')), h('code', { class: 'as-code' }, p.path))
3649
- body.push(h('p', null, t('as.runs')), h('code', { class: 'as-code' }, (p.programArguments || []).join(' ')))
3650
- body.push(h('p', { class: 'muted small' }, t('as.noWindow')))
3730
+ body.push(h('p', null, lt(k, 'writes')), h('code', { class: 'as-code' }, p.path))
3731
+ body.push(h('p', null, lt(k, 'runs')), h('code', { class: 'as-code' }, (p.programArguments || []).join(' ')))
3732
+ body.push(h('p', { class: 'muted small' }, lt(k, 'noWindow')))
3651
3733
  } else if (p) {
3652
- body.push(h('p', null, t('as.removes')), h('code', { class: 'as-code' }, p.path))
3653
- body.push(h('p', { class: 'muted small' }, t('as.offNote')))
3734
+ body.push(h('p', null, lt(k, 'removes')), h('code', { class: 'as-code' }, p.path))
3735
+ body.push(h('p', { class: 'muted small' }, lt(k, 'offNote')))
3654
3736
  }
3655
- const foot = [h('button', { class: 'btn', type: 'button', disabled: as.busy, onclick: () => dlg.el.close() }, t(p && p.changed && !p.blocked ? 'btn.cancel' : 'btn.close'))]
3737
+ const foot = [h('button', { class: 'btn', type: 'button', disabled: st.busy, onclick: () => dlg.el.close() }, t(p && p.changed && !p.blocked ? 'btn.cancel' : 'btn.close'))]
3656
3738
  if (p && p.changed && !p.blocked)
3657
- foot.push(h('button', { class: 'btn btn-primary', type: 'button', disabled: as.busy, 'aria-busy': as.busy ? 'true' : null, onclick: autostartApply }, as.busy ? spinner() : null, t(on ? 'as.turnOn' : 'as.turnOff')))
3658
- setKids(dlg.el, dialogFrame(t(on ? 'as.onTitle' : 'as.offTitle'), null, body, foot))
3739
+ foot.push(h('button', { class: 'btn btn-primary', type: 'button', disabled: st.busy, 'aria-busy': st.busy ? 'true' : null, onclick: autostartApply }, st.busy ? spinner() : null, lt(k, on ? 'turnOn' : 'turnOff')))
3740
+ setKids(dlg.el, dialogFrame(lt(k, on ? 'onTitle' : 'offTitle'), null, body, foot))
3659
3741
  }
3660
3742
  async function autostartApply() {
3661
- const on = as.want
3662
- as.busy = true
3743
+ const k = liKind
3744
+ const st = li[k]
3745
+ const on = st.want
3746
+ st.busy = true
3663
3747
  dlg.busy = true
3664
3748
  renderAutostart()
3665
3749
  let r = null
3666
- try { r = await api('/api/autostart', { on, confirm: true, programArguments: as.plan.programArguments || [] }) } catch (e) { as.planError = e }
3667
- as.busy = false
3750
+ try { r = await api('/api/' + k, { on, confirm: true, programArguments: st.plan.programArguments || [] }) } catch (e) { st.planError = e }
3751
+ st.busy = false
3668
3752
  dlg.busy = false
3669
3753
  if (r && r.applied) {
3670
- as.status = r.status
3754
+ st.status = r.status
3671
3755
  if (dlg.kind === 'autostart') dlg.el.close()
3672
- toast(t(on ? 'as.doneOn' : 'as.doneOff') + (on && !r.loaded ? ' ' + t('as.nextLogin') : ''))
3756
+ toast(lt(k, on ? 'doneOn' : 'doneOff') + (on && !r.loaded ? ' ' + lt(k, 'nextLogin') : ''))
3673
3757
  refreshSettings()
3758
+ if (k === 'menubar') renderAll()
3674
3759
  return
3675
3760
  }
3676
- if (r) { as.plan = r.plan; if (r.changedSince) toast(t('as.changedSince')) }
3761
+ if (r) { st.plan = r.plan; if (r.changedSince) toast(lt(k, 'changedSince')) }
3677
3762
  if (dlg.kind === 'autostart') renderAutostart()
3678
3763
  }
3679
3764
  function setLang(v) {
@@ -3715,6 +3800,7 @@ const MAIN = String.raw `
3715
3800
  else if (dlg.kind === 'key' && ky && ky.step !== 'enter') renderKey()
3716
3801
  else if (dlg.kind === 'terminal' && tm) renderTerminals()
3717
3802
  else if (dlg.kind === 'autostart') renderAutostart()
3803
+ else if (dlg.kind === 'pick' && pk) renderPick()
3718
3804
  }
3719
3805
  function setTheme(v) {
3720
3806
  if (CFG) { cfgPanel.theme = v; saveCfg({ theme: v }) } else { prefs.theme = v; savePrefs() }
@@ -3727,7 +3813,7 @@ const MAIN = String.raw `
3727
3813
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
3728
3814
  }
3729
3815
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
3730
- const AI_ASKS = ['ai.ask.quota', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.rc', 'ai.ask.tool']
3816
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.tool']
3731
3817
  function openRc() {
3732
3818
  if (!S.state || !rcSummary()) return
3733
3819
  rc.target = null
@@ -3767,7 +3853,7 @@ const MAIN = String.raw `
3767
3853
  // One dialog for every "let AI do it" entry: what to do, then the account and the terminal it will use, then one
3768
3854
  // button. When nothing can run it, or the panel is read-only, it copies the prompt instead.
3769
3855
  let ak = null
3770
- const TERM_NAMES = { terminal: 'Terminal', iterm2: 'iTerm2', ghostty: 'Ghostty', orca: 'Orca', wezterm: 'WezTerm', kitty: 'kitty', alacritty: 'Alacritty', custom: 'Custom' }
3856
+ const TERM_NAMES = { terminal: 'Terminal', iterm2: 'iTerm2', ghostty: 'Ghostty', orca: 'Orca', wezterm: 'WezTerm', kitty: 'kitty', alacritty: 'Alacritty', 'windows-terminal': 'Windows Terminal', custom: 'Custom' }
3771
3857
  function termName(id) {
3772
3858
  const list = ak && ak.terms ? ak.terms.terminals : []
3773
3859
  const f = list.find((x) => x.id === id)
@@ -3787,6 +3873,8 @@ const MAIN = String.raw `
3787
3873
  function openAsk(opts) {
3788
3874
  opts = opts || {}
3789
3875
  closeMenu()
3876
+ // In a Portal that offers AI Tasks itself (createPanelHandler's ask bridge), the task goes to its dialog.
3877
+ if (askBridge(BOOT, opts, window)) return
3790
3878
  ak = { task: opts.task || 'free', text: opts.text || '', context: opts.context || null, account: null, accountChanged: false, terminal: null, terminalChanged: false, pick: null, reason: null, terms: null, loading: true, busy: false, result: null, error: null, removed: false, files: [], els: {} }
3791
3879
  showDialog('ask')
3792
3880
  hookAskDrops()
@@ -4024,7 +4112,12 @@ const MAIN = String.raw `
4024
4112
  rows.push(h('label', { class: 'field', for: 'ak-term' }, h('span', null, t('ask.terminal')), sel))
4025
4113
  }
4026
4114
  if (rows.length) out.push(h('div', { class: 'ask-pick' }, rows))
4027
- if (ak.account) out.push(h('p', { class: 'small' }, t('ask.confirm', { terminal: termName(ak.terminal || 'terminal'), ref: ak.account })))
4115
+ if (ak.account) {
4116
+ // Families whose AI Tasks start with permission checks on (ADR-0031) say so after the confirm line.
4117
+ const acct = S.state && S.state.accounts.find((x) => x.ref === ak.account)
4118
+ const safe = acct && family(acct.family).aiTaskSafe
4119
+ out.push(h('p', { class: 'small' }, t('ask.confirm', { terminal: termName(ak.terminal || 'terminal'), ref: ak.account }) + (safe ? ' ' + t('ask.safe') : '')))
4120
+ }
4028
4121
  return out
4029
4122
  }
4030
4123
  function askResult() {
@@ -4281,7 +4374,193 @@ const MAIN = String.raw `
4281
4374
  setKids(dlg.el, dialogFrame(t('term.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
4282
4375
  }
4283
4376
 
4377
+ // ---------- pick commands (spec §3.13, ADR-0035) ----------
4378
+ // A short command per tool that starts, each time, the account with the most quota left. The dialog lists every
4379
+ // tool that has one or could have one; adding shows what the name would hide in the shell before it writes.
4380
+ let pk = null
4381
+ function pickOf(fam) { const e = Object.entries(S.state.pickCommands || {}).find(([, f]) => f === fam); return e ? e[0] : null }
4382
+ function pickFamilies() { return S.state.families.map((f) => f.id).filter((id) => pickOf(id) || (S.state.pickOffers || {})[id]) }
4383
+ function openPick(fam) {
4384
+ closeMenu()
4385
+ pk = { focus: fam || null, busy: false, drafts: {}, confirm: {}, renaming: {}, error: null }
4386
+ showDialog('pick')
4387
+ renderPick()
4388
+ const input = fam && document.getElementById('pk-name-' + fam)
4389
+ if (input) input.focus()
4390
+ }
4391
+ async function startPick(name) {
4392
+ if (BOOT.readOnly) { copyText(name, name); return }
4393
+ try {
4394
+ const r = await api('/api/pick/start', { name })
4395
+ const why = r.reason === 'most-room' ? t('pk.why.room', { n: String(r.pressure) }) : t(r.reason === 'others-full' ? 'pk.why.othersFull' : 'pk.why.noData')
4396
+ if (r.opened) { toast(t('pk.started', { terminal: TERM_NAMES[r.terminal] || r.terminal, ref: r.picked, why })); return }
4397
+ await copyText(name, name)
4398
+ toast(r.automation ? t('login.automation', { terminal: TERM_NAMES[r.terminal] || r.terminal }) : t('login.failed'), { kind: 'info' })
4399
+ } catch (e) { toast(e.message, { kind: 'fail' }) }
4400
+ }
4401
+ // The dialog is the preview: a name that hides nothing is added at once; one that hides a command on PATH shows
4402
+ // that first and needs a second click. A rename adds the new name, then removes the old one.
4403
+ async function pickAdd(fam, name, shown, replaces) {
4404
+ pk.busy = true
4405
+ pk.error = null
4406
+ renderPick()
4407
+ try {
4408
+ let r = await api('/api/pick/add', { name, family: fam, confirm: Boolean(shown) })
4409
+ if (r.status === 'confirm' && !r.shadows) r = await api('/api/pick/add', { name, family: fam, confirm: true })
4410
+ if (r.status === 'confirm') pk.confirm[fam] = { name, shadows: r.shadows }
4411
+ else {
4412
+ const old = replaces && replaces !== name ? await api('/api/pick/remove', { name: replaces }) : null
4413
+ delete pk.renaming[fam]
4414
+ delete pk.drafts[fam]
4415
+ const later = S.state.shellSetup && !S.state.shellSetup.loaded
4416
+ pickToast([r, old], t((old ? 'pk.renamed' : 'pk.added') + (later ? 'Setup' : ''), { name, old: replaces }))
4417
+ await load({ silent: true })
4418
+ }
4419
+ } catch (e) { pk.error = e }
4420
+ if (!pk) return
4421
+ pk.busy = false
4422
+ if (dlg.kind === 'pick') renderPick()
4423
+ }
4424
+ async function pickRemove(name) {
4425
+ pk.busy = true
4426
+ pk.error = null
4427
+ renderPick()
4428
+ try {
4429
+ pickToast([await api('/api/pick/remove', { name })], t('pk.removed', { name }))
4430
+ await load({ silent: true })
4431
+ } catch (e) { pk.error = e }
4432
+ if (!pk) return
4433
+ pk.busy = false
4434
+ if (dlg.kind === 'pick') renderPick()
4435
+ }
4436
+ // The config is written first; a shell-init file sideby could not rewrite is said, not hidden behind "added".
4437
+ function pickToast(results, done) {
4438
+ const failed = results.filter(Boolean).flatMap((r) => (r.shellInitFiles || []).filter((f) => !f.ok).map((f) => f.message))
4439
+ if (failed.length) toast(t('pk.fileFailed', { msg: failed.join('; ') }), { kind: 'fail', duration: 12000 })
4440
+ else toast(done)
4441
+ }
4442
+ // A name field with what it would hide and its button; typing updates them in place, so the caret stays put.
4443
+ function nameEditor(fam, info, initial, replaces) {
4444
+ const id = 'pk-name-' + fam
4445
+ const input = h('input', { id, type: 'text', class: 'mono', autocomplete: 'off', autocapitalize: 'none', spellcheck: 'false', maxlength: '64', placeholder: t('pk.namePh'), disabled: pk.busy, 'aria-describedby': id + '-hint' })
4446
+ input.value = pk.drafts[fam] !== undefined ? pk.drafts[fam] : initial || ''
4447
+ const offer = (S.state.pickOffers || {})[fam]
4448
+ const note = h('p', { class: 'note' })
4449
+ const go = h('button', { class: 'btn btn-sm btn-primary', type: 'button' })
4450
+ const shadowsOf = (n) => {
4451
+ const asked = pk.confirm[fam]
4452
+ return asked && asked.name === n ? asked.shadows : offer && n && n === offer.name ? offer.shadows : null
4453
+ }
4454
+ const sync = () => {
4455
+ const n = input.value.trim()
4456
+ const shadows = shadowsOf(n)
4457
+ note.hidden = !shadows
4458
+ note.textContent = shadows ? t('pk.shadows', { name: n, path: shadows, host: info.title }) : ''
4459
+ go.textContent = t(shadows ? 'pk.addAnyway' : replaces ? 'pk.save' : 'pk.add')
4460
+ go.disabled = pk.busy || !n || n === replaces
4461
+ }
4462
+ const add = () => { const n = input.value.trim(); if (n && n !== replaces) pickAdd(fam, n, shadowsOf(n), replaces) }
4463
+ input.addEventListener('input', () => { pk.drafts[fam] = input.value; sync() })
4464
+ input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); add() } })
4465
+ go.addEventListener('click', add)
4466
+ sync()
4467
+ return [
4468
+ h('label', { class: 'field', for: id }, h('span', null, t('pk.nameLabel', { host: info.title })), input),
4469
+ h('p', { class: 'field-hint', id: id + '-hint' }, t('pk.hint', { host: info.title })),
4470
+ note,
4471
+ h('div', { class: 'actions' }, go,
4472
+ replaces ? h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => { delete pk.renaming[fam]; delete pk.drafts[fam]; renderPick() } }, t('btn.cancel')) : null),
4473
+ ]
4474
+ }
4475
+ function renderPick() {
4476
+ if (!pk) return
4477
+ const body = [h('p', { class: 'muted small' }, t('pk.intro'))]
4478
+ const fams = pickFamilies()
4479
+ // Once a pick command exists, the line that makes terminals load it is the next step: first, not below the fold.
4480
+ const setupFirst = Object.keys(S.state.pickCommands || {}).length ? shellSetupNote() : null
4481
+ if (setupFirst) body.push(setupFirst)
4482
+ if (!fams.length) body.push(h('p', { class: 'note' }, t('pk.none')))
4483
+ for (const fam of fams) {
4484
+ const info = family(fam)
4485
+ const name = pickOf(fam)
4486
+ const head = h('div', { class: 'title-logo' }, badge(fam, 'sm'), h('b', null, info.title))
4487
+ if (name && pk.renaming[fam] && !BOOT.readOnly) {
4488
+ body.push(h('div', { class: 'pk-row' }, head, nameEditor(fam, info, name, name)))
4489
+ continue
4490
+ }
4491
+ if (name) {
4492
+ body.push(h('div', { class: 'pk-row' }, head,
4493
+ h('p', { class: 'small' }, h('code', { class: 'mono' }, name), ' ', t('pk.exists', { host: info.title })),
4494
+ h('div', { class: 'actions' },
4495
+ h('button', { class: 'btn btn-sm', type: 'button', disabled: pk.busy, onclick: () => startPick(name) }, icon('terminal'), t('pk.start')),
4496
+ BOOT.readOnly ? null : h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => { pk.renaming[fam] = true; renderPick(); const el = document.getElementById('pk-name-' + fam); if (el) el.focus() } }, t('pk.rename')),
4497
+ BOOT.readOnly ? null : h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => pickRemove(name) }, t('pk.remove')))))
4498
+ continue
4499
+ }
4500
+ if (BOOT.readOnly) continue
4501
+ body.push(h('div', { class: 'pk-row' }, head, nameEditor(fam, info, S.state.pickOffers[fam].name, null)))
4502
+ }
4503
+ if (fams.length && !setupFirst) body.push(shellSetupNote() || h('p', { class: 'muted small' }, t('pk.newShell')))
4504
+ if (pk.error) body.push(errorNote(pk.error, null))
4505
+ setKids(dlg.el, dialogFrame(t('pk.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
4506
+ }
4507
+ // New terminals load short commands only through one line in the shell's rc file (ADR-0036). Where a short command
4508
+ // is added and that line is missing, say so and offer to add it: the line and the file shown are the preview.
4509
+ let ssBusy = false
4510
+ async function shellSetup(undo) {
4511
+ if (ssBusy) return
4512
+ ssBusy = true
4513
+ renderShellSetupHosts()
4514
+ try {
4515
+ const r = await api('/api/shell-init/setup', undo ? { undo: true } : {})
4516
+ if (r.status === 'added') toast(t('ss.added', { rc: r.rc }), { action: { label: t('ss.undo'), run: () => shellSetup(true) } })
4517
+ else if (r.status === 'removed') toast(t('ss.removed', { rc: r.rc }))
4518
+ await load({ silent: true })
4519
+ } catch (e) { toast(e.message, { kind: 'fail' }) }
4520
+ ssBusy = false
4521
+ renderShellSetupHosts()
4522
+ }
4523
+ function renderShellSetupHosts() {
4524
+ if (dlg.kind === 'pick' && pk) renderPick()
4525
+ else if (dlg.kind === 'create' && nf && nf.result) renderCreate()
4526
+ }
4527
+ function shellSetupNote() {
4528
+ const ss = S.state.shellSetup
4529
+ if (!ss || ss.loaded || BOOT.readOnly) return null
4530
+ const line = ss.block.split('\n').find((l) => l.startsWith('eval '))
4531
+ return h('div', { class: 'note note-warn ss-note', role: 'status' },
4532
+ h('div', { class: 'note-line' }, h('b', null, t('ss.title')), ' ', t('ss.body', { rc: ss.rc })),
4533
+ h('code', { class: 'mono note-line' }, line),
4534
+ h('button', { class: 'btn btn-sm btn-primary', type: 'button', disabled: ssBusy, onclick: () => shellSetup(false) }, ssBusy ? t('ss.adding') : t('ss.add')))
4535
+ }
4536
+ // In a tool's group head: the button that starts the account with the most room, or the offer to add one.
4537
+ function pickHead(fam) {
4538
+ const name = pickOf(fam)
4539
+ // On a narrow screen only the icon and the name stay; the words are in the hover text and the label.
4540
+ if (name) return h('button', { class: 'btn btn-sm', type: 'button', title: t('pk.startTip', { name, host: family(fam).title }), 'aria-label': t('pk.startTip', { name, host: family(fam).title }), onclick: () => startPick(name) }, icon('terminal'), h('span', { class: 'hide-sm' }, t('pk.start') + ' '), h('code', { class: 'mono' }, name))
4541
+ const offer = (S.state.pickOffers || {})[fam]
4542
+ if (!offer || BOOT.readOnly) return null
4543
+ return h('button', { class: 'link-btn small', type: 'button', onclick: () => openPick(fam) }, offer.name ? [t('pk.offerShort', { name: offer.name }), h('span', { class: 'hide-sm' }, t('pk.offerMore'))] : t('pk.offerNoName'))
4544
+ }
4545
+
4284
4546
  // ---------- banners ----------
4547
+ // Offered once on macOS (spec §3.31), when quota shows and the menu bar item is off; "No thanks" is for good.
4548
+ function menubarHint() {
4549
+ if (BOOT.readOnly || prefs.mbHintDone) return null
4550
+ const st = li.menubar
4551
+ if (!st.status) {
4552
+ if (!st.loading && !st.error) loadLoginItem('menubar')
4553
+ return null
4554
+ }
4555
+ if (!st.status.supported || st.status.state !== 'off') return null
4556
+ if (!S.state.accounts.some((a) => a.quota && a.quota.status === 'ok')) return null
4557
+ const done = () => { prefs.mbHintDone = true; savePrefs(); renderBanners() }
4558
+ return h('div', { class: 'banner', role: 'status' },
4559
+ h('div', null, h('b', null, t('mb.hintTitle') + ' '), t('mb.hintBody')),
4560
+ h('div', { class: 'banner-actions' },
4561
+ h('button', { class: 'btn btn-sm btn-primary', type: 'button', onclick: () => { done(); autostartAsk(true, 'menubar') } }, t('mb.hintYes')),
4562
+ h('button', { class: 'btn btn-sm', type: 'button', onclick: done }, t('mb.hintNo'))))
4563
+ }
4285
4564
  function renderBanners() {
4286
4565
  const out = []
4287
4566
  if (S.loadError && S.state) out.push(h('div', { class: 'banner banner-fail', role: 'alert' },
@@ -4295,6 +4574,10 @@ const MAIN = String.raw `
4295
4574
  h('div', { class: 'banner-actions' },
4296
4575
  h('button', { class: 'btn btn-sm btn-primary', type: 'button', onclick: () => setPage('handoff') }, t('ah.setUp')),
4297
4576
  h('button', { class: 'btn btn-sm', type: 'button', onclick: () => { prefs.ahHintAt = Date.now(); savePrefs(); renderBanners() } }, t('ah.dismiss')))))
4577
+ else {
4578
+ const mb = menubarHint()
4579
+ if (mb) out.push(mb)
4580
+ }
4298
4581
  const rcBanner = remoteControlBanner()
4299
4582
  if (rcBanner) out.push(rcBanner)
4300
4583
  const errs = S.state.pluginErrors
@@ -4427,7 +4710,7 @@ const MAIN = String.raw `
4427
4710
  }
4428
4711
  function openUpdate() {
4429
4712
  if (!BOOT.updates) return
4430
- up = { busy: false, error: null, done: null, changed: false, skillDone: false, skillChanged: false, autoPlan: null, autoBusy: false, waitUntil: 0, checking: false, checked: false }
4713
+ up = { busy: false, error: null, done: null, confirming: null, unknown: null, changed: false, skillDone: false, skillChanged: false, autoPlan: null, autoBusy: false, waitUntil: 0, checking: false, checked: false }
4431
4714
  showDialog('update')
4432
4715
  renderUpdate()
4433
4716
  }
@@ -4437,24 +4720,36 @@ const MAIN = String.raw `
4437
4720
  up.busy = true
4438
4721
  dlg.busy = true
4439
4722
  up.error = null
4723
+ up.unknown = null
4440
4724
  renderUpdate()
4441
- try {
4442
- const r = await api('/api/update', { confirm: true, version: u.latest })
4443
- if (!r.updated) {
4444
- // The registry names another version than the dialog showed: show the new plan and let the person look again.
4445
- Object.assign(S.state.update, { latest: r.latest, available: r.available, command: r.command, canRun: r.canRun, releaseNotes: r.releaseNotes, method: r.method })
4446
- up.changed = true
4447
- } else {
4448
- up.done = r
4725
+ const target = u.latest
4726
+ const free = () => { up.busy = false; dlg.busy = false }
4727
+ await codeSwap({
4728
+ send: () => api('/api/update', { confirm: true, version: target }),
4729
+ landed: () => { const now = updState(); return now ? now.current === target : null },
4730
+ // The answer was cut: say only that it is being confirmed, never "updated", until the state shows it.
4731
+ confirming: () => { free(); up.confirming = target; renderUpdate() },
4732
+ done: (r) => {
4733
+ free()
4734
+ up.confirming = null
4735
+ if (r && !r.updated) {
4736
+ // The registry names another version than the dialog showed: show the new plan and let the person look again.
4737
+ Object.assign(S.state.update, { latest: r.latest, available: r.available, command: r.command, canRun: r.canRun, releaseNotes: r.releaseNotes, method: r.method })
4738
+ up.changed = true
4739
+ renderUpdate()
4740
+ return false
4741
+ }
4742
+ up.done = r || { updated: true, latest: target }
4449
4743
  up.waitUntil = Date.now() + 20000
4450
- updWait()
4451
- }
4452
- } catch (e) { up.error = e }
4453
- up.busy = false
4454
- dlg.busy = false
4455
- renderUpdate()
4744
+ renderUpdate()
4745
+ return true
4746
+ },
4747
+ stuck: () => { up.waitUntil = 0; renderUpdate() },
4748
+ fail: (e) => { free(); up.confirming = null; up.error = e; renderUpdate() },
4749
+ unknown: () => { free(); up.confirming = null; up.unknown = target; renderUpdate() },
4750
+ })
4456
4751
  }
4457
- // The CLI is current and the skill is behind: update the skill alone, as sideby update --yes does.
4752
+ // The CLI is current and the skill is behind: update the skill alone, as sideby update --skill --yes does.
4458
4753
  async function updSkillRun() {
4459
4754
  up.busy = true
4460
4755
  dlg.busy = true
@@ -4526,7 +4821,7 @@ const MAIN = String.raw `
4526
4821
  }
4527
4822
  // The switch between a Local Build and the npm package (ADR-0024), only where the state offers it: the other side,
4528
4823
  // one button. After the switch the page waits for the server to run the new build and reloads into it.
4529
- const vs = { busy: false, to: null, waitUntil: 0, stuck: false, error: null }
4824
+ const vs = { busy: false, to: null, stuck: false, unknown: false, error: null }
4530
4825
  function localSwitchKids(u) {
4531
4826
  const ls = u && u.localSwitch
4532
4827
  if (!ls || BOOT.readOnly) return null
@@ -4536,8 +4831,8 @@ const MAIN = String.raw `
4536
4831
  const l = ls.local
4537
4832
  const build = l ? l.version + '-dev · ' + (l.commit || '?') + (l.dirty ? '+' : '') : ''
4538
4833
  const kids = [h('p', { class: 'muted small' }, toNpm ? t('loc.toNpmHint') : t('loc.toLocalHint', { b: build, at: l.builtAt ? clock(l.builtAt) : '' }))]
4539
- if (vs.stuck) {
4540
- kids.push(h('p', { class: 'small' }, t('loc.stuck')))
4834
+ if (vs.stuck || vs.unknown) {
4835
+ kids.push(h('p', { class: 'small' }, t(vs.stuck ? 'loc.stuck' : 'loc.unconfirmed')))
4541
4836
  kids.push(h('div', { class: 'popover-actions' }, h('button', { class: 'btn btn-sm btn-primary', type: 'button', onclick: () => location.reload() }, icon('refresh'), t('loc.reload'))))
4542
4837
  } else {
4543
4838
  const newer = toNpm && u.available && u.latest
@@ -4556,27 +4851,36 @@ const MAIN = String.raw `
4556
4851
  vs.to = to
4557
4852
  vs.error = null
4558
4853
  vs.stuck = false
4854
+ vs.unknown = false
4559
4855
  renderSwitch()
4560
- try {
4561
- await api('/api/local', { to, confirm: true })
4562
- } catch (e) {
4563
- // A background Panel restarting from the new code may drop this answer, and a Portal moving to it may answer
4564
- // 5xx (spec §3.23): the state then says whether the switch happened. Only a switch that did not is an error.
4565
- const kind = switchFailure(e)
4566
- if (kind === 'fail') { vs.busy = false; vs.error = e; renderSwitch(); return }
4567
- if (kind === 'check') {
4568
- await load({ silent: true })
4569
- const ls = updState() && updState().localSwitch
4570
- if (!ls || ls.running !== to) { vs.busy = false; vs.error = e; renderSwitch(); return }
4571
- }
4572
- }
4573
- vs.waitUntil = Date.now() + 20000
4574
- localWait()
4856
+ await codeSwap({
4857
+ send: () => api('/api/local', { to, confirm: true }),
4858
+ landed: () => { const now = updState(); return now && now.localSwitch ? now.localSwitch.running === to : null },
4859
+ confirming: () => {},
4860
+ done: () => true,
4861
+ stuck: () => { vs.busy = false; vs.stuck = true; renderSwitch() },
4862
+ fail: (e) => { vs.busy = false; vs.error = e; renderSwitch() },
4863
+ unknown: () => { vs.busy = false; vs.unknown = true; renderSwitch() },
4864
+ })
4575
4865
  }
4576
- function localWait() {
4577
- if (S.newBuild) { location.reload(); return }
4578
- if (Date.now() > vs.waitUntil) { vs.busy = false; vs.stuck = true; renderSwitch(); return }
4579
- setTimeout(() => { void load({ silent: true }).then(localWait, localWait) }, 1500)
4866
+ const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
4867
+ // Reads the state; true when this read answered (a cut connection or a load already running leaves the old state).
4868
+ async function readState() {
4869
+ const before = S.loadedAt
4870
+ try { await load({ silent: true }) } catch {}
4871
+ return S.loadedAt !== before
4872
+ }
4873
+ // A request that may swap the server's code (runCodeSwap): each wait is 20 s, read every 1.5 s.
4874
+ function codeSwap(o) {
4875
+ return runCodeSwap(Object.assign({
4876
+ readState,
4877
+ newBuild: () => !!S.newBuild,
4878
+ reload: () => location.reload(),
4879
+ now: () => Date.now(),
4880
+ pause,
4881
+ windowMs: 20000,
4882
+ pollMs: 1500,
4883
+ }, o))
4580
4884
  }
4581
4885
  async function verPopCheck() {
4582
4886
  vp.checking = true
@@ -4605,12 +4909,6 @@ const MAIN = String.raw `
4605
4909
  up.checking = false
4606
4910
  renderUpdate()
4607
4911
  }
4608
- // After an Update the server (or the Portal's worker) comes back with a new build; load() then reloads the page.
4609
- function updWait() {
4610
- if (!up || !up.done || S.newBuild) { if (S.newBuild) location.reload(); return }
4611
- if (Date.now() > up.waitUntil) { renderUpdate(); return }
4612
- setTimeout(() => { void load({ silent: true }).then(updWait) }, 1500)
4613
- }
4614
4912
  async function updAuto(on) {
4615
4913
  up.autoBusy = true
4616
4914
  up.error = null
@@ -4657,19 +4955,27 @@ const MAIN = String.raw `
4657
4955
  return
4658
4956
  }
4659
4957
  body.push(h('p', null, t('upd.current', { v: u.current })))
4660
- if (up.done) {
4958
+ // While an Update runs, is being confirmed or could not be, the dialog offers nothing else to start.
4959
+ const swapping = Boolean(up.done || up.confirming || up.unknown)
4960
+ if (up.confirming) {
4961
+ body.push(h('p', { class: 'muted small' }, spinner(), ' ', t('upd.confirming', { v: up.confirming })))
4962
+ } else if (up.unknown) {
4963
+ body.push(h('p', { class: 'note note-warn' }, t('upd.unconfirmed', { v: up.unknown })))
4964
+ } else if (up.done) {
4661
4965
  body.push(h('p', { class: 'note' }, t('upd.done', { v: up.done.latest })))
4662
4966
  body.push(h('p', { class: 'muted small' }, Date.now() > up.waitUntil ? t('upd.restartHint') : [spinner(), ' ', t('upd.reloading')]))
4663
4967
  if (up.done.skillUpdated) body.push(h('p', { class: 'small' }, t('upd.skillDone')))
4968
+ else if (up.done.skillSyncStarted) body.push(h('p', { class: 'muted small' }, t('upd.skillSyncing')))
4664
4969
  else body.push(...updSkill(u))
4665
4970
  } else if (up.skillDone && !skillOld(u)) {
4666
4971
  body.push(h('p', { class: 'note' }, t('upd.skillDoneOnly')))
4667
- } else if (u.available && isLocal(u) && (leavesLocal(u) || vs.busy || vs.stuck)) {
4972
+ } else if (u.available && isLocal(u) && (leavesLocal(u) || vs.busy || vs.stuck || vs.unknown)) {
4668
4973
  // A Local Build the Panel can leave (ADR-0024): switching to the release is the update, and brings the skill.
4669
4974
  body.push(h('p', null, t('upd.localSwitch', { v: u.latest }), ' ',
4670
4975
  h('a', { href: u.releaseNotes, target: '_blank', rel: 'noopener noreferrer' }, t('upd.notes'))))
4671
4976
  if (vs.busy) body.push(h('p', { class: 'muted small' }, spinner(), ' ', t('upd.reloading')))
4672
4977
  if (vs.stuck) body.push(h('p', { class: 'note' }, t('loc.stuck')))
4978
+ if (vs.unknown) body.push(h('p', { class: 'note note-warn' }, t('loc.unconfirmed')))
4673
4979
  if (vs.error) body.push(errorNote(vs.error, null))
4674
4980
  body.push(updManual([h('p', { class: 'small' }, t('upd.localManual')), codeCopy(u.command)]))
4675
4981
  } else if (u.available && isLocal(u)) {
@@ -4709,11 +5015,11 @@ const MAIN = String.raw `
4709
5015
  body.push(h('p', { class: 'muted small' }, t('upd.latest') + (u.checkedAt ? ' · ' + t('upd.checked', { ago: ago(u.checkedAt) }) : '')))
4710
5016
  } else body.push(h('p', { class: 'muted small' }, t('upd.notYet')))
4711
5017
  // A read-only Panel sends no request and writes nothing, so it cannot check (spec §3.23).
4712
- if (!BOOT.readOnly && !up.done && !u.available && !skillDue(u))
5018
+ if (!BOOT.readOnly && !swapping && !u.available && !skillDue(u))
4713
5019
  body.push(h('p', null, h('button', { class: 'btn btn-sm', type: 'button', disabled: up.checking || up.busy, 'aria-busy': up.checking ? 'true' : null, onclick: updCheck },
4714
5020
  up.checking ? spinner() : icon('refresh'), up.checking ? t('upd.checking') : t('upd.check'))))
4715
- if (!BOOT.readOnly && !up.done && isLocal(u)) body.push(h('p', { class: 'muted small' }, t('upd.autoLocal')))
4716
- else if (!BOOT.readOnly && !up.done) {
5021
+ if (!BOOT.readOnly && !swapping && isLocal(u)) body.push(h('p', { class: 'muted small' }, t('upd.autoLocal')))
5022
+ else if (!BOOT.readOnly && !swapping) {
4717
5023
  const box = h('input', { type: 'checkbox', disabled: up.autoBusy || !u.method.canUpdate })
4718
5024
  box.checked = up.autoPlan ? up.autoPlan.auto : u.auto
4719
5025
  box.addEventListener('change', () => updAuto(box.checked))
@@ -4726,12 +5032,12 @@ const MAIN = String.raw `
4726
5032
  if (up.error) body.push(errorNote(up.error, null))
4727
5033
  const foot = [h('button', { class: 'btn', type: 'button', disabled: up.busy, onclick: () => dlg.el.close() }, t('btn.close'))]
4728
5034
  const primary = (label, run) => h('button', { class: 'btn btn-primary', type: 'button', disabled: up.busy, 'aria-busy': up.busy ? 'true' : null, onclick: run }, up.busy ? spinner() : null, up.busy ? t('upd.updating') : label)
4729
- if (u.available && isLocal(u) && vs.stuck) foot.push(h('button', { class: 'btn btn-primary', type: 'button', onclick: () => location.reload() }, icon('refresh'), t('loc.reload')))
5035
+ if (up.unknown || (u.available && isLocal(u) && (vs.stuck || vs.unknown))) foot.push(h('button', { class: 'btn btn-primary', type: 'button', onclick: () => location.reload() }, icon('refresh'), t('loc.reload')))
4730
5036
  else if (u.available && isLocal(u) && (leavesLocal(u) || vs.busy))
4731
5037
  foot.push(h('button', { class: 'btn btn-primary', type: 'button', disabled: vs.busy, 'aria-busy': vs.busy ? 'true' : null, onclick: () => localSwitchTo('npm') },
4732
5038
  vs.busy ? spinner() : icon('swap'), vs.busy ? t('loc.switching') : t('loc.toNpmV', { v: u.latest })))
4733
- else if (u.available && u.canRun && !BOOT.readOnly && !up.done) foot.push(primary(t('upd.now', { v: u.latest }), updRun))
4734
- else if (skillDue(u) && !BOOT.readOnly && !up.done) foot.push(primary(t('upd.skillNow'), updSkillRun))
5039
+ else if (u.available && u.canRun && !BOOT.readOnly && !swapping) foot.push(primary(t('upd.now', { v: u.latest }), updRun))
5040
+ else if (skillDue(u) && !BOOT.readOnly && !swapping) foot.push(primary(t('upd.skillNow'), updSkillRun))
4735
5041
  setKids(dlg.el, dialogFrame(t('upd.title'), null, body, foot))
4736
5042
  }
4737
5043
 
@@ -4743,6 +5049,8 @@ const MAIN = String.raw `
4743
5049
  $('ver-top').addEventListener('click', () => openVerPop($('ver-top')))
4744
5050
  $('refresh').addEventListener('click', refreshAll)
4745
5051
  $('ask-ai').addEventListener('click', () => openAsk())
5052
+ // In a Portal that offers AI Tasks itself the Portal has the button; opened on its own, the Panel keeps it.
5053
+ $('ask-ai').hidden = askBridged(BOOT, window)
4746
5054
  $('accounts').addEventListener('dragover', onDragOver)
4747
5055
  $('accounts').addEventListener('drop', onDrop)
4748
5056
  // Escape leaves the arrange mode, as "Done" does, unless a menu or dialog takes it first.