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
@@ -8,30 +8,33 @@ import {
8
8
  getStatusLabel,
9
9
  } from './view'
10
10
  import { syncTextareaValue } from './textarea'
11
+ import { isOpencodeSessionItem } from '../opencode/session-name'
11
12
  import { AppMode, ViewMode, type Config, type Item, type ThemeColors } from '../types'
12
13
  import { isGitHubURL } from '../util/github'
13
14
  import { shouldShowDetailPanel } from '../util/terminal'
14
15
  import SearchInput from '../ui/SearchInput'
15
16
  import SessionList from '../ui/SessionList'
16
- import OpencodeSessionGroup from '../ui/OpencodeSessionGroup'
17
+ import AgentSessionGroup from '../ui/AgentSessionGroup'
17
18
  import ItemList from '../ui/ItemList'
18
19
  import OpencodeStatsPanel from '../ui/OpencodeStatsPanel'
19
20
  import SessionDetailsPanel from '../ui/SessionDetailsPanel'
20
21
  import Toast from '../ui/Toast'
21
22
  import VersionBadge, { formatVersionBadge } from '../ui/VersionBadge'
22
23
  import { CURRENT_VERSION } from '../update/version'
24
+ import type { MultiplexerBackend } from '../multiplexer'
23
25
 
24
26
  interface Props {
25
27
  theme: ThemeColors
26
28
  appMode: AppMode
27
29
  viewMode: ViewMode
28
30
  config: Config | null
31
+ backend: MultiplexerBackend | null
29
32
  items: Item[]
30
33
  regularSessions: Item[]
31
- opencodeSessions: Item[]
34
+ agentSessions: Item[]
32
35
  selectedPrimaryItem?: Item
33
36
  cursor: number
34
- opencodeCursor: number
37
+ agentCursor: number
35
38
  searchQuery: string
36
39
  prefixActive: boolean
37
40
  pendingKillSessionName: string | null
@@ -52,12 +55,13 @@ export function AppScreen({
52
55
  appMode,
53
56
  viewMode,
54
57
  config,
58
+ backend,
55
59
  items,
56
60
  regularSessions,
57
- opencodeSessions,
61
+ agentSessions,
58
62
  selectedPrimaryItem,
59
63
  cursor,
60
- opencodeCursor,
64
+ agentCursor,
61
65
  searchQuery,
62
66
  prefixActive,
63
67
  pendingKillSessionName,
@@ -72,13 +76,19 @@ export function AppScreen({
72
76
  toastVisible,
73
77
  updatedVersion,
74
78
  }: Props) {
75
- const title = getAppTitle(appMode, viewMode)
79
+ const title = getAppTitle(appMode, viewMode, backend?.kind)
76
80
  const listStyle = getListStyle(theme, appMode)
77
81
  const totalSessions = sessionItems.filter(item => item.isSession).length
78
82
  const activeSessions = items.filter(item => item.isSession && item.isAttached).length
79
83
  const maxVisibleItems = Math.max(8, rows - (appMode === AppMode.NewSession ? 10 : 12))
80
84
  const versionLabel = formatVersionBadge(CURRENT_VERSION, updatedVersion)
81
- const footerHint = getFooterHint(appMode, config?.prefixKey)
85
+ const selectedAgentSession = agentSessions[agentCursor]
86
+ const showOpencodeStats =
87
+ viewMode === ViewMode.Sessions &&
88
+ appMode === AppMode.AgentsManage &&
89
+ selectedAgentSession !== undefined &&
90
+ isOpencodeSessionItem(selectedAgentSession)
91
+ const footerHint = getFooterHint(appMode, config?.prefixKey, selectedPrimaryItem)
82
92
 
83
93
  return (
84
94
  <>
@@ -134,7 +144,7 @@ export function AppScreen({
134
144
  flexShrink: 0,
135
145
  marginTop:
136
146
  viewMode === ViewMode.Sessions &&
137
- (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage)
147
+ (appMode === AppMode.Normal || appMode === AppMode.AgentsManage)
138
148
  ? 1
139
149
  : 0,
140
150
  }}
@@ -144,7 +154,7 @@ export function AppScreen({
144
154
  {getEmptyStateMessage(appMode, searchQuery, isGitHubURL(searchQuery))}
145
155
  </text>
146
156
  ) : viewMode === ViewMode.Sessions &&
147
- (appMode === AppMode.Normal || appMode === AppMode.OpencodeManage) ? (
157
+ (appMode === AppMode.Normal || appMode === AppMode.AgentsManage) ? (
148
158
  <>
149
159
  <SessionList
150
160
  items={regularSessions}
@@ -155,10 +165,11 @@ export function AppScreen({
155
165
  pendingKillSessionName={pendingKillSessionName}
156
166
  />
157
167
 
158
- <OpencodeSessionGroup
159
- sessions={opencodeSessions}
168
+ <AgentSessionGroup
169
+ sessions={agentSessions}
160
170
  appMode={appMode}
161
- cursor={opencodeCursor}
171
+ cursor={agentCursor}
172
+ maxItems={maxVisibleItems}
162
173
  icons={config?.icons}
163
174
  pendingKillSessionName={pendingKillSessionName}
164
175
  />
@@ -178,10 +189,14 @@ export function AppScreen({
178
189
  </box>
179
190
 
180
191
  {shouldShowDetailPanel(columns, appMode === AppMode.NewSession) &&
181
- (viewMode === ViewMode.Sessions && appMode === AppMode.OpencodeManage ? (
182
- <OpencodeStatsPanel selectedItem={opencodeSessions[opencodeCursor]} />
192
+ (showOpencodeStats ? (
193
+ <OpencodeStatsPanel selectedItem={selectedAgentSession} />
183
194
  ) : (
184
- <SessionDetailsPanel selectedItem={selectedPrimaryItem} config={config} />
195
+ <SessionDetailsPanel
196
+ selectedItem={selectedPrimaryItem}
197
+ config={config}
198
+ backend={backend}
199
+ />
185
200
  ))}
186
201
  </box>
187
202
 
package/src/app/state.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useEffect, type Dispatch, type MutableRefObject, type SetStateAction } from 'react'
2
2
  import { loadConfig } from '../config'
3
3
  import { AppMode, ViewMode, type Config, type Item } from '../types'
4
+ import { resolveMultiplexerBackend, type MultiplexerBackend } from '../multiplexer'
4
5
  import {
5
6
  getProjectSelectionIndex,
6
7
  getSessionSelectionIndex,
@@ -21,11 +22,12 @@ export async function loadRefreshedViewState(
21
22
  targetMode: ViewMode,
22
23
  config: Config,
23
24
  measure: Measure,
25
+ backend: MultiplexerBackend,
24
26
  lastSessionSelection?: string | null,
25
27
  lastProjectSelection?: string | null
26
28
  ): Promise<RefreshedViewState> {
27
29
  if (targetMode === ViewMode.Sessions) {
28
- const { sessionItems } = await loadSessionItems(config, measure, 'refresh')
30
+ const { sessionItems } = await loadSessionItems(config, measure, backend, 'refresh')
29
31
  return {
30
32
  items: sessionItems,
31
33
  sessionItems,
@@ -33,7 +35,7 @@ export async function loadRefreshedViewState(
33
35
  }
34
36
  }
35
37
 
36
- const { visibleSessions } = await loadSessionItems(config, measure, 'refresh-projects')
38
+ const { visibleSessions } = await loadSessionItems(config, measure, backend, 'refresh-projects')
37
39
  const { projectSourceItems, projectItems } = await loadProjectItemsWithLinks(
38
40
  config,
39
41
  visibleSessions,
@@ -74,6 +76,8 @@ export function useAppStartup(
74
76
  lastProjectSelectionRef: MutableRefObject<string | null>,
75
77
  mark: (label: string) => void,
76
78
  setConfig: Dispatch<SetStateAction<Config | null>>,
79
+ setBackend: Dispatch<SetStateAction<MultiplexerBackend | null>>,
80
+ setMessage: Dispatch<SetStateAction<string>>,
77
81
  setAppMode: Dispatch<SetStateAction<AppMode>>,
78
82
  setViewMode: Dispatch<SetStateAction<ViewMode>>,
79
83
  setSessionItems: Dispatch<SetStateAction<Item[]>>,
@@ -93,10 +97,20 @@ export function useAppStartup(
93
97
  }
94
98
 
95
99
  const startupAppMode = config.keybindMode === 'standard' ? AppMode.Search : AppMode.Normal
100
+ const backend = await measure('resolveBackend', () =>
101
+ resolveMultiplexerBackend({ preference: config.backend })
102
+ )
103
+ if (cancelled) return
96
104
  setConfig(config)
105
+ setBackend(backend)
97
106
  setAppMode(startupAppMode)
98
107
 
99
- const { visibleSessions, sessionItems } = await loadSessionItems(config, measure, 'startup')
108
+ const { visibleSessions, sessionItems } = await loadSessionItems(
109
+ config,
110
+ measure,
111
+ backend,
112
+ 'startup'
113
+ )
100
114
  if (cancelled) {
101
115
  return
102
116
  }
@@ -136,7 +150,11 @@ export function useAppStartup(
136
150
  mark('startup complete')
137
151
  }
138
152
 
139
- void init()
153
+ void init().catch(error => {
154
+ if (!cancelled) {
155
+ setMessage(error instanceof Error ? error.message : 'Failed to start mux-sesh')
156
+ }
157
+ })
140
158
 
141
159
  return () => {
142
160
  cancelled = true
@@ -149,6 +167,8 @@ export function useAppStartup(
149
167
  setAllItems,
150
168
  setAppMode,
151
169
  setConfig,
170
+ setBackend,
171
+ setMessage,
152
172
  setCursor,
153
173
  setItems,
154
174
  setProjectSourceItems,
package/src/app/view.ts CHANGED
@@ -1,30 +1,39 @@
1
+ import { isAgentSessionItem } from '../agents/session-name'
2
+ import { isHerdrAgentItem } from '../multiplexer/items'
1
3
  import { getPanelStyle } from '../styles/theme'
2
- import { isOpencodeSessionItem } from '../opencode/session-name'
3
- import { AppMode, ViewMode, type ThemeColors } from '../types'
4
+ import { AppMode, ViewMode, type BackendKind, type Item, type ThemeColors } from '../types'
4
5
 
5
6
  export function splitVisibleSessions<T extends { isSession: boolean; title: string }>(
6
7
  items: readonly T[]
7
8
  ) {
8
9
  return {
9
- regularSessions: items.filter(item => !isOpencodeSessionItem(item)),
10
- opencodeSessions: items.filter(isOpencodeSessionItem),
10
+ regularSessions: items.filter(item => !isAgentSessionItem(item)),
11
+ agentSessions: items.filter(isAgentSessionItem),
11
12
  }
12
13
  }
13
14
 
14
- export function getAppTitle(appMode: AppMode, viewMode: ViewMode): string {
15
+ export function getAppTitle(
16
+ appMode: AppMode,
17
+ viewMode: ViewMode,
18
+ backend: BackendKind = 'tmux'
19
+ ): string {
15
20
  if (appMode === AppMode.Search) {
16
21
  return 'Search'
17
22
  }
18
23
 
19
24
  if (appMode === AppMode.NewSession) {
20
- return 'New Session'
25
+ return backend === 'herdr' ? 'New Workspace' : 'New Session'
21
26
  }
22
27
 
23
- if (appMode === AppMode.OpencodeManage) {
24
- return 'OpenCode Sessions'
28
+ if (appMode === AppMode.AgentsManage) {
29
+ return 'Agent Sessions'
25
30
  }
26
31
 
27
- return viewMode === ViewMode.Projects ? 'Projects' : 'Sessions'
32
+ return viewMode === ViewMode.Projects
33
+ ? 'Projects'
34
+ : backend === 'herdr'
35
+ ? 'Workspaces'
36
+ : 'Sessions'
28
37
  }
29
38
 
30
39
  export function getListStyle(theme: ThemeColors, appMode: AppMode) {
@@ -55,11 +64,13 @@ export function getStatusLabel(
55
64
  : `${projectCount} projects`
56
65
  }
57
66
 
58
- export function getFooterHint(appMode: AppMode, prefixKey?: string): string {
67
+ export function getFooterHint(appMode: AppMode, prefixKey?: string, selectedItem?: Item): string {
59
68
  const prefixLabel = prefixKey ? `${prefixKey} ...` : 'direct keys'
60
69
 
61
- if (appMode === AppMode.OpencodeManage) {
62
- return `o back d kill ctrl+p commands ${prefixLabel}`
70
+ if (appMode === AppMode.AgentsManage) {
71
+ return isHerdrAgentItem(selectedItem)
72
+ ? `o back enter focus ctrl+p commands ${prefixLabel}`
73
+ : `o back d kill ctrl+p commands ${prefixLabel}`
63
74
  }
64
75
 
65
76
  if (appMode === AppMode.NewSession) {
@@ -70,7 +81,7 @@ export function getFooterHint(appMode: AppMode, prefixKey?: string): string {
70
81
  return 'enter select esc cancel'
71
82
  }
72
83
 
73
- return `enter select i search n new o opencode d kill ctrl+p commands ${prefixLabel}`
84
+ return `enter select i search n new o agents d kill ctrl+p commands ${prefixLabel}`
74
85
  }
75
86
 
76
87
  export function getEmptyStateMessage(
@@ -1,6 +1,7 @@
1
1
  import { join } from 'path'
2
2
  import type {
3
3
  Config,
4
+ BackendPreference,
4
5
  IconConfig,
5
6
  KeybindMode,
6
7
  ProjectProfile,
@@ -22,6 +23,7 @@ const DEFAULT_EDITOR_COMMAND =
22
23
  "nvim -c \"lua vim.defer_fn(function() if pcall(require, 'telescope') then vim.cmd('Telescope find_files') end end, 100)\""
23
24
  const DEFAULT_ICONS: IconConfig = {
24
25
  tmux: '',
26
+ herdr: '',
25
27
  configured: '',
26
28
  project: '',
27
29
  opencode: '',
@@ -86,6 +88,10 @@ function asSortOrder(value: unknown): SortOrder | undefined {
86
88
  : undefined
87
89
  }
88
90
 
91
+ function asBackendPreference(value: unknown): BackendPreference | undefined {
92
+ return value === 'tmux' || value === 'herdr' ? value : undefined
93
+ }
94
+
89
95
  function asThemeColorScheme(value: unknown): ThemeColorScheme | undefined {
90
96
  return value === 'light' || value === 'dark' || value === 'system' ? value : undefined
91
97
  }
@@ -127,6 +133,7 @@ function normalizeIcons(value: unknown): IconConfig | undefined {
127
133
 
128
134
  return {
129
135
  tmux: asString(value.tmux) ?? DEFAULT_ICONS.tmux,
136
+ herdr: asString(value.herdr) ?? DEFAULT_ICONS.herdr,
130
137
  configured: asString(value.configured) ?? asString(value.config) ?? DEFAULT_ICONS.configured,
131
138
  project: asString(value.project) ?? DEFAULT_ICONS.project,
132
139
  opencode: asString(value.opencode) ?? DEFAULT_ICONS.opencode,
@@ -315,6 +322,7 @@ export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME |
315
322
  homeDir
316
323
  )
317
324
  const editor = asString(raw.editor) ?? defaultConfig.editor
325
+ const backend = asBackendPreference(raw.backend)
318
326
  const editorCmd = asString(raw.editor_cmd) ?? asString(raw.editorCmd) ?? defaultConfig.editorCmd
319
327
  const keybindMode =
320
328
  asKeybindMode(raw.keybind_mode) ?? asKeybindMode(raw.keybindMode) ?? defaultConfig.keybindMode
@@ -350,6 +358,7 @@ export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME |
350
358
  }
351
359
 
352
360
  return {
361
+ backend,
353
362
  projectPaths,
354
363
  reposPath,
355
364
  editor,
@@ -411,6 +420,7 @@ function serializeThemeVariant(variant: ThemeVariant) {
411
420
 
412
421
  export function serializeConfig(config: Config): Record<string, unknown> {
413
422
  return {
423
+ backend: config.backend,
414
424
  project_paths: config.projectPaths,
415
425
  repos_path: config.reposPath,
416
426
  editor: config.editor,
@@ -1,8 +1,9 @@
1
1
  import { dirname } from 'path'
2
2
  import type { Config, Item } from '../types'
3
+ import type { MultiplexerBackend } from '../multiplexer'
4
+ import { getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
3
5
  import { getGitRoot, resolveProjectSession } from '../config/session-rules'
4
6
  import { isFileItem, resolveFileSession } from '../files/target'
5
- import { createTmuxSession, getTmuxSessionDirectory } from '../tmux'
6
7
  import { requestShutdown } from '../util/shutdown'
7
8
  import { quoteShellArg } from '../util/shell'
8
9
 
@@ -37,24 +38,38 @@ export function getNextSessionName(renameTarget: string, newName: string): strin
37
38
  return trimmedName
38
39
  }
39
40
 
40
- export async function openProjectSession(projectPath: string, config: Config): Promise<void> {
41
+ export async function openProjectSession(
42
+ projectPath: string,
43
+ config: Config,
44
+ backend: MultiplexerBackend
45
+ ): Promise<void> {
41
46
  const resolvedSession = await resolveProjectSession(projectPath, config)
42
- await createTmuxSession(resolvedSession.sessionName, projectPath, {
47
+ await backend.openOrCreate({
48
+ title: resolvedSession.sessionName,
49
+ path: projectPath,
43
50
  startupCommand: resolvedSession.startupCommand,
44
51
  })
45
52
  await requestShutdown(0)
46
53
  }
47
54
 
48
- export async function openFileSession(filePath: string, config: Config): Promise<void> {
55
+ export async function openFileSession(
56
+ filePath: string,
57
+ config: Config,
58
+ backend: MultiplexerBackend
59
+ ): Promise<void> {
49
60
  const resolvedSession = resolveFileSession(filePath, config)
50
- await createTmuxSession(resolvedSession.sessionName, resolvedSession.cwd, {
61
+ await backend.openOrCreate({
62
+ title: resolvedSession.sessionName,
63
+ path: resolvedSession.cwd,
51
64
  startupCommand: resolvedSession.startupCommand,
52
65
  })
53
66
  await requestShutdown(0)
54
67
  }
55
68
 
56
- export async function getRootSessionPath(item: Item): Promise<string> {
57
- const itemPath = item.isSession ? await getTmuxSessionDirectory(item.title) : item.path
69
+ export async function getRootSessionPath(item: Item, backend: MultiplexerBackend): Promise<string> {
70
+ const itemPath = isLiveSessionItem(item)
71
+ ? ((await backend.directory(getWorkspaceRef(item))) ?? item.path)
72
+ : item.path
58
73
  const searchRoot = !item.isSession && isFileItem(item) ? dirname(itemPath) : itemPath
59
74
  return (await getGitRoot(searchRoot)) ?? searchRoot
60
75
  }
@@ -1,12 +1,7 @@
1
1
  import { spawn } from 'bun'
2
2
  import type { Item, Config } from '../types'
3
- import {
4
- switchTmuxSession,
5
- killTmuxSession,
6
- renameTmuxSession,
7
- createNamedTmuxSession,
8
- getCurrentTmuxSessionName,
9
- } from '../tmux'
3
+ import type { MultiplexerBackend } from '../multiplexer'
4
+ import { getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
10
5
  import { getLastSessionTarget } from '../tmux/workflows'
11
6
  import { isFileItem, resolveTypedPathTarget } from '../files/target'
12
7
  import { isGitHubURL, cloneGitHubRepo } from '../util/github'
@@ -21,23 +16,24 @@ import {
21
16
  requireConfiguredItem,
22
17
  } from './action-helpers'
23
18
 
24
- export async function handleSelect(item: Item, config: Config | null) {
25
- if (item.isSession) {
26
- await switchTmuxSession(item.title)
19
+ export async function handleSelect(item: Item, config: Config | null, backend: MultiplexerBackend) {
20
+ if (isLiveSessionItem(item)) {
21
+ await backend.open(getWorkspaceRef(item))
27
22
  await requestShutdown(0)
28
23
  return
29
24
  }
30
25
 
31
26
  if (isFileItem(item)) {
32
- await openFileSession(item.path, requireConfig(config))
27
+ await openFileSession(item.path, requireConfig(config), backend)
33
28
  return
34
29
  }
35
30
 
36
- await openProjectSession(item.path, requireConfig(config))
31
+ await openProjectSession(item.path, requireConfig(config), backend)
37
32
  }
38
33
 
39
34
  export async function handleKillSession(
40
- sessionName: string,
35
+ item: Item,
36
+ backend: MultiplexerBackend,
41
37
  callbacks: {
42
38
  onSuccess: (message: string) => void
43
39
  onError: (message: string) => void
@@ -45,8 +41,11 @@ export async function handleKillSession(
45
41
  }
46
42
  ) {
47
43
  try {
48
- await killTmuxSession(sessionName)
49
- callbacks.onSuccess(`Session '${sessionName}' killed`)
44
+ if (!isLiveSessionItem(item)) throw new Error('Select a live session to close')
45
+ await backend.close(getWorkspaceRef(item))
46
+ callbacks.onSuccess(
47
+ `${backend.kind === 'herdr' ? 'Workspace' : 'Session'} '${item.title}' closed`
48
+ )
50
49
  await callbacks.refreshItems()
51
50
  } catch (error) {
52
51
  callbacks.onError(`Error killing session: ${error}`)
@@ -54,22 +53,26 @@ export async function handleKillSession(
54
53
  }
55
54
 
56
55
  export async function handleRenameSubmit(
57
- renameTarget: string,
56
+ renameTarget: Item,
58
57
  newName: string,
58
+ backend: MultiplexerBackend,
59
59
  callbacks: {
60
60
  onSuccess: (message: string) => void
61
61
  onError: (message: string) => void
62
62
  refreshItems: () => Promise<void>
63
63
  }
64
64
  ) {
65
- const nextSessionName = getNextSessionName(renameTarget, newName)
65
+ if (!isLiveSessionItem(renameTarget)) return
66
+ const nextSessionName = getNextSessionName(renameTarget.title, newName)
66
67
  if (!nextSessionName) {
67
68
  return
68
69
  }
69
70
 
70
71
  try {
71
- await renameTmuxSession(renameTarget, nextSessionName)
72
- callbacks.onSuccess(`Session renamed to '${nextSessionName}'`)
72
+ await backend.rename(getWorkspaceRef(renameTarget), nextSessionName)
73
+ callbacks.onSuccess(
74
+ `${backend.kind === 'herdr' ? 'Workspace' : 'Session'} renamed to '${nextSessionName}'`
75
+ )
73
76
  await callbacks.refreshItems()
74
77
  } catch (error) {
75
78
  callbacks.onError(`Error renaming session: ${error}`)
@@ -80,7 +83,8 @@ export async function handleNewSessionSubmit(
80
83
  searchTerm: string,
81
84
  config: Config | null,
82
85
  items: Item[],
83
- cursor: number
86
+ cursor: number,
87
+ backend: MultiplexerBackend
84
88
  ) {
85
89
  if (!searchTerm) return
86
90
 
@@ -88,7 +92,7 @@ export async function handleNewSessionSubmit(
88
92
  try {
89
93
  if (!config) return
90
94
  const clonedPath = await cloneGitHubRepo(searchTerm, config)
91
- await openProjectSession(clonedPath, config)
95
+ await openProjectSession(clonedPath, config, backend)
92
96
  } catch (error) {
93
97
  throw new Error(`Error cloning repository: ${error}`)
94
98
  }
@@ -98,64 +102,69 @@ export async function handleNewSessionSubmit(
98
102
  const typedTarget = await resolveTypedPathTarget(searchTerm)
99
103
  if (typedTarget) {
100
104
  if (typedTarget.kind === 'file') {
101
- await openFileSession(typedTarget.path, requireConfig(config))
105
+ await openFileSession(typedTarget.path, requireConfig(config), backend)
102
106
  return
103
107
  }
104
108
 
105
- await openProjectSession(typedTarget.path, requireConfig(config))
109
+ await openProjectSession(typedTarget.path, requireConfig(config), backend)
106
110
  return
107
111
  }
108
112
 
109
113
  if (items.length > 0 && cursor < items.length) {
110
114
  const selectedItem = items[cursor]
111
115
  if (isFileItem(selectedItem)) {
112
- await openFileSession(selectedItem.path, requireConfig(config))
116
+ await openFileSession(selectedItem.path, requireConfig(config), backend)
113
117
  return
114
118
  }
115
119
 
116
- await openProjectSession(selectedItem.path, requireConfig(config))
120
+ await openProjectSession(selectedItem.path, requireConfig(config), backend)
117
121
  return
118
122
  }
119
123
 
120
- await createNamedTmuxSession(searchTerm)
124
+ await backend.openOrCreate({ title: searchTerm, path: process.cwd() })
121
125
  await requestShutdown(0)
122
126
  }
123
127
 
124
- export async function handleLastSession(items: Item[]) {
125
- const currentSessionName = await getCurrentTmuxSessionName().catch(() => undefined)
128
+ export async function handleLastSession(items: Item[], backend: MultiplexerBackend) {
129
+ if (!backend.capabilities.previousWorkspace) {
130
+ throw new Error(
131
+ 'Previous workspace is unavailable because Herdr does not expose workspace activity history'
132
+ )
133
+ }
134
+ const currentSessionName = (await backend.current().catch(() => undefined))?.title
126
135
  const target = getLastSessionTarget(items, currentSessionName)
127
136
 
128
137
  if (!target) {
129
138
  throw new Error('No previous tmux session is available')
130
139
  }
131
140
 
132
- await switchTmuxSession(target.title)
141
+ if (!isLiveSessionItem(target)) throw new Error('No previous live session is available')
142
+ await backend.open(getWorkspaceRef(target))
133
143
  await requestShutdown(0)
134
144
  }
135
145
 
136
- export async function handleRootSession(item: Item | undefined, config: Config | null) {
146
+ export async function handleRootSession(
147
+ item: Item | undefined,
148
+ config: Config | null,
149
+ backend: MultiplexerBackend
150
+ ) {
137
151
  if (!item) {
138
152
  throw new Error('No session or project is selected')
139
153
  }
140
154
 
141
- await openProjectSession(await getRootSessionPath(item), requireConfig(config))
155
+ await openProjectSession(await getRootSessionPath(item, backend), requireConfig(config), backend)
142
156
  }
143
157
 
144
- export async function handleEditTarget(item: Item | undefined, config: Config | null) {
158
+ export async function handleEditTarget(
159
+ item: Item | undefined,
160
+ config: Config | null,
161
+ backend: MultiplexerBackend
162
+ ) {
145
163
  const configuredItem = requireConfiguredItem(item)
146
164
  const loadedConfig = requireConfig(config)
147
165
  const command = buildEditorCommand(loadedConfig.editor, configuredItem.path)
148
166
 
149
- if (process.env.TMUX) {
150
- const proc = spawn(['tmux', 'new-window', '-c', configuredItem.path, command], {
151
- stderr: 'pipe',
152
- })
153
- await proc.exited
154
-
155
- if (proc.exitCode !== 0) {
156
- throw new Error(`Failed to open editor for '${configuredItem.title}'`)
157
- }
158
-
167
+ if (await backend.openEditor(configuredItem.path, command)) {
159
168
  await requestShutdown(0)
160
169
  return
161
170
  }