@andorra-labs/code 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/src/account-presentation.js +4 -1
  2. package/dist/src/agent-execution.js +300 -140
  3. package/dist/src/agent-mcp.js +2 -2
  4. package/dist/src/andorra/endpoint.d.ts +7 -0
  5. package/dist/src/andorra/endpoint.js +46 -0
  6. package/dist/src/andorra/entry.d.ts +21 -0
  7. package/dist/src/andorra/entry.js +100 -0
  8. package/dist/src/andorra/errors.d.ts +2 -0
  9. package/dist/src/andorra/errors.js +39 -0
  10. package/dist/src/andorra/hosted.d.ts +52 -0
  11. package/dist/src/andorra/hosted.js +126 -0
  12. package/dist/src/andorra/monitor.d.ts +151 -0
  13. package/dist/src/andorra/monitor.js +393 -0
  14. package/dist/src/andorra/notices.d.ts +7 -0
  15. package/dist/src/andorra/notices.js +15 -0
  16. package/dist/src/andorra/opt-in.d.ts +58 -0
  17. package/dist/src/andorra/opt-in.js +112 -0
  18. package/dist/src/andorra/request-watch.d.ts +6 -0
  19. package/dist/src/andorra/request-watch.js +10 -0
  20. package/dist/src/andorra/state.d.ts +86 -0
  21. package/dist/src/andorra/state.js +238 -0
  22. package/dist/src/andorra/terminal.d.ts +68 -0
  23. package/dist/src/andorra/terminal.js +125 -0
  24. package/dist/src/andorra/usage-format.d.ts +9 -0
  25. package/dist/src/andorra/usage-format.js +19 -0
  26. package/dist/src/anthropic-credentials.js +9 -1
  27. package/dist/src/app-server/protocol.d.ts +6 -2
  28. package/dist/src/app-server/protocol.js +1 -1
  29. package/dist/src/app-server.d.ts +27 -0
  30. package/dist/src/app-server.js +292 -85
  31. package/dist/src/auth/AuthManager.d.ts +9 -0
  32. package/dist/src/auth/AuthManager.js +161 -21
  33. package/dist/src/auth/deployment.d.ts +1 -0
  34. package/dist/src/auth/deployment.js +1 -0
  35. package/dist/src/auth/index.d.ts +1 -1
  36. package/dist/src/auth/index.js +1 -1
  37. package/dist/src/auth/store.d.ts +26 -0
  38. package/dist/src/auth/store.js +34 -1
  39. package/dist/src/browser-runner.js +1 -1
  40. package/dist/src/browser-stealth.d.ts +19 -1
  41. package/dist/src/browser-stealth.js +23 -3
  42. package/dist/src/browser-ui/tokens.css +4 -4
  43. package/dist/src/browser-view.d.ts +65 -0
  44. package/dist/src/browser-view.js +229 -16
  45. package/dist/src/cli.js +43 -26
  46. package/dist/src/command-screens.d.ts +17 -1
  47. package/dist/src/command-screens.js +192 -21
  48. package/dist/src/commands.d.ts +7 -1
  49. package/dist/src/commands.js +78 -27
  50. package/dist/src/config.d.ts +6 -1
  51. package/dist/src/config.js +86 -3
  52. package/dist/src/dashboard-view.d.ts +2 -0
  53. package/dist/src/dashboard-view.js +11 -2
  54. package/dist/src/decision/PreparedSteps.js +1 -1
  55. package/dist/src/decision/applyToolMenu.js +1 -1
  56. package/dist/src/decision/toolFamilies.js +1 -1
  57. package/dist/src/decision/types.d.ts +1 -0
  58. package/dist/src/graph-health.d.ts +11 -0
  59. package/dist/src/graph-health.js +36 -4
  60. package/dist/src/graph-manager-chat.d.ts +33 -0
  61. package/dist/src/graph-manager-chat.js +159 -5
  62. package/dist/src/graph-runner.js +27 -0
  63. package/dist/src/graph-selection.js +2 -1
  64. package/dist/src/graph-ui/app.js +25 -2
  65. package/dist/src/graph-ui/manager.js +40 -5
  66. package/dist/src/graph-ui/style.css +5 -2
  67. package/dist/src/graph-ui/tokens.css +4 -4
  68. package/dist/src/graphs.js +1 -3
  69. package/dist/src/hardened-runtime.js +1 -1
  70. package/dist/src/membership-errors.js +1 -1
  71. package/dist/src/membership.d.ts +10 -2
  72. package/dist/src/membership.js +20 -6
  73. package/dist/src/model-context-windows.d.ts +2 -0
  74. package/dist/src/model-context-windows.js +24 -0
  75. package/dist/src/model-health-cache.js +1 -1
  76. package/dist/src/model-metadata.d.ts +1 -0
  77. package/dist/src/model-metadata.js +40 -3
  78. package/dist/src/palette.d.ts +1 -0
  79. package/dist/src/palette.js +1 -1
  80. package/dist/src/permissions.js +17 -4
  81. package/dist/src/provider-connection.js +15 -0
  82. package/dist/src/provider-settings.d.ts +16 -1
  83. package/dist/src/provider-settings.js +36 -20
  84. package/dist/src/providers.d.ts +14 -2
  85. package/dist/src/providers.js +69 -11
  86. package/dist/src/react-runtime.js +12 -7
  87. package/dist/src/remote/engine-pool.js +5 -4
  88. package/dist/src/run-control.d.ts +2 -2
  89. package/dist/src/run-control.js +9 -6
  90. package/dist/src/runtime.d.ts +2 -0
  91. package/dist/src/runtime.js +2 -1
  92. package/dist/src/sessions.d.ts +1 -0
  93. package/dist/src/sessions.js +4 -2
  94. package/dist/src/skills/bundled/graph-manager/errors.md +1 -1
  95. package/dist/src/skills/bundled/provenance.json +738 -738
  96. package/dist/src/subagent-run.d.ts +2 -0
  97. package/dist/src/subagent-run.js +14 -3
  98. package/dist/src/telemetry/schema.d.ts +1 -1
  99. package/dist/src/telemetry/schema.js +2 -2
  100. package/dist/src/terminal-ui.d.ts +21 -0
  101. package/dist/src/terminal-ui.js +73 -10
  102. package/dist/src/transcript.js +3 -0
  103. package/dist/src/types.d.ts +3 -0
  104. package/dist/src/workspace-instructions.js +1 -1
  105. package/package.json +12 -1
@@ -1,4 +1,5 @@
1
1
  import { AuthError, type AuthConfiguration, type AuthStatus, type CredentialStore } from './types.js';
2
+ import { type CredentialJournal } from './store.js';
2
3
  export interface OtherSignIn {
3
4
  read(): Promise<string | undefined>;
4
5
  remove(): Promise<void>;
@@ -13,10 +14,14 @@ export declare class AuthManager {
13
14
  private readonly store;
14
15
  private readonly fetch;
15
16
  private readonly keys;
17
+ private readonly journal?;
16
18
  private unsaved?;
19
+ private unsavedIsShared;
20
+ private unsavedRetires;
17
21
  constructor(options: {
18
22
  config: AuthConfiguration;
19
23
  store?: CredentialStore;
24
+ journal?: CredentialJournal;
20
25
  fetch?: typeof fetch;
21
26
  openBrowser?: (url: string) => Promise<void>;
22
27
  lockPort?: number;
@@ -49,6 +54,10 @@ export declare class AuthManager {
49
54
  revoked: boolean;
50
55
  };
51
56
  }>;
57
+ private journalled;
58
+ private pending;
59
+ private forget;
60
+ private ensureSavable;
52
61
  private rotate;
53
62
  private current;
54
63
  private refreshTokens;
@@ -2,9 +2,17 @@ import { randomBytes, randomUUID, createHash, timingSafeEqual } from 'node:crypt
2
2
  import { resolve } from 'node:path';
3
3
  import { createRemoteJWKSet, customFetch, jwtVerify } from 'jose';
4
4
  import { AuthError } from './types.js';
5
- import { createCredentialStore, credentialScope, KeyringAbsentError, KeyringCredentialStore, keyringScopes } from './store.js';
5
+ import { createCredentialJournal, createCredentialStore, credentialScope, KeyringAbsentError, KeyringCredentialStore, keyringScopes } from './store.js';
6
6
  import { withAuthLock } from './lock.js';
7
7
  import { browserUnavailableReason, openBrowser, receiveAuthorizationCode } from './callback.js';
8
+ const tokenDigest = (token) => token === undefined ? '' : createHash('sha256').update(token).digest('hex');
9
+ function validSession(s) {
10
+ const v = s;
11
+ return Boolean(v && typeof v === 'object' && typeof v.accessToken === 'string' && v.accessToken && typeof v.refreshToken === 'string' && v.refreshToken && v.refreshToken.length <= 16000 && typeof v.subject === 'string' && v.subject && typeof v.nonce === 'string' && Number.isFinite(v.expiresAt) && Number.isFinite(v.refreshExpiresAt));
12
+ }
13
+ class UnsavableSessionError extends AuthError {
14
+ constructor(options) { super('storage', 'You are still signed in, but the refreshed sign-in cannot be saved on this machine, so it was not refreshed. Free disk space and room in the OS credential store, then retry.', options); this.name = 'UnsavableSessionError'; }
15
+ }
8
16
  async function otherKeyringSignIns(currentScope) {
9
17
  let scopes;
10
18
  try {
@@ -102,12 +110,16 @@ export class AuthManager {
102
110
  store;
103
111
  fetch;
104
112
  keys;
113
+ journal;
105
114
  unsaved;
115
+ unsavedIsShared = false;
116
+ unsavedRetires = '';
106
117
  constructor(options) {
107
118
  this.options = options;
108
119
  validateAuthConfiguration(options.config);
109
120
  this.config = { ...options.config };
110
121
  this.store = options.store ?? createCredentialStore(credentialIdentity(this.config));
122
+ this.journal = options.journal ?? (options.store ? undefined : createCredentialJournal(credentialIdentity(this.config)));
111
123
  this.fetch = options.fetch ?? globalThis.fetch;
112
124
  this.keys = createRemoteJWKSet(new URL(`${this.config.issuer}/.well-known/jwks.json`), { timeoutDuration: 5000, [customFetch]: (url, init) => this.fetch(url, init) });
113
125
  }
@@ -145,10 +157,18 @@ export class AuthManager {
145
157
  async tokenResponse(body, signal) {
146
158
  const response = await this.post('/oauth2/token', body, signal);
147
159
  if (!response.ok) {
148
- await response.body?.cancel().catch(() => { });
149
- if (response.status === 400 || response.status === 401)
160
+ if (response.status !== 400 && response.status !== 401) {
161
+ await response.body?.cancel().catch(() => { });
162
+ throw new AuthError('network', 'The account service is unavailable. Retry shortly.');
163
+ }
164
+ let refusal;
165
+ try {
166
+ refusal = JSON.parse((await response.text()).slice(0, 4000))?.error;
167
+ }
168
+ catch { }
169
+ if (refusal === 'invalid_grant')
150
170
  throw new AuthError('login_required', 'Your Andorra session has expired or was revoked. Please sign in again.');
151
- throw new AuthError('network', 'The account service is unavailable. Retry shortly.');
171
+ throw new AuthError('network', 'The account service did not accept the request. Retry shortly.');
152
172
  }
153
173
  let reader;
154
174
  try {
@@ -254,6 +274,7 @@ export class AuthManager {
254
274
  throw new AuthError('cancelled', 'Authentication cancelled.');
255
275
  }
256
276
  replacedToken = current.session?.refreshToken;
277
+ await this.forget();
257
278
  }, signal);
258
279
  }
259
280
  catch (error) {
@@ -294,11 +315,20 @@ export class AuthManager {
294
315
  }
295
316
  if (signal?.aborted)
296
317
  throw new AuthError('cancelled', 'Authentication cancelled.');
318
+ const journalled = (await this.journalled())?.session.refreshToken;
319
+ const unsaved = this.unsaved?.session.refreshToken;
297
320
  await this.store.clear(JSON.stringify({ version: 1, generation: randomUUID() }));
298
321
  this.unsaved = undefined;
299
- const own = [...new Set([token, previous].filter((value) => Boolean(value)))];
322
+ let cleanup;
323
+ try {
324
+ await this.journal?.remove();
325
+ }
326
+ catch (error) {
327
+ cleanup = error;
328
+ }
329
+ const own = [...new Set([token, previous, journalled, unsaved].filter((value) => Boolean(value)))];
300
330
  if (!options.everywhere)
301
- return { own };
331
+ return { own, cleanup };
302
332
  let others;
303
333
  try {
304
334
  others = await abortable((this.options.otherSignIns ?? otherKeyringSignIns)(credentialScope(credentialIdentity(this.config))), signal);
@@ -306,7 +336,7 @@ export class AuthManager {
306
336
  catch (failure) {
307
337
  if (signal?.aborted || (failure instanceof AuthError && failure.code === 'cancelled'))
308
338
  throw new AuthError('cancelled', 'Authentication cancelled.');
309
- return { own, foreign: [], removed: 0, failure };
339
+ return { own, foreign: [], removed: 0, failure, cleanup };
310
340
  }
311
341
  const foreign = [];
312
342
  let failure;
@@ -330,27 +360,104 @@ export class AuthManager {
330
360
  failure ??= error;
331
361
  }
332
362
  }
333
- return { own, foreign, removed: others.length, ...(failure === undefined ? {} : { failure }) };
363
+ return { own, foreign, removed: others.length, cleanup, ...(failure === undefined ? {} : { failure }) };
334
364
  }, signal);
335
365
  const results = await Promise.all(tokens.own.map(token => this.revoke(token, signal).catch(() => false)));
336
- if (tokens.removed === undefined)
366
+ if (tokens.removed === undefined) {
367
+ if (tokens.cleanup !== undefined)
368
+ throw tokens.cleanup;
337
369
  return { revoked: results.every(Boolean) };
370
+ }
338
371
  const foreign = await Promise.all((tokens.foreign ?? []).map(token => this.revoke(token, signal).catch(() => false)));
339
372
  if (tokens.failure !== undefined)
340
373
  throw tokens.failure;
374
+ if (tokens.cleanup !== undefined)
375
+ throw tokens.cleanup;
341
376
  return { revoked: results.every(Boolean), others: { removed: tokens.removed, revoked: foreign.every(Boolean) } };
342
377
  }
378
+ async journalled(known) {
379
+ if (!this.journal)
380
+ return;
381
+ try {
382
+ const text = known ?? await this.journal.read();
383
+ if (!text)
384
+ return;
385
+ const value = JSON.parse(text);
386
+ if (typeof value.generation !== 'string' || value.generation.length > 100 || typeof value.replaces !== 'string' || !validSession(value.session))
387
+ return;
388
+ return { generation: value.generation, replaces: value.replaces, session: value.session };
389
+ }
390
+ catch {
391
+ return;
392
+ }
393
+ }
394
+ async pending() {
395
+ if (!this.journal)
396
+ return this.unsaved;
397
+ let text;
398
+ try {
399
+ text = await this.journal.read();
400
+ }
401
+ catch {
402
+ return this.unsaved;
403
+ }
404
+ const shared = await this.journalled(text);
405
+ if (shared && this.unsaved && !this.unsavedIsShared && shared.generation === this.unsaved.generation && tokenDigest(shared.session.refreshToken) === this.unsavedRetires)
406
+ return this.unsaved;
407
+ if (shared) {
408
+ this.unsaved = undefined;
409
+ return shared;
410
+ }
411
+ if (this.unsaved && this.unsavedIsShared)
412
+ this.unsaved = undefined;
413
+ return this.unsaved;
414
+ }
415
+ async forget() {
416
+ this.unsaved = undefined;
417
+ await this.journal?.remove().catch(() => { });
418
+ }
419
+ async ensureSavable(current, pending) {
420
+ if (!this.journal)
421
+ return pending;
422
+ try {
423
+ await this.journal.write(JSON.stringify(pending ? { version: 1, ...pending } : { version: 1, generation: current.generation, probe: true }));
424
+ return pending;
425
+ }
426
+ catch { }
427
+ try {
428
+ await this.store.write(JSON.stringify(current));
429
+ await this.forget();
430
+ return undefined;
431
+ }
432
+ catch (error) {
433
+ throw new UnsavableSessionError({ cause: error });
434
+ }
435
+ }
343
436
  async rotate(current, session) {
344
- const tokens = await this.refreshTokens(session.refreshToken);
345
- let stored = this.unsaved?.replaces ?? session.refreshToken;
437
+ const held = await this.pending();
438
+ const pending = await this.ensureSavable(current, held && held.generation === current.generation && held.session.refreshToken === session.refreshToken ? held : undefined);
439
+ let tokens;
440
+ try {
441
+ tokens = await this.refreshTokens(session.refreshToken);
442
+ }
443
+ catch (error) {
444
+ if (!pending && !this.unsaved)
445
+ await this.journal?.remove().catch(() => { });
446
+ throw error;
447
+ }
448
+ let stored = pending?.replaces ?? tokenDigest(session.refreshToken);
346
449
  const persist = async (rotated) => {
347
450
  try {
348
451
  await this.store.write(JSON.stringify({ ...current, session: rotated }));
349
- this.unsaved = undefined;
350
- stored = rotated.refreshToken;
452
+ stored = tokenDigest(rotated.refreshToken);
453
+ await this.forget();
351
454
  }
352
455
  catch {
353
456
  this.unsaved = { generation: current.generation, replaces: stored, session: rotated };
457
+ this.unsavedIsShared = false;
458
+ this.unsavedRetires = tokenDigest(session.refreshToken);
459
+ if (this.journal)
460
+ this.unsavedIsShared = await this.journal.write(JSON.stringify({ version: 1, ...this.unsaved }), { inPlace: true }).then(() => true, () => false);
354
461
  }
355
462
  };
356
463
  const interim = interimSession(tokens, session);
@@ -366,20 +473,20 @@ export class AuthManager {
366
473
  stored = await abortable(this.read(), signal);
367
474
  }
368
475
  catch (error) {
369
- if (!this.unsaved || !(error instanceof AuthError && error.code === 'storage'))
476
+ if (signal?.aborted || !(error instanceof AuthError && error.code === 'storage') || !(await this.pending()))
370
477
  throw error;
371
478
  }
372
- const pending = this.unsaved;
479
+ const pending = await this.pending();
373
480
  if (!pending)
374
481
  return stored;
375
- if (stored && (stored.generation !== pending.generation || stored.session?.refreshToken !== pending.replaces)) {
376
- this.unsaved = undefined;
482
+ if (stored && (stored.generation !== pending.generation || tokenDigest(stored.session?.refreshToken) !== pending.replaces)) {
483
+ await this.forget();
377
484
  return stored;
378
485
  }
379
486
  const recovered = { version: 1, generation: pending.generation, session: pending.session };
380
487
  try {
381
488
  await this.store.write(JSON.stringify(recovered));
382
- this.unsaved = undefined;
489
+ await this.forget();
383
490
  }
384
491
  catch { }
385
492
  return recovered;
@@ -399,7 +506,7 @@ export class AuthManager {
399
506
  }
400
507
  async clearRejectedCredential(rejection) {
401
508
  let failure;
402
- this.unsaved = undefined;
509
+ await this.forget();
403
510
  try {
404
511
  await this.store.clear(JSON.stringify({ version: 1, generation: randomUUID() }));
405
512
  }
@@ -443,9 +550,42 @@ export class AuthManager {
443
550
  return { token: next.accessToken, subject: next.subject };
444
551
  }
445
552
  catch (error) {
446
- if (error instanceof AuthError && error.code === 'login_required')
553
+ if (error instanceof UnsavableSessionError && session.expiresAt > Date.now() + 5000) {
554
+ const payload = await this.verify(session.accessToken, 'access', signal);
555
+ if (payload.sub === session.subject)
556
+ return { token: session.accessToken, subject: session.subject };
557
+ }
558
+ if (!(error instanceof AuthError) || error.code !== 'login_required')
559
+ throw error;
560
+ let latest;
561
+ try {
562
+ latest = await this.current(signal);
563
+ }
564
+ catch (failure) {
565
+ if (signal?.aborted)
566
+ throw failure;
567
+ throw new AuthError('storage', 'The sign-in could not be refreshed, and the stored sign-in could not be read to confirm it. Retry shortly.', { cause: failure });
568
+ }
569
+ const other = latest.session;
570
+ if (!other || other.refreshToken === session.refreshToken)
447
571
  throw await this.clearRejectedCredential(error);
448
- throw error;
572
+ if (other.expiresAt > Date.now() + 60000) {
573
+ const payload = await this.verify(other.accessToken, 'access', signal);
574
+ if (payload.sub !== other.subject)
575
+ throw new AuthError('invalid_token', 'Stored account identity did not match.');
576
+ return { token: other.accessToken, subject: other.subject };
577
+ }
578
+ try {
579
+ const next = await this.rotate(latest, other);
580
+ if (signal?.aborted)
581
+ throw new AuthError('cancelled', 'Authentication cancelled.');
582
+ return { token: next.accessToken, subject: next.subject };
583
+ }
584
+ catch (second) {
585
+ if (second instanceof AuthError && second.code === 'login_required')
586
+ throw await this.clearRejectedCredential(second);
587
+ throw second;
588
+ }
449
589
  }
450
590
  }
451
591
  async getAccessToken(signal) {
@@ -4,5 +4,6 @@ export declare const AUTH_DEPLOYMENT: {
4
4
  domain: string;
5
5
  apiBaseUrl: string;
6
6
  telemetryBaseUrl: string;
7
+ inferenceBaseUrl: string;
7
8
  redirectUri: string;
8
9
  };
@@ -4,5 +4,6 @@ export const AUTH_DEPLOYMENT = {
4
4
  domain: 'https://auth.andorracode.com',
5
5
  apiBaseUrl: 'https://g2jkeh2w1k.execute-api.us-east-2.amazonaws.com/v1',
6
6
  telemetryBaseUrl: 'https://98m5jdbcf0.execute-api.us-east-2.amazonaws.com/v1',
7
+ inferenceBaseUrl: 'https://inference.andorracode.com',
7
8
  redirectUri: 'http://localhost:43187/callback',
8
9
  };
@@ -3,7 +3,7 @@ import type { AuthConfiguration, AuthError } from './types.js';
3
3
  export * from './types.js';
4
4
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
5
  export { credentialIdentity } from './AuthManager.js';
6
- export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
6
+ export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, FileCredentialJournal, createCredentialStore, createCredentialJournal, type CredentialJournal } from './store.js';
7
7
  export declare function getAuthConfiguration(): AuthConfiguration;
8
8
  export declare function setAuthSignOutReporter(reporter?: (error: AuthError) => void): void;
9
9
  export declare const login: (options?: Parameters<AuthManager["login"]>[0]) => Promise<import("./types.js").AuthStatus>;
@@ -3,7 +3,7 @@ import { AuthManager } from './AuthManager.js';
3
3
  export * from './types.js';
4
4
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
5
  export { credentialIdentity } from './AuthManager.js';
6
- export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
6
+ export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, FileCredentialJournal, createCredentialStore, createCredentialJournal } from './store.js';
7
7
  export function getAuthConfiguration() { return { ...AUTH_DEPLOYMENT }; }
8
8
  let manager;
9
9
  let signOutReporter;
@@ -70,5 +70,31 @@ export declare class FallbackCredentialStore implements CredentialStore {
70
70
  clear(tombstone: string): Promise<void>;
71
71
  location(): Promise<CredentialLocation>;
72
72
  }
73
+ /**
74
+ * Where a refreshed sign-in is kept when the credential store refuses it. The account service replaces the refresh token
75
+ * on every refresh and stops honouring the old one a minute later, so a refreshed sign-in that is saved nowhere is lost
76
+ * with the process that holds it, and the next process is signed out. This owner-only file next to the home's other
77
+ * files holds that sign-in until the store accepts it again; before a refresh it is written once without a secret, to
78
+ * prove a refreshed sign-in will have somewhere to go.
79
+ */
80
+ export interface CredentialJournal {
81
+ read(): Promise<string | undefined>;
82
+ write(value: string, options?: {
83
+ inPlace?: boolean;
84
+ }): Promise<void>;
85
+ remove(): Promise<void>;
86
+ }
87
+ export declare class FileCredentialJournal implements CredentialJournal {
88
+ readonly path: string;
89
+ private readonly writable;
90
+ private readonly file;
91
+ constructor(path: string, writable?: boolean);
92
+ read(): Promise<string | undefined>;
93
+ write(value: string, options?: {
94
+ inPlace?: boolean;
95
+ }): Promise<void>;
96
+ remove(): Promise<void>;
97
+ }
98
+ export declare function createCredentialJournal(identity: string, environment?: NodeJS.ProcessEnv): CredentialJournal;
73
99
  export declare function createCredentialStore(identity: string, environment?: NodeJS.ProcessEnv): CredentialStore;
74
100
  export {};
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { chmod, mkdir, open, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
2
+ import { chmod, mkdir, open, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
3
3
  import { homedir, tmpdir } from 'node:os';
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
5
5
  import { AuthError } from './types.js';
@@ -323,6 +323,39 @@ function holdsSession(text) {
323
323
  return true;
324
324
  }
325
325
  }
326
+ export class FileCredentialJournal {
327
+ path;
328
+ writable;
329
+ file;
330
+ constructor(path, writable = true) {
331
+ this.path = path;
332
+ this.writable = writable;
333
+ this.file = new FileCredentialStore(path);
334
+ }
335
+ read() { return this.file.read(); }
336
+ async write(value, options = {}) {
337
+ if (!this.writable)
338
+ throw new AuthError('storage', 'ANDORRA_CREDENTIAL_STORE=keyring forbids keeping a sign-in in a file.');
339
+ try {
340
+ await this.file.write(value);
341
+ }
342
+ catch (error) {
343
+ if (!options.inPlace)
344
+ throw error;
345
+ try {
346
+ await writeFile(this.path, value, { encoding: 'utf8', mode: 0o600 });
347
+ }
348
+ catch {
349
+ throw error;
350
+ }
351
+ }
352
+ }
353
+ remove() { return this.file.remove(); }
354
+ }
355
+ export function createCredentialJournal(identity, environment = process.env) {
356
+ const home = environment.ANDORRACODE_HOME || join(homedir(), '.andorracode');
357
+ return new FileCredentialJournal(join(home, `credentials-${credentialScope(identity)}.pending.json`), credentialStoreMode(environment) !== 'keyring');
358
+ }
326
359
  export function createCredentialStore(identity, environment = process.env) {
327
360
  const home = environment.ANDORRACODE_HOME || join(homedir(), '.andorracode');
328
361
  return new FallbackCredentialStore(new KeyringCredentialStore(identity), new FileCredentialStore(join(home, `credentials-${credentialScope(identity)}.json`)), credentialStoreMode(environment));
@@ -202,7 +202,7 @@ export async function runBrowserTask(session, task, control, options = {}) {
202
202
  const homeWorkspace = workspace === await realpath(homedir()).catch(() => homedir());
203
203
  codeIntel = await CodeIntelligenceManager.create({ workspace, permissions, onEvent,
204
204
  config: homeWorkspace ? { ...resolveCodeIntelConfig(config), enabled: false, enabledRepos: [] } : resolveCodeIntelConfig(config) });
205
- const adapters = (provider) => trajectory.wrap(createAdapter(provider), () => ({ runId, providerId: provider.id }));
205
+ const adapters = (provider) => trajectory.wrap(createAdapter(provider, { sessionId: session.id }), () => ({ runId, providerId: provider.id }));
206
206
  const resolvedModels = new Map();
207
207
  const refreshed = await refreshModelContext(selected, signal);
208
208
  resolvedModels.set(JSON.stringify([selected.id, selected.model]), Promise.resolve({ model: refreshed.model,
@@ -6,11 +6,29 @@ export declare function stealthContextOptions(platform?: NodeJS.Platform): {
6
6
  userAgent: string;
7
7
  locale: string;
8
8
  };
9
- export declare function desktopUaOverride(platform?: NodeJS.Platform): {
9
+ export declare function desktopUaOverride(platform?: NodeJS.Platform, version?: string): {
10
10
  userAgent: string;
11
11
  acceptLanguage: string;
12
12
  platform: string;
13
13
  };
14
+ /**
15
+ * The client-hint (UA-CH) metadata Chromium itself would send for this browser.
16
+ * An Emulation.setUserAgentOverride without userAgentMetadata stops Chromium from
17
+ * sending Sec-CH-UA headers at all, so every override carries a matching set:
18
+ * the brand and major version mirror the real running browser and the platform
19
+ * mirrors the UA string, keeping UA and client hints consistent for bot checks.
20
+ */
21
+ export declare function userAgentMetadata(version: string | undefined, mobile?: boolean): {
22
+ brands: {
23
+ brand: string;
24
+ version: string;
25
+ }[];
26
+ mobile: boolean;
27
+ model: string;
28
+ platform: string;
29
+ platformVersion: string;
30
+ architecture: string;
31
+ };
14
32
  export declare function stealthInitScript(hardware?: {
15
33
  cores?: number;
16
34
  }): string;
@@ -20,8 +20,10 @@ const OS_PROFILES = {
20
20
  },
21
21
  };
22
22
  const osProfile = (platform = process.platform) => OS_PROFILES[platform === 'darwin' ? 'darwin' : platform === 'win32' ? 'win32' : 'linux'];
23
+ const safeVersion = (version) => (/^\d+(\.\d+)*$/.test(version) ? version : STEALTH_UA_VERSION);
24
+ const userAgentFor = (platform, version) => `Mozilla/5.0 (${osProfile(platform).uaPlatform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${safeVersion(version)} Safari/537.36`;
23
25
  export function stealthUserAgent(platform = process.platform) {
24
- return `Mozilla/5.0 (${osProfile(platform).uaPlatform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${STEALTH_UA_VERSION} Safari/537.36`;
26
+ return userAgentFor(platform, STEALTH_UA_VERSION);
25
27
  }
26
28
  export function stealthLaunchArgs() {
27
29
  return ['--disable-blink-features=AutomationControlled'];
@@ -29,9 +31,27 @@ export function stealthLaunchArgs() {
29
31
  export function stealthContextOptions(platform = process.platform) {
30
32
  return { userAgent: stealthUserAgent(platform), locale: STEALTH_LOCALE };
31
33
  }
32
- export function desktopUaOverride(platform = process.platform) {
34
+ export function desktopUaOverride(platform = process.platform, version = STEALTH_UA_VERSION) {
33
35
  const profile = osProfile(platform);
34
- return { userAgent: stealthUserAgent(platform), acceptLanguage: STEALTH_ACCEPT_LANGUAGE, platform: profile.cdpPlatform };
36
+ return { userAgent: userAgentFor(platform, version), acceptLanguage: STEALTH_ACCEPT_LANGUAGE, platform: profile.cdpPlatform };
37
+ }
38
+ /**
39
+ * The client-hint (UA-CH) metadata Chromium itself would send for this browser.
40
+ * An Emulation.setUserAgentOverride without userAgentMetadata stops Chromium from
41
+ * sending Sec-CH-UA headers at all, so every override carries a matching set:
42
+ * the brand and major version mirror the real running browser and the platform
43
+ * mirrors the UA string, keeping UA and client hints consistent for bot checks.
44
+ */
45
+ export function userAgentMetadata(version, mobile = false) {
46
+ const major = (typeof version === 'string' && /^\d+/.test(version) ? version : STEALTH_UA_VERSION).split('.')[0];
47
+ return {
48
+ brands: [{ brand: 'Chromium', version: major }, { brand: 'Not:A-Brand', version: '99' }],
49
+ mobile,
50
+ model: mobile ? 'Pixel 8' : '',
51
+ platform: mobile ? 'Android' : process.platform === 'darwin' ? 'macOS' : process.platform === 'win32' ? 'Windows' : 'Linux',
52
+ platformVersion: mobile ? '14' : '10.0.0',
53
+ architecture: mobile ? '' : 'x86',
54
+ };
35
55
  }
36
56
  const clampCores = (cores) => Math.min(Math.max(cores || 8, 2), 16);
37
57
  const PAGE_SCRIPT = `(cfg => {
@@ -47,8 +47,8 @@
47
47
  --accent-hover: #ffffff; --accent-ring: rgba(245,245,245,.36);
48
48
  --accent-fill: #1372da; --accent-fill-hover: #2a7fdd; --on-accent-fill: #f5f5f5;
49
49
  --accent-text: #71aeff; --focus: #1f87fc;
50
- --ok: #2f9e6a; --err: #e5484d; --warn: #c9c9c9;
51
- --ok-text: #7cc79a; --err-text: #f47174; --warn-text: #ececec; --merged-text: #bba4f2;
50
+ --ok: #2f9e6a; --err: #e5484d; --warn: #c9c9c9; --caution: #d9a520; --caution-text: #f2c94c;
51
+ --ok-text: #7cc79a; --err-text: #f47174; --warn-text: #ececec; --merged-text: #bba4f2; --draft-text: #f0a35e;
52
52
  --skill: #aab8ff; --skill-wash: rgba(120,140,255,.18);
53
53
  --ok-wash: rgba(47,158,106,.14); --err-wash: rgba(229,72,77,.14); --merged-wash: rgba(142,110,224,.14);
54
54
  --add-wash: rgba(47,158,106,.16); --del-wash: rgba(229,72,77,.16);
@@ -94,8 +94,8 @@
94
94
  --accent-hover: #333333; --accent-ring: rgba(28,28,28,.48);
95
95
  --accent-fill: #1680f3; --accent-fill-hover: #1776dd; --on-accent-fill: #ffffff;
96
96
  --accent-text: #0b6dd3; --focus: #1680f3;
97
- --ok: #3d7a5c; --err: #d13438; --warn: #45464b;
98
- --ok-text: #36704f; --err-text: #c4262e; --warn-text: #1c1c1c; --merged-text: #6a4fc4;
97
+ --ok: #3d7a5c; --err: #d13438; --warn: #45464b; --caution: #b8860b; --caution-text: #8a6100;
98
+ --ok-text: #36704f; --err-text: #c4262e; --warn-text: #1c1c1c; --merged-text: #6a4fc4; --draft-text: #b35a0e;
99
99
  --skill: #3b4fc4; --skill-wash: rgba(59,79,196,.10);
100
100
  --ok-wash: rgba(61,122,92,.08); --err-wash: rgba(209,52,56,.08); --merged-wash: rgba(106,79,196,.08);
101
101
  --add-wash: rgba(61,122,92,.14); --del-wash: rgba(209,52,56,.13);
@@ -34,6 +34,28 @@ export declare function nextFrameBudget(budget: {
34
34
  size: number;
35
35
  } | undefined;
36
36
  export declare const VIEW_MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Mobile Safari/537.36";
37
+ /**
38
+ * The panel browses with a real headed window so sites score it as a browser and
39
+ * not a bot, but the window is parked far offscreen: the pane shows the page by
40
+ * screencasting it, so the window does not need to be on screen or in the way.
41
+ * -32000 is the standard spot that Windows, macOS and Linux all keep off the
42
+ * visible desktop without clamping back.
43
+ */
44
+ export declare const VIEW_OFFSCREEN_POSITION: {
45
+ readonly left: -32000;
46
+ readonly top: -32000;
47
+ };
48
+ /** Where the window goes when the user asks to see it. */
49
+ export declare const VIEW_ONSCREEN_POSITION: {
50
+ readonly left: 80;
51
+ readonly top: 80;
52
+ };
53
+ /**
54
+ * The mobile emulation override is built from the running browser's real version,
55
+ * so the page never sees a version the browser itself does not have. Without a
56
+ * readable version the old constant stays the fallback.
57
+ */
58
+ export declare function mobileUserAgent(version: string | undefined): string;
37
59
  export declare function browserViewUrl(value: string): string;
38
60
  export declare function clampViewport(width: unknown, height: unknown): {
39
61
  width: number;
@@ -55,6 +77,14 @@ export declare const MODIFIER_BITS: Record<string, number>;
55
77
  export declare function modifierMask(modifiers: unknown): number;
56
78
  export declare function macEditingCommands(key: string, modifiers: number): string[];
57
79
  export declare function viewLaunchOptions(channel: BrowserViewChannel, executablePath: string, scale?: number, extensionPaths?: string[]): Record<string, unknown>;
80
+ /**
81
+ * The options the panel actually launches with: the stealth launch options above,
82
+ * but headed, with the real window parked offscreen. A real window is what bot
83
+ * checks (Cloudflare's managed challenge among them) look for; the pane shows the
84
+ * page by screencasting it, so the window does not have to be visible or in the
85
+ * way. parkWindow re-asserts the offscreen position after the launch.
86
+ */
87
+ export declare function headedViewLaunchOptions(channel: BrowserViewChannel, executablePath: string, scale?: number, extensionPaths?: string[]): Record<string, unknown>;
58
88
  export declare function frameGate(now: number, lastEmittedAt: number | undefined, minIntervalMs: number): boolean;
59
89
  export declare function channelCandidate(channel: BrowserViewChannel, platform: NodeJS.Platform, chromiumExecutable: () => string): string | undefined;
60
90
  export type BrowserViewProfileKind = 'project' | 'incognito' | 'isolated';
@@ -113,6 +143,25 @@ export declare class BrowserViewManager {
113
143
  private launch;
114
144
  private launchPersistent;
115
145
  private reportLoaded;
146
+ /**
147
+ * Re-assert the offscreen position over the browser-level CDP connection after
148
+ * the launch. --window-position already asks for it at startup; this second
149
+ * pass catches window managers that clamp the window back on screen (macOS has
150
+ * done so with very large negative coordinates).
151
+ */
152
+ private parkWindow;
153
+ /**
154
+ * Finds the id of the window that should be moved. The precise way is the target
155
+ * id of the tab the user is looking at; without one the browser target itself has
156
+ * no web contents to look a window up with, so the newest page target is used.
157
+ */
158
+ private windowIdFor;
159
+ private lookupWindowId;
160
+ private browserFor;
161
+ private browserCdpFor;
162
+ showWindow(sessionId: string): Promise<void>;
163
+ hideWindow(sessionId: string): Promise<void>;
164
+ private moveWindow;
116
165
  restartForExtensions(force?: boolean): Promise<{
117
166
  restarted: number;
118
167
  pending: string[];
@@ -130,6 +179,13 @@ export declare class BrowserViewManager {
130
179
  private armRestartPoll;
131
180
  private restartProfile;
132
181
  private acquireProfile;
182
+ /**
183
+ * Closes the blank pages a persistent launch was left holding, once the profile
184
+ * has at least one real page: under a headed launch the initial about:blank is
185
+ * the only tab of the real window, and closing it while it is alone destroys the
186
+ * window, so the blanks are held until a real page keeps the window alive.
187
+ */
188
+ private drainPendingBlanks;
133
189
  private claimExtensionPage;
134
190
  private claimUnclaimed;
135
191
  private releaseProfile;
@@ -145,6 +201,15 @@ export declare class BrowserViewManager {
145
201
  private showTab;
146
202
  private applyViewportMode;
147
203
  private queueViewportMode;
204
+ private browserVersion;
205
+ /**
206
+ * The desktop override after mobile emulation: built from the real running
207
+ * browser version when it is readable, falling back to the stealth version when
208
+ * it is not. A desktop UA carrying a version the running browser does not have
209
+ * is exactly what fingerprinting checks catch, so the real one wins whenever it
210
+ * is available.
211
+ */
212
+ private applyDesktopIdentity;
148
213
  private emitFrame;
149
214
  private startScreencast;
150
215
  private shrinkStream;