π OpenHands: AI-Driven Development
Electron desktop app (
npm run desktopfor dev /npm run build:desktopfor the binary) starts the same stack asdev-with-automation.mjsbut inside an Electron BrowserWindow. Two gotchas live here:Boot race vs. agent-server cold start:
dev-with-automation.mjsis a fire-and-forget launcher βmain()previously returned as soon aswaitForServicesaw the ingress proxy respond on/api/health, but ingress responds immediately while the agent-server behind it can still be downloading viauvx(first run pulls ~50 MB of Python + the SDK from PyPI, easily 30β90s).electron/main.mjsused to load the URL as soon as the proxy responded, so the React app booted, called/server_info, and got the "Request timeout" popup. Fix:main()now accepts anagentServerReadyTimeoutMsoption and returns{ config, agentServerReady };electron/main.mjsruns a two-stage wait β Stage 1 (waitForUrl) confirms the ingress proxy is up, Stage 2 (waitForAgentServer) hits${ingress}/server_infoand only accepts200(or401, which proves the proxy reached a real agent-server) before the BrowserWindow loads. Don't shorten the agent-server timeout below ~3 min β uvx cold start on slow connections genuinely takes that long.First-run feedback loop:
dev-with-automation.mjs::setServiceLogListener(cb)exposes a workspace-wide hook that firescb(name, line, level)for every line of every child-process stdout/stderr/exit.electron/main.mjs::handleServiceLogfilters for uvx install lines (Downloading...,Resolved N packages..., etc.) plus agent-server boot markers and forwards them toloading.htmlviasetLoadingStatus()βwindow.__setLoadingStatus(). The hook is best-effort and swallows listener errors β a buggy embedder must not be able to take down the dev stack.
Electron desktop packaging β
electron-builder.config.mjsusesdirectories.app: "electron"so electron/package.json is the app manifest. Even though electron/package.json has zerodependencies, app-builder-lib'scollectNodeModulesWithLoggingwalks UP from the app dir looking for the first npm workspace that resolves modules. The next dir in line is the project root, wherenpm list --jsonreports the full hoisted tree (342 dirs, ~600 MB of Vite/React/Monaco/HeroUI), and electron-builder copies all of it into250 KB together), andResources/app/node_modules/. The walk is hardcoded inapp-builder-lib/out/util/appFileCopier.js::collectNodeModulesWithLoggingβ there is no config knob to disable it. Creating an emptyelectron/node_modules/does NOT help because the collector falls through to project root when it sees zero deps. The fix is theafterPackhook (stripBundledNodeModulesinelectron-builder.config.mjs): after electron-builder copies everything, the hookrm -rfsResources/app/node_modules/(handling macOS.appbundle layout and Linux/Windows flat resources/ layout), then copies back the dependency closure ofRUNTIME_PACKAGES:sirvfor static-server.mjs,httpxyfor proxy-utils.mjs/ingress.mjs,wsfor tunnel-client.mjs (@openhands/extensions(~6 MB), which no script imports: the launcher points the agent-server'sEXTENSIONS_PATHat it so public skills load from disk. Effect:resources/app/drops from ~598 MB to ~7 MB before the extensions package; totallinux-unpacked/from ~1 GB to ~365 MB (the rest is Electron + Chromium + the bundleduvbinary). If a spawned backend script gains a new bare npm import, add the package toRUNTIME_PACKAGESβ otherwise that service crashes withERR_MODULE_NOT_FOUNDonly in the installed app. A package a backend only reads from disk fails quietly instead: without@openhands/extensionsthe launcher sets noEXTENSIONS_PATHand the agent-server falls back to cloning the extensions repo. Testing trap: an app launched fromdist-electron/inside the repo resolves bare specifiers against the repo's ownnode_modules(Node ESM resolution walks up from the script file), so a missing runtime package is invisible there β verify packaged builds from a copy outside the repo tree (e.g./Applications). Don't add real deps to electron/package.json β any real dep would survive the strip and would also have to be hand-installed inside electron/ since the project root is npm-hoisted.build:desktop:universaland--linux/--win/--macvariants all run the same hook.Electron desktop universal (multi-arch) builds β
ELECTRON_ARCH=universal npm run build:desktop:universalproduces one fat arm64+x64 DMG. The bundled uv/node runtimes are per-arch: the download scripts (arch resolution inscripts/download-arch-utils.mjs::resolveDownloadArches(); anyELECTRON_ARCHvalue other than unset oruniversalfails fast) populateresources/{bin,node}-{arm64,x64}/in universal mode (legacy flatresources/{bin,node}/otherwise),mac.extraResourcesships all four dirs into BOTH packaging passes, andmac.x64ArchFileswhitelists them through the@electron/universalmerge β the merger requires both pass trees to carry the same Mach-O file list and rejects byte-identical thin Mach-O files unless whitelisted, so bundling only the pass's own arch (e.g. via the${arch}macro) fails the merge.electron/lib/bundled-runtime-dir.mjs::resolveBundledRuntimeDir()(used byinjectBundledUv/injectBundledNode) prefers<Resources>/{bin,node}-<process.arch>β under a universal Electron binaryprocess.archreports the executing slice (arm64 native, x64 under Rosetta) β and falls back to the flat dirs. Release CI (desktop-macos.yml) builds universal; PR/manual smoke builds run a two-leg matrix β native arm64 onmacos-latestand native Intel x64 onmacos-15-intel(GitHub's last Intel macOS runner, available until Aug 2027) β so the per-arch download + packaging path is exercised on the runner's own CPU. Onmacos-15-intel(which reportsprocess.arch === "x64"),npm run build:desktopresolves the Intel runtimes into the legacy flat dirs, so that leg also guards the single-arch x64 fallback path.Electron desktop app name in dev (macOS) β
npm run desktopshows the app as "Electron" in the Dock unlessscripts/brand-dev-electron.mjs(wired as thepredesktophook) has run. There are three independent name sources and they must all be set; getting one wrong looks like the fix silently not working. (1)app.nameβ Electron-internal, drives the menu bar, About panel andapp.getPath("userData"). It comes fromproductNameinelectron/package.json, read by Electron'sdefault_appin dev andlib/browser/initwhen packaged. Notedefault_apponly reads<arg>/package.json, sonpm run desktopmust point electron at theelectron/directory βelectron electron/main.mjsmakes it probeelectron/main.mjs/package.json, miss, and leaveapp.nameat the host bundle default. (2)CFBundleDisplayName/CFBundleNamein the running bundle's Info.plist β whatlsappinfoandNSRunningApplication.localizedNamereport. (3) The.appdirectory name β this is what the Dock tooltip actually shows. macOS prefers the bundle's filesystem name over the plist keys;/Applications/DBeaver.appdisplays as "DBeaver" despiteCFBundleName = "DBeaver Community". So patching only the plist is NOT enough β the script also renamesnode_modules/electron/dist/Electron.appβ<productName>.appand rewritesnode_modules/electron/path.txtto match (getElectronPath()innode_modules/electron/index.jsjoins path.txt ontodist/and silently re-downloads Electron100 MB if it doesn't resolve, so the two must move together)./Library/Caches/electron/electron-v*.zipCFBundleExecutableis deliberately left asElectronβ/Applications/Antigravity.appships that exact value and still displays correctly, so it only affectsps/Activity Monitor. Editing the plist does not break code signing: Electron's dist is ad-hoc linker-signed (Info.plist=not bound,Sealed Resources=none), so the signature covers only the Mach-O.npm run build:desktopis unaffected by the rename β electron-builder packages from `, never fromnode_modules/electron/dist. The packaged app never had the problem: electron-builder emits.app` with matching plist keys. Already-running instances keep the name they launched with, so quit and relaunch when verifying.Electron desktop
node/npm/npxPATH bridging β when the packaged.appis launched from Finder/Spotlight on macOS, the OS gives it a minimal PATH (/usr/bin:/bin). Homebrew, nvm, asdf installs of Node.js are invisible to spawned subprocesses. Two breakages flow from that: (1) backend launcher scripts that dospawn("node", ...)can't find Node; (2) most stdio MCP marketplace entries (Slack, GitHub, Figma, etc.) usecommand: "npx", and when the agent-server tries to spawn them the missingnpxmakes the spawn fail with ENOENT β the SDK reports it as anerror_kind: "connection"MCP test failure, which the install modal renders asMCP$TEST_ERROR_CONNECTION("Could not reach the server. Check the URL and server type."), a misleading error since no URL is involved. First fix attempt β DOES NOT WORK for stdio MCPs: wrapnode/npm/npxwith thin shell scripts that run Electron withELECTRON_RUN_AS_NODE=1against the package's CLI JS. That bridges the ENOENT but stdio JSON-RPC servers spawned through the wrapper exit withMcpError: Connection closedbefore completing the MCP handshake β Electron-as-Node has subtly different stdin/stdout pipe semantics from a vanillanodebinary when used as a stdio child of a windowed process. Working fix: bundle the real Node.js distribution.scripts/download-node.mjsdownloads the officialnode-v<ver>-<platform>-<arch>tarball fromhttps://nodejs.org/dist/v<ver>/intoresources/node/(gitignored), prunesinclude/,share/, docs, andnode_modules/corepackto keep the size down (~130 MB on Linux x64, dominated by the Node binary itself). Default pin:NODE_BUNDLE_VERSION = "24.21.0"(aligned with the volta pin inpackage.jsonand theengines.node >=24requirement); override withNODE_VERSION=.electron-builder.config.mjsshipsresources/node/as an extraResource β<Resources>/node/.electron/main.mjs::injectBundledNode()prepends the platform-appropriate bin dir toPATH(POSIX:<Resources>/node/bin; Windows:<Resources>/node/) so subsequent spawns ofnode/npm/npxresolve to real binaries with full stdio fidelity. It alsochmod +x's the binaries on POSIX because electron-builder doesn't always preserve the bit.injectBundledNode()is a no-op when!app.isPackaged(devnpm run desktopuses the developer's system node).build:desktopandbuild:desktop:universalboth rundownload-node.mjsafterdownload-uv.mjs. If the bundled dir is missing at runtime,injectBundledNode()logs a loud[desktop]warning instead of silently leaving PATH bare. extraResources will not copy the distribution's rootnode_modules:app-builder-lib/src/util/filter.ts::createFilterreturnsfalsefor any entry whose path relative to the copy root is exactlynode_modules, before thefilterpatterns are consulted, so nofiltervalue can opt back in. The Windows Node zip puts npm at<root>/node_modules/npmand hits this exactly; POSIX tarballs put it at<root>/lib/node_modules/npmand are unaffected β which is why this only broke Windows. Shipped result: a workingnode.exebesidenpm.cmd/npx.cmdshims pointing at a missingnode_modules\npm\bin\npx-cli.js, so everynpx -y <pkg>spawn dies withMODULE_NOT_FOUNDand shadows the user's own npm, since the dir is PREPENDED to PATH. TheafterPackhook (restoreBundledNodeNpm) copies that directory into the packed output and then hard-fails the build ifnpm-cli.jsstill isn't there, mirroring the checkdownload-node.mjsalready runs on the source tree.