sideby 0.32.2 → 0.33.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 (47) hide show
  1. package/assets/brand/sai-painted-1024.png +0 -0
  2. package/assets/brand/sai-painted-128.png +0 -0
  3. package/assets/brand/sai-painted-256.png +0 -0
  4. package/assets/brand/sai-painted-64.png +0 -0
  5. package/dist/build.json +1 -1
  6. package/dist/src/cli/commands.js +57 -14
  7. package/dist/src/cli/format.js +3 -1
  8. package/dist/src/cli/json-schemas.js +30 -5
  9. package/dist/src/cli/main.js +9 -4
  10. package/dist/src/core/brand-mark.d.ts +18 -115
  11. package/dist/src/core/brand-mark.js +43 -174
  12. package/dist/src/core/messages.d.ts +17 -5
  13. package/dist/src/core/messages.js +38 -15
  14. package/dist/src/core/quota-fetch.js +9 -2
  15. package/dist/src/desktop/icon.d.ts +13 -1
  16. package/dist/src/desktop/icon.js +153 -285
  17. package/dist/src/families/claude/deliver.js +9 -1
  18. package/dist/src/families/claude/messaging.d.ts +7 -1
  19. package/dist/src/families/claude/messaging.js +10 -2
  20. package/dist/src/families/codex/deliver.d.ts +10 -1
  21. package/dist/src/families/codex/deliver.js +24 -2
  22. package/dist/src/families/messaging.d.ts +6 -1
  23. package/dist/src/menubar/script.d.ts +5 -0
  24. package/dist/src/menubar/script.js +111 -25
  25. package/dist/src/menubar/snapshot.d.ts +25 -5
  26. package/dist/src/menubar/snapshot.js +114 -26
  27. package/dist/src/menubar/strings.d.ts +22 -6
  28. package/dist/src/menubar/strings.js +22 -6
  29. package/dist/src/panel/handler.d.ts +2 -2
  30. package/dist/src/panel/handler.js +8 -2
  31. package/dist/src/panel/i18n.d.ts +5 -0
  32. package/dist/src/panel/i18n.js +14 -4
  33. package/dist/src/panel/page-logic.d.ts +25 -4
  34. package/dist/src/panel/page-logic.js +122 -10
  35. package/dist/src/panel/page-script.js +39 -8
  36. package/dist/src/panel/page-styles.js +5 -5
  37. package/dist/src/panel/page.js +2 -2
  38. package/dist/src/panel/theme.d.ts +4 -1
  39. package/dist/src/runtime.d.ts +3 -1
  40. package/dist/src/runtime.js +1 -1
  41. package/package.json +2 -1
  42. package/schemas/menubar-snapshot.json +102 -2
  43. package/schemas/messages.json +6 -2
  44. package/schemas/send.json +6 -2
  45. package/skills/sideby/SKILL.md +1 -1
  46. package/skills/sideby/references/panel.md +1 -1
  47. package/skills/sideby/references/sessions.md +6 -3
@@ -15,11 +15,16 @@ export interface DeliveryRequest {
15
15
  pasteText: string;
16
16
  /** A fresh look at the processes. */
17
17
  procs: ProcessView;
18
+ /**
19
+ * Whether the target's process is gone by now, from another fresh look (for after a delivery that could not be
20
+ * confirmed); a failed look counts as still running.
21
+ */
22
+ ended: () => Promise<boolean>;
18
23
  deps: MessageDeps;
19
24
  }
20
25
  export interface Delivery {
21
26
  status: MessageStatus;
22
- /** Plain-language note: why paste is needed, or what the target must still do. */
27
+ /** Plain-language note: why paste is needed, what the target must still do, or why it could not be confirmed. */
23
28
  note?: string;
24
29
  /** The Host took it but shows it only after the user approves it in the target's terminal (ADR-0045). */
25
30
  needsApproval?: boolean;
@@ -5,6 +5,11 @@ export declare const TICK_SECONDS = 5;
5
5
  export declare const STALE_SECONDS: number;
6
6
  /** A snapshot still running after this is ended, so a stuck one cannot stop the refreshes. */
7
7
  export declare const SNAPSHOT_TIMEOUT_SECONDS = 60;
8
+ /**
9
+ * While a manual refresh runs, a cache-only snapshot (`--cached`) every this many seconds, so each account's new
10
+ * numbers show as soon as its answer is kept instead of all at once at the end (spec §3.31).
11
+ */
12
+ export declare const PEEK_SECONDS = 2;
8
13
  /**
9
14
  * Hours after which an idle item starts itself again. Over many hours the menu took longer and longer to open (1.6 to
10
15
  * 2 s after 18 hours on macOS 27, 2026-10-30, against about 0.1 s fresh), with no cause found in the script.
@@ -1,7 +1,7 @@
1
1
  // The Menu Bar Item's process (spec §3.31, ADR-0034): JXA run by the system's `osascript`, with no compiled code. It
2
2
  // draws what `sideby menubar snapshot --json` says and turns clicks into sideby commands; it reads no other file and
3
3
  // decides nothing itself. Arguments: the Node binary and the sideby entry the LaunchAgent recorded.
4
- import { FAVICON_SVG, MENUBAR_ICON_SVG } from '../core/brand-mark.js';
4
+ import { MENUBAR_ICON_PNG } from '../core/brand-mark.js';
5
5
  import { MENUBAR_STRINGS } from './strings.js';
6
6
  /** Seconds between two snapshots, and between two looks at a running one. */
7
7
  export const SNAPSHOT_SECONDS = 120;
@@ -10,6 +10,11 @@ export const TICK_SECONDS = 5;
10
10
  export const STALE_SECONDS = 15 * 60;
11
11
  /** A snapshot still running after this is ended, so a stuck one cannot stop the refreshes. */
12
12
  export const SNAPSHOT_TIMEOUT_SECONDS = 60;
13
+ /**
14
+ * While a manual refresh runs, a cache-only snapshot (`--cached`) every this many seconds, so each account's new
15
+ * numbers show as soon as its answer is kept instead of all at once at the end (spec §3.31).
16
+ */
17
+ export const PEEK_SECONDS = 2;
13
18
  /**
14
19
  * Hours after which an idle item starts itself again. Over many hours the menu took longer and longer to open (1.6 to
15
20
  * 2 s after 18 hours on macOS 27, 2026-10-30, against about 0.1 s fresh), with no cause found in the script.
@@ -23,7 +28,7 @@ ObjC.import('Carbon');
23
28
  ObjC.import('stdlib');
24
29
  function run(argv) {
25
30
  var node = argv[0], entry = argv[1];
26
- var SNAPSHOT = ${SNAPSHOT_SECONDS}, TICK = ${TICK_SECONDS}, STALE = ${STALE_SECONDS}, TIMEOUT = ${SNAPSHOT_TIMEOUT_SECONDS};
31
+ var SNAPSHOT = ${SNAPSHOT_SECONDS}, TICK = ${TICK_SECONDS}, STALE = ${STALE_SECONDS}, TIMEOUT = ${SNAPSHOT_TIMEOUT_SECONDS}, PEEK = ${PEEK_SECONDS};
27
32
  var lang = 'en';
28
33
  try { lang = ObjC.unwrap($.NSLocale.preferredLanguages.firstObject) || 'en'; } catch (e) {}
29
34
  var app = $.NSApplication.sharedApplication;
@@ -31,9 +36,10 @@ function run(argv) {
31
36
  var item = $.NSStatusBar.systemStatusBar.statusItemWithLength($.NSVariableStatusItemLength);
32
37
  // Keeps the place a user drags it to with Command held, such as out from under the notch.
33
38
  item.autosaveName = 'dev.sideby.menubar';
34
- // Sai, the sideby buddy, in colour (core/brand-mark.ts); a system gauge, drawn as a template, where this macOS cannot read SVG.
35
- var icon = $.NSImage.alloc.initWithData($(${JSON.stringify(MENUBAR_ICON_SVG)}).dataUsingEncoding($.NSUTF8StringEncoding));
36
- if (!icon || icon.isNil() || !icon.isValid) {
39
+ // Sai, the painted sideby buddy, in colour (core/brand-mark.ts); a system gauge, drawn as a template, if it cannot load.
40
+ var MARK_PNG = ${JSON.stringify(MENUBAR_ICON_PNG)};
41
+ var icon = pngImage(MARK_PNG, 18);
42
+ if (!icon) {
37
43
  icon = $.NSImage.imageWithSystemSymbolNameAccessibilityDescription('gauge.with.needle', 'sideby');
38
44
  if (icon && !icon.isNil()) icon.template = true;
39
45
  }
@@ -48,7 +54,6 @@ function run(argv) {
48
54
  var refs = [], actions = [], footer = null, appearance = '', manual = false;
49
55
  // The first words, before any snapshot has said which language to use.
50
56
  var zh = /^zh/i.test(lang);
51
- var CARD_ICON = ${JSON.stringify(FAVICON_SVG)};
52
57
  var LOADING = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.loading)} : ${JSON.stringify(MENUBAR_STRINGS.en.loading)};
53
58
  var OPEN_PANEL = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.openPanel)} : ${JSON.stringify(MENUBAR_STRINGS.en.openPanel)};
54
59
  var now = function () { return Date.now() / 1000; };
@@ -69,10 +74,13 @@ function run(argv) {
69
74
  if (t.launchAndReturnError(null)) actions.push(t);
70
75
  }
71
76
  var forceNext = false;
77
+ // While a manual refresh runs: when it started (ISO, for --refreshing-since) and the cache-only snapshot in flight.
78
+ var refreshSince = '', peekTask = null, peekHandle = null, peekOut = out + '.peek';
72
79
  function startSnapshot(force) {
73
80
  if (task) { if (force) forceNext = true; return; }
74
81
  force = force || forceNext;
75
82
  forceNext = false;
83
+ if (force) refreshSince = new Date().toISOString();
76
84
  $.NSFileManager.defaultManager.createFileAtPathContentsAttributes(out, $(), $());
77
85
  hotkeyReported = hotkeyReport();
78
86
  iconReported = iconStable;
@@ -86,21 +94,62 @@ function run(argv) {
86
94
  function closeHandle() {
87
95
  if (handle) { handle.closeFile; handle = null; }
88
96
  }
97
+ // The snapshot a finished task wrote, or null.
98
+ function readSnapshot(path) {
99
+ try {
100
+ var next = JSON.parse(ObjC.unwrap($.NSString.stringWithContentsOfFileEncodingError(path, $.NSUTF8StringEncoding, null)));
101
+ return next && next.schemaVersion === 1 ? next : null;
102
+ } catch (e) { return null; }
103
+ }
89
104
  function finishSnapshot() {
90
105
  var ok = task.terminationStatus === 0;
91
106
  task = null;
92
- manual = false;
107
+ // A refresh asked for while an automatic read ran starts next; it stays a manual one.
108
+ if (!forceNext) manual = false;
93
109
  closeHandle();
94
- if (ok) {
95
- try {
96
- var text = ObjC.unwrap($.NSString.stringWithContentsOfFileEncodingError(out, $.NSUTF8StringEncoding, null));
97
- var next = JSON.parse(text);
98
- if (next && next.schemaVersion === 1) { snap = next; lastOk = now(); failed = false; hotkey(snap.hotkey); build(); return; }
99
- } catch (e) {}
100
- }
110
+ // The refresh's own result wins: a cache-only snapshot still running started before it and is dropped.
111
+ stopPeek();
112
+ var next = ok ? readSnapshot(out) : null;
113
+ if (next) { snap = next; lastOk = now(); failed = false; hotkey(snap.hotkey); build(); return; }
101
114
  failed = true;
115
+ // A cache-only snapshot may have marked rows as refreshing; nothing is refreshing any more.
116
+ if (snap) (snap.sections || []).forEach(function (s) {
117
+ s.rows.concat(s.more ? s.more.rows : []).forEach(function (r) {
118
+ if (!r.refreshing) return;
119
+ var says = snap.lang === 'zh' ? ${JSON.stringify(MENUBAR_STRINGS.zh.rowRefreshFailed)} : ${JSON.stringify(MENUBAR_STRINGS.en.rowRefreshFailed)};
120
+ r.refreshing = false; r.refreshFailed = true; r.reset = r.resetTime = says;
121
+ (r.groups || []).forEach(function (g) { g.reset = g.resetTime = says; });
122
+ });
123
+ });
102
124
  build();
103
125
  }
126
+ // During a manual refresh, a cache-only snapshot that never asks a Host: accounts already answered show their new
127
+ // numbers, the others say they are refreshing. At most one runs at a time.
128
+ function peek() {
129
+ if (task && !task.running) { finishSnapshot(); return; }
130
+ if (peekTask && !peekTask.running) {
131
+ var ok = peekTask.terminationStatus === 0;
132
+ peekTask = null;
133
+ closePeek();
134
+ var next = ok && task && manual ? readSnapshot(peekOut) : null;
135
+ if (next) { snap = next; build(); }
136
+ }
137
+ if (peekTask || !task || !manual || !refreshSince) return;
138
+ $.NSFileManager.defaultManager.createFileAtPathContentsAttributes(peekOut, $(), $());
139
+ var t = sideby(['menubar', 'snapshot', '--json', '--cached', '--refreshing-since', refreshSince, '--lang', lang]);
140
+ peekHandle = $.NSFileHandle.fileHandleForWritingAtPath(peekOut);
141
+ t.standardOutput = peekHandle;
142
+ if (t.launchAndReturnError(null)) peekTask = t;
143
+ else closePeek();
144
+ }
145
+ function closePeek() {
146
+ if (peekHandle) { peekHandle.closeFile; peekHandle = null; }
147
+ }
148
+ function stopPeek() {
149
+ if (peekTask && peekTask.running) peekTask.terminate;
150
+ peekTask = null;
151
+ closePeek();
152
+ }
104
153
 
105
154
  // The shortcut that toggles the menu from anywhere (config menubar.hotkey), registered with Carbon's
106
155
  // RegisterEventHotKey: it needs no permission, unlike watching every key press. macOS hands a press to this app as a
@@ -267,6 +316,15 @@ function run(argv) {
267
316
  img.template = template;
268
317
  return img;
269
318
  }
319
+ // A base64 PNG at size×size points; null when macOS cannot read it.
320
+ function pngImage(b64, size) {
321
+ var data = $.NSData.alloc.initWithBase64EncodedStringOptions($(b64), 0);
322
+ if (!data || data.isNil()) return null;
323
+ var img = $.NSImage.alloc.initWithData(data);
324
+ if (!img || img.isNil() || !img.isValid) return null;
325
+ img.size = $.NSMakeSize(size, size);
326
+ return img;
327
+ }
270
328
  function symbol(name) {
271
329
  var img = $.NSImage.imageWithSystemSymbolNameAccessibilityDescription(name, name);
272
330
  return img && !img.isNil() ? img : null;
@@ -319,6 +377,7 @@ function run(argv) {
319
377
  return (bars[key] = $.NSAttributedString.attributedStringWithAttachment(att));
320
378
  }
321
379
 
380
+ var keptW = { name: 0, reset: 0, tag: 0 };
322
381
  // Columns: the name, then per window its bar and percent, then the reset time. One set of tab stops lines them up
323
382
  // across every tool; the window names sit once in each tool's header, over their column. A tool with one window
324
383
  // draws it in the second column, under the others' long window.
@@ -330,20 +389,31 @@ function run(argv) {
330
389
  head: $.NSFont.systemFontOfSizeWeight(size - 2, $.NSFontWeightSemibold),
331
390
  small: $.NSFont.systemFontOfSize(size - 2),
332
391
  };
333
- // The reset column names its window ("7d · in 4d 17h"), so it is as wide as its longest entry.
334
- var nameW = 0, first = false, resetW = width('7d · in 24d 23h', L.font);
392
+ // The reset column names its window ("7d", then "tomorrow 4:59 PM"), so it is as wide as its longest entry. While the
393
+ // menu is open it never gets narrower, so rows changing during a refresh do not make the menu jump.
394
+ // The times start at one tab stop after the widest window tag, so 7d and 31d rows line their times up.
395
+ var nameW = 0, first = false, tagW = width('7d', L.font), timeW = width('Wed 12:59 PM', L.font), plainW = 0;
396
+ function measure(r) {
397
+ var c = resetCell(r);
398
+ if (c[0]) { tagW = Math.max(tagW, width(c[0], L.font)); timeW = Math.max(timeW, width(c[1], L.font)); }
399
+ else plainW = Math.max(plainW, width(c[1], L.font));
400
+ }
335
401
  sections.forEach(function (s) {
336
402
  nameW = Math.max(nameW, width(s.title, L.head));
337
403
  if (s.columns[0]) first = true;
338
404
  s.rows.concat(s.more ? s.more.rows : []).forEach(function (r) {
339
405
  nameW = Math.max(nameW, width(r.label, L.font));
340
- if (r.reset) resetW = Math.max(resetW, width(r.reset, L.font));
406
+ if (r.bars) measure(r);
341
407
  (r.groups || []).forEach(function (g) {
342
408
  nameW = Math.max(nameW, width(GROUP_INDENT + g.label, L.font));
343
- if (g.reset) resetW = Math.max(resetW, width(g.reset, L.font));
409
+ measure({ reset: g.reset, resetLabel: g.resetLabel, resetTime: g.resetTime, refreshing: r.refreshing, refreshFailed: r.refreshFailed, stale: r.stale, note: g.reset });
344
410
  });
345
411
  });
346
412
  });
413
+ tagW = Math.ceil(tagW) + 8;
414
+ var resetW = Math.max(tagW + timeW, plainW);
415
+ if (menuOpen) { nameW = Math.max(nameW, keptW.name); resetW = Math.max(resetW, keptW.reset); tagW = Math.max(tagW, keptW.tag); }
416
+ keptW = { name: nameW, reset: resetW, tag: tagW };
347
417
  var pctW = width('100%', L.mono), x = Math.ceil(nameW) + 20, stops = [], at = [];
348
418
  function tab(pos) { stops.push($.NSTextTab.alloc.initWithTextAlignmentLocationOptions($.NSTextAlignmentLeft, pos, $())); }
349
419
  for (var c = 0; c < (first ? 2 : 1); c++) {
@@ -352,6 +422,7 @@ function run(argv) {
352
422
  tab(x); x += pctW + 20;
353
423
  }
354
424
  tab(x);
425
+ tab(x + tagW);
355
426
  L.reset = x;
356
427
  L.first = first;
357
428
  L.para = $.NSMutableParagraphStyle.alloc.init;
@@ -364,6 +435,14 @@ function run(argv) {
364
435
  L.width = x + resetW + 70;
365
436
  return L;
366
437
  }
438
+ // The reset cell: [window tag, time]. The tag is drawn grey and the time in the text colour; a cell that says
439
+ // something else (refreshing, failed, an old reading, every window past its reset) has only grey words.
440
+ function resetCell(r) {
441
+ if (r.refreshing || r.refreshFailed) return ['', r.resetTime || r.reset || ''];
442
+ if (r.stale) return ['', r.note || ''];
443
+ if (r.resetLabel) return [r.resetLabel, r.resetTime];
444
+ return ['', r.reset || ''];
445
+ }
367
446
  function rowTitle(r, L) {
368
447
  var line = $.NSMutableAttributedString.alloc.init;
369
448
  var plain = attrs(null, L.font, L.para), dim = attrs($.NSColor.secondaryLabelColor, L.font, L.para);
@@ -376,11 +455,16 @@ function run(argv) {
376
455
  if (!i && !L.first) return;
377
456
  if (!b) { line.appendAttributedString(str('\t\t', plain)); return; }
378
457
  line.appendAttributedString(str('\t', plain));
379
- line.appendAttributedString(bar(b, r.stale));
380
- var c = stale() || r.stale ? color('stale') : b.level === 'ok' ? null : color(b.level);
381
- line.appendAttributedString(str('\t' + b.percent + '%', attrs(c, L.mono, L.para)));
458
+ // A window past its reset keeps its old bar in grey, with no percent: the reading no longer says how much is used.
459
+ line.appendAttributedString(bar(b, r.stale || b.passed));
460
+ var c = stale() || r.stale || b.passed ? color('stale') : b.level === 'ok' ? null : color(b.level);
461
+ line.appendAttributedString(str('\t' + (b.passed ? '–' : b.percent + '%'), attrs(c, L.mono, L.para)));
382
462
  });
383
- if (r.stale || r.reset) line.appendAttributedString(str('\t' + (r.stale ? r.note : r.reset), dim));
463
+ var cell = resetCell(r);
464
+ if (cell[0]) {
465
+ line.appendAttributedString(str('\t' + cell[0], dim));
466
+ line.appendAttributedString(str('\t' + cell[1], stale() ? dim : plain));
467
+ } else if (cell[1]) line.appendAttributedString(str('\t' + cell[1], dim));
384
468
  return line;
385
469
  }
386
470
  function accountItem(menu, r, L) {
@@ -404,7 +488,7 @@ function run(argv) {
404
488
  (r.groups || []).forEach(function (g) {
405
489
  refs.push(r.ref);
406
490
  var gi = add(menu, g.label, 'start:', refs.length);
407
- gi.attributedTitle = rowTitle({ label: GROUP_INDENT + g.label, bars: g.bars, reset: g.reset, stale: r.stale, note: g.reset }, L);
491
+ gi.attributedTitle = rowTitle({ label: GROUP_INDENT + g.label, bars: g.bars, reset: g.reset, resetLabel: g.resetLabel, resetTime: g.resetTime, refreshing: r.refreshing, refreshFailed: r.refreshFailed, stale: r.stale, note: g.reset }, L);
408
492
  gi.image = GUTTER;
409
493
  gi.toolTip = g.tip;
410
494
  });
@@ -418,7 +502,7 @@ function run(argv) {
418
502
  line.appendAttributedString(str(s.title, attrs($.NSColor.labelColor, L.head, L.headPara)));
419
503
  var cols = L.first ? s.columns : [s.columns[1]];
420
504
  cols.forEach(function (c) { line.appendAttributedString(str('\t' + (c || ''), attrs($.NSColor.secondaryLabelColor, L.small, L.headPara))); });
421
- if (s.rows.some(function (r) { return r.reset || (r.groups || []).some(function (g) { return g.reset; }); }))
505
+ if (s.rows.some(function (r) { return r.reset || r.refreshing || r.refreshFailed || (r.groups || []).some(function (g) { return g.reset; }); }))
422
506
  line.appendAttributedString(str('\t' + snap.labels.resetsHeader, attrs($.NSColor.secondaryLabelColor, L.small, L.headPara)));
423
507
  var W = Math.max(280, L.width), H = 24;
424
508
  var v = $.NSView.alloc.initWithFrame($.NSMakeRect(0, 0, W, H));
@@ -441,7 +525,7 @@ function run(argv) {
441
525
  var W = Math.max(280, L.width), H = 50;
442
526
  var v = $.NSView.alloc.initWithFrame($.NSMakeRect(0, 0, W, H));
443
527
  v.autoresizingMask = $.NSViewWidthSizable;
444
- var icon = svgImage(CARD_ICON, 30, false);
528
+ var icon = pngImage(MARK_PNG, 30);
445
529
  if (icon) {
446
530
  var iv = $.NSImageView.imageViewWithImage(icon);
447
531
  iv.frame = $.NSMakeRect(14, 10, 30, 30);
@@ -583,6 +667,7 @@ function run(argv) {
583
667
  if (footer) footer.stringValue = footerText();
584
668
  },
585
669
  },
670
+ 'peek:': { types: ['void', ['id']], implementation: function () { try { peek(); } catch (e) {} } },
586
671
  'refresh:': {
587
672
  types: ['void', ['id']],
588
673
  implementation: function () {
@@ -638,6 +723,7 @@ function run(argv) {
638
723
  startSnapshot();
639
724
  // Common modes: the tick also runs while the menu is open, so a refresh started there lands in place.
640
725
  $.NSRunLoop.mainRunLoop.addTimerForMode($.NSTimer.timerWithTimeIntervalTargetSelectorUserInfoRepeats(TICK, target, 'tick:', $(), true), $.NSRunLoopCommonModes);
726
+ $.NSRunLoop.mainRunLoop.addTimerForMode($.NSTimer.timerWithTimeIntervalTargetSelectorUserInfoRepeats(PEEK, target, 'peek:', $(), true), $.NSRunLoopCommonModes);
641
727
  app.run;
642
728
  }
643
729
  `;
@@ -5,8 +5,12 @@ export type MenubarLevel = 'ok' | 'warn' | 'fail' | 'none';
5
5
  /** One quota window drawn as a small bar. */
6
6
  export interface MenubarBar {
7
7
  label: string;
8
+ /** For a window past its reset: what it had used, drawn grey with `–` for the percent. */
8
9
  percent: number;
10
+ /** `none` for a window past its reset. */
9
11
  level: MenubarLevel;
12
+ /** The window's reset time has passed and no newer reading has come yet; it counts toward no level. */
13
+ passed?: true;
10
14
  }
11
15
  export interface MenubarRow {
12
16
  ref: string;
@@ -31,17 +35,28 @@ export interface MenubarRow {
31
35
  * A Host whose every limit covers one model group (Antigravity CLI): a line per group under the account, each with
32
36
  * its own two bars, reset and hover text, while the account's own `bars` stay null. Null otherwise.
33
37
  */
34
- groups: {
38
+ groups: ({
35
39
  label: string;
36
40
  bars: MenubarRow['bars'];
37
- reset: string;
38
41
  tip: string;
39
- }[] | null;
42
+ } & Pick<MenubarRow, 'reset' | 'resetLabel' | 'resetTime'>)[] | null;
40
43
  /**
41
- * Which window resets and how long until it does, such as `7d · in 4d 17h`: the window closest to its own red level
42
- * (85% for 5 hours, 95% for a week), so the one that runs out first. Empty when nothing is used.
44
+ * Which window resets and when, such as `7d · tomorrow 4:59 PM`: the window closest to its own red level (85% for 5
45
+ * hours, 95% for a week), so the one that runs out first. `resetLabel` and `resetTime` joined, for readers that do
46
+ * not draw. Empty when nothing is used.
43
47
  */
44
48
  reset: string;
49
+ /** The window of `reset` as the column headers name it (`5h`, `7d`); empty when the cell names no window. */
50
+ resetLabel: string;
51
+ /**
52
+ * When it resets (`in 4h 20m`, `tomorrow 4:59 PM`, spec §3.31), or what the cell says instead: every window is past
53
+ * its reset, the row is refreshing, or its refresh failed.
54
+ */
55
+ resetTime: string;
56
+ /** A manual refresh is asking the Host for this account and has no answer yet; the old bars stay. */
57
+ refreshing?: true;
58
+ /** This refresh asked the Host for this account and it failed; the old bars stay. */
59
+ refreshFailed?: true;
45
60
  /** A no-quota explanation, or an old-reading warning beside the bars. */
46
61
  note: string;
47
62
  }
@@ -109,6 +124,11 @@ export interface MenubarFamilyInput {
109
124
  quota: QuotaResult;
110
125
  /** The other refs of its Same Login: the same subscription, so one quota. */
111
126
  sameLogin?: readonly string[];
127
+ /**
128
+ * Where a manual refresh stands for this account (spec §3.31): `waiting` while it is asked and has not answered,
129
+ * `failed` when this refresh's answer failed. Left out for accounts the refresh does not ask.
130
+ */
131
+ refresh?: 'waiting' | 'failed';
112
132
  /**
113
133
  * The newest use of its login on this computer (its own and its Same Login's sessions), when known. A reading
114
134
  * older than an hour with no use since is not marked old (`quotaIsStale`).
@@ -1,4 +1,5 @@
1
1
  import { bindingWindow, openWindows, quotaIsStale, windowLevel, worseLevel, } from '../core/quota-levels.js';
2
+ import { resetDate, resetWhen } from '../panel/page-logic.js';
2
3
  import { fill, MENUBAR_STRINGS } from './strings.js';
3
4
  export const DEFAULT_MENUBAR_HOTKEY = 'opt+x';
4
5
  // macOS virtual key codes of the ANSI letters and digits (HIToolbox Events.h, kVK_ANSI_*).
@@ -98,26 +99,46 @@ export function quotaGroups(quota) {
98
99
  function groupLabel(name) {
99
100
  return name.replace(/\s+models$/i, '') || name;
100
101
  }
102
+ /** A window by its length, as hover text spells it (`5-hour window`, `7天窗口`); its label when the length is odd. */
103
+ function windowName(w, s) {
104
+ const m = Number(w.windowMinutes);
105
+ if (m > 0 && m % 1440 === 0)
106
+ return fill(s.daysWindow, { n: m / 1440 });
107
+ if (m > 0 && m % 60 === 0)
108
+ return fill(s.hoursWindow, { n: m / 60 });
109
+ return w.label;
110
+ }
101
111
  /**
102
112
  * What a Quota whose windows cover every model draws: two bar columns (the shortest window, then the fullest of the
103
113
  * others, so a third window that is used up still shows; a single window fills the second), each colored by its own
104
114
  * levels (a weekly window warns later, spec §3.26), which window runs out first and when it resets, and one hover line
105
- * per window with its use and reset.
115
+ * per window with its use and reset. A window past its reset keeps its old bar in grey and counts toward no level;
116
+ * when every window is past its reset, the reset cell says so instead of a time.
106
117
  */
107
- function drawn(quota, now, s) {
118
+ function drawn(quota, now, s, lang) {
108
119
  const open = openWindows(quota, now) ?? [];
109
120
  const windows = quota.windows
110
121
  .filter((w) => !w.name)
111
122
  .sort((x, y) => (x.windowMinutes ?? 0) - (y.windowMinutes ?? 0));
112
123
  const openOf = (w) => open.find((o) => o.label === w.label);
113
124
  const bar = (w) => {
114
- const percent = Math.round(openOf(w)?.usedPercent ?? 0);
125
+ const o = openOf(w);
126
+ if (!o)
127
+ return {
128
+ label: w.label,
129
+ percent: Math.round(Math.min(100, Math.max(0, Number(w.usedPercent) || 0))),
130
+ level: 'none',
131
+ passed: true,
132
+ };
133
+ const percent = Math.round(o.usedPercent);
115
134
  return { label: w.label, percent, level: windowLevel({ ...w, usedPercent: percent }) };
116
135
  };
136
+ // An open window always beats one past its reset, whatever the old reading said.
137
+ const weight = (b) => (b.passed ? -1 : b.percent);
117
138
  const longer = windows
118
139
  .slice(1)
119
140
  .map(bar)
120
- .reduce((best, b) => (!best || b.percent > best.percent ? b : best), null);
141
+ .reduce((best, b) => (!best || weight(b) > weight(best) ? b : best), null);
121
142
  const bars = !windows.length
122
143
  ? null
123
144
  : longer
@@ -126,22 +147,40 @@ function drawn(quota, now, s) {
126
147
  // The window that runs out first relative to its own kind: a weekly 87% before a 5-hour 60%.
127
148
  const fullest = bindingWindow(open) ?? null;
128
149
  const level = open.reduce((l, w) => worseLevel(l, windowLevel(w)), 'ok');
129
- const resetTime = fullest && fullest.usedPercent > 0 ? untilText(fullest.resetsAt, now, s) : '';
130
- const reset = resetTime ? fill(s.resetIn, { label: fullest.label, time: resetTime }) : '';
150
+ const allPassed = windows.length > 0 && open.length === 0;
151
+ const shown = fullest && fullest.usedPercent > 0 ? fullest : null;
152
+ const resetLabel = shown ? shown.label : '';
153
+ const resetTime = shown ? resetWhen(shown.resetsAt, now.getTime(), lang) : allPassed ? s.resetDue : '';
154
+ const reset = resetLabel ? fill(s.resetIn, { label: resetLabel, time: resetTime }) : resetTime;
131
155
  const lines = windows.map((w) => {
132
156
  const o = openOf(w);
133
- const p = bar(w).percent;
134
- return o && p > 0
135
- ? fill(s.windowResetsTip, { label: w.label, p, time: untilText(o.resetsAt, now, s) })
136
- : fill(s.windowTip, { label: w.label, p });
157
+ const b = bar(w);
158
+ const label = windowName(w, s);
159
+ if (b.passed)
160
+ return fill(s.windowPassedTip, { label, date: resetDate(w.resetsAt, now.getTime(), lang) });
161
+ return o && b.percent > 0
162
+ ? fill(s.windowResetsTip, {
163
+ label,
164
+ p: b.percent,
165
+ date: resetDate(o.resetsAt, now.getTime(), lang),
166
+ left: untilText(o.resetsAt, now, s),
167
+ })
168
+ : fill(s.windowTip, { label, p: b.percent });
137
169
  });
138
170
  return {
139
171
  bars,
140
- fullest,
172
+ fullest: shown,
141
173
  level,
142
174
  reset,
175
+ resetLabel,
143
176
  resetTime,
144
- parts: windows.map((w) => fill(s.window, { label: w.label, p: bar(w).percent })),
177
+ allPassed,
178
+ parts: windows.map((w) => {
179
+ const b = bar(w);
180
+ return b.passed
181
+ ? fill(s.windowPassed, { label: w.label })
182
+ : fill(s.window, { label: w.label, p: b.percent });
183
+ }),
145
184
  lines,
146
185
  };
147
186
  }
@@ -155,7 +194,25 @@ function observedText(observedAt, now, s) {
155
194
  return s.observedJustNow;
156
195
  return fill(s.observedAgo, { time: durationText(minutes, s) });
157
196
  }
158
- function row(a, plan, now, s, refreshable) {
197
+ function row(a, plan, now, s, refreshable, lang) {
198
+ const r = quotaRow(a, plan, now, s, refreshable, lang);
199
+ if (!a.refresh)
200
+ return r;
201
+ // A manual refresh in progress (spec §3.31): the old bars stay, and the reset cell says where the refresh stands.
202
+ const says = a.refresh === 'waiting' ? s.rowRefreshing : s.rowRefreshFailed;
203
+ const flag = a.refresh === 'waiting' ? { refreshing: true } : { refreshFailed: true };
204
+ const cell = { reset: says, resetLabel: '', resetTime: says };
205
+ if (!r.bars && !r.groups)
206
+ return { ...r, ...flag, note: says, detail: says };
207
+ return {
208
+ ...r,
209
+ ...flag,
210
+ ...(r.bars ? cell : {}),
211
+ groups: r.groups?.map((g) => ({ ...g, ...cell })) ?? null,
212
+ detail: [r.detail, says].filter(Boolean).join(s.sep),
213
+ };
214
+ }
215
+ function quotaRow(a, plan, now, s, refreshable, lang) {
159
216
  const recommended = Boolean(plan?.hasQuota && plan.pick === a.ref);
160
217
  const startTip = fill(s.startTip, { account: a.ref });
161
218
  const base = {
@@ -166,6 +223,8 @@ function row(a, plan, now, s, refreshable) {
166
223
  bars: null,
167
224
  groups: null,
168
225
  reset: '',
226
+ resetLabel: '',
227
+ resetTime: '',
169
228
  observedAt: null,
170
229
  stale: false,
171
230
  };
@@ -187,13 +246,19 @@ function row(a, plan, now, s, refreshable) {
187
246
  ...(quiet ? [s.quietTip] : []),
188
247
  ...(quota.fetchError ? [fill(s.fetchFailed, { error: quota.fetchError })] : []),
189
248
  ];
249
+ // Every window is past its reset: Refresh asks now, where the Family can be asked.
250
+ const due = (d) => (d.allPassed && refreshable ? [s.resetDueTip] : []);
190
251
  const groups = quotaGroups(quota);
191
252
  if (groups) {
192
253
  // One line per model group under the account, each with its own 5h and 7d bars (spec §3.31). Windows that cover
193
254
  // every model (Cursor's plan total) keep their bars on the account's own line.
194
- const drawnGroups = groups.map((g) => ({ name: g.name, d: drawn(g.quota, now, s) }));
195
- const groupTip = (g) => [g.name, ...g.d.lines.map((l) => ` ${l}`)];
196
- const all = openWindows(quota, now) ? drawn(quota, now, s) : null;
255
+ const drawnGroups = groups.map((g) => ({ name: g.name, d: drawn(g.quota, now, s, lang) }));
256
+ const groupTip = (g) => [
257
+ g.name,
258
+ ...g.d.lines.map((l) => ` ${l}`),
259
+ ...due(g.d).map((l) => ` ${l}`),
260
+ ];
261
+ const all = openWindows(quota, now) ? drawn(quota, now, s, lang) : null;
197
262
  return {
198
263
  ...base,
199
264
  observedAt: quota.observedAt,
@@ -207,16 +272,25 @@ function row(a, plan, now, s, refreshable) {
207
272
  tip: [
208
273
  ...head,
209
274
  '',
210
- ...(all ? [...all.lines, ''] : []),
275
+ ...(all ? [...all.lines, ...due(all), ''] : []),
211
276
  ...drawnGroups.flatMap(groupTip),
212
277
  '',
213
278
  startTip,
214
279
  ].join('\n'),
215
- ...(all ? { bars: all.bars, reset: all.reset } : {}),
216
- groups: drawnGroups.map((g) => ({
280
+ ...(all
281
+ ? { bars: all.bars, reset: all.reset, resetLabel: all.resetLabel, resetTime: all.resetTime }
282
+ : {}),
283
+ // Under an account with its own plan-wide bars, a model group nobody has used yet (Claude's Fable at 0%) gets no
284
+ // line of its own: it would double the list with zeros. Its numbers stay in the hover text, and its line comes
285
+ // back once it is used or its window passes its reset. An account made only of groups keeps every line.
286
+ groups: drawnGroups
287
+ .filter((g) => !all || (g.d.bars ?? []).some((b) => b && (b.percent > 0 || b.passed)))
288
+ .map((g) => ({
217
289
  label: groupLabel(g.name),
218
290
  bars: g.d.bars,
219
291
  reset: g.d.reset,
292
+ resetLabel: g.d.resetLabel,
293
+ resetTime: g.d.resetTime,
220
294
  tip: [...head, '', ...groupTip(g), '', startTip].join('\n'),
221
295
  })),
222
296
  note: stale ? s.olderReading : '',
@@ -224,10 +298,12 @@ function row(a, plan, now, s, refreshable) {
224
298
  }
225
299
  if (openWindows(quota, now) === null)
226
300
  return noted(s.noData);
227
- const d = drawn(quota, now, s);
301
+ const d = drawn(quota, now, s, lang);
228
302
  const parts = [...d.parts];
229
- if (d.resetTime)
303
+ if (d.fullest)
230
304
  parts.push(fill(s.resets, { label: d.fullest.label, time: d.resetTime }));
305
+ else if (d.allPassed)
306
+ parts.push(s.resetDue);
231
307
  if (stale)
232
308
  parts.push(s.olderReading);
233
309
  return {
@@ -236,9 +312,11 @@ function row(a, plan, now, s, refreshable) {
236
312
  stale,
237
313
  detail: parts.join(s.sep),
238
314
  level: d.level,
239
- tip: [...head, '', ...d.lines, '', startTip].join('\n'),
315
+ tip: [...head, '', ...d.lines, ...due(d), '', startTip].join('\n'),
240
316
  bars: d.bars,
241
317
  reset: d.reset,
318
+ resetLabel: d.resetLabel,
319
+ resetTime: d.resetTime,
242
320
  note: stale ? s.olderReading : '',
243
321
  };
244
322
  }
@@ -250,7 +328,7 @@ function columns(rows) {
250
328
  .find((l) => l !== undefined) ?? null;
251
329
  return [at(0), at(1)];
252
330
  }
253
- function section(f, now, s) {
331
+ function section(f, now, s, lang) {
254
332
  const logo = f.logo
255
333
  ? {
256
334
  path: f.logo.path,
@@ -259,7 +337,7 @@ function section(f, now, s) {
259
337
  ...(f.logo.gradients?.length ? { gradients: f.logo.gradients } : {}),
260
338
  }
261
339
  : null;
262
- const all = f.accounts.map((a) => ({ a, r: row(a, f.plan, now, s, f.refreshable !== false) }));
340
+ const all = f.accounts.map((a) => ({ a, r: row(a, f.plan, now, s, f.refreshable !== false, lang) }));
263
341
  const aside = (a) => a.kind === 'api' || a.login === 'logged-out';
264
342
  // A Same Login is one quota, so one row, named like the Panel's: after the directory first in Display Order (the
265
343
  // Panel's "Set as shown name" moves one there). It is recommended when any of its directories is. The other
@@ -290,7 +368,17 @@ function section(f, now, s) {
290
368
  const note = fill(s.sameLoginNote, { name: lead.a.name });
291
369
  same.push({
292
370
  ...y,
293
- r: { ...y.r, bars: null, reset: '', note, detail: note, level: 'none', recommended: false },
371
+ r: {
372
+ ...y.r,
373
+ bars: null,
374
+ reset: '',
375
+ resetLabel: '',
376
+ resetTime: '',
377
+ note,
378
+ detail: note,
379
+ level: 'none',
380
+ recommended: false,
381
+ },
294
382
  });
295
383
  }
296
384
  }
@@ -321,7 +409,7 @@ export function menubarSnapshot(families, now, lang, hotkey = null) {
321
409
  for (const f of families) {
322
410
  if (!f.accounts.length)
323
411
  continue;
324
- sections.push(section(f, now, s));
412
+ sections.push(section(f, now, s, lang));
325
413
  if (!f.plan?.hasQuota)
326
414
  continue;
327
415
  // The plan lists the usable accounts first, least used first; past them, the least used of the full ones.