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,116 +0,0 @@
1
- import { spawn } from 'bun'
2
- import { getAssistantCostTotalBySession, getLastAssistantMessageData } from './sqlite'
3
-
4
- const modelContextLimitCache = new Map<string, number>()
5
-
6
- function getModelCacheKey(modelID: string, providerID: string): string {
7
- return `${providerID}:${modelID}`
8
- }
9
-
10
- export async function getModelContextLimit(modelID: string, providerID: string): Promise<number> {
11
- const cacheKey = getModelCacheKey(modelID, providerID)
12
- const cachedLimit = modelContextLimitCache.get(cacheKey)
13
- if (cachedLimit !== undefined) {
14
- return cachedLimit
15
- }
16
-
17
- try {
18
- const proc = spawn(['opencode', 'models', providerID, '--verbose'])
19
- const output = await new Response(proc.stdout).text()
20
- await proc.exited
21
-
22
- if (proc.exitCode !== 0) {
23
- throw new Error(`opencode models exited with code ${proc.exitCode}`)
24
- }
25
-
26
- const lines = output.split('\n')
27
- let inTargetModel = false
28
- let jsonBuffer = ''
29
-
30
- for (const line of lines) {
31
- if (line === `${providerID}/${modelID}`) {
32
- inTargetModel = true
33
- jsonBuffer = ''
34
- continue
35
- }
36
-
37
- if (!inTargetModel) {
38
- continue
39
- }
40
-
41
- if (/^[a-z0-9-]+\//i.test(line)) {
42
- break
43
- }
44
-
45
- jsonBuffer += `${line}\n`
46
- }
47
-
48
- if (jsonBuffer) {
49
- const modelData = JSON.parse(jsonBuffer) as { limit?: { context?: number } }
50
- const contextLimit = modelData.limit?.context
51
- if (typeof contextLimit === 'number' && Number.isFinite(contextLimit)) {
52
- modelContextLimitCache.set(cacheKey, contextLimit)
53
- return contextLimit
54
- }
55
- }
56
- } catch (error) {
57
- console.error('Failed to get model context limit:', error)
58
- }
59
-
60
- const fallbackLimit = getFallbackContextLimit(modelID)
61
- modelContextLimitCache.set(cacheKey, fallbackLimit)
62
- return fallbackLimit
63
- }
64
-
65
- function getFallbackContextLimit(modelID: string): number {
66
- if (modelID.includes('claude-sonnet-4')) return 1000000
67
- if (modelID.includes('claude')) return 200000
68
- if (modelID.includes('gpt-4o')) return 128000
69
- if (modelID.includes('gpt-4')) return 128000
70
- return 200000
71
- }
72
-
73
- export async function getLastMessageTokens(sessionID: string): Promise<{
74
- lastMessageTokens: number
75
- contextLimit: number
76
- totalCost: number
77
- modelID?: string
78
- providerID?: string
79
- } | null> {
80
- if (!sessionID) {
81
- return null
82
- }
83
-
84
- const lastAssistantMessage = await getLastAssistantMessageData(sessionID)
85
- if (!lastAssistantMessage) {
86
- return null
87
- }
88
-
89
- const totalCost = await getAssistantCostTotalBySession(sessionID)
90
- const contextLimit =
91
- lastAssistantMessage.modelID && lastAssistantMessage.providerID
92
- ? await getModelContextLimit(lastAssistantMessage.modelID, lastAssistantMessage.providerID)
93
- : 200000
94
-
95
- return {
96
- lastMessageTokens:
97
- lastAssistantMessage.tokens.input +
98
- lastAssistantMessage.tokens.output +
99
- lastAssistantMessage.tokens.reasoning +
100
- lastAssistantMessage.tokens.cacheRead +
101
- lastAssistantMessage.tokens.cacheWrite,
102
- contextLimit,
103
- totalCost,
104
- modelID: lastAssistantMessage.modelID,
105
- providerID: lastAssistantMessage.providerID,
106
- }
107
- }
108
-
109
- export function estimateSessionCost(inputTokens: number, outputTokens: number): string {
110
- const inputCost = (inputTokens / 1_000_000) * 3
111
- const outputCost = (outputTokens / 1_000_000) * 15
112
- const total = inputCost + outputCost
113
-
114
- if (total < 0.01) return '<$0.01'
115
- return `$${total.toFixed(2)}`
116
- }
@@ -1,33 +0,0 @@
1
- export interface OpencodeStats {
2
- // Per-session stats
3
- sessionID?: string
4
- title?: string
5
- projectID?: string
6
- directory?: string
7
- messageCount?: number
8
- filesModified?: number
9
- additions?: number
10
- deletions?: number
11
- createdAt?: number
12
- updatedAt?: number
13
-
14
- // Global stats
15
- totalSessions?: number
16
- totalMessages?: number
17
- totalCost?: string
18
- costPerDay?: string
19
- inputTokens?: string
20
- outputTokens?: string
21
- cacheRead?: string
22
- cacheWrite?: string
23
- topTools?: Array<{ name: string; count: number; percentage: string }>
24
-
25
- // Aggregated stats (for home directory sessions)
26
- sessionCount?: number
27
- mostRecentTitle?: string
28
-
29
- // Current session live stats (last message)
30
- lastMessageTokens?: number
31
- contextLimit?: number
32
- sessionTotalCost?: number
33
- }
@@ -1,362 +0,0 @@
1
- import { readdir, stat } from 'fs/promises'
2
- import { basename, dirname, join } from 'path'
3
- import { spawn } from 'bun'
4
- import type { Config } from '../types'
5
- import type { WorkspaceDetails, WorkspaceRef } from '../multiplexer'
6
- import { stripAnsi } from '../util/ansi'
7
- import { getGitRoot, resolveProjectSession } from '../config/session-rules'
8
- import { resolveFileSession } from '../files/target'
9
- import { toHomeRelativePath } from '../util/path-display'
10
- import { quoteShellArg } from '../util/shell'
11
-
12
- const MAX_PREVIEW_LINES = 24
13
- const MAX_PREVIEW_LINE_LENGTH = 120
14
- const PREVIEW_COMMAND_TIMEOUT_MS = 1500
15
- const PROJECT_PREVIEW_CACHE_TTL_MS = 4000
16
- const projectPreviewCache = new Map<string, { preview: ProjectPreview; expiresAt: number }>()
17
-
18
- export interface ProjectPreview {
19
- path: string
20
- sessionName: string
21
- source: 'project' | 'wildcard' | 'default' | 'file'
22
- startupCommand?: string
23
- previewCommand?: string
24
- gitRoot?: string
25
- gitBranch?: string
26
- linkedSession?: WorkspaceDetails
27
- previewKind: 'command' | 'directory' | 'file'
28
- previewLabel: string
29
- previewLines: string[]
30
- previewNotice?: string
31
- }
32
-
33
- interface FormattedPreviewOutput {
34
- lines: string[]
35
- truncated: boolean
36
- }
37
-
38
- interface PackageSummary {
39
- name?: string
40
- scripts: string[]
41
- }
42
-
43
- export function interpolatePreviewCommand(
44
- command: string | undefined,
45
- projectPath: string
46
- ): string | undefined {
47
- if (!command) {
48
- return undefined
49
- }
50
-
51
- return command.replaceAll('{}', quoteShellArg(projectPath))
52
- }
53
-
54
- export function formatPreviewOutput(
55
- output: string,
56
- maxLines = MAX_PREVIEW_LINES
57
- ): FormattedPreviewOutput {
58
- const cleanedLines = stripAnsi(output)
59
- .replace(/\r/g, '')
60
- .split('\n')
61
- .map(line => line.trimEnd())
62
- .filter(line => line.length > 0)
63
- .map(line =>
64
- line.length > MAX_PREVIEW_LINE_LENGTH
65
- ? `${line.slice(0, MAX_PREVIEW_LINE_LENGTH - 1)}…`
66
- : line
67
- )
68
-
69
- if (cleanedLines.length === 0) {
70
- return {
71
- lines: [],
72
- truncated: false,
73
- }
74
- }
75
-
76
- const truncated = cleanedLines.length > maxLines
77
-
78
- return {
79
- lines: truncated ? cleanedLines.slice(0, maxLines) : cleanedLines,
80
- truncated,
81
- }
82
- }
83
-
84
- async function getGitBranch(projectPath: string): Promise<string | undefined> {
85
- try {
86
- const proc = spawn(['git', '-C', projectPath, 'branch', '--show-current'], {
87
- stderr: 'pipe',
88
- })
89
- const output = (await new Response(proc.stdout).text()).trim()
90
- await proc.exited
91
-
92
- if (proc.exitCode !== 0 || output.length === 0) {
93
- return undefined
94
- }
95
-
96
- return output
97
- } catch {
98
- return undefined
99
- }
100
- }
101
-
102
- async function readPackageSummary(projectPath: string): Promise<PackageSummary | null> {
103
- try {
104
- const packageJson = (await Bun.file(join(projectPath, 'package.json')).json()) as {
105
- name?: string
106
- scripts?: Record<string, string>
107
- }
108
-
109
- return {
110
- name: packageJson.name,
111
- scripts: Object.keys(packageJson.scripts ?? {}).slice(0, 6),
112
- }
113
- } catch {
114
- return null
115
- }
116
- }
117
-
118
- async function getDirectoryPreviewLines(projectPath: string): Promise<string[]> {
119
- try {
120
- const [entries, packageSummary] = await Promise.all([
121
- readdir(projectPath, { withFileTypes: true }),
122
- readPackageSummary(projectPath),
123
- ])
124
-
125
- const visibleEntries = entries
126
- .filter(entry => !entry.name.startsWith('.'))
127
- .sort(
128
- (left, right) =>
129
- Number(right.isDirectory()) - Number(left.isDirectory()) ||
130
- left.name.localeCompare(right.name)
131
- )
132
- .slice(0, 16)
133
-
134
- const lines: string[] = []
135
-
136
- if (packageSummary?.name) {
137
- lines.push(`package ${packageSummary.name}`)
138
- }
139
-
140
- if (packageSummary && packageSummary.scripts.length > 0) {
141
- lines.push(`scripts ${packageSummary.scripts.join(', ')}`)
142
- }
143
-
144
- if (lines.length > 0) {
145
- lines.push('')
146
- }
147
-
148
- for (const entry of visibleEntries) {
149
- lines.push(entry.isDirectory() ? `${entry.name}/` : entry.name)
150
- }
151
-
152
- if (lines.length === 0) {
153
- lines.push(basename(projectPath))
154
- }
155
-
156
- return lines
157
- } catch {
158
- return [basename(projectPath)]
159
- }
160
- }
161
-
162
- async function runPreviewCommand(
163
- command: string,
164
- cwd: string
165
- ): Promise<{ output?: string; notice?: string }> {
166
- try {
167
- const proc = spawn(['sh', '-lc', command], {
168
- cwd,
169
- stderr: 'pipe',
170
- })
171
-
172
- const stdoutPromise = new Response(proc.stdout).text()
173
- let timedOut = false
174
- const timeout = setTimeout(() => {
175
- timedOut = true
176
- proc.kill()
177
- }, PREVIEW_COMMAND_TIMEOUT_MS)
178
-
179
- await proc.exited
180
- clearTimeout(timeout)
181
-
182
- if (timedOut) {
183
- return { notice: 'Preview command timed out; showing directory listing instead.' }
184
- }
185
-
186
- const output = await stdoutPromise
187
- if (proc.exitCode !== 0) {
188
- return { notice: 'Preview command failed; showing directory listing instead.' }
189
- }
190
-
191
- return { output }
192
- } catch {
193
- return { notice: 'Preview command failed; showing directory listing instead.' }
194
- }
195
- }
196
-
197
- export async function getProjectPreview(
198
- projectPath: string,
199
- config: Config,
200
- linkedWorkspace?: WorkspaceRef,
201
- loadWorkspaceDetails?: (workspace: WorkspaceRef) => Promise<WorkspaceDetails>
202
- ): Promise<ProjectPreview> {
203
- const cacheKey = `${projectPath}::${linkedWorkspace ? `${linkedWorkspace.backend}:${linkedWorkspace.id}` : ''}`
204
- const cached = projectPreviewCache.get(cacheKey)
205
- if (cached && cached.expiresAt > Date.now()) {
206
- return cached.preview
207
- }
208
-
209
- const [resolvedSession, gitRootPath, gitBranch, linkedSession] = await Promise.all([
210
- resolveProjectSession(projectPath, config),
211
- getGitRoot(projectPath),
212
- getGitBranch(projectPath),
213
- linkedWorkspace && loadWorkspaceDetails
214
- ? loadWorkspaceDetails(linkedWorkspace).catch(() => null)
215
- : Promise.resolve(null),
216
- ])
217
-
218
- const resolvedPreviewCommand = interpolatePreviewCommand(
219
- resolvedSession.previewCommand,
220
- projectPath
221
- )
222
- const commandResult = resolvedPreviewCommand
223
- ? await runPreviewCommand(resolvedPreviewCommand, projectPath)
224
- : undefined
225
- const formattedCommandOutput = commandResult?.output
226
- ? formatPreviewOutput(commandResult.output)
227
- : undefined
228
-
229
- if (formattedCommandOutput && formattedCommandOutput.lines.length > 0) {
230
- const preview: ProjectPreview = {
231
- path: toHomeRelativePath(projectPath),
232
- sessionName: resolvedSession.sessionName,
233
- source: resolvedSession.source,
234
- startupCommand: resolvedSession.startupCommand,
235
- previewCommand: resolvedPreviewCommand,
236
- gitRoot: gitRootPath ? toHomeRelativePath(gitRootPath) : undefined,
237
- gitBranch,
238
- linkedSession: linkedSession ?? undefined,
239
- previewKind: 'command',
240
- previewLabel: 'Preview Output',
241
- previewLines: formattedCommandOutput.lines,
242
- previewNotice: formattedCommandOutput.truncated
243
- ? 'Preview output truncated to fit the panel.'
244
- : undefined,
245
- }
246
-
247
- projectPreviewCache.set(cacheKey, {
248
- preview,
249
- expiresAt: Date.now() + PROJECT_PREVIEW_CACHE_TTL_MS,
250
- })
251
-
252
- return preview
253
- }
254
-
255
- const fallbackLines = await getDirectoryPreviewLines(projectPath)
256
- const formattedDirectoryOutput = formatPreviewOutput(fallbackLines.join('\n'))
257
-
258
- const preview: ProjectPreview = {
259
- path: toHomeRelativePath(projectPath),
260
- sessionName: resolvedSession.sessionName,
261
- source: resolvedSession.source,
262
- startupCommand: resolvedSession.startupCommand,
263
- previewCommand: resolvedPreviewCommand,
264
- gitRoot: gitRootPath ? toHomeRelativePath(gitRootPath) : undefined,
265
- gitBranch,
266
- linkedSession: linkedSession ?? undefined,
267
- previewKind: 'directory',
268
- previewLabel: 'Directory Listing',
269
- previewLines: formattedDirectoryOutput.lines,
270
- previewNotice:
271
- commandResult?.notice ??
272
- (formattedDirectoryOutput.truncated
273
- ? 'Directory listing truncated to fit the panel.'
274
- : undefined),
275
- }
276
-
277
- projectPreviewCache.set(cacheKey, {
278
- preview,
279
- expiresAt: Date.now() + PROJECT_PREVIEW_CACHE_TTL_MS,
280
- })
281
-
282
- return preview
283
- }
284
-
285
- const FILE_PREVIEW_MAX_BYTES = 16 * 1024
286
-
287
- async function getFilePreviewLines(
288
- filePath: string
289
- ): Promise<{ lines: string[]; notice?: string }> {
290
- try {
291
- const fileInfo = await stat(filePath)
292
- const bytes = new Uint8Array(
293
- await Bun.file(filePath).slice(0, FILE_PREVIEW_MAX_BYTES).arrayBuffer()
294
- )
295
-
296
- if (bytes.includes(0)) {
297
- return {
298
- lines: [`${basename(filePath)} (${fileInfo.size} bytes)`],
299
- notice: 'Binary file; preview skipped.',
300
- }
301
- }
302
-
303
- const formatted = formatPreviewOutput(new TextDecoder().decode(bytes))
304
- return {
305
- lines: formatted.lines.length > 0 ? formatted.lines : ['(empty file)'],
306
- notice:
307
- formatted.truncated || fileInfo.size > FILE_PREVIEW_MAX_BYTES
308
- ? 'File preview truncated to fit the panel.'
309
- : undefined,
310
- }
311
- } catch {
312
- return {
313
- lines: [basename(filePath)],
314
- notice: 'Unable to read file contents.',
315
- }
316
- }
317
- }
318
-
319
- export async function getFilePreview(
320
- filePath: string,
321
- config: Config,
322
- linkedWorkspace?: WorkspaceRef,
323
- loadWorkspaceDetails?: (workspace: WorkspaceRef) => Promise<WorkspaceDetails>
324
- ): Promise<ProjectPreview> {
325
- const cacheKey = `file::${filePath}::${linkedWorkspace ? `${linkedWorkspace.backend}:${linkedWorkspace.id}` : ''}`
326
- const cached = projectPreviewCache.get(cacheKey)
327
- if (cached && cached.expiresAt > Date.now()) {
328
- return cached.preview
329
- }
330
-
331
- const parentDirectory = dirname(filePath)
332
- const resolvedSession = resolveFileSession(filePath, config)
333
- const [gitRootPath, gitBranch, linkedSession, fileLines] = await Promise.all([
334
- getGitRoot(parentDirectory),
335
- getGitBranch(parentDirectory),
336
- linkedWorkspace && loadWorkspaceDetails
337
- ? loadWorkspaceDetails(linkedWorkspace).catch(() => null)
338
- : Promise.resolve(null),
339
- getFilePreviewLines(filePath),
340
- ])
341
-
342
- const preview: ProjectPreview = {
343
- path: toHomeRelativePath(filePath),
344
- sessionName: resolvedSession.sessionName,
345
- source: 'file',
346
- startupCommand: resolvedSession.startupCommand,
347
- gitRoot: gitRootPath ? toHomeRelativePath(gitRootPath) : undefined,
348
- gitBranch,
349
- linkedSession: linkedSession ?? undefined,
350
- previewKind: 'file',
351
- previewLabel: 'File Preview',
352
- previewLines: fileLines.lines,
353
- previewNotice: fileLines.notice,
354
- }
355
-
356
- projectPreviewCache.set(cacheKey, {
357
- preview,
358
- expiresAt: Date.now() + PROJECT_PREVIEW_CACHE_TTL_MS,
359
- })
360
-
361
- return preview
362
- }
@@ -1,52 +0,0 @@
1
- import { resolve } from 'path'
2
- import type { Config, Item } from '../types'
3
- import { isLiveSessionItem } from '../multiplexer/items'
4
- import { resolveProjectSession } from '../config/session-rules'
5
- import { buildFileSessionName, isFileItem, resolveFileSession } from '../files/target'
6
-
7
- export async function annotateProjectItemsWithSessionLinks(
8
- projectItems: Item[],
9
- liveSessions: Item[],
10
- config: Config
11
- ): Promise<Item[]> {
12
- return Promise.all(
13
- projectItems.map(async projectItem => {
14
- const sessionName = isFileItem(projectItem)
15
- ? buildFileSessionName(projectItem.path)
16
- : (await resolveProjectSession(projectItem.path, config)).sessionName
17
- const sessionPath = isFileItem(projectItem)
18
- ? resolveFileSession(projectItem.path, config).cwd
19
- : projectItem.path
20
- const liveItems = liveSessions.filter(session => session.isSession)
21
- const pathMatches = liveItems.filter(
22
- session =>
23
- session.title === sessionName &&
24
- session.path &&
25
- resolve(session.path) === resolve(sessionPath)
26
- )
27
- const titleMatches = liveItems.filter(session => session.title === sessionName)
28
- const linkedSession =
29
- pathMatches[0] ?? (titleMatches.length === 1 ? titleMatches[0] : undefined)
30
-
31
- if (!linkedSession) {
32
- return {
33
- ...projectItem,
34
- linkedSessionName: undefined,
35
- linkedSessionId: undefined,
36
- linkedSessionBackend: undefined,
37
- linkedSessionAttached: undefined,
38
- }
39
- }
40
-
41
- return {
42
- ...projectItem,
43
- linkedSessionName: linkedSession.title,
44
- linkedSessionId: isLiveSessionItem(linkedSession)
45
- ? linkedSession.sessionId
46
- : linkedSession.title,
47
- linkedSessionBackend: isLiveSessionItem(linkedSession) ? linkedSession.backend : 'tmux',
48
- linkedSessionAttached: linkedSession.isAttached,
49
- }
50
- })
51
- )
52
- }