Skip to content

fix(cli): add clear-indicator and refresh-indicator subcommands (#26)#27

Merged
bakeb7j0 merged 1 commit into
mainfrom
fix/26-statusline-stale-after-compact
Apr 28, 2026
Merged

fix(cli): add clear-indicator and refresh-indicator subcommands (#26)#27
bakeb7j0 merged 1 commit into
mainfrom
fix/26-statusline-stale-after-compact

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

Summary

Adds two CLI subcommands to the nerf-server binary so future Claude Code hooks (PreCompact, SessionStart:compact) can keep the nerf: statusline indicator aligned with the real context size across compaction boundaries. Without this, the indicator goes stale post-compaction (the widget kept showing 126% after the actual context dropped to 41%) until the user manually ran /nerf status.

Changes

  • New cli.tsclear-indicator (idempotent removeIndicator) and refresh-indicator [--session-id <id>] (re-runs analyzer + writes fresh indicator).
  • index.ts dispatches subcommands at the top and exits before MCP setup; no-arg invocation continues to start the MCP stdio server unchanged.
  • tests/cli.test.ts — pure tests for isSubcommand / parseSessionIdFlag (incl. empty-string rejection) plus smoke tests for the no-agent-file no-op path.
  • Reviewer-driven: parseSessionIdFlag explicitly rejects empty-string values so the override-present-or-not contract matches resolveSessionId's truthiness check; exhaustiveness guard added on the runSubcommand switch.

Linked Issues

Closes #26

Test Plan

  • ./scripts/ci/validate.sh — tsc clean, shellcheck clean, 140 tests pass (was 139, +1 for empty-string flag rejection).
  • Built dist/nerf-server-linux-x64 and smoke-tested live:
    • clear-indicator removed nerf:* entries from /tmp/claude-statusline-rules-lawyer.json
    • refresh-indicator --session-id 991053c7-... ran the analyzer and wrote nerf:⚡ 80%
    • Both exit 0 cleanly, no stderr noise on the happy path
  • Trivy: 0 HIGH/CRITICAL.
  • MCP-stdio mode unchanged (no-arg invocation) — confirmed via existing tests/server.test.ts passing.

Companion PR in claudecode-workflow will wire the actual hooks once a v1.2.3 release of this repo is cut.

The nerf statusline indicator was push-only — the value got written
during nerf_* tool calls but nothing refreshed it on context-shifting
events like compaction or /clear. Result: post-compaction the widget
kept showing the pre-compaction percentage (e.g. 126%) until the user
manually ran /nerf status.

Add a CLI surface to the existing binary so hook scripts can poke the
indicator without going through MCP stdio:

  nerf-server clear-indicator               # idempotent removeIndicator
  nerf-server refresh-indicator [--session-id <id>]
                                            # re-runs the analyzer and
                                            # writes a fresh indicator

The dispatch sits at the top of index.ts and exits before MCP setup
when argv[0] is a known subcommand, so MCP-stdio mode is unchanged
for the no-arg invocation. parseSessionIdFlag rejects empty-string
values to keep the override-present-or-not contract aligned with
resolveSessionId's truthiness check.

The companion claudecode-workflow PR will wire PreCompact +
SessionStart:compact hooks that shell out to these subcommands.

Closes #26

Co-authored-by: Baker B <bakerb@waveeng.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bakeb7j0 bakeb7j0 added this pull request to the merge queue Apr 28, 2026
Merged via the queue into main with commit 2dfdc00 Apr 28, 2026
4 checks passed
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.

statusline indicator goes stale after compaction

1 participant