Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/skills/debug-standalone-agent-browser/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ agent-browser --session <outer-session> eval '(()=>{var ta=document.querySelecto
The screencast canvas forwards real pointer events to the nested page, and the nested page viewport is **1:1 with the canvas intrinsic size**, so mapping is just an offset:

1. Get the outer canvas box: `agent-browser --session <outer-session> eval '(()=>{var c=document.querySelector("canvas");var r=c.getBoundingClientRect();return JSON.stringify({x:r.x,y:r.y,iw:c.width,ih:c.height})})()'`
2. Find the link's center in the **nested** session DOM (the real page): `agent-browser --session dormouse.1.default eval '(()=>{var a=[...document.querySelectorAll("a")].find(x=>/github\.com/i.test(x.href));var r=a.getBoundingClientRect();return JSON.stringify({cx:r.x+r.width/2,cy:r.y+r.height/2})})()'`
2. Find the link's center in the **nested** session DOM (the real page): `agent-browser --session dormouse_1_default eval '(()=>{var a=[...document.querySelectorAll("a")].find(x=>/github\.com/i.test(x.href));var r=a.getBoundingClientRect();return JSON.stringify({cx:r.x+r.width/2,cy:r.y+r.height/2})})()'`
3. Outer click point = `canvas.x + nested.cx`, `canvas.y + nested.cy`. Click with move → down → up, and **dwell ~0.1–0.2s between down and up** — a too-fast click on an *idle* (quiet) daemon does not register:

```sh
agent-browser --session <outer-session> mouse move <X> <Y>
agent-browser --session <outer-session> mouse down ; sleep 0.12 ; agent-browser --session <outer-session> mouse up
```

Confirm the click landed against the **real** daemon, not just the panel: `agent-browser --session dormouse.1.default tab list`.
Confirm the click landed against the **real** daemon, not just the panel: `agent-browser --session dormouse_1_default tab list`.

## Timing Pattern

Expand Down
8 changes: 4 additions & 4 deletions docs/specs/dor-browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ Source of truth: `browserLaunchEnv` in `lib/src/host/browser-launch-env.ts`, `cr

### Managed identity

- **Must match `--key <name>` against `[A-Za-z0-9._-]+`**, since it becomes part of a session name and so a filesystem path; the default is `--key default`. Identity-flag exclusivity: `docs/specs/dor-cli.md` → "Browser Surface Addressing".
- **Must match `--key <name>` against `[A-Za-z0-9_-]+`**, since it becomes part of a session name, which agent-browser holds to those characters (rationale); the default is `--key default`. Identity-flag exclusivity: `docs/specs/dor-cli.md` → "Browser Surface Addressing".
- **Must resolve a key to the Surface of that provider holding it in the answering Wall**, whose stored binding — session, cwd, executable — the command runs with, so a Surface keeps its session however keys were named when it was made.
- **Must mint a key no Surface holds as `dormouse.<scope>.<name>`**, scoped by the id of the Workspace that will hold the browser, so a strip reorder renames nothing; **Must scrub every character outside `[A-Za-z0-9._-]` from scope and key**, the id's `:` included, since the name becomes a filesystem path (`workspace:3` → `dormouse.workspace-3.<name>`). **Must give a bare Wall (a VS Code webview, Pocket), which has no Workspace id, a scope of its own for its life**, so two webviews' `--key default` are two browsers (rationale). A key's concurrent first commands share one reservation of the caller's cwd and executable (`BrowserBindingReservations`). **Never mint a session a Surface anywhere in the Window holds, or the provider's reservation of another key**: take the first free `.2`, `.3`, … suffix (rationale).
- **Must let only the answering Workspace name a key**, so `dor` resolves it host-side (`docs/specs/dor-cli.md` → "Browser Surface Addressing") and names `dormouse.1.<name>` itself only with no control endpoint at all, outside Dormouse, where `dor` is a pure passthrough. **Never fall back CLI-side when the host refuses a managed invocation**, a passthrough verb included: that would name the wrong Workspace's browser, so the refusal fails the command before the binary runs (`docs/specs/dor-cli.md` → "Handle Model").
- **Must name GUI-spawned sessions `dormouse.1.gui-<hex>`, minted host-wide**, which no `--key` names; `--surface <handle>` reaches them. **Must answer only for a Surface its provider renders**: an `iframe` Surface has no session to drive.
- **Must mint a key no Surface holds as `dormouse_<scope>_<name>`**, scoped by the id of the Workspace that will hold the browser, so a strip reorder renames nothing; **Must scrub every character outside `[A-Za-z0-9_-]` from scope and key**, the id's `:` included (`workspace:3` → `dormouse_workspace-3_<name>`). **Must give a bare Wall (a VS Code webview, Pocket), which has no Workspace id, a scope of its own for its life**, so two webviews' `--key default` are two browsers (rationale). A key's concurrent first commands share one reservation of the caller's cwd and executable (`BrowserBindingReservations`). **Never mint a session a Surface anywhere in the Window holds, or the provider's reservation of another key**: take the first free `_2`, `_3`, … suffix (rationale).
- **Must let only the answering Workspace name a key**, so `dor` resolves it host-side (`docs/specs/dor-cli.md` → "Browser Surface Addressing") and names `dormouse_1_<name>` itself only with no control endpoint at all, outside Dormouse, where `dor` is a pure passthrough. **Never fall back CLI-side when the host refuses a managed invocation**, a passthrough verb included: that would name the wrong Workspace's browser, so the refusal fails the command before the binary runs (`docs/specs/dor-cli.md` → "Handle Model").
- **Must name GUI-spawned sessions `dormouse_1_gui-<hex>`, minted host-wide**, which no `--key` names; `--surface <handle>` reaches them. **Must answer only for a Surface its provider renders**: an `iframe` Surface has no session to drive.
- **Must map one browser to one Surface window-wide**, found by its host-reported native identity (agent-browser: the session; Playwright: installation, project scope and session, which a raw `--session` shares across one project's subdirectories). A command for a browser that has a Surface hands its stream over, refreshes `binaryPath` and reuses the pane — not an invariant: a Surface killed or render-swapped mid-command lets the trailing request mint a fresh pane; a killed `--surface` fails it (rationale).

Source of truth: `sessionForKey` in `dor-lib-common/src/browser-providers.ts`, `runBrowserCli` in `dor/src/commands/browser-cli.ts`, `BrowserBindingReservations` in `lib/src/components/wall/browser-binding-reservations.ts`, `ensureBrowserSurface` in `lib/src/components/wall/use-dor-control.ts`.
Expand Down
6 changes: 4 additions & 2 deletions docs/specs/dor-browser.rationale.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ Viewport preparation with agent-browser 0.27.0 (Windows, 2026-10-21): dropping `

**Why one-session-one-surface is not an invariant.** `dor` forwards the user's command before it asks the host for a surface, so a surface killed or render-swapped inside that window is gone by the time the trailing request arrives — and the session behind it is still live and needs somewhere to render.

**Why a bare Wall mints its own key scope.** Every VS Code webview is a bare Wall, and each named `--key default` `dormouse.1.default`: two webviews' default browsers were one browser behind two Surfaces, and killing either closed it under the other. Playwright had avoided it with random session names and a reservation; one deterministic scheme with a scope unique per bare Wall covers both, and needs no migration because a key finds its Surface's stored session first (review of the browser stack, 2026-09).
**Why session names use `_`, not `.`.** Session names were `dormouse.<scope>.<key>` until agent-browser 0.41.1 (2026-11-01) began refusing any `--session` outside letters, digits, `-` and `_` before starting a browser (upstream `validate session names before use`, #2272): every pane then failed to open and fell back to an iframe. Every earlier release accepts `_`.

**Why a key numbers past sessions held elsewhere.** A key's session is `dormouse.<scope>.<name>`, and the key lookup searches only the answering Wall. A pane bound to that session which left for another Workspace keeps it, so the same command here bound a second pane to the same browser, and closing either closed the other's (review of #777, 2026-09). Playwright keys had minted a fresh UUID each, so this was new there; agent-browser keys always worked this way.
**Why a bare Wall mints its own key scope.** Every VS Code webview is a bare Wall, and each named `--key default` `dormouse_1_default`: two webviews' default browsers were one browser behind two Surfaces, and killing either closed it under the other. Playwright had avoided it with random session names and a reservation; one deterministic scheme with a scope unique per bare Wall covers both, and needs no migration because a key finds its Surface's stored session first (review of the browser stack, 2026-09).

**Why a key numbers past sessions held elsewhere.** A key's session is `dormouse_<scope>_<name>`, and the key lookup searches only the answering Wall. A pane bound to that session which left for another Workspace keeps it, so the same command here bound a second pane to the same browser, and closing either closed the other's (review of #777, 2026-09). Playwright keys had minted a fresh UUID each, so this was new there; agent-browser keys always worked this way.

**Why a bind for a session another Workspace shows is answered there (2026-11).** A raw `--session` names no key, so nothing above steered it, and the bind looked only in the caller's Wall: a session whose pane sat in another Workspace got a second pane in the caller's, and closing either closed the other's. The bind now hands the request to the Wall that shows the session, by the same Window-wide session list a key's reservation reads.

Expand Down
2 changes: 1 addition & 1 deletion docs/specs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Use glossary names instead. A left-column term retains meaning only where noted.
| **reconnect** | Retired: live-PTY case → **resume**; cold start → **restore**. |
| **restore** | Keeps its cold-start rehydrate meaning. Never for Door→Pane (**reattach**), a closed Surface's rebuild (**reopen**), or alert-manager seeding (**seed**). |
| **attach** | Retired at the DOM layer (`attachTerminal`) → **mount**; user-level **reattach** (Door→Pane) keeps the `re-` prefix. |
| **session** | The durable identity of a **terminal Surface**. Never for the Activity projection (`ActivityState`, not `SessionUiState`), nor for a browser provider's lowercase `session` string (`dormouse.<scope>.<key>`) — not a Dormouse durable unit. |
| **session** | The durable identity of a **terminal Surface**. Never for the Activity projection (`ActivityState`, not `SessionUiState`), nor for a browser provider's lowercase `session` string (`dormouse_<scope>_<key>`) — not a Dormouse durable unit. |
| **terminal** | Keeps its meaning for the `xterm.Terminal` instance; prose meaning "the whole thing" is **Session**. |
| **surface** | Not retired. **Session** names only the terminal kind; **Surface** covers both. |
| **panel / pane / leaf** | Prefer **pane** for the layout slot; **leaf** is Lath's tree node for it (1:1). "panel" survives only in React component names (`TerminalPanel`, `BrowserPanel`, `IframePanel`, `AgentBrowserPanel`). |
Expand Down
14 changes: 7 additions & 7 deletions dor-lib-common/src/browser-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BARE_WALL_SCOPE = '1';
// A session name becomes a filesystem path (the daemon's socket dir), so both
// halves are held to the charset `dor agent-browser --key` enforces CLI-side: the key
// arrives over the control socket too, from clients that are not `dor`.
const UNSAFE_SESSION_CHARS = /[^A-Za-z0-9._-]/g;
const UNSAFE_SESSION_CHARS = /[^A-Za-z0-9_-]/g;

/** Env var that overrides which agent-browser binary to run; shared so `dor agent-browser`
* and the host key off the same name. */
Expand Down Expand Up @@ -278,19 +278,19 @@ export function isBrowserProvider(value: unknown): value is BrowserAutomationPro
}

/**
* Managed, scoped browser session name, `dormouse.<scope>.<key>`, for either
* Managed, scoped browser session name, `dormouse_<scope>_<key>`, for either
* provider: the host passes the Workspace's id, or the scope a bare Wall mints
* for itself; `dormouse.1.<key>` is what a caller with no host — `dor` outside
* for itself; `dormouse_1_<key>` is what a caller with no host — `dor` outside
* Dormouse — names. The scope is what keeps one `--key default` per Workspace
* from being one shared browser (`docs/specs/dor-browser.md` → Managed
* identity).
*
* agent-browser session names become filesystem paths (the socket dir), so `/`
* can't separate the namespace — the daemon fails to start; dots keep it
* readable. Shared by `dor` (--key outside Dormouse) and the lib host (key
* agent-browser takes only letters, digits, `-` and `_` in a session name
* (from 0.41.1; it rejects a dot before starting anything), so `_` separates
* the namespace. Shared by `dor` (--key outside Dormouse) and the lib host (key
* and GUI sessions).
*/
export function sessionForKey(key: string, workspaceId?: string): string {
const scope = workspaceId ? workspaceId.replace(UNSAFE_SESSION_CHARS, '-') : BARE_WALL_SCOPE;
return `dormouse.${scope}.${key.replace(UNSAFE_SESSION_CHARS, '-')}`;
return `dormouse_${scope}_${key.replace(UNSAFE_SESSION_CHARS, '-')}`;
}
14 changes: 7 additions & 7 deletions dor-lib-common/test/browser-providers.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import assert from 'node:assert/strict';
import { BROWSER_PROVIDER_IDS, BROWSER_PROVIDERS, isAllowedAgentBrowserBinary, isAllowedPlaywrightBinary, parseRenderMode, parseStreamPort, renderModeFor, sessionForKey } from '../dist/browser-providers.js';

test('sessionForKey namespaces a key under the workspace', () => {
assert.equal(sessionForKey('default'), 'dormouse.1.default');
assert.equal(sessionForKey('gui-abc'), 'dormouse.1.gui-abc');
assert.equal(sessionForKey('default'), 'dormouse_1_default');
assert.equal(sessionForKey('gui-abc'), 'dormouse_1_gui-abc');
// A Workspace id's colon is scrubbed: Windows forbids it in the socket path.
assert.equal(sessionForKey('default', 'workspace:3'), 'dormouse.workspace-3.default');
assert.equal(sessionForKey('tool.surface:7'), 'dormouse.1.tool.surface-7');
assert.equal(sessionForKey('default', 'workspace:3'), 'dormouse_workspace-3_default');
assert.equal(sessionForKey('tool.surface:7'), 'dormouse_1_tool-surface-7');
});

test('sessionForKey scrubs the key like the scope: a session name is a socket path', () => {
// The key crosses the control socket from any client, not only `dor` (which
// rejects this shape itself), so it cannot be allowed to escape the socket dir.
assert.equal(sessionForKey('../../../tmp/x', 'ws/1'), 'dormouse.ws-1...-..-..-tmp-x');
assert.equal(sessionForKey('../../../tmp/x', 'ws/1'), 'dormouse_ws-1_---------tmp-x');
// A valid key is unchanged.
assert.equal(sessionForKey('a.b_c-D9', 'ws'), 'dormouse.ws.a.b_c-D9');
assert.equal(sessionForKey('a.b_c-D9', 'ws'), 'dormouse_ws_a-b_c-D9');
});

test('parseRenderMode decodes every automated mode and renderModeFor inverts it', () => {
Expand All @@ -38,7 +38,7 @@ test('parseRenderMode reads anything else as the embed, inherited names included
test('each provider refuses a session name its CLI would read as an option or a path', () => {
for (const provider of BROWSER_PROVIDER_IDS) {
const { isSessionName } = BROWSER_PROVIDERS[provider];
assert.equal(isSessionName('dormouse.1.default'), true, provider);
assert.equal(isSessionName('dormouse_1_default'), true, provider);
for (const bad of ['../../tmp/evil', 'a/b', 'a\\b', 'a\nb', 'a\u0085b', '', 7]) {
assert.equal(isSessionName(bad), false, `${provider} ${JSON.stringify(bad)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion dor/src/commands/agent-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const agentBrowserCommand: Command = {

dor intercepts exactly three mutually exclusive identity flags:
--key <name> Managed, workspace-scoped browser identity (default "default").
Maps to agent-browser session dormouse.<workspace>.<name>,
Maps to agent-browser session dormouse_<workspace>_<name>,
so the same key in another Workspace is another browser.
--session <name> Attach to a raw agent-browser session by its literal name.
--surface <handle> Drive the browser Surface a handle names (surface:N,
Expand Down
2 changes: 1 addition & 1 deletion dor/src/commands/browser-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { BROWSER_UNBOUND_EXIT, callerWorkingDirectory, errorMessage, fail, requi
import { inferredHttpUrl, isSpecialOpenTarget, isSurfaceOpenTarget, resolveSurfaceOpenTarget } from './open-target.js';
import { callerWslDistro, linuxPathText, windowsPathArgs, type PathArgs } from './wsl-paths.js';

const KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
const KEY_PATTERN = /^[A-Za-z0-9_-]+$/;

/** The three identity flags dor intercepts, in the order they are reported when
* more than one is given. */
Expand Down
2 changes: 1 addition & 1 deletion dor/test/browser-stdin.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for (const provider of ['agent-browser', 'playwright']) {
const result = await runCli([provider, 'open', 'http://localhost:5173'], {
env: { PWD: process.cwd() },
client: {
resolveBrowser: async () => ({ binding: { session: 'dormouse.1.default', cwd: process.cwd() }, fresh: true,
resolveBrowser: async () => ({ binding: { session: 'dormouse_1_default', cwd: process.cwd() }, fresh: true,
initialViewport: { mode: 'fixed', width: 390, height: 844, dpr: 2 },
launchViewport: { width: 390, height: 844, dpr: 2 } }),
browserSurface: async () => ({ surfaceId: 'surface:2', status: 'created' }),
Expand Down
Loading
Loading