mux-sesh 1.4.0 → 1.5.0

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.
@@ -1,7 +1,150 @@
1
1
  import { spawn } from 'bun'
2
2
  import { basename } from 'path'
3
- import { stat } from 'fs/promises'
3
+ import { access, stat } from 'fs/promises'
4
4
  import type { Config, Item } from '../types'
5
+ import { normalizePathForMatching } from '../util/glob'
6
+
7
+ interface ZoxideEntry {
8
+ score: number
9
+ path: string
10
+ }
11
+
12
+ const PROJECT_MARKERS = ['.git', '.jj', 'package.json', 'Cargo.toml', 'go.mod', 'pyproject.toml', 'flake.nix']
13
+ function isIgnoredProjectDirectory(baseName: string): boolean {
14
+ return (
15
+ baseName.startsWith('.') ||
16
+ baseName === 'node_modules' ||
17
+ baseName === 'target' ||
18
+ baseName === 'build' ||
19
+ baseName === 'dist'
20
+ )
21
+ }
22
+
23
+ function toProjectItem(projectPath: string): Item {
24
+ return {
25
+ title: basename(projectPath),
26
+ desc: projectPath.replace(process.env.HOME || '', '~'),
27
+ path: projectPath,
28
+ isSession: false,
29
+ itemKind: 'project',
30
+ }
31
+ }
32
+
33
+ async function hasProjectMarker(projectPath: string): Promise<boolean> {
34
+ for (const marker of PROJECT_MARKERS) {
35
+ try {
36
+ await access(`${projectPath}/${marker}`)
37
+ return true
38
+ } catch {}
39
+ }
40
+
41
+ return false
42
+ }
43
+
44
+ export async function filterProjectCandidatePaths(projectPaths: string[]): Promise<string[]> {
45
+ const uniquePaths = [...new Set(projectPaths.map(path => normalizePathForMatching(path)))]
46
+ const matches = await Promise.all(
47
+ uniquePaths.map(async projectPath => ({
48
+ projectPath,
49
+ include: await hasProjectMarker(projectPath),
50
+ }))
51
+ )
52
+
53
+ return matches.filter(match => match.include).map(match => match.projectPath)
54
+ }
55
+
56
+ export function parseZoxideOutput(output: string): ZoxideEntry[] {
57
+ return output
58
+ .trim()
59
+ .split('\n')
60
+ .filter(Boolean)
61
+ .flatMap(line => {
62
+ const trimmed = line.trim()
63
+ const firstSpaceIndex = trimmed.indexOf(' ')
64
+ if (firstSpaceIndex === -1) {
65
+ return []
66
+ }
67
+
68
+ const score = Number(trimmed.slice(0, firstSpaceIndex))
69
+ const path = trimmed.slice(firstSpaceIndex + 1).trim()
70
+ if (!Number.isFinite(score) || !path) {
71
+ return []
72
+ }
73
+
74
+ return [{ score, path }]
75
+ })
76
+ }
77
+
78
+ function isWithinProjectRoots(projectPath: string, projectRoots: string[]): boolean {
79
+ const normalizedProjectPath = normalizePathForMatching(projectPath)
80
+
81
+ return projectRoots.some(projectRoot => {
82
+ const normalizedRoot = normalizePathForMatching(projectRoot)
83
+ return normalizedProjectPath === normalizedRoot || normalizedProjectPath.startsWith(`${normalizedRoot}/`)
84
+ })
85
+ }
86
+
87
+ export function applyZoxideMode(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
88
+ if (config.zoxideMode === 'off' || entries.length === 0) {
89
+ return items.sort((a, b) => a.title.localeCompare(b.title))
90
+ }
91
+
92
+ const zoxideScores = new Map(entries.map(entry => [normalizePathForMatching(entry.path), entry.score]))
93
+ const rankedItems = [...items].sort((left, right) => {
94
+ const scoreDifference =
95
+ (zoxideScores.get(normalizePathForMatching(right.path)) ?? 0) -
96
+ (zoxideScores.get(normalizePathForMatching(left.path)) ?? 0)
97
+
98
+ if (scoreDifference !== 0) {
99
+ return scoreDifference
100
+ }
101
+
102
+ return left.title.localeCompare(right.title)
103
+ })
104
+
105
+ if (config.zoxideMode !== 'merge') {
106
+ return rankedItems
107
+ }
108
+
109
+ const existingPaths = new Set(rankedItems.map(item => normalizePathForMatching(item.path)))
110
+ const mergedItems = entries.flatMap(entry => {
111
+ const normalizedPath = normalizePathForMatching(entry.path)
112
+ const baseName = basename(entry.path)
113
+
114
+ if (
115
+ existingPaths.has(normalizedPath) ||
116
+ !isWithinProjectRoots(entry.path, config.projectPaths) ||
117
+ isIgnoredProjectDirectory(baseName)
118
+ ) {
119
+ return []
120
+ }
121
+
122
+ existingPaths.add(normalizedPath)
123
+ return [toProjectItem(entry.path)]
124
+ })
125
+
126
+ return [...rankedItems, ...mergedItems]
127
+ }
128
+
129
+ async function getZoxideEntries(projectRoots: string[]): Promise<ZoxideEntry[]> {
130
+ try {
131
+ const proc = spawn(['zoxide', 'query', '--list', '--score'])
132
+ const output = await new Response(proc.stdout).text()
133
+ await proc.exited
134
+
135
+ if (proc.exitCode !== 0) {
136
+ return []
137
+ }
138
+
139
+ const entriesWithinRoots = parseZoxideOutput(output).filter(entry => isWithinProjectRoots(entry.path, projectRoots))
140
+ const projectCandidatePaths = await filterProjectCandidatePaths(entriesWithinRoots.map(entry => entry.path))
141
+ const projectCandidates = new Set(projectCandidatePaths)
142
+
143
+ return entriesWithinRoots.filter(entry => projectCandidates.has(normalizePathForMatching(entry.path)))
144
+ } catch {
145
+ return []
146
+ }
147
+ }
5
148
 
6
149
  export async function getProjectItems(config: Config): Promise<Item[]> {
7
150
  const items: Item[] = []
@@ -25,31 +168,19 @@ export async function getProjectItems(config: Config): Promise<Item[]> {
25
168
 
26
169
  const lines = output.trim().split('\n').filter(Boolean)
27
170
 
28
- for (const line of lines) {
171
+ const projectCandidatePaths = await filterProjectCandidatePaths(lines)
172
+
173
+ for (const line of projectCandidatePaths) {
29
174
  const baseName = basename(line)
30
175
 
31
- if (
32
- baseName.startsWith('.') ||
33
- baseName === 'node_modules' ||
34
- baseName === 'target' ||
35
- baseName === 'build' ||
36
- baseName === 'dist'
37
- ) {
176
+ if (isIgnoredProjectDirectory(baseName)) {
38
177
  continue
39
178
  }
40
179
 
41
- const name = baseName
42
- const desc = line.replace(process.env.HOME || '', '~')
43
-
44
- items.push({
45
- title: name,
46
- desc,
47
- path: line,
48
- isSession: false,
49
- })
180
+ items.push(toProjectItem(line))
50
181
  }
51
182
 
52
- items.sort((a, b) => a.title.localeCompare(b.title))
183
+ const zoxideEntries = config.zoxideMode === 'off' ? [] : await getZoxideEntries(existingPaths)
53
184
 
54
- return items
185
+ return applyZoxideMode(items, zoxideEntries, config)
55
186
  }
@@ -0,0 +1,22 @@
1
+ import type { Item } from '../types'
2
+ import { matchesGlob } from '../util/glob'
3
+
4
+ export function filterHiddenSessions(items: Item[], hiddenSessions: string[] = []): Item[] {
5
+ if (hiddenSessions.length === 0) {
6
+ return items
7
+ }
8
+
9
+ return items.filter(item => {
10
+ if (!item.isSession) {
11
+ return true
12
+ }
13
+
14
+ return !hiddenSessions.some(pattern => matchesGlob(item.title, pattern))
15
+ })
16
+ }
17
+
18
+ export function getLastSessionTarget(items: Item[], currentSessionName?: string): Item | undefined {
19
+ return items
20
+ .filter(item => item.isSession && item.title !== currentSessionName)
21
+ .sort((left, right) => (right.lastActivity ?? 0) - (left.lastActivity ?? 0))[0]
22
+ }
@@ -12,6 +12,37 @@ export enum ViewMode {
12
12
  }
13
13
 
14
14
  export type KeybindMode = 'vim' | 'standard'
15
+ export type ZoxideMode = 'off' | 'rank' | 'merge'
16
+ export type ItemKind = 'tmux' | 'configured' | 'project'
17
+ export type SortOrder = 'live-first' | 'configured-first' | 'zoxide-first' | 'alphabetical'
18
+
19
+ export interface IconConfig {
20
+ tmux: string
21
+ configured: string
22
+ project: string
23
+ opencode: string
24
+ }
25
+
26
+ export interface SessionDefaults {
27
+ startupCommand?: string
28
+ previewCommand?: string
29
+ }
30
+
31
+ export interface ProjectProfile {
32
+ path: string
33
+ sessionName?: string
34
+ startupCommand?: string
35
+ previewCommand?: string
36
+ listed?: boolean
37
+ icon?: string
38
+ }
39
+
40
+ export interface ProjectWildcard {
41
+ pattern: string
42
+ sessionName?: string
43
+ startupCommand?: string
44
+ previewCommand?: string
45
+ }
15
46
 
16
47
  export interface OpencodeSessionStats {
17
48
  sessionID?: string
@@ -39,16 +70,26 @@ export type OpencodeStatsState =
39
70
  | { status: 'missing'; message: string }
40
71
  | { status: 'error'; message: string }
41
72
 
73
+ export interface SearchMatchMetadata {
74
+ titleIndices?: number[]
75
+ descIndices?: number[]
76
+ }
77
+
42
78
  export interface Item {
43
79
  title: string
44
80
  desc: string
45
81
  path: string
46
82
  isSession: boolean
83
+ itemKind?: ItemKind
84
+ icon?: string
47
85
  isAttached?: boolean
86
+ linkedSessionName?: string
87
+ linkedSessionAttached?: boolean
48
88
  windowCount?: string
49
89
  createdAt?: number
50
90
  lastActivity?: number
51
91
  opencodeState?: OpencodeStatsState
92
+ searchMatch?: SearchMatchMetadata
52
93
  }
53
94
 
54
95
  export interface Config {
@@ -58,6 +99,14 @@ export interface Config {
58
99
  editorCmd: string
59
100
  keybindMode?: KeybindMode
60
101
  autoUpdate?: boolean
102
+ dirLength?: number
103
+ hiddenSessions?: string[]
104
+ zoxideMode?: ZoxideMode
105
+ sortOrder?: SortOrder
106
+ icons?: IconConfig
107
+ defaultSession?: SessionDefaults
108
+ projects?: ProjectProfile[]
109
+ wildcards?: ProjectWildcard[]
61
110
  }
62
111
 
63
112
  export interface WindowInfo {
@@ -1,6 +1,8 @@
1
1
  import { colors } from '../styles/theme'
2
- import { AppMode } from '../types'
2
+ import { AppMode, type IconConfig } from '../types'
3
3
  import HighlightedText from './HighlightedText'
4
+ import { getItemIconPresentation } from './item-icon'
5
+ import { getVisibleWindow } from './list-window'
4
6
  import type { Item } from '../types'
5
7
 
6
8
  interface Props {
@@ -9,6 +11,7 @@ interface Props {
9
11
  appMode: AppMode
10
12
  maxItems?: number
11
13
  searchQuery?: string
14
+ icons?: IconConfig
12
15
  }
13
16
 
14
17
  export default function ItemList({
@@ -17,36 +20,38 @@ export default function ItemList({
17
20
  appMode,
18
21
  maxItems = 20,
19
22
  searchQuery = '',
23
+ icons,
20
24
  }: Props) {
21
25
  const isSearching = searchQuery.trim().length > 0
26
+ const visibleWindow = getVisibleWindow(items, cursor, maxItems)
22
27
 
23
28
  return (
24
29
  <>
25
- {items.slice(0, maxItems).map((item, i) => {
26
- const titleMatchIndices = (item as any).titleMatchIndices as number[] | undefined
27
- const descMatchIndices = (item as any).descMatchIndices as number[] | undefined
30
+ {visibleWindow.items.map((item, i) => {
31
+ const absoluteIndex = visibleWindow.startIndex + i
32
+ const titleMatchIndices = item.searchMatch?.titleIndices
33
+ const descMatchIndices = item.searchMatch?.descIndices
28
34
  const hasTitleMatch = titleMatchIndices && titleMatchIndices.length > 0
29
35
  const hasDescMatch = descMatchIndices && descMatchIndices.length > 0
36
+ const icon = getItemIconPresentation(item, icons)
37
+ const sessionStatusLabel = item.linkedSessionName ? 'attach' : 'create'
38
+ const linkedSessionLabel = item.linkedSessionName ? ` -> ${item.linkedSessionName}` : ''
30
39
 
31
40
  return (
32
41
  <box
33
42
  key={i}
34
43
  style={{
35
- backgroundColor: i === cursor ? colors.backgroundAlt : 'transparent',
44
+ backgroundColor: absoluteIndex === cursor ? colors.backgroundAlt : 'transparent',
36
45
  height: 1,
37
46
  paddingLeft: 2,
38
47
  }}
39
48
  >
40
- {i === cursor && <text> </text>}
49
+ {absoluteIndex === cursor && <text> </text>}
41
50
  <text>
42
- {i + 1}{' '}
51
+ {absoluteIndex + 1}{' '}
43
52
  {item.isSession ? (
44
53
  <>
45
- <span
46
- style={{
47
- fg: item.isAttached ? colors.active : colors.inactive,
48
- }}
49
- >
54
+ <span style={{ fg: item.isAttached ? colors.active : colors.inactive }}>
50
55
  {item.isAttached ? '●' : '○'}
51
56
  </span>{' '}
52
57
  {isSearching && hasTitleMatch ? (
@@ -58,14 +63,16 @@ export default function ItemList({
58
63
  </>
59
64
  ) : (
60
65
  <>
66
+ <span style={{ fg: icon.color }}>{icon.glyph}</span>{' '}
61
67
  {appMode === AppMode.NewSession ? (
62
68
  <>
63
- {/* Show path (desc) with highlighting if it matches */}
64
69
  {isSearching && hasDescMatch ? (
65
70
  <HighlightedText text={item.desc} matchIndices={descMatchIndices} />
66
71
  ) : (
67
72
  item.desc
68
- )}
73
+ )}{' '}
74
+ <span style={{ fg: colors.inactive }}>{sessionStatusLabel}</span>
75
+ {linkedSessionLabel && <span style={{ fg: colors.separator }}>{linkedSessionLabel}</span>}
69
76
  </>
70
77
  ) : (
71
78
  <>
@@ -1,62 +1,68 @@
1
1
  import { colors } from '../styles/theme'
2
2
  import { formatSessionAge } from '../util/time'
3
- import type { Item, AppMode } from '../types'
3
+ import type { IconConfig, Item, AppMode } from '../types'
4
4
  import { AppMode as AppModeEnum } from '../types'
5
+ import { formatSectionHeader } from './item-icon'
5
6
 
6
7
  interface Props {
7
8
  sessions: Item[]
8
9
  appMode: AppMode
9
10
  cursor: number
11
+ icons?: IconConfig
10
12
  }
11
13
 
12
- export default function OpencodeSessionGroup({ sessions, appMode, cursor }: Props) {
14
+ export default function OpencodeSessionGroup({ sessions, appMode, cursor, icons }: Props) {
13
15
  if (sessions.length === 0) return null
14
16
 
17
+ const header = formatSectionHeader('opencode', icons)
18
+
15
19
  return (
16
20
  <>
17
21
  <text style={{ fg: colors.separator, marginTop: 2, marginBottom: 1 }}>
18
- ─ Opencode Sessions ─
22
+ <span style={{ fg: header.color }}>{header.text}</span>
19
23
  </text>
20
- {sessions.map((item, i) => (
21
- <box
22
- key={`opencode-${i}`}
23
- style={{
24
- height: 1,
25
- paddingLeft: 2,
26
- backgroundColor:
27
- appMode === AppModeEnum.OpencodeManage && i === cursor
28
- ? colors.backgroundAlt
29
- : 'transparent',
30
- }}
31
- >
32
- {appMode === AppModeEnum.OpencodeManage && i === cursor && <text> </text>}
33
- <text>
24
+ {sessions.map((item, i) => {
25
+ return (
26
+ <box
27
+ key={`opencode-${i}`}
28
+ style={{
29
+ height: 1,
30
+ paddingLeft: 2,
31
+ backgroundColor:
32
+ appMode === AppModeEnum.OpencodeManage && i === cursor
33
+ ? colors.backgroundAlt
34
+ : 'transparent',
35
+ }}
36
+ >
37
+ {appMode === AppModeEnum.OpencodeManage && i === cursor && <text> </text>}
38
+ <text>
34
39
  {appMode === AppModeEnum.OpencodeManage ? `${i + 1} ` : ' '}
35
- <span
36
- style={{
37
- fg:
38
- appMode === AppModeEnum.OpencodeManage
39
- ? item.isAttached
40
- ? colors.active
41
- : colors.inactive
42
- : colors.inactive,
43
- }}
44
- >
45
- {item.isAttached ? '●' : '○'}
46
- </span>{' '}
47
- <span
48
- style={{
49
- fg: appMode === AppModeEnum.OpencodeManage ? colors.text : colors.inactive,
50
- }}
51
- >
52
- {item.title.padEnd(20)}
53
- </span>{' '}
54
- <span style={{ fg: colors.inactive }}>
55
- {item.createdAt ? formatSessionAge(item.createdAt) : ''}
56
- </span>
57
- </text>
58
- </box>
59
- ))}
40
+ <span
41
+ style={{
42
+ fg:
43
+ appMode === AppModeEnum.OpencodeManage
44
+ ? item.isAttached
45
+ ? colors.active
46
+ : colors.inactive
47
+ : colors.inactive,
48
+ }}
49
+ >
50
+ {item.isAttached ? '●' : '○'}
51
+ </span>{' '}
52
+ <span
53
+ style={{
54
+ fg: appMode === AppModeEnum.OpencodeManage ? colors.text : colors.inactive,
55
+ }}
56
+ >
57
+ {item.title.padEnd(20)}
58
+ </span>{' '}
59
+ <span style={{ fg: colors.inactive }}>
60
+ {item.createdAt ? formatSessionAge(item.createdAt) : ''}
61
+ </span>
62
+ </text>
63
+ </box>
64
+ )
65
+ })}
60
66
  <box style={{ marginBottom: 2 }} />
61
67
  </>
62
68
  )
@@ -1,9 +1,11 @@
1
+ import type { TextareaRenderable } from '@opentui/core'
2
+ import { useEffect } from 'react'
1
3
  import { AppMode } from '../types'
2
4
 
3
5
  interface Props {
4
6
  appMode: AppMode
5
7
  searchQuery: string
6
- textareaRef: any
8
+ textareaRef: { current: TextareaRenderable | null }
7
9
  onContentChange: () => void
8
10
  prefixActive?: boolean
9
11
  }
@@ -22,6 +24,22 @@ export default function SearchInput({
22
24
  ? 'Enter new session name...'
23
25
  : 'Type to search...'
24
26
 
27
+ useEffect(() => {
28
+ if (appMode !== AppMode.Rename) {
29
+ return
30
+ }
31
+
32
+ queueMicrotask(() => {
33
+ const textarea = textareaRef.current
34
+ if (!textarea) {
35
+ return
36
+ }
37
+
38
+ textarea.focus()
39
+ textarea.gotoLineEnd()
40
+ })
41
+ }, [appMode, textareaRef])
42
+
25
43
  return (
26
44
  <box
27
45
  style={{