@andorra-labs/code 0.1.5 → 0.1.7

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 (224) hide show
  1. package/dist/src/account-presentation.js +3 -3
  2. package/dist/src/agent-execution.d.ts +2 -0
  3. package/dist/src/agent-execution.js +526 -41
  4. package/dist/src/agent-mcp-catalog.d.ts +21 -0
  5. package/dist/src/agent-mcp-catalog.js +40 -0
  6. package/dist/src/agent-mcp.d.ts +36 -3
  7. package/dist/src/agent-mcp.js +114 -45
  8. package/dist/src/app-server/protocol.d.ts +57 -5
  9. package/dist/src/app-server/protocol.js +18 -1
  10. package/dist/src/app-server/workspace.d.ts +9 -1
  11. package/dist/src/app-server/workspace.js +50 -3
  12. package/dist/src/app-server.d.ts +115 -41
  13. package/dist/src/app-server.js +1316 -221
  14. package/dist/src/auth/AuthManager.d.ts +33 -1
  15. package/dist/src/auth/AuthManager.js +138 -10
  16. package/dist/src/auth/callback-page.d.ts +4 -0
  17. package/dist/src/auth/callback-page.js +70 -0
  18. package/dist/src/auth/callback.d.ts +39 -0
  19. package/dist/src/auth/callback.js +146 -22
  20. package/dist/src/auth/index.d.ts +10 -6
  21. package/dist/src/auth/index.js +2 -2
  22. package/dist/src/auth/store.d.ts +142 -3
  23. package/dist/src/auth/store.js +334 -13
  24. package/dist/src/auth/types.d.ts +17 -1
  25. package/dist/src/auth-commands.d.ts +11 -2
  26. package/dist/src/auth-commands.js +14 -7
  27. package/dist/src/automation-runner.d.ts +9 -0
  28. package/dist/src/automation-runner.js +22 -1
  29. package/dist/src/automation-tool.js +18 -3
  30. package/dist/src/automations.d.ts +5 -0
  31. package/dist/src/automations.js +11 -1
  32. package/dist/src/browser-captcha-tool.d.ts +54 -0
  33. package/dist/src/browser-captcha-tool.js +374 -0
  34. package/dist/src/browser-panel-tool.d.ts +7 -0
  35. package/dist/src/browser-panel-tool.js +74 -3
  36. package/dist/src/browser-runner.js +19 -4
  37. package/dist/src/browser-server.js +21 -1
  38. package/dist/src/browser-session.d.ts +16 -0
  39. package/dist/src/browser-session.js +35 -0
  40. package/dist/src/browser-ui/app.js +193 -3
  41. package/dist/src/browser-ui/style.css +15 -1
  42. package/dist/src/browser-view.d.ts +72 -4
  43. package/dist/src/browser-view.js +229 -17
  44. package/dist/src/capabilities.d.ts +9 -3
  45. package/dist/src/capabilities.js +20 -5
  46. package/dist/src/capsolver.d.ts +60 -0
  47. package/dist/src/capsolver.js +101 -0
  48. package/dist/src/claude-provider.d.ts +6 -0
  49. package/dist/src/claude-provider.js +34 -3
  50. package/dist/src/cli-executable.d.ts +33 -0
  51. package/dist/src/cli-executable.js +64 -0
  52. package/dist/src/cli-process.d.ts +47 -0
  53. package/dist/src/cli-process.js +113 -0
  54. package/dist/src/cli-sign-in.d.ts +68 -0
  55. package/dist/src/cli-sign-in.js +224 -0
  56. package/dist/src/cli.js +84 -26
  57. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  58. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  59. package/dist/src/codex-provider.js +12 -0
  60. package/dist/src/coding-tools.d.ts +5 -0
  61. package/dist/src/coding-tools.js +98 -53
  62. package/dist/src/command-output-tap.d.ts +16 -0
  63. package/dist/src/command-output-tap.js +45 -0
  64. package/dist/src/command-screens.js +3 -3
  65. package/dist/src/commands.d.ts +15 -2
  66. package/dist/src/commands.js +14 -13
  67. package/dist/src/completion.d.ts +23 -5
  68. package/dist/src/completion.js +380 -17
  69. package/dist/src/config.d.ts +61 -0
  70. package/dist/src/config.js +276 -12
  71. package/dist/src/context-budget.d.ts +7 -0
  72. package/dist/src/context-budget.js +18 -1
  73. package/dist/src/deadline.js +6 -0
  74. package/dist/src/decision/FactContinuations.d.ts +41 -6
  75. package/dist/src/decision/FactContinuations.js +211 -64
  76. package/dist/src/decision/PreparedSteps.js +3 -1
  77. package/dist/src/decision/checks.d.ts +25 -0
  78. package/dist/src/decision/checks.js +77 -6
  79. package/dist/src/delegation-changes.d.ts +109 -0
  80. package/dist/src/delegation-changes.js +431 -0
  81. package/dist/src/extensions.d.ts +1 -0
  82. package/dist/src/extensions.js +16 -3
  83. package/dist/src/graph-provider-portability.js +2 -2
  84. package/dist/src/graph-quota.d.ts +1 -1
  85. package/dist/src/graph-quota.js +1 -1
  86. package/dist/src/graph-runner.js +35 -21
  87. package/dist/src/graph-selection.d.ts +6 -0
  88. package/dist/src/graph-selection.js +10 -0
  89. package/dist/src/graph-server.d.ts +8 -0
  90. package/dist/src/graph-server.js +76 -6
  91. package/dist/src/graph-sync.d.ts +65 -0
  92. package/dist/src/graph-sync.js +433 -13
  93. package/dist/src/graph-tool.d.ts +52 -0
  94. package/dist/src/graph-tool.js +136 -0
  95. package/dist/src/graph-ui/app.js +272 -50
  96. package/dist/src/graph-ui/controls.js +6 -0
  97. package/dist/src/graph-ui/drafts.js +39 -0
  98. package/dist/src/graph-ui/embed.js +1 -1
  99. package/dist/src/graph-ui/icons.js +1 -0
  100. package/dist/src/graph-ui/index.html +2 -2
  101. package/dist/src/graph-ui/skill-picker.js +242 -0
  102. package/dist/src/graph-ui/studio.css +7 -5
  103. package/dist/src/graph-ui/style.css +65 -12
  104. package/dist/src/graphs.d.ts +60 -5
  105. package/dist/src/graphs.js +191 -37
  106. package/dist/src/grok-provider.d.ts +50 -0
  107. package/dist/src/grok-provider.js +186 -0
  108. package/dist/src/handoffs.d.ts +13 -0
  109. package/dist/src/handoffs.js +31 -1
  110. package/dist/src/hardened-runtime.d.ts +4 -4
  111. package/dist/src/hardened-runtime.js +109 -9
  112. package/dist/src/managed-sign-in.d.ts +38 -0
  113. package/dist/src/managed-sign-in.js +169 -0
  114. package/dist/src/markdown.d.ts +5 -0
  115. package/dist/src/markdown.js +5 -2
  116. package/dist/src/mcp.js +11 -0
  117. package/dist/src/membership.d.ts +8 -1
  118. package/dist/src/membership.js +15 -5
  119. package/dist/src/model-metadata.js +14 -2
  120. package/dist/src/model-override.d.ts +10 -0
  121. package/dist/src/model-override.js +20 -0
  122. package/dist/src/opencode-cli-provider.d.ts +122 -0
  123. package/dist/src/opencode-cli-provider.js +415 -0
  124. package/dist/src/opencode-provider.js +23 -8
  125. package/dist/src/palette.d.ts +2 -0
  126. package/dist/src/palette.js +2 -0
  127. package/dist/src/permissions.d.ts +19 -1
  128. package/dist/src/permissions.js +30 -1
  129. package/dist/src/powershell-pool.d.ts +11 -2
  130. package/dist/src/powershell-pool.js +34 -5
  131. package/dist/src/provider-connection.js +36 -0
  132. package/dist/src/provider-engine.d.ts +2 -1
  133. package/dist/src/provider-engine.js +64 -13
  134. package/dist/src/provider-import.js +6 -1
  135. package/dist/src/provider-keys.d.ts +48 -0
  136. package/dist/src/provider-keys.js +121 -0
  137. package/dist/src/provider-settings.js +22 -3
  138. package/dist/src/providers.d.ts +12 -1
  139. package/dist/src/providers.js +27 -8
  140. package/dist/src/pull-requests.d.ts +123 -20
  141. package/dist/src/pull-requests.js +334 -84
  142. package/dist/src/qa/qa-authorize.js +9 -1
  143. package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
  144. package/dist/src/qa/runtime/ProcessManager.js +16 -0
  145. package/dist/src/react-runtime.js +106 -7
  146. package/dist/src/read-image.d.ts +30 -0
  147. package/dist/src/read-image.js +97 -0
  148. package/dist/src/remote/engine-pool.js +1 -1
  149. package/dist/src/run-progress.js +6 -1
  150. package/dist/src/run-records.d.ts +133 -27
  151. package/dist/src/run-records.js +320 -40
  152. package/dist/src/runtime.d.ts +38 -1
  153. package/dist/src/runtime.js +27 -4
  154. package/dist/src/save-lock.d.ts +11 -0
  155. package/dist/src/save-lock.js +29 -2
  156. package/dist/src/secret-redaction.d.ts +13 -0
  157. package/dist/src/secret-redaction.js +71 -0
  158. package/dist/src/session-summary.d.ts +10 -4
  159. package/dist/src/session-summary.js +14 -7
  160. package/dist/src/sessions.js +8 -2
  161. package/dist/src/shell.js +4 -1
  162. package/dist/src/side-panel.d.ts +1 -1
  163. package/dist/src/side-panel.js +1 -1
  164. package/dist/src/skill-commands.d.ts +2 -0
  165. package/dist/src/skill-commands.js +2 -0
  166. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  167. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  168. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  169. package/dist/src/skills/bundled/graph-manager/SKILL.md +100 -0
  170. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  171. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  172. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  173. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  174. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  175. package/dist/src/skills/bundled/provenance.json +50 -0
  176. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  177. package/dist/src/skills/invocable-skills.d.ts +41 -0
  178. package/dist/src/skills/invocable-skills.js +49 -0
  179. package/dist/src/skills/prompt-skills.d.ts +1 -0
  180. package/dist/src/skills/prompt-skills.js +33 -0
  181. package/dist/src/skills/runtime-skills.d.ts +4 -0
  182. package/dist/src/skills/runtime-skills.js +21 -0
  183. package/dist/src/structured-step.d.ts +55 -0
  184. package/dist/src/structured-step.js +85 -0
  185. package/dist/src/subagent-run.d.ts +1 -1
  186. package/dist/src/subagent-run.js +29 -33
  187. package/dist/src/telemetry/schema.d.ts +2 -2
  188. package/dist/src/telemetry/schema.js +3 -2
  189. package/dist/src/terminal-ui.d.ts +38 -0
  190. package/dist/src/terminal-ui.js +126 -28
  191. package/dist/src/timers.d.ts +21 -2
  192. package/dist/src/timers.js +12 -4
  193. package/dist/src/tool-dependencies.js +4 -0
  194. package/dist/src/tool-names.d.ts +18 -0
  195. package/dist/src/tool-names.js +26 -0
  196. package/dist/src/tools.d.ts +9 -0
  197. package/dist/src/tools.js +159 -20
  198. package/dist/src/trajectory.js +32 -12
  199. package/dist/src/transcript.js +5 -0
  200. package/dist/src/types.d.ts +36 -0
  201. package/dist/src/web-search.d.ts +59 -0
  202. package/dist/src/web-search.js +216 -0
  203. package/docs/agents/README.md +2 -2
  204. package/docs/agents/mcp-server.md +28 -3
  205. package/docs/agents/subagent-mode.md +7 -4
  206. package/docs/concepts/README.md +1 -1
  207. package/docs/concepts/security.md +4 -2
  208. package/docs/getting-started/accounts.md +15 -4
  209. package/docs/getting-started/configure-providers.md +30 -3
  210. package/docs/guides/README.md +1 -0
  211. package/docs/guides/browser.md +12 -0
  212. package/docs/guides/desktop-app.md +11 -4
  213. package/docs/guides/graph-builder.md +9 -1
  214. package/docs/guides/web-search.md +47 -0
  215. package/docs/reference/cli.md +4 -3
  216. package/docs/reference/config.md +4 -4
  217. package/docs/reference/slash-commands.md +2 -1
  218. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  219. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
  220. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  221. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  222. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
  223. package/package.json +1 -1
  224. package/tests/permissions-test-plan.md +2 -1
@@ -103,6 +103,30 @@ export declare function frameGate(now: number, lastEmittedAt: number | undefined
103
103
  * locations. The probe reads the filesystem and never launches anything.
104
104
  */
105
105
  export declare function channelCandidate(channel: BrowserViewChannel, platform: NodeJS.Platform, chromiumExecutable: () => string): string | undefined;
106
+ /**
107
+ * Where a session's panel browser keeps its state.
108
+ *
109
+ * `project` is the project's persistent profile — cookies, storage, history and
110
+ * cache survive restarts and are shared by every session of that project.
111
+ * `incognito` is a throwaway browser the agent asked for, and `isolated` is the
112
+ * same throwaway browser used when no project profile is available (no
113
+ * resolver, or another process already holds the profile folder).
114
+ */
115
+ export type BrowserViewProfileKind = 'project' | 'incognito' | 'isolated';
116
+ /** A project's persistent profile: an opaque key and the folder Chromium keeps it in. */
117
+ export interface BrowserViewProfile {
118
+ key: string;
119
+ directory: string;
120
+ }
121
+ export interface BrowserViewOptions {
122
+ /** The project profile a session's panel browser persists into; `undefined` keeps it isolated. */
123
+ profileFor?: (sessionId: string) => Promise<BrowserViewProfile | undefined>;
124
+ /** Tests supply a fake persistent context; production launches Chromium on the folder. */
125
+ launchProfile?: (directory: string, viewport: {
126
+ width: number;
127
+ height: number;
128
+ }) => Promise<any>;
129
+ }
106
130
  export type BrowserViewEmit = (event: string, data: Record<string, unknown>) => void;
107
131
  /**
108
132
  * One engine's panel browsers: a browser per session, a page per tab, and a CDP
@@ -112,6 +136,7 @@ export type BrowserViewEmit = (event: string, data: Record<string, unknown>) =>
112
136
  export declare class BrowserViewManager {
113
137
  private readonly emit;
114
138
  private readonly launchBrowser?;
139
+ private readonly options;
115
140
  private readonly sessions;
116
141
  /**
117
142
  * The pane's standing stream request per session, kept before a browser exists.
@@ -139,8 +164,16 @@ export declare class BrowserViewManager {
139
164
  * deleted session can never reach, or else it would hold a slot for good.
140
165
  */
141
166
  private readonly released;
167
+ /** Project profiles open now, by profile key. */
168
+ private readonly profiles;
169
+ /**
170
+ * Sessions whose panel browser is (or is about to be) incognito. The mark
171
+ * lives exactly as long as that browser: it is cleared when the browser
172
+ * closes, so the next open returns to the project profile.
173
+ */
174
+ private readonly incognito;
142
175
  private closed;
143
- constructor(emit: BrowserViewEmit, launchBrowser?: (() => Promise<any>) | undefined);
176
+ constructor(emit: BrowserViewEmit, launchBrowser?: (() => Promise<any>) | undefined, options?: BrowserViewOptions);
144
177
  private publishRuntime;
145
178
  /**
146
179
  * Probe the same executables `launch` will use, without launching anything;
@@ -155,6 +188,24 @@ export declare class BrowserViewManager {
155
188
  */
156
189
  install(): Promise<BrowserRuntimeStatus>;
157
190
  private launch;
191
+ /** Launch Chromium on a project's profile folder, with the same candidates as `launch`. */
192
+ private launchPersistent;
193
+ /**
194
+ * Join the project's shared profile browser, launching it for the first session.
195
+ *
196
+ * A profile that is still closing is waited out rather than reopened beside it:
197
+ * two processes on one profile folder is exactly what Chromium refuses.
198
+ */
199
+ private acquireProfile;
200
+ /** Leave a project's profile; the last session out closes it, which flushes cookies to disk. */
201
+ private releaseProfile;
202
+ /**
203
+ * Open the browser a new session's pages will live in: its project's profile,
204
+ * or a throwaway browser when the session is incognito or has no usable profile.
205
+ */
206
+ private openBrowserFor;
207
+ /** Close a session's browser, or only its pages when they live in a shared project profile. */
208
+ private disposeBrowser;
158
209
  private summary;
159
210
  private publishTabs;
160
211
  private scheduleIdleClose;
@@ -214,14 +265,30 @@ export declare class BrowserViewManager {
214
265
  /**
215
266
  * The session's browser context, created once.
216
267
  *
217
- * One context per session is what makes the tabs one browser: cookies, local
218
- * storage and cache are shared across the session's pages, and sessions stay
219
- * isolated from each other.
268
+ * One context is what makes the tabs one browser: cookies, local storage and
269
+ * cache are shared across the pages in it. A project session's context is its
270
+ * project's persistent profile, shared with that project's other sessions; an
271
+ * incognito or isolated session gets a fresh context of its own.
220
272
  */
221
273
  private contextFor;
222
274
  openTab(sessionId: string, url: string, signal?: AbortSignal): Promise<{
223
275
  tabId: string;
224
276
  }>;
277
+ /**
278
+ * Replace the session's panel browser with an incognito one showing a blank tab.
279
+ *
280
+ * The current browser closes first — its tabs go with it, and a project
281
+ * profile it used is left untouched on disk. Nothing the incognito browser
282
+ * does is saved, and it lasts until `endIncognito` or until it closes.
283
+ */
284
+ startIncognito(sessionId: string, signal?: AbortSignal): Promise<{
285
+ tabId: string;
286
+ }>;
287
+ /** Close the session's incognito browser, if it has one; the next open uses the project profile. */
288
+ endIncognito(sessionId: string, signal?: AbortSignal): Promise<boolean>;
289
+ /** The kind of browser the session's pages live in now, or would on the next open. */
290
+ profileKind(sessionId: string): BrowserViewProfileKind | undefined;
291
+ private openPage;
225
292
  /**
226
293
  * Remove one tab an open created and did not finish.
227
294
  *
@@ -334,6 +401,7 @@ export declare class BrowserViewManager {
334
401
  sessionSummaries(): Record<string, {
335
402
  tabs: BrowserViewTab[];
336
403
  activeTabId?: string;
404
+ profile: BrowserViewProfileKind;
337
405
  }>;
338
406
  /**
339
407
  * Release one session's panel browser now.
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { existsSync } from 'node:fs';
4
+ import { mkdir } from 'node:fs/promises';
4
5
  import { dirname, join } from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
6
7
  import { observePage, observationResult } from './browser-observation.js';
@@ -266,6 +267,8 @@ export function channelCandidate(channel, platform, chromiumExecutable) {
266
267
  ? ['/usr/bin/microsoft-edge', '/usr/bin/microsoft-edge-stable'].find(existsSync)
267
268
  : ['/usr/bin/google-chrome', '/usr/bin/google-chrome-stable'].find(existsSync);
268
269
  }
270
+ /** How long closing a profile may take: a graceful close is what flushes cookies to disk. */
271
+ const PROFILE_CLOSE_TIMEOUT_MS = 5_000;
269
272
  /**
270
273
  * One engine's panel browsers: a browser per session, a page per tab, and a CDP
271
274
  * screencast relay per active tab. Everything is keyed by the saved session id —
@@ -274,6 +277,7 @@ export function channelCandidate(channel, platform, chromiumExecutable) {
274
277
  export class BrowserViewManager {
275
278
  emit;
276
279
  launchBrowser;
280
+ options;
277
281
  sessions = new Map();
278
282
  /**
279
283
  * The pane's standing stream request per session, kept before a browser exists.
@@ -301,10 +305,19 @@ export class BrowserViewManager {
301
305
  * deleted session can never reach, or else it would hold a slot for good.
302
306
  */
303
307
  released = new Set();
308
+ /** Project profiles open now, by profile key. */
309
+ profiles = new Map();
310
+ /**
311
+ * Sessions whose panel browser is (or is about to be) incognito. The mark
312
+ * lives exactly as long as that browser: it is cleared when the browser
313
+ * closes, so the next open returns to the project profile.
314
+ */
315
+ incognito = new Set();
304
316
  closed = false;
305
- constructor(emit, launchBrowser) {
317
+ constructor(emit, launchBrowser, options = {}) {
306
318
  this.emit = emit;
307
319
  this.launchBrowser = launchBrowser;
320
+ this.options = options;
308
321
  }
309
322
  publishRuntime(status) {
310
323
  this.runtime = status;
@@ -440,8 +453,123 @@ export class BrowserViewManager {
440
453
  }
441
454
  throw new Error(`Browser runtime is not usable: ${failures.join('; ').slice(0, 1000)}`);
442
455
  }
456
+ /** Launch Chromium on a project's profile folder, with the same candidates as `launch`. */
457
+ async launchPersistent(directory, viewport) {
458
+ if (this.options.launchProfile)
459
+ return await this.options.launchProfile(directory, viewport);
460
+ await mkdir(directory, { recursive: true });
461
+ const { chromium } = await import('playwright-core');
462
+ const failures = [];
463
+ for (const channel of ['chromium', 'msedge', 'chrome']) {
464
+ if (this.closed)
465
+ throw new Error('Application is shutting down');
466
+ const candidate = channelCandidate(channel, process.platform, () => chromium.executablePath());
467
+ if (!candidate || !existsSync(candidate))
468
+ continue;
469
+ try {
470
+ return await chromium.launchPersistentContext(directory, { ...viewLaunchOptions(channel, candidate), viewport: { ...viewport }, acceptDownloads: false });
471
+ }
472
+ catch (error) {
473
+ failures.push((error instanceof Error ? error.message : String(error)).split('\n')[0]);
474
+ }
475
+ }
476
+ throw new Error(`Project browser profile is not usable: ${failures.join('; ').slice(0, 1000)}`);
477
+ }
478
+ /**
479
+ * Join the project's shared profile browser, launching it for the first session.
480
+ *
481
+ * A profile that is still closing is waited out rather than reopened beside it:
482
+ * two processes on one profile folder is exactly what Chromium refuses.
483
+ */
484
+ async acquireProfile(owner, profile, viewport) {
485
+ for (;;) {
486
+ const current = this.profiles.get(profile.key);
487
+ if (current?.closing) {
488
+ await current.closing;
489
+ continue;
490
+ }
491
+ const host = current ?? { users: new Set() };
492
+ if (!current)
493
+ this.profiles.set(profile.key, host);
494
+ host.users.add(owner);
495
+ host.starting ??= this.launchPersistent(profile.directory, viewport).then(async (context) => {
496
+ // A persistent launch opens with a blank page of its own; every tab the
497
+ // panel shows is one a session asked for.
498
+ for (const page of context.pages?.() ?? [])
499
+ await Promise.resolve().then(() => page.close()).catch(() => { });
500
+ context.on?.('close', () => { if (this.profiles.get(profile.key) === host)
501
+ this.profiles.delete(profile.key); });
502
+ host.context = context;
503
+ return context;
504
+ });
505
+ try {
506
+ return await host.starting;
507
+ }
508
+ catch (error) {
509
+ // A failed launch is not cached: the next open tries the profile again.
510
+ host.users.delete(owner);
511
+ if (this.profiles.get(profile.key) === host)
512
+ this.profiles.delete(profile.key);
513
+ throw error;
514
+ }
515
+ }
516
+ }
517
+ /** Leave a project's profile; the last session out closes it, which flushes cookies to disk. */
518
+ async releaseProfile(key, owner) {
519
+ const host = this.profiles.get(key);
520
+ if (!host)
521
+ return;
522
+ host.users.delete(owner);
523
+ if (host.users.size > 0)
524
+ return;
525
+ host.closing ??= (async () => {
526
+ const context = host.context ?? await host.starting?.catch(() => undefined);
527
+ await Promise.race([
528
+ Promise.resolve().then(() => context?.close()).catch(() => { }),
529
+ new Promise(resolve => { const timer = setTimeout(resolve, PROFILE_CLOSE_TIMEOUT_MS); timer.unref?.(); }),
530
+ ]);
531
+ if (this.profiles.get(key) === host)
532
+ this.profiles.delete(key);
533
+ })();
534
+ await host.closing;
535
+ }
536
+ /**
537
+ * Open the browser a new session's pages will live in: its project's profile,
538
+ * or a throwaway browser when the session is incognito or has no usable profile.
539
+ */
540
+ async openBrowserFor(sessionId, viewport) {
541
+ if (!this.incognito.has(sessionId)) {
542
+ const profile = this.options.profileFor ? await this.options.profileFor(sessionId).catch(() => undefined) : undefined;
543
+ if (profile) {
544
+ try {
545
+ const owner = {};
546
+ const context = await this.acquireProfile(owner, profile, viewport);
547
+ return { context, profileKey: profile.key, profileOwner: owner, profile: 'project' };
548
+ }
549
+ catch (error) {
550
+ if (this.closed)
551
+ throw error;
552
+ // Another process holds the folder, or the profile cannot be opened: the
553
+ // panel still works, on a throwaway browser that says so.
554
+ }
555
+ }
556
+ }
557
+ return { browser: await this.launch(), profile: this.incognito.has(sessionId) ? 'incognito' : 'isolated' };
558
+ }
559
+ /** Close a session's browser, or only its pages when they live in a shared project profile. */
560
+ async disposeBrowser(session) {
561
+ if (session.profileKey === undefined || session.profileOwner === undefined) {
562
+ // Playwright transport shutdown is not reliably awaitable; own the
563
+ // rejection and let the browser close land whenever it lands.
564
+ await Promise.resolve().then(() => session.browser?.close()).catch(() => { });
565
+ return;
566
+ }
567
+ await Promise.all([...session.tabs.values()].map(tab => Promise.resolve().then(() => tab.page.close()).catch(() => { })));
568
+ await this.releaseProfile(session.profileKey, session.profileOwner);
569
+ }
443
570
  summary(session) {
444
571
  return {
572
+ profile: session.profile,
445
573
  tabs: [...session.tabs.values()].map(tab => ({ id: tab.id, url: tab.url, title: tab.title, loading: tab.loading })),
446
574
  ...(session.activeTabId ? { activeTabId: session.activeTabId } : {}),
447
575
  };
@@ -801,27 +929,32 @@ export class BrowserViewManager {
801
929
  if (this.closed)
802
930
  throw new Error('Application is shutting down');
803
931
  const starting = (async () => {
804
- const browser = await this.launch();
932
+ const desired = this.desired.get(sessionId);
933
+ const viewport = desired?.viewport ?? clampViewport(undefined, undefined);
934
+ const opened = await this.openBrowserFor(sessionId, viewport);
805
935
  // Shutdown may have finished while the launch was in flight: the browser
806
936
  // that arrived late belongs to nobody, so it is closed here rather than
807
937
  // inserted into a manager that has already visited its sessions.
808
938
  if (this.closed) {
809
- await Promise.resolve().then(() => browser.close()).catch(() => { });
939
+ await this.disposeBrowser({ ...opened, tabs: new Map() });
810
940
  throw new Error('Application is shutting down');
811
941
  }
812
942
  // A release that landed while this launch was in flight has already closed
813
943
  // whatever it found; the browser this launch just produced belongs to the
814
944
  // session that no longer exists, so it goes the same way.
815
945
  if (this.released.delete(sessionId)) {
816
- await Promise.resolve().then(() => browser.close()).catch(() => { });
946
+ await this.disposeBrowser({ ...opened, tabs: new Map() });
817
947
  throw new Error('That session was deleted.');
818
948
  }
819
- const desired = this.desired.get(sessionId);
949
+ // The pane can enable streaming, resize or switch mode while the launch is in
950
+ // flight; those requests found no session to update, so the session takes
951
+ // the request as it stands now, not as it stood when the launch began.
952
+ const current = this.desired.get(sessionId);
820
953
  const session = {
821
- browser, tabs: new Map(), activeTabId: undefined, pendingTabs: 0,
822
- viewport: desired?.viewport ?? clampViewport(undefined, undefined),
823
- mode: desired?.mode ?? 'desktop',
824
- streaming: desired !== undefined, quality: desired?.quality ?? VIEW_STREAM_QUALITY, idleTimer: undefined,
954
+ ...opened, tabs: new Map(), activeTabId: undefined, pendingTabs: 0,
955
+ viewport: current?.viewport ?? viewport,
956
+ mode: current?.mode ?? 'desktop',
957
+ streaming: current !== undefined, quality: current?.quality ?? VIEW_STREAM_QUALITY, idleTimer: undefined,
825
958
  };
826
959
  this.sessions.set(sessionId, session);
827
960
  this.scheduleIdleClose(sessionId, session);
@@ -838,9 +971,10 @@ export class BrowserViewManager {
838
971
  /**
839
972
  * The session's browser context, created once.
840
973
  *
841
- * One context per session is what makes the tabs one browser: cookies, local
842
- * storage and cache are shared across the session's pages, and sessions stay
843
- * isolated from each other.
974
+ * One context is what makes the tabs one browser: cookies, local storage and
975
+ * cache are shared across the pages in it. A project session's context is its
976
+ * project's persistent profile, shared with that project's other sessions; an
977
+ * incognito or isolated session gets a fresh context of its own.
844
978
  */
845
979
  async contextFor(session) {
846
980
  if (session.context)
@@ -851,11 +985,71 @@ export class BrowserViewManager {
851
985
  return await session.contextTask;
852
986
  }
853
987
  async openTab(sessionId, url, signal) {
854
- const target = browserViewUrl(url);
988
+ return await this.openPage(sessionId, browserViewUrl(url), signal);
989
+ }
990
+ /**
991
+ * Replace the session's panel browser with an incognito one showing a blank tab.
992
+ *
993
+ * The current browser closes first — its tabs go with it, and a project
994
+ * profile it used is left untouched on disk. Nothing the incognito browser
995
+ * does is saved, and it lasts until `endIncognito` or until it closes.
996
+ */
997
+ async startIncognito(sessionId, signal) {
998
+ // Wait out every launch for this session, including one an open began while
999
+ // this call was waiting, so nothing registers a project browser behind it.
1000
+ while (this.launching.has(sessionId))
1001
+ await this.launching.get(sessionId).catch(() => undefined);
1002
+ // A switch that was stopped or timed out while waiting must not tear down the
1003
+ // browser the user is using: nothing has been closed yet.
1004
+ signal?.throwIfAborted();
1005
+ // From here to the mark there is no await: the old browser leaves the session
1006
+ // table synchronously, and the mark is set before anything can open another,
1007
+ // so an open that arrives during the teardown launches incognito too.
1008
+ const closing = this.closeSession(sessionId, 'incognito');
1009
+ this.incognito.add(sessionId);
1010
+ await closing;
1011
+ try {
1012
+ signal?.throwIfAborted();
1013
+ return await this.openPage(sessionId, 'about:blank', signal, 'incognito');
1014
+ }
1015
+ catch (error) {
1016
+ // A start that failed or was abandoned (stopped, or past its deadline) must
1017
+ // not leave an incognito browser a later open would land in unannounced:
1018
+ // one that launched but holds no tab is closed, which also clears the mark,
1019
+ // and a browser that never started leaves no mark behind.
1020
+ const session = this.sessions.get(sessionId);
1021
+ if (!session)
1022
+ this.incognito.delete(sessionId);
1023
+ else if (session.profile === 'incognito' && session.tabs.size === 0 && session.pendingTabs === 0)
1024
+ await this.closeSession(sessionId, 'incognito cancelled', session);
1025
+ throw error;
1026
+ }
1027
+ }
1028
+ /** Close the session's incognito browser, if it has one; the next open uses the project profile. */
1029
+ async endIncognito(sessionId, signal) {
1030
+ while (this.launching.has(sessionId))
1031
+ await this.launching.get(sessionId).catch(() => undefined);
1032
+ // An end that was stopped or timed out while a launch finished must not close
1033
+ // the browser afterwards: nothing has changed yet, and the agent was told it failed.
1034
+ signal?.throwIfAborted();
1035
+ const session = this.sessions.get(sessionId);
1036
+ const active = this.incognito.delete(sessionId) || session?.profile === 'incognito';
1037
+ if (session?.profile === 'incognito')
1038
+ await this.closeSession(sessionId, 'incognito ended');
1039
+ return active;
1040
+ }
1041
+ /** The kind of browser the session's pages live in now, or would on the next open. */
1042
+ profileKind(sessionId) {
1043
+ return this.sessions.get(sessionId)?.profile ?? (this.incognito.has(sessionId) ? 'incognito' : undefined);
1044
+ }
1045
+ async openPage(sessionId, target, signal, requireProfile) {
855
1046
  const session = await this.ensureSession(sessionId);
856
1047
  // The launch is the longest wait here, and the one a stop usually arrives
857
1048
  // during: a cancelled call returns before creating a page at all.
858
1049
  signal?.throwIfAborted();
1050
+ // A switch to incognito must never report success on the signed-in profile.
1051
+ if (requireProfile !== undefined && session.profile !== requireProfile)
1052
+ throw new Error(`The panel browser is not ${requireProfile}; retry the switch`);
859
1053
  if (session.closing)
860
1054
  throw new Error('Browser is closing; retry shortly');
861
1055
  // Capacity is reserved before the first await. Stopping the previous
@@ -878,7 +1072,20 @@ export class BrowserViewManager {
878
1072
  await this.stopScreencast(previous);
879
1073
  const context = await this.contextFor(session);
880
1074
  const page = await context.newPage();
881
- const cdp = await page.context().newCDPSession(page);
1075
+ const cdp = await Promise.resolve().then(() => page.context().newCDPSession(page)).catch(async (error) => {
1076
+ await Promise.resolve().then(() => page.close()).catch(() => { });
1077
+ throw error;
1078
+ });
1079
+ // A shared project profile outlives this session: a page whose session
1080
+ // started closing while it was created or attached would otherwise stay
1081
+ // open in it, unowned, because teardown closes only registered tabs. The
1082
+ // check sits directly before registration, with no await between them, so
1083
+ // a teardown that starts afterwards always finds this tab.
1084
+ if (session.closing) {
1085
+ await Promise.resolve().then(() => cdp.detach?.()).catch(() => { });
1086
+ await Promise.resolve().then(() => page.close()).catch(() => { });
1087
+ throw new Error('Browser is closing; retry shortly');
1088
+ }
882
1089
  const tab = this.wireTab(sessionId, session, page, cdp);
883
1090
  // The context was created at the viewport of the first open; a tab opened
884
1091
  // after the pane was resized has to match the pane it will be shown in, or
@@ -1412,14 +1619,18 @@ export class BrowserViewManager {
1412
1619
  // replacement that took its id in the meantime.
1413
1620
  if (expected !== undefined && session !== expected)
1414
1621
  return;
1622
+ // Incognito lasts exactly as long as its browser: once it closes, the next
1623
+ // open returns to the project profile.
1624
+ if (session.profile === 'incognito')
1625
+ this.incognito.delete(sessionId);
1415
1626
  session.closing = (async () => {
1416
1627
  this.sessions.delete(sessionId);
1417
1628
  if (session.idleTimer)
1418
1629
  clearTimeout(session.idleTimer);
1419
1630
  await Promise.all([...session.tabs.values()].map(tab => this.stopScreencast(tab)));
1420
- // Playwright transport shutdown is not reliably awaitable; own the
1421
- // rejection and let the browser close land whenever it lands.
1422
- await Promise.resolve().then(() => session.browser.close()).catch(() => { });
1631
+ // A shared project profile loses only this session's pages; the profile
1632
+ // itself closes when its last session leaves.
1633
+ await this.disposeBrowser(session);
1423
1634
  // A new browser may already hold this session id; its pane has content of
1424
1635
  // its own, so the old generation stays silent.
1425
1636
  if (this.sessions.has(sessionId))
@@ -1445,6 +1656,7 @@ export class BrowserViewManager {
1445
1656
  // Marked before the close, so a launch finishing in between still sees the
1446
1657
  // release; the marker is dropped once no launch can still be holding it.
1447
1658
  this.released.add(sessionId);
1659
+ this.incognito.delete(sessionId);
1448
1660
  try {
1449
1661
  await this.closeSession(sessionId, reason);
1450
1662
  }
@@ -1,9 +1,15 @@
1
- import { type GraphNode } from './graphs.js';
1
+ import { type CommandScope, type GraphNode } from './graphs.js';
2
2
  import type { Tool, ToolContext } from './types.js';
3
3
  /** No command-string heuristics: constrained agents receive structured operations instead of a shell.
4
4
  * QA tools are the one self-declared command surface: they are matched by an explicit
5
5
  * allowlist, gated by node capability AND their declared capability, and serialized by default. */
6
- export declare function capabilityTools(node: GraphNode, tools: Tool[], child?: boolean): Tool[];
7
- export declare function approveOperation(context: ToolContext, name: string, args: Record<string, unknown>): Promise<void>;
6
+ export declare function capabilityTools(node: GraphNode, tools: Tool[], child?: CommandScope): Tool[];
7
+ /**
8
+ * `requireUser` asks a person even under Full Access: the operation stands for something only the
9
+ * user can want, so no permission mode answers it on their behalf. Headless runs still refuse it.
10
+ */
11
+ export declare function approveOperation(context: ToolContext, name: string, args: Record<string, unknown>, options?: {
12
+ requireUser?: boolean;
13
+ }): Promise<void>;
8
14
  /** Fixed Git operations disable diff/textconv, pager and hooks, but remain host processes. */
9
15
  export declare function gitReadTool(): Tool;
@@ -1,4 +1,4 @@
1
- import { permissionMode } from './permissions.js';
1
+ import { permissionMode, assertPlanMutationAllowed } from './permissions.js';
2
2
  import { execFile } from 'node:child_process';
3
3
  import { promisify } from 'node:util';
4
4
  import { effectiveCapabilities, isQaToolName, permitsBuiltInTool } from './graphs.js';
@@ -14,7 +14,7 @@ export function capabilityTools(node, tools, child = false) {
14
14
  if (tool.providerVisible === false)
15
15
  return false;
16
16
  // Task-owned MCP clients keep the parent workspace for their entire lifetime.
17
- // Delegation cannot rebind them safely, even when the child has shell access.
17
+ // Delegation cannot rebind them safely, even for a delegated worktree child with a shell.
18
18
  if (child && tool.capability === 'external')
19
19
  return false;
20
20
  if (allowed && !allowed.some(name => toolNameMatches(name, tool.name)))
@@ -87,12 +87,23 @@ function permits(policy, required) {
87
87
  return policy.deployment === 'allowed';
88
88
  return false;
89
89
  }
90
- export async function approveOperation(context, name, args) {
90
+ /**
91
+ * `requireUser` asks a person even under Full Access: the operation stands for something only the
92
+ * user can want, so no permission mode answers it on their behalf. Headless runs still refuse it.
93
+ */
94
+ export async function approveOperation(context, name, args, options = {}) {
91
95
  context.signal.throwIfAborted();
92
- const liveMode = () => permissionMode(context) === 'full-access' ? 'yolo' : context.approvalMode ?? 'interactive';
96
+ // Structured writes (worktrees, automations, PR changes, etc.) are not covered
97
+ // by the file/shell gate. Only the explicitly read-only Git operations are exempt.
98
+ const assertAllowed = () => { if (name !== 'git_read')
99
+ assertPlanMutationAllowed(context); };
100
+ assertAllowed();
101
+ const liveMode = () => permissionMode(context) === 'full-access' && !options.requireUser ? 'yolo' : context.approvalMode ?? 'interactive';
93
102
  while (true) {
94
103
  context.signal.throwIfAborted();
104
+ assertAllowed();
95
105
  await context.onApprovalEvent?.('node.tool.approval.requested', { name, arguments: args, mode: liveMode() });
106
+ assertAllowed();
96
107
  // A prompt is a human wait: it gets the session signal so a wall clock cannot answer for
97
108
  // the user, matching the built-in tools' path in `tools.ts`.
98
109
  // Audit delivery can yield while the user changes the live permissions mode.
@@ -101,6 +112,7 @@ export async function approveOperation(context, name, args) {
101
112
  while (mode === 'interactive') {
102
113
  answer = await context.approve(name, args, context.userSignal ?? context.signal);
103
114
  context.signal.throwIfAborted();
115
+ assertAllowed();
104
116
  if (answer !== 'policy-changed')
105
117
  break;
106
118
  mode = liveMode();
@@ -109,12 +121,15 @@ export async function approveOperation(context, name, args) {
109
121
  const actor = mode === 'yolo' ? 'yolo-policy' : mode === 'headless' ? 'headless-policy' : 'local-user';
110
122
  await context.onApprovalEvent?.('node.tool.approval.decided', { name, mode, approved, actor });
111
123
  context.signal.throwIfAborted();
124
+ assertAllowed();
112
125
  if (!approved)
113
126
  throw new Error('Permission denied');
114
127
  // Policy grants can be revoked during either audit await. An explicit user's
115
128
  // approval remains scoped to this operation; automatic approval must stay live.
116
- if (mode !== 'yolo' || liveMode() === mode)
129
+ if (mode !== 'yolo' || liveMode() === mode) {
130
+ assertAllowed();
117
131
  return;
132
+ }
118
133
  }
119
134
  }
120
135
  /** Fixed Git operations disable diff/textconv, pager and hooks, but remain host processes. */
@@ -0,0 +1,60 @@
1
+ import type { Config } from './config.js';
2
+ /**
3
+ * A small CapSolver client: create a task, then poll its result.
4
+ *
5
+ * Only the proxyless task types the browser solve tool uses are modelled. The API key never leaves
6
+ * this module except in the request body sent to CapSolver; error messages never include it.
7
+ */
8
+ export declare const CAPSOLVER_ENV = "CAPSOLVER_API_KEY";
9
+ export type CapsolverTask = {
10
+ type: 'ReCaptchaV2TaskProxyLess' | 'ReCaptchaV2EnterpriseTaskProxyLess';
11
+ websiteURL: string;
12
+ websiteKey: string;
13
+ isInvisible?: boolean;
14
+ pageAction?: string;
15
+ recaptchaDataSValue?: string;
16
+ enterprisePayload?: Record<string, string>;
17
+ } | {
18
+ type: 'ReCaptchaV3TaskProxyLess' | 'ReCaptchaV3EnterpriseTaskProxyLess';
19
+ websiteURL: string;
20
+ websiteKey: string;
21
+ pageAction?: string;
22
+ } | {
23
+ type: 'AntiTurnstileTaskProxyLess';
24
+ websiteURL: string;
25
+ websiteKey: string;
26
+ metadata?: {
27
+ action?: string;
28
+ cdata?: string;
29
+ };
30
+ } | {
31
+ type: 'ImageToTextTask';
32
+ body: string;
33
+ websiteURL?: string;
34
+ module?: string;
35
+ };
36
+ export interface CapsolverKey {
37
+ key: string;
38
+ source: 'config' | 'env';
39
+ }
40
+ /** The key the solve tool uses: the saved one, otherwise the environment's. */
41
+ export declare function resolveCapsolverKey(config: Pick<Config, 'browser'> | undefined, env?: NodeJS.ProcessEnv): CapsolverKey | undefined;
42
+ /**
43
+ * Where requests go. `ANDORRA_CAPSOLVER_BASE_URL` exists so a local stub can stand in for the
44
+ * service during verification; it must be HTTPS, or HTTP on a loopback address, so a stray setting
45
+ * cannot send the key in the clear.
46
+ */
47
+ export declare function capsolverBaseUrl(env?: NodeJS.ProcessEnv): string;
48
+ export declare class CapsolverError extends Error {
49
+ readonly code?: string | undefined;
50
+ constructor(message: string, code?: string | undefined);
51
+ }
52
+ export interface CapsolverOptions {
53
+ signal: AbortSignal;
54
+ fetch?: typeof fetch;
55
+ baseUrl?: string;
56
+ pollIntervalMs?: number;
57
+ timeoutMs?: number;
58
+ }
59
+ /** Solve one task and return CapSolver's `solution` object. */
60
+ export declare function solveCapsolverTask(key: string, task: CapsolverTask, options: CapsolverOptions): Promise<Record<string, unknown>>;