mux-sesh 1.10.0 → 2.0.1
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 +133 -86
- package/bin/mux-sesh +45 -17
- package/bin/platform.sh +139 -0
- package/bin/postinstall +22 -0
- package/package.json +27 -38
- package/src/agents/index.ts +0 -1
- package/src/agents/session-name.ts +0 -24
- package/src/app/commands.ts +0 -138
- package/src/app/controller.ts +0 -437
- package/src/app/controls.ts +0 -123
- package/src/app/core-state.ts +0 -75
- package/src/app/data.ts +0 -130
- package/src/app/derived.ts +0 -77
- package/src/app/effects.ts +0 -650
- package/src/app/handlers.ts +0 -406
- package/src/app/keyboard.ts +0 -165
- package/src/app/modal-keyboard.ts +0 -137
- package/src/app/modal-state.ts +0 -53
- package/src/app/modals-layer.tsx +0 -159
- package/src/app/modals.ts +0 -108
- package/src/app/notifications.ts +0 -21
- package/src/app/opencode.ts +0 -49
- package/src/app/operations.ts +0 -31
- package/src/app/runtime.ts +0 -79
- package/src/app/screen.tsx +0 -240
- package/src/app/state.ts +0 -178
- package/src/app/textarea.ts +0 -16
- package/src/app/view.ts +0 -101
- package/src/app.tsx +0 -50
- package/src/config/index.ts +0 -475
- package/src/config/listed-sessions.ts +0 -33
- package/src/config/paths.ts +0 -13
- package/src/config/session-rules.ts +0 -100
- package/src/config/store.ts +0 -33
- package/src/files/target.ts +0 -96
- package/src/handlers/action-helpers.ts +0 -83
- package/src/handlers/actions.ts +0 -216
- package/src/handlers/keyboard/agents.ts +0 -134
- package/src/handlers/keyboard/index.ts +0 -5
- package/src/handlers/keyboard/new-session.ts +0 -58
- package/src/handlers/keyboard/normal.ts +0 -220
- package/src/handlers/keyboard/search.ts +0 -118
- package/src/handlers/keyboard/shared.ts +0 -117
- package/src/herdr/backend.ts +0 -357
- package/src/herdr/protocol.ts +0 -268
- package/src/index.tsx +0 -23
- package/src/items/order.ts +0 -95
- package/src/multiplexer/backend.ts +0 -43
- package/src/multiplexer/command.ts +0 -48
- package/src/multiplexer/index.ts +0 -21
- package/src/multiplexer/items.ts +0 -66
- package/src/multiplexer/resolve.ts +0 -109
- package/src/multiplexer/tmux-backend.ts +0 -87
- package/src/multiplexer/types.ts +0 -93
- package/src/opencode/constants.ts +0 -7
- package/src/opencode/index.ts +0 -20
- package/src/opencode/parser.ts +0 -45
- package/src/opencode/session-name.ts +0 -13
- package/src/opencode/session.ts +0 -146
- package/src/opencode/sqlite.ts +0 -447
- package/src/opencode/stats.ts +0 -26
- package/src/opencode/tokens.ts +0 -116
- package/src/opencode/types.ts +0 -33
- package/src/preview/project.ts +0 -362
- package/src/projects/session-links.ts +0 -52
- package/src/search/fff.ts +0 -224
- package/src/search/index.ts +0 -198
- package/src/settings.ts +0 -465
- package/src/styles/omarchy.ts +0 -295
- package/src/styles/opencode-themes-a.ts +0 -1442
- package/src/styles/opencode-themes-b.ts +0 -1212
- package/src/styles/opencode-tui-colors.ts +0 -1784
- package/src/styles/terminal-palette.ts +0 -156
- package/src/styles/theme-follow.ts +0 -94
- package/src/styles/theme.tsx +0 -311
- package/src/tmux/actions.ts +0 -145
- package/src/tmux/details.ts +0 -104
- package/src/tmux/helpers.ts +0 -35
- package/src/tmux/index.ts +0 -10
- package/src/tmux/list.ts +0 -31
- package/src/tmux/project-discovery.ts +0 -116
- package/src/tmux/project-loader.ts +0 -92
- package/src/tmux/project-zoxide.ts +0 -128
- package/src/tmux/projects.ts +0 -38
- package/src/tmux/workflows.ts +0 -26
- package/src/types/index.ts +0 -221
- package/src/ui/AgentSessionGroup.tsx +0 -93
- package/src/ui/CommandsModal.tsx +0 -246
- package/src/ui/ErrorScreen.tsx +0 -102
- package/src/ui/HighlightedText.tsx +0 -60
- package/src/ui/ItemList.tsx +0 -119
- package/src/ui/Modal.tsx +0 -48
- package/src/ui/OpencodeStatsPanel.tsx +0 -233
- package/src/ui/RenameModal.tsx +0 -42
- package/src/ui/SearchInput.tsx +0 -43
- package/src/ui/SessionDetailsPanel.tsx +0 -273
- package/src/ui/SessionList.tsx +0 -119
- package/src/ui/SettingEditorModal.tsx +0 -55
- package/src/ui/SettingOptionsModal.tsx +0 -95
- package/src/ui/SettingsModal.tsx +0 -102
- package/src/ui/Toast.tsx +0 -34
- package/src/ui/VersionBadge.tsx +0 -45
- package/src/ui/item-icon.ts +0 -110
- package/src/ui/list-window.ts +0 -35
- package/src/ui/session-meta.ts +0 -10
- package/src/ui/text-columns.ts +0 -17
- package/src/ui/use-textarea-focus.ts +0 -29
- package/src/update/events.ts +0 -28
- package/src/update/index.ts +0 -91
- package/src/update/installation.ts +0 -161
- package/src/update/version.ts +0 -33
- package/src/util/ansi.ts +0 -3
- package/src/util/browser.ts +0 -37
- package/src/util/clipboard.ts +0 -22
- package/src/util/errors.ts +0 -170
- package/src/util/github.ts +0 -100
- package/src/util/glob.ts +0 -51
- package/src/util/path-display.ts +0 -98
- package/src/util/perf.ts +0 -23
- package/src/util/shell.ts +0 -3
- package/src/util/shutdown.ts +0 -111
- package/src/util/terminal.ts +0 -28
- package/src/util/time.ts +0 -48
- package/tsconfig.json +0 -25
package/src/tmux/details.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
import type { SessionDetails, WindowInfo } from '../types'
|
|
3
|
-
import { formatPanePreview, formatWindowCommand, readTmuxValue } from './helpers'
|
|
4
|
-
import { toHomeRelativePath } from '../util/path-display'
|
|
5
|
-
|
|
6
|
-
const SESSION_DETAILS_CACHE_TTL_MS = 4000
|
|
7
|
-
const sessionDetailsCache = new Map<string, { details: SessionDetails; expiresAt: number }>()
|
|
8
|
-
|
|
9
|
-
export async function getCurrentTmuxSessionName(): Promise<string> {
|
|
10
|
-
return readTmuxValue(
|
|
11
|
-
['tmux', 'display-message', '-p', '#S'],
|
|
12
|
-
'Failed to resolve the current tmux session name'
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function getTmuxSessionDirectory(sessionName: string): Promise<string> {
|
|
17
|
-
return readTmuxValue(
|
|
18
|
-
['tmux', 'display-message', '-t', sessionName, '-p', '#{pane_current_path}'],
|
|
19
|
-
`Failed to resolve tmux directory for session '${sessionName}'`
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function getSessionDetails(sessionName: string): Promise<SessionDetails> {
|
|
24
|
-
const cached = sessionDetailsCache.get(sessionName)
|
|
25
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
26
|
-
return cached.details
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const statusOutput = await readTmuxValue(
|
|
30
|
-
[
|
|
31
|
-
'tmux',
|
|
32
|
-
'list-sessions',
|
|
33
|
-
'-F',
|
|
34
|
-
'#{session_name}:#{session_attached}:#{session_windows}',
|
|
35
|
-
'-f',
|
|
36
|
-
`#{==:#{session_name},${sessionName}}`,
|
|
37
|
-
],
|
|
38
|
-
`Failed to load tmux session details for '${sessionName}'`
|
|
39
|
-
)
|
|
40
|
-
const [, attached, windowCount] = statusOutput.trim().split(':')
|
|
41
|
-
|
|
42
|
-
const windowsOutput = await readTmuxValue(
|
|
43
|
-
[
|
|
44
|
-
'tmux',
|
|
45
|
-
'list-windows',
|
|
46
|
-
'-t',
|
|
47
|
-
sessionName,
|
|
48
|
-
'-F',
|
|
49
|
-
'#{window_index}\t#{window_name}\t#{pane_current_path}\t#{pane_current_command}\t#{window_active}',
|
|
50
|
-
],
|
|
51
|
-
`Failed to load tmux windows for '${sessionName}'`
|
|
52
|
-
)
|
|
53
|
-
const windowLines = windowsOutput.trim().split('\n').filter(Boolean)
|
|
54
|
-
|
|
55
|
-
const windows: WindowInfo[] = []
|
|
56
|
-
let activeWindowIndex = ''
|
|
57
|
-
|
|
58
|
-
for (const line of windowLines) {
|
|
59
|
-
const [index = '', name = '', currentPath = '', currentCommand = '', active = '0'] =
|
|
60
|
-
line.split('\t')
|
|
61
|
-
|
|
62
|
-
if (active === '1') {
|
|
63
|
-
activeWindowIndex = index
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
windows.push({
|
|
67
|
-
index,
|
|
68
|
-
name,
|
|
69
|
-
currentPath: toHomeRelativePath(currentPath),
|
|
70
|
-
currentCommand: formatWindowCommand(currentCommand),
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let panePreviewLines: string[] | undefined
|
|
75
|
-
if (activeWindowIndex.length > 0) {
|
|
76
|
-
const paneProc = spawn([
|
|
77
|
-
'tmux',
|
|
78
|
-
'capture-pane',
|
|
79
|
-
'-p',
|
|
80
|
-
'-t',
|
|
81
|
-
`${sessionName}:${activeWindowIndex}`,
|
|
82
|
-
'-S',
|
|
83
|
-
'-16',
|
|
84
|
-
])
|
|
85
|
-
const paneOutput = await new Response(paneProc.stdout).text()
|
|
86
|
-
const formatted = formatPanePreview(paneOutput)
|
|
87
|
-
panePreviewLines = formatted.length > 0 ? formatted : undefined
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const details = {
|
|
91
|
-
name: sessionName,
|
|
92
|
-
isAttached: attached === '1',
|
|
93
|
-
windowCount,
|
|
94
|
-
windows,
|
|
95
|
-
panePreviewLines,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
sessionDetailsCache.set(sessionName, {
|
|
99
|
-
details,
|
|
100
|
-
expiresAt: Date.now() + SESSION_DETAILS_CACHE_TTL_MS,
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return details
|
|
104
|
-
}
|
package/src/tmux/helpers.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { stripAnsi } from '../util/ansi'
|
|
2
|
-
|
|
3
|
-
export function formatPanePreview(output: string): string[] {
|
|
4
|
-
return stripAnsi(output)
|
|
5
|
-
.replace(/\r/g, '')
|
|
6
|
-
.split('\n')
|
|
7
|
-
.map(line => line.trimEnd())
|
|
8
|
-
.filter(line => line.length > 0)
|
|
9
|
-
.slice(-8)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function sanitizeTmuxSessionName(name: string): string {
|
|
13
|
-
return name.replace(/\./g, '_').replace(/ /g, '_')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function readTmuxValue(args: string[], errorMessage: string): Promise<string> {
|
|
17
|
-
const proc = Bun.spawn(args)
|
|
18
|
-
const output = await new Response(proc.stdout).text()
|
|
19
|
-
await proc.exited
|
|
20
|
-
|
|
21
|
-
if (proc.exitCode !== 0) {
|
|
22
|
-
throw new Error(errorMessage)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const value = output.trim()
|
|
26
|
-
if (!value) {
|
|
27
|
-
throw new Error(errorMessage)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return value
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function formatWindowCommand(currentCommand: string): string {
|
|
34
|
-
return ['bash', 'zsh', 'fish'].includes(currentCommand) ? '' : currentCommand
|
|
35
|
-
}
|
package/src/tmux/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
createNamedTmuxSession,
|
|
3
|
-
createTmuxSession,
|
|
4
|
-
killTmuxSession,
|
|
5
|
-
renameTmuxSession,
|
|
6
|
-
switchTmuxSession,
|
|
7
|
-
} from './actions'
|
|
8
|
-
export type { CreateTmuxSessionOptions } from './actions'
|
|
9
|
-
export { getCurrentTmuxSessionName, getSessionDetails, getTmuxSessionDirectory } from './details'
|
|
10
|
-
export { listTmuxSessions } from './list'
|
package/src/tmux/list.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
import type { Item } from '../types'
|
|
3
|
-
import { getLiveSessionGroupLabel } from '../util/path-display'
|
|
4
|
-
|
|
5
|
-
export async function listTmuxSessions(): Promise<Item[]> {
|
|
6
|
-
const proc = spawn([
|
|
7
|
-
'tmux',
|
|
8
|
-
'list-sessions',
|
|
9
|
-
'-F',
|
|
10
|
-
'#{session_name}\t#{session_attached}\t#{session_windows}\t#{session_created}\t#{session_activity}\t#{session_path}',
|
|
11
|
-
])
|
|
12
|
-
|
|
13
|
-
const output = await new Response(proc.stdout).text()
|
|
14
|
-
const lines = output.trim().split('\n').filter(Boolean)
|
|
15
|
-
|
|
16
|
-
return lines.map(line => {
|
|
17
|
-
const [name, attached, windows, created, activity, sessionPath = ''] = line.split('\t')
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
title: name,
|
|
21
|
-
path: sessionPath,
|
|
22
|
-
desc: getLiveSessionGroupLabel(sessionPath),
|
|
23
|
-
isSession: true,
|
|
24
|
-
itemKind: 'tmux' as const,
|
|
25
|
-
isAttached: attached === '1',
|
|
26
|
-
windowCount: windows,
|
|
27
|
-
createdAt: parseInt(created, 10),
|
|
28
|
-
lastActivity: parseInt(activity, 10),
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { basename } from 'path'
|
|
2
|
-
import { access, stat } from 'fs/promises'
|
|
3
|
-
import type { Config, Item } from '../types'
|
|
4
|
-
import { normalizePathForMatching } from '../util/glob'
|
|
5
|
-
import { getPathContextLabel } from '../util/path-display'
|
|
6
|
-
|
|
7
|
-
export interface DiscoveryCacheEntry {
|
|
8
|
-
expiresAt: number
|
|
9
|
-
items: Item[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const PROJECT_MARKERS = [
|
|
13
|
-
'.git',
|
|
14
|
-
'.jj',
|
|
15
|
-
'package.json',
|
|
16
|
-
'Cargo.toml',
|
|
17
|
-
'go.mod',
|
|
18
|
-
'pyproject.toml',
|
|
19
|
-
'flake.nix',
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
export const PRUNED_PROJECT_DIRECTORY_NAMES = [
|
|
23
|
-
'.git',
|
|
24
|
-
'.jj',
|
|
25
|
-
'node_modules',
|
|
26
|
-
'target',
|
|
27
|
-
'build',
|
|
28
|
-
'dist',
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
export function isIgnoredProjectDirectory(baseName: string): boolean {
|
|
32
|
-
return baseName.startsWith('.') || PRUNED_PROJECT_DIRECTORY_NAMES.includes(baseName)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function toProjectItem(projectPath: string): Item {
|
|
36
|
-
return {
|
|
37
|
-
title: basename(projectPath),
|
|
38
|
-
desc: getPathContextLabel(projectPath),
|
|
39
|
-
path: projectPath,
|
|
40
|
-
isSession: false,
|
|
41
|
-
itemKind: 'project',
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function uniqueNormalizedPaths(paths: string[]): string[] {
|
|
46
|
-
return [...new Set(paths.map(path => normalizePathForMatching(path)))]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function buildCacheKey(config: Config, scope: 'projects' | 'session-candidates'): string {
|
|
50
|
-
return JSON.stringify({
|
|
51
|
-
scope,
|
|
52
|
-
roots: uniqueNormalizedPaths(config.projectPaths),
|
|
53
|
-
zoxideMode: config.zoxideMode,
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function hasProjectMarker(projectPath: string): Promise<boolean> {
|
|
58
|
-
for (const marker of PROJECT_MARKERS) {
|
|
59
|
-
try {
|
|
60
|
-
await access(`${projectPath}/${marker}`)
|
|
61
|
-
return true
|
|
62
|
-
} catch {}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function filterProjectCandidatePaths(projectPaths: string[]): Promise<string[]> {
|
|
69
|
-
const uniquePaths = uniqueNormalizedPaths(projectPaths)
|
|
70
|
-
const matches = await Promise.all(
|
|
71
|
-
uniquePaths.map(async projectPath => ({
|
|
72
|
-
projectPath,
|
|
73
|
-
include: await hasProjectMarker(projectPath),
|
|
74
|
-
}))
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
return matches.filter(match => match.include).map(match => match.projectPath)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function getExistingProjectRoots(projectPaths: string[]): Promise<string[]> {
|
|
81
|
-
const existingPaths: string[] = []
|
|
82
|
-
for (const path of projectPaths) {
|
|
83
|
-
try {
|
|
84
|
-
const pathStat = await stat(path)
|
|
85
|
-
if (pathStat.isDirectory()) {
|
|
86
|
-
existingPaths.push(path)
|
|
87
|
-
}
|
|
88
|
-
} catch {}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return existingPaths
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function filterSessionCandidatePaths(paths: string[]): string[] {
|
|
95
|
-
return uniqueNormalizedPaths(paths).filter(path => !isIgnoredProjectDirectory(basename(path)))
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function getCachedDiscovery(
|
|
99
|
-
cache: Map<string, DiscoveryCacheEntry>,
|
|
100
|
-
cacheKey: string,
|
|
101
|
-
ttlMs: number,
|
|
102
|
-
load: () => Promise<Item[]>
|
|
103
|
-
): Promise<Item[]> {
|
|
104
|
-
const cached = cache.get(cacheKey)
|
|
105
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
106
|
-
return cached.items
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const items = await load()
|
|
110
|
-
cache.set(cacheKey, {
|
|
111
|
-
items,
|
|
112
|
-
expiresAt: Date.now() + ttlMs,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
return items
|
|
116
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
import type { Config, Item } from '../types'
|
|
3
|
-
import { normalizePathForMatching } from '../util/glob'
|
|
4
|
-
import {
|
|
5
|
-
buildCacheKey,
|
|
6
|
-
getCachedDiscovery,
|
|
7
|
-
getExistingProjectRoots,
|
|
8
|
-
PRUNED_PROJECT_DIRECTORY_NAMES,
|
|
9
|
-
toProjectItem,
|
|
10
|
-
type DiscoveryCacheEntry,
|
|
11
|
-
} from './project-discovery'
|
|
12
|
-
import { applyZoxideMode, getZoxideEntries } from './project-zoxide'
|
|
13
|
-
|
|
14
|
-
type Scope = 'projects' | 'session-candidates'
|
|
15
|
-
|
|
16
|
-
interface DiscoveryLoadOptions {
|
|
17
|
-
cache: Map<string, DiscoveryCacheEntry>
|
|
18
|
-
scope: Scope
|
|
19
|
-
ttlMs: number
|
|
20
|
-
scanDepth: number
|
|
21
|
-
requireProjectMarker: boolean
|
|
22
|
-
selectPaths: (paths: string[]) => Promise<string[]>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function scanDirectories(projectRoots: string[], maxDepth: number): Promise<string[]> {
|
|
26
|
-
if (projectRoots.length === 0) {
|
|
27
|
-
return []
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const pruneExpression = PRUNED_PROJECT_DIRECTORY_NAMES.flatMap((name, index) =>
|
|
31
|
-
index === 0 ? ['-name', name] : ['-o', '-name', name]
|
|
32
|
-
)
|
|
33
|
-
const args = [
|
|
34
|
-
...projectRoots,
|
|
35
|
-
'-mindepth',
|
|
36
|
-
'1',
|
|
37
|
-
'-maxdepth',
|
|
38
|
-
String(maxDepth),
|
|
39
|
-
'(',
|
|
40
|
-
...pruneExpression,
|
|
41
|
-
')',
|
|
42
|
-
'-prune',
|
|
43
|
-
'-o',
|
|
44
|
-
'-type',
|
|
45
|
-
'd',
|
|
46
|
-
'-print',
|
|
47
|
-
]
|
|
48
|
-
const proc = spawn(['find', ...args], {
|
|
49
|
-
stderr: 'pipe',
|
|
50
|
-
})
|
|
51
|
-
const output = await new Response(proc.stdout).text()
|
|
52
|
-
const stderrPromise = new Response(proc.stderr).text()
|
|
53
|
-
await proc.exited
|
|
54
|
-
await stderrPromise
|
|
55
|
-
|
|
56
|
-
return output
|
|
57
|
-
.trim()
|
|
58
|
-
.split('\n')
|
|
59
|
-
.filter(Boolean)
|
|
60
|
-
.map(path => normalizePathForMatching(path))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function runCommand(args: string[]): Promise<{ exitCode: number; output: string }> {
|
|
64
|
-
const proc = spawn(args)
|
|
65
|
-
const output = await new Response(proc.stdout).text()
|
|
66
|
-
await proc.exited
|
|
67
|
-
return { exitCode: proc.exitCode ?? 1, output }
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function loadDiscoveryItems(
|
|
71
|
-
config: Config,
|
|
72
|
-
options: DiscoveryLoadOptions
|
|
73
|
-
): Promise<Item[]> {
|
|
74
|
-
const cacheKey = buildCacheKey(config, options.scope)
|
|
75
|
-
|
|
76
|
-
return getCachedDiscovery(options.cache, cacheKey, options.ttlMs, async () => {
|
|
77
|
-
const existingPaths = await getExistingProjectRoots(config.projectPaths)
|
|
78
|
-
if (existingPaths.length === 0) {
|
|
79
|
-
return []
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const scannedPaths = await scanDirectories(existingPaths, options.scanDepth)
|
|
83
|
-
const selectedPaths = await options.selectPaths(scannedPaths)
|
|
84
|
-
const items = selectedPaths.map(toProjectItem)
|
|
85
|
-
const zoxideEntries =
|
|
86
|
-
config.zoxideMode === 'off'
|
|
87
|
-
? []
|
|
88
|
-
: await getZoxideEntries(runCommand, existingPaths, options.requireProjectMarker)
|
|
89
|
-
|
|
90
|
-
return applyZoxideMode(items, zoxideEntries, config)
|
|
91
|
-
})
|
|
92
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { basename } from 'path'
|
|
2
|
-
import type { Config, Item } from '../types'
|
|
3
|
-
import { normalizePathForMatching } from '../util/glob'
|
|
4
|
-
import {
|
|
5
|
-
filterProjectCandidatePaths,
|
|
6
|
-
isIgnoredProjectDirectory,
|
|
7
|
-
toProjectItem,
|
|
8
|
-
} from './project-discovery'
|
|
9
|
-
|
|
10
|
-
export interface ZoxideEntry {
|
|
11
|
-
score: number
|
|
12
|
-
path: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function parseZoxideOutput(output: string): ZoxideEntry[] {
|
|
16
|
-
return output
|
|
17
|
-
.trim()
|
|
18
|
-
.split('\n')
|
|
19
|
-
.filter(Boolean)
|
|
20
|
-
.flatMap(line => {
|
|
21
|
-
const trimmed = line.trim()
|
|
22
|
-
const firstSpaceIndex = trimmed.indexOf(' ')
|
|
23
|
-
if (firstSpaceIndex === -1) {
|
|
24
|
-
return []
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const score = Number(trimmed.slice(0, firstSpaceIndex))
|
|
28
|
-
const path = trimmed.slice(firstSpaceIndex + 1).trim()
|
|
29
|
-
if (!Number.isFinite(score) || !path) {
|
|
30
|
-
return []
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return [{ score, path }]
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function isWithinProjectRoots(projectPath: string, projectRoots: string[]): boolean {
|
|
38
|
-
const normalizedProjectPath = normalizePathForMatching(projectPath)
|
|
39
|
-
|
|
40
|
-
return projectRoots.some(projectRoot => {
|
|
41
|
-
const normalizedRoot = normalizePathForMatching(projectRoot)
|
|
42
|
-
return (
|
|
43
|
-
normalizedProjectPath === normalizedRoot ||
|
|
44
|
-
normalizedProjectPath.startsWith(`${normalizedRoot}/`)
|
|
45
|
-
)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function rankItemsByZoxide(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
|
|
50
|
-
if (config.zoxideMode === 'off' || entries.length === 0) {
|
|
51
|
-
return [...items].sort((a, b) => a.title.localeCompare(b.title))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const zoxideScores = new Map(
|
|
55
|
-
entries.map(entry => [normalizePathForMatching(entry.path), entry.score])
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
return [...items].sort((left, right) => {
|
|
59
|
-
const scoreDifference =
|
|
60
|
-
(zoxideScores.get(normalizePathForMatching(right.path)) ?? 0) -
|
|
61
|
-
(zoxideScores.get(normalizePathForMatching(left.path)) ?? 0)
|
|
62
|
-
|
|
63
|
-
if (scoreDifference !== 0) {
|
|
64
|
-
return scoreDifference
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return left.title.localeCompare(right.title)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function applyZoxideMode(items: Item[], entries: ZoxideEntry[], config: Config): Item[] {
|
|
72
|
-
const rankedItems = rankItemsByZoxide(items, entries, config)
|
|
73
|
-
|
|
74
|
-
if (config.zoxideMode !== 'merge') {
|
|
75
|
-
return rankedItems
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const existingPaths = new Set(rankedItems.map(item => normalizePathForMatching(item.path)))
|
|
79
|
-
const mergedItems = entries.flatMap(entry => {
|
|
80
|
-
const normalizedPath = normalizePathForMatching(entry.path)
|
|
81
|
-
const baseName = basename(entry.path)
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
existingPaths.has(normalizedPath) ||
|
|
85
|
-
!isWithinProjectRoots(entry.path, config.projectPaths) ||
|
|
86
|
-
isIgnoredProjectDirectory(baseName)
|
|
87
|
-
) {
|
|
88
|
-
return []
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
existingPaths.add(normalizedPath)
|
|
92
|
-
return [toProjectItem(entry.path)]
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
return [...rankedItems, ...mergedItems]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function getZoxideEntries(
|
|
99
|
-
spawnCommand: (args: string[]) => Promise<{ exitCode: number; output: string }>,
|
|
100
|
-
projectRoots: string[],
|
|
101
|
-
requireProjectMarker: boolean
|
|
102
|
-
): Promise<ZoxideEntry[]> {
|
|
103
|
-
try {
|
|
104
|
-
const result = await spawnCommand(['zoxide', 'query', '--list', '--score'])
|
|
105
|
-
if (result.exitCode !== 0) {
|
|
106
|
-
return []
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const entriesWithinRoots = parseZoxideOutput(result.output).filter(entry =>
|
|
110
|
-
isWithinProjectRoots(entry.path, projectRoots)
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
if (!requireProjectMarker) {
|
|
114
|
-
return entriesWithinRoots.filter(entry => !isIgnoredProjectDirectory(basename(entry.path)))
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const projectCandidatePaths = await filterProjectCandidatePaths(
|
|
118
|
-
entriesWithinRoots.map(entry => entry.path)
|
|
119
|
-
)
|
|
120
|
-
const projectCandidates = new Set(projectCandidatePaths)
|
|
121
|
-
|
|
122
|
-
return entriesWithinRoots.filter(entry =>
|
|
123
|
-
projectCandidates.has(normalizePathForMatching(entry.path))
|
|
124
|
-
)
|
|
125
|
-
} catch {
|
|
126
|
-
return []
|
|
127
|
-
}
|
|
128
|
-
}
|
package/src/tmux/projects.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Config, Item } from '../types'
|
|
2
|
-
import {
|
|
3
|
-
filterProjectCandidatePaths,
|
|
4
|
-
filterSessionCandidatePaths,
|
|
5
|
-
type DiscoveryCacheEntry,
|
|
6
|
-
} from './project-discovery'
|
|
7
|
-
import { loadDiscoveryItems } from './project-loader'
|
|
8
|
-
import { applyZoxideMode, parseZoxideOutput } from './project-zoxide'
|
|
9
|
-
|
|
10
|
-
const DISCOVERY_CACHE_TTL_MS = 15000
|
|
11
|
-
const PROJECT_SCAN_DEPTH = 3
|
|
12
|
-
const SESSION_CANDIDATE_SCAN_DEPTH = 5
|
|
13
|
-
const projectItemsCache = new Map<string, DiscoveryCacheEntry>()
|
|
14
|
-
const sessionCandidateCache = new Map<string, DiscoveryCacheEntry>()
|
|
15
|
-
|
|
16
|
-
export async function getProjectItems(config: Config): Promise<Item[]> {
|
|
17
|
-
return loadDiscoveryItems(config, {
|
|
18
|
-
cache: projectItemsCache,
|
|
19
|
-
scope: 'projects',
|
|
20
|
-
ttlMs: DISCOVERY_CACHE_TTL_MS,
|
|
21
|
-
scanDepth: PROJECT_SCAN_DEPTH,
|
|
22
|
-
requireProjectMarker: true,
|
|
23
|
-
selectPaths: filterProjectCandidatePaths,
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function getSessionCandidateItems(config: Config): Promise<Item[]> {
|
|
28
|
-
return loadDiscoveryItems(config, {
|
|
29
|
-
cache: sessionCandidateCache,
|
|
30
|
-
scope: 'session-candidates',
|
|
31
|
-
ttlMs: DISCOVERY_CACHE_TTL_MS,
|
|
32
|
-
scanDepth: SESSION_CANDIDATE_SCAN_DEPTH,
|
|
33
|
-
requireProjectMarker: false,
|
|
34
|
-
selectPaths: async paths => filterSessionCandidatePaths(paths),
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { applyZoxideMode, filterProjectCandidatePaths, parseZoxideOutput }
|
package/src/tmux/workflows.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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(
|
|
15
|
-
pattern =>
|
|
16
|
-
matchesGlob(item.title, pattern) ||
|
|
17
|
-
(item.workspaceTitle !== undefined && matchesGlob(item.workspaceTitle, pattern))
|
|
18
|
-
)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getLastSessionTarget(items: Item[], currentSessionName?: string): Item | undefined {
|
|
23
|
-
return items
|
|
24
|
-
.filter(item => item.isSession && item.title !== currentSessionName)
|
|
25
|
-
.sort((left, right) => (right.lastActivity ?? 0) - (left.lastActivity ?? 0))[0]
|
|
26
|
-
}
|