sideby 0.35.0 → 0.35.2

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.
@@ -5,9 +5,13 @@ import { groupsToAccept } from '../core/inbound.js';
5
5
  import { quotaIsStale } from '../core/quota-levels.js';
6
6
  import { remoteControlTodo } from '../core/remote-control.js';
7
7
  import { catalogMatchLevel, catalogNorm, searchCatalog } from '../core/search-catalog.js';
8
- import { accountTitle, aiTaskAccounts, aliasArgsOf, aliasIssue, aliasPrefix, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, longWindow, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, messageToCheck, networkTaskFacts, newAccountDir, nextReset, orderedAliases, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaHighLevel, quotaPressure, radioStep, reloadForBuild, remoteControlSummary, reorder, resetWhen, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, sessionRowShape, shortCwd, shortSessionLabel, sortAccounts, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, uaDayRuns, uaGroupPending, uaOnChoices, uaParseClock, uaPickTime, uaSameSlot, uaShouldRead, uaSlotNight, uaStatusParts, uaStepClock, uaToggleDay, uaWaitingCount, uaWhen, updatedAge, vendorAlias, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
8
+ import { accountTitle, aiTaskAccounts, aliasArgsOf, aliasIssue, aliasPrefix, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, longWindow, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, messageToCheck, networkTaskFacts, newAccountDir, nextReset, orderedAliases, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, portalRefresh, quotaAskable, quotaHighLevel, quotaPressure, radioStep, reloadForBuild, remoteControlSummary, reorder, resetWhen, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, sessionRowShape, shortCwd, shortSessionLabel, sortAccounts, sortMenu, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, uaDayRuns, uaGroupPending, uaOnChoices, uaParseClock, uaPickTime, uaSameSlot, uaShouldRead, uaSlotNight, uaStatusParts, uaStepClock, uaToggleDay, uaWaitingCount, uaWhen, updatedAge, vendorAlias, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
9
+ // The component library's dropdown menu, copied by the brand repo's add script (--html into ui/); do not edit it.
10
+ import { CHECK, menuItem, menuScript } from './ui/dropdown-menu/dropdown-menu.html.js';
11
+ import { cn, esc } from './ui/lib/cn.js';
9
12
  const LOGIC = [
10
13
  quotaIsStale,
14
+ portalRefresh,
11
15
  catalogNorm,
12
16
  catalogMatchLevel,
13
17
  searchCatalog,
@@ -80,6 +84,7 @@ const LOGIC = [
80
84
  saveHandoffChange,
81
85
  enableOutcome,
82
86
  reorder,
87
+ sortMenu,
83
88
  rowBadge,
84
89
  sendBlock,
85
90
  sendFileProblem,
@@ -122,6 +127,13 @@ const LOGIC = [
122
127
  ]
123
128
  .map((fn) => fn.toString())
124
129
  .join('\n');
130
+ // The menu item markup of the component library, so the pickers (selectMenu) draw the same items as its other pages.
131
+ const MENU_LIB = [
132
+ `const CHECK = ${JSON.stringify(CHECK)}`,
133
+ `const esc = ${esc.toString()}`,
134
+ cn.toString(),
135
+ menuItem.toString(),
136
+ ].join('\n');
125
137
  const MAIN = String.raw `
126
138
  const BOOT = JSON.parse(document.getElementById('sideby-boot').textContent)
127
139
  const MESSAGES = JSON.parse(document.getElementById('sideby-i18n').textContent)
@@ -310,6 +322,91 @@ const MAIN = String.raw `
310
322
  if (Array.isArray(kid)) { for (const k of kid) add(el, k); return }
311
323
  el.append(kid instanceof Node ? kid : document.createTextNode(String(kid)))
312
324
  }
325
+ // A picker in place of a native select: a field-like button that opens the component library's single-choice menu
326
+ // (menuItem; menuScript moves focus with Up, Down, Home and End, and puts the checked item in view; Enter picks, Esc
327
+ // closes). It keeps the select interface the page uses: h('option') children (also through replaceChildren), .value,
328
+ // a 'change' event (or an onchange prop), hidden, disabled and focus(). id, data-key and aria-label go on the button,
329
+ // so a <label for> still names and opens it. Beyond a select: an h('optgroup', { label }) puts a heading over its
330
+ // options, an h('hr') a line between items, data-meta grey words at an option's end and data-button shorter or longer
331
+ // words on the button than in the menu. An option with data-action (and data-icon) is an action, not a choice: it
332
+ // never holds the check or changes .value, and fires an 'action' event (or the onaction prop) with its value. An
333
+ // option with data-placeholder ("Add account…") is not a choice either: its words show, greyed, on the button while
334
+ // nothing is picked (.value ''), and it is not in the menu, so nothing there is checked.
335
+ let selectSeq = 0
336
+ function selectMenu(props, ...kids) {
337
+ const p = Object.assign({}, props)
338
+ const id = 'select-menu-' + (++selectSeq)
339
+ const onchange = p.onchange
340
+ const onaction = p.onaction
341
+ delete p.onchange
342
+ delete p.onaction
343
+ const text = h('span', { class: 'select-text' })
344
+ const btn = h('button', Object.assign(p, { type: 'button', class: 'select-btn' + (p.class ? ' ' + p.class : ''), popovertarget: id, 'aria-haspopup': 'menu' }), text)
345
+ const list = h('div', { popover: 'auto', id, role: 'menu', class: 'ui-menu', 'aria-label': p['aria-label'] || null })
346
+ const wrap = h('span', { class: 'select-wrap' }, btn, list)
347
+ let opts = []
348
+ let cur = ''
349
+ let drawn = ''
350
+ let placeholder = ''
351
+ // Only the choices carry aria-checked: a heading, a line or an action never shows the check.
352
+ const mark = () => {
353
+ for (const it of list.querySelectorAll('[role="menuitemradio"]')) it.setAttribute('aria-checked', String(it.getAttribute('data-value') === cur))
354
+ const on = opts.find((o) => o.value === cur)
355
+ text.textContent = on ? on.button : placeholder
356
+ btn.classList.toggle('is-placeholder', !on && Boolean(placeholder))
357
+ }
358
+ const setOptions = (nodes) => {
359
+ opts = []
360
+ placeholder = ''
361
+ const parts = []
362
+ const walk = (n) => {
363
+ if (Array.isArray(n)) n.forEach(walk)
364
+ else if (!n || !n.tagName) return
365
+ else if (n.tagName === 'OPTGROUP') { parts.push('<div class="ui-menu-label" role="presentation">' + esc(n.label) + '</div>'); walk(Array.from(n.children)) }
366
+ else if (n.tagName === 'OPTION' && n.hasAttribute('data-placeholder')) placeholder = n.textContent
367
+ else if (n.tagName === 'HR') parts.push('<hr class="ui-menu-separator" role="separator">')
368
+ else if (n.tagName === 'OPTION' && n.hasAttribute('data-action')) {
369
+ const ic = n.getAttribute('data-icon')
370
+ parts.push(menuItem({ label: n.textContent, icon: ic ? icon(ic).outerHTML : undefined, attrs: 'data-action="' + esc(n.value) + '"' }, id))
371
+ } else if (n.tagName === 'OPTION') {
372
+ const o = { value: n.value, label: n.textContent, button: n.getAttribute('data-button') || n.textContent, selected: n.hasAttribute('selected') }
373
+ opts.push(o)
374
+ parts.push(menuItem({ label: o.label, meta: n.getAttribute('data-meta') || undefined, radio: true, checked: false, attrs: 'data-value="' + esc(o.value) + '"' }, id))
375
+ }
376
+ }
377
+ walk(nodes)
378
+ const pre = opts.find((o) => o.selected) || (placeholder ? null : opts[0])
379
+ cur = pre ? pre.value : ''
380
+ // Same items, same markup: the open menu keeps its elements (and its focus) when a refresh brings the same options.
381
+ const html = parts.join('')
382
+ if (html !== drawn) { list.innerHTML = html; drawn = html }
383
+ mark()
384
+ }
385
+ // As in a select, a value no option has selects nothing.
386
+ Object.defineProperty(wrap, 'value', { get: () => cur, set: (v) => { const s = String(v); cur = opts.some((o) => o.value === s) ? s : ''; mark() } })
387
+ Object.defineProperty(wrap, 'disabled', { get: () => btn.disabled, set: (v) => { btn.disabled = Boolean(v) } })
388
+ wrap.replaceChildren = (...nodes) => setOptions(nodes)
389
+ wrap.focus = (o) => btn.focus(o)
390
+ if (onchange) wrap.addEventListener('change', onchange)
391
+ if (onaction) wrap.addEventListener('action', onaction)
392
+ // Picking an item closes the menu (its popovertargetaction); a new value fires 'change' on the wrapper, as a select
393
+ // does. The click stops here: the library's own radio script would otherwise check the clicked item after a
394
+ // 'change' handler has set another value (2026-11-02: "Arrange order…" kept the check while the sort read "My order").
395
+ list.addEventListener('click', (e) => {
396
+ const act = e.target.closest('[data-action]')
397
+ if (act && !act.disabled) { wrap.dispatchEvent(new CustomEvent('action', { detail: act.getAttribute('data-action') })); return }
398
+ const it = e.target.closest('[role="menuitemradio"]')
399
+ if (!it || it.disabled) return
400
+ e.stopPropagation()
401
+ if (it.getAttribute('data-value') === cur) return
402
+ cur = it.getAttribute('data-value')
403
+ mark()
404
+ wrap.dispatchEvent(new Event('change', { bubbles: true }))
405
+ mark()
406
+ })
407
+ setOptions(kids)
408
+ return wrap
409
+ }
313
410
  function dots(parts) {
314
411
  const out = []
315
412
  for (const p of parts) {
@@ -1020,6 +1117,7 @@ const MAIN = String.raw `
1020
1117
  ]
1021
1118
  }
1022
1119
  // A Main-only Family (ADR-0047) has no other Account to create.
1120
+ function aliasItem(a) { return BOOT.readOnly ? null : { icon: 'terminal', label: t('menu.setAlias'), hint: (a.aliases || [])[0], run: () => openAlias(a) } }
1023
1121
  function likeItem(a) { return BOOT.readOnly || family(a.family).mainOnly ? null : { icon: 'userPlus', label: t('menu.like'), run: () => openCreate({ family: a.family, api: a.kind === 'api' }) } }
1024
1122
  // Grouped by what the user wants to do: open, copy, manage. A Same Login row (ADR-0026) passes its other
1025
1123
  // directories: the menu is the one of the directory the row is named after, and each other directory is one item
@@ -1042,7 +1140,7 @@ const MAIN = String.raw `
1042
1140
  const items = [pinItem(a), ...hideItems(a),
1043
1141
  opens.length ? '-' : null, opens.length ? { header: t('menu.groupOpen') } : null, ...opens,
1044
1142
  '-', { header: t('menu.groupCopy') }, run, ...(fold ? [fold] : more),
1045
- '-', { header: t('menu.groupManage') }, signInItem, key, ...dirTools(a), likeItem(a),
1143
+ '-', { header: t('menu.groupManage') }, signInItem, key, aliasItem(a), ...dirTools(a), likeItem(a),
1046
1144
  ...(dirs.length ? ['-', { header: t('menu.groupOtherDirs') }, ...dirs.map((d) => d.item)] : [])]
1047
1145
  back.sub = items
1048
1146
  for (const d of dirs) d.up.sub = items
@@ -1271,17 +1369,15 @@ const MAIN = String.raw `
1271
1369
  e.preventDefault()
1272
1370
  if (tb.search.value) { tb.search.value = ''; ui.query = ''; renderAccounts() } else tb.search.blur()
1273
1371
  })
1274
- tb.family = h('select', { class: 'tb-select', 'aria-label': t('tb.family') })
1372
+ tb.family = selectMenu({ class: 'tb-select', 'aria-label': t('tb.family') })
1275
1373
  tb.family.addEventListener('change', () => { prefs.family = tb.family.value; savePrefs(); renderAccounts() })
1276
- // "Arrange order…" is not a sort: it opens the arrange mode (spec §3.25), and the sort shows "my order".
1277
- tb.sort = h('select', { class: 'tb-select', 'aria-label': t('tb.sort') },
1278
- CHOICES.sort.map((v) => h('option', { value: v }, t('sort.' + v))),
1279
- BOOT.readOnly ? null : h('option', { value: 'arrange' }, t('sort.arrange')))
1280
- tb.sort.value = prefs.sort
1374
+ // "Arrange order and pins…" is an action under the sorts, not a sort: it opens the arrange mode (spec §3.25), and
1375
+ // the sort then reads "My order".
1376
+ tb.sort = selectMenu({ class: 'tb-select', 'aria-label': t('tb.sort'), onaction: startArrange }, sortOptions())
1281
1377
  tb.sort.addEventListener('change', () => {
1282
1378
  const v = tb.sort.value
1283
1379
  // "My order" before any order of one's own would show nothing new: it opens the arrange mode instead.
1284
- if (v === 'arrange' || (v === 'manual' && !ordered() && !BOOT.readOnly)) { startArrange(); return }
1380
+ if (v === 'manual' && !ordered() && !BOOT.readOnly) { startArrange(); return }
1285
1381
  if (ui.arrange) endArrange()
1286
1382
  prefs.sort = v
1287
1383
  savePrefs()
@@ -1298,6 +1394,14 @@ const MAIN = String.raw `
1298
1394
  renderFamilyFilter()
1299
1395
  if (hadFocus) tb.search.focus()
1300
1396
  }
1397
+ // The sort menu's items (page-logic.ts, sortMenu): redrawn with the list, so "Not set" follows the saved order.
1398
+ function sortOptions() {
1399
+ const items = sortMenu(CHOICES.sort, prefs.sort, ordered(), BOOT.readOnly)
1400
+ const choices = items.filter((e) => e.kind === 'choice').map((e) => h('option', { value: e.value, selected: e.checked ? '' : undefined, 'data-meta': e.meta ? t(e.meta) : undefined, 'data-button': t('sort.button', { choice: t(e.key) }) }, t(e.key)))
1401
+ const label = items.find((e) => e.kind === 'label')
1402
+ const action = items.find((e) => e.kind === 'action')
1403
+ return [h('optgroup', { label: t(label.key) }, choices)].concat(action ? [h('hr'), h('option', { value: action.value, 'data-action': '', 'data-icon': 'grip' }, t(action.key))] : [])
1404
+ }
1301
1405
  // "Display": the view settings people change rarely, one popover instead of three buttons in the toolbar.
1302
1406
  // "Hide emails" shows once any account has one.
1303
1407
  function displayPanel() {
@@ -2473,7 +2577,7 @@ const MAIN = String.raw `
2473
2577
  pinMark(a),
2474
2578
  h('span', { class: 'name', title: a.name }, a.name),
2475
2579
  loginMark(ms),
2476
- aliasText(a),
2580
+ aliasText(a, accountTitle(a).aliases),
2477
2581
  hiddenMark(hidden && !famHidden(fam))))),
2478
2582
  h('div', { class: 'arrange-tools' },
2479
2583
  // In a hidden Family the row keeps its eye, greyed, so the columns stay in line; the group's eye shows it again.
@@ -2627,6 +2731,7 @@ const MAIN = String.raw `
2627
2731
  }
2628
2732
  function renderAccounts() {
2629
2733
  closeMenu()
2734
+ if (tb.sort) tb.sort.replaceChildren(...sortOptions())
2630
2735
  const box = $('accounts')
2631
2736
  const count = $('acct-count')
2632
2737
  if (!S.state) {
@@ -2982,7 +3087,7 @@ const MAIN = String.raw `
2982
3087
  if (g.current && !g.outOfRange) sizes.add(g.current)
2983
3088
  const key = (v) => (v === null ? 'default' : String(v))
2984
3089
  const chosen = tuneSel[g.id] !== undefined ? tuneSel[g.id] : key(g.current)
2985
- const sel = h('select', { 'aria-label': t('tune.setting') },
3090
+ const sel = selectMenu({ 'aria-label': t('tune.setting') },
2986
3091
  h('option', { value: 'default' }, t('tune.hostDefaultLong')),
2987
3092
  [...sizes].sort((x, y) => x - y).map((v) => h('option', { value: String(v) }, tokens(v) + (pick && v === pick.threshold ? ' (' + t('tune.suggestedTag') + ')' : ''))))
2988
3093
  sel.value = chosen
@@ -3947,9 +4052,9 @@ const MAIN = String.raw `
3947
4052
  ev.preventDefault()
3948
4053
  if (e.q.value) { e.q.value = ''; clearTimeout(hs.debounce); hs.q = ''; historyChanged(false) } else e.q.blur()
3949
4054
  })
3950
- e.since = h('select', { class: 'tb-select' })
4055
+ e.since = selectMenu({ class: 'tb-select' })
3951
4056
  e.since.addEventListener('change', () => { hs.since = e.since.value; historyChanged(true) })
3952
- e.family = h('select', { class: 'tb-select' })
4057
+ e.family = selectMenu({ class: 'tb-select' })
3953
4058
  e.family.addEventListener('change', () => {
3954
4059
  hs.family = e.family.value
3955
4060
  // An Account of another AI would match nothing: it is dropped before the lists are asked for again.
@@ -3957,7 +4062,7 @@ const MAIN = String.raw `
3957
4062
  relabelHistory(e)
3958
4063
  historyChanged(true)
3959
4064
  })
3960
- e.account = h('select', { class: 'tb-select' })
4065
+ e.account = selectMenu({ class: 'tb-select' })
3961
4066
  e.account.addEventListener('change', () => { hs.account = e.account.value; historyChanged(true) })
3962
4067
  e.tools = h('input', { type: 'checkbox' })
3963
4068
  e.tools.addEventListener('change', () => {
@@ -5245,7 +5350,7 @@ const MAIN = String.raw `
5245
5350
  function ahFamily(fam) {
5246
5351
  const o = ah.form.orders[fam]
5247
5352
  const f = family(fam)
5248
- const policy = h('select', { 'aria-label': t('ah.order', { host: f.title }), disabled: BOOT.readOnly },
5353
+ const policy = selectMenu({ 'aria-label': t('ah.order', { host: f.title }), disabled: BOOT.readOnly },
5249
5354
  h('option', { value: 'pressure' }, t('ah.byQuota')), h('option', { value: 'order' }, t('ah.myOrder')))
5250
5355
  policy.value = o.policy
5251
5356
  policy.addEventListener('change', () => ahEdit((form) => { form.orders[fam].policy = policy.value }))
@@ -5261,7 +5366,7 @@ const MAIN = String.raw `
5261
5366
  const free = S.state.accounts.filter((a) => !taken.has(a.ref) && !(a.aliases || []).some((n) => taken.has(n)))
5262
5367
  if (!o.order.length) kids.push(h('p', { class: 'note note-warn' }, t('ah.emptyOrder')))
5263
5368
  if (free.length && !BOOT.readOnly) {
5264
- const pick = h('select', { 'aria-label': t('ah.add') }, h('option', { value: '' }, t('ah.add') + '…'), free.map((a) => h('option', { value: a.ref }, accountLabel(a.ref))))
5369
+ const pick = selectMenu({ 'aria-label': t('ah.add') }, h('option', { value: '', 'data-placeholder': '' }, t('ah.add') + '…'), free.map((a) => h('option', { value: a.ref }, accountLabel(a.ref))))
5265
5370
  pick.addEventListener('change', () => { if (pick.value) ahEdit((form) => { form.orders[fam].order.push(pick.value) }) })
5266
5371
  kids.push(h('div', { class: 'ah-add' }, pick))
5267
5372
  }
@@ -5411,7 +5516,7 @@ const MAIN = String.raw `
5411
5516
  const list = h('datalist', { id: 'md-models' }, mi.models.map((m) => h('option', { value: m })))
5412
5517
  const model = h('input', { type: 'text', list: 'md-models', autocomplete: 'off', spellcheck: 'false', placeholder: t('md.default') + ' (' + t('md.decides', { host }) + ')', disabled: BOOT.readOnly })
5413
5518
  model.value = mi.sideby.model || ''
5414
- const effort = h('select', { disabled: BOOT.readOnly }, h('option', { value: '' }, t('md.default') + ' (' + t('md.decides', { host }) + ')'), mi.efforts.map((e) => h('option', { value: e }, e)))
5519
+ const effort = selectMenu({ disabled: BOOT.readOnly }, h('option', { value: '' }, t('md.default') + ' (' + t('md.decides', { host }) + ')'), mi.efforts.map((e) => h('option', { value: e }, e)))
5415
5520
  effort.value = mi.sideby.effort || ''
5416
5521
  const changed = () => { md.preview = null; md.error = null; renderModel() }
5417
5522
  model.addEventListener('input', () => { if (md.preview) changed() })
@@ -7043,7 +7148,7 @@ const MAIN = String.raw `
7043
7148
  const opts = HOTKEY_PRESETS.map((k) => [k, hotkeyLabel(k) + (k === HOTKEY_PRESETS[0] ? t('hk.isDefault') : '')])
7044
7149
  if (v.enabled && HOTKEY_PRESETS.indexOf(v.keys) < 0) opts.unshift([v.keys, v.label])
7045
7150
  opts.push(['off', t('hk.offOption')], ['custom', t('hk.custom')])
7046
- return h('select', { class: 'hk-select', 'data-key': 'hk-select', 'aria-label': t('hk.label'), disabled: hk.busy,
7151
+ return selectMenu({ class: 'hk-select', 'data-key': 'hk-select', 'aria-label': t('hk.label'), disabled: hk.busy,
7047
7152
  onchange: (e) => {
7048
7153
  const val = e.target.value
7049
7154
  hk.error = ''
@@ -7233,6 +7338,7 @@ const MAIN = String.raw `
7233
7338
  else if (dlg.kind === 'setup' && qs) renderSetup()
7234
7339
  else if (dlg.kind === 'tune' && tuneState) renderTune()
7235
7340
  else if (dlg.kind === 'model' && md) { md.form = null; renderModel() }
7341
+ else if (dlg.kind === 'alias' && al) renderAlias()
7236
7342
  else if (dlg.kind === 'browser') renderBrowser()
7237
7343
  else if (dlg.kind === 'update' && up) renderUpdate()
7238
7344
  else if (dlg.kind === 'rc') renderRc()
@@ -7679,8 +7785,8 @@ const MAIN = String.raw `
7679
7785
  }
7680
7786
  const rows = []
7681
7787
  if (choices.length) {
7682
- const sel = h('select', { id: 'ak-account', 'aria-label': t('ask.account') },
7683
- ak.account ? null : h('option', { value: '' }, t('ask.chooseAccount')),
7788
+ const sel = selectMenu({ id: 'ak-account', 'aria-label': t('ask.account') },
7789
+ ak.account ? null : h('option', { value: '', 'data-placeholder': '' }, t('ask.chooseAccount')),
7684
7790
  choices.map((a) => h('option', { value: a.ref }, a.ref + (a.kind === 'api' ? ' · API' : ''))))
7685
7791
  sel.value = ak.account || ''
7686
7792
  sel.addEventListener('change', () => { ak.account = sel.value || null; ak.accountChanged = Boolean(sel.value); renderAsk() })
@@ -7688,7 +7794,7 @@ const MAIN = String.raw `
7688
7794
  }
7689
7795
  const installed = ak.terms ? ak.terms.installed : []
7690
7796
  if (installed.length && ak.account) {
7691
- const sel = h('select', { id: 'ak-term', 'aria-label': t('ask.terminal') }, installed.map((id) => h('option', { value: id }, termName(id))))
7797
+ const sel = selectMenu({ id: 'ak-term', 'aria-label': t('ask.terminal') }, installed.map((id) => h('option', { value: id }, termName(id))))
7692
7798
  sel.value = ak.terminal || installed[0]
7693
7799
  sel.addEventListener('change', () => { ak.terminal = sel.value; ak.terminalChanged = true; renderAsk() })
7694
7800
  rows.push(h('label', { class: 'field', for: 'ak-term' }, h('span', null, t('ask.terminal')), sel))
@@ -7930,7 +8036,7 @@ const MAIN = String.raw `
7930
8036
  const name = (id) => { const f = d.terminals.find((x) => x.id === id); return f ? f.name : id }
7931
8037
  if (!d.installed.length) body.push(h('p', { class: 'note' }, t('term.none')))
7932
8038
  else {
7933
- const sel = h('select', { id: 'tm-pick', disabled: tm.busy, 'aria-label': t('term.pick') },
8039
+ const sel = selectMenu({ id: 'tm-pick', disabled: tm.busy, 'aria-label': t('term.pick') },
7934
8040
  h('option', { value: '' }, t('term.auto')),
7935
8041
  d.installed.map((id) => h('option', { value: id }, name(id))))
7936
8042
  sel.value = d.preferred && d.installed.includes(d.preferred) ? d.preferred : ''
@@ -8228,6 +8334,98 @@ const MAIN = String.raw `
8228
8334
  if (pk.error) body.push(errorNote(pk.error, null))
8229
8335
  setKids(dlg.el, dialogFrame(t('pk.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
8230
8336
  }
8337
+ // Short commands of one Account (spec §3.13): add one, rename or remove it. A terminal that loads shell-init picks
8338
+ // the change up at its next prompt, so the page says that instead of "open a new terminal".
8339
+ let al = null
8340
+ function openAlias(a) {
8341
+ al = { ref: a.ref, family: a.family, editing: (a.aliases || []).length ? null : '', draft: null, busy: false, error: null }
8342
+ showDialog('alias')
8343
+ renderAlias()
8344
+ const el = document.getElementById('al-name')
8345
+ if (el) el.focus()
8346
+ }
8347
+ function alAccount() { return S.state && S.state.accounts.find((x) => x.ref === al.ref) }
8348
+ async function alSave(name, replaces) {
8349
+ al.busy = true
8350
+ al.error = null
8351
+ renderAlias()
8352
+ try {
8353
+ const r = await api('/api/alias/set', replaces ? { account: al.ref, name, replaces } : { account: al.ref, name })
8354
+ al.editing = null
8355
+ al.draft = null
8356
+ const later = S.state.shellSetup && !S.state.shellSetup.loaded
8357
+ pickToast([r], t((replaces ? 'al.renamed' : 'al.added') + (later ? 'Setup' : ''), { name, old: replaces }))
8358
+ await load({ silent: true })
8359
+ } catch (e) { al.error = e }
8360
+ if (!al) return
8361
+ al.busy = false
8362
+ if (dlg.kind === 'alias') renderAlias()
8363
+ }
8364
+ async function alRemove(name) {
8365
+ al.busy = true
8366
+ al.error = null
8367
+ renderAlias()
8368
+ try {
8369
+ const r = await api('/api/alias/remove', { name })
8370
+ const back = r.account ? Object.assign({ account: r.account, name }, r.args ? { args: r.args } : {}) : null
8371
+ toast(t('al.removed', { name }), back ? { action: { label: t('ss.undo'), run: async () => { try { await api('/api/alias/set', back); await load({ silent: true }); if (dlg.kind === 'alias') renderAlias() } catch (e) { toast(e.message, { kind: 'fail' }) } } } } : undefined)
8372
+ await load({ silent: true })
8373
+ } catch (e) { al.error = e }
8374
+ if (!al) return
8375
+ al.busy = false
8376
+ if (dlg.kind === 'alias') renderAlias()
8377
+ }
8378
+ // The field is built per render, but keeps what was typed in al.draft; Enter saves.
8379
+ function alEditor(replaces) {
8380
+ const input = h('input', { id: 'al-name', type: 'text', class: 'mono', autocomplete: 'off', autocapitalize: 'none', spellcheck: 'false', maxlength: '64', placeholder: t('al.namePh'), disabled: al.busy, 'aria-describedby': 'al-name-hint' })
8381
+ input.value = al.draft !== null ? al.draft : replaces || ''
8382
+ const go = h('button', { class: 'btn btn-sm btn-primary', type: 'button' }, t(replaces ? 'pk.save' : 'pk.add'))
8383
+ const hint = h('p', { class: 'field-hint', id: 'al-name-hint' }, t('al.hint'))
8384
+ // The same rule as the config (ALIAS_NAME), said in words while typing, so a bad name never reaches the server.
8385
+ const ok = (n) => /^[A-Za-z_][A-Za-z0-9_-]*$/.test(n)
8386
+ const sync = () => {
8387
+ const n = input.value.trim()
8388
+ const bad = Boolean(n) && !ok(n)
8389
+ hint.textContent = t(bad ? 'al.badName' : 'al.hint')
8390
+ hint.className = bad ? 'field-error' : 'field-hint'
8391
+ input.classList.toggle('invalid', bad)
8392
+ input.setAttribute('aria-invalid', bad ? 'true' : 'false')
8393
+ go.disabled = al.busy || !n || bad || n === replaces
8394
+ }
8395
+ const save = () => { const n = input.value.trim(); if (n && ok(n) && n !== replaces) alSave(n, replaces) }
8396
+ input.addEventListener('input', () => { al.draft = input.value; sync() })
8397
+ input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); save() } })
8398
+ go.addEventListener('click', save)
8399
+ sync()
8400
+ return [
8401
+ h('label', { class: 'field', for: 'al-name' }, h('span', null, t('al.nameLabel')), input),
8402
+ hint,
8403
+ h('div', { class: 'actions' }, go,
8404
+ replaces || (alAccount() && (alAccount().aliases || []).length) ? h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: al.busy, onclick: () => { al.editing = null; al.draft = null; renderAlias() } }, t('btn.cancel')) : null),
8405
+ ]
8406
+ }
8407
+ function renderAlias() {
8408
+ if (!al || dlg.kind !== 'alias') return
8409
+ const a = alAccount()
8410
+ if (!a) { dlg.el.close(); return }
8411
+ const names = a.aliases || []
8412
+ const body = [h('p', { class: 'muted small' }, t('al.intro', { ref: a.ref }))]
8413
+ for (const n of names) {
8414
+ if (al.editing === n) { body.push(h('div', { class: 'pk-row' }, alEditor(n))); continue }
8415
+ const args = (a.aliasArgs || {})[n]
8416
+ body.push(h('div', { class: 'pk-row' },
8417
+ h('p', { class: 'small' }, h('code', { class: 'mono' }, n + (args ? ' → ' + args.join(' ') : ''))),
8418
+ h('div', { class: 'actions' },
8419
+ h('button', { class: 'btn btn-sm', type: 'button', disabled: al.busy, onclick: () => copyText(n) }, icon('copy'), t('al.copy')),
8420
+ h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: al.busy || al.editing !== null, onclick: () => { al.editing = n; al.draft = null; renderAlias(); const el = document.getElementById('al-name'); if (el) el.focus() } }, t('pk.rename')),
8421
+ h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: al.busy, onclick: () => alRemove(n) }, t('pk.remove')))))
8422
+ }
8423
+ if (al.editing === '') body.push(h('div', { class: 'pk-row' }, alEditor(null)))
8424
+ else if (al.editing === null) body.push(h('div', { class: 'actions' }, h('button', { class: 'btn btn-sm', type: 'button', disabled: al.busy, onclick: () => { al.editing = ''; al.draft = null; renderAlias(); const el = document.getElementById('al-name'); if (el) el.focus() } }, t(names.length ? 'al.addAnother' : 'pk.add'))))
8425
+ body.push(shellSetupNote() || h('p', { class: 'muted small' }, t('al.live')))
8426
+ if (al.error) body.push(errorNote(al.error, null))
8427
+ setKids(dlg.el, dialogFrame(t('al.title', { ref: a.ref }), a.family, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
8428
+ }
8231
8429
  // New terminals load short commands only through one line in the shell's rc file (ADR-0036). Where a short command
8232
8430
  // is added and that line is missing, say so and offer to add it: the line and the file shown are the preview.
8233
8431
  let ssBusy = false
@@ -8245,7 +8443,8 @@ const MAIN = String.raw `
8245
8443
  renderShellSetupHosts()
8246
8444
  }
8247
8445
  function renderShellSetupHosts() {
8248
- if (dlg.kind === 'pick' && pk) renderPick()
8446
+ if (dlg.kind === 'alias' && al) renderAlias()
8447
+ else if (dlg.kind === 'pick' && pk) renderPick()
8249
8448
  else if (dlg.kind === 'create' && nf && nf.result) renderCreate()
8250
8449
  }
8251
8450
  function shellSetupNote() {
@@ -8836,7 +9035,7 @@ const MAIN = String.raw `
8836
9035
  $('accounts').addEventListener('drop', onDrop)
8837
9036
  // Escape leaves the arrange mode, as "Done" does, unless a menu or dialog takes it first.
8838
9037
  document.addEventListener('keydown', (e) => {
8839
- if (e.key !== 'Escape' || e.defaultPrevented || !ui.arrange || menu.el || (dlg.el && dlg.el.open) || e.target.closest('input, select, textarea')) return
9038
+ if (e.key !== 'Escape' || e.defaultPrevented || !ui.arrange || menu.el || (dlg.el && dlg.el.open) || e.target.closest('input, select, textarea, .ui-menu')) return
8840
9039
  endArrange()
8841
9040
  })
8842
9041
  $('settings').addEventListener('click', () => openPopover($('settings'), 'settings', t('set.button'), settingsPop, 'end'))
@@ -8859,6 +9058,14 @@ const MAIN = String.raw `
8859
9058
  setInterval(tick, 1000)
8860
9059
  document.addEventListener('visibilitychange', wake)
8861
9060
  window.addEventListener('focus', wake)
9061
+ // A Portal that changed something the Panel shows says so (ADR-0006): read the state now instead of at the next
9062
+ // round, and the Unattended page its list too, so the Portal's switch and this page never disagree for long.
9063
+ window.addEventListener('message', (e) => {
9064
+ if (!portalRefresh(e, window)) return
9065
+ ua.nextAt = 0
9066
+ ua.at = 0
9067
+ if (S.state && !conn.lost) load({ silent: true })
9068
+ })
8862
9069
  `;
8863
9070
  /** The page script: the tested helpers, then the page logic, in one strict-mode function. */
8864
- export const PAGE_SCRIPT = `(() => {\n 'use strict'\n${LOGIC}\n${MAIN}})()\n`;
9071
+ export const PAGE_SCRIPT = `(() => {\n 'use strict'\n${LOGIC}\n${MENU_LIB}\n${MAIN}\n${menuScript}\n})()\n`;