Skip to content

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.

feat(ssh-p3): sshFs IPC + preload + renderer FsApi + refForProject

enese67e073f9aa8
diff --git a/src/main/index.ts b/src/main/index.ts
index 151500241..401f2d59a 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -37,6 +37,7 @@ import { initLicense } from './license'
import { initRemoteHost } from './remote/host-service'
import { initRemoteClient } from './remote/client-service'
import { initSshProject } from './remote-ssh/ssh-project'
+import { SshFs } from './ssh-fs'
// 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
@@ -238,6 +239,32 @@ app.whenReady().then(async () => {
)
ipcMain.handle(IPC.filesQuickOpen, (_e, cwd: string) => fsOps.listQuickOpenFiles(cwd))
+ // SSH-project Explorer/Editor fs: the remote analog of the fs:* handlers above, scoped to a
+ // project's ControlMaster. One SshFs bound to the SSH-project manager's own ssh runner (the SAME
+ // runner RemoteFile reuses — just forwarding stdin so writes work), resolved lazily because
+ // sshProjectManager is created below. The ref is looked up per call; a call before the manager
+ // exists, or for an unconnected project, finds no ref and fails open ([]/''/false).
+ const sshFs = new SshFs((args, stdin) =>
+ sshProjectManager ? sshProjectManager.sshRun(args, stdin) : Promise.resolve({ code: 1, stdout: '' })
+ )
+ const sshFsRefFor = (projectId: string) => sshProjectManager?.refForProject(projectId)
+ ipcMain.handle(IPC.sshFsList, (_e, projectId: string, p: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.listDir(ref, p) : Promise.resolve([])
+ })
+ ipcMain.handle(IPC.sshFsRead, (_e, projectId: string, p: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.readText(ref, p) : Promise.resolve('')
+ })
+ ipcMain.handle(IPC.sshFsReadBinary, (_e, projectId: string, p: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.readBinary(ref, p) : Promise.resolve('')
+ })
+ ipcMain.handle(IPC.sshFsWrite, (_e, projectId: string, p: string, content: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.writeText(ref, p, content) : Promise.resolve(false)
+ })
+
ipcMain.handle(IPC.dialogSelectFolder, async () => {
const result = await dialog.showOpenDialog({ properties: ['openDirectory', 'createDirectory'] })
return result.canceled || result.filePaths.length === 0 ? null : result.filePaths[0]
diff --git a/src/main/remote-ssh/ssh-project.test.ts b/src/main/remote-ssh/ssh-project.test.ts
index e479593cc..8b051aab9 100644
--- a/src/main/remote-ssh/ssh-project.test.ts
+++ b/src/main/remote-ssh/ssh-project.test.ts
@@ -39,4 +39,12 @@ describe('SshProjectManager', () => {
const { dirs } = await mgr.listDir('p1', '~')
expect(dirs).toEqual(['bin', 'src'])
})
+
+ it('refForProject resolves {conn, controlPath} after connect, undefined otherwise', async () => {
+ const { mgr } = makeMgr()
+ expect(mgr.refForProject('p1')).toBeUndefined()
+ await mgr.connect('p1', conn)
+ expect(mgr.refForProject('p1')).toEqual({ conn, controlPath: '/ud/ssh-cm/p1.sock' })
+ expect(mgr.refForProject('nope')).toBeUndefined()
+ })
})
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index 827699062..c6c8be631 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -167,8 +167,18 @@ export class SshProjectManager {
* search read over the SAME ControlMaster. `args` are full ssh child args (e.g. from
* `childArgs(conn, controlPath, cmd)`); returns `{ code, stdout }`.
*/
- sshRun(args: string[]): Promise<{ code: number; stdout: string }> {
- return this.r.run(args)
+ sshRun(args: string[], stdin?: string): Promise<{ code: number; stdout: string }> {
+ return this.r.run(args, stdin)
+ }
+
+ /**
+ * Resolve the `{ conn, controlPath }` ref for a connected project (the `SshFsRef` shape Phase 3's
+ * SshFs ops take). Returns `undefined` when the project isn't connected, so the `sshFs:*` IPC
+ * handlers can fail open (empty result) rather than throw.
+ */
+ refForProject(projectId: string): { conn: SshConnection; controlPath: string } | undefined {
+ const c = this.conns.get(projectId)
+ return c ? { conn: c.conn, controlPath: c.controlPath } : undefined
}
/** The resolved remote `$HOME` for a connected project, if known. */
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 05cdf87fe..b564d3aa2 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -96,6 +96,14 @@ const api: NodeTerminalApi = {
return () => ipcRenderer.removeListener(IPC.sshProjectStatus, h)
}
},
+ sshFs: {
+ list: (projectId: string, path: string) => ipcRenderer.invoke(IPC.sshFsList, projectId, path),
+ read: (projectId: string, path: string) => ipcRenderer.invoke(IPC.sshFsRead, projectId, path),
+ readBinary: (projectId: string, path: string) =>
+ ipcRenderer.invoke(IPC.sshFsReadBinary, projectId, path),
+ write: (projectId: string, path: string, content: string) =>
+ ipcRenderer.invoke(IPC.sshFsWrite, projectId, path, content)
+ },
git: {
status: (cwd) => ipcRenderer.invoke(IPC.gitStatus, cwd),
init: (cwd) => ipcRenderer.invoke(IPC.gitInit, cwd),
diff --git a/src/renderer/terminal/ssh-fs.ts b/src/renderer/terminal/ssh-fs.ts
new file mode 100644
index 000000000..7bb0025a7
--- /dev/null
+++ b/src/renderer/terminal/ssh-fs.ts
@@ -0,0 +1,14 @@
+// SSH-project filesystem API (renderer). `sshFs(projectId)` satisfies the same FsApi contract as
+// window.nodeTerminal.fs / remoteFs(connectionId), but proxies onto the SSH project's remote
+// filesystem over the ControlMaster (renderer → sshFs:* IPC → main ssh-fs over the master).
+import type { FsApi } from '@shared/types'
+
+export function sshFs(projectId: string): FsApi {
+ const api = window.nodeTerminal.sshFs
+ return {
+ list: (path) => api.list(projectId, path),
+ read: (path) => api.read(projectId, path),
+ readBinary: (path) => api.readBinary(projectId, path),
+ write: (path, content) => api.write(projectId, path, content)
+ }
+}
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index db9b263e6..935fee970 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -68,6 +68,10 @@ export const IPC = {
sshDisconnectProject: 'ssh:disconnect-project',
sshKillSessions: 'ssh:kill-sessions',
sshListDir: 'ssh:list-dir',
+ sshFsList: 'sshFs:list',
+ sshFsRead: 'sshFs:read',
+ sshFsReadBinary: 'sshFs:read-binary',
+ sshFsWrite: 'sshFs:write',
sshProjectStatus: 'ssh-project:status',
gitStatus: 'git:status',
gitInit: 'git:init',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 926b9d64c..9519d91b1 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -333,6 +333,20 @@ export interface SshProjectApi {
onStatus(cb: (e: { projectId: string; status: SshProjectStatus; error?: string }) => void): () => void
}
+/**
+ * SSH-project Explorer/Editor filesystem API: the same `FsApi` contract scoped to a project,
+ * proxied over the project's ControlMaster (renderer → `sshFs:*` IPC → main `SshFs`). The renderer
+ * `sshFs(projectId)` helper closes over `projectId` to expose a plain `FsApi`. Mirrors
+ * `RemoteClientApi.fs*` for relay connections; fails open ([]/''/false) when the project is not
+ * connected.
+ */
+export interface SshFsApi {
+ list(projectId: string, path: string): Promise<DirEntry[]>
+ read(projectId: string, path: string): Promise<string>
+ readBinary(projectId: string, path: string): Promise<string>
+ write(projectId: string, path: string, content: string): Promise<boolean>
+}
+
export interface GitFileChange {
path: string
/** Single-letter status: M (modified), A (added), D (deleted), R (renamed), U (untracked). */
@@ -749,6 +763,7 @@ export interface NodeTerminalApi {
settings: SettingsApi
ssh: SshApi
sshProject: SshProjectApi
+ sshFs: SshFsApi
git: GitApi
clipboard: ClipboardApi
shell: ShellApi