Skip to content

feat(statusline): add CAVEMAN_BADGE_COMPACT env var for compact badge#320

Open
drPod wants to merge 3 commits intoJuliusBrussee:mainfrom
drPod:compact-badge-env-var
Open

feat(statusline): add CAVEMAN_BADGE_COMPACT env var for compact badge#320
drPod wants to merge 3 commits intoJuliusBrussee:mainfrom
drPod:compact-badge-env-var

Conversation

@drPod
Copy link
Copy Markdown

@drPod drPod commented May 1, 2026

Summary

Adds an opt-in CAVEMAN_BADGE_COMPACT=1 env var that switches the statusline badge from [CAVEMAN] / [CAVEMAN:WENYAN-ULTRA] to a compact form ([C] / [C:WU] / etc.). Helpful for users running ccstatusline or similar dense statuslines where the full word crowds out other widgets.

  • Opt-in. Env unset (or set to anything other than the literal string 1) → existing verbose output, byte-for-byte unchanged.
  • All existing security parsing preserved verbatim: symlink reject, 64-byte cap, [a-z0-9-] charset filter, mode whitelist. The compact branch sits after validation, so attacker-controlled flag bytes can never reach the compact case block either.
  • Compact mode skips the savings suffix (⛏ 12.4k) for the same reason users opted into compact: keep the badge short. Matches the user-prompt spec (exit 0 after compact render).

Mode → badge mapping

Mode Verbose (default) Compact (CAVEMAN_BADGE_COMPACT=1)
full / empty [CAVEMAN] [C]
lite [CAVEMAN:LITE] [C:L]
ultra [CAVEMAN:ULTRA] [C:U]
wenyan-lite [CAVEMAN:WENYAN-LITE] [C:WL]
wenyan / wenyan-full [CAVEMAN:WENYAN] / [CAVEMAN:WENYAN-FULL] [C:W]
wenyan-ultra [CAVEMAN:WENYAN-ULTRA] [C:WU]
commit [CAVEMAN:COMMIT] [C:CM]
review [CAVEMAN:REVIEW] [C:RV]
compress [CAVEMAN:COMPRESS] [C:CP]

Files changed (~117 lines)

  • hooks/caveman-statusline.sh — +19 LOC. Compact branch added before existing verbose printf; existing logic untouched.
  • hooks/caveman-statusline.ps1 — +21 LOC. PowerShell parity (per CLAUDE.md "both scripts hand-kept in sync").
  • tests/test_caveman_stats.js — +76 LOC. Three new test cases:
    1. Compact badge renders correctly for every whitelisted mode (table-driven, asserts no [CAVEMAN…] leak).
    2. Default / CAVEMAN_BADGE_COMPACT=0 / CAVEMAN_BADGE_COMPACT=true all keep verbose output (only literal 1 opts in).
    3. Compact mode suppresses the savings suffix even when CAVEMAN_STATUSLINE_SAVINGS=1.
  • README.md — +1 sentence appended to the existing Statusline savings badge paragraph (no new section).

Test status

$ node tests/test_caveman_stats.js
… 32 passed, 0 failed

$ python3 -m unittest tests.test_hooks
Ran 4 tests in 0.155s — OK

$ python3 tests/verify_repo.py
All local verification checks passed

Manual smoke test confirmed each of the 9 modes renders the expected compact badge and that env unset / 0 / true all preserve the verbose path.

Notes / surfaced uncertainties

  • I touched the PowerShell script for parity since CLAUDE.md calls it out as a hand-synced sibling. Happy to drop the PS1 change if maintainer prefers a sh-only first cut.
  • I did not add a verify_repo.py assertion for compact mode — the existing one only spot-checks one verbose mode. Felt like overreach to expand it; the JS test suite is already the dense statusline-coverage venue.

🤖 Generated with Claude Code

When CAVEMAN_BADGE_COMPACT=1 is set, the statusline badge renders
as [C] / [C:L] / [C:U] etc. instead of [CAVEMAN] / [CAVEMAN:LITE].

Useful for users running ccstatusline or similar dense statuslines
where the full word is too long alongside other widgets.

Default behavior unchanged: env unset → existing verbose output.
Copilot AI review requested due to automatic review settings May 1, 2026 04:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Add opt-in CAVEMAN_BADGE_COMPACT=1 compact statusline badge variant to keep statusline short, with test coverage and README mention.

Changes:

  • Add compact badge rendering path in caveman-statusline.sh and caveman-statusline.ps1, skipping savings suffix in compact mode.
  • Add JS tests covering compact badge mapping, opt-in semantics (only literal "1"), and savings suffix suppression.
  • Document new env var in README statusline badge paragraph.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
hooks/caveman-statusline.sh Add compact badge render/exit branch gated by CAVEMAN_BADGE_COMPACT=1.
hooks/caveman-statusline.ps1 PowerShell parity for compact badge gating and mapping.
tests/test_caveman_stats.js Add table-driven compact badge tests + opt-in and suffix-suppression assertions.
README.md Document compact badge env var + examples.

Comment thread hooks/caveman-statusline.sh
Comment thread hooks/caveman-statusline.ps1
Whitelist validation rejects empty MODE before the compact branch
runs, so the empty-string handling in the case/switch was unreachable.
Remove it (option 1 from Copilot review on PR JuliusBrussee#320).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Qodo-Free-For-OSS
Copy link
Copy Markdown

Hi, New tests validate compact behavior only for caveman-statusline.sh; the PowerShell compact branch is not covered by runtime tests, increasing regression risk for Windows users.

Severity: informational | Category: reliability

How to fix: Add PS1 behavior test

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

Compact mode behavior is tested for bash only; Windows/PowerShell implementation is unverified at runtime.

Issue Context

The PowerShell script contains separate logic (switch arms) that could drift from bash mappings.

Fix Focus Areas

  • hooks/caveman-statusline.ps1[35-54]
  • tests/test_caveman_stats.js[433-507]

Suggested approach

  • If pwsh is available in CI, add a small test that writes .caveman-active, sets CAVEMAN_BADGE_COMPACT=1, runs the PS1 script, and asserts it prints the expected compact token and omits the suffix.
  • If pwsh isn’t available, consider adding a lightweight static assertion that the PS1 compact mappings include all valid modes (mirroring the bash mapping list).

Found by Qodo code review

Address Qodo bot regression-risk concern on PR JuliusBrussee#320 — extend the
existing PS static-check suite (verify_repo.py) with assertions that
caveman-statusline.ps1 contains the CAVEMAN_BADGE_COMPACT gate and the
[C] / [C:WU] compact badge mappings.

Matches repo convention: PS coverage is regex-based static analysis,
not Pester runtime tests.
@drPod
Copy link
Copy Markdown
Author

drPod commented May 1, 2026

Addressed in 48f5030 — extended tests/verify_repo.py PowerShell static-check suite to assert CAVEMAN_BADGE_COMPACT env var gate and [C] / [C:WU] compact mappings exist in caveman-statusline.ps1. Repo convention is regex-based static checks for PS (no Pester runtime in the test infra), so matched that pattern. Verified via python3 tests/verify_repo.py → all checks pass.

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.

3 participants