refactor: consolidate byte-size formatting#99768
Conversation
Dependency graph guard clearedThis PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh
|
|
Codex review: needs maintainer review before merge. Reviewed July 6, 2026, 11:59 AM ET / 15:59 UTC. Summary PR surface: Source +36, Tests +54, Generated 0, Other 0. Total +90 across 18 files. Reproducibility: not applicable. this is a refactor/API-surface PR, not a bug report. Source inspection compared the duplicated current-main formatting loops with the shared formatter options and added compatibility tests. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land the refactor after maintainer acceptance of the additive SDK export, preserving the compatibility tests and owner-specific display wrappers around the shared formatter. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a refactor/API-surface PR, not a bug report. Source inspection compared the duplicated current-main formatting loops with the shared formatter options and added compatibility tests. Is this the best way to solve the issue? Yes, with a product/API caveat: centralizing duplicated byte formatting in normalization-core while preserving caller-owned presentation policy is the maintainable shape. The remaining question is whether this should be public plugin SDK API now. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8547682dd6f3. Label changesLabel justifications:
Evidence reviewedPR surface: Source +36, Tests +54, Generated 0, Other 0. Total +90 across 18 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (7 earlier review cycles)
|
|
@clawsweeper re-review Exact head: The compact-node failure was branch-caused and is fixed by routing The dependency graph change remains intentional: agent-core directly imports the shared formatter, so the workspace dependency and lockfile importer change require fresh exact-head admin/secops authorization with |
|
🦞🧹 I asked ClawSweeper to review this item again. |
cc4d850 to
9ba62ad
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
9ba62ad to
1da8b97
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
8564529 to
63facf6
Compare
d86fd53 to
6d1b0e0
Compare
6d1b0e0 to
af74962
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
* 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
* 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
What Problem This Solves
OpenClaw had ten independent byte-size scaling and unit-selection implementations across core, Control UI, agent-core, QQBot, and file-transfer surfaces. Their binary thresholds, SI/IEC labels, precision, spacing, and rounding rules were implicit in local loops, making compatible output changes difficult to review and easy to drift.
Why This Change Was Made
This adds one dependency-free
normalization-coreformatter whose call sites explicitly selectsi,iec, orlegacy-binarystyle together with precision, spacing, maximum unit, and floor rounding where required. Owner wrappers retain invalid-input and presentation policy, plugin callers use the existingplugin-sdk/number-runtimeentrypoint, and the distinct rounded-MiB promotion contract insrc/infra/disk-space.tsremains local.The exact production TypeScript numstat is
+127/-83(net+44), calculated file-by-file with new files included and tests excluded. The positive LOC is intentional: ten separate scaling/unit-selection algorithms become one 45-line canonical implementation, while explicit style options preserve user-visible compatibility and prevent hidden SI/IEC label drift. Narrowing the migration would keep duplicate algorithms without removing the canonical owner.Maintained packages such as
pretty-bytesandfilesizewere considered, butnormalization-coreis intentionally dependency-free and these callers require exact legacy labels plus per-unit precision and rounding contracts.User Impact
No intended user-visible output changes. Existing byte labels, precision, spacing, unit caps, invalid-value fallbacks, and threshold behavior remain compatible. Plugin and core developers now have one focused formatter contract instead of copying another local loop.
Evidence
node scripts/run-vitest.mjs packages/normalization-core/src/format.test.ts src/commands/doctor-disk-space.test.ts packages/agent-core/src/harness/utils/truncate.test.ts ui/src/ui/views/agents-utils.test.ts ui/src/ui/controllers/skill-workshop.test.ts ui/src/ui/control-ui-vite-config.node.test.ts src/agents/tool-images.test.ts extensions/qqbot/src/engine/utils/file-utils.test.ts extensions/file-transfer/src/shared/params.test.ts— passed 7 Vitest shards.pnpm build— passed all phases, including tsdown, Plugin SDK export verification, and Control UI build.tbx_01kwq771m33edvath7eesca3tz, Actions run https://github.com/openclaw/openclaw/actions/runs/28716095276 — passed changed guards, full tsgo typecheck, core/extension/script lint, runtime import-cycle check, and full build; wrapperexitCode=0..agents/skills/autoreview/scripts/autoreview --mode local --prompt-file /tmp/byte-format-autoreview-context.md --stream-engine-output— clean, no accepted/actionable findings; patch rated correct with 0.94 confidence.