Skip to content

fix: correct context bomb zeros for lines and language counts#13

Merged
claude[bot] merged 1 commit intomainfrom
claude/issue-7-20260227-0009
Feb 27, 2026
Merged

fix: correct context bomb zeros for lines and language counts#13
claude[bot] merged 1 commit intomainfrom
claude/issue-7-20260227-0009

Conversation

@greynewell
Copy link
Contributor

@greynewell greynewell commented Feb 27, 2026

Remove Stats.TotalLines (not in API response), change Stats.Languages from map[string]int to []string, and change irSummary from a typed struct to map[string]any to avoid silent zero-fills if API field names change.

Closes #7

Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Restructured how language statistics are displayed and processed
    • Simplified codebase metrics presentation by removing total lines metric
    • Updated summary data handling to use a more flexible format for improved extensibility

- Remove Stats.TotalLines (not available in API response)
- Remove '· N lines' from the context bomb template
- Change Stats.Languages from map[string]int to []string since the
  API only returns language names, not per-language counts
- Change irSummary from a typed struct to map[string]any so that
  summary fields are read dynamically, avoiding silent zero-fills
  if API field names change
- Update languageList template func to accept []string and render
  plain names (e.g. 'go, json') instead of 'go (0), json (0)'

Fixes #7

Co-authored-by: Grey Newell <greynewell@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Walkthrough

The Summary field in SupermodelIR transforms from a structured type into a dynamic map[string]any, and irSummary type is removed. Stats.Languages changes from a count map to a simple string list. Template rendering logic updates to handle these structural shifts and removes the unavailable TotalLines field.

Changes

Cohort / File(s) Summary
Type Restructuring
internal/api/client.go
SupermodelIR.Summary refactored from irSummary struct to map[string]any for flexibility. irSummary type definition removed. Helper function added to extract integer values from Summary map (summaryInt). Stats.Languages type changed from map[string]int to []string, now sourced directly from Metadata.Languages. ProjectGraph population logic adjusted to read primaryLanguage and integer stats (filesProcessed, functions) from the dynamic Summary map with validation.
Template Updates
internal/template/render.go
languageList function refactored to accept []string and join directly, removing previous map iteration and count-formatting logic. TotalLines segment removed from Codebase context template (field not available in API response).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

💬 No more zeros lurking where the data should flow,
Summary opens wide, like a map we can know.
Languages list their names without phantom counts,
Template renders honest—let the truth come out!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: correcting context bomb output by fixing incorrect zeros for lines and language counts.
Linked Issues check ✅ Passed All coding objectives from issue #7 are met: removed TotalLines, changed Languages to []string, converted Summary to map[string]any, and updated template rendering logic.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the context bomb output issues identified in issue #7; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/issue-7-20260227-0009

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/api/client.go (1)

70-79: Clean helper, with a small testing consideration.

The comment on line 71 nails it—JSON numbers always unmarshal as float64 into map[string]any, so this is correct for production.

One heads-up: if you ever write unit tests where you manually construct a Summary map like this:

ir := SupermodelIR{Summary: map[string]any{"filesProcessed": 42}} // int, not float64

...it would silently return 0 because 42 is an int, not float64. You'd need to write:

ir := SupermodelIR{Summary: map[string]any{"filesProcessed": float64(42)}}

Not a bug per se—just a potential gotcha for future test authors.

🔧 Optional: Handle both int and float64 for test friendliness
 summaryInt := func(key string) int {
   if v, ok := ir.Summary[key]; ok {
     if n, ok := v.(float64); ok {
       return int(n)
     }
+    if n, ok := v.(int); ok {
+      return n
+    }
   }
   return 0
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/api/client.go` around lines 70 - 79, The helper summaryInt currently
only handles float64 and will return 0 if the Summary map contains an int
(common in tests); update summaryInt to accept additional numeric types (int,
int32, int64, uint, json.Number) and convert them to int before returning so
both real JSON-unmarshaled data and manually-constructed test maps (e.g.,
SupermodelIR.Summary) behave the same; locate the summaryInt closure in
internal/api/client.go and add type switches/handling for these numeric variants
and safe bounds/conversion to int.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/api/client.go`:
- Around line 70-79: The helper summaryInt currently only handles float64 and
will return 0 if the Summary map contains an int (common in tests); update
summaryInt to accept additional numeric types (int, int32, int64, uint,
json.Number) and convert them to int before returning so both real
JSON-unmarshaled data and manually-constructed test maps (e.g.,
SupermodelIR.Summary) behave the same; locate the summaryInt closure in
internal/api/client.go and add type switches/handling for these numeric variants
and safe bounds/conversion to int.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a0d1ed and 3df00c9.

📒 Files selected for processing (2)
  • internal/api/client.go
  • internal/template/render.go

@claude claude bot merged commit eef711f into main Feb 27, 2026
3 checks passed
@claude claude bot deleted the claude/issue-7-20260227-0009 branch February 27, 2026 00:32
This was referenced Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: context bomb shows zeros for lines and language counts

1 participant