Skip to content

Add Claude Code Integration Guide + Fix Badge Priority Bug#3040

Merged
sawka merged 5 commits intomainfrom
sawka/cc-hooks
Mar 12, 2026
Merged

Add Claude Code Integration Guide + Fix Badge Priority Bug#3040
sawka merged 5 commits intomainfrom
sawka/cc-hooks

Conversation

@sawka
Copy link
Member

@sawka sawka commented Mar 12, 2026

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

Adds a new docs page for Claude Code Tab Badges and small restructuring in an existing wsh reference doc. Frontend onboarding components now use the useWaveEnv hook and waveEnv.electron.openExternal to open docs links. Badge handling was changed in both frontend and backend from unconditional overwrite to priority-then-ID comparison (cmpBadge) that merges/accepts only higher-priority incoming badges; sorting uses the same comparator. The mock wave env gained an openExternal implementation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author; however, the title clearly conveys the intent and the changes are well-organized across related files. Consider adding a brief description explaining the Claude Code integration setup and the badge priority fix for better context.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main components of the changeset: adding Claude Code integration documentation and fixing a badge priority bug.

✏️ 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 sawka/cc-hooks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 12, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7bbf7b0
Status: ✅  Deploy successful!
Preview URL: https://2521c719.waveterm.pages.dev
Branch Preview URL: https://sawka-cc-hooks.waveterm.pages.dev

View logs

Copy link
Contributor

@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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/docs/claude-code.mdx`:
- Around line 68-78: The two examples use mismatched gold hex codes: update the
hex so both examples use the same value (make the "AskUserQuestion" command's
color match the permission prompt example and prose); locate the "PreToolUse" ->
"AskUserQuestion" block and change the color in the command string ("wsh badge
message-question --color '#e0b965' --priority 20 --beep") to the canonical hex
used elsewhere (or change the other example to '#e0b965') so both JSON snippets
and the surrounding prose reference the identical gold hex.

In `@frontend/app/store/badge.ts`:
- Around line 215-220: The client currently replaces the atom's badge with
sortBadges(candidates)[0], which loses suppressed badges; change the atom
storage to maintain a map of badgeid→badge (use the same
curAtom/globalStore.get/set and sortBadges helpers) so on incoming data.badge
you set map[badge.badgeid]=badge, on clear/clearbyid you delete the badgeid
entry (or clear the map), and after each update derive and set the visible
winner as sortBadges(Object.values(map))[0]; keep the map in globalStore for
that curAtom so clears restore lower-priority active badges.

In `@pkg/wcore/badge.go`:
- Around line 97-102: The current logic overwrites
globalBadgeStore.transient[orefStr] with a single Badge, causing cleared
BadgeIds to remove other active badges; change transient to hold a map of
BadgeId->Badge per oref (keep symbol names: globalBadgeStore.transient,
incoming, BadgeId, Priority, orefStr) so Set path inserts/updates incoming into
that per-oref map and ClearById removes by BadgeId, and after each set/clear
recompute and publish the visible winner (choose highest Priority, break ties by
BadgeId) instead of storing a single Badge directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d2b74d66-0101-456b-9ffb-7cf9a4efd1e0

📥 Commits

Reviewing files that changed from the base of the PR and between 8164ffc and 669e7c3.

📒 Files selected for processing (6)
  • docs/docs/claude-code.mdx
  • frontend/app/onboarding/onboarding-upgrade-v0140.tsx
  • frontend/app/onboarding/onboarding-upgrade-v0142.tsx
  • frontend/app/store/badge.ts
  • frontend/preview/mock/mockwaveenv.ts
  • pkg/wcore/badge.go

Comment on lines +215 to +220
if (data.clear) {
globalStore.set(curAtom, null);
} else if (data.badge != null) {
const existing = globalStore.get(curAtom);
const candidates = existing != null ? [existing, data.badge] : [data.badge];
globalStore.set(curAtom, sortBadges(candidates)[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

The client subscription still forgets suppressed badges.

sortBadges(candidates)[0] only keeps the displayed badge. If a higher-priority badge temporarily overrides a lower-priority active badge on the same oref, the later clear / clearbyid event leaves the atom empty instead of restoring the still-active lower-priority badge. Mirror the backend fix here too by tracking badges per badgeid and deriving the winner from that set.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/store/badge.ts` around lines 215 - 220, The client currently
replaces the atom's badge with sortBadges(candidates)[0], which loses suppressed
badges; change the atom storage to maintain a map of badgeid→badge (use the same
curAtom/globalStore.get/set and sortBadges helpers) so on incoming data.badge
you set map[badge.badgeid]=badge, on clear/clearbyid you delete the badgeid
entry (or clear the map), and after each update derive and set the visible
winner as sortBadges(Object.values(map))[0]; keep the map in globalStore for
that curAtom so clears restore lower-priority active badges.

Comment on lines +97 to +102
incoming := *data.Badge
existing, hasExisting := globalBadgeStore.transient[orefStr]
if !hasExisting || incoming.Priority > existing.Priority || (incoming.Priority == existing.Priority && incoming.BadgeId > existing.BadgeId) {
globalBadgeStore.transient[orefStr] = incoming
log.Printf("badge store: badge set: oref=%s badge=%+v\n", orefStr, incoming)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don't collapse per-badge state into a single stored badge.

ClearById makes badge lifecycle per badge, but this still retains only one winner in transient[orefStr]. If badge A is active, badge B with higher priority arrives, and later B clears by ID, A is gone forever even though it was never cleared. Please store active badges per oref keyed by BadgeId, then recompute the visible winner after each set/clear instead of overwriting the store with a single badge.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/wcore/badge.go` around lines 97 - 102, The current logic overwrites
globalBadgeStore.transient[orefStr] with a single Badge, causing cleared
BadgeIds to remove other active badges; change transient to hold a map of
BadgeId->Badge per oref (keep symbol names: globalBadgeStore.transient,
incoming, BadgeId, Priority, orefStr) so Set path inserts/updates incoming into
that per-oref map and ClearById removes by BadgeId, and after each set/clear
recompute and publish the visible winner (choose highest Priority, break ties by
BadgeId) instead of storing a single Badge directly.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 12, 2026

Code Review Summary

Status: 2 Ongoing Issues | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Ongoing Issues (from prior review)

The following issues were identified in prior review and remain present in the current code:

Previously Flagged - Not Yet Resolved

File Issue
frontend/app/store/badge.ts Client subscription still loses suppressed badges - when a higher-priority badge is set and then cleared, any previously active lower-priority badge is not restored
pkg/wcore/badge.go Backend stores only one badge per oref - if badge A is active, badge B (higher priority) arrives, and B clears by ID, badge A is lost forever even though it was never explicitly cleared
Resolved Issues
  • docs/docs/claude-code.mdx line 78 - Color hex mismatch (#e0b965 vs #e0b956) was fixed in subsequent commits
Files Reviewed (7 files)
  • docs/docs/claude-code.mdx - Documentation (resolved)
  • docs/docs/wsh-reference.mdx - Formatting change
  • frontend/app/onboarding/onboarding-upgrade-v0140.tsx - Uses useWaveEnv pattern
  • frontend/app/onboarding/onboarding-upgrade-v0142.tsx - Added docs link
  • frontend/app/store/badge.ts - Badge logic (ongoing issue)
  • frontend/preview/mock/mockwaveenv.ts - Mock openExternal
  • pkg/wcore/badge.go - Badge logic (ongoing issue)

The badge tracking issue represents a data integrity problem where badges can be prematurely lost. Please consider storing badges per badgeid and deriving the visible winner from that set rather than overwriting with a single badge.

Copy link
Contributor

@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 (2)
frontend/app/store/badge.ts (1)

240-251: Consider documenting the intentional difference in tie-breaking between sort functions.

sortBadges uses descending badgeid (via cmpBadge(b, a)), while sortBadgesForTab uses ascending badgeid. The ascending order in sortBadgesForTab matches the documented behavior in claude-code.mdx: "Ties at the same priority go to the earliest badge set."

A brief inline comment explaining why these differ would help future maintainers understand the intentional design.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/store/badge.ts` around lines 240 - 251, Add a short inline
comment above sortBadges and sortBadgesForTab explaining the intentional
tie-breaker difference: note that sortBadges uses descending badgeid (via
cmpBadge(b, a)) while sortBadgesForTab uses ascending badgeid so "ties at the
same priority go to the earliest badge set" per claude-code.mdx; reference the
functions sortBadges and sortBadgesForTab and briefly state that this
discrepancy is deliberate to preserve documented behavior.
docs/docs/claude-code.mdx (1)

85-87: External issue references may become stale.

The links to Claude Code issues (#5186, #19627) are helpful context, but external issue URLs can change or become unavailable. Consider periodically verifying these links remain valid, or adding the issue titles inline so the context is preserved even if links break.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/docs/claude-code.mdx` around lines 85 - 87, Update the "Known Issue"
warning block that mentions Claude Code and `Notification` hooks to include the
titles (or short summaries) of the referenced external issues (`#5186` and `#19627`)
inline next to their links and add a short note to periodically verify the URLs;
specifically edit the warning text containing "Notification" and the two issue
links so it reads like: link + issue title (or brief one-line summary) and
append a parenthetical reminder to check links for staleness, ensuring readers
keep context if the external URLs change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/docs/claude-code.mdx`:
- Around line 85-87: Update the "Known Issue" warning block that mentions Claude
Code and `Notification` hooks to include the titles (or short summaries) of the
referenced external issues (`#5186` and `#19627`) inline next to their links and add
a short note to periodically verify the URLs; specifically edit the warning text
containing "Notification" and the two issue links so it reads like: link + issue
title (or brief one-line summary) and append a parenthetical reminder to check
links for staleness, ensuring readers keep context if the external URLs change.

In `@frontend/app/store/badge.ts`:
- Around line 240-251: Add a short inline comment above sortBadges and
sortBadgesForTab explaining the intentional tie-breaker difference: note that
sortBadges uses descending badgeid (via cmpBadge(b, a)) while sortBadgesForTab
uses ascending badgeid so "ties at the same priority go to the earliest badge
set" per claude-code.mdx; reference the functions sortBadges and
sortBadgesForTab and briefly state that this discrepancy is deliberate to
preserve documented behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5c92f412-d337-4ce7-b4d0-d55223520164

📥 Commits

Reviewing files that changed from the base of the PR and between 669e7c3 and 7bbf7b0.

📒 Files selected for processing (4)
  • docs/docs/claude-code.mdx
  • docs/docs/wsh-reference.mdx
  • frontend/app/store/badge.ts
  • pkg/wcore/badge.go
✅ Files skipped from review due to trivial changes (1)
  • docs/docs/wsh-reference.mdx

@sawka sawka merged commit 52dd0a2 into main Mar 12, 2026
10 of 11 checks passed
@sawka sawka deleted the sawka/cc-hooks branch March 12, 2026 05:16
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.

1 participant