Skip to content

[Repo Assist] refactor: extract ModelFormatting helper; deduplicate FormatTokenCount/FormatCount#111

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-dedupe-format-helpers-20260327-d953f122a6255fb7
Draft

[Repo Assist] refactor: extract ModelFormatting helper; deduplicate FormatTokenCount/FormatCount#111
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-dedupe-format-helpers-20260327-d953f122a6255fb7

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated draft PR from Repo Assist.

Summary

FormatTokenCount (in SessionInfo) and FormatCount (in GatewayUsageInfo) were byte-for-byte identical private static methods:

private static string FormatTokenCount(long n)  // SessionInfo
private static string FormatCount(long n)        // GatewayUsageInfo
{
    if (n >= 1_000_000) return $"{n / 1_000_000.0:F1}M";
    if (n >= 1_000) return $"{n / 1_000.0:F1}K";
    return n.ToString();
}
```

Both format a `long` with K/M suffix for compact display — a clear DRY violation that would require keeping two copies in sync if the format logic ever changed.

## Change

- Removed both duplicated private methods
- Added a new `internal static class ModelFormatting` (file-scoped, at the bottom of `Models.cs`) with a single `FormatLargeNumber(long n)` method
- Updated both callsites to use `ModelFormatting.FormatLargeNumber(...)`

No behaviour change — output is identical.

## Why this placement?

`ModelFormatting` lives at the bottom of `Models.cs` (file-scoped) so it stays co-located with the model types that use it, without introducing a new file for a 6-line helper. It's `internal` so it's available to the test project if anyone wants to add unit tests for the formatting logic.

## Test Status

503 tests pass, 18 skipped (infrastructure) — same as baseline.

```
Passed!  - Failed: 0, Passed: 503, Skipped: 18, Total: 521

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

…t/FormatCount

FormatTokenCount (in SessionInfo) and FormatCount (in GatewayUsageInfo) were
identical private static methods — a clear DRY violation. Both formatted a
long with K/M suffix for compact display.

Extract to a new file-scoped internal static class ModelFormatting with a
single FormatLargeNumber method, and update both callsites to use it.

No behaviour change. 503 tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants