sideby 0.35.9 → 0.36.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 (66) hide show
  1. package/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +12 -0
  3. package/dist/src/cli/commands.js +480 -6
  4. package/dist/src/cli/format.d.ts +12 -1
  5. package/dist/src/cli/format.js +23 -3
  6. package/dist/src/cli/json-schemas.js +166 -1
  7. package/dist/src/cli/main.js +18 -4
  8. package/dist/src/core/advisor.d.ts +176 -0
  9. package/dist/src/core/advisor.js +472 -0
  10. package/dist/src/core/browser-profiles.d.ts +16 -0
  11. package/dist/src/core/browser-profiles.js +45 -0
  12. package/dist/src/core/cli-commands.js +25 -1
  13. package/dist/src/core/config.d.ts +29 -0
  14. package/dist/src/core/config.js +25 -0
  15. package/dist/src/core/handoff-select.d.ts +13 -2
  16. package/dist/src/core/handoff-select.js +6 -2
  17. package/dist/src/core/launch.d.ts +4 -0
  18. package/dist/src/core/launch.js +7 -0
  19. package/dist/src/core/limit-reset.d.ts +198 -0
  20. package/dist/src/core/limit-reset.js +299 -0
  21. package/dist/src/core/quota-fetch.d.ts +57 -2
  22. package/dist/src/core/quota-fetch.js +291 -13
  23. package/dist/src/core/quota-levels.d.ts +70 -0
  24. package/dist/src/core/quota-levels.js +80 -0
  25. package/dist/src/core/quota-store.d.ts +15 -1
  26. package/dist/src/core/quota-store.js +26 -1
  27. package/dist/src/core/same-login.d.ts +8 -0
  28. package/dist/src/core/same-login.js +39 -2
  29. package/dist/src/core/search-catalog.js +38 -0
  30. package/dist/src/families/claude/index.js +2 -0
  31. package/dist/src/families/codex/index.js +3 -1
  32. package/dist/src/families/codex/quota.d.ts +23 -1
  33. package/dist/src/families/codex/quota.js +122 -21
  34. package/dist/src/families/grok/quota-log.d.ts +1 -0
  35. package/dist/src/menubar/script.js +70 -18
  36. package/dist/src/menubar/snapshot.d.ts +33 -1
  37. package/dist/src/menubar/snapshot.js +79 -11
  38. package/dist/src/menubar/strings.d.ts +16 -0
  39. package/dist/src/menubar/strings.js +16 -0
  40. package/dist/src/panel/handler.d.ts +21 -0
  41. package/dist/src/panel/handler.js +111 -9
  42. package/dist/src/panel/i18n.d.ts +87 -0
  43. package/dist/src/panel/i18n.js +174 -0
  44. package/dist/src/panel/page-logic.d.ts +17 -0
  45. package/dist/src/panel/page-logic.js +23 -0
  46. package/dist/src/panel/page-script.js +440 -19
  47. package/dist/src/panel/page-styles.js +38 -2
  48. package/dist/src/plugins/loader.d.ts +2 -0
  49. package/dist/src/plugins/loader.js +27 -0
  50. package/dist/src/runtime.d.ts +63 -1
  51. package/dist/src/runtime.js +529 -9
  52. package/dist/src/types.d.ts +67 -0
  53. package/package.json +1 -1
  54. package/schemas/advisor.json +332 -0
  55. package/schemas/config.json +22 -0
  56. package/schemas/error.json +4 -0
  57. package/schemas/menubar-reset.json +93 -0
  58. package/schemas/menubar-snapshot.json +70 -2
  59. package/schemas/quota-reset.json +369 -0
  60. package/schemas/quota.json +30 -0
  61. package/schemas/update.json +4 -0
  62. package/skills/sideby/SKILL.md +6 -2
  63. package/skills/sideby/references/ai-tasks.md +1 -1
  64. package/skills/sideby/references/panel.md +14 -0
  65. package/skills/sideby/references/quota.md +27 -0
  66. package/skills/sideby/references/update.md +1 -1
@@ -1,16 +1,20 @@
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 { advisorPending } from '../core/advisor.js';
3
4
  import { filterCommands } from '../core/cli-commands.js';
4
5
  import { groupsToAccept } from '../core/inbound.js';
5
- import { quotaIsStale } from '../core/quota-levels.js';
6
+ import { limitResetOffer, quotaAge, quotaIsStale, windowAge } from '../core/quota-levels.js';
6
7
  import { remoteControlTodo } from '../core/remote-control.js';
7
8
  import { catalogMatchLevel, catalogNorm, searchCatalog } from '../core/search-catalog.js';
8
- import { accountTitle, aiTaskAccounts, aliasArgsOf, aliasIssue, aliasPrefix, askBridge, askBridged, askCopy, askPermissionNote, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, expiredLogins, 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, openBridge, openBridged, 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
+ import { accountTitle, advisorPick, advisorSummary, aiTaskAccounts, aliasArgsOf, aliasIssue, aliasPrefix, askBridge, askBridged, askCopy, askPermissionNote, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, expiredLogins, 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, openBridge, openBridged, 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
10
  // The component library's dropdown menu, copied by the brand repo's add script (--html into ui/); do not edit it.
10
11
  import { CHECK, menuItem, menuScript } from './ui/dropdown-menu/dropdown-menu.html.js';
11
12
  import { cn, esc } from './ui/lib/cn.js';
12
13
  const LOGIC = [
13
14
  quotaIsStale,
15
+ windowAge,
16
+ quotaAge,
17
+ limitResetOffer,
14
18
  portalRefresh,
15
19
  openBridge,
16
20
  openBridged,
@@ -84,6 +88,9 @@ const LOGIC = [
84
88
  quotaPressure,
85
89
  remoteControlSummary,
86
90
  remoteControlTodo,
91
+ advisorSummary,
92
+ advisorPick,
93
+ advisorPending,
87
94
  groupsToAccept,
88
95
  saveHandoffChange,
89
96
  enableOutcome,
@@ -159,6 +166,7 @@ const MAIN = String.raw `
159
166
  const AUTO_MS = 20000
160
167
  const FAST_MS = 5000
161
168
  const PENDING_MS = 1500
169
+ const ASKING_MS = 2000
162
170
  const FAST_FOR_MS = 3 * 60000
163
171
  // After the layout follows a width into another band, how long the width must hold still before a later crossing
164
172
  // in the same gesture is applied (page-logic.ts, widthFollower).
@@ -172,7 +180,7 @@ const MAIN = String.raw `
172
180
  silent: false, lastTry: 0, pending: false, fastUntil: 0, fastFamily: null,
173
181
  }
174
182
  // View state that is not saved: the search text, the attention filter, the Health check filter.
175
- const ui = { query: '', attention: false, allFindings: false, healthRef: null, checkingRef: null, desktopRef: null, browserRef: null, appBusy: null, appRemove: null, copied: null, appNew: null, highlight: null, fade: true, loginRefs: new Map(), order: { families: [], units: {} }, drag: null, arrange: null }
183
+ const ui = { query: '', attention: false, allFindings: false, healthRef: null, checkingRef: null, desktopRef: null, browserRef: null, appBusy: null, appRemove: null, copied: null, resetRef: null, appNew: null, highlight: null, fade: true, loginRefs: new Map(), order: { families: [], units: {} }, drag: null, arrange: null }
176
184
  const $ = (id) => document.getElementById(id)
177
185
 
178
186
  // ---------- preferences ----------
@@ -579,9 +587,11 @@ const MAIN = String.raw `
579
587
  // fetches the new token from api/session and sends that same request once more; the server refused it before
580
588
  // running it, so the retry cannot apply anything twice. A request that got no answer is never replayed.
581
589
  let token = BOOT.token
582
- function failure(message, retryable, network, status, code) {
590
+ function failure(message, retryable, network, status, code, operationId) {
583
591
  const e = new Error(message)
584
592
  e.code = code || ''
593
+ // A Limit Reset that got no final answer names its operation, so "Check again" retries that one (ADR-0072).
594
+ e.operationId = operationId || ''
585
595
  e.retryable = retryable
586
596
  e.network = Boolean(network)
587
597
  e.status = status || 0
@@ -618,7 +628,7 @@ const MAIN = String.raw `
618
628
  const msg = (data && data.error) || 'request failed (' + res.status + ')'
619
629
  // 4xx messages are written for people (what is wrong, what to do); 5xx ones are internal, so they get a lead-in.
620
630
  if (res.status >= 500) throw failure(t('err.server', { msg }), true, false, res.status)
621
- throw failure(msg.charAt(0).toUpperCase() + msg.slice(1), false, false, res.status, data && typeof data.code === 'string' ? data.code : '')
631
+ throw failure(msg.charAt(0).toUpperCase() + msg.slice(1), false, false, res.status, data && typeof data.code === 'string' ? data.code : '', data && typeof data.operationId === 'string' ? data.operationId : '')
622
632
  }
623
633
  }
624
634
 
@@ -1174,7 +1184,7 @@ const MAIN = String.raw `
1174
1184
  const items = [pinItem(a), ...hideItems(a),
1175
1185
  opens.length ? '-' : null, opens.length ? { header: t('menu.groupOpen') } : null, ...opens,
1176
1186
  '-', { header: t('menu.groupCopy') }, run, ...(fold ? [fold] : more),
1177
- '-', { header: t('menu.groupManage') }, signInItem, key, aliasItem(a), ...dirTools(a), likeItem(a),
1187
+ '-', { header: t('menu.groupManage') }, resetItem(a), signInItem, key, aliasItem(a), ...dirTools(a), likeItem(a),
1178
1188
  ...(dirs.length ? ['-', { header: t('menu.groupOtherDirs') }, ...dirs.map((d) => d.item)] : [])]
1179
1189
  back.sub = items
1180
1190
  for (const d of dirs) d.up.sub = items
@@ -1492,12 +1502,16 @@ const MAIN = String.raw `
1492
1502
  }
1493
1503
  // A window's cell: percent and countdown on one line, the bar under them. The label shows where no column
1494
1504
  // header does (cards, narrow screens).
1495
- function meter(w, now, stale, observedAt, withLength) {
1505
+ // age: this window's own read time and whether its number is old (windowAge, ADR-0073).
1506
+ function meter(w, now, age, withLength) {
1507
+ const stale = age.stale
1508
+ const observedAt = age.observedAt
1496
1509
  const st = windowState(w, now, WARN, FAIL, LONG)
1497
1510
  const passed = passedWindow(w, observedAt, now)
1498
1511
  const left = prefs.quota === 'left'
1499
1512
  const shown = left ? 100 - st.pct : st.pct
1500
- const asOf = stale ? t('quota.asOf', { ago: ago(observedAt) }) : ''
1513
+ // When and where this number was read is always in the hover text, old or not.
1514
+ const asOf = [Number.isFinite(Date.parse(observedAt)) ? t('quota.readAt', { at: clock(observedAt), ago: ago(observedAt) }) : t('quota.readUnknown'), age.source ? t('quota.source', { source: age.source }) : ''].filter(Boolean).join(' · ')
1501
1515
  // The same words as the menu bar and the CLI (spec §3.31): a countdown under a day, then tomorrow, a weekday, a date.
1502
1516
  const reset = passed ? t('quota.resetShort') : t('quota.resetsIn', { d: resetWhen(w.resetsAt, now, lang) })
1503
1517
  // The wide list's column says only the model group, so the hover names which of its limits this is.
@@ -1545,15 +1559,27 @@ const MAIN = String.raw `
1545
1559
  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)
1546
1560
  return times.length ? new Date(Math.max(...times)).toISOString() : null
1547
1561
  }
1562
+ // A note under the bars that was not there at the last render fades in once; the first paint draws all at rest.
1563
+ const noteSeen = new Set()
1564
+ function noteClass(key, cls, present) {
1565
+ if (!present) { noteSeen.delete(key); return cls }
1566
+ const fresh = !noteSeen.has(key) && S.firstAt && Date.now() - S.firstAt > 1000
1567
+ noteSeen.add(key)
1568
+ return cls + (fresh ? ' q-new' : '')
1569
+ }
1548
1570
  function quotaBlock(a, now, cols) {
1549
1571
  // Still reading (a slow plugin or Host): say so where its numbers will appear; the page asks again soon.
1550
1572
  if (a.pending) return h('div', { class: 'quota' }, h('div', { class: 'q-note' }, spinner(), t('acct.reading', { host: famTitle(a) })))
1551
1573
  const q = a.quota
1552
1574
  if (!q) return h('div', { class: 'quota' }, h('div', { class: 'q-note' }, '—'))
1553
1575
  if (q.status !== 'ok') return h('div', { class: 'quota' }, quotaNote(a, q))
1554
- const stale = quotaIsStale(q, now, lastUseOf(a))
1576
+ // Each window by its own read time (ADR-0073); the row says the oldest once, under the bars.
1577
+ const lastUse = lastUseOf(a)
1578
+ const every = family(a.family).quotaEvery
1579
+ const age = quotaAge(q, now, lastUse, every)
1580
+ const stale = age.stale
1555
1581
  // Over an hour old but unused here since: the numbers stand, and the hover text says what it cannot see.
1556
- const quiet = !stale && now - Date.parse(q.observedAt) > 3600_000
1582
+ const quiet = !stale && age.quiet
1557
1583
  // Old numbers of a Host that cannot be asked (Claude Code) change only when a session runs in the account.
1558
1584
  const waits = stale && !q.fetchError && !family(a.family).quotaRefresh ? t('quota.staleSession') : null
1559
1585
  const wins = q.windows || []
@@ -1563,17 +1589,265 @@ const MAIN = String.raw `
1563
1589
  const via = q.fetched ? t('quota.fetchedFrom', { host: famTitle(a), ago: ago(q.observedAt) }) : null
1564
1590
  const failed = q.fetchError ? t('quota.lastCheckFailed', { why: q.fetchError }) : null
1565
1591
  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
1592
+ // The age next to the numbers only once they are older than the Family asks (or old); failed and undated at once.
1593
+ const showAge = Boolean(age.showAge && wins.length)
1594
+ const asOf = showAge
1595
+ ? h('span', { class: noteClass(a.ref + ':asof', 'q-asof', true), title: failed || [t('quota.asOf', { ago: ago(age.observedAt) }), waits].filter(Boolean).join('\n') }, icon('clock'), q.fetchError ? t('quota.fetchFailed') + ' · ' : '', t('quota.staleShort', { ago: agoShort(now - Date.parse(age.observedAt)) }))
1596
+ : null
1597
+ if (!showAge) noteClass(a.ref + ':asof', '', false)
1598
+ const resets = limitResetsNote(a, q)
1599
+ const resetBtn = resetButton(a, q, now)
1566
1600
  // --qr: this row's own number of windows, so a narrow list can split the width between them alone (--qn is the
1567
1601
  // widest Family's, for the wide list's shared columns).
1568
- return h('div', { class: 'quota' + (stale ? ' is-stale' : ''), title, css: wins.length ? { '--qr': String(cols.length) } : null },
1602
+ return h('div', { class: 'quota' + (stale ? ' is-stale' : '') + (ui.resetRef === a.ref ? ' is-resetting' : ''), title, css: wins.length ? { '--qr': String(cols.length) } : null },
1569
1603
  wins.length ? cols.map((c) => {
1570
1604
  // A model group with several limits (Antigravity's 5-hour and weekly) shows the one that binds first.
1571
1605
  const same = wins.filter((x) => winKey(x) === c)
1572
1606
  const w = bindingWindow(same, now, WARN, FAIL, LONG)
1573
- return w ? meter(w, now, stale, q.observedAt, same.length > 1) : noMeter(winTitle(c), winShort(c))
1607
+ return w ? meter(w, now, windowAge(q, w, now, lastUse, every), same.length > 1) : noMeter(winTitle(c), winShort(c))
1574
1608
  }) : h('div', { class: 'q-note' }, t('quota.noWindows')),
1575
- // Old numbers keep their colours and say their age once, under the bars.
1576
- 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)
1609
+ // Old numbers keep their colours and say their age once, under the bars, next to the Limit Resets the account holds.
1610
+ asOf || resets || resetBtn ? h('div', { class: 'q-foot' }, asOf, resets, resetBtn) : null)
1611
+ }
1612
+ // The Limit Resets an account holds (ADR-0072), where its Host tells: a quiet count under the bars, with when it
1613
+ // was read and when the next one expires in the hover text. A Same Login is one row, so it shows once.
1614
+ function limitResetsNote(a, q) {
1615
+ const r = q.limitResets
1616
+ if (!r || !(r.available > 0)) { noteClass(a.ref + ':resets', '', false); return null }
1617
+ const tipText = [t('reset.tip', { host: famTitle(a), ago: ago(r.observedAt) }), r.nextExpiresAt ? t('reset.expires', { at: clock(r.nextExpiresAt) }) : t('reset.noExpiry', { host: famTitle(a) })].join('\n')
1618
+ return h('span', { class: noteClass(a.ref + ':resets', 'q-resets', true), title: tipText }, icon('refresh'), tn('reset.count', r.available))
1619
+ }
1620
+ // ---------- using a Limit Reset (spec §3.40, ADR-0072) ----------
1621
+ // Codex spends one through its own CLI, after a dialog that shows the numbers read just now; Claude Code can only
1622
+ // be sent to the vendor's page. A button shows on the row when it matters (limitResetOffer); otherwise the action is
1623
+ // in the row's menu and the command palette. Nothing here spends by itself.
1624
+ function resetKind(a) { return a.kind === 'api' || BOOT.readOnly ? null : family(a.family).limitReset || null }
1625
+ function resetSite(a) { return String(family(a.family).limitResetPage || '').replace(/^https:\/\//, '').split('/')[0] }
1626
+ function resetWindowName(w) { return (w.name ? w.name + ' · ' : '') + winTitle(w.label) }
1627
+ // What the link is for: the tight windows, who the account is, and what sideby cannot see.
1628
+ function resetPageHint(a, q, offer) {
1629
+ const tight = offer ? offer.tight.map((i) => resetWindowName(q.windows[i]) + ' ' + Math.round(q.windows[i].usedPercent) + '%') : []
1630
+ const who = a.identity && a.identity.email ? emailText(a.identity.email) : a.ref
1631
+ return [tight.length ? t('reset.page.tight', { list: tight.join(', ') }) : '', t('reset.page.who', { who, site: resetSite(a) }), t('reset.page.blind', { host: famTitle(a) })].filter(Boolean).join('\n')
1632
+ }
1633
+ function resetButton(a, q, now) {
1634
+ const kind = resetKind(a)
1635
+ const offer = kind ? limitResetOffer(q, kind, now, { short: WARN, long: LONG.warn }) : null
1636
+ if (!offer) { noteClass(a.ref + ':resetbtn', '', false); return null }
1637
+ const busy = ui.resetRef === a.ref
1638
+ const cls = noteClass(a.ref + ':resetbtn', 'btn btn-sm q-reset-btn', true)
1639
+ if (kind === 'page')
1640
+ return h('button', { class: cls, type: 'button', disabled: busy, 'aria-busy': busy ? 'true' : null, title: resetPageHint(a, q, offer), onclick: (e) => { e.stopPropagation(); openResetPage(a) } }, busy ? spinner() : icon('globe'), t('reset.usePage', { site: resetSite(a) }))
1641
+ const why = [offer.tight.length ? t('reset.page.tight', { list: offer.tight.map((i) => resetWindowName(q.windows[i]) + ' ' + Math.round(q.windows[i].usedPercent) + '%').join(', ') }) : '', offer.expiring && q.limitResets.nextExpiresAt ? t('reset.expires', { at: clock(q.limitResets.nextExpiresAt) }) : '', t('reset.useHint')].filter(Boolean).join('\n')
1642
+ return h('button', { class: cls, type: 'button', disabled: busy, title: why, onclick: (e) => { e.stopPropagation(); openReset(a) } }, t('reset.use'))
1643
+ }
1644
+ // The same action in the row's menu, also when the row shows no button. A Host that says an account holds none has
1645
+ // no item; one that cannot tell (Claude Code) always has the link.
1646
+ function resetItem(a) {
1647
+ const kind = resetKind(a)
1648
+ if (!kind) return null
1649
+ const q = a.quota && a.quota.status === 'ok' ? a.quota : null
1650
+ if (kind === 'page') return { icon: 'globe', label: t('reset.usePage', { site: resetSite(a) }), hint: resetSite(a), disabled: ui.resetRef === a.ref, run: () => openResetPage(a) }
1651
+ if (q && q.limitResets && !(q.limitResets.available > 0)) return null
1652
+ return { icon: 'refresh', label: t('reset.useMenu'), hint: q && q.limitResets ? tn('reset.count', q.limitResets.available) : '', run: () => openReset(a) }
1653
+ }
1654
+ // After the jump to the vendor's page: when the user is back on this page, that account's quota is asked once.
1655
+ const resetJump = { ref: null, away: false }
1656
+ async function openResetPage(a) {
1657
+ if (ui.resetRef) return
1658
+ ui.resetRef = a.ref
1659
+ renderAccounts()
1660
+ try {
1661
+ const r = await api('/api/quota/reset/open', { account: a.ref })
1662
+ resetJump.ref = a.ref
1663
+ resetJump.away = document.visibilityState !== 'visible' || !document.hasFocus()
1664
+ const who = a.identity && a.identity.email ? emailText(a.identity.email) : a.ref
1665
+ toast(t(r.profile ? 'reset.page.openedIn' : 'reset.page.opened', { site: resetSite(a), name: r.profile ? profileLabel(r.profile) : '', who }), { kind: 'info', duration: 9000 })
1666
+ } catch (e) { toast(t('reset.page.failed', { url: family(a.family).limitResetPage || '', msg: e.message }), { kind: 'fail' }) }
1667
+ ui.resetRef = null
1668
+ renderAccounts()
1669
+ }
1670
+ function resetLeft() { if (resetJump.ref) resetJump.away = true }
1671
+ async function resetReturned() {
1672
+ if (!resetJump.ref || !resetJump.away || document.visibilityState !== 'visible') return
1673
+ const ref = resetJump.ref
1674
+ resetJump.ref = null
1675
+ resetJump.away = false
1676
+ ui.resetRef = ref
1677
+ renderAccounts()
1678
+ try { await api('/api/quota/refresh', { account: ref }) } catch {}
1679
+ ui.resetRef = null
1680
+ await load({ silent: true })
1681
+ renderAccounts()
1682
+ }
1683
+ // The accounts the palette's "Use a limit reset" offers: one row per login, those a Host says hold none left out.
1684
+ function resetCandidates() {
1685
+ if (!S.state) return []
1686
+ return S.state.accounts.filter((a) => {
1687
+ const kind = resetKind(a)
1688
+ if (!kind || a.login === 'logged-out' || (loginLead(a) && loginLead(a) !== a.ref)) return false
1689
+ const q = a.quota && a.quota.status === 'ok' ? a.quota : null
1690
+ return kind === 'page' || !(q && q.limitResets && !(q.limitResets.available > 0))
1691
+ })
1692
+ }
1693
+ let rs = null
1694
+ // "#reset=<account>": where the Menu Bar Item sends the user for a Codex account. It only opens the confirmation;
1695
+ // the address is cleaned at once, so a reload does not open it again.
1696
+ function resetFromHash() {
1697
+ const m = /^#reset=(.+)$/.exec(location.hash)
1698
+ if (!m || !S.state) return
1699
+ let ref = ''
1700
+ try { ref = decodeURIComponent(m[1]) } catch {}
1701
+ try { history.replaceState(null, '', location.pathname + location.search) } catch {}
1702
+ const a = S.state.accounts.find((x) => x.ref === ref)
1703
+ if (!a || (dlg.el && dlg.el.open)) return
1704
+ const lead = loginLead(a)
1705
+ const head = (lead && S.state.accounts.find((x) => x.ref === lead)) || a
1706
+ // Only the confirmation opens from an address: a link never starts a browser or uses anything by itself.
1707
+ if (resetKind(head) === 'use') openReset(head)
1708
+ }
1709
+ function openResetPick() {
1710
+ const list = resetCandidates()
1711
+ if (list.length === 1 && resetKind(list[0]) === 'use') { openReset(list[0]); return }
1712
+ rs = { step: 'pick', ref: null, plan: null, result: null, error: null, operationId: '' }
1713
+ showDialog('reset')
1714
+ dlg.onClose = () => { rs = null; renderAccounts() }
1715
+ renderReset()
1716
+ }
1717
+ function openReset(a) {
1718
+ closeMenu()
1719
+ rs = { step: 'loading', ref: a.ref, plan: null, result: null, error: null, operationId: '' }
1720
+ showDialog('reset')
1721
+ dlg.onClose = () => { rs = null; renderAccounts() }
1722
+ renderReset()
1723
+ resetPlan()
1724
+ }
1725
+ // The plan: the count and the quota read from the Host now, never the numbers the row happened to show.
1726
+ async function resetPlan() {
1727
+ const mine = rs
1728
+ try {
1729
+ const r = await api('/api/quota/reset', { account: mine.ref })
1730
+ if (rs !== mine) return
1731
+ rs.plan = r.plan
1732
+ rs.operationId = r.plan.operationId || ''
1733
+ rs.step = 'plan'
1734
+ } catch (e) {
1735
+ if (rs !== mine) return
1736
+ rs.error = e
1737
+ rs.step = 'error'
1738
+ }
1739
+ renderReset()
1740
+ load({ silent: true })
1741
+ }
1742
+ async function resetConfirm() {
1743
+ if (!rs || !rs.operationId || dlg.busy) return
1744
+ const mine = rs
1745
+ rs.step = 'busy'
1746
+ rs.error = null
1747
+ dlg.busy = true
1748
+ ui.resetRef = rs.ref
1749
+ renderReset()
1750
+ try {
1751
+ const r = await api('/api/quota/reset', { account: mine.ref, operationId: mine.operationId, confirm: true })
1752
+ rs.result = r.result
1753
+ rs.step = r.result.outcome === 'reset' || r.result.outcome === 'already-done' ? 'done' : 'nothing'
1754
+ } catch (e) {
1755
+ rs.error = e
1756
+ if (e.operationId) rs.operationId = e.operationId
1757
+ // A confirmation that got no answer the page can read (the connection dropped, a server error, a reply that is
1758
+ // not a result) may have been carried out: it is as unknown as a Host that did not answer, and "Check again"
1759
+ // asks about that same operation. Only an answer that says so (4xx, an expired page) is a plain error.
1760
+ rs.lost = e.code !== 'outcome-unknown' && Boolean(e.network || e.status >= 500 || e.retryable === undefined)
1761
+ rs.step = e.code === 'outcome-unknown' || rs.lost ? 'unknown' : 'error'
1762
+ }
1763
+ dlg.busy = false
1764
+ ui.resetRef = null
1765
+ if (rs === mine && dlg.kind === 'reset') renderReset()
1766
+ await load({ silent: true })
1767
+ if (rs === mine && dlg.kind === 'reset') renderReset()
1768
+ }
1769
+ // One window in the dialog: its name, used percent, own reset time and bar. The same element stays through the
1770
+ // steps, so the bar eases from the old number to the real one the Host reports afterwards.
1771
+ function resetWindowRow(w, now, busy) {
1772
+ const st = windowState(w, now, WARN, FAIL, LONG)
1773
+ const key = (w.name || '') + '|' + w.label
1774
+ return h('div', { class: 'rs-win lvl-' + st.level + (busy ? ' is-busy' : ''), 'data-key': 'rs-' + key, 'data-patch': '' },
1775
+ h('span', { class: 'rs-win-name' }, resetWindowName(w)),
1776
+ h('span', { class: 'rs-win-pct' }, st.pct + '%', h('span', { class: 'm-unit' }, ' ' + t('quota.unitUsed'))),
1777
+ h('span', { class: 'rs-win-reset' }, st.passed ? t('quota.resetShort') : t('quota.resetsIn', { d: resetWhen(w.resetsAt, now, lang) })),
1778
+ h('div', { class: 'bar', 'data-patch': '', role: 'meter', 'aria-label': resetWindowName(w), 'aria-valuemin': '0', 'aria-valuemax': '100', 'aria-valuenow': String(st.pct) }, h('span', { css: { width: st.pct + '%' } })))
1779
+ }
1780
+ function renderReset() {
1781
+ if (!rs || dlg.kind !== 'reset') return
1782
+ const now = Date.now()
1783
+ const close = h('button', { class: 'btn', type: 'button', 'data-key': 'rs-close', disabled: dlg.busy, onclick: () => dlg.el.close() }, t(rs.step === 'done' || rs.step === 'nothing' ? 'btn.done' : rs.step === 'pick' || rs.step === 'error' || rs.step === 'unknown' ? 'btn.close' : 'btn.cancel'))
1784
+ const frame = (fam, body, foot) => [
1785
+ h('div', { class: 'dlg-head', 'data-patch': '' },
1786
+ h('h2', { id: 'dlg-title', class: 'title-logo', 'data-patch': '' }, fam ? badge(fam, 'sm') : null, t('reset.title')),
1787
+ h('button', { class: 'icon-btn', type: 'button', 'aria-label': t('btn.close'), disabled: dlg.busy, onclick: () => dlg.el.close() }, icon('x'))),
1788
+ h('div', { class: 'dlg-body rs-body', 'data-patch': '' }, body),
1789
+ h('div', { class: 'dlg-foot', 'data-patch': '' }, foot),
1790
+ ]
1791
+ if (rs.step === 'pick') {
1792
+ const list = resetCandidates()
1793
+ const body = [h('p', { class: 'muted small', 'data-key': 'rs-intro' }, t('reset.pick.intro'))]
1794
+ if (!list.length) body.push(h('p', { class: 'note', 'data-key': 'rs-none' }, t('reset.pick.none')))
1795
+ else body.push(h('ul', { class: 'rs-pick', 'data-key': 'rs-pick' }, list.map((a) => {
1796
+ const q = a.quota && a.quota.status === 'ok' ? a.quota : null
1797
+ const page = resetKind(a) === 'page'
1798
+ const peers = (a.sameLogin || []).map(refName)
1799
+ return h('li', null, h('button', { class: 'rs-pick-btn', type: 'button', onclick: () => { if (page) { dlg.el.close(); openResetPage(a) } else openReset(a) } },
1800
+ badge(a.family, 'sm'),
1801
+ h('span', { class: 'rs-pick-main' }, h('b', null, a.ref), peers.length ? h('span', { class: 'muted small' }, ' = ' + peers.join(', ')) : null,
1802
+ h('span', { class: 'rs-pick-sub' }, page ? t('reset.usePage', { site: resetSite(a) }) : q && q.limitResets ? tn('reset.count', q.limitResets.available) : t('reset.pick.unknown'))),
1803
+ icon(page ? 'globe' : 'chevron', 'rs-pick-go')))
1804
+ })))
1805
+ patch(dlg.el, frame(null, body, [close]))
1806
+ return
1807
+ }
1808
+ const a = S.state && S.state.accounts.find((x) => x.ref === rs.ref)
1809
+ if (!a) { dlg.el.close(); return }
1810
+ const plan = rs.plan
1811
+ // While the plan is being read, the row's kept numbers hold the place of the fresh ones, so the dialog opens at
1812
+ // the size it will have.
1813
+ const shown = rs.result && rs.result.quota && rs.result.quota.status === 'ok' ? rs.result.quota : plan && plan.quota.status === 'ok' ? plan.quota : a.quota && a.quota.status === 'ok' ? a.quota : null
1814
+ const stock = rs.result && rs.result.quota && rs.result.quota.status === 'ok' ? rs.result.quota.limitResets : plan ? plan.limitResets : shown ? shown.limitResets : null
1815
+ const peers = plan ? plan.sameLogin : a.sameLogin || []
1816
+ const who = a.identity && a.identity.email ? emailText(a.identity.email) : ''
1817
+ const body = []
1818
+ body.push(h('div', { class: 'rs-acct', 'data-key': 'rs-acct', 'data-patch': '' },
1819
+ h('b', { class: 'mono' }, a.ref), who ? h('span', { class: 'muted' }, ' · ' + who) : null,
1820
+ peers.length ? h('div', { class: 'rs-peers' }, t('reset.peers', { names: peers.join(', ') })) : null))
1821
+ const wins = shown ? shown.windows.filter((w) => !w.name) : []
1822
+ const reading = rs.step === 'loading'
1823
+ body.push(h('div', { class: 'rs-wins' + (reading ? ' is-reading' : ''), 'data-key': 'rs-wins', 'data-patch': '' },
1824
+ wins.length ? wins.map((w) => resetWindowRow(w, now, rs.step === 'busy')) : h('p', { class: 'muted small' }, t('quota.noWindows'))))
1825
+ const after = plan && plan.expectedAfter !== undefined ? plan.expectedAfter : null
1826
+ const stockLine = reading ? [spinner(), t('reset.reading', { host: famTitle(a) })]
1827
+ : rs.step === 'done' || rs.step === 'nothing'
1828
+ ? [stock ? tn('reset.left', stock.available) : t('reset.stockUnknown')]
1829
+ : stock
1830
+ ? [tn('reset.count', stock.available), after !== null ? ' → ' + t('reset.after', { n: after }) : '', ' · ', stock.nextExpiresAt ? t('reset.expires', { at: clock(stock.nextExpiresAt) }) : t('reset.expiryUnknown')]
1831
+ : [t('reset.stockUnknown')]
1832
+ body.push(h('div', { class: 'rs-stock', 'data-key': 'rs-stock', 'data-patch': '' }, icon('refresh'), h('span', { 'data-patch': '' }, stockLine)))
1833
+ // One message slot, the same height through the steps: what confirming does, then what happened.
1834
+ let msg
1835
+ if (rs.step === 'busy') msg = h('p', { class: 'note rs-msg', role: 'status' }, spinner(), t('reset.busy', { host: famTitle(a) }))
1836
+ else if (rs.step === 'done') msg = h('p', { class: 'note note-ok rs-msg', role: 'status' }, t(rs.result.outcome === 'already-done' ? 'reset.done.already' : 'reset.done', { ref: a.ref }), rs.result.quotaPending ? ' ' + t('reset.done.pending') : ' ' + t('reset.done.real', { host: famTitle(a) }))
1837
+ else if (rs.step === 'nothing') msg = h('p', { class: 'note rs-msg', role: 'status' }, t(rs.result.outcome === 'none-left' ? 'reset.nothing.none' : 'reset.nothing.window', { ref: a.ref }))
1838
+ else if (rs.step === 'unknown') msg = h('p', { class: 'note note-warn rs-msg', role: 'alert' }, t(rs.lost ? 'reset.noAnswer' : 'reset.unknown', { host: famTitle(a) }))
1839
+ else if (rs.step === 'error') msg = h('p', { class: 'note note-fail rs-msg', role: 'alert' }, rs.error.message)
1840
+ else if (plan && !plan.canUse) msg = h('p', { class: 'note note-warn rs-msg' }, plan.blocked ? plan.blocked.charAt(0).toUpperCase() + plan.blocked.slice(1) + '.' : t('reset.blocked'))
1841
+ else msg = h('p', { class: 'note note-warn rs-msg' }, t(plan && plan.unresolved ? 'reset.confirm.unresolved' : peers.length ? 'reset.confirm.warnAll' : 'reset.confirm.warn', { host: famTitle(a), ref: a.ref }))
1842
+ body.push(h('div', { class: 'rs-slot', 'data-key': 'rs-slot', 'data-patch': '' }, msg))
1843
+ const foot = [close]
1844
+ if (rs.step === 'loading' || rs.step === 'plan' || rs.step === 'busy') {
1845
+ const can = rs.step === 'plan' && plan && plan.canUse && rs.operationId
1846
+ foot.push(h('button', { class: 'btn btn-primary', type: 'button', 'data-key': 'rs-go', disabled: !can, 'aria-busy': rs.step === 'busy' ? 'true' : null, onclick: resetConfirm }, rs.step === 'busy' ? spinner() : null, t(plan && plan.unresolved ? 'reset.confirm.check' : 'reset.confirm.go')))
1847
+ } else if ((rs.step === 'unknown' || (rs.step === 'error' && rs.error.code === 'outcome-not-saved')) && rs.operationId) {
1848
+ foot.push(h('button', { class: 'btn btn-primary', type: 'button', 'data-key': 'rs-go', onclick: resetConfirm }, t('reset.confirm.check')))
1849
+ }
1850
+ patch(dlg.el, frame(a.family, body, foot))
1577
1851
  }
1578
1852
  function usageBlock(a) {
1579
1853
  const u = a.usage
@@ -1932,7 +2206,7 @@ const MAIN = String.raw `
1932
2206
  }
1933
2207
  // What a row or card shows depends on more than the account (health, view preferences, language); the
1934
2208
  // fingerprint covers what its click handlers use.
1935
- 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)]) }
2209
+ function rowSig(a) { return sig([a, healthOf(a.ref), isNext(a), ui.desktopRef === a.ref, ui.browserRef === a.ref, ui.resetRef === a.ref, ui.copied === a.ref, browserFor(a), prefs.hideEmail, isOpen(a), loginLead(a), isPinned(a), isHidden(a), famHidden(a.family)]) }
1936
2210
  // Whether the row sits in a login group (spec §3.21): its first row then shows the quota for all of them.
1937
2211
  function inLogin(a) { return ui.loginRefs.has(a.ref) }
1938
2212
  // The group's first row, which shows the quota for all of them.
@@ -3427,6 +3701,7 @@ const MAIN = String.raw `
3427
3701
  setKids(box, kids)
3428
3702
  }
3429
3703
  window.addEventListener('hashchange', () => {
3704
+ if (/^#reset=/.test(location.hash)) { resetFromHash(); return }
3430
3705
  navSeq++
3431
3706
  curPage = pageFromHash()
3432
3707
  if (curPage === 'sessions') { const m = location.hash === '#live' ? 'live' : 'history'; if (m !== hs.mode) { hs.mode = m; sp.drawn = '' } }
@@ -6636,6 +6911,7 @@ const MAIN = String.raw `
6636
6911
  if (S.state && S.state.accounts.length && !BOOT.readOnly) out.push('order')
6637
6912
  out.push('ai')
6638
6913
  if (S.state && rcSummary()) out.push('rc')
6914
+ if (advSummary()) out.push('advisor')
6639
6915
  if (S.state && ahState()) out.push('ah')
6640
6916
  if (S.state && (S.state.quotaChecks || []).length) out.push('checks')
6641
6917
  if (S.state && S.state.network) out.push('net')
@@ -6650,6 +6926,7 @@ const MAIN = String.raw `
6650
6926
  b.setAttribute('aria-label', t('set.button') + (warn ? colon() + t('set.rcOn') : ''))
6651
6927
  refreshSettings()
6652
6928
  if (dlg.kind === 'rc') renderRc()
6929
+ if (dlg.kind === 'advisor') renderAdvisor()
6653
6930
  if (dlg.kind === 'net' && net) renderNet()
6654
6931
  }
6655
6932
  // The settings live in two places (spec §3.29, 2026-10-20). The header popover holds only what people change
@@ -6718,6 +6995,7 @@ const MAIN = String.raw `
6718
6995
  acct.push(fm('pick', link(t('pk.title'), names.length ? names.join(', ') : t('pk.noneYet'), names.length ? 'chip-ok' : '', () => openPick(null), true)))
6719
6996
  }
6720
6997
  if (secs.includes('rc')) acct.push(fm('rc', rcLink(leave)))
6998
+ if (secs.includes('advisor')) acct.push(fm('advisor', advLink(leave)))
6721
6999
  // Quota checks that ask the Host (spec §3.26): one switch per Family under one shared explanation.
6722
7000
  const checks = []
6723
7001
  let every = 15
@@ -6826,6 +7104,7 @@ const MAIN = String.raw `
6826
7104
  inbound: { run: openInbound, ok: () => Boolean(S.state) },
6827
7105
  'unattended-on': { run: () => uaGo('on'), ok: () => Boolean(uaStatusNow()), nav: true },
6828
7106
  'unattended-add-slot': { run: () => uaGo('add'), ok: () => Boolean(uaStatusNow()), nav: true },
7107
+ 'limit-reset': { run: openResetPick, ok: () => resetCandidates().length > 0 },
6829
7108
  }
6830
7109
  function palHealth() {
6831
7110
  setPage('accounts')
@@ -7423,8 +7702,10 @@ const MAIN = String.raw `
7423
7702
  else if (dlg.kind === 'model' && md) { md.form = null; renderModel() }
7424
7703
  else if (dlg.kind === 'alias' && al) renderAlias()
7425
7704
  else if (dlg.kind === 'browser') renderBrowser()
7705
+ else if (dlg.kind === 'reset' && rs) renderReset()
7426
7706
  else if (dlg.kind === 'update' && up) renderUpdate()
7427
7707
  else if (dlg.kind === 'rc') renderRc()
7708
+ else if (dlg.kind === 'advisor') renderAdvisor()
7428
7709
  else if (dlg.kind === 'inbound') renderInbound()
7429
7710
  else if (dlg.kind === 'ask' && ak) { if (ak.els.text) ak.text = ak.els.text.value; renderAsk() }
7430
7711
  else if (dlg.kind === 'key' && ky && ky.step !== 'enter') renderKey()
@@ -7446,7 +7727,7 @@ const MAIN = String.raw `
7446
7727
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
7447
7728
  }
7448
7729
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
7449
- 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.expired', '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.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
7730
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.reset', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.expired', '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.advisor', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
7450
7731
  // Network Guard (spec §3.35): one dialog with the switch, the allowed countries and the newest result per address.
7451
7732
  // Countries are never ticked for the user, the current one included: a wrong network would allow itself.
7452
7733
  const NET_COMMON = ['US', 'JP', 'SG', 'GB', 'DE', 'FR', 'NL', 'CA', 'AU', 'KR', 'TW', 'HK']
@@ -7610,6 +7891,137 @@ const MAIN = String.raw `
7610
7891
  setKids(dlg.el, dialogFrame(t('rc.dialogTitle'), null, body, foot))
7611
7892
  }
7612
7893
 
7894
+ // ---------- Advisor (spec §3.41, ADR-0074) ----------
7895
+ // Claude Code's advisor: one choice for every Claude settings file. Picking a model lists each file that changes, from
7896
+ // what to what, and that sideby will unlock /advisor at launch; only the confirmation writes, and its toast carries
7897
+ // the undo. The unlock switch is sideby's own setting, so it writes at once, also with an undo.
7898
+ // target: the choice waiting for its confirmation; null while nothing is chosen.
7899
+ const adv = { busy: false, target: null }
7900
+ const ADV_CHOICES = ['fable', 'opus', 'sonnet', 'off']
7901
+ function advState() { return S.state && S.state.advisor }
7902
+ function advSummary() { const a = advState(); return a ? advisorSummary(a.groups) : null }
7903
+ function advName(v) { return t('adv.state.' + v) }
7904
+ function advLink(leave) {
7905
+ const sum = advSummary()
7906
+ // A settings file that turns experimental features off hides the advisor whatever it names, so the row says that.
7907
+ if (advState().groups.some((g) => g.betasOff)) return setLink(leave, t('adv.button'), t('adv.state.betas'), 'chip-warn', openAdvisor, true)
7908
+ return setLink(leave, t('adv.button'), advName(sum), sum === 'off' || sum === 'mixed' ? '' : 'chip-ok', openAdvisor, true)
7909
+ }
7910
+ function openAdvisor() {
7911
+ if (!advState()) return
7912
+ adv.target = null
7913
+ showDialog('advisor')
7914
+ // Empty first, so the first render draws the dialog at its size instead of growing rows in.
7915
+ setKids(dlg.el, [])
7916
+ renderAdvisor()
7917
+ }
7918
+ // What advisorModel holds, as keyChange shows it: null is "not set".
7919
+ function advValue(g) { return g.state === 'off' ? null : g.state === 'other' ? (g.model ? '"' + g.model + '"' : t('adv.otherValue')) : '"' + g.state + '"' }
7920
+ // The server's own rule (core/advisor.ts), so the page offers exactly the change the server would make.
7921
+ function advPlan(st, to) { return to ? advisorPending(st.groups, to, st) : { todo: [], unlocks: false, apiBetas: false } }
7922
+ function renderAdvisor() {
7923
+ const st = advState()
7924
+ if (!st) { if (dlg.el && dlg.el.open) dlg.el.close(); return }
7925
+ const groups = st.groups
7926
+ const sum = advisorSummary(groups)
7927
+ const to = adv.target
7928
+ const { todo, unlocks, apiBetas } = advPlan(st, to)
7929
+ const changing = new Set(todo.map((g) => g.file))
7930
+ // API accounts on a file that loses the variable: sideby gives it to them at launch instead.
7931
+ const apiRefs = to && to !== 'off' ? todo.filter((g) => g.betasOff).flatMap((g) => g.apiAccounts || []) : []
7932
+ const ro = BOOT.readOnly
7933
+ const pick = (v) => { adv.target = advisorPick(v, sum, advPlan(st, v)); renderAdvisor() }
7934
+ const choose = h('div', { class: 'set-row rc-switch' }, h('span', null, t('adv.pick')),
7935
+ h('div', { class: 'seg', role: 'group', 'aria-label': t('adv.pick') }, ADV_CHOICES.map((v) =>
7936
+ h('button', { class: 'seg-btn', type: 'button', 'data-key': 'adv:' + v, disabled: ro || adv.busy, 'aria-pressed': String((to || sum) === v), onclick: () => pick(v) }, advName(v)))))
7937
+ const chip = (g) => g.state === 'blocked' ? 'chip-fail' : g.state === 'missing' || g.state === 'off' || g.state === 'other' ? '' : 'chip-ok'
7938
+ const rows = groups.map((g) => h('li', { class: 'rc-row', 'data-key': 'adv-row:' + g.file },
7939
+ h('div', null, h('code', null, g.file), ' ', h('span', { class: 'chip chip-sm ' + chip(g) }, g.state === 'other' && g.model ? g.model : advName(g.state))),
7940
+ h('div', { class: 'muted small' }, t('rc.usedBy', { refs: g.accounts.map(shortRef).join(', ') })),
7941
+ g.reason ? h('div', { class: 'muted small' }, g.why ? t('settings.why.' + g.why) : g.reason) : null,
7942
+ g.betasOff && g.apiAccounts ? h('div', { class: 'muted small' }, t('adv.apiUsedBy', { refs: g.apiAccounts.map(shortRef).join(', ') })) : null,
7943
+ g.betasOff ? h('div', { class: 'note note-warn small' }, t('adv.betasWarn', { v: 'CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS' })) : null,
7944
+ changing.has(g.file) && g.state !== to ? h('div', { class: 'small rc-change', 'data-enter': 'adv-change:' + to + ':' + g.file }, keyChange('advisorModel', advValue(g), to === 'off' ? null : '"' + to + '"')) : null,
7945
+ changing.has(g.file) && to !== 'off' && g.betasOff ? h('div', { class: 'small rc-change', 'data-enter': 'adv-betas:' + g.file },
7946
+ h('span', { class: 'key-change' }, h('code', null, 'env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS'), ' ', h('code', null, g.betasValue), ' → ', t('adv.removed'))) : null))
7947
+ const body = [h('p', { class: 'small' }, t('adv.explain')), choose, h('ul', { class: 'rc-list' }, rows)]
7948
+ if (to && to !== 'off' && todo.some((g) => g.betasOff)) body.push(h('div', { class: 'note note-warn small', 'data-enter': 'adv-betas-note' }, t('adv.betasNote')))
7949
+ if (apiRefs.length) {
7950
+ const refs = apiRefs.map(shortRef).join(', ')
7951
+ body.push(apiBetas
7952
+ ? h('div', { class: 'note small', 'data-enter': 'adv-api-note' }, t('adv.apiNote', { refs }), ' ', h('code', null, 'CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1'))
7953
+ : h('div', { class: 'note small', 'data-enter': 'adv-api-already' }, t('adv.apiAlready', { refs })))
7954
+ }
7955
+ if (to && (todo.length || unlocks)) {
7956
+ if (unlocks) body.push(h('div', { class: 'note small', 'data-enter': 'adv-unlocks' }, t('adv.unlockNote'), ' ', h('code', null, 'CLAUDE_CODE_ENABLE_EXPERIMENTAL_ADVISOR_TOOL=1')))
7957
+ body.push(h('p', { class: 'small muted', 'data-enter': 'adv-note:' + (to === 'off' ? 'off' : 'on') }, t(to === 'off' ? 'adv.offNote' : 'adv.onNote')))
7958
+ } else if (to) body.push(h('p', { class: 'small muted', 'data-enter': 'adv-nothing' }, t('adv.nothing')))
7959
+ // sideby's own switch: whether the sessions it starts get the variable that shows /advisor.
7960
+ body.push(h('div', { class: 'set-row rc-switch adv-unlock' },
7961
+ h('div', { class: 'set-text' }, h('span', { class: 'set-label' }, t('adv.unlockSwitch')), h('span', { class: 'set-hint' }, t('adv.unlockHint'))),
7962
+ h('div', { class: 'seg', role: 'group', 'aria-label': t('adv.unlockSwitch') }, [[true, t('ah.on')], [false, t('ah.off')]].map(([v, text]) =>
7963
+ h('button', { class: 'seg-btn', type: 'button', 'data-key': 'adv-unlock:' + v, disabled: ro || adv.busy, 'aria-pressed': String(st.unlock === v), onclick: () => { if (st.unlock !== v) setAdvisorUnlock(v) } }, text)))))
7964
+ // sideby's other setting here: whether API accounts get the variable at launch (config claude.apiBetasOff).
7965
+ // While the chosen change turns it on, the note above already says so; the current "no" would read as a contradiction.
7966
+ if ((st.apiBetasOff || groups.some((g) => g.apiAccounts)) && !apiBetas) body.push(h('p', { class: 'small muted', 'data-enter': 'adv-api-state' }, t(st.apiBetasOff ? 'adv.apiOn' : 'adv.apiOff', { v: 'CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS' })))
7967
+ if (st.envOff) body.push(h('div', { class: 'note note-warn small' }, t('adv.envOff', { v: st.envOff })))
7968
+ body.push(h('p', { class: 'small muted' }, t('adv.unavailable')))
7969
+ if (ro) body.push(h('p', { class: 'small' }, t('adv.readOnly')))
7970
+ if (!askBridged(BOOT, window)) body.push(h('p', { class: 'small' }, h('button', { class: 'link-btn small', type: 'button', 'data-key': 'adv-ask', onclick: () => openAsk({ text: t('ai.ask.advisor') }) }, t('adv.ask'))))
7971
+ const foot = [h('button', { class: 'btn', type: 'button', 'data-key': 'adv-close', disabled: adv.busy, onclick: () => { if (!to) dlg.el.close(); else { adv.target = null; renderAdvisor() } } }, t(to ? 'btn.cancel' : 'btn.close'))]
7972
+ if (!ro && !to && groups.some((g) => g.undo)) foot.push(h('button', { class: 'btn', type: 'button', 'data-key': 'adv-undo', disabled: adv.busy, onclick: advisorUndo }, t('adv.undo')))
7973
+ if (!ro && to) foot.push(h('button', { class: 'btn btn-primary', type: 'button', 'data-key': 'adv-confirm', disabled: adv.busy || !(todo.length || unlocks), 'aria-busy': adv.busy ? 'true' : null, onclick: () => setAdvisorModel(to) }, adv.busy ? spinner() : null, to === 'off' ? t('adv.confirmOff') : t('adv.confirmUse', { m: advName(to) })))
7974
+ patchEnter(dlg.el, dialogFrame(t('adv.title'), null, body, foot))
7975
+ }
7976
+ function advBusy(v) {
7977
+ adv.busy = v
7978
+ if (dlg.kind === 'advisor') renderAdvisor()
7979
+ }
7980
+ async function setAdvisorModel(to) {
7981
+ const st = advState()
7982
+ if (!st) return
7983
+ const files = advPlan(st, to).todo.map((g) => g.file)
7984
+ advBusy(true)
7985
+ try {
7986
+ const r = await api('/api/advisor/set', { confirm: true, to, files })
7987
+ if (r.changedSince) toast(t('as.changedSince'), { kind: 'fail' })
7988
+ else if (r.ok) {
7989
+ // Show the new state now; the reload that follows confirms it.
7990
+ const changed = new Set(files)
7991
+ // A model also removed the variable that turned experimental features off; off leaves it.
7992
+ const base = (g) => g.apiAccounts ? { file: g.file, accounts: g.accounts, apiAccounts: g.apiAccounts } : { file: g.file, accounts: g.accounts }
7993
+ const after = (g) => to === 'off' && g.betasOff ? { ...base(g), state: to, betasOff: true, betasValue: g.betasValue, undo: true } : { ...base(g), state: to, undo: true }
7994
+ S.state.advisor = { ...st, unlock: st.unlock || Boolean(r.unlocked), apiBetasOff: st.apiBetasOff || r.apiBetas === true, groups: st.groups.map((g) => changed.has(g.file) ? after(g) : g) }
7995
+ adv.target = null
7996
+ toast(to === 'off' ? t('adv.doneOff') : t('adv.done', { m: advName(to) }), { kind: 'ok', action: { label: t('toast.undo'), run: advisorUndo }, duration: 12000 })
7997
+ } else toast(t('adv.failed', { msg: r.message }), { kind: 'fail' })
7998
+ } catch (e) { toast(t('adv.failed', { msg: e.message }), { kind: 'fail' }) }
7999
+ advBusy(false)
8000
+ refreshSettings()
8001
+ await load({ silent: true })
8002
+ }
8003
+ async function advisorUndo() {
8004
+ advBusy(true)
8005
+ try {
8006
+ const r = await api('/api/advisor/undo', { confirm: true })
8007
+ toast(r.ok ? t('adv.undone') : r.message, { kind: r.ok ? 'ok' : 'fail' })
8008
+ } catch (e) { toast(t('toast.undoFailed', { msg: e.message }), { kind: 'fail' }) }
8009
+ advBusy(false)
8010
+ await load({ silent: true })
8011
+ }
8012
+ async function setAdvisorUnlock(on) {
8013
+ advBusy(true)
8014
+ try {
8015
+ const r = await api('/api/advisor/unlock', { on })
8016
+ if (r.unlock === on) {
8017
+ if (advState()) S.state.advisor = { ...advState(), unlock: on }
8018
+ toast(t(on ? 'adv.unlockOn' : 'adv.unlockOff'), { kind: 'ok', action: { label: t('toast.undo'), run: () => setAdvisorUnlock(!on) }, duration: 8000 })
8019
+ } else toast(t('adv.failed', { msg: r.message }), { kind: 'fail' })
8020
+ } catch (e) { toast(t('adv.failed', { msg: e.message }), { kind: 'fail' }) }
8021
+ advBusy(false)
8022
+ await load({ silent: true })
8023
+ }
8024
+
7613
8025
  // ---------- AI Tasks (spec §3.28) ----------
7614
8026
  // One dialog for every "let AI do it" entry: what to do, then the account and the terminal it will use, then one
7615
8027
  // button. When nothing can run it, or the panel is read-only, it copies the prompt instead.
@@ -8669,7 +9081,7 @@ const MAIN = String.raw `
8669
9081
  try { state = await api('/api/state') } catch (e) { error = e }
8670
9082
  if (seq === loadSeq) {
8671
9083
  if (state) {
8672
- if (!S.state) ui.fade = true
9084
+ if (!S.state) { ui.fade = true; S.firstAt = Date.now() }
8673
9085
  S.state = state; S.loadError = null; S.loadedAt = Date.now()
8674
9086
  // The server now runs another build (sideby was reinstalled and restarted): this page's script is old.
8675
9087
  if (state.build && BOOT.build && state.build !== BOOT.build && !S.newBuild) {
@@ -8692,6 +9104,7 @@ const MAIN = String.raw `
8692
9104
  else toast(t('toast.refreshFailed', { msg: error.message }), { kind: 'fail' })
8693
9105
  }
8694
9106
  if (S.state && opts.check) runCheck()
9107
+ resetFromHash()
8695
9108
  reloadForNewBuild()
8696
9109
  }
8697
9110
  // Reloads into the new build once the viewer is not in the middle of something (a dialog, a form, a selection).
@@ -8716,11 +9129,18 @@ const MAIN = String.raw `
8716
9129
  const pending = S.state.accounts.some((a) => a.pending)
8717
9130
  if (!pending) S.pendingSince = 0
8718
9131
  else if (!S.pendingSince) S.pendingSince = now
8719
- const every = pending && now - S.pendingSince < 30_000 ? PENDING_MS : now < S.fastUntil ? FAST_MS : AUTO_MS
9132
+ // A Host being asked for its Quota behind the kept answer (spec §3.26): its row takes the new numbers as soon as
9133
+ // they land, without waiting for the next round. For half a minute, as above: an ask ends after 20 s.
9134
+ const asking = (S.state.quotaAsking || []).length > 0
9135
+ if (!asking) S.askingSince = 0
9136
+ else if (!S.askingSince) S.askingSince = now
9137
+ const every = pending && now - S.pendingSince < 30_000 ? PENDING_MS : asking && now - S.askingSince < 30_000 ? ASKING_MS : now < S.fastUntil ? FAST_MS : AUTO_MS
8720
9138
  if (!S.loading && !conn.lost && !S.fixing && !S.checking && !dlg.busy && now - S.lastTry >= every) load({ silent: true })
8721
9139
  }
8722
9140
  // Coming back to the page refreshes at once.
8723
9141
  function wake() {
9142
+ // Back from the vendor's page a Limit Reset is used on: that account's quota is asked once (ADR-0072).
9143
+ if (resetJump.ref && resetJump.away) { resetReturned(); return }
8724
9144
  if (document.visibilityState !== 'visible' || !S.state || S.loading || conn.lost) return
8725
9145
  if (Date.now() - S.lastTry > 3000) load({ silent: true })
8726
9146
  }
@@ -9174,7 +9594,8 @@ const MAIN = String.raw `
9174
9594
  // The sessions too, so the Sessions page opens with its rows already there.
9175
9595
  loadSessions()
9176
9596
  setInterval(tick, 1000)
9177
- document.addEventListener('visibilitychange', wake)
9597
+ document.addEventListener('visibilitychange', () => { if (document.visibilityState !== 'visible') resetLeft(); wake() })
9598
+ window.addEventListener('blur', resetLeft)
9178
9599
  window.addEventListener('focus', wake)
9179
9600
  // A Portal that changed something the Panel shows says so (ADR-0006): read the state now instead of at the next
9180
9601
  // round, and the Unattended page its list too, so the Portal's switch and this page never disagree for long.