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(fs): mkdir + exists across desktop, server and SSH surfaces

enesd063242ab4ef
diff --git a/src/core/fs-ops.test.ts b/src/core/fs-ops.test.ts
new file mode 100644
index 000000000..b00d3465a
--- /dev/null
+++ b/src/core/fs-ops.test.ts
@@ -0,0 +1,30 @@
+import { mkdtempSync, rmSync, writeFileSync } from 'fs'
+import { tmpdir } from 'os'
+import { join } from 'path'
+import { afterAll, describe, expect, it } from 'vitest'
+import { makeDir, pathExists } from './fs-ops'
+
+const root = mkdtempSync(join(tmpdir(), 'fs-ops-'))
+afterAll(() => rmSync(root, { recursive: true, force: true }))
+
+describe('makeDir', () => {
+ it('creates nested directories recursively', async () => {
+ expect(await makeDir(join(root, 'a/b/c'))).toBe(true)
+ expect(await pathExists(join(root, 'a/b/c'))).toBe(true)
+ })
+ it('is idempotent on an existing dir', async () => {
+ expect(await makeDir(join(root, 'a'))).toBe(true)
+ })
+ it('fails open (false) when blocked by a file', async () => {
+ writeFileSync(join(root, 'file.txt'), 'x')
+ expect(await makeDir(join(root, 'file.txt/sub'))).toBe(false)
+ })
+})
+
+describe('pathExists', () => {
+ it('true for files and dirs, false for missing', async () => {
+ expect(await pathExists(join(root, 'file.txt'))).toBe(true)
+ expect(await pathExists(join(root, 'a'))).toBe(true)
+ expect(await pathExists(join(root, 'nope'))).toBe(false)
+ })
+})
diff --git a/src/core/fs-ops.ts b/src/core/fs-ops.ts
index 2529bb7cb..720f80688 100644
--- a/src/core/fs-ops.ts
+++ b/src/core/fs-ops.ts
@@ -99,6 +99,26 @@ export async function writeText(filePath: string, content: string): Promise<bool
}
}
+/** Create a directory (recursive, mkdir -p semantics). Resolves `true` on success. */
+export async function makeDir(dirPath: string): Promise<boolean> {
+ try {
+ await fs.mkdir(dirPath, { recursive: true })
+ return true
+ } catch {
+ return false
+ }
+}
+
+/** True when the path exists (file or directory). */
+export async function pathExists(p: string): Promise<boolean> {
+ try {
+ await fs.stat(p)
+ return true
+ } catch {
+ return false
+ }
+}
+
const QUICK_OPEN_FILE_CAP = 50_000
const QUICK_OPEN_TIMEOUT_MS = 10_000
diff --git a/src/main/index.ts b/src/main/index.ts
index 25fd1014c..8f04ab0c0 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -498,6 +498,8 @@ app.whenReady().then(async () => {
ipcMain.handle(IPC.fsWrite, (_e, filePath: string, content: string) =>
fsOps.writeText(filePath, content)
)
+ ipcMain.handle(IPC.fsMkdir, (_e, dirPath: string) => fsOps.makeDir(dirPath))
+ ipcMain.handle(IPC.fsExists, (_e, p: string) => fsOps.pathExists(p))
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
@@ -525,6 +527,14 @@ app.whenReady().then(async () => {
const ref = sshFsRefFor(projectId)
return ref ? sshFs.writeText(ref, p, content) : Promise.resolve(false)
})
+ ipcMain.handle(IPC.sshFsMkdir, (_e, projectId: string, p: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.mkdir(ref, p) : Promise.resolve(false)
+ })
+ ipcMain.handle(IPC.sshFsExists, (_e, projectId: string, p: string) => {
+ const ref = sshFsRefFor(projectId)
+ return ref ? sshFs.exists(ref, p) : Promise.resolve(false)
+ })
ipcMain.handle(IPC.dialogSelectFolder, async () => {
const result = await dialog.showOpenDialog({ properties: ['openDirectory', 'createDirectory'] })
diff --git a/src/main/ssh-fs.test.ts b/src/main/ssh-fs.test.ts
index c1962efe3..301ecea12 100644
--- a/src/main/ssh-fs.test.ts
+++ b/src/main/ssh-fs.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
-import { sshListArgs, sshReadArgs, sshReadBinaryArgs, sshWriteArgs, sshCheckIgnoreArgs, parseLsEntries, SshFs } from './ssh-fs'
+import { sshListArgs, sshReadArgs, sshReadBinaryArgs, sshWriteArgs, sshMkdirArgs, sshExistsArgs, sshCheckIgnoreArgs, parseLsEntries, SshFs } from './ssh-fs'
const conn = { host: 'h', user: 'u' }
const ref = { conn, controlPath: '/s.sock' }
@@ -29,6 +29,18 @@ describe('ssh-fs arg builders', () => {
expect(j).toContain(`mkdir -p ~/'projects'`)
expect(j).toContain(`cat > ~/'projects/file.txt'`)
})
+ it('mkdir runs mkdir -p on the quoted path', () => {
+ expect(sshMkdirArgs(conn, '/s.sock', '/a b/c').join(' ')).toContain(`mkdir -p '/a b/c'`)
+ })
+ it('mkdir leaves a leading ~/ unquoted so the remote shell tilde-expands the path', () => {
+ expect(sshMkdirArgs(conn, '/s', '~/projects/new').join(' ')).toContain(`mkdir -p ~/'projects/new'`)
+ })
+ it('exists runs test -e on the quoted path', () => {
+ expect(sshExistsArgs(conn, '/s.sock', '/a b/c').join(' ')).toContain(`test -e '/a b/c'`)
+ })
+ it('exists leaves a leading ~/ unquoted so the remote shell tilde-expands the path', () => {
+ expect(sshExistsArgs(conn, '/s', '~/projects/file.txt').join(' ')).toContain(`test -e ~/'projects/file.txt'`)
+ })
it('check-ignore quotes the dir as a remote path (~ expands) but quotes entry NAMES literally', () => {
const j = sshCheckIgnoreArgs(conn, '/s', '~/p', ['node_modules', "a'b"]).join(' ')
expect(j).toContain(`git -C ~/'p' check-ignore -- 'node_modules' 'a'\\''b'`)
@@ -70,4 +82,12 @@ describe('SshFs (injected runner)', () => {
it('fail-open: listDir → [] when the ls run fails', async () => {
expect(await new SshFs(async () => ({ code: 1, stdout: '' })).listDir(ref, '/p')).toEqual([])
})
+ it('mkdir true on code 0, false otherwise', async () => {
+ expect(await new SshFs(async () => ({ code: 0, stdout: '' })).mkdir(ref, '/d')).toBe(true)
+ expect(await new SshFs(async () => ({ code: 1, stdout: '' })).mkdir(ref, '/d')).toBe(false)
+ })
+ it('exists true on code 0 (test -e), false otherwise', async () => {
+ expect(await new SshFs(async () => ({ code: 0, stdout: '' })).exists(ref, '/d')).toBe(true)
+ expect(await new SshFs(async () => ({ code: 1, stdout: '' })).exists(ref, '/d')).toBe(false)
+ })
})
diff --git a/src/main/ssh-fs.ts b/src/main/ssh-fs.ts
index 6c706893f..46548e82a 100644
--- a/src/main/ssh-fs.ts
+++ b/src/main/ssh-fs.ts
@@ -30,6 +30,12 @@ export function sshReadBinaryArgs(conn: SshConnection, cp: string, path: string)
export function sshWriteArgs(conn: SshConnection, cp: string, path: string): string[] {
return childArgs(conn, cp, `mkdir -p ${quoteRemotePath(dirname(path))} && cat > ${quoteRemotePath(path)}`)
}
+export function sshMkdirArgs(conn: SshConnection, cp: string, path: string): string[] {
+ return childArgs(conn, cp, `mkdir -p ${quoteRemotePath(path)}`)
+}
+export function sshExistsArgs(conn: SshConnection, cp: string, path: string): string[] {
+ return childArgs(conn, cp, `test -e ${quoteRemotePath(path)}`)
+}
export function sshCheckIgnoreArgs(conn: SshConnection, cp: string, dir: string, names: string[]): string[] {
// The dir is a remote path (may be tilde-prefixed) → quoteRemotePath; the entry NAMES are bare
// filenames with no tilde → posixQuote literally (and inject-safe).
@@ -97,4 +103,22 @@ export class SshFs {
return false
}
}
+
+ async mkdir(ref: SshFsRef, path: string): Promise<boolean> {
+ try {
+ const { code } = await this.run(sshMkdirArgs(ref.conn, ref.controlPath, path))
+ return code === 0
+ } catch {
+ return false
+ }
+ }
+
+ async exists(ref: SshFsRef, path: string): Promise<boolean> {
+ try {
+ const { code } = await this.run(sshExistsArgs(ref.conn, ref.controlPath, path))
+ return code === 0
+ } catch {
+ return false
+ }
+ }
}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 8944d47c6..cc1cc5b35 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -148,7 +148,9 @@ const api: NodeTerminalApi = {
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)
+ ipcRenderer.invoke(IPC.sshFsWrite, projectId, path, content),
+ mkdir: (projectId: string, p: string) => ipcRenderer.invoke(IPC.sshFsMkdir, projectId, p),
+ exists: (projectId: string, p: string) => ipcRenderer.invoke(IPC.sshFsExists, projectId, p)
},
git: {
status: (cwd) => ipcRenderer.invoke(IPC.gitStatus, cwd),
@@ -213,7 +215,9 @@ const api: NodeTerminalApi = {
list: (dirPath: string) => ipcRenderer.invoke(IPC.fsList, dirPath),
read: (filePath: string) => ipcRenderer.invoke(IPC.fsRead, filePath),
readBinary: (filePath: string) => ipcRenderer.invoke(IPC.fsReadBinary, filePath),
- write: (filePath: string, content: string) => ipcRenderer.invoke(IPC.fsWrite, filePath, content)
+ write: (filePath: string, content: string) => ipcRenderer.invoke(IPC.fsWrite, filePath, content),
+ mkdir: (dirPath: string) => ipcRenderer.invoke(IPC.fsMkdir, dirPath),
+ exists: (p: string) => ipcRenderer.invoke(IPC.fsExists, p)
},
media: {
allow: (absPath: string) => ipcRenderer.invoke(IPC.mediaAllow, absPath),
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index 6f7c55b79..c197c1dfe 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -135,7 +135,9 @@ export function buildStubApi(): Omit<
list: U('sshFs.list'),
read: U('sshFs.read'),
readBinary: U('sshFs.readBinary'),
- write: U('sshFs.write')
+ write: U('sshFs.write'),
+ mkdir: U('sshFs.mkdir'),
+ exists: U('sshFs.exists')
},
clipboard: {
// Clipboard API → execCommand → visible error. `navigator.clipboard` only exists in a SECURE
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index d1a6c231a..7f1293292 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -231,7 +231,9 @@ export function buildFilesApi(
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>
+ write: (filePath, content) => client.request(IPC.fsWrite, filePath, content) as Promise<boolean>,
+ mkdir: (dirPath) => client.request(IPC.fsMkdir, dirPath) as Promise<boolean>,
+ exists: (p) => client.request(IPC.fsExists, p) as Promise<boolean>
}
const git: GitApi = {
diff --git a/src/renderer/terminal/remote-fs.ts b/src/renderer/terminal/remote-fs.ts
index 7e6175033..6fab9174e 100644
--- a/src/renderer/terminal/remote-fs.ts
+++ b/src/renderer/terminal/remote-fs.ts
@@ -16,6 +16,12 @@ export function remoteFs(connectionId: string): FsApi {
list: (dirPath) => client.fsList(connectionId, dirPath),
read: (filePath) => client.fsRead(connectionId, filePath),
readBinary: (filePath) => client.fsReadBinary(connectionId, filePath),
- write: (filePath, content) => client.fsWrite(connectionId, filePath, content)
+ write: (filePath, content) => client.fsWrite(connectionId, filePath, content),
+ // mkdir/exists are not yet plumbed through the E2EE relay RPC (RemoteClientApi has no
+ // fsMkdir/fsExists). Until the host-service surface gains them, degrade gracefully: a relay
+ // Explorer reports "does not exist" and cannot create dirs, rather than throwing. See the
+ // fs.mkdir/exists task follow-up.
+ mkdir: () => Promise.resolve(false),
+ exists: () => Promise.resolve(false)
}
}
diff --git a/src/renderer/terminal/ssh-fs.ts b/src/renderer/terminal/ssh-fs.ts
index 7bb0025a7..af278b9bf 100644
--- a/src/renderer/terminal/ssh-fs.ts
+++ b/src/renderer/terminal/ssh-fs.ts
@@ -9,6 +9,8 @@ export function sshFs(projectId: string): FsApi {
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)
+ write: (path, content) => api.write(projectId, path, content),
+ mkdir: (path) => api.mkdir(projectId, path),
+ exists: (path) => api.exists(projectId, path)
}
}
diff --git a/src/server/handlers/fs.test.ts b/src/server/handlers/fs.test.ts
index 92d9cd11d..4309db656 100644
--- a/src/server/handlers/fs.test.ts
+++ b/src/server/handlers/fs.test.ts
@@ -38,6 +38,12 @@ describe('server fs handlers', () => {
fs.writeFileSync(f, Buffer.from([1, 2, 3]))
expect(await call(IPC.fsReadBinary, f)).toBe(Buffer.from([1, 2, 3]).toString('base64'))
})
+ it('mkdir creates a nested dir and exists reports it', async () => {
+ const nested = path.join(dir, 'x/y/z')
+ expect(await call(IPC.fsExists, nested)).toBe(false)
+ expect(await call(IPC.fsMkdir, nested)).toBe(true)
+ expect(await call(IPC.fsExists, nested)).toBe(true)
+ })
it('quickOpen lists files under the root', async () => {
fs.writeFileSync(path.join(dir, 'q.txt'), 'x')
const files = (await call(IPC.filesQuickOpen, dir)) as string[]
diff --git a/src/server/handlers/fs.ts b/src/server/handlers/fs.ts
index fe64d1003..f26000322 100644
--- a/src/server/handlers/fs.ts
+++ b/src/server/handlers/fs.ts
@@ -11,5 +11,7 @@ export function registerFsHandlers(platform: ServerPlatform): void {
platform.handle(IPC.fsRead, (filePath: string) => fsOps.readText(filePath))
platform.handle(IPC.fsReadBinary, (filePath: string) => fsOps.readBinary(filePath))
platform.handle(IPC.fsWrite, (filePath: string, content: string) => fsOps.writeText(filePath, content))
+ platform.handle(IPC.fsMkdir, (dirPath: string) => fsOps.makeDir(dirPath))
+ platform.handle(IPC.fsExists, (p: string) => fsOps.pathExists(p))
platform.handle(IPC.filesQuickOpen, (cwd: string) => fsOps.listQuickOpenFiles(cwd))
}
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 455d7a581..8c432ba88 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -125,6 +125,8 @@ export const IPC = {
fsRead: 'fs:read',
fsReadBinary: 'fs:read-binary',
fsWrite: 'fs:write',
+ fsMkdir: 'fs:mkdir',
+ fsExists: 'fs:exists',
filesQuickOpen: 'files:quick-open',
settingsLoad: 'settings:load',
settingsSave: 'settings:save',
@@ -142,6 +144,8 @@ export const IPC = {
sshFsRead: 'sshFs:read',
sshFsReadBinary: 'sshFs:read-binary',
sshFsWrite: 'sshFs:write',
+ sshFsMkdir: 'sshFs:mkdir',
+ sshFsExists: 'sshFs:exists',
sshProjectStatus: 'ssh-project:status',
gitStatus: 'git:status',
gitInit: 'git:init',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index f33d77fdc..1f618e871 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -358,6 +358,10 @@ export interface FsApi {
readBinary(filePath: string): Promise<string>
/** Write text to a file; resolves true on success. */
write(filePath: string, content: string): Promise<boolean>
+ /** Create a directory (recursive). Resolves true on success. */
+ mkdir(dirPath: string): Promise<boolean>
+ /** True when the path exists (file or directory). */
+ exists(path: string): Promise<boolean>
}
export interface FilesApi {
@@ -575,6 +579,8 @@ export interface SshFsApi {
read(projectId: string, path: string): Promise<string>
readBinary(projectId: string, path: string): Promise<string>
write(projectId: string, path: string, content: string): Promise<boolean>
+ mkdir(projectId: string, path: string): Promise<boolean>
+ exists(projectId: string, path: string): Promise<boolean>
}
export interface GitFileChange {