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(palette): main-process quick-open file lister + files.quickOpen IPC

enes3f339741547f
diff --git a/src/main/fs-ops.ts b/src/main/fs-ops.ts
index b1f402e98..748cd528c 100644
--- a/src/main/fs-ops.ts
+++ b/src/main/fs-ops.ts
@@ -9,9 +9,17 @@
// empty/false rather than throwing, so a missing file or unreadable dir degrades gracefully.
import { promises as fs } from 'fs'
-import { execFile } from 'child_process'
+import { sep } from 'path'
+import { execFile, spawn } from 'child_process'
import { promisify } from 'util'
import type { DirEntry } from '../shared/types'
+import {
+ buildRgArgsForQuickOpen,
+ buildGitLsFilesArgs,
+ normalizeQuickOpenRgLine,
+ shouldIncludeQuickOpenPath,
+ HIDDEN_DIR_BLOCKLIST
+} from '../shared/quick-open-filter'
const run = promisify(execFile)
@@ -84,3 +92,112 @@ export async function writeText(filePath: string, content: string): Promise<bool
return false
}
}
+
+const QUICK_OPEN_FILE_CAP = 50_000
+const QUICK_OPEN_TIMEOUT_MS = 10_000
+
+// Spawn a lister command, stream stdout split on `splitChar`, normalize+filter each path into
+// `out`. Resolves with `true` on a clean run, `false` on spawn error / nonzero-ish exit, so the
+// caller can fall through to the next strategy. Never rejects.
+function runLister(
+ cmd: string,
+ args: string[],
+ cwd: string,
+ splitChar: string,
+ out: Set<string>
+): Promise<boolean> {
+ return new Promise((resolve) => {
+ let buf = ''
+ let settled = false
+ const child = spawn(cmd, args, { cwd, stdio: ['ignore', 'pipe', 'ignore'] })
+ const timer = setTimeout(() => child.kill(), QUICK_OPEN_TIMEOUT_MS)
+ const take = (line: string): void => {
+ if (out.size >= QUICK_OPEN_FILE_CAP) return
+ const rel = normalizeQuickOpenRgLine(line)
+ if (rel && shouldIncludeQuickOpenPath(rel)) out.add(rel)
+ }
+ const finish = (ok: boolean): void => {
+ if (settled) return
+ settled = true
+ clearTimeout(timer)
+ resolve(ok)
+ }
+ child.stdout.setEncoding('utf8')
+ child.stdout.on('data', (chunk: string) => {
+ buf += chunk
+ let idx = buf.indexOf(splitChar)
+ while (idx !== -1) {
+ take(buf.slice(0, idx))
+ buf = buf.slice(idx + 1)
+ idx = buf.indexOf(splitChar)
+ }
+ })
+ child.on('error', () => finish(false))
+ child.on('close', (code) => {
+ if (buf) take(buf)
+ // rg: 0=matches, 1=no matches, 2=partial (unreadable subdir) — all usable. git: 0.
+ finish(code === 0 || code === 1 || (code === 2 && out.size > 0))
+ })
+ })
+}
+
+// Last-resort BFS walk for non-git roots with no rg. Prunes the blocklist + node_modules,
+// caps total. Returns root-relative `/`-paths.
+async function walkDirCapped(rootPath: string): Promise<string[]> {
+ const out: string[] = []
+ const queue: string[] = ['']
+ while (queue.length && out.length < QUICK_OPEN_FILE_CAP) {
+ const rel = queue.shift() as string
+ let dirents: import('fs').Dirent[]
+ try {
+ dirents = await fs.readdir(rel ? `${rootPath}/${rel}` : rootPath, { withFileTypes: true })
+ } catch {
+ continue
+ }
+ for (const d of dirents) {
+ if (d.name === 'node_modules' || HIDDEN_DIR_BLOCKLIST.has(d.name)) continue
+ const childRel = rel ? `${rel}/${d.name}` : d.name
+ if (d.isDirectory()) queue.push(childRel)
+ else if (d.isFile() && out.length < QUICK_OPEN_FILE_CAP) out.push(childRel)
+ }
+ }
+ return out
+}
+
+let rgChecked: boolean | null = null
+async function rgAvailable(): Promise<boolean> {
+ if (rgChecked !== null) return rgChecked
+ rgChecked = await new Promise<boolean>((resolve) => {
+ const child = spawn('rg', ['--version'], { stdio: 'ignore' })
+ child.on('error', () => resolve(false))
+ child.on('close', (code) => resolve(code === 0))
+ })
+ return rgChecked
+}
+
+/**
+ * Fuzzy-open file index for `rootPath`: root-relative `/`-paths. Two passes (tracked + ignored
+ * so git-ignored build output like dist/*.dmg appears) minus a noise blocklist. rg →
+ * git ls-files → capped readdir walk. Always resolves ([] if everything fails).
+ */
+export async function listQuickOpenFiles(rootPath: string): Promise<string[]> {
+ try {
+ const st = await fs.stat(rootPath)
+ if (!st.isDirectory()) return []
+ } catch {
+ return []
+ }
+ const out = new Set<string>()
+ if (await rgAvailable()) {
+ const { primary, ignoredPass } = buildRgArgsForQuickOpen({ forceSlashSeparator: sep === '\\' })
+ await runLister('rg', primary, rootPath, '\n', out)
+ await runLister('rg', ignoredPass, rootPath, '\n', out)
+ }
+ if (out.size === 0) {
+ const { primary, ignoredPass } = buildGitLsFilesArgs()
+ const okPrimary = await runLister('git', primary, rootPath, '\0', out)
+ if (okPrimary) await runLister('git', ignoredPass, rootPath, '\0', out)
+ if (!okPrimary) for (const p of await walkDirCapped(rootPath)) out.add(p)
+ }
+ return [...out].sort().slice(0, QUICK_OPEN_FILE_CAP)
+}
diff --git a/src/main/index.ts b/src/main/index.ts
index 7648dd193..71dc568e6 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -185,6 +185,7 @@ app.whenReady().then(async () => {
ipcMain.handle(IPC.fsWrite, (_e, filePath: string, content: string) =>
fsOps.writeText(filePath, content)
)
+ ipcMain.handle(IPC.filesQuickOpen, (_e, cwd: string) => fsOps.listQuickOpenFiles(cwd))
ipcMain.handle(IPC.dialogSelectFolder, async () => {
const result = await dialog.showOpenDialog({ properties: ['openDirectory', 'createDirectory'] })
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 763cb21a9..3f76607ab 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -121,6 +121,9 @@ const api: NodeTerminalApi = {
readBinary: (filePath: string) => ipcRenderer.invoke(IPC.fsReadBinary, filePath),
write: (filePath: string, content: string) => ipcRenderer.invoke(IPC.fsWrite, filePath, content)
},
+ files: {
+ quickOpen: (cwd: string) => ipcRenderer.invoke(IPC.filesQuickOpen, cwd)
+ },
updates: {
onAvailable: (listener) => {
const handler = (_e: unknown, info: UpdateInfo) => listener(info)
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 56815f290..2e48f34ba 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -54,6 +54,7 @@ export const IPC = {
fsRead: 'fs:read',
fsReadBinary: 'fs:read-binary',
fsWrite: 'fs:write',
+ filesQuickOpen: 'files:quick-open',
settingsLoad: 'settings:load',
settingsSave: 'settings:save',
gitStatus: 'git:status',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 476284772..0df0098be 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -190,6 +190,11 @@ export interface FsApi {
write(filePath: string, content: string): Promise<boolean>
}
+export interface FilesApi {
+ /** Fuzzy-open file index for a project root: root-relative `/`-paths ([] on failure). */
+ quickOpen(cwd: string): Promise<string[]>
+}
+
/** A user-defined agent (BYO CLI). In no capability list, so it gets only spawn +
* terminal-title + process status (no hooks/branch/loop/bridge). */
export interface CustomAgent {
@@ -664,6 +669,7 @@ export interface NodeTerminalApi {
clipboard: ClipboardApi
shell: ShellApi
fs: FsApi
+ files: FilesApi
updates: UpdateApi
announcements: AnnouncementsApi
license: LicenseApi