mux-sesh 1.4.0 → 1.5.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 +123 -7
- package/package.json +3 -3
- package/src/app.tsx +178 -35
- package/src/components/KeybindHelp.tsx +48 -2
- package/src/config/index.ts +206 -19
- package/src/config/listed-sessions.ts +36 -0
- package/src/config/session-rules.ts +101 -0
- package/src/handlers/actions.ts +93 -6
- package/src/handlers/keyboard.ts +114 -64
- package/src/items/order.ts +50 -0
- package/src/opencode/session.ts +1 -17
- package/src/opencode/stats.ts +1 -1
- package/src/preview/project.ts +235 -0
- package/src/projects/session-links.ts +31 -0
- package/src/search/index.ts +83 -47
- package/src/tmux/index.ts +58 -14
- package/src/tmux/projects.ts +151 -20
- package/src/tmux/workflows.ts +22 -0
- package/src/types/index.ts +49 -0
- package/src/ui/ItemList.tsx +21 -14
- package/src/ui/OpencodeSessionGroup.tsx +48 -42
- package/src/ui/SearchInput.tsx +19 -1
- package/src/ui/SessionDetailsPanel.tsx +179 -45
- package/src/ui/SessionList.tsx +67 -33
- package/src/ui/item-icon.ts +77 -0
- package/src/ui/list-window.ts +22 -0
- package/src/update/installation.ts +4 -15
- package/src/update/version.ts +2 -1
- package/src/util/glob.ts +47 -0
- package/src/util/terminal.ts +6 -20
package/src/handlers/keyboard.ts
CHANGED
|
@@ -1,65 +1,81 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
+
import type { Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
3
|
+
import { AppMode, ViewMode, KeybindMode, type Item, type OpencodeSessionStats } from '../types'
|
|
2
4
|
import { requestShutdown } from '../util/shutdown'
|
|
3
5
|
|
|
6
|
+
export interface KeyboardInput {
|
|
7
|
+
name?: string
|
|
8
|
+
ctrl?: boolean
|
|
9
|
+
shift?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export interface KeyboardHandlerContext {
|
|
5
13
|
appMode: AppMode
|
|
6
14
|
viewMode: ViewMode
|
|
7
|
-
items:
|
|
8
|
-
regularSessions:
|
|
9
|
-
opencodeSessions:
|
|
15
|
+
items: Item[]
|
|
16
|
+
regularSessions: Item[]
|
|
17
|
+
opencodeSessions: Item[]
|
|
10
18
|
cursor: number
|
|
11
19
|
opencodeCursor: number
|
|
12
20
|
searchQuery: string
|
|
13
21
|
renameTarget: string
|
|
14
|
-
projectItems:
|
|
15
|
-
sessionItems:
|
|
22
|
+
projectItems: Item[]
|
|
23
|
+
sessionItems: Item[]
|
|
16
24
|
prefixActive: boolean
|
|
17
|
-
prefixTimeoutRef:
|
|
18
|
-
textareaRef:
|
|
25
|
+
prefixTimeoutRef: MutableRefObject<NodeJS.Timeout | null>
|
|
26
|
+
textareaRef: MutableRefObject<TextareaRenderable | null>
|
|
19
27
|
|
|
20
28
|
setAppMode: (mode: AppMode) => void
|
|
21
29
|
setViewMode: (mode: ViewMode) => void
|
|
22
|
-
setCursor:
|
|
23
|
-
setOpencodeCursor:
|
|
30
|
+
setCursor: Dispatch<SetStateAction<number>>
|
|
31
|
+
setOpencodeCursor: Dispatch<SetStateAction<number>>
|
|
24
32
|
setSearchQuery: (query: string) => void
|
|
25
33
|
setRenameTarget: (target: string) => void
|
|
26
|
-
setAllItems:
|
|
27
|
-
setItems:
|
|
34
|
+
setAllItems: Dispatch<SetStateAction<Item[]>>
|
|
35
|
+
setItems: Dispatch<SetStateAction<Item[]>>
|
|
28
36
|
setPrefixActive: (active: boolean) => void
|
|
29
37
|
|
|
30
38
|
refreshItems: (forceViewMode?: ViewMode) => Promise<void>
|
|
31
|
-
handleSelect: (item:
|
|
39
|
+
handleSelect: (item: Item) => Promise<void>
|
|
32
40
|
handleKillSession: (sessionName: string) => Promise<void>
|
|
33
|
-
|
|
41
|
+
handleLastSession: () => Promise<void>
|
|
42
|
+
handleRootSession: (item?: Item) => Promise<void>
|
|
43
|
+
handleEditTarget: (item?: Item) => Promise<void>
|
|
44
|
+
loadOpencodeStatsForSession: (sessionName: string) => Promise<OpencodeSessionStats | null>
|
|
34
45
|
setMessage: (message: string) => void
|
|
35
46
|
}
|
|
36
47
|
|
|
48
|
+
function getKeyName(key: KeyboardInput): string {
|
|
49
|
+
return key.name ?? ''
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
export function handleNormalMode(
|
|
38
|
-
key:
|
|
53
|
+
key: KeyboardInput,
|
|
39
54
|
ctx: KeyboardHandlerContext,
|
|
40
55
|
keybindMode: KeybindMode = 'vim'
|
|
41
56
|
) {
|
|
57
|
+
const keyName = getKeyName(key)
|
|
42
58
|
// Standard mode requires Ctrl for most actions
|
|
43
59
|
const isStandard = keybindMode === 'standard'
|
|
44
60
|
|
|
45
61
|
// Handle quit (q for vim, Ctrl+Q or Escape for standard)
|
|
46
62
|
if (
|
|
47
|
-
(isStandard && ((key.ctrl &&
|
|
48
|
-
(!isStandard && (
|
|
63
|
+
(isStandard && ((key.ctrl && keyName === 'q') || keyName === 'escape')) ||
|
|
64
|
+
(!isStandard && (keyName === 'q' || keyName === 'escape'))
|
|
49
65
|
) {
|
|
50
66
|
void requestShutdown(0)
|
|
51
67
|
return
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
// Handle search mode (i for vim, Ctrl+I for standard)
|
|
55
|
-
if ((!isStandard &&
|
|
71
|
+
if ((!isStandard && keyName === 'i') || (isStandard && key.ctrl && keyName === 'i')) {
|
|
56
72
|
ctx.setAppMode(AppMode.Search)
|
|
57
73
|
ctx.setSearchQuery('')
|
|
58
74
|
return
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
// Handle new session (n for vim, Ctrl+N for standard)
|
|
62
|
-
if ((!isStandard &&
|
|
78
|
+
if ((!isStandard && keyName === 'n') || (isStandard && key.ctrl && keyName === 'n')) {
|
|
63
79
|
ctx.setAppMode(AppMode.NewSession)
|
|
64
80
|
if (ctx.viewMode === ViewMode.Sessions) {
|
|
65
81
|
}
|
|
@@ -72,7 +88,7 @@ export function handleNormalMode(
|
|
|
72
88
|
}
|
|
73
89
|
|
|
74
90
|
// Handle opencode mode (o for vim, Ctrl+O for standard)
|
|
75
|
-
if ((!isStandard &&
|
|
91
|
+
if ((!isStandard && keyName === 'o') || (isStandard && key.ctrl && keyName === 'o')) {
|
|
76
92
|
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
77
93
|
ctx.setAppMode(AppMode.OpencodeManage)
|
|
78
94
|
ctx.setOpencodeCursor(0)
|
|
@@ -81,9 +97,29 @@ export function handleNormalMode(
|
|
|
81
97
|
return
|
|
82
98
|
}
|
|
83
99
|
|
|
100
|
+
if ((!isStandard && keyName === 'l') || (isStandard && key.ctrl && keyName === 'l')) {
|
|
101
|
+
void ctx.handleLastSession()
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if ((!isStandard && keyName === 'g') || (isStandard && key.ctrl && keyName === 'g')) {
|
|
106
|
+
const selectedItem =
|
|
107
|
+
ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
108
|
+
void ctx.handleRootSession(selectedItem)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ((!isStandard && keyName === 'e') || (isStandard && key.ctrl && keyName === 'e')) {
|
|
113
|
+
const selectedItem = ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
114
|
+
if (selectedItem?.itemKind === 'configured') {
|
|
115
|
+
void ctx.handleEditTarget(selectedItem)
|
|
116
|
+
}
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
84
120
|
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
85
|
-
if ((!isStandard &&
|
|
86
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.
|
|
121
|
+
if ((!isStandard && keyName === 'd') || (isStandard && key.ctrl && keyName === 'd')) {
|
|
122
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
87
123
|
ctx.handleKillSession(ctx.regularSessions[ctx.cursor].title)
|
|
88
124
|
}
|
|
89
125
|
return
|
|
@@ -91,10 +127,10 @@ export function handleNormalMode(
|
|
|
91
127
|
|
|
92
128
|
// Handle rename (r for vim, Ctrl+R for standard)
|
|
93
129
|
if (
|
|
94
|
-
(!isStandard &&
|
|
95
|
-
(isStandard && key.ctrl &&
|
|
130
|
+
(!isStandard && keyName === 'r') ||
|
|
131
|
+
(isStandard && key.ctrl && keyName === 'r' && !key.shift)
|
|
96
132
|
) {
|
|
97
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.
|
|
133
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
98
134
|
ctx.setAppMode(AppMode.Rename)
|
|
99
135
|
ctx.setRenameTarget(ctx.regularSessions[ctx.cursor].title)
|
|
100
136
|
ctx.setSearchQuery(ctx.regularSessions[ctx.cursor].title)
|
|
@@ -104,8 +140,8 @@ export function handleNormalMode(
|
|
|
104
140
|
|
|
105
141
|
// Handle refresh (R for vim, Ctrl+Shift+R for standard)
|
|
106
142
|
if (
|
|
107
|
-
(!isStandard &&
|
|
108
|
-
(isStandard && key.ctrl && key.shift &&
|
|
143
|
+
(!isStandard && keyName === 'R') ||
|
|
144
|
+
(isStandard && key.ctrl && key.shift && keyName === 'r')
|
|
109
145
|
) {
|
|
110
146
|
ctx.refreshItems()
|
|
111
147
|
ctx.setMessage('Refreshed')
|
|
@@ -115,12 +151,12 @@ export function handleNormalMode(
|
|
|
115
151
|
|
|
116
152
|
// Handle view mode switches (vim only)
|
|
117
153
|
if (!isStandard) {
|
|
118
|
-
if (
|
|
154
|
+
if (keyName === 's') {
|
|
119
155
|
ctx.setViewMode(ViewMode.Sessions)
|
|
120
156
|
ctx.refreshItems(ViewMode.Sessions)
|
|
121
157
|
return
|
|
122
158
|
}
|
|
123
|
-
if (
|
|
159
|
+
if (keyName === 'p') {
|
|
124
160
|
ctx.setViewMode(ViewMode.Projects)
|
|
125
161
|
ctx.refreshItems(ViewMode.Projects)
|
|
126
162
|
return
|
|
@@ -128,7 +164,7 @@ export function handleNormalMode(
|
|
|
128
164
|
}
|
|
129
165
|
|
|
130
166
|
// Handle navigation
|
|
131
|
-
if (
|
|
167
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
132
168
|
if (ctx.viewMode === ViewMode.Sessions) {
|
|
133
169
|
ctx.setCursor(c => Math.min(c + 1, ctx.regularSessions.length - 1))
|
|
134
170
|
} else {
|
|
@@ -137,13 +173,13 @@ export function handleNormalMode(
|
|
|
137
173
|
return
|
|
138
174
|
}
|
|
139
175
|
|
|
140
|
-
if (
|
|
176
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
141
177
|
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
142
178
|
return
|
|
143
179
|
}
|
|
144
180
|
|
|
145
181
|
// Handle selection
|
|
146
|
-
if (
|
|
182
|
+
if (keyName === 'return') {
|
|
147
183
|
if (ctx.regularSessions[ctx.cursor]) {
|
|
148
184
|
ctx.handleSelect(ctx.regularSessions[ctx.cursor])
|
|
149
185
|
}
|
|
@@ -151,8 +187,8 @@ export function handleNormalMode(
|
|
|
151
187
|
}
|
|
152
188
|
|
|
153
189
|
// Handle number shortcuts (vim only)
|
|
154
|
-
if (!isStandard &&
|
|
155
|
-
const num = parseInt(
|
|
190
|
+
if (!isStandard && keyName >= '1' && keyName <= '9') {
|
|
191
|
+
const num = parseInt(keyName, 10) - 1
|
|
156
192
|
if (num >= 0 && num < ctx.regularSessions.length) {
|
|
157
193
|
ctx.handleSelect(ctx.regularSessions[num])
|
|
158
194
|
}
|
|
@@ -160,24 +196,25 @@ export function handleNormalMode(
|
|
|
160
196
|
}
|
|
161
197
|
|
|
162
198
|
export function handleOpencodeManageMode(
|
|
163
|
-
key:
|
|
199
|
+
key: KeyboardInput,
|
|
164
200
|
ctx: KeyboardHandlerContext,
|
|
165
201
|
keybindMode: KeybindMode = 'vim'
|
|
166
202
|
) {
|
|
203
|
+
const keyName = getKeyName(key)
|
|
167
204
|
const isStandard = keybindMode === 'standard'
|
|
168
205
|
|
|
169
206
|
// Handle back/exit (o/Esc for vim, Ctrl+O/Esc for standard)
|
|
170
207
|
if (
|
|
171
|
-
|
|
172
|
-
(!isStandard &&
|
|
173
|
-
(isStandard && key.ctrl &&
|
|
208
|
+
keyName === 'escape' ||
|
|
209
|
+
(!isStandard && keyName === 'o') ||
|
|
210
|
+
(isStandard && key.ctrl && keyName === 'o')
|
|
174
211
|
) {
|
|
175
212
|
ctx.setAppMode(AppMode.Normal)
|
|
176
213
|
return
|
|
177
214
|
}
|
|
178
215
|
|
|
179
216
|
// Handle navigation down
|
|
180
|
-
if (
|
|
217
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
181
218
|
ctx.setOpencodeCursor(c => {
|
|
182
219
|
const newCursor = Math.min(c + 1, ctx.opencodeSessions.length - 1)
|
|
183
220
|
if (newCursor !== c && ctx.opencodeSessions[newCursor]) {
|
|
@@ -189,7 +226,7 @@ export function handleOpencodeManageMode(
|
|
|
189
226
|
}
|
|
190
227
|
|
|
191
228
|
// Handle navigation up
|
|
192
|
-
if (
|
|
229
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
193
230
|
ctx.setOpencodeCursor(c => {
|
|
194
231
|
const newCursor = Math.max(c - 1, 0)
|
|
195
232
|
if (newCursor !== c && ctx.opencodeSessions[newCursor]) {
|
|
@@ -201,7 +238,7 @@ export function handleOpencodeManageMode(
|
|
|
201
238
|
}
|
|
202
239
|
|
|
203
240
|
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
204
|
-
if ((!isStandard &&
|
|
241
|
+
if ((!isStandard && keyName === 'd') || (isStandard && key.ctrl && keyName === 'd')) {
|
|
205
242
|
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
206
243
|
ctx.handleKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
207
244
|
}
|
|
@@ -209,7 +246,7 @@ export function handleOpencodeManageMode(
|
|
|
209
246
|
}
|
|
210
247
|
|
|
211
248
|
// Handle rename (r for vim, Ctrl+R for standard)
|
|
212
|
-
if ((!isStandard &&
|
|
249
|
+
if ((!isStandard && keyName === 'r') || (isStandard && key.ctrl && keyName === 'r')) {
|
|
213
250
|
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
214
251
|
ctx.setAppMode(AppMode.Rename)
|
|
215
252
|
ctx.setRenameTarget(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
@@ -219,10 +256,11 @@ export function handleOpencodeManageMode(
|
|
|
219
256
|
}
|
|
220
257
|
|
|
221
258
|
export function handleSearchMode(
|
|
222
|
-
key:
|
|
259
|
+
key: KeyboardInput,
|
|
223
260
|
ctx: KeyboardHandlerContext,
|
|
224
261
|
keybindMode: KeybindMode = 'vim'
|
|
225
262
|
) {
|
|
263
|
+
const keyName = getKeyName(key)
|
|
226
264
|
const isStandard = keybindMode === 'standard'
|
|
227
265
|
|
|
228
266
|
// Standard mode: Prefix key system with Ctrl+X
|
|
@@ -236,7 +274,7 @@ export function handleSearchMode(
|
|
|
236
274
|
}
|
|
237
275
|
ctx.setPrefixActive(false)
|
|
238
276
|
|
|
239
|
-
switch (
|
|
277
|
+
switch (keyName) {
|
|
240
278
|
case 'd': // Ctrl+X d - delete/kill
|
|
241
279
|
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
242
280
|
ctx.handleKillSession(ctx.items[ctx.cursor].title)
|
|
@@ -257,18 +295,28 @@ export function handleSearchMode(
|
|
|
257
295
|
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
258
296
|
}
|
|
259
297
|
return
|
|
260
|
-
case '
|
|
298
|
+
case 'l': // Ctrl+X l - last session
|
|
299
|
+
void ctx.handleLastSession()
|
|
300
|
+
return
|
|
301
|
+
case 'g': { // Ctrl+X g - root session
|
|
302
|
+
const selectedItem = ctx.viewMode === ViewMode.Sessions ? ctx.items[ctx.cursor] : ctx.items[ctx.cursor]
|
|
303
|
+
void ctx.handleRootSession(selectedItem)
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
case 'r':
|
|
307
|
+
if (key.shift) {
|
|
308
|
+
ctx.refreshItems()
|
|
309
|
+
ctx.setMessage('Refreshed')
|
|
310
|
+
setTimeout(() => ctx.setMessage(''), 2000)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
|
|
261
314
|
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
262
315
|
ctx.setAppMode(AppMode.Rename)
|
|
263
316
|
ctx.setRenameTarget(ctx.items[ctx.cursor].title)
|
|
264
317
|
ctx.setSearchQuery(ctx.items[ctx.cursor].title)
|
|
265
318
|
}
|
|
266
319
|
return
|
|
267
|
-
case 'R': // Ctrl+X R - refresh
|
|
268
|
-
ctx.refreshItems()
|
|
269
|
-
ctx.setMessage('Refreshed')
|
|
270
|
-
setTimeout(() => ctx.setMessage(''), 2000)
|
|
271
|
-
return
|
|
272
320
|
default:
|
|
273
321
|
// Not a valid prefix command, ignore
|
|
274
322
|
return
|
|
@@ -276,7 +324,7 @@ export function handleSearchMode(
|
|
|
276
324
|
}
|
|
277
325
|
|
|
278
326
|
// Handle Ctrl+X prefix activation
|
|
279
|
-
if (key.ctrl &&
|
|
327
|
+
if (key.ctrl && keyName === 'x') {
|
|
280
328
|
ctx.setPrefixActive(true)
|
|
281
329
|
|
|
282
330
|
// Clear prefix after 2 seconds if no key pressed
|
|
@@ -288,14 +336,14 @@ export function handleSearchMode(
|
|
|
288
336
|
}
|
|
289
337
|
|
|
290
338
|
// Ctrl+Q to quit (immediate, no prefix needed)
|
|
291
|
-
if (key.ctrl &&
|
|
339
|
+
if (key.ctrl && keyName === 'q') {
|
|
292
340
|
void requestShutdown(0)
|
|
293
341
|
return
|
|
294
342
|
}
|
|
295
343
|
}
|
|
296
344
|
|
|
297
345
|
// Handle Esc differently based on mode
|
|
298
|
-
if (
|
|
346
|
+
if (keyName === 'escape') {
|
|
299
347
|
if (isStandard) {
|
|
300
348
|
// Standard mode: just clear search, stay in search mode
|
|
301
349
|
ctx.setSearchQuery('')
|
|
@@ -309,7 +357,7 @@ export function handleSearchMode(
|
|
|
309
357
|
return
|
|
310
358
|
}
|
|
311
359
|
|
|
312
|
-
switch (
|
|
360
|
+
switch (keyName) {
|
|
313
361
|
case 'return':
|
|
314
362
|
if (ctx.items.length > 0) {
|
|
315
363
|
ctx.handleSelect(ctx.items[0])
|
|
@@ -325,16 +373,17 @@ export function handleSearchMode(
|
|
|
325
373
|
}
|
|
326
374
|
|
|
327
375
|
export function handleNewSessionMode(
|
|
328
|
-
key:
|
|
376
|
+
key: KeyboardInput,
|
|
329
377
|
ctx: KeyboardHandlerContext,
|
|
330
378
|
keybindMode: KeybindMode = 'vim'
|
|
331
379
|
) {
|
|
380
|
+
const keyName = getKeyName(key)
|
|
332
381
|
const isStandard = keybindMode === 'standard'
|
|
333
382
|
|
|
334
383
|
// Handle Ctrl keybinds in standard mode
|
|
335
384
|
if (isStandard && key.ctrl) {
|
|
336
385
|
// Ctrl+I to switch to search mode
|
|
337
|
-
|
|
386
|
+
if (keyName === 'i') {
|
|
338
387
|
ctx.setAppMode(AppMode.Search)
|
|
339
388
|
ctx.setViewMode(ViewMode.Sessions)
|
|
340
389
|
ctx.setAllItems(ctx.sessionItems)
|
|
@@ -344,14 +393,14 @@ export function handleNewSessionMode(
|
|
|
344
393
|
}
|
|
345
394
|
|
|
346
395
|
// Ctrl+D to delete session (if on sessions view)
|
|
347
|
-
|
|
396
|
+
if (keyName === 'd' && ctx.items[ctx.cursor]?.isSession) {
|
|
348
397
|
ctx.handleKillSession(ctx.items[ctx.cursor].title)
|
|
349
398
|
return
|
|
350
399
|
}
|
|
351
400
|
}
|
|
352
401
|
|
|
353
402
|
// Handle Esc differently based on mode
|
|
354
|
-
if (
|
|
403
|
+
if (keyName === 'escape') {
|
|
355
404
|
if (isStandard) {
|
|
356
405
|
// Standard mode: return to search mode (always in insert mode)
|
|
357
406
|
ctx.setAppMode(AppMode.Search)
|
|
@@ -370,7 +419,7 @@ export function handleNewSessionMode(
|
|
|
370
419
|
return
|
|
371
420
|
}
|
|
372
421
|
|
|
373
|
-
switch (
|
|
422
|
+
switch (keyName) {
|
|
374
423
|
case 'return':
|
|
375
424
|
break
|
|
376
425
|
case 'down':
|
|
@@ -383,16 +432,17 @@ export function handleNewSessionMode(
|
|
|
383
432
|
}
|
|
384
433
|
|
|
385
434
|
export function handleRenameMode(
|
|
386
|
-
key:
|
|
435
|
+
key: KeyboardInput,
|
|
387
436
|
ctx: KeyboardHandlerContext,
|
|
388
437
|
keybindMode: KeybindMode = 'vim'
|
|
389
438
|
) {
|
|
439
|
+
const keyName = getKeyName(key)
|
|
390
440
|
const isStandard = keybindMode === 'standard'
|
|
391
441
|
|
|
392
442
|
// Handle Ctrl keybinds in standard mode
|
|
393
443
|
if (isStandard && key.ctrl) {
|
|
394
444
|
// Ctrl+I to switch to search mode
|
|
395
|
-
|
|
445
|
+
if (keyName === 'i') {
|
|
396
446
|
ctx.setAppMode(AppMode.Search)
|
|
397
447
|
ctx.setSearchQuery('')
|
|
398
448
|
ctx.setRenameTarget('')
|
|
@@ -400,7 +450,7 @@ export function handleRenameMode(
|
|
|
400
450
|
}
|
|
401
451
|
|
|
402
452
|
// Ctrl+D to delete the rename target session
|
|
403
|
-
|
|
453
|
+
if (keyName === 'd' && ctx.renameTarget) {
|
|
404
454
|
ctx.handleKillSession(ctx.renameTarget)
|
|
405
455
|
ctx.setAppMode(AppMode.Search)
|
|
406
456
|
ctx.setSearchQuery('')
|
|
@@ -410,7 +460,7 @@ export function handleRenameMode(
|
|
|
410
460
|
}
|
|
411
461
|
|
|
412
462
|
// Handle Esc differently based on mode
|
|
413
|
-
if (
|
|
463
|
+
if (keyName === 'escape') {
|
|
414
464
|
if (isStandard) {
|
|
415
465
|
// Standard mode: return to search mode (always in insert mode)
|
|
416
466
|
ctx.setAppMode(AppMode.Search)
|
|
@@ -427,7 +477,7 @@ export function handleRenameMode(
|
|
|
427
477
|
return
|
|
428
478
|
}
|
|
429
479
|
|
|
430
|
-
switch (
|
|
480
|
+
switch (keyName) {
|
|
431
481
|
case 'return':
|
|
432
482
|
break
|
|
433
483
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Item, SortOrder } from '../types'
|
|
2
|
+
|
|
3
|
+
function compareByTitle(left: Item, right: Item): number {
|
|
4
|
+
return left.title.localeCompare(right.title)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isOpencodeSession(item: Item): boolean {
|
|
8
|
+
return item.isSession && item.title.startsWith('opencode-')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isConfiguredSession(item: Item): boolean {
|
|
12
|
+
return item.itemKind === 'configured'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function sortByGroup(items: Item[], groups: Array<'live' | 'configured'>): Item[] {
|
|
16
|
+
const configuredItems = items.filter(isConfiguredSession).sort(compareByTitle)
|
|
17
|
+
const liveItems = items.filter(item => !isConfiguredSession(item)).sort(compareByTitle)
|
|
18
|
+
const groupedItems = new Map([
|
|
19
|
+
['configured', configuredItems],
|
|
20
|
+
['live', liveItems],
|
|
21
|
+
])
|
|
22
|
+
|
|
23
|
+
return groups.flatMap(group => groupedItems.get(group) ?? [])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function orderSessionItems(items: Item[], sortOrder: SortOrder = 'live-first'): Item[] {
|
|
27
|
+
const opencodeItems = items.filter(isOpencodeSession).sort(compareByTitle)
|
|
28
|
+
const regularItems = items.filter(item => !isOpencodeSession(item))
|
|
29
|
+
|
|
30
|
+
const orderedRegularItems =
|
|
31
|
+
sortOrder === 'configured-first'
|
|
32
|
+
? sortByGroup(regularItems, ['configured', 'live'])
|
|
33
|
+
: sortOrder === 'alphabetical'
|
|
34
|
+
? [...regularItems].sort(compareByTitle)
|
|
35
|
+
: sortByGroup(regularItems, ['live', 'configured'])
|
|
36
|
+
|
|
37
|
+
return [...orderedRegularItems, ...opencodeItems]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function orderProjectItems(items: Item[], sortOrder: SortOrder = 'live-first'): Item[] {
|
|
41
|
+
if (sortOrder === 'alphabetical') {
|
|
42
|
+
return [...items].sort(compareByTitle)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return items
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getSessionSection(item: Item): 'live' | 'configured' {
|
|
49
|
+
return item.itemKind === 'configured' ? 'configured' : 'live'
|
|
50
|
+
}
|
package/src/opencode/session.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from './sqlite'
|
|
11
11
|
import { getLastMessageTokens } from './tokens'
|
|
12
12
|
import type { OpencodeStats } from './types'
|
|
13
|
+
import { getTmuxSessionDirectory } from '../tmux'
|
|
13
14
|
|
|
14
15
|
function toSummaryValue(value: number | null): number {
|
|
15
16
|
return value ?? 0
|
|
@@ -38,23 +39,6 @@ async function buildSessionStats(row: OpencodeSessionRow): Promise<OpencodeStats
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
export async function getTmuxSessionDirectory(sessionName: string): Promise<string> {
|
|
42
|
-
const proc = spawn(['tmux', 'display-message', '-t', sessionName, '-p', '#{pane_current_path}'])
|
|
43
|
-
const output = await new Response(proc.stdout).text()
|
|
44
|
-
await proc.exited
|
|
45
|
-
|
|
46
|
-
if (proc.exitCode !== 0) {
|
|
47
|
-
throw new Error(`Failed to resolve tmux directory for session '${sessionName}'`)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const directory = output.trim()
|
|
51
|
-
if (!directory) {
|
|
52
|
-
throw new Error(`tmux returned an empty directory for session '${sessionName}'`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return directory
|
|
56
|
-
}
|
|
57
|
-
|
|
58
42
|
export async function getMessageCount(sessionID: string): Promise<number> {
|
|
59
43
|
if (!sessionID) {
|
|
60
44
|
return 0
|
package/src/opencode/stats.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getTmuxSessionDirectory,
|
|
3
2
|
getActiveOpencodeSession,
|
|
4
3
|
getAggregatedOpencodeStats,
|
|
5
4
|
getMostRecentSessionForDirectory,
|
|
6
5
|
} from './session'
|
|
7
6
|
import type { OpencodeStats } from './types'
|
|
7
|
+
import { getTmuxSessionDirectory } from '../tmux'
|
|
8
8
|
|
|
9
9
|
export async function getOpencodeSessionStats(
|
|
10
10
|
tmuxSessionName: string
|