pi-hashline-edit-pro 0.3.9 → 0.4.0
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/package.json +2 -3
- package/src/hashline/hash.ts +27 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hashline-edit-pro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Strict hashline read/edit tool override for pi-coding-agent with hash-anchored edits (4-char, 24-bit)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"diff": "^8.0.2",
|
|
34
34
|
"file-type": "^21.3.0",
|
|
35
|
-
"
|
|
35
|
+
"xxhash-wasm": "^1.1.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@earendil-works/pi-coding-agent": ">=0.74.0",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
47
47
|
"@types/node": "^22.0.0",
|
|
48
|
-
"@types/xxhashjs": "^0.2.4",
|
|
49
48
|
"vitest": "^4.1.8"
|
|
50
49
|
}
|
|
51
50
|
}
|
package/src/hashline/hash.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
2
|
+
import xxhash from "xxhash-wasm";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const HASH_LENGTH = 4;
|
|
@@ -42,8 +42,33 @@ export const HASHLINE_BARE_PREFIX_RE = new RegExp(`^\\s*(${HASH_CHARS_CLASS})│
|
|
|
42
42
|
|
|
43
43
|
const RE_SIGNIFICANT = /[\p{L}\p{N}]/u;
|
|
44
44
|
|
|
45
|
+
// Lazy-initialized xxhash-wasm hasher. Initialization starts at module load
|
|
46
|
+
// time and completes in ~2ms. By the time any tool calls xxh32(), the hasher
|
|
47
|
+
// is ready.
|
|
48
|
+
type Hasher = { h32(input: string, seed?: number): number };
|
|
49
|
+
let hasherPromise: Promise<Hasher> | null = null;
|
|
50
|
+
let hasherSync: Hasher | null = null;
|
|
51
|
+
|
|
52
|
+
function getHasher(): Hasher {
|
|
53
|
+
if (hasherSync) return hasherSync;
|
|
54
|
+
// Fast path won't hit this in practice — the wasm init completes in ~2ms
|
|
55
|
+
// and no tool call happens at import time. But if it does, throw clearly.
|
|
56
|
+
throw new Error("xxhash-wasm not initialized yet. This should not happen.");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Start initialization immediately at module load time.
|
|
60
|
+
hasherPromise = xxhash().then((h) => {
|
|
61
|
+
hasherSync = h;
|
|
62
|
+
return h;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Export for tests that need to await readiness.
|
|
66
|
+
export function ensureHasherReady(): Promise<Hasher> {
|
|
67
|
+
return hasherPromise!;
|
|
68
|
+
}
|
|
69
|
+
|
|
45
70
|
function xxh32(input: string, seed = 0): number {
|
|
46
|
-
return
|
|
71
|
+
return getHasher().h32(input, seed) >>> 0;
|
|
47
72
|
}
|
|
48
73
|
|
|
49
74
|
const SYMBOL_DISCRIMINATOR = (lineNumber: number): string => `S${lineNumber}`;
|