diff --git a/src/cli.ts b/src/cli.ts index d3c5c450..f4222390 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -67,8 +67,9 @@ program .description('Interactive usage dashboard') .option('-p, --period ', 'Starting period: today, week, month, 30days', 'week') .option('--provider ', 'Filter by provider: all, claude, codex', 'all') + .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) .action(async (opts) => { - await renderDashboard(toPeriod(opts.period), opts.provider) + await renderDashboard(toPeriod(opts.period), opts.provider, opts.refresh) }) function buildPeriodData(label: string, projects: ProjectSummary[]): PeriodData { @@ -153,16 +154,18 @@ program .command('today') .description('Today\'s usage dashboard') .option('--provider ', 'Filter by provider: all, claude, codex', 'all') + .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) .action(async (opts) => { - await renderDashboard('today', opts.provider) + await renderDashboard('today', opts.provider, opts.refresh) }) program .command('month') .description('This month\'s usage dashboard') .option('--provider ', 'Filter by provider: all, claude, codex', 'all') + .option('--refresh ', 'Auto-refresh interval in seconds', parseInt) .action(async (opts) => { - await renderDashboard('month', opts.provider) + await renderDashboard('month', opts.provider, opts.refresh) }) program diff --git a/src/dashboard.tsx b/src/dashboard.tsx index 2130c0f0..04ed6221 100644 --- a/src/dashboard.tsx +++ b/src/dashboard.tsx @@ -194,18 +194,16 @@ const _homeEncoded = homedir().replace(/\//g, '-') function shortProject(encoded: string): string { let path = encoded.replace(/^-/, '') - // Strip home dir prefix (e.g. "Users-torukmakto-" → "") if (path.startsWith(_homeEncoded.replace(/^-/, ''))) { path = path.slice(_homeEncoded.replace(/^-/, '').length).replace(/^-/, '') } - // Strip common system prefixes path = path .replace(/^private-tmp-[^-]+-[^-]+-/, '') // /private/tmp/// .replace(/^private-tmp-/, '') .replace(/^tmp-/, '') - if (!path) return '~' + if (!path) return 'home' const parts = path.split('-').filter(Boolean) if (parts.length <= 3) return parts.join('/') @@ -485,10 +483,11 @@ function DashboardContent({ projects, period, columns }: { projects: ProjectSumm ) } -function InteractiveDashboard({ initialProjects, initialPeriod, initialProvider }: { +function InteractiveDashboard({ initialProjects, initialPeriod, initialProvider, refreshSeconds }: { initialProjects: ProjectSummary[] initialPeriod: Period initialProvider: string + refreshSeconds?: number }) { const { exit } = useApp() const [period, setPeriod] = useState(initialPeriod) @@ -528,6 +527,12 @@ function InteractiveDashboard({ initialProjects, initialPeriod, initialProvider setLoading(false) }, []) + useEffect(() => { + if (!refreshSeconds || refreshSeconds <= 0) return + const id = setInterval(() => { reloadData(period, activeProvider) }, refreshSeconds * 1000) + return () => clearInterval(id) + }, [refreshSeconds, period, activeProvider, reloadData]) + const switchPeriod = useCallback(async (newPeriod: Period) => { if (newPeriod === period) return setPeriod(newPeriod) @@ -592,7 +597,7 @@ function StaticDashboard({ projects, period }: { projects: ProjectSummary[]; per ) } -export async function renderDashboard(period: Period = 'week', provider: string = 'all'): Promise { +export async function renderDashboard(period: Period = 'week', provider: string = 'all', refreshSeconds?: number): Promise { await loadPricing() const range = getDateRange(period) const projects = await parseAllSessions(range, provider) @@ -601,7 +606,7 @@ export async function renderDashboard(period: Period = 'week', provider: string if (isTTY) { const { waitUntilExit } = render( - + ) await waitUntilExit() } else {