From 71da8e0719c50d9b11c918b032b9ed4d77aabf5b Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Mon, 4 May 2026 22:44:55 +0530 Subject: feat: parallel tool execution with automatic mutation serialization - Add lightweight async mutex (src/util/mutex.ts) for FIFO serialization - Add serialized?: boolean to BrowserToolDefinition - Wire mutex acquisition into registerBrowserTool execute wrapper - Expose mutationMutex() on BrowserClient - Mark all mutation tools (click, type, scroll, navigate, switch_tab, etc.) as serialized - Leave observation tools (screenshot, page_info, execute_js, http_get, etc.) unguarded - Update prompt and skill docs to reflect parallel-safe behavior - Fix scroll tool: add Page.bringToFront, explicit button:none/buttons:0/pointerType:mouse - Update .gitignore to ignore scripts/ and data/ folders --- src/util/mutex.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/util/mutex.ts (limited to 'src/util/mutex.ts') diff --git a/src/util/mutex.ts b/src/util/mutex.ts new file mode 100644 index 0000000..08efe76 --- /dev/null +++ b/src/util/mutex.ts @@ -0,0 +1,25 @@ +/** + * Lightweight async mutex (~10 lines). Acquire returns a release function. + * When the mutex is free, acquire() resolves immediately. When held, + * callers are queued and execute serially in FIFO order. + */ +export type Mutex = { + acquire(): Promise<() => void>; +}; + +export const createMutex = (): Mutex => { + let queue = Promise.resolve(undefined); + + return { + async acquire(): Promise<() => void> { + let release = () => {}; + const next = new Promise((resolve) => { + release = resolve; + }); + const prev = queue; + queue = prev.then(() => next); + await prev; + return release; + }, + }; +}; -- cgit v1.2.3