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.
- package/README.md +90 -59
- package/package.json +7 -5
- package/src/app/commands.ts +120 -0
- package/src/app/controller.ts +397 -0
- package/src/app/controls.ts +121 -0
- package/src/app/core-state.ts +71 -0
- package/src/app/data.ts +90 -0
- package/src/app/derived.ts +77 -0
- package/src/app/effects.ts +392 -0
- package/src/app/handlers.ts +325 -0
- package/src/app/keyboard.ts +161 -0
- package/src/app/modal-keyboard.ts +118 -0
- package/src/app/modal-state.ts +50 -0
- package/src/app/modals-layer.tsx +159 -0
- package/src/app/modals.ts +108 -0
- package/src/app/notifications.ts +21 -0
- package/src/app/opencode.ts +49 -0
- package/src/app/operations.ts +31 -0
- package/src/app/runtime.ts +76 -0
- package/src/app/screen.tsx +217 -0
- package/src/app/state.ts +166 -0
- package/src/app/textarea.ts +16 -0
- package/src/app/view.ts +89 -0
- package/src/app.tsx +7 -1101
- package/src/config/index.ts +36 -42
- package/src/config/listed-sessions.ts +2 -5
- package/src/config/paths.ts +13 -0
- package/src/config/session-rules.ts +10 -11
- package/src/config/store.ts +26 -0
- package/src/handlers/action-helpers.ts +50 -0
- package/src/handlers/actions.ts +34 -65
- package/src/handlers/keyboard/index.ts +5 -0
- package/src/handlers/keyboard/new-session.ts +57 -0
- package/src/handlers/keyboard/normal.ts +201 -0
- package/src/handlers/keyboard/opencode.ts +104 -0
- package/src/handlers/keyboard/search.ts +113 -0
- package/src/handlers/keyboard/shared.ts +116 -0
- package/src/items/order.ts +21 -2
- package/src/opencode/sqlite.ts +21 -6
- package/src/preview/project.ts +41 -15
- package/src/search/index.ts +4 -1
- package/src/settings.ts +294 -297
- package/src/styles/opencode-themes-a.ts +1442 -1
- package/src/styles/opencode-themes-b.ts +1212 -1
- package/src/styles/opencode-tui-colors.ts +1784 -1
- package/src/styles/theme.tsx +2 -1
- package/src/tmux/actions.ts +103 -0
- package/src/tmux/details.ts +123 -0
- package/src/tmux/helpers.ts +35 -0
- package/src/tmux/index.ts +10 -286
- package/src/tmux/list.ts +31 -0
- package/src/tmux/project-discovery.ts +113 -0
- package/src/tmux/project-loader.ts +74 -0
- package/src/tmux/project-zoxide.ts +128 -0
- package/src/tmux/projects.ts +23 -261
- package/src/types/index.ts +0 -1
- package/src/ui/CommandsModal.tsx +87 -22
- package/src/ui/HighlightedText.tsx +1 -5
- package/src/ui/ItemList.tsx +26 -11
- package/src/ui/Modal.tsx +8 -1
- package/src/ui/OpencodeSessionGroup.tsx +20 -9
- package/src/ui/OpencodeStatsPanel.tsx +48 -15
- package/src/ui/RenameModal.tsx +17 -17
- package/src/ui/SearchInput.tsx +1 -20
- package/src/ui/SessionDetailsPanel.tsx +43 -15
- package/src/ui/SessionList.tsx +25 -4
- package/src/ui/SettingEditorModal.tsx +15 -9
- package/src/ui/SettingOptionsModal.tsx +30 -12
- package/src/ui/SettingsModal.tsx +20 -14
- package/src/ui/VersionBadge.tsx +3 -1
- package/src/ui/item-icon.ts +5 -1
- package/src/ui/list-window.ts +5 -1
- package/src/ui/text-columns.ts +17 -0
- package/src/ui/use-textarea-focus.ts +26 -0
- package/src/update/index.ts +10 -2
- package/src/update/installation.ts +6 -2
- package/src/util/ansi.ts +3 -0
- package/src/util/glob.ts +5 -1
- package/src/util/path-display.ts +98 -0
- package/src/components/KeybindHelp.tsx +0 -289
- package/src/handlers/keyboard.ts +0 -654
- package/src/ui/SessionStats.tsx +0 -32
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { AppMode, ViewMode, type KeybindMode } from '../../types'
|
|
2
|
+
import { requestShutdown } from '../../util/shutdown'
|
|
3
|
+
import {
|
|
4
|
+
activatePrefix,
|
|
5
|
+
clearPrefix,
|
|
6
|
+
enterNewSessionMode,
|
|
7
|
+
getKeyName,
|
|
8
|
+
getQuickSelectItem,
|
|
9
|
+
getSelectedItem,
|
|
10
|
+
matchesPrefixKey,
|
|
11
|
+
openSelectedEditTarget,
|
|
12
|
+
openSelectedRootSession,
|
|
13
|
+
setTimedMessage,
|
|
14
|
+
type KeyboardHandlerContext,
|
|
15
|
+
type KeyboardInput,
|
|
16
|
+
} from './shared'
|
|
17
|
+
|
|
18
|
+
export function handleNormalMode(
|
|
19
|
+
key: KeyboardInput,
|
|
20
|
+
ctx: KeyboardHandlerContext,
|
|
21
|
+
keybindMode: KeybindMode = 'vim'
|
|
22
|
+
) {
|
|
23
|
+
const keyName = getKeyName(key)
|
|
24
|
+
const isStandard = keybindMode === 'standard'
|
|
25
|
+
|
|
26
|
+
if (ctx.prefixActive) {
|
|
27
|
+
clearPrefix(ctx)
|
|
28
|
+
|
|
29
|
+
if (key.shift && keyName.toLowerCase() === 'r') {
|
|
30
|
+
ctx.clearPendingKill()
|
|
31
|
+
void ctx.refreshItems()
|
|
32
|
+
setTimedMessage(ctx, 'Refreshed')
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch (keyName) {
|
|
37
|
+
case 'l':
|
|
38
|
+
ctx.clearPendingKill()
|
|
39
|
+
void ctx.handleLastSession()
|
|
40
|
+
return
|
|
41
|
+
case 'g':
|
|
42
|
+
openSelectedRootSession(ctx)
|
|
43
|
+
return
|
|
44
|
+
case 'e':
|
|
45
|
+
openSelectedEditTarget(ctx)
|
|
46
|
+
return
|
|
47
|
+
case 'd':
|
|
48
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
49
|
+
ctx.requestKillSession(ctx.regularSessions[ctx.cursor].title)
|
|
50
|
+
}
|
|
51
|
+
return
|
|
52
|
+
case 'r':
|
|
53
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
54
|
+
ctx.clearPendingKill()
|
|
55
|
+
ctx.openRenameModal(ctx.regularSessions[ctx.cursor].title)
|
|
56
|
+
}
|
|
57
|
+
return
|
|
58
|
+
case 's':
|
|
59
|
+
ctx.clearPendingKill()
|
|
60
|
+
ctx.setViewMode(ViewMode.Sessions)
|
|
61
|
+
void ctx.refreshItems(ViewMode.Sessions)
|
|
62
|
+
return
|
|
63
|
+
case 'p':
|
|
64
|
+
ctx.clearPendingKill()
|
|
65
|
+
ctx.setViewMode(ViewMode.Projects)
|
|
66
|
+
void ctx.refreshItems(ViewMode.Projects)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
|
|
74
|
+
activatePrefix(ctx)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
(isStandard && ((key.ctrl && keyName === 'q') || keyName === 'escape')) ||
|
|
80
|
+
(!isStandard && (keyName === 'q' || keyName === 'escape'))
|
|
81
|
+
) {
|
|
82
|
+
void requestShutdown(0)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!isStandard && keyName === 'i') {
|
|
87
|
+
ctx.clearPendingKill()
|
|
88
|
+
ctx.setAppMode(AppMode.Search)
|
|
89
|
+
ctx.setSearchQuery('')
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!isStandard && keyName === 'n') {
|
|
94
|
+
enterNewSessionMode(ctx)
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!isStandard && keyName === 'o') {
|
|
99
|
+
ctx.clearPendingKill()
|
|
100
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
101
|
+
ctx.setAppMode(AppMode.OpencodeManage)
|
|
102
|
+
ctx.setOpencodeCursor(0)
|
|
103
|
+
void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
104
|
+
}
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (key.ctrl && keyName === 'p') {
|
|
109
|
+
ctx.clearPendingKill()
|
|
110
|
+
ctx.openCommandsModal()
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'l') {
|
|
115
|
+
ctx.clearPendingKill()
|
|
116
|
+
void ctx.handleLastSession()
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'g') {
|
|
121
|
+
openSelectedRootSession(ctx)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'e') {
|
|
126
|
+
openSelectedEditTarget(ctx)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!isStandard && keyName === 'd') {
|
|
131
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
132
|
+
ctx.requestKillSession(ctx.regularSessions[ctx.cursor].title)
|
|
133
|
+
}
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'r') {
|
|
138
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
139
|
+
ctx.clearPendingKill()
|
|
140
|
+
ctx.openRenameModal(ctx.regularSessions[ctx.cursor].title)
|
|
141
|
+
}
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'R') {
|
|
146
|
+
ctx.clearPendingKill()
|
|
147
|
+
void ctx.refreshItems()
|
|
148
|
+
setTimedMessage(ctx, 'Refreshed')
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!isStandard) {
|
|
153
|
+
if (keyName === 's') {
|
|
154
|
+
ctx.clearPendingKill()
|
|
155
|
+
ctx.setViewMode(ViewMode.Sessions)
|
|
156
|
+
void ctx.refreshItems(ViewMode.Sessions)
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (keyName === 'p') {
|
|
161
|
+
ctx.clearPendingKill()
|
|
162
|
+
ctx.setViewMode(ViewMode.Projects)
|
|
163
|
+
void ctx.refreshItems(ViewMode.Projects)
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
169
|
+
ctx.clearPendingKill()
|
|
170
|
+
if (ctx.viewMode === ViewMode.Sessions) {
|
|
171
|
+
ctx.setCursor(cursor => Math.min(cursor + 1, ctx.regularSessions.length - 1))
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
ctx.setCursor(cursor => Math.min(cursor + 1, ctx.items.length - 1))
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
180
|
+
ctx.clearPendingKill()
|
|
181
|
+
ctx.setCursor(cursor => Math.max(cursor - 1, 0))
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (keyName === 'return') {
|
|
186
|
+
ctx.clearPendingKill()
|
|
187
|
+
const item = getSelectedItem(ctx)
|
|
188
|
+
if (item) {
|
|
189
|
+
void ctx.handleSelect(item)
|
|
190
|
+
}
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!isStandard && keyName >= '1' && keyName <= '9') {
|
|
195
|
+
ctx.clearPendingKill()
|
|
196
|
+
const item = getQuickSelectItem(ctx, Number.parseInt(keyName, 10) - 1)
|
|
197
|
+
if (item) {
|
|
198
|
+
void ctx.handleSelect(item)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AppMode, type KeybindMode } from '../../types'
|
|
2
|
+
import {
|
|
3
|
+
activatePrefix,
|
|
4
|
+
clearPrefix,
|
|
5
|
+
getKeyName,
|
|
6
|
+
matchesPrefixKey,
|
|
7
|
+
type KeyboardHandlerContext,
|
|
8
|
+
type KeyboardInput,
|
|
9
|
+
} from './shared'
|
|
10
|
+
|
|
11
|
+
export function handleOpencodeManageMode(
|
|
12
|
+
key: KeyboardInput,
|
|
13
|
+
ctx: KeyboardHandlerContext,
|
|
14
|
+
keybindMode: KeybindMode = 'vim'
|
|
15
|
+
) {
|
|
16
|
+
const keyName = getKeyName(key)
|
|
17
|
+
const isStandard = keybindMode === 'standard'
|
|
18
|
+
|
|
19
|
+
if (key.ctrl && keyName === 'p') {
|
|
20
|
+
ctx.clearPendingKill()
|
|
21
|
+
ctx.openCommandsModal()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (ctx.prefixActive) {
|
|
26
|
+
clearPrefix(ctx)
|
|
27
|
+
|
|
28
|
+
switch (keyName) {
|
|
29
|
+
case 'o':
|
|
30
|
+
ctx.clearPendingKill()
|
|
31
|
+
ctx.setAppMode(AppMode.Normal)
|
|
32
|
+
return
|
|
33
|
+
case 'd':
|
|
34
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
35
|
+
ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
36
|
+
}
|
|
37
|
+
return
|
|
38
|
+
case 'r':
|
|
39
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
40
|
+
ctx.clearPendingKill()
|
|
41
|
+
ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
42
|
+
}
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
|
|
50
|
+
activatePrefix(ctx)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (keyName === 'escape' || (!ctx.prefixKey && !isStandard && keyName === 'o')) {
|
|
55
|
+
ctx.clearPendingKill()
|
|
56
|
+
ctx.setAppMode(AppMode.Normal)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
61
|
+
ctx.clearPendingKill()
|
|
62
|
+
ctx.setOpencodeCursor(cursor => {
|
|
63
|
+
const next = Math.min(cursor + 1, ctx.opencodeSessions.length - 1)
|
|
64
|
+
if (next !== cursor && ctx.opencodeSessions[next]) {
|
|
65
|
+
void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[next].title)
|
|
66
|
+
}
|
|
67
|
+
return next
|
|
68
|
+
})
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
73
|
+
ctx.clearPendingKill()
|
|
74
|
+
ctx.setOpencodeCursor(cursor => {
|
|
75
|
+
const next = Math.max(cursor - 1, 0)
|
|
76
|
+
if (next !== cursor && ctx.opencodeSessions[next]) {
|
|
77
|
+
void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[next].title)
|
|
78
|
+
}
|
|
79
|
+
return next
|
|
80
|
+
})
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!isStandard && keyName === 'd') {
|
|
85
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
86
|
+
ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
87
|
+
}
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'r') {
|
|
92
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
93
|
+
ctx.clearPendingKill()
|
|
94
|
+
ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
95
|
+
}
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!ctx.prefixKey && !isStandard && keyName === ',') {
|
|
100
|
+
ctx.clearPendingKill()
|
|
101
|
+
ctx.openSettingsModal()
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { AppMode, ViewMode, type KeybindMode } from '../../types'
|
|
2
|
+
import { requestShutdown } from '../../util/shutdown'
|
|
3
|
+
import {
|
|
4
|
+
activatePrefix,
|
|
5
|
+
clearPrefix,
|
|
6
|
+
enterNewSessionMode,
|
|
7
|
+
getKeyName,
|
|
8
|
+
matchesPrefixKey,
|
|
9
|
+
setTimedMessage,
|
|
10
|
+
type KeyboardHandlerContext,
|
|
11
|
+
type KeyboardInput,
|
|
12
|
+
} from './shared'
|
|
13
|
+
|
|
14
|
+
export function handleSearchMode(
|
|
15
|
+
key: KeyboardInput,
|
|
16
|
+
ctx: KeyboardHandlerContext,
|
|
17
|
+
keybindMode: KeybindMode = 'vim'
|
|
18
|
+
) {
|
|
19
|
+
const keyName = getKeyName(key)
|
|
20
|
+
const isStandard = keybindMode === 'standard'
|
|
21
|
+
|
|
22
|
+
if (isStandard) {
|
|
23
|
+
if (ctx.prefixActive) {
|
|
24
|
+
clearPrefix(ctx)
|
|
25
|
+
|
|
26
|
+
switch (keyName) {
|
|
27
|
+
case 'd':
|
|
28
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
29
|
+
ctx.requestKillSession(ctx.items[ctx.cursor].title)
|
|
30
|
+
}
|
|
31
|
+
return
|
|
32
|
+
case 'n':
|
|
33
|
+
enterNewSessionMode(ctx)
|
|
34
|
+
return
|
|
35
|
+
case 'o':
|
|
36
|
+
ctx.clearPendingKill()
|
|
37
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
38
|
+
ctx.setAppMode(AppMode.OpencodeManage)
|
|
39
|
+
ctx.setOpencodeCursor(0)
|
|
40
|
+
void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
41
|
+
}
|
|
42
|
+
return
|
|
43
|
+
case 's':
|
|
44
|
+
ctx.clearPendingKill()
|
|
45
|
+
ctx.openSettingsModal()
|
|
46
|
+
return
|
|
47
|
+
case 'l':
|
|
48
|
+
ctx.clearPendingKill()
|
|
49
|
+
void ctx.handleLastSession()
|
|
50
|
+
return
|
|
51
|
+
case 'g':
|
|
52
|
+
ctx.clearPendingKill()
|
|
53
|
+
void ctx.handleRootSession(ctx.items[ctx.cursor])
|
|
54
|
+
return
|
|
55
|
+
case 'r':
|
|
56
|
+
if (key.shift) {
|
|
57
|
+
void ctx.refreshItems()
|
|
58
|
+
setTimedMessage(ctx, 'Refreshed')
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
63
|
+
ctx.clearPendingKill()
|
|
64
|
+
ctx.openRenameModal(ctx.items[ctx.cursor].title)
|
|
65
|
+
}
|
|
66
|
+
return
|
|
67
|
+
default:
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (matchesPrefixKey(key, ctx.prefixKey)) {
|
|
73
|
+
activatePrefix(ctx)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (key.ctrl && keyName === 'q') {
|
|
78
|
+
void requestShutdown(0)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (keyName === 'escape') {
|
|
84
|
+
ctx.clearPendingKill()
|
|
85
|
+
if (isStandard) {
|
|
86
|
+
ctx.setSearchQuery('')
|
|
87
|
+
ctx.setCursor(0)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ctx.setAppMode(AppMode.Normal)
|
|
92
|
+
ctx.setSearchQuery('')
|
|
93
|
+
ctx.setCursor(0)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
switch (keyName) {
|
|
98
|
+
case 'return':
|
|
99
|
+
ctx.clearPendingKill()
|
|
100
|
+
if (ctx.items.length > 0) {
|
|
101
|
+
void ctx.handleSelect(ctx.items[0])
|
|
102
|
+
}
|
|
103
|
+
break
|
|
104
|
+
case 'down':
|
|
105
|
+
ctx.clearPendingKill()
|
|
106
|
+
ctx.setCursor(cursor => Math.min(cursor + 1, ctx.items.length - 1))
|
|
107
|
+
break
|
|
108
|
+
case 'up':
|
|
109
|
+
ctx.clearPendingKill()
|
|
110
|
+
ctx.setCursor(cursor => Math.max(cursor - 1, 0))
|
|
111
|
+
break
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
2
|
+
import { AppMode, ViewMode, type Config, type Item, type OpencodeSessionStats } from '../../types'
|
|
3
|
+
|
|
4
|
+
export interface KeyboardInput {
|
|
5
|
+
name?: string
|
|
6
|
+
ctrl?: boolean
|
|
7
|
+
shift?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface KeyboardHandlerContext {
|
|
11
|
+
appMode: AppMode
|
|
12
|
+
viewMode: ViewMode
|
|
13
|
+
items: Item[]
|
|
14
|
+
regularSessions: Item[]
|
|
15
|
+
opencodeSessions: Item[]
|
|
16
|
+
cursor: number
|
|
17
|
+
opencodeCursor: number
|
|
18
|
+
searchQuery: string
|
|
19
|
+
prefixKey?: string
|
|
20
|
+
projectItems: Item[]
|
|
21
|
+
sessionItems: Item[]
|
|
22
|
+
prefixActive: boolean
|
|
23
|
+
prefixTimeoutRef: MutableRefObject<NodeJS.Timeout | null>
|
|
24
|
+
setAppMode: (mode: AppMode) => void
|
|
25
|
+
setViewMode: (mode: ViewMode) => void
|
|
26
|
+
setCursor: Dispatch<SetStateAction<number>>
|
|
27
|
+
setOpencodeCursor: Dispatch<SetStateAction<number>>
|
|
28
|
+
setSearchQuery: (query: string) => void
|
|
29
|
+
setAllItems: Dispatch<SetStateAction<Item[]>>
|
|
30
|
+
setItems: Dispatch<SetStateAction<Item[]>>
|
|
31
|
+
setPrefixActive: (active: boolean) => void
|
|
32
|
+
refreshItems: (forceViewMode?: ViewMode, nextConfig?: Config) => Promise<void>
|
|
33
|
+
requestKillSession: (sessionName: string) => void
|
|
34
|
+
clearPendingKill: () => void
|
|
35
|
+
handleSelect: (item: Item) => Promise<void>
|
|
36
|
+
handleKillSession: (sessionName: string) => Promise<void>
|
|
37
|
+
handleLastSession: () => Promise<void>
|
|
38
|
+
handleRootSession: (item?: Item) => Promise<void>
|
|
39
|
+
handleEditTarget: (item?: Item) => Promise<void>
|
|
40
|
+
openRenameModal: (sessionName: string) => void
|
|
41
|
+
openCommandsModal: () => void
|
|
42
|
+
openSettingsModal: () => void
|
|
43
|
+
loadOpencodeStatsForSession: (sessionName: string) => Promise<OpencodeSessionStats | null>
|
|
44
|
+
setMessage: (message: string) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getKeyName(key: KeyboardInput): string {
|
|
48
|
+
return key.name ?? ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function matchesPrefixKey(key: KeyboardInput, prefixKey = 'ctrl+x'): boolean {
|
|
52
|
+
const parts = prefixKey.toLowerCase().split('+')
|
|
53
|
+
const keyPart = parts.at(-1) ?? prefixKey.toLowerCase()
|
|
54
|
+
const expectsCtrl = parts.includes('ctrl')
|
|
55
|
+
const expectsShift = parts.includes('shift')
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
Boolean(key.ctrl) === expectsCtrl &&
|
|
59
|
+
Boolean(key.shift) === expectsShift &&
|
|
60
|
+
getKeyName(key).toLowerCase() === keyPart
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function clearPrefix(ctx: KeyboardHandlerContext) {
|
|
65
|
+
if (ctx.prefixTimeoutRef.current) {
|
|
66
|
+
clearTimeout(ctx.prefixTimeoutRef.current)
|
|
67
|
+
ctx.prefixTimeoutRef.current = null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
ctx.setPrefixActive(false)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function activatePrefix(ctx: KeyboardHandlerContext) {
|
|
74
|
+
ctx.setPrefixActive(true)
|
|
75
|
+
ctx.prefixTimeoutRef.current = setTimeout(() => {
|
|
76
|
+
ctx.setPrefixActive(false)
|
|
77
|
+
}, 2000)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function setTimedMessage(ctx: KeyboardHandlerContext, message: string, timeout = 2000) {
|
|
81
|
+
ctx.setMessage(message)
|
|
82
|
+
setTimeout(() => ctx.setMessage(''), timeout)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getSelectedItem(ctx: KeyboardHandlerContext): Item | undefined {
|
|
86
|
+
return ctx.viewMode === ViewMode.Sessions
|
|
87
|
+
? ctx.regularSessions[ctx.cursor]
|
|
88
|
+
: ctx.items[ctx.cursor]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getQuickSelectItem(ctx: KeyboardHandlerContext, index: number): Item | undefined {
|
|
92
|
+
return ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[index] : ctx.items[index]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function enterNewSessionMode(ctx: KeyboardHandlerContext) {
|
|
96
|
+
ctx.clearPendingKill()
|
|
97
|
+
ctx.setAppMode(AppMode.NewSession)
|
|
98
|
+
ctx.setViewMode(ViewMode.Projects)
|
|
99
|
+
ctx.setAllItems(ctx.projectItems)
|
|
100
|
+
ctx.setItems(ctx.projectItems)
|
|
101
|
+
ctx.setCursor(Math.max(0, ctx.projectItems.length - 1))
|
|
102
|
+
ctx.setSearchQuery('')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function openSelectedRootSession(ctx: KeyboardHandlerContext) {
|
|
106
|
+
ctx.clearPendingKill()
|
|
107
|
+
void ctx.handleRootSession(getSelectedItem(ctx))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function openSelectedEditTarget(ctx: KeyboardHandlerContext) {
|
|
111
|
+
ctx.clearPendingKill()
|
|
112
|
+
const item = getSelectedItem(ctx)
|
|
113
|
+
if (item?.itemKind === 'configured') {
|
|
114
|
+
void ctx.handleEditTarget(item)
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/items/order.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import type { Item, SortOrder } from '../types'
|
|
2
|
+
import { getLiveSessionSortKey } from '../util/path-display'
|
|
2
3
|
|
|
3
4
|
function compareByTitle(left: Item, right: Item): number {
|
|
4
5
|
return left.title.localeCompare(right.title)
|
|
5
6
|
}
|
|
6
7
|
|
|
8
|
+
function compareLiveSessions(left: Item, right: Item): number {
|
|
9
|
+
const leftGroupKey = getLiveSessionSortKey(left.path, left.title)
|
|
10
|
+
const rightGroupKey = getLiveSessionSortKey(right.path, right.title)
|
|
11
|
+
const groupDifference = leftGroupKey.localeCompare(rightGroupKey)
|
|
12
|
+
|
|
13
|
+
if (groupDifference !== 0) {
|
|
14
|
+
return groupDifference
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return left.title.localeCompare(right.title)
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
function isOpencodeSession(item: Item): boolean {
|
|
8
21
|
return item.isSession && item.title.startsWith('opencode-')
|
|
9
22
|
}
|
|
@@ -14,7 +27,7 @@ function isConfiguredSession(item: Item): boolean {
|
|
|
14
27
|
|
|
15
28
|
function sortByGroup(items: Item[], groups: Array<'live' | 'configured'>): Item[] {
|
|
16
29
|
const configuredItems = items.filter(isConfiguredSession).sort(compareByTitle)
|
|
17
|
-
const liveItems = items.filter(item => !isConfiguredSession(item)).sort(
|
|
30
|
+
const liveItems = items.filter(item => !isConfiguredSession(item)).sort(compareLiveSessions)
|
|
18
31
|
const groupedItems = new Map([
|
|
19
32
|
['configured', configuredItems],
|
|
20
33
|
['live', liveItems],
|
|
@@ -31,7 +44,13 @@ export function orderSessionItems(items: Item[], sortOrder: SortOrder = 'live-fi
|
|
|
31
44
|
sortOrder === 'configured-first'
|
|
32
45
|
? sortByGroup(regularItems, ['configured', 'live'])
|
|
33
46
|
: sortOrder === 'alphabetical'
|
|
34
|
-
? [...regularItems].sort(
|
|
47
|
+
? [...regularItems].sort((left, right) => {
|
|
48
|
+
if (isConfiguredSession(left) || isConfiguredSession(right)) {
|
|
49
|
+
return compareByTitle(left, right)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return compareLiveSessions(left, right)
|
|
53
|
+
})
|
|
35
54
|
: sortByGroup(regularItems, ['live', 'configured'])
|
|
36
55
|
|
|
37
56
|
return [...orderedRegularItems, ...opencodeItems]
|
package/src/opencode/sqlite.ts
CHANGED
|
@@ -260,7 +260,9 @@ export function getMostRecentSessionRowFromDatabase(
|
|
|
260
260
|
return getSessionRow(database, directory)
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
export async function getMostRecentSessionRow(
|
|
263
|
+
export async function getMostRecentSessionRow(
|
|
264
|
+
directory: string
|
|
265
|
+
): Promise<OpencodeSessionRow | null> {
|
|
264
266
|
return withDatabase(database => getMostRecentSessionRowFromDatabase(database, directory))
|
|
265
267
|
}
|
|
266
268
|
|
|
@@ -309,11 +311,18 @@ export function getMostRecentSessionTitleForDirectoryFromDatabase(
|
|
|
309
311
|
return statement.get(directory)?.title ?? null
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
export async function getMostRecentSessionTitleForDirectory(
|
|
313
|
-
|
|
314
|
+
export async function getMostRecentSessionTitleForDirectory(
|
|
315
|
+
directory: string
|
|
316
|
+
): Promise<string | null> {
|
|
317
|
+
return withDatabase(database =>
|
|
318
|
+
getMostRecentSessionTitleForDirectoryFromDatabase(database, directory)
|
|
319
|
+
)
|
|
314
320
|
}
|
|
315
321
|
|
|
316
|
-
export function getMessageCountBySessionFromDatabase(
|
|
322
|
+
export function getMessageCountBySessionFromDatabase(
|
|
323
|
+
database: Database,
|
|
324
|
+
sessionID: string
|
|
325
|
+
): number {
|
|
317
326
|
return getMessageAggregate(database, sessionID).messageCount
|
|
318
327
|
}
|
|
319
328
|
|
|
@@ -321,7 +330,10 @@ export async function getMessageCountBySession(sessionID: string): Promise<numbe
|
|
|
321
330
|
return withDatabase(database => getMessageCountBySessionFromDatabase(database, sessionID))
|
|
322
331
|
}
|
|
323
332
|
|
|
324
|
-
export function getMessageCountByDirectoryFromDatabase(
|
|
333
|
+
export function getMessageCountByDirectoryFromDatabase(
|
|
334
|
+
database: Database,
|
|
335
|
+
directory: string
|
|
336
|
+
): number {
|
|
325
337
|
const statement = database.query<{ messageCount: number }, [string]>(`
|
|
326
338
|
SELECT COUNT(m.id) AS messageCount
|
|
327
339
|
FROM message m
|
|
@@ -336,7 +348,10 @@ export async function getMessageCountByDirectory(directory: string): Promise<num
|
|
|
336
348
|
return withDatabase(database => getMessageCountByDirectoryFromDatabase(database, directory))
|
|
337
349
|
}
|
|
338
350
|
|
|
339
|
-
export function getAssistantCostTotalBySessionFromDatabase(
|
|
351
|
+
export function getAssistantCostTotalBySessionFromDatabase(
|
|
352
|
+
database: Database,
|
|
353
|
+
sessionID: string
|
|
354
|
+
): number {
|
|
340
355
|
return getMessageAggregate(database, sessionID).totalCost
|
|
341
356
|
}
|
|
342
357
|
|