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
feat(bridge): real fs/git/files/context namespaces over the WS client
enesa07afcfd185e
diff --git a/src/renderer/bridge/stubs.test.ts b/src/renderer/bridge/stubs.test.tsindex 7e37fc251..d7ccb699b 100644--- a/src/renderer/bridge/stubs.test.ts+++ b/src/renderer/bridge/stubs.test.ts@@ -11,7 +11,6 @@ describe('bridge stubs', () => {const s = buildStubApi()for (const un of [s.license.onChange(() => {}),- s.context.onUpdate(() => {}),s.onCloseNode(() => {}),s.onFocusNode(() => {}),s.browser.onBrowserNewWindow(() => {}),@@ -46,7 +45,6 @@ describe('bridge stubs', () => {expect(() => {s.setBadgeCount(3)s.contextLink.setLinks({} as never)- s.context.ensure('sid', '/cwd', undefined)s.sendAgentControlResult({} as never)}).not.toThrow()})diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex 55df9e0f7..284aac969 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -1,16 +1,17 @@// Graceful non-terminal stub surface for the browser (Server Edition) build.//-// The three real namespaces (`pty`, `workspace`, `settings`) are provided by the ws-bridge-// (Task 8); everything else here degrades benignly so the renderer boots without a full-// Electron preload. The exact per-member behavior is the boot-path contract encoded in the-// Task 7 brief (derived from a full renderer-boot audit): every `on*` subscription MUST return-// a callable no-op unsubscribe (the renderer uses the return value as a React effect cleanup —-// a missing member or a non-function return is a mount crash), promise members that the boot-// path awaits resolve to a benign value, and everything else rejects with a coded error.+// The real namespaces (`pty`, `workspace`, `settings`, and the fs/git/files/context group from+// `buildFilesApi`) are provided by the ws-bridge; everything else here degrades benignly so the+// renderer boots without a full Electron preload. The exact per-member behavior is the boot-path+// contract encoded in the Task 7 brief (derived from a full renderer-boot audit): every `on*`+// subscription MUST return a callable no-op unsubscribe (the renderer uses the return value as a+// React effect cleanup — a missing member or a non-function return is a mount crash), promise+// members that the boot path awaits resolve to a benign value, and everything else rejects with a+// coded error.//-// The object is `satisfies Omit<NodeTerminalApi, 'pty' | 'workspace' | 'settings'>`, so the-// TypeScript compiler is the completeness test: if `NodeTerminalApi` gains a member, this file-// fails to typecheck until the stub is declared.+// The object is `satisfies Omit<NodeTerminalApi, 'pty' | 'workspace' | 'settings' | 'fs' | 'git'+// | 'files' | 'context'>`, so the TypeScript compiler is the completeness test: if+// `NodeTerminalApi` gains a member, this file fails to typecheck until the stub is declared.import type { ClaudeUsage, NodeTerminalApi, NotifyPayload, UpdatePolicy } from '../../shared/types'import { E_UNSUPPORTED } from '../../shared/rpc'@@ -36,7 +37,10 @@ const noop = (): void => {}/** Promise<void> member: a resolved no-op. */const pnoop = (): Promise<void> => Promise.resolve()-export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'settings'> {+export function buildStubApi(): Omit<+ NodeTerminalApi,+ 'pty' | 'workspace' | 'settings' | 'fs' | 'git' | 'files' | 'context'+> {const api = {dialog: {// Web folder/file pickers are Phase 3.@@ -64,49 +68,6 @@ export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'setreadBinary: U('sshFs.readBinary'),write: U('sshFs.write')},- git: {- status: U('git.status'),- init: U('git.init'),- clone: U('git.clone'),- cloneAbort: U('git.cloneAbort'),- cloneDefaultParent: U('git.cloneDefaultParent'),- onCloneProgress: noopUnsub,- commit: U('git.commit'),- push: U('git.push'),- pull: U('git.pull'),- sync: U('git.sync'),- publish: U('git.publish'),- stage: U('git.stage'),- unstage: U('git.unstage'),- stageAll: U('git.stageAll'),- unstageAll: U('git.unstageAll'),- diff: U('git.diff'),- discard: U('git.discard'),- switchBranch: U('git.switchBranch'),- createBranch: U('git.createBranch'),- showFile: U('git.showFile'),- generateMessage: U('git.generateMessage'),- history: U('git.history'),- commitFiles: U('git.commitFiles'),- remoteCommitUrl: U('git.remoteCommitUrl'),- merge: U('git.merge'),- rebase: U('git.rebase'),- deleteBranch: U('git.deleteBranch'),- renameBranch: U('git.renameBranch'),- fetch: U('git.fetch'),- forcePush: U('git.forcePush'),- stashPush: U('git.stashPush'),- stashPop: U('git.stashPop'),- revert: U('git.revert'),- branchAt: U('git.branchAt'),- checkoutCommit: U('git.checkoutCommit'),- repoRoot: U('git.repoRoot'),- worktreeList: U('git.worktreeList'),- worktreeAdd: U('git.worktreeAdd'),- worktreeMerge: U('git.worktreeMerge'),- worktreeRemove: U('git.worktreeRemove'),- setActiveRemote: U('git.setActiveRemote')- },clipboard: {// The one browser-native member: use the Clipboard API when present, swallow failures.writeText: (text: string): void => {@@ -120,12 +81,6 @@ export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'setopenPath: noop,openExternal: noop},- fs: {- list: U('fs.list'),- read: U('fs.read'),- readBinary: U('fs.readBinary'),- write: U('fs.write')- },media: {allow: U('media.allow'),writeHtml: U('media.writeHtml')@@ -135,9 +90,6 @@ export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'setunregister: noop,onBrowserNewWindow: noopUnsub},- files: {- quickOpen: U('files.quickOpen')- },updates: {onAvailable: noopUnsub,onDownloaded: noopUnsub,@@ -171,10 +123,6 @@ export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'setrefresh: U('usage.refresh'),onUpdate: noopUnsub},- context: {- onUpdate: noopUnsub,- ensure: noop- },claude: {readTranscript: U('claude.readTranscript')},@@ -258,7 +206,10 @@ export function buildStubApi(): Omit<NodeTerminalApi, 'pty' | 'workspace' | 'setonSubagentActivity: noopUnsub,onAgentControl: noopUnsub,sendAgentControlResult: noop- } satisfies Omit<NodeTerminalApi, 'pty' | 'workspace' | 'settings'>+ } satisfies Omit<+ NodeTerminalApi,+ 'pty' | 'workspace' | 'settings' | 'fs' | 'git' | 'files' | 'context'+ >return api}diff --git a/src/renderer/bridge/ws-bridge.namespaces.test.ts b/src/renderer/bridge/ws-bridge.namespaces.test.tsnew file mode 100644index 000000000..9dc895c20--- /dev/null+++ b/src/renderer/bridge/ws-bridge.namespaces.test.ts@@ -0,0 +1,48 @@+import { describe, it, expect } from 'vitest'+import { buildFilesApi } from './ws-bridge'+import { IPC } from '../../shared/ipc'++function fakeClient() {+ const calls: Array<{ kind: string; method: string; args: unknown[] }> = []+ return {+ calls,+ request: (method: string, ...args: unknown[]) => {+ calls.push({ kind: 'request', method, args })+ return Promise.resolve('R')+ },+ cast: (method: string, ...args: unknown[]) => calls.push({ kind: 'cast', method, args }),+ subscribe: (channel: string, _fn: (...a: unknown[]) => void) => {+ calls.push({ kind: 'subscribe', method: channel, args: [] })+ return () => {}+ }+ }+}++describe('buildFilesApi', () => {+ it('fs/git/files members are request-shaped with the right channels', async () => {+ const c = fakeClient()+ const api = buildFilesApi(c as never)+ await api.fs.read('/x')+ await api.git.status('/repo')+ await api.git.showFile('/repo', 'HEAD', 'a.txt')+ await api.files.quickOpen('/repo')+ expect(c.calls).toEqual([+ { kind: 'request', method: IPC.fsRead, args: ['/x'] },+ { kind: 'request', method: IPC.gitStatus, args: ['/repo'] },+ { kind: 'request', method: IPC.gitShowFile, args: ['/repo', 'HEAD', 'a.txt'] },+ { kind: 'request', method: IPC.filesQuickOpen, args: ['/repo'] }+ ])+ })+ it('context.ensure is a cast; context.onUpdate/git.onCloneProgress subscribe', () => {+ const c = fakeClient()+ const api = buildFilesApi(c as never)+ api.context.ensure('sid', '/cwd', undefined)+ const un = api.context.onUpdate(() => {})+ const un2 = api.git.onCloneProgress(() => {})+ expect(c.calls[0]).toEqual({ kind: 'cast', method: IPC.contextEnsure, args: ['sid', '/cwd', undefined] })+ expect(c.calls[1]).toEqual({ kind: 'subscribe', method: IPC.contextUpdate, args: [] })+ expect(c.calls[2]).toEqual({ kind: 'subscribe', method: IPC.gitCloneProgress, args: [] })+ expect(typeof un).toBe('function')+ expect(typeof un2).toBe('function')+ })+})diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.tsindex 7aa9b3a61..ca2221bf5 100644--- a/src/renderer/bridge/ws-bridge.ts+++ b/src/renderer/bridge/ws-bridge.ts@@ -9,6 +9,10 @@import { parseRpcMessage, decodePtyData, type RpcMessage } from '../../shared/rpc'import { IPC } from '../../shared/ipc'import type {+ ContextApi,+ FilesApi,+ FsApi,+ GitApi,NodeTerminalApi,PtyApi,PtyCreateOptions,@@ -187,6 +191,122 @@ function buildRealApi(client: RpcClient): Pick<NodeTerminalApi, 'pty' | 'workspareturn { pty, workspace, settings }}+/**+ * Build the real `fs` / `git` / `files` / `context` namespaces over an RpcClient, mirroring the+ * preload's invoke(→request) / send(→cast) / on*(→subscribe) split member-for-member. Every+ * `fs.*`, `git.*`, `files.quickOpen` and `git.generateMessage` member is an `invoke` in the+ * preload → `client.request`; `context.ensure` is a `send` → `client.cast`; the event-shaped+ * `git.onCloneProgress` / `context.onUpdate` are `.on` → `client.subscribe`. `git.generateMessage`+ * routes over `IPC.commitGenerate` (not a git:* channel) exactly as the preload does. Each namespace+ * is declared against its `NodeTerminalApi` slice so `satisfies` makes the compiler the completeness+ * gate: a missing or misnamed member fails typecheck.+ */+export function buildFilesApi(+ client: RpcClient+): Pick<NodeTerminalApi, 'fs' | 'git' | 'files' | 'context'> {+ const fs: FsApi = {+ list: (dirPath) => client.request(IPC.fsList, dirPath) as ReturnType<FsApi['list']>,+ read: (filePath) => client.request(IPC.fsRead, filePath) as Promise<string>,+ readBinary: (filePath) => client.request(IPC.fsReadBinary, filePath) as Promise<string>,+ write: (filePath, content) => client.request(IPC.fsWrite, filePath, content) as Promise<boolean>+ }++ const git: GitApi = {+ status: (cwd) => client.request(IPC.gitStatus, cwd) as ReturnType<GitApi['status']>,+ init: (cwd) => client.request(IPC.gitInit, cwd) as ReturnType<GitApi['init']>,+ clone: (parentDir, url) =>+ client.request(IPC.gitClone, parentDir, url) as ReturnType<GitApi['clone']>,+ cloneAbort: () => client.request(IPC.gitCloneAbort) as Promise<void>,+ cloneDefaultParent: () => client.request(IPC.gitCloneDefaultParent) as Promise<string>,+ onCloneProgress: (listener) => client.subscribe(IPC.gitCloneProgress, listener as Listener),+ commit: (cwd, message) =>+ client.request(IPC.gitCommit, cwd, message) as ReturnType<GitApi['commit']>,+ push: (cwd) => client.request(IPC.gitPush, cwd) as ReturnType<GitApi['push']>,+ pull: (cwd) => client.request(IPC.gitPull, cwd) as ReturnType<GitApi['pull']>,+ sync: (cwd) => client.request(IPC.gitSync, cwd) as ReturnType<GitApi['sync']>,+ publish: (cwd, name, isPrivate) =>+ client.request(IPC.gitPublish, cwd, name, isPrivate) as ReturnType<GitApi['publish']>,+ stage: (cwd, paths) => client.request(IPC.gitStage, cwd, paths) as ReturnType<GitApi['stage']>,+ unstage: (cwd, paths) =>+ client.request(IPC.gitUnstage, cwd, paths) as ReturnType<GitApi['unstage']>,+ stageAll: (cwd) => client.request(IPC.gitStageAll, cwd) as ReturnType<GitApi['stageAll']>,+ unstageAll: (cwd) => client.request(IPC.gitUnstageAll, cwd) as ReturnType<GitApi['unstageAll']>,+ diff: (cwd, path, staged, untracked) =>+ client.request(IPC.gitDiff, cwd, path, staged, untracked) as Promise<string>,+ discard: (cwd, path, untracked) =>+ client.request(IPC.gitDiscard, cwd, path, untracked) as ReturnType<GitApi['discard']>,+ switchBranch: (cwd, name) =>+ client.request(IPC.gitSwitchBranch, cwd, name) as ReturnType<GitApi['switchBranch']>,+ createBranch: (cwd, name) =>+ client.request(IPC.gitCreateBranch, cwd, name) as ReturnType<GitApi['createBranch']>,+ showFile: (cwd, ref, path) =>+ client.request(IPC.gitShowFile, cwd, ref, path) as Promise<string>,+ generateMessage: (cwd) =>+ client.request(IPC.commitGenerate, cwd) as ReturnType<GitApi['generateMessage']>,+ history: (cwd, options) =>+ client.request(IPC.gitHistory, cwd, options) as ReturnType<GitApi['history']>,+ commitFiles: (cwd, oid) =>+ client.request(IPC.gitCommitFiles, cwd, oid) as ReturnType<GitApi['commitFiles']>,+ remoteCommitUrl: (cwd, sha) =>+ client.request(IPC.gitRemoteCommitUrl, cwd, sha) as Promise<string | null>,+ merge: (cwd, ref) => client.request(IPC.gitMerge, cwd, ref) as ReturnType<GitApi['merge']>,+ rebase: (cwd, onto) => client.request(IPC.gitRebase, cwd, onto) as ReturnType<GitApi['rebase']>,+ deleteBranch: (cwd, name, force) =>+ client.request(IPC.gitDeleteBranch, cwd, name, force) as ReturnType<GitApi['deleteBranch']>,+ renameBranch: (cwd, newName) =>+ client.request(IPC.gitRenameBranch, cwd, newName) as ReturnType<GitApi['renameBranch']>,+ fetch: (cwd) => client.request(IPC.gitFetch, cwd) as ReturnType<GitApi['fetch']>,+ forcePush: (cwd) => client.request(IPC.gitForcePush, cwd) as ReturnType<GitApi['forcePush']>,+ stashPush: (cwd) => client.request(IPC.gitStashPush, cwd) as ReturnType<GitApi['stashPush']>,+ stashPop: (cwd) => client.request(IPC.gitStashPop, cwd) as ReturnType<GitApi['stashPop']>,+ revert: (cwd, oid) => client.request(IPC.gitRevert, cwd, oid) as ReturnType<GitApi['revert']>,+ branchAt: (cwd, name, oid) =>+ client.request(IPC.gitBranchAt, cwd, name, oid) as ReturnType<GitApi['branchAt']>,+ checkoutCommit: (cwd, oid) =>+ client.request(IPC.gitCheckoutCommit, cwd, oid) as ReturnType<GitApi['checkoutCommit']>,+ repoRoot: (cwd) => client.request(IPC.gitRepoRoot, cwd) as Promise<string | null>,+ worktreeList: (repoPath) =>+ client.request(IPC.gitWorktreeList, repoPath) as ReturnType<GitApi['worktreeList']>,+ worktreeAdd: (repoPath, wtPath, branch, baseRef, isNew) =>+ client.request(+ IPC.gitWorktreeAdd,+ repoPath,+ wtPath,+ branch,+ baseRef,+ isNew+ ) as ReturnType<GitApi['worktreeAdd']>,+ worktreeMerge: (repoPath, branch, baseRef) =>+ client.request(+ IPC.gitWorktreeMerge,+ repoPath,+ branch,+ baseRef+ ) as ReturnType<GitApi['worktreeMerge']>,+ worktreeRemove: (repoPath, wtPath, deleteBranch) =>+ client.request(+ IPC.gitWorktreeRemove,+ repoPath,+ wtPath,+ deleteBranch+ ) as ReturnType<GitApi['worktreeRemove']>,+ setActiveRemote: (projectId) =>+ client.request(IPC.gitSetActiveRemote, projectId) as Promise<void>+ }++ const files: FilesApi = {+ quickOpen: (cwd) => client.request(IPC.filesQuickOpen, cwd) as Promise<string[]>+ }++ const context: ContextApi = {+ onUpdate: (listener) => client.subscribe(IPC.contextUpdate, listener as Listener),+ ensure: (sessionId, cwd, accountId) =>+ client.cast(IPC.contextEnsure, sessionId, cwd, accountId)+ }++ return { fs, git, files, context }+}+/** WS URL for the current page: same host, `/ws`, ws→http / wss→https. */function wsUrl(): string {const scheme = location.protocol === 'https:' ? 'wss' : 'ws'@@ -272,7 +392,8 @@ export async function installWsBridge(): Promise<void> {client.onClose(() => startReconnect())const api: NodeTerminalApi = {...buildStubApi(),- ...buildRealApi(client)+ ...buildRealApi(client),+ ...buildFilesApi(client)};(window as unknown as { nodeTerminal: NodeTerminalApi }).nodeTerminal = api}