@cortexkit/opencode-antigravity-auth 3.0.6 → 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 (211) hide show
  1. package/dist/cli.js +1621 -183
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +228 -62
  4. package/dist/index.js +2728 -883
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +291 -104
  7. package/dist/server.js +2255 -390
  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 +41 -1
  13. package/dist/src/common-auth-embedded/claustrum/consumer.js +152 -6
  14. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
  15. package/dist/src/common-auth-embedded/claustrum/custody.js +311 -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/fs/refresh-file-lock.d.ts +8 -2
  25. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
  26. package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
  27. package/dist/src/common-auth-embedded/quota/format.d.ts +17 -3
  28. package/dist/src/common-auth-embedded/quota/format.js +203 -18
  29. package/dist/src/common-auth-embedded/quota/index.d.ts +2 -2
  30. package/dist/src/common-auth-embedded/quota/index.js +1 -1
  31. package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
  32. package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  33. package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
  34. package/dist/src/common-auth-embedded/setup/command-runner.js +118 -24
  35. package/dist/src/common-auth-embedded/setup/command.js +75 -19
  36. package/dist/src/common-auth-embedded/setup/enroll.js +17 -5
  37. package/dist/src/common-auth-embedded/setup/index.d.ts +2 -1
  38. package/dist/src/common-auth-embedded/setup/index.js +1 -0
  39. package/dist/src/common-auth-embedded/setup/register.js +8 -2
  40. package/dist/src/common-auth-embedded/setup/types.d.ts +14 -0
  41. package/dist/src/common-auth-embedded/source-output.json +142 -94
  42. package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
  43. package/dist/src/common-auth-embedded/store/pool.js +0 -1
  44. package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  45. package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
  46. package/dist/src/ga/server/index.d.ts +2 -0
  47. package/dist/src/ga/server/index.d.ts.map +1 -1
  48. package/dist/src/ga/server/index.js +18 -3
  49. package/dist/src/ga/server/index.js.map +1 -1
  50. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  51. package/dist/src/ga/tui/host-ga.js +37 -3
  52. package/dist/src/ga/tui/host-ga.js.map +1 -1
  53. package/dist/src/plugin/auth-loader.d.ts +2 -1
  54. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  55. package/dist/src/plugin/auth-loader.js +5 -4
  56. package/dist/src/plugin/auth-loader.js.map +1 -1
  57. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  58. package/dist/src/plugin/config/schema.js +2 -1
  59. package/dist/src/plugin/config/schema.js.map +1 -1
  60. package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
  61. package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
  62. package/dist/src/plugin/fetch-interceptor.js +8 -6
  63. package/dist/src/plugin/fetch-interceptor.js.map +1 -1
  64. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  65. package/dist/src/plugin/ga-location-services.js +7 -3
  66. package/dist/src/plugin/ga-location-services.js.map +1 -1
  67. package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
  68. package/dist/src/plugin/gemini-dump.js +2 -5
  69. package/dist/src/plugin/gemini-dump.js.map +1 -1
  70. package/dist/src/plugin/index.d.ts.map +1 -1
  71. package/dist/src/plugin/index.js +3 -3
  72. package/dist/src/plugin/index.js.map +1 -1
  73. package/dist/src/plugin/logging-utils.d.ts.map +1 -1
  74. package/dist/src/plugin/logging-utils.js +2 -5
  75. package/dist/src/plugin/logging-utils.js.map +1 -1
  76. package/dist/src/plugin/request.d.ts +1 -2
  77. package/dist/src/plugin/request.d.ts.map +1 -1
  78. package/dist/src/plugin/request.js +8 -12
  79. package/dist/src/plugin/request.js.map +1 -1
  80. package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
  81. package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
  82. package/dist/src/plugin/shared/after-handoff.js +89 -0
  83. package/dist/src/plugin/shared/after-handoff.js.map +1 -0
  84. package/dist/src/plugin/shared/request-services.d.ts +16 -3
  85. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  86. package/dist/src/plugin/shared/request-services.js +193 -90
  87. package/dist/src/plugin/shared/request-services.js.map +1 -1
  88. package/dist/src/plugin/shared/vault-request-credentials.d.ts +13 -4
  89. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  90. package/dist/src/plugin/shared/vault-request-credentials.js +17 -1
  91. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  92. package/dist/src/plugin/vault-custody.d.ts +16 -1
  93. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  94. package/dist/src/plugin/vault-custody.js +60 -10
  95. package/dist/src/plugin/vault-custody.js.map +1 -1
  96. package/dist/src/sidebar-projection.d.ts +4 -0
  97. package/dist/src/sidebar-projection.d.ts.map +1 -1
  98. package/dist/src/sidebar-projection.js +6 -2
  99. package/dist/src/sidebar-projection.js.map +1 -1
  100. package/dist/src/tui/quota-layout.d.ts +94 -0
  101. package/dist/src/tui/quota-layout.d.ts.map +1 -0
  102. package/dist/src/tui/quota-layout.js +139 -0
  103. package/dist/src/tui/quota-layout.js.map +1 -0
  104. package/dist/src/tui/route-layout.d.ts +8 -0
  105. package/dist/src/tui/route-layout.d.ts.map +1 -0
  106. package/dist/src/tui/route-layout.js +36 -0
  107. package/dist/src/tui/route-layout.js.map +1 -0
  108. package/dist/src/tui.d.ts.map +1 -1
  109. package/dist/src/tui.js +105 -191
  110. package/dist/src/tui.js.map +1 -1
  111. package/dist/tui-build-map.json +60 -31
  112. package/dist/tui-ga-build-map.json +46 -17
  113. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
  114. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +41 -1
  115. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
  116. package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
  117. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
  118. package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
  119. package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
  120. package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  121. package/dist/types/src/common-auth-embedded/quota/format.d.ts +17 -3
  122. package/dist/types/src/common-auth-embedded/quota/index.d.ts +2 -2
  123. package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
  124. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  125. package/dist/types/src/common-auth-embedded/setup/index.d.ts +2 -1
  126. package/dist/types/src/common-auth-embedded/setup/types.d.ts +14 -0
  127. package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
  128. package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  129. package/dist/types/src/ga/server/index.d.ts +2 -0
  130. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  131. package/dist/types/src/plugin/auth-loader.d.ts +2 -1
  132. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  133. package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
  134. package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
  135. package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
  136. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  137. package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
  138. package/dist/types/src/plugin/index.d.ts.map +1 -1
  139. package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
  140. package/dist/types/src/plugin/request.d.ts +1 -2
  141. package/dist/types/src/plugin/request.d.ts.map +1 -1
  142. package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
  143. package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
  144. package/dist/types/src/plugin/shared/request-services.d.ts +16 -3
  145. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  146. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +13 -4
  147. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  148. package/dist/types/src/plugin/vault-custody.d.ts +16 -1
  149. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  150. package/package.json +4 -4
  151. package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
  152. package/src/common-auth-embedded/claustrum/availability.js +106 -0
  153. package/src/common-auth-embedded/claustrum/consumer.d.ts +41 -1
  154. package/src/common-auth-embedded/claustrum/consumer.js +152 -6
  155. package/src/common-auth-embedded/claustrum/custody.d.ts +135 -14
  156. package/src/common-auth-embedded/claustrum/custody.js +311 -16
  157. package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
  158. package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
  159. package/src/common-auth-embedded/claustrum/index.js +4 -1
  160. package/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
  161. package/src/common-auth-embedded/claustrum/insula.js +286 -21
  162. package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
  163. package/src/common-auth-embedded/claustrum/watch.js +254 -0
  164. package/src/common-auth-embedded/fs/private-files.js +10 -2
  165. package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
  166. package/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
  167. package/src/common-auth-embedded/pi-slot/lock.js +7 -3
  168. package/src/common-auth-embedded/quota/format.d.ts +17 -3
  169. package/src/common-auth-embedded/quota/format.js +203 -18
  170. package/src/common-auth-embedded/quota/index.d.ts +2 -2
  171. package/src/common-auth-embedded/quota/index.js +1 -1
  172. package/src/common-auth-embedded/quota/projection.d.ts +16 -0
  173. package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
  174. package/src/common-auth-embedded/setup/command-error.js +79 -0
  175. package/src/common-auth-embedded/setup/command-runner.js +118 -24
  176. package/src/common-auth-embedded/setup/command.js +75 -19
  177. package/src/common-auth-embedded/setup/enroll.js +17 -5
  178. package/src/common-auth-embedded/setup/index.d.ts +2 -1
  179. package/src/common-auth-embedded/setup/index.js +1 -0
  180. package/src/common-auth-embedded/setup/register.js +8 -2
  181. package/src/common-auth-embedded/setup/types.d.ts +14 -0
  182. package/src/common-auth-embedded/source-output.json +142 -94
  183. package/src/common-auth-embedded/store/pool.d.ts +1 -1
  184. package/src/common-auth-embedded/store/pool.js +0 -1
  185. package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
  186. package/src/common-auth-embedded/store/refresh-lock.js +0 -1
  187. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
  188. package/src/tui-compiled/common-auth-embedded/quota/format.js +203 -18
  189. package/src/tui-compiled/common-auth-embedded/quota/index.js +1 -1
  190. package/src/tui-compiled/tui/quota-layout.js +378 -0
  191. package/src/tui-compiled/tui/route-layout.js +30 -0
  192. package/src/tui-compiled/tui.js +245 -501
  193. package/src/tui-ga-compiled/host-ga.js +82 -52
  194. package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  195. package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  196. package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +203 -18
  197. package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +1 -1
  198. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
  199. package/src/tui-ga-raw/host-ga.tsx +71 -30
  200. package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
  201. package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
  202. package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +203 -18
  203. package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +1 -1
  204. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
  205. package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
  206. package/src/tui-raw/common-auth-embedded/quota/format.js +203 -18
  207. package/src/tui-raw/common-auth-embedded/quota/index.js +1 -1
  208. package/src/tui-raw/tui/quota-layout.tsx +391 -0
  209. package/src/tui-raw/tui/route-layout.js +30 -0
  210. package/src/tui-raw/tui.tsx +171 -411
  211. package/src/tui.tsx +171 -411
@@ -13,14 +13,16 @@
13
13
  * score, and per-session routing decisions), so the fleet components are
14
14
  * adapted rather than copied verbatim:
15
15
  *
16
- * - `WindowRow` reads `remainingPercent + resetAt` from the Antigravity
17
- * `SidebarQuotaEntry` shape and colors via `quotaTone` (remaining
18
- * threshold) instead of `usageTone` (used threshold). Each window is one
19
- * line sized from the measured sidebar width.
16
+ * - The quota rows come from `tui/quota-layout.tsx`, shared with the
17
+ * OpenCode 2 sidebar: each window reads `remainingPercent + resetAt` from
18
+ * the Antigravity `SidebarQuotaEntry` shape, is colored via `quotaTone`
19
+ * (remaining threshold) instead of `usageTone` (used threshold), and is
20
+ * one line sized from the measured sidebar width.
20
21
  * - `AccountBlock` derives its status word (`active` / `idle` /
21
- * `cooling` / `off`) from the Antigravity account state, shows the
22
- * reading age once per account, and groups windows under `Gemini` and
23
- * `Other models` headers. The routing health score is not shown.
22
+ * `cooling` / `off`) from the Antigravity account state; the shared block
23
+ * shows the reading age once per account and groups windows under
24
+ * `Gemini` and `Other models` headers. The routing health score is not
25
+ * shown.
24
26
  * - `Routing` shows the mounted session's most recent `activeRouting`
25
27
  * entry, or `No request yet` before the session's first request, since
26
28
  * Antigravity does not maintain a per-session sidebar state alongside the
@@ -46,19 +48,26 @@ import type {
46
48
  TuiThemeCurrent,
47
49
  } from "@opencode-ai/plugin/tui"
48
50
  import { createSlot } from "@opentui/solid"
49
- import { createSignal, For, type JSX, onCleanup, onMount, Show } from "solid-js"
50
51
  import {
51
- NO_QUOTA_READING,
52
- type QuotaReading,
53
- type QuotaWindowText,
54
- quotaReadingAge,
55
- quotaWindowText,
56
- } from "./quota-presentation.js"
52
+ createMemo,
53
+ createSignal,
54
+ For,
55
+ type JSX,
56
+ onCleanup,
57
+ onMount,
58
+ Show,
59
+ } from "solid-js"
60
+
61
+ import {
62
+ formatQuota,
63
+ isQuotaStale,
64
+ type ProjectedLimit,
65
+ type ProjectedQuota,
66
+ } from "./common-auth-embedded/quota/index.js"
57
67
  import { getRpcDir } from "./rpc/rpc-dir.js"
58
68
  import {
59
69
  readSidebarState,
60
70
  type SidebarAccountState,
61
- type SidebarQuotaKey,
62
71
  type SidebarStateV1,
63
72
  } from "./sidebar-state.js"
64
73
  import { createTuiFileLogger, type TuiLogger } from "./tui/file-logger.js"
@@ -67,6 +76,18 @@ import {
67
76
  dispatchV1Notification,
68
77
  type V1Notification,
69
78
  } from "./tui/host-v1.tsx"
79
+ import {
80
+ ASSUMED_CONTENT_WIDTH,
81
+ accountWindows,
82
+ fitLabel,
83
+ GROUP_NAMES,
84
+ QUOTA_ORDER,
85
+ QuotaAccountBlock,
86
+ type QuotaPalette,
87
+ type QuotaTone,
88
+ quotaTone,
89
+ } from "./tui/quota-layout.tsx"
90
+ import { routeLineFits } from "./tui/route-layout.js"
70
91
  import {
71
92
  type AntigravityAuthTuiPrefs,
72
93
  type AppearancePrefs,
@@ -128,36 +149,6 @@ let rpcInFlight = false
128
149
  const GLOBAL_NOTIFICATION_CURSOR = '__global__'
129
150
  const MAX_NOTIFICATION_CURSORS = 256
130
151
 
131
- // Group headers name each quota pool in plain words.
132
- const GROUP_NAMES: Record<SidebarQuotaKey, string> = {
133
- gemini: 'Gemini',
134
- 'non-gemini': 'Other models',
135
- }
136
-
137
- // The collapsed row has room for one word before the window name.
138
- const COLLAPSED_GROUP_NAMES: Record<SidebarQuotaKey, string> = {
139
- gemini: 'Gemini',
140
- 'non-gemini': 'Other',
141
- }
142
-
143
- const QUOTA_ORDER: readonly SidebarQuotaKey[] = ['gemini', 'non-gemini']
144
-
145
- // Shown instead of a stored figure once the window has reset since it was
146
- // read: the stored figure describes the window before the reset.
147
- const RESET_SINCE_READING = 'reset since last check'
148
-
149
- // Content width (the panel's width inside its padding) used until the first
150
- // layout pass reports the real one. It fits the narrowest OpenCode sidebar.
151
- const ASSUMED_CONTENT_WIDTH = 28
152
-
153
- // A window row is `<name> <bar> <figure> <reset>`. The bar shrinks to this
154
- // before the reset column is dropped; below it the bar is dropped too.
155
- const MIN_BAR_WIDTH = 4
156
- // The widest figure the formatter writes: `100% left`.
157
- const FIGURE_WIDTH = 9
158
- // A window name (`5h`, `7d`) and the space after it.
159
- const NAME_WIDTH = 3
160
-
161
152
  // --- Theme tokens ----------------------------------------------------------
162
153
  //
163
154
  // The sidebar pulls its colors from the live host theme (`api.theme.current`
@@ -171,7 +162,7 @@ const NAME_WIDTH = 3
171
162
  // uses are populated; the rest of the TuiThemeCurrent fields are left
172
163
  // undefined and the `??` chain in `toneColor` falls through cleanly.
173
164
 
174
- type Tone = 'ok' | 'warn' | 'err' | 'muted' | 'accent' | 'text'
165
+ type Tone = QuotaTone
175
166
  type Theme = TuiThemeCurrent
176
167
  type ThemeColor = Theme['text']
177
168
 
@@ -250,31 +241,15 @@ function toneColor(theme: Theme, tone: Tone): ThemeColor {
250
241
  }
251
242
  }
252
243
 
253
- function quotaTone(usedPct: number, appearance: AppearancePrefs): Tone {
254
- if (usedPct < appearance.warnThreshold) return 'ok'
255
- if (usedPct < appearance.errorThreshold) return 'warn'
256
- return 'err'
257
- }
258
-
259
- interface BarSegment {
260
- text: string
261
- tone: Tone
262
- }
263
-
264
- function quotaBarSegments(
265
- remainingPct: number,
266
- width: number,
267
- appearance: AppearancePrefs,
268
- ): BarSegment[] {
269
- const usedCells = Math.max(
270
- 0,
271
- Math.min(Math.round((remainingPct / 100) * width), width),
272
- )
273
- const tone = quotaTone(100 - remainingPct, appearance)
274
- return [
275
- { text: appearance.barFilledChar.repeat(usedCells), tone },
276
- { text: appearance.barEmptyChar.repeat(width - usedCells), tone },
277
- ].filter((segment) => segment.text.length > 0)
244
+ // The shared quota layout reads its colors through this palette. Muted text
245
+ // and the account label read `textMuted` and `text` straight from the theme,
246
+ // without the `toneColor` fallback chain.
247
+ function themePalette(theme: () => Theme): QuotaPalette {
248
+ return {
249
+ text: () => theme().text,
250
+ muted: () => theme().textMuted,
251
+ tone: (tone) => toneColor(theme(), tone),
252
+ }
278
253
  }
279
254
 
280
255
  export interface SidebarPanelProps {
@@ -488,8 +463,8 @@ function StatRow(props: {
488
463
  }
489
464
 
490
465
  // Fleet CollapsedRow: muted label left, caller-supplied value right. The
491
- // collapsed view renders one for the active account. The caller sizes both
492
- // sides to the measured width, so neither side may wrap.
466
+ // collapsed view renders one row for every visible account. The caller sizes
467
+ // both sides to the measured width, so neither side may wrap.
493
468
  function CollapsedRow(props: {
494
469
  theme: () => Theme
495
470
  label: string
@@ -505,161 +480,8 @@ function CollapsedRow(props: {
505
480
  )
506
481
  }
507
482
 
508
- // --- Width-fitted quota rows ------------------------------------------------
509
- //
510
- // The OpenCode 1 sidebar is about 32 to 48 columns wide. Every quota line is
511
- // sized from the measured content width so that it fits on one line: text is
512
- // never left to the renderer's wrapping, which breaks a row mid-word or down
513
- // to one character per line once the right-hand column runs out of room.
514
-
515
- interface AccountWindow {
516
- key: SidebarQuotaKey
517
- reading: QuotaReading
518
- text: QuotaWindowText
519
- }
520
-
521
- // One entry per stored window, in group order. A pool stored before
522
- // per-window readings existed contributes one window without a name.
523
- function accountWindows(
524
- account: SidebarAccountState,
525
- now: number,
526
- ): AccountWindow[] {
527
- const result: AccountWindow[] = []
528
- for (const key of QUOTA_ORDER) {
529
- const entry = account.quota[key]
530
- if (!entry) continue
531
- const readings: QuotaReading[] =
532
- entry.windows && entry.windows.length > 0
533
- ? entry.windows.map((window) => ({
534
- window: window.window,
535
- remainingPercent: window.remainingPercent,
536
- resetAt: window.resetAt,
537
- checkedAt: window.checkedAt,
538
- }))
539
- : [
540
- {
541
- remainingPercent: entry.remainingPercent,
542
- resetAt: entry.resetAt,
543
- checkedAt: entry.checkedAt,
544
- },
545
- ]
546
- for (const reading of readings)
547
- result.push({ key, reading, text: quotaWindowText(reading, now) })
548
- }
549
- return result
550
- }
551
-
552
- // A window shows its figure only while no reset has happened since it was
553
- // read and it has a read time at all.
554
- function showsFigure(window: AccountWindow): boolean {
555
- return window.text.remaining != null && !window.text.resetSinceReading
556
- }
557
-
558
- interface WindowRowLayout {
559
- bar: number
560
- reset: boolean
561
- }
562
-
563
- // Column widths for one `<name> <bar> <figure> <reset>` row within `width`
564
- // cells. The bar shrinks first, down to MIN_BAR_WIDTH; then the reset column
565
- // is dropped; then the bar.
566
- function windowRowLayout(
567
- width: number,
568
- named: boolean,
569
- resetWidth: number,
570
- maxBar: number,
571
- ): WindowRowLayout {
572
- const room = width - (named ? NAME_WIDTH : 0) - FIGURE_WIDTH
573
- if (resetWidth > 0) {
574
- const bar = Math.min(maxBar, room - resetWidth - 2)
575
- if (bar >= MIN_BAR_WIDTH) return { bar, reset: true }
576
- }
577
- const bar = Math.min(maxBar, room - 1)
578
- return { bar: bar >= MIN_BAR_WIDTH ? bar : 0, reset: false }
579
- }
580
-
581
- // Shorten a label to `max` cells, marking the cut with an ellipsis.
582
- function fitLabel(label: string, max: number): string {
583
- if (label.length <= max) return label
584
- if (max <= 0) return ''
585
- if (max === 1) return '…'
586
- return `${label.slice(0, max - 1)}…`
587
- }
588
-
589
- // One quota window on one line. The bar fills with remaining quota; the
590
- // figure and reset come from the shared formatter. A window that reset since
591
- // its reading shows that fact, dim, in place of the stale figure.
592
- function WindowRow(props: {
593
- theme: () => Theme
594
- appearance: AppearancePrefs
595
- window: AccountWindow
596
- layout: WindowRowLayout
597
- }): JSX.Element {
598
- const text = () => props.window.text
599
- const tone = () => quotaTone(100 - (text().remaining ?? 0), props.appearance)
600
- return (
601
- <box width='100%' flexDirection='row'>
602
- <Show when={text().name !== ''}>
603
- <text
604
- width={NAME_WIDTH}
605
- flexShrink={0}
606
- wrapMode='none'
607
- fg={props.theme().textMuted}
608
- >
609
- {text().name}
610
- </text>
611
- </Show>
612
- <Show
613
- when={showsFigure(props.window)}
614
- fallback={
615
- <text flexShrink={1} wrapMode='none' fg={props.theme().textMuted}>
616
- {text().resetSinceReading ? RESET_SINCE_READING : text().figure}
617
- </text>
618
- }
619
- >
620
- <Show when={props.layout.bar > 0}>
621
- <box width={props.layout.bar + 1} flexShrink={0} flexDirection='row'>
622
- <For
623
- each={quotaBarSegments(
624
- text().remaining ?? 0,
625
- props.layout.bar,
626
- props.appearance,
627
- )}
628
- >
629
- {(segment) => (
630
- <text
631
- wrapMode='none'
632
- fg={toneColor(props.theme(), segment.tone)}
633
- >
634
- {segment.text}
635
- </text>
636
- )}
637
- </For>
638
- </box>
639
- </Show>
640
- <text
641
- flexShrink={0}
642
- wrapMode='none'
643
- fg={toneColor(props.theme(), tone())}
644
- >
645
- {text().figure}
646
- </text>
647
- <box flexGrow={1} />
648
- <Show when={props.layout.reset && text().reset !== ''}>
649
- <text flexShrink={0} wrapMode='none' fg={props.theme().textMuted}>
650
- {text().reset}
651
- </text>
652
- </Show>
653
- </Show>
654
- </box>
655
- )
656
- }
657
-
658
- // Fleet AccountBlock, adapted to Antigravity's per-account data. The header
659
- // line is the account label, the reading age when the oldest reading is
660
- // stale, and the status word right-aligned; the age moves to its own dim
661
- // line when the three do not fit. Below it each quota group present gets a
662
- // plain-word header and one WindowRow per window. Status word priorities
483
+ // One account in the Quota section: the shared quota block, with the status
484
+ // word computed from the sidebar file's account state. Status word priorities
663
485
  // (first match wins):
664
486
  // - `off` when the account is disabled
665
487
  // - `cooling <wait>` when cooldownUntil is still in the future
@@ -690,134 +512,64 @@ function AccountBlock(props: {
690
512
  if (cooldownMs() > 0) return 'warn'
691
513
  return active() ? 'ok' : 'muted'
692
514
  }
693
- const windows = () => accountWindows(props.account, props.now())
694
- const age = () =>
695
- quotaReadingAge(
696
- windows().map((window) => window.reading),
697
- props.now(),
698
- )
699
- const ageInline = () =>
700
- age() !== '' &&
701
- props.account.label.length + 3 + age().length + 1 + statusWord().length <=
702
- props.width()
703
- const label = () =>
704
- fitLabel(props.account.label, props.width() - 1 - statusWord().length)
705
- // One reset column width per account, so bars line up across its rows.
706
- const resetWidth = () =>
707
- Math.max(
708
- 0,
709
- ...windows()
710
- .filter(showsFigure)
711
- .map((window) => window.text.reset.length),
712
- )
713
- const layoutFor = (window: AccountWindow) =>
714
- windowRowLayout(
715
- props.width(),
716
- window.text.name !== '',
717
- resetWidth(),
718
- props.appearance.barWidth,
719
- )
720
- const groups = () =>
721
- QUOTA_ORDER.map((key) => ({
722
- key,
723
- windows: windows().filter((window) => window.key === key),
724
- })).filter((group) => group.windows.length > 0)
725
515
  return (
726
- <box width='100%' flexDirection='column' marginTop={props.marginTop ?? 0}>
727
- <box width='100%' flexDirection='row'>
728
- <text flexShrink={0} wrapMode='none' fg={props.theme().text}>
729
- <b>{label()}</b>
730
- </text>
731
- <Show when={ageInline()}>
732
- <text flexShrink={0} wrapMode='none' fg={props.theme().textMuted}>
733
- {` · ${age()}`}
734
- </text>
735
- </Show>
736
- <box flexGrow={1} />
737
- <text
738
- flexShrink={0}
739
- wrapMode='none'
740
- fg={toneColor(props.theme(), statusTone())}
741
- >
742
- <b>{statusWord()}</b>
743
- </text>
744
- </box>
745
- <Show when={age() !== '' && !ageInline()}>
746
- <text wrapMode='none' fg={props.theme().textMuted}>
747
- {age()}
748
- </text>
749
- </Show>
750
- <Show
751
- when={groups().length > 0}
752
- fallback={
753
- <text wrapMode='none' fg={props.theme().textMuted}>
754
- {NO_QUOTA_READING}
755
- </text>
756
- }
757
- >
758
- <For each={groups()}>
759
- {(group) => (
760
- <>
761
- <text wrapMode='none' fg={props.theme().textMuted}>
762
- {GROUP_NAMES[group.key]}
763
- </text>
764
- <For each={group.windows}>
765
- {(window) => (
766
- <WindowRow
767
- theme={props.theme}
768
- appearance={props.appearance}
769
- window={window}
770
- layout={layoutFor(window)}
771
- />
772
- )}
773
- </For>
774
- </>
775
- )}
776
- </For>
777
- </Show>
778
- </box>
516
+ <QuotaAccountBlock
517
+ palette={themePalette(props.theme)}
518
+ appearance={props.appearance}
519
+ account={props.account}
520
+ status={statusWord()}
521
+ statusTone={statusTone()}
522
+ now={props.now}
523
+ width={props.width}
524
+ marginTop={props.marginTop}
525
+ />
779
526
  )
780
527
  }
781
528
 
782
- interface CollapsedQuota {
783
- // The group and window of the figure (`Other 7d `), dropped when narrow.
784
- prefix: string
785
- text: string
786
- remaining: number | null
787
- }
788
-
789
- // The collapsed row's figure: the lowest current window across both groups.
790
- // A window that reset since its reading is not current and never binds.
791
- function collapsedQuota(
529
+ // Sidebar snapshots store quota values as percentages and epoch-millisecond
530
+ // reset times. Adapt those values to the shared projection so common-auth, not
531
+ // the renderer, decides how the narrow line reads.
532
+ function sidebarQuotaProjection(
792
533
  account: SidebarAccountState,
793
534
  now: number,
794
- ): CollapsedQuota {
795
- if (account.quota.gemini == null && account.quota['non-gemini'] == null)
796
- return { prefix: '', text: '—', remaining: null }
797
- const windows = accountWindows(account, now)
798
- let lowest: AccountWindow | undefined
799
- for (const window of windows) {
800
- if (!showsFigure(window)) continue
535
+ ): ProjectedQuota | undefined {
536
+ const limits: ProjectedLimit[] = []
537
+ for (const { key, reading } of accountWindows(account, now)) {
538
+ const { checkedAt, remainingPercent, resetAt, window } = reading
801
539
  if (
802
- lowest === undefined ||
803
- (window.text.remaining ?? 100) < (lowest.text.remaining ?? 100)
540
+ typeof checkedAt !== 'number' ||
541
+ !Number.isFinite(checkedAt) ||
542
+ checkedAt < 0 ||
543
+ !Number.isFinite(remainingPercent)
804
544
  )
805
- lowest = window
806
- }
807
- if (lowest) {
808
- const name = lowest.text.name
809
- return {
810
- prefix: `${COLLAPSED_GROUP_NAMES[lowest.key]}${name ? ` ${name}` : ''} `,
811
- text: lowest.text.figure,
812
- remaining: lowest.text.remaining,
813
- }
545
+ continue
546
+ const resetsAt =
547
+ typeof resetAt === 'number' &&
548
+ Number.isFinite(resetAt) &&
549
+ Math.abs(resetAt) <= 8.64e15
550
+ ? new Date(resetAt).toISOString()
551
+ : undefined
552
+ limits.push({
553
+ scope: key,
554
+ label: GROUP_NAMES[key],
555
+ kind: 'reading',
556
+ checkedAt,
557
+ remainingPercent: Math.max(0, Math.min(100, remainingPercent)),
558
+ ...(window
559
+ ? { windowMinutes: window === 'weekly' ? 7 * 24 * 60 : 5 * 60 }
560
+ : {}),
561
+ ...(resetsAt ? { resetsAt } : {}),
562
+ })
814
563
  }
564
+ if (limits.length === 0) return undefined
815
565
  return {
816
- prefix: '',
817
- text: windows.some((window) => window.text.resetSinceReading)
818
- ? RESET_SINCE_READING
819
- : NO_QUOTA_READING,
820
- remaining: null,
566
+ scope: 'all',
567
+ limits,
568
+ checkedAt: Math.min(...limits.map((limit) => limit.checkedAt)),
569
+ groups: QUOTA_ORDER.map((scope) => ({
570
+ scope,
571
+ label: GROUP_NAMES[scope],
572
+ })),
821
573
  }
822
574
  }
823
575
 
@@ -998,70 +750,77 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
998
750
  </Show>
999
751
  </box>
1000
752
 
1001
- {/* Collapsed: the active account's lowest current figure and fleet status dot. */}
753
+ {/* Collapsed: one measured, non-wrapping row for each visible account. */}
1002
754
  <Show when={collapsed() && hasData()}>
1003
- {(() => {
1004
- const account = () =>
1005
- visibleAccounts().find((entry) => entry.current) ??
1006
- visibleAccounts()[0]
1007
- const unavailable = () => {
1008
- const selected = account()
755
+ <For each={visibleAccounts()}>
756
+ {(account) => {
757
+ const unavailable = () =>
758
+ !account.enabled ||
759
+ (account.cooldownUntil != null && account.cooldownUntil > now())
760
+ const line = createMemo(() => {
761
+ const currentTime = now()
762
+ const projection = sidebarQuotaProjection(account, currentTime)
763
+ const text = formatQuota(projection, {
764
+ now: currentTime,
765
+ form: 'narrow',
766
+ })
767
+ const remaining = projection?.limits.length
768
+ ? Math.min(
769
+ ...projection.limits.map(
770
+ (limit) => limit.remainingPercent ?? 100,
771
+ ),
772
+ )
773
+ : undefined
774
+ const tone =
775
+ remaining === undefined
776
+ ? 'muted'
777
+ : quotaTone(100 - remaining, prefs().appearance)
778
+ const stale = isQuotaStale(projection, { now: currentTime })
779
+ const dot = unavailable() ? ' ⊘' : ' ●'
780
+ const width = contentWidth()
781
+ // Keep a complete shared line or omit it; a partial quota can
782
+ // make an account look as if it has less remaining.
783
+ const showQuota = text.length <= width
784
+ const showDot =
785
+ dot.length <= width &&
786
+ (!showQuota || text.length + dot.length <= width)
787
+ const rightWidth =
788
+ (showQuota ? text.length : 0) + (showDot ? dot.length : 0)
789
+ const labelWidth = Math.max(0, width - rightWidth - 1)
790
+ return {
791
+ dot,
792
+ label: fitLabel(account.label, labelWidth),
793
+ showDot,
794
+ showQuota,
795
+ stale,
796
+ text,
797
+ tone,
798
+ }
799
+ })
800
+ const quotaColor = () =>
801
+ line().stale ? theme().textMuted : toneColor(theme(), line().tone)
802
+ const dotColor = () =>
803
+ line().stale
804
+ ? theme().textMuted
805
+ : toneColor(theme(), unavailable() ? 'err' : line().tone)
1009
806
  return (
1010
- selected != null &&
1011
- (!selected.enabled ||
1012
- (selected.cooldownUntil != null &&
1013
- selected.cooldownUntil > now()))
807
+ <CollapsedRow theme={theme} label={line().label}>
808
+ <box flexDirection='row' flexShrink={0}>
809
+ <Show when={line().showQuota}>
810
+ <text flexShrink={0} wrapMode='none' fg={quotaColor()}>
811
+ <b>{line().text}</b>
812
+ </text>
813
+ </Show>
814
+ <Show when={line().showDot}>
815
+ <text flexShrink={0} wrapMode='none' fg={dotColor()}>
816
+ {line().dot}
817
+ </text>
818
+ </Show>
819
+ </box>
820
+ </CollapsedRow>
1014
821
  )
1015
- }
1016
- return (
1017
- <Show when={account()}>
1018
- {(selected) => {
1019
- const quota = () => collapsedQuota(selected(), now())
1020
- const tone = (): Tone => {
1021
- const remaining = quota().remaining
1022
- return remaining == null
1023
- ? 'muted'
1024
- : quotaTone(100 - remaining, prefs().appearance)
1025
- }
1026
- // Label, one space, the figure and the two-cell dot. The
1027
- // group prefix goes first when narrow; then the label is cut.
1028
- const figure = () => {
1029
- const { prefix, text } = quota()
1030
- const full = `${prefix}${text}`
1031
- return selected().label.length + 1 + full.length + 2 <=
1032
- contentWidth()
1033
- ? full
1034
- : text
1035
- }
1036
- const label = () =>
1037
- fitLabel(
1038
- selected().label,
1039
- contentWidth() - 1 - figure().length - 2,
1040
- )
1041
- return (
1042
- <CollapsedRow theme={theme} label={label()}>
1043
- <box flexDirection='row' flexShrink={0}>
1044
- <text
1045
- flexShrink={0}
1046
- wrapMode='none'
1047
- fg={toneColor(theme(), tone())}
1048
- >
1049
- <b>{figure()}</b>
1050
- </text>
1051
- <text
1052
- flexShrink={0}
1053
- wrapMode='none'
1054
- fg={toneColor(theme(), unavailable() ? 'err' : tone())}
1055
- >
1056
- {unavailable() ? ' ⊘' : ' ●'}
1057
- </text>
1058
- </box>
1059
- </CollapsedRow>
1060
- )
1061
- }}
1062
- </Show>
1063
- )
1064
- })()}
822
+ }}
823
+ </For>
1065
824
  </Show>
1066
825
 
1067
826
  {/* Expanded: full sections. Also render when there's no data so the
@@ -1105,10 +864,11 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
1105
864
  >
1106
865
  {(route) => (
1107
866
  <Show
1108
- when={
1109
- 'Route'.length + 1 + routeValue(route()).length <=
1110
- contentWidth()
1111
- }
867
+ when={routeLineFits(
868
+ 'Route',
869
+ routeValue(route()),
870
+ contentWidth(),
871
+ )}
1112
872
  fallback={
1113
873
  <For each={routeLines(route())}>
1114
874
  {(line) => (