@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
@@ -63,8 +63,12 @@ export function quotaWindowName(limit) {
63
63
  function clampPercent(remaining) {
64
64
  return Math.min(100, Math.max(0, remaining));
65
65
  }
66
+ /** A remaining percentage as the whole number every form shows. */
67
+ function wholePercent(remaining) {
68
+ return Math.round(clampPercent(remaining));
69
+ }
66
70
  function percentLeft(remaining) {
67
- return `${Math.round(clampPercent(remaining))}% left`;
71
+ return `${wholePercent(remaining)}% left`;
68
72
  }
69
73
  function resetDetails(resetsAt, checkedAt, now) {
70
74
  const at = resetsAt === undefined ? Number.NaN : Date.parse(resetsAt);
@@ -98,6 +102,16 @@ function displayOrder(left, right) {
98
102
  * and the optional age keep the shared formatter's wording.
99
103
  */
100
104
  export function quotaWindowParts(quota, options) {
105
+ const { windows, age } = scopedWindowParts(quota, options);
106
+ const parts = windows.map(({ part }) => part);
107
+ return age === undefined ? { windows: parts } : { windows: parts, age };
108
+ }
109
+ /**
110
+ * `quotaWindowParts` with each window's scope kept beside it. The narrow form
111
+ * needs the scope to name and pick model-scoped windows; the public parts do
112
+ * not carry it, so their shape stays as it was.
113
+ */
114
+ function scopedWindowParts(quota, options) {
101
115
  if (!quota)
102
116
  return { windows: [] };
103
117
  const { now } = options;
@@ -107,12 +121,18 @@ export function quotaWindowParts(quota, options) {
107
121
  const windows = readings.map((limit) => {
108
122
  const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
109
123
  return {
110
- kind: 'window',
111
- name: quotaWindowName(limit),
112
- figure: percentLeft(limit.remainingPercent ?? 0),
113
- remainingPercent,
114
- checkedAt: limit.checkedAt,
115
- ...resetDetails(limit.resetsAt, limit.checkedAt, now),
124
+ scope: limit.scope,
125
+ ...(limit.windowMinutes === undefined
126
+ ? {}
127
+ : { windowMinutes: limit.windowMinutes }),
128
+ part: {
129
+ kind: 'window',
130
+ name: quotaWindowName(limit),
131
+ figure: percentLeft(limit.remainingPercent ?? 0),
132
+ remainingPercent,
133
+ checkedAt: limit.checkedAt,
134
+ ...resetDetails(limit.resetsAt, limit.checkedAt, now),
135
+ },
116
136
  };
117
137
  });
118
138
  const budget = quota.budget;
@@ -124,32 +144,196 @@ export function quotaWindowParts(quota, options) {
124
144
  ? `credits ${percentLeft(remainingPercent)}`
125
145
  : 'credits available';
126
146
  windows.push({
127
- kind: 'budget',
128
- name: 'credits',
129
- figure,
130
- ...(remainingPercent === undefined
131
- ? {}
132
- : { remainingPercent: clampPercent(remainingPercent) }),
133
- checkedAt: budget.checkedAt,
134
- ...resetDetails(budget.resetsAt, budget.checkedAt, now),
147
+ scope: ALL_SCOPE,
148
+ spent: budget.reached,
149
+ part: {
150
+ kind: 'budget',
151
+ name: 'credits',
152
+ figure,
153
+ ...(remainingPercent === undefined
154
+ ? {}
155
+ : { remainingPercent: clampPercent(remainingPercent) }),
156
+ checkedAt: budget.checkedAt,
157
+ ...resetDetails(budget.resetsAt, budget.checkedAt, now),
158
+ },
135
159
  });
136
160
  }
137
161
  if (windows.length > 0) {
138
- const age = now - Math.min(...windows.map((part) => part.checkedAt));
162
+ const age = now - Math.min(...windows.map(({ part }) => part.checkedAt));
139
163
  if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
140
164
  return { windows, age: `checked ${shortSpan(age)} ago` };
141
165
  }
142
166
  }
143
167
  return { windows };
144
168
  }
169
+ /**
170
+ * Whether the reading is stale: true exactly when the compact and full forms
171
+ * would end with `checked … ago`. The narrow form leaves that age out to stay
172
+ * short, so a caller drawing a narrow line uses this to dim it instead.
173
+ */
174
+ export function isQuotaStale(quota, options) {
175
+ return scopedWindowParts(quota, options).age !== undefined;
176
+ }
177
+ /**
178
+ * The model a scope names, as a display name: any namespace before a colon
179
+ * is dropped (`model:claude-opus-4` → `claude-opus-4`) and the first letter is
180
+ * capitalized (`fable` → `Fable`); the rest stays as written.
181
+ */
182
+ function scopeDisplayName(scope) {
183
+ const model = scope.slice(scope.indexOf(':') + 1);
184
+ return model.charAt(0).toUpperCase() + model.slice(1);
185
+ }
186
+ /**
187
+ * Short names for the model scopes in one row: the first two letters of each
188
+ * display name. Names that would read the same for different models are each
189
+ * extended one letter at a time until they differ (`Fable` and `Fabric` read
190
+ * `Fabl` and `Fabr`); a name that runs out of letters stays whole.
191
+ */
192
+ function scopeAbbreviations(scopes) {
193
+ const names = [...new Set(scopes.map(scopeDisplayName))];
194
+ const lengths = new Map(names.map((name) => [name, 2]));
195
+ const short = (name) => name.slice(0, lengths.get(name));
196
+ for (;;) {
197
+ const byShort = new Map();
198
+ for (const name of names) {
199
+ byShort.set(short(name), [...(byShort.get(short(name)) ?? []), name]);
200
+ }
201
+ let extended = false;
202
+ for (const group of byShort.values()) {
203
+ if (group.length < 2)
204
+ continue;
205
+ for (const name of group) {
206
+ const length = lengths.get(name) ?? 2;
207
+ if (length < name.length) {
208
+ lengths.set(name, length + 1);
209
+ extended = true;
210
+ }
211
+ }
212
+ }
213
+ if (!extended)
214
+ break;
215
+ }
216
+ return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
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
+ }
278
+ /**
279
+ * The narrow form's pieces: every account-wide window as `5h 92%`, then at
280
+ * most one more item, with ` left` added once to the last piece. That item is
281
+ * the tightest (least remaining) of the model-scoped windows and the credit
282
+ * budget, so the line stays bounded whatever the account carries: a scoped
283
+ * window reads under its short model name (`Fa 98%`), the budget as `cr 75%`
284
+ * (`cr 0%` when spent). On a tie a scoped window wins over the budget, and
285
+ * among scoped windows the first in display order wins. The choice depends
286
+ * only on the reading, never on a width. A budget without a percentage cannot
287
+ * be chosen; when nothing at all is shown it keeps its compact wording
288
+ * (`credits available`). No age is added; `isQuotaStale` says whether the
289
+ * reading is stale. A window whose reset arrived after the reading keeps its
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`).
293
+ */
294
+ function narrowTextParts(quota, options) {
295
+ const { windows } = scopedWindowParts(quota, options);
296
+ const grouped = groupedNarrowPieces(quota?.groups, windows);
297
+ if (grouped)
298
+ return grouped;
299
+ const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
300
+ const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
301
+ const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
302
+ // The items competing for the one slot after the account-wide windows, in
303
+ // tie-break order: scoped windows in display order, then the budget. A
304
+ // spent budget counts as 0% left; one without a percentage cannot compete.
305
+ const budget = windows.find(({ part }) => part.kind === 'budget');
306
+ const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
307
+ const extras = [
308
+ ...scoped.map(({ scope, part }) => ({
309
+ label: abbreviations.get(scope) ?? scope,
310
+ remaining: part.remainingPercent ?? 0,
311
+ })),
312
+ ...(budgetLeft === undefined
313
+ ? []
314
+ : [{ label: 'cr', remaining: budgetLeft }]),
315
+ ];
316
+ // Strictly lower wins, so on a tie the earlier item keeps the slot.
317
+ const tightest = extras.reduce((best, item) => best === undefined || item.remaining < best.remaining ? item : best, undefined);
318
+ const pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
319
+ if (tightest) {
320
+ pieces.push(`${tightest.label} ${wholePercent(tightest.remaining)}%`);
321
+ }
322
+ if (pieces.length === 0)
323
+ return windows.map(({ part }) => part.figure);
324
+ return pieces.map((piece, index) => index === pieces.length - 1 ? `${piece} left` : piece);
325
+ }
145
326
  /**
146
327
  * The pieces of a quota text, in order: one per reported window
147
328
  * (`5h 58% left, resets 2h`), then the credit budget when there is one, then
148
329
  * `checked 3h ago` when the oldest piece shown is stale. Empty when nothing
149
330
  * was reported; `formatQuota` turns that into a sentence. A caller printing
150
- * one line per window (the terminal auth menu) uses these directly.
331
+ * one line per window (the terminal auth menu) uses these directly. In the
332
+ * narrow form the pieces are the narrow line's (`5h 92%`, `7d 66% left`).
151
333
  */
152
334
  export function quotaTextParts(quota, options) {
335
+ if (options.form === 'narrow')
336
+ return narrowTextParts(quota, options);
153
337
  const parts = quotaWindowParts(quota, options);
154
338
  const full = (options.form ?? 'full') === 'full';
155
339
  const text = parts.windows.map((part) => {
@@ -160,7 +344,8 @@ export function quotaTextParts(quota, options) {
160
344
  }
161
345
  /**
162
346
  * A row's quota as one line: `5h 58% left · 7d 90% left` in the compact
163
- * form, with `, resets 2h` after each window in the full form. With nothing
347
+ * form, with `, resets 2h` after each window in the full form, and
348
+ * `5h 58% · 7d 90% left` in the narrow form. With nothing
164
349
  * reported it is `NO_QUOTA_READING`, or `NO_LIMITS_REPORTED` when the
165
350
  * provider answered without a limit for any window.
166
351
  */
@@ -1,10 +1,10 @@
1
1
  export type { QuotaCodec } from './codec.js';
2
2
  export { quotaCodec } from './codec.js';
3
3
  export type { QuotaParts, QuotaTextForm, QuotaTextOptions, QuotaWindowPart, } from './format.js';
4
- export { formatQuota, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, quotaWindowParts, } from './format.js';
4
+ export { formatQuota, isQuotaStale, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, quotaWindowParts, } from './format.js';
5
5
  export type { CreditBudgetCleared, CreditBudgetEntry, CreditBudgetReading, QuotaAbsentEntry, QuotaCounter, QuotaEntry, QuotaMap, QuotaReadingEntry, QuotaRetiredEntry, } from './map.js';
6
6
  export { ALL_SCOPE, DEFAULT_REQUIRED_LABELS, decodeQuotaMap, emptyQuotaMap, isQuotaMap, } from './map.js';
7
7
  export type { ObservedBudget, ObservedPair, ObservedReading, QuotaObservation, } from './merge.js';
8
8
  export { isQuotaObservation, mergeQuotaObservation, QuotaCodecError, } from './merge.js';
9
- export type { ExhaustionReset, ProjectedBudget, ProjectedLimit, ProjectedQuota, } from './projection.js';
9
+ export type { ExhaustionReset, ProjectedBudget, ProjectedLimit, ProjectedQuota, QuotaGroup, } from './projection.js';
10
10
  export { budgetExhaustedResetAt, futureResetAt, projectQuota, readsExhausted, } from './projection.js';
@@ -1,5 +1,5 @@
1
1
  export { quotaCodec } from './codec.js';
2
- export { formatQuota, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, quotaWindowParts, } from './format.js';
2
+ export { formatQuota, isQuotaStale, NO_LIMITS_REPORTED, NO_QUOTA_READING, QUOTA_STALE_AFTER_MS, quotaTextParts, quotaWindowName, quotaWindowParts, } from './format.js';
3
3
  export { ALL_SCOPE, DEFAULT_REQUIRED_LABELS, decodeQuotaMap, emptyQuotaMap, isQuotaMap, } from './map.js';
4
4
  export { isQuotaObservation, mergeQuotaObservation, QuotaCodecError, } from './merge.js';
5
5
  export { budgetExhaustedResetAt, futureResetAt, projectQuota, readsExhausted, } from './projection.js';
@@ -19,6 +19,15 @@ export interface ProjectedBudget {
19
19
  remainingPercent?: number;
20
20
  resetsAt?: string;
21
21
  }
22
+ /**
23
+ * A named group of windows, such as antigravity-auth's `Gemini` and
24
+ * `Other models`: every window stored under `scope` belongs to it, and
25
+ * `label` is the group's display name.
26
+ */
27
+ export interface QuotaGroup {
28
+ scope: string;
29
+ label: string;
30
+ }
22
31
  export interface ProjectedQuota {
23
32
  scope: string;
24
33
  /** One entry per label: longest known window first, unknown lengths last. */
@@ -31,6 +40,13 @@ export interface ProjectedQuota {
31
40
  /** Present only when the stored budget is a reading, not cleared. */
32
41
  budget?: ProjectedBudget;
33
42
  counters?: Record<string, QuotaCounter>;
43
+ /**
44
+ * The named groups the windows belong to, in the order the plugin lists
45
+ * them. Set only by a plugin whose windows all belong to such groups; the
46
+ * narrow form then shows one item per group (see `formatQuota`).
47
+ * `projectQuota` never sets it.
48
+ */
49
+ groups?: readonly QuotaGroup[];
34
50
  }
35
51
  /**
36
52
  * Resolves `map` for a request in `scope` (`all` or a model family). A family
@@ -0,0 +1,32 @@
1
+ import type { SetupHostEnrollment } from './types.js';
2
+ /**
3
+ * Keeps the Pi install refusal message stable while exposing safe process details.
4
+ * A clipped tail can start inside a credential, so discard its first line—or
5
+ * the whole tail if it has no newline—before redacting.
6
+ */
7
+ export declare class SetupCommandError extends Error {
8
+ readonly step = "pi-install";
9
+ readonly exitCode: number | null;
10
+ readonly signal: string | null;
11
+ readonly stderrTail: string;
12
+ constructor(details: {
13
+ exitCode: number | null;
14
+ signal: string | null;
15
+ stderrTail: string;
16
+ stderrTruncated?: boolean;
17
+ });
18
+ }
19
+ /** The line setup prints for one host's outcome, e.g. `Pi: not connected`. */
20
+ export declare function setupEnrollmentLine({ host, outcome, }: SetupHostEnrollment): string;
21
+ /**
22
+ * Remember which hosts a failed setup left connected to the vault, against the
23
+ * thrown value. Only objects can carry a record; a thrown primitive is left as
24
+ * it is, and the printed lines are then the only report.
25
+ */
26
+ export declare function recordSetupEnrollment(failure: unknown, enrollment: readonly SetupHostEnrollment[]): void;
27
+ /**
28
+ * The per-host vault enrollment outcomes a failed `runSetup` recorded for the
29
+ * value it threw, or `undefined` when setup failed before any host's enrollment
30
+ * began, or the value is not one setup threw (or is not an object).
31
+ */
32
+ export declare function setupEnrollment(error: unknown): readonly SetupHostEnrollment[] | undefined;
@@ -0,0 +1,79 @@
1
+ import { redact } from '../logger/redact.js';
2
+ import { STDERR_TAIL_MAX_BYTES } from './command-runner.js';
3
+ const PI_INSTALL_ERROR_MESSAGE = 'Pi install failed; run pi install after checking your npm connection.';
4
+ function utf8Tail(value) {
5
+ const bytes = Buffer.from(value, 'utf8');
6
+ if (bytes.length <= STDERR_TAIL_MAX_BYTES)
7
+ return value;
8
+ let start = bytes.length - STDERR_TAIL_MAX_BYTES;
9
+ while (start < bytes.length) {
10
+ const byte = bytes[start];
11
+ if (byte === undefined || (byte & 0xc0) !== 0x80)
12
+ break;
13
+ start++;
14
+ }
15
+ return bytes.subarray(start).toString('utf8');
16
+ }
17
+ function dropPartialLine(tail) {
18
+ const newline = tail.indexOf('\n');
19
+ return newline < 0 ? '' : tail.slice(newline + 1);
20
+ }
21
+ /**
22
+ * Keeps the Pi install refusal message stable while exposing safe process details.
23
+ * A clipped tail can start inside a credential, so discard its first line—or
24
+ * the whole tail if it has no newline—before redacting.
25
+ */
26
+ export class SetupCommandError extends Error {
27
+ step = 'pi-install';
28
+ exitCode;
29
+ signal;
30
+ stderrTail;
31
+ constructor(details) {
32
+ super(PI_INSTALL_ERROR_MESSAGE);
33
+ this.name = 'SetupCommandError';
34
+ this.exitCode = details.exitCode;
35
+ this.signal = details.signal;
36
+ const tail = details.stderrTruncated
37
+ ? dropPartialLine(details.stderrTail)
38
+ : details.stderrTail;
39
+ const redacted = redact(tail);
40
+ this.stderrTail = utf8Tail(typeof redacted === 'string' ? redacted : '');
41
+ }
42
+ }
43
+ const HOST_LABELS = { opencode: 'OpenCode', pi: 'Pi' };
44
+ const OUTCOME_TEXT = {
45
+ enrolled: 'connected to the vault',
46
+ 'not-enrolled': 'not connected',
47
+ unknown: 'unknown, check with ck auth status',
48
+ };
49
+ /** The line setup prints for one host's outcome, e.g. `Pi: not connected`. */
50
+ export function setupEnrollmentLine({ host, outcome, }) {
51
+ return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
52
+ }
53
+ // Outcomes recorded against the value a failed `runSetup` threw. A WeakMap
54
+ // keeps the thrown value itself untouched: setup never reads, rewrites or
55
+ // stringifies what a step or plugin callback threw, so a getter, a proxy or a
56
+ // frozen error behaves exactly as it would without setup in between, and
57
+ // callers that classify errors by message see the original text.
58
+ const recordedEnrollment = new WeakMap();
59
+ /**
60
+ * Remember which hosts a failed setup left connected to the vault, against the
61
+ * thrown value. Only objects can carry a record; a thrown primitive is left as
62
+ * it is, and the printed lines are then the only report.
63
+ */
64
+ export function recordSetupEnrollment(failure, enrollment) {
65
+ if ((typeof failure !== 'object' && typeof failure !== 'function') ||
66
+ !failure)
67
+ return;
68
+ recordedEnrollment.set(failure, Object.freeze(enrollment.map((entry) => Object.freeze({ ...entry }))));
69
+ }
70
+ /**
71
+ * The per-host vault enrollment outcomes a failed `runSetup` recorded for the
72
+ * value it threw, or `undefined` when setup failed before any host's enrollment
73
+ * began, or the value is not one setup threw (or is not an object).
74
+ */
75
+ export function setupEnrollment(error) {
76
+ if ((typeof error !== 'object' && typeof error !== 'function') || !error)
77
+ return undefined;
78
+ return recordedEnrollment.get(error);
79
+ }
@@ -1,35 +1,129 @@
1
- import { execFile } from 'node:child_process';
1
+ import { spawn } from 'node:child_process';
2
+ export const STDERR_TAIL_MAX_BYTES = 4 * 1024;
3
+ const STDOUT_MAX_BYTES = 1024 * 1024;
4
+ class ByteTail {
5
+ buffer = Buffer.alloc(STDERR_TAIL_MAX_BYTES);
6
+ start = 0;
7
+ length = 0;
8
+ truncated = false;
9
+ get didTruncate() {
10
+ return this.truncated;
11
+ }
12
+ push(chunk) {
13
+ if (chunk.length >= STDERR_TAIL_MAX_BYTES) {
14
+ if (chunk.length > STDERR_TAIL_MAX_BYTES || this.length > 0)
15
+ this.truncated = true;
16
+ chunk.copy(this.buffer, 0, chunk.length - STDERR_TAIL_MAX_BYTES);
17
+ this.start = 0;
18
+ this.length = STDERR_TAIL_MAX_BYTES;
19
+ return;
20
+ }
21
+ const overflow = Math.max(0, this.length + chunk.length - STDERR_TAIL_MAX_BYTES);
22
+ if (overflow > 0)
23
+ this.truncated = true;
24
+ this.start = (this.start + overflow) % STDERR_TAIL_MAX_BYTES;
25
+ this.length -= overflow;
26
+ const writeAt = (this.start + this.length) % STDERR_TAIL_MAX_BYTES;
27
+ const firstLength = Math.min(chunk.length, STDERR_TAIL_MAX_BYTES - writeAt);
28
+ chunk.copy(this.buffer, writeAt, 0, firstLength);
29
+ if (firstLength < chunk.length)
30
+ chunk.copy(this.buffer, 0, firstLength);
31
+ this.length += chunk.length;
32
+ }
33
+ toString() {
34
+ const bytes = Buffer.alloc(this.length);
35
+ const firstLength = Math.min(this.length, STDERR_TAIL_MAX_BYTES - this.start);
36
+ this.buffer.copy(bytes, 0, this.start, this.start + firstLength);
37
+ if (firstLength < this.length)
38
+ this.buffer.copy(bytes, firstLength, 0, this.length - firstLength);
39
+ let start = 0;
40
+ while (start < bytes.length) {
41
+ const byte = bytes[start];
42
+ if (byte === undefined || (byte & 0xc0) !== 0x80)
43
+ break;
44
+ start++;
45
+ }
46
+ return bytes.subarray(start).toString('utf8');
47
+ }
48
+ }
2
49
  export const defaultCommandRunner = {
3
50
  run(file, args, options = {}) {
4
51
  return new Promise((resolve) => {
5
52
  const started = performance.now();
6
53
  const timeoutMs = options.timeoutMs ?? 15_000;
7
- execFile(file, [...args], {
8
- env: options.env ?? process.env,
9
- timeout: timeoutMs,
10
- windowsHide: true,
11
- windowsVerbatimArguments: options.windowsVerbatimArguments,
12
- maxBuffer: 1024 * 1024,
13
- }, (error, stdout, stderr) => {
14
- const durationMs = performance.now() - started;
54
+ const stderr = new ByteTail();
55
+ const stdout = [];
56
+ let stdoutLength = 0;
57
+ let outputExceeded = false;
58
+ let spawnError = false;
59
+ let timedOut = false;
60
+ let child;
61
+ try {
62
+ child = spawn(file, [...args], {
63
+ env: options.env ?? process.env,
64
+ windowsHide: true,
65
+ windowsVerbatimArguments: options.windowsVerbatimArguments,
66
+ stdio: ['ignore', 'pipe', 'pipe'],
67
+ });
68
+ }
69
+ catch {
70
+ resolve({
71
+ exitCode: 1,
72
+ stdout: '',
73
+ stderr: '',
74
+ spawnError: true,
75
+ signal: null,
76
+ timedOut: false,
77
+ durationMs: performance.now() - started,
78
+ });
79
+ return;
80
+ }
81
+ const timer = timeoutMs > 0
82
+ ? setTimeout(() => {
83
+ timedOut = true;
84
+ child.kill('SIGTERM');
85
+ }, timeoutMs)
86
+ : undefined;
87
+ child.stdout?.on('data', (chunk) => {
88
+ const remaining = STDOUT_MAX_BYTES - stdoutLength;
89
+ const length = Math.min(remaining, chunk.length);
90
+ if (length > 0) {
91
+ stdout.push(chunk.subarray(0, length));
92
+ stdoutLength += length;
93
+ }
94
+ if (chunk.length > remaining) {
95
+ outputExceeded = true;
96
+ child.kill('SIGTERM');
97
+ }
98
+ });
99
+ child.stderr?.on('data', (chunk) => stderr.push(chunk));
100
+ let settled = false;
101
+ const settle = (code, signal) => {
102
+ if (settled)
103
+ return;
104
+ settled = true;
105
+ if (timer)
106
+ clearTimeout(timer);
15
107
  resolve({
16
- exitCode: error
17
- ? typeof error.code === 'number'
18
- ? error.code
19
- : 1
20
- : 0,
21
- stdout: String(stdout ?? ''),
22
- stderr: String(stderr ?? ''),
23
- signal: error?.signal ?? null,
24
- // Buffer-limit and spawn errors have string codes, not timeout kills.
25
- timedOut: error?.killed === true &&
26
- typeof error.code !== 'string' &&
27
- error.signal === 'SIGTERM' &&
28
- durationMs >= timeoutMs &&
29
- timeoutMs > 0,
30
- durationMs,
108
+ exitCode: spawnError ? 1 : outputExceeded ? 1 : (code ?? 1),
109
+ stdout: Buffer.concat(stdout, stdoutLength).toString('utf8'),
110
+ stderr: stderr.toString(),
111
+ stderrTruncated: stderr.didTruncate,
112
+ ...(spawnError ? { spawnError: true } : {}),
113
+ signal: signal ?? null,
114
+ timedOut,
115
+ durationMs: performance.now() - started,
31
116
  });
117
+ };
118
+ child.once('error', () => {
119
+ spawnError = true;
120
+ // A child that never started (ENOENT, EACCES) has no process for the
121
+ // timer to kill. Node documents no guarantee that 'close' follows that
122
+ // 'error', so settle here rather than wait for it.
123
+ if (child.pid === undefined)
124
+ settle(null, null);
32
125
  });
126
+ child.once('close', (code, signal) => settle(code, signal));
33
127
  });
34
128
  },
35
129
  };