@cortexkit/opencode-antigravity-auth 3.0.9 → 3.0.11
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 +803 -281
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +142 -53
- package/dist/index.js +1114 -471
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +152 -63
- package/dist/server.js +1145 -502
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +25 -21
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +27 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -0
- package/dist/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/dist/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/dist/src/common-auth-embedded/claustrum/roster.js +100 -43
- package/dist/src/common-auth-embedded/fs/private-files.d.ts +2 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +49 -3
- package/dist/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
- package/dist/src/common-auth-embedded/fs/with-lock.js +2 -0
- package/dist/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/dist/src/common-auth-embedded/quota/format.js +50 -5
- package/dist/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/dist/src/common-auth-embedded/quota/index.js +2 -2
- package/dist/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/dist/src/common-auth-embedded/quota/map.js +31 -6
- package/dist/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/dist/src/common-auth-embedded/quota/merge.js +17 -3
- package/dist/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/dist/src/common-auth-embedded/quota/projection.js +3 -1
- package/dist/src/common-auth-embedded/setup/enroll.d.ts +34 -0
- package/dist/src/common-auth-embedded/setup/enroll.js +116 -34
- package/dist/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/setup/index.js +1 -0
- package/dist/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
- package/dist/src/common-auth-embedded/setup/process-fence.js +61 -4
- package/dist/src/common-auth-embedded/setup/types.d.ts +5 -0
- package/dist/src/common-auth-embedded/source-output.json +115 -91
- package/dist/src/plugin/lifecycle.d.ts.map +1 -1
- package/dist/src/plugin/lifecycle.js +48 -27
- package/dist/src/plugin/lifecycle.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +5 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +1 -0
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +125 -7
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +13 -3
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/tui-build-map.json +25 -25
- package/dist/tui-ga-build-map.json +21 -21
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/dist/types/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/dist/types/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +34 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +5 -0
- package/dist/types/src/plugin/config/schema.d.ts +2 -2
- package/dist/types/src/plugin/lifecycle.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts +5 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/consumer.d.ts +3 -1
- package/src/common-auth-embedded/claustrum/consumer.js +25 -21
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +5 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +27 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/index.js +1 -0
- package/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/src/common-auth-embedded/claustrum/roster.js +100 -43
- package/src/common-auth-embedded/fs/private-files.d.ts +2 -0
- package/src/common-auth-embedded/fs/private-files.js +49 -3
- package/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
- package/src/common-auth-embedded/fs/with-lock.js +2 -0
- package/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/src/common-auth-embedded/quota/format.js +50 -5
- package/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/src/common-auth-embedded/quota/index.js +2 -2
- package/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/src/common-auth-embedded/quota/map.js +31 -6
- package/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/src/common-auth-embedded/quota/merge.js +17 -3
- package/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/src/common-auth-embedded/quota/projection.js +3 -1
- package/src/common-auth-embedded/setup/enroll.d.ts +34 -0
- package/src/common-auth-embedded/setup/enroll.js +116 -34
- package/src/common-auth-embedded/setup/index.d.ts +1 -0
- package/src/common-auth-embedded/setup/index.js +1 -0
- package/src/common-auth-embedded/setup/process-fence.d.ts +14 -0
- package/src/common-auth-embedded/setup/process-fence.js +61 -4
- package/src/common-auth-embedded/setup/types.d.ts +5 -0
- package/src/common-auth-embedded/source-output.json +115 -91
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +49 -3
- package/src/tui-compiled/common-auth-embedded/quota/format.js +50 -5
- package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-compiled/common-auth-embedded/quota/map.js +31 -6
- package/src/tui-compiled/common-auth-embedded/quota/merge.js +17 -3
- package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
- package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +31 -6
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +50 -5
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +17 -3
- package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +31 -6
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +50 -5
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +17 -3
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +49 -3
- package/src/tui-raw/common-auth-embedded/quota/format.js +50 -5
- package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-raw/common-auth-embedded/quota/map.js +31 -6
- package/src/tui-raw/common-auth-embedded/quota/merge.js +17 -3
- package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
package/dist/index.js
CHANGED
|
@@ -64,6 +64,12 @@ function isQuotaCounter(value) {
|
|
|
64
64
|
function isQuotaCounters(value) {
|
|
65
65
|
return isRecord2(value) && Object.values(value).every(isQuotaCounter);
|
|
66
66
|
}
|
|
67
|
+
function isBoolean(value) {
|
|
68
|
+
return typeof value === "boolean";
|
|
69
|
+
}
|
|
70
|
+
function isQuotaCredits(value) {
|
|
71
|
+
return isRecord2(value) && typeof value.hasCredits === "boolean" && typeof value.unlimited === "boolean" && optional2(value, "balance", isFiniteNumber) && optional2(value, "overageLimitReached", isBoolean) && isFiniteNumber(value.checkedAt);
|
|
72
|
+
}
|
|
67
73
|
function readQuotaCounters(value) {
|
|
68
74
|
if (!isRecord2(value))
|
|
69
75
|
return void 0;
|
|
@@ -75,11 +81,16 @@ function decodeQuotaMap(value) {
|
|
|
75
81
|
return value;
|
|
76
82
|
if (!isRecord2(value))
|
|
77
83
|
return void 0;
|
|
78
|
-
const { counters: rawCounters, ...rest } = value;
|
|
84
|
+
const { counters: rawCounters, credits: rawCredits, ...rest } = value;
|
|
79
85
|
if (!isQuotaMap(rest))
|
|
80
86
|
return void 0;
|
|
81
87
|
const counters = readQuotaCounters(rawCounters);
|
|
82
|
-
|
|
88
|
+
const credits = isQuotaCredits(rawCredits) ? rawCredits : void 0;
|
|
89
|
+
return {
|
|
90
|
+
...rest,
|
|
91
|
+
...counters === void 0 ? {} : { counters },
|
|
92
|
+
...credits === void 0 ? {} : { credits }
|
|
93
|
+
};
|
|
83
94
|
}
|
|
84
95
|
function isQuotaMap(value) {
|
|
85
96
|
if (!isRecord2(value) || !Array.isArray(value.limits))
|
|
@@ -93,7 +104,7 @@ function isQuotaMap(value) {
|
|
|
93
104
|
return false;
|
|
94
105
|
seen.add(key);
|
|
95
106
|
}
|
|
96
|
-
return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters);
|
|
107
|
+
return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters) && optional2(value, "credits", isQuotaCredits);
|
|
97
108
|
}
|
|
98
109
|
var ALL_SCOPE, DEFAULT_REQUIRED_LABELS;
|
|
99
110
|
var init_map = __esm({
|
|
@@ -156,7 +167,7 @@ function isQuotaObservation(value) {
|
|
|
156
167
|
}
|
|
157
168
|
if (!coverage.every(isObservedPair))
|
|
158
169
|
return false;
|
|
159
|
-
return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters));
|
|
170
|
+
return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters)) && (value.credits === void 0 || isQuotaCredits(value.credits));
|
|
160
171
|
}
|
|
161
172
|
function compareEntries(left, right) {
|
|
162
173
|
if (left.scope !== right.scope)
|
|
@@ -182,6 +193,14 @@ function mergeCounters(stored, observed) {
|
|
|
182
193
|
}
|
|
183
194
|
return counters.size === 0 ? void 0 : Object.fromEntries(counters);
|
|
184
195
|
}
|
|
196
|
+
function mergeCredits(stored, observed) {
|
|
197
|
+
if (observed === void 0)
|
|
198
|
+
return stored;
|
|
199
|
+
if (stored !== void 0 && observed.checkedAt < stored.checkedAt) {
|
|
200
|
+
return stored;
|
|
201
|
+
}
|
|
202
|
+
return { ...observed };
|
|
203
|
+
}
|
|
185
204
|
function mergeQuotaObservation(stored, observation) {
|
|
186
205
|
const decoded = stored === void 0 ? void 0 : decodeQuotaMap(stored);
|
|
187
206
|
if (stored !== void 0 && decoded === void 0) {
|
|
@@ -225,14 +244,16 @@ function mergeQuotaObservation(stored, observation) {
|
|
|
225
244
|
const existing = entries.get(key);
|
|
226
245
|
entries.set(key, existing === void 0 || existing.kind === "absent" ? { scope, label: pair.label, kind: "absent", checkedAt: at } : { scope, label: pair.label, kind: "retired", retiredAt: at });
|
|
227
246
|
}
|
|
228
|
-
const { limits: _limits, budget: _budget, counters: _counters, ...unknownKeys } = base;
|
|
247
|
+
const { limits: _limits, budget: _budget, counters: _counters, credits: _credits, ...unknownKeys } = base;
|
|
229
248
|
const budget = mergeBudget(base.budget, observation.budget, at);
|
|
230
249
|
const counters = mergeCounters(base.counters, observation.counters);
|
|
250
|
+
const credits = mergeCredits(base.credits, observation.credits);
|
|
231
251
|
return {
|
|
232
252
|
...unknownKeys,
|
|
233
253
|
limits: [...entries.values()].sort(compareEntries),
|
|
234
254
|
...budget === void 0 ? {} : { budget },
|
|
235
|
-
...counters === void 0 ? {} : { counters }
|
|
255
|
+
...counters === void 0 ? {} : { counters },
|
|
256
|
+
...credits === void 0 ? {} : { credits }
|
|
236
257
|
};
|
|
237
258
|
}
|
|
238
259
|
var QuotaCodecError;
|
|
@@ -327,6 +348,13 @@ function quotaWindowParts(quota, options) {
|
|
|
327
348
|
const parts = windows2.map(({ part }) => part);
|
|
328
349
|
return age === void 0 ? { windows: parts } : { windows: parts, age };
|
|
329
350
|
}
|
|
351
|
+
function withShortNames(windows2) {
|
|
352
|
+
const abbreviations = scopeAbbreviations(windows2.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE).map(({ scope }) => scope));
|
|
353
|
+
for (const window of windows2) {
|
|
354
|
+
window.part.short = window.part.kind === "budget" ? "cr" : window.scope === ALL_SCOPE ? window.part.name : abbreviations.get(window.scope) ?? window.scope;
|
|
355
|
+
}
|
|
356
|
+
return windows2;
|
|
357
|
+
}
|
|
330
358
|
function scopedWindowParts(quota, options) {
|
|
331
359
|
if (!quota)
|
|
332
360
|
return { windows: [] };
|
|
@@ -340,6 +368,7 @@ function scopedWindowParts(quota, options) {
|
|
|
340
368
|
part: {
|
|
341
369
|
kind: "window",
|
|
342
370
|
name: quotaWindowName(limit),
|
|
371
|
+
short: "",
|
|
343
372
|
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
344
373
|
remainingPercent,
|
|
345
374
|
checkedAt: limit.checkedAt,
|
|
@@ -357,6 +386,7 @@ function scopedWindowParts(quota, options) {
|
|
|
357
386
|
part: {
|
|
358
387
|
kind: "budget",
|
|
359
388
|
name: "credits",
|
|
389
|
+
short: "",
|
|
360
390
|
figure,
|
|
361
391
|
...remainingPercent === void 0 ? {} : { remainingPercent: clampPercent(remainingPercent) },
|
|
362
392
|
checkedAt: budget.checkedAt,
|
|
@@ -364,6 +394,7 @@ function scopedWindowParts(quota, options) {
|
|
|
364
394
|
}
|
|
365
395
|
});
|
|
366
396
|
}
|
|
397
|
+
withShortNames(windows2);
|
|
367
398
|
if (windows2.length > 0) {
|
|
368
399
|
const age = now - Math.min(...windows2.map(({ part }) => part.checkedAt));
|
|
369
400
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
@@ -443,15 +474,14 @@ function narrowTextParts(quota, options) {
|
|
|
443
474
|
return grouped;
|
|
444
475
|
const general = windows2.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
|
|
445
476
|
const scoped = windows2.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
|
|
446
|
-
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
|
447
477
|
const budget = windows2.find(({ part }) => part.kind === "budget");
|
|
448
478
|
const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
|
|
449
479
|
const extras = [
|
|
450
|
-
...scoped.map(({
|
|
451
|
-
label:
|
|
480
|
+
...scoped.map(({ part }) => ({
|
|
481
|
+
label: part.short,
|
|
452
482
|
remaining: part.remainingPercent ?? 0
|
|
453
483
|
})),
|
|
454
|
-
...budgetLeft === void 0 ? [] : [{ label:
|
|
484
|
+
...budgetLeft === void 0 || budget === void 0 ? [] : [{ label: budget.part.short, remaining: budgetLeft }]
|
|
455
485
|
];
|
|
456
486
|
const tightest = extras.reduce((best, item) => best === void 0 || item.remaining < best.remaining ? item : best, void 0);
|
|
457
487
|
const pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
|
|
@@ -479,6 +509,16 @@ function formatQuota(quota, options) {
|
|
|
479
509
|
return parts.join(" \xB7 ");
|
|
480
510
|
return quota && quota.limits.length > 0 ? NO_LIMITS_REPORTED : NO_QUOTA_READING;
|
|
481
511
|
}
|
|
512
|
+
function quotaCreditsText(credits) {
|
|
513
|
+
if (credits === void 0)
|
|
514
|
+
return void 0;
|
|
515
|
+
if (credits.unlimited)
|
|
516
|
+
return "Unlimited";
|
|
517
|
+
if (!credits.hasCredits)
|
|
518
|
+
return void 0;
|
|
519
|
+
const { balance } = credits;
|
|
520
|
+
return typeof balance === "number" && Number.isFinite(balance) && balance > 0 ? `${Math.round(balance)} credits` : "Available";
|
|
521
|
+
}
|
|
482
522
|
var QUOTA_STALE_AFTER_MS, NO_QUOTA_READING, NO_LIMITS_REPORTED, NARROW_GROUP_LIMIT;
|
|
483
523
|
var init_format = __esm({
|
|
484
524
|
"../core/dist/common-auth-embedded/quota/format.js"() {
|
|
@@ -560,12 +600,14 @@ function projectQuota(map, scope = ALL_SCOPE) {
|
|
|
560
600
|
const checkedAt = stamped.length > 0 ? Math.min(...stamped.map((limit) => limit.checkedAt)) : void 0;
|
|
561
601
|
const budget = map?.budget?.kind === "reading" ? projectBudget(map.budget) : void 0;
|
|
562
602
|
const counters = readQuotaCounters(map?.counters);
|
|
603
|
+
const credits = isQuotaCredits(map?.credits) ? map.credits : void 0;
|
|
563
604
|
return {
|
|
564
605
|
scope,
|
|
565
606
|
limits,
|
|
566
607
|
...checkedAt === void 0 ? {} : { checkedAt },
|
|
567
608
|
...budget === void 0 ? {} : { budget },
|
|
568
|
-
...counters === void 0 ? {} : { counters }
|
|
609
|
+
...counters === void 0 ? {} : { counters },
|
|
610
|
+
...credits === void 0 ? {} : { credits }
|
|
569
611
|
};
|
|
570
612
|
}
|
|
571
613
|
function budgetExhaustedResetAt(quota, now) {
|
|
@@ -608,12 +650,14 @@ __export(quota_exports, {
|
|
|
608
650
|
emptyQuotaMap: () => emptyQuotaMap,
|
|
609
651
|
formatQuota: () => formatQuota,
|
|
610
652
|
futureResetAt: () => futureResetAt,
|
|
653
|
+
isQuotaCredits: () => isQuotaCredits,
|
|
611
654
|
isQuotaMap: () => isQuotaMap,
|
|
612
655
|
isQuotaObservation: () => isQuotaObservation,
|
|
613
656
|
isQuotaStale: () => isQuotaStale,
|
|
614
657
|
mergeQuotaObservation: () => mergeQuotaObservation,
|
|
615
658
|
projectQuota: () => projectQuota,
|
|
616
659
|
quotaCodec: () => quotaCodec2,
|
|
660
|
+
quotaCreditsText: () => quotaCreditsText,
|
|
617
661
|
quotaTextParts: () => quotaTextParts,
|
|
618
662
|
quotaWindowName: () => quotaWindowName,
|
|
619
663
|
quotaWindowParts: () => quotaWindowParts,
|
|
@@ -720,7 +764,8 @@ var init_identity = __esm({
|
|
|
720
764
|
// ../core/dist/common-auth-embedded/fs/private-files.js
|
|
721
765
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
722
766
|
import { lstat as lstat2, readFile as readFile4, rename as rename3, unlink as unlink5 } from "node:fs/promises";
|
|
723
|
-
import {
|
|
767
|
+
import { tmpdir } from "node:os";
|
|
768
|
+
import { dirname as dirname5, join as join4, resolve as resolve2 } from "node:path";
|
|
724
769
|
function ioCode(detail) {
|
|
725
770
|
if (detail?.reason === "io-error") {
|
|
726
771
|
if (detail.win32Code === 2 || detail.win32Code === 3)
|
|
@@ -730,8 +775,31 @@ function ioCode(detail) {
|
|
|
730
775
|
}
|
|
731
776
|
return detail?.code ?? "ERR_PRIVATE_FILE";
|
|
732
777
|
}
|
|
778
|
+
function privateFilesUnavailable(cause) {
|
|
779
|
+
return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
|
|
780
|
+
code: "ERR_PRIVATE_FILES_UNAVAILABLE",
|
|
781
|
+
reason: PRIVATE_FILES_UNAVAILABLE_REASON
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
function isUnavailable(api, error) {
|
|
785
|
+
return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
|
|
786
|
+
}
|
|
787
|
+
async function assertNativeAddonLoads(api) {
|
|
788
|
+
try {
|
|
789
|
+
await api.verifyPrivatePath(join4(tmpdir(), `.common-auth-private-files-probe-${randomUUID7()}`), "file");
|
|
790
|
+
} catch (error) {
|
|
791
|
+
if (isUnavailable(api, error))
|
|
792
|
+
throw privateFilesUnavailable(error);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
733
795
|
function loadBackend() {
|
|
734
|
-
backend ??= import("@cortexkit/private-files")
|
|
796
|
+
backend ??= import("@cortexkit/private-files").then(async (api) => {
|
|
797
|
+
if (windowsPrivateFiles)
|
|
798
|
+
await assertNativeAddonLoads(api);
|
|
799
|
+
return api;
|
|
800
|
+
}, (cause) => {
|
|
801
|
+
throw windowsPrivateFiles ? privateFilesUnavailable(cause) : cause;
|
|
802
|
+
});
|
|
735
803
|
return backend;
|
|
736
804
|
}
|
|
737
805
|
async function privateOperation(path5, stage, operation) {
|
|
@@ -957,12 +1025,13 @@ async function writePrivateAtomic(path5, bytes, options = {}) {
|
|
|
957
1025
|
});
|
|
958
1026
|
}
|
|
959
1027
|
}
|
|
960
|
-
var windowsPrivateFiles, migrationNotices, backend, PrivateFileError, safeParentOptionsForTest;
|
|
1028
|
+
var windowsPrivateFiles, migrationNotices, backend, PRIVATE_FILES_UNAVAILABLE_REASON, PrivateFileError, safeParentOptionsForTest;
|
|
961
1029
|
var init_private_files = __esm({
|
|
962
1030
|
"../core/dist/common-auth-embedded/fs/private-files.js"() {
|
|
963
1031
|
"use strict";
|
|
964
1032
|
windowsPrivateFiles = process.platform === "win32";
|
|
965
1033
|
migrationNotices = /* @__PURE__ */ new Set();
|
|
1034
|
+
PRIVATE_FILES_UNAVAILABLE_REASON = "native-addon-unavailable";
|
|
966
1035
|
PrivateFileError = class extends Error {
|
|
967
1036
|
path;
|
|
968
1037
|
stage;
|
|
@@ -977,7 +1046,7 @@ var init_private_files = __esm({
|
|
|
977
1046
|
orphanPath;
|
|
978
1047
|
constructor(path5, stage, cause) {
|
|
979
1048
|
const detail = cause;
|
|
980
|
-
super(`Private file refused at ${stage}: ${path5} (${detail?.reason ?? detail?.code ?? "io-error"}).
|
|
1049
|
+
super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path5} (${PRIVATE_FILES_UNAVAILABLE_REASON}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path5} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
981
1050
|
this.path = path5;
|
|
982
1051
|
this.stage = stage;
|
|
983
1052
|
this.name = "PrivateFileError";
|
|
@@ -1088,7 +1157,7 @@ var init_atomic_write = __esm({
|
|
|
1088
1157
|
// ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
|
|
1089
1158
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
1090
1159
|
import { mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename5, rm as rm4, stat as stat3 } from "node:fs/promises";
|
|
1091
|
-
import { dirname as dirname7, join as
|
|
1160
|
+
import { dirname as dirname7, join as join5 } from "node:path";
|
|
1092
1161
|
async function createExclusiveText(path5, text2) {
|
|
1093
1162
|
const handle = await open4(path5, "wx", 384);
|
|
1094
1163
|
try {
|
|
@@ -1106,7 +1175,7 @@ function acquireRefreshFileLock(options) {
|
|
|
1106
1175
|
}
|
|
1107
1176
|
async function acquireRefreshFileLockWithClock(options) {
|
|
1108
1177
|
const lockPath = lockPathFor(options.path, options.name);
|
|
1109
|
-
const legacyOwnerPath =
|
|
1178
|
+
const legacyOwnerPath = join5(lockPath, "owner.json");
|
|
1110
1179
|
const ownerId = randomUUID9();
|
|
1111
1180
|
const now = options.now ?? Date.now;
|
|
1112
1181
|
let renewTimer = null;
|
|
@@ -1114,8 +1183,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1114
1183
|
let releaseConfirmed = false;
|
|
1115
1184
|
let loss;
|
|
1116
1185
|
let resolveLoss;
|
|
1117
|
-
const lostPromise = new Promise((
|
|
1118
|
-
resolveLoss =
|
|
1186
|
+
const lostPromise = new Promise((resolve20) => {
|
|
1187
|
+
resolveLoss = resolve20;
|
|
1119
1188
|
});
|
|
1120
1189
|
function notifyTimerStep(event) {
|
|
1121
1190
|
try {
|
|
@@ -1149,7 +1218,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1149
1218
|
let terminalIOError;
|
|
1150
1219
|
let renewalInFlight = null;
|
|
1151
1220
|
const evictPath = `${lockPath}.evicting`;
|
|
1152
|
-
const evictOwnerPath =
|
|
1221
|
+
const evictOwnerPath = join5(evictPath, "owner.json");
|
|
1153
1222
|
const evictOwnerId = randomUUID9();
|
|
1154
1223
|
const EVICT_TTL = 5e3;
|
|
1155
1224
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -1272,7 +1341,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1272
1341
|
}
|
|
1273
1342
|
}
|
|
1274
1343
|
async function backoff() {
|
|
1275
|
-
await new Promise((
|
|
1344
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
1276
1345
|
}
|
|
1277
1346
|
async function readLockState(notifyReady = true) {
|
|
1278
1347
|
if (notifyReady && options.onStep)
|
|
@@ -1722,6 +1791,7 @@ function lockPathFor(target, name) {
|
|
|
1722
1791
|
async function withLock(target, options, fn) {
|
|
1723
1792
|
const started = performance.now();
|
|
1724
1793
|
for (; ; ) {
|
|
1794
|
+
options.signal?.throwIfAborted();
|
|
1725
1795
|
const lock = await acquireRefreshFileLock({
|
|
1726
1796
|
path: target,
|
|
1727
1797
|
name: options.name,
|
|
@@ -1732,6 +1802,7 @@ async function withLock(target, options, fn) {
|
|
|
1732
1802
|
});
|
|
1733
1803
|
if (lock) {
|
|
1734
1804
|
try {
|
|
1805
|
+
options.signal?.throwIfAborted();
|
|
1735
1806
|
return await fn(lock);
|
|
1736
1807
|
} finally {
|
|
1737
1808
|
await lock.release();
|
|
@@ -1745,7 +1816,7 @@ async function withLock(target, options, fn) {
|
|
|
1745
1816
|
timeoutMs: options.timeoutMs
|
|
1746
1817
|
});
|
|
1747
1818
|
}
|
|
1748
|
-
await new Promise((
|
|
1819
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(25, Math.ceil(remaining))));
|
|
1749
1820
|
}
|
|
1750
1821
|
}
|
|
1751
1822
|
var LockContentionError, LockOwnershipError;
|
|
@@ -1781,13 +1852,13 @@ function assertNotInsideHook(operation) {
|
|
|
1781
1852
|
function runInsideHook(operation, fn) {
|
|
1782
1853
|
return insideHook.run(operation, async () => await fn());
|
|
1783
1854
|
}
|
|
1784
|
-
async function callFailureHook(operation, hook, rowId2, error,
|
|
1855
|
+
async function callFailureHook(operation, hook, rowId2, error, logger3) {
|
|
1785
1856
|
if (!hook)
|
|
1786
1857
|
return;
|
|
1787
1858
|
try {
|
|
1788
1859
|
await runInsideHook(operation, () => hook(rowId2, error));
|
|
1789
1860
|
} catch (hookError) {
|
|
1790
|
-
|
|
1861
|
+
logger3?.warn("store failure hook threw; the original failure stands", {
|
|
1791
1862
|
operation,
|
|
1792
1863
|
rowId: rowId2,
|
|
1793
1864
|
error: hookError instanceof Error ? hookError.message : String(hookError)
|
|
@@ -1864,7 +1935,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
1864
1935
|
});
|
|
1865
1936
|
}
|
|
1866
1937
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
1867
|
-
await new Promise((
|
|
1938
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(options.retryMs + jitter, remaining)));
|
|
1868
1939
|
}
|
|
1869
1940
|
}
|
|
1870
1941
|
function definedOnly(spec) {
|
|
@@ -2942,11 +3013,11 @@ var init_mutate = __esm({
|
|
|
2942
3013
|
if (isRecord4(this.state.accounts) && Object.hasOwn(this.state.accounts, id))
|
|
2943
3014
|
delete this.state.accounts[id];
|
|
2944
3015
|
}
|
|
2945
|
-
setStateAccount(id,
|
|
3016
|
+
setStateAccount(id, fields2) {
|
|
2946
3017
|
if (!isRecord4(this.state.accounts))
|
|
2947
3018
|
this.state.accounts = {};
|
|
2948
3019
|
Object.defineProperty(this.state.accounts, id, {
|
|
2949
|
-
value:
|
|
3020
|
+
value: fields2,
|
|
2950
3021
|
enumerable: true,
|
|
2951
3022
|
writable: true,
|
|
2952
3023
|
configurable: true
|
|
@@ -4495,12 +4566,12 @@ var init_pull = __esm({
|
|
|
4495
4566
|
firedAtLoad;
|
|
4496
4567
|
logger;
|
|
4497
4568
|
inflight = /* @__PURE__ */ new Set();
|
|
4498
|
-
constructor(rt, hook, onFailure, firedAtLoad,
|
|
4569
|
+
constructor(rt, hook, onFailure, firedAtLoad, logger3) {
|
|
4499
4570
|
this.rt = rt;
|
|
4500
4571
|
this.hook = hook;
|
|
4501
4572
|
this.onFailure = onFailure;
|
|
4502
4573
|
this.firedAtLoad = firedAtLoad;
|
|
4503
|
-
this.logger =
|
|
4574
|
+
this.logger = logger3;
|
|
4504
4575
|
}
|
|
4505
4576
|
fire(id, reason) {
|
|
4506
4577
|
if (!this.hook)
|
|
@@ -5582,15 +5653,15 @@ function createRedactor(options = {}) {
|
|
|
5582
5653
|
return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
5583
5654
|
}
|
|
5584
5655
|
function errorEntries(error) {
|
|
5585
|
-
const
|
|
5656
|
+
const fields2 = error;
|
|
5586
5657
|
const entries = [
|
|
5587
5658
|
["name", error.name],
|
|
5588
5659
|
["message", error.message],
|
|
5589
5660
|
["stack", error.stack]
|
|
5590
5661
|
];
|
|
5591
5662
|
for (const key of ["code", "status", "cause"])
|
|
5592
|
-
if (
|
|
5593
|
-
entries.push([key,
|
|
5663
|
+
if (fields2[key] !== void 0)
|
|
5664
|
+
entries.push([key, fields2[key]]);
|
|
5594
5665
|
const listed = new Set(entries.map(([key]) => key));
|
|
5595
5666
|
for (const entry of Object.entries(error))
|
|
5596
5667
|
if (!listed.has(entry[0]))
|
|
@@ -5832,7 +5903,7 @@ function createEngine(options) {
|
|
|
5832
5903
|
} catch {
|
|
5833
5904
|
}
|
|
5834
5905
|
}
|
|
5835
|
-
function
|
|
5906
|
+
function schedule2() {
|
|
5836
5907
|
if (!timer)
|
|
5837
5908
|
timer = setTimeout(() => {
|
|
5838
5909
|
timer = void 0;
|
|
@@ -5874,7 +5945,7 @@ function createEngine(options) {
|
|
|
5874
5945
|
void flushed.catch(() => {
|
|
5875
5946
|
});
|
|
5876
5947
|
} else
|
|
5877
|
-
|
|
5948
|
+
schedule2();
|
|
5878
5949
|
} catch {
|
|
5879
5950
|
}
|
|
5880
5951
|
}
|
|
@@ -6745,9 +6816,9 @@ function findAction(sections, request) {
|
|
|
6745
6816
|
return actions?.find((action) => action.id === request.actionId);
|
|
6746
6817
|
}
|
|
6747
6818
|
function createCommandMenu(options) {
|
|
6748
|
-
const
|
|
6819
|
+
const logger3 = options.logger ?? createLogger2("commands");
|
|
6749
6820
|
const redact3 = createTextRedactor(options.redaction);
|
|
6750
|
-
const seam = { logger:
|
|
6821
|
+
const seam = { logger: logger3, redact: redact3 };
|
|
6751
6822
|
const now = options.now ?? Date.now;
|
|
6752
6823
|
const extras = options.extras ?? [];
|
|
6753
6824
|
const replaced = options.replace ?? {};
|
|
@@ -6774,7 +6845,7 @@ function createCommandMenu(options) {
|
|
|
6774
6845
|
content: await section.build(invocation)
|
|
6775
6846
|
};
|
|
6776
6847
|
} catch (error) {
|
|
6777
|
-
|
|
6848
|
+
logger3.warn("command menu section failed to build", {
|
|
6778
6849
|
command: options.command,
|
|
6779
6850
|
section: id,
|
|
6780
6851
|
error: redact3(error instanceof Error ? error.message : String(error))
|
|
@@ -6861,7 +6932,7 @@ function createCommandMenu(options) {
|
|
|
6861
6932
|
};
|
|
6862
6933
|
} catch (error) {
|
|
6863
6934
|
const failure2 = projectFailure(error);
|
|
6864
|
-
|
|
6935
|
+
logger3.warn("command menu action failed", {
|
|
6865
6936
|
command: options.command,
|
|
6866
6937
|
section: request.sectionId,
|
|
6867
6938
|
action: request.actionId,
|
|
@@ -7473,7 +7544,7 @@ async function select(terminal, items, options) {
|
|
|
7473
7544
|
writeLine("");
|
|
7474
7545
|
renderedLines = lines;
|
|
7475
7546
|
};
|
|
7476
|
-
return new Promise((
|
|
7547
|
+
return new Promise((resolve20) => {
|
|
7477
7548
|
const wasRaw = stdin.isRaw ?? false;
|
|
7478
7549
|
const cleanup2 = () => {
|
|
7479
7550
|
if (cleaned)
|
|
@@ -7493,7 +7564,7 @@ async function select(terminal, items, options) {
|
|
|
7493
7564
|
};
|
|
7494
7565
|
const finish = (value) => {
|
|
7495
7566
|
cleanup2();
|
|
7496
|
-
|
|
7567
|
+
resolve20(value);
|
|
7497
7568
|
};
|
|
7498
7569
|
const onSignal = () => finish(null);
|
|
7499
7570
|
const onKey = (data) => {
|
|
@@ -7533,7 +7604,7 @@ async function select(terminal, items, options) {
|
|
|
7533
7604
|
stdin.setRawMode(true);
|
|
7534
7605
|
} catch {
|
|
7535
7606
|
cleanup2();
|
|
7536
|
-
|
|
7607
|
+
resolve20(null);
|
|
7537
7608
|
return;
|
|
7538
7609
|
}
|
|
7539
7610
|
stdin.resume();
|
|
@@ -8816,7 +8887,7 @@ var init_any_signal = __esm({
|
|
|
8816
8887
|
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID12 } from "node:crypto";
|
|
8817
8888
|
import { constants as fsConstants } from "node:fs";
|
|
8818
8889
|
import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename6, stat as stat4, unlink as unlink6 } from "node:fs/promises";
|
|
8819
|
-
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as
|
|
8890
|
+
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve5 } from "node:path";
|
|
8820
8891
|
import { ClaustrumCredentialError as ClaustrumCredentialError2, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
8821
8892
|
function classifyEnrollmentError(error) {
|
|
8822
8893
|
if (!(error instanceof ClaustrumCredentialError2))
|
|
@@ -8842,7 +8913,7 @@ function getClaustrumEnrollmentPaths(tokenPath) {
|
|
|
8842
8913
|
const extension = extname(tokenPath) || ".json";
|
|
8843
8914
|
const stem = basename3(tokenPath, extname(tokenPath));
|
|
8844
8915
|
return {
|
|
8845
|
-
statePath:
|
|
8916
|
+
statePath: join6(dirname9(tokenPath), `${stem}-state${extension}`),
|
|
8846
8917
|
tokenPath
|
|
8847
8918
|
};
|
|
8848
8919
|
}
|
|
@@ -8850,7 +8921,7 @@ function hostEnrollmentPaths(input2) {
|
|
|
8850
8921
|
const override = input2.override?.trim();
|
|
8851
8922
|
if (override && !isAbsolute2(override) && !input2.cwd)
|
|
8852
8923
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
8853
|
-
const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input2.cwd, override) :
|
|
8924
|
+
const tokenPath = override ? isAbsolute2(override) ? override : resolve5(input2.cwd, override) : join6(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
8854
8925
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
8855
8926
|
}
|
|
8856
8927
|
function isRecord6(value) {
|
|
@@ -8979,13 +9050,13 @@ async function readBoundedJson(path5) {
|
|
|
8979
9050
|
await descriptor.close();
|
|
8980
9051
|
}
|
|
8981
9052
|
}
|
|
8982
|
-
function accountRecords(text2,
|
|
9053
|
+
function accountRecords(text2, fields2) {
|
|
8983
9054
|
const records = [];
|
|
8984
9055
|
for (const line of text2.split("\n")) {
|
|
8985
9056
|
if (line.trim() === "" || line.startsWith("#"))
|
|
8986
9057
|
continue;
|
|
8987
9058
|
const parts = line.split(":");
|
|
8988
|
-
if (parts.length !==
|
|
9059
|
+
if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
|
|
8989
9060
|
return void 0;
|
|
8990
9061
|
records.push(parts);
|
|
8991
9062
|
}
|
|
@@ -9083,7 +9154,7 @@ async function writeStateAtomic(path5, state, ancestorOptions = {}) {
|
|
|
9083
9154
|
}
|
|
9084
9155
|
if (windowsPrivateFiles)
|
|
9085
9156
|
return writePrivateAtomic(path5, bytes);
|
|
9086
|
-
const temporary =
|
|
9157
|
+
const temporary = join6(parent, `.${basename3(path5)}.${process.pid}.${randomUUID12()}.tmp`);
|
|
9087
9158
|
let descriptor;
|
|
9088
9159
|
let created = false;
|
|
9089
9160
|
try {
|
|
@@ -9260,7 +9331,7 @@ async function disconnectClaustrumEnrollment(paths, proposedName) {
|
|
|
9260
9331
|
await lock.release();
|
|
9261
9332
|
}
|
|
9262
9333
|
}
|
|
9263
|
-
var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
|
|
9334
|
+
var ENROLLMENT_SCHEMA, ENROLLMENT_FILE_MAX_BYTES, ENROLLMENT_LOCK_TTL_MS, TOKEN_RE, UNSUPPORTED_ENROLLMENT_CODE, TERMINAL_ENROLLMENT_CODES, RETRYABLE_ENROLLMENT_CODES, ClaustrumEnrollmentManager;
|
|
9264
9335
|
var init_enrollment = __esm({
|
|
9265
9336
|
"../core/dist/common-auth-embedded/claustrum/enrollment.js"() {
|
|
9266
9337
|
"use strict";
|
|
@@ -9271,7 +9342,13 @@ var init_enrollment = __esm({
|
|
|
9271
9342
|
ENROLLMENT_FILE_MAX_BYTES = 16 * 1024;
|
|
9272
9343
|
ENROLLMENT_LOCK_TTL_MS = 3e4;
|
|
9273
9344
|
TOKEN_RE = /^[0-9a-f]{64}$/;
|
|
9345
|
+
UNSUPPORTED_ENROLLMENT_CODE = "unknown_method";
|
|
9274
9346
|
TERMINAL_ENROLLMENT_CODES = /* @__PURE__ */ new Set([
|
|
9347
|
+
// The daemon's answer to an operation it does not implement: a vault built
|
|
9348
|
+
// before the enrollment ceremony. It arrives as a transport Error frame with
|
|
9349
|
+
// no class, which claustrum-client before 0.13.0 labels transient/retry, but
|
|
9350
|
+
// asking again can never succeed.
|
|
9351
|
+
UNSUPPORTED_ENROLLMENT_CODE,
|
|
9275
9352
|
"invalid_params",
|
|
9276
9353
|
"pending_exists",
|
|
9277
9354
|
"not_found",
|
|
@@ -9405,6 +9482,18 @@ var init_enrollment = __esm({
|
|
|
9405
9482
|
retryCode: refusal3.code
|
|
9406
9483
|
};
|
|
9407
9484
|
}
|
|
9485
|
+
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
|
|
9486
|
+
await lock.assertOwned();
|
|
9487
|
+
await unlink6(this.#paths.statePath).catch((cause) => {
|
|
9488
|
+
if (cause.code !== "ENOENT")
|
|
9489
|
+
throw cause;
|
|
9490
|
+
});
|
|
9491
|
+
return {
|
|
9492
|
+
state: "unavailable",
|
|
9493
|
+
proposedName: state.proposedName,
|
|
9494
|
+
code: refusal3.code
|
|
9495
|
+
};
|
|
9496
|
+
}
|
|
9408
9497
|
return this.#block(state, refusal3.code);
|
|
9409
9498
|
}
|
|
9410
9499
|
}
|
|
@@ -9535,9 +9624,9 @@ function scopedRetryReason(served, current) {
|
|
|
9535
9624
|
return "version-unchanged";
|
|
9536
9625
|
return "rotated";
|
|
9537
9626
|
}
|
|
9538
|
-
function decideScopedRetryAfter401(site, served, current,
|
|
9627
|
+
function decideScopedRetryAfter401(site, served, current, logger3 = defaultLogger) {
|
|
9539
9628
|
const retry = isScopedCredentialRotation(served, current);
|
|
9540
|
-
|
|
9629
|
+
logger3.debug("scoped 401 re-authorized", {
|
|
9541
9630
|
site,
|
|
9542
9631
|
credentialId: served.credentialId,
|
|
9543
9632
|
servedVersion: served.recordVersion,
|
|
@@ -10110,6 +10199,7 @@ var init_interlock = __esm({
|
|
|
10110
10199
|
|
|
10111
10200
|
// ../core/dist/common-auth-embedded/claustrum/roster.js
|
|
10112
10201
|
import { createHash as createHash7 } from "node:crypto";
|
|
10202
|
+
import { resolve as resolve6 } from "node:path";
|
|
10113
10203
|
function hash(value) {
|
|
10114
10204
|
return createHash7("sha256").update(value).digest("hex");
|
|
10115
10205
|
}
|
|
@@ -10330,7 +10420,7 @@ async function readVaultRoster(path5) {
|
|
|
10330
10420
|
return decodeRoster(value);
|
|
10331
10421
|
}
|
|
10332
10422
|
async function mutateVaultRoster(path5, change, options = {}) {
|
|
10333
|
-
return withLock(path5, WRITE_LOCK, async (lock) => {
|
|
10423
|
+
return withLock(path5, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
|
|
10334
10424
|
const current = await readVaultRoster(path5);
|
|
10335
10425
|
const { next, result } = await change(current, {
|
|
10336
10426
|
assertOwned: () => lock.assertOwned()
|
|
@@ -10340,6 +10430,7 @@ async function mutateVaultRoster(path5, change, options = {}) {
|
|
|
10340
10430
|
await writeJsonAtomic2(path5, next, {
|
|
10341
10431
|
beforeRename: async () => {
|
|
10342
10432
|
await options.beforePublish?.();
|
|
10433
|
+
options.signal?.throwIfAborted();
|
|
10343
10434
|
await lock.assertOwned();
|
|
10344
10435
|
}
|
|
10345
10436
|
});
|
|
@@ -10389,43 +10480,51 @@ function receiptFence(row, receipt2) {
|
|
|
10389
10480
|
return "bind";
|
|
10390
10481
|
return "refuse";
|
|
10391
10482
|
}
|
|
10392
|
-
function recordVaultQuota(path5, input2) {
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
const bound = fence === "bind" ? { accountIdentity: input2.accountIdentity, unclaimed: true } : {};
|
|
10400
|
-
return {
|
|
10401
|
-
next: {
|
|
10402
|
-
...current,
|
|
10403
|
-
rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
|
|
10404
|
-
},
|
|
10405
|
-
result: true
|
|
10406
|
-
};
|
|
10483
|
+
async function recordVaultQuota(path5, input2) {
|
|
10484
|
+
const { routeId, observation, ...receipt2 } = input2;
|
|
10485
|
+
return enqueueFencedVaultQuota(path5, {
|
|
10486
|
+
routeId,
|
|
10487
|
+
observation,
|
|
10488
|
+
accountIdentity: receipt2.accountIdentity,
|
|
10489
|
+
receipt: receipt2
|
|
10407
10490
|
});
|
|
10408
10491
|
}
|
|
10492
|
+
async function enqueueFencedVaultQuota(path5, publication2) {
|
|
10493
|
+
if (!isQuotaObservation(publication2.observation))
|
|
10494
|
+
return false;
|
|
10495
|
+
const current = pendingVaultQuota(path5, await readVaultRoster(path5));
|
|
10496
|
+
if (!applyVaultQuota(current, publication2).kept)
|
|
10497
|
+
return false;
|
|
10498
|
+
return enqueueVaultQuota(path5, publication2);
|
|
10499
|
+
}
|
|
10409
10500
|
function recordVaultAccountQuota(path5, input2) {
|
|
10410
|
-
return
|
|
10411
|
-
|
|
10412
|
-
|
|
10413
|
-
|
|
10414
|
-
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
|
|
10420
|
-
|
|
10421
|
-
|
|
10422
|
-
|
|
10501
|
+
return enqueueFencedVaultQuota(path5, input2);
|
|
10502
|
+
}
|
|
10503
|
+
function applyVaultQuota(current, input2) {
|
|
10504
|
+
const row = current?.rows.find((entry) => entry.routeId === input2.routeId);
|
|
10505
|
+
const fence = !row ? "refuse" : input2.receipt ? receiptFence(row, input2.receipt) : row.accountIdentity !== void 0 && row.accountIdentity === input2.accountIdentity ? "hold" : "refuse";
|
|
10506
|
+
if (!current || !row || fence === "refuse")
|
|
10507
|
+
return { roster: current, kept: false };
|
|
10508
|
+
const quota = mergeQuotaObservation(row.quota, input2.observation);
|
|
10509
|
+
const bound = fence === "bind" ? { accountIdentity: input2.accountIdentity, unclaimed: true } : {};
|
|
10510
|
+
return {
|
|
10511
|
+
roster: {
|
|
10512
|
+
...current,
|
|
10513
|
+
rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
|
|
10514
|
+
},
|
|
10515
|
+
kept: true
|
|
10516
|
+
};
|
|
10517
|
+
}
|
|
10518
|
+
function forgetPendingVaultDiscovery(path5) {
|
|
10519
|
+
pendingDiscoveries.delete(resolve6(path5));
|
|
10423
10520
|
}
|
|
10424
10521
|
async function refreshVaultRoster(options) {
|
|
10425
10522
|
options.signal?.throwIfAborted();
|
|
10426
10523
|
const active2 = async () => await options.isActive?.() ?? true;
|
|
10427
|
-
if (!await active2())
|
|
10524
|
+
if (!await active2()) {
|
|
10525
|
+
forgetPendingVaultDiscovery(options.path);
|
|
10428
10526
|
return void 0;
|
|
10527
|
+
}
|
|
10429
10528
|
const lease = await acquireRefreshFileLock({
|
|
10430
10529
|
...DISCOVERY_LEASE,
|
|
10431
10530
|
path: options.path,
|
|
@@ -10438,8 +10537,18 @@ async function refreshVaultRoster(options) {
|
|
|
10438
10537
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
10439
10538
|
return persisted;
|
|
10440
10539
|
}
|
|
10540
|
+
const key = resolve6(options.path);
|
|
10541
|
+
let discovered;
|
|
10441
10542
|
try {
|
|
10442
|
-
const
|
|
10543
|
+
const previous = await readVaultRoster(options.path);
|
|
10544
|
+
const pending = pendingDiscoveries.get(key);
|
|
10545
|
+
discovered = pending && (pending.previousView === previous?.view || pending.inventory.view === previous?.view) ? pending : {
|
|
10546
|
+
inventory: await options.custody.discover(options.signal),
|
|
10547
|
+
previousView: previous?.view
|
|
10548
|
+
};
|
|
10549
|
+
pendingDiscoveries.delete(key);
|
|
10550
|
+
const { inventory } = discovered;
|
|
10551
|
+
options.onInventory?.(inventory);
|
|
10443
10552
|
options.signal?.throwIfAborted();
|
|
10444
10553
|
return await mutateVaultRoster(options.path, async (current) => {
|
|
10445
10554
|
if (!await active2())
|
|
@@ -10450,7 +10559,16 @@ async function refreshVaultRoster(options) {
|
|
|
10450
10559
|
const next = projectVaultRoster(current, inventory, projection);
|
|
10451
10560
|
const changed = JSON.stringify(current) !== JSON.stringify(next);
|
|
10452
10561
|
return { ...changed && { next }, result: next };
|
|
10562
|
+
}, {
|
|
10563
|
+
beforePublish: async () => {
|
|
10564
|
+
options.signal?.throwIfAborted();
|
|
10565
|
+
await lease.assertOwned();
|
|
10566
|
+
}
|
|
10453
10567
|
});
|
|
10568
|
+
} catch (error) {
|
|
10569
|
+
if (error instanceof LockContentionError && discovered && !options.signal?.aborted && await active2())
|
|
10570
|
+
pendingDiscoveries.set(key, discovered);
|
|
10571
|
+
throw error;
|
|
10454
10572
|
} finally {
|
|
10455
10573
|
await lease.release();
|
|
10456
10574
|
}
|
|
@@ -10487,7 +10605,7 @@ function resolveVaultPrimary(input2) {
|
|
|
10487
10605
|
...previous && previous.accountIdentity !== identity && { replaced: previous }
|
|
10488
10606
|
};
|
|
10489
10607
|
}
|
|
10490
|
-
var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE;
|
|
10608
|
+
var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE, pendingDiscoveries;
|
|
10491
10609
|
var init_roster = __esm({
|
|
10492
10610
|
"../core/dist/common-auth-embedded/claustrum/roster.js"() {
|
|
10493
10611
|
"use strict";
|
|
@@ -10496,6 +10614,8 @@ var init_roster = __esm({
|
|
|
10496
10614
|
init_quota();
|
|
10497
10615
|
init_errors2();
|
|
10498
10616
|
init_interlock();
|
|
10617
|
+
init_quota_writer();
|
|
10618
|
+
init_quota_writer();
|
|
10499
10619
|
DEFAULT_ROUTE_PREFIX = "vault:";
|
|
10500
10620
|
SKIPPED_REASONS = /* @__PURE__ */ new Set([
|
|
10501
10621
|
"empty credential id",
|
|
@@ -10506,9 +10626,238 @@ var init_roster = __esm({
|
|
|
10506
10626
|
WRITE_LOCK = {
|
|
10507
10627
|
name: "claustrum-roster-write",
|
|
10508
10628
|
ttlMs: 1e4,
|
|
10509
|
-
timeoutMs: 5e3
|
|
10629
|
+
timeoutMs: 5e3,
|
|
10630
|
+
renew: true
|
|
10510
10631
|
};
|
|
10511
10632
|
DISCOVERY_LEASE = { name: "claustrum-roster", ttlMs: 3e4 };
|
|
10633
|
+
pendingDiscoveries = /* @__PURE__ */ new Map();
|
|
10634
|
+
}
|
|
10635
|
+
});
|
|
10636
|
+
|
|
10637
|
+
// ../core/dist/common-auth-embedded/claustrum/quota-writer.js
|
|
10638
|
+
import { resolve as resolve7 } from "node:path";
|
|
10639
|
+
function writerFor(path5) {
|
|
10640
|
+
const key = resolve7(path5);
|
|
10641
|
+
let writer = writers.get(key);
|
|
10642
|
+
if (!writer) {
|
|
10643
|
+
writer = {
|
|
10644
|
+
path: key,
|
|
10645
|
+
pending: /* @__PURE__ */ new Map(),
|
|
10646
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
10647
|
+
wake: /* @__PURE__ */ new Set(),
|
|
10648
|
+
abort: new AbortController(),
|
|
10649
|
+
failures: 0,
|
|
10650
|
+
draining: false,
|
|
10651
|
+
order: 0
|
|
10652
|
+
};
|
|
10653
|
+
writers.set(key, writer);
|
|
10654
|
+
}
|
|
10655
|
+
return writer;
|
|
10656
|
+
}
|
|
10657
|
+
function retainVaultQuotaWriter(path5, listener) {
|
|
10658
|
+
const writer = writerFor(path5);
|
|
10659
|
+
writer.listeners.add(listener);
|
|
10660
|
+
let released;
|
|
10661
|
+
return () => released ??= (() => {
|
|
10662
|
+
writer.listeners.delete(listener);
|
|
10663
|
+
return writer.listeners.size ? Promise.resolve() : drainVaultQuota(path5);
|
|
10664
|
+
})();
|
|
10665
|
+
}
|
|
10666
|
+
function fields(publication2) {
|
|
10667
|
+
const result = /* @__PURE__ */ new Map();
|
|
10668
|
+
const { observation } = publication2;
|
|
10669
|
+
const witness = JSON.stringify([
|
|
10670
|
+
publication2.routeId,
|
|
10671
|
+
publication2.receipt?.credentialId,
|
|
10672
|
+
publication2.receipt?.accountIdentitySource,
|
|
10673
|
+
publication2.receipt?.expectedAccountIdentity
|
|
10674
|
+
]);
|
|
10675
|
+
const add = (key, at, part) => result.set(`${witness}:${key}`, {
|
|
10676
|
+
at,
|
|
10677
|
+
order: 0,
|
|
10678
|
+
publication: { ...publication2, observation: part }
|
|
10679
|
+
});
|
|
10680
|
+
const keyFor = (scope, label) => JSON.stringify([scope ?? "all", label]);
|
|
10681
|
+
const read = /* @__PURE__ */ new Set();
|
|
10682
|
+
for (const reading of observation.readings ?? []) {
|
|
10683
|
+
const key = keyFor(reading.scope, reading.label);
|
|
10684
|
+
read.add(key);
|
|
10685
|
+
add(key, observation.checkedAt, {
|
|
10686
|
+
checkedAt: observation.checkedAt,
|
|
10687
|
+
readings: [{ ...reading }]
|
|
10688
|
+
});
|
|
10689
|
+
}
|
|
10690
|
+
for (const pair of observation.coverage ?? []) {
|
|
10691
|
+
const key = keyFor(pair.scope, pair.label);
|
|
10692
|
+
if (!read.has(key))
|
|
10693
|
+
add(key, observation.checkedAt, {
|
|
10694
|
+
checkedAt: observation.checkedAt,
|
|
10695
|
+
coverage: [{ ...pair }]
|
|
10696
|
+
});
|
|
10697
|
+
}
|
|
10698
|
+
if (observation.budget)
|
|
10699
|
+
add("budget", observation.checkedAt, {
|
|
10700
|
+
checkedAt: observation.checkedAt,
|
|
10701
|
+
budget: { ...observation.budget }
|
|
10702
|
+
});
|
|
10703
|
+
for (const [name, counter] of Object.entries(observation.counters ?? {})) {
|
|
10704
|
+
add(`counter:${name}`, counter.checkedAt, {
|
|
10705
|
+
checkedAt: observation.checkedAt,
|
|
10706
|
+
counters: { [name]: { ...counter } }
|
|
10707
|
+
});
|
|
10708
|
+
}
|
|
10709
|
+
if (observation.credits)
|
|
10710
|
+
add("credits", observation.credits.checkedAt, {
|
|
10711
|
+
checkedAt: observation.checkedAt,
|
|
10712
|
+
credits: { ...observation.credits }
|
|
10713
|
+
});
|
|
10714
|
+
if (!result.size)
|
|
10715
|
+
add("empty", observation.checkedAt, { checkedAt: observation.checkedAt });
|
|
10716
|
+
return result;
|
|
10717
|
+
}
|
|
10718
|
+
function enqueueVaultQuota(path5, publication2) {
|
|
10719
|
+
if (!isQuotaObservation(publication2.observation))
|
|
10720
|
+
return Promise.resolve(false);
|
|
10721
|
+
const writer = writerFor(path5);
|
|
10722
|
+
const account = JSON.stringify([
|
|
10723
|
+
publication2.accountIdentity ?? null,
|
|
10724
|
+
publication2.accountIdentity === void 0 ? publication2.routeId : null
|
|
10725
|
+
]);
|
|
10726
|
+
const pending = writer.pending.get(account) ?? /* @__PURE__ */ new Map();
|
|
10727
|
+
for (const [key, field] of fields(publication2)) {
|
|
10728
|
+
const previous = pending.get(key);
|
|
10729
|
+
if (!previous || field.at >= previous.at) {
|
|
10730
|
+
field.order = ++writer.order;
|
|
10731
|
+
if (field.publication.observation.coverage)
|
|
10732
|
+
field.priorReading = previous?.publication.observation.readings ? previous.publication : previous?.priorReading;
|
|
10733
|
+
pending.set(key, field);
|
|
10734
|
+
}
|
|
10735
|
+
}
|
|
10736
|
+
if (pending.size)
|
|
10737
|
+
writer.pending.set(account, pending);
|
|
10738
|
+
for (const listener of writer.listeners)
|
|
10739
|
+
listener(publication2);
|
|
10740
|
+
schedule(writer, COALESCE_MS);
|
|
10741
|
+
return Promise.resolve(true);
|
|
10742
|
+
}
|
|
10743
|
+
function orderedFields(pending) {
|
|
10744
|
+
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
10745
|
+
}
|
|
10746
|
+
function pendingVaultQuota(path5, roster) {
|
|
10747
|
+
const writer = writers.get(resolve7(path5));
|
|
10748
|
+
if (writer) {
|
|
10749
|
+
for (const field of orderedFields(writer.pending)) {
|
|
10750
|
+
if (field.priorReading)
|
|
10751
|
+
roster = applyVaultQuota(roster, field.priorReading).roster;
|
|
10752
|
+
roster = applyVaultQuota(roster, field.publication).roster;
|
|
10753
|
+
}
|
|
10754
|
+
}
|
|
10755
|
+
return roster;
|
|
10756
|
+
}
|
|
10757
|
+
function schedule(writer, delay3) {
|
|
10758
|
+
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
10759
|
+
return;
|
|
10760
|
+
writer.timer = setTimeout(() => {
|
|
10761
|
+
writer.timer = void 0;
|
|
10762
|
+
flush(writer);
|
|
10763
|
+
}, delay3);
|
|
10764
|
+
if (!writer.draining)
|
|
10765
|
+
writer.timer.unref?.();
|
|
10766
|
+
}
|
|
10767
|
+
function flush(writer) {
|
|
10768
|
+
if (writer.running || writer.abort.signal.aborted)
|
|
10769
|
+
return;
|
|
10770
|
+
const batch = new Map([...writer.pending].map(([account, pending]) => [
|
|
10771
|
+
account,
|
|
10772
|
+
new Map(pending)
|
|
10773
|
+
]));
|
|
10774
|
+
writer.running = (async () => {
|
|
10775
|
+
try {
|
|
10776
|
+
await mutateVaultRoster(writer.path, (current) => {
|
|
10777
|
+
let next = current;
|
|
10778
|
+
for (const field of orderedFields(batch)) {
|
|
10779
|
+
if (field.priorReading)
|
|
10780
|
+
next = applyVaultQuota(next, field.priorReading).roster;
|
|
10781
|
+
next = applyVaultQuota(next, field.publication).roster;
|
|
10782
|
+
}
|
|
10783
|
+
return { ...next !== current && { next }, result: void 0 };
|
|
10784
|
+
}, { signal: writer.abort.signal });
|
|
10785
|
+
for (const [account, fields2] of batch) {
|
|
10786
|
+
const pending = writer.pending.get(account);
|
|
10787
|
+
for (const [key, field] of fields2) {
|
|
10788
|
+
if (pending?.get(key) === field)
|
|
10789
|
+
pending.delete(key);
|
|
10790
|
+
}
|
|
10791
|
+
if (!pending?.size)
|
|
10792
|
+
writer.pending.delete(account);
|
|
10793
|
+
}
|
|
10794
|
+
writer.failures = 0;
|
|
10795
|
+
} catch (error) {
|
|
10796
|
+
if (!writer.abort.signal.aborted && writer.failures++ === 0) {
|
|
10797
|
+
logger.warn("vault quota publication delayed; retrying", {
|
|
10798
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10799
|
+
});
|
|
10800
|
+
}
|
|
10801
|
+
} finally {
|
|
10802
|
+
writer.running = void 0;
|
|
10803
|
+
for (const wake of writer.wake)
|
|
10804
|
+
wake();
|
|
10805
|
+
const backoff = writer.failures ? Math.min(5e3, 100 * 2 ** Math.min(writer.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
|
|
10806
|
+
schedule(writer, backoff);
|
|
10807
|
+
}
|
|
10808
|
+
})();
|
|
10809
|
+
}
|
|
10810
|
+
async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
10811
|
+
const key = resolve7(path5);
|
|
10812
|
+
const writer = writers.get(key);
|
|
10813
|
+
if (!writer)
|
|
10814
|
+
return;
|
|
10815
|
+
writer.draining = true;
|
|
10816
|
+
clearTimeout(writer.timer);
|
|
10817
|
+
writer.timer = void 0;
|
|
10818
|
+
let deadline;
|
|
10819
|
+
let wake;
|
|
10820
|
+
const drained = new Promise((done) => {
|
|
10821
|
+
wake = () => {
|
|
10822
|
+
if (!writer.pending.size || writer.abort.signal.aborted)
|
|
10823
|
+
done();
|
|
10824
|
+
};
|
|
10825
|
+
writer.wake.add(wake);
|
|
10826
|
+
wake();
|
|
10827
|
+
});
|
|
10828
|
+
try {
|
|
10829
|
+
if (writer.pending.size)
|
|
10830
|
+
flush(writer);
|
|
10831
|
+
await Promise.race([
|
|
10832
|
+
drained,
|
|
10833
|
+
new Promise((done) => {
|
|
10834
|
+
deadline = setTimeout(done, Math.max(0, timeoutMs));
|
|
10835
|
+
})
|
|
10836
|
+
]);
|
|
10837
|
+
} finally {
|
|
10838
|
+
clearTimeout(deadline);
|
|
10839
|
+
if (wake)
|
|
10840
|
+
writer.wake.delete(wake);
|
|
10841
|
+
writer.draining = false;
|
|
10842
|
+
if (!writer.listeners.size) {
|
|
10843
|
+
writer.abort.abort();
|
|
10844
|
+
clearTimeout(writer.timer);
|
|
10845
|
+
writer.pending.clear();
|
|
10846
|
+
if (writers.get(key) === writer)
|
|
10847
|
+
writers.delete(key);
|
|
10848
|
+
}
|
|
10849
|
+
}
|
|
10850
|
+
}
|
|
10851
|
+
var writers, logger, COALESCE_MS;
|
|
10852
|
+
var init_quota_writer = __esm({
|
|
10853
|
+
"../core/dist/common-auth-embedded/claustrum/quota-writer.js"() {
|
|
10854
|
+
"use strict";
|
|
10855
|
+
init_logger();
|
|
10856
|
+
init_quota();
|
|
10857
|
+
init_roster();
|
|
10858
|
+
writers = /* @__PURE__ */ new Map();
|
|
10859
|
+
logger = createLogger2("claustrum");
|
|
10860
|
+
COALESCE_MS = 100;
|
|
10512
10861
|
}
|
|
10513
10862
|
});
|
|
10514
10863
|
|
|
@@ -10523,6 +10872,7 @@ var init_consumer = __esm({
|
|
|
10523
10872
|
init_enrollment();
|
|
10524
10873
|
init_errors2();
|
|
10525
10874
|
init_insula();
|
|
10875
|
+
init_quota_writer();
|
|
10526
10876
|
init_roster();
|
|
10527
10877
|
init_watch();
|
|
10528
10878
|
ClaustrumConsumer = class {
|
|
@@ -10546,9 +10896,13 @@ var init_consumer = __esm({
|
|
|
10546
10896
|
#insulaSkips = /* @__PURE__ */ new Map();
|
|
10547
10897
|
/** When this instance last completed a discovery, by `now`. */
|
|
10548
10898
|
#discoveredAt;
|
|
10899
|
+
#releaseQuotaWriter;
|
|
10549
10900
|
constructor(options) {
|
|
10550
10901
|
this.#options = options;
|
|
10551
10902
|
this.#logger = options.logger ?? createLogger2("claustrum");
|
|
10903
|
+
this.#releaseQuotaWriter = retainVaultQuotaWriter(options.rosterPath, (publication2) => {
|
|
10904
|
+
this.#roster = applyVaultQuota(this.#roster, publication2).roster;
|
|
10905
|
+
});
|
|
10552
10906
|
}
|
|
10553
10907
|
#assertOpen(signal) {
|
|
10554
10908
|
this.#shutdown.signal.throwIfAborted();
|
|
@@ -10562,7 +10916,7 @@ var init_consumer = __esm({
|
|
|
10562
10916
|
this.#shutdown.signal,
|
|
10563
10917
|
...signal ? [signal] : []
|
|
10564
10918
|
]);
|
|
10565
|
-
return new Promise((
|
|
10919
|
+
return new Promise((resolve20, reject) => {
|
|
10566
10920
|
const cleanup2 = () => {
|
|
10567
10921
|
combined.signal.removeEventListener("abort", abort);
|
|
10568
10922
|
combined.dispose();
|
|
@@ -10577,7 +10931,7 @@ var init_consumer = __esm({
|
|
|
10577
10931
|
if (combined.signal.aborted)
|
|
10578
10932
|
reject(combined.signal.reason);
|
|
10579
10933
|
else
|
|
10580
|
-
|
|
10934
|
+
resolve20(value);
|
|
10581
10935
|
}, (error) => {
|
|
10582
10936
|
cleanup2();
|
|
10583
10937
|
reject(error);
|
|
@@ -10677,11 +11031,9 @@ var init_consumer = __esm({
|
|
|
10677
11031
|
let discovered;
|
|
10678
11032
|
const roster = await refreshVaultRoster({
|
|
10679
11033
|
path: this.#options.rosterPath,
|
|
10680
|
-
custody
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
return discovered;
|
|
10684
|
-
}
|
|
11034
|
+
custody,
|
|
11035
|
+
onInventory: (inventory) => {
|
|
11036
|
+
discovered = inventory;
|
|
10685
11037
|
},
|
|
10686
11038
|
isActive: () => this.#active(),
|
|
10687
11039
|
signal: this.#shutdown.signal,
|
|
@@ -10694,7 +11046,7 @@ var init_consumer = __esm({
|
|
|
10694
11046
|
});
|
|
10695
11047
|
this.#assertOpen();
|
|
10696
11048
|
const changed = roster?.view !== this.#roster?.view;
|
|
10697
|
-
this.#roster = roster;
|
|
11049
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, roster);
|
|
10698
11050
|
custody.retain(roster?.rows ?? []);
|
|
10699
11051
|
if (discovered && roster?.view !== void 0)
|
|
10700
11052
|
this.#grantReach = discovered.grantReach ? { view: roster.view, reach: discovered.grantReach } : void 0;
|
|
@@ -10830,7 +11182,7 @@ var init_consumer = __esm({
|
|
|
10830
11182
|
return void 0;
|
|
10831
11183
|
try {
|
|
10832
11184
|
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
10833
|
-
const roster = await readVaultRoster(this.#options.rosterPath);
|
|
11185
|
+
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10834
11186
|
const row = roster?.rows.find((entry) => entry.routeId === routeId);
|
|
10835
11187
|
return this.#normalizeInsulaQuota(row?.accountIdentity);
|
|
10836
11188
|
} catch {
|
|
@@ -10844,7 +11196,7 @@ var init_consumer = __esm({
|
|
|
10844
11196
|
return { miss: "unreachable" };
|
|
10845
11197
|
try {
|
|
10846
11198
|
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
10847
|
-
const roster = await readVaultRoster(this.#options.rosterPath);
|
|
11199
|
+
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10848
11200
|
const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
|
|
10849
11201
|
if (!account || !this.#insula)
|
|
10850
11202
|
return { miss: "unreachable" };
|
|
@@ -10894,7 +11246,7 @@ var init_consumer = __esm({
|
|
|
10894
11246
|
this.#insula = void 0;
|
|
10895
11247
|
throw new ClaustrumConsumerError("not-active", "Claustrum scoped custody is not active");
|
|
10896
11248
|
}
|
|
10897
|
-
const current = await readVaultRoster(this.#options.rosterPath);
|
|
11249
|
+
const current = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10898
11250
|
this.#assertOpen(signal);
|
|
10899
11251
|
const observed = roster.rows.find((row) => row.routeId === routeId);
|
|
10900
11252
|
const configured = current?.rows.find((row) => row.routeId === routeId);
|
|
@@ -10973,13 +11325,13 @@ var init_consumer = __esm({
|
|
|
10973
11325
|
async decline(routeId) {
|
|
10974
11326
|
this.#assertOpen();
|
|
10975
11327
|
await declineVaultRoute(this.#options.rosterPath, routeId);
|
|
10976
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11328
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10977
11329
|
this.#custody?.retain(this.#roster?.rows ?? []);
|
|
10978
11330
|
}
|
|
10979
11331
|
async accept(routeId) {
|
|
10980
11332
|
this.#assertOpen();
|
|
10981
11333
|
await acceptVaultRoute(this.#options.rosterPath, routeId);
|
|
10982
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11334
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10983
11335
|
}
|
|
10984
11336
|
/**
|
|
10985
11337
|
* Store a quota or profile observation for a vault route. The receipt the
|
|
@@ -10989,7 +11341,7 @@ var init_consumer = __esm({
|
|
|
10989
11341
|
*/
|
|
10990
11342
|
async recordQuota(routeId, observation, attempt) {
|
|
10991
11343
|
this.#assertOpen();
|
|
10992
|
-
|
|
11344
|
+
return recordVaultQuota(this.#options.rosterPath, {
|
|
10993
11345
|
routeId,
|
|
10994
11346
|
observation,
|
|
10995
11347
|
credentialId: attempt.credentialId,
|
|
@@ -11001,27 +11353,21 @@ var init_consumer = __esm({
|
|
|
11001
11353
|
expectedAccountIdentity: attempt.expectedAccountIdentity
|
|
11002
11354
|
}
|
|
11003
11355
|
});
|
|
11004
|
-
if (kept)
|
|
11005
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11006
|
-
return kept;
|
|
11007
11356
|
}
|
|
11008
11357
|
/**
|
|
11009
11358
|
* Store a background observation that belongs to an account rather than to
|
|
11010
11359
|
* a served credential (an insula reading from `cachedInsulaQuotaForRoute`).
|
|
11011
11360
|
* It lands only while the route is still bound to that known account, so no
|
|
11012
11361
|
* credential fetch is needed and a replaced account's reading is dropped.
|
|
11013
|
-
*
|
|
11362
|
+
* Memory updates immediately; durable publication is detached and coalesced.
|
|
11014
11363
|
*/
|
|
11015
11364
|
async recordAccountQuota(routeId, accountIdentity, observation) {
|
|
11016
11365
|
this.#assertOpen();
|
|
11017
|
-
|
|
11366
|
+
return recordVaultAccountQuota(this.#options.rosterPath, {
|
|
11018
11367
|
routeId,
|
|
11019
11368
|
accountIdentity,
|
|
11020
11369
|
observation
|
|
11021
11370
|
});
|
|
11022
|
-
if (kept)
|
|
11023
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11024
|
-
return kept;
|
|
11025
11371
|
}
|
|
11026
11372
|
close() {
|
|
11027
11373
|
if (this.#shutdown.signal.aborted)
|
|
@@ -11036,6 +11382,13 @@ var init_consumer = __esm({
|
|
|
11036
11382
|
this.#insula = void 0;
|
|
11037
11383
|
this.#roster = void 0;
|
|
11038
11384
|
this.#grantReach = void 0;
|
|
11385
|
+
void this.#releaseQuotaWriter();
|
|
11386
|
+
forgetPendingVaultDiscovery(this.#options.rosterPath);
|
|
11387
|
+
}
|
|
11388
|
+
/** Close immediately; the last consumer also waits for the writer's bounded drain. */
|
|
11389
|
+
async dispose() {
|
|
11390
|
+
this.close();
|
|
11391
|
+
await this.#releaseQuotaWriter();
|
|
11039
11392
|
}
|
|
11040
11393
|
};
|
|
11041
11394
|
}
|
|
@@ -11078,6 +11431,7 @@ __export(claustrum_exports, {
|
|
|
11078
11431
|
declineAccount: () => declineAccount,
|
|
11079
11432
|
declineVaultRoute: () => declineVaultRoute,
|
|
11080
11433
|
disconnectClaustrumEnrollment: () => disconnectClaustrumEnrollment,
|
|
11434
|
+
drainVaultQuota: () => drainVaultQuota,
|
|
11081
11435
|
enrollmentAuthority: () => enrollmentAuthority,
|
|
11082
11436
|
enrollmentName: () => enrollmentName,
|
|
11083
11437
|
getClaustrumEnrollmentPaths: () => getClaustrumEnrollmentPaths,
|
|
@@ -11116,6 +11470,7 @@ var init_claustrum = __esm({
|
|
|
11116
11470
|
init_host_slot();
|
|
11117
11471
|
init_insula();
|
|
11118
11472
|
init_interlock();
|
|
11473
|
+
init_quota_writer();
|
|
11119
11474
|
init_roster();
|
|
11120
11475
|
init_watch();
|
|
11121
11476
|
}
|
|
@@ -11196,7 +11551,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11196
11551
|
if (!released && lastUpdate + RENEWAL_STALE < Date.now())
|
|
11197
11552
|
compromise();
|
|
11198
11553
|
}
|
|
11199
|
-
function
|
|
11554
|
+
function schedule2(delay3 = UPDATE) {
|
|
11200
11555
|
if (released)
|
|
11201
11556
|
return;
|
|
11202
11557
|
timer = setTimeout(() => {
|
|
@@ -11210,7 +11565,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11210
11565
|
if (errorCode(error) === "ENOENT" || lastUpdate + RENEWAL_STALE < Date.now())
|
|
11211
11566
|
compromise();
|
|
11212
11567
|
else
|
|
11213
|
-
|
|
11568
|
+
schedule2(1e3);
|
|
11214
11569
|
}
|
|
11215
11570
|
async function update() {
|
|
11216
11571
|
assertFresh();
|
|
@@ -11243,14 +11598,14 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11243
11598
|
mtime = next.getTime();
|
|
11244
11599
|
lastUpdate = Date.now();
|
|
11245
11600
|
active.set(path5, { ...identity, mtime, renewedAt: lastUpdate });
|
|
11246
|
-
|
|
11601
|
+
schedule2();
|
|
11247
11602
|
}
|
|
11248
11603
|
onRenew?.(async () => {
|
|
11249
11604
|
if (timer)
|
|
11250
11605
|
clearTimeout(timer);
|
|
11251
11606
|
await update();
|
|
11252
11607
|
});
|
|
11253
|
-
|
|
11608
|
+
schedule2();
|
|
11254
11609
|
return {
|
|
11255
11610
|
assertFresh,
|
|
11256
11611
|
async release() {
|
|
@@ -11309,7 +11664,7 @@ var init_lock = __esm({
|
|
|
11309
11664
|
import { createHash as createHash8 } from "node:crypto";
|
|
11310
11665
|
import { constants as constants2 } from "node:fs";
|
|
11311
11666
|
import { lstat as lstat3, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
11312
|
-
import { dirname as dirname10, resolve as
|
|
11667
|
+
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
11313
11668
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
11314
11669
|
function rootSpans(text2) {
|
|
11315
11670
|
let i = text2.indexOf("{") + 1;
|
|
@@ -11510,8 +11865,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
11510
11865
|
if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
11511
11866
|
throw new PiSlotError("invalid-options");
|
|
11512
11867
|
}
|
|
11513
|
-
const authPath =
|
|
11514
|
-
const stashPath =
|
|
11868
|
+
const authPath = resolve8(options.authPath);
|
|
11869
|
+
const stashPath = resolve8(options.stashPath);
|
|
11515
11870
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
11516
11871
|
throw new PiSlotError("invalid-options");
|
|
11517
11872
|
}
|
|
@@ -11680,7 +12035,7 @@ var init_pi_slot = __esm({
|
|
|
11680
12035
|
|
|
11681
12036
|
// src/plugin/index.ts
|
|
11682
12037
|
import { createHash as createHash20, randomUUID as randomUUID20 } from "node:crypto";
|
|
11683
|
-
import { join as
|
|
12038
|
+
import { join as join33, resolve as resolve19 } from "node:path";
|
|
11684
12039
|
|
|
11685
12040
|
// ../core/dist/abort-forwarding.js
|
|
11686
12041
|
function forwardAbort(source, target) {
|
|
@@ -18228,7 +18583,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
18228
18583
|
});
|
|
18229
18584
|
}
|
|
18230
18585
|
async function sleep(ms) {
|
|
18231
|
-
await new Promise((
|
|
18586
|
+
await new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18232
18587
|
}
|
|
18233
18588
|
async function acquireFencedFileLock(options) {
|
|
18234
18589
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -18344,8 +18699,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18344
18699
|
let released = false;
|
|
18345
18700
|
let lost = false;
|
|
18346
18701
|
let lostResolve = null;
|
|
18347
|
-
let lostPromise = new Promise((
|
|
18348
|
-
lostResolve =
|
|
18702
|
+
let lostPromise = new Promise((resolve20) => {
|
|
18703
|
+
lostResolve = resolve20;
|
|
18349
18704
|
});
|
|
18350
18705
|
const markLost = () => {
|
|
18351
18706
|
if (lost)
|
|
@@ -18355,9 +18710,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18355
18710
|
clearInterval(renewTimer);
|
|
18356
18711
|
renewTimer = null;
|
|
18357
18712
|
}
|
|
18358
|
-
const
|
|
18713
|
+
const resolve20 = lostResolve;
|
|
18359
18714
|
lostResolve = null;
|
|
18360
|
-
|
|
18715
|
+
resolve20?.();
|
|
18361
18716
|
};
|
|
18362
18717
|
const setupRenew = () => {
|
|
18363
18718
|
if (options.renew === false)
|
|
@@ -18584,7 +18939,7 @@ var AccountStorageUnreadableError = class extends Error {
|
|
|
18584
18939
|
}
|
|
18585
18940
|
};
|
|
18586
18941
|
var RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
18587
|
-
var DEFAULT_SLEEP = (ms) => new Promise((
|
|
18942
|
+
var DEFAULT_SLEEP = (ms) => new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18588
18943
|
var DEFAULT_BUILD_BACKUP_PATH = (path5, now) => `${path5}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
18589
18944
|
async function ensureSecurePermissions(path5) {
|
|
18590
18945
|
try {
|
|
@@ -18975,7 +19330,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
18975
19330
|
return mutateAccountStorage(path5, () => incoming);
|
|
18976
19331
|
}
|
|
18977
19332
|
async function clearAccountStorage(path5) {
|
|
18978
|
-
const sleep5 = (ms) => new Promise((
|
|
19333
|
+
const sleep5 = (ms) => new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18979
19334
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
18980
19335
|
try {
|
|
18981
19336
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -20166,8 +20521,8 @@ var AccountManager = class _AccountManager {
|
|
|
20166
20521
|
await this.saveInFlight;
|
|
20167
20522
|
return;
|
|
20168
20523
|
}
|
|
20169
|
-
return new Promise((
|
|
20170
|
-
this.savePromiseResolvers.push({ resolve:
|
|
20524
|
+
return new Promise((resolve20, reject) => {
|
|
20525
|
+
this.savePromiseResolvers.push({ resolve: resolve20, reject });
|
|
20171
20526
|
});
|
|
20172
20527
|
}
|
|
20173
20528
|
async dispose() {
|
|
@@ -20210,8 +20565,8 @@ var AccountManager = class _AccountManager {
|
|
|
20210
20565
|
reject(error);
|
|
20211
20566
|
throw error;
|
|
20212
20567
|
}
|
|
20213
|
-
for (const { resolve:
|
|
20214
|
-
|
|
20568
|
+
for (const { resolve: resolve20 } of resolvers)
|
|
20569
|
+
resolve20();
|
|
20215
20570
|
}
|
|
20216
20571
|
async executeSave() {
|
|
20217
20572
|
this.savePending = false;
|
|
@@ -20225,16 +20580,16 @@ var AccountManager = class _AccountManager {
|
|
|
20225
20580
|
}
|
|
20226
20581
|
try {
|
|
20227
20582
|
await this.saveToDisk();
|
|
20228
|
-
for (const { resolve:
|
|
20229
|
-
|
|
20583
|
+
for (const { resolve: resolve20 } of resolvers) {
|
|
20584
|
+
resolve20();
|
|
20230
20585
|
}
|
|
20231
20586
|
} catch (error) {
|
|
20232
20587
|
if (isStorageLockContention(error)) {
|
|
20233
20588
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
20234
20589
|
error: String(error)
|
|
20235
20590
|
});
|
|
20236
|
-
for (const { resolve:
|
|
20237
|
-
|
|
20591
|
+
for (const { resolve: resolve20 } of resolvers) {
|
|
20592
|
+
resolve20();
|
|
20238
20593
|
}
|
|
20239
20594
|
return;
|
|
20240
20595
|
}
|
|
@@ -20711,7 +21066,7 @@ function getHttpsProxy(url) {
|
|
|
20711
21066
|
}
|
|
20712
21067
|
}
|
|
20713
21068
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
20714
|
-
return new Promise((
|
|
21069
|
+
return new Promise((resolve20, reject) => {
|
|
20715
21070
|
let buffer = Buffer3.alloc(0);
|
|
20716
21071
|
const timeout = setTimeout(() => {
|
|
20717
21072
|
onTimeout();
|
|
@@ -20734,7 +21089,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
20734
21089
|
return;
|
|
20735
21090
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
20736
21091
|
const leftover = buffer.subarray(marker + 4);
|
|
20737
|
-
cleanup2(() =>
|
|
21092
|
+
cleanup2(() => resolve20({ head, leftover }));
|
|
20738
21093
|
};
|
|
20739
21094
|
socket.on("data", onData);
|
|
20740
21095
|
socket.once("error", onError);
|
|
@@ -20748,7 +21103,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
20748
21103
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
20749
21104
|
signal: signal ?? void 0
|
|
20750
21105
|
});
|
|
20751
|
-
await new Promise((
|
|
21106
|
+
await new Promise((resolve20, reject) => {
|
|
20752
21107
|
const timeout = setTimeout(() => {
|
|
20753
21108
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
20754
21109
|
proxySocket.destroy();
|
|
@@ -20757,7 +21112,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
20757
21112
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20758
21113
|
proxySocket.once("connect", () => {
|
|
20759
21114
|
cleanup2();
|
|
20760
|
-
|
|
21115
|
+
resolve20();
|
|
20761
21116
|
});
|
|
20762
21117
|
proxySocket.once("error", (error) => {
|
|
20763
21118
|
cleanup2();
|
|
@@ -20782,7 +21137,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20782
21137
|
if (leftover.length > 0) {
|
|
20783
21138
|
proxySocket.unshift(leftover);
|
|
20784
21139
|
}
|
|
20785
|
-
return await new Promise((
|
|
21140
|
+
return await new Promise((resolve20, reject) => {
|
|
20786
21141
|
const tlsOptions = {
|
|
20787
21142
|
socket: proxySocket,
|
|
20788
21143
|
servername: targetHost,
|
|
@@ -20797,7 +21152,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20797
21152
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20798
21153
|
tlsSocket.once("secureConnect", () => {
|
|
20799
21154
|
cleanup2();
|
|
20800
|
-
|
|
21155
|
+
resolve20(tlsSocket);
|
|
20801
21156
|
});
|
|
20802
21157
|
tlsSocket.once("error", (error) => {
|
|
20803
21158
|
cleanup2();
|
|
@@ -20806,7 +21161,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20806
21161
|
});
|
|
20807
21162
|
}
|
|
20808
21163
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
20809
|
-
return await new Promise((
|
|
21164
|
+
return await new Promise((resolve20, reject) => {
|
|
20810
21165
|
const tlsOptions = {
|
|
20811
21166
|
host: targetUrl.hostname,
|
|
20812
21167
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -20822,7 +21177,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
20822
21177
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20823
21178
|
socket.once("secureConnect", () => {
|
|
20824
21179
|
cleanup2();
|
|
20825
|
-
|
|
21180
|
+
resolve20(socket);
|
|
20826
21181
|
});
|
|
20827
21182
|
socket.once("error", (error) => {
|
|
20828
21183
|
cleanup2();
|
|
@@ -22025,11 +22380,11 @@ function containsCredential(value, credentials, projectIds, seen = /* @__PURE__
|
|
|
22025
22380
|
function redactCredentialError(error, credentials, projectIds) {
|
|
22026
22381
|
const source = error instanceof Error || error instanceof DOMException ? error : void 0;
|
|
22027
22382
|
const message = redactCredentialText(source?.message ?? String(error), credentials, projectIds);
|
|
22028
|
-
const
|
|
22383
|
+
const fields2 = source ? Reflect.ownKeys(source).map((key) => ({
|
|
22029
22384
|
key,
|
|
22030
22385
|
descriptor: Object.getOwnPropertyDescriptor(source, key)
|
|
22031
22386
|
})) : [];
|
|
22032
|
-
const cause =
|
|
22387
|
+
const cause = fields2.find(({ key }) => key === "cause")?.descriptor;
|
|
22033
22388
|
const secretCause = cause && (!("value" in cause) || containsCredential(cause.value, credentials, projectIds));
|
|
22034
22389
|
try {
|
|
22035
22390
|
if (source) {
|
|
@@ -22039,7 +22394,7 @@ function redactCredentialError(error, credentials, projectIds) {
|
|
|
22039
22394
|
configurable: true,
|
|
22040
22395
|
writable: true
|
|
22041
22396
|
});
|
|
22042
|
-
for (const { key, descriptor } of
|
|
22397
|
+
for (const { key, descriptor } of fields2) {
|
|
22043
22398
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
22044
22399
|
continue;
|
|
22045
22400
|
const value = scrub2(descriptor.value, credentials, projectIds);
|
|
@@ -22054,7 +22409,7 @@ function redactCredentialError(error, credentials, projectIds) {
|
|
|
22054
22409
|
}
|
|
22055
22410
|
const safe = new Error(message);
|
|
22056
22411
|
safe.name = redactCredentialText(source?.name ?? "Error", credentials, projectIds);
|
|
22057
|
-
for (const { key, descriptor } of
|
|
22412
|
+
for (const { key, descriptor } of fields2) {
|
|
22058
22413
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
22059
22414
|
continue;
|
|
22060
22415
|
Object.defineProperty(safe, key, {
|
|
@@ -22181,15 +22536,15 @@ async function redactCredentialResponse(response, credentials, bufferedBody, pro
|
|
|
22181
22536
|
|
|
22182
22537
|
// ../core/dist/pi-paths.js
|
|
22183
22538
|
import { homedir } from "node:os";
|
|
22184
|
-
import { dirname as dirname11, join as
|
|
22539
|
+
import { dirname as dirname11, join as join7 } from "node:path";
|
|
22185
22540
|
function getPiConfigDir() {
|
|
22186
|
-
return process.env.PI_AGENT_DIR?.trim() ||
|
|
22541
|
+
return process.env.PI_AGENT_DIR?.trim() || join7(homedir(), ".pi", "agent");
|
|
22187
22542
|
}
|
|
22188
22543
|
function getPiAntigravityAuthFile() {
|
|
22189
|
-
return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() ||
|
|
22544
|
+
return process.env.PI_ANTIGRAVITY_AUTH_FILE?.trim() || join7(getPiConfigDir(), "antigravity-accounts.json");
|
|
22190
22545
|
}
|
|
22191
22546
|
function getPiAntigravityVaultDir() {
|
|
22192
|
-
return
|
|
22547
|
+
return join7(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
|
|
22193
22548
|
}
|
|
22194
22549
|
|
|
22195
22550
|
// ../core/dist/pre-response-deadline.js
|
|
@@ -22365,8 +22720,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
22365
22720
|
return allowedTiers[0]?.id;
|
|
22366
22721
|
}
|
|
22367
22722
|
function wait(ms) {
|
|
22368
|
-
return new Promise((
|
|
22369
|
-
setTimeout(
|
|
22723
|
+
return new Promise((resolve20) => {
|
|
22724
|
+
setTimeout(resolve20, ms);
|
|
22370
22725
|
});
|
|
22371
22726
|
}
|
|
22372
22727
|
function extractManagedProjectId(payload) {
|
|
@@ -22925,11 +23280,16 @@ function mostConstrainedWindow(windows2) {
|
|
|
22925
23280
|
};
|
|
22926
23281
|
}
|
|
22927
23282
|
function poolForBucketId(bucketId) {
|
|
22928
|
-
|
|
22929
|
-
|
|
22930
|
-
|
|
22931
|
-
|
|
22932
|
-
|
|
23283
|
+
switch (bucketId) {
|
|
23284
|
+
case "gemini-5h":
|
|
23285
|
+
case "gemini-weekly":
|
|
23286
|
+
return "gemini";
|
|
23287
|
+
case "3p-5h":
|
|
23288
|
+
case "3p-weekly":
|
|
23289
|
+
return "non-gemini";
|
|
23290
|
+
default:
|
|
23291
|
+
return null;
|
|
23292
|
+
}
|
|
22933
23293
|
}
|
|
22934
23294
|
function parseDescriptionModelCount(description) {
|
|
22935
23295
|
const prefixMatch = description.match(/^[^:]+:\s*/);
|
|
@@ -22950,31 +23310,60 @@ function windowDurationMs(window) {
|
|
|
22950
23310
|
}
|
|
22951
23311
|
}
|
|
22952
23312
|
function aggregateQuotaSummary(response) {
|
|
22953
|
-
const
|
|
22954
|
-
|
|
23313
|
+
const windowsByPool = {
|
|
23314
|
+
gemini: /* @__PURE__ */ new Map(),
|
|
23315
|
+
"non-gemini": /* @__PURE__ */ new Map()
|
|
23316
|
+
};
|
|
23317
|
+
const modelCounts = {
|
|
23318
|
+
gemini: 0,
|
|
23319
|
+
"non-gemini": 0
|
|
23320
|
+
};
|
|
23321
|
+
const seenBucketIds = /* @__PURE__ */ new Set();
|
|
23322
|
+
const duplicateBucketIds = /* @__PURE__ */ new Set();
|
|
22955
23323
|
for (const group of response.groups) {
|
|
22956
|
-
const
|
|
23324
|
+
const contributingPools = /* @__PURE__ */ new Set();
|
|
22957
23325
|
for (const bucket of group.buckets) {
|
|
22958
|
-
|
|
22959
|
-
|
|
23326
|
+
if (bucket.disabled === true)
|
|
23327
|
+
continue;
|
|
23328
|
+
const pool = poolForBucketId(bucket.bucketId);
|
|
23329
|
+
if (!pool)
|
|
22960
23330
|
continue;
|
|
22961
|
-
|
|
23331
|
+
contributingPools.add(pool);
|
|
23332
|
+
const window = {
|
|
22962
23333
|
window: bucket.window,
|
|
22963
23334
|
remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
|
|
22964
23335
|
resetTime: bucket.resetTime
|
|
22965
|
-
}
|
|
23336
|
+
};
|
|
23337
|
+
const previous = windowsByPool[pool].get(bucket.bucketId);
|
|
23338
|
+
if (seenBucketIds.has(bucket.bucketId)) {
|
|
23339
|
+
duplicateBucketIds.add(bucket.bucketId);
|
|
23340
|
+
} else {
|
|
23341
|
+
seenBucketIds.add(bucket.bucketId);
|
|
23342
|
+
}
|
|
23343
|
+
if (!previous || window.remainingFraction < previous.remainingFraction) {
|
|
23344
|
+
windowsByPool[pool].set(bucket.bucketId, window);
|
|
23345
|
+
}
|
|
22966
23346
|
}
|
|
23347
|
+
const modelCount = group.description ? parseDescriptionModelCount(group.description) : 0;
|
|
23348
|
+
for (const pool of contributingPools)
|
|
23349
|
+
modelCounts[pool] += modelCount;
|
|
23350
|
+
}
|
|
23351
|
+
if (duplicateBucketIds.size > 0) {
|
|
23352
|
+
log4.debug("duplicate quota summary bucket ids", {
|
|
23353
|
+
bucketIds: [...duplicateBucketIds].sort()
|
|
23354
|
+
});
|
|
23355
|
+
}
|
|
23356
|
+
const groups = {};
|
|
23357
|
+
let totalCount = 0;
|
|
23358
|
+
for (const pool of ["gemini", "non-gemini"]) {
|
|
23359
|
+
const windows2 = [...windowsByPool[pool].values()];
|
|
22967
23360
|
if (windows2.length === 0)
|
|
22968
23361
|
continue;
|
|
22969
23362
|
windows2.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
|
|
22970
23363
|
const constrained = mostConstrainedWindow(windows2);
|
|
22971
|
-
|
|
22972
|
-
if (!recognizedBucket)
|
|
22973
|
-
continue;
|
|
22974
|
-
const pool = poolForBucketId(recognizedBucket.bucketId);
|
|
22975
|
-
if (!pool || !constrained)
|
|
23364
|
+
if (!constrained)
|
|
22976
23365
|
continue;
|
|
22977
|
-
const modelCount =
|
|
23366
|
+
const modelCount = modelCounts[pool];
|
|
22978
23367
|
groups[pool] = {
|
|
22979
23368
|
remainingFraction: constrained.remainingFraction,
|
|
22980
23369
|
resetTime: constrained.resetTime,
|
|
@@ -23337,6 +23726,7 @@ function toGeminiSchema(schema, options = {}) {
|
|
|
23337
23726
|
}
|
|
23338
23727
|
const numericConstraintHints = [];
|
|
23339
23728
|
const inputSchema = mergeSchemaAllOf(schema, numericConstraintHints);
|
|
23729
|
+
const schemaType = typeof inputSchema.type === "string" ? inputSchema.type.toUpperCase() : void 0;
|
|
23340
23730
|
let result = {};
|
|
23341
23731
|
const propertyNames = /* @__PURE__ */ new Set();
|
|
23342
23732
|
if (inputSchema.properties && typeof inputSchema.properties === "object") {
|
|
@@ -23345,6 +23735,12 @@ function toGeminiSchema(schema, options = {}) {
|
|
|
23345
23735
|
}
|
|
23346
23736
|
}
|
|
23347
23737
|
for (const [key, value] of Object.entries(inputSchema)) {
|
|
23738
|
+
if (schemaType !== void 0) {
|
|
23739
|
+
if (key === "items" && schemaType !== "ARRAY")
|
|
23740
|
+
continue;
|
|
23741
|
+
if (schemaType !== "OBJECT" && ["properties", "required", "propertyOrdering"].includes(key))
|
|
23742
|
+
continue;
|
|
23743
|
+
}
|
|
23348
23744
|
if (options.claudeValidated) {
|
|
23349
23745
|
if (key === "title")
|
|
23350
23746
|
continue;
|
|
@@ -24393,12 +24789,12 @@ async function commitVaultProviderState(input2) {
|
|
|
24393
24789
|
function untilAborted(pending, signal) {
|
|
24394
24790
|
if (!signal)
|
|
24395
24791
|
return pending;
|
|
24396
|
-
return new Promise((
|
|
24792
|
+
return new Promise((resolve20, reject) => {
|
|
24397
24793
|
const abort = () => reject(signal.reason);
|
|
24398
24794
|
signal.addEventListener("abort", abort, { once: true });
|
|
24399
24795
|
if (signal.aborted)
|
|
24400
24796
|
abort();
|
|
24401
|
-
pending.then(
|
|
24797
|
+
pending.then(resolve20, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
24402
24798
|
});
|
|
24403
24799
|
}
|
|
24404
24800
|
var AntigravityVaultSourceError = class extends Error {
|
|
@@ -24664,6 +25060,7 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
24664
25060
|
}
|
|
24665
25061
|
|
|
24666
25062
|
// ../core/dist/vault-enrollment-authority.js
|
|
25063
|
+
var UNSUPPORTED_VAULT_CODE = "unknown_method";
|
|
24667
25064
|
var VAULT_ACCOUNT_REMEDY = "Vault account access is unavailable. Connect accounts in the vault, or disconnect the vault to use local accounts.";
|
|
24668
25065
|
async function enrollmentAuthority2(paths, proposedName, reader) {
|
|
24669
25066
|
try {
|
|
@@ -24763,7 +25160,7 @@ async function initAntigravityVersion() {
|
|
|
24763
25160
|
// src/cli.ts
|
|
24764
25161
|
import { execFile } from "node:child_process";
|
|
24765
25162
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
24766
|
-
import { resolve as
|
|
25163
|
+
import { resolve as resolve14 } from "node:path";
|
|
24767
25164
|
import { createInterface } from "node:readline/promises";
|
|
24768
25165
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24769
25166
|
import { promisify } from "node:util";
|
|
@@ -24821,17 +25218,18 @@ import {
|
|
|
24821
25218
|
writeFileSync
|
|
24822
25219
|
} from "node:fs";
|
|
24823
25220
|
import { homedir as homedir3 } from "node:os";
|
|
24824
|
-
import { dirname as dirname14, join as
|
|
25221
|
+
import { dirname as dirname14, join as join10, resolve as resolve11 } from "node:path";
|
|
24825
25222
|
|
|
24826
25223
|
// src/common-auth-embedded/logger/engine.js
|
|
24827
25224
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
24828
25225
|
import { open as open8 } from "node:fs/promises";
|
|
24829
|
-
import { dirname as dirname13, resolve as
|
|
25226
|
+
import { dirname as dirname13, resolve as resolve10 } from "node:path";
|
|
24830
25227
|
|
|
24831
25228
|
// src/common-auth-embedded/fs/private-files.js
|
|
24832
25229
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
24833
25230
|
import { lstat as lstat4, readFile as readFile8, rename as rename7, unlink as unlink8 } from "node:fs/promises";
|
|
24834
|
-
import {
|
|
25231
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
25232
|
+
import { dirname as dirname12, join as join8, resolve as resolve9 } from "node:path";
|
|
24835
25233
|
var windowsPrivateFiles2 = process.platform === "win32";
|
|
24836
25234
|
var migrationNotices2 = /* @__PURE__ */ new Set();
|
|
24837
25235
|
function ioCode2(detail) {
|
|
@@ -24844,8 +25242,32 @@ function ioCode2(detail) {
|
|
|
24844
25242
|
return detail?.code ?? "ERR_PRIVATE_FILE";
|
|
24845
25243
|
}
|
|
24846
25244
|
var backend2;
|
|
25245
|
+
var PRIVATE_FILES_UNAVAILABLE_REASON2 = "native-addon-unavailable";
|
|
25246
|
+
function privateFilesUnavailable2(cause) {
|
|
25247
|
+
return Object.assign(new Error("Windows private-files native addon is unavailable", { cause }), {
|
|
25248
|
+
code: "ERR_PRIVATE_FILES_UNAVAILABLE",
|
|
25249
|
+
reason: PRIVATE_FILES_UNAVAILABLE_REASON2
|
|
25250
|
+
});
|
|
25251
|
+
}
|
|
25252
|
+
function isUnavailable2(api, error) {
|
|
25253
|
+
return error instanceof api.PrivateFilesUnavailableError || error?.code === "ERR_PRIVATE_FILES_UNAVAILABLE";
|
|
25254
|
+
}
|
|
25255
|
+
async function assertNativeAddonLoads2(api) {
|
|
25256
|
+
try {
|
|
25257
|
+
await api.verifyPrivatePath(join8(tmpdir2(), `.common-auth-private-files-probe-${randomUUID13()}`), "file");
|
|
25258
|
+
} catch (error) {
|
|
25259
|
+
if (isUnavailable2(api, error))
|
|
25260
|
+
throw privateFilesUnavailable2(error);
|
|
25261
|
+
}
|
|
25262
|
+
}
|
|
24847
25263
|
function loadBackend2() {
|
|
24848
|
-
backend2 ??= import("@cortexkit/private-files")
|
|
25264
|
+
backend2 ??= import("@cortexkit/private-files").then(async (api) => {
|
|
25265
|
+
if (windowsPrivateFiles2)
|
|
25266
|
+
await assertNativeAddonLoads2(api);
|
|
25267
|
+
return api;
|
|
25268
|
+
}, (cause) => {
|
|
25269
|
+
throw windowsPrivateFiles2 ? privateFilesUnavailable2(cause) : cause;
|
|
25270
|
+
});
|
|
24849
25271
|
return backend2;
|
|
24850
25272
|
}
|
|
24851
25273
|
var PrivateFileError2 = class extends Error {
|
|
@@ -24862,7 +25284,7 @@ var PrivateFileError2 = class extends Error {
|
|
|
24862
25284
|
orphanPath;
|
|
24863
25285
|
constructor(path5, stage, cause) {
|
|
24864
25286
|
const detail = cause;
|
|
24865
|
-
super(`Private file refused at ${stage}: ${path5} (${detail?.reason ?? detail?.code ?? "io-error"}).
|
|
25287
|
+
super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path5} (${PRIVATE_FILES_UNAVAILABLE_REASON2}). The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path5} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
24866
25288
|
this.path = path5;
|
|
24867
25289
|
this.stage = stage;
|
|
24868
25290
|
this.name = "PrivateFileError";
|
|
@@ -24882,7 +25304,7 @@ async function privateOperation2(path5, stage, operation) {
|
|
|
24882
25304
|
}
|
|
24883
25305
|
var safeParentOptionsForTest2;
|
|
24884
25306
|
async function verifySafeDirectory2(path5, options) {
|
|
24885
|
-
path5 =
|
|
25307
|
+
path5 = resolve9(path5);
|
|
24886
25308
|
options ??= safeParentOptionsForTest2;
|
|
24887
25309
|
await privateOperation2(path5, "safe-parent", async () => {
|
|
24888
25310
|
const result = await (await loadBackend2()).verifySafeParent(path5, options);
|
|
@@ -24897,7 +25319,7 @@ async function verifySafeDirectory2(path5, options) {
|
|
|
24897
25319
|
});
|
|
24898
25320
|
}
|
|
24899
25321
|
async function verifyPrivate2(path5, kind, migrate = false) {
|
|
24900
|
-
path5 =
|
|
25322
|
+
path5 = resolve9(path5);
|
|
24901
25323
|
if (kind === "directory")
|
|
24902
25324
|
return verifySafeDirectory2(path5);
|
|
24903
25325
|
await privateOperation2(path5, "verify", async () => {
|
|
@@ -24932,7 +25354,7 @@ async function verifyPrivate2(path5, kind, migrate = false) {
|
|
|
24932
25354
|
});
|
|
24933
25355
|
}
|
|
24934
25356
|
async function ensurePrivateDirectory3(path5, _migrate = false, options) {
|
|
24935
|
-
path5 =
|
|
25357
|
+
path5 = resolve9(path5);
|
|
24936
25358
|
await privateOperation2(path5, "directory", async () => {
|
|
24937
25359
|
const api = await loadBackend2();
|
|
24938
25360
|
try {
|
|
@@ -24963,7 +25385,7 @@ async function readPrivateText2(path5, migrate = false) {
|
|
|
24963
25385
|
async function readPrivateBuffer2(path5, migrate = false) {
|
|
24964
25386
|
if (!windowsPrivateFiles2)
|
|
24965
25387
|
return readFile8(path5);
|
|
24966
|
-
path5 =
|
|
25388
|
+
path5 = resolve9(path5);
|
|
24967
25389
|
if (migrate) {
|
|
24968
25390
|
await verifySafeDirectory2(dirname12(path5));
|
|
24969
25391
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -24971,20 +25393,20 @@ async function readPrivateBuffer2(path5, migrate = false) {
|
|
|
24971
25393
|
return privateOperation2(path5, "read", async () => (await loadBackend2()).readOwnerOnly(path5));
|
|
24972
25394
|
}
|
|
24973
25395
|
async function createPrivateBytes2(path5, bytes) {
|
|
24974
|
-
await verifySafeDirectory2(dirname12(
|
|
25396
|
+
await verifySafeDirectory2(dirname12(resolve9(path5)));
|
|
24975
25397
|
await privateOperation2(path5, "create", async () => {
|
|
24976
|
-
await (await loadBackend2()).createPrivateFile(
|
|
25398
|
+
await (await loadBackend2()).createPrivateFile(resolve9(path5), bytes);
|
|
24977
25399
|
});
|
|
24978
25400
|
}
|
|
24979
25401
|
async function createPrivateDirectoryExclusive2(path5) {
|
|
24980
|
-
await verifySafeDirectory2(dirname12(
|
|
25402
|
+
await verifySafeDirectory2(dirname12(resolve9(path5)));
|
|
24981
25403
|
await privateOperation2(path5, "directory-create", async () => {
|
|
24982
|
-
await (await loadBackend2()).createOwnerOnly(
|
|
25404
|
+
await (await loadBackend2()).createOwnerOnly(resolve9(path5), { kind: "dir" });
|
|
24983
25405
|
});
|
|
24984
25406
|
}
|
|
24985
25407
|
async function replaceWindowsFile2(from, to, options = {}) {
|
|
24986
|
-
from =
|
|
24987
|
-
to =
|
|
25408
|
+
from = resolve9(from);
|
|
25409
|
+
to = resolve9(to);
|
|
24988
25410
|
const now = options.now ?? (() => performance.now());
|
|
24989
25411
|
const start = now();
|
|
24990
25412
|
const leaseDeadline = options.deadline ?? Infinity;
|
|
@@ -25027,7 +25449,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
25027
25449
|
throw error;
|
|
25028
25450
|
}
|
|
25029
25451
|
async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
25030
|
-
path5 =
|
|
25452
|
+
path5 = resolve9(path5);
|
|
25031
25453
|
await ensurePrivateDirectory3(dirname12(path5));
|
|
25032
25454
|
try {
|
|
25033
25455
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -25035,7 +25457,7 @@ async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
|
25035
25457
|
if (error.code !== "ENOENT")
|
|
25036
25458
|
throw error;
|
|
25037
25459
|
}
|
|
25038
|
-
const stage =
|
|
25460
|
+
const stage = resolve9(options.stagePath ?? `${path5}.${randomUUID13()}.tmp`);
|
|
25039
25461
|
if (dirname12(stage) !== dirname12(path5))
|
|
25040
25462
|
throw new PrivateFileError2(path5, "stage-directory", { code: "EXDEV" });
|
|
25041
25463
|
let created = false;
|
|
@@ -25111,15 +25533,15 @@ function createRedactor2(options = {}) {
|
|
|
25111
25533
|
return SECRET_KEY_EXACT2.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
25112
25534
|
}
|
|
25113
25535
|
function errorEntries(error) {
|
|
25114
|
-
const
|
|
25536
|
+
const fields2 = error;
|
|
25115
25537
|
const entries = [
|
|
25116
25538
|
["name", error.name],
|
|
25117
25539
|
["message", error.message],
|
|
25118
25540
|
["stack", error.stack]
|
|
25119
25541
|
];
|
|
25120
25542
|
for (const key of ["code", "status", "cause"])
|
|
25121
|
-
if (
|
|
25122
|
-
entries.push([key,
|
|
25543
|
+
if (fields2[key] !== void 0)
|
|
25544
|
+
entries.push([key, fields2[key]]);
|
|
25123
25545
|
const listed = new Set(entries.map(([key]) => key));
|
|
25124
25546
|
for (const entry of Object.entries(error))
|
|
25125
25547
|
if (!listed.has(entry[0]))
|
|
@@ -25220,7 +25642,7 @@ async function openWindowsFile2(sink, file) {
|
|
|
25220
25642
|
return sink.handle;
|
|
25221
25643
|
}
|
|
25222
25644
|
async function flushWindowsFile2(sink, file, text2) {
|
|
25223
|
-
file =
|
|
25645
|
+
file = resolve10(file);
|
|
25224
25646
|
try {
|
|
25225
25647
|
if (sink.file !== file)
|
|
25226
25648
|
await closeWindowsFile2(sink);
|
|
@@ -25357,7 +25779,7 @@ function createEngine2(options) {
|
|
|
25357
25779
|
} catch {
|
|
25358
25780
|
}
|
|
25359
25781
|
}
|
|
25360
|
-
function
|
|
25782
|
+
function schedule2() {
|
|
25361
25783
|
if (!timer)
|
|
25362
25784
|
timer = setTimeout(() => {
|
|
25363
25785
|
timer = void 0;
|
|
@@ -25399,7 +25821,7 @@ function createEngine2(options) {
|
|
|
25399
25821
|
void flushed.catch(() => {
|
|
25400
25822
|
});
|
|
25401
25823
|
} else
|
|
25402
|
-
|
|
25824
|
+
schedule2();
|
|
25403
25825
|
} catch {
|
|
25404
25826
|
}
|
|
25405
25827
|
}
|
|
@@ -25478,7 +25900,7 @@ import {
|
|
|
25478
25900
|
unlinkSync
|
|
25479
25901
|
} from "node:fs";
|
|
25480
25902
|
import { homedir as homedir2 } from "node:os";
|
|
25481
|
-
import { join as
|
|
25903
|
+
import { join as join9 } from "node:path";
|
|
25482
25904
|
import { env } from "node:process";
|
|
25483
25905
|
|
|
25484
25906
|
// src/plugin/logging-utils.ts
|
|
@@ -25610,16 +26032,16 @@ var liveLogFilePaths = /* @__PURE__ */ new Set();
|
|
|
25610
26032
|
function getConfigDir() {
|
|
25611
26033
|
const platform = process.platform;
|
|
25612
26034
|
if (platform === "win32") {
|
|
25613
|
-
return
|
|
25614
|
-
env.APPDATA ||
|
|
26035
|
+
return join9(
|
|
26036
|
+
env.APPDATA || join9(homedir2(), "AppData", "Roaming"),
|
|
25615
26037
|
"opencode"
|
|
25616
26038
|
);
|
|
25617
26039
|
}
|
|
25618
|
-
const xdgConfig2 = env.XDG_CONFIG_HOME ||
|
|
25619
|
-
return
|
|
26040
|
+
const xdgConfig2 = env.XDG_CONFIG_HOME || join9(homedir2(), ".config");
|
|
26041
|
+
return join9(xdgConfig2, "opencode");
|
|
25620
26042
|
}
|
|
25621
26043
|
function getLogsDir(customLogDir) {
|
|
25622
|
-
const logsDir = customLogDir ||
|
|
26044
|
+
const logsDir = customLogDir || join9(getConfigDir(), "antigravity-logs");
|
|
25623
26045
|
try {
|
|
25624
26046
|
mkdirSync(logsDir, { recursive: true, mode: 448 });
|
|
25625
26047
|
} catch {
|
|
@@ -25630,9 +26052,9 @@ function createLogFilePath(customLogDir) {
|
|
|
25630
26052
|
const logsDir = getLogsDir(customLogDir);
|
|
25631
26053
|
cleanupOldLogs(logsDir, 25);
|
|
25632
26054
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
25633
|
-
let candidate =
|
|
26055
|
+
let candidate = join9(logsDir, `antigravity-debug-${timestamp}.log`);
|
|
25634
26056
|
for (let suffix = 2; liveLogFilePaths.has(candidate); suffix++) {
|
|
25635
|
-
candidate =
|
|
26057
|
+
candidate = join9(logsDir, `antigravity-debug-${timestamp}-${suffix}.log`);
|
|
25636
26058
|
}
|
|
25637
26059
|
return candidate;
|
|
25638
26060
|
}
|
|
@@ -25640,7 +26062,7 @@ function cleanupOldLogs(logsDir, maxFiles) {
|
|
|
25640
26062
|
try {
|
|
25641
26063
|
const files = readdirSync(logsDir).filter(
|
|
25642
26064
|
(file) => file.startsWith("antigravity-debug-") && file.endsWith(".log")
|
|
25643
|
-
).map((file) =>
|
|
26065
|
+
).map((file) => join9(logsDir, file));
|
|
25644
26066
|
if (files.length <= maxFiles) {
|
|
25645
26067
|
return;
|
|
25646
26068
|
}
|
|
@@ -25740,13 +26162,13 @@ function closeDebugStream(state) {
|
|
|
25740
26162
|
state.logWriter = () => {
|
|
25741
26163
|
};
|
|
25742
26164
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
25743
|
-
return new Promise((
|
|
25744
|
-
current.once("close", () =>
|
|
25745
|
-
current.once("error", () =>
|
|
26165
|
+
return new Promise((resolve20) => {
|
|
26166
|
+
current.once("close", () => resolve20());
|
|
26167
|
+
current.once("error", () => resolve20());
|
|
25746
26168
|
try {
|
|
25747
26169
|
current.end();
|
|
25748
26170
|
} catch {
|
|
25749
|
-
|
|
26171
|
+
resolve20();
|
|
25750
26172
|
}
|
|
25751
26173
|
});
|
|
25752
26174
|
}
|
|
@@ -26018,13 +26440,13 @@ function closeDebugLog() {
|
|
|
26018
26440
|
if (!state || !current) return Promise.resolve();
|
|
26019
26441
|
state.logStream = null;
|
|
26020
26442
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
26021
|
-
return new Promise((
|
|
26022
|
-
current.once("close", () =>
|
|
26023
|
-
current.once("error", () =>
|
|
26443
|
+
return new Promise((resolve20) => {
|
|
26444
|
+
current.once("close", () => resolve20());
|
|
26445
|
+
current.once("error", () => resolve20());
|
|
26024
26446
|
try {
|
|
26025
26447
|
current.end();
|
|
26026
26448
|
} catch {
|
|
26027
|
-
|
|
26449
|
+
resolve20();
|
|
26028
26450
|
}
|
|
26029
26451
|
});
|
|
26030
26452
|
}
|
|
@@ -26219,7 +26641,7 @@ var GITIGNORE_ENTRIES = [
|
|
|
26219
26641
|
"antigravity-logs/"
|
|
26220
26642
|
];
|
|
26221
26643
|
async function ensureGitignore(configDir) {
|
|
26222
|
-
const gitignorePath =
|
|
26644
|
+
const gitignorePath = join10(configDir, ".gitignore");
|
|
26223
26645
|
try {
|
|
26224
26646
|
let content;
|
|
26225
26647
|
let existingLines = [];
|
|
@@ -26265,7 +26687,7 @@ async function ensureGitignore(configDir) {
|
|
|
26265
26687
|
}
|
|
26266
26688
|
}
|
|
26267
26689
|
function ensureGitignoreSync(configDir) {
|
|
26268
|
-
const gitignorePath =
|
|
26690
|
+
const gitignorePath = join10(configDir, ".gitignore");
|
|
26269
26691
|
try {
|
|
26270
26692
|
let content;
|
|
26271
26693
|
let existingLines = [];
|
|
@@ -26304,8 +26726,8 @@ function ensureGitignoreSync(configDir) {
|
|
|
26304
26726
|
}
|
|
26305
26727
|
}
|
|
26306
26728
|
function getLegacyWindowsConfigDir() {
|
|
26307
|
-
return
|
|
26308
|
-
process.env.APPDATA ||
|
|
26729
|
+
return join10(
|
|
26730
|
+
process.env.APPDATA || join10(homedir3(), "AppData", "Roaming"),
|
|
26309
26731
|
"opencode"
|
|
26310
26732
|
);
|
|
26311
26733
|
}
|
|
@@ -26313,15 +26735,15 @@ function getConfigDir2() {
|
|
|
26313
26735
|
if (process.env.OPENCODE_CONFIG_DIR) {
|
|
26314
26736
|
return process.env.OPENCODE_CONFIG_DIR;
|
|
26315
26737
|
}
|
|
26316
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
26317
|
-
return
|
|
26738
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join10(homedir3(), ".config");
|
|
26739
|
+
return join10(xdgConfig2, "opencode");
|
|
26318
26740
|
}
|
|
26319
26741
|
function migrateLegacyWindowsConfig() {
|
|
26320
26742
|
if (process.platform !== "win32") {
|
|
26321
26743
|
return false;
|
|
26322
26744
|
}
|
|
26323
|
-
const newPath =
|
|
26324
|
-
const legacyPath =
|
|
26745
|
+
const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
|
|
26746
|
+
const legacyPath = join10(
|
|
26325
26747
|
getLegacyWindowsConfigDir(),
|
|
26326
26748
|
"antigravity-accounts.json"
|
|
26327
26749
|
);
|
|
@@ -26356,11 +26778,11 @@ function migrateLegacyWindowsConfig() {
|
|
|
26356
26778
|
}
|
|
26357
26779
|
}
|
|
26358
26780
|
function getStoragePathWithMigration() {
|
|
26359
|
-
const newPath =
|
|
26781
|
+
const newPath = join10(getConfigDir2(), "antigravity-accounts.json");
|
|
26360
26782
|
if (process.platform === "win32") {
|
|
26361
26783
|
migrateLegacyWindowsConfig();
|
|
26362
26784
|
if (!existsSync3(newPath)) {
|
|
26363
|
-
const legacyPath =
|
|
26785
|
+
const legacyPath = join10(
|
|
26364
26786
|
getLegacyWindowsConfigDir(),
|
|
26365
26787
|
"antigravity-accounts.json"
|
|
26366
26788
|
);
|
|
@@ -26391,7 +26813,7 @@ var LegacyAccountPoolRetiredError = class extends Error {
|
|
|
26391
26813
|
};
|
|
26392
26814
|
async function assertLegacyPoolInUse(legacyPath) {
|
|
26393
26815
|
try {
|
|
26394
|
-
await assertLegacyAccountStorageWritable(
|
|
26816
|
+
await assertLegacyAccountStorageWritable(resolve11(legacyPath));
|
|
26395
26817
|
} catch (error) {
|
|
26396
26818
|
throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
|
|
26397
26819
|
}
|
|
@@ -26411,7 +26833,7 @@ function refusalMessage(admission) {
|
|
|
26411
26833
|
}
|
|
26412
26834
|
async function bindingOf(options) {
|
|
26413
26835
|
const now = options.now ?? (() => Date.now());
|
|
26414
|
-
const legacyPath =
|
|
26836
|
+
const legacyPath = resolve11(options.legacyPath ?? getStoragePath());
|
|
26415
26837
|
return {
|
|
26416
26838
|
legacyPath,
|
|
26417
26839
|
now,
|
|
@@ -26479,7 +26901,7 @@ async function openAccountStore(options) {
|
|
|
26479
26901
|
}
|
|
26480
26902
|
function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
26481
26903
|
return initializeFreshAccountStore(modules, {
|
|
26482
|
-
legacyPath:
|
|
26904
|
+
legacyPath: resolve11(options.legacyPath ?? getStoragePath()),
|
|
26483
26905
|
now: options.now ?? (() => Date.now())
|
|
26484
26906
|
});
|
|
26485
26907
|
}
|
|
@@ -26696,7 +27118,7 @@ async function replacePoolLogins(repository, results, options = {}) {
|
|
|
26696
27118
|
// src/sidebar-state.ts
|
|
26697
27119
|
import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
26698
27120
|
import { homedir as homedir4 } from "node:os";
|
|
26699
|
-
import { dirname as dirname15, join as
|
|
27121
|
+
import { dirname as dirname15, join as join11 } from "node:path";
|
|
26700
27122
|
|
|
26701
27123
|
// ../../node_modules/.bun/xdg-basedir@5.1.0/node_modules/xdg-basedir/index.js
|
|
26702
27124
|
import os from "os";
|
|
@@ -26755,8 +27177,8 @@ async function emitMergeStep(step) {
|
|
|
26755
27177
|
function getSidebarStateFile() {
|
|
26756
27178
|
const override = process.env[SIDEBAR_STATE_ENV];
|
|
26757
27179
|
if (override && override.trim().length > 0) return override;
|
|
26758
|
-
const base = xdgState ??
|
|
26759
|
-
return
|
|
27180
|
+
const base = xdgState ?? join11(homedir4(), ".local", "state");
|
|
27181
|
+
return join11(base, SIDEBAR_STATE_DIR, SIDEBAR_STATE_FILENAME);
|
|
26760
27182
|
}
|
|
26761
27183
|
function readSidebarState(path5 = getSidebarStateFile()) {
|
|
26762
27184
|
let raw;
|
|
@@ -27102,7 +27524,7 @@ function drainSidebarWrites() {
|
|
|
27102
27524
|
return sidebarWriteChain;
|
|
27103
27525
|
}
|
|
27104
27526
|
async function sleep3(ms) {
|
|
27105
|
-
await new Promise((
|
|
27527
|
+
await new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
27106
27528
|
}
|
|
27107
27529
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
27108
27530
|
const start = Date.now();
|
|
@@ -27412,8 +27834,8 @@ var openCodeStore = {
|
|
|
27412
27834
|
clear: async () => {
|
|
27413
27835
|
}
|
|
27414
27836
|
};
|
|
27415
|
-
function defaultDiagnostic(message,
|
|
27416
|
-
debugLogToFile(
|
|
27837
|
+
function defaultDiagnostic(message, fields2) {
|
|
27838
|
+
debugLogToFile(fields2 ? `${message} ${JSON.stringify(fields2)}` : message);
|
|
27417
27839
|
}
|
|
27418
27840
|
var AccountStoreNotReadyError = class extends Error {
|
|
27419
27841
|
read;
|
|
@@ -27560,7 +27982,7 @@ function createLocationQuotaManager(options) {
|
|
|
27560
27982
|
fetchTimeoutMs: options.fetchTimeoutMs
|
|
27561
27983
|
});
|
|
27562
27984
|
const sidebar = options.sidebar;
|
|
27563
|
-
const
|
|
27985
|
+
const logger3 = options.logger;
|
|
27564
27986
|
return withSidebarPushAfterRefresh(
|
|
27565
27987
|
manager,
|
|
27566
27988
|
sidebar ? (account) => pushSidebarQuotaSnapshot(
|
|
@@ -27569,7 +27991,7 @@ function createLocationQuotaManager(options) {
|
|
|
27569
27991
|
sidebar.getActiveIndexByFamily,
|
|
27570
27992
|
{
|
|
27571
27993
|
write: sidebar.write,
|
|
27572
|
-
logger:
|
|
27994
|
+
logger: logger3,
|
|
27573
27995
|
healthScore: sidebar.healthScore ?? null,
|
|
27574
27996
|
now: sidebar.now
|
|
27575
27997
|
}
|
|
@@ -27933,14 +28355,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
27933
28355
|
name = "LocalQuotaGrantStaleError";
|
|
27934
28356
|
};
|
|
27935
28357
|
function untilQuotaAborted(pending, signal) {
|
|
27936
|
-
return new Promise((
|
|
28358
|
+
return new Promise((resolve20, reject) => {
|
|
27937
28359
|
const abort = () => reject(signal.reason);
|
|
27938
28360
|
if (signal.aborted) abort();
|
|
27939
28361
|
else signal.addEventListener("abort", abort, { once: true });
|
|
27940
28362
|
void pending.then(
|
|
27941
28363
|
(value) => {
|
|
27942
28364
|
signal.removeEventListener("abort", abort);
|
|
27943
|
-
|
|
28365
|
+
resolve20(value);
|
|
27944
28366
|
},
|
|
27945
28367
|
(error) => {
|
|
27946
28368
|
signal.removeEventListener("abort", abort);
|
|
@@ -28300,7 +28722,7 @@ function heldAccount(manager, ref) {
|
|
|
28300
28722
|
);
|
|
28301
28723
|
}
|
|
28302
28724
|
function createStoreQuotaService(options) {
|
|
28303
|
-
const { manager, logger:
|
|
28725
|
+
const { manager, logger: logger3 } = options;
|
|
28304
28726
|
const credentials = options.credentials ?? createLocalAccountCredentials(manager, { repository: options.repository });
|
|
28305
28727
|
const authorize = async (account, _signal, purpose = "required") => {
|
|
28306
28728
|
const ref = account.rowRef;
|
|
@@ -28373,11 +28795,11 @@ function createStoreQuotaService(options) {
|
|
|
28373
28795
|
};
|
|
28374
28796
|
const fetchAccountQuota = createAuthorizedFetchAccountQuota({
|
|
28375
28797
|
authorize: (account) => authorize(account),
|
|
28376
|
-
logger:
|
|
28798
|
+
logger: logger3,
|
|
28377
28799
|
transport: options.transport
|
|
28378
28800
|
});
|
|
28379
28801
|
const quotaManager = createLocationQuotaManager({
|
|
28380
|
-
logger:
|
|
28802
|
+
logger: logger3,
|
|
28381
28803
|
fetchAccountQuota,
|
|
28382
28804
|
// Backoff and cache are per credential: a re-authenticated row starts
|
|
28383
28805
|
// fresh instead of inheriting its predecessor's state.
|
|
@@ -28450,7 +28872,7 @@ function createStoreQuotaService(options) {
|
|
|
28450
28872
|
(failure2) => failure2.rowId
|
|
28451
28873
|
);
|
|
28452
28874
|
failedRows = report === void 0 || failedIds.length === 0 || failedIds.some((id) => id === void 0) ? "all" : new Set(failedIds.filter((id) => id !== void 0));
|
|
28453
|
-
|
|
28875
|
+
logger3.debug("quota readings were not all persisted", {
|
|
28454
28876
|
error: error instanceof Error ? error.message : String(error)
|
|
28455
28877
|
});
|
|
28456
28878
|
}
|
|
@@ -28561,12 +28983,12 @@ async function startOAuthListener({
|
|
|
28561
28983
|
let resolveCallback;
|
|
28562
28984
|
let rejectCallback;
|
|
28563
28985
|
let timeoutHandle;
|
|
28564
|
-
const callbackPromise = new Promise((
|
|
28986
|
+
const callbackPromise = new Promise((resolve20, reject) => {
|
|
28565
28987
|
resolveCallback = (url) => {
|
|
28566
28988
|
if (settled) return;
|
|
28567
28989
|
settled = true;
|
|
28568
28990
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
28569
|
-
|
|
28991
|
+
resolve20(url);
|
|
28570
28992
|
};
|
|
28571
28993
|
rejectCallback = (error) => {
|
|
28572
28994
|
if (settled) return;
|
|
@@ -28725,7 +29147,7 @@ async function startOAuthListener({
|
|
|
28725
29147
|
});
|
|
28726
29148
|
});
|
|
28727
29149
|
const bindAddress = getBindAddress();
|
|
28728
|
-
await new Promise((
|
|
29150
|
+
await new Promise((resolve20, reject) => {
|
|
28729
29151
|
const handleError = (error) => {
|
|
28730
29152
|
server.off("error", handleError);
|
|
28731
29153
|
if (error.code === "EADDRINUSE") {
|
|
@@ -28741,7 +29163,7 @@ async function startOAuthListener({
|
|
|
28741
29163
|
server.once("error", handleError);
|
|
28742
29164
|
server.listen(port, bindAddress, () => {
|
|
28743
29165
|
server.off("error", handleError);
|
|
28744
|
-
|
|
29166
|
+
resolve20();
|
|
28745
29167
|
});
|
|
28746
29168
|
});
|
|
28747
29169
|
server.on("error", (error) => {
|
|
@@ -28749,7 +29171,7 @@ async function startOAuthListener({
|
|
|
28749
29171
|
});
|
|
28750
29172
|
return {
|
|
28751
29173
|
waitForCallback: () => callbackPromise,
|
|
28752
|
-
close: () => new Promise((
|
|
29174
|
+
close: () => new Promise((resolve20, reject) => {
|
|
28753
29175
|
server.close((error) => {
|
|
28754
29176
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
28755
29177
|
reject(error);
|
|
@@ -28758,7 +29180,7 @@ async function startOAuthListener({
|
|
|
28758
29180
|
if (!settled) {
|
|
28759
29181
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
28760
29182
|
}
|
|
28761
|
-
|
|
29183
|
+
resolve20();
|
|
28762
29184
|
});
|
|
28763
29185
|
})
|
|
28764
29186
|
};
|
|
@@ -28770,7 +29192,7 @@ async function startOAuthListener({
|
|
|
28770
29192
|
|
|
28771
29193
|
// src/setup.ts
|
|
28772
29194
|
import { lstat as lstat5, readFile as readFile13 } from "node:fs/promises";
|
|
28773
|
-
import { join as
|
|
29195
|
+
import { join as join18, resolve as resolve13 } from "node:path";
|
|
28774
29196
|
|
|
28775
29197
|
// src/auth-method-labels.ts
|
|
28776
29198
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
@@ -28942,7 +29364,7 @@ async function select2(terminal, items, options) {
|
|
|
28942
29364
|
writeLine("");
|
|
28943
29365
|
renderedLines = lines;
|
|
28944
29366
|
};
|
|
28945
|
-
return new Promise((
|
|
29367
|
+
return new Promise((resolve20) => {
|
|
28946
29368
|
const wasRaw = stdin.isRaw ?? false;
|
|
28947
29369
|
const cleanup2 = () => {
|
|
28948
29370
|
if (cleaned)
|
|
@@ -28962,7 +29384,7 @@ async function select2(terminal, items, options) {
|
|
|
28962
29384
|
};
|
|
28963
29385
|
const finish = (value) => {
|
|
28964
29386
|
cleanup2();
|
|
28965
|
-
|
|
29387
|
+
resolve20(value);
|
|
28966
29388
|
};
|
|
28967
29389
|
const onSignal = () => finish(null);
|
|
28968
29390
|
const onKey = (data) => {
|
|
@@ -29002,7 +29424,7 @@ async function select2(terminal, items, options) {
|
|
|
29002
29424
|
stdin.setRawMode(true);
|
|
29003
29425
|
} catch {
|
|
29004
29426
|
cleanup2();
|
|
29005
|
-
|
|
29427
|
+
resolve20(null);
|
|
29006
29428
|
return;
|
|
29007
29429
|
}
|
|
29008
29430
|
stdin.resume();
|
|
@@ -29016,7 +29438,7 @@ async function select2(terminal, items, options) {
|
|
|
29016
29438
|
import { createHash as createHash10, randomBytes as randomBytes5, randomUUID as randomUUID16 } from "node:crypto";
|
|
29017
29439
|
import { constants as fsConstants2 } from "node:fs";
|
|
29018
29440
|
import { chmod as chmod3, mkdir as mkdir12, open as open10, readFile as readFile10, realpath as realpath4, rename as rename9, stat as stat7, unlink as unlink9 } from "node:fs/promises";
|
|
29019
|
-
import { basename as basename4, dirname as dirname17, extname as extname2, isAbsolute as isAbsolute3, join as
|
|
29441
|
+
import { basename as basename4, dirname as dirname17, extname as extname2, isAbsolute as isAbsolute3, join as join13, resolve as resolve12 } from "node:path";
|
|
29020
29442
|
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
29021
29443
|
|
|
29022
29444
|
// src/common-auth-embedded/fs/lock-constants.js
|
|
@@ -29038,7 +29460,7 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
29038
29460
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
29039
29461
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
29040
29462
|
import { mkdir as mkdir11, open as open9, readFile as readFile9, rename as rename8, rm as rm5, stat as stat6 } from "node:fs/promises";
|
|
29041
|
-
import { dirname as dirname16, join as
|
|
29463
|
+
import { dirname as dirname16, join as join12 } from "node:path";
|
|
29042
29464
|
|
|
29043
29465
|
// src/common-auth-embedded/fs/with-lock.js
|
|
29044
29466
|
function lockPathFor2(target, name) {
|
|
@@ -29073,7 +29495,7 @@ function acquireRefreshFileLock2(options) {
|
|
|
29073
29495
|
}
|
|
29074
29496
|
async function acquireRefreshFileLockWithClock2(options) {
|
|
29075
29497
|
const lockPath = lockPathFor2(options.path, options.name);
|
|
29076
|
-
const legacyOwnerPath =
|
|
29498
|
+
const legacyOwnerPath = join12(lockPath, "owner.json");
|
|
29077
29499
|
const ownerId = randomUUID15();
|
|
29078
29500
|
const now = options.now ?? Date.now;
|
|
29079
29501
|
let renewTimer = null;
|
|
@@ -29081,8 +29503,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
29081
29503
|
let releaseConfirmed = false;
|
|
29082
29504
|
let loss;
|
|
29083
29505
|
let resolveLoss;
|
|
29084
|
-
const lostPromise = new Promise((
|
|
29085
|
-
resolveLoss =
|
|
29506
|
+
const lostPromise = new Promise((resolve20) => {
|
|
29507
|
+
resolveLoss = resolve20;
|
|
29086
29508
|
});
|
|
29087
29509
|
function notifyTimerStep(event) {
|
|
29088
29510
|
try {
|
|
@@ -29116,7 +29538,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
29116
29538
|
let terminalIOError;
|
|
29117
29539
|
let renewalInFlight = null;
|
|
29118
29540
|
const evictPath = `${lockPath}.evicting`;
|
|
29119
|
-
const evictOwnerPath =
|
|
29541
|
+
const evictOwnerPath = join12(evictPath, "owner.json");
|
|
29120
29542
|
const evictOwnerId = randomUUID15();
|
|
29121
29543
|
const EVICT_TTL = 5e3;
|
|
29122
29544
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
@@ -29239,7 +29661,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
29239
29661
|
}
|
|
29240
29662
|
}
|
|
29241
29663
|
async function backoff() {
|
|
29242
|
-
await new Promise((
|
|
29664
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
29243
29665
|
}
|
|
29244
29666
|
async function readLockState(notifyReady = true) {
|
|
29245
29667
|
if (notifyReady && options.onStep)
|
|
@@ -29687,7 +30109,13 @@ var ENROLLMENT_SCHEMA2 = 1;
|
|
|
29687
30109
|
var ENROLLMENT_FILE_MAX_BYTES2 = 16 * 1024;
|
|
29688
30110
|
var ENROLLMENT_LOCK_TTL_MS2 = 3e4;
|
|
29689
30111
|
var TOKEN_RE2 = /^[0-9a-f]{64}$/;
|
|
30112
|
+
var UNSUPPORTED_ENROLLMENT_CODE2 = "unknown_method";
|
|
29690
30113
|
var TERMINAL_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
|
|
30114
|
+
// The daemon's answer to an operation it does not implement: a vault built
|
|
30115
|
+
// before the enrollment ceremony. It arrives as a transport Error frame with
|
|
30116
|
+
// no class, which claustrum-client before 0.13.0 labels transient/retry, but
|
|
30117
|
+
// asking again can never succeed.
|
|
30118
|
+
UNSUPPORTED_ENROLLMENT_CODE2,
|
|
29691
30119
|
"invalid_params",
|
|
29692
30120
|
"pending_exists",
|
|
29693
30121
|
"not_found",
|
|
@@ -29717,7 +30145,7 @@ function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
|
29717
30145
|
const extension = extname2(tokenPath) || ".json";
|
|
29718
30146
|
const stem = basename4(tokenPath, extname2(tokenPath));
|
|
29719
30147
|
return {
|
|
29720
|
-
statePath:
|
|
30148
|
+
statePath: join13(dirname17(tokenPath), `${stem}-state${extension}`),
|
|
29721
30149
|
tokenPath
|
|
29722
30150
|
};
|
|
29723
30151
|
}
|
|
@@ -29725,7 +30153,7 @@ function hostEnrollmentPaths2(input2) {
|
|
|
29725
30153
|
const override = input2.override?.trim();
|
|
29726
30154
|
if (override && !isAbsolute3(override) && !input2.cwd)
|
|
29727
30155
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
29728
|
-
const tokenPath = override ? isAbsolute3(override) ? override :
|
|
30156
|
+
const tokenPath = override ? isAbsolute3(override) ? override : resolve12(input2.cwd, override) : join13(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
29729
30157
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
29730
30158
|
}
|
|
29731
30159
|
function isRecord10(value) {
|
|
@@ -29854,13 +30282,13 @@ async function readBoundedJson2(path5) {
|
|
|
29854
30282
|
await descriptor.close();
|
|
29855
30283
|
}
|
|
29856
30284
|
}
|
|
29857
|
-
function accountRecords2(text2,
|
|
30285
|
+
function accountRecords2(text2, fields2) {
|
|
29858
30286
|
const records = [];
|
|
29859
30287
|
for (const line of text2.split("\n")) {
|
|
29860
30288
|
if (line.trim() === "" || line.startsWith("#"))
|
|
29861
30289
|
continue;
|
|
29862
30290
|
const parts = line.split(":");
|
|
29863
|
-
if (parts.length !==
|
|
30291
|
+
if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
|
|
29864
30292
|
return void 0;
|
|
29865
30293
|
records.push(parts);
|
|
29866
30294
|
}
|
|
@@ -29958,7 +30386,7 @@ async function writeStateAtomic2(path5, state, ancestorOptions = {}) {
|
|
|
29958
30386
|
}
|
|
29959
30387
|
if (windowsPrivateFiles2)
|
|
29960
30388
|
return writePrivateAtomic2(path5, bytes);
|
|
29961
|
-
const temporary =
|
|
30389
|
+
const temporary = join13(parent, `.${basename4(path5)}.${process.pid}.${randomUUID16()}.tmp`);
|
|
29962
30390
|
let descriptor;
|
|
29963
30391
|
let created = false;
|
|
29964
30392
|
try {
|
|
@@ -30182,6 +30610,18 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
30182
30610
|
retryCode: refusal3.code
|
|
30183
30611
|
};
|
|
30184
30612
|
}
|
|
30613
|
+
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
|
|
30614
|
+
await lock.assertOwned();
|
|
30615
|
+
await unlink9(this.#paths.statePath).catch((cause) => {
|
|
30616
|
+
if (cause.code !== "ENOENT")
|
|
30617
|
+
throw cause;
|
|
30618
|
+
});
|
|
30619
|
+
return {
|
|
30620
|
+
state: "unavailable",
|
|
30621
|
+
proposedName: state.proposedName,
|
|
30622
|
+
code: refusal3.code
|
|
30623
|
+
};
|
|
30624
|
+
}
|
|
30185
30625
|
return this.#block(state, refusal3.code);
|
|
30186
30626
|
}
|
|
30187
30627
|
}
|
|
@@ -30320,7 +30760,7 @@ var ByteTail = class {
|
|
|
30320
30760
|
};
|
|
30321
30761
|
var defaultCommandRunner = {
|
|
30322
30762
|
run(file, args, options = {}) {
|
|
30323
|
-
return new Promise((
|
|
30763
|
+
return new Promise((resolve20) => {
|
|
30324
30764
|
const started = performance.now();
|
|
30325
30765
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
30326
30766
|
const stderr = new ByteTail();
|
|
@@ -30338,7 +30778,7 @@ var defaultCommandRunner = {
|
|
|
30338
30778
|
stdio: ["ignore", "pipe", "pipe"]
|
|
30339
30779
|
});
|
|
30340
30780
|
} catch {
|
|
30341
|
-
|
|
30781
|
+
resolve20({
|
|
30342
30782
|
exitCode: 1,
|
|
30343
30783
|
stdout: "",
|
|
30344
30784
|
stderr: "",
|
|
@@ -30373,7 +30813,7 @@ var defaultCommandRunner = {
|
|
|
30373
30813
|
settled = true;
|
|
30374
30814
|
if (timer)
|
|
30375
30815
|
clearTimeout(timer);
|
|
30376
|
-
|
|
30816
|
+
resolve20({
|
|
30377
30817
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
30378
30818
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
30379
30819
|
stderr: stderr.toString(),
|
|
@@ -30459,8 +30899,8 @@ function recordSetupEnrollment(failure2, enrollment) {
|
|
|
30459
30899
|
// src/common-auth-embedded/setup/detect.js
|
|
30460
30900
|
import { accessSync, constants as constants3, existsSync as existsSync5, readFileSync as readFileSync4, realpathSync, statSync as statSync5 } from "node:fs";
|
|
30461
30901
|
import { mkdtemp, rm as rm6 } from "node:fs/promises";
|
|
30462
|
-
import { tmpdir } from "node:os";
|
|
30463
|
-
import { join as
|
|
30902
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
30903
|
+
import { join as join14 } from "node:path";
|
|
30464
30904
|
import { parse } from "jsonc-parser";
|
|
30465
30905
|
|
|
30466
30906
|
// src/common-auth-embedded/setup/paths.js
|
|
@@ -30631,7 +31071,7 @@ async function detectHosts(plugin, io = {}) {
|
|
|
30631
31071
|
return null;
|
|
30632
31072
|
let root;
|
|
30633
31073
|
try {
|
|
30634
|
-
root = await mkdtemp(
|
|
31074
|
+
root = await mkdtemp(join14(tmpdir3(), "common-auth-setup-version-"));
|
|
30635
31075
|
const probeEnv = {
|
|
30636
31076
|
...env3,
|
|
30637
31077
|
HOME: root,
|
|
@@ -30700,6 +31140,8 @@ import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexki
|
|
|
30700
31140
|
var WINDOWS_CIM_TIMEOUT_MS = 45e3;
|
|
30701
31141
|
var HOSTS = /* @__PURE__ */ new Set(["opencode", "litecode", "opencode2", "pi"]);
|
|
30702
31142
|
var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun"]);
|
|
31143
|
+
var WINDOWS_FENCE_FILTER = [...HOSTS, ...RUNTIMES].map((name) => `Name LIKE '${name}%'`).join(" OR ");
|
|
31144
|
+
var WINDOWS_FENCE_QUERY = `$ErrorActionPreference = 'Stop'; $rows = @(Get-CimInstance Win32_Process -Filter "${WINDOWS_FENCE_FILTER}" | Select-Object Name,ProcessId,CommandLine); ConvertTo-Json -Compress -Depth 3 -InputObject @{ complete = $true; processes = $rows }`;
|
|
30703
31145
|
var PI_SCRIPT_PATTERN = /(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;
|
|
30704
31146
|
function commandArguments(command) {
|
|
30705
31147
|
return [...command.matchAll(/"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? "");
|
|
@@ -30802,6 +31244,7 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
|
|
|
30802
31244
|
};
|
|
30803
31245
|
async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
30804
31246
|
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
31247
|
+
const selfPid = options.selfPid ?? process.pid;
|
|
30805
31248
|
let inspection = {
|
|
30806
31249
|
step: windows2 ? "tasklist" : "ps",
|
|
30807
31250
|
exitCode: null,
|
|
@@ -30838,6 +31281,29 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
30838
31281
|
}
|
|
30839
31282
|
};
|
|
30840
31283
|
try {
|
|
31284
|
+
if (windows2 && options.hostImagesOnly) {
|
|
31285
|
+
const details = await inspect("CIM", "powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", WINDOWS_FENCE_QUERY], WINDOWS_CIM_TIMEOUT_MS);
|
|
31286
|
+
if (details.exitCode !== 0)
|
|
31287
|
+
throw new ProcessInspectionError(inspection);
|
|
31288
|
+
const value = JSON.parse(details.stdout);
|
|
31289
|
+
if (!value || typeof value !== "object" || !("complete" in value) || value.complete !== true || !("processes" in value))
|
|
31290
|
+
throw new ProcessInspectionError(inspection);
|
|
31291
|
+
const listed = value.processes;
|
|
31292
|
+
const rows = listed === null ? [] : Array.isArray(listed) ? listed : [listed];
|
|
31293
|
+
const processes2 = [];
|
|
31294
|
+
for (const row of rows) {
|
|
31295
|
+
if (!row || typeof row !== "object" || !("Name" in row) || typeof row.Name !== "string" || !("ProcessId" in row) || !Number.isSafeInteger(row.ProcessId) || row.ProcessId < 0 || !("CommandLine" in row))
|
|
31296
|
+
throw new ProcessInspectionError(inspection);
|
|
31297
|
+
const pid = row.ProcessId;
|
|
31298
|
+
if (!/^(?:node|bun)\.exe$/i.test(row.Name))
|
|
31299
|
+
processes2.push({ pid, command: row.Name });
|
|
31300
|
+
else if (typeof row.CommandLine === "string")
|
|
31301
|
+
processes2.push({ pid, command: row.CommandLine });
|
|
31302
|
+
else if (pid !== selfPid)
|
|
31303
|
+
throw new ProcessInspectionError(inspection);
|
|
31304
|
+
}
|
|
31305
|
+
return processes2;
|
|
31306
|
+
}
|
|
30841
31307
|
const result = await inspect(windows2 ? "tasklist" : "ps", windows2 ? "tasklist.exe" : "ps", windows2 ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
|
|
30842
31308
|
if (result.exitCode !== 0)
|
|
30843
31309
|
throw new ProcessInspectionError(inspection);
|
|
@@ -30870,7 +31336,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
30870
31336
|
}
|
|
30871
31337
|
if (!processes.length)
|
|
30872
31338
|
throw new ProcessInspectionError(inspection);
|
|
30873
|
-
const runtimes = processes.filter((entry) => entry.pid !==
|
|
31339
|
+
const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
|
|
30874
31340
|
if (windows2 && runtimes.length && options.inspectRuntimes !== false) {
|
|
30875
31341
|
const details = await inspect("CIM", "powershell.exe", [
|
|
30876
31342
|
"-NoProfile",
|
|
@@ -30903,10 +31369,15 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
30903
31369
|
}
|
|
30904
31370
|
}
|
|
30905
31371
|
function createProcessFence(runner = defaultCommandRunner, options = {}) {
|
|
30906
|
-
const
|
|
31372
|
+
const selfPid = options.selfPid ?? process.pid;
|
|
31373
|
+
const isHost = (entry) => entry.pid !== selfPid && hostName(entry.command) !== null;
|
|
30907
31374
|
return {
|
|
30908
31375
|
async listRunningHosts(env3) {
|
|
30909
|
-
return (await listSetupProcesses(runner, {
|
|
31376
|
+
return (await listSetupProcesses(runner, {
|
|
31377
|
+
...options,
|
|
31378
|
+
env: env3,
|
|
31379
|
+
hostImagesOnly: true
|
|
31380
|
+
})).filter(isHost);
|
|
30910
31381
|
},
|
|
30911
31382
|
async previewRunningHosts(env3) {
|
|
30912
31383
|
const processes = await listSetupProcesses(runner, {
|
|
@@ -30917,7 +31388,7 @@ function createProcessFence(runner = defaultCommandRunner, options = {}) {
|
|
|
30917
31388
|
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
30918
31389
|
return {
|
|
30919
31390
|
hosts: processes.filter(isHost),
|
|
30920
|
-
uncheckedRuntimes: windows2 ? processes.filter((entry) => entry.pid !==
|
|
31391
|
+
uncheckedRuntimes: windows2 ? processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
|
|
30921
31392
|
};
|
|
30922
31393
|
}
|
|
30923
31394
|
};
|
|
@@ -30930,8 +31401,27 @@ async function assertHostsStopped(fence, env3) {
|
|
|
30930
31401
|
|
|
30931
31402
|
// src/common-auth-embedded/setup/enroll.js
|
|
30932
31403
|
var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
|
|
31404
|
+
var UNSUPPORTED_VAULT_MESSAGE = "This Claustrum vault does not support connecting plugins yet, so setup cannot connect to it. Run setup without --claustrum to use local accounts.";
|
|
31405
|
+
var ENROLLMENT_WAIT_MS = 3e5;
|
|
31406
|
+
var APPROVAL_POLL_MS = 1e3;
|
|
31407
|
+
var PROPOSE_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
31408
|
+
function safeCode(code2) {
|
|
31409
|
+
return code2 && /^[a-z][a-z0-9_]{0,63}$/.test(code2) ? code2 : "unknown";
|
|
31410
|
+
}
|
|
30933
31411
|
var HostNotEnrolledError = class extends Error {
|
|
31412
|
+
reason;
|
|
31413
|
+
lastErrorCode;
|
|
31414
|
+
constructor(message, details) {
|
|
31415
|
+
super(message);
|
|
31416
|
+
this.name = "HostNotEnrolledError";
|
|
31417
|
+
this.reason = details.reason;
|
|
31418
|
+
if (details.lastErrorCode !== void 0)
|
|
31419
|
+
this.lastErrorCode = safeCode(details.lastErrorCode);
|
|
31420
|
+
}
|
|
30934
31421
|
};
|
|
31422
|
+
function approveCommand(requestId, name) {
|
|
31423
|
+
return `ck auth enroll approve --request-id ${requestId} --name ${name}`;
|
|
31424
|
+
}
|
|
30935
31425
|
async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
30936
31426
|
const { name, paths: input2 } = plugin.vault.hosts[host];
|
|
30937
31427
|
const paths = hostEnrollmentPaths2(input2);
|
|
@@ -30940,54 +31430,94 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
30940
31430
|
connectionFile: plugin.vault.connectionFile,
|
|
30941
31431
|
handshakeTimeoutMs: 2e3
|
|
30942
31432
|
}).catch(() => {
|
|
30943
|
-
throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.");
|
|
31433
|
+
throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.", { reason: "connection-failed" });
|
|
30944
31434
|
});
|
|
31435
|
+
const now = io.now ?? (() => performance.now());
|
|
31436
|
+
const wait2 = io.wait ?? delay;
|
|
30945
31437
|
try {
|
|
30946
31438
|
const manager = new ClaustrumEnrollmentManager2({
|
|
30947
31439
|
proposedName: name,
|
|
30948
31440
|
paths,
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
|
|
30953
|
-
|
|
30954
|
-
enrollPoll: async (input3) => {
|
|
30955
|
-
await fence();
|
|
30956
|
-
return client.enrollPoll(input3);
|
|
30957
|
-
}
|
|
30958
|
-
},
|
|
31441
|
+
// Each tick of the wait below checks the fence once, just before
|
|
31442
|
+
// reconcile proposes or polls. Checking again inside every vault call
|
|
31443
|
+
// doubled the process listings per tick, and on Windows each listing
|
|
31444
|
+
// starts PowerShell.
|
|
31445
|
+
client,
|
|
30959
31446
|
writeTokenFile: async (path5, file) => {
|
|
30960
31447
|
await fence();
|
|
30961
31448
|
await writeEnrollmentTokenFile3(path5, file);
|
|
30962
31449
|
}
|
|
30963
31450
|
});
|
|
31451
|
+
printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
|
|
31452
|
+
const deadline = now() + ENROLLMENT_WAIT_MS;
|
|
30964
31453
|
let printedRequest;
|
|
30965
|
-
|
|
31454
|
+
let lastCode;
|
|
31455
|
+
let reportedCode;
|
|
31456
|
+
let failedProposals = 0;
|
|
31457
|
+
for (; ; ) {
|
|
30966
31458
|
await fence();
|
|
30967
31459
|
const status = await manager.reconcile();
|
|
30968
31460
|
if (status.state === "approved") {
|
|
30969
31461
|
printLine2(terminal, `Connected ${host} to Claustrum.`);
|
|
30970
31462
|
return;
|
|
30971
31463
|
}
|
|
31464
|
+
if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
|
|
31465
|
+
throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
|
|
31466
|
+
reason: "unsupported-vault",
|
|
31467
|
+
lastErrorCode: status.code
|
|
31468
|
+
});
|
|
30972
31469
|
if (status.state !== "pending" && status.state !== "busy")
|
|
30973
|
-
throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup."
|
|
30974
|
-
|
|
30975
|
-
|
|
30976
|
-
|
|
30977
|
-
|
|
30978
|
-
|
|
30979
|
-
|
|
30980
|
-
|
|
30981
|
-
|
|
30982
|
-
|
|
30983
|
-
|
|
30984
|
-
|
|
31470
|
+
throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.", {
|
|
31471
|
+
reason: "refused",
|
|
31472
|
+
..."code" in status && { lastErrorCode: status.code }
|
|
31473
|
+
});
|
|
31474
|
+
let pause = APPROVAL_POLL_MS;
|
|
31475
|
+
if (status.state === "busy")
|
|
31476
|
+
lastCode = "busy";
|
|
31477
|
+
else if (status.retryCode)
|
|
31478
|
+
lastCode = status.retryCode;
|
|
31479
|
+
if (status.state === "pending" && status.requestId) {
|
|
31480
|
+
failedProposals = 0;
|
|
31481
|
+
if (status.requestId !== printedRequest) {
|
|
31482
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
|
|
31483
|
+
throw new HostNotEnrolledError("Invalid enrollment request id.", {
|
|
31484
|
+
reason: "invalid-request"
|
|
31485
|
+
});
|
|
31486
|
+
printedRequest = status.requestId;
|
|
31487
|
+
printLine2(terminal, "Waiting for approval. In another terminal, run:");
|
|
31488
|
+
printLine2(terminal, ` ${approveCommand(status.requestId, name)}`);
|
|
31489
|
+
printLine2(terminal, `Enrollment files: ${paths.statePath}, ${paths.tokenPath}`);
|
|
31490
|
+
}
|
|
31491
|
+
} else if (status.state === "pending" && status.retryCode) {
|
|
31492
|
+
pause = PROPOSE_BACKOFF_MS[Math.min(failedProposals, PROPOSE_BACKOFF_MS.length - 1)] ?? APPROVAL_POLL_MS;
|
|
31493
|
+
failedProposals++;
|
|
31494
|
+
const code3 = safeCode(status.retryCode);
|
|
31495
|
+
if (code3 !== reportedCode) {
|
|
31496
|
+
reportedCode = code3;
|
|
31497
|
+
printLine2(terminal, `The vault has not created the request yet (${code3}); retrying.`);
|
|
31498
|
+
}
|
|
31499
|
+
}
|
|
31500
|
+
const remaining = deadline - now();
|
|
31501
|
+
if (remaining <= 0)
|
|
31502
|
+
break;
|
|
31503
|
+
await wait2(Math.min(pause, remaining));
|
|
31504
|
+
}
|
|
31505
|
+
if (printedRequest)
|
|
31506
|
+
throw new HostNotEnrolledError(`Claustrum approval is still pending. In another terminal, run: ${approveCommand(printedRequest, name)} and then rerun setup.`, {
|
|
31507
|
+
reason: "approval-pending",
|
|
31508
|
+
...lastCode !== void 0 && { lastErrorCode: lastCode }
|
|
31509
|
+
});
|
|
31510
|
+
const code2 = safeCode(lastCode);
|
|
31511
|
+
throw new HostNotEnrolledError(`The vault never created the enrollment request (last error: ${code2}). Check that ck is running, then rerun setup.`, { reason: "request-not-created", lastErrorCode: code2 });
|
|
30985
31512
|
} catch (error) {
|
|
30986
|
-
if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError
|
|
31513
|
+
if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError || // Built above from fixed text and vetted values only.
|
|
31514
|
+
error instanceof HostNotEnrolledError)
|
|
30987
31515
|
throw error;
|
|
30988
|
-
|
|
30989
|
-
|
|
30990
|
-
|
|
31516
|
+
const code2 = error?.code;
|
|
31517
|
+
throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE, {
|
|
31518
|
+
reason: "incomplete",
|
|
31519
|
+
...typeof code2 === "string" && { lastErrorCode: code2 }
|
|
31520
|
+
});
|
|
30991
31521
|
} finally {
|
|
30992
31522
|
client.close();
|
|
30993
31523
|
}
|
|
@@ -31025,7 +31555,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
31025
31555
|
// src/common-auth-embedded/setup/config-write.js
|
|
31026
31556
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
31027
31557
|
import { mkdir as mkdir13, open as open11, rename as rename10, stat as stat9, unlink as unlink10 } from "node:fs/promises";
|
|
31028
|
-
import { basename as basename5, dirname as dirname18, join as
|
|
31558
|
+
import { basename as basename5, dirname as dirname18, join as join15 } from "node:path";
|
|
31029
31559
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
31030
31560
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
31031
31561
|
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
@@ -31040,7 +31570,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
31040
31570
|
throw error;
|
|
31041
31571
|
}
|
|
31042
31572
|
}
|
|
31043
|
-
const stage =
|
|
31573
|
+
const stage = join15(parent, `.${basename5(file)}.${(options.stageName ?? randomUUID17)()}.tmp`);
|
|
31044
31574
|
let created = false;
|
|
31045
31575
|
try {
|
|
31046
31576
|
const handle = await open11(stage, "wx", mode ?? 438);
|
|
@@ -31407,11 +31937,11 @@ ${write.content}`);
|
|
|
31407
31937
|
// src/plugin/vault-activation.ts
|
|
31408
31938
|
import { readFile as readFile11 } from "node:fs/promises";
|
|
31409
31939
|
import { homedir as homedir6 } from "node:os";
|
|
31410
|
-
import { join as
|
|
31940
|
+
import { join as join16 } from "node:path";
|
|
31411
31941
|
var V1_VAULT_ACTIVATION_LABEL = "Activate approved Antigravity vault";
|
|
31412
31942
|
function nativeOpenCodeAuthPath(env3 = process.env, home = homedir6()) {
|
|
31413
|
-
return
|
|
31414
|
-
env3.XDG_DATA_HOME ||
|
|
31943
|
+
return join16(
|
|
31944
|
+
env3.XDG_DATA_HOME || join16(home, ".local", "share"),
|
|
31415
31945
|
"opencode",
|
|
31416
31946
|
"auth.json"
|
|
31417
31947
|
);
|
|
@@ -31458,7 +31988,7 @@ function createV1VaultActivationMethod(input2) {
|
|
|
31458
31988
|
|
|
31459
31989
|
// src/plugin/vault-custody.ts
|
|
31460
31990
|
import { chmod as chmod4, mkdir as mkdir14, readFile as readFile12 } from "node:fs/promises";
|
|
31461
|
-
import { dirname as dirname19, join as
|
|
31991
|
+
import { dirname as dirname19, join as join17 } from "node:path";
|
|
31462
31992
|
|
|
31463
31993
|
// src/plugin/shared/vault-request-credentials.ts
|
|
31464
31994
|
function vaultAccountRows(routes) {
|
|
@@ -31661,7 +32191,7 @@ function createVaultSelectionState(options) {
|
|
|
31661
32191
|
report(error);
|
|
31662
32192
|
}
|
|
31663
32193
|
};
|
|
31664
|
-
const
|
|
32194
|
+
const flush2 = () => {
|
|
31665
32195
|
writing = writing.then(async () => {
|
|
31666
32196
|
for (const row of [...changed]) await writeRow(row);
|
|
31667
32197
|
});
|
|
@@ -31677,7 +32207,7 @@ function createVaultSelectionState(options) {
|
|
|
31677
32207
|
accessVerdict: mark,
|
|
31678
32208
|
fingerprint: mark,
|
|
31679
32209
|
requestSave: () => {
|
|
31680
|
-
void
|
|
32210
|
+
void flush2();
|
|
31681
32211
|
}
|
|
31682
32212
|
},
|
|
31683
32213
|
admitted(row, attribution) {
|
|
@@ -31700,7 +32230,7 @@ function createVaultSelectionState(options) {
|
|
|
31700
32230
|
}
|
|
31701
32231
|
}
|
|
31702
32232
|
},
|
|
31703
|
-
flush,
|
|
32233
|
+
flush: flush2,
|
|
31704
32234
|
recordQuota(attribution, quota, signal) {
|
|
31705
32235
|
return options.source.commitState(
|
|
31706
32236
|
attribution,
|
|
@@ -31919,12 +32449,12 @@ var OPENCODE_VAULT_HOST = "opencode";
|
|
|
31919
32449
|
var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
|
|
31920
32450
|
var OPENCODE_VAULT_DIR_NAME = "antigravity-auth-vault";
|
|
31921
32451
|
function openCodeVaultPaths(accountFile) {
|
|
31922
|
-
const dir =
|
|
32452
|
+
const dir = join17(dirname19(accountFile), OPENCODE_VAULT_DIR_NAME);
|
|
31923
32453
|
return {
|
|
31924
32454
|
dir,
|
|
31925
|
-
modeFile:
|
|
31926
|
-
rosterFile:
|
|
31927
|
-
stateFile:
|
|
32455
|
+
modeFile: join17(dir, "opencode-mode.json"),
|
|
32456
|
+
rosterFile: join17(dir, "opencode-roster.json"),
|
|
32457
|
+
stateFile: join17(dir, "opencode-state.json")
|
|
31928
32458
|
};
|
|
31929
32459
|
}
|
|
31930
32460
|
async function ensureVaultDir(dir) {
|
|
@@ -32099,11 +32629,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
32099
32629
|
].join("\n");
|
|
32100
32630
|
const waitForApproval = async () => {
|
|
32101
32631
|
while (!closed) {
|
|
32102
|
-
await new Promise((
|
|
32632
|
+
await new Promise((resolve20) => {
|
|
32103
32633
|
const done = () => {
|
|
32104
32634
|
clearTimeout(timer);
|
|
32105
32635
|
cancelWait = void 0;
|
|
32106
|
-
|
|
32636
|
+
resolve20();
|
|
32107
32637
|
};
|
|
32108
32638
|
const timer = setTimeout(done, 2e3);
|
|
32109
32639
|
timer.unref?.();
|
|
@@ -32272,6 +32802,9 @@ async function refusalOr(step) {
|
|
|
32272
32802
|
}
|
|
32273
32803
|
return "Done. Start a new request to use the change.";
|
|
32274
32804
|
}
|
|
32805
|
+
function isUnsupportedEnrollment(status) {
|
|
32806
|
+
return status.state === "unavailable" && status.code === UNSUPPORTED_VAULT_CODE;
|
|
32807
|
+
}
|
|
32275
32808
|
function describeEnrollment(status) {
|
|
32276
32809
|
switch (status.state) {
|
|
32277
32810
|
case "idle":
|
|
@@ -32285,7 +32818,7 @@ function describeEnrollment(status) {
|
|
|
32285
32818
|
case "blocked":
|
|
32286
32819
|
return `blocked (${status.code})`;
|
|
32287
32820
|
case "unavailable":
|
|
32288
|
-
return `vault unavailable (${status.code})`;
|
|
32821
|
+
return isUnsupportedEnrollment(status) ? "this vault can't connect plugins yet" : `vault unavailable (${status.code})`;
|
|
32289
32822
|
case "busy":
|
|
32290
32823
|
return "another setup step is running";
|
|
32291
32824
|
}
|
|
@@ -32352,10 +32885,15 @@ function enrollmentGuidance(status) {
|
|
|
32352
32885
|
return [
|
|
32353
32886
|
"Resolve the enrollment problem with the vault operator, then request vault access again."
|
|
32354
32887
|
];
|
|
32355
|
-
if (status.state === "unavailable")
|
|
32888
|
+
if (status.state === "unavailable") {
|
|
32889
|
+
if (isUnsupportedEnrollment(status))
|
|
32890
|
+
return [
|
|
32891
|
+
"This Claustrum vault is too old to connect plugins. Ask the vault operator to update Claustrum, or keep using your local accounts."
|
|
32892
|
+
];
|
|
32356
32893
|
return [
|
|
32357
32894
|
"Check that the vault is running and its connection file is available, then request vault access again."
|
|
32358
32895
|
];
|
|
32896
|
+
}
|
|
32359
32897
|
if (status.state === "busy")
|
|
32360
32898
|
return [
|
|
32361
32899
|
"Another enrollment operation is running. OpenCode will keep checking its outcome in the background."
|
|
@@ -32388,7 +32926,7 @@ function statusLines(status) {
|
|
|
32388
32926
|
// src/setup.ts
|
|
32389
32927
|
var PI_PLACEHOLDER_KEY = "antigravity-vault-custody";
|
|
32390
32928
|
function nativeAuthPath(host, context) {
|
|
32391
|
-
return host === "opencode" ? nativeOpenCodeAuthPath() :
|
|
32929
|
+
return host === "opencode" ? nativeOpenCodeAuthPath() : join18(context.piAgentDir, "auth.json");
|
|
32392
32930
|
}
|
|
32393
32931
|
function provider(host) {
|
|
32394
32932
|
return host === "opencode" ? OPENCODE_VAULT_PROVIDER : ANTIGRAVITY_PROVIDER_ID;
|
|
@@ -32444,7 +32982,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
32444
32982
|
beforeRename: async () => {
|
|
32445
32983
|
await assertSetupHostsStopped();
|
|
32446
32984
|
const claustrum = await loadCommonAuthClaustrum();
|
|
32447
|
-
const stateDir = host === "opencode" ? openCodeVaultPaths(
|
|
32985
|
+
const stateDir = host === "opencode" ? openCodeVaultPaths(resolve13(getStoragePath())).dir : getPiAntigravityVaultDir();
|
|
32448
32986
|
if (await claustrum.enrollmentAuthority(
|
|
32449
32987
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
32450
32988
|
`antigravity-auth-${host}`
|
|
@@ -32474,7 +33012,7 @@ async function persistPiSetupLogin(result, context) {
|
|
|
32474
33012
|
}
|
|
32475
33013
|
async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
32476
33014
|
const claustrum = await loadCommonAuthClaustrum();
|
|
32477
|
-
const opencode = openCodeVaultPaths(
|
|
33015
|
+
const opencode = openCodeVaultPaths(resolve13(getStoragePath()));
|
|
32478
33016
|
const piDir = getPiAntigravityVaultDir();
|
|
32479
33017
|
const hosts = {
|
|
32480
33018
|
opencode: {
|
|
@@ -32493,7 +33031,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
32493
33031
|
const assertLocal = async (host, context) => {
|
|
32494
33032
|
if (host === "opencode")
|
|
32495
33033
|
return assertLocalOpenCodeLogin(
|
|
32496
|
-
|
|
33034
|
+
resolve13(getStoragePath()),
|
|
32497
33035
|
context.opencodeGeneration
|
|
32498
33036
|
);
|
|
32499
33037
|
if (await authority(host) !== "local")
|
|
@@ -32509,7 +33047,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
32509
33047
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
32510
33048
|
if ((await openPiSlot2({
|
|
32511
33049
|
authPath: nativeAuthPath(host, context),
|
|
32512
|
-
stashPath:
|
|
33050
|
+
stashPath: join18(piDir, "google-login-stash.json"),
|
|
32513
33051
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
32514
33052
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
32515
33053
|
}).inspect()).slot === "placeholder")
|
|
@@ -32546,7 +33084,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
32546
33084
|
const { openPiSlot: openPiSlot2 } = await loadCommonAuthPiSlot();
|
|
32547
33085
|
const inspection = await openPiSlot2({
|
|
32548
33086
|
authPath: nativeAuthPath("pi", context),
|
|
32549
|
-
stashPath:
|
|
33087
|
+
stashPath: join18(piDir, "google-login-stash.json"),
|
|
32550
33088
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
32551
33089
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
32552
33090
|
}).inspect();
|
|
@@ -32665,7 +33203,7 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
32665
33203
|
await assertSetupHostsStopped();
|
|
32666
33204
|
await openPiSlot2({
|
|
32667
33205
|
authPath: nativeAuthPath(host, context),
|
|
32668
|
-
stashPath:
|
|
33206
|
+
stashPath: join18(piDir, "google-login-stash.json"),
|
|
32669
33207
|
provider: ANTIGRAVITY_PROVIDER_ID,
|
|
32670
33208
|
placeholderKey: PI_PLACEHOLDER_KEY
|
|
32671
33209
|
}).enterVault();
|
|
@@ -33025,7 +33563,7 @@ function createDefaultCliDependencies() {
|
|
|
33025
33563
|
throw new Error(
|
|
33026
33564
|
"Pi setup requires its detected native agent directory."
|
|
33027
33565
|
);
|
|
33028
|
-
const legacyPath =
|
|
33566
|
+
const legacyPath = resolve14(getStoragePath());
|
|
33029
33567
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(legacyPath, context?.opencodeGeneration);
|
|
33030
33568
|
try {
|
|
33031
33569
|
return await performOAuthLogin(request, {
|
|
@@ -33185,7 +33723,7 @@ async function readAccountStore(legacyPath) {
|
|
|
33185
33723
|
function createDefaultAccountStoreOperations() {
|
|
33186
33724
|
const offline = { processesStopped: true };
|
|
33187
33725
|
return {
|
|
33188
|
-
legacyPath: () =>
|
|
33726
|
+
legacyPath: () => resolve14(getStoragePath()),
|
|
33189
33727
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
33190
33728
|
legacyPath,
|
|
33191
33729
|
offline,
|
|
@@ -33685,17 +34223,17 @@ function isTuiConnected(sessionId) {
|
|
|
33685
34223
|
|
|
33686
34224
|
// src/rpc/rpc-dir.ts
|
|
33687
34225
|
import { createHash as createHash11 } from "node:crypto";
|
|
33688
|
-
import { homedir as homedir8, tmpdir as
|
|
33689
|
-
import { isAbsolute as isAbsolute4, join as
|
|
34226
|
+
import { homedir as homedir8, tmpdir as tmpdir4 } from "node:os";
|
|
34227
|
+
import { isAbsolute as isAbsolute4, join as join22, resolve as resolve15 } from "node:path";
|
|
33690
34228
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
33691
34229
|
function getRpcDir(projectDirectory) {
|
|
33692
34230
|
const override = process.env[RPC_DIR_ENV]?.trim();
|
|
33693
34231
|
if (override) {
|
|
33694
|
-
return isAbsolute4(override) ? override :
|
|
34232
|
+
return isAbsolute4(override) ? override : resolve15(projectDirectory, override);
|
|
33695
34233
|
}
|
|
33696
|
-
const projectHash = createHash11("sha256").update(
|
|
33697
|
-
const stateHome = process.env.XDG_STATE_HOME ??
|
|
33698
|
-
return
|
|
34234
|
+
const projectHash = createHash11("sha256").update(resolve15(projectDirectory)).digest("hex").slice(0, 16);
|
|
34235
|
+
const stateHome = process.env.XDG_STATE_HOME ?? join22(homedir8(), ".local", "state");
|
|
34236
|
+
return join22(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
33699
34237
|
}
|
|
33700
34238
|
|
|
33701
34239
|
// src/common-auth-embedded/rpc/notifications.js
|
|
@@ -33706,7 +34244,7 @@ function isSessionId(value) {
|
|
|
33706
34244
|
// src/common-auth-embedded/rpc/port-file.js
|
|
33707
34245
|
import { createHash as createHash12, randomUUID as randomUUID18 } from "node:crypto";
|
|
33708
34246
|
import { chmod as chmod5, mkdir as mkdir15, open as open12, readdir, rename as rename11, rmdir as rmdir2, stat as stat10, unlink as unlink11 } from "node:fs/promises";
|
|
33709
|
-
import { join as
|
|
34247
|
+
import { join as join23, resolve as resolve16 } from "node:path";
|
|
33710
34248
|
function isProbeablePid(pid) {
|
|
33711
34249
|
return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0;
|
|
33712
34250
|
}
|
|
@@ -33737,7 +34275,7 @@ async function removeCorruptPortFile(portFile, log16) {
|
|
|
33737
34275
|
}
|
|
33738
34276
|
async function writePortFile(dir, entry, options = {}) {
|
|
33739
34277
|
const writeOnce = async () => {
|
|
33740
|
-
const target =
|
|
34278
|
+
const target = join23(dir, `port-${entry.pid}.json`);
|
|
33741
34279
|
if (windowsPrivateFiles2) {
|
|
33742
34280
|
await ensurePrivateDirectory3(dir, options.secureDir ?? false);
|
|
33743
34281
|
await options.beforeWrite?.();
|
|
@@ -33793,12 +34331,12 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
33793
34331
|
return;
|
|
33794
34332
|
throw error;
|
|
33795
34333
|
}
|
|
33796
|
-
const active2 =
|
|
34334
|
+
const active2 = resolve16(activeDir);
|
|
33797
34335
|
for (const projectDir of projectDirs) {
|
|
33798
34336
|
if (!projectDir.isDirectory() || !isManagedDir(projectDir.name)) {
|
|
33799
34337
|
continue;
|
|
33800
34338
|
}
|
|
33801
|
-
const dir =
|
|
34339
|
+
const dir = join23(root, projectDir.name);
|
|
33802
34340
|
let names;
|
|
33803
34341
|
try {
|
|
33804
34342
|
names = await readdir(dir);
|
|
@@ -33810,7 +34348,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
33810
34348
|
for (const name of names) {
|
|
33811
34349
|
if (!name.startsWith("port-") || !name.endsWith(".json"))
|
|
33812
34350
|
continue;
|
|
33813
|
-
const portFile =
|
|
34351
|
+
const portFile = join23(dir, name);
|
|
33814
34352
|
let raw;
|
|
33815
34353
|
try {
|
|
33816
34354
|
raw = await readPrivateText2(portFile);
|
|
@@ -33837,7 +34375,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
33837
34375
|
await unlink11(portFile).catch(() => {
|
|
33838
34376
|
});
|
|
33839
34377
|
}
|
|
33840
|
-
if (
|
|
34378
|
+
if (resolve16(dir) !== active2)
|
|
33841
34379
|
await rmdir2(dir).catch(() => {
|
|
33842
34380
|
});
|
|
33843
34381
|
}
|
|
@@ -33847,7 +34385,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
33847
34385
|
import { randomBytes as randomBytes6, timingSafeEqual } from "node:crypto";
|
|
33848
34386
|
import { unlink as unlink12 } from "node:fs/promises";
|
|
33849
34387
|
import { createServer as createServer2 } from "node:http";
|
|
33850
|
-
import { join as
|
|
34388
|
+
import { join as join24 } from "node:path";
|
|
33851
34389
|
var RpcRequestError = class extends Error {
|
|
33852
34390
|
status;
|
|
33853
34391
|
constructor(status, message) {
|
|
@@ -33867,7 +34405,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
33867
34405
|
}
|
|
33868
34406
|
};
|
|
33869
34407
|
function readBody(req) {
|
|
33870
|
-
return new Promise((
|
|
34408
|
+
return new Promise((resolve20, reject) => {
|
|
33871
34409
|
const tooLarge = (declaredOversize = false) => {
|
|
33872
34410
|
req.removeAllListeners("data");
|
|
33873
34411
|
req.on("data", () => {
|
|
@@ -33890,7 +34428,7 @@ function readBody(req) {
|
|
|
33890
34428
|
}
|
|
33891
34429
|
chunks.push(chunk);
|
|
33892
34430
|
});
|
|
33893
|
-
req.on("end", () =>
|
|
34431
|
+
req.on("end", () => resolve20(Buffer.concat(chunks).toString("utf8")));
|
|
33894
34432
|
req.on("error", reject);
|
|
33895
34433
|
});
|
|
33896
34434
|
}
|
|
@@ -34058,12 +34596,12 @@ async function startRpcServer(options) {
|
|
|
34058
34596
|
json(500, { error: "internal error" });
|
|
34059
34597
|
}
|
|
34060
34598
|
}
|
|
34061
|
-
const port = await new Promise((
|
|
34599
|
+
const port = await new Promise((resolve20, reject) => {
|
|
34062
34600
|
server.on("error", reject);
|
|
34063
34601
|
server.listen(0, "127.0.0.1", () => {
|
|
34064
34602
|
const addr = server.address();
|
|
34065
34603
|
if (addr && typeof addr === "object")
|
|
34066
|
-
|
|
34604
|
+
resolve20(addr.port);
|
|
34067
34605
|
else
|
|
34068
34606
|
reject(new Error("no port"));
|
|
34069
34607
|
});
|
|
@@ -34086,20 +34624,20 @@ async function startRpcServer(options) {
|
|
|
34086
34624
|
rpcPort: port
|
|
34087
34625
|
});
|
|
34088
34626
|
} catch (error) {
|
|
34089
|
-
await new Promise((
|
|
34627
|
+
await new Promise((resolve20) => server.close(() => resolve20()));
|
|
34090
34628
|
throw error;
|
|
34091
34629
|
}
|
|
34092
34630
|
return {
|
|
34093
34631
|
port,
|
|
34094
34632
|
token,
|
|
34095
34633
|
async stop() {
|
|
34096
|
-
await new Promise((
|
|
34634
|
+
await new Promise((resolve20) => {
|
|
34097
34635
|
server.closeAllConnections?.();
|
|
34098
|
-
server.close(() =>
|
|
34636
|
+
server.close(() => resolve20());
|
|
34099
34637
|
for (const socket of connections)
|
|
34100
34638
|
socket.destroy();
|
|
34101
34639
|
});
|
|
34102
|
-
const portFile =
|
|
34640
|
+
const portFile = join24(options.dir, `port-${process.pid}.json`);
|
|
34103
34641
|
const current = await readPrivateText2(portFile).then((raw) => JSON.parse(raw)).catch((error) => {
|
|
34104
34642
|
if (error instanceof PrivateFileError2 && error.code !== "ENOENT")
|
|
34105
34643
|
throw error;
|
|
@@ -34169,21 +34707,21 @@ function parsePending(value) {
|
|
|
34169
34707
|
function present4(value) {
|
|
34170
34708
|
return value === null ? void 0 : value;
|
|
34171
34709
|
}
|
|
34172
|
-
function accessBlockOf(
|
|
34173
|
-
if (
|
|
34174
|
-
if (
|
|
34175
|
-
const reason = present4(
|
|
34176
|
-
const at = present4(
|
|
34710
|
+
function accessBlockOf(fields2) {
|
|
34711
|
+
if (fields2 === void 0) return { kind: "none" };
|
|
34712
|
+
if (fields2.accountIneligible === true) {
|
|
34713
|
+
const reason = present4(fields2.accountIneligibleReason);
|
|
34714
|
+
const at = present4(fields2.accountIneligibleAt);
|
|
34177
34715
|
return {
|
|
34178
34716
|
kind: "ineligible",
|
|
34179
34717
|
...reason !== void 0 ? { reason } : {},
|
|
34180
34718
|
...at !== void 0 ? { at } : {}
|
|
34181
34719
|
};
|
|
34182
34720
|
}
|
|
34183
|
-
if (
|
|
34184
|
-
const reason = present4(
|
|
34185
|
-
const verificationUrl = present4(
|
|
34186
|
-
const at = present4(
|
|
34721
|
+
if (fields2.verificationRequired === true) {
|
|
34722
|
+
const reason = present4(fields2.verificationRequiredReason);
|
|
34723
|
+
const verificationUrl = present4(fields2.verificationUrl);
|
|
34724
|
+
const at = present4(fields2.verificationRequiredAt);
|
|
34187
34725
|
return {
|
|
34188
34726
|
kind: "verification-required",
|
|
34189
34727
|
...reason !== void 0 ? { reason } : {},
|
|
@@ -35161,7 +35699,7 @@ import { createInterface as createInterface2 } from "node:readline/promises";
|
|
|
35161
35699
|
// src/plugin/config/updater.ts
|
|
35162
35700
|
import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
35163
35701
|
import { homedir as homedir9 } from "node:os";
|
|
35164
|
-
import { dirname as dirname21, join as
|
|
35702
|
+
import { dirname as dirname21, join as join25 } from "node:path";
|
|
35165
35703
|
var PLUGIN_NAME = "@cortexkit/opencode-antigravity-auth@latest";
|
|
35166
35704
|
var SCHEMA_URL = "https://opencode.ai/config.json";
|
|
35167
35705
|
var OPENCODE_JSON_FILENAME = "opencode.json";
|
|
@@ -35173,13 +35711,13 @@ function stripJsonCommentsAndTrailingCommas(json) {
|
|
|
35173
35711
|
).replace(/,(\s*[}\]])/g, "$1");
|
|
35174
35712
|
}
|
|
35175
35713
|
function getOpencodeConfigDir() {
|
|
35176
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
35177
|
-
return
|
|
35714
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join25(homedir9(), ".config");
|
|
35715
|
+
return join25(xdgConfig2, "opencode");
|
|
35178
35716
|
}
|
|
35179
35717
|
function getOpencodeConfigPath() {
|
|
35180
35718
|
const configDir = getOpencodeConfigDir();
|
|
35181
|
-
const jsoncPath =
|
|
35182
|
-
const jsonPath =
|
|
35719
|
+
const jsoncPath = join25(configDir, OPENCODE_JSONC_FILENAME);
|
|
35720
|
+
const jsonPath = join25(configDir, OPENCODE_JSON_FILENAME);
|
|
35183
35721
|
if (existsSync8(jsoncPath)) {
|
|
35184
35722
|
return jsoncPath;
|
|
35185
35723
|
}
|
|
@@ -35438,7 +35976,7 @@ async function select3(items, options) {
|
|
|
35438
35976
|
}
|
|
35439
35977
|
renderedLines = linesWritten;
|
|
35440
35978
|
};
|
|
35441
|
-
return new Promise((
|
|
35979
|
+
return new Promise((resolve20) => {
|
|
35442
35980
|
const wasRaw = stdin.isRaw ?? false;
|
|
35443
35981
|
const cleanup2 = () => {
|
|
35444
35982
|
if (isCleanedUp) return;
|
|
@@ -35459,11 +35997,11 @@ async function select3(items, options) {
|
|
|
35459
35997
|
};
|
|
35460
35998
|
const onSignal = () => {
|
|
35461
35999
|
cleanup2();
|
|
35462
|
-
|
|
36000
|
+
resolve20(null);
|
|
35463
36001
|
};
|
|
35464
36002
|
const finishWithValue = (value) => {
|
|
35465
36003
|
cleanup2();
|
|
35466
|
-
|
|
36004
|
+
resolve20(value);
|
|
35467
36005
|
};
|
|
35468
36006
|
const findNextSelectable = (from, direction) => {
|
|
35469
36007
|
if (items.length === 0) return from;
|
|
@@ -35509,7 +36047,7 @@ async function select3(items, options) {
|
|
|
35509
36047
|
stdin.setRawMode(true);
|
|
35510
36048
|
} catch {
|
|
35511
36049
|
cleanup2();
|
|
35512
|
-
|
|
36050
|
+
resolve20(null);
|
|
35513
36051
|
return;
|
|
35514
36052
|
}
|
|
35515
36053
|
stdin.resume();
|
|
@@ -37900,21 +38438,21 @@ import {
|
|
|
37900
38438
|
unlinkSync as unlinkSync3,
|
|
37901
38439
|
writeFileSync as writeFileSync5
|
|
37902
38440
|
} from "node:fs";
|
|
37903
|
-
import { homedir as homedir10, tmpdir as
|
|
37904
|
-
import { dirname as dirname22, join as
|
|
38441
|
+
import { homedir as homedir10, tmpdir as tmpdir5 } from "node:os";
|
|
38442
|
+
import { dirname as dirname22, join as join26 } from "node:path";
|
|
37905
38443
|
function getConfigDir3() {
|
|
37906
38444
|
const platform = process.platform;
|
|
37907
38445
|
if (platform === "win32") {
|
|
37908
|
-
return
|
|
37909
|
-
process.env.APPDATA ||
|
|
38446
|
+
return join26(
|
|
38447
|
+
process.env.APPDATA || join26(homedir10(), "AppData", "Roaming"),
|
|
37910
38448
|
"opencode"
|
|
37911
38449
|
);
|
|
37912
38450
|
}
|
|
37913
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
37914
|
-
return
|
|
38451
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join26(homedir10(), ".config");
|
|
38452
|
+
return join26(xdgConfig2, "opencode");
|
|
37915
38453
|
}
|
|
37916
38454
|
function getSignatureCacheFilePath() {
|
|
37917
|
-
return
|
|
38455
|
+
return join26(getConfigDir3(), "antigravity-signature-cache.json");
|
|
37918
38456
|
}
|
|
37919
38457
|
var SignatureCache = class {
|
|
37920
38458
|
// In-memory cache: key -> entry with signature and optional thinking text
|
|
@@ -38197,8 +38735,8 @@ var SignatureCache = class {
|
|
|
38197
38735
|
last_write: now
|
|
38198
38736
|
}
|
|
38199
38737
|
};
|
|
38200
|
-
const tmpPath =
|
|
38201
|
-
|
|
38738
|
+
const tmpPath = join26(
|
|
38739
|
+
tmpdir5(),
|
|
38202
38740
|
`antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`
|
|
38203
38741
|
);
|
|
38204
38742
|
writeFileSync5(tmpPath, JSON.stringify(cacheData, null, 2), "utf-8");
|
|
@@ -38265,7 +38803,7 @@ var SignatureCache = class {
|
|
|
38265
38803
|
// src/plugin/config/loader.ts
|
|
38266
38804
|
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync3 } from "node:fs";
|
|
38267
38805
|
import { homedir as homedir11 } from "node:os";
|
|
38268
|
-
import { basename as basename6, dirname as dirname23, join as
|
|
38806
|
+
import { basename as basename6, dirname as dirname23, join as join27, resolve as resolve17 } from "node:path";
|
|
38269
38807
|
|
|
38270
38808
|
// src/plugin/config/schema.ts
|
|
38271
38809
|
import { z } from "zod";
|
|
@@ -38760,14 +39298,14 @@ function getConfigDir4() {
|
|
|
38760
39298
|
if (process.env.OPENCODE_CONFIG_DIR) {
|
|
38761
39299
|
return process.env.OPENCODE_CONFIG_DIR;
|
|
38762
39300
|
}
|
|
38763
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ||
|
|
38764
|
-
return
|
|
39301
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME || join27(homedir11(), ".config");
|
|
39302
|
+
return join27(xdgConfig2, "opencode");
|
|
38765
39303
|
}
|
|
38766
39304
|
function getUserConfigPath() {
|
|
38767
|
-
return
|
|
39305
|
+
return join27(getConfigDir4(), "antigravity.json");
|
|
38768
39306
|
}
|
|
38769
39307
|
function getProjectConfigPath(directory) {
|
|
38770
|
-
return
|
|
39308
|
+
return join27(directory, ".opencode", "antigravity.json");
|
|
38771
39309
|
}
|
|
38772
39310
|
function loadConfigFile(path5, log16) {
|
|
38773
39311
|
try {
|
|
@@ -38823,12 +39361,12 @@ function loadConfigWithLogger(directory, log16) {
|
|
|
38823
39361
|
return config;
|
|
38824
39362
|
}
|
|
38825
39363
|
function canonicalizeOwnedPath(path5) {
|
|
38826
|
-
const absolute =
|
|
39364
|
+
const absolute = resolve17(path5);
|
|
38827
39365
|
const missing = [];
|
|
38828
39366
|
let current = absolute;
|
|
38829
39367
|
for (; ; ) {
|
|
38830
39368
|
try {
|
|
38831
|
-
return
|
|
39369
|
+
return join27(realpathSync3(current), ...missing.reverse());
|
|
38832
39370
|
} catch {
|
|
38833
39371
|
const parent = dirname23(current);
|
|
38834
39372
|
if (parent === current) return absolute;
|
|
@@ -39134,9 +39672,9 @@ function clearSignatureCache(sessionId) {
|
|
|
39134
39672
|
// src/plugin/image-saver.ts
|
|
39135
39673
|
import { chmodSync as chmodSync4, existsSync as existsSync11, mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
39136
39674
|
import { homedir as homedir12 } from "node:os";
|
|
39137
|
-
import { join as
|
|
39675
|
+
import { join as join28 } from "node:path";
|
|
39138
39676
|
function getImageOutputDir(outputDir) {
|
|
39139
|
-
const resolved = outputDir ??
|
|
39677
|
+
const resolved = outputDir ?? join28(homedir12(), ".opencode", "generated-images");
|
|
39140
39678
|
if (!existsSync11(resolved)) {
|
|
39141
39679
|
mkdirSync6(resolved, { recursive: true, mode: 448 });
|
|
39142
39680
|
}
|
|
@@ -39159,7 +39697,7 @@ function generateImageFilename(mimeType) {
|
|
|
39159
39697
|
function saveImageToDisk(base64Data, mimeType, outputDir) {
|
|
39160
39698
|
try {
|
|
39161
39699
|
const resolvedOutputDir = getImageOutputDir(outputDir);
|
|
39162
|
-
const filePath =
|
|
39700
|
+
const filePath = join28(resolvedOutputDir, generateImageFilename(mimeType));
|
|
39163
39701
|
writeFileSync6(filePath, Buffer.from(base64Data, "base64"), { mode: 384 });
|
|
39164
39702
|
chmodSync4(filePath, 384);
|
|
39165
39703
|
return filePath;
|
|
@@ -39594,11 +40132,11 @@ data: ${JSON.stringify(syntheticUsage)}
|
|
|
39594
40132
|
// src/plugin/gemini-dump.ts
|
|
39595
40133
|
import { createHash as createHash14 } from "node:crypto";
|
|
39596
40134
|
import { appendFileSync as appendFileSync4, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
39597
|
-
import { tmpdir as
|
|
39598
|
-
import { join as
|
|
40135
|
+
import { tmpdir as tmpdir6 } from "node:os";
|
|
40136
|
+
import { join as join29 } from "node:path";
|
|
39599
40137
|
var DUMP_STATUS_TITLE = "## Gemini Dump Status";
|
|
39600
40138
|
var DUMP_DIR_ENV = "OPENCODE_ANTIGRAVITY_GEMINI_DUMP_DIR";
|
|
39601
|
-
var DEFAULT_DUMP_DIR =
|
|
40139
|
+
var DEFAULT_DUMP_DIR = join29(tmpdir6(), "opencode-antigravity-gemini-dumps");
|
|
39602
40140
|
var DUMP_DIR_MODE = 448;
|
|
39603
40141
|
var DUMP_FILE_MODE = 384;
|
|
39604
40142
|
var nextDumpId = 0;
|
|
@@ -39752,7 +40290,7 @@ function writeGeminiDump(input2) {
|
|
|
39752
40290
|
nextDumpId += 1;
|
|
39753
40291
|
const id = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${String(nextDumpId).padStart(5, "0")}-${input2.streaming ? "stream" : "json"}`;
|
|
39754
40292
|
const dumpDir = getGeminiDumpDirectory();
|
|
39755
|
-
const prefix =
|
|
40293
|
+
const prefix = join29(dumpDir, id);
|
|
39756
40294
|
mkdirSync7(dumpDir, { recursive: true, mode: DUMP_DIR_MODE });
|
|
39757
40295
|
const context = {
|
|
39758
40296
|
id,
|
|
@@ -39836,21 +40374,21 @@ import {
|
|
|
39836
40374
|
unlinkSync as unlinkSync4,
|
|
39837
40375
|
writeFileSync as writeFileSync8
|
|
39838
40376
|
} from "node:fs";
|
|
39839
|
-
import { join as
|
|
40377
|
+
import { join as join31 } from "node:path";
|
|
39840
40378
|
|
|
39841
40379
|
// src/plugin/recovery/constants.ts
|
|
39842
40380
|
import { homedir as homedir13 } from "node:os";
|
|
39843
|
-
import { join as
|
|
40381
|
+
import { join as join30 } from "node:path";
|
|
39844
40382
|
function getXdgData() {
|
|
39845
40383
|
const platform = process.platform;
|
|
39846
40384
|
if (platform === "win32") {
|
|
39847
|
-
return process.env.APPDATA ||
|
|
40385
|
+
return process.env.APPDATA || join30(homedir13(), "AppData", "Roaming");
|
|
39848
40386
|
}
|
|
39849
|
-
return process.env.XDG_DATA_HOME ||
|
|
40387
|
+
return process.env.XDG_DATA_HOME || join30(homedir13(), ".local", "share");
|
|
39850
40388
|
}
|
|
39851
|
-
var OPENCODE_STORAGE =
|
|
39852
|
-
var MESSAGE_STORAGE =
|
|
39853
|
-
var PART_STORAGE =
|
|
40389
|
+
var OPENCODE_STORAGE = join30(getXdgData(), "opencode", "storage");
|
|
40390
|
+
var MESSAGE_STORAGE = join30(OPENCODE_STORAGE, "message");
|
|
40391
|
+
var PART_STORAGE = join30(OPENCODE_STORAGE, "part");
|
|
39854
40392
|
var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
39855
40393
|
"thinking",
|
|
39856
40394
|
"redacted_thinking",
|
|
@@ -39860,13 +40398,13 @@ var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
|
39860
40398
|
// src/plugin/recovery/storage.ts
|
|
39861
40399
|
function getMessageDir(sessionID) {
|
|
39862
40400
|
if (!existsSync12(MESSAGE_STORAGE)) return "";
|
|
39863
|
-
const directPath =
|
|
40401
|
+
const directPath = join31(MESSAGE_STORAGE, sessionID);
|
|
39864
40402
|
if (existsSync12(directPath)) {
|
|
39865
40403
|
return directPath;
|
|
39866
40404
|
}
|
|
39867
40405
|
try {
|
|
39868
40406
|
for (const dir of readdirSync2(MESSAGE_STORAGE)) {
|
|
39869
|
-
const sessionPath =
|
|
40407
|
+
const sessionPath = join31(MESSAGE_STORAGE, dir, sessionID);
|
|
39870
40408
|
if (existsSync12(sessionPath)) {
|
|
39871
40409
|
return sessionPath;
|
|
39872
40410
|
}
|
|
@@ -39883,7 +40421,7 @@ function readMessages(sessionID) {
|
|
|
39883
40421
|
for (const file of readdirSync2(messageDir)) {
|
|
39884
40422
|
if (!file.endsWith(".json")) continue;
|
|
39885
40423
|
try {
|
|
39886
|
-
const content = readFileSync11(
|
|
40424
|
+
const content = readFileSync11(join31(messageDir, file), "utf-8");
|
|
39887
40425
|
messages.push(JSON.parse(content));
|
|
39888
40426
|
} catch {
|
|
39889
40427
|
}
|
|
@@ -39899,14 +40437,14 @@ function readMessages(sessionID) {
|
|
|
39899
40437
|
});
|
|
39900
40438
|
}
|
|
39901
40439
|
function readParts(messageID) {
|
|
39902
|
-
const partDir =
|
|
40440
|
+
const partDir = join31(PART_STORAGE, messageID);
|
|
39903
40441
|
if (!existsSync12(partDir)) return [];
|
|
39904
40442
|
const parts = [];
|
|
39905
40443
|
try {
|
|
39906
40444
|
for (const file of readdirSync2(partDir)) {
|
|
39907
40445
|
if (!file.endsWith(".json")) continue;
|
|
39908
40446
|
try {
|
|
39909
|
-
const content = readFileSync11(
|
|
40447
|
+
const content = readFileSync11(join31(partDir, file), "utf-8");
|
|
39910
40448
|
parts.push(JSON.parse(content));
|
|
39911
40449
|
} catch {
|
|
39912
40450
|
}
|
|
@@ -39948,7 +40486,7 @@ function findMessagesWithOrphanThinking(sessionID) {
|
|
|
39948
40486
|
return result;
|
|
39949
40487
|
}
|
|
39950
40488
|
function prependThinkingPart(sessionID, messageID) {
|
|
39951
|
-
const partDir =
|
|
40489
|
+
const partDir = join31(PART_STORAGE, messageID);
|
|
39952
40490
|
try {
|
|
39953
40491
|
if (!existsSync12(partDir)) {
|
|
39954
40492
|
mkdirSync8(partDir, { recursive: true });
|
|
@@ -39963,7 +40501,7 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
39963
40501
|
synthetic: true
|
|
39964
40502
|
};
|
|
39965
40503
|
writeFileSync8(
|
|
39966
|
-
|
|
40504
|
+
join31(partDir, `${partId}.json`),
|
|
39967
40505
|
JSON.stringify(part, null, 2)
|
|
39968
40506
|
);
|
|
39969
40507
|
return true;
|
|
@@ -39972,14 +40510,14 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
39972
40510
|
}
|
|
39973
40511
|
}
|
|
39974
40512
|
function stripThinkingParts(messageID) {
|
|
39975
|
-
const partDir =
|
|
40513
|
+
const partDir = join31(PART_STORAGE, messageID);
|
|
39976
40514
|
if (!existsSync12(partDir)) return false;
|
|
39977
40515
|
let anyRemoved = false;
|
|
39978
40516
|
try {
|
|
39979
40517
|
for (const file of readdirSync2(partDir)) {
|
|
39980
40518
|
if (!file.endsWith(".json")) continue;
|
|
39981
40519
|
try {
|
|
39982
|
-
const filePath =
|
|
40520
|
+
const filePath = join31(partDir, file);
|
|
39983
40521
|
const content = readFileSync11(filePath, "utf-8");
|
|
39984
40522
|
const part = JSON.parse(content);
|
|
39985
40523
|
if (THINKING_TYPES.has(part.type)) {
|
|
@@ -41744,6 +42282,7 @@ var NATIVE_GOOGLE_ERROR_MESSAGES = {
|
|
|
41744
42282
|
operator_policy: "Antigravity account pool is unavailable under the operator quota policy. Adjust /antigravity-killswitch or refresh quota.",
|
|
41745
42283
|
soft_quota: "Antigravity account pool is unavailable under the quota protection policy. Add accounts, wait for quota reset, or disable soft quota protection.",
|
|
41746
42284
|
pool_unavailable: "Antigravity account pool has no account available within the configured wait limit. Add accounts with `opencode auth login` or wait for quota reset.",
|
|
42285
|
+
model_unavailable: "The requested Antigravity model is not available to the configured accounts. Choose another model.",
|
|
41747
42286
|
missing_access_token: "Missing access token. Run `opencode auth login` to reauthenticate.",
|
|
41748
42287
|
empty_response: "Antigravity returned an empty response after the internal retry attempts."
|
|
41749
42288
|
};
|
|
@@ -43740,10 +44279,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
43740
44279
|
cancellation.release();
|
|
43741
44280
|
throw error;
|
|
43742
44281
|
}
|
|
43743
|
-
let
|
|
44282
|
+
let resolve20 = () => {
|
|
43744
44283
|
};
|
|
43745
44284
|
const settled = new Promise((done) => {
|
|
43746
|
-
|
|
44285
|
+
resolve20 = done;
|
|
43747
44286
|
});
|
|
43748
44287
|
let stopping = false;
|
|
43749
44288
|
let finished = false;
|
|
@@ -43753,7 +44292,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
43753
44292
|
finished = true;
|
|
43754
44293
|
cancellation.signal.removeEventListener("abort", abort);
|
|
43755
44294
|
cancellation.release();
|
|
43756
|
-
|
|
44295
|
+
resolve20();
|
|
43757
44296
|
};
|
|
43758
44297
|
const abort = () => {
|
|
43759
44298
|
if (finished || stopping) return;
|
|
@@ -43822,8 +44361,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
43822
44361
|
let running = false;
|
|
43823
44362
|
let resolveCompletion = () => {
|
|
43824
44363
|
};
|
|
43825
|
-
const completion = new Promise((
|
|
43826
|
-
resolveCompletion =
|
|
44364
|
+
const completion = new Promise((resolve20) => {
|
|
44365
|
+
resolveCompletion = resolve20;
|
|
43827
44366
|
});
|
|
43828
44367
|
const finish = () => {
|
|
43829
44368
|
if (finished) return;
|
|
@@ -43870,14 +44409,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
43870
44409
|
};
|
|
43871
44410
|
}
|
|
43872
44411
|
function publishResponse(dispatch) {
|
|
43873
|
-
return new Promise((
|
|
44412
|
+
return new Promise((resolve20, reject) => {
|
|
43874
44413
|
let acknowledge;
|
|
43875
44414
|
void Promise.resolve().then(
|
|
43876
44415
|
() => dispatch((callback) => {
|
|
43877
44416
|
acknowledge = callback;
|
|
43878
44417
|
})
|
|
43879
44418
|
).then((response) => {
|
|
43880
|
-
|
|
44419
|
+
resolve20(response);
|
|
43881
44420
|
acknowledge?.();
|
|
43882
44421
|
}, reject);
|
|
43883
44422
|
});
|
|
@@ -45629,15 +46168,15 @@ function projectCommandAccountRows(storage) {
|
|
|
45629
46168
|
|
|
45630
46169
|
// src/plugin/dependencies.ts
|
|
45631
46170
|
import { homedir as homedir14 } from "node:os";
|
|
45632
|
-
import { join as
|
|
46171
|
+
import { join as join32 } from "node:path";
|
|
45633
46172
|
function defaultFilesystemRoots() {
|
|
45634
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ??
|
|
45635
|
-
const xdgState2 = process.env.XDG_STATE_HOME ??
|
|
46173
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME ?? join32(homedir14(), ".config");
|
|
46174
|
+
const xdgState2 = process.env.XDG_STATE_HOME ?? join32(homedir14(), ".local", "state");
|
|
45636
46175
|
return {
|
|
45637
46176
|
projectRoot: process.cwd(),
|
|
45638
|
-
userConfigRoot:
|
|
45639
|
-
sidebarStateRoot:
|
|
45640
|
-
rpcRoot:
|
|
46177
|
+
userConfigRoot: join32(xdgConfig2, "opencode"),
|
|
46178
|
+
sidebarStateRoot: join32(xdgState2, "cortexkit", "antigravity-auth"),
|
|
46179
|
+
rpcRoot: join32(xdgState2, "cortexkit", "antigravity-auth", "rpc")
|
|
45641
46180
|
};
|
|
45642
46181
|
}
|
|
45643
46182
|
function resolvePluginDependencies(overrides = {}) {
|
|
@@ -45666,10 +46205,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
45666
46205
|
}
|
|
45667
46206
|
async function defaultSleep(ms, signal) {
|
|
45668
46207
|
if (ms <= 0) return;
|
|
45669
|
-
await new Promise((
|
|
46208
|
+
await new Promise((resolve20, reject) => {
|
|
45670
46209
|
const timer = setTimeout(() => {
|
|
45671
46210
|
signal?.removeEventListener("abort", onAbort);
|
|
45672
|
-
|
|
46211
|
+
resolve20();
|
|
45673
46212
|
}, ms);
|
|
45674
46213
|
timer.unref?.();
|
|
45675
46214
|
const onAbort = () => {
|
|
@@ -45691,7 +46230,7 @@ function createEventHandler({
|
|
|
45691
46230
|
sessionRegistry,
|
|
45692
46231
|
sessionRecovery,
|
|
45693
46232
|
updateChecker,
|
|
45694
|
-
logger:
|
|
46233
|
+
logger: logger3
|
|
45695
46234
|
}) {
|
|
45696
46235
|
return async (input2) => {
|
|
45697
46236
|
await updateChecker.event(input2);
|
|
@@ -45703,14 +46242,14 @@ function createEventHandler({
|
|
|
45703
46242
|
sessionRegistry.register(sessionId, parentSessionId);
|
|
45704
46243
|
}
|
|
45705
46244
|
if (parentSessionId) {
|
|
45706
|
-
|
|
46245
|
+
logger3.debug("child-session-detected", {
|
|
45707
46246
|
sessionId,
|
|
45708
46247
|
parentID: parentSessionId
|
|
45709
46248
|
});
|
|
45710
46249
|
} else {
|
|
45711
46250
|
const previousSummary = lifecycle.getAccountManager()?.getSessionSummary();
|
|
45712
46251
|
if (previousSummary && (previousSummary.totalClaude > 0 || previousSummary.totalGemini > 0)) {
|
|
45713
|
-
|
|
46252
|
+
logger3.debug("prev-session-quota-summary", {
|
|
45714
46253
|
durationMinutes: previousSummary.durationMinutes,
|
|
45715
46254
|
totalClaude: previousSummary.totalClaude,
|
|
45716
46255
|
totalGemini: previousSummary.totalGemini,
|
|
@@ -45718,7 +46257,7 @@ function createEventHandler({
|
|
|
45718
46257
|
accountsUsed: previousSummary.accountsUsed
|
|
45719
46258
|
});
|
|
45720
46259
|
}
|
|
45721
|
-
|
|
46260
|
+
logger3.debug("root-session-detected", { sessionId });
|
|
45722
46261
|
}
|
|
45723
46262
|
}
|
|
45724
46263
|
if (input2.event.type === "session.deleted") {
|
|
@@ -45727,7 +46266,7 @@ function createEventHandler({
|
|
|
45727
46266
|
if (sessionId) {
|
|
45728
46267
|
sessionRegistry.delete(sessionId);
|
|
45729
46268
|
lifecycle.getAccountManager()?.deleteSessionState(sessionId);
|
|
45730
|
-
const eventLogger =
|
|
46269
|
+
const eventLogger = logger3;
|
|
45731
46270
|
void removeSidebarActiveRouting(sessionId).catch((error2) => {
|
|
45732
46271
|
eventLogger.debug("sidebar-route-remove-failed", {
|
|
45733
46272
|
sessionId,
|
|
@@ -45763,7 +46302,7 @@ function createEventHandler({
|
|
|
45763
46302
|
});
|
|
45764
46303
|
const successToast = getRecoverySuccessToast();
|
|
45765
46304
|
const isChildSession = sessionRegistry.getParentSessionId(sessionID) !== null;
|
|
45766
|
-
|
|
46305
|
+
logger3.debug("recovery-toast", {
|
|
45767
46306
|
...successToast,
|
|
45768
46307
|
isChildSession,
|
|
45769
46308
|
toastScope: config.toast_scope
|
|
@@ -46246,7 +46785,7 @@ function throwIfAllKilled(input2) {
|
|
|
46246
46785
|
}
|
|
46247
46786
|
|
|
46248
46787
|
// src/plugin/session-context.ts
|
|
46249
|
-
import { resolve as
|
|
46788
|
+
import { resolve as resolve18 } from "node:path";
|
|
46250
46789
|
import { pathToFileURL } from "node:url";
|
|
46251
46790
|
var FALLBACK_SESSION_KEY = "__default__";
|
|
46252
46791
|
function extractOpenCodeSessionIdentity(headers) {
|
|
@@ -46260,7 +46799,7 @@ var AgySessionRegistry = class {
|
|
|
46260
46799
|
requestSessions;
|
|
46261
46800
|
parentSessionIds = /* @__PURE__ */ new Map();
|
|
46262
46801
|
constructor(directory, options = {}) {
|
|
46263
|
-
const workspaceUri = directory ? pathToFileURL(
|
|
46802
|
+
const workspaceUri = directory ? pathToFileURL(resolve18(directory)).href : "";
|
|
46264
46803
|
this.requestSessions = new AgyRequestSessionStore(workspaceUri, options);
|
|
46265
46804
|
}
|
|
46266
46805
|
getOrCreate(identity) {
|
|
@@ -46408,7 +46947,7 @@ function formatWaitTime(ms) {
|
|
|
46408
46947
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
46409
46948
|
}
|
|
46410
46949
|
function sleep4(ms, signal) {
|
|
46411
|
-
return new Promise((
|
|
46950
|
+
return new Promise((resolve20, reject) => {
|
|
46412
46951
|
if (signal?.aborted) {
|
|
46413
46952
|
reject(
|
|
46414
46953
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -46417,7 +46956,7 @@ function sleep4(ms, signal) {
|
|
|
46417
46956
|
}
|
|
46418
46957
|
const timeout = setTimeout(() => {
|
|
46419
46958
|
cleanup2();
|
|
46420
|
-
|
|
46959
|
+
resolve20();
|
|
46421
46960
|
}, ms);
|
|
46422
46961
|
const onAbort = () => {
|
|
46423
46962
|
cleanup2();
|
|
@@ -46673,6 +47212,7 @@ function createRequestExecutor(deps) {
|
|
|
46673
47212
|
let localRecaptureUsed = false;
|
|
46674
47213
|
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1e3;
|
|
46675
47214
|
let allAccountsBlockedAt;
|
|
47215
|
+
const modelUnavailableIndexes = /* @__PURE__ */ new Set();
|
|
46676
47216
|
while (true) {
|
|
46677
47217
|
await assertAdmission();
|
|
46678
47218
|
checkAborted();
|
|
@@ -46736,6 +47276,26 @@ function createRequestExecutor(deps) {
|
|
|
46736
47276
|
const killedIndexes = eligibleIndexes === null ? void 0 : new Set(
|
|
46737
47277
|
accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
|
|
46738
47278
|
);
|
|
47279
|
+
if (modelUnavailableIndexes.size > 0) {
|
|
47280
|
+
const candidates = accountManager.getEnabledAccounts().filter(
|
|
47281
|
+
(entry) => eligibleIndexes === null || eligibleIndexes.has(entry.index)
|
|
47282
|
+
);
|
|
47283
|
+
if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
|
|
47284
|
+
pushDebug(
|
|
47285
|
+
`model-unavailable: all ${candidates.length} eligible account(s) skipped`
|
|
47286
|
+
);
|
|
47287
|
+
log16.warn("model-unavailable-all-accounts", {
|
|
47288
|
+
family,
|
|
47289
|
+
model,
|
|
47290
|
+
accounts: candidates.length
|
|
47291
|
+
});
|
|
47292
|
+
return createNativeGoogleErrorResponse({
|
|
47293
|
+
status: 412,
|
|
47294
|
+
reason: "model_unavailable"
|
|
47295
|
+
});
|
|
47296
|
+
}
|
|
47297
|
+
}
|
|
47298
|
+
const excludedIndexes = modelUnavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...modelUnavailableIndexes]);
|
|
46739
47299
|
let account = accountManager.getCurrentOrNextForFamily(
|
|
46740
47300
|
family,
|
|
46741
47301
|
model,
|
|
@@ -46744,7 +47304,7 @@ function createRequestExecutor(deps) {
|
|
|
46744
47304
|
config.soft_quota_threshold_percent,
|
|
46745
47305
|
softQuotaCacheTtlMs,
|
|
46746
47306
|
accountSessionIdentity,
|
|
46747
|
-
|
|
47307
|
+
excludedIndexes
|
|
46748
47308
|
);
|
|
46749
47309
|
if (account && eligibleIndexes !== null && !eligibleIndexes.has(account.index)) {
|
|
46750
47310
|
pushDebug(
|
|
@@ -47211,6 +47771,7 @@ function createRequestExecutor(deps) {
|
|
|
47211
47771
|
};
|
|
47212
47772
|
let apiRequestCount = 0;
|
|
47213
47773
|
let shouldSwitchAccount = false;
|
|
47774
|
+
let skippedForModelUnavailable = false;
|
|
47214
47775
|
if (account.fingerprint) {
|
|
47215
47776
|
pushDebug(
|
|
47216
47777
|
`fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`
|
|
@@ -47590,6 +48151,37 @@ function createRequestExecutor(deps) {
|
|
|
47590
48151
|
shouldSwitchAccount = true;
|
|
47591
48152
|
break;
|
|
47592
48153
|
}
|
|
48154
|
+
if (response.status === 404 && currentEndpoint === ANTIGRAVITY_ENDPOINT_DAILY) {
|
|
48155
|
+
const notFoundBody = await deadline.wait(
|
|
48156
|
+
() => response.clone().text().catch(() => "")
|
|
48157
|
+
);
|
|
48158
|
+
const unavailable = parseModelUnavailableError(notFoundBody);
|
|
48159
|
+
if (unavailable) {
|
|
48160
|
+
if (tokenConsumed) {
|
|
48161
|
+
trackers.token.refund(account.index);
|
|
48162
|
+
tokenConsumed = false;
|
|
48163
|
+
}
|
|
48164
|
+
const reasonCodes = unavailable.reasons.length > 0 ? unavailable.reasons.join(",") : "none";
|
|
48165
|
+
const note = `model-unavailable idx=${account.index} status=${unavailable.status} reasons=${reasonCodes}`;
|
|
48166
|
+
pushDebug(note);
|
|
48167
|
+
debug.logAntigravityDebugResponse(debugContext, response, {
|
|
48168
|
+
note
|
|
48169
|
+
});
|
|
48170
|
+
log16.info("model-unavailable", {
|
|
48171
|
+
accountIndex: account.index,
|
|
48172
|
+
family,
|
|
48173
|
+
model,
|
|
48174
|
+
status: unavailable.status,
|
|
48175
|
+
reasons: unavailable.reasons
|
|
48176
|
+
});
|
|
48177
|
+
void response.body?.cancel().catch(() => {
|
|
48178
|
+
});
|
|
48179
|
+
modelUnavailableIndexes.add(account.index);
|
|
48180
|
+
skippedForModelUnavailable = true;
|
|
48181
|
+
shouldSwitchAccount = true;
|
|
48182
|
+
break;
|
|
48183
|
+
}
|
|
48184
|
+
}
|
|
47593
48185
|
const quotaKey = getQuotaKey(family, model);
|
|
47594
48186
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
47595
48187
|
retryState.resetAccountFailureState(account.index);
|
|
@@ -47656,7 +48248,7 @@ function createRequestExecutor(deps) {
|
|
|
47656
48248
|
break;
|
|
47657
48249
|
}
|
|
47658
48250
|
}
|
|
47659
|
-
const shouldRetryEndpoint = response.status ===
|
|
48251
|
+
const shouldRetryEndpoint = response.status === 404 || response.status >= 500;
|
|
47660
48252
|
if (shouldRetryEndpoint && i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
47661
48253
|
await logResponseBody2(debugContext, response, response.status);
|
|
47662
48254
|
lastFailure = createFailureContext(response);
|
|
@@ -47907,6 +48499,9 @@ function createRequestExecutor(deps) {
|
|
|
47907
48499
|
}
|
|
47908
48500
|
}
|
|
47909
48501
|
}
|
|
48502
|
+
if (shouldSwitchAccount && skippedForModelUnavailable) {
|
|
48503
|
+
continue;
|
|
48504
|
+
}
|
|
47910
48505
|
if (shouldSwitchAccount) {
|
|
47911
48506
|
accountSwitchCount++;
|
|
47912
48507
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
@@ -48109,6 +48704,32 @@ function createRequestExecutor(deps) {
|
|
|
48109
48704
|
dispose
|
|
48110
48705
|
};
|
|
48111
48706
|
}
|
|
48707
|
+
var ERROR_REASON_CODE = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
48708
|
+
function parseModelUnavailableError(bodyText) {
|
|
48709
|
+
let body;
|
|
48710
|
+
try {
|
|
48711
|
+
body = JSON.parse(bodyText);
|
|
48712
|
+
} catch {
|
|
48713
|
+
return null;
|
|
48714
|
+
}
|
|
48715
|
+
const envelope = Array.isArray(body) ? body[0] : body;
|
|
48716
|
+
if (!envelope || typeof envelope !== "object") return null;
|
|
48717
|
+
const error = envelope.error;
|
|
48718
|
+
if (!error || typeof error !== "object") return null;
|
|
48719
|
+
if (error.status !== "NOT_FOUND") return null;
|
|
48720
|
+
const details = error.details;
|
|
48721
|
+
const reasons = [];
|
|
48722
|
+
if (Array.isArray(details)) {
|
|
48723
|
+
for (const detail of details) {
|
|
48724
|
+
if (!detail || typeof detail !== "object") continue;
|
|
48725
|
+
const reason = detail.reason;
|
|
48726
|
+
if (typeof reason === "string" && ERROR_REASON_CODE.test(reason)) {
|
|
48727
|
+
reasons.push(reason);
|
|
48728
|
+
}
|
|
48729
|
+
}
|
|
48730
|
+
}
|
|
48731
|
+
return { status: "NOT_FOUND", reasons };
|
|
48732
|
+
}
|
|
48112
48733
|
function extractRateLimitBodyInfo(body) {
|
|
48113
48734
|
if (!body || typeof body !== "object") return { retryDelayMs: null };
|
|
48114
48735
|
const error = body.error;
|
|
@@ -48161,8 +48782,8 @@ function extractRateLimitBodyInfo(body) {
|
|
|
48161
48782
|
}
|
|
48162
48783
|
}
|
|
48163
48784
|
if (message) {
|
|
48164
|
-
const
|
|
48165
|
-
const rawDuration =
|
|
48785
|
+
const reset = message.match(/(?:reset after|resets? in)\s+([0-9hms.]+)/i);
|
|
48786
|
+
const rawDuration = reset?.[1];
|
|
48166
48787
|
if (rawDuration) {
|
|
48167
48788
|
const parsed = parseDurationToMs(rawDuration);
|
|
48168
48789
|
if (parsed !== null) {
|
|
@@ -48691,6 +49312,19 @@ function createGoogleSearchTool({
|
|
|
48691
49312
|
// src/plugin/lifecycle.ts
|
|
48692
49313
|
var NOOP_DRAIN = async () => {
|
|
48693
49314
|
};
|
|
49315
|
+
async function collectCleanupFailure(cleanup2, failures) {
|
|
49316
|
+
try {
|
|
49317
|
+
await cleanup2();
|
|
49318
|
+
} catch (error) {
|
|
49319
|
+
failures.push(error);
|
|
49320
|
+
}
|
|
49321
|
+
}
|
|
49322
|
+
function reportCleanupFailures(failures) {
|
|
49323
|
+
if (failures.length === 1) throw failures[0];
|
|
49324
|
+
if (failures.length > 1) {
|
|
49325
|
+
throw new AggregateError(failures, "Plugin cleanup failed");
|
|
49326
|
+
}
|
|
49327
|
+
}
|
|
48694
49328
|
function createPluginLifecycle(options) {
|
|
48695
49329
|
let accountManager = null;
|
|
48696
49330
|
let refreshQueue = null;
|
|
@@ -48702,19 +49336,19 @@ function createPluginLifecycle(options) {
|
|
|
48702
49336
|
const consumers = [];
|
|
48703
49337
|
const drainSidebarWrites2 = options.drainSidebarWrites ?? NOOP_DRAIN;
|
|
48704
49338
|
const retire2 = (manager, queue2, requests) => {
|
|
48705
|
-
const queueDrained =
|
|
49339
|
+
const queueDrained = (async () => {
|
|
49340
|
+
await queue2?.dispose();
|
|
49341
|
+
})();
|
|
48706
49342
|
const record3 = {
|
|
48707
49343
|
requests,
|
|
48708
49344
|
done: (async () => {
|
|
48709
|
-
const
|
|
48710
|
-
|
|
48711
|
-
|
|
49345
|
+
const failures = [];
|
|
49346
|
+
await Promise.all([
|
|
49347
|
+
collectCleanupFailure(() => queueDrained, failures),
|
|
49348
|
+
collectCleanupFailure(() => requests?.retire(), failures)
|
|
48712
49349
|
]);
|
|
48713
|
-
await manager.dispose();
|
|
48714
|
-
|
|
48715
|
-
(outcome) => outcome.status === "rejected"
|
|
48716
|
-
);
|
|
48717
|
-
if (failed) throw failed.reason;
|
|
49350
|
+
await collectCleanupFailure(() => manager.dispose(), failures);
|
|
49351
|
+
reportCleanupFailures(failures);
|
|
48718
49352
|
})()
|
|
48719
49353
|
};
|
|
48720
49354
|
retiring.add(record3);
|
|
@@ -48724,8 +49358,6 @@ function createPluginLifecycle(options) {
|
|
|
48724
49358
|
if (!requests) retiring.delete(record3);
|
|
48725
49359
|
}
|
|
48726
49360
|
);
|
|
48727
|
-
void queueDrained.catch(() => {
|
|
48728
|
-
});
|
|
48729
49361
|
return { queueDrained, done: record3.done };
|
|
48730
49362
|
};
|
|
48731
49363
|
const disposeAccountRuntime = async () => {
|
|
@@ -48737,23 +49369,26 @@ function createPluginLifecycle(options) {
|
|
|
48737
49369
|
accountRequests = null;
|
|
48738
49370
|
const retired = [...retiring];
|
|
48739
49371
|
retiring.clear();
|
|
49372
|
+
const failures = [];
|
|
48740
49373
|
const aborted = Promise.all([
|
|
48741
|
-
oldRequests?.dispose(),
|
|
48742
|
-
...retired.map(
|
|
49374
|
+
collectCleanupFailure(() => oldRequests?.dispose(), failures),
|
|
49375
|
+
...retired.map(
|
|
49376
|
+
(record3) => collectCleanupFailure(() => record3.requests?.dispose(), failures)
|
|
49377
|
+
)
|
|
48743
49378
|
]);
|
|
48744
|
-
const liveQueueDrained =
|
|
48745
|
-
|
|
48746
|
-
|
|
48747
|
-
await aborted;
|
|
48748
|
-
const retirements = await Promise.allSettled(
|
|
48749
|
-
retired.map((record3) => record3.done)
|
|
49379
|
+
const liveQueueDrained = collectCleanupFailure(
|
|
49380
|
+
() => oldQueue?.dispose(),
|
|
49381
|
+
failures
|
|
48750
49382
|
);
|
|
48751
|
-
await
|
|
48752
|
-
|
|
48753
|
-
|
|
48754
|
-
(
|
|
48755
|
-
|
|
48756
|
-
|
|
49383
|
+
await Promise.all([
|
|
49384
|
+
aborted,
|
|
49385
|
+
liveQueueDrained,
|
|
49386
|
+
...retired.map(
|
|
49387
|
+
(record3) => collectCleanupFailure(() => record3.done, failures)
|
|
49388
|
+
)
|
|
49389
|
+
]);
|
|
49390
|
+
await collectCleanupFailure(() => oldManager?.dispose(), failures);
|
|
49391
|
+
reportCleanupFailures(failures);
|
|
48757
49392
|
};
|
|
48758
49393
|
const register = (disposable, phase = "consumer") => {
|
|
48759
49394
|
if (closing) {
|
|
@@ -48803,24 +49438,32 @@ function createPluginLifecycle(options) {
|
|
|
48803
49438
|
};
|
|
48804
49439
|
let failDisposal = () => {
|
|
48805
49440
|
};
|
|
48806
|
-
disposal = new Promise((
|
|
48807
|
-
finishDisposal =
|
|
49441
|
+
disposal = new Promise((resolve20, reject) => {
|
|
49442
|
+
finishDisposal = resolve20;
|
|
48808
49443
|
failDisposal = reject;
|
|
48809
49444
|
});
|
|
48810
49445
|
void (async () => {
|
|
48811
|
-
|
|
48812
|
-
await
|
|
48813
|
-
|
|
48814
|
-
|
|
49446
|
+
const failures = [];
|
|
49447
|
+
await collectCleanupFailure(disposeAccountRuntime, failures);
|
|
49448
|
+
await collectCleanupFailure(
|
|
49449
|
+
() => options.shutdownDiskSignatureCache(),
|
|
49450
|
+
failures
|
|
49451
|
+
);
|
|
49452
|
+
await collectCleanupFailure(
|
|
49453
|
+
() => options.sessionRegistry.clear(),
|
|
49454
|
+
failures
|
|
49455
|
+
);
|
|
49456
|
+
await collectCleanupFailure(() => options.clearFetchState(), failures);
|
|
48815
49457
|
for (const disposable of producers) {
|
|
48816
|
-
await disposable.dispose();
|
|
49458
|
+
await collectCleanupFailure(() => disposable.dispose(), failures);
|
|
48817
49459
|
}
|
|
48818
49460
|
producers.length = 0;
|
|
48819
|
-
await drainSidebarWrites2
|
|
49461
|
+
await collectCleanupFailure(drainSidebarWrites2, failures);
|
|
48820
49462
|
for (const disposable of consumers) {
|
|
48821
|
-
await disposable.dispose();
|
|
49463
|
+
await collectCleanupFailure(() => disposable.dispose(), failures);
|
|
48822
49464
|
}
|
|
48823
49465
|
consumers.length = 0;
|
|
49466
|
+
reportCleanupFailures(failures);
|
|
48824
49467
|
})().then(finishDisposal, failDisposal);
|
|
48825
49468
|
}
|
|
48826
49469
|
return disposal;
|
|
@@ -48917,7 +49560,7 @@ function createVaultAccountMenuSections(pool, selectorOf, checkQuota) {
|
|
|
48917
49560
|
}
|
|
48918
49561
|
|
|
48919
49562
|
// src/plugin/index.ts
|
|
48920
|
-
var
|
|
49563
|
+
var logger2 = createLogger4("plugin");
|
|
48921
49564
|
function quotaAccountIdentity4(refreshToken) {
|
|
48922
49565
|
return createHash20("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
48923
49566
|
}
|
|
@@ -48986,7 +49629,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
48986
49629
|
});
|
|
48987
49630
|
let vaultQuotaPoller;
|
|
48988
49631
|
const vaultCustody = createOpenCodeVaultCustody({
|
|
48989
|
-
accountFile:
|
|
49632
|
+
accountFile: resolve19(getStoragePath()),
|
|
48990
49633
|
insulaQuota: true,
|
|
48991
49634
|
readHostSlot: async () => {
|
|
48992
49635
|
if (!cachedGetAuth)
|
|
@@ -49110,7 +49753,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49110
49753
|
});
|
|
49111
49754
|
function scheduleSidebarPublication() {
|
|
49112
49755
|
void sidebarPublisher.publish().catch(
|
|
49113
|
-
(error) =>
|
|
49756
|
+
(error) => logger2.debug("sidebar-source-publish-failed", {
|
|
49114
49757
|
error: error instanceof Error ? error.name : "unknown"
|
|
49115
49758
|
})
|
|
49116
49759
|
);
|
|
@@ -49140,7 +49783,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49140
49783
|
}
|
|
49141
49784
|
);
|
|
49142
49785
|
})().catch(
|
|
49143
|
-
(error) =>
|
|
49786
|
+
(error) => logger2.debug("sidebar-routing-publish-failed", {
|
|
49144
49787
|
error: error instanceof Error ? error.name : "unknown"
|
|
49145
49788
|
})
|
|
49146
49789
|
);
|
|
@@ -49185,8 +49828,8 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49185
49828
|
readProviderState: () => vaultCustody.readState(),
|
|
49186
49829
|
publishSidebar: () => sidebarPublisher.publish(),
|
|
49187
49830
|
transport: vaultQuotaTransport,
|
|
49188
|
-
logger,
|
|
49189
|
-
onOutcome: (level, outcome) => (level === "warn" ? quotaOutcomeLogger :
|
|
49831
|
+
logger: logger2,
|
|
49832
|
+
onOutcome: (level, outcome) => (level === "warn" ? quotaOutcomeLogger : logger2)[level](
|
|
49190
49833
|
"vault-quota-tick",
|
|
49191
49834
|
{ ...outcome }
|
|
49192
49835
|
),
|
|
@@ -49198,7 +49841,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49198
49841
|
lifecycle.register(vaultQuotaPoller, "producer");
|
|
49199
49842
|
}
|
|
49200
49843
|
const operatorSettings = createOperatorSettingsController({
|
|
49201
|
-
projectConfigPath:
|
|
49844
|
+
projectConfigPath: join33(directory, ".opencode", "antigravity.json"),
|
|
49202
49845
|
// getUserConfigPath() already returns the full file path including
|
|
49203
49846
|
// 'antigravity.json' — do NOT join again or the path double-nests
|
|
49204
49847
|
// into <dir>/antigravity.json/antigravity.json.
|
|
@@ -49222,7 +49865,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49222
49865
|
sessionRegistry,
|
|
49223
49866
|
sessionRecovery,
|
|
49224
49867
|
updateChecker,
|
|
49225
|
-
logger
|
|
49868
|
+
logger: logger2
|
|
49226
49869
|
});
|
|
49227
49870
|
let storeQuota = null;
|
|
49228
49871
|
const currentStoreQuota = async (knownRepository) => {
|
|
@@ -49328,7 +49971,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49328
49971
|
source,
|
|
49329
49972
|
ref,
|
|
49330
49973
|
signal: check,
|
|
49331
|
-
logger,
|
|
49974
|
+
logger: logger2,
|
|
49332
49975
|
transport: vaultQuotaTransport
|
|
49333
49976
|
})
|
|
49334
49977
|
},
|
|
@@ -49588,7 +50231,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
49588
50231
|
if (await readAuthority() === "local")
|
|
49589
50232
|
await lifecycle.getAccountManager()?.refreshFromRepository();
|
|
49590
50233
|
} catch (error) {
|
|
49591
|
-
|
|
50234
|
+
logger2.warn("menu-routing-refresh-failed", { error: String(error) });
|
|
49592
50235
|
pushNotification(
|
|
49593
50236
|
{
|
|
49594
50237
|
command: ANTIGRAVITY_MENU_COMMAND,
|