sideby 0.43.0 → 0.44.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.
@@ -6,7 +6,7 @@ import { groupsToAccept } from '../core/inbound.js';
6
6
  import { limitResetOffer, quotaAge, quotaIsStale, windowAge } from '../core/quota-levels.js';
7
7
  import { remoteControlTodo } from '../core/remote-control.js';
8
8
  import { catalogMatchLevel, catalogNorm, searchCatalog } from '../core/search-catalog.js';
9
- import { accountTitle, advisorPick, advisorSummary, aiTaskAccounts, aliasArgsOf, aliasIssue, aliasPrefix, askBridge, askBridged, askCopy, askPermissionNote, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dateFormatter, dotsKeepKeyboard, enableOutcome, expiredLogins, fileSize, findingSentence, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyRowSig, historyWhen, historyWhenNext, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, longWindow, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, messageToCheck, networkDiagnoseTaskFacts, 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, startedFromView, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, toastMerge, uaDayRuns, uaGroupByProject, 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, dateFormatter, dotsKeepKeyboard, enableOutcome, expiredLogins, fileSize, findingSentence, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyRowSig, historyWhen, historyWhenNext, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, longWindow, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, messageToCheck, networkDiagnoseTaskFacts, networkTaskFacts, newAccountDir, nextReset, openBridge, openBridged, orderedAliases, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pickNowChoice, pinnedIn, portalRefresh, quotaAskable, quotaHighLevel, quotaPressure, radioStep, reloadForBuild, remoteControlSummary, reorder, resetWhen, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, sessionRowShape, shortCwd, shortSessionLabel, sortAccounts, sortMenu, sortSessions, startedFromView, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, toastMerge, uaDayRuns, uaGroupByProject, uaGroupPending, uaOnChoices, uaParseClock, uaPickTime, uaSameSlot, uaShouldRead, uaSlotNight, uaStatusParts, uaStepClock, uaToggleDay, uaWaitingCount, uaWhen, updatedAge, vendorAlias, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
10
10
  // The component library's dropdown menu, copied by the brand repo's add script (--html into ui/); do not edit it.
11
11
  import { CHECK, menuItem, menuScript } from './ui/dropdown-menu/dropdown-menu.html.js';
12
12
  import { cn, esc } from './ui/lib/cn.js';
@@ -78,6 +78,7 @@ const LOGIC = [
78
78
  longWindow,
79
79
  newAccountDir,
80
80
  nextReset,
81
+ pickNowChoice,
81
82
  canLeaveLocal,
82
83
  codeSwapOutcome,
83
84
  dateFormatter,
@@ -190,6 +191,10 @@ const MAIN = String.raw `
190
191
  // View state that is not saved: the search text, the attention filter, the Health check filter.
191
192
  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 }
192
193
  const $ = (id) => document.getElementById(id)
194
+ // The change feed (spec §3.45, ADR-0084): seq, the server's count of Quota file changes this page has seen; ctl, the
195
+ // held request; watching, whether the server watches any file; retryAt, when to ask again after a failure or while
196
+ // nothing is watched; off, an older server without the feed.
197
+ const chg = { seq: null, ctl: null, watching: false, retryAt: 0, off: false }
193
198
 
194
199
  // ---------- preferences ----------
195
200
  // Kept in localStorage, which can be missing or throw (private windows, blocked storage): every access is guarded
@@ -1326,14 +1331,16 @@ const MAIN = String.raw `
1326
1331
  function renderUpdated() {
1327
1332
  const busy = S.loading && !S.silent
1328
1333
  const every = Math.round((S.fastUntil > Date.now() ? FAST_MS : AUTO_MS) / 1000)
1329
- const text = S.loading && !S.state ? t('top.loading') : busy ? t('top.refreshing') : S.loadedAt ? t('top.updated', { ago: agoShort(Date.now() - S.loadedAt), s: every }) : ''
1334
+ // While Quota files are watched (spec §3.45), new numbers come as they land, not on the next round.
1335
+ const live = chg.watching && every === AUTO_MS / 1000
1336
+ const text = S.loading && !S.state ? t('top.loading') : busy ? t('top.refreshing') : S.loadedAt ? t(live ? 'top.updatedLive' : 'top.updated', { ago: agoShort(Date.now() - S.loadedAt), s: every }) : ''
1330
1337
  const el = $('updated')
1331
1338
  if (el.textContent !== text) el.textContent = text
1332
1339
  // A dot says whether the numbers are live: green while they refresh on their own, amber when they stopped.
1333
1340
  const stale = conn.lost || Boolean(S.loadError)
1334
1341
  el.classList.toggle('is-live', Boolean(S.loadedAt) && !stale)
1335
1342
  el.classList.toggle('is-stale', Boolean(S.loadedAt) && stale)
1336
- el.title = !S.loadedAt ? '' : (stale ? t('top.stale') + ' ' : '') + t('top.updatedTitle', { at: clock(new Date(S.loadedAt).toISOString()), s: Math.round((S.fastUntil > Date.now() ? FAST_MS : AUTO_MS) / 1000) })
1343
+ el.title = !S.loadedAt ? '' : (stale ? t('top.stale') + ' ' : '') + t(live ? 'top.updatedTitleLive' : 'top.updatedTitle', { at: clock(new Date(S.loadedAt).toISOString()), s: every })
1337
1344
  }
1338
1345
  function renderTop() {
1339
1346
  renderUpdated()
@@ -1370,8 +1377,8 @@ const MAIN = String.raw `
1370
1377
  }
1371
1378
  function stat(label, value, sub, extra, opts) {
1372
1379
  const kids = [h('div', { class: 'stat-text' }, h('div', { class: 'stat-label' }, label), h('div', { class: 'stat-value' }, value), h('div', { class: 'stat-sub' }, sub)), extra]
1373
- if (opts && opts.onclick) return h('button', { class: 'stat stat-btn' + (opts.cls ? ' ' + opts.cls : ''), type: 'button', 'aria-pressed': String(Boolean(opts.pressed)), 'aria-label': t('stat.btnLabel', { label, value, sub, action: opts.title || '' }), title: opts.title, onclick: opts.onclick }, kids)
1374
- return h('div', { class: 'stat' + (opts && opts.cls ? ' ' + opts.cls : '') }, kids)
1380
+ if (opts && opts.onclick) return h('button', { class: 'stat stat-btn' + (opts.cls ? ' ' + opts.cls : ''), type: 'button', 'aria-pressed': opts.pressed === undefined ? null : String(Boolean(opts.pressed)), 'aria-label': t('stat.btnLabel', { label, value, sub, action: opts.title || '' }), title: opts.title, onclick: opts.onclick }, kids)
1381
+ return h('div', { class: 'stat' + (opts && opts.cls ? ' ' + opts.cls : ''), title: (opts && opts.title) || null }, kids)
1375
1382
  }
1376
1383
  function spark(daily, cls) {
1377
1384
  if (!Array.isArray(daily) || !daily.length) return null
@@ -1417,6 +1424,7 @@ const MAIN = String.raw `
1417
1424
  const daily = mergeDaily(usages.map((a) => a.usage.daily)).slice(-BOOT.usageDays)
1418
1425
  const nr = nextReset(list, now)
1419
1426
  patch(box, [
1427
+ pickNowStat(list, now),
1420
1428
  stat(t('stat.accounts'), String(list.length), dots([tn('stat.families', famCount), apiCount ? tn('stat.api', apiCount) : null])),
1421
1429
  need
1422
1430
  ? stat(t('stat.attention'), String(need), needSub, h('span', { class: 'stat-act' }, t(ui.attention ? 'stat.attentionOff' : 'stat.attentionOn')), { cls: 'stat-warn', pressed: ui.attention, title: [needTitle, t(ui.attention ? 'stat.attentionOff' : 'stat.attentionOn')].join('\n'), onclick: () => { ui.attention = !ui.attention; renderSummary(); renderAccounts() } })
@@ -1428,6 +1436,52 @@ const MAIN = String.raw `
1428
1436
  ])
1429
1437
  }
1430
1438
 
1439
+ // "Best to use now" (spec §3.45): the account sideby next would pick in one tool, the quota it has left, and one click
1440
+ // that starts it. One value line and one line under it in every state, so the card keeps its size as answers change.
1441
+ function pickNowStat(list, now) {
1442
+ const pn = S.state.pickNow || {}
1443
+ const shownFams = new Set(list.map((a) => a.family))
1444
+ const choice = pickNowChoice(pn, familyOrder().filter((f) => shownFams.has(f)), prefs.family || '')
1445
+ const card = (label, value, sub, extra, opts) => stat(label, value, sub, extra, Object.assign({ cls: 'stat-pick' }, opts, { cls: 'stat-pick' + (opts && opts.cls ? ' ' + opts.cls : '') }))
1446
+ if (!choice) {
1447
+ const reading = list.some((a) => a.kind === 'subscription' && (a.pending || a.usagePending))
1448
+ return card(t('stat.pickNow'), '—', t(reading ? 'stat.pickReading' : prefs.family ? 'stat.pickNoSourceOne' : 'stat.pickNoSource'))
1449
+ }
1450
+ const fam = choice.family
1451
+ const e = pn[fam]
1452
+ const subs = list.filter((a) => a.family === fam && a.kind === 'subscription')
1453
+ const label = [...shownFams].filter((f) => pn[f]).length > 1 ? t('stat.pickNowIn', { title: family(fam).title }) : t('stat.pickNow')
1454
+ const shownName = (ref) => { const a = S.state.accounts.find((x) => x.ref === ref); return (a && a.aliases && a.aliases[0]) || ref }
1455
+ // Why a tool has no pick, in a few words: "All used up · claude:main is back in 1h 35m".
1456
+ const noPick = (x) => x.why === 'used-up' ? t('stat.pickUsedUp') + ' · ' + (x.earliestReset ? t('stat.pickBack', { ref: shownName(x.earliestReset.ref), when: t('time.in', { d: formatDuration(Math.max(0, Date.parse(x.earliestReset.at) - now), lang) }) }) : t('stat.pickWait')) : t(x.why === 'no-quota' ? 'stat.pickNoQuota' : 'stat.pickSignIn')
1457
+ const others = choice.others.length ? t('stat.pickOthers', { list: '' }) + '\n' + choice.others.map((f) => family(f).title + colon() + (pn[f].pick ? shownName(pn[f].pick) : noPick(pn[f]))).join('\n') : null
1458
+ if (!e.pick) {
1459
+ if (e.why === 'used-up') {
1460
+ const back = e.earliestReset ? t('stat.pickBack', { ref: shownName(e.earliestReset.ref), when: t('time.in', { d: formatDuration(Math.max(0, Date.parse(e.earliestReset.at) - now), lang) }) }) : t('stat.pickWait')
1461
+ return card(label, t('stat.pickUsedUp'), back, null, { cls: 'stat-warn', title: [e.earliestReset ? clock(e.earliestReset.at) : null, others].filter(Boolean).join('\n') || null })
1462
+ }
1463
+ return card(label, '—', t(e.why === 'no-quota' ? 'stat.pickNoQuota' : 'stat.pickSignIn'), null, { title: [e.why === 'no-quota' ? t('stat.pickNoQuotaTip') : null, others].filter(Boolean).join('\n') || null })
1464
+ }
1465
+ const a = S.state.accounts.find((x) => x.ref === e.pick)
1466
+ const left = pickLeft(a, now)
1467
+ const sub = e.reason === 'unknown' ? t('stat.pickNoData') : e.reason === 'tight' ? t('stat.pickTight') + ' · ' + left : left
1468
+ const keys = { expiring: 'acct.nextWhyExpiring', room: 'acct.nextWhyRoom', tight: 'acct.nextWhyTight', unknown: 'acct.nextWhyUnknown' }
1469
+ const why = subs.length > 1 ? t(keys[e.reason] || 'acct.nextWhy', { title: family(fam).title }) : t('stat.pickOnly', { title: family(fam).title })
1470
+ const act = BOOT.readOnly ? t('stat.pickCopyTip', { family: fam }) : t('stat.pickStartTip')
1471
+ // A short command on the card: the account's full name heads the hover text.
1472
+ const title = [shownName(e.pick) !== e.pick ? e.pick : null, why, e.running ? tn('acct.nextRunning', e.running) : null, others, act].filter(Boolean).join('\n')
1473
+ return card(label, shownName(e.pick), sub, h('span', { class: 'stat-act' }, icon(BOOT.readOnly ? 'copy' : 'terminal'), t(BOOT.readOnly ? 'stat.pickCopy' : 'stat.pickStart')),
1474
+ { cls: 'stat-acct' + (e.reason === 'tight' ? ' stat-warn' : ''), title, onclick: () => (BOOT.readOnly ? copyText('sideby next ' + fam) : startPick(null, fam)) })
1475
+ }
1476
+ // The quota an account has left in each counted window, shortest first: "5-hour 72% left · Weekly 40% left".
1477
+ function pickLeft(a, now) {
1478
+ const q = a && a.quota
1479
+ if (!q || q.status !== 'ok') return t('stat.pickNoData')
1480
+ const wins = (q.windows || []).filter((w) => !w.name).slice().sort((x, y) => (Number(x.windowMinutes) || 0) - (Number(y.windowMinutes) || 0))
1481
+ if (!wins.length) return t('stat.pickNoData')
1482
+ return wins.map((w) => passedWindow(w, q.observedAt, now) ? t('stat.pickReset', { w: winShort(w.label) }) : t('stat.pickLeft', { w: winShort(w.label), n: String(Math.max(0, 100 - Math.round(Number(w.usedPercent) || 0))) })).join(' · ')
1483
+ }
1484
+
1431
1485
  // ---------- toolbar ----------
1432
1486
  const tb = {}
1433
1487
  function seg(label, options, value, onPick) {
@@ -1918,6 +1972,13 @@ const MAIN = String.raw `
1918
1972
  }
1919
1973
  function usageBlock(a) {
1920
1974
  const u = a.usage
1975
+ // Its usage is still being parsed while the rest is in: two lines, as the numbers take, so the row keeps its height.
1976
+ if (!u && a.usagePending) {
1977
+ return h('div', { class: 'usage', 'aria-busy': 'true' },
1978
+ h('div', { class: 'u-text' },
1979
+ h('span', { class: 'u-num faint' }, '—'),
1980
+ h('div', { class: 'u-sub' }, t('acct.reading', { host: famTitle(a) }))))
1981
+ }
1921
1982
  if (!u) return h('div', { class: 'usage' })
1922
1983
  if (u.status !== 'ok') {
1923
1984
  const key = u.reason === 'no-session' ? 'usage.none' : u.reason === 'no-source' ? 'usage.noSource' : 'usage.unreadable'
@@ -9171,13 +9232,16 @@ const MAIN = String.raw `
9171
9232
  const input = fam && document.getElementById('pk-name-' + fam)
9172
9233
  if (input) input.focus()
9173
9234
  }
9174
- async function startPick(name) {
9235
+ // By the Pick Command's name, or by tool (the "Best to use now" card, spec §3.45).
9236
+ async function startPick(name, fam) {
9175
9237
  if (BOOT.readOnly) { copyText(name, name); return }
9176
9238
  try {
9177
- const r = await api('/api/pick/start', { name })
9239
+ const r = await api('/api/pick/start', name ? { name } : { family: fam })
9178
9240
  const why = r.reason === 'most-room' ? t(r.expiring ? 'pk.why.expiring' : r.running ? 'pk.why.roomRunning' : 'pk.why.room', { n: String(r.pressure), w: r.window ? winTitle(r.window) + ' ' : '', running: String(r.running || 0) }) : r.reason === 'tight' ? t('pk.why.tight', { n: String(r.pressure), w: r.window ? winTitle(r.window) + ' ' : '', limit: String(r.limit), longLimit: String(r.longLimit) }) : t(r.reason === 'others-full' ? 'pk.why.othersFull' : 'pk.why.noData')
9179
- if (r.opened) { toast(t('pk.started', { terminal: TERM_NAMES[r.terminal] || r.terminal, ref: r.picked, why })); return }
9180
- await copyText(name, name)
9241
+ // The start counts for the next pick (ADR-0083): the card and the Next mark move on at once.
9242
+ if (r.opened) { toast(t('pk.started', { terminal: TERM_NAMES[r.terminal] || r.terminal, ref: r.picked, why })); load({ silent: true }); return }
9243
+ const cmd = name || 'sideby run ' + r.picked
9244
+ await copyText(cmd, cmd)
9181
9245
  toast(r.automation ? t('login.automation', { terminal: TERM_NAMES[r.terminal] || r.terminal }) : t('login.failed'), { kind: 'info' })
9182
9246
  } catch (e) { toast(e.message, { kind: 'fail' }) }
9183
9247
  }
@@ -9580,11 +9644,12 @@ const MAIN = String.raw `
9580
9644
  sessionsTick()
9581
9645
  messagesTick()
9582
9646
  if (document.visibilityState !== 'visible' || !S.state) return
9647
+ watchChanges()
9583
9648
  if (S.pending && !S.loading && !uiBusy()) { S.pending = false; renderAll() }
9584
9649
  const now = Date.now()
9585
9650
  // An Account still being read is asked for again soon, so it fills in without waiting for the next round.
9586
9651
  // For half a minute: the server says "took too long" after a minute, which the normal round then shows.
9587
- const pending = S.state.accounts.some((a) => a.pending)
9652
+ const pending = S.state.accounts.some((a) => a.pending || a.usagePending || a.refreshing)
9588
9653
  if (!pending) S.pendingSince = 0
9589
9654
  else if (!S.pendingSince) S.pendingSince = now
9590
9655
  // A Host being asked for its Quota behind the kept answer (spec §3.26): its row takes the new numbers as soon as
@@ -9595,6 +9660,35 @@ const MAIN = String.raw `
9595
9660
  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
9596
9661
  if (!S.loading && !conn.lost && !S.fixing && !S.checking && !dlg.busy && now - S.lastTry >= every) load({ silent: true })
9597
9662
  }
9663
+ // One request held open while the page is visible: the server answers it when a Quota file changes, and the page
9664
+ // reads its state at once. Not through api(): a request this page stops when hidden is not a lost connection.
9665
+ async function watchChanges() {
9666
+ if (chg.ctl || chg.off || conn.lost || document.visibilityState !== 'visible' || Date.now() < chg.retryAt) return
9667
+ const ctl = new AbortController()
9668
+ chg.ctl = ctl
9669
+ let res = null
9670
+ let data = null
9671
+ try {
9672
+ res = await fetch(BOOT.basePath + '/api/changes' + (chg.seq === null ? '' : '?since=' + chg.seq), { cache: 'no-store', signal: ctl.signal })
9673
+ if (res.ok) data = await res.json()
9674
+ } catch {}
9675
+ chg.ctl = null
9676
+ if (res && res.status === 404) { chg.off = true; chg.watching = false; renderUpdated(); return }
9677
+ if (!data || typeof data.seq !== 'number') {
9678
+ if (!ctl.signal.aborted) chg.retryAt = Date.now() + 5000
9679
+ return
9680
+ }
9681
+ chg.seq = data.seq
9682
+ if (chg.watching !== Boolean(data.watching)) { chg.watching = Boolean(data.watching); renderUpdated() }
9683
+ if (!data.watching) chg.retryAt = Date.now() + 60000
9684
+ if (data.changed) quotaChanged()
9685
+ watchChanges()
9686
+ }
9687
+ // A Quota file changed: read now, or, while a check, a fix or a dialog's work runs, at the first tick after it.
9688
+ function quotaChanged() {
9689
+ if (!conn.lost && !S.fixing && !S.checking && !dlg.busy) load({ silent: true })
9690
+ else S.lastTry = 0
9691
+ }
9598
9692
  // Coming back to the page refreshes at once.
9599
9693
  function wake() {
9600
9694
  // Back from the vendor's page a Limit Reset is used on: that account's quota is asked once (ADR-0072).
@@ -10052,7 +10146,11 @@ const MAIN = String.raw `
10052
10146
  // The sessions too, so the Sessions page opens with its rows already there.
10053
10147
  loadSessions()
10054
10148
  setInterval(tick, 1000)
10055
- document.addEventListener('visibilitychange', () => { if (document.visibilityState !== 'visible') resetLeft(); wake() })
10149
+ document.addEventListener('visibilitychange', () => {
10150
+ // A hidden page holds no request: browsers give a site only a few connections.
10151
+ if (document.visibilityState !== 'visible') { resetLeft(); if (chg.ctl) chg.ctl.abort() }
10152
+ wake()
10153
+ })
10056
10154
  window.addEventListener('blur', resetLeft)
10057
10155
  window.addEventListener('focus', wake)
10058
10156
  // A Portal that changed something the Panel shows says so (ADR-0006): read the state now instead of at the next
@@ -141,7 +141,7 @@ code, .mono { font-family: var(--mono); font-size: 12px; }
141
141
  .theme-bad { color: var(--fail); }
142
142
  .theme-fade, .theme-fade * { transition: background-color var(--duration-base) var(--ease-out), color var(--duration-base) var(--ease-out), border-color var(--duration-base) var(--ease-out), fill var(--duration-base) var(--ease-out) !important; }
143
143
  @media (prefers-reduced-motion: reduce) { .theme-fade, .theme-fade * { transition: none !important; } }
144
- /* Summary: four quiet numbers in one surface. */
144
+ /* Summary: the account to use now on a line of its own, then four quiet numbers, in one surface. */
145
145
  .summary[hidden], #checkup[hidden] { display: none; }
146
146
  .summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
147
147
  .stat { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; min-width: 0; padding: 16px 20px; border-left: 1px solid var(--border); text-align: left; }
@@ -155,6 +155,13 @@ code, .mono { font-family: var(--mono); font-size: 12px; }
155
155
  .stat-btn[aria-pressed=true] { background: var(--selected); color: var(--brand); }
156
156
  .stat-warn .stat-value { color: var(--warn); }
157
157
  .stat-ok .stat-value { color: var(--ok); }
158
+ .stat-pick { grid-column: 1 / -1; align-items: center; min-height: 56px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
159
+ .stat-pick + .stat { border-left: 0; }
160
+ .stat-pick .stat-text { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; }
161
+ .stat-pick .stat-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
162
+ .stat-acct .stat-value { font-family: var(--mono); font-size: 18px; letter-spacing: 0; }
163
+ .stat-pick .stat-act { align-self: center; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
164
+ .sk-pick { height: 24px; width: 45%; }
158
165
  .label-tip { display: inline-flex; align-items: center; gap: 8px; }
159
166
 
160
167
  /* Toolbar */
@@ -1034,7 +1041,8 @@ ${UI_CSS}
1034
1041
  .sk-title { height: 12px; width: 22%; }
1035
1042
  .sk-bar { height: 8px; flex: 1; max-width: 160px; margin-left: auto; }
1036
1043
  .sk-line { height: 12px; margin: 8px 0; }
1037
- .sk-stat { height: 40px; margin: 16px 20px; }
1044
+ /* As tall as a card's label, number and line under it, so the summary keeps its height when the numbers land. */
1045
+ .sk-stat { height: 47px; margin: 8px 0; }
1038
1046
  .w50 { width: 50%; } .w70 { width: 70%; }
1039
1047
  @keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
1040
1048
  .view-in > * { animation: view-in var(--duration-base) var(--ease-out) both; }
@@ -1085,8 +1093,8 @@ ${UI_CSS}
1085
1093
  .toolbar > .btn-primary { width: var(--ctl-h); padding: 0; justify-content: center; }
1086
1094
  .toolbar > .btn-primary > span { display: none; }
1087
1095
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1088
- .stat:nth-child(3) { border-left: 0; }
1089
- .stat:nth-child(n+3) { border-top: 1px solid var(--border); }
1096
+ .stat:nth-child(4) { border-left: 0; }
1097
+ .stat:nth-child(n+4) { border-top: 1px solid var(--border); }
1090
1098
  }
1091
1099
  :root[data-width=phone] { --gutter: 14px; }
1092
1100
  :where(:root[data-width=phone]) {
@@ -1119,10 +1127,11 @@ ${UI_CSS}
1119
1127
  #accounts { --col-gap: 14px; }
1120
1128
  /* One window per line, so the reset time is never cut off. */
1121
1129
  .row > .quota { grid-template-columns: 1fr; row-gap: 12px; max-width: none; }
1122
- /* On a phone the summary keeps what needs a look and the next reset. */
1123
- .stat:nth-child(1), .stat:nth-child(3) { display: none; }
1124
- .stat:nth-child(n) { border-top: 0; }
1125
- .stat:nth-child(4) { border-left: 1px solid var(--border); }
1130
+ /* On a phone the summary keeps the account to use now, what needs a look and the next reset. */
1131
+ .stat:nth-child(2), .stat:nth-child(4) { display: none; }
1132
+ .stat:nth-child(3) { border-left: 0; }
1133
+ .stat:nth-child(5) { border-left: 1px solid var(--border); border-top: 0; }
1134
+ .stat-pick { flex-direction: row; align-items: center; padding: 12px 12px; }
1126
1135
  .row-end .icon-btn { width: 36px; height: 36px; }
1127
1136
  .sess-row { grid-template-columns: auto minmax(0, 1fr); row-gap: 12px; }
1128
1137
  .sess-actions { grid-column: 2; }
@@ -35,6 +35,8 @@ function attr(value) {
35
35
  // layout; the page script then follows the width as it changes.
36
36
  const SKELETON_ROW = `<div class="sk-row"><span class="sk sk-badge"></span><span class="sk sk-title"></span><span class="sk sk-bar"></span><span class="sk sk-bar"></span></div>`;
37
37
  const SKELETON_STAT = `<div class="stat"><span class="sk sk-stat w70"></span></div>`;
38
+ /** The "Best to use now" card's place (spec §3.45), so the summary opens at its final size. */
39
+ const SKELETON_PICK = `<div class="stat stat-pick"><span class="sk sk-pick"></span></div>`;
38
40
  export function renderPage(opts) {
39
41
  const nonce = opts.nonce ? ` nonce="${attr(opts.nonce)}"` : '';
40
42
  const theme = opts.theme ?? resolveTheme(undefined);
@@ -108,7 +110,7 @@ export function renderPage(opts) {
108
110
  <main class="wrap">
109
111
  <div id="banners"></div>
110
112
  <nav id="pages" class="pages" role="tablist" hidden></nav>
111
- <section id="summary" class="summary" aria-busy="true">${SKELETON_STAT.repeat(4)}</section>
113
+ <section id="summary" class="summary" aria-busy="true">${SKELETON_PICK}${SKELETON_STAT.repeat(4)}</section>
112
114
  <section id="handoff-page" class="block page" aria-labelledby="h-handoff" hidden></section>
113
115
  <section id="tuning-page" class="block page" aria-labelledby="h-tuning" hidden></section>
114
116
  <section id="sessions-page" class="block page" aria-labelledby="h-sessions" hidden></section>
@@ -279,6 +279,17 @@ export interface Runtime {
279
279
  family: string;
280
280
  choice: PickChoice;
281
281
  }>;
282
+ /**
283
+ * The Account a start in `family` makes now, by the rules of a Pick Command of that Family (`pickChoice`), whether
284
+ * or not it has one: the Panel's "Best to use now" card (spec §3.45). `record` as in `pickChoice`.
285
+ */
286
+ familyPick(family: string, opts?: {
287
+ record?: boolean;
288
+ recorded?: (rec: PickRecord) => void;
289
+ }): Promise<{
290
+ family: string;
291
+ choice: PickChoice;
292
+ }>;
282
293
  /**
283
294
  * The Pick Command to offer for a Family: the existing one, else a free name following its Aliases (or cc, cx, gk),
284
295
  * with the command on PATH it would hide, or `name: null` when no such name is free (the user types one); null when
@@ -1060,6 +1060,9 @@ export async function createRuntime(opts = {}) {
1060
1060
  const family = rt.pickCommandFamily(name);
1061
1061
  if (family === undefined)
1062
1062
  throw new UserError(`no pick command "${name}"; add one with \`sideby alias add ${name} --pick <family>\``);
1063
+ return { name, ...(await rt.familyPick(family, po)) };
1064
+ },
1065
+ async familyPick(family, po = {}) {
1063
1066
  const f = familyOf(family);
1064
1067
  // API Accounts are never picked, also not as the fallback (ADR-0035).
1065
1068
  const subs = (await accounts()).filter((a) => a.family === f.id && a.kind !== 'api');
@@ -1084,13 +1087,13 @@ export async function createRuntime(opts = {}) {
1084
1087
  })),
1085
1088
  }), (r) => r, po.recorded);
1086
1089
  }
1087
- return { name, family, choice: { ref, reason: 'no-quota-data' } };
1090
+ return { family, choice: { ref, reason: 'no-quota-data' } };
1088
1091
  }
1089
1092
  const plan = await rt.handoff(f.id, {
1090
1093
  picks: po.record ? (p) => choosePick(p, main).ref : 'read',
1091
1094
  ...(po.recorded ? { recorded: po.recorded } : {}),
1092
1095
  });
1093
- return { name, family, choice: choosePick(plan, main) };
1096
+ return { family, choice: choosePick(plan, main) };
1094
1097
  },
1095
1098
  async pickSuggestion(familyId, given) {
1096
1099
  const f = families.get(familyId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sideby",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Run work, personal and API-key accounts at the same time, without their configs drifting apart.",
5
5
  "license": "MIT",
6
6
  "author": "Adonis0123 (https://github.com/Adonis0123)",
package/schemas/next.json CHANGED
@@ -156,6 +156,31 @@
156
156
  },
157
157
  "description": "The window closest to its own Takeover Limit; absent when none is open."
158
158
  },
159
+ "windows": {
160
+ "type": "array",
161
+ "items": {
162
+ "type": "object",
163
+ "required": [
164
+ "label",
165
+ "usedPercent",
166
+ "resetsAt"
167
+ ],
168
+ "properties": {
169
+ "label": {
170
+ "type": "string",
171
+ "description": "Such as `5h` or `7d`."
172
+ },
173
+ "usedPercent": {
174
+ "type": "number",
175
+ "description": "Rounded; what is left is 100 minus it."
176
+ },
177
+ "resetsAt": {
178
+ "type": "string"
179
+ }
180
+ }
181
+ },
182
+ "description": "Every counted window (no model name) that has not reset yet, so a caller can show what the pick has left; absent when none is open."
183
+ },
159
184
  "resetsAt": {
160
185
  "type": "string",
161
186
  "description": "For full: when it is usable again. With a window used up, when those windows reset; otherwise when every window is under its Takeover Limit again."
@@ -2,7 +2,7 @@
2
2
  name: sideby
3
3
  description: Use when the user runs, or wants to run, several AI coding accounts (Claude Code, Codex, Grok Build, pi) side by side. Covers installing sideby and setting up a new account ("install sideby", "set up another Claude account", "add cc008", "配置一个 cc00x", "再加一个 Codex 账号"), explaining what accounts share and what stays separate ("what do my accounts share?", "这些账号共享了什么"), showing which account a session is ("show [cc001] in the status line", "加上账号标识"), finding a past session of any account ("找一下我上周改登录页的那个会话"), telling another running session something, in any account ("告诉 cc002 ……", "给跑构建的那个会话发消息"; Claude Code's own SendMessage reaches only sessions of the same account), seeing accounts, quota and usage, moving on when one hits its 5-hour or weekly limit, moving the current task to another account ("用 cc008 继续", "交回 cc008"), adding a short command (alias) or a pick command that starts whichever account has the most quota ("加个 cc"), adding an API account from a vendor's docs ("加一个 DeepSeek API 账号"), supporting a new tool, and repairing drifted account directories (skills, hooks, rules or settings not shared, wrong symlinks, credential file permissions). Drives the `sideby` CLI with `--json`; the agent does every step except browser sign-in, filling in secrets and starting interactive sessions, which it hands to the user as one command (inside an Auto Handoff session, `sideby handoff ready --to` moves the task itself).
4
4
  metadata:
5
- version: "0.43.0"
5
+ version: "0.44.0"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help
@@ -63,7 +63,7 @@ Account refs are `<family>:<name>`; a bare `<name>` works only when it is unique
63
63
  | Turn Auto Update on or off | `sideby update --auto on|off --json` | `references/update.md` |
64
64
  | Switch between a local build of sideby and the release ("切换到正式版", "切回 dev 版本") | `sideby local --json`, `sideby local on|off --json` (exits 10 first) | `references/update.md` |
65
65
  | Repair drift or permissions | `sideby doctor [ref] --json`, then `--fix` after they agree | `references/diagnose.md` |
66
- | Keep working because an account hit its limit | `sideby next <family> --json` | `references/handoff.md` |
66
+ | Keep working because an account hit its limit, or which account to use now ("现在该用哪个账号") | `sideby next <family> --json` | `references/handoff.md` |
67
67
  | Turn on Auto Handoff ("自动接力", "自动交接", "hand over when quota runs low"), see what it still needs, hand this session over now, or pick an account with room for a subtask | `sideby handoff status --json`, `sideby handoff enable --json` (exit 10 first), `sideby handoff ready`, `sideby next <family> --json` | `references/handoff.md` |
68
68
  | Explain or change the handoff rules ("接力规则", "什么时候换号", "让 Codex 接 Claude", "别用 API 账号接力") | `sideby handoff rules --json`, `sideby config set handoff.<key> <value>` or `sideby handoff enable --other-ai/--api --json` (exit 10 first) | `references/handoff.md` |
69
69
  | Sign an account in again or switch it to another login ("换个账号登录", "两个目录登录的是同一个号", "sign claude:work in with another account") | `sideby list --json` (`identity`, `sameLogin`), then give the user `sideby login <ref>` | `references/accounts.md` |
@@ -21,6 +21,8 @@ Use this when the user says an account hit its 5-hour or weekly limit ("usage li
21
21
 
22
22
  The two limits differ because one full 5-hour window costs only about a fifth of a week: a week at 87% is still `ready` and yellow, not red. When the user asks why such an account was picked, say that.
23
23
 
24
+ Each entry's `windows` lists every counted window not reset yet (`label`, `usedPercent`, `resetsAt`): say what is left in each, such as "claude:002 has 72% of its 5-hour window and 40% of its week left". The Panel's top line, **Best to use now**, shows the same pick and numbers for one tool and starts it on a click; point a user who is not in a terminal there.
25
+
24
26
  Each entry's `observedAt` says when its quota was recorded (`quotaFrom` when it was read from another account of the same login). An entry with `sameLoginAs` is signed in as the same login as the account you run in: it shares that quota and is never picked. If `hasQuota` is `false`, no account has quota data: the pick is only a guess, so say so and suggest turning quota on (see the routing table in SKILL.md) or letting the user choose.
25
27
  3. Give the user the command to run in their own terminal: `sideby next <family>` (starts the pick) or `sideby run <pick>`. Host arguments go after `--`. Do not run it yourself.
26
28
  4. Offer a handoff note: the new session starts empty, because each account keeps its own sessions. Write a short note the user can paste into it: the goal, what is done, what is in progress, the files involved, and the next step.