mux-sesh 1.6.4 → 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 (78) 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 -1136
  25. package/src/config/index.ts +36 -42
  26. package/src/config/paths.ts +13 -0
  27. package/src/config/session-rules.ts +6 -2
  28. package/src/config/store.ts +26 -0
  29. package/src/handlers/action-helpers.ts +50 -0
  30. package/src/handlers/actions.ts +34 -65
  31. package/src/handlers/keyboard/index.ts +5 -0
  32. package/src/handlers/keyboard/new-session.ts +57 -0
  33. package/src/handlers/keyboard/normal.ts +201 -0
  34. package/src/handlers/keyboard/opencode.ts +104 -0
  35. package/src/handlers/keyboard/search.ts +113 -0
  36. package/src/handlers/keyboard/shared.ts +116 -0
  37. package/src/opencode/sqlite.ts +21 -6
  38. package/src/preview/project.ts +41 -15
  39. package/src/search/index.ts +4 -1
  40. package/src/settings.ts +294 -297
  41. package/src/styles/opencode-themes-a.ts +1442 -1
  42. package/src/styles/opencode-themes-b.ts +1212 -1
  43. package/src/styles/opencode-tui-colors.ts +1784 -1
  44. package/src/styles/theme.tsx +2 -1
  45. package/src/tmux/actions.ts +103 -0
  46. package/src/tmux/details.ts +123 -0
  47. package/src/tmux/helpers.ts +35 -0
  48. package/src/tmux/index.ts +10 -288
  49. package/src/tmux/list.ts +31 -0
  50. package/src/tmux/project-discovery.ts +113 -0
  51. package/src/tmux/project-loader.ts +74 -0
  52. package/src/tmux/project-zoxide.ts +128 -0
  53. package/src/tmux/projects.ts +23 -262
  54. package/src/types/index.ts +0 -1
  55. package/src/ui/CommandsModal.tsx +87 -22
  56. package/src/ui/HighlightedText.tsx +1 -5
  57. package/src/ui/ItemList.tsx +14 -4
  58. package/src/ui/Modal.tsx +8 -1
  59. package/src/ui/OpencodeSessionGroup.tsx +20 -9
  60. package/src/ui/OpencodeStatsPanel.tsx +48 -15
  61. package/src/ui/RenameModal.tsx +17 -17
  62. package/src/ui/SearchInput.tsx +1 -20
  63. package/src/ui/SessionDetailsPanel.tsx +43 -15
  64. package/src/ui/SessionList.tsx +23 -6
  65. package/src/ui/SettingEditorModal.tsx +15 -9
  66. package/src/ui/SettingOptionsModal.tsx +30 -12
  67. package/src/ui/SettingsModal.tsx +20 -14
  68. package/src/ui/VersionBadge.tsx +3 -1
  69. package/src/ui/item-icon.ts +5 -1
  70. package/src/ui/list-window.ts +5 -1
  71. package/src/ui/use-textarea-focus.ts +26 -0
  72. package/src/update/index.ts +10 -2
  73. package/src/update/installation.ts +6 -2
  74. package/src/util/ansi.ts +3 -0
  75. package/src/util/glob.ts +5 -1
  76. package/src/components/KeybindHelp.tsx +0 -289
  77. package/src/handlers/keyboard.ts +0 -654
  78. package/src/ui/SessionStats.tsx +0 -32
@@ -0,0 +1,397 @@
1
+ import { useRef } from 'react'
2
+ import { useAppCoreState } from './core-state'
3
+ import { useAutoUpdateScheduler, useAppBehaviors } from './effects'
4
+ import { createAppControls } from './controls'
5
+ import { getSessionCommandState, getSettingsState } from './derived'
6
+ import { useAppKeyboard } from './keyboard'
7
+ import { useAppModalState } from './modal-state'
8
+ import { createAppRuntime } from './runtime'
9
+ import { createAppHandlers, handleKillSessionWithFeedback } from './handlers'
10
+ import { useAppStartup } from './state'
11
+ import { getConfigPath, saveConfig } from '../config'
12
+ import { getOpencodeSessionStats } from '../opencode'
13
+ import { resolveTheme } from '../styles/theme'
14
+ import { useTerminalSize } from '../util/terminal'
15
+ import { mark, measure } from '../util/perf'
16
+ import { getSettingEditorTitle, isOptionSetting } from '../settings'
17
+
18
+ export function useAppController() {
19
+ const {
20
+ appMode,
21
+ setAppMode,
22
+ viewMode,
23
+ setViewMode,
24
+ items,
25
+ setItems,
26
+ allItems,
27
+ setAllItems,
28
+ projectSourceItems,
29
+ setProjectSourceItems,
30
+ sessionCandidateItems,
31
+ setSessionCandidateItems,
32
+ sessionItems,
33
+ setSessionItems,
34
+ cursor,
35
+ setCursor,
36
+ opencodeCursor,
37
+ setOpencodeCursor,
38
+ searchQuery,
39
+ setSearchQuery,
40
+ message,
41
+ setMessage,
42
+ renameTarget,
43
+ setRenameTarget,
44
+ config,
45
+ setConfig,
46
+ pendingKillSessionName,
47
+ setPendingKillSessionName,
48
+ prefixActive,
49
+ setPrefixActive,
50
+ prefixTimeoutRef,
51
+ textareaRef,
52
+ lastSessionSelectionRef,
53
+ lastProjectSelectionRef,
54
+ toastMessage,
55
+ setToastMessage,
56
+ toastVisible,
57
+ setToastVisible,
58
+ updatedVersion,
59
+ setUpdatedVersion,
60
+ } = useAppCoreState()
61
+
62
+ const {
63
+ modalState,
64
+ setModalState,
65
+ modalInputValue,
66
+ setModalInputValue,
67
+ commandsCursor,
68
+ setCommandsCursor,
69
+ commandsSearchQuery,
70
+ setCommandsSearchQuery,
71
+ settingsCursor,
72
+ setSettingsCursor,
73
+ settingsSearchQuery,
74
+ setSettingsSearchQuery,
75
+ settingOptionsCursor,
76
+ setSettingOptionsCursor,
77
+ settingOptionsSearchQuery,
78
+ setSettingOptionsSearchQuery,
79
+ settingEditorValue,
80
+ setSettingEditorValue,
81
+ settingEditorError,
82
+ setSettingEditorError,
83
+ modalTextareaRef,
84
+ commandsSearchTextareaRef,
85
+ settingsSearchTextareaRef,
86
+ settingOptionsSearchTextareaRef,
87
+ settingEditorTextareaRef,
88
+ } = useAppModalState()
89
+
90
+ const { columns, rows } = useTerminalSize()
91
+ const configPath = getConfigPath()
92
+ const resolvedTheme = resolveTheme(config?.theme, config?.themes, config?.colorScheme)
93
+ const theme = resolvedTheme.colors
94
+ const { filteredSettingsEntries, filteredSettingOptions } = getSettingsState(
95
+ config,
96
+ modalState,
97
+ settingsSearchQuery,
98
+ settingOptionsSearchQuery
99
+ )
100
+ const hasScheduledAutoUpdateRef = useRef(false)
101
+
102
+ useAppStartup(
103
+ measure,
104
+ lastSessionSelectionRef,
105
+ lastProjectSelectionRef,
106
+ mark,
107
+ setConfig,
108
+ setAppMode,
109
+ setViewMode,
110
+ setSessionItems,
111
+ setProjectSourceItems,
112
+ setAllItems,
113
+ setItems,
114
+ setCursor
115
+ )
116
+
117
+ useAutoUpdateScheduler(config, hasScheduledAutoUpdateRef)
118
+
119
+ const { showMessage, refreshItems, loadOpencodeStatsForSession } = createAppRuntime({
120
+ config,
121
+ viewMode,
122
+ measure,
123
+ lastSessionSelectionRef,
124
+ lastProjectSelectionRef,
125
+ setSessionItems,
126
+ setProjectSourceItems,
127
+ setAllItems,
128
+ setItems,
129
+ setCursor,
130
+ setMessage,
131
+ getOpencodeSessionStats,
132
+ })
133
+
134
+ const {
135
+ regularSessions,
136
+ opencodeSessions,
137
+ selectedOpencodeSessionName,
138
+ selectedPrimaryItem,
139
+ filteredCommandEntries,
140
+ } = getSessionCommandState(
141
+ appMode,
142
+ viewMode,
143
+ items,
144
+ cursor,
145
+ opencodeCursor,
146
+ config,
147
+ commandsSearchQuery
148
+ )
149
+
150
+ const {
151
+ clearPendingKill,
152
+ requestKillSession,
153
+ openRenameModal,
154
+ openCommandsModal,
155
+ openSettingsModal,
156
+ openSettingOptions,
157
+ openSettingEditor,
158
+ closeModal,
159
+ } = createAppControls({
160
+ config,
161
+ pendingKillSessionName,
162
+ handleKillSession: sessionName =>
163
+ handleKillSessionWithFeedback(sessionName, {
164
+ config,
165
+ items,
166
+ sessionItems,
167
+ cursor,
168
+ showMessage,
169
+ refreshItems,
170
+ setPendingKillSessionName,
171
+ }),
172
+ setPendingKillSessionName,
173
+ setRenameTarget,
174
+ setModalInputValue,
175
+ setModalState,
176
+ setCommandsSearchQuery,
177
+ setCommandsCursor,
178
+ setSettingEditorError,
179
+ setSettingsSearchQuery,
180
+ setSettingsCursor,
181
+ setSettingOptionsSearchQuery,
182
+ setSettingOptionsCursor,
183
+ setSettingEditorValue,
184
+ })
185
+
186
+ const {
187
+ handleKillSessionWrapper,
188
+ handleSelectWrapper,
189
+ handleLastSessionWrapper,
190
+ handleRootSessionWrapper,
191
+ handleEditTargetWrapper,
192
+ handleRenameSubmit,
193
+ handleNewSessionSubmit,
194
+ handleSettingsEditorSubmit,
195
+ handleSettingOptionSubmit,
196
+ executeCommand,
197
+ } = createAppHandlers({
198
+ appMode,
199
+ viewMode,
200
+ config,
201
+ items,
202
+ sessionItems,
203
+ cursor,
204
+ showMessage,
205
+ refreshItems,
206
+ opencodeCursor,
207
+ regularSessions,
208
+ opencodeSessions,
209
+ selectedPrimaryItem,
210
+ sessionCandidateItems,
211
+ projectSourceItems,
212
+ closeModal,
213
+ openRenameModal,
214
+ openSettingsModal,
215
+ requestKillSession,
216
+ setAppMode,
217
+ setViewMode,
218
+ setAllItems,
219
+ setItems,
220
+ setCursor,
221
+ setSearchQuery,
222
+ setOpencodeCursor,
223
+ setPendingKillSessionName,
224
+ saveConfig,
225
+ setConfig,
226
+ setSettingEditorError,
227
+ settingEditorValue,
228
+ settingEditorPlainText: settingEditorTextareaRef.current?.plainText,
229
+ renameTarget,
230
+ renamedValue: (modalTextareaRef.current?.plainText ?? modalInputValue).trim(),
231
+ searchTerm: searchQuery.trim(),
232
+ loadOpencodeStatsForSession,
233
+ })
234
+
235
+ useAppKeyboard({
236
+ appMode,
237
+ viewMode,
238
+ config,
239
+ items,
240
+ regularSessions,
241
+ opencodeSessions,
242
+ sessionItems,
243
+ sessionCandidateItems,
244
+ projectSourceItems,
245
+ cursor,
246
+ opencodeCursor,
247
+ searchQuery,
248
+ prefixActive,
249
+ prefixTimeoutRef,
250
+ modalState,
251
+ filteredCommandEntries,
252
+ commandsCursor,
253
+ setCommandsCursor,
254
+ filteredSettingsEntries,
255
+ settingsCursor,
256
+ setSettingsCursor,
257
+ filteredSettingOptions,
258
+ settingOptionsCursor,
259
+ setSettingOptionsCursor,
260
+ setModalState,
261
+ setSettingEditorError,
262
+ executeCommand,
263
+ handleSettingOptionSubmit,
264
+ handleSettingsEditorSubmit,
265
+ handleRenameSubmit,
266
+ handleNewSessionSubmit,
267
+ isOptionSetting,
268
+ openSettingOptions,
269
+ openSettingEditor,
270
+ closeModal,
271
+ clearPendingKill,
272
+ requestKillSession,
273
+ openRenameModal,
274
+ openCommandsModal,
275
+ openSettingsModal,
276
+ refreshItems,
277
+ handleSelect: handleSelectWrapper,
278
+ handleKillSession: handleKillSessionWrapper,
279
+ handleLastSession: handleLastSessionWrapper,
280
+ handleRootSession: handleRootSessionWrapper,
281
+ handleEditTarget: handleEditTargetWrapper,
282
+ loadOpencodeStatsForSession,
283
+ setAppMode,
284
+ setViewMode,
285
+ setCursor,
286
+ setOpencodeCursor,
287
+ setSearchQuery,
288
+ setAllItems,
289
+ setItems,
290
+ setPrefixActive,
291
+ setMessage,
292
+ })
293
+
294
+ useAppBehaviors({
295
+ appMode,
296
+ viewMode,
297
+ config,
298
+ sessionItems,
299
+ projectSourceItems,
300
+ sessionCandidateItems,
301
+ lastSessionSelectionRef,
302
+ lastProjectSelectionRef,
303
+ setAllItems,
304
+ setItems,
305
+ setCursor,
306
+ setSessionCandidateItems,
307
+ filteredCommandEntriesLength: filteredCommandEntries.length,
308
+ setCommandsCursor,
309
+ commandsSearchQuery,
310
+ filteredSettingsEntriesLength: filteredSettingsEntries.length,
311
+ setSettingsCursor,
312
+ filteredSettingOptionsLength: filteredSettingOptions.length,
313
+ setSettingOptionsCursor,
314
+ cursor,
315
+ items,
316
+ selectedPrimaryItem,
317
+ pendingKillSessionName,
318
+ opencodeSessions,
319
+ opencodeCursor,
320
+ regularSessions,
321
+ setPendingKillSessionName,
322
+ searchQuery,
323
+ allItems,
324
+ selectedOpencodeSessionName,
325
+ loadOpencodeStatsForSession,
326
+ setUpdatedVersion,
327
+ setToastMessage,
328
+ setToastVisible,
329
+ })
330
+
331
+ return {
332
+ theme,
333
+ resolvedTheme,
334
+ columns,
335
+ rows,
336
+ screenProps: {
337
+ theme,
338
+ appMode,
339
+ viewMode,
340
+ config,
341
+ items,
342
+ regularSessions,
343
+ opencodeSessions,
344
+ selectedPrimaryItem,
345
+ cursor,
346
+ opencodeCursor,
347
+ searchQuery,
348
+ prefixActive,
349
+ pendingKillSessionName,
350
+ projectCount: projectSourceItems.length,
351
+ sessionItems,
352
+ rows,
353
+ columns,
354
+ textareaRef,
355
+ setSearchQuery,
356
+ message,
357
+ toastMessage,
358
+ toastVisible,
359
+ updatedVersion,
360
+ },
361
+ modalProps: {
362
+ modalState,
363
+ columns,
364
+ rows,
365
+ configPath,
366
+ themeId: resolvedTheme.id,
367
+ themeName: resolvedTheme.name,
368
+ colorMode: resolvedTheme.mode,
369
+ filteredCommandEntries,
370
+ commandsCursor,
371
+ commandsSearchQuery,
372
+ setCommandsCursor,
373
+ setCommandsSearchQuery,
374
+ filteredSettingsEntries,
375
+ settingsCursor,
376
+ settingsSearchQuery,
377
+ setSettingsCursor,
378
+ setSettingsSearchQuery,
379
+ filteredSettingOptions,
380
+ settingOptionsCursor,
381
+ settingOptionsSearchQuery,
382
+ setSettingOptionsCursor,
383
+ setSettingOptionsSearchQuery,
384
+ settingEditorValue,
385
+ settingEditorError,
386
+ setSettingEditorValue,
387
+ modalInputValue,
388
+ setModalInputValue,
389
+ commandsSearchTextareaRef,
390
+ settingsSearchTextareaRef,
391
+ settingOptionsSearchTextareaRef,
392
+ settingEditorTextareaRef,
393
+ modalTextareaRef,
394
+ getSettingEditorTitle,
395
+ },
396
+ }
397
+ }
@@ -0,0 +1,121 @@
1
+ import type { Dispatch, SetStateAction } from 'react'
2
+ import {
3
+ closeModal as resetModalState,
4
+ openCommandsModal as showCommandsModal,
5
+ openRenameModal as showRenameModal,
6
+ openSettingEditor as showSettingEditor,
7
+ openSettingOptions as showSettingOptions,
8
+ openSettingsModal as showSettingsModal,
9
+ type ModalState,
10
+ } from './modals'
11
+ import type { Config } from '../types'
12
+ import type { SettingsFieldId } from '../settings'
13
+
14
+ interface AppControlsOptions {
15
+ config: Config | null
16
+ pendingKillSessionName: string | null
17
+ handleKillSession: (sessionName: string) => Promise<void>
18
+ setPendingKillSessionName: Dispatch<SetStateAction<string | null>>
19
+ setRenameTarget: Dispatch<SetStateAction<string>>
20
+ setModalInputValue: Dispatch<SetStateAction<string>>
21
+ setModalState: Dispatch<SetStateAction<ModalState>>
22
+ setCommandsSearchQuery: Dispatch<SetStateAction<string>>
23
+ setCommandsCursor: Dispatch<SetStateAction<number>>
24
+ setSettingEditorError: Dispatch<SetStateAction<string>>
25
+ setSettingsSearchQuery: Dispatch<SetStateAction<string>>
26
+ setSettingsCursor: Dispatch<SetStateAction<number>>
27
+ setSettingOptionsSearchQuery: Dispatch<SetStateAction<string>>
28
+ setSettingOptionsCursor: Dispatch<SetStateAction<number>>
29
+ setSettingEditorValue: Dispatch<SetStateAction<string>>
30
+ }
31
+
32
+ export function createAppControls(options: AppControlsOptions) {
33
+ function clearPendingKill() {
34
+ options.setPendingKillSessionName(null)
35
+ }
36
+
37
+ function requestKillSession(sessionName: string) {
38
+ if (options.pendingKillSessionName === sessionName) {
39
+ void options.handleKillSession(sessionName)
40
+ return
41
+ }
42
+
43
+ options.setPendingKillSessionName(sessionName)
44
+ }
45
+
46
+ function openRenameModal(sessionName: string) {
47
+ showRenameModal(
48
+ sessionName,
49
+ clearPendingKill,
50
+ options.setRenameTarget,
51
+ options.setModalInputValue,
52
+ options.setModalState
53
+ )
54
+ }
55
+
56
+ function openCommandsModal() {
57
+ showCommandsModal(
58
+ clearPendingKill,
59
+ options.setCommandsSearchQuery,
60
+ options.setCommandsCursor,
61
+ options.setModalState
62
+ )
63
+ }
64
+
65
+ function openSettingsModal() {
66
+ showSettingsModal(
67
+ options.config,
68
+ clearPendingKill,
69
+ options.setSettingEditorError,
70
+ options.setSettingsSearchQuery,
71
+ options.setSettingsCursor,
72
+ options.setModalState
73
+ )
74
+ }
75
+
76
+ function openSettingOptions(field: SettingsFieldId) {
77
+ showSettingOptions(
78
+ field,
79
+ options.setSettingOptionsSearchQuery,
80
+ options.setSettingOptionsCursor,
81
+ options.setModalState
82
+ )
83
+ }
84
+
85
+ function openSettingEditor(field: SettingsFieldId) {
86
+ showSettingEditor(
87
+ options.config,
88
+ field,
89
+ options.setSettingEditorError,
90
+ options.setSettingEditorValue,
91
+ options.setModalState
92
+ )
93
+ }
94
+
95
+ function closeModal() {
96
+ resetModalState({
97
+ setModalState: options.setModalState,
98
+ setModalInputValue: options.setModalInputValue,
99
+ setCommandsSearchQuery: options.setCommandsSearchQuery,
100
+ setCommandsCursor: options.setCommandsCursor,
101
+ setSettingsSearchQuery: options.setSettingsSearchQuery,
102
+ setSettingsCursor: options.setSettingsCursor,
103
+ setSettingOptionsSearchQuery: options.setSettingOptionsSearchQuery,
104
+ setSettingOptionsCursor: options.setSettingOptionsCursor,
105
+ setSettingEditorValue: options.setSettingEditorValue,
106
+ setSettingEditorError: options.setSettingEditorError,
107
+ setRenameTarget: options.setRenameTarget,
108
+ })
109
+ }
110
+
111
+ return {
112
+ clearPendingKill,
113
+ requestKillSession,
114
+ openRenameModal,
115
+ openCommandsModal,
116
+ openSettingsModal,
117
+ openSettingOptions,
118
+ openSettingEditor,
119
+ closeModal,
120
+ }
121
+ }
@@ -0,0 +1,71 @@
1
+ import type { TextareaRenderable } from '@opentui/core'
2
+ import { useRef, useState } from 'react'
3
+ import { AppMode, ViewMode, type Config, type Item } from '../types'
4
+
5
+ export function useAppCoreState() {
6
+ const [appMode, setAppMode] = useState(AppMode.Normal)
7
+ const [viewMode, setViewMode] = useState(ViewMode.Sessions)
8
+ const [items, setItems] = useState<Item[]>([])
9
+ const [allItems, setAllItems] = useState<Item[]>([])
10
+ const [projectSourceItems, setProjectSourceItems] = useState<Item[]>([])
11
+ const [sessionCandidateItems, setSessionCandidateItems] = useState<Item[]>([])
12
+ const [sessionItems, setSessionItems] = useState<Item[]>([])
13
+ const [cursor, setCursor] = useState(0)
14
+ const [opencodeCursor, setOpencodeCursor] = useState(0)
15
+ const [searchQuery, setSearchQuery] = useState('')
16
+ const [message, setMessage] = useState('')
17
+ const [renameTarget, setRenameTarget] = useState('')
18
+ const [config, setConfig] = useState<Config | null>(null)
19
+ const [pendingKillSessionName, setPendingKillSessionName] = useState<string | null>(null)
20
+ const [prefixActive, setPrefixActive] = useState(false)
21
+ const prefixTimeoutRef = useRef<NodeJS.Timeout | null>(null)
22
+ const textareaRef = useRef<TextareaRenderable | null>(null)
23
+ const lastSessionSelectionRef = useRef<string | null>(null)
24
+ const lastProjectSelectionRef = useRef<string | null>(null)
25
+ const [toastMessage, setToastMessage] = useState('')
26
+ const [toastVisible, setToastVisible] = useState(false)
27
+ const [updatedVersion, setUpdatedVersion] = useState<string | null>(null)
28
+
29
+ return {
30
+ appMode,
31
+ setAppMode,
32
+ viewMode,
33
+ setViewMode,
34
+ items,
35
+ setItems,
36
+ allItems,
37
+ setAllItems,
38
+ projectSourceItems,
39
+ setProjectSourceItems,
40
+ sessionCandidateItems,
41
+ setSessionCandidateItems,
42
+ sessionItems,
43
+ setSessionItems,
44
+ cursor,
45
+ setCursor,
46
+ opencodeCursor,
47
+ setOpencodeCursor,
48
+ searchQuery,
49
+ setSearchQuery,
50
+ message,
51
+ setMessage,
52
+ renameTarget,
53
+ setRenameTarget,
54
+ config,
55
+ setConfig,
56
+ pendingKillSessionName,
57
+ setPendingKillSessionName,
58
+ prefixActive,
59
+ setPrefixActive,
60
+ prefixTimeoutRef,
61
+ textareaRef,
62
+ lastSessionSelectionRef,
63
+ lastProjectSelectionRef,
64
+ toastMessage,
65
+ setToastMessage,
66
+ toastVisible,
67
+ setToastVisible,
68
+ updatedVersion,
69
+ setUpdatedVersion,
70
+ }
71
+ }
@@ -0,0 +1,90 @@
1
+ import { getListedSessionItems, mergeSessionItems } from '../config/listed-sessions'
2
+ import { orderProjectItems, orderSessionItems } from '../items/order'
3
+ import { annotateProjectItemsWithSessionLinks } from '../projects/session-links'
4
+ import { clearMatchIndices } from '../search'
5
+ import { listTmuxSessions } from '../tmux'
6
+ import { getProjectItems, getSessionCandidateItems } from '../tmux/projects'
7
+ import { filterHiddenSessions } from '../tmux/workflows'
8
+ import type { Config, Item } from '../types'
9
+
10
+ export type Measure = <T>(name: string, fn: () => Promise<T>) => Promise<T>
11
+
12
+ export function getSessionSelectionIndex(nextItems: Item[], selection?: string | null): number {
13
+ const regularItems = nextItems.filter(
14
+ item => !(item.isSession && item.title.startsWith('opencode-'))
15
+ )
16
+ if (regularItems.length === 0 || !selection) {
17
+ return 0
18
+ }
19
+
20
+ const index = regularItems.findIndex(item => item.title === selection)
21
+ return index >= 0 ? index : 0
22
+ }
23
+
24
+ export function getProjectSelectionIndex(nextItems: Item[], selection?: string | null): number {
25
+ if (nextItems.length === 0 || !selection) {
26
+ return 0
27
+ }
28
+
29
+ const index = nextItems.findIndex(item => item.path === selection)
30
+ return index >= 0 ? index : 0
31
+ }
32
+
33
+ export async function loadSessionItems(
34
+ config: Config,
35
+ measure: Measure,
36
+ labelPrefix = 'sessions'
37
+ ): Promise<{ visibleSessions: Item[]; sessionItems: Item[] }> {
38
+ const sessions = await measure(`${labelPrefix}:listTmuxSessions`, listTmuxSessions)
39
+ const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
40
+ const listedSessions = await measure(`${labelPrefix}:getListedSessionItems`, () =>
41
+ getListedSessionItems(config)
42
+ )
43
+ const sessionItems = clearMatchIndices(
44
+ orderSessionItems(mergeSessionItems(visibleSessions, listedSessions), config.sortOrder)
45
+ )
46
+
47
+ return {
48
+ visibleSessions,
49
+ sessionItems,
50
+ }
51
+ }
52
+
53
+ export async function loadProjectItemsWithLinks(
54
+ config: Config,
55
+ liveSessions: Item[],
56
+ measure: Measure,
57
+ sourceItems?: Item[]
58
+ ): Promise<{ projectSourceItems: Item[]; projectItems: Item[] }> {
59
+ const projectSourceItems =
60
+ sourceItems ??
61
+ orderProjectItems(
62
+ await measure('projects:getProjectItems', () => getProjectItems(config)),
63
+ config.sortOrder
64
+ )
65
+
66
+ const projectItems = clearMatchIndices(
67
+ orderProjectItems(
68
+ await measure('projects:linkProjectItems', () =>
69
+ annotateProjectItemsWithSessionLinks(projectSourceItems, liveSessions, config)
70
+ ),
71
+ config.sortOrder
72
+ )
73
+ )
74
+
75
+ return {
76
+ projectSourceItems,
77
+ projectItems,
78
+ }
79
+ }
80
+
81
+ export async function loadSessionCandidateItems(config: Config, measure: Measure): Promise<Item[]> {
82
+ const [candidates, sessions] = await measure('loadSessionCandidateItems', () =>
83
+ Promise.all([getSessionCandidateItems(config), listTmuxSessions()])
84
+ )
85
+
86
+ const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
87
+ return measure('linkSessionCandidateItems', () =>
88
+ annotateProjectItemsWithSessionLinks(candidates, visibleSessions, config)
89
+ )
90
+ }