mux-sesh 1.6.4 → 1.7.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.
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 +92 -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 +158 -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,158 @@
1
+ import { useEffect, type Dispatch, type MutableRefObject, type SetStateAction } from 'react'
2
+ import { loadConfig } from '../config'
3
+ import { AppMode, ViewMode, type Config, type Item } from '../types'
4
+ import {
5
+ getProjectSelectionIndex,
6
+ getSessionSelectionIndex,
7
+ loadProjectSourceItems,
8
+ loadProjectItemsWithLinks,
9
+ loadSessionItems,
10
+ type Measure,
11
+ } from './data'
12
+
13
+ export interface RefreshedViewState {
14
+ items: Item[]
15
+ cursor: number
16
+ sessionItems?: Item[]
17
+ projectSourceItems?: Item[]
18
+ }
19
+
20
+ export async function loadRefreshedViewState(
21
+ targetMode: ViewMode,
22
+ config: Config,
23
+ measure: Measure,
24
+ lastSessionSelection?: string | null,
25
+ lastProjectSelection?: string | null
26
+ ): Promise<RefreshedViewState> {
27
+ if (targetMode === ViewMode.Sessions) {
28
+ const { sessionItems } = await loadSessionItems(config, measure, 'refresh')
29
+ return {
30
+ items: sessionItems,
31
+ sessionItems,
32
+ cursor: getSessionSelectionIndex(sessionItems, lastSessionSelection),
33
+ }
34
+ }
35
+
36
+ const { visibleSessions } = await loadSessionItems(config, measure, 'refresh-projects')
37
+ const { projectSourceItems, projectItems } = await loadProjectItemsWithLinks(
38
+ config,
39
+ visibleSessions,
40
+ measure
41
+ )
42
+
43
+ return {
44
+ items: projectItems,
45
+ projectSourceItems,
46
+ cursor: getProjectSelectionIndex(projectItems, lastProjectSelection),
47
+ }
48
+ }
49
+
50
+ export function applyRefreshedViewState(
51
+ refreshedState: RefreshedViewState,
52
+ setSessionItems: Dispatch<SetStateAction<Item[]>>,
53
+ setProjectSourceItems: Dispatch<SetStateAction<Item[]>>,
54
+ setAllItems: Dispatch<SetStateAction<Item[]>>,
55
+ setItems: Dispatch<SetStateAction<Item[]>>,
56
+ setCursor: Dispatch<SetStateAction<number>>
57
+ ) {
58
+ if (refreshedState.sessionItems) {
59
+ setSessionItems(refreshedState.sessionItems)
60
+ }
61
+
62
+ if (refreshedState.projectSourceItems) {
63
+ setProjectSourceItems(refreshedState.projectSourceItems)
64
+ }
65
+
66
+ setAllItems(refreshedState.items)
67
+ setItems(refreshedState.items)
68
+ setCursor(refreshedState.cursor)
69
+ }
70
+
71
+ export function useAppStartup(
72
+ measure: Measure,
73
+ lastSessionSelectionRef: MutableRefObject<string | null>,
74
+ lastProjectSelectionRef: MutableRefObject<string | null>,
75
+ mark: (label: string) => void,
76
+ setConfig: Dispatch<SetStateAction<Config | null>>,
77
+ setAppMode: Dispatch<SetStateAction<AppMode>>,
78
+ setViewMode: Dispatch<SetStateAction<ViewMode>>,
79
+ setSessionItems: Dispatch<SetStateAction<Item[]>>,
80
+ setProjectSourceItems: Dispatch<SetStateAction<Item[]>>,
81
+ setAllItems: Dispatch<SetStateAction<Item[]>>,
82
+ setItems: Dispatch<SetStateAction<Item[]>>,
83
+ setCursor: Dispatch<SetStateAction<number>>
84
+ ) {
85
+ useEffect(() => {
86
+ let cancelled = false
87
+
88
+ async function init() {
89
+ mark('startup begin')
90
+ const config = await measure('loadConfig', loadConfig)
91
+ if (cancelled) {
92
+ return
93
+ }
94
+
95
+ const startupAppMode = config.keybindMode === 'standard' ? AppMode.Search : AppMode.Normal
96
+ setConfig(config)
97
+ setAppMode(startupAppMode)
98
+
99
+ const { visibleSessions, sessionItems } = await loadSessionItems(config, measure, 'startup')
100
+ if (cancelled) {
101
+ return
102
+ }
103
+
104
+ setSessionItems(sessionItems)
105
+
106
+ if (sessionItems.length > 0) {
107
+ setViewMode(ViewMode.Sessions)
108
+ setAllItems(sessionItems)
109
+ setItems(sessionItems)
110
+ setCursor(getSessionSelectionIndex(sessionItems, lastSessionSelectionRef.current))
111
+ mark('startup complete')
112
+
113
+ const projectSourceItems = await loadProjectSourceItems(config, measure)
114
+ if (cancelled) {
115
+ return
116
+ }
117
+
118
+ setProjectSourceItems(projectSourceItems)
119
+ return
120
+ }
121
+
122
+ const { projectSourceItems, projectItems } = await loadProjectItemsWithLinks(
123
+ config,
124
+ visibleSessions,
125
+ measure
126
+ )
127
+ if (cancelled) {
128
+ return
129
+ }
130
+
131
+ setViewMode(ViewMode.Projects)
132
+ setProjectSourceItems(projectSourceItems)
133
+ setAllItems(projectItems)
134
+ setItems(projectItems)
135
+ setCursor(getProjectSelectionIndex(projectItems, lastProjectSelectionRef.current))
136
+ mark('startup complete')
137
+ }
138
+
139
+ void init()
140
+
141
+ return () => {
142
+ cancelled = true
143
+ }
144
+ }, [
145
+ lastProjectSelectionRef,
146
+ lastSessionSelectionRef,
147
+ mark,
148
+ measure,
149
+ setAllItems,
150
+ setAppMode,
151
+ setConfig,
152
+ setCursor,
153
+ setItems,
154
+ setProjectSourceItems,
155
+ setSessionItems,
156
+ setViewMode,
157
+ ])
158
+ }
@@ -0,0 +1,16 @@
1
+ import type { TextareaRenderable } from '@opentui/core'
2
+ import type { Dispatch, MutableRefObject, SetStateAction } from 'react'
3
+
4
+ export function syncTextareaValue(
5
+ textareaRef: MutableRefObject<TextareaRenderable | null>,
6
+ setValue: Dispatch<SetStateAction<string>>,
7
+ resetCursor?: Dispatch<SetStateAction<number>>
8
+ ) {
9
+ const value = textareaRef.current?.plainText
10
+ if (value === undefined) {
11
+ return
12
+ }
13
+
14
+ setValue(value)
15
+ resetCursor?.(0)
16
+ }
@@ -0,0 +1,89 @@
1
+ import { getPanelStyle } from '../styles/theme'
2
+ import { AppMode, ViewMode, type ThemeColors } from '../types'
3
+
4
+ export function splitVisibleSessions<T extends { isSession: boolean; title: string }>(
5
+ items: readonly T[]
6
+ ) {
7
+ return {
8
+ regularSessions: items.filter(item => !(item.isSession && item.title.startsWith('opencode-'))),
9
+ opencodeSessions: items.filter(item => item.isSession && item.title.startsWith('opencode-')),
10
+ }
11
+ }
12
+
13
+ export function getAppTitle(appMode: AppMode, viewMode: ViewMode): string {
14
+ if (appMode === AppMode.Search) {
15
+ return 'Search'
16
+ }
17
+
18
+ if (appMode === AppMode.NewSession) {
19
+ return 'New Session'
20
+ }
21
+
22
+ if (appMode === AppMode.OpencodeManage) {
23
+ return 'OpenCode Sessions'
24
+ }
25
+
26
+ return viewMode === ViewMode.Projects ? 'Projects' : 'Sessions'
27
+ }
28
+
29
+ export function getListStyle(theme: ThemeColors, appMode: AppMode) {
30
+ if (appMode === AppMode.NewSession) {
31
+ return {
32
+ ...getPanelStyle(theme, 'full'),
33
+ flexGrow: 1,
34
+ flexShrink: 1,
35
+ }
36
+ }
37
+
38
+ return {
39
+ ...getPanelStyle(theme, 'split'),
40
+ flexGrow: 1,
41
+ flexShrink: 1,
42
+ minWidth: 40,
43
+ }
44
+ }
45
+
46
+ export function getStatusLabel(
47
+ viewMode: ViewMode,
48
+ activeSessions: number,
49
+ totalSessions: number,
50
+ projectCount: number
51
+ ): string {
52
+ return viewMode === ViewMode.Sessions
53
+ ? `${activeSessions}/${totalSessions} active`
54
+ : `${projectCount} projects`
55
+ }
56
+
57
+ export function getFooterHint(appMode: AppMode, prefixKey?: string): string {
58
+ const prefixLabel = prefixKey ? `${prefixKey} ...` : 'direct keys'
59
+
60
+ if (appMode === AppMode.OpencodeManage) {
61
+ return `o back d kill ctrl+p commands ${prefixLabel}`
62
+ }
63
+
64
+ if (appMode === AppMode.NewSession) {
65
+ return 'enter create esc cancel'
66
+ }
67
+
68
+ if (appMode === AppMode.Search) {
69
+ return 'enter select esc cancel'
70
+ }
71
+
72
+ return `enter select i search n new o opencode d kill ctrl+p commands ${prefixLabel}`
73
+ }
74
+
75
+ export function getEmptyStateMessage(
76
+ appMode: AppMode,
77
+ searchQuery: string,
78
+ isGitHubURL: boolean
79
+ ): string {
80
+ if (appMode === AppMode.NewSession && searchQuery && isGitHubURL) {
81
+ return 'Clone & create session'
82
+ }
83
+
84
+ if (appMode === AppMode.NewSession && searchQuery) {
85
+ return `Create session: ${searchQuery}`
86
+ }
87
+
88
+ return 'No items found'
89
+ }