Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/commands/cli/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { getVersionCheckInfo } from "../../lib/db/version-check.js";
import { UpgradeError } from "../../lib/errors.js";
import { formatUpgradeResult } from "../../lib/formatters/human.js";
import { formatBytes } from "../../lib/formatters/numbers.js";
import { CommandOutput } from "../../lib/formatters/output.js";
import { logger } from "../../lib/logger.js";
import { withProgress } from "../../lib/polling.js";
Expand Down Expand Up @@ -541,8 +542,9 @@ async function executeStandardUpgrade(opts: {
);

if (downloadResult?.patchBytes) {
const kb = (downloadResult.patchBytes / 1024).toFixed(1);
log.info(`Applied delta patch (${kb} KB downloaded)`);
log.info(
`Applied delta patch (${formatBytes(downloadResult.patchBytes)} downloaded)`
);
}

// Run setup on the new binary to update completions, agent skills,
Expand Down Expand Up @@ -611,8 +613,9 @@ async function migrateToStandaloneForNightly(
);

if (downloadResult?.patchBytes) {
const kb = (downloadResult.patchBytes / 1024).toFixed(1);
log.info(`Applied delta patch (${kb} KB downloaded)`);
log.info(
`Applied delta patch (${formatBytes(downloadResult.patchBytes)} downloaded)`
);
}

if (!downloadResult) {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/delta-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "./binary.js";
import { applyPatch } from "./bspatch.js";
import { CLI_VERSION } from "./constants.js";
import { formatBytes } from "./formatters/numbers.js";
import {
downloadLayerBlob,
fetchManifest,
Expand Down Expand Up @@ -1017,7 +1018,7 @@ async function resolveAndApplyDelta(
if (cached) {
Sentry.getActiveSpan()?.setAttribute("delta.source", "cache");
log.debug(
`Using cached patches: ${cached.patches.length} patch(es), ${cached.totalSize} bytes total`
`Using cached patches: ${cached.patches.length} patch(es), ${formatBytes(cached.totalSize)} total`
);
return await applyChainAndReturn(cached, oldBinaryPath, destPath);
}
Expand All @@ -1034,7 +1035,7 @@ async function resolveAndApplyDelta(
const chain = await resolveFromNetwork();
if (chain) {
log.debug(
`Resolved ${channel} chain: ${chain.patches.length} patch(es), ${chain.totalSize} bytes total`
`Resolved ${channel} chain: ${chain.patches.length} patch(es), ${formatBytes(chain.totalSize)} total`
);
}
if (!chain) {
Expand Down
27 changes: 27 additions & 0 deletions src/lib/formatters/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ export function formatCompactWithUnit(
return appendUnitSuffix(compactFormatter.format(Math.round(value)), unit);
}

/**
* Format a byte count as a human-readable string with binary units.
*
* Uses 1024-based conversion with one fractional digit. Values below 1 KB
* are shown as whole bytes. Unlike {@link formatCompactWithUnit} with
* `"byte"`, this avoids the "BB" collision where `Intl.NumberFormat`
* compact notation uses "B" for billions and `appendUnitSuffix` adds
* another "B" for bytes.
*
* @example formatBytes(512) // "512 B"
* @example formatBytes(3435689) // "3.3 MB"
* @example formatBytes(106989888) // "102.0 MB"
* @example formatBytes(1073741824) // "1.0 GB"
*/
export function formatBytes(bytes: number): string {
if (bytes < 1024) {
return `${bytes} B`;
}
if (bytes < 1024 * 1024) {
return `${(bytes / 1024).toFixed(1)} KB`;
}
if (bytes < 1024 * 1024 * 1024) {
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
}

/**
* Format a percentage value with one decimal place, or "—" when absent.
*
Expand Down
3 changes: 2 additions & 1 deletion src/lib/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getInstallInfo, setInstallInfo } from "./db/install-info.js";
import type { ReleaseChannel } from "./db/release-channel.js";
import { attemptDeltaUpgrade, type DeltaResult } from "./delta-upgrade.js";
import { AbortError, UpgradeError } from "./errors.js";
import { formatBytes } from "./formatters/numbers.js";
import {
downloadNightlyBlob,
fetchManifest,
Expand Down Expand Up @@ -804,7 +805,7 @@ export async function downloadBinaryToTemp(
// exponential backoff so a transient filesystem-visibility race
// self-heals without asking the user to rerun.
const verifiedSize = await waitForBinaryVisible(tempPath);
log.debug(`Downloaded binary verified (${verifiedSize} bytes)`);
log.debug(`Binary verified (${formatBytes(verifiedSize)})`);

// Clear consumed patch cache — patches for the old version are useless
// after the binary has been updated (whether via delta or full download).
Expand Down
Loading