mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-05-16 19:44:14 +00:00
shortProject: cache homedir, normalize Windows backslashes, fix stale test helper
This commit is contained in:
parent
872f635a0d
commit
eca60a38ee
2 changed files with 8 additions and 6 deletions
|
|
@ -247,13 +247,15 @@ function DailyActivity({ projects, days = 14, pw, bw }: { projects: ProjectSumma
|
|||
)
|
||||
}
|
||||
|
||||
const _home = homedir()
|
||||
const _homePrefix = _home.endsWith('/') ? _home : _home + '/'
|
||||
|
||||
export function shortProject(absPath: string): string {
|
||||
const home = homedir()
|
||||
const homePrefix = home.endsWith('/') ? home : home + '/'
|
||||
const normalized = absPath.replace(/\\/g, '/')
|
||||
let path: string
|
||||
if (absPath === home) path = ''
|
||||
else if (absPath.startsWith(homePrefix)) path = absPath.slice(homePrefix.length)
|
||||
else path = absPath
|
||||
if (normalized === _home) path = ''
|
||||
else if (normalized.startsWith(_homePrefix)) path = normalized.slice(_homePrefix.length)
|
||||
else path = normalized
|
||||
path = path.replace(/^\/+/, '')
|
||||
path = path.replace(/^private\/tmp\/[^/]+\/[^/]+\//, '').replace(/^private\/tmp\//, '').replace(/^tmp\//, '')
|
||||
if (!path) return 'home'
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function makeProject(name: string, sessions: SessionSummary[]): ProjectSummary {
|
|||
|
||||
// Logic replicated from TopSessions component
|
||||
function getTopSessions(projects: ProjectSummary[], n = 5) {
|
||||
const all = projects.flatMap(p => p.sessions.map(s => ({ ...s, projectName: p.project })))
|
||||
const all = projects.flatMap(p => p.sessions.map(s => ({ ...s, projectPath: p.projectPath })))
|
||||
return [...all].sort((a, b) => b.totalCostUSD - a.totalCostUSD).slice(0, n)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue