mux-sesh 1.5.0 → 1.6.1

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/src/app.tsx CHANGED
@@ -2,7 +2,7 @@ import type { TextareaRenderable } from '@opentui/core'
2
2
  import { useKeyboard } from '@opentui/react'
3
3
  import { useState, useEffect, useRef } from 'react'
4
4
  import { AppMode, ViewMode, type Item, type Config, type OpencodeStatsState } from './types'
5
- import { loadConfig } from './config'
5
+ import { getConfigPath, loadConfig, saveConfig } from './config'
6
6
  import { getListedSessionItems, mergeSessionItems } from './config/listed-sessions'
7
7
  import { orderProjectItems, orderSessionItems } from './items/order'
8
8
  import { annotateProjectItemsWithSessionLinks } from './projects/session-links'
@@ -12,26 +12,41 @@ import { getProjectItems } from './tmux/projects'
12
12
  import { filterAndSortItems, clearMatchIndices } from './search'
13
13
  import { isGitHubURL } from './util/github'
14
14
  import { getOpencodeSessionStats } from './opencode'
15
- import { formatSessionAge } from './util/time'
16
- import { colors, sessionListStyle, sessionListStyleFull } from './styles/theme'
15
+ import { ThemeProvider, getPanelStyle, resolveTheme } from './styles/theme'
17
16
  import { useTerminalSize, shouldShowDetailPanel } from './util/terminal'
18
17
  import Toast from './ui/Toast'
19
18
  import { checkAndUpdate, updateEvents } from './update'
20
- import KeybindHelp from './components/KeybindHelp'
19
+ import { CURRENT_VERSION } from './update/version'
21
20
  import OpencodeStatsPanel from './ui/OpencodeStatsPanel'
22
21
  import SessionDetailsPanel from './ui/SessionDetailsPanel'
23
22
  import SessionList from './ui/SessionList'
24
23
  import OpencodeSessionGroup from './ui/OpencodeSessionGroup'
25
24
  import SearchInput from './ui/SearchInput'
26
- import SessionStats from './ui/SessionStats'
27
25
  import ItemList from './ui/ItemList'
26
+ import VersionBadge from './ui/VersionBadge'
27
+ import RenameModal from './ui/RenameModal'
28
+ import CommandsModal, { filterCommandEntries, getCommandEntries, type CommandId } from './ui/CommandsModal'
29
+ import SettingsModal from './ui/SettingsModal'
30
+ import SettingOptionsModal from './ui/SettingOptionsModal'
31
+ import SettingEditorModal from './ui/SettingEditorModal'
32
+ import {
33
+ applyEditorSetting,
34
+ applyOptionSetting,
35
+ filterSettingsEntries,
36
+ filterSettingsOptions,
37
+ getSettingEditorTitle,
38
+ getSettingEditorValue,
39
+ getSettingsEntries,
40
+ getSettingOptions,
41
+ isOptionSetting,
42
+ type SettingsFieldId,
43
+ } from './settings'
28
44
  import {
29
45
  type KeyboardHandlerContext,
30
46
  handleNormalMode,
31
47
  handleOpencodeManageMode,
32
48
  handleSearchMode,
33
49
  handleNewSessionMode,
34
- handleRenameMode,
35
50
  } from './handlers/keyboard'
36
51
  import {
37
52
  handleSelect as actionHandleSelect,
@@ -43,6 +58,14 @@ import {
43
58
  handleEditTarget as actionHandleEditTarget,
44
59
  } from './handlers/actions'
45
60
 
61
+ type ModalState =
62
+ | { type: 'rename'; target: string }
63
+ | { type: 'commands' }
64
+ | { type: 'settings' }
65
+ | { type: 'setting-options'; field: SettingsFieldId }
66
+ | { type: 'setting-editor'; field: SettingsFieldId }
67
+ | null
68
+
46
69
  export function App() {
47
70
  const [appMode, setAppMode] = useState(AppMode.Normal)
48
71
  const [viewMode, setViewMode] = useState(ViewMode.Sessions)
@@ -56,14 +79,40 @@ export function App() {
56
79
  const [message, setMessage] = useState('')
57
80
  const [renameTarget, setRenameTarget] = useState('')
58
81
  const [config, setConfig] = useState<Config | null>(null)
82
+ const [modalState, setModalState] = useState<ModalState>(null)
83
+ const [modalInputValue, setModalInputValue] = useState('')
84
+ const [commandsCursor, setCommandsCursor] = useState(0)
85
+ const [commandsSearchQuery, setCommandsSearchQuery] = useState('')
86
+ const [settingsCursor, setSettingsCursor] = useState(0)
87
+ const [settingsSearchQuery, setSettingsSearchQuery] = useState('')
88
+ const [settingOptionsCursor, setSettingOptionsCursor] = useState(0)
89
+ const [settingOptionsSearchQuery, setSettingOptionsSearchQuery] = useState('')
90
+ const [settingEditorValue, setSettingEditorValue] = useState('')
91
+ const [settingEditorError, setSettingEditorError] = useState('')
92
+ const [pendingKillSessionName, setPendingKillSessionName] = useState<string | null>(null)
59
93
  const [prefixActive, setPrefixActive] = useState(false)
60
94
  const prefixTimeoutRef = useRef<NodeJS.Timeout | null>(null)
61
95
  const textareaRef = useRef<TextareaRenderable | null>(null)
96
+ const modalTextareaRef = useRef<TextareaRenderable | null>(null)
97
+ const commandsSearchTextareaRef = useRef<TextareaRenderable | null>(null)
98
+ const settingsSearchTextareaRef = useRef<TextareaRenderable | null>(null)
99
+ const settingOptionsSearchTextareaRef = useRef<TextareaRenderable | null>(null)
100
+ const settingEditorTextareaRef = useRef<TextareaRenderable | null>(null)
62
101
  const lastSessionSelectionRef = useRef<string | null>(null)
63
102
  const lastProjectSelectionRef = useRef<string | null>(null)
64
103
  const { columns, rows } = useTerminalSize()
65
104
  const [toastMessage, setToastMessage] = useState('')
66
105
  const [toastVisible, setToastVisible] = useState(false)
106
+ const [updatedVersion, setUpdatedVersion] = useState<string | null>(null)
107
+ const configPath = getConfigPath()
108
+ const resolvedTheme = resolveTheme(config?.theme, config?.themes, config?.colorScheme)
109
+ const theme = resolvedTheme.colors
110
+ const settingsEntries = config ? getSettingsEntries(config) : []
111
+ const filteredSettingsEntries = filterSettingsEntries(settingsEntries, settingsSearchQuery)
112
+ const currentOptionField = modalState?.type === 'setting-options' ? modalState.field : undefined
113
+ const settingOptions = config && currentOptionField ? getSettingOptions(config, currentOptionField) : []
114
+ const filteredSettingOptions = filterSettingsOptions(settingOptions, settingOptionsSearchQuery)
115
+ const hasScheduledAutoUpdateRef = useRef(false)
67
116
 
68
117
  function getSessionSelectionIndex(nextItems: Item[]): number {
69
118
  const regularItems = nextItems.filter(item => !(item.isSession && item.title.startsWith('opencode-')))
@@ -115,16 +164,9 @@ export function App() {
115
164
  setAppMode(AppMode.Search)
116
165
  }
117
166
 
118
- const sessions = await listTmuxSessions()
167
+ const [sessions, listedSessions] = await Promise.all([listTmuxSessions(), getListedSessionItems(cfg)])
119
168
  const visibleSessions = filterHiddenSessions(sessions, cfg.hiddenSessions)
120
- const listedSessions = await getListedSessionItems(cfg)
121
169
  const combinedSessions = orderSessionItems(mergeSessionItems(visibleSessions, listedSessions), cfg.sortOrder)
122
- const projects = orderProjectItems(
123
- await annotateProjectItemsWithSessionLinks(await getProjectItems(cfg), visibleSessions, cfg),
124
- cfg.sortOrder
125
- )
126
-
127
- setProjectItems(projects)
128
170
 
129
171
  if (combinedSessions.length > 0) {
130
172
  setViewMode(ViewMode.Sessions)
@@ -132,34 +174,56 @@ export function App() {
132
174
  setAllItems(combinedSessions)
133
175
  setItems(combinedSessions)
134
176
  setCursor(getSessionSelectionIndex(combinedSessions))
135
- } else {
177
+ }
178
+
179
+ const rawProjects = await getProjectItems(cfg)
180
+ const projects = orderProjectItems(
181
+ await annotateProjectItemsWithSessionLinks(rawProjects, visibleSessions, cfg),
182
+ cfg.sortOrder
183
+ )
184
+
185
+ setProjectItems(projects)
186
+
187
+ if (combinedSessions.length === 0) {
136
188
  setViewMode(ViewMode.Projects)
137
189
  setAllItems(projects)
138
190
  setItems(projects)
139
191
  setCursor(getProjectSelectionIndex(projects))
140
192
  }
141
- checkAndUpdate(cfg).catch(error => {
142
- console.error('Auto-update check failed:', error)
143
- })
144
193
  }
145
194
  init()
146
195
  }, [])
147
196
 
148
- async function refreshItems(forceViewMode?: ViewMode) {
149
- if (!config) return
197
+ useEffect(() => {
198
+ if (!config || hasScheduledAutoUpdateRef.current) {
199
+ return
200
+ }
201
+
202
+ hasScheduledAutoUpdateRef.current = true
203
+
204
+ const timeout = setTimeout(() => {
205
+ checkAndUpdate(config).catch(error => {
206
+ console.error('Auto-update check failed:', error)
207
+ })
208
+ }, 1000)
209
+
210
+ return () => clearTimeout(timeout)
211
+ }, [config])
212
+ async function refreshItems(forceViewMode?: ViewMode, nextConfig = config) {
213
+ if (!nextConfig) return
150
214
 
151
215
  const targetMode = forceViewMode ?? viewMode
152
216
 
153
217
  if (targetMode === ViewMode.Sessions) {
154
218
  const sessions = await listTmuxSessions()
155
- const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
156
- const listedSessions = await getListedSessionItems(config)
219
+ const visibleSessions = filterHiddenSessions(sessions, nextConfig.hiddenSessions)
220
+ const listedSessions = await getListedSessionItems(nextConfig)
157
221
  const cleanSessions = clearMatchIndices(
158
- orderSessionItems(mergeSessionItems(visibleSessions, listedSessions), config.sortOrder)
222
+ orderSessionItems(mergeSessionItems(visibleSessions, listedSessions), nextConfig.sortOrder)
159
223
  )
160
224
  const linkedProjects = orderProjectItems(
161
- await annotateProjectItemsWithSessionLinks(projectItems, visibleSessions, config),
162
- config.sortOrder
225
+ await annotateProjectItemsWithSessionLinks(projectItems, visibleSessions, nextConfig),
226
+ nextConfig.sortOrder
163
227
  )
164
228
  setSessionItems(cleanSessions)
165
229
  setProjectItems(linkedProjects)
@@ -168,10 +232,10 @@ export function App() {
168
232
  setCursor(getSessionSelectionIndex(cleanSessions))
169
233
  } else {
170
234
  const sessions = await listTmuxSessions()
171
- const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
235
+ const visibleSessions = filterHiddenSessions(sessions, nextConfig.hiddenSessions)
172
236
  const projects = orderProjectItems(
173
- await annotateProjectItemsWithSessionLinks(await getProjectItems(config), visibleSessions, config),
174
- config.sortOrder
237
+ await annotateProjectItemsWithSessionLinks(await getProjectItems(nextConfig), visibleSessions, nextConfig),
238
+ nextConfig.sortOrder
175
239
  )
176
240
  const cleanProjects = clearMatchIndices(projects)
177
241
  setProjectItems(cleanProjects)
@@ -221,8 +285,12 @@ export function App() {
221
285
  appMode === AppMode.OpencodeManage ? opencodeSessions[opencodeCursor]?.title : undefined
222
286
  const selectedPrimaryItem =
223
287
  viewMode === ViewMode.Sessions && appMode === AppMode.Normal ? regularSessions[cursor] : items[cursor]
288
+ const commandEntries = getCommandEntries(appMode, config?.keybindMode, config?.prefixKey, selectedPrimaryItem)
289
+ const filteredCommandEntries = filterCommandEntries(commandEntries, commandsSearchQuery)
224
290
 
225
291
  async function handleKillSessionWrapper(sessionName: string) {
292
+ setPendingKillSessionName(null)
293
+
226
294
  await actionKillSession(sessionName, {
227
295
  onSuccess: msg => {
228
296
  setMessage(msg)
@@ -270,8 +338,75 @@ export function App() {
270
338
  }
271
339
  }
272
340
 
341
+ function clearPendingKill() {
342
+ setPendingKillSessionName(null)
343
+ }
344
+
345
+ function requestKillSession(sessionName: string) {
346
+ if (pendingKillSessionName === sessionName) {
347
+ void handleKillSessionWrapper(sessionName)
348
+ return
349
+ }
350
+
351
+ setPendingKillSessionName(sessionName)
352
+ }
353
+
354
+ function openRenameModal(sessionName: string) {
355
+ clearPendingKill()
356
+ setRenameTarget(sessionName)
357
+ setModalInputValue(sessionName)
358
+ setModalState({ type: 'rename', target: sessionName })
359
+ }
360
+
361
+ function openCommandsModal() {
362
+ clearPendingKill()
363
+ setCommandsSearchQuery('')
364
+ setCommandsCursor(0)
365
+ setModalState({ type: 'commands' })
366
+ }
367
+
368
+ function openSettingsModal() {
369
+ if (!config) {
370
+ return
371
+ }
372
+
373
+ clearPendingKill()
374
+ setSettingEditorError('')
375
+ setSettingsSearchQuery('')
376
+ setSettingsCursor(0)
377
+ setModalState({ type: 'settings' })
378
+ }
379
+
380
+ function openSettingOptions(field: SettingsFieldId) {
381
+ setSettingOptionsSearchQuery('')
382
+ setSettingOptionsCursor(0)
383
+ setModalState({ type: 'setting-options', field })
384
+ }
385
+
386
+ function openSettingEditor(field: SettingsFieldId) {
387
+ if (!config) {
388
+ return
389
+ }
390
+
391
+ setSettingEditorError('')
392
+ setSettingEditorValue(getSettingEditorValue(config, field))
393
+ setModalState({ type: 'setting-editor', field })
394
+ }
395
+
396
+ function closeModal() {
397
+ setModalState(null)
398
+ setModalInputValue('')
399
+ setCommandsSearchQuery('')
400
+ setCommandsCursor(0)
401
+ setSettingsSearchQuery('')
402
+ setSettingOptionsSearchQuery('')
403
+ setSettingEditorValue('')
404
+ setSettingEditorError('')
405
+ setRenameTarget('')
406
+ }
407
+
273
408
  async function handleRenameSubmit() {
274
- const newName = searchQuery.trim()
409
+ const newName = (modalTextareaRef.current?.plainText ?? modalInputValue).trim()
275
410
  if (newName && newName !== renameTarget) {
276
411
  await actionRenameSubmit(renameTarget, newName, {
277
412
  onSuccess: msg => {
@@ -285,9 +420,8 @@ export function App() {
285
420
  refreshItems,
286
421
  })
287
422
  }
288
- setAppMode(AppMode.Normal)
289
- setSearchQuery('')
290
- setRenameTarget('')
423
+
424
+ closeModal()
291
425
  }
292
426
 
293
427
  async function handleNewSessionSubmit() {
@@ -303,6 +437,120 @@ export function App() {
303
437
  }
304
438
  }
305
439
 
440
+ async function executeCommand(commandID: CommandId) {
441
+ switch (commandID) {
442
+ case 'search':
443
+ closeModal()
444
+ setAppMode(AppMode.Search)
445
+ setSearchQuery('')
446
+ return
447
+ case 'new-session':
448
+ closeModal()
449
+ setAppMode(AppMode.NewSession)
450
+ setViewMode(ViewMode.Projects)
451
+ setAllItems(projectItems)
452
+ setItems(projectItems)
453
+ setCursor(Math.max(0, projectItems.length - 1))
454
+ setSearchQuery('')
455
+ return
456
+ case 'open-settings':
457
+ openSettingsModal()
458
+ return
459
+ case 'view-projects':
460
+ closeModal()
461
+ setViewMode(ViewMode.Projects)
462
+ await refreshItems(ViewMode.Projects)
463
+ return
464
+ case 'view-sessions':
465
+ closeModal()
466
+ setViewMode(ViewMode.Sessions)
467
+ await refreshItems(ViewMode.Sessions)
468
+ return
469
+ case 'rename-session': {
470
+ const target =
471
+ appMode === AppMode.OpencodeManage ? opencodeSessions[opencodeCursor] : viewMode === ViewMode.Sessions ? regularSessions[cursor] : undefined
472
+ if (target?.isSession) {
473
+ openRenameModal(target.title)
474
+ }
475
+ return
476
+ }
477
+ case 'kill-session': {
478
+ const target =
479
+ appMode === AppMode.OpencodeManage ? opencodeSessions[opencodeCursor] : viewMode === ViewMode.Sessions ? regularSessions[cursor] : undefined
480
+ if (target?.isSession) {
481
+ closeModal()
482
+ requestKillSession(target.title)
483
+ }
484
+ return
485
+ }
486
+ case 'last-session':
487
+ closeModal()
488
+ await handleLastSessionWrapper()
489
+ return
490
+ case 'root-session':
491
+ closeModal()
492
+ await handleRootSessionWrapper(selectedPrimaryItem)
493
+ return
494
+ case 'edit-target':
495
+ closeModal()
496
+ await handleEditTargetWrapper(selectedPrimaryItem)
497
+ return
498
+ case 'open-opencode':
499
+ closeModal()
500
+ if (viewMode === ViewMode.Sessions && opencodeSessions.length > 0) {
501
+ setAppMode(AppMode.OpencodeManage)
502
+ setOpencodeCursor(0)
503
+ await loadOpencodeStatsForSession(opencodeSessions[0].title)
504
+ }
505
+ return
506
+ case 'refresh':
507
+ closeModal()
508
+ await refreshItems()
509
+ setMessage('Refreshed')
510
+ setTimeout(() => setMessage(''), 2000)
511
+ return
512
+ case 'back':
513
+ closeModal()
514
+ setAppMode(AppMode.Normal)
515
+ return
516
+ }
517
+ }
518
+
519
+ async function applyAndPersistConfig(nextConfig: Config, successMessage: string) {
520
+ await saveConfig(nextConfig)
521
+ setConfig(nextConfig)
522
+ await refreshItems(undefined, nextConfig)
523
+ setMessage(successMessage)
524
+ setTimeout(() => setMessage(''), 2000)
525
+ }
526
+
527
+ async function handleSettingsEditorSubmit(field: SettingsFieldId) {
528
+ if (!config) {
529
+ return
530
+ }
531
+
532
+ try {
533
+ const rawText = settingEditorTextareaRef.current?.plainText ?? settingEditorValue
534
+ const nextConfig = applyEditorSetting(config, field, rawText, process.env.HOME || '~')
535
+
536
+ setSettingEditorError('')
537
+ await applyAndPersistConfig(nextConfig, `${getSettingEditorTitle(field)} updated`)
538
+ openSettingsModal()
539
+ } catch (error) {
540
+ const errorMessage = error instanceof Error ? error.message : 'Failed to save settings'
541
+ setSettingEditorError(errorMessage)
542
+ }
543
+ }
544
+
545
+ async function handleSettingOptionSubmit(field: SettingsFieldId, value: string) {
546
+ if (!config) {
547
+ return
548
+ }
549
+
550
+ const nextConfig = applyOptionSetting(config, field, value)
551
+ await applyAndPersistConfig(nextConfig, `${getSettingEditorTitle(field)} updated`)
552
+ }
553
+
306
554
  const keyboardContext: KeyboardHandlerContext = {
307
555
  appMode,
308
556
  viewMode,
@@ -313,6 +561,7 @@ export function App() {
313
561
  opencodeCursor,
314
562
  searchQuery,
315
563
  renameTarget,
564
+ prefixKey: config?.prefixKey,
316
565
  projectItems,
317
566
  sessionItems,
318
567
  prefixActive,
@@ -328,33 +577,114 @@ export function App() {
328
577
  setItems,
329
578
  setPrefixActive,
330
579
  refreshItems,
580
+ requestKillSession,
581
+ clearPendingKill,
331
582
  handleSelect: handleSelectWrapper,
332
583
  handleKillSession: handleKillSessionWrapper,
333
584
  handleLastSession: handleLastSessionWrapper,
334
585
  handleRootSession: handleRootSessionWrapper,
335
586
  handleEditTarget: handleEditTargetWrapper,
587
+ openRenameModal,
588
+ openCommandsModal,
589
+ openSettingsModal,
336
590
  loadOpencodeStatsForSession,
337
591
  setMessage,
338
592
  }
339
593
 
340
594
  useKeyboard(key => {
341
595
  const keybindMode = config?.keybindMode || 'vim'
596
+
597
+ if (modalState?.type === 'rename') {
598
+ if (key.name === 'return') {
599
+ void handleRenameSubmit()
600
+ } else if (key.name === 'escape') {
601
+ closeModal()
602
+ }
603
+ return
604
+ }
605
+
606
+ if (modalState?.type === 'commands') {
607
+ if (key.name === 'escape' || key.name === 'q') {
608
+ closeModal()
609
+ } else if (key.name === 'down' || key.name === 'j') {
610
+ setCommandsCursor(current => Math.min(current + 1, filteredCommandEntries.length - 1))
611
+ } else if (key.name === 'up' || key.name === 'k') {
612
+ setCommandsCursor(current => Math.max(current - 1, 0))
613
+ } else if (key.name === 'return') {
614
+ const command = filteredCommandEntries[commandsCursor]
615
+ if (!command) {
616
+ return
617
+ }
618
+ void executeCommand(command.id)
619
+ }
620
+ return
621
+ }
622
+
623
+ if (modalState?.type === 'settings') {
624
+ if (key.name === 'escape') {
625
+ closeModal()
626
+ } else if (key.name === 'down' || key.name === 'j') {
627
+ setSettingsCursor(current => Math.min(current + 1, filteredSettingsEntries.length - 1))
628
+ } else if (key.name === 'up' || key.name === 'k') {
629
+ setSettingsCursor(current => Math.max(current - 1, 0))
630
+ } else if (key.name === 'return') {
631
+ const entry = filteredSettingsEntries[settingsCursor]
632
+ if (!entry) {
633
+ return
634
+ }
635
+
636
+ if (isOptionSetting(entry.id)) {
637
+ openSettingOptions(entry.id)
638
+ } else {
639
+ openSettingEditor(entry.id)
640
+ }
641
+ } else if (key.name === 'e') {
642
+ const entry = filteredSettingsEntries[settingsCursor]
643
+ if (!entry) return
644
+ if (isOptionSetting(entry.id)) {
645
+ openSettingOptions(entry.id)
646
+ } else {
647
+ openSettingEditor(entry.id)
648
+ }
649
+ }
650
+ return
651
+ }
652
+
653
+ if (modalState?.type === 'setting-options') {
654
+ if (key.name === 'escape') {
655
+ setModalState({ type: 'settings' })
656
+ } else if (key.name === 'down' || key.name === 'j') {
657
+ setSettingOptionsCursor(current => Math.min(current + 1, filteredSettingOptions.length - 1))
658
+ } else if (key.name === 'up' || key.name === 'k') {
659
+ setSettingOptionsCursor(current => Math.max(current - 1, 0))
660
+ } else if (key.name === 'return') {
661
+ const option = filteredSettingOptions[settingOptionsCursor]
662
+ if (!option) return
663
+ void handleSettingOptionSubmit(modalState.field, option.value)
664
+ }
665
+ return
666
+ }
667
+
668
+ if (modalState?.type === 'setting-editor') {
669
+ if (key.name === 'escape') {
670
+ setModalState({ type: 'settings' })
671
+ setSettingEditorError('')
672
+ } else if (key.name === 'return') {
673
+ void handleSettingsEditorSubmit(modalState.field)
674
+ }
675
+ return
676
+ }
677
+
342
678
  if (appMode === AppMode.Normal) {
343
679
  handleNormalMode(key, keyboardContext, keybindMode)
344
680
  } else if (appMode === AppMode.Search) {
345
681
  handleSearchMode(key, keyboardContext, keybindMode)
346
682
  } else if (appMode === AppMode.NewSession) {
347
683
  if (key.name === 'return') {
348
- handleNewSessionSubmit()
684
+ void handleNewSessionSubmit()
349
685
  } else {
350
686
  handleNewSessionMode(key, keyboardContext, keybindMode)
351
687
  }
352
- } else if (appMode === AppMode.Rename) {
353
- if (key.name === 'return') {
354
- handleRenameSubmit()
355
- } else {
356
- handleRenameMode(key, keyboardContext, keybindMode)
357
- }
358
688
  } else if (appMode === AppMode.OpencodeManage) {
359
689
  handleOpencodeManageMode(key, keyboardContext, keybindMode)
360
690
  }
@@ -362,7 +692,14 @@ export function App() {
362
692
 
363
693
  useEffect(() => {
364
694
  const unsubscribe = updateEvents.on(event => {
365
- setToastMessage(`v${event.version}`)
695
+ if (event.kind === 'updated') {
696
+ setUpdatedVersion(event.version)
697
+ setToastMessage(`Updated in background to v${event.version}. Restart mux-sesh to use it.`)
698
+ } else if (event.kind === 'available') {
699
+ setToastMessage(`Update available: v${event.version}`)
700
+ } else {
701
+ setToastMessage(`Background update to v${event.version} failed.`)
702
+ }
366
703
  setToastVisible(true)
367
704
  setTimeout(() => {
368
705
  setToastVisible(false)
@@ -393,6 +730,37 @@ export function App() {
393
730
  }
394
731
  }, [appMode, viewMode, projectItems])
395
732
 
733
+ useEffect(() => {
734
+ if (filteredCommandEntries.length === 0) {
735
+ setCommandsCursor(0)
736
+ return
737
+ }
738
+
739
+ setCommandsCursor(current => Math.min(current, filteredCommandEntries.length - 1))
740
+ }, [filteredCommandEntries.length])
741
+
742
+ useEffect(() => {
743
+ setCommandsCursor(0)
744
+ }, [commandsSearchQuery])
745
+
746
+ useEffect(() => {
747
+ if (filteredSettingsEntries.length === 0) {
748
+ setSettingsCursor(0)
749
+ return
750
+ }
751
+
752
+ setSettingsCursor(current => Math.min(current, filteredSettingsEntries.length - 1))
753
+ }, [filteredSettingsEntries.length])
754
+
755
+ useEffect(() => {
756
+ if (filteredSettingOptions.length === 0) {
757
+ setSettingOptionsCursor(0)
758
+ return
759
+ }
760
+
761
+ setSettingOptionsCursor(current => Math.min(current, filteredSettingOptions.length - 1))
762
+ }, [filteredSettingOptions.length])
763
+
396
764
  useEffect(() => {
397
765
  const selectedItem = appMode === AppMode.NewSession ? items[cursor] : selectedPrimaryItem
398
766
 
@@ -412,6 +780,23 @@ export function App() {
412
780
  }
413
781
  }, [appMode, viewMode, cursor, items, selectedPrimaryItem])
414
782
 
783
+ useEffect(() => {
784
+ if (!pendingKillSessionName) {
785
+ return
786
+ }
787
+
788
+ const selectedSessionName =
789
+ appMode === AppMode.OpencodeManage
790
+ ? opencodeSessions[opencodeCursor]?.title
791
+ : viewMode === ViewMode.Sessions
792
+ ? regularSessions[cursor]?.title
793
+ : undefined
794
+
795
+ if (selectedSessionName !== pendingKillSessionName) {
796
+ setPendingKillSessionName(null)
797
+ }
798
+ }, [appMode, cursor, opencodeCursor, opencodeSessions, pendingKillSessionName, regularSessions, viewMode])
799
+
415
800
  useEffect(() => {
416
801
  if (appMode === AppMode.Search || appMode === AppMode.NewSession) {
417
802
  if (searchQuery.trim()) {
@@ -443,176 +828,245 @@ export function App() {
443
828
 
444
829
  const title =
445
830
  appMode === AppMode.Search
446
- ? 'Search Sessions'
831
+ ? 'Search'
447
832
  : appMode === AppMode.NewSession
448
- ? '󰏌 New Session'
449
- : appMode === AppMode.Rename
450
- ? '󰏫 Rename Session'
451
- : appMode === AppMode.OpencodeManage
452
- ? ' Opencode Sessions'
453
- : ' Tmux Session Manager'
833
+ ? 'New Session'
834
+ : appMode === AppMode.OpencodeManage
835
+ ? 'OpenCode Sessions'
836
+ : viewMode === ViewMode.Projects
837
+ ? 'Projects'
838
+ : 'Sessions'
454
839
 
455
840
  const listStyle =
456
841
  appMode === AppMode.NewSession
457
842
  ? {
458
- ...sessionListStyleFull,
843
+ ...getPanelStyle(theme, 'full'),
459
844
  flexGrow: 1,
460
845
  flexShrink: 1,
461
846
  }
462
847
  : {
463
- ...sessionListStyle,
848
+ ...getPanelStyle(theme, 'split'),
464
849
  flexGrow: 1,
465
850
  flexShrink: 1,
466
851
  minWidth: 40,
467
852
  }
468
853
 
469
- const totalSessions =
470
- viewMode === ViewMode.Sessions && appMode === AppMode.Normal
471
- ? items.filter(item => item.isSession).length
472
- : 0
854
+ const totalSessions = sessionItems.filter(item => item.isSession).length
473
855
  const activeSessions = items.filter(item => item.isSession && item.isAttached).length
474
- const idleSessions = totalSessions - activeSessions
475
-
476
- const sessionsWithAges = items
477
- .filter(item => item.isSession && item.createdAt)
478
- .sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0))
479
-
480
- const oldestSession =
481
- sessionsWithAges.length > 0 ? formatSessionAge(sessionsWithAges[0].createdAt!) : 'N/A'
482
- const newestSession =
483
- sessionsWithAges.length > 0
484
- ? formatSessionAge(sessionsWithAges[sessionsWithAges.length - 1].createdAt!)
485
- : 'N/A'
486
- const maxVisibleItems = Math.max(8, rows - (appMode === AppMode.NewSession ? 10 : 16))
856
+ const maxVisibleItems = Math.max(8, rows - (appMode === AppMode.NewSession ? 10 : 12))
857
+ const prefixLabel = config?.prefixKey ? `${config.prefixKey} ...` : 'direct keys'
858
+ const footerHint =
859
+ appMode === AppMode.OpencodeManage
860
+ ? `o back d kill ctrl+p commands ${prefixLabel}`
861
+ : appMode === AppMode.NewSession
862
+ ? 'enter create esc cancel'
863
+ : appMode === AppMode.Search
864
+ ? 'enter select esc cancel'
865
+ : `enter select i search n new o opencode d kill ctrl+p commands ${prefixLabel}`
487
866
 
488
867
  return (
489
- <box
490
- style={{
491
- flexDirection: 'row',
492
- alignItems: 'stretch',
493
- justifyContent: 'center',
494
- width: '100%',
495
- height: '100%',
496
- gap: 1,
497
- }}
498
- >
499
- {/* Left panel - Session/Project list */}
500
- <box style={listStyle}>
501
- <box style={{ alignItems: 'center', justifyContent: 'center' }}>
502
- <text style={{ fg: colors.primary, marginBottom: 1, marginTop: 1 }}>{title}</text>
503
- </box>
868
+ <ThemeProvider theme={theme}>
869
+ <box
870
+ style={{
871
+ flexDirection: 'row',
872
+ alignItems: 'stretch',
873
+ justifyContent: 'center',
874
+ width: '100%',
875
+ height: '100%',
876
+ gap: 1,
877
+ backgroundColor: theme.background,
878
+ }}
879
+ >
880
+ <box style={listStyle}>
881
+ <box style={{ justifyContent: 'space-between', marginBottom: 1 }}>
882
+ <box style={{ flexDirection: 'column' }}>
883
+ <text style={{ fg: theme.text }}>mux-sesh</text>
884
+ <text style={{ fg: theme.textSubtle }}>{title}</text>
885
+ </box>
886
+ <box style={{ flexDirection: 'column', alignItems: 'flex-end' }}>
887
+ <text style={{ fg: theme.textMuted }}>
888
+ {viewMode === ViewMode.Sessions ? `${activeSessions}/${totalSessions} active` : `${projectItems.length} projects`}
889
+ </text>
890
+ <text style={{ fg: theme.textSubtle }}>{`${resolvedTheme.name} · ${resolvedTheme.mode}`}</text>
891
+ </box>
892
+ </box>
504
893
 
505
- {/* Search input */}
506
- {(appMode === AppMode.Search ||
507
- appMode === AppMode.NewSession ||
508
- appMode === AppMode.Rename) && (
509
- <SearchInput
510
- key={appMode}
511
- appMode={appMode}
512
- searchQuery={searchQuery}
513
- textareaRef={textareaRef}
514
- prefixActive={prefixActive}
515
- onContentChange={() => {
516
- if (textareaRef.current && textareaRef.current.plainText !== undefined) {
517
- setSearchQuery(textareaRef.current.plainText)
518
- }
894
+ {(appMode === AppMode.Search || appMode === AppMode.NewSession) && (
895
+ <SearchInput
896
+ key={appMode}
897
+ appMode={appMode}
898
+ searchQuery={searchQuery}
899
+ textareaRef={textareaRef}
900
+ prefixActive={prefixActive}
901
+ onContentChange={() => {
902
+ if (textareaRef.current && textareaRef.current.plainText !== undefined) {
903
+ setSearchQuery(textareaRef.current.plainText)
904
+ }
905
+ }}
906
+ />
907
+ )}
908
+
909
+ <box
910
+ style={{
911
+ alignSelf: 'auto',
912
+ flexDirection: 'column',
913
+ flexGrow: 0,
914
+ flexShrink: 0,
915
+ marginTop:
916
+ viewMode === ViewMode.Sessions && (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage)
917
+ ? 1
918
+ : 0,
519
919
  }}
520
- />
521
- )}
920
+ >
921
+ {items.length === 0 ? (
922
+ <text style={{ fg: theme.inactive }}>
923
+ {appMode === AppMode.NewSession && searchQuery && isGitHubURL(searchQuery)
924
+ ? 'Clone & create session'
925
+ : appMode === AppMode.NewSession && searchQuery
926
+ ? `Create session: ${searchQuery}`
927
+ : 'No items found'}
928
+ </text>
929
+ ) : viewMode === ViewMode.Sessions && (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage) ? (
930
+ <>
931
+ <SessionList
932
+ items={regularSessions}
933
+ cursor={cursor}
934
+ searchQuery={searchQuery}
935
+ maxItems={maxVisibleItems}
936
+ icons={config?.icons}
937
+ pendingKillSessionName={pendingKillSessionName}
938
+ />
522
939
 
523
- {/* Items list */}
524
- <box
525
- style={{
526
- alignSelf: 'auto',
527
- flexDirection: 'column',
528
- flexGrow: 0,
529
- flexShrink: 0,
530
- marginTop:
531
- viewMode === ViewMode.Sessions &&
532
- (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage)
533
- ? 2
534
- : 0,
535
- }}
536
- >
537
- {items.length === 0 ? (
538
- <text style={{ fg: colors.inactive }}>
539
- {appMode === AppMode.NewSession && searchQuery && isGitHubURL(searchQuery)
540
- ? `Clone & create session`
541
- : appMode === AppMode.NewSession && searchQuery
542
- ? `Create session: ${searchQuery}`
543
- : 'No items found'}
544
- </text>
545
- ) : viewMode === ViewMode.Sessions &&
546
- (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage) ? (
547
- <>
548
- {/* Regular sessions */}
549
- <SessionList
550
- items={regularSessions}
940
+ <OpencodeSessionGroup
941
+ sessions={opencodeSessions}
942
+ appMode={appMode}
943
+ cursor={opencodeCursor}
944
+ icons={config?.icons}
945
+ pendingKillSessionName={pendingKillSessionName}
946
+ />
947
+ </>
948
+ ) : (
949
+ <ItemList
950
+ items={items}
551
951
  cursor={cursor}
952
+ appMode={appMode}
552
953
  searchQuery={searchQuery}
553
954
  maxItems={maxVisibleItems}
554
955
  icons={config?.icons}
956
+ pendingKillSessionName={pendingKillSessionName}
555
957
  />
958
+ )}
959
+ </box>
556
960
 
557
- {/* Opencode sessions group */}
558
- <OpencodeSessionGroup
559
- sessions={opencodeSessions}
560
- appMode={appMode}
561
- cursor={opencodeCursor}
562
- icons={config?.icons}
563
- />
564
-
565
- {/* Session statistics */}
566
- <SessionStats
567
- totalSessions={totalSessions}
568
- activeSessions={activeSessions}
569
- idleSessions={idleSessions}
570
- oldestSession={oldestSession}
571
- newestSession={newestSession}
572
- />
573
- </>
574
- ) : (
575
- <ItemList
576
- items={items}
577
- cursor={cursor}
578
- appMode={appMode}
579
- searchQuery={searchQuery}
580
- maxItems={maxVisibleItems}
581
- icons={config?.icons}
582
- />
961
+ {(message || columns < 80 || footerHint) && (
962
+ <box style={{ flexDirection: 'column', marginTop: 1 }}>
963
+ {message && <text style={{ fg: theme.action }}>{message}</text>}
964
+ {columns < 80 && appMode !== AppMode.NewSession && (
965
+ <text style={{ fg: theme.textSubtle }}>Resize for the detail pane.</text>
966
+ )}
967
+ <text style={{ fg: theme.textSubtle }}>{footerHint}</text>
968
+ </box>
583
969
  )}
584
970
  </box>
585
971
 
586
- {/* Message */}
587
- {message && <text style={{ fg: colors.action, marginTop: 1 }}>{message}</text>}
972
+ {shouldShowDetailPanel(columns, appMode === AppMode.NewSession) && (
973
+ <>
974
+ {viewMode === ViewMode.Sessions && appMode === AppMode.OpencodeManage ? (
975
+ <OpencodeStatsPanel selectedItem={opencodeSessions[opencodeCursor]} />
976
+ ) : (
977
+ <SessionDetailsPanel selectedItem={selectedPrimaryItem} config={config} />
978
+ )}
979
+ </>
980
+ )}
588
981
 
589
- {/* Terminal size warning */}
590
- {columns < 80 && appMode !== AppMode.NewSession && (
591
- <text style={{ fg: colors.inactive, marginTop: 1 }}>
592
- Terminal too small. Resize for full view.
593
- </text>
982
+ {modalState?.type === 'rename' && (
983
+ <RenameModal
984
+ target={modalState.target}
985
+ initialValue={modalInputValue}
986
+ columns={columns}
987
+ textareaRef={modalTextareaRef}
988
+ onContentChange={() => {
989
+ if (modalTextareaRef.current?.plainText !== undefined) {
990
+ setModalInputValue(modalTextareaRef.current.plainText)
991
+ }
992
+ }}
993
+ />
594
994
  )}
595
995
 
596
- {/* Keybind help */}
597
- <box style={{ marginTop: 1, flexDirection: 'column' }}>
598
- <KeybindHelp appMode={appMode} keybindMode={config?.keybindMode} selectedItem={selectedPrimaryItem} />
599
- </box>
600
- </box>
996
+ {modalState?.type === 'commands' && (
997
+ <CommandsModal
998
+ columns={columns}
999
+ themeId={resolvedTheme.id}
1000
+ entries={filteredCommandEntries}
1001
+ cursor={commandsCursor}
1002
+ searchQuery={commandsSearchQuery}
1003
+ textareaRef={commandsSearchTextareaRef}
1004
+ onContentChange={() => {
1005
+ if (commandsSearchTextareaRef.current?.plainText !== undefined) {
1006
+ setCommandsSearchQuery(commandsSearchTextareaRef.current.plainText)
1007
+ setCommandsCursor(0)
1008
+ }
1009
+ }}
1010
+ />
1011
+ )}
601
1012
 
602
- {/* Right panel - Detail panel (only in non-new-session modes) */}
603
- {shouldShowDetailPanel(columns, appMode === AppMode.NewSession) && (
604
- <>
605
- {viewMode === ViewMode.Sessions && appMode === AppMode.OpencodeManage ? (
606
- <OpencodeStatsPanel selectedItem={opencodeSessions[opencodeCursor]} />
607
- ) : (
608
- <SessionDetailsPanel
609
- selectedItem={selectedPrimaryItem}
610
- config={config}
611
- />
612
- )}
613
- </>
614
- )}
615
- <Toast message={toastMessage} visible={toastVisible} />
616
- </box>
1013
+ {modalState?.type === 'settings' && config && (
1014
+ <SettingsModal
1015
+ configPath={configPath}
1016
+ themeName={resolvedTheme.name}
1017
+ colorMode={resolvedTheme.mode}
1018
+ columns={columns}
1019
+ entries={filteredSettingsEntries}
1020
+ cursor={settingsCursor}
1021
+ searchQuery={settingsSearchQuery}
1022
+ textareaRef={settingsSearchTextareaRef}
1023
+ onContentChange={() => {
1024
+ if (settingsSearchTextareaRef.current?.plainText !== undefined) {
1025
+ setSettingsSearchQuery(settingsSearchTextareaRef.current.plainText)
1026
+ setSettingsCursor(0)
1027
+ }
1028
+ }}
1029
+ />
1030
+ )}
1031
+
1032
+ {modalState?.type === 'setting-options' && (
1033
+ <SettingOptionsModal
1034
+ title={getSettingEditorTitle(modalState.field)}
1035
+ description='Select an option to apply it immediately'
1036
+ columns={columns}
1037
+ options={filteredSettingOptions}
1038
+ cursor={settingOptionsCursor}
1039
+ searchQuery={settingOptionsSearchQuery}
1040
+ textareaRef={settingOptionsSearchTextareaRef}
1041
+ onContentChange={() => {
1042
+ if (settingOptionsSearchTextareaRef.current?.plainText !== undefined) {
1043
+ setSettingOptionsSearchQuery(settingOptionsSearchTextareaRef.current.plainText)
1044
+ setSettingOptionsCursor(0)
1045
+ }
1046
+ }}
1047
+ />
1048
+ )}
1049
+
1050
+ {modalState?.type === 'setting-editor' && (
1051
+ <SettingEditorModal
1052
+ title={getSettingEditorTitle(modalState.field)}
1053
+ description='Edit value and press Enter to apply immediately'
1054
+ value={settingEditorValue}
1055
+ error={settingEditorError}
1056
+ columns={columns}
1057
+ rows={rows}
1058
+ textareaRef={settingEditorTextareaRef}
1059
+ onContentChange={() => {
1060
+ if (settingEditorTextareaRef.current?.plainText !== undefined) {
1061
+ setSettingEditorValue(settingEditorTextareaRef.current.plainText)
1062
+ }
1063
+ }}
1064
+ />
1065
+ )}
1066
+
1067
+ <Toast message={toastMessage} visible={toastVisible} />
1068
+ <VersionBadge currentVersion={CURRENT_VERSION} updatedVersion={updatedVersion} />
1069
+ </box>
1070
+ </ThemeProvider>
617
1071
  )
618
1072
  }