mux-sesh 2.0.0 → 2.0.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/LICENSE +2 -2
- package/README.md +150 -161
- package/bin/mux-sesh +62 -0
- package/bin/platform.sh +139 -0
- package/bin/postinstall +22 -0
- package/package.json +30 -33
- package/config.example.json +0 -7
- package/src/app.tsx +0 -416
- package/src/components/KeybindHelp.tsx +0 -222
- package/src/config/index.ts +0 -52
- package/src/handlers/actions.ts +0 -86
- package/src/handlers/keyboard.ts +0 -431
- package/src/index.tsx +0 -9
- package/src/opencode/constants.ts +0 -5
- package/src/opencode/index.ts +0 -19
- package/src/opencode/parser.ts +0 -54
- package/src/opencode/session.ts +0 -278
- package/src/opencode/stats.ts +0 -34
- package/src/opencode/tokens.ts +0 -143
- package/src/opencode/types.ts +0 -33
- package/src/search/index.ts +0 -148
- package/src/styles/theme.ts +0 -46
- package/src/tmux/index.ts +0 -187
- package/src/tmux/projects.ts +0 -55
- package/src/types/index.ts +0 -80
- package/src/ui/HighlightedText.tsx +0 -61
- package/src/ui/ItemList.tsx +0 -93
- package/src/ui/OpencodeSessionGroup.tsx +0 -63
- package/src/ui/OpencodeStatsPanel.tsx +0 -178
- package/src/ui/SearchInput.tsx +0 -42
- package/src/ui/SessionDetailsPanel.tsx +0 -94
- package/src/ui/SessionList.tsx +0 -57
- package/src/ui/SessionStats.tsx +0 -30
- package/src/util/github.ts +0 -55
- package/src/util/time.ts +0 -48
package/src/handlers/keyboard.ts
DELETED
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import { AppMode, ViewMode, KeybindMode } from '../types'
|
|
2
|
-
|
|
3
|
-
export interface KeyboardHandlerContext {
|
|
4
|
-
appMode: AppMode
|
|
5
|
-
viewMode: ViewMode
|
|
6
|
-
items: any[]
|
|
7
|
-
regularSessions: any[]
|
|
8
|
-
opencodeSessions: any[]
|
|
9
|
-
cursor: number
|
|
10
|
-
opencodeCursor: number
|
|
11
|
-
searchQuery: string
|
|
12
|
-
renameTarget: string
|
|
13
|
-
projectItems: any[]
|
|
14
|
-
sessionItems: any[]
|
|
15
|
-
prefixActive: boolean
|
|
16
|
-
prefixTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>
|
|
17
|
-
textareaRef: React.MutableRefObject<any>
|
|
18
|
-
|
|
19
|
-
setAppMode: (mode: AppMode) => void
|
|
20
|
-
setViewMode: (mode: ViewMode) => void
|
|
21
|
-
setCursor: (cursor: number | ((prev: number) => number)) => void
|
|
22
|
-
setOpencodeCursor: (cursor: number | ((prev: number) => number)) => void
|
|
23
|
-
setSearchQuery: (query: string) => void
|
|
24
|
-
setRenameTarget: (target: string) => void
|
|
25
|
-
setAllItems: (items: any[]) => void
|
|
26
|
-
setItems: (items: any[]) => void
|
|
27
|
-
setPrefixActive: (active: boolean) => void
|
|
28
|
-
|
|
29
|
-
refreshItems: (forceViewMode?: ViewMode) => Promise<void>
|
|
30
|
-
handleSelect: (item: any) => Promise<void>
|
|
31
|
-
handleKillSession: (sessionName: string) => Promise<void>
|
|
32
|
-
loadOpencodeStatsForSession: (sessionName: string) => Promise<any>
|
|
33
|
-
setMessage: (message: string) => void
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function handleNormalMode(
|
|
37
|
-
key: any,
|
|
38
|
-
ctx: KeyboardHandlerContext,
|
|
39
|
-
keybindMode: KeybindMode = 'vim'
|
|
40
|
-
) {
|
|
41
|
-
// Standard mode requires Ctrl for most actions
|
|
42
|
-
const isStandard = keybindMode === 'standard'
|
|
43
|
-
|
|
44
|
-
// Handle quit (q for vim, Ctrl+Q or Escape for standard)
|
|
45
|
-
if (
|
|
46
|
-
(isStandard && ((key.ctrl && key.name === 'q') || key.name === 'escape')) ||
|
|
47
|
-
(!isStandard && (key.name === 'q' || key.name === 'escape'))
|
|
48
|
-
) {
|
|
49
|
-
process.exit(0)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Handle search mode (i for vim, Ctrl+I for standard)
|
|
53
|
-
if ((!isStandard && key.name === 'i') || (isStandard && key.ctrl && key.name === 'i')) {
|
|
54
|
-
ctx.setAppMode(AppMode.Search)
|
|
55
|
-
ctx.setSearchQuery('')
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Handle new session (n for vim, Ctrl+N for standard)
|
|
60
|
-
if ((!isStandard && key.name === 'n') || (isStandard && key.ctrl && key.name === 'n')) {
|
|
61
|
-
ctx.setAppMode(AppMode.NewSession)
|
|
62
|
-
if (ctx.viewMode === ViewMode.Sessions) {
|
|
63
|
-
}
|
|
64
|
-
ctx.setViewMode(ViewMode.Projects)
|
|
65
|
-
ctx.setAllItems(ctx.projectItems)
|
|
66
|
-
ctx.setItems(ctx.projectItems)
|
|
67
|
-
ctx.setCursor(Math.max(0, ctx.projectItems.length - 1))
|
|
68
|
-
ctx.setSearchQuery('')
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Handle opencode mode (o for vim, Ctrl+O for standard)
|
|
73
|
-
if ((!isStandard && key.name === 'o') || (isStandard && key.ctrl && key.name === 'o')) {
|
|
74
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
75
|
-
ctx.setAppMode(AppMode.OpencodeManage)
|
|
76
|
-
ctx.setOpencodeCursor(0)
|
|
77
|
-
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
78
|
-
}
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
83
|
-
if ((!isStandard && key.name === 'd') || (isStandard && key.ctrl && key.name === 'd')) {
|
|
84
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
85
|
-
ctx.handleKillSession(ctx.items[ctx.cursor].title)
|
|
86
|
-
}
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Handle rename (r for vim, Ctrl+R for standard)
|
|
91
|
-
if (
|
|
92
|
-
(!isStandard && key.name === 'r') ||
|
|
93
|
-
(isStandard && key.ctrl && key.name === 'r' && !key.shift)
|
|
94
|
-
) {
|
|
95
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
96
|
-
ctx.setAppMode(AppMode.Rename)
|
|
97
|
-
ctx.setRenameTarget(ctx.items[ctx.cursor].title)
|
|
98
|
-
ctx.setSearchQuery(ctx.items[ctx.cursor].title)
|
|
99
|
-
}
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Handle refresh (R for vim, Ctrl+Shift+R for standard)
|
|
104
|
-
if (
|
|
105
|
-
(!isStandard && key.name === 'R') ||
|
|
106
|
-
(isStandard && key.ctrl && key.shift && key.name === 'r')
|
|
107
|
-
) {
|
|
108
|
-
ctx.refreshItems()
|
|
109
|
-
ctx.setMessage('Refreshed')
|
|
110
|
-
setTimeout(() => ctx.setMessage(''), 2000)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Handle view mode switches (vim only)
|
|
115
|
-
if (!isStandard) {
|
|
116
|
-
if (key.name === 's') {
|
|
117
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
118
|
-
ctx.refreshItems(ViewMode.Sessions)
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
if (key.name === 'p') {
|
|
122
|
-
ctx.setViewMode(ViewMode.Projects)
|
|
123
|
-
ctx.refreshItems(ViewMode.Projects)
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Handle navigation
|
|
129
|
-
if (key.name === 'down' || (!isStandard && key.name === 'j')) {
|
|
130
|
-
if (ctx.viewMode === ViewMode.Sessions) {
|
|
131
|
-
ctx.setCursor(c => Math.min(c + 1, ctx.regularSessions.length - 1))
|
|
132
|
-
} else {
|
|
133
|
-
ctx.setCursor(c => Math.min(c + 1, ctx.items.length - 1))
|
|
134
|
-
}
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (key.name === 'up' || (!isStandard && key.name === 'k')) {
|
|
139
|
-
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Handle selection
|
|
144
|
-
if (key.name === 'return') {
|
|
145
|
-
if (ctx.items[ctx.cursor]) {
|
|
146
|
-
ctx.handleSelect(ctx.items[ctx.cursor])
|
|
147
|
-
}
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Handle number shortcuts (vim only)
|
|
152
|
-
if (!isStandard && key.name >= '1' && key.name <= '9') {
|
|
153
|
-
const num = parseInt(key.name) - 1
|
|
154
|
-
if (num >= 0 && num < ctx.items.length) {
|
|
155
|
-
ctx.handleSelect(ctx.items[num])
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function handleOpencodeManageMode(
|
|
161
|
-
key: any,
|
|
162
|
-
ctx: KeyboardHandlerContext,
|
|
163
|
-
keybindMode: KeybindMode = 'vim'
|
|
164
|
-
) {
|
|
165
|
-
const isStandard = keybindMode === 'standard'
|
|
166
|
-
|
|
167
|
-
// Handle back/exit (o/Esc for vim, Ctrl+O/Esc for standard)
|
|
168
|
-
if (
|
|
169
|
-
key.name === 'escape' ||
|
|
170
|
-
(!isStandard && key.name === 'o') ||
|
|
171
|
-
(isStandard && key.ctrl && key.name === 'o')
|
|
172
|
-
) {
|
|
173
|
-
ctx.setAppMode(AppMode.Normal)
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Handle navigation down
|
|
178
|
-
if (key.name === 'down' || (!isStandard && key.name === 'j')) {
|
|
179
|
-
ctx.setOpencodeCursor(c => {
|
|
180
|
-
const newCursor = Math.min(c + 1, ctx.opencodeSessions.length - 1)
|
|
181
|
-
if (newCursor !== c) {
|
|
182
|
-
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[newCursor].title)
|
|
183
|
-
}
|
|
184
|
-
return newCursor
|
|
185
|
-
})
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Handle navigation up
|
|
190
|
-
if (key.name === 'up' || (!isStandard && key.name === 'k')) {
|
|
191
|
-
ctx.setOpencodeCursor(c => {
|
|
192
|
-
const newCursor = Math.max(c - 1, 0)
|
|
193
|
-
if (newCursor !== c) {
|
|
194
|
-
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[newCursor].title)
|
|
195
|
-
}
|
|
196
|
-
return newCursor
|
|
197
|
-
})
|
|
198
|
-
return
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
202
|
-
if ((!isStandard && key.name === 'd') || (isStandard && key.ctrl && key.name === 'd')) {
|
|
203
|
-
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
204
|
-
ctx.handleKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
205
|
-
}
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Handle rename (r for vim, Ctrl+R for standard)
|
|
210
|
-
if ((!isStandard && key.name === 'r') || (isStandard && key.ctrl && key.name === 'r')) {
|
|
211
|
-
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
212
|
-
ctx.setAppMode(AppMode.Rename)
|
|
213
|
-
ctx.setRenameTarget(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
214
|
-
ctx.setSearchQuery(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export function handleSearchMode(
|
|
220
|
-
key: any,
|
|
221
|
-
ctx: KeyboardHandlerContext,
|
|
222
|
-
keybindMode: KeybindMode = 'vim'
|
|
223
|
-
) {
|
|
224
|
-
const isStandard = keybindMode === 'standard'
|
|
225
|
-
|
|
226
|
-
// Standard mode: Prefix key system with Ctrl+X
|
|
227
|
-
if (isStandard) {
|
|
228
|
-
// If prefix is active, handle single-letter commands
|
|
229
|
-
if (ctx.prefixActive) {
|
|
230
|
-
// Clear prefix timeout
|
|
231
|
-
if (ctx.prefixTimeoutRef.current) {
|
|
232
|
-
clearTimeout(ctx.prefixTimeoutRef.current)
|
|
233
|
-
ctx.prefixTimeoutRef.current = null
|
|
234
|
-
}
|
|
235
|
-
ctx.setPrefixActive(false)
|
|
236
|
-
|
|
237
|
-
switch (key.name) {
|
|
238
|
-
case 'd': // Ctrl+X d - delete/kill
|
|
239
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
240
|
-
ctx.handleKillSession(ctx.items[ctx.cursor].title)
|
|
241
|
-
}
|
|
242
|
-
return
|
|
243
|
-
case 'n': // Ctrl+X n - new session
|
|
244
|
-
ctx.setSearchQuery('')
|
|
245
|
-
ctx.setAppMode(AppMode.NewSession)
|
|
246
|
-
ctx.setViewMode(ViewMode.Projects)
|
|
247
|
-
ctx.setAllItems(ctx.projectItems)
|
|
248
|
-
ctx.setItems(ctx.projectItems)
|
|
249
|
-
ctx.setCursor(Math.max(0, ctx.projectItems.length - 1))
|
|
250
|
-
return
|
|
251
|
-
case 'o': // Ctrl+X o - opencode
|
|
252
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
253
|
-
ctx.setAppMode(AppMode.OpencodeManage)
|
|
254
|
-
ctx.setOpencodeCursor(0)
|
|
255
|
-
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
256
|
-
}
|
|
257
|
-
return
|
|
258
|
-
case 'r': // Ctrl+X r - rename
|
|
259
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
260
|
-
ctx.setAppMode(AppMode.Rename)
|
|
261
|
-
ctx.setRenameTarget(ctx.items[ctx.cursor].title)
|
|
262
|
-
ctx.setSearchQuery(ctx.items[ctx.cursor].title)
|
|
263
|
-
}
|
|
264
|
-
return
|
|
265
|
-
case 'R': // Ctrl+X R - refresh
|
|
266
|
-
ctx.refreshItems()
|
|
267
|
-
ctx.setMessage('Refreshed')
|
|
268
|
-
setTimeout(() => ctx.setMessage(''), 2000)
|
|
269
|
-
return
|
|
270
|
-
default:
|
|
271
|
-
// Not a valid prefix command, ignore
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Handle Ctrl+X prefix activation
|
|
277
|
-
if (key.ctrl && key.name === 'x') {
|
|
278
|
-
ctx.setPrefixActive(true)
|
|
279
|
-
|
|
280
|
-
// Clear prefix after 2 seconds if no key pressed
|
|
281
|
-
const timeout = setTimeout(() => {
|
|
282
|
-
ctx.setPrefixActive(false)
|
|
283
|
-
}, 2000)
|
|
284
|
-
ctx.prefixTimeoutRef.current = timeout
|
|
285
|
-
return
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Ctrl+Q to quit (immediate, no prefix needed)
|
|
289
|
-
if (key.ctrl && key.name === 'q') {
|
|
290
|
-
process.exit(0)
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Handle Esc differently based on mode
|
|
295
|
-
if (key.name === 'escape') {
|
|
296
|
-
if (isStandard) {
|
|
297
|
-
// Standard mode: just clear search, stay in search mode
|
|
298
|
-
ctx.setSearchQuery('')
|
|
299
|
-
ctx.setCursor(0)
|
|
300
|
-
} else {
|
|
301
|
-
// Vim mode: exit to normal mode
|
|
302
|
-
ctx.setAppMode(AppMode.Normal)
|
|
303
|
-
ctx.setSearchQuery('')
|
|
304
|
-
ctx.setCursor(0)
|
|
305
|
-
}
|
|
306
|
-
return
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
switch (key.name) {
|
|
310
|
-
case 'return':
|
|
311
|
-
if (ctx.items.length > 0) {
|
|
312
|
-
ctx.handleSelect(ctx.items[0])
|
|
313
|
-
}
|
|
314
|
-
break
|
|
315
|
-
case 'down':
|
|
316
|
-
ctx.setCursor(c => Math.min(c + 1, ctx.items.length - 1))
|
|
317
|
-
break
|
|
318
|
-
case 'up':
|
|
319
|
-
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
320
|
-
break
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
export function handleNewSessionMode(
|
|
325
|
-
key: any,
|
|
326
|
-
ctx: KeyboardHandlerContext,
|
|
327
|
-
keybindMode: KeybindMode = 'vim'
|
|
328
|
-
) {
|
|
329
|
-
const isStandard = keybindMode === 'standard'
|
|
330
|
-
|
|
331
|
-
// Handle Ctrl keybinds in standard mode
|
|
332
|
-
if (isStandard && key.ctrl) {
|
|
333
|
-
// Ctrl+I to switch to search mode
|
|
334
|
-
if (key.name === 'i') {
|
|
335
|
-
ctx.setAppMode(AppMode.Search)
|
|
336
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
337
|
-
ctx.setAllItems(ctx.sessionItems)
|
|
338
|
-
ctx.setItems(ctx.sessionItems)
|
|
339
|
-
ctx.setSearchQuery('')
|
|
340
|
-
return
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// Ctrl+D to delete session (if on sessions view)
|
|
344
|
-
if (key.name === 'd' && ctx.items[ctx.cursor]?.isSession) {
|
|
345
|
-
ctx.handleKillSession(ctx.items[ctx.cursor].title)
|
|
346
|
-
return
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Handle Esc differently based on mode
|
|
351
|
-
if (key.name === 'escape') {
|
|
352
|
-
if (isStandard) {
|
|
353
|
-
// Standard mode: return to search mode (always in insert mode)
|
|
354
|
-
ctx.setAppMode(AppMode.Search)
|
|
355
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
356
|
-
ctx.setSearchQuery('')
|
|
357
|
-
ctx.setCursor(0)
|
|
358
|
-
// Reload sessions to restore the list
|
|
359
|
-
ctx.refreshItems(ViewMode.Sessions)
|
|
360
|
-
} else {
|
|
361
|
-
// Vim mode: return to normal mode
|
|
362
|
-
ctx.setAppMode(AppMode.Normal)
|
|
363
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
364
|
-
ctx.setSearchQuery('')
|
|
365
|
-
ctx.setCursor(0)
|
|
366
|
-
}
|
|
367
|
-
return
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
switch (key.name) {
|
|
371
|
-
case 'return':
|
|
372
|
-
break
|
|
373
|
-
case 'down':
|
|
374
|
-
ctx.setCursor(c => Math.min(c + 1, ctx.items.length - 1))
|
|
375
|
-
break
|
|
376
|
-
case 'up':
|
|
377
|
-
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
378
|
-
break
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export function handleRenameMode(
|
|
383
|
-
key: any,
|
|
384
|
-
ctx: KeyboardHandlerContext,
|
|
385
|
-
keybindMode: KeybindMode = 'vim'
|
|
386
|
-
) {
|
|
387
|
-
const isStandard = keybindMode === 'standard'
|
|
388
|
-
|
|
389
|
-
// Handle Ctrl keybinds in standard mode
|
|
390
|
-
if (isStandard && key.ctrl) {
|
|
391
|
-
// Ctrl+I to switch to search mode
|
|
392
|
-
if (key.name === 'i') {
|
|
393
|
-
ctx.setAppMode(AppMode.Search)
|
|
394
|
-
ctx.setSearchQuery('')
|
|
395
|
-
ctx.setRenameTarget('')
|
|
396
|
-
return
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// Ctrl+D to delete the rename target session
|
|
400
|
-
if (key.name === 'd' && ctx.renameTarget) {
|
|
401
|
-
ctx.handleKillSession(ctx.renameTarget)
|
|
402
|
-
ctx.setAppMode(AppMode.Search)
|
|
403
|
-
ctx.setSearchQuery('')
|
|
404
|
-
ctx.setRenameTarget('')
|
|
405
|
-
return
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// Handle Esc differently based on mode
|
|
410
|
-
if (key.name === 'escape') {
|
|
411
|
-
if (isStandard) {
|
|
412
|
-
// Standard mode: return to search mode (always in insert mode)
|
|
413
|
-
ctx.setAppMode(AppMode.Search)
|
|
414
|
-
ctx.setSearchQuery('')
|
|
415
|
-
ctx.setRenameTarget('')
|
|
416
|
-
// Reload sessions to restore the list
|
|
417
|
-
ctx.refreshItems(ViewMode.Sessions)
|
|
418
|
-
} else {
|
|
419
|
-
// Vim mode: return to normal mode
|
|
420
|
-
ctx.setAppMode(AppMode.Normal)
|
|
421
|
-
ctx.setSearchQuery('')
|
|
422
|
-
ctx.setRenameTarget('')
|
|
423
|
-
}
|
|
424
|
-
return
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
switch (key.name) {
|
|
428
|
-
case 'return':
|
|
429
|
-
break
|
|
430
|
-
}
|
|
431
|
-
}
|
package/src/index.tsx
DELETED
package/src/opencode/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './types'
|
|
2
|
-
export * from './constants'
|
|
3
|
-
export * from './parser'
|
|
4
|
-
export * from './tokens'
|
|
5
|
-
export * from './session'
|
|
6
|
-
export * from './stats'
|
|
7
|
-
|
|
8
|
-
export function formatSessionAge(timestamp: number): string {
|
|
9
|
-
const now = Date.now()
|
|
10
|
-
const diff = now - timestamp
|
|
11
|
-
|
|
12
|
-
const minutes = Math.floor(diff / 60000)
|
|
13
|
-
const hours = Math.floor(diff / 3600000)
|
|
14
|
-
const days = Math.floor(diff / 86400000)
|
|
15
|
-
|
|
16
|
-
if (minutes < 60) return `${minutes}m ago`
|
|
17
|
-
if (hours < 24) return `${hours}h ago`
|
|
18
|
-
return `${days}d ago`
|
|
19
|
-
}
|
package/src/opencode/parser.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
import type { OpencodeStats } from './types'
|
|
3
|
-
|
|
4
|
-
export async function getGlobalOpencodeStats(): Promise<OpencodeStats> {
|
|
5
|
-
try {
|
|
6
|
-
const proc = spawn(['opencode', 'stats'])
|
|
7
|
-
const output = await new Response(proc.stdout).text()
|
|
8
|
-
|
|
9
|
-
const stats: OpencodeStats = {}
|
|
10
|
-
|
|
11
|
-
const lines = output.split('\n')
|
|
12
|
-
|
|
13
|
-
for (const line of lines) {
|
|
14
|
-
if (line.includes('Sessions') && !line.includes('Opencode')) {
|
|
15
|
-
const match = line.match(/Sessions\s+(\d+)/)
|
|
16
|
-
if (match) stats.totalSessions = parseInt(match[1], 10)
|
|
17
|
-
}
|
|
18
|
-
if (line.includes('Messages')) {
|
|
19
|
-
const match = line.match(/Messages\s+([\d,]+)/)
|
|
20
|
-
if (match) stats.totalMessages = parseInt(match[1].replace(/,/g, ''), 10)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (line.includes('Total Cost')) {
|
|
24
|
-
const match = line.match(/Total Cost\s+\$?([\d.]+)/)
|
|
25
|
-
if (match) stats.totalCost = `$${match[1]}`
|
|
26
|
-
}
|
|
27
|
-
if (line.includes('Cost/Day')) {
|
|
28
|
-
const match = line.match(/Cost\/Day\s+\$?([\d.]+)/)
|
|
29
|
-
if (match) stats.costPerDay = `$${match[1]}`
|
|
30
|
-
}
|
|
31
|
-
if (line.includes('Input') && !line.includes('Cost')) {
|
|
32
|
-
const match = line.match(/Input\s+([\d.]+[KMG]?)/)
|
|
33
|
-
if (match) stats.inputTokens = match[1]
|
|
34
|
-
}
|
|
35
|
-
if (line.includes('Output')) {
|
|
36
|
-
const match = line.match(/Output\s+([\d.]+[KMG]?)/)
|
|
37
|
-
if (match) stats.outputTokens = match[1]
|
|
38
|
-
}
|
|
39
|
-
if (line.includes('Cache Read')) {
|
|
40
|
-
const match = line.match(/Cache Read\s+([\d.]+[KMG]?)/)
|
|
41
|
-
if (match) stats.cacheRead = match[1]
|
|
42
|
-
}
|
|
43
|
-
if (line.includes('Cache Write')) {
|
|
44
|
-
const match = line.match(/Cache Write\s+([\d.]+[KMG]?)/)
|
|
45
|
-
if (match) stats.cacheWrite = match[1]
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return stats
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error('Failed to get global OpenCode stats:', error)
|
|
52
|
-
return {}
|
|
53
|
-
}
|
|
54
|
-
}
|