Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(build): ship the session host, and resolve it from inside the asar
Erik Zwepee6b9df6170f
diff --git a/package-lock.json b/package-lock.jsonindex 5d415dcc4..d267eb46a 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "node-terminal",- "version": "0.3.3",+ "version": "0.3.4","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "node-terminal",- "version": "0.3.3",+ "version": "0.3.4","hasInstallScript": true,"license": "BUSL-1.1","dependencies": {diff --git a/package.json b/package.jsonindex a09b030e1..7b420a362 100644--- a/package.json+++ b/package.json@@ -14,7 +14,7 @@"main": "./out/main/index.js","scripts": {"dev": "electron-vite dev",- "build": "electron-vite build && npm run build:codex-relay",+ "build": "electron-vite build && npm run host:build && npm run build:codex-relay","build:codex-relay": "node scripts/build-codex-relay.mjs","preview": "electron-vite preview","start": "electron-vite preview",@@ -28,10 +28,10 @@"server:dev": "npm run build && npm run server:build && node out/server/main.cjs","make-icon": "node scripts/make-icon.mjs","make-social": "node scripts/make-social.mjs",- "dist": "npm run make-icon && electron-vite build && electron-builder --mac --arm64 --publish never -c.mac.identity=null -c.mac.notarize=false -c.extraMetadata.nodeTermUpdates=disabled",- "dist:linux": "npm run make-icon && electron-vite build && electron-builder --linux --publish never -c.extraMetadata.nodeTermUpdates=disabled",- "dist:win": "npm run make-icon && electron-vite build && electron-builder --win --x64 --publish never -c.extraMetadata.nodeTermUpdates=disabled",- "release": "npm run make-icon && electron-vite build && sh -c 'electron-builder --mac --arm64 --x64 --publish never; s=$?; npm run rebuild; exit $s'",+ "dist": "npm run make-icon && electron-vite build && npm run host:build && electron-builder --mac --arm64 --publish never -c.mac.identity=null -c.mac.notarize=false -c.extraMetadata.nodeTermUpdates=disabled",+ "dist:linux": "npm run make-icon && electron-vite build && npm run host:build && electron-builder --linux --publish never -c.extraMetadata.nodeTermUpdates=disabled",+ "dist:win": "npm run make-icon && electron-vite build && npm run host:build && electron-builder --win --x64 --publish never -c.extraMetadata.nodeTermUpdates=disabled",+ "release": "npm run make-icon && electron-vite build && npm run host:build && sh -c 'electron-builder --mac --arm64 --x64 --publish never; s=$?; npm run rebuild; exit $s'","postinstall": "node scripts/patch-node-pty.mjs && electron-rebuild -f -w node-pty,smart-whisper"},"build": {diff --git a/src/core/platform.ts b/src/core/platform.tsindex df63cb516..6a4681f06 100644--- a/src/core/platform.ts+++ b/src/core/platform.ts@@ -13,6 +13,12 @@ export interface CorePlatform {* because it is an Electron notion: the Server Edition has no such directory and simply omits* it, which is also how src/core stays Electron-free (no-electron.test.ts). */readonly resourcesPath?: string+ /** Electron's `app.getAppPath()` — `<resourcesPath>/app.asar` when packaged, the repo root in+ * dev. This is where `build.files` carries `out/**`, so it is where the session-host bundle+ * lands; see session-host-launcher.ts for why it must be resolved from INSIDE the asar rather+ * than copied beside it. OPTIONAL for the same reason as `resourcesPath`: an Electron notion+ * the Server Edition omits. */+ readonly appPath?: string/** Seal / unseal a secret at rest, byte-in byte-out. Present together on a shell that can* encrypt (Desktop: Electron safeStorage). Their ABSENCE is a supported configuration, not a* degradation: the Server Edition runs headless with no OS keychain and deliberately storesdiff --git a/src/core/session-host-backend.ts b/src/core/session-host-backend.tsindex 7837ca413..744c7da2c 100644--- a/src/core/session-host-backend.ts+++ b/src/core/session-host-backend.ts@@ -20,6 +20,10 @@ function getClient(): SessionHostClient {client = new SessionHostClient({userDataDir: platform().userDataDir,resourcesPath: platform().resourcesPath,+ // The one that actually answers in a packaged build: `app.getAppPath()` is the asar, where+ // `build.files` already carries `out/session-host/host.cjs`. In dev it is the repo root, so+ // the same candidate covers both.+ appPath: platform().appPath,// Dev-mode fallback, mirroring `findTmux`'s own `process.cwd()` use: under `electron-vite// dev` the cwd is the repo root, which is where `npm run host:build` writes its bundle.repoRoot: process.cwd()@@ -30,7 +34,7 @@ function getClient(): SessionHostClient {/*** Is the session-host bundle actually present on this machine? False only in a dev checkout that- * never ran `npm run host:build` (or `npm run build`, which now runs it too) — unlike tmux, this+ * never ran `npm run host:build` (or `npm run build`, which runs it too) — unlike tmux, this* backend has no external binary to be "missing"; the only way it can be unavailable is an* incomplete build. `pty-manager.ts` combines this with "no local tmux was found" and the* `tmuxEnabled` setting to decide whether to actually select this backend for a given session.diff --git a/src/core/session-host-client.ts b/src/core/session-host-client.tsindex a40bef0ab..866b9867a 100644--- a/src/core/session-host-client.ts+++ b/src/core/session-host-client.ts@@ -239,6 +239,7 @@ export class SessionHostClient {private readonly deps: {userDataDir: stringresourcesPath?: string | null+ appPath?: string | nullrepoRoot?: string | null}) {}@@ -247,6 +248,7 @@ export class SessionHostClient {return (resolveSessionHostScript({resourcesPath: this.deps.resourcesPath,+ appPath: this.deps.appPath,repoRoot: this.deps.repoRoot}) !== null)@@ -346,6 +348,7 @@ export class SessionHostClient {const script = resolveSessionHostScript({resourcesPath: this.deps.resourcesPath,+ appPath: this.deps.appPath,repoRoot: this.deps.repoRoot})if (!script) {diff --git a/src/core/session-host-launcher.test.ts b/src/core/session-host-launcher.test.tsnew file mode 100644index 000000000..94663bf30--- /dev/null+++ b/src/core/session-host-launcher.test.ts@@ -0,0 +1,62 @@+import { describe, it, expect } from 'vitest'+import path from 'path'+import { resolveSessionHostScript } from './session-host-launcher'++const asar = path.join('/app', 'resources', 'app.asar')+const resources = path.join('/app', 'resources')+const repo = path.join('/home', 'me', 'nodeterm')++const inAsar = path.join(asar, 'out', 'session-host', 'host.cjs')+const inResources = path.join(resources, 'session-host', 'host.cjs')+const inRepo = path.join(repo, 'out', 'session-host', 'host.cjs')++/** `exists` is injected so the resolution order is testable without a filesystem. */+const only = (...present: string[]) => (p: string) => present.includes(p)++describe('resolveSessionHostScript', () => {+ it('finds the bundle inside the asar — the packaged path', () => {+ // This is the one that matters: `build.files` carries `out/**` into the asar, so the bundle is+ // already there, and a host resolved from inside the asar can reach `node-pty` (a host copied+ // to <resourcesPath>/session-host cannot — see the module comment).+ expect(+ resolveSessionHostScript({ resourcesPath: resources, appPath: asar, repoRoot: repo, exists: only(inAsar) })+ ).toBe(inAsar)+ })++ it('finds the bundle in a dev checkout, where appPath IS the repo root', () => {+ expect(+ resolveSessionHostScript({ appPath: repo, repoRoot: repo, exists: only(inRepo) })+ ).toBe(inRepo)+ })++ it('still honours an extraResources copy when one exists, and prefers it', () => {+ // Kept ahead of the others so an installation that DOES ship the copy is unaffected.+ expect(+ resolveSessionHostScript({ resourcesPath: resources, appPath: asar, exists: only(inResources, inAsar) })+ ).toBe(inResources)+ })++ it('falls back to repoRoot for a shell that supplies no app path', () => {+ expect(resolveSessionHostScript({ repoRoot: repo, exists: only(inRepo) })).toBe(inRepo)+ })++ it('answers null when the bundle was never built', () => {+ // An incomplete build is the only way this backend can be unavailable, so the miss must be+ // clean rather than a path that does not exist.+ expect(+ resolveSessionHostScript({ resourcesPath: resources, appPath: asar, repoRoot: repo, exists: () => false })+ ).toBeNull()+ })++ it('ignores absent opts rather than building paths from undefined', () => {+ expect(resolveSessionHostScript({ exists: () => true })).toBeNull()+ })++ it('keeps looking when a candidate throws', () => {+ const exists = (p: string) => {+ if (p === inResources) throw new Error('EPERM')+ return p === inAsar+ }+ expect(resolveSessionHostScript({ resourcesPath: resources, appPath: asar, exists })).toBe(inAsar)+ })+})diff --git a/src/core/session-host-launcher.ts b/src/core/session-host-launcher.tsindex 95b49ab5a..051c4ad70 100644--- a/src/core/session-host-launcher.ts+++ b/src/core/session-host-launcher.ts@@ -10,20 +10,37 @@ import { spawn } from 'child_process'/*** Where `out/session-host/host.cjs` lives, in dev vs a packaged build.*- * - Packaged: `electron-builder`'s `extraResources` copies `out/session-host` to- * `<resourcesPath>/session-host` (see package.json's `build.extraResources`), mirroring how the- * bundled tmux binary lands under `<resourcesPath>/bin`.- * - Dev (`electron-vite dev`): `process.cwd()` is the repo root, and `npm run build` /- * `npm run host:build` write straight to `<repoRoot>/out/session-host/host.cjs`.+ * - Packaged: inside the asar, at `<appPath>/out/session-host/host.cjs`. `build.files` is+ * `["out/**", "package.json"]`, so the bundle is already carried there by the ordinary packaging+ * rules — nothing has to copy it anywhere.+ *+ * This is deliberately NOT `<resourcesPath>/session-host` via `extraResources`, which is what the+ * original comment here described (an `extraResources` entry that was never actually added). A+ * host placed there cannot RUN: Electron patches `Module._nodeModulePaths` so a script under+ * `resourcesPath` may only resolve from paths under `resourcesPath`, and the search list for+ * `<resourcesPath>/session-host` is just+ *+ * <resourcesPath>/session-host/node_modules+ * <resourcesPath>/node_modules+ *+ * neither of which holds `node-pty` — which the bundle needs, since `host:build` marks it+ * `--external`. From inside the asar the search list instead reaches+ * `<resourcesPath>/app.asar/node_modules`, where electron-builder's unpacked-native redirect+ * makes `node-pty` resolve. Measured on a packaged Windows build; see the tests.+ *+ * - Dev (`electron-vite dev`): `app.getAppPath()` IS the repo root, so the same candidate answers+ * both. `repoRoot` (`process.cwd()`) stays as a fallback for shells that supply no app path.*/export function resolveSessionHostScript(opts: {resourcesPath?: string | null+ appPath?: string | nullrepoRoot?: string | nullexists?: (p: string) => boolean}): string | null {const exists = opts.exists ?? fs.existsSyncconst candidates: string[] = []if (opts.resourcesPath) candidates.push(path.join(opts.resourcesPath, 'session-host', 'host.cjs'))+ if (opts.appPath) candidates.push(path.join(opts.appPath, 'out', 'session-host', 'host.cjs'))if (opts.repoRoot) candidates.push(path.join(opts.repoRoot, 'out', 'session-host', 'host.cjs'))for (const c of candidates) {try {diff --git a/src/main/platform-electron.ts b/src/main/platform-electron.tsindex c276f9b99..8baf99f64 100644--- a/src/main/platform-electron.ts+++ b/src/main/platform-electron.ts@@ -81,6 +81,11 @@ export function electronPlatform(): ElectronPlatform {get resourcesPath() {return process.resourcesPath},+ // `<resourcesPath>/app.asar` when packaged, the repo root under `electron-vite dev` — one+ // candidate that answers for both, which is why the session-host lookup prefers it.+ get appPath() {+ return app.getAppPath()+ },// The ipcMain half of each registration is UNCHANGED — the local window's call is bit-identical// to what it was before the table existed (same event-stripping, same sender id).handle: (ch, fn) => {