Skip to content

fix(gain): report a missing hook on every view, not just the default one with data - #4038

Merged
TaKO8Ki merged 1 commit into
rtk-ai:developfrom
KuSh:fix/gain-hook-warning-every-view
Oct 5, 2026
Merged

TaKO8Ki merged 1 commit into
rtk-ai:developfrom
KuSh:fix/gain-hook-warning-every-view

Conversation

@KuSh

@KuSh KuSh commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4035

Problem

rtk gain reports a missing or outdated hook on only one of its invocations: the default view, and only when there is tracking data. --daily, --weekly, --monthly, --all and the empty report all stay silent.

The empty report is the worst case. With no hook installed nothing is tracked, so "no data" is usually caused by the missing hook — and that is the one run where the user is told nothing:

$ rtk gain
No tracking data yet.
Run some rtk commands to start tracking savings.

The advice never appears there, because rtk gain is also exempt from the daily [rtk] /!\ No hook installed reminder — exempt on the grounds that it prints its own.

Cause

The hook_check::status() block sits inside the default-view branch (if !daily && !weekly && !monthly && !all), which is itself after the summary.total_commands == 0 early return. Two gates, so four of five views and the empty report never reach it.

Fix

Hoist the check into warn_hook_issues() and call it once, above the early return and outside the view branch. The JSON and CSV exports return earlier and stay free of it.

suppress_hook_warning keeps hiding the missing-hook arm, and keeps leaving the outdated-hook arm visible — hoisting must not hand the warning back to users who opted out on the views that were previously silent.

Measured

Isolated HOME holding a .claude directory with no hook registered, counting [warn] No hook installed lines:

invocation before after
rtk gain (with data) 1 1
rtk gain --daily 0 1
rtk gain --weekly 0 1
rtk gain --monthly 0 1
rtk gain --all 0 1
rtk gain (empty database) 0 1
rtk gain --format json / csv 0 0
any view, RTK_SUPPRESS_HOOK_WARNING=1 0 0
no ~/.claude at all 0 0

Tests

tests/gain_hook_warning_test.rs — 12 cases. The nine-case matrix is @AngelVRodC's from #4039, which covered this ground better than my original three: it counts occurrences rather than testing contains, so a double-print fails; it seeds real tracking data via rtk proxy true, so the view flags exercise the with-data path instead of the early return; it separates stdout from stderr; and it pins the not-applicable state (no ~/.claude → silent). #4039 is closed as a duplicate in favour of this PR.

Three cases added on top, covering the suppress_hook_warning interaction.

Mutation-checked, both directions:

  • putting the call back inside the default-view branch → 6 of 12 fail
  • dropping the hook_warning_suppressed() gate → 1 fails (suppress_hook_warning_hides_the_missing_arm_on_every_view)

That second one is worth noting: both this PR's first revision and #4039 dropped that gate, because both were written before #776 landed. Neither the original three tests nor the nine-case matrix caught it.

The tests spawn the binary through common::rtk_command() and pin HOME, RTK_DB_PATH, XDG_CONFIG_HOME and XDG_DATA_HOME onto a per-test temporary home, the same isolating_env pattern as tests/hook_warning_scope_test.rs. The earlier version pinned only HOME, which passed either way while writing a real rtk/history.db into an exported XDG_DATA_HOME; the same run now leaves nothing outside the temporary home.

Unix-gated, because hook_check::status() resolves the Claude directory through the home directory and only Unix takes that from $HOME.

Gate

Rebased on develop. cargo fmt --all clean, cargo clippy --all-targets clean, cargo test --all 4125 passed / 0 failed, Windows cross-check clean, and green under LC_ALL=de_DE.UTF-8 with GIT_DIR pointed at a real repository.

🤖 Generated with Claude Code

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added analytics bug Something isn't working hook labels Sep 13, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes rtk gain so the missing/outdated hook warning is printed on every view (default, --daily, --weekly, --monthly, --all) and on the empty report, not just the default view when data exists. The check is hoisted out of the default-view branch into a standalone warn_hook_issues() call made before the early return, while JSON/CSV exports still return earlier and stay unaffected.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4035


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@KuSh
KuSh force-pushed the fix/gain-hook-warning-every-view branch 2 times, most recently from f046585 to 7caab43 Compare September 19, 2026 08:40
@pszymkowiak
pszymkowiak requested a review from TaKO8Ki October 5, 2026 04:12

@TaKO8Ki TaKO8Ki left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the fix. I left a comment.

Comment thread tests/gain_hook_warning_test.rs Resolved
`rtk gain` only reported a missing or outdated hook on the default view with
tracking data, so `--daily`, `--weekly`, `--monthly`, `--all` and the empty
report stayed silent. The empty report is where the advice matters most: with
no hook nothing is tracked, which is the likeliest reason there is nothing to
show.

Hoist the check into `warn_hook_issues()` and call it once, above the
empty-report early return and outside the view branch. The JSON and CSV
exports return earlier and stay free of it. `suppress_hook_warning` keeps
hiding the missing-hook arm, and keeps leaving the outdated-hook arm visible.

The tests spawn the binary through `common::rtk_command()` and pin `HOME`,
`RTK_DB_PATH` and the `XDG_*` directories onto a temporary home, so a runner
that exports any of them cannot reach past it.

Co-Authored-By: Angel V. Rodriguez C. <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@KuSh
KuSh force-pushed the fix/gain-hook-warning-every-view branch from 7caab43 to 7231fd2 Compare October 5, 2026 16:51

@TaKO8Ki TaKO8Ki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. 🚀

@TaKO8Ki
TaKO8Ki merged commit 5019e9c into rtk-ai:develop Oct 5, 2026
12 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 5, 2026
@KuSh
KuSh deleted the fix/gain-hook-warning-every-view branch October 5, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics bug Something isn't working hook

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk gain reports a missing hook on only one of its five views — never on the empty report, where it matters most

2 participants