Skip to content

fix(ui): flip /usage gauge color thresholds#2046

Open
he-yufeng wants to merge 1 commit intoMoonshotAI:mainfrom
he-yufeng:fix/usage-ratio-color-inverted
Open

fix(ui): flip /usage gauge color thresholds#2046
he-yufeng wants to merge 1 commit intoMoonshotAI:mainfrom
he-yufeng:fix/usage-ratio-color-inverted

Conversation

@he-yufeng
Copy link
Copy Markdown

@he-yufeng he-yufeng commented Apr 23, 2026

Fixes #2019.

_format_row in src/kimi_cli/ui/shell/usage.py computes

ratio = (row.limit - row.used) / row.limit if row.limit > 0 else 0

i.e. the remaining fraction (and the caller renders it as {percent:.0f}% left). The color helper below reads ratio as if it were a "used" gauge:

def _ratio_color(ratio: float) -> str:
    if ratio >= 0.9:
        return "red"      # actually: 90%+ remaining, should be green
    if ratio >= 0.7:
        return "yellow"   # 70%+ remaining, should be green too
    return "green"        # < 70% remaining, gauge silently goes green as it drains

So the progress bar is green while usage is almost full and turns red right after a reset. This PR flips the thresholds so red kicks in when ≤10% remains and yellow when ≤30% remains, which matches the % left label.

Reporter (@sunmy2019) also gave the same fix in the issue. Added a short comment explaining the direction since the variable name alone doesn't make it obvious.


Open in Devin Review

_format_row computes ratio as (limit - used) / limit, i.e. the
remaining fraction, and the caller labels it "% left". _ratio_color,
however, reads ratio like a "used" gauge — 90%+ remaining renders
red and anything below 70% remaining renders green, which is the
opposite of the intended warning signal.

Flip the comparisons so red kicks in once 10% or less remains and
yellow once 30% or less remains, matching the "% left" label.

Fixes MoonshotAI#2019
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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.

Wrong usage color

1 participant