buddy-reroll 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -18,9 +18,10 @@ import {
18
18
  findCurrentSalt,
19
19
  matches,
20
20
  rollFrom,
21
+ setNodeHashMode,
21
22
  } from "./lib/companion.js";
22
23
  import { formatDoctorReport, getDoctorReport } from "./lib/doctor.js";
23
- import { findBinaryPath, findConfigPath, getClaudeBinaryOverride, getPatchability } from "./lib/runtime.js";
24
+ import { findBinaryPath, findConfigPath, getClaudeBinaryOverride, getPatchability, isBunBinary } from "./lib/runtime.js";
24
25
  import { parallelBruteForce } from "./lib/finder.js";
25
26
  import { estimateAttempts, formatProgress } from "./lib/estimator.js";
26
27
  import { installHook, removeHook, storeSalt, readStoredSalt } from "./lib/hooks.js";
@@ -265,7 +266,7 @@ function formatCompanionCard(result) {
265
266
 
266
267
  // ── Interactive mode ─────────────────────────────────────────────────────
267
268
 
268
- async function interactiveMode(binaryPath, configPath, userId) {
269
+ async function interactiveMode(binaryPath, configPath, userId, nodeHash) {
269
270
  const { currentSalt, currentRoll } = readCurrentCompanion(binaryPath, userId);
270
271
 
271
272
  const uiOpts = {
@@ -274,7 +275,7 @@ async function interactiveMode(binaryPath, configPath, userId) {
274
275
  binaryPath,
275
276
  configPath,
276
277
  userId,
277
- bruteForce: parallelBruteForce,
278
+ bruteForce: (uid, tgt, onProg, sig) => parallelBruteForce(uid, tgt, onProg, sig, { nodeHash }),
278
279
  patchBinary,
279
280
  resignBinary,
280
281
  clearCompanion,
@@ -303,7 +304,7 @@ async function interactiveMode(binaryPath, configPath, userId) {
303
304
 
304
305
  // ── Non-interactive mode ─────────────────────────────────────────────────
305
306
 
306
- async function nonInteractiveMode(args, binaryPath, configPath, userId) {
307
+ async function nonInteractiveMode(args, binaryPath, configPath, userId, nodeHash) {
307
308
  console.log(` Binary: ${binaryPath}`);
308
309
  console.log(` Config: ${configPath}`);
309
310
  console.log(` User ID: ${userId.slice(0, 8)}...`);
@@ -357,7 +358,7 @@ async function nonInteractiveMode(args, binaryPath, configPath, userId) {
357
358
  try {
358
359
  found = await parallelBruteForce(userId, target, (attempts, elapsed, est, workers) => {
359
360
  process.stdout.write(`\r ${formatProgress(attempts, elapsed, est, workers)}`);
360
- });
361
+ }, undefined, { nodeHash });
361
362
  } catch (err) {
362
363
  fail(`\n ✗ ${err.message}`);
363
364
  }
@@ -536,6 +537,9 @@ async function main() {
536
537
  fail("✗ Could not find Claude Code binary. Checked PATH and known install locations.");
537
538
  }
538
539
 
540
+ const nodeHash = !isBunBinary(binaryPath);
541
+ if (nodeHash) setNodeHashMode(true);
542
+
539
543
  const configPath = findConfigPath();
540
544
  if (!configPath) fail("✗ Could not find Claude Code config file. Checked ~/.claude/.config.json and ~/.claude.json.");
541
545
 
@@ -548,9 +552,9 @@ async function main() {
548
552
  const isCommand = args.restore || args.current || args.doctor || args.hook || args.unhook || args["apply-hook"];
549
553
 
550
554
  if (!hasTargetFlags && !isCommand) {
551
- await interactiveMode(binaryPath, configPath, userId);
555
+ await interactiveMode(binaryPath, configPath, userId, nodeHash);
552
556
  } else {
553
- await nonInteractiveMode(args, binaryPath, configPath, userId);
557
+ await nonInteractiveMode(args, binaryPath, configPath, userId, nodeHash);
554
558
  }
555
559
  }
556
560
 
package/lib/companion.js CHANGED
@@ -37,7 +37,23 @@ function mulberry32(seed) {
37
37
 
38
38
  import { wyhash } from "./wyhash.js";
39
39
 
40
+ let _nodeHash = false;
41
+
42
+ export function setNodeHashMode(enabled) {
43
+ _nodeHash = enabled;
44
+ }
45
+
46
+ function fnv1a(str) {
47
+ let h = 2166136261;
48
+ for (let i = 0; i < str.length; i++) {
49
+ h ^= str.charCodeAt(i);
50
+ h = Math.imul(h, 16777619);
51
+ }
52
+ return h >>> 0;
53
+ }
54
+
40
55
  function hashString(value) {
56
+ if (_nodeHash) return fnv1a(value);
41
57
  if (typeof Bun !== "undefined") return Number(BigInt(Bun.hash(value)) & 0xffffffffn);
42
58
  return Number(wyhash(0n, value) & 0xffffffffn);
43
59
  }
package/lib/finder.js CHANGED
@@ -7,7 +7,7 @@ import { rollFrom } from "./companion.js";
7
7
 
8
8
  const WORKER_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "worker.js");
9
9
 
10
- export async function parallelBruteForce(userId, target, onProgress, signal) {
10
+ export async function parallelBruteForce(userId, target, onProgress, signal, { nodeHash = false } = {}) {
11
11
  const numWorkers = Math.max(1, Math.min(cpus().length, 8));
12
12
  const expected = estimateAttempts(target);
13
13
 
@@ -42,7 +42,9 @@ export async function parallelBruteForce(userId, target, onProgress, signal) {
42
42
  workerStderr[i] = "";
43
43
  workerAttempts[i] = 0;
44
44
 
45
- const child = spawn(process.execPath, [WORKER_SCRIPT, userId, JSON.stringify(target)], {
45
+ const args = [WORKER_SCRIPT, userId, JSON.stringify(target)];
46
+ if (nodeHash) args.push("--node-hash");
47
+ const child = spawn(process.execPath, args, {
46
48
  stdio: ["ignore", "pipe", "pipe"],
47
49
  });
48
50
  children.push(child);
package/lib/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import { accessSync, constants, existsSync, readFileSync, readdirSync, realpathSync, statSync } from "fs";
1
+ import { accessSync, closeSync, constants, existsSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync } from "fs";
2
2
  import { execFileSync } from "child_process";
3
3
  import { join, dirname, isAbsolute } from "path";
4
4
  import { homedir, platform } from "os";
@@ -17,6 +17,23 @@ function isRealBinary(candidatePath) {
17
17
  }
18
18
  }
19
19
 
20
+ export function isBunBinary(binaryPath) {
21
+ let fd;
22
+ try {
23
+ fd = openSync(binaryPath, "r");
24
+ const buf = Buffer.alloc(4);
25
+ readSync(fd, buf, 0, 4, 0);
26
+ const h0 = buf[0], h1 = buf[1];
27
+ // Mach-O (LE/BE), ELF, PE → compiled Bun binary
28
+ return (h0 === 0xcf && h1 === 0xfa) || (h0 === 0xfe && h1 === 0xed) ||
29
+ (h0 === 0x7f && h1 === 0x45) || (h0 === 0x4d && h1 === 0x5a);
30
+ } catch {
31
+ return true; // default to Bun (most common install)
32
+ } finally {
33
+ if (fd !== undefined) try { closeSync(fd); } catch {}
34
+ }
35
+ }
36
+
20
37
  export function getClaudeConfigDir() {
21
38
  return process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
22
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buddy-reroll",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Reroll your Claude Code buddy companion to any species/rarity/eye/hat/shiny combo",
5
5
  "type": "module",
6
6
  "bin": {
package/scripts/worker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { rollFrom, matches } from "../lib/companion.js";
2
+ import { rollFrom, matches, setNodeHashMode } from "../lib/companion.js";
3
3
 
4
4
  const SALT_LEN = 15;
5
5
  const CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
@@ -22,6 +22,8 @@ try {
22
22
  process.exit(1);
23
23
  }
24
24
 
25
+ if (process.argv.includes("--node-hash")) setNodeHashMode(true);
26
+
25
27
  if (!userId || !target) {
26
28
  process.stderr.write("Usage: worker.js <userId> '<targetJSON>'\n");
27
29
  process.exit(1);