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
refactor(core): electron CorePlatform adapter, initialized at boot
enes167c4902b989
diff --git a/src/main/index.ts b/src/main/index.tsindex bb8b981d0..70a1263b3 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -58,6 +58,8 @@ import {allowMediaPath,writeAgentHtml} from './media-protocol'+import { initPlatform } from '../core/platform'+import { electronPlatform } from './platform-electron'// Dev-only: NT_MULTI lets a SECOND instance run (host + client testing on one machine) with an// isolated userData via NT_USER_DATA — its own device-id/session/license/workspace. Never active@@ -65,6 +67,11 @@ import {const NT_MULTI = !app.isPackaged && !!process.env.NT_MULTIif (NT_MULTI && process.env.NT_USER_DATA) app.setPath('userData', process.env.NT_USER_DATA)+// First thing in bootstrap: install the Electron CorePlatform so anything in src/core+// (wired in later tasks) can resolve platform() at boot. Placed after the NT_MULTI+// userData override so userDataDir reads the final path; nothing consumes it yet.+initPlatform(electronPlatform())+// Only hand the OS a URL with a vetted scheme. Blocks file://, smb://, and custom// protocol-handler schemes that could be smuggled in via remote announcement feeds or// rendered markdown links. Used by both the window-open handler and the IPC handler.diff --git a/src/main/platform-electron.test.ts b/src/main/platform-electron.test.tsnew file mode 100644index 000000000..a76c9bbb7--- /dev/null+++ b/src/main/platform-electron.test.ts@@ -0,0 +1,64 @@+import { describe, it, expect, vi, beforeEach } from 'vitest'++const h: {+ handlers: Record<string, (...a: any[]) => unknown>+ sent: Array<{ id?: number; channel: string; args: any[] }>+} = { handlers: {}, sent: [] }++vi.mock('electron', () => ({+ app: {+ getPath: () => '/tmp/ud',+ getVersion: () => '9.9.9',+ isPackaged: false,+ },+ ipcMain: {+ handle: (ch: string, fn: (...a: any[]) => unknown) => {+ h.handlers[ch] = fn+ },+ on: (ch: string, fn: (...a: any[]) => void) => {+ h.handlers[ch] = fn+ },+ },+ webContents: {+ fromId: (id: number) =>+ id === 1+ ? { isDestroyed: () => false, send: (ch: string, ...args: any[]) => h.sent.push({ id, channel: ch, args }) }+ : undefined,+ },+ shell: { openExternal: vi.fn(async () => {}) },+}))++vi.mock('./main-window', () => ({+ sendToMain: (ch: string, ...args: any[]) => h.sent.push({ channel: ch, args }),+}))++import { electronPlatform } from './platform-electron'++beforeEach(() => {+ h.handlers = {}+ h.sent = []+})++describe('electronPlatform', () => {+ it('exposes app paths and version', () => {+ const p = electronPlatform()+ expect(p.userDataDir).toBe('/tmp/ud')+ expect(p.appVersion).toBe('9.9.9')+ expect(p.isPackaged).toBe(false)+ })++ it('strips the ipc event from handle/on and forwards sender id in handleWithSender', async () => {+ const p = electronPlatform()+ p.handle('c1', (a: number) => a + 1)+ expect(await h.handlers['c1']({ sender: { id: 1 } }, 41)).toBe(42)+ p.handleWithSender('c2', (senderId: number, a: string) => `${senderId}:${a}`)+ expect(await h.handlers['c2']({ sender: { id: 7 } }, 'x')).toBe('7:x')+ })++ it('sendTo drops silently when the webContents is gone', () => {+ const p = electronPlatform()+ p.sendTo(1, 'ev', 'a')+ p.sendTo(999, 'ev', 'b') // must not throw+ expect(h.sent).toEqual([{ id: 1, channel: 'ev', args: ['a'] }])+ })+})diff --git a/src/main/platform-electron.ts b/src/main/platform-electron.tsnew file mode 100644index 000000000..1f0bbed26--- /dev/null+++ b/src/main/platform-electron.ts@@ -0,0 +1,27 @@+import { app, ipcMain, shell, webContents } from 'electron'+import type { CorePlatform } from '../core/platform'+import { sendToMain } from './main-window'++/** The Electron shell's CorePlatform. Getters keep app.getPath lazy (safe pre-ready). */+export function electronPlatform(): CorePlatform {+ return {+ get userDataDir() {+ return app.getPath('userData')+ },+ get appVersion() {+ return app.getVersion()+ },+ get isPackaged() {+ return app.isPackaged+ },+ handle: (ch, fn) => ipcMain.handle(ch, (_e, ...args) => fn(...args)),+ on: (ch, fn) => ipcMain.on(ch, (_e, ...args) => fn(...args)),+ handleWithSender: (ch, fn) => ipcMain.handle(ch, (e, ...args) => fn(e.sender.id, ...args)),+ sendTo: (id, ch, ...args) => {+ const wc = webContents.fromId(id)+ if (wc && !wc.isDestroyed()) wc.send(ch, ...args)+ },+ broadcast: (ch, ...args) => sendToMain(ch, ...args),+ openExternal: (url) => shell.openExternal(url),+ }+}