mux-sesh 1.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/LICENSE +21 -0
- package/README.md +224 -0
- package/config.example.json +7 -0
- package/package.json +60 -0
- package/src/app.tsx +416 -0
- package/src/components/KeybindHelp.tsx +222 -0
- package/src/config/index.ts +52 -0
- package/src/handlers/actions.ts +86 -0
- package/src/handlers/keyboard.ts +431 -0
- package/src/index.tsx +9 -0
- package/src/opencode/constants.ts +5 -0
- package/src/opencode/index.ts +19 -0
- package/src/opencode/parser.ts +54 -0
- package/src/opencode/session.ts +278 -0
- package/src/opencode/stats.ts +34 -0
- package/src/opencode/tokens.ts +143 -0
- package/src/opencode/types.ts +33 -0
- package/src/search/index.ts +148 -0
- package/src/styles/theme.ts +46 -0
- package/src/tmux/index.ts +187 -0
- package/src/tmux/projects.ts +55 -0
- package/src/types/index.ts +80 -0
- package/src/ui/HighlightedText.tsx +61 -0
- package/src/ui/ItemList.tsx +93 -0
- package/src/ui/OpencodeSessionGroup.tsx +63 -0
- package/src/ui/OpencodeStatsPanel.tsx +178 -0
- package/src/ui/SearchInput.tsx +42 -0
- package/src/ui/SessionDetailsPanel.tsx +94 -0
- package/src/ui/SessionList.tsx +57 -0
- package/src/ui/SessionStats.tsx +30 -0
- package/src/util/github.ts +55 -0
- package/src/util/time.ts +48 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { getGlobalOpencodeStats, formatSessionAge } from '../opencode'
|
|
3
|
+
import type { OpencodeStats } from '../opencode'
|
|
4
|
+
import { colors, detailPanelStyle } from '../styles/theme'
|
|
5
|
+
import type { Item } from '../types'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
selectedItem?: Item
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function OpencodeStatsPanel({ selectedItem }: Props) {
|
|
12
|
+
const [globalStats, setGlobalStats] = useState<OpencodeStats | null>(null)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
getGlobalOpencodeStats().then(setGlobalStats)
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
const sessionStats = selectedItem?.opencodeStats
|
|
19
|
+
|
|
20
|
+
const formatNumber = (num: number): string => {
|
|
21
|
+
return num.toLocaleString()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const lastMessageTokens = sessionStats?.lastMessageTokens || 0
|
|
25
|
+
const contextLimit = sessionStats?.contextLimit || 200000
|
|
26
|
+
const contextPercentage =
|
|
27
|
+
lastMessageTokens > 0 && contextLimit > 0
|
|
28
|
+
? Math.round((lastMessageTokens / contextLimit) * 100)
|
|
29
|
+
: 0
|
|
30
|
+
const sessionCost = sessionStats?.sessionTotalCost || 0
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<box style={detailPanelStyle}>
|
|
34
|
+
{/* Header */}
|
|
35
|
+
<box style={{ alignItems: 'center', justifyContent: 'center', marginBottom: 2 }}>
|
|
36
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}> OpenCode Stats</text>
|
|
37
|
+
</box>
|
|
38
|
+
|
|
39
|
+
<box style={{ flexDirection: 'row', marginBottom: 2 }}>
|
|
40
|
+
{/* Current Session Column */}
|
|
41
|
+
{sessionStats ? (
|
|
42
|
+
sessionStats.lastMessageTokens !== undefined ? (
|
|
43
|
+
<box style={{ flexDirection: 'column', marginLeft: 2, width: '50%' }}>
|
|
44
|
+
<text style={{ fg: colors.key, marginBottom: 1 }}>Current Session</text>
|
|
45
|
+
<text>
|
|
46
|
+
Messages:{' '}
|
|
47
|
+
<span style={{ fg: colors.active }}>{sessionStats.messageCount || 0}</span>
|
|
48
|
+
</text>
|
|
49
|
+
<text>
|
|
50
|
+
Cost: <span style={{ fg: colors.action }}>${sessionCost.toFixed(2)}</span>
|
|
51
|
+
</text>
|
|
52
|
+
<text style={{ marginTop: 1 }}>
|
|
53
|
+
Context: <span style={{ fg: colors.text }}>{formatNumber(lastMessageTokens)}</span>
|
|
54
|
+
<span style={{ fg: colors.action }}>/{contextPercentage}%</span>
|
|
55
|
+
</text>
|
|
56
|
+
</box>
|
|
57
|
+
) : (
|
|
58
|
+
<box style={{ flexDirection: 'column', marginLeft: 2, width: '50%' }}>
|
|
59
|
+
<text style={{ fg: colors.inactive }}>Loading stats...</text>
|
|
60
|
+
</box>
|
|
61
|
+
)
|
|
62
|
+
) : (
|
|
63
|
+
<box style={{ flexDirection: 'column', marginLeft: 2, width: '50%' }}>
|
|
64
|
+
<text style={{ fg: colors.inactive }}>Loading stats...</text>
|
|
65
|
+
</box>
|
|
66
|
+
)}
|
|
67
|
+
|
|
68
|
+
{/* Global Overview Column */}
|
|
69
|
+
{globalStats && (
|
|
70
|
+
<box style={{ flexDirection: 'column', marginLeft: 2 }}>
|
|
71
|
+
<text style={{ fg: colors.key, marginBottom: 1 }}>Global Overview</text>
|
|
72
|
+
<text>
|
|
73
|
+
Sessions: <span style={{ fg: colors.active }}>{globalStats.totalSessions || 0}</span>
|
|
74
|
+
</text>
|
|
75
|
+
<text>
|
|
76
|
+
Messages: <span style={{ fg: colors.active }}>{globalStats.totalMessages || 0}</span>
|
|
77
|
+
</text>
|
|
78
|
+
<text>
|
|
79
|
+
Total Cost:{' '}
|
|
80
|
+
<span style={{ fg: colors.action }}>{globalStats.totalCost || '$0.00'}</span>
|
|
81
|
+
</text>
|
|
82
|
+
<text>
|
|
83
|
+
Cost/Day: <span style={{ fg: colors.text }}>{globalStats.costPerDay || '$0.00'}</span>
|
|
84
|
+
</text>
|
|
85
|
+
|
|
86
|
+
<text style={{ fg: colors.key, marginTop: 1, marginBottom: 1 }}>Token Usage</text>
|
|
87
|
+
<text>
|
|
88
|
+
Input: <span style={{ fg: colors.text }}>{globalStats.inputTokens || '0'}</span>
|
|
89
|
+
</text>
|
|
90
|
+
<text>
|
|
91
|
+
Output: <span style={{ fg: colors.text }}>{globalStats.outputTokens || '0'}</span>
|
|
92
|
+
</text>
|
|
93
|
+
<text>
|
|
94
|
+
Cache Read:{' '}
|
|
95
|
+
<span style={{ fg: colors.inactive }}>{globalStats.cacheRead || '0'}</span>
|
|
96
|
+
</text>
|
|
97
|
+
<text>
|
|
98
|
+
Cache Write:{' '}
|
|
99
|
+
<span style={{ fg: colors.inactive }}>{globalStats.cacheWrite || '0'}</span>
|
|
100
|
+
</text>
|
|
101
|
+
</box>
|
|
102
|
+
)}
|
|
103
|
+
</box>
|
|
104
|
+
|
|
105
|
+
{/* Selected Session Stats */}
|
|
106
|
+
{sessionStats && (
|
|
107
|
+
<>
|
|
108
|
+
<box style={{ alignItems: 'center', justifyContent: 'center', marginTop: 1 }}>
|
|
109
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}> Session Details</text>
|
|
110
|
+
</box>
|
|
111
|
+
|
|
112
|
+
<box style={{ flexDirection: 'column', marginLeft: 2 }}>
|
|
113
|
+
{sessionStats.title && (
|
|
114
|
+
<text style={{ marginBottom: 1 }}>
|
|
115
|
+
<span style={{ fg: colors.key }}>Title:</span> {sessionStats.title}
|
|
116
|
+
</text>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
{sessionStats.directory && (
|
|
120
|
+
<text style={{ marginBottom: 1, fg: colors.fileTree }}>{sessionStats.directory}</text>
|
|
121
|
+
)}
|
|
122
|
+
|
|
123
|
+
{/* Show session count for aggregated stats */}
|
|
124
|
+
{sessionStats.sessionCount !== undefined && (
|
|
125
|
+
<text>
|
|
126
|
+
Sessions: <span style={{ fg: colors.active }}>{sessionStats.sessionCount}</span>
|
|
127
|
+
</text>
|
|
128
|
+
)}
|
|
129
|
+
|
|
130
|
+
{sessionStats.messageCount !== undefined && (
|
|
131
|
+
<text>
|
|
132
|
+
Messages: <span style={{ fg: colors.active }}>{sessionStats.messageCount}</span>
|
|
133
|
+
</text>
|
|
134
|
+
)}
|
|
135
|
+
|
|
136
|
+
{sessionStats.filesModified !== undefined && sessionStats.filesModified > 0 && (
|
|
137
|
+
<text>
|
|
138
|
+
Files Modified:{' '}
|
|
139
|
+
<span style={{ fg: colors.action }}>{sessionStats.filesModified}</span>
|
|
140
|
+
</text>
|
|
141
|
+
)}
|
|
142
|
+
|
|
143
|
+
{/* Show most recent session title for aggregated stats */}
|
|
144
|
+
{sessionStats.mostRecentTitle && (
|
|
145
|
+
<text style={{ marginTop: 1 }}>
|
|
146
|
+
<span style={{ fg: colors.key }}>Most Recent:</span> {sessionStats.mostRecentTitle}
|
|
147
|
+
</text>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{sessionStats.createdAt && (
|
|
151
|
+
<text style={{ marginTop: 1 }}>
|
|
152
|
+
Created:{' '}
|
|
153
|
+
<span style={{ fg: colors.inactive }}>
|
|
154
|
+
{formatSessionAge(sessionStats.createdAt)}
|
|
155
|
+
</span>
|
|
156
|
+
</text>
|
|
157
|
+
)}
|
|
158
|
+
|
|
159
|
+
{sessionStats.updatedAt && (
|
|
160
|
+
<text>
|
|
161
|
+
Updated:{' '}
|
|
162
|
+
<span style={{ fg: colors.inactive }}>
|
|
163
|
+
{formatSessionAge(sessionStats.updatedAt)}
|
|
164
|
+
</span>
|
|
165
|
+
</text>
|
|
166
|
+
)}
|
|
167
|
+
</box>
|
|
168
|
+
</>
|
|
169
|
+
)}
|
|
170
|
+
|
|
171
|
+
{!sessionStats && (
|
|
172
|
+
<box style={{ marginTop: 2, marginLeft: 2 }}>
|
|
173
|
+
<text style={{ fg: colors.inactive }}>No session data found</text>
|
|
174
|
+
</box>
|
|
175
|
+
)}
|
|
176
|
+
</box>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AppMode } from '../types'
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
appMode: AppMode
|
|
5
|
+
searchQuery: string
|
|
6
|
+
textareaRef: any
|
|
7
|
+
onContentChange: () => void
|
|
8
|
+
prefixActive?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function SearchInput({
|
|
12
|
+
appMode,
|
|
13
|
+
searchQuery,
|
|
14
|
+
textareaRef,
|
|
15
|
+
onContentChange,
|
|
16
|
+
prefixActive = false,
|
|
17
|
+
}: Props) {
|
|
18
|
+
const placeholder =
|
|
19
|
+
appMode === AppMode.NewSession
|
|
20
|
+
? 'Type project name, GitHub URL, or custom session name...'
|
|
21
|
+
: appMode === AppMode.Rename
|
|
22
|
+
? 'Enter new session name...'
|
|
23
|
+
: 'Type to search...'
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<box
|
|
27
|
+
style={{
|
|
28
|
+
marginBottom: 1,
|
|
29
|
+
height: 3,
|
|
30
|
+
backgroundColor: prefixActive ? '#3a3d5c' : 'transparent',
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<textarea
|
|
34
|
+
ref={textareaRef}
|
|
35
|
+
placeholder={placeholder}
|
|
36
|
+
initialValue={searchQuery}
|
|
37
|
+
onContentChange={onContentChange}
|
|
38
|
+
focused={!prefixActive}
|
|
39
|
+
/>
|
|
40
|
+
</box>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { getSessionDetails } from '../tmux'
|
|
3
|
+
import { colors, detailPanelStyle } from '../styles/theme'
|
|
4
|
+
import type { Item, SessionDetails } from '../types'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
selectedItem?: Item
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function SessionDetailsPanel({ selectedItem }: Props) {
|
|
11
|
+
const [details, setDetails] = useState<SessionDetails | null>(null)
|
|
12
|
+
const [loading, setLoading] = useState(false)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (selectedItem?.isSession) {
|
|
16
|
+
setLoading(true)
|
|
17
|
+
getSessionDetails(selectedItem.title)
|
|
18
|
+
.then(setDetails)
|
|
19
|
+
.catch(() => setDetails(null))
|
|
20
|
+
.finally(() => setLoading(false))
|
|
21
|
+
} else {
|
|
22
|
+
setDetails(null)
|
|
23
|
+
}
|
|
24
|
+
}, [selectedItem])
|
|
25
|
+
|
|
26
|
+
if (!selectedItem?.isSession) {
|
|
27
|
+
return (
|
|
28
|
+
<box style={detailPanelStyle}>
|
|
29
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>Details</text>
|
|
30
|
+
<text style={{ fg: colors.inactive }}>No session selected</text>
|
|
31
|
+
</box>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (loading) {
|
|
36
|
+
return (
|
|
37
|
+
<box style={detailPanelStyle}>
|
|
38
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{selectedItem.title}</text>
|
|
39
|
+
<text style={{ fg: colors.inactive }}>Loading...</text>
|
|
40
|
+
</box>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!details) {
|
|
45
|
+
return (
|
|
46
|
+
<box style={detailPanelStyle}>
|
|
47
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{selectedItem.title}</text>
|
|
48
|
+
<text style={{ fg: colors.inactive }}>Unable to load session details</text>
|
|
49
|
+
</box>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<box style={detailPanelStyle}>
|
|
55
|
+
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
56
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{details.name}</text>
|
|
57
|
+
</box>
|
|
58
|
+
|
|
59
|
+
<box style={{ flexDirection: 'column', marginBottom: 1, marginLeft: 2 }}>
|
|
60
|
+
<text>
|
|
61
|
+
Status:{' '}
|
|
62
|
+
<span style={{ fg: details.isAttached ? colors.active : colors.inactive }}>
|
|
63
|
+
{details.isAttached ? '● Active' : '○ Inactive'}
|
|
64
|
+
</span>
|
|
65
|
+
</text>
|
|
66
|
+
<text>Windows: {details.windowCount}</text>
|
|
67
|
+
</box>
|
|
68
|
+
|
|
69
|
+
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
70
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}> Windows</text>
|
|
71
|
+
</box>
|
|
72
|
+
|
|
73
|
+
<box style={{ flexDirection: 'column', marginLeft: 2 }}>
|
|
74
|
+
{details.windows.length === 0 ? (
|
|
75
|
+
<text style={{ fg: colors.inactive }}>No windows found</text>
|
|
76
|
+
) : (
|
|
77
|
+
details.windows.map((win, i) => (
|
|
78
|
+
<box key={i} style={{ flexDirection: 'column', marginBottom: 1 }}>
|
|
79
|
+
<text>
|
|
80
|
+
{win.index}: {win.name}
|
|
81
|
+
</text>
|
|
82
|
+
{win.currentCommand && (
|
|
83
|
+
<text style={{ fg: colors.program, marginLeft: 2 }}> {win.currentCommand}</text>
|
|
84
|
+
)}
|
|
85
|
+
{win.currentPath && (
|
|
86
|
+
<text style={{ fg: colors.fileTree, marginLeft: 2 }}> {win.currentPath}</text>
|
|
87
|
+
)}
|
|
88
|
+
</box>
|
|
89
|
+
))
|
|
90
|
+
)}
|
|
91
|
+
</box>
|
|
92
|
+
</box>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { colors } from '../styles/theme'
|
|
2
|
+
import { formatSessionAge } from '../util/time'
|
|
3
|
+
import HighlightedText from './HighlightedText'
|
|
4
|
+
import type { Item } from '../types'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
items: Item[]
|
|
8
|
+
cursor: number
|
|
9
|
+
maxItems?: number
|
|
10
|
+
searchQuery?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function SessionList({ items, cursor, maxItems = 20, searchQuery = '' }: Props) {
|
|
14
|
+
const isSearching = searchQuery.trim().length > 0
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{items.slice(0, maxItems).map((item, i) => {
|
|
19
|
+
const matchIndices = (item as any).titleMatchIndices as number[] | undefined
|
|
20
|
+
const titlePadded = item.title.padEnd(20)
|
|
21
|
+
const sessionAge = item.createdAt ? formatSessionAge(item.createdAt) : ''
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<box
|
|
25
|
+
key={i}
|
|
26
|
+
style={{
|
|
27
|
+
backgroundColor: i === cursor ? colors.backgroundAlt : 'transparent',
|
|
28
|
+
height: 1,
|
|
29
|
+
paddingLeft: 2,
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
{i === cursor && <text> </text>}
|
|
33
|
+
<text>
|
|
34
|
+
{i + 1}{' '}
|
|
35
|
+
<span
|
|
36
|
+
style={{
|
|
37
|
+
fg: item.isAttached ? colors.active : colors.inactive,
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
{item.isAttached ? '●' : '○'}
|
|
41
|
+
</span>{' '}
|
|
42
|
+
{isSearching && matchIndices && matchIndices.length > 0 ? (
|
|
43
|
+
<>
|
|
44
|
+
<HighlightedText text={item.title} matchIndices={matchIndices} />
|
|
45
|
+
{' '.repeat(20 - item.title.length)}
|
|
46
|
+
</>
|
|
47
|
+
) : (
|
|
48
|
+
titlePadded
|
|
49
|
+
)}{' '}
|
|
50
|
+
<span style={{ fg: colors.inactive }}>{sessionAge}</span>
|
|
51
|
+
</text>
|
|
52
|
+
</box>
|
|
53
|
+
)
|
|
54
|
+
})}
|
|
55
|
+
</>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { colors } from '../styles/theme'
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
totalSessions: number
|
|
5
|
+
activeSessions: number
|
|
6
|
+
idleSessions: number
|
|
7
|
+
oldestSession: string
|
|
8
|
+
newestSession: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function SessionStats({
|
|
12
|
+
totalSessions,
|
|
13
|
+
activeSessions,
|
|
14
|
+
idleSessions,
|
|
15
|
+
oldestSession,
|
|
16
|
+
newestSession,
|
|
17
|
+
}: Props) {
|
|
18
|
+
if (totalSessions === 0) return null
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<text style={{ marginTop: 2, fg: colors.text }}>
|
|
23
|
+
Sessions: {totalSessions} ({activeSessions} active, {idleSessions} idle)
|
|
24
|
+
</text>
|
|
25
|
+
<text style={{ fg: colors.text }}>
|
|
26
|
+
Oldest: {oldestSession} Newest: {newestSession}
|
|
27
|
+
</text>
|
|
28
|
+
</>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { spawn } from 'bun'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { mkdir, stat } from 'fs/promises'
|
|
4
|
+
import type { Config } from '../types'
|
|
5
|
+
|
|
6
|
+
export function isGitHubURL(input: string): boolean {
|
|
7
|
+
const trimmed = input.trim()
|
|
8
|
+
return trimmed.startsWith('https://github.com/') || trimmed.startsWith('git@github.com:')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function extractRepoName(url: string): string {
|
|
12
|
+
const trimmed = url.trim()
|
|
13
|
+
|
|
14
|
+
if (trimmed.startsWith('https://github.com/')) {
|
|
15
|
+
const path = trimmed.replace('https://github.com/', '').replace('.git', '')
|
|
16
|
+
const parts = path.split('/')
|
|
17
|
+
if (parts.length >= 2) {
|
|
18
|
+
return parts[1]
|
|
19
|
+
}
|
|
20
|
+
} else if (trimmed.startsWith('git@github.com:')) {
|
|
21
|
+
const path = trimmed.replace('git@github.com:', '').replace('.git', '')
|
|
22
|
+
const parts = path.split('/')
|
|
23
|
+
if (parts.length >= 2) {
|
|
24
|
+
return parts[1]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function cloneGitHubRepo(url: string, config: Config): Promise<string> {
|
|
32
|
+
const repoName = extractRepoName(url)
|
|
33
|
+
if (!repoName) {
|
|
34
|
+
throw new Error('Could not extract repository name from URL')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const reposDir = config.reposPath
|
|
38
|
+
await mkdir(reposDir, { recursive: true })
|
|
39
|
+
|
|
40
|
+
const targetDir = join(reposDir, repoName)
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await stat(targetDir)
|
|
44
|
+
return targetDir
|
|
45
|
+
} catch {}
|
|
46
|
+
|
|
47
|
+
const proc = spawn(['git', 'clone', url, targetDir])
|
|
48
|
+
await proc.exited
|
|
49
|
+
|
|
50
|
+
if (proc.exitCode !== 0) {
|
|
51
|
+
throw new Error('Failed to clone repository')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return targetDir
|
|
55
|
+
}
|
package/src/util/time.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function formatDuration(seconds: number): string {
|
|
2
|
+
if (seconds < 60) {
|
|
3
|
+
return 'just now'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const minutes = Math.floor(seconds / 60)
|
|
7
|
+
const hours = Math.floor(minutes / 60)
|
|
8
|
+
const days = Math.floor(hours / 24)
|
|
9
|
+
const weeks = Math.floor(days / 7)
|
|
10
|
+
|
|
11
|
+
if (weeks > 0) {
|
|
12
|
+
const remainingDays = days % 7
|
|
13
|
+
if (remainingDays > 0) {
|
|
14
|
+
return `${weeks}w ${remainingDays}d`
|
|
15
|
+
}
|
|
16
|
+
return `${weeks}w`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (days > 0) {
|
|
20
|
+
const remainingHours = hours % 24
|
|
21
|
+
if (remainingHours > 0) {
|
|
22
|
+
return `${days}d ${remainingHours}h`
|
|
23
|
+
}
|
|
24
|
+
return `${days}d`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (hours > 0) {
|
|
28
|
+
const remainingMinutes = minutes % 60
|
|
29
|
+
if (remainingMinutes > 0) {
|
|
30
|
+
return `${hours}h ${remainingMinutes}m`
|
|
31
|
+
}
|
|
32
|
+
return `${hours}h`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return `${minutes}m`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function formatSessionAge(createdTimestamp: number): string {
|
|
39
|
+
const now = Math.floor(Date.now() / 1000)
|
|
40
|
+
const age = now - createdTimestamp
|
|
41
|
+
return formatDuration(age)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function formatLastActivity(activityTimestamp: number): string {
|
|
45
|
+
const now = Math.floor(Date.now() / 1000)
|
|
46
|
+
const timeSince = now - activityTimestamp
|
|
47
|
+
return formatDuration(timeSince)
|
|
48
|
+
}
|