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(server): fs.* + files.quickOpen handlers over core fs-ops

enesf3dae40dfb5b
diff --git a/src/server/handlers/fs.test.ts b/src/server/handlers/fs.test.ts
new file mode 100644
index 000000000..36f2bf33f
--- /dev/null
+++ b/src/server/handlers/fs.test.ts
@@ -0,0 +1,46 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest'
+import fs from 'fs'
+import os from 'os'
+import path from 'path'
+import { ServerPlatform } from '../platform-server'
+import { registerFsHandlers } from './fs'
+import { IPC } from '../../shared/ipc'
+
+let dir: string, platform: ServerPlatform, ui: number
+beforeEach(() => {
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-fs-'))
+ platform = new ServerPlatform({ userDataDir: dir, appVersion: '0' })
+ registerFsHandlers(platform)
+ ui = platform.attach({ sendText: () => {}, sendBinary: () => {} })
+})
+afterEach(() => fs.rmSync(dir, { recursive: true, force: true }))
+
+async function call(method: string, ...args: unknown[]) {
+ const res = await platform.dispatch(ui, { t: 'req', id: 1, method, args })
+ if (!res.ok) throw new Error(res.error.code)
+ return res.result
+}
+
+describe('server fs handlers', () => {
+ it('write then read round-trips through fsOps', async () => {
+ const f = path.join(dir, 'hi.txt')
+ expect(await call(IPC.fsWrite, f, 'merhaba')).toBe(true)
+ expect(await call(IPC.fsRead, f)).toBe('merhaba')
+ })
+ it('list returns directory entries', async () => {
+ fs.writeFileSync(path.join(dir, 'a.txt'), 'x')
+ fs.mkdirSync(path.join(dir, 'sub'))
+ const entries = (await call(IPC.fsList, dir)) as Array<{ name: string; isDirectory: boolean }>
+ expect(entries.map((e) => e.name).sort()).toEqual(['a.txt', 'sub'])
+ })
+ it('readBinary returns base64', async () => {
+ const f = path.join(dir, 'b.bin')
+ fs.writeFileSync(f, Buffer.from([1, 2, 3]))
+ expect(await call(IPC.fsReadBinary, f)).toBe(Buffer.from([1, 2, 3]).toString('base64'))
+ })
+ 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[]
+ expect(files.some((p) => p.endsWith('q.txt'))).toBe(true)
+ })
+})
diff --git a/src/server/handlers/fs.ts b/src/server/handlers/fs.ts
new file mode 100644
index 000000000..fe64d1003
--- /dev/null
+++ b/src/server/handlers/fs.ts
@@ -0,0 +1,15 @@
+import type { ServerPlatform } from '../platform-server'
+import * as fsOps from '../../core/fs-ops'
+import { IPC } from '../../shared/ipc'
+
+/** Register the fs.* + files.quickOpen RPC surface. The desktop registers these inline in
+ * src/main/index.ts; the logic is already pure in src/core/fs-ops.ts, so the server just
+ * wraps it. Threat model: an authenticated user already has a shell, so server-local file
+ * read/write adds no new exposure. */
+export function registerFsHandlers(platform: ServerPlatform): void {
+ platform.handle(IPC.fsList, (dirPath: string) => fsOps.listDir(dirPath))
+ 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.filesQuickOpen, (cwd: string) => fsOps.listQuickOpenFiles(cwd))
+}