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.
Files changed (51) hide show
  1. package/README.md +27 -9
  2. package/package.json +4 -2
  3. package/src/agents/index.ts +1 -0
  4. package/src/agents/session-name.ts +24 -0
  5. package/src/app/commands.ts +20 -16
  6. package/src/app/controller.ts +30 -18
  7. package/src/app/controls.ts +11 -9
  8. package/src/app/core-state.ts +8 -4
  9. package/src/app/data.ts +42 -7
  10. package/src/app/derived.ts +11 -11
  11. package/src/app/effects.ts +141 -23
  12. package/src/app/handlers.ts +48 -24
  13. package/src/app/keyboard.ts +12 -12
  14. package/src/app/modals.ts +8 -8
  15. package/src/app/runtime.ts +4 -1
  16. package/src/app/screen.tsx +30 -15
  17. package/src/app/state.ts +24 -4
  18. package/src/app/view.ts +24 -13
  19. package/src/config/index.ts +10 -0
  20. package/src/handlers/action-helpers.ts +22 -7
  21. package/src/handlers/actions.ts +51 -42
  22. package/src/handlers/keyboard/agents.ts +134 -0
  23. package/src/handlers/keyboard/index.ts +1 -1
  24. package/src/handlers/keyboard/new-session.ts +1 -1
  25. package/src/handlers/keyboard/normal.ts +12 -8
  26. package/src/handlers/keyboard/search.ts +10 -6
  27. package/src/handlers/keyboard/shared.ts +6 -6
  28. package/src/herdr/backend.ts +357 -0
  29. package/src/herdr/protocol.ts +268 -0
  30. package/src/items/order.ts +7 -11
  31. package/src/multiplexer/backend.ts +43 -0
  32. package/src/multiplexer/command.ts +48 -0
  33. package/src/multiplexer/index.ts +21 -0
  34. package/src/multiplexer/items.ts +66 -0
  35. package/src/multiplexer/resolve.ts +106 -0
  36. package/src/multiplexer/tmux-backend.ts +87 -0
  37. package/src/multiplexer/types.ts +93 -0
  38. package/src/opencode/session-name.ts +5 -4
  39. package/src/preview/project.ts +13 -11
  40. package/src/projects/session-links.ts +22 -4
  41. package/src/settings.ts +19 -0
  42. package/src/tmux/workflows.ts +5 -1
  43. package/src/types/index.ts +14 -2
  44. package/src/ui/{OpencodeSessionGroup.tsx → AgentSessionGroup.tsx} +27 -12
  45. package/src/ui/CommandsModal.tsx +18 -10
  46. package/src/ui/ItemList.tsx +3 -2
  47. package/src/ui/SessionDetailsPanel.tsx +68 -34
  48. package/src/ui/SessionList.tsx +23 -7
  49. package/src/ui/item-icon.ts +24 -12
  50. package/src/ui/session-meta.ts +10 -0
  51. package/src/handlers/keyboard/opencode.ts +0 -105
@@ -1,19 +1,21 @@
1
1
  import { useEffect, useState } from 'react'
2
2
  import { getFilePreview, getProjectPreview, type ProjectPreview } from '../preview/project'
3
3
  import { isFileItem } from '../files/target'
4
- import { getSessionDetails } from '../tmux'
5
4
  import { getDetailPanelStyle, useTheme } from '../styles/theme'
6
- import type { Config, Item, SessionDetails } from '../types'
5
+ import type { Config, Item } from '../types'
6
+ import type { MultiplexerBackend, WorkspaceDetails, WorkspaceRef } from '../multiplexer'
7
+ import { getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
7
8
 
8
9
  interface Props {
9
10
  selectedItem?: Item
10
11
  config: Config | null
12
+ backend: MultiplexerBackend | null
11
13
  }
12
14
 
13
15
  type DetailState =
14
16
  | { status: 'idle' }
15
17
  | { status: 'loading' }
16
- | { status: 'session'; details: SessionDetails }
18
+ | { status: 'session'; details: WorkspaceDetails }
17
19
  | { status: 'project'; details: ProjectPreview }
18
20
  | { status: 'error'; message: string }
19
21
 
@@ -72,10 +74,13 @@ function ProjectPreviewView({ preview }: { preview: ProjectPreview }) {
72
74
  <SectionLabel>Live session</SectionLabel>
73
75
  <MetaRow
74
76
  label="Status"
75
- value={preview.linkedSession.isAttached ? 'attached' : 'detached'}
76
- color={preview.linkedSession.isAttached ? theme.active : theme.textMuted}
77
+ value={preview.linkedSession.isActive ? 'active' : 'inactive'}
78
+ color={preview.linkedSession.isActive ? theme.active : theme.textMuted}
79
+ />
80
+ <MetaRow
81
+ label={preview.linkedSession.unitLabel}
82
+ value={String(preview.linkedSession.units.length)}
77
83
  />
78
- <MetaRow label="Windows" value={String(preview.linkedSession.windowCount)} />
79
84
  </box>
80
85
  )}
81
86
 
@@ -97,50 +102,64 @@ function ProjectPreviewView({ preview }: { preview: ProjectPreview }) {
97
102
  )
98
103
  }
99
104
 
100
- function SessionDetailsView({ details }: { details: SessionDetails }) {
105
+ function SessionDetailsView({ details }: { details: WorkspaceDetails }) {
101
106
  const theme = useTheme()
102
107
 
103
108
  return (
104
109
  <box style={{ flexDirection: 'column' }}>
105
- <text style={{ fg: theme.secondary }}>{details.name}</text>
110
+ <text style={{ fg: theme.secondary }}>{details.workspace.title}</text>
106
111
 
107
112
  <box style={{ flexDirection: 'column', marginTop: 1 }}>
108
113
  <MetaRow
109
114
  label="Status"
110
- value={details.isAttached ? 'active' : 'inactive'}
111
- color={details.isAttached ? theme.active : theme.textMuted}
115
+ value={details.isActive ? 'active' : 'inactive'}
116
+ color={details.isActive ? theme.active : theme.textMuted}
112
117
  />
113
- <MetaRow label="Windows" value={String(details.windowCount)} />
118
+ <MetaRow label={details.unitLabel} value={String(details.units.length)} />
114
119
  </box>
115
120
 
116
- <SectionLabel>Windows</SectionLabel>
121
+ <SectionLabel>{details.unitLabel}</SectionLabel>
117
122
  <box style={{ flexDirection: 'column', marginTop: 1 }}>
118
- {details.windows.length === 0 ? (
119
- <text style={{ fg: theme.textMuted }}>No windows found</text>
123
+ {details.units.length === 0 ? (
124
+ <text style={{ fg: theme.textMuted }}>No {details.unitLabel.toLowerCase()} found</text>
120
125
  ) : (
121
- details.windows.map(win => (
122
- <box
123
- key={`${win.index}:${win.name}`}
124
- style={{ flexDirection: 'column', marginBottom: 1 }}
125
- >
126
- <text style={{ fg: theme.text }}>
127
- {win.index}: {win.name}
128
- </text>
129
- {win.currentPath && <text style={{ fg: theme.fileTree }}>{win.currentPath}</text>}
130
- {win.currentCommand && (
131
- <text style={{ fg: theme.textSubtle }}>{win.currentCommand}</text>
126
+ details.units.map(unit => (
127
+ <box key={unit.id} style={{ flexDirection: 'column', marginBottom: 1 }}>
128
+ <text style={{ fg: theme.text }}>{unit.name}</text>
129
+ {unit.currentPath && <text style={{ fg: theme.fileTree }}>{unit.currentPath}</text>}
130
+ {unit.currentCommand && (
131
+ <text style={{ fg: theme.textSubtle }}>{unit.currentCommand}</text>
132
132
  )}
133
133
  </box>
134
134
  ))
135
135
  )}
136
136
  </box>
137
137
 
138
- {details.panePreviewLines && details.panePreviewLines.length > 0 && (
138
+ {details.agents.length > 0 && (
139
+ <>
140
+ <SectionLabel>Agents</SectionLabel>
141
+ <box style={{ flexDirection: 'column', marginTop: 1 }}>
142
+ {details.agents.map(agent => (
143
+ <box key={agent.paneId} style={{ flexDirection: 'column', marginBottom: 1 }}>
144
+ <text style={{ fg: theme.action }}>
145
+ {agent.name} · {agent.status}
146
+ </text>
147
+ {agent.cwd && <text style={{ fg: theme.fileTree }}>{agent.cwd}</text>}
148
+ </box>
149
+ ))}
150
+ </box>
151
+ </>
152
+ )}
153
+
154
+ {details.previewLines && details.previewLines.length > 0 && (
139
155
  <>
140
156
  <SectionLabel>Preview</SectionLabel>
141
157
  <box style={{ flexDirection: 'column', marginTop: 1 }}>
142
- {details.panePreviewLines.map((line, index) => (
143
- <text key={`${details.name}:preview:${index}`} style={{ fg: theme.textMuted }}>
158
+ {details.previewLines.map((line, index) => (
159
+ <text
160
+ key={`${details.workspace.id}:preview:${index}`}
161
+ style={{ fg: theme.textMuted }}
162
+ >
144
163
  {line}
145
164
  </text>
146
165
  ))}
@@ -151,7 +170,7 @@ function SessionDetailsView({ details }: { details: SessionDetails }) {
151
170
  )
152
171
  }
153
172
 
154
- export default function SessionDetailsPanel({ selectedItem, config }: Props) {
173
+ export default function SessionDetailsPanel({ selectedItem, config, backend }: Props) {
155
174
  const theme = useTheme()
156
175
  const [detailState, setDetailState] = useState<DetailState>({ status: 'idle' })
157
176
 
@@ -167,8 +186,9 @@ export default function SessionDetailsPanel({ selectedItem, config }: Props) {
167
186
  setDetailState({ status: 'loading' })
168
187
 
169
188
  try {
170
- if (selectedItem.isSession) {
171
- const details = await getSessionDetails(selectedItem.title)
189
+ if (isLiveSessionItem(selectedItem)) {
190
+ if (!backend) throw new Error('Multiplexer backend is not loaded yet')
191
+ const details = await backend.details(getWorkspaceRef(selectedItem))
172
192
  if (!cancelled) {
173
193
  setDetailState({ status: 'session', details })
174
194
  }
@@ -182,9 +202,23 @@ export default function SessionDetailsPanel({ selectedItem, config }: Props) {
182
202
  return
183
203
  }
184
204
 
205
+ const linkedWorkspace: WorkspaceRef | undefined =
206
+ selectedItem.linkedSessionId && selectedItem.linkedSessionBackend
207
+ ? {
208
+ backend: selectedItem.linkedSessionBackend,
209
+ id: selectedItem.linkedSessionId,
210
+ title: selectedItem.linkedSessionName ?? selectedItem.linkedSessionId,
211
+ }
212
+ : undefined
185
213
  const details = isFileItem(selectedItem)
186
- ? await getFilePreview(selectedItem.path, config, selectedItem.linkedSessionName)
187
- : await getProjectPreview(selectedItem.path, config, selectedItem.linkedSessionName)
214
+ ? await getFilePreview(selectedItem.path, config, linkedWorkspace, workspace => {
215
+ if (!backend) throw new Error('Multiplexer backend is not loaded yet')
216
+ return backend.details(workspace)
217
+ })
218
+ : await getProjectPreview(selectedItem.path, config, linkedWorkspace, workspace => {
219
+ if (!backend) throw new Error('Multiplexer backend is not loaded yet')
220
+ return backend.details(workspace)
221
+ })
188
222
  if (!cancelled) {
189
223
  setDetailState({ status: 'project', details })
190
224
  }
@@ -201,7 +235,7 @@ export default function SessionDetailsPanel({ selectedItem, config }: Props) {
201
235
  return () => {
202
236
  cancelled = true
203
237
  }
204
- }, [config, selectedItem])
238
+ }, [backend, config, selectedItem])
205
239
 
206
240
  const panelStyle = {
207
241
  ...getDetailPanelStyle(theme),
@@ -1,11 +1,12 @@
1
1
  import { useTheme } from '../styles/theme'
2
- import { formatSessionAge } from '../util/time'
3
2
  import type { IconConfig, Item } from '../types'
4
3
  import { getSessionSection } from '../items/order'
4
+ import { getItemKey } from '../multiplexer/items'
5
5
  import HighlightedText from './HighlightedText'
6
6
  import { formatSectionHeader, getItemIconPresentation } from './item-icon'
7
7
  import { getVisibleWindow } from './list-window'
8
8
  import { getMutedLabelColumnWidth, getMutedLabelSpacer } from './text-columns'
9
+ import { getSessionMeta } from './session-meta'
9
10
 
10
11
  interface Props {
11
12
  items: Item[]
@@ -34,20 +35,23 @@ export default function SessionList({
34
35
  {visibleWindow.items.map((item, i) => {
35
36
  const absoluteIndex = visibleWindow.startIndex + i
36
37
  const matchIndices = item.searchMatch?.titleIndices
37
- const itemMeta = item.isSession && item.createdAt ? formatSessionAge(item.createdAt) : ''
38
+ const itemMeta = getSessionMeta(item)
38
39
  const icon = getItemIconPresentation(theme, item, icons)
39
40
  const currentSection = getSessionSection(item)
40
41
  const previousItem = absoluteIndex > 0 ? items[absoluteIndex - 1] : undefined
41
42
  const previousSection = previousItem ? getSessionSection(previousItem) : undefined
42
43
  const showSectionHeader = i === 0 || currentSection !== previousSection
43
- const sectionHeader = formatSectionHeader(theme, currentSection, icons)
44
- const pendingKill = item.title === pendingKillSessionName
44
+ const sectionHeader = formatSectionHeader(theme, currentSection, icons, item.backend)
45
+ const pendingKill = getItemKey(item) === pendingKillSessionName
45
46
  const selected = absoluteIndex === cursor
46
47
  const mutedLabelSpacer =
47
48
  item.isSession && item.desc ? getMutedLabelSpacer(item.title, mutedLabelColumnWidth) : ''
48
49
 
49
50
  return (
50
- <box key={i} style={{ flexDirection: 'column' }}>
51
+ <box
52
+ key={item.isSession ? getItemKey(item) : `${getItemKey(item)}:${item.path}`}
53
+ style={{ flexDirection: 'column' }}
54
+ >
51
55
  {showSectionHeader && (
52
56
  <text
53
57
  style={{
@@ -91,8 +95,20 @@ export default function SessionList({
91
95
  ) : null}
92
96
  </text>
93
97
 
94
- <text style={{ fg: pendingKill ? theme.danger : theme.textSubtle }}>
95
- {pendingKill ? 'press d again to kill' : itemMeta}
98
+ <text
99
+ style={{
100
+ fg: pendingKill
101
+ ? theme.danger
102
+ : item.agentStatus === 'blocked'
103
+ ? theme.danger
104
+ : item.agentStatus === 'working'
105
+ ? theme.active
106
+ : theme.textSubtle,
107
+ }}
108
+ >
109
+ {pendingKill
110
+ ? `press d again to ${item.itemKind === 'herdr' ? 'close' : 'kill'}`
111
+ : itemMeta}
96
112
  </text>
97
113
  </box>
98
114
  </box>
@@ -1,6 +1,6 @@
1
+ import { isAgentSessionItem } from '../agents/session-name'
1
2
  import type { SessionSection } from '../items/order'
2
- import { isOpencodeSessionItem } from '../opencode/session-name'
3
- import type { IconConfig, Item, ThemeColors } from '../types'
3
+ import type { BackendKind, IconConfig, Item, ThemeColors } from '../types'
4
4
 
5
5
  export interface ItemIconPresentation {
6
6
  glyph: string
@@ -12,6 +12,7 @@ const FILE_ITEM_GLYPH = '  '
12
12
  function getIconConfig(icons?: IconConfig): IconConfig {
13
13
  return {
14
14
  tmux: icons?.tmux ?? '',
15
+ herdr: icons?.herdr ?? 'H',
15
16
  configured: icons?.configured ?? '',
16
17
  project: icons?.project ?? '',
17
18
  opencode: icons?.opencode ?? '',
@@ -46,14 +47,19 @@ export function getItemIconPresentation(
46
47
  if (item.isSession) {
47
48
  return {
48
49
  glyph:
49
- item.icon ?? (isOpencodeSessionItem(item) ? resolvedIcons.opencode : resolvedIcons.tmux),
50
+ item.icon ??
51
+ (isAgentSessionItem(item)
52
+ ? resolvedIcons.opencode
53
+ : item.itemKind === 'herdr'
54
+ ? resolvedIcons.herdr
55
+ : resolvedIcons.tmux),
50
56
  color: item.isAttached ? theme.active : theme.inactive,
51
57
  }
52
58
  }
53
59
 
54
60
  if (item.linkedSessionName) {
55
61
  return {
56
- glyph: resolvedIcons.tmux,
62
+ glyph: item.linkedSessionBackend === 'herdr' ? resolvedIcons.herdr : resolvedIcons.tmux,
57
63
  color: item.linkedSessionAttached ? theme.active : theme.inactive,
58
64
  }
59
65
  }
@@ -66,8 +72,9 @@ export function getItemIconPresentation(
66
72
 
67
73
  export function getSessionSectionPresentation(
68
74
  theme: ThemeColors,
69
- section: SessionSection | 'opencode',
70
- icons?: IconConfig
75
+ section: SessionSection | 'agents',
76
+ icons?: IconConfig,
77
+ backend?: BackendKind
71
78
  ): ItemIconPresentation & { label: string } {
72
79
  const resolvedIcons = getIconConfig(icons)
73
80
 
@@ -76,19 +83,24 @@ export function getSessionSectionPresentation(
76
83
  return { glyph: '', color: theme.accent, label: 'Pinned' }
77
84
  case 'configured':
78
85
  return { glyph: resolvedIcons.configured, color: theme.action, label: 'Configured' }
79
- case 'opencode':
80
- return { glyph: resolvedIcons.opencode, color: theme.action, label: 'OpenCode' }
86
+ case 'agents':
87
+ return { glyph: resolvedIcons.opencode, color: theme.action, label: 'Agents' }
81
88
  case 'live':
82
- return { glyph: resolvedIcons.tmux, color: theme.action, label: 'Live' }
89
+ return {
90
+ glyph: backend === 'herdr' ? resolvedIcons.herdr : resolvedIcons.tmux,
91
+ color: theme.action,
92
+ label: 'Live',
93
+ }
83
94
  }
84
95
  }
85
96
 
86
97
  export function formatSectionHeader(
87
98
  theme: ThemeColors,
88
- section: SessionSection | 'opencode',
89
- icons?: IconConfig
99
+ section: SessionSection | 'agents',
100
+ icons?: IconConfig,
101
+ backend?: BackendKind
90
102
  ): ItemIconPresentation & { text: string } {
91
- const presentation = getSessionSectionPresentation(theme, section, icons)
103
+ const presentation = getSessionSectionPresentation(theme, section, icons, backend)
92
104
  const prefix = presentation.glyph.length > 0 ? `${presentation.glyph} ` : ''
93
105
 
94
106
  return {
@@ -0,0 +1,10 @@
1
+ import type { Item } from '../types'
2
+ import { formatSessionAge } from '../util/time'
3
+
4
+ export function getSessionMeta(item: Item): string {
5
+ if (item.itemKind === 'herdr') {
6
+ return item.agentStatus && item.agentStatus !== 'unknown' ? item.agentStatus : ''
7
+ }
8
+
9
+ return item.createdAt ? formatSessionAge(item.createdAt) : ''
10
+ }
@@ -1,105 +0,0 @@
1
- import { AppMode, type KeybindMode } from '../../types'
2
- import { clampCursorIndex } from '../../ui/list-window'
3
- import {
4
- activatePrefix,
5
- clearPrefix,
6
- getKeyName,
7
- matchesPrefixKey,
8
- type KeyboardHandlerContext,
9
- type KeyboardInput,
10
- } from './shared'
11
-
12
- export function handleOpencodeManageMode(
13
- key: KeyboardInput,
14
- ctx: KeyboardHandlerContext,
15
- keybindMode: KeybindMode = 'vim'
16
- ) {
17
- const keyName = getKeyName(key)
18
- const isStandard = keybindMode === 'standard'
19
-
20
- if (key.ctrl && keyName === 'p') {
21
- ctx.clearPendingKill()
22
- ctx.openCommandsModal()
23
- return
24
- }
25
-
26
- if (ctx.prefixActive) {
27
- clearPrefix(ctx)
28
-
29
- switch (keyName) {
30
- case 'o':
31
- ctx.clearPendingKill()
32
- ctx.setAppMode(AppMode.Normal)
33
- return
34
- case 'd':
35
- if (ctx.opencodeSessions[ctx.opencodeCursor]) {
36
- ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
37
- }
38
- return
39
- case 'r':
40
- if (ctx.opencodeSessions[ctx.opencodeCursor]) {
41
- ctx.clearPendingKill()
42
- ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
43
- }
44
- return
45
- }
46
-
47
- return
48
- }
49
-
50
- if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
51
- activatePrefix(ctx)
52
- return
53
- }
54
-
55
- if (keyName === 'escape' || (!ctx.prefixKey && !isStandard && keyName === 'o')) {
56
- ctx.clearPendingKill()
57
- ctx.setAppMode(AppMode.Normal)
58
- return
59
- }
60
-
61
- if (keyName === 'down' || (!isStandard && keyName === 'j')) {
62
- ctx.clearPendingKill()
63
- ctx.setOpencodeCursor(cursor => {
64
- const next = clampCursorIndex(ctx.opencodeSessions.length, cursor + 1)
65
- if (next !== cursor && ctx.opencodeSessions[next]) {
66
- void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[next].title)
67
- }
68
- return next
69
- })
70
- return
71
- }
72
-
73
- if (keyName === 'up' || (!isStandard && keyName === 'k')) {
74
- ctx.clearPendingKill()
75
- ctx.setOpencodeCursor(cursor => {
76
- const next = clampCursorIndex(ctx.opencodeSessions.length, cursor - 1)
77
- if (next !== cursor && ctx.opencodeSessions[next]) {
78
- void ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[next].title)
79
- }
80
- return next
81
- })
82
- return
83
- }
84
-
85
- if (!isStandard && keyName === 'd') {
86
- if (ctx.opencodeSessions[ctx.opencodeCursor]) {
87
- ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
88
- }
89
- return
90
- }
91
-
92
- if (!ctx.prefixKey && !isStandard && keyName === 'r') {
93
- if (ctx.opencodeSessions[ctx.opencodeCursor]) {
94
- ctx.clearPendingKill()
95
- ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
96
- }
97
- return
98
- }
99
-
100
- if (!ctx.prefixKey && !isStandard && keyName === ',') {
101
- ctx.clearPendingKill()
102
- ctx.openSettingsModal()
103
- return
104
- }
105
- }