The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
feat(ego-browser): expose claimTaskSpace as a public helper
0x084f773fedd0e
diff --git a/AGENTS.md b/AGENTS.mdindex 3b30bf1..661778a 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -24,7 +24,7 @@ Data flow: `stdin JS` → `runMain()` → `helperContext()` helpers → browser## Task SpacesTask spaces are isolated browsing contexts with an ownership model (`agent` / `user`):-- `useOrCreateTaskSpace(nameOrId)` reuses an agent-owned space, claims a user-owned one, or creates a new one. Ids are numeric; prefer `task.id` over names across rounds.+- `useOrCreateTaskSpace(nameOrId)` reuses an agent-owned space or creates a new one; it no longer auto-claims user-owned spaces. Use `claimTaskSpace(nameOrId)` to take ownership of a user-owned space. Ids are numeric; prefer `task.id` over names across rounds.- `switchTaskSpace` requires agent ownership; `newTaskSpace` creates; `completeTaskSpace(nameOrId, { keep })` finishes (`keep` is mandatory).- Control handoff: `handOffTaskSpace` / `takeOverTaskSpace` / `waitForAgentControl`.diff --git a/package/ego-browser/src/helpers.test.mjs b/package/ego-browser/src/helpers.test.mjsindex 192aa15..a84c715 100644--- a/package/ego-browser/src/helpers.test.mjs+++ b/package/ego-browser/src/helpers.test.mjs@@ -3,6 +3,7 @@ import assert from "node:assert/strict";import * as helperExports from "../dist/src/helpers.js";import {+ claimTaskSpace,completeTaskSpace,handOffTaskSpace,newTaskSpace,@@ -92,13 +93,13 @@ test("listTaskSpaces throws on binding error objects", async () => {);});-test("taskspace helper surface exposes public helpers without claimTaskSpace", () => {+test("taskspace helper surface exposes public helpers including claimTaskSpace", () => {const context = helperContext();assert.equal(typeof context.listTaskSpaces, "function");assert.equal(typeof context.switchTaskSpace, "function");assert.equal(typeof context.newTaskSpace, "function");assert.equal(typeof context.useOrCreateTaskSpace, "function");- assert.equal(context.claimTaskSpace, undefined);+ assert.equal(typeof context.claimTaskSpace, "function");assert.equal(typeof helperExports.openOrReuseTab, "function");assert.equal(typeof context.openOrReuseTab, "function");assert.equal(typeof helperExports.closeTab, "function");@@ -318,7 +319,43 @@ test("useOrCreateTaskSpace reuses existing agent-owned spaces", async () => {assert.deepEqual(calls, [["listTaskSpaces"], ["useTaskSpace", 7]]);});-test("useOrCreateTaskSpace claims existing user-owned spaces", async () => {+test("useOrCreateTaskSpace selects user-owned spaces without claiming and surfaces the live native error", async () => {+ const calls = [];+ await withEgo(+ {+ async listTaskSpaces() {+ calls.push(["listTaskSpaces"]);+ return {+ taskSpaces: [+ {+ taskId: "checkout-flow",+ id: 7,+ name: "checkout-flow",+ ownership: "user",+ },+ ],+ };+ },+ async claimTaskSpace(id, name) {+ calls.push(["claimTaskSpace", id, name]);+ return { taskId: name, id, name, ownership: "agent" };+ },+ useTaskSpace(taskId) {+ calls.push(["useTaskSpace", taskId]);+ return { error: "The task is under user control" };+ },+ },+ async () => {+ await assert.rejects(+ () => useOrCreateTaskSpace("checkout-flow"),+ /useOrCreateTaskSpace: The task is under user control/,+ );+ },+ );+ assert.deepEqual(calls, [["listTaskSpaces"], ["useTaskSpace", 7]]);+});++test("claimTaskSpace claims and selects an existing user-owned space", async () => {const calls = [];await withEgo({@@ -345,7 +382,7 @@ test("useOrCreateTaskSpace claims existing user-owned spaces", async () => {},},async () => {- assert.deepEqual(await useOrCreateTaskSpace("checkout-flow"), {+ assert.deepEqual(await claimTaskSpace("checkout-flow"), {taskId: "checkout-flow",id: 7,name: "checkout-flow",@@ -360,6 +397,29 @@ test("useOrCreateTaskSpace claims existing user-owned spaces", async () => {]);});+test("claimTaskSpace throws on an unknown task space", async () => {+ const calls = [];+ await withEgo(+ {+ async listTaskSpaces() {+ calls.push(["listTaskSpaces"]);+ return { taskSpaces: [] };+ },+ async claimTaskSpace(id, name) {+ calls.push(["claimTaskSpace", id, name]);+ return { taskId: name, id, name, ownership: "agent" };+ },+ },+ async () => {+ await assert.rejects(+ () => claimTaskSpace("checkout-flow"),+ /task space not found: checkout-flow/,+ );+ },+ );+ assert.deepEqual(calls, [["listTaskSpaces"]]);+});+test("useOrCreateTaskSpace creates missing spaces", async () => {const calls = [];await withEgo(diff --git a/package/ego-browser/src/helpers.ts b/package/ego-browser/src/helpers.tsindex f62afee..94f372d 100644--- a/package/ego-browser/src/helpers.ts+++ b/package/ego-browser/src/helpers.ts@@ -91,7 +91,7 @@ export async function listTaskSpaces() {* does when the target space is user-owned:** switchTaskSpace -> throws (agent-owned only)- * useOrCreateTaskSpace -> claims it (ownership transfers to the agent)+ * claimTaskSpace -> claims it (ownership transfers to the agent), then selects it* handOffTaskSpace -> skipped, resolves { done: false, skipped: "user-owned" }* completeTaskSpace { keep: true } -> skipped, resolves { done: false, skipped: "user-owned" }* completeTaskSpace { keep: false } -> claims it, then closes it@@ -152,7 +152,9 @@ export async function newTaskSpace(name) {}/**- * Use an existing agent-owned task space, claim an existing user-owned space, or create it when missing.+ * Use an existing agent-owned task space, or create it when missing. User-owned+ * spaces are selected but not claimed (the native bridge surfaces its live+ * user-control error) — call claimTaskSpace(nameOrId) to take ownership.* @param {string|number} nameOrId Task space name or numeric id.* @returns {Promise<{taskId:string,id:number,name:string,createdBy?:string,ownership?:string,recentTabTitles?:string[]}>}*/@@ -169,14 +171,29 @@ export async function useOrCreateTaskSpace(nameOrId) {return selectTaskSpace(globalThis.ego, existing, "useOrCreateTaskSpace");}if (existing.ownership === "user") {- return claimTaskSpace(existing, "useOrCreateTaskSpace");+ // Don't claim user-owned spaces here. Select it and let the native bridge+ // surface its live user-control error verbatim; use claimTaskSpace(nameOrId)+ // to take ownership.+ return selectTaskSpace(globalThis.ego, existing, "useOrCreateTaskSpace");}throw new Error(`useOrCreateTaskSpace cannot use task space ${JSON.stringify(nameOrId)} with ownership ${JSON.stringify(existing.ownership)}`,);}-async function claimTaskSpace(space, op = "claimTaskSpace") {+/**+ * Claim a user-owned task space (ownership transfers to the agent) and select it+ * for the current Node invocation. Resolves the space by id/name, claims it via+ * ego.claimTaskSpace, then selects it.+ * @param {string|number} nameOrId Task space id or name.+ * @returns {Promise<{taskId:string,id:number,name:string,createdBy?:string,ownership?:string,recentTabTitles?:string[]}>}+ */+export async function claimTaskSpace(nameOrId) {+ const space = await findTaskSpace(nameOrId);+ return claimResolvedTaskSpace(space, "claimTaskSpace");+}++async function claimResolvedTaskSpace(space, op = "claimTaskSpace") {const ego = globalThis.ego;if (!ego || typeof ego.claimTaskSpace !== "function") {throw new Error(`${op} requires ego.claimTaskSpace`);@@ -254,7 +271,7 @@ export async function completeTaskSpace(assertNoEgoError(await ego.completeTaskSpace(), "completeTaskSpace");} else {if (match.ownership === "user") {- await claimTaskSpace(match, "completeTaskSpace");+ await claimResolvedTaskSpace(match, "completeTaskSpace");} else {await selectTaskSpace(ego, match, "completeTaskSpace");}@@ -489,6 +506,7 @@ export function helperContext(extra: any = {}) {switchTaskSpace,newTaskSpace,useOrCreateTaskSpace,+ claimTaskSpace,completeTaskSpace,handOffTaskSpace,takeOverTaskSpace,diff --git a/package/ego-browser/src/taskspace-e2e.test.mjs b/package/ego-browser/src/taskspace-e2e.test.mjsindex fe7c90e..825b2af 100644--- a/package/ego-browser/src/taskspace-e2e.test.mjs+++ b/package/ego-browser/src/taskspace-e2e.test.mjs@@ -27,6 +27,10 @@ class FakeEgo {throw new TypeError("useTaskSpace requires numeric id");}this.calls.push(["useTaskSpace", id]);+ const space = this.taskSpaces.find((candidate) => candidate.id === id);+ if (space && space.ownership === "user") {+ return { error: "The task is under user control" };+ }this.selectedId = id;return id;}@@ -184,7 +188,7 @@ test("taskspace e2e claims and selects an existing user-owned task space", asyncconst result = await runTaskspaceScript(ego,`- const task = await useOrCreateTaskSpace("checkout-flow");+ const task = await claimTaskSpace("checkout-flow");cliLog(JSON.stringify({ task, selected: ego.selectedId }));`,);@@ -207,7 +211,26 @@ test("taskspace e2e claims and selects an existing user-owned task space", async]);});-test("taskspace e2e exposes newTaskSpace but not claimTaskSpace as a helper", async () => {+test("taskspace e2e useOrCreateTaskSpace selects user-owned spaces without claiming and surfaces the live native error", async () => {+ const ego = new FakeEgo([+ {+ taskId: "checkout-flow",+ id: 7,+ name: "checkout-flow",+ createdBy: "user",+ ownership: "user",+ },+ ]);++ await assert.rejects(+ () =>+ runTaskspaceScript(ego, `await useOrCreateTaskSpace("checkout-flow")`),+ /The task is under user control/,+ );+ assert.deepEqual(ego.calls, [["listTaskSpaces"], ["useTaskSpace", 7]]);+});++test("taskspace e2e exposes newTaskSpace and claimTaskSpace as helpers", async () => {const ego = new FakeEgo();const result = await runTaskspaceScript(ego,@@ -225,7 +248,7 @@ test("taskspace e2e exposes newTaskSpace but not claimTaskSpace as a helper", asassert.deepEqual(firstJsonLine(result.stdout), {newType: "function",switchType: "function",- claimType: "undefined",+ claimType: "function",rawClaimType: "function",});});diff --git a/skills/ego-browser/SKILL.md b/skills/ego-browser/SKILL.mdindex a4c8f23..1dec513 100644--- a/skills/ego-browser/SKILL.md+++ b/skills/ego-browser/SKILL.md@@ -30,7 +30,7 @@ The heredoc body runs as a Node.js script that controls the selected ego-browser## Common helpers-- Task spaces: `listTaskSpaces`, `useOrCreateTaskSpace`, `handOffTaskSpace`, `takeOverTaskSpace`, `waitForAgentControl`, `completeTaskSpace`+- Task spaces: `listTaskSpaces`, `useOrCreateTaskSpace`, `claimTaskSpace`, `handOffTaskSpace`, `takeOverTaskSpace`, `waitForAgentControl`, `completeTaskSpace`- Navigation / state: `listTabs`, `openOrReuseTab`, `closeTab`, `gotoAndWait`, `currentTab`, `switchTab`, `gotoUrl`, `pageInfo`, `ensureRealTab`- Observation: `snapshotText`, `captureScreenshot`, `drainEvents`- Scroll / mouse: `scrollBy`, `scrollToBottomUntil`, `scroll`, `click`, `doubleClick`, `hover`, `dragMouse`@@ -63,14 +63,14 @@ A task often takes multiple heredoc rounds to complete. Because the Node.js runtUse a short name for the active user goal when creating a new task space. Keep reusing that task space for follow-up questions, corrections, refinements, re-checks, and result validation, even if you previously thought the task was complete. Choose a new task space only when the user clearly starts a separate, unrelated goal. Prefer using the numeric `id` returned by `useOrCreateTaskSpace` (for example, `task.id`) to resume a known task in later rounds and avoid name collisions.-To continue work from an existing user-owned task space, use `await listTaskSpaces()` to find the space, call `await useOrCreateTaskSpace(id)` to claim it, then use `await listTabs()` and `await switchTab(targetId)` to select the exact tab before acting. This is different from resuming a handoff from your own prior task space, which starts with `await takeOverTaskSpace(nameOrId)`.+To continue work from an existing user-owned task space, use `await listTaskSpaces()` to find the space, call `await claimTaskSpace(id)` to take ownership and select it, then use `await listTabs()` and `await switchTab(targetId)` to select the exact tab before acting. This is different from resuming a handoff from your own prior task space, which starts with `await takeOverTaskSpace(nameOrId)`.**Ownership policy** — every task space has `ownership: 'agent' | 'agentDelegatedToUser' | 'user'`; the helpers treat user-owned spaces differently:| Helper | When the target space is user-owned ||---|---|| `switchTaskSpace` | throws — agent-owned spaces only |-| `useOrCreateTaskSpace` | claims it (ownership transfers to the agent) |+| `claimTaskSpace` | claims it (ownership transfers to the agent), then selects it || `handOffTaskSpace` | skipped — resolves `{ done: false, skipped: 'user-owned' }` || `completeTaskSpace(…, { keep: true })` | skipped — resolves `{ done: false, skipped: 'user-owned' }` || `completeTaskSpace(…, { keep: false })` | claims it, then closes it |