Fix hash function: use Bun.hash (wyhash) instead of FNV-1a#3
Fix hash function: use Bun.hash (wyhash) instead of FNV-1a#3kvkmh wants to merge 1 commit intoithiria894:masterfrom
Conversation
Claude Code ships as a Bun executable, so its buddy generation uses Bun.hash() (wyhash), not the FNV-1a fallback. Running the tools with `node` produces completely different hashes, causing rerolled IDs to generate unexpected species/rarity. - Add Bun.hash detection to hash functions in all three tools - Add runtime warning when running under Node instead of Bun - Update README: document the Bun.hash requirement, change all `node` commands to `bun run`, add Bun install prerequisite - Update FAQ to clarify Bun is required, not optional Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe codebase has been updated to prioritize Bun's native Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
reroll.js (1)
55-58: Consider centralizing hash runtime selection to avoid drift across scripts.This Bun/FNV fallback logic is now duplicated in
reroll.js,shiny_hunt.js, andverify.js. A shared helper would reduce maintenance risk if hash behavior changes again.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@reroll.js` around lines 55 - 58, Create a single shared helper (e.g., computeRuntimeHash or getStableHash) that encapsulates the runtime selection between Bun.hash and the FNV-1a fallback (the existing Bun.hash(...) & 0xffffffffn logic and the FNV-1a fallback used now), export it from a new module and replace the duplicated logic in reroll.js, shiny_hunt.js, and verify.js to call that helper; ensure the helper returns a Number and preserves the exact mask/behavior (0xffffffff) so callers like the current Bun.hash branch and FNV fallback get identical results.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@reroll.js`:
- Around line 47-53: The script's usage/banner still suggests running with node
which produces wrong results; find the usage banner strings that mention "node
..." (the top-of-file usage/help strings) and update them to instruct users to
run the script with "bun run <script>" (e.g., "bun run reroll.js" or "bun run
<script>") so the banner consistently reflects the Bun requirement; ensure all
occurrences of the old "node" invocation in the banner/help text are replaced
and any explanatory text mentions Bun as the required runtime.
---
Nitpick comments:
In `@reroll.js`:
- Around line 55-58: Create a single shared helper (e.g., computeRuntimeHash or
getStableHash) that encapsulates the runtime selection between Bun.hash and the
FNV-1a fallback (the existing Bun.hash(...) & 0xffffffffn logic and the FNV-1a
fallback used now), export it from a new module and replace the duplicated logic
in reroll.js, shiny_hunt.js, and verify.js to call that helper; ensure the
helper returns a Number and preserves the exact mask/behavior (0xffffffff) so
callers like the current Bun.hash branch and FNV fallback get identical results.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ea2c3243-b526-4b9f-a93e-86ef33bbcce2
📒 Files selected for processing (4)
README.mdreroll.jsshiny_hunt.jsverify.js
| // ─── Hash: matches Claude Code's actual implementation ────────────────────── | ||
| // | ||
| // Claude Code uses Bun.hash (wyhash) when running on Bun, with FNV-1a as a | ||
| // fallback for non-Bun environments. Since the Claude Code binary ships as a | ||
| // Bun executable, Bun.hash is what's actually used in practice. Running this | ||
| // tool with Node will produce WRONG results — use `bun run` instead. | ||
|
|
There was a problem hiding this comment.
Update script usage banner to bun run to match runtime requirement.
The new guidance says Bun is required, but users copying the usage banner (Line 5, Line 8, Line 9) will still run node ... and get mismatched output.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@reroll.js` around lines 47 - 53, The script's usage/banner still suggests
running with node which produces wrong results; find the usage banner strings
that mention "node ..." (the top-of-file usage/help strings) and update them to
instruct users to run the script with "bun run <script>" (e.g., "bun run
reroll.js" or "bun run <script>") so the banner consistently reflects the Bun
requirement; ensure all occurrences of the old "node" invocation in the
banner/help text are replaced and any explanatory text mentions Bun as the
required runtime.
Summary
Bun.hash()(wyhash), not the FNV-1a fallback. Running the tools withnodeproduces completely different hashes, causing rerolled IDs to generate unexpected species/rarity.Bun.hashdetection to the hash function in all three tools (reroll.js,shiny_hunt.js,verify.js)nodecommands tobun runHow we found this
We set a
userIDthat our FNV-1a implementation predicted would produce a shiny legendary ghost — but Claude Code hatched an uncommon owl instead. Extracting the actual hash function from the Claude Code binary (~/.local/share/claude/versions/2.1.92) revealed the two code paths:After switching to
Bun.hash, the same ID correctly verified as a shiny legendary ghost and hatched as expected.Test plan
bun run verify.js <id>output matches the actual buddy hatched by Claude Codebun run shiny_hunt.js ghostfinds IDs that produce real shiny legendary ghostsnode run verify.jsshows the warning about wrong hash function🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
nodetobun runthroughout the guideChanges