Files
fusion/packages/dashboard/app/utils/formatBytes.ts
gsxdsm 4df5c62854 FN-8133: add local codebase context metrics
Expose local codebase token estimates and apparent disk size in the project dashboard.

- Add a bounded, cached, symlink-safe codebase metrics service and project API.
- Display token and disk indicators across Command Center overview states.
- Add formatting, route, UI, and metric calibration coverage with a minor changeset.

Files changed:
 .changeset/fn-8133-codebase-metrics.md             |   7 +
 docs/dashboard-guide.md                            |   2 +-
 .../dashboard/app/__tests__/api-projects.test.ts   |  12 ++
 packages/dashboard/app/api/legacy.ts               |  14 ++
 .../components/command-center/CommandCenter.css    |   5 +
 .../components/command-center/CommandCenter.tsx    |  65 +++++++--
 .../CommandCenter.mobile-chart-layout.test.ts      |   4 +
 .../__tests__/CommandCenter.test.tsx               |  10 ++
 .../__tests__/SystemStatsArea.test.tsx             |   8 +
 .../command-center/areas/SystemStatsArea.tsx       |   8 +-
 .../app/utils/__tests__/formatBytes.test.ts        |  18 +++
 packages/dashboard/app/utils/formatBytes.ts        |  11 ++
 .../src/lib/__tests__/codebase-metrics.test.ts     |  62 ++++++++
 .../lib/__tests__/fixtures/token-corpus/README.md  |  17 +++
 .../fixtures/token-corpus/calibration/component.ts |   1 +
 .../fixtures/token-corpus/calibration/config.json  |   1 +
 .../lib/__tests__/fixtures/token-corpus/example.ts |   1 +
 .../lib/__tests__/fixtures/token-corpus/notes.md   |   3 +
 .../fixtures/token-corpus/reference-counts.json    |   9 ++
 .../__tests__/fixtures/token-corpus/settings.json  |   1 +
 .../lib/__tests__/fixtures/token-corpus/view.tsx   |   1 +
 packages/dashboard/src/lib/codebase-metrics.ts     | 161 +++++++++++++++++++++
 .../__tests__/codebase-metrics-route.test.ts       |  34 +++++
 .../src/routes/register-project-routes.ts          |  19 +++
 24 files changed, 456 insertions(+), 18 deletions(-)

Fusion-Task-Id: FN-8133

Fusion-Task-Lineage: d591636b-d4b8-469e-8788-c4516eeb8405

Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
2026-07-16 14:08:43 -07:00

12 lines
664 B
TypeScript

/*
FNXC:CommandCenter 2026-07-16-10:00:
The shared byte formatter is deliberately granular (B/KB/MB/GB) because Project Disk size and System telemetry must not present a sub-megabyte value as 0 MB. Invalid and negative measurements remain unavailable rather than inventing a size.
*/
export function formatBytes(bytes: number): string {
if (!Number.isFinite(bytes) || bytes < 0) return "—";
if (bytes < 1024) return `${Math.round(bytes)} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(0)} MB`;
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
}