@humain/humain-code 0.8.1 → 0.8.3
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/CHANGELOG.md +36 -0
- package/dist/bundle/chunks/{chunk-E7OBH44W.js → chunk-2XD7TLKB.js} +6 -6
- package/dist/bundle/chunks/{chunk-3CGMVKHA.js → chunk-3E37CJCE.js} +1 -1
- package/dist/bundle/chunks/{chunk-ROFZVEFN.js → chunk-4GB7A76U.js} +77 -72
- package/dist/bundle/chunks/{chunk-P2Y2H7SD.js → chunk-6JTCRCNF.js} +2 -2
- package/dist/bundle/chunks/{chunk-6TTMNQXI.js → chunk-7LSTTCSC.js} +145 -120
- package/dist/bundle/chunks/{chunk-QRRVZYTG.js → chunk-AW24RHGJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-7X6DNT45.js → chunk-B3ZLWVDA.js} +8 -6
- package/dist/bundle/chunks/{chunk-APNPBT7Y.js → chunk-BRSLXHED.js} +1 -1
- package/dist/bundle/chunks/{chunk-KONLZKPL.js → chunk-E4VUW4RI.js} +1 -1
- package/dist/bundle/chunks/{chunk-NICPFMOP.js → chunk-JKX5EGOT.js} +1 -1
- package/dist/bundle/chunks/{chunk-D3KYOSQY.js → chunk-JSHKS7VH.js} +1 -1
- package/dist/bundle/chunks/{chunk-SXOIQWNX.js → chunk-JX6YIPNK.js} +1 -1
- package/dist/bundle/chunks/{chunk-WBSGWISD.js → chunk-M5TVWJ5T.js} +5 -4
- package/dist/bundle/chunks/{chunk-XZ7FTBXS.js → chunk-MUN4ZZZP.js} +1189 -1195
- package/dist/bundle/chunks/{chunk-CQ2CE3RB.js → chunk-QFDZEUFU.js} +2 -2
- package/dist/bundle/chunks/{chunk-DD5UT56Y.js → chunk-R2KD2HFT.js} +67 -66
- package/dist/bundle/chunks/chunk-S2US54IU.js +37 -0
- package/dist/bundle/chunks/{chunk-IMUFBWEK.js → chunk-T2ZGMEMV.js} +42 -41
- package/dist/bundle/chunks/{chunk-FQ4KS5S4.js → chunk-UZOIHLNU.js} +1 -1
- package/dist/bundle/chunks/{chunk-6YVORXTX.js → chunk-VSXVZVBE.js} +253 -232
- package/dist/bundle/chunks/{chunk-P42E6YY6.js → chunk-ZAHVC5V2.js} +206 -194
- package/dist/bundle/chunks/{chunk-DJG2WUNM.js → chunk-ZSWU5KKA.js} +1 -1
- package/dist/bundle/chunks/{compat-SRCNS6OQ.js → compat-4ILE5BEC.js} +1 -1
- package/dist/bundle/chunks/{dist-TRAK7EXI.js → dist-I6CI3CG5.js} +6 -6
- package/dist/bundle/chunks/{dist-4OMLHRJE.js → dist-NXHRL2KY.js} +1 -1
- package/dist/bundle/chunks/{easter-egg-3d-VVUF3C3X.js → easter-egg-3d-VZC5WOYV.js} +1 -1
- package/dist/bundle/chunks/{entry-SRYLSS5P.js → entry-6XDR2IDE.js} +1 -1
- package/dist/bundle/chunks/{execute-I3WGGPWL.js → execute-6MEJJF2T.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-4KO3Q4B5.js → flow-implementer-XOP4MG5X.js} +4 -4
- package/dist/bundle/chunks/{inprocess-TOBRVK4C.js → inprocess-MBKFGDM2.js} +4 -4
- package/dist/bundle/chunks/{interactive-mode-BJJKPBXD.js → interactive-mode-3322RQEH.js} +2 -2
- package/dist/bundle/chunks/{session-picker-4JQEGLDD.js → session-picker-EYKCMFQR.js} +1 -1
- package/dist/bundle/chunks/{startup-ui-AKTA4NDP.js → startup-ui-7ODOR34R.js} +2 -2
- package/dist/bundle/chunks/{trace-command-7ORDQ3JS.js → trace-command-VM7FBWPE.js} +4 -4
- package/dist/bundle/chunks/{virtual-modules-3CT5BMBA.js → virtual-modules-47MGUPYN.js} +8 -8
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/coordination/adapter/delivery.d.ts +27 -0
- package/dist/coordination/adapter/delivery.d.ts.map +1 -1
- package/dist/coordination/adapter/delivery.js +164 -4
- package/dist/coordination/adapter/delivery.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +31 -5
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/presence.d.ts +5 -0
- package/dist/coordination/adapter/presence.d.ts.map +1 -1
- package/dist/coordination/adapter/presence.js +25 -3
- package/dist/coordination/adapter/presence.js.map +1 -1
- package/dist/coordination/adapter/question-routing.d.ts +7 -0
- package/dist/coordination/adapter/question-routing.d.ts.map +1 -0
- package/dist/coordination/adapter/question-routing.js +40 -0
- package/dist/coordination/adapter/question-routing.js.map +1 -0
- package/dist/coordination/adapter/receipts.d.ts +7 -0
- package/dist/coordination/adapter/receipts.d.ts.map +1 -1
- package/dist/coordination/adapter/receipts.js +25 -2
- package/dist/coordination/adapter/receipts.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts +19 -3
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +93 -19
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/client/client.d.ts +2 -2
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +4 -0
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/protocol.d.ts.map +1 -1
- package/dist/coordination/transport/protocol.js +23 -0
- package/dist/coordination/transport/protocol.js.map +1 -1
- package/dist/coordination/transport/types.d.ts +11 -1
- package/dist/coordination/transport/types.d.ts.map +1 -1
- package/dist/coordination/transport/types.js.map +1 -1
- package/dist/core/model-resolver.js +2 -2
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +14 -8
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +14 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +166 -14
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/run-outcome.d.ts +1 -1
- package/dist/core/run-outcome.d.ts.map +1 -1
- package/dist/core/run-outcome.js +2 -2
- package/dist/core/run-outcome.js.map +1 -1
- package/dist/core/run-preflight.d.ts.map +1 -1
- package/dist/core/run-preflight.js +15 -8
- package/dist/core/run-preflight.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +17 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +2 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +10 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/extensions/usage/index.js +5 -5
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/humain/gateway/client.d.ts.map +1 -1
- package/dist/humain/gateway/client.js +36 -9
- package/dist/humain/gateway/client.js.map +1 -1
- package/dist/humain/gateway/http.d.ts.map +1 -1
- package/dist/humain/gateway/http.js +26 -6
- package/dist/humain/gateway/http.js.map +1 -1
- package/dist/humain/gateway/provider.d.ts.map +1 -1
- package/dist/humain/gateway/provider.js +9 -2
- package/dist/humain/gateway/provider.js.map +1 -1
- package/dist/humain/hcode/facade.d.ts +12 -1
- package/dist/humain/hcode/facade.d.ts.map +1 -1
- package/dist/humain/hcode/facade.js +35 -8
- package/dist/humain/hcode/facade.js.map +1 -1
- package/dist/humain/hcode/login-copy.d.ts.map +1 -1
- package/dist/humain/hcode/login-copy.js +10 -0
- package/dist/humain/hcode/login-copy.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +6 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +26 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +35 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +179 -3
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/working-indicator-engine.d.ts +32 -0
- package/dist/modes/interactive/components/working-indicator-engine.d.ts.map +1 -0
- package/dist/modes/interactive/components/working-indicator-engine.js +112 -0
- package/dist/modes/interactive/components/working-indicator-engine.js.map +1 -0
- package/dist/modes/interactive/fullscreen.d.ts +13 -0
- package/dist/modes/interactive/fullscreen.d.ts.map +1 -0
- package/dist/modes/interactive/fullscreen.js +25 -0
- package/dist/modes/interactive/fullscreen.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +4 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +117 -19
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/humain-dark.json +5 -4
- package/dist/modes/interactive/theme/humain-light.json +6 -5
- package/docs/cli.md +6 -0
- package/docs/coordination.md +16 -4
- package/docs/development.md +7 -0
- package/docs/environment-variables.md +2 -1
- package/docs/providers.md +19 -5
- package/docs/settings.md +20 -0
- package/docs/usage.md +2 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/settings.schema.json +29 -0
- package/dist/bundle/chunks/chunk-UEW6TUSP.js +0 -36
- package/dist/bundle/chunks/chunk-YPZPCHNV.js +0 -3
|
@@ -26,6 +26,10 @@ export interface OAuthAccountIdentity {
|
|
|
26
26
|
/** Derives provider-specific identity before the generic credential fields are considered. */
|
|
27
27
|
export type OAuthAccountIdentityResolver = (credential: OAuthCredential) => OAuthAccountIdentity | undefined;
|
|
28
28
|
export interface PoolAccount<T extends Credential = Credential> {
|
|
29
|
+
/** Unsafe stored ownership; excluded from activation and refresh until matching sign-in. */
|
|
30
|
+
quarantine?: {
|
|
31
|
+
identity?: string;
|
|
32
|
+
};
|
|
29
33
|
key: string;
|
|
30
34
|
label: string;
|
|
31
35
|
credential: T;
|
|
@@ -219,6 +223,7 @@ export declare function getQuotaExhaustionSignal(message: AssistantMessage): Quo
|
|
|
219
223
|
/** Whether the account is currently usable (never exhausted, or its exhaustion window has passed). */
|
|
220
224
|
export declare function isOAuthAccountUsable(account: {
|
|
221
225
|
exhaustedUntil?: number;
|
|
226
|
+
quarantine?: unknown;
|
|
222
227
|
}, nowMs: number): boolean;
|
|
223
228
|
/** Exact removal fallback: next usable account round-robin, then first remaining in insertion order. */
|
|
224
229
|
export declare function getOAuthAccountRemovalSuccessor<T extends Credential>(accounts: readonly PoolAccount<T>[], accountKey: string, nowMs?: number): PoolAccount<T> | undefined;
|
|
@@ -253,6 +258,15 @@ export declare class OAuthAccountPool {
|
|
|
253
258
|
* back to the key.
|
|
254
259
|
*/
|
|
255
260
|
getAccountIdentity(providerId: string, credential: OAuthCredential): OAuthAccountIdentity | undefined;
|
|
261
|
+
/** Describe a request's observed account without resolving auth or consulting the later active selection. */
|
|
262
|
+
getAccountDescription(providerId: string, key: string | undefined): string | undefined;
|
|
263
|
+
/** Reject a quarantined grant using the pool view loaded before auth resolution; safe under the auth lock. */
|
|
264
|
+
assertCredentialUsable(providerId: string, credential: OAuthCredential): void;
|
|
265
|
+
/** Bind a refresh result to the credential that issued the grant, never provider-returned local metadata. */
|
|
266
|
+
bindRefresh(providerId: string, issued: OAuthCredential, refreshed: OAuthCredential): OAuthCredential;
|
|
267
|
+
/** Load ownership evidence without reading auth.json or holding a pool lock across auth resolution. */
|
|
268
|
+
loadIntegrity(providerId: string, options?: AuthOperationOptions): Promise<void>;
|
|
269
|
+
private quarantineCrosslinks;
|
|
256
270
|
/** Last parse error of the pool file, if the file is corrupt. */
|
|
257
271
|
getError(): string | undefined;
|
|
258
272
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-account-pool.d.ts","sourceRoot":"","sources":["../../src/core/oauth-account-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK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AClF,gBAAgB,CACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,sBAAsB,GAC7B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAG5C;YAEa,cAAc;IA0G5B,mGAAmG;IAC7F,iBAAiB,CACtB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,GAAG;QAChC,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC;KAC9D,GACC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA8BlC;IAED;;;;;OAKG;IACG,sBAAsB,CAC3B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,gCAAgC,GAAG,SAAS,CAAC,CA+CvD;IAED,4FAA4F;IAC5F,OAAO,CAAC,gBAAgB;IA+HxB;;;;;;;;;;;;;OAaG;YACW,GAAG;CAmTjB"}
|
|
@@ -281,6 +281,11 @@ function parsePoolData(content) {
|
|
|
281
281
|
(typeof account.exhaustedUntil !== "number" || !Number.isFinite(account.exhaustedUntil)))) {
|
|
282
282
|
throw new Error("invalid account entry");
|
|
283
283
|
}
|
|
284
|
+
if (account.quarantine !== undefined &&
|
|
285
|
+
(!isRecord(account.quarantine) ||
|
|
286
|
+
(account.quarantine.identity !== undefined &&
|
|
287
|
+
!isSafeAccountKey(account.quarantine.identity, account.credential))))
|
|
288
|
+
throw new Error("invalid account quarantine");
|
|
284
289
|
if (!isSafeAccountKey(key, account.credential))
|
|
285
290
|
throw new Error("invalid account key");
|
|
286
291
|
// Labels are displayed: an unsafe one falls back to the validated key instead of rejecting the pool.
|
|
@@ -299,7 +304,8 @@ function toPoolAccount(pool, key) {
|
|
|
299
304
|
exhaustedUntil: stored.exhaustedUntil,
|
|
300
305
|
...(stored.quotaFailures !== undefined ? { quotaFailures: stored.quotaFailures } : {}),
|
|
301
306
|
...(stored.cooldownRevision !== undefined ? { cooldownRevision: stored.cooldownRevision } : {}),
|
|
302
|
-
|
|
307
|
+
...(stored.quarantine ? { quarantine: structuredClone(stored.quarantine) } : {}),
|
|
308
|
+
active: pool.active === key && !stored.quarantine,
|
|
303
309
|
};
|
|
304
310
|
}
|
|
305
311
|
function toAccount(pool, key) {
|
|
@@ -320,14 +326,14 @@ function toAccounts(pool) {
|
|
|
320
326
|
}
|
|
321
327
|
/** Whether the account is currently usable (never exhausted, or its exhaustion window has passed). */
|
|
322
328
|
export function isOAuthAccountUsable(account, nowMs) {
|
|
323
|
-
return account.exhaustedUntil === undefined || account.exhaustedUntil <= nowMs;
|
|
329
|
+
return !account.quarantine && (account.exhaustedUntil === undefined || account.exhaustedUntil <= nowMs);
|
|
324
330
|
}
|
|
325
331
|
/** Exact removal fallback: next usable account round-robin, then first remaining in insertion order. */
|
|
326
332
|
export function getOAuthAccountRemovalSuccessor(accounts, accountKey, nowMs = Date.now()) {
|
|
327
333
|
const index = accounts.findIndex((account) => account.key === accountKey);
|
|
328
334
|
const ordered = [...accounts.slice(index + 1), ...accounts.slice(0, index)];
|
|
329
335
|
return (ordered.find((account) => isOAuthAccountUsable(account, nowMs)) ??
|
|
330
|
-
accounts.find((account) => account.key !== accountKey));
|
|
336
|
+
accounts.find((account) => account.key !== accountKey && !account.quarantine));
|
|
331
337
|
}
|
|
332
338
|
function earliestResetAt(pool, nowMs, includeApiKeys = false) {
|
|
333
339
|
const resetTimes = Object.values(pool.accounts)
|
|
@@ -406,7 +412,7 @@ export class OAuthAccountPool {
|
|
|
406
412
|
const credential = { type: "oauth", access: accessToken, refresh: "", expires: 0 };
|
|
407
413
|
const cached = this.cache
|
|
408
414
|
.get(providerId)
|
|
409
|
-
?.find((account) => account.credential.type === "oauth" && account.credential.access === accessToken);
|
|
415
|
+
?.find((account) => !account.quarantine && account.credential.type === "oauth" && account.credential.access === accessToken);
|
|
410
416
|
if (cached)
|
|
411
417
|
return cached.key;
|
|
412
418
|
const key = this.resolvers.get(providerId)?.(credential)?.key;
|
|
@@ -418,6 +424,19 @@ export class OAuthAccountPool {
|
|
|
418
424
|
* back to the key.
|
|
419
425
|
*/
|
|
420
426
|
getAccountIdentity(providerId, credential) {
|
|
427
|
+
const token = providerId === "openai-codex" ? resolveOpenAICodexAccountIdentity(credential) : undefined;
|
|
428
|
+
const owner = this.cache.get(providerId)?.find((account) => account.key === credential.accountKey);
|
|
429
|
+
if (token &&
|
|
430
|
+
owner?.credential.type === "oauth" &&
|
|
431
|
+
resolveOpenAICodexAccountIdentity(owner.credential)?.key !== token.key) {
|
|
432
|
+
const actual = this.cache
|
|
433
|
+
.get(providerId)
|
|
434
|
+
?.find((account) => account.credential.type === "oauth" &&
|
|
435
|
+
resolveOpenAICodexAccountIdentity(account.credential)?.key === token.key);
|
|
436
|
+
return actual
|
|
437
|
+
? { key: actual.key, label: actual.label }
|
|
438
|
+
: this.getAccountIdentity(providerId, { ...credential, accountKey: undefined });
|
|
439
|
+
}
|
|
421
440
|
if (typeof credential.accountKey === "string" &&
|
|
422
441
|
/^account-[0-9a-f-]{36}$/.test(credential.accountKey) &&
|
|
423
442
|
isSafeAccountKey(credential.accountKey, credential))
|
|
@@ -430,6 +449,84 @@ export class OAuthAccountPool {
|
|
|
430
449
|
label: isSafeIdentityValue(resolved.label, credential) ? resolved.label : resolved.key,
|
|
431
450
|
};
|
|
432
451
|
}
|
|
452
|
+
/** Describe a request's observed account without resolving auth or consulting the later active selection. */
|
|
453
|
+
getAccountDescription(providerId, key) {
|
|
454
|
+
const account = this.cache.get(providerId)?.find((entry) => entry.key === key);
|
|
455
|
+
if (!account)
|
|
456
|
+
return undefined;
|
|
457
|
+
const saved = account.credential;
|
|
458
|
+
const upstream = saved.type === "oauth"
|
|
459
|
+
? ((providerId === "openai-codex" ? getOpenAICodexTokenIdentity(saved.access)?.accountId : undefined) ??
|
|
460
|
+
saved.accountId)
|
|
461
|
+
: undefined;
|
|
462
|
+
return isSafeIdentityValue(upstream, saved) ? `${account.label} (${upstream})` : account.label;
|
|
463
|
+
}
|
|
464
|
+
/** Reject a quarantined grant using the pool view loaded before auth resolution; safe under the auth lock. */
|
|
465
|
+
assertCredentialUsable(providerId, credential) {
|
|
466
|
+
const accounts = this.cache.get(providerId);
|
|
467
|
+
const owner = accounts?.find((account) => account.key === credential.accountKey);
|
|
468
|
+
if (owner?.quarantine ||
|
|
469
|
+
(!owner && accounts?.some((account) => account.quarantine && sameCredential(account.credential, credential))))
|
|
470
|
+
throw new Error("Account is quarantined; sign in to the matching account again");
|
|
471
|
+
}
|
|
472
|
+
/** Bind a refresh result to the credential that issued the grant, never provider-returned local metadata. */
|
|
473
|
+
bindRefresh(providerId, issued, refreshed) {
|
|
474
|
+
const before = this.loginIdentity(providerId, issued);
|
|
475
|
+
const after = this.loginIdentity(providerId, refreshed);
|
|
476
|
+
if (before && after && before.key !== after.key)
|
|
477
|
+
throw new Error("OAuth refresh returned a different account or workspace");
|
|
478
|
+
const bound = { ...refreshed, accountKey: issued.accountKey };
|
|
479
|
+
for (const field of OAUTH_ACCOUNT_IDENTITY_FIELDS) {
|
|
480
|
+
if (issued[field] !== undefined && (field !== "accountLabel" || bound[field] === undefined))
|
|
481
|
+
bound[field] = issued[field];
|
|
482
|
+
}
|
|
483
|
+
return bound;
|
|
484
|
+
}
|
|
485
|
+
/** Load ownership evidence without reading auth.json or holding a pool lock across auth resolution. */
|
|
486
|
+
async loadIntegrity(providerId, options) {
|
|
487
|
+
await this.storage.withLockAsync(async (content) => {
|
|
488
|
+
const data = parsePoolData(content);
|
|
489
|
+
const pool = Object.hasOwn(data, providerId) ? data[providerId] : { active: "", accounts: {} };
|
|
490
|
+
this.quarantineCrosslinks(providerId, pool);
|
|
491
|
+
this.cache.set(providerId, toPoolAccounts(pool));
|
|
492
|
+
return { result: undefined };
|
|
493
|
+
}, options);
|
|
494
|
+
}
|
|
495
|
+
quarantineCrosslinks(providerId, pool) {
|
|
496
|
+
for (const [key, account] of Object.entries(pool.accounts)) {
|
|
497
|
+
const saved = account.credential;
|
|
498
|
+
if (saved.type !== "oauth" || account.quarantine)
|
|
499
|
+
continue;
|
|
500
|
+
const token = providerId === "openai-codex" ? getOpenAICodexTokenIdentity(saved.access) : undefined;
|
|
501
|
+
const wrongStamp = typeof saved.accountKey === "string" &&
|
|
502
|
+
saved.accountKey !== key &&
|
|
503
|
+
Object.hasOwn(pool.accounts, saved.accountKey);
|
|
504
|
+
const wrongIdentity = token &&
|
|
505
|
+
saved.accountId !== undefined &&
|
|
506
|
+
saved.accountId !== token.accountId &&
|
|
507
|
+
((typeof saved.accountId === "string" &&
|
|
508
|
+
saved.accountId !== key &&
|
|
509
|
+
Object.hasOwn(pool.accounts, saved.accountId)) ||
|
|
510
|
+
(token.accountId !== key && Object.hasOwn(pool.accounts, token.accountId)));
|
|
511
|
+
// Loading cannot infer ownership from an alias or a lone credential's inconsistent metadata.
|
|
512
|
+
// A self-stamped legacy slot needs a canonical neighbor as evidence of a foreign grant.
|
|
513
|
+
const legacyIdentity = providerId === "openai-codex" && !/^account-[0-9a-f-]{36}$/.test(key) && !/^local-\d+$/.test(key);
|
|
514
|
+
const canonical = token && Object.hasOwn(pool.accounts, token.accountId)
|
|
515
|
+
? pool.accounts[token.accountId].credential
|
|
516
|
+
: undefined;
|
|
517
|
+
const canonicalOwner = canonical?.type === "oauth" &&
|
|
518
|
+
getOpenAICodexTokenIdentity(canonical.access)?.accountId === token?.accountId;
|
|
519
|
+
const wrongLegacyOwner = legacyIdentity && token && key !== token.accountId && saved.accountKey === key && canonicalOwner;
|
|
520
|
+
if (wrongStamp || wrongIdentity || wrongLegacyOwner) {
|
|
521
|
+
const identity = wrongLegacyOwner
|
|
522
|
+
? key
|
|
523
|
+
: wrongIdentity && isSafeAccountKey(saved.accountId, saved)
|
|
524
|
+
? saved.accountId
|
|
525
|
+
: this.loginIdentity(providerId, saved)?.key;
|
|
526
|
+
account.quarantine = identity ? { identity } : {};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
433
530
|
/** Last parse error of the pool file, if the file is corrupt. */
|
|
434
531
|
getError() {
|
|
435
532
|
return this.error;
|
|
@@ -464,7 +561,7 @@ export class OAuthAccountPool {
|
|
|
464
561
|
displayAccounts(providerId, accounts) {
|
|
465
562
|
const winners = new Map();
|
|
466
563
|
const identities = accounts.map((account) => {
|
|
467
|
-
if (account.credential.type !== "oauth")
|
|
564
|
+
if (account.quarantine || account.credential.type !== "oauth")
|
|
468
565
|
return undefined;
|
|
469
566
|
const identity = this.loginIdentity(providerId, account.credential)?.key;
|
|
470
567
|
if (identity === undefined)
|
|
@@ -501,7 +598,7 @@ export class OAuthAccountPool {
|
|
|
501
598
|
removeExpiredAliases(providerId, pool, key) {
|
|
502
599
|
const survivor = pool.accounts[key]?.credential;
|
|
503
600
|
const now = Date.now();
|
|
504
|
-
if (survivor?.type !== "oauth" || survivor.expires <= now || !survivor.refresh)
|
|
601
|
+
if (pool.accounts[key]?.quarantine || survivor?.type !== "oauth" || survivor.expires <= now || !survivor.refresh)
|
|
505
602
|
return;
|
|
506
603
|
const identity = this.loginIdentity(providerId, survivor)?.key;
|
|
507
604
|
if (identity === undefined)
|
|
@@ -509,6 +606,7 @@ export class OAuthAccountPool {
|
|
|
509
606
|
for (const [alias, { credential }] of Object.entries(pool.accounts)) {
|
|
510
607
|
// Expired access alone is not proof of a dead login: a different refresh grant can still be valid.
|
|
511
608
|
if (alias === key ||
|
|
609
|
+
pool.accounts[alias].quarantine ||
|
|
512
610
|
alias === pool.active ||
|
|
513
611
|
credential.type !== "oauth" ||
|
|
514
612
|
credential.expires > now ||
|
|
@@ -521,7 +619,9 @@ export class OAuthAccountPool {
|
|
|
521
619
|
}
|
|
522
620
|
}
|
|
523
621
|
async getActive(providerId, options) {
|
|
524
|
-
return this.run(providerId, "read", options, (pool) => Object.hasOwn(pool.accounts, pool.active) &&
|
|
622
|
+
return this.run(providerId, "read", options, (pool) => Object.hasOwn(pool.accounts, pool.active) &&
|
|
623
|
+
!pool.accounts[pool.active].quarantine &&
|
|
624
|
+
pool.accounts[pool.active].credential.type === "oauth"
|
|
525
625
|
? toAccount(pool, pool.active)
|
|
526
626
|
: undefined);
|
|
527
627
|
}
|
|
@@ -593,7 +693,10 @@ export class OAuthAccountPool {
|
|
|
593
693
|
throw new Error("Invalid account label");
|
|
594
694
|
const identity = credential.type === "oauth" ? this.loginIdentity(providerId, credential) : undefined;
|
|
595
695
|
const matches = Object.keys(pool.accounts).filter((key) => {
|
|
596
|
-
const
|
|
696
|
+
const entry = pool.accounts[key];
|
|
697
|
+
const stored = entry.credential;
|
|
698
|
+
if (entry.quarantine)
|
|
699
|
+
return identity !== undefined && entry.quarantine.identity === identity.key;
|
|
597
700
|
if (credential.type === "api_key")
|
|
598
701
|
return stored.type === "api_key" && stored.key === credential.key;
|
|
599
702
|
return (stored.type === "oauth" &&
|
|
@@ -625,8 +728,14 @@ export class OAuthAccountPool {
|
|
|
625
728
|
const existing = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;
|
|
626
729
|
if (existing && existing.credential.type !== credential.type)
|
|
627
730
|
throw new Error("Account credential type cannot change");
|
|
731
|
+
if (existing?.quarantine && (!identity || !existing.quarantine.identity))
|
|
732
|
+
throw new Error("Quarantined account identity is unknown; use Add another account");
|
|
628
733
|
if (existing?.credential.type === "oauth" && identity !== undefined) {
|
|
629
|
-
const existingIdentity =
|
|
734
|
+
const existingIdentity = existing.quarantine
|
|
735
|
+
? existing.quarantine.identity
|
|
736
|
+
? { key: existing.quarantine.identity }
|
|
737
|
+
: undefined
|
|
738
|
+
: this.loginIdentity(providerId, existing.credential);
|
|
630
739
|
if (existingIdentity !== undefined && existingIdentity.key !== identity.key)
|
|
631
740
|
throw new Error("Sign-in returned a different account or workspace. Sign in to the selected account or use Add another account.");
|
|
632
741
|
}
|
|
@@ -661,6 +770,8 @@ export class OAuthAccountPool {
|
|
|
661
770
|
return this.run(providerId, "write", options, (pool, context) => {
|
|
662
771
|
if (!Object.hasOwn(pool.accounts, accountKey))
|
|
663
772
|
return undefined;
|
|
773
|
+
if (pool.accounts[accountKey].quarantine)
|
|
774
|
+
throw new Error("Account is quarantined; sign in to the matching account again");
|
|
664
775
|
context.activate = true;
|
|
665
776
|
delete pool.returnTo;
|
|
666
777
|
pool.active = accountKey;
|
|
@@ -697,6 +808,10 @@ export class OAuthAccountPool {
|
|
|
697
808
|
const local = options?.key === undefined && !identity ? nextLocalAccountIdentity(pool) : undefined;
|
|
698
809
|
const key = options?.key ?? identity?.key ?? local.key;
|
|
699
810
|
const existing = pool.accounts[key];
|
|
811
|
+
if (existing?.quarantine &&
|
|
812
|
+
(!existing.quarantine.identity ||
|
|
813
|
+
this.loginIdentity(providerId, credential)?.key !== existing.quarantine.identity))
|
|
814
|
+
throw new Error("Sign-in returned a different account or workspace");
|
|
700
815
|
pool.accounts[key] = {
|
|
701
816
|
credential: providerId === "openai-codex"
|
|
702
817
|
? structuredClone(credential)
|
|
@@ -715,6 +830,8 @@ export class OAuthAccountPool {
|
|
|
715
830
|
return this.run(providerId, "write", options, (pool, context) => {
|
|
716
831
|
if (!Object.hasOwn(pool.accounts, accountKey) || pool.accounts[accountKey].credential.type !== "oauth")
|
|
717
832
|
return undefined;
|
|
833
|
+
if (pool.accounts[accountKey].quarantine)
|
|
834
|
+
throw new Error("Account is quarantined; sign in to the matching account again");
|
|
718
835
|
context.activate = true;
|
|
719
836
|
delete pool.returnTo;
|
|
720
837
|
pool.active = accountKey;
|
|
@@ -898,7 +1015,9 @@ export class OAuthAccountPool {
|
|
|
898
1015
|
pool.returnTo.fromKey = untried;
|
|
899
1016
|
return { outcome: "untried", account: toAccount(pool, untried) };
|
|
900
1017
|
}
|
|
901
|
-
if (!Object.hasOwn(pool.accounts, targetKey) ||
|
|
1018
|
+
if (!Object.hasOwn(pool.accounts, targetKey) ||
|
|
1019
|
+
pool.accounts[targetKey].quarantine ||
|
|
1020
|
+
pool.accounts[targetKey].credential.type !== "oauth")
|
|
902
1021
|
return { outcome: "missing" };
|
|
903
1022
|
pool.active = targetKey;
|
|
904
1023
|
if (pool.returnTo)
|
|
@@ -912,11 +1031,12 @@ export class OAuthAccountPool {
|
|
|
912
1031
|
if (credential?.type === "api_key") {
|
|
913
1032
|
if (!includeApiKeys || !isApiKeyCredential(credential))
|
|
914
1033
|
return undefined;
|
|
1034
|
+
const apiKey = credential.key;
|
|
915
1035
|
const existingKey = Object.keys(pool.accounts).find((key) => pool.accounts[key].credential.type === "api_key" &&
|
|
916
|
-
pool.accounts[key].credential.key ===
|
|
1036
|
+
pool.accounts[key].credential.key === apiKey);
|
|
917
1037
|
const cachedKey = this.cache
|
|
918
1038
|
.get(providerId)
|
|
919
|
-
?.find((account) => account.credential.type === "api_key" && account.credential.key ===
|
|
1039
|
+
?.find((account) => account.credential.type === "api_key" && account.credential.key === apiKey)?.key;
|
|
920
1040
|
const key = existingKey ?? cachedKey ?? `account-${randomUUID()}`;
|
|
921
1041
|
const existing = pool.accounts[key];
|
|
922
1042
|
pool.accounts[key] = {
|
|
@@ -930,6 +1050,29 @@ export class OAuthAccountPool {
|
|
|
930
1050
|
}
|
|
931
1051
|
if (credential?.type !== "oauth")
|
|
932
1052
|
return undefined;
|
|
1053
|
+
// Reconciliation is not consent to recover an unsafe slot, even when auth still contains its grant.
|
|
1054
|
+
const owner = isSafeAccountKey(credential.accountKey, credential) && Object.hasOwn(pool.accounts, credential.accountKey)
|
|
1055
|
+
? pool.accounts[credential.accountKey]
|
|
1056
|
+
: undefined;
|
|
1057
|
+
if (owner?.quarantine ||
|
|
1058
|
+
(!owner &&
|
|
1059
|
+
Object.values(pool.accounts).some((entry) => entry.quarantine && sameCredential(credential, entry.credential))))
|
|
1060
|
+
return undefined;
|
|
1061
|
+
// Repair auth's identity metadata when its stamp names another stored owner; otherwise retain
|
|
1062
|
+
// mismatched metadata so downstream identity validation can reject it rather than laundering it.
|
|
1063
|
+
const tokenIdentity = providerId === "openai-codex" ? getOpenAICodexTokenIdentity(credential.access) : undefined;
|
|
1064
|
+
if (tokenIdentity &&
|
|
1065
|
+
(credential.accountId === undefined ||
|
|
1066
|
+
(owner?.credential.type === "oauth" &&
|
|
1067
|
+
this.loginIdentity(providerId, owner.credential)?.key !== tokenIdentity.accountId)))
|
|
1068
|
+
credential = { ...credential, accountId: tokenIdentity.accountId };
|
|
1069
|
+
const stamped = credential.accountKey;
|
|
1070
|
+
if (isSafeAccountKey(stamped, credential) && Object.hasOwn(pool.accounts, stamped)) {
|
|
1071
|
+
const owner = pool.accounts[stamped].credential;
|
|
1072
|
+
if (owner.type !== "oauth" ||
|
|
1073
|
+
this.loginIdentity(providerId, owner)?.key !== this.loginIdentity(providerId, credential)?.key)
|
|
1074
|
+
credential = { ...credential, accountKey: undefined };
|
|
1075
|
+
}
|
|
933
1076
|
let identity = this.getAccountIdentity(providerId, credential);
|
|
934
1077
|
const loginId = this.loginIdentity(providerId, credential)?.key;
|
|
935
1078
|
const stampedKey = credential.accountKey;
|
|
@@ -974,6 +1117,8 @@ export class OAuthAccountPool {
|
|
|
974
1117
|
: nextLocalAccountIdentity(pool);
|
|
975
1118
|
}
|
|
976
1119
|
const existing = pool.accounts[identity.key];
|
|
1120
|
+
if (existing?.quarantine)
|
|
1121
|
+
return undefined;
|
|
977
1122
|
pool.accounts[identity.key] = {
|
|
978
1123
|
credential: providerId === "openai-codex" && !identity.key.startsWith("account-")
|
|
979
1124
|
? structuredClone(credential)
|
|
@@ -1081,6 +1226,8 @@ export class OAuthAccountPool {
|
|
|
1081
1226
|
/** Applies `operation` to a copy of the stored pool as if auth.json held `credential`. */
|
|
1082
1227
|
const plan = (credential) => {
|
|
1083
1228
|
let pool = stored ? structuredClone(stored) : { active: "", accounts: {} };
|
|
1229
|
+
// Persist evidence, not a restamp: ambiguous ownership never authorizes another slot's grant.
|
|
1230
|
+
this.quarantineCrosslinks(providerId, pool);
|
|
1084
1231
|
const currentKey = this.upsertCredential(pool, credential, providerId, pool.active, includeApiKeys);
|
|
1085
1232
|
if (providerId !== "openai-codex")
|
|
1086
1233
|
reserveLocalAccountKeys(pool);
|
|
@@ -1148,7 +1295,7 @@ export class OAuthAccountPool {
|
|
|
1148
1295
|
const { pool, context } = replan(latest);
|
|
1149
1296
|
const key = usageRefresh.key ?? pool.active;
|
|
1150
1297
|
const account = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;
|
|
1151
|
-
if (account?.credential.type !== "oauth")
|
|
1298
|
+
if (account?.quarantine || account?.credential.type !== "oauth")
|
|
1152
1299
|
return undefined;
|
|
1153
1300
|
if (account.credential.expires > Date.now()) {
|
|
1154
1301
|
next.result = usageRefresh.result(toAccount(pool, key));
|
|
@@ -1163,7 +1310,10 @@ export class OAuthAccountPool {
|
|
|
1163
1310
|
next.result = usageRefresh.result(refreshed);
|
|
1164
1311
|
return undefined;
|
|
1165
1312
|
}
|
|
1166
|
-
account.credential = {
|
|
1313
|
+
account.credential = {
|
|
1314
|
+
...this.bindRefresh(providerId, account.credential, refreshed),
|
|
1315
|
+
accountKey: key,
|
|
1316
|
+
};
|
|
1167
1317
|
next.result = usageRefresh.result(toAccount(pool, key));
|
|
1168
1318
|
return context.currentKey === key ? structuredClone(account.credential) : undefined;
|
|
1169
1319
|
}, authLink.options);
|
|
@@ -1196,6 +1346,8 @@ export class OAuthAccountPool {
|
|
|
1196
1346
|
(context.currentKey === undefined ||
|
|
1197
1347
|
!canActivate(toPoolAccount(source, context.currentKey), toPoolAccount(pool, pool.active))))
|
|
1198
1348
|
throw new Error("Account activation is no longer authorized");
|
|
1349
|
+
if (pool.accounts[pool.active].quarantine)
|
|
1350
|
+
return undefined;
|
|
1199
1351
|
if (sameCredential(target, latest))
|
|
1200
1352
|
return undefined;
|
|
1201
1353
|
if (latest !== undefined &&
|