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.
Files changed (124) hide show
  1. package/README.md +133 -86
  2. package/bin/mux-sesh +45 -17
  3. package/bin/platform.sh +139 -0
  4. package/bin/postinstall +22 -0
  5. package/package.json +27 -38
  6. package/src/agents/index.ts +0 -1
  7. package/src/agents/session-name.ts +0 -24
  8. package/src/app/commands.ts +0 -138
  9. package/src/app/controller.ts +0 -437
  10. package/src/app/controls.ts +0 -123
  11. package/src/app/core-state.ts +0 -75
  12. package/src/app/data.ts +0 -130
  13. package/src/app/derived.ts +0 -77
  14. package/src/app/effects.ts +0 -650
  15. package/src/app/handlers.ts +0 -406
  16. package/src/app/keyboard.ts +0 -165
  17. package/src/app/modal-keyboard.ts +0 -137
  18. package/src/app/modal-state.ts +0 -53
  19. package/src/app/modals-layer.tsx +0 -159
  20. package/src/app/modals.ts +0 -108
  21. package/src/app/notifications.ts +0 -21
  22. package/src/app/opencode.ts +0 -49
  23. package/src/app/operations.ts +0 -31
  24. package/src/app/runtime.ts +0 -79
  25. package/src/app/screen.tsx +0 -240
  26. package/src/app/state.ts +0 -178
  27. package/src/app/textarea.ts +0 -16
  28. package/src/app/view.ts +0 -101
  29. package/src/app.tsx +0 -50
  30. package/src/config/index.ts +0 -475
  31. package/src/config/listed-sessions.ts +0 -33
  32. package/src/config/paths.ts +0 -13
  33. package/src/config/session-rules.ts +0 -100
  34. package/src/config/store.ts +0 -33
  35. package/src/files/target.ts +0 -96
  36. package/src/handlers/action-helpers.ts +0 -83
  37. package/src/handlers/actions.ts +0 -216
  38. package/src/handlers/keyboard/agents.ts +0 -134
  39. package/src/handlers/keyboard/index.ts +0 -5
  40. package/src/handlers/keyboard/new-session.ts +0 -58
  41. package/src/handlers/keyboard/normal.ts +0 -220
  42. package/src/handlers/keyboard/search.ts +0 -118
  43. package/src/handlers/keyboard/shared.ts +0 -117
  44. package/src/herdr/backend.ts +0 -357
  45. package/src/herdr/protocol.ts +0 -268
  46. package/src/index.tsx +0 -23
  47. package/src/items/order.ts +0 -95
  48. package/src/multiplexer/backend.ts +0 -43
  49. package/src/multiplexer/command.ts +0 -48
  50. package/src/multiplexer/index.ts +0 -21
  51. package/src/multiplexer/items.ts +0 -66
  52. package/src/multiplexer/resolve.ts +0 -109
  53. package/src/multiplexer/tmux-backend.ts +0 -87
  54. package/src/multiplexer/types.ts +0 -93
  55. package/src/opencode/constants.ts +0 -7
  56. package/src/opencode/index.ts +0 -20
  57. package/src/opencode/parser.ts +0 -45
  58. package/src/opencode/session-name.ts +0 -13
  59. package/src/opencode/session.ts +0 -146
  60. package/src/opencode/sqlite.ts +0 -447
  61. package/src/opencode/stats.ts +0 -26
  62. package/src/opencode/tokens.ts +0 -116
  63. package/src/opencode/types.ts +0 -33
  64. package/src/preview/project.ts +0 -362
  65. package/src/projects/session-links.ts +0 -52
  66. package/src/search/fff.ts +0 -224
  67. package/src/search/index.ts +0 -198
  68. package/src/settings.ts +0 -465
  69. package/src/styles/omarchy.ts +0 -295
  70. package/src/styles/opencode-themes-a.ts +0 -1442
  71. package/src/styles/opencode-themes-b.ts +0 -1212
  72. package/src/styles/opencode-tui-colors.ts +0 -1784
  73. package/src/styles/terminal-palette.ts +0 -156
  74. package/src/styles/theme-follow.ts +0 -94
  75. package/src/styles/theme.tsx +0 -311
  76. package/src/tmux/actions.ts +0 -145
  77. package/src/tmux/details.ts +0 -104
  78. package/src/tmux/helpers.ts +0 -35
  79. package/src/tmux/index.ts +0 -10
  80. package/src/tmux/list.ts +0 -31
  81. package/src/tmux/project-discovery.ts +0 -116
  82. package/src/tmux/project-loader.ts +0 -92
  83. package/src/tmux/project-zoxide.ts +0 -128
  84. package/src/tmux/projects.ts +0 -38
  85. package/src/tmux/workflows.ts +0 -26
  86. package/src/types/index.ts +0 -221
  87. package/src/ui/AgentSessionGroup.tsx +0 -93
  88. package/src/ui/CommandsModal.tsx +0 -246
  89. package/src/ui/ErrorScreen.tsx +0 -102
  90. package/src/ui/HighlightedText.tsx +0 -60
  91. package/src/ui/ItemList.tsx +0 -119
  92. package/src/ui/Modal.tsx +0 -48
  93. package/src/ui/OpencodeStatsPanel.tsx +0 -233
  94. package/src/ui/RenameModal.tsx +0 -42
  95. package/src/ui/SearchInput.tsx +0 -43
  96. package/src/ui/SessionDetailsPanel.tsx +0 -273
  97. package/src/ui/SessionList.tsx +0 -119
  98. package/src/ui/SettingEditorModal.tsx +0 -55
  99. package/src/ui/SettingOptionsModal.tsx +0 -95
  100. package/src/ui/SettingsModal.tsx +0 -102
  101. package/src/ui/Toast.tsx +0 -34
  102. package/src/ui/VersionBadge.tsx +0 -45
  103. package/src/ui/item-icon.ts +0 -110
  104. package/src/ui/list-window.ts +0 -35
  105. package/src/ui/session-meta.ts +0 -10
  106. package/src/ui/text-columns.ts +0 -17
  107. package/src/ui/use-textarea-focus.ts +0 -29
  108. package/src/update/events.ts +0 -28
  109. package/src/update/index.ts +0 -91
  110. package/src/update/installation.ts +0 -161
  111. package/src/update/version.ts +0 -33
  112. package/src/util/ansi.ts +0 -3
  113. package/src/util/browser.ts +0 -37
  114. package/src/util/clipboard.ts +0 -22
  115. package/src/util/errors.ts +0 -170
  116. package/src/util/github.ts +0 -100
  117. package/src/util/glob.ts +0 -51
  118. package/src/util/path-display.ts +0 -98
  119. package/src/util/perf.ts +0 -23
  120. package/src/util/shell.ts +0 -3
  121. package/src/util/shutdown.ts +0 -111
  122. package/src/util/terminal.ts +0 -28
  123. package/src/util/time.ts +0 -48
  124. package/tsconfig.json +0 -25
@@ -1,357 +0,0 @@
1
- import { resolve } from 'path'
2
- import {
3
- MultiplexerError,
4
- type LiveWorkspace,
5
- type MultiplexerBackend,
6
- type OpenWorkspaceInput,
7
- type WorkspaceDetails,
8
- type WorkspaceRef,
9
- } from '../multiplexer'
10
- import type { CommandOptions, CommandRunner } from '../multiplexer/command'
11
- import {
12
- parseHerdrCreatedWorkspace,
13
- parseHerdrCreatedTab,
14
- parseHerdrResult,
15
- parseHerdrSnapshot,
16
- type HerdrSnapshot,
17
- type HerdrWorkspace,
18
- } from './protocol'
19
-
20
- export type { CommandOptions, CommandRunner } from '../multiplexer/command'
21
-
22
- export interface HerdrBackendOptions {
23
- runner: CommandRunner
24
- insideHerdr: boolean
25
- }
26
-
27
- const AGENTS_WORKSPACE_LABEL = 'Agents'
28
-
29
- function isAgentTarget(workspace: WorkspaceRef): workspace is Extract<
30
- WorkspaceRef,
31
- { backend: 'herdr' }
32
- > & {
33
- target: { kind: 'agent'; tabId: string; paneId: string }
34
- } {
35
- return workspace.backend === 'herdr' && workspace.target?.kind === 'agent'
36
- }
37
-
38
- function workspacePaths(snapshot: HerdrSnapshot, workspace: HerdrWorkspace): string[] {
39
- const panes = snapshot.panes.filter(pane => pane.workspaceId === workspace.id)
40
- const activePane =
41
- panes.find(
42
- pane =>
43
- pane.id ===
44
- snapshot.layouts.find(layout => layout.tabId === workspace.activeTabId)?.focusedPaneId
45
- ) ??
46
- panes.find(pane => pane.tabId === workspace.activeTabId) ??
47
- panes[0]
48
- return [activePane?.cwd, workspace.worktreePath].filter(
49
- (path): path is string => typeof path === 'string' && path.length > 0
50
- )
51
- }
52
-
53
- function workspacePath(snapshot: HerdrSnapshot, workspace: HerdrWorkspace): string {
54
- return workspacePaths(snapshot, workspace)[0] ?? ''
55
- }
56
-
57
- function focusedPaneForTab(snapshot: HerdrSnapshot, tabId: string) {
58
- const focusedPaneId = snapshot.layouts.find(layout => layout.tabId === tabId)?.focusedPaneId
59
- return (
60
- snapshot.panes.find(pane => pane.id === focusedPaneId) ??
61
- snapshot.panes.find(pane => pane.tabId === tabId)
62
- )
63
- }
64
-
65
- export function createHerdrBackend(options: HerdrBackendOptions): MultiplexerBackend {
66
- let latestSnapshot: HerdrSnapshot | undefined
67
-
68
- async function snapshot(): Promise<HerdrSnapshot> {
69
- const result = await options.runner.run(['herdr', 'api', 'snapshot'])
70
- if (result.exitCode !== 0) {
71
- const reason = result.stderr.trim()
72
- throw new MultiplexerError(
73
- 'command-failed',
74
- reason
75
- ? `Failed to load Herdr workspaces: ${reason}`
76
- : 'Failed to load Herdr workspaces. Run herdr status --json to verify the server.'
77
- )
78
- }
79
- latestSnapshot = parseHerdrSnapshot(result.stdout)
80
- return latestSnapshot
81
- }
82
-
83
- async function command(argv: readonly string[], expectedType: string): Promise<string> {
84
- const result = await options.runner.run(argv)
85
- if (result.exitCode !== 0) {
86
- const reason = result.stderr.trim()
87
- throw new MultiplexerError(
88
- 'command-failed',
89
- reason
90
- ? `Herdr command failed: ${reason}`
91
- : `Herdr command failed: ${argv.slice(1).join(' ')}`
92
- )
93
- }
94
- parseHerdrResult(result.stdout, expectedType)
95
- return result.stdout
96
- }
97
-
98
- async function commandWithoutOutput(argv: readonly string[]): Promise<void> {
99
- const result = await options.runner.run(argv)
100
- if (result.exitCode !== 0) {
101
- const reason = result.stderr.trim()
102
- throw new MultiplexerError(
103
- 'command-failed',
104
- reason
105
- ? `Herdr command failed: ${reason}`
106
- : `Herdr command failed: ${argv.slice(1).join(' ')}`
107
- )
108
- }
109
- }
110
-
111
- async function focus(workspaceId: string): Promise<void> {
112
- await command(['herdr', 'workspace', 'focus', workspaceId], 'workspace_info')
113
- latestSnapshot = undefined
114
- }
115
-
116
- async function attachIfNeeded(): Promise<void> {
117
- if (options.insideHerdr) {
118
- return
119
- }
120
- const result = await options.runner.run(['herdr'], { inheritStdio: true })
121
- if (result.exitCode !== 0) {
122
- throw new MultiplexerError(
123
- 'command-failed',
124
- 'Failed to attach the Herdr client. The selected workspace remains focused.'
125
- )
126
- }
127
- }
128
-
129
- return {
130
- kind: 'herdr',
131
- capabilities: { previousWorkspace: false },
132
- async list(): Promise<LiveWorkspace[]> {
133
- const state = await snapshot()
134
- return state.workspaces.flatMap(workspace => {
135
- if (workspace.label !== AGENTS_WORKSPACE_LABEL) {
136
- return [
137
- {
138
- backend: 'herdr' as const,
139
- id: workspace.id,
140
- title: workspace.label,
141
- path: workspacePath(state, workspace),
142
- isActive: workspace.focused,
143
- unitCount: workspace.tabCount,
144
- agentStatus: workspace.agentStatus,
145
- },
146
- ]
147
- }
148
-
149
- return state.agents
150
- .filter(agent => agent.workspaceId === workspace.id)
151
- .map(agent => {
152
- const pane = state.panes.find(entry => entry.id === agent.paneId)
153
- const tab = state.tabs.find(entry => entry.id === agent.tabId)
154
- return {
155
- backend: 'herdr' as const,
156
- id: workspace.id,
157
- title: agent.name ?? agent.displayAgent ?? agent.agent ?? tab?.label ?? 'agent',
158
- workspaceTitle: workspace.label,
159
- path:
160
- agent.foregroundCwd ??
161
- agent.cwd ??
162
- pane?.foregroundCwd ??
163
- pane?.cwd ??
164
- workspace.worktreePath ??
165
- '',
166
- isActive:
167
- workspace.focused &&
168
- (state.focusedPaneId === agent.paneId || state.focusedTabId === agent.tabId),
169
- unitCount: 1,
170
- agentStatus: agent.status,
171
- target: { kind: 'agent' as const, tabId: agent.tabId, paneId: agent.paneId },
172
- }
173
- })
174
- })
175
- },
176
- async open(workspace: WorkspaceRef): Promise<void> {
177
- if (isAgentTarget(workspace)) {
178
- await command(['herdr', 'tab', 'focus', workspace.target.tabId], 'tab_info')
179
- latestSnapshot = undefined
180
- } else {
181
- await focus(workspace.id)
182
- }
183
- await attachIfNeeded()
184
- },
185
- async openOrCreate(input: OpenWorkspaceInput): Promise<void> {
186
- const state = await snapshot()
187
- const normalizedPath = resolve(input.path)
188
- const existing = state.workspaces.find(
189
- workspace =>
190
- workspace.label === input.title &&
191
- workspacePaths(state, workspace).some(path => resolve(path) === normalizedPath)
192
- )
193
- if (existing) {
194
- await focus(existing.id)
195
- await attachIfNeeded()
196
- return
197
- }
198
-
199
- const output = await command(
200
- ['herdr', 'workspace', 'create', '--cwd', input.path, '--label', input.title, '--focus'],
201
- 'workspace_created'
202
- )
203
- const created = parseHerdrCreatedWorkspace(output)
204
- if (input.startupCommand) {
205
- await commandWithoutOutput([
206
- 'herdr',
207
- 'pane',
208
- 'run',
209
- created.rootPaneId,
210
- input.startupCommand,
211
- ])
212
- }
213
- latestSnapshot = undefined
214
- await attachIfNeeded()
215
- },
216
- async rename(workspace: WorkspaceRef, title: string): Promise<void> {
217
- if (isAgentTarget(workspace)) {
218
- throw new MultiplexerError(
219
- 'unsupported',
220
- 'Cannot rename an agent tab from mux-sesh. Rename it in Herdr instead.'
221
- )
222
- }
223
- await command(['herdr', 'workspace', 'rename', workspace.id, title], 'workspace_info')
224
- latestSnapshot = undefined
225
- },
226
- async close(workspace: WorkspaceRef): Promise<void> {
227
- if (isAgentTarget(workspace)) {
228
- throw new MultiplexerError(
229
- 'unsupported',
230
- 'Cannot close an agent tab from mux-sesh. Close it in Herdr instead.'
231
- )
232
- }
233
- await command(['herdr', 'workspace', 'close', workspace.id], 'ok')
234
- latestSnapshot = undefined
235
- },
236
- async current(): Promise<WorkspaceRef | undefined> {
237
- const state = latestSnapshot ?? (await snapshot())
238
- const workspace = state.workspaces.find(entry => entry.id === state.focusedWorkspaceId)
239
- return workspace ? { backend: 'herdr', id: workspace.id, title: workspace.label } : undefined
240
- },
241
- async directory(workspace: WorkspaceRef): Promise<string | undefined> {
242
- const state = latestSnapshot ?? (await snapshot())
243
- if (isAgentTarget(workspace)) {
244
- const pane = state.panes.find(entry => entry.id === workspace.target.paneId)
245
- return pane?.foregroundCwd ?? pane?.cwd
246
- }
247
- const target = state.workspaces.find(entry => entry.id === workspace.id)
248
- return target ? workspacePath(state, target) || undefined : undefined
249
- },
250
- async details(workspace: WorkspaceRef): Promise<WorkspaceDetails> {
251
- const state = latestSnapshot ?? (await snapshot())
252
- const target = state.workspaces.find(entry => entry.id === workspace.id)
253
- if (!target) {
254
- throw new MultiplexerError(
255
- 'command-failed',
256
- `Herdr workspace '${workspace.title}' (${workspace.id}) no longer exists.`
257
- )
258
- }
259
-
260
- const workspaceTabs = state.tabs.filter(
261
- tab =>
262
- tab.workspaceId === workspace.id &&
263
- (!isAgentTarget(workspace) || tab.id === workspace.target.tabId)
264
- )
265
- const workspacePanes = state.panes.filter(pane => pane.workspaceId === workspace.id)
266
- const previewPane = isAgentTarget(workspace)
267
- ? state.panes.find(pane => pane.id === workspace.target.paneId)
268
- : (focusedPaneForTab(state, target.activeTabId) ?? workspacePanes[0])
269
- let previewLines: string[] | undefined
270
- if (previewPane) {
271
- const preview = await options.runner.run([
272
- 'herdr',
273
- 'pane',
274
- 'read',
275
- previewPane.id,
276
- '--source',
277
- 'recent-unwrapped',
278
- '--lines',
279
- '16',
280
- ])
281
- if (preview.exitCode === 0) {
282
- const lines = preview.stdout
283
- .split('\n')
284
- .map(line => line.trimEnd())
285
- .filter(line => line.length > 0)
286
- previewLines = lines.length > 0 ? lines : undefined
287
- }
288
- }
289
-
290
- return {
291
- workspace: isAgentTarget(workspace)
292
- ? workspace
293
- : { backend: 'herdr', id: target.id, title: target.label },
294
- isActive: isAgentTarget(workspace)
295
- ? target.focused &&
296
- (state.focusedPaneId === workspace.target.paneId ||
297
- state.focusedTabId === workspace.target.tabId)
298
- : target.focused,
299
- unitLabel: 'Tabs',
300
- units: workspaceTabs.map(tab => {
301
- const pane = focusedPaneForTab(state, tab.id)
302
- return {
303
- id: tab.id,
304
- name: tab.label,
305
- currentPath: pane?.foregroundCwd ?? pane?.cwd ?? '',
306
- currentCommand: pane?.displayAgent ?? pane?.label ?? pane?.title ?? '',
307
- }
308
- }),
309
- previewLines,
310
- agents: state.agents
311
- .filter(
312
- agent =>
313
- agent.workspaceId === workspace.id &&
314
- (!isAgentTarget(workspace) || agent.paneId === workspace.target.paneId)
315
- )
316
- .map(agent => ({
317
- paneId: agent.paneId,
318
- name: agent.name ?? agent.displayAgent ?? agent.agent ?? 'agent',
319
- status: agent.status,
320
- cwd: agent.foregroundCwd ?? agent.cwd,
321
- })),
322
- }
323
- },
324
- async openEditor(path: string, editorCommand: string): Promise<boolean> {
325
- if (!options.insideHerdr) {
326
- return false
327
- }
328
- const state = latestSnapshot ?? (await snapshot())
329
- const workspaceId = state.focusedWorkspaceId
330
- if (!workspaceId) {
331
- throw new MultiplexerError(
332
- 'command-failed',
333
- 'Herdr has no focused workspace for the editor tab.'
334
- )
335
- }
336
- const output = await command(
337
- [
338
- 'herdr',
339
- 'tab',
340
- 'create',
341
- '--workspace',
342
- workspaceId,
343
- '--cwd',
344
- path,
345
- '--label',
346
- 'editor',
347
- '--focus',
348
- ],
349
- 'tab_created'
350
- )
351
- const created = parseHerdrCreatedTab(output)
352
- await commandWithoutOutput(['herdr', 'pane', 'run', created.rootPaneId, editorCommand])
353
- latestSnapshot = undefined
354
- return true
355
- },
356
- }
357
- }
@@ -1,268 +0,0 @@
1
- import { MultiplexerError, type AgentStatus } from '../multiplexer'
2
-
3
- export interface HerdrWorkspace {
4
- id: string
5
- label: string
6
- focused: boolean
7
- tabCount: number
8
- activeTabId: string
9
- agentStatus: AgentStatus
10
- worktreePath?: string
11
- }
12
-
13
- export interface HerdrTab {
14
- id: string
15
- workspaceId: string
16
- number: number
17
- label: string
18
- }
19
-
20
- export interface HerdrPane {
21
- id: string
22
- workspaceId: string
23
- tabId: string
24
- focused: boolean
25
- agentStatus: AgentStatus
26
- cwd?: string
27
- foregroundCwd?: string
28
- displayAgent?: string
29
- label?: string
30
- title?: string
31
- }
32
-
33
- export interface HerdrAgent {
34
- paneId: string
35
- workspaceId: string
36
- tabId: string
37
- status: AgentStatus
38
- name?: string
39
- agent?: string
40
- displayAgent?: string
41
- cwd?: string
42
- foregroundCwd?: string
43
- }
44
-
45
- export interface HerdrLayout {
46
- workspaceId: string
47
- tabId: string
48
- focusedPaneId: string
49
- }
50
-
51
- export interface HerdrSnapshot {
52
- focusedWorkspaceId?: string
53
- focusedTabId?: string
54
- focusedPaneId?: string
55
- workspaces: HerdrWorkspace[]
56
- tabs: HerdrTab[]
57
- panes: HerdrPane[]
58
- layouts: HerdrLayout[]
59
- agents: HerdrAgent[]
60
- }
61
-
62
- export interface HerdrCreatedWorkspace {
63
- workspaceId: string
64
- workspaceTitle: string
65
- rootPaneId: string
66
- }
67
-
68
- export interface HerdrCreatedTab {
69
- tabId: string
70
- rootPaneId: string
71
- }
72
-
73
- export interface HerdrStatus {
74
- running: boolean
75
- compatible?: boolean
76
- protocol?: number
77
- }
78
-
79
- export const MIN_SUPPORTED_HERDR_PROTOCOL = 17
80
-
81
- function isRecord(value: unknown): value is Record<string, unknown> {
82
- return typeof value === 'object' && value !== null && !Array.isArray(value)
83
- }
84
-
85
- function invalid(message: string): never {
86
- throw new MultiplexerError(
87
- 'invalid-response',
88
- `Herdr returned an invalid response: ${message}. Run 'herdr status --json' to verify the server and protocol.`
89
- )
90
- }
91
-
92
- function record(value: unknown, field: string): Record<string, unknown> {
93
- return isRecord(value) ? value : invalid(`expected ${field} to be an object`)
94
- }
95
-
96
- function array(value: unknown, field: string): unknown[] {
97
- return Array.isArray(value) ? value : invalid(`expected ${field} to be an array`)
98
- }
99
-
100
- function string(value: unknown, field: string): string {
101
- return typeof value === 'string' && value.length > 0
102
- ? value
103
- : invalid(`expected ${field} to be a non-empty string`)
104
- }
105
-
106
- function optionalString(value: unknown): string | undefined {
107
- return typeof value === 'string' && value.length > 0 ? value : undefined
108
- }
109
-
110
- function number(value: unknown, field: string): number {
111
- return typeof value === 'number' && Number.isFinite(value)
112
- ? value
113
- : invalid(`expected ${field} to be a number`)
114
- }
115
-
116
- function boolean(value: unknown, field: string): boolean {
117
- return typeof value === 'boolean' ? value : invalid(`expected ${field} to be a boolean`)
118
- }
119
-
120
- function agentStatus(value: unknown): AgentStatus {
121
- return value === 'idle' ||
122
- value === 'working' ||
123
- value === 'blocked' ||
124
- value === 'done' ||
125
- value === 'unknown'
126
- ? value
127
- : 'unknown'
128
- }
129
-
130
- function parseWorkspace(value: unknown): HerdrWorkspace {
131
- const raw = record(value, 'workspace')
132
- const worktree =
133
- raw.worktree === undefined ? undefined : record(raw.worktree, 'workspace.worktree')
134
- return {
135
- id: string(raw.workspace_id, 'workspace.workspace_id'),
136
- label: string(raw.label, 'workspace.label'),
137
- focused: boolean(raw.focused, 'workspace.focused'),
138
- tabCount: number(raw.tab_count, 'workspace.tab_count'),
139
- activeTabId: string(raw.active_tab_id, 'workspace.active_tab_id'),
140
- agentStatus: agentStatus(raw.agent_status),
141
- worktreePath: optionalString(worktree?.checkout_path),
142
- }
143
- }
144
-
145
- function parseTab(value: unknown): HerdrTab {
146
- const raw = record(value, 'tab')
147
- return {
148
- id: string(raw.tab_id, 'tab.tab_id'),
149
- workspaceId: string(raw.workspace_id, 'tab.workspace_id'),
150
- number: number(raw.number, 'tab.number'),
151
- label: string(raw.label, 'tab.label'),
152
- }
153
- }
154
-
155
- function parsePane(value: unknown): HerdrPane {
156
- const raw = record(value, 'pane')
157
- return {
158
- id: string(raw.pane_id, 'pane.pane_id'),
159
- workspaceId: string(raw.workspace_id, 'pane.workspace_id'),
160
- tabId: string(raw.tab_id, 'pane.tab_id'),
161
- focused: boolean(raw.focused, 'pane.focused'),
162
- agentStatus: agentStatus(raw.agent_status),
163
- cwd: optionalString(raw.cwd),
164
- foregroundCwd: optionalString(raw.foreground_cwd),
165
- displayAgent: optionalString(raw.display_agent),
166
- label: optionalString(raw.label),
167
- title: optionalString(raw.title),
168
- }
169
- }
170
-
171
- function parseAgent(value: unknown): HerdrAgent {
172
- const raw = record(value, 'agent')
173
- return {
174
- paneId: string(raw.pane_id, 'agent.pane_id'),
175
- workspaceId: string(raw.workspace_id, 'agent.workspace_id'),
176
- tabId: string(raw.tab_id, 'agent.tab_id'),
177
- status: agentStatus(raw.agent_status),
178
- name: optionalString(raw.name),
179
- agent: optionalString(raw.agent),
180
- displayAgent: optionalString(raw.display_agent),
181
- cwd: optionalString(raw.cwd),
182
- foregroundCwd: optionalString(raw.foreground_cwd),
183
- }
184
- }
185
-
186
- function parseLayout(value: unknown): HerdrLayout {
187
- const raw = record(value, 'layout')
188
- return {
189
- workspaceId: string(raw.workspace_id, 'layout.workspace_id'),
190
- tabId: string(raw.tab_id, 'layout.tab_id'),
191
- focusedPaneId: string(raw.focused_pane_id, 'layout.focused_pane_id'),
192
- }
193
- }
194
-
195
- export function parseHerdrSnapshot(output: string): HerdrSnapshot {
196
- const result = parseHerdrResult(output, 'session_snapshot')
197
- const snapshot = record(result.snapshot, 'result.snapshot')
198
- return {
199
- focusedWorkspaceId: optionalString(snapshot.focused_workspace_id),
200
- focusedTabId: optionalString(snapshot.focused_tab_id),
201
- focusedPaneId: optionalString(snapshot.focused_pane_id),
202
- workspaces: array(snapshot.workspaces, 'snapshot.workspaces').map(parseWorkspace),
203
- tabs: array(snapshot.tabs, 'snapshot.tabs').map(parseTab),
204
- panes: array(snapshot.panes, 'snapshot.panes').map(parsePane),
205
- layouts: array(snapshot.layouts, 'snapshot.layouts').map(parseLayout),
206
- agents: array(snapshot.agents, 'snapshot.agents').map(parseAgent),
207
- }
208
- }
209
-
210
- export function parseHerdrResult(output: string, expectedType: string): Record<string, unknown> {
211
- let decoded: unknown
212
- try {
213
- decoded = JSON.parse(output)
214
- } catch {
215
- invalid('output was not valid JSON')
216
- }
217
-
218
- const envelope = record(decoded, 'response')
219
- if (envelope.error !== undefined) {
220
- const error = record(envelope.error, 'error')
221
- const message = optionalString(error.message) ?? 'unknown Herdr API error'
222
- throw new MultiplexerError('command-failed', `Herdr rejected the request: ${message}`)
223
- }
224
-
225
- const result = record(envelope.result, 'result')
226
- if (result.type !== expectedType) {
227
- invalid(`expected result.type to be '${expectedType}'`)
228
- }
229
-
230
- return result
231
- }
232
-
233
- export function parseHerdrCreatedWorkspace(output: string): HerdrCreatedWorkspace {
234
- const result = parseHerdrResult(output, 'workspace_created')
235
- const workspace = record(result.workspace, 'result.workspace')
236
- const rootPane = record(result.root_pane, 'result.root_pane')
237
- return {
238
- workspaceId: string(workspace.workspace_id, 'workspace.workspace_id'),
239
- workspaceTitle: string(workspace.label, 'workspace.label'),
240
- rootPaneId: string(rootPane.pane_id, 'root_pane.pane_id'),
241
- }
242
- }
243
-
244
- export function parseHerdrCreatedTab(output: string): HerdrCreatedTab {
245
- const result = parseHerdrResult(output, 'tab_created')
246
- const tab = record(result.tab, 'result.tab')
247
- const rootPane = record(result.root_pane, 'result.root_pane')
248
- return {
249
- tabId: string(tab.tab_id, 'tab.tab_id'),
250
- rootPaneId: string(rootPane.pane_id, 'root_pane.pane_id'),
251
- }
252
- }
253
-
254
- export function parseHerdrStatus(output: string): HerdrStatus {
255
- let decoded: unknown
256
- try {
257
- decoded = JSON.parse(output)
258
- } catch {
259
- invalid('status output was not valid JSON')
260
- }
261
- const root = record(decoded, 'status')
262
- const server = record(root.server, 'status.server')
263
- return {
264
- running: boolean(server.running, 'status.server.running'),
265
- compatible: typeof server.compatible === 'boolean' ? server.compatible : undefined,
266
- protocol: typeof server.protocol === 'number' ? server.protocol : undefined,
267
- }
268
- }
package/src/index.tsx DELETED
@@ -1,23 +0,0 @@
1
- import { createCliRenderer } from '@opentui/core'
2
- import { createRoot } from '@opentui/react'
3
- import { App } from './app'
4
- import { ignoreUnhandledThemeFollowSignal } from './styles/theme-follow'
5
- import { initializeFatalErrorHandling, initializeShutdown, requestShutdown } from './util/shutdown'
6
-
7
- initializeFatalErrorHandling()
8
- ignoreUnhandledThemeFollowSignal()
9
-
10
- const renderer = await createCliRenderer({
11
- exitOnCtrlC: false,
12
- openConsoleOnError: false,
13
- })
14
-
15
- initializeShutdown(renderer)
16
-
17
- for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP'] as const) {
18
- process.on(signal, () => {
19
- void requestShutdown(signal === 'SIGINT' ? 130 : 0)
20
- })
21
- }
22
-
23
- createRoot(renderer).render(<App />)