mux-sesh 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,6 +52,8 @@ tmux source-file ~/.tmux.conf
52
52
  - Sessions view shows live tmux sessions.
53
53
  - Projects view shows scanned or configured directories.
54
54
  - Selecting a project attaches to an existing session when possible, or creates one.
55
+ - The new-session flow searches files and directories under `project_paths` as you type, powered by [fff](https://github.com/dmtrKovalenko/fff).
56
+ - Selecting a file creates a session in the file's directory and opens it in your editor.
55
57
  - The new-session flow can also clone a GitHub repository into your configured repos directory.
56
58
 
57
59
  ## Minimal Configuration
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "mux-sesh",
4
- "version": "1.8.0",
4
+ "version": "1.9.0",
5
5
  "description": "A beautiful tmux session manager built with OpenTUI - fuzzy search sessions, manage projects, clone from GitHub",
6
6
  "type": "module",
7
7
  "packageManager": "bun@1.3.5",
@@ -48,13 +48,17 @@
48
48
  "engines": {
49
49
  "bun": ">=1.0.0"
50
50
  },
51
+ "overrides": {
52
+ "@types/node": "^24"
53
+ },
51
54
  "dependencies": {
55
+ "@ff-labs/fff-bun": "0.9.4",
52
56
  "@opentui/core": "0.1.60",
53
57
  "@opentui/react": "0.1.60",
54
58
  "react": "^19.2.2"
55
59
  },
56
60
  "devDependencies": {
57
- "@types/bun": "1.3.5",
61
+ "@types/bun": "1.3.14",
58
62
  "@types/react": "^19.2.7",
59
63
  "prettier": "3.6.2",
60
64
  "typescript": "^5.9.3"
@@ -2,12 +2,15 @@ import { useEffect, useRef, type Dispatch, type MutableRefObject, type SetStateA
2
2
  import { checkAndUpdate, updateEvents } from '../update'
3
3
  import { showTemporaryToast } from './notifications'
4
4
  import { clearMatchIndices, filterAndSortItems } from '../search'
5
+ import { combineFileSearchResults, searchFilesAndDirectories, warmFileSearch } from '../search/fff'
6
+ import { annotateProjectItemsWithSessionLinks } from '../projects/session-links'
5
7
  import {
6
8
  getProjectSelectionIndex,
7
9
  getSessionSelectionIndex,
8
10
  loadSessionCandidateItems,
9
11
  } from './data'
10
12
  import { AppMode, ViewMode, type Config, type Item } from '../types'
13
+ import { isGitHubURL } from '../util/github'
11
14
  import { measure } from '../util/perf'
12
15
 
13
16
  export function useAutoUpdateScheduler(
@@ -269,6 +272,60 @@ export function useSearchFiltering(
269
272
  }, [allItems, appMode, searchQuery, setCursor, setItems])
270
273
  }
271
274
 
275
+ export function useNewSessionFileSearch(
276
+ appMode: AppMode,
277
+ config: Config | null,
278
+ searchQuery: string,
279
+ sessionItems: Item[],
280
+ setItems: Dispatch<SetStateAction<Item[]>>,
281
+ setCursor: Dispatch<SetStateAction<number>>
282
+ ) {
283
+ const sessionItemsRef = useRef(sessionItems)
284
+ sessionItemsRef.current = sessionItems
285
+
286
+ useEffect(() => {
287
+ if (appMode !== AppMode.NewSession || !config) {
288
+ return
289
+ }
290
+
291
+ const nextConfig = config
292
+ const query = searchQuery.trim()
293
+
294
+ if (!query || isGitHubURL(query)) {
295
+ void warmFileSearch(nextConfig)
296
+ return
297
+ }
298
+
299
+ let cancelled = false
300
+
301
+ async function runFileSearch() {
302
+ const fileSearchItems = await searchFilesAndDirectories(query, nextConfig)
303
+ if (cancelled || fileSearchItems.length === 0) {
304
+ return
305
+ }
306
+
307
+ const liveSessions = sessionItemsRef.current.filter(item => item.isSession)
308
+ const annotated = await annotateProjectItemsWithSessionLinks(
309
+ fileSearchItems,
310
+ liveSessions,
311
+ nextConfig
312
+ )
313
+ if (cancelled) {
314
+ return
315
+ }
316
+
317
+ setItems(current => combineFileSearchResults(annotated, current, query))
318
+ setCursor(0)
319
+ }
320
+
321
+ void runFileSearch()
322
+
323
+ return () => {
324
+ cancelled = true
325
+ }
326
+ }, [appMode, config, searchQuery, setCursor, setItems])
327
+ }
328
+
272
329
  export function useOpencodeStatsPolling(
273
330
  selectedOpencodeSessionName: string | undefined,
274
331
  loadOpencodeStatsForSession: (sessionName: string) => Promise<unknown>
@@ -388,5 +445,13 @@ export function useAppBehaviors(options: UseAppBehaviorsOptions) {
388
445
  options.setItems,
389
446
  options.setCursor
390
447
  )
448
+ useNewSessionFileSearch(
449
+ options.appMode,
450
+ options.config,
451
+ options.searchQuery,
452
+ options.sessionItems,
453
+ options.setItems,
454
+ options.setCursor
455
+ )
391
456
  useOpencodeStatsPolling(options.selectedOpencodeSessionName, options.loadOpencodeStatsForSession)
392
457
  }
@@ -0,0 +1,99 @@
1
+ import { basename, dirname, isAbsolute, join } from 'path'
2
+ import { stat } from 'fs/promises'
3
+ import type { Config, Item } from '../types'
4
+
5
+ export interface ResolvedFileSession {
6
+ sessionName: string
7
+ cwd: string
8
+ startupCommand: string
9
+ }
10
+
11
+ export type TypedPathTarget = { kind: 'file' | 'directory'; path: string }
12
+
13
+ function quoteShellArg(value: string): string {
14
+ return `'${value.replaceAll("'", "'\\''")}'`
15
+ }
16
+
17
+ function sanitizeSessionName(value: string): string {
18
+ return value.replace(/[.\s/]+/g, '_')
19
+ }
20
+
21
+ export function isFileItem(item: Pick<Item, 'itemKind'>): boolean {
22
+ return item.itemKind === 'file'
23
+ }
24
+
25
+ export function expandUserPath(value: string, homeDir = process.env.HOME || ''): string {
26
+ if (value === '~') {
27
+ return homeDir || value
28
+ }
29
+
30
+ if (value.startsWith('~/') && homeDir) {
31
+ return join(homeDir, value.slice(2))
32
+ }
33
+
34
+ return value
35
+ }
36
+
37
+ export function buildFileSessionName(filePath: string): string {
38
+ const fileBase = basename(filePath)
39
+ const parentBase = basename(dirname(filePath))
40
+ const combined =
41
+ parentBase && parentBase !== '.' && parentBase !== '/' ? `${parentBase}_${fileBase}` : fileBase
42
+
43
+ return sanitizeSessionName(combined)
44
+ }
45
+
46
+ export function interpolateStartupCommand(command: string, filePath: string): string {
47
+ return command
48
+ .replaceAll('{file}', quoteShellArg(filePath))
49
+ .replaceAll('{dir}', quoteShellArg(dirname(filePath)))
50
+ .replaceAll('{}', quoteShellArg(filePath))
51
+ }
52
+
53
+ export function buildFileStartupCommand(filePath: string, config: Config): string {
54
+ const configured = config.defaultSession?.startupCommand
55
+ if (configured && /\{file\}|\{dir\}|\{\}/.test(configured)) {
56
+ return interpolateStartupCommand(configured, filePath)
57
+ }
58
+
59
+ return `${config.editor} ${quoteShellArg(filePath)}`
60
+ }
61
+
62
+ export function resolveFileSession(filePath: string, config: Config): ResolvedFileSession {
63
+ return {
64
+ sessionName: buildFileSessionName(filePath),
65
+ cwd: dirname(filePath),
66
+ startupCommand: buildFileStartupCommand(filePath, config),
67
+ }
68
+ }
69
+
70
+ export function looksLikePathInput(value: string): boolean {
71
+ return value.startsWith('/') || value === '~' || value.startsWith('~/') || value.startsWith('./')
72
+ }
73
+
74
+ export async function resolveTypedPathTarget(
75
+ searchTerm: string,
76
+ homeDir = process.env.HOME || ''
77
+ ): Promise<TypedPathTarget | null> {
78
+ if (!looksLikePathInput(searchTerm)) {
79
+ return null
80
+ }
81
+
82
+ const expanded = expandUserPath(searchTerm, homeDir)
83
+ const absolute = isAbsolute(expanded) ? expanded : join(process.cwd(), expanded)
84
+
85
+ try {
86
+ const info = await stat(absolute)
87
+ if (info.isFile()) {
88
+ return { kind: 'file', path: absolute }
89
+ }
90
+
91
+ if (info.isDirectory()) {
92
+ return { kind: 'directory', path: absolute }
93
+ }
94
+
95
+ return null
96
+ } catch {
97
+ return null
98
+ }
99
+ }
@@ -1,5 +1,7 @@
1
+ import { dirname } from 'path'
1
2
  import type { Config, Item } from '../types'
2
3
  import { getGitRoot, resolveProjectSession } from '../config/session-rules'
4
+ import { isFileItem, resolveFileSession } from '../files/target'
3
5
  import { createTmuxSession, getTmuxSessionDirectory } from '../tmux'
4
6
  import { requestShutdown } from '../util/shutdown'
5
7
 
@@ -44,7 +46,16 @@ export async function openProjectSession(projectPath: string, config: Config): P
44
46
  await requestShutdown(0)
45
47
  }
46
48
 
49
+ export async function openFileSession(filePath: string, config: Config): Promise<void> {
50
+ const resolvedSession = resolveFileSession(filePath, config)
51
+ await createTmuxSession(resolvedSession.sessionName, resolvedSession.cwd, {
52
+ startupCommand: resolvedSession.startupCommand,
53
+ })
54
+ await requestShutdown(0)
55
+ }
56
+
47
57
  export async function getRootSessionPath(item: Item): Promise<string> {
48
58
  const itemPath = item.isSession ? await getTmuxSessionDirectory(item.title) : item.path
49
- return (await getGitRoot(itemPath)) ?? itemPath
59
+ const searchRoot = !item.isSession && isFileItem(item) ? dirname(itemPath) : itemPath
60
+ return (await getGitRoot(searchRoot)) ?? searchRoot
50
61
  }
@@ -8,12 +8,14 @@ import {
8
8
  getCurrentTmuxSessionName,
9
9
  } from '../tmux'
10
10
  import { getLastSessionTarget } from '../tmux/workflows'
11
+ import { isFileItem, resolveTypedPathTarget } from '../files/target'
11
12
  import { isGitHubURL, cloneGitHubRepo } from '../util/github'
12
13
  import { requestShutdown } from '../util/shutdown'
13
14
  import {
14
15
  buildEditorCommand,
15
16
  getNextSessionName,
16
17
  getRootSessionPath,
18
+ openFileSession,
17
19
  openProjectSession,
18
20
  requireConfig,
19
21
  requireConfiguredItem,
@@ -26,6 +28,11 @@ export async function handleSelect(item: Item, config: Config | null) {
26
28
  return
27
29
  }
28
30
 
31
+ if (isFileItem(item)) {
32
+ await openFileSession(item.path, requireConfig(config))
33
+ return
34
+ }
35
+
29
36
  await openProjectSession(item.path, requireConfig(config))
30
37
  }
31
38
 
@@ -85,13 +92,33 @@ export async function handleNewSessionSubmit(
85
92
  } catch (error) {
86
93
  throw new Error(`Error cloning repository: ${error}`)
87
94
  }
88
- } else if (items.length > 0 && cursor < items.length) {
95
+ return
96
+ }
97
+
98
+ const typedTarget = await resolveTypedPathTarget(searchTerm)
99
+ if (typedTarget) {
100
+ if (typedTarget.kind === 'file') {
101
+ await openFileSession(typedTarget.path, requireConfig(config))
102
+ return
103
+ }
104
+
105
+ await openProjectSession(typedTarget.path, requireConfig(config))
106
+ return
107
+ }
108
+
109
+ if (items.length > 0 && cursor < items.length) {
89
110
  const selectedItem = items[cursor]
111
+ if (isFileItem(selectedItem)) {
112
+ await openFileSession(selectedItem.path, requireConfig(config))
113
+ return
114
+ }
115
+
90
116
  await openProjectSession(selectedItem.path, requireConfig(config))
91
- } else {
92
- await createNamedTmuxSession(searchTerm)
93
- await requestShutdown(0)
117
+ return
94
118
  }
119
+
120
+ await createNamedTmuxSession(searchTerm)
121
+ await requestShutdown(0)
95
122
  }
96
123
 
97
124
  export async function handleLastSession(items: Item[]) {
@@ -1,10 +1,11 @@
1
- import { readdir } from 'fs/promises'
2
- import { basename, join } from 'path'
1
+ import { readdir, stat } from 'fs/promises'
2
+ import { basename, dirname, join } from 'path'
3
3
  import { spawn } from 'bun'
4
4
  import { getSessionDetails } from '../tmux'
5
5
  import type { Config, SessionDetails } from '../types'
6
6
  import { stripAnsi } from '../util/ansi'
7
7
  import { getGitRoot, resolveProjectSession } from '../config/session-rules'
8
+ import { resolveFileSession } from '../files/target'
8
9
 
9
10
  const MAX_PREVIEW_LINES = 24
10
11
  const MAX_PREVIEW_LINE_LENGTH = 120
@@ -15,13 +16,13 @@ const projectPreviewCache = new Map<string, { preview: ProjectPreview; expiresAt
15
16
  export interface ProjectPreview {
16
17
  path: string
17
18
  sessionName: string
18
- source: 'project' | 'wildcard' | 'default'
19
+ source: 'project' | 'wildcard' | 'default' | 'file'
19
20
  startupCommand?: string
20
21
  previewCommand?: string
21
22
  gitRoot?: string
22
23
  gitBranch?: string
23
24
  linkedSession?: SessionDetails
24
- previewKind: 'command' | 'directory'
25
+ previewKind: 'command' | 'directory' | 'file'
25
26
  previewLabel: string
26
27
  previewLines: string[]
27
28
  previewNotice?: string
@@ -281,3 +282,81 @@ export async function getProjectPreview(
281
282
 
282
283
  return preview
283
284
  }
285
+
286
+ const FILE_PREVIEW_MAX_BYTES = 16 * 1024
287
+
288
+ async function getFilePreviewLines(
289
+ filePath: string
290
+ ): Promise<{ lines: string[]; notice?: string }> {
291
+ try {
292
+ const fileInfo = await stat(filePath)
293
+ const bytes = new Uint8Array(
294
+ await Bun.file(filePath).slice(0, FILE_PREVIEW_MAX_BYTES).arrayBuffer()
295
+ )
296
+
297
+ if (bytes.includes(0)) {
298
+ return {
299
+ lines: [`${basename(filePath)} (${fileInfo.size} bytes)`],
300
+ notice: 'Binary file; preview skipped.',
301
+ }
302
+ }
303
+
304
+ const formatted = formatPreviewOutput(new TextDecoder().decode(bytes))
305
+ return {
306
+ lines: formatted.lines.length > 0 ? formatted.lines : ['(empty file)'],
307
+ notice:
308
+ formatted.truncated || fileInfo.size > FILE_PREVIEW_MAX_BYTES
309
+ ? 'File preview truncated to fit the panel.'
310
+ : undefined,
311
+ }
312
+ } catch {
313
+ return {
314
+ lines: [basename(filePath)],
315
+ notice: 'Unable to read file contents.',
316
+ }
317
+ }
318
+ }
319
+
320
+ export async function getFilePreview(
321
+ filePath: string,
322
+ config: Config,
323
+ linkedSessionName?: string
324
+ ): Promise<ProjectPreview> {
325
+ const cacheKey = `file::${filePath}::${linkedSessionName ?? ''}`
326
+ const cached = projectPreviewCache.get(cacheKey)
327
+ if (cached && cached.expiresAt > Date.now()) {
328
+ return cached.preview
329
+ }
330
+
331
+ const parentDirectory = dirname(filePath)
332
+ const resolvedSession = resolveFileSession(filePath, config)
333
+ const [gitRootPath, gitBranch, linkedSession, fileLines] = await Promise.all([
334
+ getGitRoot(parentDirectory),
335
+ getGitBranch(parentDirectory),
336
+ linkedSessionName
337
+ ? getSessionDetails(linkedSessionName).catch(() => null)
338
+ : Promise.resolve(null),
339
+ getFilePreviewLines(filePath),
340
+ ])
341
+
342
+ const preview: ProjectPreview = {
343
+ path: displayPath(filePath),
344
+ sessionName: resolvedSession.sessionName,
345
+ source: 'file',
346
+ startupCommand: resolvedSession.startupCommand,
347
+ gitRoot: gitRootPath ? displayPath(gitRootPath) : undefined,
348
+ gitBranch,
349
+ linkedSession: linkedSession ?? undefined,
350
+ previewKind: 'file',
351
+ previewLabel: 'File Preview',
352
+ previewLines: fileLines.lines,
353
+ previewNotice: fileLines.notice,
354
+ }
355
+
356
+ projectPreviewCache.set(cacheKey, {
357
+ preview,
358
+ expiresAt: Date.now() + PROJECT_PREVIEW_CACHE_TTL_MS,
359
+ })
360
+
361
+ return preview
362
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Config, Item } from '../types'
2
2
  import { resolveProjectSession } from '../config/session-rules'
3
+ import { buildFileSessionName, isFileItem } from '../files/target'
3
4
 
4
5
  export async function annotateProjectItemsWithSessionLinks(
5
6
  projectItems: Item[],
@@ -10,8 +11,10 @@ export async function annotateProjectItemsWithSessionLinks(
10
11
 
11
12
  return Promise.all(
12
13
  projectItems.map(async projectItem => {
13
- const resolvedSession = await resolveProjectSession(projectItem.path, config)
14
- const linkedSession = liveSessionsByTitle.get(resolvedSession.sessionName)
14
+ const sessionName = isFileItem(projectItem)
15
+ ? buildFileSessionName(projectItem.path)
16
+ : (await resolveProjectSession(projectItem.path, config)).sessionName
17
+ const linkedSession = liveSessionsByTitle.get(sessionName)
15
18
 
16
19
  if (!linkedSession) {
17
20
  return {
@@ -0,0 +1,224 @@
1
+ import { basename, join } from 'path'
2
+ import { homedir } from 'os'
3
+ import type { FileFinder, MixedSearchResult } from '@ff-labs/fff-bun'
4
+ import { scoreSearchItems } from './index'
5
+ import type { Config, Item } from '../types'
6
+
7
+ declare global {
8
+ // Build-time constant used by @ff-labs/fff-bun for compiled binaries.
9
+ const FFF_LIBC: 'gnu' | 'musl'
10
+ }
11
+ import { getExistingProjectRoots, uniqueNormalizedPaths } from '../tmux/project-discovery'
12
+ import { getPathContextLabel } from '../util/path-display'
13
+
14
+ const DEFAULT_RESULT_LIMIT = 60
15
+ const SCAN_WAIT_TIMEOUT_MS = 1500
16
+
17
+ interface ScoredItem {
18
+ item: Item
19
+ score: number
20
+ }
21
+
22
+ type FffModule = typeof import('@ff-labs/fff-bun')
23
+
24
+ const state: {
25
+ module?: FffModule | null
26
+ finders: Map<string, Promise<FileFinder | null>>
27
+ } = {
28
+ finders: new Map(),
29
+ }
30
+
31
+ function isFileSearchDisabled(): boolean {
32
+ const flag = process.env.MUX_SESH_DISABLE_FFF?.toLowerCase()
33
+ return flag === '1' || flag === 'true'
34
+ }
35
+
36
+ async function loadFffModule(): Promise<FffModule | null> {
37
+ if (state.module !== undefined) {
38
+ return state.module
39
+ }
40
+
41
+ if (isFileSearchDisabled()) {
42
+ state.module = null
43
+ return null
44
+ }
45
+
46
+ try {
47
+ const loaded = await import('@ff-labs/fff-bun')
48
+ state.module = loaded.FileFinder.isAvailable() ? loaded : null
49
+ } catch {
50
+ state.module = null
51
+ }
52
+
53
+ return state.module
54
+ }
55
+
56
+ async function getFinder(root: string): Promise<FileFinder | null> {
57
+ const cached = state.finders.get(root)
58
+ if (cached) {
59
+ return cached
60
+ }
61
+
62
+ const created = (async () => {
63
+ const loaded = await loadFffModule()
64
+ if (!loaded) {
65
+ return null
66
+ }
67
+
68
+ const made = loaded.FileFinder.create({
69
+ basePath: root,
70
+ disableMmapCache: true,
71
+ disableContentIndexing: true,
72
+ enableHomeDirScanning: root === homedir(),
73
+ })
74
+ if (!made.ok) {
75
+ return null
76
+ }
77
+
78
+ await made.value.waitForScan(SCAN_WAIT_TIMEOUT_MS)
79
+ return made.value
80
+ })()
81
+
82
+ state.finders.set(root, created)
83
+ return created
84
+ }
85
+
86
+ export function mapMixedResultToScoredItems(root: string, result: MixedSearchResult): ScoredItem[] {
87
+ return result.items.flatMap((mixed, index): ScoredItem[] => {
88
+ const score = result.scores[index]?.total ?? 0
89
+
90
+ if (mixed.type === 'file') {
91
+ const path = join(root, mixed.item.relativePath)
92
+ return [
93
+ {
94
+ score,
95
+ item: {
96
+ title: mixed.item.fileName,
97
+ desc: getPathContextLabel(path),
98
+ path,
99
+ isSession: false,
100
+ itemKind: 'file' as const,
101
+ },
102
+ },
103
+ ]
104
+ }
105
+
106
+ const relative = mixed.item.relativePath.replace(/[\\/]+$/, '')
107
+ if (!relative) {
108
+ return []
109
+ }
110
+
111
+ const path = join(root, relative)
112
+ return [
113
+ {
114
+ score,
115
+ item: {
116
+ title: basename(path),
117
+ desc: getPathContextLabel(path),
118
+ path,
119
+ isSession: false,
120
+ itemKind: 'project' as const,
121
+ },
122
+ },
123
+ ]
124
+ })
125
+ }
126
+
127
+ export function mergeScoredItems(results: ScoredItem[][], limit: number): Item[] {
128
+ const seenPaths = new Set<string>()
129
+
130
+ return results
131
+ .flat()
132
+ .sort(
133
+ (left, right) => right.score - left.score || left.item.path.length - right.item.path.length
134
+ )
135
+ .flatMap(scored => {
136
+ if (seenPaths.has(scored.item.path)) {
137
+ return []
138
+ }
139
+
140
+ seenPaths.add(scored.item.path)
141
+ return [scored.item]
142
+ })
143
+ .slice(0, limit)
144
+ }
145
+
146
+ export function combineFileSearchResults(
147
+ fileSearchItems: Item[],
148
+ localItems: Item[],
149
+ query: string
150
+ ): Item[] {
151
+ if (fileSearchItems.length === 0) {
152
+ return localItems
153
+ }
154
+
155
+ const localPaths = new Set(localItems.map(item => item.path))
156
+ const newFileSearchItems = fileSearchItems.filter(item => !localPaths.has(item.path))
157
+ const candidates = [...localItems, ...newFileSearchItems]
158
+
159
+ const scored = scoreSearchItems(candidates, query).sort((left, right) => right.score - left.score)
160
+ const scoredPaths = new Set(scored.map(result => result.item.path))
161
+
162
+ // fff matched these (typo-resistant) even though the local matcher rejected
163
+ // them; keep them visible at the bottom in fff ranking order.
164
+ const typoOnlyItems = newFileSearchItems.filter(item => !scoredPaths.has(item.path))
165
+
166
+ return [...scored.map(result => result.item), ...typoOnlyItems]
167
+ }
168
+
169
+ async function searchRoot(root: string, query: string, limit: number): Promise<ScoredItem[]> {
170
+ const finder = await getFinder(root)
171
+ if (!finder) {
172
+ return []
173
+ }
174
+
175
+ const result = finder.mixedSearch(query, { pageSize: limit })
176
+ if (!result.ok) {
177
+ return []
178
+ }
179
+
180
+ return mapMixedResultToScoredItems(root, result.value)
181
+ }
182
+
183
+ export async function isFileSearchAvailable(): Promise<boolean> {
184
+ return (await loadFffModule()) !== null
185
+ }
186
+
187
+ export async function warmFileSearch(config: Config): Promise<void> {
188
+ if (!(await loadFffModule())) {
189
+ return
190
+ }
191
+
192
+ const roots = await getExistingProjectRoots(uniqueNormalizedPaths(config.projectPaths))
193
+ await Promise.all(roots.map(root => getFinder(root)))
194
+ }
195
+
196
+ export async function searchFilesAndDirectories(
197
+ query: string,
198
+ config: Config,
199
+ limit = DEFAULT_RESULT_LIMIT
200
+ ): Promise<Item[]> {
201
+ const trimmed = query.trim()
202
+ if (!trimmed || !(await loadFffModule())) {
203
+ return []
204
+ }
205
+
206
+ const roots = await getExistingProjectRoots(uniqueNormalizedPaths(config.projectPaths))
207
+ if (roots.length === 0) {
208
+ return []
209
+ }
210
+
211
+ const results = await Promise.all(roots.map(root => searchRoot(root, trimmed, limit)))
212
+ return mergeScoredItems(results, limit)
213
+ }
214
+
215
+ export async function destroyFileSearch(): Promise<void> {
216
+ const pending = [...state.finders.values()]
217
+ state.finders.clear()
218
+ state.module = undefined
219
+
220
+ for (const finderPromise of pending) {
221
+ const finder = await finderPromise.catch(() => null)
222
+ finder?.destroy()
223
+ }
224
+ }
@@ -176,6 +176,13 @@ export function clearMatchIndices(items: Item[]): Item[] {
176
176
  return items.map(item => withSearchMatch(item))
177
177
  }
178
178
 
179
+ export function scoreSearchItems(items: Item[], query: string): SearchResult[] {
180
+ return items.flatMap(item => {
181
+ const result = buildSearchResult(item, query)
182
+ return result ? [result] : []
183
+ })
184
+ }
185
+
179
186
  export function filterAndSortItems(items: Item[], query: string): Item[] {
180
187
  if (!query.trim()) {
181
188
  return clearMatchIndices(items)
@@ -12,7 +12,7 @@ export enum ViewMode {
12
12
 
13
13
  export type KeybindMode = 'vim' | 'standard'
14
14
  export type ZoxideMode = 'off' | 'rank' | 'merge'
15
- export type ItemKind = 'tmux' | 'configured' | 'project'
15
+ export type ItemKind = 'tmux' | 'configured' | 'project' | 'file'
16
16
  export type SortOrder = 'live-first' | 'configured-first' | 'zoxide-first' | 'alphabetical'
17
17
 
18
18
  export interface IconConfig {
@@ -37,7 +37,11 @@ export default function ItemList({
37
37
  const hasTitleMatch = titleMatchIndices && titleMatchIndices.length > 0
38
38
  const hasDescMatch = descMatchIndices && descMatchIndices.length > 0
39
39
  const icon = getItemIconPresentation(theme, item, icons)
40
- const sessionStatusLabel = item.linkedSessionName ? 'attach' : 'create'
40
+ const sessionStatusLabel = item.linkedSessionName
41
+ ? 'attach'
42
+ : item.itemKind === 'file'
43
+ ? 'open'
44
+ : 'create'
41
45
  const linkedSessionLabel = item.linkedSessionName ? ` -> ${item.linkedSessionName}` : ''
42
46
  const pendingKill = item.isSession && item.title === pendingKillSessionName
43
47
  const selected = absoluteIndex === cursor
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useState } from 'react'
2
- import { getProjectPreview, type ProjectPreview } from '../preview/project'
2
+ import { getFilePreview, getProjectPreview, type ProjectPreview } from '../preview/project'
3
+ import { isFileItem } from '../files/target'
3
4
  import { getSessionDetails } from '../tmux'
4
5
  import { getDetailPanelStyle, useTheme } from '../styles/theme'
5
6
  import type { Config, Item, SessionDetails } from '../types'
@@ -24,6 +25,8 @@ function formatSourceLabel(source: ProjectPreview['source']): string {
24
25
  return 'Wildcard rule'
25
26
  case 'default':
26
27
  return 'Default rule'
28
+ case 'file':
29
+ return 'File target'
27
30
  }
28
31
  }
29
32
 
@@ -179,11 +182,9 @@ export default function SessionDetailsPanel({ selectedItem, config }: Props) {
179
182
  return
180
183
  }
181
184
 
182
- const details = await getProjectPreview(
183
- selectedItem.path,
184
- config,
185
- selectedItem.linkedSessionName
186
- )
185
+ const details = isFileItem(selectedItem)
186
+ ? await getFilePreview(selectedItem.path, config, selectedItem.linkedSessionName)
187
+ : await getProjectPreview(selectedItem.path, config, selectedItem.linkedSessionName)
187
188
  if (!cancelled) {
188
189
  setDetailState({ status: 'project', details })
189
190
  }
@@ -6,6 +6,8 @@ export interface ItemIconPresentation {
6
6
  color: string
7
7
  }
8
8
 
9
+ const FILE_ITEM_GLYPH = '  '
10
+
9
11
  function getIconConfig(icons?: IconConfig): IconConfig {
10
12
  return {
11
13
  tmux: icons?.tmux ?? '',
@@ -29,6 +31,17 @@ export function getItemIconPresentation(
29
31
  }
30
32
  }
31
33
 
34
+ if (item.itemKind === 'file') {
35
+ return {
36
+ glyph: item.icon ?? FILE_ITEM_GLYPH,
37
+ color: item.linkedSessionAttached
38
+ ? theme.active
39
+ : item.linkedSessionName
40
+ ? theme.inactive
41
+ : theme.fileTree,
42
+ }
43
+ }
44
+
32
45
  if (item.isSession) {
33
46
  return {
34
47
  glyph: