refactor: consolidate byte-size formatting (#99768)

* refactor: consolidate byte-size formatting

* fix: stabilize byte formatter import boundary

* fix: keep byte formatter within SDK budget

* fix: emit byte formatter package entry

* refactor: trim byte formatter surface

* fix: use narrow byte formatter import

* refactor: remove byte formatter dependency changes

* fix: refresh rebased byte formatter baseline
This commit is contained in:
Dallin Romney
2026-07-06 09:26:04 -07:00
committed by GitHub
parent b29d472e41
commit 5af7ba92ce
18 changed files with 172 additions and 82 deletions

View File

@@ -1,4 +1,5 @@
// Commander registration for gateway status, health, diagnostics, discovery, and run commands.
import { formatByteSize } from "@openclaw/normalization-core";
import type { Command } from "commander";
import { formatDocsLink } from "../../../packages/terminal-core/src/links.js";
import { colorize, isRich, theme } from "../../../packages/terminal-core/src/theme.js";
@@ -232,15 +233,12 @@ function formatBytes(value: number | undefined): string {
if (value === undefined) {
return "n/a";
}
const units = ["B", "KiB", "MiB", "GiB"];
let amount = value;
let unitIndex = 0;
while (amount >= 1024 && unitIndex < units.length - 1) {
amount /= 1024;
unitIndex += 1;
}
const digits = unitIndex === 0 || amount >= 100 ? 0 : 1;
return `${amount.toFixed(digits)} ${units[unitIndex]}`;
return formatByteSize(value, {
style: "iec",
maxUnit: "giga",
separator: " ",
fractionDigits: (amount, unit) => (unit === "byte" || amount >= 100 ? 0 : 1),
});
}
function formatStabilityEvent(record: DiagnosticStabilityEventRecord): string {