← Commit history

v2.0.351: Discover Hydrogen's control API instead of hardcoding a container-side port: the bridge runs on the desktop where 47084 is closed and the control URL is dynamic, so the version gate had been failing open and the module's send relay answered 502. Probe the discovery responder, cache the result, and re-probe whenever a call fails.

John Lauer ·6d841dd9c0 ·2mo ago ·parent cbe2935
4 files changed +69−18
adom-bridge-puppeteer-manifest.json+5−5
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "2.0.350",-  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.350/adom-bridge-puppeteer-v2.0.350.zip",-  "sha256": "ffbe05985c00ef886003578ee1380ff3b8037b1d86b2d9fc29c19f572bb72d62",-  "size": 1523713,+  "version": "2.0.351",+  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.351/adom-bridge-puppeteer-v2.0.351.zip",+  "sha256": "2aef6914e913ced5f90d41f459f2ddd64df978b7ea7f9ee17b0e9d486b96ba91",+  "size": 1524570,   "verbPrefixes": [     "browser_",     "desktop_recorder_",@@ -12,5 +12,5 @@   ],   "healthEndpoint": "/status",   "statusVerb": "browser_readiness",-  "released_at": "2026-08-25T15:58:30.190128Z"+  "released_at": "2026-08-25T16:01:52.837814Z" }
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.350\ No newline at end of file+2.0.351\ No newline at end of file
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.350",+  "version": "2.0.351",   "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+62−11
@@ -12409,16 +12409,61 @@ const DEMO_PROMPT = 'Run the pup demo and show me what pup can do on my machine.   + '5. Read the pup dashboard LED status and tell me each light. If anything is not green, name the exact verb that fixes it and offer to run it.\n\n'   + 'Then close the demo window so nothing is left on my desktop.'; -// The local Hydrogen control API. The bridge runs ON the desktop, so this is a plain loopback call-// with nothing to route and no desktop to disambiguate.-let HYDROGEN_CTL = 'http://127.0.0.1:47084';-try {-  const u = fs.readFileSync(path.join(os.homedir(), '.adom', 'hydrogen-control-url'), 'utf8').trim();-  if (u) HYDROGEN_CTL = u.replace(/\/$/, '');-} catch (e) {}-function hydrogenGet(urlPath, timeoutMs) {+// The local Hydrogen control API. THE PORT IS DYNAMIC AND MUST BE DISCOVERED (v2.0.351).+// This used to hardcode 47084 with a fallback to ~/.adom/hydrogen-control-url. Both are+// CONTAINER-side facts that I inherited when the say-strip moved from the container helper into+// this bridge, and neither holds on the desktop: there is no hydrogen-control-url file there, and+// ah's control API was actually on 63549. So every call to Hydrogen from this bridge was hitting a+// closed port. The version gate failed OPEN (an unreachable probe is treated as "cannot read, do+// not block"), so it looked healthy while gating nothing, and the module's send relay answered 502.+// Found by the module's checkSend probe, which exists for exactly this: a missing gate reads as an+// allowed gate rather than as an error.+//+// The discovery responder answers on one of four fixed candidates and its body carries the real+// control_url. Probe, cache, and RE-PROBE whenever a call fails, because the port moves when ah+// restarts and a cached value is stale from that moment on.+const HYDROGEN_DISCOVERY_PORTS = [47080, 48080, 49180, 50280];+let HYDROGEN_CTL = null;+let _ctlAt = 0;+function _httpGetJson(url, timeoutMs) {   return new Promise((resolve) => {-    const req = http.get(HYDROGEN_CTL + urlPath, { timeout: timeoutMs || 2500 }, (res2) => {+    const req = http.get(url, { timeout: timeoutMs || 1500 }, (r) => {+      let b = ''; r.on('data', d => { b += d; });+      r.on('end', () => { let j = null; try { j = JSON.parse(b); } catch (e) {} resolve(j); });+    });+    req.on('error', () => resolve(null));+    req.on('timeout', () => { req.destroy(); resolve(null); });+  });+}+async function hydrogenControlUrl(force) {+  if (!force && HYDROGEN_CTL && Date.now() - _ctlAt < 300000) return HYDROGEN_CTL;+  // In a container the workspace file is authoritative and costs nothing to read.+  try {+    const u = fs.readFileSync(path.join(os.homedir(), '.adom', 'hydrogen-control-url'), 'utf8').trim();+    if (u) { HYDROGEN_CTL = u.replace(/\/$/, ''); _ctlAt = Date.now(); return HYDROGEN_CTL; }+  } catch (e) {}+  for (const port of HYDROGEN_DISCOVERY_PORTS) {+    const j = await _httpGetJson(`http://127.0.0.1:${port}/`, 1200);+    if (j && j.control_url) {+      HYDROGEN_CTL = String(j.control_url).replace(/\/$/, '');+      _ctlAt = Date.now();+      console.log(`[hydrogen] control API discovered at ${HYDROGEN_CTL} (via responder on ${port})`);+      return HYDROGEN_CTL;+    }+  }+  HYDROGEN_CTL = null;+  return null;+}+async function hydrogenGet(urlPath, timeoutMs) {+  let r = await _hydrogenGetOnce(await hydrogenControlUrl(false), urlPath, timeoutMs);+  // A dead port means the cached URL is stale (ah restarted), not that Hydrogen is gone.+  if (!r.status) r = await _hydrogenGetOnce(await hydrogenControlUrl(true), urlPath, timeoutMs);+  return r;+}+function _hydrogenGetOnce(base, urlPath, timeoutMs) {+  if (!base) return Promise.resolve({ status: 0, error: 'hydrogen control API not discovered' });+  return new Promise((resolve) => {+    const req = http.get(base + urlPath, { timeout: timeoutMs || 2500 }, (res2) => {       let b = ''; res2.on('data', (d) => { b += d; });       res2.on('end', () => { let j = null; try { j = JSON.parse(b); } catch (e) {} resolve({ status: res2.statusCode, json: j, raw: b, contentType: res2.headers['content-type'] || null }); });     });@@ -12426,10 +12471,16 @@ function hydrogenGet(urlPath, timeoutMs) {     req.on('timeout', () => { req.destroy(); resolve({ status: 0, error: 'timeout' }); });   }); }-function hydrogenPost(urlPath, bodyObj, timeoutMs) {+async function hydrogenPost(urlPath, bodyObj, timeoutMs) {+  let r = await _hydrogenPostOnce(await hydrogenControlUrl(false), urlPath, bodyObj, timeoutMs);+  if (!r.status) r = await _hydrogenPostOnce(await hydrogenControlUrl(true), urlPath, bodyObj, timeoutMs);+  return r;+}+function _hydrogenPostOnce(base, urlPath, bodyObj, timeoutMs) {+  if (!base) return Promise.resolve({ status: 0, error: 'hydrogen control API not discovered' });   return new Promise((resolve) => {     const data = JSON.stringify(bodyObj);-    const req = http.request(HYDROGEN_CTL + urlPath, { method: 'POST', timeout: timeoutMs || 4000,+    const req = http.request(base + urlPath, { method: 'POST', timeout: timeoutMs || 4000,       headers: { 'content-type': 'application/json', 'content-length': Buffer.byteLength(data) } }, (res2) => {       let b = ''; res2.on('data', (d) => { b += d; });       res2.on('end', () => { let j = null; try { j = JSON.parse(b); } catch (e) {} resolve({ status: res2.statusCode, json: j, raw: b, contentType: res2.headers['content-type'] || null }); });