Skip to content

refactor: consolidate byte-size formatting#99768

Merged
RomneyDa merged 8 commits into
mainfrom
refactor/byte-format-consolidation
Jul 6, 2026
Merged

refactor: consolidate byte-size formatting#99768
RomneyDa merged 8 commits into
mainfrom
refactor/byte-format-consolidation

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member

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-core formatter whose call sites explicitly select si, iec, or legacy-binary style together with precision, spacing, maximum unit, and floor rounding where required. Owner wrappers retain invalid-input and presentation policy, plugin callers use the existing plugin-sdk/number-runtime entrypoint, and the distinct rounded-MiB promotion contract in src/infra/disk-space.ts remains 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-bytes and filesize were considered, but normalization-core is 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

  • Focused compatibility matrix: 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.
  • Published/lazy boundary build: pnpm build — passed all phases, including tsdown, Plugin SDK export verification, and Control UI build.
  • Final changed/build gate after rebase: Blacksmith Testbox 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; wrapper exitCode=0.
  • SDK contract checks: generated API baseline, synced exports, verified referenced subpaths, and checked docs formatting.
  • Structured closeout: .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.

@RomneyDa
RomneyDa requested a review from a team as a code owner July 4, 2026 02:24
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling channel: qqbot plugin: file-transfer labels Jul 4, 2026
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jul 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: af74962d21c08508673e246d9448a6c9af4c00d4

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 6, 2026, 11:59 AM ET / 15:59 UTC.

Summary
The PR adds a shared formatByteSize helper in normalization-core, exports it through plugin-sdk/number-runtime, migrates selected core, UI, QQBot, and file-transfer byte-size displays to it, and refreshes SDK surface budget/baseline files.

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.

  • Public plugin SDK export: 1 added, 0 removed. The new formatByteSize export is the main maintainer decision because it becomes plugin-facing API after release.

Stored data model
Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-disk-space.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🌊 off-meta tidepool
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Merging this PR accepts formatByteSize as a public plugin-sdk/number-runtime API; after release, the helper name and option shape become harder to change without a plugin compatibility plan.

Maintainer options:

  1. Accept the SDK contract before merge (recommended)
    Proceed once a maintainer confirms the public helper name and option shape are the intended plugin contract.
  2. Remove the public export first
    Keep the shared helper internal and migrate only core/bundled call sites until the SDK API is separately approved.
  3. Pause for API shape review
    Defer merge if maintainers want a narrower SDK subpath, SI style support, or a different rounding/precision contract.

Next step before merge

  • [P2] Human review is needed to accept or reject the additive public plugin SDK export; there is no narrow automated repair to queue.

Maintainer decision needed

  • Question: Should OpenClaw accept formatByteSize as a public plugin-sdk/number-runtime export with this option shape, or keep byte-size formatting internal for now?
  • Rationale: The code path looks sound, but public plugin SDK expansion is a stable contract decision that ClawSweeper should not make automatically.
  • Likely owner: steipete — steipete is assigned on the PR and has recent history owning the normalization-core extraction and plugin SDK boundary preservation work.
  • Options:
    • Accept SDK helper (recommended): Merge after maintainer review confirms this helper belongs in the public plugin SDK and required checks remain green.
    • Keep it internal: Remove the plugin SDK export and keep bundled-plugin callers on an internal/core-owned path until a public contract is explicitly designed.
    • Pause for API design: Hold the PR if maintainers want SI support, a narrower subpath, or a different option contract before release.

Security
Cleared: No concrete security or supply-chain concern was found; the current diff does not change package managers, lockfiles, workflows, dependency sources, lifecycle hooks, or downloaded artifacts.

Review details

Best 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 changes

Label justifications:

  • P2: This is a normal-priority refactor with compatibility-sensitive plugin SDK surface but no urgent user-facing regression.
  • merge-risk: 🚨 compatibility: The PR adds a public plugin SDK helper whose name and option shape would become a compatibility contract after release.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor real-behavior proof gate does not apply because this is a maintainer-associated PR; the PR body’s Testbox and focused test evidence remains useful supplemental validation.
Evidence reviewed

PR surface:

Source +36, Tests +54, Generated 0, Other 0. Total +90 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 12 113 77 +36
Tests 4 55 1 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 2 2 0
Other 1 2 2 0
Total 18 172 82 +90

What I checked:

Likely related people:

  • steipete: GitHub path history shows the normalization-core extraction and plugin SDK preservation work in commit 00d8d7e, and this PR is assigned to steipete for review. (role: SDK and normalization-core history owner; confidence: high; commits: 00d8d7ead059; files: packages/normalization-core/src/index.ts, src/plugin-sdk/number-runtime.ts)
  • RomneyDa: GitHub path history shows recent normalization-core consolidation work in commits cf14b27 and febc700, and this PR continues that same consolidation theme. (role: recent shared-normalization contributor; confidence: high; commits: cf14b27d81e6, febc70036f29; files: packages/normalization-core/src/index.ts)
  • vincentkoc: GitHub path history shows recent work on src/agents/tool-images.ts, one of the agent call sites migrated by this PR. (role: adjacent agent-runtime contributor; confidence: medium; commits: 80805ad7a583, 6b2af6c1ee01; files: src/agents/tool-images.ts)
  • shakkernerd: GitHub path history shows recent Control UI architecture work touching the display surface that this PR migrates. (role: recent UI area contributor; confidence: medium; commits: 65e12328aa20; files: ui/src/lib/agents/display.ts, ui/src/pages/skill-workshop/proposals.ts)
  • alkor2000: GitHub path history shows the disk-space doctor behavior and formatting contract were introduced in commit 9d97e68. (role: doctor disk-space feature introducer; confidence: medium; commits: 9d97e683d419; files: src/commands/doctor-disk-space.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (7 earlier review cycles)
  • reviewed 2026-07-04T04:02:20.132Z sha 1da8b97 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T19:02:11.973Z sha 06f0758 :: needs changes before merge. :: [P1] Preserve the current agent-core typebox version
  • reviewed 2026-07-04T19:07:52.417Z sha 06f0758 :: needs changes before merge. :: [P1] Preserve the current agent-core typebox version
  • reviewed 2026-07-04T20:07:49.660Z sha 8564529 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T20:15:22.483Z sha 8564529 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T23:53:26.375Z sha 63facf6 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T00:11:36.268Z sha 6d1b0e0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 4, 2026
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Exact head: cc4d850dada78a2c3c612b8aa462bac500ce02f8

The compact-node failure was branch-caused and is fixed by routing tool-images through the existing normalization-core root barrel, avoiding the duplicate subpath import while preserving formatter behavior and the explicit production TypeScript disclosure of +127/-83 (net +44). Focused proof passes 85 tests across formatter, tool-images, and secrets runtime coverage; pnpm build passes; fresh autoreview is clean with no actionable findings.

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 /allow-dependencies-change.

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/byte-format-consolidation branch from cc4d850 to 9ba62ad Compare July 4, 2026 02:57
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@RomneyDa
RomneyDa force-pushed the refactor/byte-format-consolidation branch from 9ba62ad to 1da8b97 Compare July 4, 2026 03:56
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/byte-format-consolidation branch from 8564529 to 63facf6 Compare July 4, 2026 23:47
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 4, 2026
@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Jul 4, 2026
@clawsweeper clawsweeper Bot removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 5, 2026
@RomneyDa
RomneyDa force-pushed the refactor/byte-format-consolidation branch from d86fd53 to 6d1b0e0 Compare July 5, 2026 00:04
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 5, 2026
@RomneyDa
RomneyDa force-pushed the refactor/byte-format-consolidation branch from 6d1b0e0 to af74962 Compare July 6, 2026 15:28
@RomneyDa

RomneyDa commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@RomneyDa
RomneyDa merged commit 5af7ba9 into main Jul 6, 2026
98 of 99 checks passed
@RomneyDa
RomneyDa deleted the refactor/byte-format-consolidation branch July 6, 2026 16:26
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
* 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
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: qqbot cli CLI command changes commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants