mux-sesh 1.6.3 → 1.7.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.
Files changed (82) hide show
  1. package/README.md +90 -59
  2. package/package.json +7 -5
  3. package/src/app/commands.ts +120 -0
  4. package/src/app/controller.ts +397 -0
  5. package/src/app/controls.ts +121 -0
  6. package/src/app/core-state.ts +71 -0
  7. package/src/app/data.ts +90 -0
  8. package/src/app/derived.ts +77 -0
  9. package/src/app/effects.ts +392 -0
  10. package/src/app/handlers.ts +325 -0
  11. package/src/app/keyboard.ts +161 -0
  12. package/src/app/modal-keyboard.ts +118 -0
  13. package/src/app/modal-state.ts +50 -0
  14. package/src/app/modals-layer.tsx +159 -0
  15. package/src/app/modals.ts +108 -0
  16. package/src/app/notifications.ts +21 -0
  17. package/src/app/opencode.ts +49 -0
  18. package/src/app/operations.ts +31 -0
  19. package/src/app/runtime.ts +76 -0
  20. package/src/app/screen.tsx +217 -0
  21. package/src/app/state.ts +166 -0
  22. package/src/app/textarea.ts +16 -0
  23. package/src/app/view.ts +89 -0
  24. package/src/app.tsx +7 -1101
  25. package/src/config/index.ts +36 -42
  26. package/src/config/listed-sessions.ts +2 -5
  27. package/src/config/paths.ts +13 -0
  28. package/src/config/session-rules.ts +10 -11
  29. package/src/config/store.ts +26 -0
  30. package/src/handlers/action-helpers.ts +50 -0
  31. package/src/handlers/actions.ts +34 -65
  32. package/src/handlers/keyboard/index.ts +5 -0
  33. package/src/handlers/keyboard/new-session.ts +57 -0
  34. package/src/handlers/keyboard/normal.ts +201 -0
  35. package/src/handlers/keyboard/opencode.ts +104 -0
  36. package/src/handlers/keyboard/search.ts +113 -0
  37. package/src/handlers/keyboard/shared.ts +116 -0
  38. package/src/items/order.ts +21 -2
  39. package/src/opencode/sqlite.ts +21 -6
  40. package/src/preview/project.ts +41 -15
  41. package/src/search/index.ts +4 -1
  42. package/src/settings.ts +294 -297
  43. package/src/styles/opencode-themes-a.ts +1442 -1
  44. package/src/styles/opencode-themes-b.ts +1212 -1
  45. package/src/styles/opencode-tui-colors.ts +1784 -1
  46. package/src/styles/theme.tsx +2 -1
  47. package/src/tmux/actions.ts +103 -0
  48. package/src/tmux/details.ts +123 -0
  49. package/src/tmux/helpers.ts +35 -0
  50. package/src/tmux/index.ts +10 -286
  51. package/src/tmux/list.ts +31 -0
  52. package/src/tmux/project-discovery.ts +113 -0
  53. package/src/tmux/project-loader.ts +74 -0
  54. package/src/tmux/project-zoxide.ts +128 -0
  55. package/src/tmux/projects.ts +23 -261
  56. package/src/types/index.ts +0 -1
  57. package/src/ui/CommandsModal.tsx +87 -22
  58. package/src/ui/HighlightedText.tsx +1 -5
  59. package/src/ui/ItemList.tsx +26 -11
  60. package/src/ui/Modal.tsx +8 -1
  61. package/src/ui/OpencodeSessionGroup.tsx +20 -9
  62. package/src/ui/OpencodeStatsPanel.tsx +48 -15
  63. package/src/ui/RenameModal.tsx +17 -17
  64. package/src/ui/SearchInput.tsx +1 -20
  65. package/src/ui/SessionDetailsPanel.tsx +43 -15
  66. package/src/ui/SessionList.tsx +25 -4
  67. package/src/ui/SettingEditorModal.tsx +15 -9
  68. package/src/ui/SettingOptionsModal.tsx +30 -12
  69. package/src/ui/SettingsModal.tsx +20 -14
  70. package/src/ui/VersionBadge.tsx +3 -1
  71. package/src/ui/item-icon.ts +5 -1
  72. package/src/ui/list-window.ts +5 -1
  73. package/src/ui/text-columns.ts +17 -0
  74. package/src/ui/use-textarea-focus.ts +26 -0
  75. package/src/update/index.ts +10 -2
  76. package/src/update/installation.ts +6 -2
  77. package/src/util/ansi.ts +3 -0
  78. package/src/util/glob.ts +5 -1
  79. package/src/util/path-display.ts +98 -0
  80. package/src/components/KeybindHelp.tsx +0 -289
  81. package/src/handlers/keyboard.ts +0 -654
  82. package/src/ui/SessionStats.tsx +0 -32
@@ -0,0 +1,113 @@
1
+ import { basename } from 'path'
2
+ import { access, stat } from 'fs/promises'
3
+ import type { Config, Item } from '../types'
4
+ import { normalizePathForMatching } from '../util/glob'
5
+ import { getPathContextLabel } from '../util/path-display'
6
+
7
+ export interface DiscoveryCacheEntry {
8
+ expiresAt: number
9
+ items: Item[]
10
+ }
11
+
12
+ const PROJECT_MARKERS = [
13
+ '.git',
14
+ '.jj',
15
+ 'package.json',
16
+ 'Cargo.toml',
17
+ 'go.mod',
18
+ 'pyproject.toml',
19
+ 'flake.nix',
20
+ ]
21
+
22
+ export function isIgnoredProjectDirectory(baseName: string): boolean {
23
+ return (
24
+ baseName.startsWith('.') ||
25
+ baseName === 'node_modules' ||
26
+ baseName === 'target' ||
27
+ baseName === 'build' ||
28
+ baseName === 'dist'
29
+ )
30
+ }
31
+
32
+ export function toProjectItem(projectPath: string): Item {
33
+ return {
34
+ title: basename(projectPath),
35
+ desc: getPathContextLabel(projectPath),
36
+ path: projectPath,
37
+ isSession: false,
38
+ itemKind: 'project',
39
+ }
40
+ }
41
+
42
+ export function uniqueNormalizedPaths(paths: string[]): string[] {
43
+ return [...new Set(paths.map(path => normalizePathForMatching(path)))]
44
+ }
45
+
46
+ export function buildCacheKey(config: Config, scope: 'projects' | 'session-candidates'): string {
47
+ return JSON.stringify({
48
+ scope,
49
+ roots: uniqueNormalizedPaths(config.projectPaths),
50
+ zoxideMode: config.zoxideMode,
51
+ })
52
+ }
53
+
54
+ async function hasProjectMarker(projectPath: string): Promise<boolean> {
55
+ for (const marker of PROJECT_MARKERS) {
56
+ try {
57
+ await access(`${projectPath}/${marker}`)
58
+ return true
59
+ } catch {}
60
+ }
61
+
62
+ return false
63
+ }
64
+
65
+ export async function filterProjectCandidatePaths(projectPaths: string[]): Promise<string[]> {
66
+ const uniquePaths = uniqueNormalizedPaths(projectPaths)
67
+ const matches = await Promise.all(
68
+ uniquePaths.map(async projectPath => ({
69
+ projectPath,
70
+ include: await hasProjectMarker(projectPath),
71
+ }))
72
+ )
73
+
74
+ return matches.filter(match => match.include).map(match => match.projectPath)
75
+ }
76
+
77
+ export async function getExistingProjectRoots(projectPaths: string[]): Promise<string[]> {
78
+ const existingPaths: string[] = []
79
+ for (const path of projectPaths) {
80
+ try {
81
+ const pathStat = await stat(path)
82
+ if (pathStat.isDirectory()) {
83
+ existingPaths.push(path)
84
+ }
85
+ } catch {}
86
+ }
87
+
88
+ return existingPaths
89
+ }
90
+
91
+ export function filterSessionCandidatePaths(paths: string[]): string[] {
92
+ return uniqueNormalizedPaths(paths).filter(path => !isIgnoredProjectDirectory(basename(path)))
93
+ }
94
+
95
+ export async function getCachedDiscovery(
96
+ cache: Map<string, DiscoveryCacheEntry>,
97
+ cacheKey: string,
98
+ ttlMs: number,
99
+ load: () => Promise<Item[]>
100
+ ): Promise<Item[]> {
101
+ const cached = cache.get(cacheKey)
102
+ if (cached && cached.expiresAt > Date.now()) {
103
+ return cached.items
104
+ }
105
+
106
+ const items = await load()
107
+ cache.set(cacheKey, {
108
+ items,
109
+ expiresAt: Date.now() + ttlMs,
110
+ })
111
+
112
+ return items
113
+ }
@@ -0,0 +1,74 @@
1
+ import { spawn } from 'bun'
2
+ import type { Config, Item } from '../types'
3
+ import { normalizePathForMatching } from '../util/glob'
4
+ import {
5
+ buildCacheKey,
6
+ getCachedDiscovery,
7
+ getExistingProjectRoots,
8
+ toProjectItem,
9
+ type DiscoveryCacheEntry,
10
+ } from './project-discovery'
11
+ import { applyZoxideMode, getZoxideEntries } from './project-zoxide'
12
+
13
+ type Scope = 'projects' | 'session-candidates'
14
+
15
+ interface DiscoveryLoadOptions {
16
+ cache: Map<string, DiscoveryCacheEntry>
17
+ scope: Scope
18
+ ttlMs: number
19
+ scanDepth: number
20
+ requireProjectMarker: boolean
21
+ selectPaths: (paths: string[]) => Promise<string[]>
22
+ }
23
+
24
+ async function scanDirectories(projectRoots: string[], maxDepth: number): Promise<string[]> {
25
+ if (projectRoots.length === 0) {
26
+ return []
27
+ }
28
+
29
+ const args = [...projectRoots, '-mindepth', '1', '-maxdepth', String(maxDepth), '-type', 'd']
30
+ const proc = spawn(['find', ...args], {
31
+ stderr: 'pipe',
32
+ })
33
+ const output = await new Response(proc.stdout).text()
34
+ const stderrPromise = new Response(proc.stderr).text()
35
+ await proc.exited
36
+ await stderrPromise
37
+
38
+ return output
39
+ .trim()
40
+ .split('\n')
41
+ .filter(Boolean)
42
+ .map(path => normalizePathForMatching(path))
43
+ }
44
+
45
+ async function runCommand(args: string[]): Promise<{ exitCode: number; output: string }> {
46
+ const proc = spawn(args)
47
+ const output = await new Response(proc.stdout).text()
48
+ await proc.exited
49
+ return { exitCode: proc.exitCode ?? 1, output }
50
+ }
51
+
52
+ export async function loadDiscoveryItems(
53
+ config: Config,
54
+ options: DiscoveryLoadOptions
55
+ ): Promise<Item[]> {
56
+ const cacheKey = buildCacheKey(config, options.scope)
57
+
58
+ return getCachedDiscovery(options.cache, cacheKey, options.ttlMs, async () => {
59
+ const existingPaths = await getExistingProjectRoots(config.projectPaths)
60
+ if (existingPaths.length === 0) {
61
+ return []
62
+ }
63
+
64
+ const scannedPaths = await scanDirectories(existingPaths, options.scanDepth)
65
+ const selectedPaths = await options.selectPaths(scannedPaths)
66
+ const items = selectedPaths.map(toProjectItem)
67
+ const zoxideEntries =
68
+ config.zoxideMode === 'off'
69
+ ? []
70
+ : await getZoxideEntries(runCommand, existingPaths, options.requireProjectMarker)
71
+
72
+ return applyZoxideMode(items, zoxideEntries, config)
73
+ })
74
+ }
@@ -0,0 +1,128 @@
1
+ import { basename } from 'path'
2
+ import type { Config, Item } from '../types'
3
+ import { normalizePathForMatching } from '../util/glob'
4
+ import {
5
+ filterProjectCandidatePaths,
6
+ isIgnoredProjectDirectory,
7
+ toProjectItem,
8
+ } from './project-discovery'
9
+
10
+ export interface ZoxideEntry {
11
+ score: number
12
+ path: string
13
+ }
14
+
15
+ export function parseZoxideOutput(output: string): ZoxideEntry[] {
16
+ return output
17
+ .trim()
18
+ .split('\n')
19
+ .filter(Boolean)
20
+ .flatMap(line => {
21
+ const trimmed = line.trim()
22
+ const firstSpaceIndex = trimmed.indexOf(' ')
23
+ if (firstSpaceIndex === -1) {
24
+ return []
25
+ }
26
+
27
+ const score = Number(trimmed.slice(0, firstSpaceIndex))
28
+ const path = trimmed.slice(firstSpaceIndex + 1).trim()
29
+ if (!Number.isFinite(score) || !path) {
30
+ return []
31
+ }
32
+
33
+ return [{ score, path }]
34
+ })
35
+ }
36
+
37
+ export function isWithinProjectRoots(projectPath: string, projectRoots: string[]): boolean {
38
+ const normalizedProjectPath = normalizePathForMatching(projectPath)
39
+
40
+ return projectRoots.some(projectRoot => {
41
+ const normalizedRoot = normalizePathForMatching(projectRoot)
42
+ return (
43
+ normalizedProjectPath === normalizedRoot ||
44
+ normalizedProjectPath.startsWith(`${normalizedRoot}/`)
45
+ )
46
+ })
47
+ }
48
+
49
+ function rankItemsByZoxide(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
50
+ if (config.zoxideMode === 'off' || entries.length === 0) {
51
+ return items.sort((a, b) => a.title.localeCompare(b.title))
52
+ }
53
+
54
+ const zoxideScores = new Map(
55
+ entries.map(entry => [normalizePathForMatching(entry.path), entry.score])
56
+ )
57
+
58
+ return [...items].sort((left, right) => {
59
+ const scoreDifference =
60
+ (zoxideScores.get(normalizePathForMatching(right.path)) ?? 0) -
61
+ (zoxideScores.get(normalizePathForMatching(left.path)) ?? 0)
62
+
63
+ if (scoreDifference !== 0) {
64
+ return scoreDifference
65
+ }
66
+
67
+ return left.title.localeCompare(right.title)
68
+ })
69
+ }
70
+
71
+ export function applyZoxideMode(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
72
+ const rankedItems = rankItemsByZoxide(items, entries, config)
73
+
74
+ if (config.zoxideMode !== 'merge') {
75
+ return rankedItems
76
+ }
77
+
78
+ const existingPaths = new Set(rankedItems.map(item => normalizePathForMatching(item.path)))
79
+ const mergedItems = entries.flatMap(entry => {
80
+ const normalizedPath = normalizePathForMatching(entry.path)
81
+ const baseName = basename(entry.path)
82
+
83
+ if (
84
+ existingPaths.has(normalizedPath) ||
85
+ !isWithinProjectRoots(entry.path, config.projectPaths) ||
86
+ isIgnoredProjectDirectory(baseName)
87
+ ) {
88
+ return []
89
+ }
90
+
91
+ existingPaths.add(normalizedPath)
92
+ return [toProjectItem(entry.path)]
93
+ })
94
+
95
+ return [...rankedItems, ...mergedItems]
96
+ }
97
+
98
+ export async function getZoxideEntries(
99
+ spawnCommand: (args: string[]) => Promise<{ exitCode: number; output: string }>,
100
+ projectRoots: string[],
101
+ requireProjectMarker: boolean
102
+ ): Promise<ZoxideEntry[]> {
103
+ try {
104
+ const result = await spawnCommand(['zoxide', 'query', '--list', '--score'])
105
+ if (result.exitCode !== 0) {
106
+ return []
107
+ }
108
+
109
+ const entriesWithinRoots = parseZoxideOutput(result.output).filter(entry =>
110
+ isWithinProjectRoots(entry.path, projectRoots)
111
+ )
112
+
113
+ if (!requireProjectMarker) {
114
+ return entriesWithinRoots.filter(entry => !isIgnoredProjectDirectory(basename(entry.path)))
115
+ }
116
+
117
+ const projectCandidatePaths = await filterProjectCandidatePaths(
118
+ entriesWithinRoots.map(entry => entry.path)
119
+ )
120
+ const projectCandidates = new Set(projectCandidatePaths)
121
+
122
+ return entriesWithinRoots.filter(entry =>
123
+ projectCandidates.has(normalizePathForMatching(entry.path))
124
+ )
125
+ } catch {
126
+ return []
127
+ }
128
+ }
@@ -1,276 +1,38 @@
1
- import { spawn } from 'bun'
2
- import { basename } from 'path'
3
- import { access, stat } from 'fs/promises'
4
1
  import type { Config, Item } from '../types'
5
- import { normalizePathForMatching } from '../util/glob'
2
+ import {
3
+ filterProjectCandidatePaths,
4
+ filterSessionCandidatePaths,
5
+ type DiscoveryCacheEntry,
6
+ } from './project-discovery'
7
+ import { loadDiscoveryItems } from './project-loader'
8
+ import { applyZoxideMode, parseZoxideOutput } from './project-zoxide'
6
9
 
7
- interface ZoxideEntry {
8
- score: number
9
- path: string
10
- }
11
-
12
- interface DiscoveryCacheEntry {
13
- expiresAt: number
14
- items: Item[]
15
- }
16
-
17
- const PROJECT_MARKERS = ['.git', '.jj', 'package.json', 'Cargo.toml', 'go.mod', 'pyproject.toml', 'flake.nix']
18
10
  const DISCOVERY_CACHE_TTL_MS = 15000
19
11
  const PROJECT_SCAN_DEPTH = 3
20
12
  const SESSION_CANDIDATE_SCAN_DEPTH = 5
21
13
  const projectItemsCache = new Map<string, DiscoveryCacheEntry>()
22
14
  const sessionCandidateCache = new Map<string, DiscoveryCacheEntry>()
23
15
 
24
- function isIgnoredProjectDirectory(baseName: string): boolean {
25
- return (
26
- baseName.startsWith('.') ||
27
- baseName === 'node_modules' ||
28
- baseName === 'target' ||
29
- baseName === 'build' ||
30
- baseName === 'dist'
31
- )
32
- }
33
-
34
- function toProjectItem(projectPath: string): Item {
35
- return {
36
- title: basename(projectPath),
37
- desc: projectPath.replace(process.env.HOME || '', '~'),
38
- path: projectPath,
39
- isSession: false,
40
- itemKind: 'project',
41
- }
42
- }
43
-
44
- function uniqueNormalizedPaths(paths: string[]): string[] {
45
- return [...new Set(paths.map(path => normalizePathForMatching(path)))]
46
- }
47
-
48
- function buildCacheKey(config: Config, scope: 'projects' | 'session-candidates'): string {
49
- return JSON.stringify({
50
- scope,
51
- roots: uniqueNormalizedPaths(config.projectPaths),
52
- zoxideMode: config.zoxideMode,
53
- })
54
- }
55
-
56
- async function hasProjectMarker(projectPath: string): Promise<boolean> {
57
- for (const marker of PROJECT_MARKERS) {
58
- try {
59
- await access(`${projectPath}/${marker}`)
60
- return true
61
- } catch {}
62
- }
63
-
64
- return false
65
- }
66
-
67
- export async function filterProjectCandidatePaths(projectPaths: string[]): Promise<string[]> {
68
- const uniquePaths = uniqueNormalizedPaths(projectPaths)
69
- const matches = await Promise.all(
70
- uniquePaths.map(async projectPath => ({
71
- projectPath,
72
- include: await hasProjectMarker(projectPath),
73
- }))
74
- )
75
-
76
- return matches.filter(match => match.include).map(match => match.projectPath)
77
- }
78
-
79
- export function parseZoxideOutput(output: string): ZoxideEntry[] {
80
- return output
81
- .trim()
82
- .split('\n')
83
- .filter(Boolean)
84
- .flatMap(line => {
85
- const trimmed = line.trim()
86
- const firstSpaceIndex = trimmed.indexOf(' ')
87
- if (firstSpaceIndex === -1) {
88
- return []
89
- }
90
-
91
- const score = Number(trimmed.slice(0, firstSpaceIndex))
92
- const path = trimmed.slice(firstSpaceIndex + 1).trim()
93
- if (!Number.isFinite(score) || !path) {
94
- return []
95
- }
96
-
97
- return [{ score, path }]
98
- })
99
- }
100
-
101
- function isWithinProjectRoots(projectPath: string, projectRoots: string[]): boolean {
102
- const normalizedProjectPath = normalizePathForMatching(projectPath)
103
-
104
- return projectRoots.some(projectRoot => {
105
- const normalizedRoot = normalizePathForMatching(projectRoot)
106
- return normalizedProjectPath === normalizedRoot || normalizedProjectPath.startsWith(`${normalizedRoot}/`)
107
- })
108
- }
109
-
110
- function rankItemsByZoxide(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
111
- if (config.zoxideMode === 'off' || entries.length === 0) {
112
- return items.sort((a, b) => a.title.localeCompare(b.title))
113
- }
114
-
115
- const zoxideScores = new Map(entries.map(entry => [normalizePathForMatching(entry.path), entry.score]))
116
-
117
- return [...items].sort((left, right) => {
118
- const scoreDifference =
119
- (zoxideScores.get(normalizePathForMatching(right.path)) ?? 0) -
120
- (zoxideScores.get(normalizePathForMatching(left.path)) ?? 0)
121
-
122
- if (scoreDifference !== 0) {
123
- return scoreDifference
124
- }
125
-
126
- return left.title.localeCompare(right.title)
127
- })
128
- }
129
-
130
- export function applyZoxideMode(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
131
- const rankedItems = rankItemsByZoxide(items, entries, config)
132
-
133
- if (config.zoxideMode !== 'merge') {
134
- return rankedItems
135
- }
136
-
137
- const existingPaths = new Set(rankedItems.map(item => normalizePathForMatching(item.path)))
138
- const mergedItems = entries.flatMap(entry => {
139
- const normalizedPath = normalizePathForMatching(entry.path)
140
- const baseName = basename(entry.path)
141
-
142
- if (
143
- existingPaths.has(normalizedPath) ||
144
- !isWithinProjectRoots(entry.path, config.projectPaths) ||
145
- isIgnoredProjectDirectory(baseName)
146
- ) {
147
- return []
148
- }
149
-
150
- existingPaths.add(normalizedPath)
151
- return [toProjectItem(entry.path)]
152
- })
153
-
154
- return [...rankedItems, ...mergedItems]
155
- }
156
-
157
- async function getZoxideEntries(projectRoots: string[], requireProjectMarker: boolean): Promise<ZoxideEntry[]> {
158
- try {
159
- const proc = spawn(['zoxide', 'query', '--list', '--score'])
160
- const output = await new Response(proc.stdout).text()
161
- await proc.exited
162
-
163
- if (proc.exitCode !== 0) {
164
- return []
165
- }
166
-
167
- const entriesWithinRoots = parseZoxideOutput(output).filter(entry => isWithinProjectRoots(entry.path, projectRoots))
168
-
169
- if (!requireProjectMarker) {
170
- return entriesWithinRoots.filter(entry => !isIgnoredProjectDirectory(basename(entry.path)))
171
- }
172
-
173
- const projectCandidatePaths = await filterProjectCandidatePaths(entriesWithinRoots.map(entry => entry.path))
174
- const projectCandidates = new Set(projectCandidatePaths)
175
-
176
- return entriesWithinRoots.filter(entry => projectCandidates.has(normalizePathForMatching(entry.path)))
177
- } catch {
178
- return []
179
- }
180
- }
181
-
182
- async function getExistingProjectRoots(projectPaths: string[]): Promise<string[]> {
183
- const existingPaths: string[] = []
184
- for (const path of projectPaths) {
185
- try {
186
- const pathStat = await stat(path)
187
- if (pathStat.isDirectory()) {
188
- existingPaths.push(path)
189
- }
190
- } catch {}
191
- }
192
-
193
- return existingPaths
194
- }
195
-
196
- async function scanDirectories(projectRoots: string[], maxDepth: number): Promise<string[]> {
197
- if (projectRoots.length === 0) {
198
- return []
199
- }
200
-
201
- const args = [...projectRoots, '-mindepth', '1', '-maxdepth', String(maxDepth), '-type', 'd']
202
- const proc = spawn(['find', ...args], {
203
- stderr: 'pipe',
204
- })
205
- const output = await new Response(proc.stdout).text()
206
- const stderrPromise = new Response(proc.stderr).text()
207
- await proc.exited
208
- await stderrPromise
209
-
210
- return output
211
- .trim()
212
- .split('\n')
213
- .filter(Boolean)
214
- .map(path => normalizePathForMatching(path))
215
- }
216
-
217
- function filterSessionCandidatePaths(paths: string[]): string[] {
218
- return uniqueNormalizedPaths(paths).filter(path => !isIgnoredProjectDirectory(basename(path)))
219
- }
220
-
221
- async function getCachedDiscovery(
222
- cache: Map<string, DiscoveryCacheEntry>,
223
- cacheKey: string,
224
- load: () => Promise<Item[]>
225
- ): Promise<Item[]> {
226
- const cached = cache.get(cacheKey)
227
- if (cached && cached.expiresAt > Date.now()) {
228
- return cached.items
229
- }
230
-
231
- const items = await load()
232
- cache.set(cacheKey, {
233
- items,
234
- expiresAt: Date.now() + DISCOVERY_CACHE_TTL_MS,
235
- })
236
-
237
- return items
238
- }
239
-
240
16
  export async function getProjectItems(config: Config): Promise<Item[]> {
241
- const cacheKey = buildCacheKey(config, 'projects')
242
-
243
- return getCachedDiscovery(projectItemsCache, cacheKey, async () => {
244
- const existingPaths = await getExistingProjectRoots(config.projectPaths)
245
- if (existingPaths.length === 0) {
246
- return []
247
- }
248
-
249
- const scannedPaths = await scanDirectories(existingPaths, PROJECT_SCAN_DEPTH)
250
- const projectCandidatePaths = await filterProjectCandidatePaths(scannedPaths)
251
- const items = projectCandidatePaths
252
- .filter(path => !isIgnoredProjectDirectory(basename(path)))
253
- .map(toProjectItem)
254
-
255
- const zoxideEntries = config.zoxideMode === 'off' ? [] : await getZoxideEntries(existingPaths, true)
256
- return applyZoxideMode(items, zoxideEntries, config)
17
+ return loadDiscoveryItems(config, {
18
+ cache: projectItemsCache,
19
+ scope: 'projects',
20
+ ttlMs: DISCOVERY_CACHE_TTL_MS,
21
+ scanDepth: PROJECT_SCAN_DEPTH,
22
+ requireProjectMarker: true,
23
+ selectPaths: filterProjectCandidatePaths,
257
24
  })
258
25
  }
259
26
 
260
27
  export async function getSessionCandidateItems(config: Config): Promise<Item[]> {
261
- const cacheKey = buildCacheKey(config, 'session-candidates')
262
-
263
- return getCachedDiscovery(sessionCandidateCache, cacheKey, async () => {
264
- const existingPaths = await getExistingProjectRoots(config.projectPaths)
265
- if (existingPaths.length === 0) {
266
- return []
267
- }
268
-
269
- const scannedPaths = await scanDirectories(existingPaths, SESSION_CANDIDATE_SCAN_DEPTH)
270
- const candidatePaths = filterSessionCandidatePaths(scannedPaths)
271
- const items = candidatePaths.map(toProjectItem)
272
- const zoxideEntries = config.zoxideMode === 'off' ? [] : await getZoxideEntries(existingPaths, false)
273
-
274
- return applyZoxideMode(items, zoxideEntries, config)
28
+ return loadDiscoveryItems(config, {
29
+ cache: sessionCandidateCache,
30
+ scope: 'session-candidates',
31
+ ttlMs: DISCOVERY_CACHE_TTL_MS,
32
+ scanDepth: SESSION_CANDIDATE_SCAN_DEPTH,
33
+ requireProjectMarker: false,
34
+ selectPaths: async paths => filterSessionCandidatePaths(paths),
275
35
  })
276
36
  }
37
+
38
+ export { applyZoxideMode, filterProjectCandidatePaths, parseZoxideOutput }
@@ -2,7 +2,6 @@ export enum AppMode {
2
2
  Normal,
3
3
  Search,
4
4
  NewSession,
5
- Rename,
6
5
  OpencodeManage,
7
6
  }
8
7