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,475 +0,0 @@
1
- import { join } from 'path'
2
- import type {
3
- Config,
4
- BackendPreference,
5
- IconConfig,
6
- KeybindMode,
7
- ProjectProfile,
8
- ProjectWildcard,
9
- SessionDefaults,
10
- SortOrder,
11
- ThemeColorScheme,
12
- ThemeDefinition,
13
- ThemePalette,
14
- ThemeVariant,
15
- ZoxideMode,
16
- } from '../types'
17
-
18
- const DEFAULT_EDITOR = 'nvim'
19
- const DEFAULT_THEME = 'rosepine'
20
- const DEFAULT_COLOR_SCHEME: ThemeColorScheme = 'system'
21
- const DEFAULT_PREFIX_KEY = 'ctrl+x'
22
- const DEFAULT_EDITOR_COMMAND =
23
- "nvim -c \"lua vim.defer_fn(function() if pcall(require, 'telescope') then vim.cmd('Telescope find_files') end end, 100)\""
24
- const DEFAULT_ICONS: IconConfig = {
25
- tmux: '',
26
- herdr: '',
27
- configured: '',
28
- project: '',
29
- opencode: '',
30
- }
31
- const OPTIONAL_THEME_PALETTE_KEYS = ['accent', 'interactive', 'diffAdd', 'diffDelete'] as const
32
-
33
- function isRecord(value: unknown): value is Record<string, unknown> {
34
- return typeof value === 'object' && value !== null
35
- }
36
-
37
- function asString(value: unknown): string | undefined {
38
- return typeof value === 'string' && value.length > 0 ? value : undefined
39
- }
40
-
41
- function asBoolean(value: unknown): boolean | undefined {
42
- return typeof value === 'boolean' ? value : undefined
43
- }
44
-
45
- function asStringArray(value: unknown): string[] | undefined {
46
- if (!Array.isArray(value)) {
47
- return undefined
48
- }
49
-
50
- const strings = value.filter(
51
- (entry): entry is string => typeof entry === 'string' && entry.length > 0
52
- )
53
- return strings.length > 0 ? strings : undefined
54
- }
55
-
56
- function uniqueStrings(values?: string[]): string[] | undefined {
57
- if (!values || values.length === 0) {
58
- return undefined
59
- }
60
-
61
- const seen = new Set<string>()
62
- const unique = values.filter(value => {
63
- if (seen.has(value)) {
64
- return false
65
- }
66
-
67
- seen.add(value)
68
- return true
69
- })
70
-
71
- return unique.length > 0 ? unique : undefined
72
- }
73
-
74
- function asKeybindMode(value: unknown): KeybindMode | undefined {
75
- return value === 'vim' || value === 'standard' ? value : undefined
76
- }
77
-
78
- function asZoxideMode(value: unknown): ZoxideMode | undefined {
79
- return value === 'off' || value === 'rank' || value === 'merge' ? value : undefined
80
- }
81
-
82
- function asSortOrder(value: unknown): SortOrder | undefined {
83
- return value === 'live-first' ||
84
- value === 'configured-first' ||
85
- value === 'zoxide-first' ||
86
- value === 'alphabetical'
87
- ? value
88
- : undefined
89
- }
90
-
91
- function asBackendPreference(value: unknown): BackendPreference | undefined {
92
- return value === 'tmux' || value === 'herdr' ? value : undefined
93
- }
94
-
95
- function asThemeColorScheme(value: unknown): ThemeColorScheme | undefined {
96
- return value === 'light' || value === 'dark' || value === 'system' ? value : undefined
97
- }
98
-
99
- function asPositiveInteger(value: unknown): number | undefined {
100
- return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined
101
- }
102
-
103
- function expandHomePath(value: string, homeDir: string): string {
104
- if (!value.startsWith('~')) {
105
- return value
106
- }
107
-
108
- return join(homeDir, value.slice(1))
109
- }
110
-
111
- function normalizeSessionDefaults(value: unknown): SessionDefaults | undefined {
112
- if (!isRecord(value)) {
113
- return undefined
114
- }
115
-
116
- const startupCommand = asString(value.startup_command) ?? asString(value.startupCommand)
117
- const previewCommand = asString(value.preview_command) ?? asString(value.previewCommand)
118
-
119
- if (!startupCommand && !previewCommand) {
120
- return undefined
121
- }
122
-
123
- return {
124
- startupCommand,
125
- previewCommand,
126
- }
127
- }
128
-
129
- function normalizeIcons(value: unknown): IconConfig | undefined {
130
- if (!isRecord(value)) {
131
- return undefined
132
- }
133
-
134
- return {
135
- tmux: asString(value.tmux) ?? DEFAULT_ICONS.tmux,
136
- herdr: asString(value.herdr) ?? DEFAULT_ICONS.herdr,
137
- configured: asString(value.configured) ?? asString(value.config) ?? DEFAULT_ICONS.configured,
138
- project: asString(value.project) ?? DEFAULT_ICONS.project,
139
- opencode: asString(value.opencode) ?? DEFAULT_ICONS.opencode,
140
- }
141
- }
142
-
143
- function normalizeThemePalette(value: unknown): ThemePalette | undefined {
144
- if (!isRecord(value)) {
145
- return undefined
146
- }
147
-
148
- const neutral = asString(value.neutral)
149
- const ink = asString(value.ink)
150
- const primary = asString(value.primary)
151
- const success = asString(value.success)
152
- const warning = asString(value.warning)
153
- const error = asString(value.error)
154
- const info = asString(value.info)
155
-
156
- if (!neutral || !ink || !primary || !success || !warning || !error || !info) {
157
- return undefined
158
- }
159
-
160
- const normalized: ThemePalette = {
161
- neutral,
162
- ink,
163
- primary,
164
- success,
165
- warning,
166
- error,
167
- info,
168
- }
169
-
170
- for (const key of OPTIONAL_THEME_PALETTE_KEYS) {
171
- const color = asString(value[key])
172
- if (color) {
173
- normalized[key] = color
174
- }
175
- }
176
-
177
- return normalized
178
- }
179
-
180
- function normalizeThemeVariant(value: unknown): ThemeVariant | undefined {
181
- if (!isRecord(value)) {
182
- return undefined
183
- }
184
-
185
- const palette = normalizeThemePalette(value.palette)
186
- if (!palette) {
187
- return undefined
188
- }
189
-
190
- const overrides = isRecord(value.overrides)
191
- ? Object.fromEntries(
192
- Object.entries(value.overrides)
193
- .map(([key, override]) => [key, asString(override)])
194
- .filter((entry): entry is [string, string] => typeof entry[1] === 'string')
195
- )
196
- : undefined
197
-
198
- return {
199
- palette,
200
- overrides: overrides && Object.keys(overrides).length > 0 ? overrides : undefined,
201
- }
202
- }
203
-
204
- function normalizeThemeDefinition(value: unknown, id: string): ThemeDefinition | undefined {
205
- if (!isRecord(value)) {
206
- return undefined
207
- }
208
-
209
- const light = normalizeThemeVariant(value.light)
210
- const dark = normalizeThemeVariant(value.dark)
211
-
212
- if (!light || !dark) {
213
- return undefined
214
- }
215
-
216
- return {
217
- name: asString(value.name) ?? id,
218
- light,
219
- dark,
220
- }
221
- }
222
-
223
- function normalizeThemes(value: unknown): Record<string, ThemeDefinition> | undefined {
224
- if (!isRecord(value)) {
225
- return undefined
226
- }
227
-
228
- const entries = Object.entries(value).flatMap(([name, definition]) => {
229
- const normalizedDefinition = normalizeThemeDefinition(definition, name)
230
- if (!normalizedDefinition) {
231
- return []
232
- }
233
-
234
- return [[name, normalizedDefinition] as const]
235
- })
236
-
237
- return entries.length > 0 ? Object.fromEntries(entries) : undefined
238
- }
239
-
240
- function normalizeProjectProfiles(value: unknown, homeDir: string): ProjectProfile[] | undefined {
241
- if (!Array.isArray(value)) {
242
- return undefined
243
- }
244
-
245
- const profiles = value.flatMap(entry => {
246
- if (!isRecord(entry)) {
247
- return []
248
- }
249
-
250
- const path = asString(entry.path)
251
- if (!path) {
252
- return []
253
- }
254
-
255
- return [
256
- {
257
- path: expandHomePath(path, homeDir),
258
- sessionName: asString(entry.session_name) ?? asString(entry.sessionName),
259
- startupCommand: asString(entry.startup_command) ?? asString(entry.startupCommand),
260
- previewCommand: asString(entry.preview_command) ?? asString(entry.previewCommand),
261
- listed: asBoolean(entry.listed),
262
- icon: asString(entry.icon),
263
- },
264
- ]
265
- })
266
-
267
- return profiles.length > 0 ? profiles : undefined
268
- }
269
-
270
- function normalizeWildcards(value: unknown, homeDir: string): ProjectWildcard[] | undefined {
271
- if (!Array.isArray(value)) {
272
- return undefined
273
- }
274
-
275
- const wildcards = value.flatMap(entry => {
276
- if (!isRecord(entry)) {
277
- return []
278
- }
279
-
280
- const pattern = asString(entry.pattern)
281
- if (!pattern) {
282
- return []
283
- }
284
-
285
- return [
286
- {
287
- pattern: expandHomePath(pattern, homeDir),
288
- sessionName: asString(entry.session_name) ?? asString(entry.sessionName),
289
- startupCommand: asString(entry.startup_command) ?? asString(entry.startupCommand),
290
- previewCommand: asString(entry.preview_command) ?? asString(entry.previewCommand),
291
- },
292
- ]
293
- })
294
-
295
- return wildcards.length > 0 ? wildcards : undefined
296
- }
297
-
298
- export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME || '~'): Config {
299
- const raw = isRecord(rawConfig) ? rawConfig : {}
300
- const defaultConfig = getDefaultConfig(homeDir)
301
- const requestedTheme = asString(raw.theme)
302
- const normalizedTheme =
303
- requestedTheme === 'rose-pine'
304
- ? 'rosepine'
305
- : requestedTheme === 'opencode-dark' || requestedTheme === 'opencode-light'
306
- ? 'opencode'
307
- : requestedTheme
308
- const implicitColorScheme =
309
- requestedTheme === 'opencode-light'
310
- ? 'light'
311
- : requestedTheme === 'opencode-dark'
312
- ? 'dark'
313
- : undefined
314
-
315
- const projectPaths = (
316
- asStringArray(raw.project_paths) ??
317
- asStringArray(raw.projectPaths) ??
318
- defaultConfig.projectPaths
319
- ).map(projectPath => expandHomePath(projectPath, homeDir))
320
- const reposPath = expandHomePath(
321
- asString(raw.repos_path) ?? asString(raw.reposPath) ?? defaultConfig.reposPath,
322
- homeDir
323
- )
324
- const editor = asString(raw.editor) ?? defaultConfig.editor
325
- const backend = asBackendPreference(raw.backend)
326
- const editorCmd = asString(raw.editor_cmd) ?? asString(raw.editorCmd) ?? defaultConfig.editorCmd
327
- const keybindMode =
328
- asKeybindMode(raw.keybind_mode) ?? asKeybindMode(raw.keybindMode) ?? defaultConfig.keybindMode
329
- const prefixKey = asString(raw.prefix_key) ?? asString(raw.prefixKey) ?? defaultConfig.prefixKey
330
- const zoxideMode =
331
- asZoxideMode(raw.zoxide_mode) ?? asZoxideMode(raw.zoxideMode) ?? defaultConfig.zoxideMode
332
- const sortOrder =
333
- asSortOrder(raw.sort_order) ?? asSortOrder(raw.sortOrder) ?? defaultConfig.sortOrder
334
- const theme = normalizedTheme ?? defaultConfig.theme
335
- const colorScheme =
336
- asThemeColorScheme(raw.color_scheme) ??
337
- asThemeColorScheme(raw.colorScheme) ??
338
- implicitColorScheme ??
339
- defaultConfig.colorScheme
340
- const themes = normalizeThemes(raw.themes) ?? defaultConfig.themes
341
- const autoUpdate =
342
- asBoolean(raw.auto_update) ?? asBoolean(raw.autoUpdate) ?? defaultConfig.autoUpdate
343
- const dirLength =
344
- asPositiveInteger(raw.dir_length) ?? asPositiveInteger(raw.dirLength) ?? defaultConfig.dirLength
345
- const hiddenSessions =
346
- asStringArray(raw.hidden_sessions) ??
347
- asStringArray(raw.hiddenSessions) ??
348
- defaultConfig.hiddenSessions
349
- const pinnedSessions =
350
- uniqueStrings(asStringArray(raw.pinned_sessions) ?? asStringArray(raw.pinnedSessions)) ??
351
- defaultConfig.pinnedSessions
352
- const icons = normalizeIcons(raw.icons) ?? defaultConfig.icons
353
- const configuredDefaultSession =
354
- normalizeSessionDefaults(raw.default_session) ?? normalizeSessionDefaults(raw.defaultSession)
355
- const defaultSession = {
356
- startupCommand: configuredDefaultSession?.startupCommand ?? editorCmd,
357
- previewCommand: configuredDefaultSession?.previewCommand,
358
- }
359
-
360
- return {
361
- backend,
362
- projectPaths,
363
- reposPath,
364
- editor,
365
- editorCmd,
366
- keybindMode,
367
- prefixKey,
368
- zoxideMode,
369
- sortOrder,
370
- theme,
371
- colorScheme,
372
- themes,
373
- autoUpdate,
374
- dirLength,
375
- hiddenSessions,
376
- pinnedSessions,
377
- icons,
378
- defaultSession,
379
- projects: normalizeProjectProfiles(raw.projects, homeDir) ?? defaultConfig.projects,
380
- wildcards: normalizeWildcards(raw.wildcards, homeDir) ?? defaultConfig.wildcards,
381
- }
382
- }
383
-
384
- export function getDefaultConfig(homeDir = process.env.HOME || '~'): Config {
385
- return {
386
- projectPaths: [join(homeDir, 'dev'), join(homeDir, 'personal')],
387
- reposPath: join(homeDir, 'dev', 'repos'),
388
- editor: DEFAULT_EDITOR,
389
- editorCmd: DEFAULT_EDITOR_COMMAND,
390
- keybindMode: 'vim',
391
- prefixKey: DEFAULT_PREFIX_KEY,
392
- zoxideMode: 'off',
393
- sortOrder: 'live-first',
394
- theme: DEFAULT_THEME,
395
- colorScheme: DEFAULT_COLOR_SCHEME,
396
- themes: {},
397
- autoUpdate: true,
398
- dirLength: 1,
399
- hiddenSessions: [],
400
- pinnedSessions: [],
401
- icons: DEFAULT_ICONS,
402
- defaultSession: {
403
- startupCommand: DEFAULT_EDITOR_COMMAND,
404
- },
405
- projects: [],
406
- wildcards: [],
407
- }
408
- }
409
-
410
- function serializeThemeVariant(variant: ThemeVariant) {
411
- return variant.overrides && Object.keys(variant.overrides).length > 0
412
- ? {
413
- palette: variant.palette,
414
- overrides: variant.overrides,
415
- }
416
- : {
417
- palette: variant.palette,
418
- }
419
- }
420
-
421
- export function serializeConfig(config: Config): Record<string, unknown> {
422
- return {
423
- backend: config.backend,
424
- project_paths: config.projectPaths,
425
- repos_path: config.reposPath,
426
- editor: config.editor,
427
- editor_cmd: config.editorCmd,
428
- keybind_mode: config.keybindMode,
429
- prefix_key: config.prefixKey,
430
- zoxide_mode: config.zoxideMode,
431
- sort_order: config.sortOrder,
432
- theme: config.theme,
433
- color_scheme: config.colorScheme,
434
- auto_update: config.autoUpdate,
435
- dir_length: config.dirLength,
436
- hidden_sessions: config.hiddenSessions,
437
- pinned_sessions: config.pinnedSessions,
438
- icons: config.icons,
439
- default_session: config.defaultSession
440
- ? {
441
- startup_command: config.defaultSession.startupCommand,
442
- preview_command: config.defaultSession.previewCommand,
443
- }
444
- : undefined,
445
- themes: config.themes
446
- ? Object.fromEntries(
447
- Object.entries(config.themes).map(([id, theme]) => [
448
- id,
449
- {
450
- name: theme.name,
451
- light: serializeThemeVariant(theme.light),
452
- dark: serializeThemeVariant(theme.dark),
453
- },
454
- ])
455
- )
456
- : undefined,
457
- projects: config.projects?.map(project => ({
458
- path: project.path,
459
- session_name: project.sessionName,
460
- startup_command: project.startupCommand,
461
- preview_command: project.previewCommand,
462
- listed: project.listed,
463
- icon: project.icon,
464
- })),
465
- wildcards: config.wildcards?.map(wildcard => ({
466
- pattern: wildcard.pattern,
467
- session_name: wildcard.sessionName,
468
- startup_command: wildcard.startupCommand,
469
- preview_command: wildcard.previewCommand,
470
- })),
471
- }
472
- }
473
-
474
- export { getConfigDir, getConfigPath, getHomeDir } from './paths'
475
- export { loadConfig, saveConfig } from './store'
@@ -1,33 +0,0 @@
1
- import type { Config, Item, ProjectProfile } from '../types'
2
- import { resolveProjectSession } from './session-rules'
3
- import { getPathGroupLabel } from '../util/path-display'
4
-
5
- function isListedProjectProfile(profile: ProjectProfile): boolean {
6
- return profile.listed === true
7
- }
8
-
9
- export async function getListedSessionItems(config: Config): Promise<Item[]> {
10
- const listedProfiles = (config.projects ?? []).filter(isListedProjectProfile)
11
-
12
- return Promise.all(
13
- listedProfiles.map(async profile => {
14
- const resolvedSession = await resolveProjectSession(profile.path, config)
15
-
16
- return {
17
- title: resolvedSession.sessionName,
18
- desc: getPathGroupLabel(profile.path),
19
- path: profile.path,
20
- isSession: false,
21
- itemKind: 'configured' as const,
22
- icon: profile.icon,
23
- }
24
- })
25
- )
26
- }
27
-
28
- export function mergeSessionItems(tmuxSessions: Item[], listedSessions: Item[]): Item[] {
29
- const liveSessionTitles = new Set(tmuxSessions.map(item => item.title))
30
- const uniqueListedSessions = listedSessions.filter(item => !liveSessionTitles.has(item.title))
31
-
32
- return [...tmuxSessions, ...uniqueListedSessions]
33
- }
@@ -1,13 +0,0 @@
1
- import { join } from 'path'
2
-
3
- export function getHomeDir(): string {
4
- return process.env.HOME || '~'
5
- }
6
-
7
- export function getConfigDir(homeDir = getHomeDir()): string {
8
- return process.env.XDG_CONFIG_HOME || join(homeDir, '.config')
9
- }
10
-
11
- export function getConfigPath(homeDir = getHomeDir()): string {
12
- return join(getConfigDir(homeDir), 'mux-sesh', 'config.json')
13
- }
@@ -1,100 +0,0 @@
1
- import { basename } from 'path'
2
- import { spawn } from 'bun'
3
- import type { Config, ProjectProfile, ProjectWildcard } from '../types'
4
- import { matchesGlob, normalizePathForMatching } from '../util/glob'
5
-
6
- export interface ResolvedProjectSession {
7
- sessionName: string
8
- startupCommand?: string
9
- previewCommand?: string
10
- source: 'project' | 'wildcard' | 'default'
11
- }
12
-
13
- export interface ResolveProjectSessionOptions {
14
- getGitRoot?: (projectPath: string) => Promise<string | null>
15
- }
16
-
17
- function sanitizeSessionName(value: string): string {
18
- return value.replace(/[.\s/]+/g, '_')
19
- }
20
-
21
- function pathMatches(projectPath: string, pattern: string): boolean {
22
- return matchesGlob(normalizePathForMatching(projectPath), normalizePathForMatching(pattern), {
23
- pathSeparatorAware: true,
24
- })
25
- }
26
-
27
- function findProjectProfile(projectPath: string, config: Config): ProjectProfile | undefined {
28
- return config.projects?.find(profile => normalizePathForMatching(profile.path) === projectPath)
29
- }
30
-
31
- function findWildcard(projectPath: string, config: Config): ProjectWildcard | undefined {
32
- return config.wildcards?.find(wildcard => pathMatches(projectPath, wildcard.pattern))
33
- }
34
-
35
- export async function getGitRoot(projectPath: string): Promise<string | null> {
36
- try {
37
- const proc = spawn(['git', '-C', projectPath, 'rev-parse', '--show-toplevel'], {
38
- stderr: 'pipe',
39
- })
40
- const output = (await new Response(proc.stdout).text()).trim()
41
- await proc.exited
42
-
43
- if (proc.exitCode !== 0 || output.length === 0) {
44
- return null
45
- }
46
-
47
- return output
48
- } catch {
49
- return null
50
- }
51
- }
52
-
53
- function buildSessionName(projectPath: string, dirLength = 1): string {
54
- const namingPath = normalizePathForMatching(projectPath)
55
- const parts = namingPath.split('/').filter(Boolean)
56
- const segmentCount = Math.max(1, dirLength)
57
- const relevantParts = parts.slice(-segmentCount)
58
- const joined = relevantParts.length > 0 ? relevantParts.join('_') : basename(projectPath)
59
-
60
- return sanitizeSessionName(joined)
61
- }
62
-
63
- export async function resolveProjectSession(
64
- projectPath: string,
65
- config: Config,
66
- _options: ResolveProjectSessionOptions = {}
67
- ): Promise<ResolvedProjectSession> {
68
- const normalizedProjectPath = normalizePathForMatching(projectPath)
69
- const projectProfile = findProjectProfile(normalizedProjectPath, config)
70
-
71
- if (projectProfile) {
72
- return {
73
- sessionName: sanitizeSessionName(
74
- projectProfile.sessionName ?? buildSessionName(projectPath, config.dirLength)
75
- ),
76
- startupCommand: projectProfile.startupCommand ?? config.defaultSession?.startupCommand,
77
- previewCommand: projectProfile.previewCommand ?? config.defaultSession?.previewCommand,
78
- source: 'project',
79
- }
80
- }
81
-
82
- const wildcard = findWildcard(normalizedProjectPath, config)
83
- if (wildcard) {
84
- return {
85
- sessionName: sanitizeSessionName(
86
- wildcard.sessionName ?? buildSessionName(projectPath, config.dirLength)
87
- ),
88
- startupCommand: wildcard.startupCommand ?? config.defaultSession?.startupCommand,
89
- previewCommand: wildcard.previewCommand ?? config.defaultSession?.previewCommand,
90
- source: 'wildcard',
91
- }
92
- }
93
-
94
- return {
95
- sessionName: buildSessionName(projectPath, config.dirLength),
96
- startupCommand: config.defaultSession?.startupCommand,
97
- previewCommand: config.defaultSession?.previewCommand,
98
- source: 'default',
99
- }
100
- }
@@ -1,33 +0,0 @@
1
- import { mkdir } from 'fs/promises'
2
- import { dirname } from 'path'
3
- import type { Config } from '../types'
4
- import { getConfigPath, getHomeDir } from './paths'
5
- import { getDefaultConfig, normalizeConfig, serializeConfig } from './index'
6
-
7
- export async function loadConfig(): Promise<Config> {
8
- const homeDir = getHomeDir()
9
- const configPath = getConfigPath(homeDir)
10
- const file = Bun.file(configPath)
11
-
12
- if (!(await file.exists())) {
13
- const defaultConfig = getDefaultConfig(homeDir)
14
- await saveConfig(defaultConfig, homeDir)
15
- return defaultConfig
16
- }
17
-
18
- try {
19
- return normalizeConfig(await file.json(), homeDir)
20
- } catch (error) {
21
- const detail = error instanceof Error ? ` ${error.message}` : ''
22
- throw new Error(
23
- `Failed to parse mux-sesh config at ${configPath}. Fix the JSON or move the file aside; existing config was not overwritten.${detail}`
24
- )
25
- }
26
- }
27
-
28
- export async function saveConfig(config: Config, homeDir = getHomeDir()): Promise<void> {
29
- const configPath = getConfigPath(homeDir)
30
-
31
- await mkdir(dirname(configPath), { recursive: true })
32
- await Bun.write(configPath, JSON.stringify(serializeConfig(config), null, 2))
33
- }