@andorra-labs/code 0.1.13 → 0.1.15

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 (168) hide show
  1. package/dist/src/account-presentation.js +4 -1
  2. package/dist/src/acp-agent.d.ts +54 -0
  3. package/dist/src/acp-agent.js +991 -0
  4. package/dist/src/agent-execution.js +304 -140
  5. package/dist/src/agent-mcp-catalog.js +2 -0
  6. package/dist/src/agent-mcp.d.ts +2 -0
  7. package/dist/src/agent-mcp.js +86 -4
  8. package/dist/src/andorra/endpoint.d.ts +7 -0
  9. package/dist/src/andorra/endpoint.js +46 -0
  10. package/dist/src/andorra/entry.d.ts +21 -0
  11. package/dist/src/andorra/entry.js +118 -0
  12. package/dist/src/andorra/errors.d.ts +2 -0
  13. package/dist/src/andorra/errors.js +39 -0
  14. package/dist/src/andorra/hosted.d.ts +55 -0
  15. package/dist/src/andorra/hosted.js +130 -0
  16. package/dist/src/andorra/monitor.d.ts +151 -0
  17. package/dist/src/andorra/monitor.js +393 -0
  18. package/dist/src/andorra/notices.d.ts +16 -0
  19. package/dist/src/andorra/notices.js +38 -0
  20. package/dist/src/andorra/opt-in.d.ts +58 -0
  21. package/dist/src/andorra/opt-in.js +112 -0
  22. package/dist/src/andorra/request-watch.d.ts +6 -0
  23. package/dist/src/andorra/request-watch.js +10 -0
  24. package/dist/src/andorra/state.d.ts +86 -0
  25. package/dist/src/andorra/state.js +238 -0
  26. package/dist/src/andorra/terminal.d.ts +70 -0
  27. package/dist/src/andorra/terminal.js +125 -0
  28. package/dist/src/andorra/usage-format.d.ts +9 -0
  29. package/dist/src/andorra/usage-format.js +19 -0
  30. package/dist/src/anthropic-credentials.js +9 -1
  31. package/dist/src/app-server/protocol.d.ts +10 -2
  32. package/dist/src/app-server/protocol.js +1 -1
  33. package/dist/src/app-server/workspace.d.ts +1 -0
  34. package/dist/src/app-server/workspace.js +141 -10
  35. package/dist/src/app-server.d.ts +35 -0
  36. package/dist/src/app-server.js +377 -124
  37. package/dist/src/auth/AuthManager.d.ts +9 -0
  38. package/dist/src/auth/AuthManager.js +164 -24
  39. package/dist/src/auth/deployment.d.ts +1 -0
  40. package/dist/src/auth/deployment.js +1 -0
  41. package/dist/src/auth/index.d.ts +1 -1
  42. package/dist/src/auth/index.js +1 -1
  43. package/dist/src/auth/store.d.ts +26 -0
  44. package/dist/src/auth/store.js +34 -1
  45. package/dist/src/browser-bridge.d.ts +1 -0
  46. package/dist/src/browser-bridge.js +5 -2
  47. package/dist/src/browser-external-app.d.ts +27 -0
  48. package/dist/src/browser-external-app.js +60 -0
  49. package/dist/src/browser-panel-tool.d.ts +6 -0
  50. package/dist/src/browser-panel-tool.js +36 -0
  51. package/dist/src/browser-runner.js +1 -1
  52. package/dist/src/browser-server.d.ts +5 -0
  53. package/dist/src/browser-server.js +27 -3
  54. package/dist/src/browser-stealth.d.ts +19 -1
  55. package/dist/src/browser-stealth.js +23 -3
  56. package/dist/src/browser-ui/tokens.css +4 -4
  57. package/dist/src/browser-view.d.ts +81 -0
  58. package/dist/src/browser-view.js +289 -18
  59. package/dist/src/bug-report.d.ts +81 -0
  60. package/dist/src/bug-report.js +235 -0
  61. package/dist/src/claude-provider.d.ts +2 -1
  62. package/dist/src/claude-provider.js +10 -8
  63. package/dist/src/cli-sign-in.d.ts +3 -1
  64. package/dist/src/cli-sign-in.js +4 -1
  65. package/dist/src/cli.js +205 -58
  66. package/dist/src/coding-tools.js +7 -7
  67. package/dist/src/command-screens.d.ts +26 -3
  68. package/dist/src/command-screens.js +323 -85
  69. package/dist/src/commands.d.ts +7 -1
  70. package/dist/src/commands.js +79 -27
  71. package/dist/src/completion-gates.d.ts +22 -0
  72. package/dist/src/completion-gates.js +11 -0
  73. package/dist/src/config.d.ts +11 -1
  74. package/dist/src/config.js +134 -3
  75. package/dist/src/dashboard-view.d.ts +2 -0
  76. package/dist/src/dashboard-view.js +11 -2
  77. package/dist/src/decision/PreparedSteps.js +1 -1
  78. package/dist/src/decision/applyToolMenu.js +1 -1
  79. package/dist/src/decision/toolFamilies.js +1 -1
  80. package/dist/src/decision/types.d.ts +1 -0
  81. package/dist/src/google-provider.d.ts +31 -0
  82. package/dist/src/google-provider.js +153 -0
  83. package/dist/src/graph-health.d.ts +11 -0
  84. package/dist/src/graph-health.js +36 -4
  85. package/dist/src/graph-manager-chat.d.ts +33 -0
  86. package/dist/src/graph-manager-chat.js +165 -6
  87. package/dist/src/graph-runner.js +27 -0
  88. package/dist/src/graph-selection.js +2 -1
  89. package/dist/src/graph-sync.d.ts +1 -0
  90. package/dist/src/graph-sync.js +93 -34
  91. package/dist/src/graph-tool.d.ts +2 -0
  92. package/dist/src/graph-tool.js +2 -2
  93. package/dist/src/graph-ui/app.js +92 -10
  94. package/dist/src/graph-ui/edge-router.js +121 -53
  95. package/dist/src/graph-ui/manager.js +40 -5
  96. package/dist/src/graph-ui/style.css +5 -2
  97. package/dist/src/graph-ui/tokens.css +4 -4
  98. package/dist/src/graph-visibility.d.ts +31 -0
  99. package/dist/src/graph-visibility.js +102 -0
  100. package/dist/src/graphs.js +1 -3
  101. package/dist/src/hardened-runtime.js +1 -1
  102. package/dist/src/live-model.d.ts +24 -0
  103. package/dist/src/live-model.js +37 -0
  104. package/dist/src/managed-sign-in.d.ts +1 -0
  105. package/dist/src/managed-sign-in.js +13 -0
  106. package/dist/src/membership-errors.d.ts +2 -0
  107. package/dist/src/membership-errors.js +6 -2
  108. package/dist/src/membership.d.ts +13 -2
  109. package/dist/src/membership.js +39 -8
  110. package/dist/src/model-context-windows.d.ts +2 -0
  111. package/dist/src/model-context-windows.js +24 -0
  112. package/dist/src/model-health-cache.js +1 -1
  113. package/dist/src/model-metadata.d.ts +1 -0
  114. package/dist/src/model-metadata.js +47 -3
  115. package/dist/src/paged-transcript.d.ts +2 -0
  116. package/dist/src/paged-transcript.js +16 -0
  117. package/dist/src/palette.d.ts +1 -0
  118. package/dist/src/palette.js +1 -1
  119. package/dist/src/permissions.js +17 -4
  120. package/dist/src/provider-connection.js +32 -0
  121. package/dist/src/provider-engine.d.ts +5 -0
  122. package/dist/src/provider-engine.js +3 -3
  123. package/dist/src/provider-import.js +3 -1
  124. package/dist/src/provider-settings.d.ts +16 -1
  125. package/dist/src/provider-settings.js +50 -22
  126. package/dist/src/providers.d.ts +29 -3
  127. package/dist/src/providers.js +100 -18
  128. package/dist/src/react-runtime.js +33 -12
  129. package/dist/src/read-document-tool.d.ts +2 -0
  130. package/dist/src/read-document-tool.js +6 -6
  131. package/dist/src/remote/engine-pool.js +31 -6
  132. package/dist/src/run-control.d.ts +2 -2
  133. package/dist/src/run-control.js +9 -6
  134. package/dist/src/runtime-environment.d.ts +1 -0
  135. package/dist/src/runtime-environment.js +13 -0
  136. package/dist/src/runtime.d.ts +2 -0
  137. package/dist/src/runtime.js +2 -1
  138. package/dist/src/save-lock.js +14 -7
  139. package/dist/src/session-title.d.ts +3 -0
  140. package/dist/src/session-title.js +5 -2
  141. package/dist/src/sessions.d.ts +1 -0
  142. package/dist/src/sessions.js +4 -2
  143. package/dist/src/sign-in-detection.d.ts +1 -1
  144. package/dist/src/sign-in-detection.js +10 -3
  145. package/dist/src/sign-in-offer.js +1 -1
  146. package/dist/src/skill-commands.js +1 -1
  147. package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
  148. package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
  149. package/dist/src/skills/bundled/graph-manager/errors.md +2 -1
  150. package/dist/src/skills/bundled/provenance.json +743 -738
  151. package/dist/src/skills/runtime-skills.js +1 -0
  152. package/dist/src/subagent-run.d.ts +2 -0
  153. package/dist/src/subagent-run.js +14 -3
  154. package/dist/src/telemetry/schema.d.ts +1 -1
  155. package/dist/src/telemetry/schema.js +2 -2
  156. package/dist/src/telemetry/uploader.d.ts +7 -1
  157. package/dist/src/telemetry/uploader.js +11 -2
  158. package/dist/src/terminal-links.d.ts +16 -0
  159. package/dist/src/terminal-links.js +113 -0
  160. package/dist/src/terminal-ui.d.ts +29 -1
  161. package/dist/src/terminal-ui.js +113 -24
  162. package/dist/src/tool-catalog.js +1 -1
  163. package/dist/src/trajectory.js +6 -1
  164. package/dist/src/transcript.d.ts +2 -0
  165. package/dist/src/transcript.js +5 -1
  166. package/dist/src/types.d.ts +5 -0
  167. package/dist/src/workspace-instructions.js +1 -1
  168. package/package.json +13 -1
@@ -5,7 +5,8 @@ import { mkdir } from 'node:fs/promises';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { observePage, observationResult } from './browser-observation.js';
8
- import { desktopUaOverride, hardenContext, stealthContextOptions, stealthLaunchArgs } from './browser-stealth.js';
8
+ import { externalAppPromptNote, externalAppScheme, guardExternalApps } from './browser-external-app.js';
9
+ import { desktopUaOverride, hardenContext, stealthLaunchArgs, STEALTH_LOCALE, userAgentMetadata } from './browser-stealth.js';
9
10
  export const VIEW_TAB_LIMIT = 6;
10
11
  export const VIEW_SESSION_LIMIT = 4;
11
12
  export const VIEW_IDLE_CLOSE_MS = 10 * 60 * 1000;
@@ -28,8 +29,33 @@ export function nextFrameBudget(budget, scale) {
28
29
  }
29
30
  const VIEW_MAX_VIEWPORT = { width: 1600, height: 2200 };
30
31
  export 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';
32
+ // Fallback for the mobile override when the running browser's version cannot be read.
31
33
  const VIEW_URL_LIMIT = 2048;
32
34
  const VIEW_CLIPBOARD_LIMIT = 1_000_000;
35
+ /**
36
+ * The panel browses with a real headed window so sites score it as a browser and
37
+ * not a bot, but the window is parked far offscreen: the pane shows the page by
38
+ * screencasting it, so the window does not need to be on screen or in the way.
39
+ * -32000 is the standard spot that Windows, macOS and Linux all keep off the
40
+ * visible desktop without clamping back.
41
+ */
42
+ export const VIEW_OFFSCREEN_POSITION = { left: -32000, top: -32000 };
43
+ /** Where the window goes when the user asks to see it. */
44
+ export const VIEW_ONSCREEN_POSITION = { left: 80, top: 80 };
45
+ const VIEW_WINDOW_ARGS = [
46
+ `--window-position=${VIEW_OFFSCREEN_POSITION.left},${VIEW_OFFSCREEN_POSITION.top}`,
47
+ '--window-size=1600,1000',
48
+ ];
49
+ /**
50
+ * The mobile emulation override is built from the running browser's real version,
51
+ * so the page never sees a version the browser itself does not have. Without a
52
+ * readable version the old constant stays the fallback.
53
+ */
54
+ export function mobileUserAgent(version) {
55
+ if (!version || !/^\d+(\.\d+)*$/.test(version))
56
+ return VIEW_MOBILE_USER_AGENT;
57
+ return `Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version} Mobile Safari/537.36`;
58
+ }
33
59
  const SELECTION_STATE = `(() => {
34
60
  const active = document.activeElement;
35
61
  const inFrame = !!active && (active.tagName === 'IFRAME' || active.tagName === 'FRAME');
@@ -194,6 +220,17 @@ export function viewLaunchOptions(channel, executablePath, scale = 1, extensionP
194
220
  timeout: 20_000,
195
221
  };
196
222
  }
223
+ /**
224
+ * The options the panel actually launches with: the stealth launch options above,
225
+ * but headed, with the real window parked offscreen. A real window is what bot
226
+ * checks (Cloudflare's managed challenge among them) look for; the pane shows the
227
+ * page by screencasting it, so the window does not have to be visible or in the
228
+ * way. parkWindow re-asserts the offscreen position after the launch.
229
+ */
230
+ export function headedViewLaunchOptions(channel, executablePath, scale = 1, extensionPaths = []) {
231
+ const base = viewLaunchOptions(channel, executablePath, scale, extensionPaths);
232
+ return { ...base, headless: false, args: [...base.args, ...VIEW_WINDOW_ARGS] };
233
+ }
197
234
  export function frameGate(now, lastEmittedAt, minIntervalMs) {
198
235
  return lastEmittedAt === undefined || now - lastEmittedAt >= minIntervalMs;
199
236
  }
@@ -359,7 +396,7 @@ export class BrowserViewManager {
359
396
  if (!candidate || !existsSync(candidate))
360
397
  continue;
361
398
  try {
362
- return await chromium.launch(viewLaunchOptions(channel, candidate, scale));
399
+ return await chromium.launch(headedViewLaunchOptions(channel, candidate, scale));
363
400
  }
364
401
  catch (error) {
365
402
  failures.push((error instanceof Error ? error.message : String(error)).split('\n')[0]);
@@ -392,8 +429,11 @@ export class BrowserViewManager {
392
429
  if (!candidate || !existsSync(candidate))
393
430
  continue;
394
431
  const open = async (paths) => {
395
- const context = await chromium.launchPersistentContext(directory, { ...viewLaunchOptions(channel, candidate, scale, paths), ...stealthContextOptions(), viewport: { ...viewport }, acceptDownloads: false });
432
+ // Headed, so the browser's own identity goes through: no fake UA is set on
433
+ // the context. Only the locale stays as a stealth option.
434
+ const context = await chromium.launchPersistentContext(directory, { ...headedViewLaunchOptions(channel, candidate, scale, paths), locale: STEALTH_LOCALE, viewport: { ...viewport }, acceptDownloads: false });
396
435
  await hardenContext(context);
436
+ await guardExternalApps(context);
397
437
  return context;
398
438
  };
399
439
  try {
@@ -446,6 +486,169 @@ export class BrowserViewManager {
446
486
  }
447
487
  this.options.extensions?.report(status);
448
488
  }
489
+ /**
490
+ * Re-assert the offscreen position over the browser-level CDP connection after
491
+ * the launch. --window-position already asks for it at startup; this second
492
+ * pass catches window managers that clamp the window back on screen (macOS has
493
+ * done so with very large negative coordinates).
494
+ */
495
+ parkWindow(browser) {
496
+ try {
497
+ const session = browser?.newBrowserCDPSession?.();
498
+ if (!session)
499
+ return;
500
+ void Promise.resolve().then(() => session).then(async (cdp) => {
501
+ const windowId = await this.windowIdFor(cdp, undefined);
502
+ if (windowId === undefined)
503
+ return;
504
+ await cdp.send('Browser.setWindowBounds', { windowId, bounds: { windowState: 'normal', ...VIEW_OFFSCREEN_POSITION } });
505
+ }).catch(() => { });
506
+ }
507
+ catch { /* same: never let window parking break the launch */ }
508
+ }
509
+ /**
510
+ * Finds the id of the window that should be moved. The precise way is the target
511
+ * id of the tab the user is looking at; without one the browser target itself has
512
+ * no web contents to look a window up with, so the newest page target is used.
513
+ */
514
+ async windowIdFor(cdp, targetId) {
515
+ if (targetId !== undefined) {
516
+ const direct = await this.lookupWindowId(cdp, { targetId });
517
+ if (direct !== undefined)
518
+ return direct;
519
+ }
520
+ const fallback = await this.lookupWindowId(cdp, {});
521
+ if (fallback !== undefined)
522
+ return fallback;
523
+ try {
524
+ const targets = await cdp.send('Target.getTargets');
525
+ const page = (targets?.targetInfos ?? []).find((info) => info.type === 'page' && typeof info.targetId === 'string');
526
+ if (page)
527
+ return await this.lookupWindowId(cdp, { targetId: page.targetId });
528
+ }
529
+ catch { /* nothing more to try */ }
530
+ return undefined;
531
+ }
532
+ async lookupWindowId(cdp, params) {
533
+ try {
534
+ const window = await cdp.send('Browser.getWindowForTarget', params);
535
+ return typeof window?.windowId === 'number' ? window.windowId : undefined;
536
+ }
537
+ catch {
538
+ return undefined;
539
+ }
540
+ }
541
+ browserFor(session) {
542
+ if (session.profileKey !== undefined && session.profileOwner !== undefined) {
543
+ return this.profiles.get(session.profileKey)?.context?.browser?.() ?? session.browser;
544
+ }
545
+ return session.browser;
546
+ }
547
+ async browserCdpFor(session) {
548
+ if (session.profileKey !== undefined && session.profileOwner !== undefined) {
549
+ const host = this.profiles.get(session.profileKey);
550
+ if (!host)
551
+ throw new Error('The browser is closing; retry shortly');
552
+ host.browserCdp ??= Promise.resolve().then(() => {
553
+ const browser = this.browserFor(session);
554
+ if (!browser?.newBrowserCDPSession)
555
+ throw new Error('The panel browser cannot be moved on screen: it does not expose window control');
556
+ return browser.newBrowserCDPSession();
557
+ });
558
+ try {
559
+ return await host.browserCdp;
560
+ }
561
+ catch (error) {
562
+ if (this.profiles.get(session.profileKey)?.browserCdp === host.browserCdp)
563
+ host.browserCdp = undefined;
564
+ throw error;
565
+ }
566
+ }
567
+ session.browserCdp ??= Promise.resolve().then(() => {
568
+ const browser = this.browserFor(session);
569
+ if (!browser?.newBrowserCDPSession)
570
+ throw new Error('The panel browser cannot be moved on screen: it does not expose window control');
571
+ return browser.newBrowserCDPSession();
572
+ });
573
+ try {
574
+ return await session.browserCdp;
575
+ }
576
+ catch (error) {
577
+ session.browserCdp = undefined;
578
+ throw error;
579
+ }
580
+ }
581
+ async showWindow(sessionId) {
582
+ await this.moveWindow(sessionId, VIEW_ONSCREEN_POSITION, true);
583
+ // The user can now see and answer the prompt on the tab this brought to the front, so that tab's
584
+ // notice has done its job. Other tabs keep theirs: their prompts are still behind this one, or in
585
+ // a popup's own window that was not moved.
586
+ const session = this.sessions.get(sessionId);
587
+ const active = session?.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
588
+ if (!session || !active?.appPrompt)
589
+ return;
590
+ active.appPrompt = undefined;
591
+ this.publishTabs(sessionId, session);
592
+ }
593
+ async hideWindow(sessionId) {
594
+ await this.moveWindow(sessionId, VIEW_OFFSCREEN_POSITION, false);
595
+ }
596
+ /**
597
+ * Whether the native window holding this tab is on the user's screen right now.
598
+ * Sessions of one project share a window, so one session can hide what another
599
+ * showed; the window's own bounds are the only record that stays true.
600
+ */
601
+ async windowOnScreen(session, tab) {
602
+ try {
603
+ const cdp = await this.browserCdpFor(session);
604
+ const found = await cdp.send('Browser.getWindowForTarget', tab.targetId !== undefined ? { targetId: tab.targetId } : {});
605
+ const bounds = found?.bounds;
606
+ return typeof bounds?.left === 'number' && typeof bounds.top === 'number' && bounds.windowState !== 'minimized'
607
+ && bounds.left > VIEW_OFFSCREEN_POSITION.left / 2 && bounds.top > VIEW_OFFSCREEN_POSITION.top / 2;
608
+ }
609
+ catch {
610
+ return false;
611
+ }
612
+ }
613
+ /**
614
+ * An app link got past the in-page guard. With the window on screen the user can
615
+ * see the browser's prompt; otherwise the tab is flagged so the panel and the
616
+ * agent are told why it stopped responding.
617
+ */
618
+ async flagAppPrompt(sessionId, session, tab, scheme) {
619
+ const at = Date.now();
620
+ if (await this.windowOnScreen(session, tab))
621
+ return;
622
+ if (session.closing || session.tabs.get(tab.id) !== tab)
623
+ return;
624
+ tab.appPrompt = { scheme, at };
625
+ this.publishTabs(sessionId, session);
626
+ }
627
+ /** What to tell the agent when a tab may be stuck behind the browser's "Open app?" prompt. */
628
+ appPromptNote(sessionId, tabId) {
629
+ const session = this.sessions.get(sessionId);
630
+ const tab = session ? session.tabs.get(tabId ?? session.activeTabId ?? '') : undefined;
631
+ return tab?.appPrompt ? externalAppPromptNote(tab.appPrompt) : undefined;
632
+ }
633
+ async moveWindow(sessionId, position, activate) {
634
+ const session = this.sessions.get(sessionId);
635
+ if (!session || session.closing)
636
+ throw new Error('No browser tab is open for this session');
637
+ this.scheduleIdleClose(sessionId, session);
638
+ const cdp = await this.browserCdpFor(session);
639
+ const active = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
640
+ const windowId = await this.windowIdFor(cdp, active?.targetId);
641
+ if (windowId === undefined)
642
+ throw new Error('The browser window could not be found to move');
643
+ await cdp.send('Browser.setWindowBounds', { windowId, bounds: { windowState: 'normal', ...position } });
644
+ if (activate) {
645
+ // Showing the window also raises the tab the panel is showing: the manager's
646
+ // selection and the native browser's selected tab are separate, so without
647
+ // this the real window can come up on a different tab than the one the user
648
+ // is interacting with (including while solving a challenge).
649
+ await Promise.resolve().then(() => active?.page?.bringToFront?.()).catch(() => { });
650
+ }
651
+ }
449
652
  async restartForExtensions(force = false) {
450
653
  if (this.closed)
451
654
  return { restarted: 0, pending: [] };
@@ -622,24 +825,31 @@ export class BrowserViewManager {
622
825
  await current.restarting;
623
826
  continue;
624
827
  }
625
- const host = current ?? { users: new Set() };
828
+ const host = current ?? { users: new Set(), pendingBlanks: [] };
626
829
  if (!current)
627
830
  this.profiles.set(profile.key, host);
628
831
  host.users.add(owner);
629
832
  if (!host.starting)
630
833
  host.scale = scale;
631
834
  host.starting ??= this.launchPersistent(profile.directory, viewport, scale).then(async (context) => {
632
- for (const page of context.pages?.() ?? []) {
835
+ const pages = context.pages?.() ?? [];
836
+ const isBlank = (page) => {
633
837
  const url = String(page.url?.() ?? '');
634
- if (url && url !== 'about:blank')
635
- (host.unclaimed ??= []).push(page);
636
- else
637
- await Promise.resolve().then(() => page.close()).catch(() => { });
638
- }
838
+ return !url || url === 'about:blank';
839
+ };
840
+ (host.unclaimed ??= []).push(...pages.filter(page => !isBlank(page)));
841
+ // Hold the leftover about:blank pages instead of closing them: under a headed
842
+ // launch the initial about:blank is the only tab of the real window, and
843
+ // closing it destroys the window, so every later Target.createTarget fails
844
+ // with "Failed to open a new tab". Headless tolerated that; a real window does
845
+ // not. The blanks are drained (drainPendingBlanks) as soon as the profile has
846
+ // a real page keeping the window alive.
847
+ host.pendingBlanks.push(...pages.filter(page => isBlank(page)));
639
848
  context.on?.('page', (page) => { void this.claimExtensionPage(profile.key, page); });
640
849
  context.on?.('close', () => { if (this.profiles.get(profile.key) === host)
641
850
  this.profiles.delete(profile.key); });
642
851
  host.context = context;
852
+ this.parkWindow(context?.browser?.());
643
853
  return context;
644
854
  });
645
855
  try {
@@ -653,6 +863,19 @@ export class BrowserViewManager {
653
863
  }
654
864
  }
655
865
  }
866
+ /**
867
+ * Closes the blank pages a persistent launch was left holding, once the profile
868
+ * has at least one real page: under a headed launch the initial about:blank is
869
+ * the only tab of the real window, and closing it while it is alone destroys the
870
+ * window, so the blanks are held until a real page keeps the window alive.
871
+ */
872
+ async drainPendingBlanks(host) {
873
+ if (!host?.pendingBlanks?.length)
874
+ return;
875
+ const blanks = host.pendingBlanks.splice(0);
876
+ for (const blank of blanks)
877
+ await Promise.resolve().then(() => blank.close()).catch(() => { });
878
+ }
656
879
  async claimExtensionPage(key, page) {
657
880
  await new Promise(resolve => { const timer = setTimeout(resolve, EXTENSION_PAGE_CLAIM_MS); timer.unref?.(); });
658
881
  if (this.claimedPages.has(page) || page.isClosed?.() === true || this.closed)
@@ -687,6 +910,8 @@ export class BrowserViewManager {
687
910
  this.claimedPages.add(page);
688
911
  void this.adoptPage(sessionId, session, page);
689
912
  }
913
+ if (pages.length)
914
+ void this.drainPendingBlanks(host);
690
915
  }
691
916
  async releaseProfile(key, owner) {
692
917
  const host = this.profiles.get(key);
@@ -721,7 +946,9 @@ export class BrowserViewManager {
721
946
  }
722
947
  }
723
948
  }
724
- return { browser: await this.launch(scale), profile: this.incognito.has(sessionId) ? 'incognito' : 'isolated', renderScale: scale };
949
+ const browser = await this.launch(scale);
950
+ this.parkWindow(browser);
951
+ return { browser, profile: this.incognito.has(sessionId) ? 'incognito' : 'isolated', renderScale: scale };
725
952
  }
726
953
  async disposeBrowser(session) {
727
954
  if (session.profileKey === undefined || session.profileOwner === undefined) {
@@ -734,7 +961,7 @@ export class BrowserViewManager {
734
961
  summary(session) {
735
962
  return {
736
963
  profile: session.profile,
737
- tabs: [...session.tabs.values()].map(tab => ({ id: tab.id, url: tab.url, title: tab.title, loading: tab.loading })),
964
+ tabs: [...session.tabs.values()].map(tab => ({ id: tab.id, url: tab.url, title: tab.title, loading: tab.loading, ...(tab.appPrompt ? { appPrompt: { ...tab.appPrompt } } : {}) })),
738
965
  ...(session.activeTabId ? { activeTabId: session.activeTabId } : {}),
739
966
  };
740
967
  }
@@ -809,10 +1036,17 @@ export class BrowserViewManager {
809
1036
  if (mobile === Boolean(tab.emulated))
810
1037
  return;
811
1038
  tab.emulated = mobile;
812
- await tab.cdp.send('Emulation.setUserAgentOverride', mobile
813
- ? { userAgent: VIEW_MOBILE_USER_AGENT }
814
- : desktopUaOverride());
815
- await tab.cdp.send('Emulation.setTouchEmulationEnabled', { enabled: mobile, ...(mobile ? { maxTouchPoints: 5 } : {}) });
1039
+ if (mobile) {
1040
+ const version = this.browserVersion(session);
1041
+ await tab.cdp.send('Emulation.setUserAgentOverride', { userAgent: mobileUserAgent(version), userAgentMetadata: userAgentMetadata(version, true) });
1042
+ await tab.cdp.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
1043
+ }
1044
+ else {
1045
+ // Switching back to desktop re-applies the desktop identity: built from the
1046
+ // real running version when it can be read, the stealth fallback otherwise.
1047
+ await this.applyDesktopIdentity(session, tab);
1048
+ await tab.cdp.send('Emulation.setTouchEmulationEnabled', { enabled: false });
1049
+ }
816
1050
  }
817
1051
  catch { }
818
1052
  }
@@ -821,6 +1055,22 @@ export class BrowserViewManager {
821
1055
  tab.modeTask = tail.then(() => this.applyViewportMode(session, tab));
822
1056
  return tab.modeTask;
823
1057
  }
1058
+ browserVersion(session) {
1059
+ const context = session.context;
1060
+ const version = (context?.browser?.() ?? this.browserFor(session))?.version?.();
1061
+ return typeof version === 'string' && /^\d+(\.\d+)*$/.test(version) ? version : undefined;
1062
+ }
1063
+ /**
1064
+ * The desktop override after mobile emulation: built from the real running
1065
+ * browser version when it is readable, falling back to the stealth version when
1066
+ * it is not. A desktop UA carrying a version the running browser does not have
1067
+ * is exactly what fingerprinting checks catch, so the real one wins whenever it
1068
+ * is available.
1069
+ */
1070
+ async applyDesktopIdentity(session, tab) {
1071
+ const version = this.browserVersion(session);
1072
+ await tab.cdp.send('Emulation.setUserAgentOverride', { ...desktopUaOverride(process.platform, version), userAgentMetadata: userAgentMetadata(version) }).catch(() => { });
1073
+ }
824
1074
  emitFrame(sessionId, session, tab, payload) {
825
1075
  if (session.closing || this.sessions.get(sessionId) !== session)
826
1076
  return;
@@ -886,6 +1136,13 @@ export class BrowserViewManager {
886
1136
  id: randomUUID(), page, cdp, url: '', title: '', loading: false,
887
1137
  streaming: false, seq: 0, lastEmitAt: undefined, imageWidth: session.viewport.width, imageHeight: session.viewport.height,
888
1138
  };
1139
+ // The target id ties window moves (show/hide) to the window that holds this
1140
+ // tab, so an extension popup opening its own window does not move the wrong one.
1141
+ void Promise.resolve().then(() => cdp.send('Target.getTargetInfo')).then((info) => {
1142
+ const id = info?.targetInfo?.targetId;
1143
+ if (typeof id === 'string' && id)
1144
+ tab.targetId = id;
1145
+ }).catch(() => { });
889
1146
  const publish = () => this.publishTabs(sessionId, session);
890
1147
  let documentRequest;
891
1148
  page.on('request', (request) => {
@@ -894,6 +1151,16 @@ export class BrowserViewManager {
894
1151
  documentRequest = request;
895
1152
  }
896
1153
  catch { }
1154
+ // An app link the in-page guard could not cancel (an iframe src, a redirect, a
1155
+ // form post) still shows up here, in any frame. Chromium is now raising its
1156
+ // "Open app?" prompt, which nothing in this process can see or dismiss.
1157
+ let scheme;
1158
+ try {
1159
+ scheme = externalAppScheme(request?.url?.());
1160
+ }
1161
+ catch { }
1162
+ if (scheme)
1163
+ void this.flagAppPrompt(sessionId, session, tab, scheme);
897
1164
  });
898
1165
  page.on('requestfailed', (request) => { if (request === documentRequest)
899
1166
  documentRequest = undefined; });
@@ -1087,8 +1354,9 @@ export class BrowserViewManager {
1087
1354
  if (session.context)
1088
1355
  return session.context;
1089
1356
  session.contextTask ??= Promise.resolve()
1090
- .then(() => session.browser.newContext({ viewport: { ...session.viewport }, acceptDownloads: false, ...stealthContextOptions() }))
1091
- .then(async (context) => { await hardenContext(context); session.context = context; return context; });
1357
+ // Headed: the browser's own identity goes through, only the locale stays as a stealth option.
1358
+ .then(() => session.browser.newContext({ viewport: { ...session.viewport }, acceptDownloads: false, locale: STEALTH_LOCALE }))
1359
+ .then(async (context) => { await hardenContext(context); await guardExternalApps(context); session.context = context; return context; });
1092
1360
  return await session.contextTask;
1093
1361
  }
1094
1362
  async openTab(sessionId, url, signal) {
@@ -1193,6 +1461,9 @@ export class BrowserViewManager {
1193
1461
  }
1194
1462
  session.activeTabId = tab.id;
1195
1463
  this.publishTabs(sessionId, session);
1464
+ // The profile now has a real page keeping the window alive: leftover launch
1465
+ // blanks can go. Awaited so the close is settled before the open reports.
1466
+ await this.drainPendingBlanks(session.profileKey === undefined ? undefined : this.profiles.get(session.profileKey));
1196
1467
  try {
1197
1468
  await page.goto(target, { waitUntil: 'domcontentloaded', timeout: VIEW_GOTO_TIMEOUT_MS });
1198
1469
  }
@@ -0,0 +1,81 @@
1
+ import type { Tool } from './types.js';
2
+ /** The built-in skill that interviews the user; a run that carries it also gets the tool below. */
3
+ export declare const BUG_REPORT_SKILL = "andorra:bug-report";
4
+ export declare const BUG_REPORT_TOOL = "submit_bug_report";
5
+ export declare const SEND_CHOICE = "Send report";
6
+ export declare const CANCEL_CHOICE = "Do not send";
7
+ /** The report's text fields with the byte limits the service enforces (infra/andorra-auth/bug_report.py). */
8
+ declare const FIELDS: readonly [{
9
+ readonly name: "title";
10
+ readonly required: true;
11
+ readonly limit: 120;
12
+ readonly heading: "Title";
13
+ }, {
14
+ readonly name: "description";
15
+ readonly required: true;
16
+ readonly limit: 4000;
17
+ readonly heading: "What happened";
18
+ }, {
19
+ readonly name: "steps";
20
+ readonly required: false;
21
+ readonly limit: 2000;
22
+ readonly heading: "Steps to reproduce";
23
+ }, {
24
+ readonly name: "expected";
25
+ readonly required: false;
26
+ readonly limit: 1000;
27
+ readonly heading: "Expected";
28
+ }, {
29
+ readonly name: "actual";
30
+ readonly required: false;
31
+ readonly limit: 2000;
32
+ readonly heading: "Actual";
33
+ }];
34
+ type FieldName = typeof FIELDS[number]['name'];
35
+ export type BugReport = {
36
+ title: string;
37
+ description: string;
38
+ } & Partial<Record<Exclude<FieldName, 'title' | 'description'>, string>>;
39
+ export interface BugReportEnvironment {
40
+ appVersion?: string;
41
+ surface?: 'cli' | 'desktop';
42
+ os: 'windows' | 'macos' | 'linux' | 'other';
43
+ arch: 'x64' | 'arm64' | 'other';
44
+ }
45
+ export type BugReportFailure = 'signed_out' | 'refused' | 'invalid' | 'limit' | 'unavailable';
46
+ export declare class BugReportError extends Error {
47
+ readonly code: BugReportFailure;
48
+ constructor(code: BugReportFailure, message: string);
49
+ }
50
+ /** The report as it will be sent: trimmed, bounded, and with anything credential-shaped replaced. */
51
+ export declare function normalizeBugReport(args: Record<string, unknown>): BugReport;
52
+ /** Exactly what the user is asked to approve: every field that will be sent, and what is attached. */
53
+ export declare function bugReportPreview(report: BugReport, environment: BugReportEnvironment): string;
54
+ export declare function bugReportEnvironment(env?: NodeJS.ProcessEnv, version?: () => Promise<string | undefined>): Promise<BugReportEnvironment>;
55
+ export interface BugReportDependencies {
56
+ accessToken(signal?: AbortSignal): Promise<string>;
57
+ apiBaseUrl(): string;
58
+ fetch: typeof globalThis.fetch;
59
+ }
60
+ export interface BugReportClient {
61
+ /** Throws `signed_out` unless an Andorra account is signed in on this installation. */
62
+ token(signal?: AbortSignal): Promise<string>;
63
+ submit(report: BugReport, environment: BugReportEnvironment, token: string, signal?: AbortSignal): Promise<{
64
+ reference: string;
65
+ }>;
66
+ }
67
+ export declare function createBugReportClient(deps: BugReportDependencies): BugReportClient;
68
+ /** The shipped client. Sign-in code is loaded on first use, so a run that never reports does not pay for it. */
69
+ export declare const bugReports: BugReportClient;
70
+ export interface BugReportToolOptions {
71
+ client?: BugReportClient;
72
+ environment?: () => Promise<BugReportEnvironment>;
73
+ /** Tells the surface a question is open, the way ask_user does, so the tool clock pauses while it waits. */
74
+ emit?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
75
+ }
76
+ /**
77
+ * Files a bug report with the Andorra team. The report leaves the machine only after the user has read
78
+ * exactly what will be sent and chosen to send it, so the tool refuses on a surface where nobody can answer.
79
+ */
80
+ export declare function bugReportTool(options?: BugReportToolOptions): Tool;
81
+ export {};