buddy-reroll 0.3.6 → 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/README.md +6 -9
- package/index.js +11 -7
- package/lib/companion.js +16 -0
- package/lib/estimator.js +19 -20
- package/lib/estimator.test.js +21 -19
- package/lib/finder.js +4 -2
- package/lib/runtime.js +18 -1
- package/package.json +1 -1
- package/scripts/worker.js +3 -1
- package/ui-fallback.js +10 -5
- package/ui.jsx +10 -5
package/README.md
CHANGED
|
@@ -12,16 +12,13 @@ Pick the perfect [Claude Code](https://docs.anthropic.com/en/docs/claude-code) `
|
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
# Bun (recommended)
|
|
15
|
-
|
|
15
|
+
bunx buddy-reroll
|
|
16
16
|
|
|
17
17
|
# npm
|
|
18
|
-
npm install -g buddy-reroll
|
|
19
|
-
|
|
20
|
-
# No install needed
|
|
21
18
|
npx buddy-reroll
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
Bun
|
|
21
|
+
Bun is faster, but Node.js >= 20 produces identical results — no Bun required.
|
|
25
22
|
|
|
26
23
|
## Usage
|
|
27
24
|
|
|
@@ -87,12 +84,12 @@ buddy-reroll --unhook # remove whenever you want
|
|
|
87
84
|
|
|
88
85
|
## How fast is it?
|
|
89
86
|
|
|
90
|
-
buddy-reroll uses all your CPU cores (up to 8) to find the right companion.
|
|
87
|
+
buddy-reroll uses all your CPU cores (up to 8) to find the right companion. Both runtimes use the same wyhash algorithm as Claude Code, so your buddy will always match `/buddy` exactly.
|
|
91
88
|
|
|
92
|
-
| Runtime | Speed |
|
|
89
|
+
| Runtime | Speed | Hash |
|
|
93
90
|
|---|---|---|
|
|
94
|
-
| Bun | Faster |
|
|
95
|
-
| Node.js >= 20 | Slightly slower |
|
|
91
|
+
| Bun | Faster (native `Bun.hash`) | wyhash ✓ |
|
|
92
|
+
| Node.js >= 20 | Slightly slower (pure JS) | wyhash ✓ |
|
|
96
93
|
|
|
97
94
|
## Requirements
|
|
98
95
|
|
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/estimator.js
CHANGED
|
@@ -16,28 +16,27 @@ export function estimateAttempts(target) {
|
|
|
16
16
|
return Math.round(1 / probability);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function formatTime(seconds) {
|
|
20
|
+
if (seconds < 60) return Math.round(seconds) + "s";
|
|
21
|
+
const minutes = Math.floor(seconds / 60);
|
|
22
|
+
const secs = Math.round(seconds % 60);
|
|
23
|
+
return minutes + "m " + secs + "s";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatRate(rate) {
|
|
27
|
+
if (rate >= 1_000_000) return (rate / 1_000_000).toFixed(1) + "M/s";
|
|
28
|
+
if (rate >= 1_000) return (rate / 1_000).toFixed(1) + "k/s";
|
|
29
|
+
return rate.toFixed(1) + "/s";
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
export function formatProgress(attempts, elapsed, expected, workers) {
|
|
20
|
-
const
|
|
21
|
-
const rate = attempts /
|
|
22
|
-
|
|
23
|
-
let rateStr;
|
|
24
|
-
if (rate >= 1_000_000) {
|
|
25
|
-
rateStr = (rate / 1_000_000).toFixed(1) + "M tries/s";
|
|
26
|
-
} else if (rate >= 1_000) {
|
|
27
|
-
rateStr = (rate / 1_000).toFixed(1) + "k tries/s";
|
|
28
|
-
} else {
|
|
29
|
-
rateStr = rate.toFixed(1) + " tries/s";
|
|
30
|
-
}
|
|
33
|
+
const elapsedSec = elapsed / 1000;
|
|
34
|
+
const rate = attempts / elapsedSec;
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (remaining < 60) {
|
|
35
|
-
etaStr = Math.round(remaining) + "s";
|
|
36
|
-
} else {
|
|
37
|
-
const minutes = Math.floor(remaining / 60);
|
|
38
|
-
const seconds = Math.round(remaining % 60);
|
|
39
|
-
etaStr = minutes + "m " + seconds + "s";
|
|
36
|
+
if (attempts >= expected) {
|
|
37
|
+
return `Still searching... ${formatTime(elapsedSec)} | ${formatRate(rate)} | taking longer than usual`;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
const remaining = (expected - attempts) / rate;
|
|
41
|
+
return `Searching... ${formatTime(elapsedSec)} | ${formatRate(rate)} | ~${formatTime(remaining)} left`;
|
|
43
42
|
}
|
package/lib/estimator.test.js
CHANGED
|
@@ -59,39 +59,41 @@ describe("estimateAttempts", () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
describe("formatProgress", () => {
|
|
62
|
-
it("
|
|
62
|
+
it("shows elapsed time and rate", () => {
|
|
63
63
|
const result = formatProgress(5_000_000, 2000, 10_000_000, 8);
|
|
64
|
-
expect(result).toContain("
|
|
65
|
-
expect(result).toContain("
|
|
66
|
-
expect(result).toContain("
|
|
64
|
+
expect(result).toContain("Searching...");
|
|
65
|
+
expect(result).toContain("2s");
|
|
66
|
+
expect(result).toContain("2.5M/s");
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it("
|
|
69
|
+
it("shows ETA when under expected", () => {
|
|
70
70
|
const result = formatProgress(50_000, 5000, 100_000, 4);
|
|
71
|
-
expect(result).toContain("
|
|
72
|
-
expect(result).toContain("10.0k tries/s");
|
|
73
|
-
expect(result).toContain("4 cores");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("formats ETA in seconds", () => {
|
|
77
|
-
const result = formatProgress(9_000_000, 1000, 10_000_000, 8);
|
|
71
|
+
expect(result).toContain("Searching...");
|
|
78
72
|
expect(result).toContain("left");
|
|
79
|
-
expect(result).toContain("s");
|
|
80
73
|
});
|
|
81
74
|
|
|
82
75
|
it("formats ETA in minutes and seconds", () => {
|
|
83
76
|
const result = formatProgress(1_000_000, 1000, 100_000_000, 8);
|
|
84
77
|
expect(result).toContain("m");
|
|
78
|
+
expect(result).toContain("left");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("shows 'taking longer than usual' past expected", () => {
|
|
82
|
+
const result = formatProgress(10_000_000, 2000, 10_000_000, 8);
|
|
83
|
+
expect(result).toContain("Still searching...");
|
|
84
|
+
expect(result).toContain("taking longer than usual");
|
|
85
|
+
expect(result).not.toContain("left");
|
|
85
86
|
});
|
|
86
87
|
|
|
87
|
-
it("
|
|
88
|
-
const result = formatProgress(
|
|
89
|
-
expect(result).toContain("
|
|
88
|
+
it("shows 'taking longer than usual' well past expected", () => {
|
|
89
|
+
const result = formatProgress(30_000_000, 6000, 10_000_000, 8);
|
|
90
|
+
expect(result).toContain("Still searching...");
|
|
91
|
+
expect(result).toContain("6s");
|
|
90
92
|
});
|
|
91
93
|
|
|
92
|
-
it("handles
|
|
94
|
+
it("handles very small elapsed time", () => {
|
|
93
95
|
const result = formatProgress(1_000_000, 1, 10_000_000, 8);
|
|
94
|
-
expect(result).toContain("
|
|
95
|
-
expect(result).toContain("
|
|
96
|
+
expect(result).toContain("Searching...");
|
|
97
|
+
expect(result).toContain("/s");
|
|
96
98
|
});
|
|
97
99
|
});
|
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
|
|
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
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);
|
package/ui-fallback.js
CHANGED
|
@@ -155,11 +155,16 @@ export async function runInteractiveUI(opts) {
|
|
|
155
155
|
let found;
|
|
156
156
|
try {
|
|
157
157
|
found = await bruteForce(userId, target, (attempts, elapsed, expected, workers) => {
|
|
158
|
-
const
|
|
159
|
-
const rate = attempts /
|
|
160
|
-
const rateStr = rate >= 1e6 ? `${(rate / 1e6).toFixed(1)}M` : `${(rate / 1e3).toFixed(1)}k`;
|
|
161
|
-
const
|
|
162
|
-
|
|
158
|
+
const elapsedSec = elapsed / 1000;
|
|
159
|
+
const rate = attempts / elapsedSec;
|
|
160
|
+
const rateStr = rate >= 1e6 ? `${(rate / 1e6).toFixed(1)}M/s` : `${(rate / 1e3).toFixed(1)}k/s`;
|
|
161
|
+
const fmtTime = (s) => s < 60 ? `${Math.round(s)}s` : `${Math.floor(s / 60)}m ${Math.round(s % 60)}s`;
|
|
162
|
+
if (attempts >= expected) {
|
|
163
|
+
process.stdout.write(`\r Still searching... ${fmtTime(elapsedSec)} | ${rateStr} | taking longer than usual`);
|
|
164
|
+
} else {
|
|
165
|
+
const remaining = (expected - attempts) / rate;
|
|
166
|
+
process.stdout.write(`\r Searching... ${fmtTime(elapsedSec)} | ${rateStr} | ~${fmtTime(remaining)} left`);
|
|
167
|
+
}
|
|
163
168
|
});
|
|
164
169
|
} catch (err) {
|
|
165
170
|
console.log(chalk.red(`\n✗ ${err.message}`));
|
package/ui.jsx
CHANGED
|
@@ -213,11 +213,16 @@ function SearchStep({ userId, target, bruteForce, onFound, onFail, isActive }) {
|
|
|
213
213
|
try {
|
|
214
214
|
found = await bruteForce(userId, target, (attempts, elapsed, expected, workers) => {
|
|
215
215
|
if (!ac.signal.aborted) {
|
|
216
|
-
const
|
|
217
|
-
const rate = attempts /
|
|
218
|
-
const rateStr = rate >= 1e6 ? `${(rate / 1e6).toFixed(1)}M` : `${(rate / 1e3).toFixed(1)}k`;
|
|
219
|
-
const
|
|
220
|
-
|
|
216
|
+
const elapsedSec = elapsed / 1000;
|
|
217
|
+
const rate = attempts / elapsedSec;
|
|
218
|
+
const rateStr = rate >= 1e6 ? `${(rate / 1e6).toFixed(1)}M/s` : `${(rate / 1e3).toFixed(1)}k/s`;
|
|
219
|
+
const fmtTime = (s) => s < 60 ? `${Math.round(s)}s` : `${Math.floor(s / 60)}m ${Math.round(s % 60)}s`;
|
|
220
|
+
if (attempts >= expected) {
|
|
221
|
+
setProgress(`Still searching... ${fmtTime(elapsedSec)} | ${rateStr} | taking longer than usual`);
|
|
222
|
+
} else {
|
|
223
|
+
const remaining = (expected - attempts) / rate;
|
|
224
|
+
setProgress(`Searching... ${fmtTime(elapsedSec)} | ${rateStr} | ~${fmtTime(remaining)} left`);
|
|
225
|
+
}
|
|
221
226
|
}
|
|
222
227
|
}, ac.signal);
|
|
223
228
|
} catch {
|