From 5cfa7ccc8f4082db111bc0186c5fa3d44b767ad3 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 00:01:32 +0530 Subject: refactor(tools): declare concurrency in the tool definition serialized: true was applied in registry.ts, away from the tools it describes. Now a required concurrency field on each definition, with a test pinning the serialized set so the classes cannot drift. The lock check defaults to taking the mutex for any class that is not explicitly "parallel", so a definition that bypasses defineBrowserTool at runtime fails safe rather than racing on shared CDP state. The test script gains --conditions=import: pi-coding-agent publishes no "require" condition, so importing any tool definition from a CJS-loaded test could not resolve it. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/tabs.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/domains/tabs.ts') diff --git a/src/domains/tabs.ts b/src/domains/tabs.ts index e3e2623..2971a6b 100644 --- a/src/domains/tabs.ts +++ b/src/domains/tabs.ts @@ -24,6 +24,7 @@ export const listTabsTool = defineBrowserTool({ "Internal tabs (chrome://) included by default; pass includeInternal=false to exclude them.", ], parameters: ListTabsArgs, + concurrency: "parallel", async handler(args, { client }): Promise> { const r = await client.listTabs(args.includeInternal ?? true); if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); @@ -50,6 +51,7 @@ export const currentTabTool = defineBrowserTool({ promptSnippet: "Get current tab info", promptGuidelines: ["Returns targetId, url, title, and whether the tab is owned by this harness session."], parameters: Type.Object({}), + concurrency: "parallel", async handler(_a, { client }): Promise> { const cur = client.current(); if (!cur) return err({ kind: "invalid_state", message: "No tab attached." }); @@ -83,6 +85,7 @@ export const switchTabTool = defineBrowserTool({ "Refuses tabs not owned by this session — use browser_new_tab to open a controllable tab instead.", ], parameters: SwitchTabArgs, + concurrency: "serialized", async handler(args, { client }): Promise> { // Resolve to a concrete targetId (exact, or unique hex prefix). We resolve // first so the ownership check sees the canonical id, not the prefix. @@ -141,6 +144,7 @@ export const newTabTool = defineBrowserTool({ "Pass url to navigate immediately.", ], parameters: NewTabArgs, + concurrency: "serialized", async handler(args, { client }): Promise> { const r = await client.newTab(args.url); if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); @@ -167,6 +171,7 @@ export const closeTabTool = defineBrowserTool({ "Accepts exact targetId or a unique hex prefix (>=8 chars).", ], parameters: CloseTabArgs, + concurrency: "serialized", async handler(args, { client }): Promise> { let resolved = args.targetId; if (!client.owns(resolved)) { -- cgit v1.2.3