"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import { Button } from "@kandev/ui/button"; import { Spinner } from "@kandev/ui/spinner"; import { Badge } from "@kandev/ui/badge"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kandev/ui/table"; import { IconDatabase, IconRefresh, IconAlertTriangle, IconFolderOpen } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { useDiskUsage } from "@/hooks/domains/system/use-disk-usage"; import { openDataFolder } from "@/lib/api/domains/system-api"; import { useActionFeedback } from "@/hooks/use-action-feedback"; import type { DiskBreakdown } from "@/lib/types/system"; import { formatBytes } from "@/lib/utils/format-bytes"; import { ActionButtonContent } from "./action-button-content"; import { JobProgressIndicator } from "./job-progress-indicator"; const REFRESH_HELP = "Walks every directory inside the data folder and adds up the file sizes. Results are cached for a couple of hours; click to compute fresh numbers right now. Can take a few seconds on large workspaces."; type Row = { key: keyof Omit; label: string; }; const ROWS: Row[] = [ { key: "data_dir", label: "Data directory" }, { key: "worktrees", label: "Worktrees" }, { key: "repos", label: "Repositories" }, { key: "sessions", label: "Sessions" }, { key: "tasks", label: "Tasks" }, { key: "quick_chat", label: "Quick chat" }, { key: "backups", label: "Backups" }, ]; function formatComputedAt(iso: string): string { const parsed = new Date(iso); if (Number.isNaN(parsed.getTime())) return iso; return parsed.toLocaleString(); } function HomeDirRow({ homeDir }: { homeDir: string }) { return (

Data directory

{homeDir}

); } function WarningsBlock({ warnings }: { warnings: string[] }) { if (warnings.length === 0) return null; return (
Some directories could not be measured:
    {warnings.map((w, i) => (
  • {w}
  • ))}
); } function BreakdownTable({ data }: { data: DiskBreakdown }) { return ( Path Size {ROWS.map((row) => ( {row.label} {formatBytes(data[row.key])} ))} Total {formatBytes(data.total)}
); } export function DiskUsageCard() { const { diskUsage, isLoading, error, refresh } = useDiskUsage(); const refreshFeedback = useActionFeedback(); const data = diskUsage?.data ?? null; const computing = diskUsage?.computing ?? false; const homeDir = diskUsage?.home_dir ?? ""; const onRefresh = () => void refreshFeedback.run(async () => { await refresh(); }); return ( Disk Usage {computing && data && ( Refreshing... )}
{REFRESH_HELP}
{homeDir && } {error && (

{error}

)} {!data && (
Calculating...
)} {data && (

Computed at {formatComputedAt(data.computed_at)}

)}
); }