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/items/order.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { Item, SortOrder } from '../types'
|
|
2
|
-
import { isAgentSessionItem } from '../agents/session-name'
|
|
3
|
-
import { getLiveSessionSortKey } from '../util/path-display'
|
|
4
|
-
|
|
5
|
-
export type SessionSection = 'pinned' | 'live' | 'configured'
|
|
6
|
-
|
|
7
|
-
function compareByTitle(left: Item, right: Item): number {
|
|
8
|
-
return left.title.localeCompare(right.title)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function compareLiveSessions(left: Item, right: Item): number {
|
|
12
|
-
const leftGroupKey = getLiveSessionSortKey(left.path, left.title)
|
|
13
|
-
const rightGroupKey = getLiveSessionSortKey(right.path, right.title)
|
|
14
|
-
const groupDifference = leftGroupKey.localeCompare(rightGroupKey)
|
|
15
|
-
|
|
16
|
-
if (groupDifference !== 0) {
|
|
17
|
-
return groupDifference
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return left.title.localeCompare(right.title)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isConfiguredSession(item: Item): boolean {
|
|
24
|
-
return item.itemKind === 'configured'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function applyPinnedState(items: Item[], pinnedSessions: readonly string[]): Item[] {
|
|
28
|
-
const pinnedSet = new Set(pinnedSessions)
|
|
29
|
-
|
|
30
|
-
return items.map(item => ({
|
|
31
|
-
...item,
|
|
32
|
-
isPinned: pinnedSet.has(item.title),
|
|
33
|
-
}))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function splitPinnedItems(items: Item[], pinnedSessions: readonly string[]) {
|
|
37
|
-
const pinnedItems = pinnedSessions.flatMap(title => items.filter(item => item.title === title))
|
|
38
|
-
const pinnedSet = new Set(pinnedItems)
|
|
39
|
-
const remainingItems = items.filter(item => !pinnedSet.has(item))
|
|
40
|
-
|
|
41
|
-
return { pinnedItems, remainingItems }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function sortByGroup(items: Item[], groups: Array<'live' | 'configured'>): Item[] {
|
|
45
|
-
const configuredItems = items.filter(isConfiguredSession).sort(compareByTitle)
|
|
46
|
-
const liveItems = items.filter(item => !isConfiguredSession(item)).sort(compareLiveSessions)
|
|
47
|
-
const groupedItems = new Map([
|
|
48
|
-
['configured', configuredItems],
|
|
49
|
-
['live', liveItems],
|
|
50
|
-
])
|
|
51
|
-
|
|
52
|
-
return groups.flatMap(group => groupedItems.get(group) ?? [])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function orderSessionItems(
|
|
56
|
-
items: Item[],
|
|
57
|
-
sortOrder: SortOrder = 'live-first',
|
|
58
|
-
pinnedSessions: readonly string[] = []
|
|
59
|
-
): Item[] {
|
|
60
|
-
const itemsWithPinnedState = applyPinnedState(items, pinnedSessions)
|
|
61
|
-
const agentItems = itemsWithPinnedState.filter(isAgentSessionItem).sort(compareByTitle)
|
|
62
|
-
const regularItems = itemsWithPinnedState.filter(item => !isAgentSessionItem(item))
|
|
63
|
-
const { pinnedItems, remainingItems } = splitPinnedItems(regularItems, pinnedSessions)
|
|
64
|
-
|
|
65
|
-
const orderedRegularItems =
|
|
66
|
-
sortOrder === 'configured-first'
|
|
67
|
-
? sortByGroup(remainingItems, ['configured', 'live'])
|
|
68
|
-
: sortOrder === 'alphabetical'
|
|
69
|
-
? [...remainingItems].sort((left, right) => {
|
|
70
|
-
if (isConfiguredSession(left) || isConfiguredSession(right)) {
|
|
71
|
-
return compareByTitle(left, right)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return compareLiveSessions(left, right)
|
|
75
|
-
})
|
|
76
|
-
: sortByGroup(remainingItems, ['live', 'configured'])
|
|
77
|
-
|
|
78
|
-
return [...pinnedItems, ...orderedRegularItems, ...agentItems]
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function orderProjectItems(items: Item[], sortOrder: SortOrder = 'live-first'): Item[] {
|
|
82
|
-
if (sortOrder === 'alphabetical') {
|
|
83
|
-
return [...items].sort(compareByTitle)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return items
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function getSessionSection(item: Item): SessionSection {
|
|
90
|
-
if (item.isPinned) {
|
|
91
|
-
return 'pinned'
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return item.itemKind === 'configured' ? 'configured' : 'live'
|
|
95
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { createHerdrBackend } from '../herdr/backend'
|
|
2
|
-
import { createCommandRunner, type CommandRunner } from './command'
|
|
3
|
-
import { probeBackendAvailability, probeHerdrAvailability, resolveBackendKind } from './resolve'
|
|
4
|
-
import { createTmuxBackend } from './tmux-backend'
|
|
5
|
-
import { MultiplexerError, type BackendPreference, type MultiplexerBackend } from './types'
|
|
6
|
-
|
|
7
|
-
export interface ResolveMultiplexerOptions {
|
|
8
|
-
preference?: BackendPreference
|
|
9
|
-
env?: Readonly<Record<string, string | undefined>>
|
|
10
|
-
runner?: CommandRunner
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function resolveMultiplexerBackend(
|
|
14
|
-
options: ResolveMultiplexerOptions = {}
|
|
15
|
-
): Promise<MultiplexerBackend> {
|
|
16
|
-
const env = options.env ?? process.env
|
|
17
|
-
const runner = options.runner ?? createCommandRunner()
|
|
18
|
-
if (env.HERDR_ENV === '1') {
|
|
19
|
-
const herdr = await probeHerdrAvailability(runner)
|
|
20
|
-
if (!herdr.running) {
|
|
21
|
-
throw new MultiplexerError(
|
|
22
|
-
'server-stopped',
|
|
23
|
-
'mux-sesh is running inside Herdr, but its server is unavailable.'
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
if (herdr.compatible !== true) {
|
|
27
|
-
throw new MultiplexerError(
|
|
28
|
-
'protocol-mismatch',
|
|
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
|
-
)
|
|
31
|
-
}
|
|
32
|
-
return createHerdrBackend({ runner, insideHerdr: true })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const contextKind = env.TMUX ? 'tmux' : undefined
|
|
36
|
-
const kind =
|
|
37
|
-
contextKind ??
|
|
38
|
-
resolveBackendKind(env, options.preference, await probeBackendAvailability(runner))
|
|
39
|
-
|
|
40
|
-
return kind === 'herdr'
|
|
41
|
-
? createHerdrBackend({ runner, insideHerdr: false })
|
|
42
|
-
: createTmuxBackend({ runner, insideTmux: Boolean(env.TMUX) })
|
|
43
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
|
-
|
|
3
|
-
export interface CommandResult {
|
|
4
|
-
exitCode: number
|
|
5
|
-
stdout: string
|
|
6
|
-
stderr: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface CommandOptions {
|
|
10
|
-
inheritStdio?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface CommandRunner {
|
|
14
|
-
run(command: readonly string[], options?: CommandOptions): Promise<CommandResult>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function readStream(stream: unknown): Promise<string> {
|
|
18
|
-
return stream instanceof ReadableStream ? new Response(stream).text() : ''
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function createCommandRunner(): CommandRunner {
|
|
22
|
-
return {
|
|
23
|
-
async run(command, options = {}): Promise<CommandResult> {
|
|
24
|
-
try {
|
|
25
|
-
const proc = spawn(
|
|
26
|
-
[...command],
|
|
27
|
-
options.inheritStdio
|
|
28
|
-
? { stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' }
|
|
29
|
-
: { stdout: 'pipe', stderr: 'pipe' }
|
|
30
|
-
)
|
|
31
|
-
const stdoutPromise = readStream(proc.stdout)
|
|
32
|
-
const stderrPromise = readStream(proc.stderr)
|
|
33
|
-
await proc.exited
|
|
34
|
-
return {
|
|
35
|
-
exitCode: proc.exitCode ?? 1,
|
|
36
|
-
stdout: await stdoutPromise,
|
|
37
|
-
stderr: await stderrPromise,
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return {
|
|
41
|
-
exitCode: 127,
|
|
42
|
-
stdout: '',
|
|
43
|
-
stderr: error instanceof Error ? error.message : 'Unable to start command',
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/multiplexer/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { probeBackendAvailability, probeHerdrAvailability, resolveBackendKind } from './resolve'
|
|
2
|
-
export type { BackendAvailability, BackendState } from './resolve'
|
|
3
|
-
export { MultiplexerError } from './types'
|
|
4
|
-
export { createCommandRunner } from './command'
|
|
5
|
-
export { resolveMultiplexerBackend } from './backend'
|
|
6
|
-
export { createTmuxBackend } from './tmux-backend'
|
|
7
|
-
export type { CommandOptions, CommandResult, CommandRunner } from './command'
|
|
8
|
-
export type {
|
|
9
|
-
AgentStatus,
|
|
10
|
-
BackendKind,
|
|
11
|
-
BackendPreference,
|
|
12
|
-
HerdrAgentTarget,
|
|
13
|
-
LiveWorkspace,
|
|
14
|
-
MultiplexerBackend,
|
|
15
|
-
MultiplexerCapabilities,
|
|
16
|
-
OpenWorkspaceInput,
|
|
17
|
-
WorkspaceAgentDetails,
|
|
18
|
-
WorkspaceDetails,
|
|
19
|
-
WorkspaceRef,
|
|
20
|
-
WorkspaceUnitDetails,
|
|
21
|
-
} from './types'
|
package/src/multiplexer/items.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Item } from '../types'
|
|
2
|
-
import type { HerdrAgentTarget, LiveWorkspace, WorkspaceRef } from './types'
|
|
3
|
-
import { getLiveSessionGroupLabel } from '../util/path-display'
|
|
4
|
-
|
|
5
|
-
export interface LiveSessionItem extends Item {
|
|
6
|
-
isSession: true
|
|
7
|
-
itemKind: 'tmux' | 'herdr'
|
|
8
|
-
sessionId: string
|
|
9
|
-
backend: 'tmux' | 'herdr'
|
|
10
|
-
target?: HerdrAgentTarget
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function workspaceToItem(workspace: LiveWorkspace): LiveSessionItem {
|
|
14
|
-
return {
|
|
15
|
-
title: workspace.title,
|
|
16
|
-
desc: getLiveSessionGroupLabel(workspace.path),
|
|
17
|
-
path: workspace.path,
|
|
18
|
-
isSession: true,
|
|
19
|
-
itemKind: workspace.backend,
|
|
20
|
-
sessionId: workspace.id,
|
|
21
|
-
backend: workspace.backend,
|
|
22
|
-
target: workspace.backend === 'herdr' ? workspace.target : undefined,
|
|
23
|
-
workspaceTitle: workspace.workspaceTitle,
|
|
24
|
-
agentStatus: workspace.agentStatus,
|
|
25
|
-
isAttached: workspace.isActive,
|
|
26
|
-
windowCount: String(workspace.unitCount),
|
|
27
|
-
createdAt: workspace.createdAt,
|
|
28
|
-
lastActivity: workspace.lastActivity,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isLiveSessionItem(item: Item): item is LiveSessionItem {
|
|
33
|
-
return (
|
|
34
|
-
item.isSession &&
|
|
35
|
-
(item.itemKind === 'tmux' || item.itemKind === 'herdr') &&
|
|
36
|
-
item.backend === item.itemKind &&
|
|
37
|
-
typeof item.sessionId === 'string'
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function isHerdrAgentItem(
|
|
42
|
-
item: Item | undefined
|
|
43
|
-
): item is LiveSessionItem & { backend: 'herdr'; target: HerdrAgentTarget } {
|
|
44
|
-
return (
|
|
45
|
-
item !== undefined &&
|
|
46
|
-
isLiveSessionItem(item) &&
|
|
47
|
-
item.backend === 'herdr' &&
|
|
48
|
-
item.target?.kind === 'agent'
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getWorkspaceRef(item: LiveSessionItem): WorkspaceRef {
|
|
53
|
-
return item.backend === 'herdr'
|
|
54
|
-
? { backend: 'herdr', id: item.sessionId, title: item.title, target: item.target }
|
|
55
|
-
: { backend: 'tmux', id: item.sessionId, title: item.title }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function getSessionKey(item: LiveSessionItem): string {
|
|
59
|
-
return item.target
|
|
60
|
-
? `${item.backend}:${item.sessionId}:agent:${item.target.paneId}`
|
|
61
|
-
: `${item.backend}:${item.sessionId}`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getItemKey(item: Item): string {
|
|
65
|
-
return isLiveSessionItem(item) ? getSessionKey(item) : `${item.itemKind ?? 'item'}:${item.title}`
|
|
66
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { MultiplexerError, type BackendKind, type BackendPreference } from './types'
|
|
2
|
-
import type { CommandRunner } from './command'
|
|
3
|
-
import { MIN_SUPPORTED_HERDR_PROTOCOL, parseHerdrStatus } from '../herdr/protocol'
|
|
4
|
-
|
|
5
|
-
export interface BackendState {
|
|
6
|
-
installed: boolean
|
|
7
|
-
running: boolean
|
|
8
|
-
compatible?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface BackendAvailability {
|
|
12
|
-
tmux: BackendState
|
|
13
|
-
herdr: BackendState
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function probeHerdrAvailability(runner: CommandRunner): Promise<BackendState> {
|
|
17
|
-
const result = await runner.run(['herdr', 'status', '--json'])
|
|
18
|
-
if (result.exitCode !== 0) {
|
|
19
|
-
return { installed: result.exitCode !== 127, running: false }
|
|
20
|
-
}
|
|
21
|
-
const status = parseHerdrStatus(result.stdout)
|
|
22
|
-
return {
|
|
23
|
-
installed: true,
|
|
24
|
-
running: status.running,
|
|
25
|
-
compatible:
|
|
26
|
-
status.compatible === true &&
|
|
27
|
-
status.protocol !== undefined &&
|
|
28
|
-
status.protocol >= MIN_SUPPORTED_HERDR_PROTOCOL,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function probeBackendAvailability(
|
|
33
|
-
runner: CommandRunner
|
|
34
|
-
): Promise<BackendAvailability> {
|
|
35
|
-
const [tmuxVersion, tmuxServer, herdr] = await Promise.all([
|
|
36
|
-
runner.run(['tmux', '-V']),
|
|
37
|
-
runner.run(['tmux', 'list-sessions']),
|
|
38
|
-
probeHerdrAvailability(runner),
|
|
39
|
-
])
|
|
40
|
-
const tmuxInstalled = tmuxVersion.exitCode === 0
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
tmux: { installed: tmuxInstalled, running: tmuxInstalled && tmuxServer.exitCode === 0 },
|
|
44
|
-
herdr,
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function resolveBackendKind(
|
|
49
|
-
env: Readonly<Record<string, string | undefined>>,
|
|
50
|
-
preference: BackendPreference | undefined,
|
|
51
|
-
availability: BackendAvailability
|
|
52
|
-
): BackendKind {
|
|
53
|
-
if (env.HERDR_ENV === '1') {
|
|
54
|
-
return 'herdr'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (env.TMUX) {
|
|
58
|
-
return 'tmux'
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (preference === 'herdr') {
|
|
62
|
-
if (availability.herdr.running && availability.herdr.compatible !== true) {
|
|
63
|
-
throw new MultiplexerError(
|
|
64
|
-
'protocol-mismatch',
|
|
65
|
-
'Herdr is configured, but its client and server protocols are incompatible. Restart the Herdr server, then relaunch mux-sesh.'
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
if (!availability.herdr.running) {
|
|
69
|
-
throw new MultiplexerError(
|
|
70
|
-
'server-stopped',
|
|
71
|
-
'Herdr is configured, but its server is not running. Start Herdr, then relaunch mux-sesh.'
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
return 'herdr'
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (preference === 'tmux') {
|
|
78
|
-
if (!availability.tmux.installed) {
|
|
79
|
-
throw new MultiplexerError(
|
|
80
|
-
'unavailable',
|
|
81
|
-
'tmux is configured, but its executable is unavailable. Install tmux, then relaunch mux-sesh.'
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
return 'tmux'
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (availability.tmux.running && !availability.herdr.running) {
|
|
88
|
-
return 'tmux'
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const herdrUsable = availability.herdr.running && availability.herdr.compatible === true
|
|
92
|
-
|
|
93
|
-
if (herdrUsable && !availability.tmux.running) {
|
|
94
|
-
return 'herdr'
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (availability.tmux.running && herdrUsable) {
|
|
98
|
-
return 'tmux'
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (availability.tmux.installed) {
|
|
102
|
-
return 'tmux'
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
throw new MultiplexerError(
|
|
106
|
-
'unavailable',
|
|
107
|
-
'No usable multiplexer backend was found. Install tmux or start Herdr, then relaunch mux-sesh.'
|
|
108
|
-
)
|
|
109
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { CommandRunner } from './command'
|
|
2
|
-
import type {
|
|
3
|
-
LiveWorkspace,
|
|
4
|
-
MultiplexerBackend,
|
|
5
|
-
OpenWorkspaceInput,
|
|
6
|
-
WorkspaceDetails,
|
|
7
|
-
WorkspaceRef,
|
|
8
|
-
} from './types'
|
|
9
|
-
import {
|
|
10
|
-
createTmuxSession,
|
|
11
|
-
getCurrentTmuxSessionName,
|
|
12
|
-
getSessionDetails,
|
|
13
|
-
getTmuxSessionDirectory,
|
|
14
|
-
killTmuxSession,
|
|
15
|
-
listTmuxSessions,
|
|
16
|
-
renameTmuxSession,
|
|
17
|
-
switchTmuxSession,
|
|
18
|
-
} from '../tmux'
|
|
19
|
-
|
|
20
|
-
export interface TmuxBackendOptions {
|
|
21
|
-
runner: CommandRunner
|
|
22
|
-
insideTmux: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createTmuxBackend(options: TmuxBackendOptions): MultiplexerBackend {
|
|
26
|
-
return {
|
|
27
|
-
kind: 'tmux',
|
|
28
|
-
capabilities: { previousWorkspace: true },
|
|
29
|
-
async list(): Promise<LiveWorkspace[]> {
|
|
30
|
-
return (await listTmuxSessions()).map(item => ({
|
|
31
|
-
backend: 'tmux',
|
|
32
|
-
id: item.title,
|
|
33
|
-
title: item.title,
|
|
34
|
-
path: item.path,
|
|
35
|
-
isActive: item.isAttached === true,
|
|
36
|
-
unitCount: Number.parseInt(item.windowCount ?? '0', 10),
|
|
37
|
-
createdAt: item.createdAt,
|
|
38
|
-
lastActivity: item.lastActivity,
|
|
39
|
-
}))
|
|
40
|
-
},
|
|
41
|
-
async open(workspace: WorkspaceRef): Promise<void> {
|
|
42
|
-
await switchTmuxSession(workspace.id)
|
|
43
|
-
},
|
|
44
|
-
async openOrCreate(input: OpenWorkspaceInput): Promise<void> {
|
|
45
|
-
await createTmuxSession(input.title, input.path, { startupCommand: input.startupCommand })
|
|
46
|
-
},
|
|
47
|
-
async rename(workspace: WorkspaceRef, title: string): Promise<void> {
|
|
48
|
-
await renameTmuxSession(workspace.id, title)
|
|
49
|
-
},
|
|
50
|
-
async close(workspace: WorkspaceRef): Promise<void> {
|
|
51
|
-
await killTmuxSession(workspace.id)
|
|
52
|
-
},
|
|
53
|
-
async current(): Promise<WorkspaceRef | undefined> {
|
|
54
|
-
const title = await getCurrentTmuxSessionName()
|
|
55
|
-
return { backend: 'tmux', id: title, title }
|
|
56
|
-
},
|
|
57
|
-
async directory(workspace: WorkspaceRef): Promise<string | undefined> {
|
|
58
|
-
return getTmuxSessionDirectory(workspace.id)
|
|
59
|
-
},
|
|
60
|
-
async details(workspace: WorkspaceRef): Promise<WorkspaceDetails> {
|
|
61
|
-
const details = await getSessionDetails(workspace.id)
|
|
62
|
-
return {
|
|
63
|
-
workspace,
|
|
64
|
-
isActive: details.isAttached,
|
|
65
|
-
unitLabel: 'Windows',
|
|
66
|
-
units: details.windows.map(window => ({
|
|
67
|
-
id: window.index,
|
|
68
|
-
name: window.name,
|
|
69
|
-
currentPath: window.currentPath,
|
|
70
|
-
currentCommand: window.currentCommand,
|
|
71
|
-
})),
|
|
72
|
-
previewLines: details.panePreviewLines,
|
|
73
|
-
agents: [],
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
async openEditor(path: string, command: string): Promise<boolean> {
|
|
77
|
-
if (!options.insideTmux) {
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
const result = await options.runner.run(['tmux', 'new-window', '-c', path, command])
|
|
81
|
-
if (result.exitCode !== 0) {
|
|
82
|
-
throw new Error(`Failed to open tmux editor window: ${result.stderr.trim()}`)
|
|
83
|
-
}
|
|
84
|
-
return true
|
|
85
|
-
},
|
|
86
|
-
}
|
|
87
|
-
}
|
package/src/multiplexer/types.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
export type BackendKind = 'tmux' | 'herdr'
|
|
2
|
-
export type BackendPreference = BackendKind
|
|
3
|
-
export type AgentStatus = 'idle' | 'working' | 'blocked' | 'done' | 'unknown'
|
|
4
|
-
|
|
5
|
-
interface WorkspaceIdentity {
|
|
6
|
-
id: string
|
|
7
|
-
title: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface HerdrAgentTarget {
|
|
11
|
-
kind: 'agent'
|
|
12
|
-
tabId: string
|
|
13
|
-
paneId: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type WorkspaceRef =
|
|
17
|
-
| (WorkspaceIdentity & { backend: 'tmux' })
|
|
18
|
-
| (WorkspaceIdentity & { backend: 'herdr'; target?: HerdrAgentTarget })
|
|
19
|
-
|
|
20
|
-
export type LiveWorkspace = WorkspaceRef & {
|
|
21
|
-
workspaceTitle?: string
|
|
22
|
-
path: string
|
|
23
|
-
isActive: boolean
|
|
24
|
-
unitCount: number
|
|
25
|
-
createdAt?: number
|
|
26
|
-
lastActivity?: number
|
|
27
|
-
agentStatus?: AgentStatus
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface OpenWorkspaceInput {
|
|
31
|
-
title: string
|
|
32
|
-
path: string
|
|
33
|
-
startupCommand?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface WorkspaceUnitDetails {
|
|
37
|
-
id: string
|
|
38
|
-
name: string
|
|
39
|
-
currentPath: string
|
|
40
|
-
currentCommand: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface WorkspaceAgentDetails {
|
|
44
|
-
paneId: string
|
|
45
|
-
name: string
|
|
46
|
-
status: AgentStatus
|
|
47
|
-
cwd?: string
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface WorkspaceDetails {
|
|
51
|
-
workspace: WorkspaceRef
|
|
52
|
-
isActive: boolean
|
|
53
|
-
unitLabel: 'Windows' | 'Tabs'
|
|
54
|
-
units: WorkspaceUnitDetails[]
|
|
55
|
-
previewLines?: string[]
|
|
56
|
-
agents: WorkspaceAgentDetails[]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface MultiplexerCapabilities {
|
|
60
|
-
previousWorkspace: boolean
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface MultiplexerBackend {
|
|
64
|
-
kind: BackendKind
|
|
65
|
-
capabilities: MultiplexerCapabilities
|
|
66
|
-
list(): Promise<LiveWorkspace[]>
|
|
67
|
-
open(workspace: WorkspaceRef): Promise<void>
|
|
68
|
-
openOrCreate(input: OpenWorkspaceInput): Promise<void>
|
|
69
|
-
rename(workspace: WorkspaceRef, title: string): Promise<void>
|
|
70
|
-
close(workspace: WorkspaceRef): Promise<void>
|
|
71
|
-
current(): Promise<WorkspaceRef | undefined>
|
|
72
|
-
directory(workspace: WorkspaceRef): Promise<string | undefined>
|
|
73
|
-
details(workspace: WorkspaceRef): Promise<WorkspaceDetails>
|
|
74
|
-
openEditor(path: string, command: string): Promise<boolean>
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export type MultiplexerErrorCode =
|
|
78
|
-
| 'unavailable'
|
|
79
|
-
| 'server-stopped'
|
|
80
|
-
| 'protocol-mismatch'
|
|
81
|
-
| 'command-failed'
|
|
82
|
-
| 'invalid-response'
|
|
83
|
-
| 'unsupported'
|
|
84
|
-
|
|
85
|
-
export class MultiplexerError extends Error {
|
|
86
|
-
constructor(
|
|
87
|
-
readonly code: MultiplexerErrorCode,
|
|
88
|
-
message: string
|
|
89
|
-
) {
|
|
90
|
-
super(message)
|
|
91
|
-
this.name = 'MultiplexerError'
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
|
|
3
|
-
export const OPENCODE_DATA_DIR = join(process.env.HOME || '', '.local/share/opencode')
|
|
4
|
-
export const OPENCODE_DATABASE_PATH = join(OPENCODE_DATA_DIR, 'opencode.db')
|
|
5
|
-
export const OPENCODE_STORAGE = join(process.env.HOME || '', '.local/share/opencode/storage')
|
|
6
|
-
export const SESSION_STORAGE = join(OPENCODE_STORAGE, 'session')
|
|
7
|
-
export const MESSAGE_STORAGE = join(OPENCODE_STORAGE, 'message')
|
package/src/opencode/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from './types'
|
|
2
|
-
export * from './constants'
|
|
3
|
-
export * from './parser'
|
|
4
|
-
export * from './tokens'
|
|
5
|
-
export * from './session'
|
|
6
|
-
export * from './session-name'
|
|
7
|
-
export * from './stats'
|
|
8
|
-
|
|
9
|
-
export function formatSessionAge(timestamp: number): string {
|
|
10
|
-
const now = Date.now()
|
|
11
|
-
const diff = now - timestamp
|
|
12
|
-
|
|
13
|
-
const minutes = Math.floor(diff / 60000)
|
|
14
|
-
const hours = Math.floor(diff / 3600000)
|
|
15
|
-
const days = Math.floor(diff / 86400000)
|
|
16
|
-
|
|
17
|
-
if (minutes < 60) return `${minutes}m ago`
|
|
18
|
-
if (hours < 24) return `${hours}h ago`
|
|
19
|
-
return `${days}d ago`
|
|
20
|
-
}
|
package/src/opencode/parser.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { OpencodeStats } from './types'
|
|
2
|
-
import { getGlobalStats } from './sqlite'
|
|
3
|
-
|
|
4
|
-
const GLOBAL_STATS_CACHE_TTL_MS = 10_000
|
|
5
|
-
|
|
6
|
-
let globalStatsCache: { stats: OpencodeStats; expiresAt: number } | null = null
|
|
7
|
-
|
|
8
|
-
function formatTokenCount(value: number): string {
|
|
9
|
-
if (value >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(1)}B`
|
|
10
|
-
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`
|
|
11
|
-
if (value >= 1_000) return `${(value / 1_000).toFixed(1)}K`
|
|
12
|
-
return value.toLocaleString()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function getGlobalOpencodeStats(): Promise<OpencodeStats> {
|
|
16
|
-
if (globalStatsCache && globalStatsCache.expiresAt > Date.now()) {
|
|
17
|
-
return globalStatsCache.stats
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const stats = await getGlobalStats()
|
|
21
|
-
|
|
22
|
-
const totalCost = stats.totalCost
|
|
23
|
-
const oldestCreatedAt = stats.oldestCreatedAt ?? Date.now()
|
|
24
|
-
const newestUpdatedAt = stats.newestUpdatedAt ?? oldestCreatedAt
|
|
25
|
-
const daySpan = Math.max(1, Math.ceil((newestUpdatedAt - oldestCreatedAt) / 86_400_000))
|
|
26
|
-
const costPerDay = totalCost / daySpan
|
|
27
|
-
|
|
28
|
-
const formattedStats = {
|
|
29
|
-
totalSessions: stats.totalSessions,
|
|
30
|
-
totalMessages: stats.totalMessages,
|
|
31
|
-
totalCost: `$${totalCost.toFixed(2)}`,
|
|
32
|
-
costPerDay: `$${costPerDay.toFixed(2)}`,
|
|
33
|
-
inputTokens: formatTokenCount(stats.inputTokens),
|
|
34
|
-
outputTokens: formatTokenCount(stats.outputTokens),
|
|
35
|
-
cacheRead: formatTokenCount(stats.cacheRead),
|
|
36
|
-
cacheWrite: formatTokenCount(stats.cacheWrite),
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
globalStatsCache = {
|
|
40
|
-
stats: formattedStats,
|
|
41
|
-
expiresAt: Date.now() + GLOBAL_STATS_CACHE_TTL_MS,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return formattedStats
|
|
45
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Item } from '../types'
|
|
2
|
-
|
|
3
|
-
const OPENCODE_SESSION_PREFIX = 'opencode-'
|
|
4
|
-
|
|
5
|
-
export function isOpencodeSessionName(sessionName: string): boolean {
|
|
6
|
-
return sessionName.startsWith(OPENCODE_SESSION_PREFIX)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isOpencodeSessionItem(
|
|
10
|
-
item: Pick<Item, 'isSession' | 'title' | 'itemKind'>
|
|
11
|
-
): boolean {
|
|
12
|
-
return item.isSession && item.itemKind !== 'herdr' && isOpencodeSessionName(item.title)
|
|
13
|
-
}
|