buddy-reroll 0.3.5 → 0.3.7
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/lib/companion.js +5 -9
- package/lib/companion.test.js +6 -0
- package/lib/estimator.js +19 -20
- package/lib/estimator.test.js +21 -19
- package/lib/wyhash.js +88 -0
- package/lib/wyhash.test.js +50 -0
- package/package.json +1 -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/lib/companion.js
CHANGED
|
@@ -35,17 +35,11 @@ function mulberry32(seed) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
let h = 2166136261;
|
|
40
|
-
for (let i = 0; i < str.length; i++) {
|
|
41
|
-
h ^= str.charCodeAt(i);
|
|
42
|
-
h = Math.imul(h, 16777619);
|
|
43
|
-
}
|
|
44
|
-
return h >>> 0;
|
|
45
|
-
}
|
|
38
|
+
import { wyhash } from "./wyhash.js";
|
|
46
39
|
|
|
47
40
|
function hashString(value) {
|
|
48
|
-
return
|
|
41
|
+
if (typeof Bun !== "undefined") return Number(BigInt(Bun.hash(value)) & 0xffffffffn);
|
|
42
|
+
return Number(wyhash(0n, value) & 0xffffffffn);
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
function pick(rng, items) {
|
|
@@ -119,6 +113,8 @@ function findCurrentSalt(binaryData) {
|
|
|
119
113
|
for (const candidate of candidates) {
|
|
120
114
|
if (/[\d-]/.test(candidate)) return candidate;
|
|
121
115
|
}
|
|
116
|
+
// Brute-forced salts can be purely alphabetic — accept any candidate
|
|
117
|
+
if (candidates.size > 0) return candidates.values().next().value;
|
|
122
118
|
|
|
123
119
|
return null;
|
|
124
120
|
}
|
package/lib/companion.test.js
CHANGED
|
@@ -127,6 +127,12 @@ describe("findCurrentSalt", () => {
|
|
|
127
127
|
expect(findCurrentSalt(data)).toBe(patchedSalt);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
it("finds purely-alphabetic patched salt via context markers", () => {
|
|
131
|
+
const alphaSalt = "zaxZaEwKsjWqmfz";
|
|
132
|
+
const data = Buffer.from(`some data "${alphaSalt}" inspirationSeed more data`);
|
|
133
|
+
expect(findCurrentSalt(data)).toBe(alphaSalt);
|
|
134
|
+
});
|
|
135
|
+
|
|
130
136
|
it("returns null when no salt found", () => {
|
|
131
137
|
const data = Buffer.from("no salt here at all");
|
|
132
138
|
expect(findCurrentSalt(data)).toBeNull();
|
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/wyhash.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Wyhash v4.2 — Pure JavaScript implementation
|
|
2
|
+
// Ported from @pencroff-lab/wyhash-ts (Apache-2.0)
|
|
3
|
+
// https://github.com/pencroff-lab/wyhash-ts
|
|
4
|
+
//
|
|
5
|
+
// Produces identical output to Bun.hash() for string inputs.
|
|
6
|
+
|
|
7
|
+
const secret = [
|
|
8
|
+
0xa0761d6478bd642fn,
|
|
9
|
+
0xe7037ed1a0b428dbn,
|
|
10
|
+
0x8ebc6af09c88c6e3n,
|
|
11
|
+
0x589965cc75374cc3n,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function read(data, offset, bytes) {
|
|
15
|
+
let result = 0n;
|
|
16
|
+
for (let i = 0; i < bytes && offset + i < data.length; i++) {
|
|
17
|
+
result |= BigInt(data[offset + i]) << (BigInt(i) * 8n);
|
|
18
|
+
}
|
|
19
|
+
return BigInt.asUintN(64, result);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function mum(a, b) {
|
|
23
|
+
const x = a * b;
|
|
24
|
+
return [BigInt.asUintN(64, x), BigInt.asUintN(64, x >> 64n)];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function mix(a, b) {
|
|
28
|
+
const [aMul, bMul] = mum(a, b);
|
|
29
|
+
return aMul ^ bMul;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sum64(seed, input) {
|
|
33
|
+
let a, b;
|
|
34
|
+
let state0 = seed ^ mix(seed ^ secret[0], secret[1]);
|
|
35
|
+
const len = input.length;
|
|
36
|
+
|
|
37
|
+
if (len <= 16) {
|
|
38
|
+
if (len >= 4) {
|
|
39
|
+
const end = len - 4;
|
|
40
|
+
const quarter = (len >> 3) << 2;
|
|
41
|
+
a = (read(input, 0, 4) << 32n) | read(input, quarter, 4);
|
|
42
|
+
b = (read(input, end, 4) << 32n) | read(input, end - quarter, 4);
|
|
43
|
+
} else if (len > 0) {
|
|
44
|
+
a = (BigInt(input[0]) << 16n) | (BigInt(input[len >> 1]) << 8n) | BigInt(input[len - 1]);
|
|
45
|
+
b = 0n;
|
|
46
|
+
} else {
|
|
47
|
+
a = 0n;
|
|
48
|
+
b = 0n;
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
const state = [state0, state0, state0];
|
|
52
|
+
let i = 0;
|
|
53
|
+
|
|
54
|
+
if (len >= 48) {
|
|
55
|
+
while (i + 48 < len) {
|
|
56
|
+
for (let j = 0; j < 3; j++) {
|
|
57
|
+
const aRound = read(input, i + 8 * (2 * j), 8);
|
|
58
|
+
const bRound = read(input, i + 8 * (2 * j + 1), 8);
|
|
59
|
+
state[j] = mix(aRound ^ secret[j + 1], bRound ^ state[j]);
|
|
60
|
+
}
|
|
61
|
+
i += 48;
|
|
62
|
+
}
|
|
63
|
+
state[0] ^= state[1] ^ state[2];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const remaining = input.subarray(i);
|
|
67
|
+
let k = 0;
|
|
68
|
+
while (k + 16 < remaining.length) {
|
|
69
|
+
state[0] = mix(read(remaining, k, 8) ^ secret[1], read(remaining, k + 8, 8) ^ state[0]);
|
|
70
|
+
k += 16;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
a = read(input, len - 16, 8);
|
|
74
|
+
b = read(input, len - 8, 8);
|
|
75
|
+
state0 = state[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
a ^= secret[1];
|
|
79
|
+
b ^= state0;
|
|
80
|
+
[a, b] = mum(a, b);
|
|
81
|
+
return mix(a ^ secret[0] ^ BigInt(len), b ^ secret[1]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const encoder = new TextEncoder();
|
|
85
|
+
|
|
86
|
+
export function wyhash(seed, key) {
|
|
87
|
+
return sum64(BigInt.asUintN(64, seed), encoder.encode(key));
|
|
88
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import { wyhash } from "./wyhash.js";
|
|
3
|
+
|
|
4
|
+
describe("wyhash", () => {
|
|
5
|
+
it("matches Bun.hash for empty string", () => {
|
|
6
|
+
expect(wyhash(0n, "")).toBe(BigInt(Bun.hash("")));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("matches Bun.hash for short strings", () => {
|
|
10
|
+
const cases = ["a", "ab", "abc", "hello", "hello world"];
|
|
11
|
+
for (const s of cases) {
|
|
12
|
+
expect(wyhash(0n, s)).toBe(BigInt(Bun.hash(s)));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("matches Bun.hash for companion-realistic inputs", () => {
|
|
17
|
+
const salts = ["friend-2026-401", "friend-2026-abc", "xxxxxxxxxxxxxxx"];
|
|
18
|
+
const userIds = ["anon", "fd50b3fd-1234-5678-9abc-def012345678"];
|
|
19
|
+
for (const uid of userIds) {
|
|
20
|
+
for (const salt of salts) {
|
|
21
|
+
const key = uid + salt;
|
|
22
|
+
expect(wyhash(0n, key)).toBe(BigInt(Bun.hash(key)));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("matches Bun.hash for long strings (>48 bytes)", () => {
|
|
28
|
+
const long = "a".repeat(100);
|
|
29
|
+
expect(wyhash(0n, long)).toBe(BigInt(Bun.hash(long)));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("matches Bun.hash for unicode strings", () => {
|
|
33
|
+
const cases = ["한글", "αβγδ", "🎮🐉✨"];
|
|
34
|
+
for (const s of cases) {
|
|
35
|
+
expect(wyhash(0n, s)).toBe(BigInt(Bun.hash(s)));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns bigint", () => {
|
|
40
|
+
expect(typeof wyhash(0n, "test")).toBe("bigint");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("is deterministic", () => {
|
|
44
|
+
expect(wyhash(0n, "test")).toBe(wyhash(0n, "test"));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("produces different output for different inputs", () => {
|
|
48
|
+
expect(wyhash(0n, "hello")).not.toBe(wyhash(0n, "world"));
|
|
49
|
+
});
|
|
50
|
+
});
|
package/package.json
CHANGED
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 {
|