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): return task finish receipts
JackWangf983c1b65dde
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/task-space.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/task-space.mjsindex e31abd3..d49a841 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/task-space.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/task-space.mjs@@ -90,7 +90,14 @@ export function taskSpaceCase() {const boundaryPage = resumedTask.userPage();assert(Boolean(boundaryPage), "takeover captures the tab active at the user boundary");const handedOffSpaceId = resumedTask.spaceId;- await resumedTask.finish({ keep: "all" });+ const keepAllReceipt = await resumedTask.finish({ keep: "all" });+ assertEqual(keepAllReceipt.spaceId, handedOffSpaceId, "task.finish receipt identifies its space");+ assertEqual(keepAllReceipt.closedSpace, false, "keep all reports that the space remains open");+ assert(+ keepAllReceipt.keptManagedLabels.includes(boundaryPage.label),+ "keep all receipt lists the retained managed Page"+ );+ assertEqual(keepAllReceipt.closedManagedLabels.length, 0, "keep all receipt reports no managed Page closures");assert((await listTaskSpaces()).some((space) => space.id === handedOffSpaceId),"task.finish keeps the handed-off browser space"@@ -99,7 +106,12 @@ export function taskSpaceCase() {const closeTask = await taskSpace(taskName + " v2 close through finish");const closeSpaceId = closeTask.spaceId;- await closeTask.finish({ keep: [] });+ const closeReceipt = await closeTask.finish({ keep: [] });+ assertEqual(closeReceipt.spaceId, closeSpaceId, "close receipt identifies its space");+ assertEqual(closeReceipt.closedSpace, true, "empty keep reports that the whole space closed");+ assertEqual(closeReceipt.keptManagedLabels.length, 0, "closed-space receipt reports no retained managed Pages");+ assert(closeReceipt.closedManagedLabels.length > 0, "closed-space receipt lists the managed Pages it closed");+ assertEqual(closeReceipt.preservedUnmanagedCount, 0, "closed-space receipt reports no protected unmanaged tabs");for (let attempt = 0; attempt < 20; attempt += 1) {if (!(await listTaskSpaces()).some((space) => space.id === closeSpaceId)) break;await new Promise((resolve) => setTimeout(resolve, 50));@@ -114,7 +126,18 @@ export function taskSpaceCase() {const retainedPage = await finishTask.newPage();await retainedPage.goto(baseUrl + "/secondary?v2-lifecycle=retain");const finishSpaceId = finishTask.spaceId;- await finishTask.finish({ keep: [retainedPage.label] });+ const namedReceipt = await finishTask.finish({ keep: [retainedPage.label] });+ assertEqual(namedReceipt.closedSpace, false, "named retention reports that the space remains open");+ assertEqual(+ JSON.stringify(namedReceipt.keptManagedLabels),+ JSON.stringify([retainedPage.label]),+ "named retention receipt lists the retained Page"+ );+ assert(+ namedReceipt.closedManagedLabels.includes("p1"),+ "named retention receipt lists the discarded Agent Page"+ );+ assertEqual(namedReceipt.preservedUnmanagedCount, 0, "named retention reports no unmanaged tabs");assert((await listTaskSpaces()).some((space) => space.id === finishSpaceId),"task.finish keeps the browser space when one Page is retained"diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjsindex 40072da..962d84c 100644--- a/package/ego-browser/src/page-model.test.mjs+++ b/package/ego-browser/src/page-model.test.mjs@@ -1379,7 +1379,14 @@ test("TaskSpace uses spaceId and finishes while keeping every managed Page", asyconst finishTask = taskForRound(fixture, "round-b", services);const page = await finishTask.newPage();- await finishTask.finish({ keep: "all" });+ const receipt = await finishTask.finish({ keep: "all" });+ assert.deepEqual(receipt, {+ spaceId: 7,+ closedSpace: false,+ keptManagedLabels: [page.label],+ closedManagedLabels: [],+ preservedUnmanagedCount: 0,+ });assert.deepEqual((await ledger.read(7)).pages, {});assert.equal(fixture.tabs.has(page.targetId), true);@@ -1414,7 +1421,15 @@ test("TaskSpace finish keeps named Pages and protects unknown-origin Pages", asyopenedBy: "unknown",});- await task.finish({ keep: ["p2"] });+ const receipt = await task.finish({ keep: ["p2"] });++ assert.deepEqual(receipt, {+ spaceId: 7,+ closedSpace: false,+ keptManagedLabels: ["p2", "user-page"],+ closedManagedLabels: ["p1", "p3"],+ preservedUnmanagedCount: 0,+ });assert.deepEqual(lifecycleCalls, ["finish"]);assert.deepEqual([...fixture.tabs.keys()].sort(), [@@ -1442,7 +1457,15 @@ test("TaskSpace finish closes the whole space when no Pages are retained", async});await openTestPage(task, "https://example.test/one");- await task.finish({ keep: [] });+ const receipt = await task.finish({ keep: [] });++ assert.deepEqual(receipt, {+ spaceId: 7,+ closedSpace: true,+ keptManagedLabels: [],+ closedManagedLabels: ["p1"],+ preservedUnmanagedCount: 0,+ });assert.deepEqual(lifecycleCalls, ["close"]);assert.equal(@@ -1473,7 +1496,15 @@ test("TaskSpace finish keeps protected unmanaged tabs even with an empty keep lifixture.addExternalTab("target-user", "https://example.test/user");await ledger.keepUnmanaged(7, "target-user", "unknown");- await task.finish({ keep: [] });+ const receipt = await task.finish({ keep: [] });++ assert.deepEqual(receipt, {+ spaceId: 7,+ closedSpace: false,+ keptManagedLabels: [],+ closedManagedLabels: ["p1"],+ preservedUnmanagedCount: 1,+ });assert.deepEqual(lifecycleCalls, ["finish"]);assert.equal(fixture.tabs.has(agentPage.targetId), false);diff --git a/package/ego-browser/src/page-model.ts b/package/ego-browser/src/page-model.tsindex a9121e1..402b1f8 100644--- a/package/ego-browser/src/page-model.ts+++ b/package/ego-browser/src/page-model.ts@@ -169,6 +169,14 @@ type FinishOptions = {keep: "all" | string[];};+export type TaskFinishReceipt = {+ spaceId: number;+ closedSpace: boolean;+ keptManagedLabels: string[];+ closedManagedLabels: string[];+ preservedUnmanagedCount: number;+};+type PageWaitForFileChooserOptions = {timeout?: number;};@@ -973,14 +981,14 @@ class TaskSpace {}/** Finish the task with an explicit managed-Page retention policy. */- async finish(options: FinishOptions): Promise<void> {+ async finish(options: FinishOptions): Promise<TaskFinishReceipt> {validatePublicApiOptions("TaskSpace.finish", options);if (!Object.hasOwn(options, "keep") || options.keep === undefined) {throw new TypeError("task.finish requires the keep option. Expected: await task.finish({ keep })",);}- await this.#services.gate.withSpace(this.spaceId, async () => {+ return this.#services.gate.withSpace(this.spaceId, async () => {const { ledger, tabs } = await this.#reconcilePages();const keepLabels =options.keep === "all"@@ -997,6 +1005,19 @@ class TaskSpace {const managedByTarget = new Map(Object.values(ledger.pages).map((page) => [page.targetId, page]),);+ const labelsToClose = Object.entries(ledger.pages)+ .filter(+ ([label, page]) =>+ page.openedBy === "agent" && !keepLabels.has(label),+ )+ .map(([label]) => label);+ const closedManagedLabelSet = new Set(labelsToClose);+ const keptManagedLabels = Object.keys(ledger.pages).filter(+ (label) => !closedManagedLabelSet.has(label),+ );+ const preservedUnmanagedCount = tabs.filter(+ (tab) => !managedByTarget.has(tab.targetId),+ ).length;const hasProtectedTabs = tabs.some((tab) => {const managed = managedByTarget.get(tab.targetId);return !managed || managed.openedBy === "unknown";@@ -1009,20 +1030,27 @@ class TaskSpace {) {await this.#services.closeTaskSpace();await this.#discardTerminalState();- return;+ return {+ spaceId: this.spaceId,+ closedSpace: true,+ keptManagedLabels: [],+ closedManagedLabels: labelsToClose,+ preservedUnmanagedCount,+ };}- const labelsToClose = Object.entries(ledger.pages)- .filter(- ([label, page]) =>- page.openedBy === "agent" && !keepLabels.has(label),- )- .map(([label]) => label);for (const label of labelsToClose) {await this.page(label).close();}await this.#services.completeTaskSpace();await this.#discardTerminalState();+ return {+ spaceId: this.spaceId,+ closedSpace: false,+ keptManagedLabels,+ closedManagedLabels: labelsToClose,+ preservedUnmanagedCount,+ };});}diff --git a/package/ego-browser/src/public-api-schema.test.mjs b/package/ego-browser/src/public-api-schema.test.mjsindex 2e710cf..c985d32 100644--- a/package/ego-browser/src/public-api-schema.test.mjs+++ b/package/ego-browser/src/public-api-schema.test.mjs@@ -142,7 +142,7 @@ test("the generated reference contains signatures and option descriptions", () =assert.match(markdown, /`await task\.newPage\(\)`/);assert.match(markdown,- /`await task\.finish\(\{ keep \}\)`.*keep selected managed Pages/,+ /`await task\.finish\(\{ keep \}\)`.*return a receipt with retained and closed managed Page labels/,);assert.doesNotMatch(markdown, /task\.close/);assert.match(diff --git a/package/ego-browser/src/public-api-schema.ts b/package/ego-browser/src/public-api-schema.tsindex 71d51ae..e458da4 100644--- a/package/ego-browser/src/public-api-schema.ts+++ b/package/ego-browser/src/public-api-schema.ts@@ -164,7 +164,7 @@ export const PUBLIC_API_SCHEMA: readonly PublicApiEntry[] = [name: "TaskSpace.finish",signature: "await task.finish({ keep })",summary:- "Finish the task and keep selected managed Pages; an empty list closes the space when no protected tabs remain.",+ "Finish the task and return a receipt with retained and closed managed Page labels; an empty list closes the space when no protected tabs remain.",options: {keep: option("pageRetention",diff --git a/skills/ego-browser/references/api.md b/skills/ego-browser/references/api.mdindex c55f114..1418667 100644--- a/skills/ego-browser/references/api.md+++ b/skills/ego-browser/references/api.md@@ -24,22 +24,22 @@ Selectors accept refs, Ego locators, XPath, and raw CSS. A small compatibility s## TaskSpace-| API | Options | Purpose |-| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |-| `task.spaceId` | — | Stable numeric identifier for this task space. |-| `task.name` | — | Human-readable task-space name. |-| `task.ownership` | — | Ownership state captured when this TaskSpace was created. |-| `task.page(label)` | — | Create a lazy Page handle for a durable page label. |-| `task.userPage()` | — | Return the tab active at the claim/takeover boundary, when one was captured. |-| `await task.pages()` | — | List the managed Page handles in this space. |-| `await task.tabs()` | — | List managed Pages and unmanaged tabs in this space. |-| `await task.newPage()` | — | Create and durably label a blank Page. |-| `await task.adopt(unmanagedPage, { as? })` | `as` — Permanent Page label. | Bring an unmanaged tab under the Page lifecycle. |-| `await task.release(label)` | — | Stop managing an unknown-origin Page without closing it. |-| `await task.waitForControl({ interval?, timeout? })` | `interval` — Polling interval in milliseconds.<br>`timeout` — Maximum duration in milliseconds. | Wait for Agent control without taking it from the user. |-| `await task.handOff()` | — | Give control of this space to the user. |-| `await task.finish({ keep })` | `keep` — Required Page retention policy: "all" or an array of managed Page labels. | Finish the task and keep selected managed Pages; an empty list closes the space when no protected tabs remain. |-| `await task.cdp(method, params?, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Send a Target or Browser domain CDP command. |+| API | Options | Purpose |+| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |+| `task.spaceId` | — | Stable numeric identifier for this task space. |+| `task.name` | — | Human-readable task-space name. |+| `task.ownership` | — | Ownership state captured when this TaskSpace was created. |+| `task.page(label)` | — | Create a lazy Page handle for a durable page label. |+| `task.userPage()` | — | Return the tab active at the claim/takeover boundary, when one was captured. |+| `await task.pages()` | — | List the managed Page handles in this space. |+| `await task.tabs()` | — | List managed Pages and unmanaged tabs in this space. |+| `await task.newPage()` | — | Create and durably label a blank Page. |+| `await task.adopt(unmanagedPage, { as? })` | `as` — Permanent Page label. | Bring an unmanaged tab under the Page lifecycle. |+| `await task.release(label)` | — | Stop managing an unknown-origin Page without closing it. |+| `await task.waitForControl({ interval?, timeout? })` | `interval` — Polling interval in milliseconds.<br>`timeout` — Maximum duration in milliseconds. | Wait for Agent control without taking it from the user. |+| `await task.handOff()` | — | Give control of this space to the user. |+| `await task.finish({ keep })` | `keep` — Required Page retention policy: "all" or an array of managed Page labels. | Finish the task and return a receipt with retained and closed managed Page labels; an empty list closes the space when no protected tabs remain. |+| `await task.cdp(method, params?, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Send a Target or Browser domain CDP command. |## Page