@cortexkit/opencode-antigravity-auth 3.0.7 → 3.0.8

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 (118) hide show
  1. package/dist/cli.js +1001 -63
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +112 -30
  4. package/dist/index.js +1270 -219
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +154 -48
  7. package/dist/server.js +1190 -120
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
  11. package/dist/src/common-auth-embedded/claustrum/availability.js +106 -0
  12. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
  13. package/dist/src/common-auth-embedded/claustrum/consumer.js +114 -5
  14. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
  15. package/dist/src/common-auth-embedded/claustrum/custody.js +294 -16
  16. package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
  17. package/dist/src/common-auth-embedded/claustrum/index.d.ts +5 -3
  18. package/dist/src/common-auth-embedded/claustrum/index.js +4 -1
  19. package/dist/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
  20. package/dist/src/common-auth-embedded/claustrum/insula.js +286 -21
  21. package/dist/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
  22. package/dist/src/common-auth-embedded/claustrum/watch.js +254 -0
  23. package/dist/src/common-auth-embedded/fs/private-files.js +10 -2
  24. package/dist/src/common-auth-embedded/quota/format.d.ts +3 -0
  25. package/dist/src/common-auth-embedded/quota/format.js +69 -1
  26. package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
  27. package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
  28. package/dist/src/common-auth-embedded/source-output.json +81 -49
  29. package/dist/src/ga/server/index.d.ts +2 -0
  30. package/dist/src/ga/server/index.d.ts.map +1 -1
  31. package/dist/src/ga/server/index.js +14 -1
  32. package/dist/src/ga/server/index.js.map +1 -1
  33. package/dist/src/plugin/auth-loader.d.ts +2 -1
  34. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  35. package/dist/src/plugin/auth-loader.js +5 -4
  36. package/dist/src/plugin/auth-loader.js.map +1 -1
  37. package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
  38. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  39. package/dist/src/plugin/fetch-interceptor.js +8 -6
  40. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  41. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  42. package/dist/src/plugin/ga-location-services.js +3 -0
  43. package/dist/src/plugin/ga-location-services.js.map +1 -1
  44. package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
  45. package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
  46. package/dist/src/plugin/shared/after-handoff.js +89 -0
  47. package/dist/src/plugin/shared/after-handoff.js.map +1 -0
  48. package/dist/src/plugin/shared/request-services.d.ts +8 -2
  49. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  50. package/dist/src/plugin/shared/request-services.js +57 -36
  51. package/dist/src/plugin/shared/request-services.js.map +1 -1
  52. package/dist/src/plugin/shared/vault-request-credentials.d.ts +2 -2
  53. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  54. package/dist/src/plugin/shared/vault-request-credentials.js +14 -1
  55. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  56. package/dist/src/plugin/vault-custody.d.ts +2 -0
  57. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  58. package/dist/src/plugin/vault-custody.js +3 -0
  59. package/dist/src/plugin/vault-custody.js.map +1 -1
  60. package/dist/src/tui.d.ts.map +1 -1
  61. package/dist/src/tui.js +82 -66
  62. package/dist/src/tui.js.map +1 -1
  63. package/dist/tui-build-map.json +27 -27
  64. package/dist/tui-ga-build-map.json +5 -5
  65. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
  66. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
  67. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
  68. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
  69. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
  70. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
  71. package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
  72. package/dist/types/src/common-auth-embedded/quota/format.d.ts +3 -0
  73. package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
  74. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
  75. package/dist/types/src/ga/server/index.d.ts +2 -0
  76. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  77. package/dist/types/src/plugin/auth-loader.d.ts +2 -1
  78. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  79. package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
  80. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  81. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  82. package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
  83. package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
  84. package/dist/types/src/plugin/shared/request-services.d.ts +8 -2
  85. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  86. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +2 -2
  87. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  88. package/dist/types/src/plugin/vault-custody.d.ts +2 -0
  89. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  90. package/package.json +4 -4
  91. package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
  92. package/src/common-auth-embedded/claustrum/availability.js +106 -0
  93. package/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
  94. package/src/common-auth-embedded/claustrum/consumer.js +114 -5
  95. package/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
  96. package/src/common-auth-embedded/claustrum/custody.js +294 -16
  97. package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
  98. package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
  99. package/src/common-auth-embedded/claustrum/index.js +4 -1
  100. package/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
  101. package/src/common-auth-embedded/claustrum/insula.js +286 -21
  102. package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
  103. package/src/common-auth-embedded/claustrum/watch.js +254 -0
  104. package/src/common-auth-embedded/fs/private-files.js +10 -2
  105. package/src/common-auth-embedded/quota/format.d.ts +3 -0
  106. package/src/common-auth-embedded/quota/format.js +69 -1
  107. package/src/common-auth-embedded/quota/index.d.ts +1 -1
  108. package/src/common-auth-embedded/quota/projection.d.ts +16 -0
  109. package/src/common-auth-embedded/source-output.json +81 -49
  110. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
  111. package/src/tui-compiled/common-auth-embedded/quota/format.js +69 -1
  112. package/src/tui-compiled/tui.js +123 -97
  113. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +69 -1
  114. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +69 -1
  115. package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
  116. package/src/tui-raw/common-auth-embedded/quota/format.js +69 -1
  117. package/src/tui-raw/tui.tsx +126 -107
  118. package/src/tui.tsx +126 -107
@@ -184,19 +184,25 @@ export async function replaceWindowsFile(from, to, options = {}) {
184
184
  to = resolve(to);
185
185
  const now = options.now ?? (() => performance.now());
186
186
  const start = now();
187
- const deadline = Math.min(start + 500, options.deadline ?? Infinity);
187
+ const leaseDeadline = options.deadline ?? Infinity;
188
+ let retryDeadline;
188
189
  const delays = [0, 10, 20, 40, 80, 100];
189
190
  let original;
190
191
  let attempts = 0;
191
192
  for (const delay of delays) {
193
+ const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
192
194
  if (now() >= deadline)
193
195
  break;
194
196
  if (delay)
195
197
  await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay, Math.max(0, deadline - now())));
196
198
  if (now() >= deadline)
197
199
  break;
200
+ const fenceStart = now();
198
201
  await options.beforeRename?.();
199
- if (now() >= deadline)
202
+ // Ownership checks fence every attempt but do not spend the sharing-retry budget.
203
+ if (retryDeadline !== undefined)
204
+ retryDeadline += now() - fenceStart;
205
+ if (now() >= leaseDeadline)
200
206
  break;
201
207
  attempts++;
202
208
  try {
@@ -212,6 +218,8 @@ export async function replaceWindowsFile(from, to, options = {}) {
212
218
  !detail.reason;
213
219
  if (!candidate)
214
220
  break;
221
+ // Start the retry window only once a rename has actually failed.
222
+ retryDeadline ??= now() + 500;
215
223
  }
216
224
  }
217
225
  const error = new PrivateFileError(to, 'rename', original ??
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
122
122
  const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
123
123
  return {
124
124
  scope: limit.scope,
125
+ ...(limit.windowMinutes === undefined
126
+ ? {}
127
+ : { windowMinutes: limit.windowMinutes }),
125
128
  part: {
126
129
  kind: 'window',
127
130
  name: quotaWindowName(limit),
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
212
215
  }
213
216
  return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
214
217
  }
218
+ /** The most groups a grouped narrow line shows. */
219
+ const NARROW_GROUP_LIMIT = 2;
220
+ /**
221
+ * The names the groups read under in the narrow line, one per listed group:
222
+ * each label's short name, derived exactly as a model window's is (`Gemini`
223
+ * → `Ge`, `Other models` → `Ot`, colliding names extended until they
224
+ * differ), computed over every listed group so a group keeps its name
225
+ * whichever groups show. A blank label falls back to the group's scope.
226
+ */
227
+ function groupShortNames(groups) {
228
+ const labels = groups.map((group) => group.label.trim() || group.scope);
229
+ const short = scopeAbbreviations(labels);
230
+ return labels.map((label) => short.get(label) ?? label);
231
+ }
232
+ /**
233
+ * The narrow line of a reading whose windows belong to named groups and that
234
+ * has no account-wide window: for each group, its tightest window as
235
+ * `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
236
+ * one with least left, compared before rounding; on a tie the first in
237
+ * display order (the shorter window) wins. At most two groups show: the two
238
+ * with least left, earlier-listed first on a tie, and always in the order
239
+ * the reading lists them, so the line does not reorder as the figures move.
240
+ * A group with no reported window is skipped. Windows outside the listed
241
+ * groups and the credit budget are left out. Undefined when the rule does
242
+ * not apply, so the caller uses the ordinary narrow rule.
243
+ */
244
+ function groupedNarrowPieces(groups, windows) {
245
+ if (!groups || groups.length === 0)
246
+ return undefined;
247
+ const reported = windows.filter(({ part }) => part.kind === 'window');
248
+ if (reported.some(({ scope }) => scope === ALL_SCOPE))
249
+ return undefined;
250
+ const candidates = groups.flatMap((group, listed) => {
251
+ const inGroup = reported.filter(({ scope }) => scope === group.scope);
252
+ // `windows` is already in display order, and strictly lower wins, so on
253
+ // a tie the shorter window keeps the place.
254
+ const groupTightest = inGroup.reduce((least, window) => least === undefined ||
255
+ (window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
256
+ ? window
257
+ : least, undefined);
258
+ return groupTightest ? [{ group, listed, window: groupTightest }] : [];
259
+ });
260
+ if (candidates.length === 0)
261
+ return undefined;
262
+ const names = groupShortNames(groups);
263
+ const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
264
+ const shown = [...candidates]
265
+ .sort((a, b) => left(a) - left(b) || a.listed - b.listed)
266
+ .slice(0, NARROW_GROUP_LIMIT)
267
+ .sort((a, b) => a.listed - b.listed);
268
+ return shown.map((candidate, index) => {
269
+ const { windowMinutes } = candidate.window;
270
+ const piece = [
271
+ names[candidate.listed] ?? candidate.group.scope,
272
+ ...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
273
+ `${wholePercent(left(candidate))}%`,
274
+ ].join(' ');
275
+ return index === shown.length - 1 ? `${piece} left` : piece;
276
+ });
277
+ }
215
278
  /**
216
279
  * The narrow form's pieces: every account-wide window as `5h 92%`, then at
217
280
  * most one more item, with ` left` added once to the last piece. That item is
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
224
287
  * be chosen; when nothing at all is shown it keeps its compact wording
225
288
  * (`credits available`). No age is added; `isQuotaStale` says whether the
226
289
  * reading is stale. A window whose reset arrived after the reading keeps its
227
- * figure, as in the other forms.
290
+ * figure, as in the other forms. A reading that lists named groups and has no
291
+ * account-wide window reads one item per group instead (see
292
+ * `groupedNarrowPieces`).
228
293
  */
229
294
  function narrowTextParts(quota, options) {
230
295
  const { windows } = scopedWindowParts(quota, options);
296
+ const grouped = groupedNarrowPieces(quota?.groups, windows);
297
+ if (grouped)
298
+ return grouped;
231
299
  const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
232
300
  const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
233
301
  const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
@@ -52,13 +52,13 @@ import { readFileSync } from "node:fs";
52
52
  import { dirname, join } from "node:path";
53
53
  import { fileURLToPath } from "node:url";
54
54
  import { createSlot } from "opentui:runtime-module:%40opentui%2Fsolid";
55
- import { createSignal, For, onCleanup, onMount, Show } from "opentui:runtime-module:solid-js";
56
- import { NO_QUOTA_READING } from "./quota-presentation.js";
55
+ import { createMemo, createSignal, For, onCleanup, onMount, Show } from "opentui:runtime-module:solid-js";
56
+ import { formatQuota, isQuotaStale } from "./common-auth-embedded/quota/index.js";
57
57
  import { getRpcDir } from "./rpc/rpc-dir.js";
58
58
  import { readSidebarState } from "./sidebar-state.js";
59
59
  import { createTuiFileLogger } from "./tui/file-logger.js";
60
60
  import { createV1MenuTransport, dispatchV1Notification } from "./tui/host-v1.js";
61
- import { ASSUMED_CONTENT_WIDTH, accountWindows, fitLabel, QuotaAccountBlock, quotaTone, RESET_SINCE_READING, showsFigure } from "./tui/quota-layout.js";
61
+ import { ASSUMED_CONTENT_WIDTH, accountWindows, fitLabel, GROUP_NAMES, QUOTA_ORDER, QuotaAccountBlock, quotaTone } from "./tui/quota-layout.js";
62
62
  import { routeLineFits } from "./tui/route-layout.js";
63
63
  import { computeEffectiveOrder, DEFAULT_PREFS, DEFAULT_SLOT_ORDER, PLUGIN_KEY, queueTuiPreferenceUpdate, readTuiPreferencesFile, resolveAntigravityAuthPrefs, watchTuiPreferences } from "./tui-preferences.js";
64
64
  const ID = 'cortexkit.antigravity-auth';
@@ -106,11 +106,6 @@ let rpcInFlight = false;
106
106
  const GLOBAL_NOTIFICATION_CURSOR = '__global__';
107
107
  const MAX_NOTIFICATION_CURSORS = 256;
108
108
 
109
- // The collapsed row has room for one word before the window name.
110
- const COLLAPSED_GROUP_NAMES = {
111
- gemini: 'Gemini',
112
- 'non-gemini': 'Other'
113
- };
114
109
  // --- Theme tokens ----------------------------------------------------------
115
110
  //
116
111
  // The sidebar pulls its colors from the live host theme (`api.theme.current`
@@ -390,8 +385,8 @@ function StatRow(props) {
390
385
  }
391
386
 
392
387
  // Fleet CollapsedRow: muted label left, caller-supplied value right. The
393
- // collapsed view renders one for the active account. The caller sizes both
394
- // sides to the measured width, so neither side may wrap.
388
+ // collapsed view renders one row for every visible account. The caller sizes
389
+ // both sides to the measured width, so neither side may wrap.
395
390
  function CollapsedRow(props) {
396
391
  return (() => {
397
392
  var _el$8 = _$createElement("box"),
@@ -460,32 +455,47 @@ function AccountBlock(props) {
460
455
  }
461
456
  });
462
457
  }
463
- // The collapsed row's figure: the lowest current window across both groups.
464
- // A window that reset since its reading is not current and never binds.
465
- function collapsedQuota(account, now) {
466
- if (account.quota.gemini == null && account.quota['non-gemini'] == null) return {
467
- prefix: '',
468
- text: '—',
469
- remaining: null
470
- };
471
- const windows = accountWindows(account, now);
472
- let lowest;
473
- for (const window of windows) {
474
- if (!showsFigure(window)) continue;
475
- if (lowest === undefined || (window.text.remaining ?? 100) < (lowest.text.remaining ?? 100)) lowest = window;
476
- }
477
- if (lowest) {
478
- const name = lowest.text.name;
479
- return {
480
- prefix: `${COLLAPSED_GROUP_NAMES[lowest.key]}${name ? ` ${name}` : ''} `,
481
- text: lowest.text.figure,
482
- remaining: lowest.text.remaining
483
- };
458
+
459
+ // Sidebar snapshots store quota values as percentages and epoch-millisecond
460
+ // reset times. Adapt those values to the shared projection so common-auth, not
461
+ // the renderer, decides how the narrow line reads.
462
+ function sidebarQuotaProjection(account, now) {
463
+ const limits = [];
464
+ for (const {
465
+ key,
466
+ reading
467
+ } of accountWindows(account, now)) {
468
+ const {
469
+ checkedAt,
470
+ remainingPercent,
471
+ resetAt,
472
+ window
473
+ } = reading;
474
+ if (typeof checkedAt !== 'number' || !Number.isFinite(checkedAt) || checkedAt < 0 || !Number.isFinite(remainingPercent)) continue;
475
+ const resetsAt = typeof resetAt === 'number' && Number.isFinite(resetAt) && Math.abs(resetAt) <= 8.64e15 ? new Date(resetAt).toISOString() : undefined;
476
+ limits.push({
477
+ scope: key,
478
+ label: GROUP_NAMES[key],
479
+ kind: 'reading',
480
+ checkedAt,
481
+ remainingPercent: Math.max(0, Math.min(100, remainingPercent)),
482
+ ...(window ? {
483
+ windowMinutes: window === 'weekly' ? 7 * 24 * 60 : 5 * 60
484
+ } : {}),
485
+ ...(resetsAt ? {
486
+ resetsAt
487
+ } : {})
488
+ });
484
489
  }
490
+ if (limits.length === 0) return undefined;
485
491
  return {
486
- prefix: '',
487
- text: windows.some(window => window.text.resetSinceReading) ? RESET_SINCE_READING : NO_QUOTA_READING,
488
- remaining: null
492
+ scope: 'all',
493
+ limits,
494
+ checkedAt: Math.min(...limits.map(limit => limit.checkedAt)),
495
+ groups: QUOTA_ORDER.map(scope => ({
496
+ scope,
497
+ label: GROUP_NAMES[scope]
498
+ }))
489
499
  };
490
500
  }
491
501
  function formatWait(ms) {
@@ -668,70 +678,86 @@ export function SidebarPanel(props) {
668
678
  return _$memo(() => !!collapsed())() && hasData();
669
679
  },
670
680
  get children() {
671
- return (() => {
672
- const account = () => visibleAccounts().find(entry => entry.current) ?? visibleAccounts()[0];
673
- const unavailable = () => {
674
- const selected = account();
675
- return selected != null && (!selected.enabled || selected.cooldownUntil != null && selected.cooldownUntil > now());
676
- };
677
- return _$createComponent(Show, {
678
- get when() {
679
- return account();
680
- },
681
- children: selected => {
682
- const quota = () => collapsedQuota(selected(), now());
683
- const tone = () => {
684
- const remaining = quota().remaining;
685
- return remaining == null ? 'muted' : quotaTone(100 - remaining, prefs().appearance);
686
- };
687
- // Label, one space, the figure and the two-cell dot. The
688
- // group prefix goes first when narrow; then the label is cut.
689
- const figure = () => {
690
- const {
691
- prefix,
692
- text
693
- } = quota();
694
- const full = `${prefix}${text}`;
695
- return selected().label.length + 1 + full.length + 2 <= contentWidth() ? full : text;
696
- };
697
- const label = () => fitLabel(selected().label, contentWidth() - 1 - figure().length - 2);
698
- return _$createComponent(CollapsedRow, {
699
- theme: theme,
700
- get label() {
701
- return label();
702
- },
703
- get children() {
704
- var _el$18 = _$createElement("box"),
705
- _el$19 = _$createElement("text"),
706
- _el$20 = _$createElement("b"),
707
- _el$21 = _$createElement("text");
708
- _$insertNode(_el$18, _el$19);
709
- _$insertNode(_el$18, _el$21);
710
- _$setProp(_el$18, "flexDirection", 'row');
711
- _$setProp(_el$18, "flexShrink", 0);
712
- _$insertNode(_el$19, _el$20);
713
- _$setProp(_el$19, "flexShrink", 0);
714
- _$setProp(_el$19, "wrapMode", 'none');
715
- _$insert(_el$20, figure);
716
- _$setProp(_el$21, "flexShrink", 0);
717
- _$setProp(_el$21, "wrapMode", 'none');
718
- _$insert(_el$21, () => unavailable() ? ' ⊘' : ' ●');
719
- _$effect(_p$ => {
720
- var _v$8 = toneColor(theme(), tone()),
721
- _v$9 = toneColor(theme(), unavailable() ? 'err' : tone());
722
- _v$8 !== _p$.e && (_p$.e = _$setProp(_el$19, "fg", _v$8, _p$.e));
723
- _v$9 !== _p$.t && (_p$.t = _$setProp(_el$21, "fg", _v$9, _p$.t));
724
- return _p$;
725
- }, {
726
- e: undefined,
727
- t: undefined
728
- });
729
- return _el$18;
730
- }
681
+ return _$createComponent(For, {
682
+ get each() {
683
+ return visibleAccounts();
684
+ },
685
+ children: account => {
686
+ const unavailable = () => !account.enabled || account.cooldownUntil != null && account.cooldownUntil > now();
687
+ const line = createMemo(() => {
688
+ const currentTime = now();
689
+ const projection = sidebarQuotaProjection(account, currentTime);
690
+ const text = formatQuota(projection, {
691
+ now: currentTime,
692
+ form: 'narrow'
731
693
  });
732
- }
733
- });
734
- })();
694
+ const remaining = projection?.limits.length ? Math.min(...projection.limits.map(limit => limit.remainingPercent ?? 100)) : undefined;
695
+ const tone = remaining === undefined ? 'muted' : quotaTone(100 - remaining, prefs().appearance);
696
+ const stale = isQuotaStale(projection, {
697
+ now: currentTime
698
+ });
699
+ const dot = unavailable() ? ' ⊘' : ' ●';
700
+ const width = contentWidth();
701
+ // Keep a complete shared line or omit it; a partial quota can
702
+ // make an account look as if it has less remaining.
703
+ const showQuota = text.length <= width;
704
+ const showDot = dot.length <= width && (!showQuota || text.length + dot.length <= width);
705
+ const rightWidth = (showQuota ? text.length : 0) + (showDot ? dot.length : 0);
706
+ const labelWidth = Math.max(0, width - rightWidth - 1);
707
+ return {
708
+ dot,
709
+ label: fitLabel(account.label, labelWidth),
710
+ showDot,
711
+ showQuota,
712
+ stale,
713
+ text,
714
+ tone
715
+ };
716
+ });
717
+ const quotaColor = () => line().stale ? theme().textMuted : toneColor(theme(), line().tone);
718
+ const dotColor = () => line().stale ? theme().textMuted : toneColor(theme(), unavailable() ? 'err' : line().tone);
719
+ return _$createComponent(CollapsedRow, {
720
+ theme: theme,
721
+ get label() {
722
+ return line().label;
723
+ },
724
+ get children() {
725
+ var _el$18 = _$createElement("box");
726
+ _$setProp(_el$18, "flexDirection", 'row');
727
+ _$setProp(_el$18, "flexShrink", 0);
728
+ _$insert(_el$18, _$createComponent(Show, {
729
+ get when() {
730
+ return line().showQuota;
731
+ },
732
+ get children() {
733
+ var _el$19 = _$createElement("text"),
734
+ _el$20 = _$createElement("b");
735
+ _$insertNode(_el$19, _el$20);
736
+ _$setProp(_el$19, "flexShrink", 0);
737
+ _$setProp(_el$19, "wrapMode", 'none');
738
+ _$insert(_el$20, () => line().text);
739
+ _$effect(_$p => _$setProp(_el$19, "fg", quotaColor(), _$p));
740
+ return _el$19;
741
+ }
742
+ }), null);
743
+ _$insert(_el$18, _$createComponent(Show, {
744
+ get when() {
745
+ return line().showDot;
746
+ },
747
+ get children() {
748
+ var _el$21 = _$createElement("text");
749
+ _$setProp(_el$21, "flexShrink", 0);
750
+ _$setProp(_el$21, "wrapMode", 'none');
751
+ _$insert(_el$21, () => line().dot);
752
+ _$effect(_$p => _$setProp(_el$21, "fg", dotColor(), _$p));
753
+ return _el$21;
754
+ }
755
+ }), null);
756
+ return _el$18;
757
+ }
758
+ });
759
+ }
760
+ });
735
761
  }
736
762
  }), null);
737
763
  _$insert(_el$0, _$createComponent(Show, {
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
122
122
  const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
123
123
  return {
124
124
  scope: limit.scope,
125
+ ...(limit.windowMinutes === undefined
126
+ ? {}
127
+ : { windowMinutes: limit.windowMinutes }),
125
128
  part: {
126
129
  kind: 'window',
127
130
  name: quotaWindowName(limit),
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
212
215
  }
213
216
  return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
214
217
  }
218
+ /** The most groups a grouped narrow line shows. */
219
+ const NARROW_GROUP_LIMIT = 2;
220
+ /**
221
+ * The names the groups read under in the narrow line, one per listed group:
222
+ * each label's short name, derived exactly as a model window's is (`Gemini`
223
+ * → `Ge`, `Other models` → `Ot`, colliding names extended until they
224
+ * differ), computed over every listed group so a group keeps its name
225
+ * whichever groups show. A blank label falls back to the group's scope.
226
+ */
227
+ function groupShortNames(groups) {
228
+ const labels = groups.map((group) => group.label.trim() || group.scope);
229
+ const short = scopeAbbreviations(labels);
230
+ return labels.map((label) => short.get(label) ?? label);
231
+ }
232
+ /**
233
+ * The narrow line of a reading whose windows belong to named groups and that
234
+ * has no account-wide window: for each group, its tightest window as
235
+ * `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
236
+ * one with least left, compared before rounding; on a tie the first in
237
+ * display order (the shorter window) wins. At most two groups show: the two
238
+ * with least left, earlier-listed first on a tie, and always in the order
239
+ * the reading lists them, so the line does not reorder as the figures move.
240
+ * A group with no reported window is skipped. Windows outside the listed
241
+ * groups and the credit budget are left out. Undefined when the rule does
242
+ * not apply, so the caller uses the ordinary narrow rule.
243
+ */
244
+ function groupedNarrowPieces(groups, windows) {
245
+ if (!groups || groups.length === 0)
246
+ return undefined;
247
+ const reported = windows.filter(({ part }) => part.kind === 'window');
248
+ if (reported.some(({ scope }) => scope === ALL_SCOPE))
249
+ return undefined;
250
+ const candidates = groups.flatMap((group, listed) => {
251
+ const inGroup = reported.filter(({ scope }) => scope === group.scope);
252
+ // `windows` is already in display order, and strictly lower wins, so on
253
+ // a tie the shorter window keeps the place.
254
+ const groupTightest = inGroup.reduce((least, window) => least === undefined ||
255
+ (window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
256
+ ? window
257
+ : least, undefined);
258
+ return groupTightest ? [{ group, listed, window: groupTightest }] : [];
259
+ });
260
+ if (candidates.length === 0)
261
+ return undefined;
262
+ const names = groupShortNames(groups);
263
+ const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
264
+ const shown = [...candidates]
265
+ .sort((a, b) => left(a) - left(b) || a.listed - b.listed)
266
+ .slice(0, NARROW_GROUP_LIMIT)
267
+ .sort((a, b) => a.listed - b.listed);
268
+ return shown.map((candidate, index) => {
269
+ const { windowMinutes } = candidate.window;
270
+ const piece = [
271
+ names[candidate.listed] ?? candidate.group.scope,
272
+ ...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
273
+ `${wholePercent(left(candidate))}%`,
274
+ ].join(' ');
275
+ return index === shown.length - 1 ? `${piece} left` : piece;
276
+ });
277
+ }
215
278
  /**
216
279
  * The narrow form's pieces: every account-wide window as `5h 92%`, then at
217
280
  * most one more item, with ` left` added once to the last piece. That item is
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
224
287
  * be chosen; when nothing at all is shown it keeps its compact wording
225
288
  * (`credits available`). No age is added; `isQuotaStale` says whether the
226
289
  * reading is stale. A window whose reset arrived after the reading keeps its
227
- * figure, as in the other forms.
290
+ * figure, as in the other forms. A reading that lists named groups and has no
291
+ * account-wide window reads one item per group instead (see
292
+ * `groupedNarrowPieces`).
228
293
  */
229
294
  function narrowTextParts(quota, options) {
230
295
  const { windows } = scopedWindowParts(quota, options);
296
+ const grouped = groupedNarrowPieces(quota?.groups, windows);
297
+ if (grouped)
298
+ return grouped;
231
299
  const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
232
300
  const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
233
301
  const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
122
122
  const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
123
123
  return {
124
124
  scope: limit.scope,
125
+ ...(limit.windowMinutes === undefined
126
+ ? {}
127
+ : { windowMinutes: limit.windowMinutes }),
125
128
  part: {
126
129
  kind: 'window',
127
130
  name: quotaWindowName(limit),
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
212
215
  }
213
216
  return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
214
217
  }
218
+ /** The most groups a grouped narrow line shows. */
219
+ const NARROW_GROUP_LIMIT = 2;
220
+ /**
221
+ * The names the groups read under in the narrow line, one per listed group:
222
+ * each label's short name, derived exactly as a model window's is (`Gemini`
223
+ * → `Ge`, `Other models` → `Ot`, colliding names extended until they
224
+ * differ), computed over every listed group so a group keeps its name
225
+ * whichever groups show. A blank label falls back to the group's scope.
226
+ */
227
+ function groupShortNames(groups) {
228
+ const labels = groups.map((group) => group.label.trim() || group.scope);
229
+ const short = scopeAbbreviations(labels);
230
+ return labels.map((label) => short.get(label) ?? label);
231
+ }
232
+ /**
233
+ * The narrow line of a reading whose windows belong to named groups and that
234
+ * has no account-wide window: for each group, its tightest window as
235
+ * `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
236
+ * one with least left, compared before rounding; on a tie the first in
237
+ * display order (the shorter window) wins. At most two groups show: the two
238
+ * with least left, earlier-listed first on a tie, and always in the order
239
+ * the reading lists them, so the line does not reorder as the figures move.
240
+ * A group with no reported window is skipped. Windows outside the listed
241
+ * groups and the credit budget are left out. Undefined when the rule does
242
+ * not apply, so the caller uses the ordinary narrow rule.
243
+ */
244
+ function groupedNarrowPieces(groups, windows) {
245
+ if (!groups || groups.length === 0)
246
+ return undefined;
247
+ const reported = windows.filter(({ part }) => part.kind === 'window');
248
+ if (reported.some(({ scope }) => scope === ALL_SCOPE))
249
+ return undefined;
250
+ const candidates = groups.flatMap((group, listed) => {
251
+ const inGroup = reported.filter(({ scope }) => scope === group.scope);
252
+ // `windows` is already in display order, and strictly lower wins, so on
253
+ // a tie the shorter window keeps the place.
254
+ const groupTightest = inGroup.reduce((least, window) => least === undefined ||
255
+ (window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
256
+ ? window
257
+ : least, undefined);
258
+ return groupTightest ? [{ group, listed, window: groupTightest }] : [];
259
+ });
260
+ if (candidates.length === 0)
261
+ return undefined;
262
+ const names = groupShortNames(groups);
263
+ const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
264
+ const shown = [...candidates]
265
+ .sort((a, b) => left(a) - left(b) || a.listed - b.listed)
266
+ .slice(0, NARROW_GROUP_LIMIT)
267
+ .sort((a, b) => a.listed - b.listed);
268
+ return shown.map((candidate, index) => {
269
+ const { windowMinutes } = candidate.window;
270
+ const piece = [
271
+ names[candidate.listed] ?? candidate.group.scope,
272
+ ...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
273
+ `${wholePercent(left(candidate))}%`,
274
+ ].join(' ');
275
+ return index === shown.length - 1 ? `${piece} left` : piece;
276
+ });
277
+ }
215
278
  /**
216
279
  * The narrow form's pieces: every account-wide window as `5h 92%`, then at
217
280
  * most one more item, with ` left` added once to the last piece. That item is
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
224
287
  * be chosen; when nothing at all is shown it keeps its compact wording
225
288
  * (`credits available`). No age is added; `isQuotaStale` says whether the
226
289
  * reading is stale. A window whose reset arrived after the reading keeps its
227
- * figure, as in the other forms.
290
+ * figure, as in the other forms. A reading that lists named groups and has no
291
+ * account-wide window reads one item per group instead (see
292
+ * `groupedNarrowPieces`).
228
293
  */
229
294
  function narrowTextParts(quota, options) {
230
295
  const { windows } = scopedWindowParts(quota, options);
296
+ const grouped = groupedNarrowPieces(quota?.groups, windows);
297
+ if (grouped)
298
+ return grouped;
231
299
  const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
232
300
  const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
233
301
  const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
@@ -184,19 +184,25 @@ export async function replaceWindowsFile(from, to, options = {}) {
184
184
  to = resolve(to);
185
185
  const now = options.now ?? (() => performance.now());
186
186
  const start = now();
187
- const deadline = Math.min(start + 500, options.deadline ?? Infinity);
187
+ const leaseDeadline = options.deadline ?? Infinity;
188
+ let retryDeadline;
188
189
  const delays = [0, 10, 20, 40, 80, 100];
189
190
  let original;
190
191
  let attempts = 0;
191
192
  for (const delay of delays) {
193
+ const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
192
194
  if (now() >= deadline)
193
195
  break;
194
196
  if (delay)
195
197
  await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay, Math.max(0, deadline - now())));
196
198
  if (now() >= deadline)
197
199
  break;
200
+ const fenceStart = now();
198
201
  await options.beforeRename?.();
199
- if (now() >= deadline)
202
+ // Ownership checks fence every attempt but do not spend the sharing-retry budget.
203
+ if (retryDeadline !== undefined)
204
+ retryDeadline += now() - fenceStart;
205
+ if (now() >= leaseDeadline)
200
206
  break;
201
207
  attempts++;
202
208
  try {
@@ -212,6 +218,8 @@ export async function replaceWindowsFile(from, to, options = {}) {
212
218
  !detail.reason;
213
219
  if (!candidate)
214
220
  break;
221
+ // Start the retry window only once a rename has actually failed.
222
+ retryDeadline ??= now() + 500;
215
223
  }
216
224
  }
217
225
  const error = new PrivateFileError(to, 'rename', original ??