@cortexkit/opencode-antigravity-auth 3.0.7 → 3.0.9
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.
- package/dist/cli.js +1097 -78
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +128 -36
- package/dist/index.js +1523 -285
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +183 -64
- package/dist/server.js +1448 -189
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
- package/dist/src/common-auth-embedded/auth-menu/login.js +14 -11
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +36 -2
- package/dist/src/common-auth-embedded/claustrum/consumer.js +154 -6
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/src/common-auth-embedded/claustrum/index.js +4 -1
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +71 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +348 -21
- package/dist/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +10 -2
- package/dist/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/src/common-auth-embedded/quota/format.js +69 -1
- package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/src/common-auth-embedded/source-output.json +87 -55
- package/dist/src/ga/server/index.d.ts +2 -0
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +14 -1
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +2 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +5 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +8 -1
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +8 -6
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +3 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +1 -0
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +1 -1
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +17 -5
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/src/plugin/shared/after-handoff.js +89 -0
- package/dist/src/plugin/shared/after-handoff.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +57 -36
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +11 -8
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +23 -5
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +4 -0
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +12 -0
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/plugin/vault-insula-quota.d.ts +6 -0
- package/dist/src/plugin/vault-insula-quota.d.ts.map +1 -0
- package/dist/src/plugin/vault-insula-quota.js +50 -0
- package/dist/src/plugin/vault-insula-quota.js.map +1 -0
- package/dist/src/plugin/vault-quota-outcome.d.ts +1 -1
- package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -1
- package/dist/src/plugin/vault-quota-outcome.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +82 -66
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +27 -27
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +36 -2
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +71 -0
- package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/types/src/ga/server/index.d.ts +2 -0
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +2 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/quota.d.ts +1 -1
- package/dist/types/src/plugin/quota.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +11 -8
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +4 -0
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-insula-quota.d.ts +6 -0
- package/dist/types/src/plugin/vault-insula-quota.d.ts.map +1 -0
- package/dist/types/src/plugin/vault-quota-outcome.d.ts +1 -1
- package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
- package/src/common-auth-embedded/auth-menu/login.js +14 -11
- package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/src/common-auth-embedded/claustrum/consumer.d.ts +36 -2
- package/src/common-auth-embedded/claustrum/consumer.js +154 -6
- package/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/src/common-auth-embedded/claustrum/index.js +4 -1
- package/src/common-auth-embedded/claustrum/insula.d.ts +71 -0
- package/src/common-auth-embedded/claustrum/insula.js +348 -21
- package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/src/common-auth-embedded/fs/private-files.js +10 -2
- package/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/src/common-auth-embedded/quota/format.js +69 -1
- package/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/src/common-auth-embedded/source-output.json +87 -55
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-compiled/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-compiled/tui.js +123 -97
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-raw/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-raw/tui.tsx +126 -107
- package/src/tui.tsx +126 -107
|
@@ -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
|
|
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
|
-
|
|
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));
|
package/src/tui-raw/tui.tsx
CHANGED
|
@@ -48,13 +48,26 @@ import type {
|
|
|
48
48
|
TuiThemeCurrent,
|
|
49
49
|
} from "@opencode-ai/plugin/tui"
|
|
50
50
|
import { createSlot } from "@opentui/solid"
|
|
51
|
-
import {
|
|
52
|
-
|
|
51
|
+
import {
|
|
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"
|
|
53
67
|
import { getRpcDir } from "./rpc/rpc-dir.js"
|
|
54
68
|
import {
|
|
55
69
|
readSidebarState,
|
|
56
70
|
type SidebarAccountState,
|
|
57
|
-
type SidebarQuotaKey,
|
|
58
71
|
type SidebarStateV1,
|
|
59
72
|
} from "./sidebar-state.js"
|
|
60
73
|
import { createTuiFileLogger, type TuiLogger } from "./tui/file-logger.js"
|
|
@@ -64,16 +77,15 @@ import {
|
|
|
64
77
|
type V1Notification,
|
|
65
78
|
} from "./tui/host-v1.tsx"
|
|
66
79
|
import {
|
|
67
|
-
type AccountWindow,
|
|
68
80
|
ASSUMED_CONTENT_WIDTH,
|
|
69
81
|
accountWindows,
|
|
70
82
|
fitLabel,
|
|
83
|
+
GROUP_NAMES,
|
|
84
|
+
QUOTA_ORDER,
|
|
71
85
|
QuotaAccountBlock,
|
|
72
86
|
type QuotaPalette,
|
|
73
87
|
type QuotaTone,
|
|
74
88
|
quotaTone,
|
|
75
|
-
RESET_SINCE_READING,
|
|
76
|
-
showsFigure,
|
|
77
89
|
} from "./tui/quota-layout.tsx"
|
|
78
90
|
import { routeLineFits } from "./tui/route-layout.js"
|
|
79
91
|
import {
|
|
@@ -137,11 +149,6 @@ let rpcInFlight = false
|
|
|
137
149
|
const GLOBAL_NOTIFICATION_CURSOR = '__global__'
|
|
138
150
|
const MAX_NOTIFICATION_CURSORS = 256
|
|
139
151
|
|
|
140
|
-
// The collapsed row has room for one word before the window name.
|
|
141
|
-
const COLLAPSED_GROUP_NAMES: Record<SidebarQuotaKey, string> = {
|
|
142
|
-
gemini: 'Gemini',
|
|
143
|
-
'non-gemini': 'Other',
|
|
144
|
-
}
|
|
145
152
|
// --- Theme tokens ----------------------------------------------------------
|
|
146
153
|
//
|
|
147
154
|
// The sidebar pulls its colors from the live host theme (`api.theme.current`
|
|
@@ -456,8 +463,8 @@ function StatRow(props: {
|
|
|
456
463
|
}
|
|
457
464
|
|
|
458
465
|
// Fleet CollapsedRow: muted label left, caller-supplied value right. The
|
|
459
|
-
// collapsed view renders one for
|
|
460
|
-
// 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.
|
|
461
468
|
function CollapsedRow(props: {
|
|
462
469
|
theme: () => Theme
|
|
463
470
|
label: string
|
|
@@ -519,45 +526,50 @@ function AccountBlock(props: {
|
|
|
519
526
|
)
|
|
520
527
|
}
|
|
521
528
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
remaining: number | null
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// The collapsed row's figure: the lowest current window across both groups.
|
|
530
|
-
// A window that reset since its reading is not current and never binds.
|
|
531
|
-
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(
|
|
532
533
|
account: SidebarAccountState,
|
|
533
534
|
now: number,
|
|
534
|
-
):
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
let lowest: AccountWindow | undefined
|
|
539
|
-
for (const window of windows) {
|
|
540
|
-
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
|
|
541
539
|
if (
|
|
542
|
-
|
|
543
|
-
(
|
|
540
|
+
typeof checkedAt !== 'number' ||
|
|
541
|
+
!Number.isFinite(checkedAt) ||
|
|
542
|
+
checkedAt < 0 ||
|
|
543
|
+
!Number.isFinite(remainingPercent)
|
|
544
544
|
)
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
+
})
|
|
554
563
|
}
|
|
564
|
+
if (limits.length === 0) return undefined
|
|
555
565
|
return {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
+
})),
|
|
561
573
|
}
|
|
562
574
|
}
|
|
563
575
|
|
|
@@ -738,70 +750,77 @@ export function SidebarPanel(props: SidebarPanelProps): JSX.Element {
|
|
|
738
750
|
</Show>
|
|
739
751
|
</box>
|
|
740
752
|
|
|
741
|
-
{/* Collapsed:
|
|
753
|
+
{/* Collapsed: one measured, non-wrapping row for each visible account. */}
|
|
742
754
|
<Show when={collapsed() && hasData()}>
|
|
743
|
-
{(
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
const
|
|
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)
|
|
749
806
|
return (
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
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>
|
|
754
821
|
)
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
<Show when={account()}>
|
|
758
|
-
{(selected) => {
|
|
759
|
-
const quota = () => collapsedQuota(selected(), now())
|
|
760
|
-
const tone = (): Tone => {
|
|
761
|
-
const remaining = quota().remaining
|
|
762
|
-
return remaining == null
|
|
763
|
-
? 'muted'
|
|
764
|
-
: quotaTone(100 - remaining, prefs().appearance)
|
|
765
|
-
}
|
|
766
|
-
// Label, one space, the figure and the two-cell dot. The
|
|
767
|
-
// group prefix goes first when narrow; then the label is cut.
|
|
768
|
-
const figure = () => {
|
|
769
|
-
const { prefix, text } = quota()
|
|
770
|
-
const full = `${prefix}${text}`
|
|
771
|
-
return selected().label.length + 1 + full.length + 2 <=
|
|
772
|
-
contentWidth()
|
|
773
|
-
? full
|
|
774
|
-
: text
|
|
775
|
-
}
|
|
776
|
-
const label = () =>
|
|
777
|
-
fitLabel(
|
|
778
|
-
selected().label,
|
|
779
|
-
contentWidth() - 1 - figure().length - 2,
|
|
780
|
-
)
|
|
781
|
-
return (
|
|
782
|
-
<CollapsedRow theme={theme} label={label()}>
|
|
783
|
-
<box flexDirection='row' flexShrink={0}>
|
|
784
|
-
<text
|
|
785
|
-
flexShrink={0}
|
|
786
|
-
wrapMode='none'
|
|
787
|
-
fg={toneColor(theme(), tone())}
|
|
788
|
-
>
|
|
789
|
-
<b>{figure()}</b>
|
|
790
|
-
</text>
|
|
791
|
-
<text
|
|
792
|
-
flexShrink={0}
|
|
793
|
-
wrapMode='none'
|
|
794
|
-
fg={toneColor(theme(), unavailable() ? 'err' : tone())}
|
|
795
|
-
>
|
|
796
|
-
{unavailable() ? ' ⊘' : ' ●'}
|
|
797
|
-
</text>
|
|
798
|
-
</box>
|
|
799
|
-
</CollapsedRow>
|
|
800
|
-
)
|
|
801
|
-
}}
|
|
802
|
-
</Show>
|
|
803
|
-
)
|
|
804
|
-
})()}
|
|
822
|
+
}}
|
|
823
|
+
</For>
|
|
805
824
|
</Show>
|
|
806
825
|
|
|
807
826
|
{/* Expanded: full sections. Also render when there's no data so the
|