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): CorePlatform seam + electron-import boundary test
enes2d14cb242555
diff --git a/src/core/no-electron.test.ts b/src/core/no-electron.test.tsnew file mode 100644index 000000000..c23643107--- /dev/null+++ b/src/core/no-electron.test.ts@@ -0,0 +1,19 @@+import { describe, it, expect } from 'vitest'+import fs from 'fs'+import path from 'path'++function walk(dir: string): string[] {+ return fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => {+ const p = path.join(dir, e.name)+ return e.isDirectory() ? walk(p) : p.endsWith('.ts') ? [p] : []+ })+}++describe('core boundary', () => {+ it('no file under src/core imports electron', () => {+ const offenders = walk(__dirname).filter((f) =>+ /from ['"]electron['"]|require\(['"]electron['"]\)/.test(fs.readFileSync(f, 'utf8'))+ )+ expect(offenders).toEqual([])+ })+})diff --git a/src/core/platform-fake.ts b/src/core/platform-fake.tsnew file mode 100644index 000000000..a1b279ebf--- /dev/null+++ b/src/core/platform-fake.ts@@ -0,0 +1,41 @@+import type { CorePlatform } from './platform'++export interface FakePlatform extends CorePlatform {+ handlers: Record<string, (...args: any[]) => unknown>+ listeners: Record<string, (...args: any[]) => void>+ sent: Array<{ to: number | 'broadcast'; channel: string; args: any[] }>+ opened: string[]+}++/** In-memory CorePlatform for tests. Not a mock library — plain recording object. */+export function fakePlatform(overrides: Partial<CorePlatform> = {}): FakePlatform {+ const f: FakePlatform = {+ userDataDir: '/tmp/nodeterm-test',+ appVersion: '0.0.0-test',+ isPackaged: false,+ handlers: {},+ listeners: {},+ sent: [],+ opened: [],+ handle(ch, fn) {+ f.handlers[ch] = fn+ },+ on(ch, fn) {+ f.listeners[ch] = fn+ },+ handleWithSender(ch, fn) {+ f.handlers[ch] = fn as (...args: any[]) => unknown+ },+ sendTo(to, channel, ...args) {+ f.sent.push({ to, channel, args })+ },+ broadcast(channel, ...args) {+ f.sent.push({ to: 'broadcast', channel, args })+ },+ async openExternal(url) {+ f.opened.push(url)+ },+ ...overrides,+ }+ return f+}diff --git a/src/core/platform.test.ts b/src/core/platform.test.tsnew file mode 100644index 000000000..ed656083f--- /dev/null+++ b/src/core/platform.test.ts@@ -0,0 +1,31 @@+import { describe, it, expect, afterEach } from 'vitest'+import { initPlatform, platform, resetPlatformForTests } from './platform'+import { fakePlatform } from './platform-fake'++afterEach(() => resetPlatformForTests())++describe('core platform accessor', () => {+ it('throws before initialization', () => {+ expect(() => platform()).toThrow(/not initialized/)+ })++ it('returns the initialized platform', () => {+ const fake = fakePlatform({ userDataDir: '/tmp/x' })+ initPlatform(fake)+ expect(platform().userDataDir).toBe('/tmp/x')+ })++ it('fake records handlers, sends and openExternal', async () => {+ const fake = fakePlatform()+ fake.handle('a:b', () => 42)+ expect(await fake.handlers['a:b']()).toBe(42)+ fake.sendTo(7, 'ev', 1)+ fake.broadcast('ev2', 'x')+ await fake.openExternal('https://example.com')+ expect(fake.sent).toEqual([+ { to: 7, channel: 'ev', args: [1] },+ { to: 'broadcast', channel: 'ev2', args: ['x'] },+ ])+ expect(fake.opened).toEqual(['https://example.com'])+ })+})diff --git a/src/core/platform.ts b/src/core/platform.tsnew file mode 100644index 000000000..56cb64f25--- /dev/null+++ b/src/core/platform.ts@@ -0,0 +1,38 @@+/**+ * The platform seam of the Server Edition split: everything in src/core talks+ * to its shell (Electron main today, the Linux server later) only through this+ * interface. src/core must never import 'electron' (see no-electron.test.ts).+ */+export interface CorePlatform {+ /** Root for all persistent state (Electron: app.getPath('userData')). */+ readonly userDataDir: string+ readonly appVersion: string+ readonly isPackaged: boolean+ /** Register a request/response RPC handler (Electron: ipcMain.handle, event stripped). */+ handle(channel: string, fn: (...args: any[]) => unknown): void+ /** Register a fire-and-forget handler (Electron: ipcMain.on, event stripped). */+ on(channel: string, fn: (...args: any[]) => void): void+ /** Like handle, but fn receives the calling UI's numeric id first (Electron: event.sender.id). */+ handleWithSender(channel: string, fn: (senderId: number, ...args: any[]) => unknown): void+ /** Send to one attached UI by id (Electron: webContents.fromId). Silently drops if gone. */+ sendTo(uiId: number, channel: string, ...args: any[]): void+ /** Send to every attached UI (Electron: the main window). */+ broadcast(channel: string, ...args: any[]): void+ /** Open a URL in the user's default browser. */+ openExternal(url: string): Promise<void>+}++let current: CorePlatform | null = null++export function initPlatform(p: CorePlatform): void {+ current = p+}++export function platform(): CorePlatform {+ if (!current) throw new Error('core platform not initialized — call initPlatform() at boot')+ return current+}++export function resetPlatformForTests(): void {+ current = null+}diff --git a/tsconfig.node.json b/tsconfig.node.jsonindex 90285e219..e019f9560 100644--- a/tsconfig.node.json+++ b/tsconfig.node.json@@ -17,6 +17,7 @@"electron.vite.config.ts","src/main/**/*","src/preload/**/*",- "src/shared/**/*"+ "src/shared/**/*",+ "src/core/**/*"]}diff --git a/vitest.config.ts b/vitest.config.tsindex c0a5a9d74..9f6958f9f 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -4,6 +4,7 @@ import { resolve } from 'path'export default defineConfig({test: {include: [+ 'src/core/**/*.test.ts','src/shared/**/*.test.ts','src/main/**/*.test.ts','src/renderer/**/*.test.ts',