mux-sesh 1.9.7 → 1.9.9

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 CHANGED
@@ -20,7 +20,7 @@ Fast tmux session and Herdr workspace switching from a polished terminal UI.
20
20
  Prerequisites:
21
21
 
22
22
  - [Bun](https://bun.sh)
23
- - [tmux](https://github.com/tmux/tmux/wiki) or Herdr 0.7.5
23
+ - [tmux](https://github.com/tmux/tmux/wiki) or Herdr 0.7.5 or newer
24
24
  - [git](https://git-scm.com) for cloning GitHub repositories from the new-session flow
25
25
 
26
26
  Install globally:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "mux-sesh",
4
- "version": "1.9.7",
4
+ "version": "1.9.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.14",
@@ -174,6 +174,10 @@ export function useAppController() {
174
174
  showMessage,
175
175
  refreshItems,
176
176
  setPendingKillSessionName,
177
+ regularSessions,
178
+ rememberedSessions: (key: string | null) => {
179
+ lastSessionSelectionRef.current = key
180
+ },
177
181
  }),
178
182
  setPendingKillSessionName,
179
183
  setRenameTarget,
@@ -213,6 +217,9 @@ export function useAppController() {
213
217
  refreshItems,
214
218
  agentCursor,
215
219
  regularSessions,
220
+ rememberedSessions: (key: string | null) => {
221
+ lastSessionSelectionRef.current = key
222
+ },
216
223
  agentSessions,
217
224
  selectedPrimaryItem,
218
225
  sessionCandidateItems,
@@ -28,6 +28,8 @@ interface SharedHandlerOptions {
28
28
 
29
29
  interface KillHandlerOptions extends SharedHandlerOptions {
30
30
  setPendingKillSessionName: (sessionName: string | null) => void
31
+ regularSessions: Item[]
32
+ rememberedSessions: (key: string | null) => void
31
33
  }
32
34
 
33
35
  interface SettingsHandlerOptions {
@@ -53,6 +55,8 @@ export async function handleKillSessionWithFeedback(
53
55
  onSuccess: msg => options.showMessage(msg),
54
56
  onError: msg => options.showMessage(msg, 3000),
55
57
  refreshItems: () => options.refreshItems(),
58
+ regularSessions: options.regularSessions,
59
+ rememberedSessions: options.rememberedSessions,
56
60
  })
57
61
  }
58
62
 
@@ -260,6 +264,7 @@ interface CreateAppHandlersOptions extends SharedHandlerOptions {
260
264
  renamedValue: string
261
265
  searchTerm: string
262
266
  loadOpencodeStatsForSession: (sessionName: string) => Promise<OpencodeSessionStats | null>
267
+ rememberedSessions: (key: string | null) => void
263
268
  }
264
269
 
265
270
  export function createAppHandlers(options: CreateAppHandlersOptions) {
@@ -277,6 +282,8 @@ export function createAppHandlers(options: CreateAppHandlersOptions) {
277
282
  await handleKillSessionWithFeedback(item, {
278
283
  ...sharedOptions,
279
284
  setPendingKillSessionName: options.setPendingKillSessionName,
285
+ regularSessions: options.regularSessions,
286
+ rememberedSessions: options.rememberedSessions,
280
287
  })
281
288
  }
282
289
 
@@ -1,7 +1,7 @@
1
1
  import { dirname } from 'path'
2
2
  import type { Config, Item } from '../types'
3
3
  import type { MultiplexerBackend } from '../multiplexer'
4
- import { getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
4
+ import { getItemKey, getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
5
5
  import { getGitRoot, resolveProjectSession } from '../config/session-rules'
6
6
  import { isFileItem, resolveFileSession } from '../files/target'
7
7
  import { requestShutdown } from '../util/shutdown'
@@ -38,6 +38,14 @@ export function getNextSessionName(renameTarget: string, newName: string): strin
38
38
  return trimmedName
39
39
  }
40
40
 
41
+ export function getSessionSelectionAfterRemoval(
42
+ regularSessions: Item[],
43
+ removed: Item
44
+ ): string | null {
45
+ const neighbor = regularSessions.find(session => session.title === removed.title)
46
+ return neighbor ? getItemKey(neighbor) : null
47
+ }
48
+
41
49
  export async function openProjectSession(
42
50
  projectPath: string,
43
51
  config: Config,
@@ -1,7 +1,7 @@
1
1
  import { spawn } from 'bun'
2
2
  import type { Item, Config } from '../types'
3
3
  import type { MultiplexerBackend } from '../multiplexer'
4
- import { getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
4
+ import { getItemKey, getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
5
5
  import { getLastSessionTarget } from '../tmux/workflows'
6
6
  import { isFileItem, resolveTypedPathTarget } from '../files/target'
7
7
  import { isGitHubURL, cloneGitHubRepo } from '../util/github'
@@ -31,6 +31,13 @@ export async function handleSelect(item: Item, config: Config | null, backend: M
31
31
  await openProjectSession(item.path, requireConfig(config), backend)
32
32
  }
33
33
 
34
+ function getKillNeighbor(item: Item, regularSessions: Item[]): Item | undefined {
35
+ const sessions = regularSessions.filter(isLiveSessionItem)
36
+ const index = sessions.findIndex(session => getItemKey(session) === getItemKey(item))
37
+ if (index < 0) return undefined
38
+ return sessions[index - 1] ?? sessions[index + 1]
39
+ }
40
+
34
41
  export async function handleKillSession(
35
42
  item: Item,
36
43
  backend: MultiplexerBackend,
@@ -38,17 +45,47 @@ export async function handleKillSession(
38
45
  onSuccess: (message: string) => void
39
46
  onError: (message: string) => void
40
47
  refreshItems: () => Promise<void>
48
+ regularSessions: Item[]
49
+ rememberedSessions: (key: string | null) => void
41
50
  }
42
51
  ) {
52
+ let closed = false
53
+
43
54
  try {
44
55
  if (!isLiveSessionItem(item)) throw new Error('Select a live session to close')
45
- await backend.close(getWorkspaceRef(item))
56
+
57
+ const target = getWorkspaceRef(item)
58
+ const neighbor = getKillNeighbor(item, callbacks.regularSessions)
59
+ const prior = await backend.current().catch(() => undefined)
60
+ const wasCurrent = prior !== undefined && prior.id === target.id
61
+
62
+ await backend.close(target)
63
+ closed = true
64
+
65
+ callbacks.rememberedSessions(neighbor ? getItemKey(neighbor) : null)
66
+
67
+ if (!wasCurrent && prior) {
68
+ const now = await backend.current().catch(() => undefined)
69
+ if (!now || now.id !== prior.id) {
70
+ await backend.open(prior)
71
+ }
72
+ } else if (wasCurrent && neighbor && isLiveSessionItem(neighbor)) {
73
+ const preferred = getWorkspaceRef(neighbor)
74
+ const now = await backend.current().catch(() => undefined)
75
+ if (!now || now.id !== preferred.id) {
76
+ await backend.open(preferred)
77
+ }
78
+ }
79
+
46
80
  callbacks.onSuccess(
47
81
  `${backend.kind === 'herdr' ? 'Workspace' : 'Session'} '${item.title}' closed`
48
82
  )
49
- await callbacks.refreshItems()
50
83
  } catch (error) {
51
84
  callbacks.onError(`Error killing session: ${error}`)
85
+ } finally {
86
+ if (closed) {
87
+ await callbacks.refreshItems().catch(() => {})
88
+ }
52
89
  }
53
90
  }
54
91
 
@@ -76,7 +76,7 @@ export interface HerdrStatus {
76
76
  protocol?: number
77
77
  }
78
78
 
79
- export const SUPPORTED_HERDR_PROTOCOL = 17
79
+ export const MIN_SUPPORTED_HERDR_PROTOCOL = 17
80
80
 
81
81
  function isRecord(value: unknown): value is Record<string, unknown> {
82
82
  return typeof value === 'object' && value !== null && !Array.isArray(value)
@@ -26,7 +26,7 @@ export async function resolveMultiplexerBackend(
26
26
  if (herdr.compatible !== true) {
27
27
  throw new MultiplexerError(
28
28
  'protocol-mismatch',
29
- 'The active Herdr client and server are not compatible with mux-sesh. Herdr 0.7.5 protocol 17 is required.'
29
+ 'The active Herdr client and server are not compatible with mux-sesh. Herdr 0.7.5 or newer with protocol 17 or newer is required.'
30
30
  )
31
31
  }
32
32
  return createHerdrBackend({ runner, insideHerdr: true })
@@ -1,6 +1,6 @@
1
1
  import { MultiplexerError, type BackendKind, type BackendPreference } from './types'
2
2
  import type { CommandRunner } from './command'
3
- import { parseHerdrStatus, SUPPORTED_HERDR_PROTOCOL } from '../herdr/protocol'
3
+ import { MIN_SUPPORTED_HERDR_PROTOCOL, parseHerdrStatus } from '../herdr/protocol'
4
4
 
5
5
  export interface BackendState {
6
6
  installed: boolean
@@ -22,7 +22,10 @@ export async function probeHerdrAvailability(runner: CommandRunner): Promise<Bac
22
22
  return {
23
23
  installed: true,
24
24
  running: status.running,
25
- compatible: status.compatible === true && status.protocol === SUPPORTED_HERDR_PROTOCOL,
25
+ compatible:
26
+ status.compatible === true &&
27
+ status.protocol !== undefined &&
28
+ status.protocol >= MIN_SUPPORTED_HERDR_PROTOCOL,
26
29
  }
27
30
  }
28
31