mux-sesh 1.9.3 → 1.9.5
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 +27 -9
- package/package.json +4 -2
- package/src/agents/index.ts +1 -0
- package/src/agents/session-name.ts +24 -0
- package/src/app/commands.ts +20 -16
- package/src/app/controller.ts +30 -18
- package/src/app/controls.ts +11 -9
- package/src/app/core-state.ts +8 -4
- package/src/app/data.ts +42 -7
- package/src/app/derived.ts +11 -11
- package/src/app/effects.ts +141 -23
- package/src/app/handlers.ts +48 -24
- package/src/app/keyboard.ts +12 -12
- package/src/app/modals.ts +8 -8
- package/src/app/runtime.ts +4 -1
- package/src/app/screen.tsx +30 -15
- package/src/app/state.ts +24 -4
- package/src/app/view.ts +24 -13
- package/src/config/index.ts +10 -0
- package/src/handlers/action-helpers.ts +22 -7
- package/src/handlers/actions.ts +51 -42
- package/src/handlers/keyboard/agents.ts +134 -0
- package/src/handlers/keyboard/index.ts +1 -1
- package/src/handlers/keyboard/new-session.ts +1 -1
- package/src/handlers/keyboard/normal.ts +12 -8
- package/src/handlers/keyboard/search.ts +10 -6
- package/src/handlers/keyboard/shared.ts +6 -6
- package/src/herdr/backend.ts +357 -0
- package/src/herdr/protocol.ts +268 -0
- package/src/items/order.ts +7 -11
- package/src/multiplexer/backend.ts +43 -0
- package/src/multiplexer/command.ts +48 -0
- package/src/multiplexer/index.ts +21 -0
- package/src/multiplexer/items.ts +66 -0
- package/src/multiplexer/resolve.ts +106 -0
- package/src/multiplexer/tmux-backend.ts +87 -0
- package/src/multiplexer/types.ts +93 -0
- package/src/opencode/session-name.ts +5 -4
- package/src/preview/project.ts +13 -11
- package/src/projects/session-links.ts +22 -4
- package/src/settings.ts +19 -0
- package/src/tmux/workflows.ts +5 -1
- package/src/types/index.ts +14 -2
- package/src/ui/{OpencodeSessionGroup.tsx → AgentSessionGroup.tsx} +27 -12
- package/src/ui/CommandsModal.tsx +18 -10
- package/src/ui/ItemList.tsx +3 -2
- package/src/ui/SessionDetailsPanel.tsx +68 -34
- package/src/ui/SessionList.tsx +23 -7
- package/src/ui/item-icon.ts +24 -12
- package/src/ui/session-meta.ts +10 -0
- package/src/handlers/keyboard/opencode.ts +0 -105
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# mux-sesh
|
|
2
2
|
|
|
3
|
-
Fast tmux session
|
|
3
|
+
Fast tmux session and Herdr workspace switching from a polished terminal UI.
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="screenshot.png" alt="mux-sesh screenshot" width="800">
|
|
@@ -8,19 +8,19 @@ Fast tmux session switching and project launching from a polished terminal UI.
|
|
|
8
8
|
|
|
9
9
|
## Why mux-sesh
|
|
10
10
|
|
|
11
|
-
- Switch
|
|
11
|
+
- Switch between live tmux sessions or Herdr workspaces without leaving the keyboard.
|
|
12
12
|
- Launch local projects from a single, searchable picker.
|
|
13
13
|
- Keep reusable project rules in config instead of shell scripts.
|
|
14
|
-
- Stay inside
|
|
14
|
+
- Stay inside your multiplexer with previews, quick actions, and lightweight workflows.
|
|
15
15
|
|
|
16
16
|
## Quick Start
|
|
17
17
|
|
|
18
|
-
`mux-sesh` runs on Bun and talks directly to tmux.
|
|
18
|
+
`mux-sesh` runs on Bun and talks directly to tmux or Herdr. Herdr needs no mux-sesh plugin.
|
|
19
19
|
|
|
20
20
|
Prerequisites:
|
|
21
21
|
|
|
22
22
|
- [Bun](https://bun.sh)
|
|
23
|
-
- [tmux](https://github.com/tmux/tmux/wiki)
|
|
23
|
+
- [tmux](https://github.com/tmux/tmux/wiki) or Herdr 0.7.5
|
|
24
24
|
- [git](https://git-scm.com) for cloning GitHub repositories from the new-session flow
|
|
25
25
|
|
|
26
26
|
Install globally:
|
|
@@ -49,20 +49,38 @@ tmux source-file ~/.tmux.conf
|
|
|
49
49
|
|
|
50
50
|
## How It Works
|
|
51
51
|
|
|
52
|
-
- Sessions view shows live tmux sessions.
|
|
52
|
+
- Sessions view shows live tmux sessions or Herdr workspaces.
|
|
53
53
|
- Projects view shows scanned or configured directories.
|
|
54
|
-
- Selecting a project attaches to an existing session when possible, or creates one.
|
|
54
|
+
- Selecting a project attaches to an existing session or workspace when possible, or creates one.
|
|
55
55
|
- The new-session flow searches files and directories under `project_paths` as you type, powered by [fff](https://github.com/dmtrKovalenko/fff).
|
|
56
56
|
- Selecting a file creates a session in the file's directory and opens it in your editor.
|
|
57
|
+
- Newly created Herdr workspaces and tabs are focused automatically when launching a project or editor.
|
|
58
|
+
- The Agents section shows Herdr workspaces with detected native agent status alongside tmux agent sessions and `tui_chat`; Herdr `unknown` status and age are hidden.
|
|
57
59
|
- The new-session flow can also clone a GitHub repository into your configured repos directory.
|
|
58
60
|
|
|
61
|
+
Herdr concepts map directly into the UI:
|
|
62
|
+
|
|
63
|
+
| mux-sesh | Herdr |
|
|
64
|
+
| -------- | --------- |
|
|
65
|
+
| Session | Workspace |
|
|
66
|
+
| Window | Tab |
|
|
67
|
+
| Pane | Pane |
|
|
68
|
+
|
|
69
|
+
Backend detection uses `HERDR_ENV`, then `TMUX`, then an explicit `backend`, then running servers. Auto detection chooses tmux when both run and defaults to installed tmux when neither runs.
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{ "backend": "herdr" }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Explicit Herdr selection is strict: its server must already run, and mux-sesh never starts it or falls back. Config changes apply on the next mux-sesh launch.
|
|
76
|
+
|
|
59
77
|
## Minimal Configuration
|
|
60
78
|
|
|
61
79
|
Config lives at `~/.config/mux-sesh/config.json`.
|
|
62
80
|
|
|
63
81
|
```json
|
|
64
82
|
{
|
|
65
|
-
"project_paths": ["~/dev"
|
|
83
|
+
"project_paths": ["~/dev"],
|
|
66
84
|
"repos_path": "~/dev/repos",
|
|
67
85
|
"keybind_mode": "vim",
|
|
68
86
|
"prefix_key": "ctrl+x",
|
|
@@ -94,7 +112,7 @@ With the default prefix key, secondary actions live behind `ctrl+x`:
|
|
|
94
112
|
|
|
95
113
|
- `ctrl+x s` sessions
|
|
96
114
|
- `ctrl+x p` projects
|
|
97
|
-
- `ctrl+x l` last session
|
|
115
|
+
- `ctrl+x l` last session (tmux only)
|
|
98
116
|
- `ctrl+x g` git root session
|
|
99
117
|
- `ctrl+x r` rename session
|
|
100
118
|
- `ctrl+x e` edit configured target
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "mux-sesh",
|
|
4
|
-
"version": "1.9.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.9.5",
|
|
5
|
+
"description": "An OpenTUI manager for tmux sessions and Herdr workspaces with fuzzy project search",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"packageManager": "bun@1.3.5",
|
|
8
8
|
"bin": {
|
|
@@ -25,9 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"tmux",
|
|
28
|
+
"herdr",
|
|
28
29
|
"tui",
|
|
29
30
|
"terminal",
|
|
30
31
|
"session-manager",
|
|
32
|
+
"workspace-manager",
|
|
31
33
|
"opentui",
|
|
32
34
|
"cli",
|
|
33
35
|
"tmux-manager",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './session-name'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Item } from '../types'
|
|
2
|
+
|
|
3
|
+
const AGENT_SESSION_PREFIXES = ['opencode-', 'pi-', 'codex-', 'claude-'] as const
|
|
4
|
+
const SIDE_SESSION_NAMES = new Set(['tui_chat'])
|
|
5
|
+
|
|
6
|
+
export function isAgentSessionName(sessionName: string): boolean {
|
|
7
|
+
return (
|
|
8
|
+
AGENT_SESSION_PREFIXES.some(prefix => sessionName.startsWith(prefix)) ||
|
|
9
|
+
SIDE_SESSION_NAMES.has(sessionName)
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isAgentSessionItem(
|
|
14
|
+
item: Pick<Item, 'isSession' | 'title' | 'itemKind' | 'agentStatus' | 'target'>
|
|
15
|
+
): boolean {
|
|
16
|
+
if (!item.isSession) {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return item.itemKind === 'herdr'
|
|
21
|
+
? item.target?.kind === 'agent' ||
|
|
22
|
+
(item.agentStatus !== undefined && item.agentStatus !== 'unknown')
|
|
23
|
+
: isAgentSessionName(item.title)
|
|
24
|
+
}
|
package/src/app/commands.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isOpencodeSessionItem } from '../opencode/session-name'
|
|
1
2
|
import type { CommandId } from '../ui/CommandsModal'
|
|
2
3
|
import { AppMode, ViewMode, type Item } from '../types'
|
|
3
4
|
|
|
@@ -5,16 +6,16 @@ interface ExecuteCommandContext {
|
|
|
5
6
|
appMode: AppMode
|
|
6
7
|
viewMode: ViewMode
|
|
7
8
|
cursor: number
|
|
8
|
-
|
|
9
|
+
agentCursor: number
|
|
9
10
|
regularSessions: Item[]
|
|
10
|
-
|
|
11
|
+
agentSessions: Item[]
|
|
11
12
|
selectedPrimaryItem?: Item
|
|
12
13
|
sessionCandidateItems: Item[]
|
|
13
14
|
projectSourceItems: Item[]
|
|
14
15
|
closeModal: () => void
|
|
15
|
-
openRenameModal: (
|
|
16
|
+
openRenameModal: (item: Item) => void
|
|
16
17
|
openSettingsModal: () => void
|
|
17
|
-
requestKillSession: (
|
|
18
|
+
requestKillSession: (item: Item) => void
|
|
18
19
|
togglePinnedSession: (sessionName: string) => Promise<void>
|
|
19
20
|
setAppMode: (mode: AppMode) => void
|
|
20
21
|
setViewMode: (mode: ViewMode) => void
|
|
@@ -22,7 +23,7 @@ interface ExecuteCommandContext {
|
|
|
22
23
|
setItems: (items: Item[]) => void
|
|
23
24
|
setCursor: (cursor: number) => void
|
|
24
25
|
setSearchQuery: (value: string) => void
|
|
25
|
-
|
|
26
|
+
setAgentCursor: (cursor: number) => void
|
|
26
27
|
refreshItems: (forceViewMode?: ViewMode) => Promise<void>
|
|
27
28
|
handleLastSession: () => Promise<void>
|
|
28
29
|
handleRootSession: (item?: Item) => Promise<void>
|
|
@@ -65,26 +66,26 @@ export async function executeCommand(commandID: CommandId, ctx: ExecuteCommandCo
|
|
|
65
66
|
return
|
|
66
67
|
case 'rename-session': {
|
|
67
68
|
const target =
|
|
68
|
-
ctx.appMode === AppMode.
|
|
69
|
-
? ctx.
|
|
69
|
+
ctx.appMode === AppMode.AgentsManage
|
|
70
|
+
? ctx.agentSessions[ctx.agentCursor]
|
|
70
71
|
: ctx.viewMode === ViewMode.Sessions
|
|
71
72
|
? ctx.regularSessions[ctx.cursor]
|
|
72
73
|
: undefined
|
|
73
74
|
if (target?.isSession) {
|
|
74
|
-
ctx.openRenameModal(target
|
|
75
|
+
ctx.openRenameModal(target)
|
|
75
76
|
}
|
|
76
77
|
return
|
|
77
78
|
}
|
|
78
79
|
case 'kill-session': {
|
|
79
80
|
const target =
|
|
80
|
-
ctx.appMode === AppMode.
|
|
81
|
-
? ctx.
|
|
81
|
+
ctx.appMode === AppMode.AgentsManage
|
|
82
|
+
? ctx.agentSessions[ctx.agentCursor]
|
|
82
83
|
: ctx.viewMode === ViewMode.Sessions
|
|
83
84
|
? ctx.regularSessions[ctx.cursor]
|
|
84
85
|
: undefined
|
|
85
86
|
if (target?.isSession) {
|
|
86
87
|
ctx.closeModal()
|
|
87
|
-
ctx.requestKillSession(target
|
|
88
|
+
ctx.requestKillSession(target)
|
|
88
89
|
}
|
|
89
90
|
return
|
|
90
91
|
}
|
|
@@ -109,12 +110,15 @@ export async function executeCommand(commandID: CommandId, ctx: ExecuteCommandCo
|
|
|
109
110
|
ctx.closeModal()
|
|
110
111
|
await ctx.handleEditTarget(ctx.selectedPrimaryItem)
|
|
111
112
|
return
|
|
112
|
-
case 'open-
|
|
113
|
+
case 'open-agents':
|
|
113
114
|
ctx.closeModal()
|
|
114
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.
|
|
115
|
-
ctx.setAppMode(AppMode.
|
|
116
|
-
ctx.
|
|
117
|
-
|
|
115
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.agentSessions.length > 0) {
|
|
116
|
+
ctx.setAppMode(AppMode.AgentsManage)
|
|
117
|
+
ctx.setAgentCursor(0)
|
|
118
|
+
const firstAgent = ctx.agentSessions[0]
|
|
119
|
+
if (isOpencodeSessionItem(firstAgent)) {
|
|
120
|
+
await ctx.loadOpencodeStatsForSession(firstAgent.title)
|
|
121
|
+
}
|
|
118
122
|
}
|
|
119
123
|
return
|
|
120
124
|
case 'refresh':
|
package/src/app/controller.ts
CHANGED
|
@@ -33,8 +33,8 @@ export function useAppController() {
|
|
|
33
33
|
setSessionItems,
|
|
34
34
|
cursor,
|
|
35
35
|
setCursor,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
agentCursor,
|
|
37
|
+
setAgentCursor,
|
|
38
38
|
searchQuery,
|
|
39
39
|
setSearchQuery,
|
|
40
40
|
message,
|
|
@@ -43,6 +43,8 @@ export function useAppController() {
|
|
|
43
43
|
setRenameTarget,
|
|
44
44
|
config,
|
|
45
45
|
setConfig,
|
|
46
|
+
backend,
|
|
47
|
+
setBackend,
|
|
46
48
|
pendingKillSessionName,
|
|
47
49
|
setPendingKillSessionName,
|
|
48
50
|
prefixActive,
|
|
@@ -105,6 +107,8 @@ export function useAppController() {
|
|
|
105
107
|
lastProjectSelectionRef,
|
|
106
108
|
mark,
|
|
107
109
|
setConfig,
|
|
110
|
+
setBackend,
|
|
111
|
+
setMessage,
|
|
108
112
|
setAppMode,
|
|
109
113
|
setViewMode,
|
|
110
114
|
setSessionItems,
|
|
@@ -118,6 +122,7 @@ export function useAppController() {
|
|
|
118
122
|
|
|
119
123
|
const { showMessage, refreshItems, loadOpencodeStatsForSession } = createAppRuntime({
|
|
120
124
|
config,
|
|
125
|
+
backend,
|
|
121
126
|
viewMode,
|
|
122
127
|
measure,
|
|
123
128
|
lastSessionSelectionRef,
|
|
@@ -133,8 +138,8 @@ export function useAppController() {
|
|
|
133
138
|
|
|
134
139
|
const {
|
|
135
140
|
regularSessions,
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
agentSessions,
|
|
142
|
+
selectedAgentSession,
|
|
138
143
|
selectedPrimaryItem,
|
|
139
144
|
filteredCommandEntries,
|
|
140
145
|
} = getSessionCommandState(
|
|
@@ -142,7 +147,7 @@ export function useAppController() {
|
|
|
142
147
|
viewMode,
|
|
143
148
|
items,
|
|
144
149
|
cursor,
|
|
145
|
-
|
|
150
|
+
agentCursor,
|
|
146
151
|
config,
|
|
147
152
|
commandsSearchQuery
|
|
148
153
|
)
|
|
@@ -159,8 +164,9 @@ export function useAppController() {
|
|
|
159
164
|
} = createAppControls({
|
|
160
165
|
config,
|
|
161
166
|
pendingKillSessionName,
|
|
162
|
-
handleKillSession:
|
|
163
|
-
handleKillSessionWithFeedback(
|
|
167
|
+
handleKillSession: item =>
|
|
168
|
+
handleKillSessionWithFeedback(item, {
|
|
169
|
+
backend,
|
|
164
170
|
config,
|
|
165
171
|
items,
|
|
166
172
|
sessionItems,
|
|
@@ -196,6 +202,7 @@ export function useAppController() {
|
|
|
196
202
|
handleTogglePinnedSessionWrapper,
|
|
197
203
|
executeCommand,
|
|
198
204
|
} = createAppHandlers({
|
|
205
|
+
backend,
|
|
199
206
|
appMode,
|
|
200
207
|
viewMode,
|
|
201
208
|
config,
|
|
@@ -204,9 +211,9 @@ export function useAppController() {
|
|
|
204
211
|
cursor,
|
|
205
212
|
showMessage,
|
|
206
213
|
refreshItems,
|
|
207
|
-
|
|
214
|
+
agentCursor,
|
|
208
215
|
regularSessions,
|
|
209
|
-
|
|
216
|
+
agentSessions,
|
|
210
217
|
selectedPrimaryItem,
|
|
211
218
|
sessionCandidateItems,
|
|
212
219
|
projectSourceItems,
|
|
@@ -220,7 +227,7 @@ export function useAppController() {
|
|
|
220
227
|
setItems,
|
|
221
228
|
setCursor,
|
|
222
229
|
setSearchQuery,
|
|
223
|
-
|
|
230
|
+
setAgentCursor,
|
|
224
231
|
setPendingKillSessionName,
|
|
225
232
|
saveConfig,
|
|
226
233
|
setConfig,
|
|
@@ -239,12 +246,12 @@ export function useAppController() {
|
|
|
239
246
|
config,
|
|
240
247
|
items,
|
|
241
248
|
regularSessions,
|
|
242
|
-
|
|
249
|
+
agentSessions,
|
|
243
250
|
sessionItems,
|
|
244
251
|
sessionCandidateItems,
|
|
245
252
|
projectSourceItems,
|
|
246
253
|
cursor,
|
|
247
|
-
|
|
254
|
+
agentCursor,
|
|
248
255
|
searchQuery,
|
|
249
256
|
prefixActive,
|
|
250
257
|
prefixTimeoutRef,
|
|
@@ -285,7 +292,7 @@ export function useAppController() {
|
|
|
285
292
|
setAppMode,
|
|
286
293
|
setViewMode,
|
|
287
294
|
setCursor,
|
|
288
|
-
|
|
295
|
+
setAgentCursor,
|
|
289
296
|
setSearchQuery,
|
|
290
297
|
setAllItems,
|
|
291
298
|
setItems,
|
|
@@ -297,6 +304,7 @@ export function useAppController() {
|
|
|
297
304
|
appMode,
|
|
298
305
|
viewMode,
|
|
299
306
|
config,
|
|
307
|
+
backend,
|
|
300
308
|
sessionItems,
|
|
301
309
|
projectSourceItems,
|
|
302
310
|
sessionCandidateItems,
|
|
@@ -304,7 +312,10 @@ export function useAppController() {
|
|
|
304
312
|
lastProjectSelectionRef,
|
|
305
313
|
setAllItems,
|
|
306
314
|
setItems,
|
|
315
|
+
setSessionItems,
|
|
307
316
|
setCursor,
|
|
317
|
+
setAgentCursor,
|
|
318
|
+
setMessage,
|
|
308
319
|
setSessionCandidateItems,
|
|
309
320
|
filteredCommandEntriesLength: filteredCommandEntries.length,
|
|
310
321
|
setCommandsCursor,
|
|
@@ -317,13 +328,13 @@ export function useAppController() {
|
|
|
317
328
|
items,
|
|
318
329
|
selectedPrimaryItem,
|
|
319
330
|
pendingKillSessionName,
|
|
320
|
-
|
|
321
|
-
|
|
331
|
+
agentSessions,
|
|
332
|
+
agentCursor,
|
|
322
333
|
regularSessions,
|
|
323
334
|
setPendingKillSessionName,
|
|
324
335
|
searchQuery,
|
|
325
336
|
allItems,
|
|
326
|
-
|
|
337
|
+
selectedAgentSession,
|
|
327
338
|
loadOpencodeStatsForSession,
|
|
328
339
|
setUpdatedVersion,
|
|
329
340
|
setToastMessage,
|
|
@@ -340,12 +351,13 @@ export function useAppController() {
|
|
|
340
351
|
appMode,
|
|
341
352
|
viewMode,
|
|
342
353
|
config,
|
|
354
|
+
backend,
|
|
343
355
|
items,
|
|
344
356
|
regularSessions,
|
|
345
|
-
|
|
357
|
+
agentSessions,
|
|
346
358
|
selectedPrimaryItem,
|
|
347
359
|
cursor,
|
|
348
|
-
|
|
360
|
+
agentCursor,
|
|
349
361
|
searchQuery,
|
|
350
362
|
prefixActive,
|
|
351
363
|
pendingKillSessionName,
|
package/src/app/controls.ts
CHANGED
|
@@ -8,15 +8,16 @@ import {
|
|
|
8
8
|
openSettingsModal as showSettingsModal,
|
|
9
9
|
type ModalState,
|
|
10
10
|
} from './modals'
|
|
11
|
-
import type { Config } from '../types'
|
|
11
|
+
import type { Config, Item } from '../types'
|
|
12
|
+
import { getItemKey } from '../multiplexer/items'
|
|
12
13
|
import type { SettingsFieldId } from '../settings'
|
|
13
14
|
|
|
14
15
|
interface AppControlsOptions {
|
|
15
16
|
config: Config | null
|
|
16
17
|
pendingKillSessionName: string | null
|
|
17
|
-
handleKillSession: (
|
|
18
|
+
handleKillSession: (item: Item) => Promise<void>
|
|
18
19
|
setPendingKillSessionName: Dispatch<SetStateAction<string | null>>
|
|
19
|
-
setRenameTarget: Dispatch<SetStateAction<
|
|
20
|
+
setRenameTarget: Dispatch<SetStateAction<Item | null>>
|
|
20
21
|
setModalInputValue: Dispatch<SetStateAction<string>>
|
|
21
22
|
setModalState: Dispatch<SetStateAction<ModalState>>
|
|
22
23
|
setCommandsSearchQuery: Dispatch<SetStateAction<string>>
|
|
@@ -34,18 +35,19 @@ export function createAppControls(options: AppControlsOptions) {
|
|
|
34
35
|
options.setPendingKillSessionName(null)
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
function requestKillSession(
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
function requestKillSession(item: Item) {
|
|
39
|
+
const sessionKey = getItemKey(item)
|
|
40
|
+
if (options.pendingKillSessionName === sessionKey) {
|
|
41
|
+
void options.handleKillSession(item)
|
|
40
42
|
return
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
options.setPendingKillSessionName(
|
|
45
|
+
options.setPendingKillSessionName(sessionKey)
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
function openRenameModal(
|
|
48
|
+
function openRenameModal(item: Item) {
|
|
47
49
|
showRenameModal(
|
|
48
|
-
|
|
50
|
+
item,
|
|
49
51
|
clearPendingKill,
|
|
50
52
|
options.setRenameTarget,
|
|
51
53
|
options.setModalInputValue,
|
package/src/app/core-state.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TextareaRenderable } from '@opentui/core'
|
|
2
2
|
import { useRef, useState } from 'react'
|
|
3
3
|
import { AppMode, ViewMode, type Config, type Item } from '../types'
|
|
4
|
+
import type { MultiplexerBackend } from '../multiplexer'
|
|
4
5
|
|
|
5
6
|
export function useAppCoreState() {
|
|
6
7
|
const [appMode, setAppMode] = useState(AppMode.Normal)
|
|
@@ -11,11 +12,12 @@ export function useAppCoreState() {
|
|
|
11
12
|
const [sessionCandidateItems, setSessionCandidateItems] = useState<Item[]>([])
|
|
12
13
|
const [sessionItems, setSessionItems] = useState<Item[]>([])
|
|
13
14
|
const [cursor, setCursor] = useState(0)
|
|
14
|
-
const [
|
|
15
|
+
const [agentCursor, setAgentCursor] = useState(0)
|
|
15
16
|
const [searchQuery, setSearchQuery] = useState('')
|
|
16
17
|
const [message, setMessage] = useState('')
|
|
17
|
-
const [renameTarget, setRenameTarget] = useState(
|
|
18
|
+
const [renameTarget, setRenameTarget] = useState<Item | null>(null)
|
|
18
19
|
const [config, setConfig] = useState<Config | null>(null)
|
|
20
|
+
const [backend, setBackend] = useState<MultiplexerBackend | null>(null)
|
|
19
21
|
const [pendingKillSessionName, setPendingKillSessionName] = useState<string | null>(null)
|
|
20
22
|
const [prefixActive, setPrefixActive] = useState(false)
|
|
21
23
|
const prefixTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
|
@@ -43,8 +45,8 @@ export function useAppCoreState() {
|
|
|
43
45
|
setSessionItems,
|
|
44
46
|
cursor,
|
|
45
47
|
setCursor,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
agentCursor,
|
|
49
|
+
setAgentCursor,
|
|
48
50
|
searchQuery,
|
|
49
51
|
setSearchQuery,
|
|
50
52
|
message,
|
|
@@ -53,6 +55,8 @@ export function useAppCoreState() {
|
|
|
53
55
|
setRenameTarget,
|
|
54
56
|
config,
|
|
55
57
|
setConfig,
|
|
58
|
+
backend,
|
|
59
|
+
setBackend,
|
|
56
60
|
pendingKillSessionName,
|
|
57
61
|
setPendingKillSessionName,
|
|
58
62
|
prefixActive,
|
package/src/app/data.ts
CHANGED
|
@@ -2,21 +2,26 @@ import { getListedSessionItems, mergeSessionItems } from '../config/listed-sessi
|
|
|
2
2
|
import { orderProjectItems, orderSessionItems } from '../items/order'
|
|
3
3
|
import { annotateProjectItemsWithSessionLinks } from '../projects/session-links'
|
|
4
4
|
import { clearMatchIndices } from '../search'
|
|
5
|
-
import {
|
|
5
|
+
import { workspaceToItem } from '../multiplexer/items'
|
|
6
|
+
import type { MultiplexerBackend } from '../multiplexer'
|
|
7
|
+
import { getItemKey } from '../multiplexer/items'
|
|
6
8
|
import { getProjectItems, getSessionCandidateItems } from '../tmux/projects'
|
|
7
9
|
import { filterHiddenSessions } from '../tmux/workflows'
|
|
8
|
-
import {
|
|
10
|
+
import { isAgentSessionItem } from '../agents/session-name'
|
|
9
11
|
import type { Config, Item } from '../types'
|
|
12
|
+
import { clampCursorIndex } from '../ui/list-window'
|
|
10
13
|
|
|
11
14
|
export type Measure = <T>(name: string, fn: () => Promise<T>) => Promise<T>
|
|
12
15
|
|
|
13
16
|
export function getSessionSelectionIndex(nextItems: Item[], selection?: string | null): number {
|
|
14
|
-
const regularItems = nextItems.filter(item => !
|
|
17
|
+
const regularItems = nextItems.filter(item => !isAgentSessionItem(item))
|
|
15
18
|
if (regularItems.length === 0 || !selection) {
|
|
16
19
|
return 0
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
const index = regularItems.findIndex(
|
|
22
|
+
const index = regularItems.findIndex(
|
|
23
|
+
item => getItemKey(item) === selection || item.title === selection
|
|
24
|
+
)
|
|
20
25
|
return index >= 0 ? index : 0
|
|
21
26
|
}
|
|
22
27
|
|
|
@@ -29,12 +34,35 @@ export function getProjectSelectionIndex(nextItems: Item[], selection?: string |
|
|
|
29
34
|
return index >= 0 ? index : 0
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
export function getAgentSelectionIndex(
|
|
38
|
+
nextItems: Item[],
|
|
39
|
+
selection: string | undefined,
|
|
40
|
+
currentCursor: number
|
|
41
|
+
): number {
|
|
42
|
+
const agentSessions = nextItems.filter(isAgentSessionItem)
|
|
43
|
+
const selectedIndex = selection
|
|
44
|
+
? agentSessions.findIndex(item => getItemKey(item) === selection)
|
|
45
|
+
: -1
|
|
46
|
+
return selectedIndex >= 0 ? selectedIndex : clampCursorIndex(agentSessions.length, currentCursor)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function reuseSessionItemIdentities(previous: Item[], next: Item[]): Item[] {
|
|
50
|
+
const previousByKey = new Map(previous.map(item => [getItemKey(item), item]))
|
|
51
|
+
return next.map(item => {
|
|
52
|
+
const existing = previousByKey.get(getItemKey(item))
|
|
53
|
+
return existing && JSON.stringify(existing) === JSON.stringify(item) ? existing : item
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
32
57
|
export async function loadSessionItems(
|
|
33
58
|
config: Config,
|
|
34
59
|
measure: Measure,
|
|
60
|
+
backend: MultiplexerBackend,
|
|
35
61
|
labelPrefix = 'sessions'
|
|
36
62
|
): Promise<{ visibleSessions: Item[]; sessionItems: Item[] }> {
|
|
37
|
-
const sessions = await measure(`${labelPrefix}:
|
|
63
|
+
const sessions = await measure(`${labelPrefix}:listWorkspaces`, async () =>
|
|
64
|
+
(await backend.list()).map(workspaceToItem)
|
|
65
|
+
)
|
|
38
66
|
const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
|
|
39
67
|
const listedSessions = await measure(`${labelPrefix}:getListedSessionItems`, () =>
|
|
40
68
|
getListedSessionItems(config)
|
|
@@ -83,9 +111,16 @@ export async function loadProjectSourceItems(config: Config, measure: Measure):
|
|
|
83
111
|
)
|
|
84
112
|
}
|
|
85
113
|
|
|
86
|
-
export async function loadSessionCandidateItems(
|
|
114
|
+
export async function loadSessionCandidateItems(
|
|
115
|
+
config: Config,
|
|
116
|
+
measure: Measure,
|
|
117
|
+
backend: MultiplexerBackend
|
|
118
|
+
): Promise<Item[]> {
|
|
87
119
|
const [candidates, sessions] = await measure('loadSessionCandidateItems', () =>
|
|
88
|
-
Promise.all([
|
|
120
|
+
Promise.all([
|
|
121
|
+
getSessionCandidateItems(config),
|
|
122
|
+
backend.list().then(items => items.map(workspaceToItem)),
|
|
123
|
+
])
|
|
89
124
|
)
|
|
90
125
|
|
|
91
126
|
const visibleSessions = filterHiddenSessions(sessions, config.hiddenSessions)
|
package/src/app/derived.ts
CHANGED
|
@@ -13,8 +13,8 @@ import { splitVisibleSessions } from './view'
|
|
|
13
13
|
|
|
14
14
|
interface SessionCommandState {
|
|
15
15
|
regularSessions: Item[]
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
agentSessions: Item[]
|
|
17
|
+
selectedAgentSession: Item | undefined
|
|
18
18
|
selectedPrimaryItem: Item | undefined
|
|
19
19
|
filteredCommandEntries: CommandEntry[]
|
|
20
20
|
}
|
|
@@ -29,28 +29,28 @@ export function getSessionCommandState(
|
|
|
29
29
|
viewMode: ViewMode,
|
|
30
30
|
items: Item[],
|
|
31
31
|
cursor: number,
|
|
32
|
-
|
|
32
|
+
agentCursor: number,
|
|
33
33
|
config: Config | null,
|
|
34
34
|
commandsSearchQuery: string
|
|
35
35
|
): SessionCommandState {
|
|
36
36
|
const sessionSplit =
|
|
37
37
|
viewMode === ViewMode.Sessions &&
|
|
38
|
-
(appMode === AppMode.Normal || appMode === AppMode.
|
|
38
|
+
(appMode === AppMode.Normal || appMode === AppMode.AgentsManage)
|
|
39
39
|
? splitVisibleSessions(items)
|
|
40
|
-
: { regularSessions: items,
|
|
40
|
+
: { regularSessions: items, agentSessions: [] }
|
|
41
41
|
|
|
42
42
|
const selectedPrimaryItem =
|
|
43
43
|
viewMode === ViewMode.Sessions && appMode === AppMode.Normal
|
|
44
44
|
? sessionSplit.regularSessions[cursor]
|
|
45
|
-
:
|
|
45
|
+
: viewMode === ViewMode.Sessions && appMode === AppMode.AgentsManage
|
|
46
|
+
? sessionSplit.agentSessions[agentCursor]
|
|
47
|
+
: items[cursor]
|
|
46
48
|
|
|
47
49
|
return {
|
|
48
50
|
regularSessions: sessionSplit.regularSessions,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
appMode === AppMode.
|
|
52
|
-
? sessionSplit.opencodeSessions[opencodeCursor]?.title
|
|
53
|
-
: undefined,
|
|
51
|
+
agentSessions: sessionSplit.agentSessions,
|
|
52
|
+
selectedAgentSession:
|
|
53
|
+
appMode === AppMode.AgentsManage ? sessionSplit.agentSessions[agentCursor] : undefined,
|
|
54
54
|
selectedPrimaryItem,
|
|
55
55
|
filteredCommandEntries: filterCommandEntries(
|
|
56
56
|
getCommandEntries(appMode, config?.keybindMode, config?.prefixKey, selectedPrimaryItem),
|