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): pure quick-open file-listing filter (rg/git args + blocklist)

enes34587a301b6d
diff --git a/src/shared/quick-open-filter.test.ts b/src/shared/quick-open-filter.test.ts
new file mode 100644
index 000000000..a2403745d
--- /dev/null
+++ b/src/shared/quick-open-filter.test.ts
@@ -0,0 +1,53 @@
+import { describe, it, expect } from 'vitest'
+import {
+ shouldIncludeQuickOpenPath,
+ buildHiddenDirExcludeGlobs,
+ buildRgArgsForQuickOpen,
+ buildGitLsFilesArgs,
+ normalizeQuickOpenRgLine
+} from './quick-open-filter'
+
+describe('shouldIncludeQuickOpenPath', () => {
+ it('keeps normal source and git-ignored build output', () => {
+ expect(shouldIncludeQuickOpenPath('src/main/index.ts')).toBe(true)
+ expect(shouldIncludeQuickOpenPath('dist/nodeterm-0.2.0-arm64.dmg')).toBe(true)
+ expect(shouldIncludeQuickOpenPath('.claude/worktrees/b5-test/dist/app.dmg')).toBe(true)
+ })
+ it('drops node_modules, .git and blocklisted dirs at any depth', () => {
+ expect(shouldIncludeQuickOpenPath('node_modules/react/index.js')).toBe(false)
+ expect(shouldIncludeQuickOpenPath('a/b/node_modules/x.js')).toBe(false)
+ expect(shouldIncludeQuickOpenPath('.git/config')).toBe(false)
+ expect(shouldIncludeQuickOpenPath('.cache/x')).toBe(false)
+ expect(shouldIncludeQuickOpenPath('packages/.vscode/settings.json')).toBe(false)
+ })
+})
+
+describe('normalizeQuickOpenRgLine', () => {
+ it('strips ./ prefix and trailing CR, returns null for junk', () => {
+ expect(normalizeQuickOpenRgLine('./src/a.ts')).toBe('src/a.ts')
+ expect(normalizeQuickOpenRgLine('src/a.ts\r')).toBe('src/a.ts')
+ expect(normalizeQuickOpenRgLine('')).toBeNull()
+ expect(normalizeQuickOpenRgLine('.')).toBeNull()
+ expect(normalizeQuickOpenRgLine('../escape')).toBeNull()
+ })
+ it('forces forward slashes', () => {
+ expect(normalizeQuickOpenRgLine('src\\main\\a.ts')).toBe('src/main/a.ts')
+ })
+})
+
+describe('arg builders', () => {
+ it('rg primary respects ignore, ignoredPass adds --no-ignore-vcs; both prune node_modules', () => {
+ const { primary, ignoredPass } = buildRgArgsForQuickOpen({ forceSlashSeparator: false })
+ expect(primary).toContain('--files')
+ expect(primary).toContain('--hidden')
+ expect(primary).not.toContain('--no-ignore-vcs')
+ expect(ignoredPass).toContain('--no-ignore-vcs')
+ expect(buildHiddenDirExcludeGlobs()).toContain('!**/node_modules')
+ expect(primary).toContain('!**/node_modules')
+ })
+ it('git ls-files primary lists tracked+untracked, ignoredPass adds --ignored', () => {
+ const { primary, ignoredPass } = buildGitLsFilesArgs()
+ expect(primary).toEqual(['-z', '--cached', '--others', '--exclude-standard'])
+ expect(ignoredPass).toEqual(['-z', '--others', '--ignored', '--exclude-standard'])
+ })
+})
diff --git a/src/shared/quick-open-filter.ts b/src/shared/quick-open-filter.ts
new file mode 100644
index 000000000..11d654144
--- /dev/null
+++ b/src/shared/quick-open-filter.ts
@@ -0,0 +1,103 @@
+/**
+ * Pure Quick Open (⌘K file search) listing policy — no IO, no Electron. Trimmed port of
+ * REF's quick-open-filter.ts: a noise blocklist + rg/git arg builders + line normalization.
+ * The caller (main process) owns process execution. v1 is single local root (no
+ * WSL/SSH/exclude-prefix logic).
+ */
+
+// Tool-generated caches / VCS / editor state that are never hand-edited. Deliberately omits
+// .claude (worktrees + build output live under it) and other user-authored dotdirs.
+export const HIDDEN_DIR_BLOCKLIST: ReadonlySet<string> = new Set([
+ '.git',
+ '.next',
+ '.nuxt',
+ '.cache',
+ '.vscode',
+ '.idea',
+ '.yarn',
+ '.pnpm-store',
+ '.terraform',
+ '.docker',
+ '.husky'
+])
+
+// Pruned from every traversal but not a dotdir, so tracked separately.
+const NON_DOTTED_PRUNE = 'node_modules'
+
+/**
+ * True if `relPath` (`/`-separated, root-relative) does not traverse a blocklisted segment.
+ * Correctness backstop after the rg/git pruning globs. Walks segment-by-segment without
+ * allocating (called once per listed file; large repos produce ~100k files).
+ */
+export function shouldIncludeQuickOpenPath(relPath: string): boolean {
+ let start = 0
+ const len = relPath.length
+ while (start < len) {
+ let end = relPath.indexOf('/', start)
+ if (end === -1) end = len
+ const segment = relPath.substring(start, end)
+ if (segment === NON_DOTTED_PRUNE || HIDDEN_DIR_BLOCKLIST.has(segment)) return false
+ start = end + 1
+ }
+ return true
+}
+
+// rg/git glob metacharacters — escape so a dir literally named `feature[1]` isn't a glob.
+const GLOB_META = new Set<string>(['*', '?', '[', ']', '{', '}', '\\'])
+function escapeGlob(segment: string): string {
+ let out = ''
+ for (const ch of segment) out += GLOB_META.has(ch) ? `\\${ch}` : ch
+ return out
+}
+
+/**
+ * `--glob !**\/<name>` (directory-match form) for each blocklist dir + node_modules, so rg
+ * prunes traversal of huge caches instead of merely dropping already-listed files.
+ */
+export function buildHiddenDirExcludeGlobs(): string[] {
+ const names = [NON_DOTTED_PRUNE, ...HIDDEN_DIR_BLOCKLIST]
+ const out: string[] = []
+ for (const name of names) out.push('--glob', `!**/${escapeGlob(name)}`)
+ return out
+}
+
+/**
+ * The two rg arg arrays. Run with `cwd: rootPath` and searchRoot `.` so output is
+ * cwd-relative. `primary` respects .gitignore; `ignoredPass` adds --no-ignore-vcs to surface
+ * git-ignored build output (dist/...). forceSlashSeparator true on Windows (no-op elsewhere).
+ */
+export function buildRgArgsForQuickOpen(opts: { forceSlashSeparator: boolean }): {
+ primary: string[]
+ ignoredPass: string[]
+} {
+ const sepArgs = opts.forceSlashSeparator ? ['--path-separator', '/'] : []
+ const globs = buildHiddenDirExcludeGlobs()
+ const primary = ['--files', '--hidden', ...sepArgs, ...globs, '.']
+ const ignoredPass = ['--files', '--hidden', '--no-ignore-vcs', ...sepArgs, ...globs, '.']
+ return { primary, ignoredPass }
+}
+
+/**
+ * Fallback when rg is unavailable. NUL-delimited (`-z`) so paths with tabs/newlines stay
+ * intact. primary = tracked + untracked-not-ignored; ignoredPass = ignored untracked files.
+ */
+export function buildGitLsFilesArgs(): { primary: string[]; ignoredPass: string[] } {
+ return {
+ primary: ['-z', '--cached', '--others', '--exclude-standard'],
+ ignoredPass: ['-z', '--others', '--ignored', '--exclude-standard']
+ }
+}
+
+/**
+ * One rg/cwd-relative stdout line → root-relative `/`-path, or null for junk / root-escapes.
+ */
+export function normalizeQuickOpenRgLine(rawLine: string): string | null {
+ let line = rawLine
+ if (line.length > 0 && line.charCodeAt(line.length - 1) === 13) line = line.slice(0, -1) // CR
+ if (!line) return null
+ let rel = line.replace(/\\/g, '/')
+ if (rel.startsWith('./')) rel = rel.slice(2)
+ else if (rel === '.') return null
+ if (!rel || rel.startsWith('/') || rel === '..' || rel.startsWith('../')) return null
+ return rel
+}