← Commit history

Close issue 41, the isolation hole the nb thread caught that masqueraded as a cross-thread takeover: a verb naming a DEAD sessionId now hard-errors with session_not_found and the live-session list instead of silently falling back to another thread's active window, and per John's ai-thread model the activeSessionId implication is deleted from every session-targeting verb: omitted sessionId resolves to the CALLER THREAD's own window (the shared ai-thread-slug keying pup_open_window uses, or the single window the thread owns by explicit name), with a teaching error when the thread has none or several; the ownership gate also now covers resolved targets, not just explicitly named ones

John Lauer ·e6bb3c146e ·2mo ago ·parent 269fb91
4 files changed +69−13
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "2.0.27",-  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.27/adom-bridge-puppeteer-v2.0.27.zip",-  "sha256": "198a7e9f77df2291bb7863ec316afce2fde5d43ff472e4e433b6069af355d2d2",-  "size": 639100,+  "version": "2.0.28",+  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.28/adom-bridge-puppeteer-v2.0.28.zip",+  "sha256": "bbd10344fcf8fb9dc26e21ef8770118e14782d8fa40f0e375c8a3ff39f83f50a",+  "size": 640433,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.27+2.0.28
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.27",+  "version": "2.0.28",   "description": "Drives a browser ALREADY on the machine \u2014 installed Chrome, else Microsoft Edge (every Windows PC ships with Edge) \u2014 launched with a FRESH isolated profile, so the common case has NO ~150 MB Chrome-for-Testing download and it never touches the user's real tabs/logins. Binds its local server to LOOPBACK (127.0.0.1) only, so no Windows Firewall 'allow Node through the firewall' prompt ever pops. Chrome for Testing is fetched only as a LAST RESORT if the machine has no Chromium browser at all. SPAWN-VERIFIED fallback: pup tries each detected browser (Chrome \u2192 Edge \u2192 CfT) and actually launches it, falling through to the next if one won't start (and handling browsers like Edge that relaunch onto another PID), so a corrupt/partial install never hard-fails an open. The browser that launches is cached as the default (persisted across restarts) so it isn't re-probed each time. On spawn the bridge SELF-WARMS: detects browsers + disk, and only if the box has no Chrome/Edge and no cached CfT does it background-fetch CfT so the first open is instant. pup_use pins a specific browser (chrome | edge | cft | auto); {browser:'chrome',install:true} downloads & installs REAL Google Chrome (user-scoped, no admin) on an Edge-only box. pup_readiness (READ-ONLY) reports which browser will be used + the full candidate list + the default + free disk. Every failure returns a specific errorCode + _hint (chrome_install_no_disk, chrome_download_network, chrome_install_permission, chrome_stable_not_detected, \u2026). Launches with FULL browser permissions by default for full debug (strictPermissions:true opts out). Headful automation: open/close windows+tabs, navigate, screenshot, eval JS, record. pup is a GENERIC, non-profile browser only \u2014 every session is a fresh isolated Chrome/Edge process, never the user's real signed-in browser; profile defaults to sessionId. To drive the user's REAL Chrome/Edge (their profile, cookies, SSO), use the Adom browser EXTENSION's nbrowser_* verbs \u2014 a separate bridge, not pup's job. macOS (v1.9.74+): full parity with mac-native mechanics \u2014 background-by-default is the app-level hide (windows stay drivable/screenshottable while hidden), raise/lower map to unhide+activate/hide, pup_alert_window posts a native toast whose click focuses the window, pup_use {browser:'chrome',install:true} installs Chrome from the official dmg, and taskbar identity/badging remains Windows-only.",   "homepage": "https://wiki.adom.inc/adom/adom-bridge",   "author": "Adom Inc.",
src/server.js+63−7
@@ -6773,6 +6773,14 @@ async function enumAllPupChromeHwnds() {  // v1.8.23: verbs that MUTATE a session's visible state → auto-flash the window so the // user knows the agent changed it. evaluate counts UNLESS {readOnly:true}.+// v2.0.28 (#41 + John: "we moved to ai-thread name and dropped sessionId"): every verb that TARGETS+// one session. With sessionId omitted these resolve to the CALLER THREAD's own window (the same+// ai-<thread-slug> keying pup_open_window uses) — never to activeSessionId, which is just whichever+// window was touched last, usually another thread's.+const SESSION_TARGETING_VERBS = new Set(['pup_navigate', 'pup_reload', 'pup_back', 'pup_forward', 'pup_open_tab', 'pup_switch_tab', 'pup_close_tab', 'pup_close_window', 'pup_eval', 'pup_evaluate', 'pup_click', 'pup_type', 'pup_press_key', 'pup_input_dispatch', 'pup_screenshot', 'pup_screenshot_full_res', 'pup_errors', 'pup_list_tabs', 'pup_wait', 'pup_alert_window', 'pup_focus_window', 'pup_raise_os_window', 'pup_lower_os_window', 'pup_window_info', 'pup_record_start', 'pup_record_stop', 'pup_wiki_set_view', 'pup_switch_window']);+function threadDefaultSessionId(callerThread) {+  return 'ai-' + String(callerThread).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40);+} const MUTATING_VERBS = new Set(['pup_open_window', 'pup_open_tab', 'pup_navigate', 'pup_reload', 'pup_back', 'pup_forward', 'pup_switch_tab', 'pup_click', 'pup_type', 'pup_press_key', 'pup_input_dispatch', 'pup_eval', 'pup_evaluate']);  // Debounced auto-flash: one flash per window per ~5s burst of verbs, re-armed after@@ -10011,13 +10019,61 @@ const server = http.createServer(async (req, res) => {       // ownership so the trail stays honest. Read verbs (screenshot, list, status, errors) stay       // open so threads can observe each other's windows without disturbing them. Runs BEFORE the       // ownership-record block so a refused caller never pollutes lastDrivenBy attribution.+      // v2.0.28 (John: "we moved to ai-thread name and dropped sessionId"): a session-targeting verb+      // with sessionId OMITTED resolves to the CALLER THREAD's own window — first the derived+      // ai-<thread-slug> window, else the single window the thread owns under an explicit name.+      // No match is a teaching error. The old activeSessionId fallback (= whichever window ANY+      // thread touched last) is gone from every session-targeting verb.+      if (args && !args.sessionId && _callerThread && SESSION_TARGETING_VERBS.has(command)) {+        const derived = threadDefaultSessionId(_callerThread);+        if (sessions.has(derived)) args.sessionId = derived;+        else {+          const mine = [...sessions.entries()].filter(([, s2]) => (s2.owner || s2._ownerThread) === _callerThread).map(([k]) => k);+          if (mine.length === 1) args.sessionId = mine[0];+          else {+            sendJSON(res, {+              success: false,+              errorCode: mine.length ? 'ambiguous_session' : 'no_session_for_thread',+              error: mine.length+                ? `Your thread owns ${mine.length} windows — name the sessionId you mean (${mine.join(', ')}).`+                : `Your thread ("${_callerThread}") has no pup window yet.`,+              liveSessions: [...sessions.keys()],+              _hint: `pup no longer implies the "active" window (that was whichever window ANY thread touched last — issue #41). ${mine.length ? 'Pass the sessionId explicitly.' : 'Open your own window first: pup_open_window (omit sessionId and your thread gets its own).'}`,+            }, 404);+            return;+          }+        }+      }++      // v2.0.28 (#41, the nb thread's catch): a verb naming an EXPLICIT sessionId that no longer+      // exists must ERROR. It used to silently fall back to activeSessionId — ANOTHER thread's+      // window — so after a bridge restart, a thread driving its dead id navigated and screenshotted+      // the pup-wiki thread's window while every response LOOKED ok. That is also what masqueraded+      // as the "kicad took over nb's window" incident. Nothing mutates, nothing screenshots, the+      // caller learns exactly what happened and how to recover.+      if (args && typeof args.sessionId === 'string' && args.sessionId+          && command !== 'pup_open_window' && !sessions.has(args.sessionId)) {+        const live = [...sessions.keys()];+        sendJSON(res, {+          success: false,+          errorCode: 'session_not_found',+          error: `Session "${args.sessionId}" does not exist (it may have died in a bridge restart).`,+          liveSessions: live,+          _hint: `Nothing was done — pup no longer falls back to the active window (that silently drove ANOTHER thread's window; issue #41). Re-create your window with pup_open_window (reusing the same sessionId is fine)${live.length ? `. Live sessions right now: ${live.join(', ')}` : ''}.`,+        }, 404);+        return;+      }+       {         const OWNER_GATED = MUTATING_VERBS.has(command)           || ['pup_close_tab', 'pup_close_window', 'pup_close', 'pup_configure', 'pup_focus_window',               'pup_raise_os_window', 'pup_lower_os_window', 'pup_alert_window', 'pup_wiki_set_view',               'pup_record_start', 'pup_record_stop'].includes(command);-        if (OWNER_GATED && args && args.sessionId && _callerThread) {-          const _gs = sessions.get(args.sessionId);+        // v2.0.28 (#41 second half): with sessionId OMITTED, mutating verbs resolve to activeSessionId+        // — which may be another thread's window. Gate the RESOLVED target, not just the named one.+        const _gateSid = (args && args.sessionId) || (OWNER_GATED && command !== 'pup_open_window' ? activeSessionId : null);+        if (OWNER_GATED && _gateSid && _callerThread) {+          const _gs = sessions.get(_gateSid);           const _owner = _gs && (_gs.owner || _gs._ownerThread);           if (_gs && _owner && _owner !== _callerThread) {             if (args.takeover) {@@ -10025,17 +10081,17 @@ const server = http.createServer(async (req, res) => {               // action (reload/navigate/close to repair or hand off) must not steal the window —               // v2.0.19 reassigned on every takeover, so a repair reload would have locked the               // original owner out of its own window. The action is still logged with both names.-              console.log(`[takeover] "${args.sessionId}": thread "${_callerThread}" acted on "${_owner}"'s window via ${command} (takeover:true — sanctioned only when the user asked${command === 'pup_open_window' ? '; ownership TRANSFERRED' : '; ownership unchanged'})`);+              console.log(`[takeover] "${_gateSid}": thread "${_callerThread}" acted on "${_owner}"'s window via ${command} (takeover:true — sanctioned only when the user asked${command === 'pup_open_window' ? '; ownership TRANSFERRED' : '; ownership unchanged'})`);               _gs._lastTakeoverBy = _callerThread; _gs._takenOverAt = Date.now();               if (command === 'pup_open_window') { _gs._takenOverFrom = _owner; _gs.owner = _callerThread; _gs._ownerThread = _callerThread; }             } else {-              console.log(`[own] REFUSED ${command} on "${args.sessionId}" — owner "${_owner}", caller "${_callerThread}"`);+              console.log(`[own] REFUSED ${command} on "${_gateSid}"${args.sessionId ? '' : ' (RESOLVED from activeSessionId — name your own sessionId)'} — owner "${_owner}", caller "${_callerThread}"`);               let _curUrl = null; try { _curUrl = _gs.page?.url() || null; } catch (e) {}               sendJSON(res, {                 success: false,                 errorCode: 'session_owned_by_another_thread',-                error: `Session "${args.sessionId}" belongs to AI thread "${_owner}" — your thread ("${_callerThread}") cannot ${command} it.`,-                sessionId: args.sessionId, owner: _owner, requestedBy: _callerThread, currentUrl: _curUrl,+                error: `Session "${_gateSid}"${args.sessionId ? '' : ' (the ACTIVE window — you omitted sessionId)'} belongs to AI thread "${_owner}" — your thread ("${_callerThread}") cannot ${command} it.`,+                sessionId: _gateSid, owner: _owner, requestedBy: _callerThread, currentUrl: _curUrl,                 _hint: `STOP — this window is owned by "${_owner}"; driving it would break that thread's work in front of the user. Open your OWN window instead: pup_open_window WITHOUT a sessionId gives your thread its own window (keyed on your --ai-thread name), or pass a unique task-prefixed sessionId. Only pass takeover:true if the USER explicitly told you to take this window over — every takeover is logged with both thread names.`,               }, 409);               return;@@ -10297,7 +10353,7 @@ const server = http.createServer(async (req, res) => {                 error: 'No sessionId AND no caller identity. Either pass a sessionId, or (better) identify your thread — adom-bridge-cli --ai-thread "<your thread>" ... — and pup gives your thread its OWN window automatically: first open creates it, later opens become tabs in it, and no other thread can touch it.' });               return;             }-            args.sessionId = 'ai-' + String(_callerThread).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40);+            args.sessionId = threadDefaultSessionId(_callerThread);   // v2.0.28: shared keying helper             const _own = sessions.get(args.sessionId);             if (_own && isSessionAlive(_own) && args.url) {               try {