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/files/target.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { basename, dirname, isAbsolute, join } from 'path'
|
|
2
|
-
import { stat } from 'fs/promises'
|
|
3
|
-
import type { Config, Item } from '../types'
|
|
4
|
-
import { quoteShellArg } from '../util/shell'
|
|
5
|
-
|
|
6
|
-
export interface ResolvedFileSession {
|
|
7
|
-
sessionName: string
|
|
8
|
-
cwd: string
|
|
9
|
-
startupCommand: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type TypedPathTarget = { kind: 'file' | 'directory'; path: string }
|
|
13
|
-
|
|
14
|
-
function sanitizeSessionName(value: string): string {
|
|
15
|
-
return value.replace(/[.\s/]+/g, '_')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function isFileItem(item: Pick<Item, 'itemKind'>): boolean {
|
|
19
|
-
return item.itemKind === 'file'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function expandUserPath(value: string, homeDir = process.env.HOME || ''): string {
|
|
23
|
-
if (value === '~') {
|
|
24
|
-
return homeDir || value
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (value.startsWith('~/') && homeDir) {
|
|
28
|
-
return join(homeDir, value.slice(2))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return value
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function buildFileSessionName(filePath: string): string {
|
|
35
|
-
const fileBase = basename(filePath)
|
|
36
|
-
const parentBase = basename(dirname(filePath))
|
|
37
|
-
const combined =
|
|
38
|
-
parentBase && parentBase !== '.' && parentBase !== '/' ? `${parentBase}_${fileBase}` : fileBase
|
|
39
|
-
|
|
40
|
-
return sanitizeSessionName(combined)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function interpolateStartupCommand(command: string, filePath: string): string {
|
|
44
|
-
return command
|
|
45
|
-
.replaceAll('{file}', quoteShellArg(filePath))
|
|
46
|
-
.replaceAll('{dir}', quoteShellArg(dirname(filePath)))
|
|
47
|
-
.replaceAll('{}', quoteShellArg(filePath))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function buildFileStartupCommand(filePath: string, config: Config): string {
|
|
51
|
-
const configured = config.defaultSession?.startupCommand
|
|
52
|
-
if (configured && /\{file\}|\{dir\}|\{\}/.test(configured)) {
|
|
53
|
-
return interpolateStartupCommand(configured, filePath)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return `${config.editor} ${quoteShellArg(filePath)}`
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function resolveFileSession(filePath: string, config: Config): ResolvedFileSession {
|
|
60
|
-
return {
|
|
61
|
-
sessionName: buildFileSessionName(filePath),
|
|
62
|
-
cwd: dirname(filePath),
|
|
63
|
-
startupCommand: buildFileStartupCommand(filePath, config),
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function looksLikePathInput(value: string): boolean {
|
|
68
|
-
return value.startsWith('/') || value === '~' || value.startsWith('~/') || value.startsWith('./')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function resolveTypedPathTarget(
|
|
72
|
-
searchTerm: string,
|
|
73
|
-
homeDir = process.env.HOME || ''
|
|
74
|
-
): Promise<TypedPathTarget | null> {
|
|
75
|
-
if (!looksLikePathInput(searchTerm)) {
|
|
76
|
-
return null
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const expanded = expandUserPath(searchTerm, homeDir)
|
|
80
|
-
const absolute = isAbsolute(expanded) ? expanded : join(process.cwd(), expanded)
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
const info = await stat(absolute)
|
|
84
|
-
if (info.isFile()) {
|
|
85
|
-
return { kind: 'file', path: absolute }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (info.isDirectory()) {
|
|
89
|
-
return { kind: 'directory', path: absolute }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return null
|
|
93
|
-
} catch {
|
|
94
|
-
return null
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { dirname } from 'path'
|
|
2
|
-
import type { Config, Item } from '../types'
|
|
3
|
-
import type { MultiplexerBackend } from '../multiplexer'
|
|
4
|
-
import { getItemKey, getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
|
|
5
|
-
import { getGitRoot, resolveProjectSession } from '../config/session-rules'
|
|
6
|
-
import { isFileItem, resolveFileSession } from '../files/target'
|
|
7
|
-
import { requestShutdown } from '../util/shutdown'
|
|
8
|
-
import { quoteShellArg } from '../util/shell'
|
|
9
|
-
|
|
10
|
-
export { quoteShellArg } from '../util/shell'
|
|
11
|
-
|
|
12
|
-
export function buildEditorCommand(editor: string, path: string): string {
|
|
13
|
-
return `${editor} ${quoteShellArg(path)}`
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function requireConfig(config: Config | null): Config {
|
|
17
|
-
if (!config) {
|
|
18
|
-
throw new Error('Config is not loaded yet')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return config
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function requireConfiguredItem(item: Item | undefined): Item {
|
|
25
|
-
if (!item || item.itemKind !== 'configured') {
|
|
26
|
-
throw new Error('Select a configured session to edit its target')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return item
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getNextSessionName(renameTarget: string, newName: string): string | null {
|
|
33
|
-
const trimmedName = newName.trim()
|
|
34
|
-
if (!trimmedName || trimmedName === renameTarget) {
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return trimmedName
|
|
39
|
-
}
|
|
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
|
-
|
|
49
|
-
export async function openProjectSession(
|
|
50
|
-
projectPath: string,
|
|
51
|
-
config: Config,
|
|
52
|
-
backend: MultiplexerBackend
|
|
53
|
-
): Promise<void> {
|
|
54
|
-
const resolvedSession = await resolveProjectSession(projectPath, config)
|
|
55
|
-
await backend.openOrCreate({
|
|
56
|
-
title: resolvedSession.sessionName,
|
|
57
|
-
path: projectPath,
|
|
58
|
-
startupCommand: resolvedSession.startupCommand,
|
|
59
|
-
})
|
|
60
|
-
await requestShutdown(0)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function openFileSession(
|
|
64
|
-
filePath: string,
|
|
65
|
-
config: Config,
|
|
66
|
-
backend: MultiplexerBackend
|
|
67
|
-
): Promise<void> {
|
|
68
|
-
const resolvedSession = resolveFileSession(filePath, config)
|
|
69
|
-
await backend.openOrCreate({
|
|
70
|
-
title: resolvedSession.sessionName,
|
|
71
|
-
path: resolvedSession.cwd,
|
|
72
|
-
startupCommand: resolvedSession.startupCommand,
|
|
73
|
-
})
|
|
74
|
-
await requestShutdown(0)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function getRootSessionPath(item: Item, backend: MultiplexerBackend): Promise<string> {
|
|
78
|
-
const itemPath = isLiveSessionItem(item)
|
|
79
|
-
? ((await backend.directory(getWorkspaceRef(item))) ?? item.path)
|
|
80
|
-
: item.path
|
|
81
|
-
const searchRoot = !item.isSession && isFileItem(item) ? dirname(itemPath) : itemPath
|
|
82
|
-
return (await getGitRoot(searchRoot)) ?? searchRoot
|
|
83
|
-
}
|
package/src/handlers/actions.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
import type { Item, Config } from '../types'
|
|
3
|
-
import type { MultiplexerBackend } from '../multiplexer'
|
|
4
|
-
import { getItemKey, getWorkspaceRef, isLiveSessionItem } from '../multiplexer/items'
|
|
5
|
-
import { getLastSessionTarget } from '../tmux/workflows'
|
|
6
|
-
import { isFileItem, resolveTypedPathTarget } from '../files/target'
|
|
7
|
-
import { isGitHubURL, cloneGitHubRepo } from '../util/github'
|
|
8
|
-
import { requestShutdown } from '../util/shutdown'
|
|
9
|
-
import {
|
|
10
|
-
buildEditorCommand,
|
|
11
|
-
getNextSessionName,
|
|
12
|
-
getRootSessionPath,
|
|
13
|
-
openFileSession,
|
|
14
|
-
openProjectSession,
|
|
15
|
-
requireConfig,
|
|
16
|
-
requireConfiguredItem,
|
|
17
|
-
} from './action-helpers'
|
|
18
|
-
|
|
19
|
-
export async function handleSelect(item: Item, config: Config | null, backend: MultiplexerBackend) {
|
|
20
|
-
if (isLiveSessionItem(item)) {
|
|
21
|
-
await backend.open(getWorkspaceRef(item))
|
|
22
|
-
await requestShutdown(0)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isFileItem(item)) {
|
|
27
|
-
await openFileSession(item.path, requireConfig(config), backend)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
await openProjectSession(item.path, requireConfig(config), backend)
|
|
32
|
-
}
|
|
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
|
-
|
|
41
|
-
export async function handleKillSession(
|
|
42
|
-
item: Item,
|
|
43
|
-
backend: MultiplexerBackend,
|
|
44
|
-
callbacks: {
|
|
45
|
-
onSuccess: (message: string) => void
|
|
46
|
-
onError: (message: string) => void
|
|
47
|
-
refreshItems: () => Promise<void>
|
|
48
|
-
regularSessions: Item[]
|
|
49
|
-
rememberedSessions: (key: string | null) => void
|
|
50
|
-
}
|
|
51
|
-
) {
|
|
52
|
-
let closed = false
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
if (!isLiveSessionItem(item)) throw new Error('Select a live session to close')
|
|
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
|
-
|
|
80
|
-
callbacks.onSuccess(
|
|
81
|
-
`${backend.kind === 'herdr' ? 'Workspace' : 'Session'} '${item.title}' closed`
|
|
82
|
-
)
|
|
83
|
-
} catch (error) {
|
|
84
|
-
callbacks.onError(`Error killing session: ${error}`)
|
|
85
|
-
} finally {
|
|
86
|
-
if (closed) {
|
|
87
|
-
await callbacks.refreshItems().catch(() => {})
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function handleRenameSubmit(
|
|
93
|
-
renameTarget: Item,
|
|
94
|
-
newName: string,
|
|
95
|
-
backend: MultiplexerBackend,
|
|
96
|
-
callbacks: {
|
|
97
|
-
onSuccess: (message: string) => void
|
|
98
|
-
onError: (message: string) => void
|
|
99
|
-
refreshItems: () => Promise<void>
|
|
100
|
-
}
|
|
101
|
-
) {
|
|
102
|
-
if (!isLiveSessionItem(renameTarget)) return
|
|
103
|
-
const nextSessionName = getNextSessionName(renameTarget.title, newName)
|
|
104
|
-
if (!nextSessionName) {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
await backend.rename(getWorkspaceRef(renameTarget), nextSessionName)
|
|
110
|
-
callbacks.onSuccess(
|
|
111
|
-
`${backend.kind === 'herdr' ? 'Workspace' : 'Session'} renamed to '${nextSessionName}'`
|
|
112
|
-
)
|
|
113
|
-
await callbacks.refreshItems()
|
|
114
|
-
} catch (error) {
|
|
115
|
-
callbacks.onError(`Error renaming session: ${error}`)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export async function handleNewSessionSubmit(
|
|
120
|
-
searchTerm: string,
|
|
121
|
-
config: Config | null,
|
|
122
|
-
items: Item[],
|
|
123
|
-
cursor: number,
|
|
124
|
-
backend: MultiplexerBackend
|
|
125
|
-
) {
|
|
126
|
-
if (!searchTerm) return
|
|
127
|
-
|
|
128
|
-
if (isGitHubURL(searchTerm)) {
|
|
129
|
-
try {
|
|
130
|
-
if (!config) return
|
|
131
|
-
const clonedPath = await cloneGitHubRepo(searchTerm, config)
|
|
132
|
-
await openProjectSession(clonedPath, config, backend)
|
|
133
|
-
} catch (error) {
|
|
134
|
-
throw new Error(`Error cloning repository: ${error}`)
|
|
135
|
-
}
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const typedTarget = await resolveTypedPathTarget(searchTerm)
|
|
140
|
-
if (typedTarget) {
|
|
141
|
-
if (typedTarget.kind === 'file') {
|
|
142
|
-
await openFileSession(typedTarget.path, requireConfig(config), backend)
|
|
143
|
-
return
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await openProjectSession(typedTarget.path, requireConfig(config), backend)
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (items.length > 0 && cursor < items.length) {
|
|
151
|
-
const selectedItem = items[cursor]
|
|
152
|
-
if (isFileItem(selectedItem)) {
|
|
153
|
-
await openFileSession(selectedItem.path, requireConfig(config), backend)
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
await openProjectSession(selectedItem.path, requireConfig(config), backend)
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
await backend.openOrCreate({ title: searchTerm, path: process.cwd() })
|
|
162
|
-
await requestShutdown(0)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export async function handleLastSession(items: Item[], backend: MultiplexerBackend) {
|
|
166
|
-
if (!backend.capabilities.previousWorkspace) {
|
|
167
|
-
throw new Error(
|
|
168
|
-
'Previous workspace is unavailable because Herdr does not expose workspace activity history'
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
const currentSessionName = (await backend.current().catch(() => undefined))?.title
|
|
172
|
-
const target = getLastSessionTarget(items, currentSessionName)
|
|
173
|
-
|
|
174
|
-
if (!target) {
|
|
175
|
-
throw new Error('No previous tmux session is available')
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!isLiveSessionItem(target)) throw new Error('No previous live session is available')
|
|
179
|
-
await backend.open(getWorkspaceRef(target))
|
|
180
|
-
await requestShutdown(0)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export async function handleRootSession(
|
|
184
|
-
item: Item | undefined,
|
|
185
|
-
config: Config | null,
|
|
186
|
-
backend: MultiplexerBackend
|
|
187
|
-
) {
|
|
188
|
-
if (!item) {
|
|
189
|
-
throw new Error('No session or project is selected')
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
await openProjectSession(await getRootSessionPath(item, backend), requireConfig(config), backend)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export async function handleEditTarget(
|
|
196
|
-
item: Item | undefined,
|
|
197
|
-
config: Config | null,
|
|
198
|
-
backend: MultiplexerBackend
|
|
199
|
-
) {
|
|
200
|
-
const configuredItem = requireConfiguredItem(item)
|
|
201
|
-
const loadedConfig = requireConfig(config)
|
|
202
|
-
const command = buildEditorCommand(loadedConfig.editor, configuredItem.path)
|
|
203
|
-
|
|
204
|
-
if (await backend.openEditor(configuredItem.path, command)) {
|
|
205
|
-
await requestShutdown(0)
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
spawn(['sh', '-lc', command], {
|
|
210
|
-
cwd: configuredItem.path,
|
|
211
|
-
stdin: 'inherit',
|
|
212
|
-
stdout: 'inherit',
|
|
213
|
-
stderr: 'inherit',
|
|
214
|
-
})
|
|
215
|
-
await requestShutdown(0)
|
|
216
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { isOpencodeSessionItem } from '../../opencode/session-name'
|
|
2
|
-
import { isHerdrAgentItem } from '../../multiplexer/items'
|
|
3
|
-
import type { Item } from '../../types'
|
|
4
|
-
import { AppMode, type KeybindMode } from '../../types'
|
|
5
|
-
import { clampCursorIndex } from '../../ui/list-window'
|
|
6
|
-
import {
|
|
7
|
-
activatePrefix,
|
|
8
|
-
clearPrefix,
|
|
9
|
-
getKeyName,
|
|
10
|
-
matchesPrefixKey,
|
|
11
|
-
type KeyboardHandlerContext,
|
|
12
|
-
type KeyboardInput,
|
|
13
|
-
} from './shared'
|
|
14
|
-
|
|
15
|
-
function loadStatsIfOpencode(ctx: KeyboardHandlerContext, item: Item) {
|
|
16
|
-
if (isOpencodeSessionItem(item)) {
|
|
17
|
-
void ctx.loadOpencodeStatsForSession(item.title)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function handleAgentsManageMode(
|
|
22
|
-
key: KeyboardInput,
|
|
23
|
-
ctx: KeyboardHandlerContext,
|
|
24
|
-
keybindMode: KeybindMode = 'vim'
|
|
25
|
-
) {
|
|
26
|
-
const keyName = getKeyName(key)
|
|
27
|
-
const isStandard = keybindMode === 'standard'
|
|
28
|
-
|
|
29
|
-
if (key.ctrl && keyName === 'p') {
|
|
30
|
-
ctx.clearPendingKill()
|
|
31
|
-
ctx.openCommandsModal()
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (ctx.prefixActive) {
|
|
36
|
-
clearPrefix(ctx)
|
|
37
|
-
|
|
38
|
-
switch (keyName) {
|
|
39
|
-
case 'o':
|
|
40
|
-
ctx.clearPendingKill()
|
|
41
|
-
ctx.setAppMode(AppMode.Normal)
|
|
42
|
-
return
|
|
43
|
-
case 'd':
|
|
44
|
-
if (
|
|
45
|
-
ctx.agentSessions[ctx.agentCursor] &&
|
|
46
|
-
!isHerdrAgentItem(ctx.agentSessions[ctx.agentCursor])
|
|
47
|
-
) {
|
|
48
|
-
ctx.requestKillSession(ctx.agentSessions[ctx.agentCursor])
|
|
49
|
-
}
|
|
50
|
-
return
|
|
51
|
-
case 'r':
|
|
52
|
-
if (
|
|
53
|
-
ctx.agentSessions[ctx.agentCursor] &&
|
|
54
|
-
!isHerdrAgentItem(ctx.agentSessions[ctx.agentCursor])
|
|
55
|
-
) {
|
|
56
|
-
ctx.clearPendingKill()
|
|
57
|
-
ctx.openRenameModal(ctx.agentSessions[ctx.agentCursor])
|
|
58
|
-
}
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
|
|
66
|
-
activatePrefix(ctx)
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (keyName === 'escape' || (!ctx.prefixKey && !isStandard && keyName === 'o')) {
|
|
71
|
-
ctx.clearPendingKill()
|
|
72
|
-
ctx.setAppMode(AppMode.Normal)
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (keyName === 'return' || keyName === 'enter') {
|
|
77
|
-
const selectedAgent = ctx.agentSessions[ctx.agentCursor]
|
|
78
|
-
if (selectedAgent) {
|
|
79
|
-
void ctx.handleSelect(selectedAgent)
|
|
80
|
-
}
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
85
|
-
ctx.clearPendingKill()
|
|
86
|
-
ctx.setAgentCursor(cursor => {
|
|
87
|
-
const next = clampCursorIndex(ctx.agentSessions.length, cursor + 1)
|
|
88
|
-
if (next !== cursor && ctx.agentSessions[next]) {
|
|
89
|
-
loadStatsIfOpencode(ctx, ctx.agentSessions[next])
|
|
90
|
-
}
|
|
91
|
-
return next
|
|
92
|
-
})
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
97
|
-
ctx.clearPendingKill()
|
|
98
|
-
ctx.setAgentCursor(cursor => {
|
|
99
|
-
const next = clampCursorIndex(ctx.agentSessions.length, cursor - 1)
|
|
100
|
-
if (next !== cursor && ctx.agentSessions[next]) {
|
|
101
|
-
loadStatsIfOpencode(ctx, ctx.agentSessions[next])
|
|
102
|
-
}
|
|
103
|
-
return next
|
|
104
|
-
})
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!isStandard && keyName === 'd') {
|
|
109
|
-
if (
|
|
110
|
-
ctx.agentSessions[ctx.agentCursor] &&
|
|
111
|
-
!isHerdrAgentItem(ctx.agentSessions[ctx.agentCursor])
|
|
112
|
-
) {
|
|
113
|
-
ctx.requestKillSession(ctx.agentSessions[ctx.agentCursor])
|
|
114
|
-
}
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!ctx.prefixKey && !isStandard && keyName === 'r') {
|
|
119
|
-
if (
|
|
120
|
-
ctx.agentSessions[ctx.agentCursor] &&
|
|
121
|
-
!isHerdrAgentItem(ctx.agentSessions[ctx.agentCursor])
|
|
122
|
-
) {
|
|
123
|
-
ctx.clearPendingKill()
|
|
124
|
-
ctx.openRenameModal(ctx.agentSessions[ctx.agentCursor])
|
|
125
|
-
}
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!ctx.prefixKey && !isStandard && keyName === ',') {
|
|
130
|
-
ctx.clearPendingKill()
|
|
131
|
-
ctx.openSettingsModal()
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AppMode, ViewMode, type KeybindMode } from '../../types'
|
|
2
|
-
import { clampCursorIndex } from '../../ui/list-window'
|
|
3
|
-
import { getKeyName, type KeyboardHandlerContext, type KeyboardInput } from './shared'
|
|
4
|
-
|
|
5
|
-
export function handleNewSessionMode(
|
|
6
|
-
key: KeyboardInput,
|
|
7
|
-
ctx: KeyboardHandlerContext,
|
|
8
|
-
keybindMode: KeybindMode = 'vim'
|
|
9
|
-
) {
|
|
10
|
-
const keyName = getKeyName(key)
|
|
11
|
-
const isStandard = keybindMode === 'standard'
|
|
12
|
-
|
|
13
|
-
if (isStandard && key.ctrl) {
|
|
14
|
-
if (keyName === 'i') {
|
|
15
|
-
ctx.clearPendingKill()
|
|
16
|
-
ctx.setAppMode(AppMode.Search)
|
|
17
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
18
|
-
ctx.setAllItems(ctx.sessionItems)
|
|
19
|
-
ctx.setItems(ctx.sessionItems)
|
|
20
|
-
ctx.setSearchQuery('')
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (keyName === 'd' && ctx.items[ctx.cursor]?.isSession) {
|
|
25
|
-
ctx.requestKillSession(ctx.items[ctx.cursor])
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (keyName === 'escape') {
|
|
31
|
-
ctx.clearPendingKill()
|
|
32
|
-
if (isStandard) {
|
|
33
|
-
ctx.setAppMode(AppMode.Search)
|
|
34
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
35
|
-
ctx.setSearchQuery('')
|
|
36
|
-
ctx.setCursor(0)
|
|
37
|
-
void ctx.refreshItems(ViewMode.Sessions)
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
ctx.setAppMode(AppMode.Normal)
|
|
42
|
-
ctx.setViewMode(ViewMode.Sessions)
|
|
43
|
-
ctx.setSearchQuery('')
|
|
44
|
-
ctx.setCursor(0)
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
switch (keyName) {
|
|
49
|
-
case 'down':
|
|
50
|
-
ctx.clearPendingKill()
|
|
51
|
-
ctx.setCursor(cursor => clampCursorIndex(ctx.items.length, cursor + 1))
|
|
52
|
-
break
|
|
53
|
-
case 'up':
|
|
54
|
-
ctx.clearPendingKill()
|
|
55
|
-
ctx.setCursor(cursor => clampCursorIndex(ctx.items.length, cursor - 1))
|
|
56
|
-
break
|
|
57
|
-
}
|
|
58
|
-
}
|