sideby 0.22.0 → 0.23.1

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 (52) hide show
  1. package/ai-tasks.json +14 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.d.ts +7 -0
  4. package/dist/src/cli/commands.js +326 -21
  5. package/dist/src/cli/json-schemas.js +76 -1
  6. package/dist/src/cli/main.js +32 -4
  7. package/dist/src/core/ask.js +6 -1
  8. package/dist/src/core/config.d.ts +5 -1
  9. package/dist/src/core/config.js +18 -3
  10. package/dist/src/core/quota-levels.d.ts +7 -2
  11. package/dist/src/core/quota-levels.js +13 -3
  12. package/dist/src/core/themes.d.ts +107 -0
  13. package/dist/src/core/themes.js +463 -0
  14. package/dist/src/menubar/snapshot.d.ts +10 -0
  15. package/dist/src/menubar/snapshot.js +14 -6
  16. package/dist/src/menubar/strings.d.ts +6 -0
  17. package/dist/src/menubar/strings.js +6 -0
  18. package/dist/src/panel/handler.d.ts +2 -0
  19. package/dist/src/panel/handler.js +125 -1
  20. package/dist/src/panel/i18n.d.ts +49 -0
  21. package/dist/src/panel/i18n.js +104 -6
  22. package/dist/src/panel/page-logic.d.ts +20 -1
  23. package/dist/src/panel/page-logic.js +41 -0
  24. package/dist/src/panel/page-script.js +268 -39
  25. package/dist/src/panel/page-styles.d.ts +2 -0
  26. package/dist/src/panel/page-styles.js +57 -31
  27. package/dist/src/panel/theme.d.ts +6 -1
  28. package/dist/src/panel/theme.js +4 -0
  29. package/dist/src/panel/themes.d.ts +14 -0
  30. package/dist/src/panel/themes.js +162 -0
  31. package/dist/src/runtime.d.ts +4 -0
  32. package/package.json +1 -1
  33. package/schemas/config.json +29 -1
  34. package/schemas/families.json +5 -0
  35. package/schemas/hide.json +157 -0
  36. package/schemas/list.json +10 -0
  37. package/schemas/order.json +26 -1
  38. package/schemas/pin.json +17 -0
  39. package/schemas/theme-check.json +140 -0
  40. package/schemas/theme-export.json +86 -0
  41. package/schemas/theme-import.json +92 -0
  42. package/schemas/theme-preview.json +86 -0
  43. package/schemas/theme-remove.json +87 -0
  44. package/schemas/theme-use.json +88 -0
  45. package/schemas/theme.json +137 -0
  46. package/schemas/unhide.json +157 -0
  47. package/schemas/unpin.json +17 -0
  48. package/skills/sideby/SKILL.md +3 -1
  49. package/skills/sideby/references/ai-tasks.md +1 -1
  50. package/skills/sideby/references/panel.md +9 -0
  51. package/skills/sideby/references/quota.md +1 -1
  52. package/skills/sideby/references/themes.md +47 -0
@@ -3,7 +3,7 @@
3
3
  import { groupsToAccept } from '../core/inbound.js';
4
4
  import { quotaIsStale } from '../core/quota-levels.js';
5
5
  import { remoteControlTodo } from '../core/remote-control.js';
6
- import { aiTaskAccounts, aliasArgsOf, aliasIssue, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaPressure, remoteControlSummary, reorder, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, shortCwd, shortSessionLabel, sortAccounts, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, updatedAge, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
6
+ import { aiTaskAccounts, aliasArgsOf, aliasIssue, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaHighLevel, quotaPressure, remoteControlSummary, reorder, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, shortCwd, shortSessionLabel, sortAccounts, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, updatedAge, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
7
7
  const LOGIC = [
8
8
  quotaIsStale,
9
9
  aiTaskAccounts,
@@ -17,6 +17,7 @@ const LOGIC = [
17
17
  aliasIssue,
18
18
  attentionReasons,
19
19
  attentionWhy,
20
+ quotaHighLevel,
20
21
  autostartNote,
21
22
  hotkeyFromKey,
22
23
  hotkeyPressKind,
@@ -81,6 +82,7 @@ const LOGIC = [
81
82
  tailInView,
82
83
  updatedAge,
83
84
  pinnedIn,
85
+ hiddenIn,
84
86
  widthFollower,
85
87
  widthTier,
86
88
  windowState,
@@ -354,6 +356,11 @@ const MAIN = String.raw `
354
356
  }
355
357
 
356
358
  const ICONS = {
359
+ // Lucide "users-round", "messages-square", "gauge" and "route" for the page tabs (ISC license)
360
+ tabAccounts: 'M18 21a8 8 0 0 0-16 0M5 8a5 5 0 1 0 10 0 5 5 0 1 0-10 0M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3',
361
+ tabSessions: 'M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2zM20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1',
362
+ tabTuning: 'm12 14 4-4M3.34 19a10 10 0 1 1 17.32 0',
363
+ tabHandoff: 'M3 19a3 3 0 1 0 6 0 3 3 0 1 0-6 0M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15M15 5a3 3 0 1 0 6 0 3 3 0 1 0-6 0',
357
364
  refresh: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7',
358
365
  search: 'M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4.2-4.2',
359
366
  chevron: 'M9 6l6 6-6 6',
@@ -974,7 +981,7 @@ const MAIN = String.raw `
974
981
  up.from = item
975
982
  return { up, item }
976
983
  })
977
- const items = [pinItem(a),
984
+ const items = [pinItem(a), ...hideItems(a),
978
985
  opens.length ? '-' : null, opens.length ? { header: t('menu.groupOpen') } : null, ...opens,
979
986
  '-', { header: t('menu.groupCopy') }, run, ...(fold ? [fold] : more),
980
987
  '-', { header: t('menu.groupManage') }, signInItem, key, ...dirTools(a), likeItem(a),
@@ -1143,7 +1150,8 @@ const MAIN = String.raw `
1143
1150
  function renderSummary() {
1144
1151
  const box = $('summary')
1145
1152
  if (!S.state) { if (S.loadError) box.hidden = true; return }
1146
- const list = S.state.accounts
1153
+ // Hidden Accounts (spec §3.25) stay out of the counts and the attention card; the list's last line counts them.
1154
+ const list = visibleAccounts()
1147
1155
  // Another page keeps it hidden: a refresh while there must not push that page down (renderPageChrome shows it).
1148
1156
  box.hidden = !list.length || curPage !== 'accounts'
1149
1157
  box.removeAttribute('aria-busy')
@@ -1159,9 +1167,10 @@ const MAIN = String.raw `
1159
1167
  for (const r of rs) counts[r] = (counts[r] || 0) + 1
1160
1168
  }
1161
1169
  const order = ['error', 'health-fail', 'signed-out', 'not-installed', 'quota-high', 'health-warn']
1162
- // Who needs a look, by name: counting reasons beside a count of accounts made numbers that did not add up.
1170
+ // Who needs a look, by name: counting reasons beside a count of accounts made numbers that did not add up. One name
1171
+ // and a count, as two names did not fit the card.
1163
1172
  const needing = list.filter((a) => reasonsOf(a, now).length)
1164
- const needSub = need ? t(needing.length > 2 ? 'stat.needWhoMore' : 'stat.needWho', { names: needing.slice(0, 2).map((a) => a.ref).join(' · '), n: needing.length - 2 }) : t('stat.allClear')
1173
+ const needSub = need ? t(needing.length > 1 ? 'stat.needWhoMore' : 'stat.needWho', { names: needing[0].ref, n: needing.length - 1 }) : t('stat.allClear')
1165
1174
  const needTitle = need ? order.filter((r) => counts[r]).map((r) => tn('need.' + r, counts[r])).join(' · ') : null
1166
1175
  const usages = list.filter((a) => a.usage && a.usage.status === 'ok')
1167
1176
  const total = usages.reduce((s, a) => s + (Number(a.usage.totalTokens) || 0), 0)
@@ -1243,9 +1252,10 @@ const MAIN = String.raw `
1243
1252
  }
1244
1253
  function renderFamilyFilter() {
1245
1254
  if (!tb.family) return
1246
- const fams = S.state ? S.state.families.filter((f) => S.state.accounts.some((a) => a.family === f.id)) : []
1255
+ const list = S.state ? listedAccounts() : []
1256
+ const fams = S.state ? S.state.families.filter((f) => list.some((a) => a.family === f.id)) : []
1247
1257
  tb.family.replaceChildren(h('option', { value: '' }, t('tb.allFamilies')),
1248
- ...fams.map((f) => h('option', { value: f.id }, f.title + ' (' + S.state.accounts.filter((a) => a.family === f.id).length + ')')))
1258
+ ...fams.map((f) => h('option', { value: f.id }, f.title + ' (' + list.filter((a) => a.family === f.id).length + ')')))
1249
1259
  if (prefs.family && S.state && !fams.some((f) => f.id === prefs.family)) prefs.family = ''
1250
1260
  tb.family.value = prefs.family
1251
1261
  tb.family.hidden = fams.length < 2 && !prefs.family
@@ -1328,20 +1338,30 @@ const MAIN = String.raw `
1328
1338
  if (!quotaAskable(q.reason)) return null
1329
1339
  return h('button', { class: 'link-btn small q-ask', type: 'button', onclick: (e) => { e.stopPropagation(); openAsk({ task: 'quota', context: { account: a.ref, family: a.family, quotaReason: q.reason + (q.detail ? ': ' + q.detail : ''), version: BOOT.version } }) } }, t('ask.quotaWhy'))
1330
1340
  }
1341
+ // The newest session of this login on this computer: the Account's own and its Same Login's (spec §3.31).
1342
+ function lastUseOf(a) {
1343
+ const refs = [a.ref, ...(a.sameLogin || [])]
1344
+ const times = (S.state ? S.state.accounts : []).filter((x) => refs.includes(x.ref) && x.usage && x.usage.status === 'ok' && x.usage.lastActivityAt).map((x) => Date.parse(x.usage.lastActivityAt)).filter(Number.isFinite)
1345
+ return times.length ? new Date(Math.max(...times)).toISOString() : null
1346
+ }
1331
1347
  function quotaBlock(a, now, cols) {
1332
1348
  // Still reading (a slow plugin or Host): say so where its numbers will appear; the page asks again soon.
1333
1349
  if (a.pending) return h('div', { class: 'quota' }, h('div', { class: 'q-note' }, spinner(), t('acct.reading', { host: famTitle(a) })))
1334
1350
  const q = a.quota
1335
1351
  if (!q) return h('div', { class: 'quota' }, h('div', { class: 'q-note' }, '—'))
1336
1352
  if (q.status !== 'ok') return h('div', { class: 'quota' }, quotaNote(a, q))
1337
- const stale = quotaIsStale(q, now)
1353
+ const stale = quotaIsStale(q, now, lastUseOf(a))
1354
+ // Over an hour old but unused here since: the numbers stand, and the hover text says what it cannot see.
1355
+ const quiet = !stale && now - Date.parse(q.observedAt) > 3600_000
1356
+ // Old numbers of a Host that cannot be asked (Claude Code) change only when a session runs in the account.
1357
+ const waits = stale && !q.fetchError && !family(a.family).quotaRefresh ? t('quota.staleSession') : null
1338
1358
  const wins = q.windows || []
1339
1359
  // A reading borrowed from another Account of the same login says where it came from (spec §3.21).
1340
1360
  const from = q.from ? t('quota.sharedFrom', { name: refName(q.from), ago: ago(q.observedAt) }) : null
1341
1361
  // Where the numbers came from when the Host was asked (spec §3.26), and why the latest ask failed.
1342
1362
  const via = q.fetched ? t('quota.fetchedFrom', { host: famTitle(a), ago: ago(q.observedAt) }) : null
1343
1363
  const failed = q.fetchError ? t('quota.lastCheckFailed', { why: q.fetchError }) : null
1344
- const title = [from || via || (stale ? null : t('quota.dataFrom', { ago: ago(q.observedAt) })), failed].filter(Boolean).join('\n') || null
1364
+ const title = [from || via || (stale ? null : t('quota.dataFrom', { ago: ago(q.observedAt) })), quiet ? t('quota.quiet') : null, failed, waits].filter(Boolean).join('\n') || null
1345
1365
  // --qr: this row's own number of windows, so a narrow list can split the width between them alone (--qn is the
1346
1366
  // widest Family's, for the wide list's shared columns).
1347
1367
  return h('div', { class: 'quota' + (stale ? ' is-stale' : ''), title, css: wins.length ? { '--qr': String(cols.length) } : null },
@@ -1352,7 +1372,7 @@ const MAIN = String.raw `
1352
1372
  return w ? meter(w, now, stale, q.observedAt, same.length > 1) : noMeter(winTitle(c), winShort(c))
1353
1373
  }) : h('div', { class: 'q-note' }, t('quota.noWindows')),
1354
1374
  // Old numbers keep their colours and say their age once, under the bars.
1355
- stale && wins.length ? h('div', { class: 'q-asof', title: failed || t('quota.asOf', { ago: ago(q.observedAt) }) }, icon('clock'), q.fetchError ? t('quota.fetchFailed') + ' · ' : '', t('quota.staleShort', { ago: agoShort(now - Date.parse(q.observedAt)) })) : null)
1375
+ stale && wins.length ? h('div', { class: 'q-asof', title: failed || [t('quota.asOf', { ago: ago(q.observedAt) }), waits].filter(Boolean).join('\n') }, icon('clock'), q.fetchError ? t('quota.fetchFailed') + ' · ' : '', t('quota.staleShort', { ago: agoShort(now - Date.parse(q.observedAt)) })) : null)
1356
1376
  }
1357
1377
  function usageBlock(a) {
1358
1378
  const u = a.usage
@@ -1408,7 +1428,7 @@ const MAIN = String.raw `
1408
1428
  }
1409
1429
  // A word, not only a colour (spec §3.8): what kind of look the account needs; the reason is on hover.
1410
1430
  function attentionWord(subject, reason) {
1411
- const lvl = reason === 'health-fail' ? 'fail' : 'warn'
1431
+ const lvl = reason === 'health-fail' ? 'fail' : reason === 'quota-high' ? quotaHighLevel(subject, Date.now(), FAIL) : 'warn'
1412
1432
  const why = whyOf(subject, Date.now())
1413
1433
  const word = reason === 'health-fail' ? t('att.fix') : reason === 'quota-high' ? t('att.quota') : t('att.check')
1414
1434
  const dot = h('span', { class: 'dot dot-' + lvl, 'aria-hidden': 'true' })
@@ -1459,6 +1479,7 @@ const MAIN = String.raw `
1459
1479
  h('span', { class: 'name', title: a.name }, a.name),
1460
1480
  loginMark(o.linked || members),
1461
1481
  aliasText(a),
1482
+ hiddenMark(isHidden(a) && !famHidden(a.family)),
1462
1483
  statusBadge(a, members))
1463
1484
  }
1464
1485
  // An organization name as the vendor wrote it, without a trailing comma or full stop it sometimes carries.
@@ -1660,7 +1681,7 @@ const MAIN = String.raw `
1660
1681
  }
1661
1682
  // What a row or card shows depends on more than the account (health, view preferences, language); the
1662
1683
  // fingerprint covers what its click handlers use.
1663
- function rowSig(a) { return sig([a, healthOf(a.ref), isNext(a), ui.desktopRef === a.ref, ui.browserRef === a.ref, ui.copied === a.ref, browserFor(a), prefs.hideEmail, isOpen(a), loginLead(a), isPinned(a)]) }
1684
+ function rowSig(a) { return sig([a, healthOf(a.ref), isNext(a), ui.desktopRef === a.ref, ui.browserRef === a.ref, ui.copied === a.ref, browserFor(a), prefs.hideEmail, isOpen(a), loginLead(a), isPinned(a), isHidden(a), famHidden(a.family)]) }
1664
1685
  // Whether the row sits in a login group (spec §3.21): its first row then shows the quota for all of them.
1665
1686
  function inLogin(a) { return ui.loginRefs.has(a.ref) }
1666
1687
  // The group's first row, which shows the quota for all of them.
@@ -1957,13 +1978,15 @@ const MAIN = String.raw `
1957
1978
  // The group's attention tag says who and why: with one Account its name and reason, and a click shows its row;
1958
1979
  // with more, the count, each one's reason on hover, and a click shows only them (as the summary card does).
1959
1980
  function attentionTag(needing, now) {
1981
+ // Red when one of them needs a fix or has a red quota bar, so the tag matches what the rows show.
1982
+ const lvl = needing.some((a) => reasonsOf(a, now).includes('health-fail') || quotaHighLevel(a, now, FAIL) === 'fail') ? 'fail' : 'warn'
1960
1983
  if (needing.length === 1) {
1961
1984
  const a = needing[0]
1962
1985
  const label = a.name + ' · ' + whyOf(a, now)
1963
- return h('button', { class: 'tag tag-warn tag-btn', type: 'button', title: t('group.attentionShow', { name: a.name }), onclick: () => flashRow(a.ref) }, label)
1986
+ return h('button', { class: 'tag tag-' + lvl + ' tag-btn', type: 'button', title: t('group.attentionShow', { name: a.name }), onclick: () => flashRow(a.ref) }, label)
1964
1987
  }
1965
1988
  const list = needing.map((a) => a.name + colon() + whyOf(a, now)).join('\n')
1966
- return h('button', { class: 'tag tag-warn tag-btn', type: 'button', title: list, 'aria-pressed': String(ui.attention), onclick: () => { ui.attention = !ui.attention; renderSummary(); renderAccounts() } }, tn('group.attention', needing.length))
1989
+ return h('button', { class: 'tag tag-' + lvl + ' tag-btn', type: 'button', title: list, 'aria-pressed': String(ui.attention), onclick: () => { ui.attention = !ui.attention; renderSummary(); renderAccounts() } }, tn('group.attention', needing.length))
1967
1990
  }
1968
1991
  // ---------- Grok Bot windows (ADR-0019) ----------
1969
1992
  // Windows of an app that signs in apart from every account, so they get a group of their own after the accounts.
@@ -2144,11 +2167,13 @@ const MAIN = String.raw `
2144
2167
  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')))
2145
2168
  : null,
2146
2169
  off && setup && setup.plan.status === 'blocked' ? h('span', { class: 'muted small label-tip' }, t('quota.blocked'), tipRaw(t('quota.blocked'), setup.plan.message)) : null,
2170
+ hiddenMark(famHidden(fam)),
2171
+ ui.arrange && !BOOT.readOnly ? hideToggle(info.title, famHidden(fam), () => toggleHideFamily(fam)) : null,
2147
2172
  ui.arrange ? null : pickHead(fam)))
2148
2173
  const body = collapsedNow ? null : cards
2149
2174
  ? h('div', { class: 'grid', id: bodyId, 'data-key': 'cards', 'data-patch': '' }, loginClusters(list).map((x) => Array.isArray(x) ? loginCard(x, now, cols) : card(x, now, cols)))
2150
2175
  : 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)))
2151
- return h('section', { class: 'group' + (cards ? ' group-cards' : ' group-list') + (collapsedNow ? ' is-collapsed' : '') + (ui.arrange ? ' is-arranging' : ''), 'aria-label': info.title, 'data-key': 'g:' + fam, 'data-fam': fam, 'data-patch': '' },
2176
+ return h('section', { class: 'group' + (cards ? ' group-cards' : ' group-list') + (collapsedNow ? ' is-collapsed' : '') + (ui.arrange ? ' is-arranging' : '') + (famHidden(fam) ? ' is-hidden' : ''), 'aria-label': info.title, 'data-key': 'g:' + fam, 'data-fam': fam, 'data-patch': '' },
2152
2177
  head, collapsedNow || cards || ui.arrange ? null : colHead(cols, list), body)
2153
2178
  }
2154
2179
  function emptyState() {
@@ -2218,7 +2243,8 @@ const MAIN = String.raw `
2218
2243
  }
2219
2244
  function ordered() { const d = displayOf(); return Boolean((d.families && d.families.length) || (d.accounts && Object.keys(d.accounts).length)) }
2220
2245
  function copyDisplay(d) {
2221
- return { families: d.families ? d.families.slice() : [], accounts: Object.assign({}, d.accounts || {}), pinned: Object.assign({}, d.pinned || {}) }
2246
+ return { families: d.families ? d.families.slice() : [], accounts: Object.assign({}, d.accounts || {}), pinned: Object.assign({}, d.pinned || {}),
2247
+ hiddenFamilies: d.hiddenFamilies ? d.hiddenFamilies.slice() : [], hidden: Object.assign({}, d.hidden || {}) }
2222
2248
  }
2223
2249
  // Shows next at once and writes it to the config. Writes go one at a time; a failed one puts back what the config
2224
2250
  // last confirmed, never another write's unsaved state.
@@ -2227,7 +2253,7 @@ const MAIN = String.raw `
2227
2253
  if (!displaySaves.pending) displaySaves.confirmed = before
2228
2254
  displaySaves.pending++
2229
2255
  S.state.display = next
2230
- renderAccounts()
2256
+ renderDisplayed()
2231
2257
  const run = displaySaves.chain.then(async () => {
2232
2258
  try {
2233
2259
  const r = await api('/api/display-order', { display: next })
@@ -2236,7 +2262,7 @@ const MAIN = String.raw `
2236
2262
  return true
2237
2263
  } catch (e) {
2238
2264
  // A newer write already on its way settles the screen; only the latest one puts things back.
2239
- if (S.state.display === next) { S.state.display = displaySaves.confirmed; renderAccounts() }
2265
+ if (S.state.display === next) { S.state.display = displaySaves.confirmed; renderDisplayed() }
2240
2266
  toast(t(failKey || 'order.failed', { msg: e.message }), { kind: 'fail' })
2241
2267
  return false
2242
2268
  } finally { displaySaves.pending-- }
@@ -2258,6 +2284,74 @@ const MAIN = String.raw `
2258
2284
  next.pinned[a.family] = list
2259
2285
  saveDisplay(before, next, 'pin.failed')
2260
2286
  }
2287
+ // What the Display Order changes on screen: the accounts, and the counts and tool filter that leave Hidden ones out.
2288
+ function renderDisplayed() { renderAccounts(); renderSummary(); renderFamilyFilter(); renderPageChrome() }
2289
+
2290
+ // ---------- Hidden Families and Accounts (spec §3.25) ----------
2291
+ // Display only: a hidden Account still starts, shows in History and can be picked by a Handoff.
2292
+ function isHidden(a) { return hiddenIn(a, displayOf()) }
2293
+ function famHidden(fam) { return (displayOf().hiddenFamilies || []).includes(fam) }
2294
+ function hiddenOf(fam) { return (displayOf().hidden || {})[fam] || [] }
2295
+ function visibleAccounts() { return S.state.accounts.filter((a) => !isHidden(a)) }
2296
+ // The accounts the list shows: the arrange mode and "Show hidden" bring the hidden ones back, marked.
2297
+ function listedAccounts() { return ui.arrange || ui.showHidden ? S.state.accounts : visibleAccounts() }
2298
+ function afterHide(hide, name, undo) {
2299
+ // Hiding from the list itself makes the row go away; the toast says where it went and offers it back.
2300
+ if (hide && !ui.arrange && !ui.showHidden) toast(t('hide.done', { name }), { action: { label: t('order.undo'), run: undo } })
2301
+ }
2302
+ // Hides or shows an Account, with the other directories of its Same Login.
2303
+ function toggleHide(a) {
2304
+ const before = displayOf()
2305
+ const next = copyDisplay(before)
2306
+ const names = [a.name].concat((a.sameLogin || []).map(refName))
2307
+ const exists = (n) => S.state.accounts.some((x) => x.family === a.family && x.name === n)
2308
+ const list = hiddenOf(a.family).filter((n) => !names.includes(n) && exists(n))
2309
+ const hide = !hiddenIn(a, { hidden: displayOf().hidden })
2310
+ if (hide) list.push(...names.filter(exists))
2311
+ next.hidden[a.family] = list
2312
+ saveDisplay(before, next, 'hide.failed').then((ok) => { if (ok) afterHide(hide, a.ref, () => toggleHide(a)) })
2313
+ }
2314
+ function toggleHideFamily(fam) {
2315
+ const before = displayOf()
2316
+ const next = copyDisplay(before)
2317
+ const hide = !famHidden(fam)
2318
+ next.hiddenFamilies = hide ? next.hiddenFamilies.concat(fam) : next.hiddenFamilies.filter((x) => x !== fam)
2319
+ saveDisplay(before, next, 'hide.failed').then((ok) => { if (ok) afterHide(hide, family(fam).title, () => toggleHideFamily(fam)) })
2320
+ }
2321
+ // The row menu's items: hide this account, or all of its tool; on a hidden row, show it again.
2322
+ function hideItems(a) {
2323
+ if (BOOT.readOnly) return []
2324
+ const title = family(a.family).title
2325
+ if (famHidden(a.family)) return [{ icon: 'eye', label: t('hide.showFamily', { title }), run: () => toggleHideFamily(a.family) }]
2326
+ if (isHidden(a)) return [{ icon: 'eye', label: t('hide.showAccount'), run: () => toggleHide(a) }]
2327
+ return [{ icon: 'eyeOff', label: t('hide.account'), run: () => toggleHide(a) }, { icon: 'eyeOff', label: t('hide.family', { title }), run: () => toggleHideFamily(a.family) }]
2328
+ }
2329
+ // A hidden row or group says so while "Show hidden" or the arrange mode brings it back.
2330
+ function hiddenMark(on) {
2331
+ return on ? h('span', { class: 'chip chip-sm hidden-chip' }, icon('eyeOff'), t('hide.mark')) : null
2332
+ }
2333
+ // The eye in the arrange mode: one click hides or shows the Family or the Account (with its Same Login).
2334
+ function hideToggle(label, hidden, run) {
2335
+ const text = t(hidden ? 'hide.showName' : 'hide.hideName', { name: label })
2336
+ return h('button', { class: 'icon-btn hide-btn' + (hidden ? ' is-on' : ''), type: 'button', 'aria-pressed': String(hidden), 'aria-label': text, title: text, onclick: (e) => { e.stopPropagation(); run() } }, icon(hidden ? 'eyeOff' : 'eye'))
2337
+ }
2338
+ // Under the list: how many are hidden, a red dot when one of them needs a look, and the switch to show them.
2339
+ function hiddenBar(n) {
2340
+ const now = Date.now()
2341
+ const needs = S.state.accounts.some((a) => isHidden(a) && reasonsOf(a, now).length)
2342
+ return h('div', { class: 'hidden-bar', 'data-key': 'hidden-bar', 'data-sig': sig([n, needs, Boolean(ui.showHidden), lang]) },
2343
+ needs ? h('span', { class: 'hidden-dot', role: 'img', title: t('hide.needs'), 'aria-label': t('hide.needs') }) : null,
2344
+ h('span', { class: 'muted small' }, tn('hide.count', n)),
2345
+ h('button', { class: 'link-btn small', type: 'button', 'aria-expanded': String(Boolean(ui.showHidden)), onclick: toggleShowHidden }, t(ui.showHidden ? 'hide.collapse' : 'hide.show')))
2346
+ }
2347
+ function toggleShowHidden() { ui.showHidden = !ui.showHidden; renderFamilyFilter(); renderAccounts() }
2348
+ // Everything is hidden: say so, instead of the first-run screen that would suggest the accounts are gone.
2349
+ function allHiddenState() {
2350
+ return h('div', { class: 'empty empty-sm', 'data-key': 'all-hidden' },
2351
+ h('h3', null, t('hide.allTitle')),
2352
+ h('p', { class: 'muted' }, t('hide.allBody')),
2353
+ h('button', { class: 'btn', type: 'button', onclick: toggleShowHidden }, icon('eye'), t('hide.show')))
2354
+ }
2261
2355
 
2262
2356
  // The arrange mode: the only place to drag (spec §3.25). It starts from the order on screen, saves each move at
2263
2357
  // once, and "Done" offers to put back the order it started from.
@@ -2307,13 +2401,19 @@ const MAIN = String.raw `
2307
2401
  const label = ms.map((m) => m.name).join(', ')
2308
2402
  const full = !pinned && pinnedUnits(fam) >= PIN_MAX
2309
2403
  const pinLabel = full ? t('pin.full', { n: PIN_MAX }) : t(pinned ? 'pin.unpinName' : 'pin.pinName', { name: label, title: family(fam).title })
2310
- return h('div', { class: 'row row-arrange' + (pinned ? ' is-pinned' : ''), role: 'listitem', 'data-ref': a.ref, 'data-key': 'arr:' + loginKey(ms.map((m) => m.ref)), 'data-sig': sig([ms.map(rowSig), at, lo, hi, full]) },
2404
+ const hidden = isHidden(a)
2405
+ return h('div', { class: 'row row-arrange' + (pinned ? ' is-pinned' : '') + (hidden ? ' is-hidden' : ''), role: 'listitem', 'data-ref': a.ref, 'data-key': 'arr:' + loginKey(ms.map((m) => m.ref)), 'data-sig': sig([ms.map(rowSig), at, lo, hi, full, hidden, famHidden(fam)]) },
2311
2406
  h('div', { class: 'ident' }, dragHandle('account', fam, a.name, label), badge(fam, 'sm'), h('div', { class: 'ident-text' }, h('div', { class: 'ident-name' },
2312
2407
  pinMark(a),
2313
2408
  h('span', { class: 'name', title: a.name }, a.name),
2314
2409
  loginMark(ms),
2315
- aliasText(a)))),
2410
+ aliasText(a),
2411
+ hiddenMark(hidden && !famHidden(fam))))),
2316
2412
  h('div', { class: 'arrange-tools' },
2413
+ // In a hidden Family the row keeps its eye, greyed, so the columns stay in line; the group's eye shows it again.
2414
+ famHidden(fam)
2415
+ ? h('button', { class: 'icon-btn hide-btn is-on', type: 'button', disabled: true, title: t('hide.inFamily', { title: family(fam).title }), 'aria-label': t('hide.inFamily', { title: family(fam).title }) }, icon('eyeOff'))
2416
+ : hideToggle(label, isHidden(a), () => toggleHide(a)),
2317
2417
  h('button', { class: 'icon-btn', type: 'button', 'aria-label': t('order.up', { name: label }), title: t('order.up', { name: label }), disabled: at <= lo ? true : undefined, onclick: () => moveUnit('account', fam, at, at - 1, { focus: a.name, label, button: 'up' }) }, icon('arrowUp')),
2318
2418
  h('button', { class: 'icon-btn', type: 'button', 'aria-label': t('order.down', { name: label }), title: t('order.down', { name: label }), disabled: at >= hi ? true : undefined, onclick: () => moveUnit('account', fam, at, at + 1, { focus: a.name, label, button: 'down' }) }, icon('arrowDown')),
2319
2419
  // Words, not a lone pin icon at the end of the row: the arrange mode is where the order and the pins are set.
@@ -2447,8 +2547,10 @@ const MAIN = String.raw `
2447
2547
  // Forgets the order of Families and accounts; pins stay.
2448
2548
  async function resetOrder() {
2449
2549
  const before = displayOf()
2450
- const pinned = before.pinned && Object.keys(before.pinned).length ? before.pinned : null
2451
- if (await saveDisplay(before, pinned ? { pinned } : {})) toast(t('order.reset'))
2550
+ const keep = {}
2551
+ for (const k of ['pinned', 'hidden']) if (before[k] && Object.keys(before[k]).length) keep[k] = before[k]
2552
+ if (before.hiddenFamilies && before.hiddenFamilies.length) keep.hiddenFamilies = before.hiddenFamilies
2553
+ if (await saveDisplay(before, keep)) toast(t('order.reset'))
2452
2554
  }
2453
2555
  // Words for screen readers only, such as the new place of something moved with the keyboard.
2454
2556
  let live = null
@@ -2470,13 +2572,17 @@ const MAIN = String.raw `
2470
2572
  const now = Date.now()
2471
2573
  $('toolbar').hidden = !all.length
2472
2574
  if (!all.length) { setKids(count, null); patch(box, [emptyState()].concat(appGroups())); return }
2473
- const shown = all.filter((a) => (!prefs.family || a.family === prefs.family) && matchesQuery(a, ui.query, famTitle(a)) && (!ui.attention || reasonsOf(a, now).length))
2474
- const filtered = shown.length !== all.length
2575
+ const listed = listedAccounts()
2576
+ const hiddenN = all.length - visibleAccounts().length
2577
+ if (!listed.length) { setKids(count, null); patch(box, [allHiddenState()].concat(appGroups())); return }
2578
+ const shown = listed.filter((a) => (!prefs.family || a.family === prefs.family) && matchesQuery(a, ui.query, famTitle(a)) && (!ui.attention || reasonsOf(a, now).length))
2579
+ const filtered = shown.length !== listed.length
2475
2580
  patch(count, filtered
2476
- ? [t('count.filtered', { n: shown.length, total: all.length }), ' ', h('button', { class: 'link-btn', type: 'button', onclick: clearFilters }, t('filter.clear'))]
2477
- : tn('count.accounts', all.length))
2581
+ ? [t('count.filtered', { n: shown.length, total: listed.length }), ' ', h('button', { class: 'link-btn', type: 'button', onclick: clearFilters }, t('filter.clear'))]
2582
+ : tn('count.accounts', listed.length))
2478
2583
  const apps = appGroups()
2479
- if (!shown.length && !apps.length) { patch(box, noMatch()); return }
2584
+ const tail = hiddenN && !ui.arrange ? [hiddenBar(hiddenN)] : []
2585
+ if (!shown.length && !apps.length) { patch(box, [noMatch()].concat(tail)); return }
2480
2586
  ui.loginRefs = new Map()
2481
2587
  for (const x of loginClusters(shown)) if (Array.isArray(x)) for (const a of x) ui.loginRefs.set(a.ref, loginMembers(x)[0].ref)
2482
2588
  // Families in the Display Order (spec §3.25) whatever the sort; each group gets the quota columns it uses.
@@ -2496,10 +2602,10 @@ const MAIN = String.raw `
2496
2602
  const sorted = withPinned(sortAccounts(list, prefs.sort, now, accountOrder(fam)), pinnedOf(fam))
2497
2603
  const cols = quotaColumns(sorted)
2498
2604
  width = Math.max(width, cols.length)
2499
- groups.push(group(fam, sorted, all.filter((a) => a.family === fam).length, now, cols))
2605
+ groups.push(group(fam, sorted, listed.filter((a) => a.family === fam).length, now, cols))
2500
2606
  }
2501
2607
  box.style.setProperty('--qn', String(width))
2502
- patch(box, (ui.arrange ? [arrangeBar()] : []).concat(groups))
2608
+ patch(box, (ui.arrange ? [arrangeBar()] : []).concat(groups, tail))
2503
2609
  if (ui.fade && !REDUCED) {
2504
2610
  box.classList.add('view-in')
2505
2611
  setTimeout(() => box.classList.remove('view-in'), 400)
@@ -2959,8 +3065,9 @@ const MAIN = String.raw `
2959
3065
  if (canHandoff) tabs.push(['handoff', t('page.handoff')])
2960
3066
  nav.hidden = tabs.length < 2
2961
3067
  // Underline tabs: each page has its mark, the Accounts tab its count and Auto Handoff a dot while it is on.
2962
- const tabIcon = { accounts: 'users', sessions: 'messages', tuning: 'sliders', handoff: 'swap' }
2963
- const nAccounts = S.state ? S.state.accounts.length : 0
3068
+ const tabIcon = { accounts: 'tabAccounts', sessions: 'tabSessions', tuning: 'tabTuning', handoff: 'tabHandoff' }
3069
+ // The tab counts what the list shows: Hidden Accounts (spec §3.25) are counted on the line under it.
3070
+ const nAccounts = S.state ? visibleAccounts().length : 0
2964
3071
  const handoffOn = Boolean(ahState() && ahState().settings.auto)
2965
3072
  // Redrawn only when something on it changes, so a refresh never replays the underline.
2966
3073
  const navShape = JSON.stringify([lang, curPage, tabs, nAccounts, handoffOn, sp.opening, pasteCount()])
@@ -5323,7 +5430,8 @@ const MAIN = String.raw `
5323
5430
  const a = S.state.accounts.find((x) => x.ref === r.ref)
5324
5431
  const p = a ? quotaPressure(a, Date.now()) : -1
5325
5432
  return h('li', null,
5326
- h('span', { class: 'title-logo' }, badge(r.family, 'sm'), h('span', { class: 'mono' }, accountLabel(r.ref))),
5433
+ // A hidden Account can still take over (spec §3.25): the mark says why it is here though the list leaves it out.
5434
+ h('span', { class: 'title-logo' }, badge(r.family, 'sm'), h('span', { class: 'mono' }, accountLabel(r.ref)), hiddenMark(Boolean(a && isHidden(a)))),
5327
5435
  h('span', { class: 'muted num' }, p >= 0 ? t('hp.used', { p: Math.round(p) }) : t('hp.noQuota')),
5328
5436
  h('span', { class: r.decision.kind === 'none' ? 'muted' : null }, hpDecision(r.decision, r.starts)))
5329
5437
  }))
@@ -5643,7 +5751,7 @@ const MAIN = String.raw `
5643
5751
  function settingsGroups(leave) {
5644
5752
  const secs = settingsSections()
5645
5753
  const link = (...args) => setLink(leave, ...args)
5646
- const general = [...lookRows(), autostartRow('autostart')]
5754
+ const general = [...lookRows(), link(t('th.title'), themeLabel(), '', openThemes, true), autostartRow('autostart')]
5647
5755
  if (!BOOT.readOnly) general.push(link(t('term.title'), '', '', openTerminals, true))
5648
5756
  // The menu bar switch shows only where it works (macOS); while its state loads it waits, unseen.
5649
5757
  const bar = []
@@ -5656,7 +5764,8 @@ const MAIN = String.raw `
5656
5764
  const acct = []
5657
5765
  // The arrange mode (spec §3.25) has a place here too, where people look for "how do I change this".
5658
5766
  if (secs.includes('order')) {
5659
- const pins = Object.values(displayOf().pinned || {}).some((x) => x.length)
5767
+ const d = displayOf()
5768
+ const pins = [d.pinned, d.hidden].some((r) => Object.values(r || {}).some((x) => x.length)) || Boolean(d.hiddenFamilies && d.hiddenFamilies.length)
5660
5769
  acct.push(link(t('set.order'), t(ordered() || pins ? 'set.orderMine' : 'set.orderDefault'), '', () => {
5661
5770
  setPage('accounts')
5662
5771
  startArrange()
@@ -6018,6 +6127,7 @@ const MAIN = String.raw `
6018
6127
  function adoptPanel(next) {
6019
6128
  if (!CFG || cfgSaving) return
6020
6129
  next = next || {}
6130
+ if ((next.colorTheme || 'default') !== themeChosen) refreshThemeCss()
6021
6131
  if (next.theme === cfgPanel.theme && next.language === cfgPanel.language) return
6022
6132
  cfgPanel = Object.assign({}, next)
6023
6133
  applyTheme()
@@ -6041,6 +6151,7 @@ const MAIN = String.raw `
6041
6151
  else if (dlg.kind === 'ask' && ak) { if (ak.els.text) ak.text = ak.els.text.value; renderAsk() }
6042
6152
  else if (dlg.kind === 'key' && ky && ky.step !== 'enter') renderKey()
6043
6153
  else if (dlg.kind === 'terminal' && tm) renderTerminals()
6154
+ else if (dlg.kind === 'theme' && th) renderThemes()
6044
6155
  else if (dlg.kind === 'autostart') renderAutostart()
6045
6156
  else if (dlg.kind === 'mbset') renderMenubarSettings()
6046
6157
  else if (dlg.kind === 'pick' && pk) renderPick()
@@ -6057,7 +6168,7 @@ const MAIN = String.raw `
6057
6168
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
6058
6169
  }
6059
6170
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
6060
- const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.tool']
6171
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.theme', 'ai.ask.tool']
6061
6172
  function openRc() {
6062
6173
  if (!S.state || !rcSummary()) return
6063
6174
  rc.target = null
@@ -6179,7 +6290,7 @@ const MAIN = String.raw `
6179
6290
  const ATTACH_ACCEPT = 'image/png,image/jpeg,image/gif,image/webp,video/mp4,video/quicktime,video/webm'
6180
6291
  let dropsHooked = false
6181
6292
  // Which open dialog takes pasted or dropped files now: the AI Task's or "Send to it"'s, until it shows its result.
6182
- function dropTarget() {
6293
+ function fileDropTarget() {
6183
6294
  if (BOOT.readOnly) return null
6184
6295
  if (dlg.kind === 'ask' && ak && !ak.result) return askAddFiles
6185
6296
  if (dlg.kind === 'send' && sd && !sd.result) return sendAddFiles
@@ -6189,7 +6300,7 @@ const MAIN = String.raw `
6189
6300
  if (dropsHooked) return
6190
6301
  dropsHooked = true
6191
6302
  const el = dlg.el
6192
- const active = () => Boolean(dropTarget())
6303
+ const active = () => Boolean(fileDropTarget())
6193
6304
  const hasFiles = (e) => e.dataTransfer && Array.prototype.indexOf.call(e.dataTransfer.types || [], 'Files') >= 0
6194
6305
  el.addEventListener('paste', (e) => {
6195
6306
  const cd = e.clipboardData
@@ -6199,7 +6310,7 @@ const MAIN = String.raw `
6199
6310
  if (!active() || !files.length) return
6200
6311
  // A file copied in Finder also carries its name as text; only the file is wanted.
6201
6312
  e.preventDefault()
6202
- dropTarget()(files)
6313
+ fileDropTarget()(files)
6203
6314
  })
6204
6315
  el.addEventListener('dragover', (e) => {
6205
6316
  if (!active() || !hasFiles(e)) return
@@ -6212,7 +6323,7 @@ const MAIN = String.raw `
6212
6323
  el.classList.remove('drop-on')
6213
6324
  if (!active() || !hasFiles(e)) return
6214
6325
  e.preventDefault()
6215
- dropTarget()(Array.from(e.dataTransfer.files || []))
6326
+ fileDropTarget()(Array.from(e.dataTransfer.files || []))
6216
6327
  })
6217
6328
  }
6218
6329
  function askAttachField() {
@@ -6628,6 +6739,124 @@ const MAIN = String.raw `
6628
6739
  setKids(dlg.el, dialogFrame(t('term.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
6629
6740
  }
6630
6741
 
6742
+ // ---------- Themes (spec §3.34, ADR-0050) ----------
6743
+ // The Theme dialog: Built-in Themes and Theme Files as cards, the user's own color, and "Let AI pick my colors".
6744
+ // A switch swaps the page's token rules in place (a constructed sheet after the page's own), so the colors ease over
6745
+ // instead of the page reloading.
6746
+ let th = null
6747
+ let themeFetching = false
6748
+ // The Theme config names ('default' when none) and the one the page shows (inside a Portal, 'default' is its colors).
6749
+ let themeChosen = (BOOT.panel && BOOT.panel.colorTheme) || 'default'
6750
+ let themeNow = themeChosen === 'default' ? 'sky' : themeChosen
6751
+ function themeName(x) { return x.source === 'portal' ? t('th.page') : x.id === 'custom' && x.source === 'file' ? t('th.custom') : lang === 'zh' && x.nameZh ? x.nameZh : x.name }
6752
+ function themeLabel() {
6753
+ const x = th && th.data && th.data.themes.find((y) => y.id === themeNow)
6754
+ if (x) return themeName(x)
6755
+ if (themeNow === 'default') return t('th.page')
6756
+ const b = { sky: ['Sky', '晴空'], leaf: ['New Leaf', '新叶'] }[themeNow]
6757
+ return b ? b[lang === 'zh' ? 1 : 0] : themeNow
6758
+ }
6759
+ function applyThemeCss(css) {
6760
+ if (!css || typeof CSSStyleSheet !== 'function' || !('adoptedStyleSheets' in document)) { location.reload(); return }
6761
+ const root = document.documentElement
6762
+ if (!REDUCED) { root.classList.add('theme-fade'); setTimeout(() => root.classList.remove('theme-fade'), 220) }
6763
+ const sheet = new CSSStyleSheet()
6764
+ sheet.replaceSync(css)
6765
+ document.adoptedStyleSheets = [sheet]
6766
+ }
6767
+ function refreshThemeCss() {
6768
+ if (themeFetching) return
6769
+ themeFetching = true
6770
+ api('/api/themes').then((d) => { themeFetching = false; themeData(d) }, () => { themeFetching = false })
6771
+ }
6772
+ function themeData(d) {
6773
+ themeNow = d.active
6774
+ themeChosen = d.chosen
6775
+ applyThemeCss(d.css)
6776
+ if (th) { th.data = d; if (dlg.kind === 'theme') renderThemes() }
6777
+ refreshSettings()
6778
+ }
6779
+ function openThemes() {
6780
+ closeMenu()
6781
+ th = { data: null, busy: false, error: null, accent: null, ai: '', armed: null, status: null }
6782
+ showDialog('theme')
6783
+ renderThemes()
6784
+ api('/api/themes').then((d) => { if (th) { th.data = d; themeNow = d.active; themeChosen = d.chosen; renderThemes() } }, (e) => { if (th) { th.error = e; renderThemes() } })
6785
+ }
6786
+ async function themeSend(body) {
6787
+ if (th) { th.busy = true; th.error = null; renderThemes() }
6788
+ let d = null
6789
+ try { d = await api('/api/theme', body) } catch (e) { if (th) th.error = e; else toast(e.message, { kind: 'fail' }) }
6790
+ if (th) th.busy = false
6791
+ if (d) themeData(d)
6792
+ else if (th && dlg.kind === 'theme') renderThemes()
6793
+ return d
6794
+ }
6795
+ async function useThemeBy(body) {
6796
+ const d = await themeSend(body)
6797
+ if (!d || !th) return
6798
+ const x = d.themes.find((y) => y.id === d.active)
6799
+ th.status = { text: t('th.switched', { name: x ? themeName(x) : d.active }), undo: true }
6800
+ renderThemes()
6801
+ }
6802
+ async function undoThemeSwitch() {
6803
+ const back = await themeSend({ undo: true })
6804
+ if (!back || !th) return
6805
+ const y = back.themes.find((z) => z.id === back.active)
6806
+ th.status = { text: t('th.undone', { name: y ? themeName(y) : back.active }), undo: false }
6807
+ renderThemes()
6808
+ }
6809
+ function renderThemes() {
6810
+ if (!th) return
6811
+ const d = th.data
6812
+ const body = [h('p', { class: 'muted small' }, t('th.intro'))]
6813
+ // What changed, with undo, sits in the footer beside Close, so the dialog never grows when it appears.
6814
+ const st = th.status
6815
+ const status = h('p', { class: 'theme-status small', role: 'status' }, st ? [st.text, st.undo ? h('button', { class: 'link-btn', type: 'button', disabled: th.busy, onclick: undoThemeSwitch }, t('th.undo')) : null] : null)
6816
+ if (!d && !th.error) body.push(h('p', { class: 'muted small' }, spinner(), ' ', t('th.loading')))
6817
+ if (d) {
6818
+ if (d.fallback) body.push(h('p', { class: 'note note-warn' }, d.fallback))
6819
+ else if (d.adjusted) body.push(h('p', { class: 'note' }, t('th.adjusted', { n: d.adjusted })))
6820
+ body.push(h('div', { class: 'theme-grid', role: 'radiogroup', 'aria-label': t('th.title') }, d.themes.filter((x) => x.source === 'builtin' || !x.problems.length).map((x) => {
6821
+ const on = x.id === d.active
6822
+ return h('button', { class: 'theme-card' + (on ? ' is-on' : ''), type: 'button', role: 'radio', 'aria-checked': String(on), disabled: th.busy || (BOOT.readOnly && !on), onclick: () => { if (!on && !BOOT.readOnly) useThemeBy({ use: x.id }) } },
6823
+ h('span', { class: 'theme-sw', 'aria-hidden': 'true' }, x.swatches.map((c) => h('span', { css: { background: c } }))),
6824
+ h('span', { class: 'theme-name' }, h('span', null, themeName(x)), on ? h('span', { class: 'chip chip-sm chip-ok' }, t('th.inUse')) : x.source === 'file' ? h('span', { class: 'faint small' }, t('th.mine')) : null))
6825
+ })))
6826
+ if (!BOOT.readOnly) {
6827
+ const cur = d.themes.find((y) => y.id === d.active)
6828
+ const pick = h('input', { id: 'th-accent', type: 'color', value: th.accent || (cur && cur.swatches[2]) || '#3f8fc4', disabled: th.busy, 'aria-label': t('th.accent') })
6829
+ pick.addEventListener('input', () => { th.accent = pick.value })
6830
+ body.push(h('div', { class: 'theme-row' },
6831
+ h('label', { class: 'theme-label', for: 'th-accent' }, t('th.accent')), pick,
6832
+ h('button', { class: 'btn btn-sm', type: 'button', disabled: th.busy, onclick: () => useThemeBy({ accent: pick.value }) }, t('th.accentUse'))),
6833
+ h('p', { class: 'field-hint' }, t('th.accentHint')))
6834
+ const ai = h('input', { id: 'th-ai', type: 'text', autocomplete: 'off', placeholder: t('th.aiPh'), 'aria-label': t('th.ai') })
6835
+ ai.value = th.ai
6836
+ ai.addEventListener('input', () => { th.ai = ai.value })
6837
+ const go = () => {
6838
+ openAsk({ task: 'theme', text: th.ai.trim(), context: { theme: cur ? cur.name + ' (' + cur.id + ')' : d.active, version: BOOT.version } })
6839
+ }
6840
+ ai.addEventListener('keydown', (e) => { if (e.key === 'Enter' && !e.isComposing) { e.preventDefault(); go() } })
6841
+ body.push(h('label', { class: 'field', for: 'th-ai' }, h('span', null, t('th.ai')), ai),
6842
+ h('div', { class: 'theme-row' }, h('button', { class: 'btn btn-sm', type: 'button', onclick: go }, icon('bot'), t('th.aiGo')), h('span', { class: 'field-hint' }, t('th.aiHint'))))
6843
+ const files = d.themes.filter((x) => x.source === 'file')
6844
+ if (files.length) body.push(h('div', { class: 'theme-files' }, h('p', { class: 'set-label' }, t('th.files')), files.map((x) => {
6845
+ const sure = th.armed === x.id
6846
+ return h('div', { class: 'theme-file' },
6847
+ h('span', { class: 'theme-file-name' }, themeName(x), x.problems.length ? h('span', { class: 'theme-bad small' }, x.problems[0]) : null),
6848
+ h('button', { class: 'btn btn-sm' + (sure ? ' btn-danger' : ''), type: 'button', disabled: th.busy, onclick: async () => {
6849
+ if (!sure) { th.armed = x.id; renderThemes(); return }
6850
+ th.armed = null
6851
+ if (await themeSend({ remove: x.id })) toast(t('th.removed', { name: themeName(x) }))
6852
+ } }, t(sure ? 'th.removeSure' : 'th.remove')))
6853
+ })))
6854
+ }
6855
+ }
6856
+ if (th.error) body.push(errorNote(th.error, null))
6857
+ setKids(dlg.el, dialogFrame(t('th.title'), null, body, [status, h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
6858
+ }
6859
+
6631
6860
  // ---------- pick commands (spec §3.13, ADR-0035) ----------
6632
6861
  // A short command per tool that starts, each time, the account with the most quota left. The dialog lists every
6633
6862
  // tool that has one or could have one; adding shows what the name would hide in the shell before it writes.
@@ -5,3 +5,5 @@ import { type ResolvedTheme } from './theme.ts';
5
5
  * `data-theme` on the root element.
6
6
  */
7
7
  export declare function pageStyles(theme?: ResolvedTheme): string;
8
+ /** Only the token rules of `pageStyles`: the page swaps them in when the user picks another Theme (spec §3.34). */
9
+ export declare function tokenStyles(theme: ResolvedTheme): string;