@bash0816/claude-code 2.1.285 → 2.1.287

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 CHANGED
@@ -37,7 +37,7 @@ npm が `claude` bin link を管理する状態になれば、通常の `npm ins
37
37
  Latest audited version / 最新監査済み版:
38
38
 
39
39
  ```sh
40
- npm install -g @bash0816/claude-code@2.1.284
40
+ npm install -g @bash0816/claude-code@2.1.286
41
41
  ```
42
42
 
43
43
  ## Update / 更新
@@ -2443,7 +2443,7 @@
2443
2443
  "entry_format": "esm-chunked",
2444
2444
  "tarball_integrity": "sha512-vAvIr+MVnm5IrSq8KoJrZkoG3BFpLvVEqfrx15w7hWW+gcSYHPvN33lfkzXvs5L8MYXxNW0Ae86MLiCH+x4ldQ==",
2445
2445
  "tarball_sha256": "f8a0dc539db3c860bdd12a345a51db798908b089a1696f9720c57776dace4cbf",
2446
- "status": "offset_discovered",
2446
+ "status": "termux_verified",
2447
2447
  "num_modules": 2352,
2448
2448
  "byte_count": 151006916,
2449
2449
  "cycle_hoists": [
@@ -2473,6 +2473,80 @@
2473
2473
  "expectedOccurrences": 1
2474
2474
  }
2475
2475
  ]
2476
+ },
2477
+ "2.1.286": {
2478
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.286",
2479
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.286",
2480
+ "entry_format": "esm-chunked",
2481
+ "tarball_integrity": "sha512-dHQ/ObyC4jaGHVk+gFE8P8PALMIVLhQSyhiC3y3kkuLp0H0MHgLxHt/srQ3zJs892ClDbtl1swxv4bw1ioruZA==",
2482
+ "tarball_sha256": "ab87947d331c045aa6fc3c7934d31d8cca5fcdf676d10bcae0b0adfc5210f397",
2483
+ "status": "termux_verified",
2484
+ "num_modules": 2352,
2485
+ "byte_count": 152348702,
2486
+ "cycle_hoists": [
2487
+ {
2488
+ "file": "chunk-qe2mz88r.js",
2489
+ "targetModule": "chunk-n4h7ertc.js",
2490
+ "expectedOccurrences": 1,
2491
+ "assertProperties": [
2492
+ "default"
2493
+ ]
2494
+ },
2495
+ {
2496
+ "file": "chunk-qe2mz88r.js",
2497
+ "targetModule": "chunk-y315rak0.js",
2498
+ "expectedOccurrences": 1,
2499
+ "assertProperties": []
2500
+ }
2501
+ ],
2502
+ "cycle_hoists_skipped_assets": [
2503
+ "chart.umd.min.js",
2504
+ "hljsBundle.generated.min.js",
2505
+ "mermaid.min.js"
2506
+ ],
2507
+ "hooks_standalone_patches": [
2508
+ {
2509
+ "file": "chunk-fdyfv9ag.js",
2510
+ "expectedOccurrences": 1
2511
+ }
2512
+ ]
2513
+ },
2514
+ "2.1.287": {
2515
+ "wrapper_spec": "@anthropic-ai/claude-code@2.1.287",
2516
+ "native_spec": "@anthropic-ai/claude-code-linux-arm64@2.1.287",
2517
+ "entry_format": "esm-chunked",
2518
+ "tarball_integrity": "sha512-MU3ReK1kjstDmjEOzhFZaphh2AVUKnPaik6lOV0WLs3/mOM7mE/mqkdcQ/Sv0KwHH5MnOhSkIjCEl0/8tr+vRg==",
2519
+ "tarball_sha256": "33ae16d93e1e82b9de10684b540650a9ffbb654eb317e4bfc1ff0f932816f1bc",
2520
+ "status": "offset_discovered",
2521
+ "num_modules": 2387,
2522
+ "byte_count": 154994332,
2523
+ "cycle_hoists": [
2524
+ {
2525
+ "file": "chunk-gakypdfc.js",
2526
+ "targetModule": "chunk-1wr3731n.js",
2527
+ "expectedOccurrences": 1,
2528
+ "assertProperties": [
2529
+ "default"
2530
+ ]
2531
+ },
2532
+ {
2533
+ "file": "chunk-gakypdfc.js",
2534
+ "targetModule": "chunk-g2519ff0.js",
2535
+ "expectedOccurrences": 1,
2536
+ "assertProperties": []
2537
+ }
2538
+ ],
2539
+ "cycle_hoists_skipped_assets": [
2540
+ "chart.umd.min.js",
2541
+ "hljsBundle.generated.min.js",
2542
+ "mermaid.min.js"
2543
+ ],
2544
+ "hooks_standalone_patches": [
2545
+ {
2546
+ "file": "chunk-9fhg5qd1.js",
2547
+ "expectedOccurrences": 1
2548
+ }
2549
+ ]
2476
2550
  }
2477
2551
  }
2478
2552
  }
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "manifest_version": 1,
3
3
  "package_name": "@bash0816/claude-code",
4
- "latest_audited_version": "2.1.284",
5
- "latest_candidate_version": "2.1.285",
6
- "previous_stable_version": "2.1.283",
4
+ "latest_audited_version": "2.1.286",
5
+ "latest_candidate_version": "2.1.287",
6
+ "previous_stable_version": "2.1.285",
7
7
  "stable_pinned_version": "2.1.220-2",
8
8
  "manifest_url": "https://raw.githubusercontent.com/bash0816/ClaudeCode-Termux/main/config/claude-termux-release-manifest.json"
9
9
  }
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+ const test = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const { execFileSync } = require('node:child_process');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+ const cwd = path.resolve(__dirname, '..');
8
+
9
+ test('npm pack excludes upstream test fixtures and includes runtime files', () => {
10
+ assert.ok(fs.existsSync(path.join(cwd, 'lib/test-fixtures/upstream-2.1.287/chunk-8h7qs60z.mjs')));
11
+ const output = execFileSync('npm', ['pack', '--dry-run', '--json'], { cwd, encoding: 'utf8' });
12
+ const files = JSON.parse(output)[0].files.map(file => file.path);
13
+ assert.equal(files.some(file => file.startsWith('lib/test-fixtures/')), false);
14
+ assert.ok(files.includes('bin/claude'));
15
+ assert.ok(files.includes('lib/termux-run-claude-native.sh'));
16
+ });
@@ -0,0 +1,184 @@
1
+ 'use strict';
2
+ const test = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const vm = require('node:vm');
7
+ const crypto = require('node:crypto');
8
+ const zlib = require('node:zlib');
9
+
10
+ const root = path.resolve(__dirname, '..');
11
+ const fixtureDir = path.join(__dirname, 'test-fixtures/upstream-2.1.287');
12
+ const shim = fs.readFileSync(path.join(__dirname, 'termux-run-claude-native.sh'), 'utf8');
13
+ const shaExpected = '59ad1d5afd8bc3db3a68e12c6611c318f894a85dc55b465e90aebb583a2b94f6';
14
+
15
+ function payloadOf(source) {
16
+ const marker = '// ---- payload ----\n';
17
+ const at = source.indexOf(marker);
18
+ assert.notEqual(at, -1, 'fixture payload marker exists');
19
+ return source.slice(at + marker.length);
20
+ }
21
+ function headerless(file) { return payloadOf(fs.readFileSync(file, 'utf8')); }
22
+ function sourceFromFixture() {
23
+ const file = path.join(fixtureDir, 'chunk-8h7qs60z.mjs');
24
+ const fixture = headerless(file);
25
+ const upstreamImport = 'import{uze}from"/$bunfs/root/chunk-ncm29pd2.js";import{k}from"/$bunfs/root/chunk-gwr1he3z.js";import{Rt,B,Od}from"/$bunfs/root/chunk-jx85q2yb.js";import{hd}from"/$bunfs/root/chunk-wpk2k2yt.js";import{Pg}from"/$bunfs/root/chunk-rs5m5t99.js";';
26
+ const localImport = 'import{uze,k,Rt,B,Od,hd,Pg}from"./stubs.mjs";';
27
+ assert.equal((fixture.match(new RegExp(localImport.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')) || []).length, 1);
28
+ return fixture.replace(localImport, upstreamImport);
29
+ }
30
+ function balanced(source, at) {
31
+ const start = source.indexOf('{', at); let depth = 0, quote = '', escape = false;
32
+ for (let i = start; i < source.length; i++) {
33
+ const c = source[i];
34
+ if (quote) { if (escape) escape = false; else if (c === '\\') escape = true; else if (c === quote) quote = ''; continue; }
35
+ if (c === '"' || c === "'" || c === '`') quote = c;
36
+ else if (c === '{') depth++;
37
+ else if (c === '}' && --depth === 0) return source.slice(start, i + 1);
38
+ }
39
+ throw new Error('unbalanced object');
40
+ }
41
+ function implementations() {
42
+ const blocks = [...shim.matchAll(/cat <<'NODE' > "\$_(?:helper|bootstrap)"([\s\S]*?)\nNODE/g)].map(m => m[1]);
43
+ assert.equal(blocks.length, 2, 'both shim NODE heredocs found');
44
+ const sha = blocks.flatMap(block => [...block.matchAll(/SHA256:\s*\{/g)].map(m => balanced(block, m.index + m[0].indexOf('{'))));
45
+ assert.equal(sha.length, 4, 'four SHA256 implementations extracted');
46
+ const crc = blocks.flatMap(block => [...block.matchAll(/stableHash\.crc32\s*=\s*function\s+bunHashCrc32/g)].map(m => {
47
+ const start = block.lastIndexOf('function stableHash(value, seed) {', m.index);
48
+ const end = block.indexOf('\n};', start) + 3;
49
+ const close = block.indexOf('};', m.index) + 2;
50
+ assert.ok(start >= 0 && end > 2 && close > 1);
51
+ return `${block.slice(start, end)}\n${block.slice(m.index, close)}\nmodule.exports=stableHash.crc32;`;
52
+ }));
53
+ assert.equal(crc.length, 2, 'two crc32 implementations extracted');
54
+ const shaFns = sha.map(code => {
55
+ const m = { exports: {} };
56
+ vm.runInNewContext(`module.exports=${code}`, { module: m, require, Buffer, Uint8Array, ArrayBuffer });
57
+ return m.exports.hash;
58
+ });
59
+ const crcFns = crc.map(code => { const m = { exports: {} }; vm.runInNewContext(code, { module: m, require, Buffer, Uint8Array, ArrayBuffer }); return m.exports; });
60
+ return { shaFns, crcFns };
61
+ }
62
+ const { shaFns, crcFns } = implementations();
63
+ function bunFor(sha, crc) { return { SHA256: { hash: sha }, hash: { crc32: crc } }; }
64
+ function bodyOf(length, messageBlockLength = 131072) {
65
+ const messages = '"messages":[', system = '],"system":';
66
+ const prefix = 'x'.repeat(131071);
67
+ const messageSegment = messages + 'm'.repeat(messageBlockLength - messages.length);
68
+ const tailLength = length - prefix.length - messageSegment.length - system.length;
69
+ assert.ok(tailLength >= 0);
70
+ return prefix + messageSegment + system + 's'.repeat(tailLength);
71
+ }
72
+ function gunzipMatches(gzip, body) {
73
+ assert.equal(gzip[0], 0x1f); assert.equal(gzip[1], 0x8b);
74
+ assert.ok(Buffer.from(gzip).toString('hex').match(/0000ffff/g)?.length >= 2, 'sync flush markers');
75
+ assert.deepEqual(zlib.gunzipSync(gzip), Buffer.from(body));
76
+ }
77
+
78
+ // The fixture source is checked byte-for-byte after reversing the sole import replacement.
79
+ test('upstream fixtures preserve and verify their source bytes', async () => {
80
+ for (const name of fs.readdirSync(fixtureDir).filter(name => name.endsWith('.mjs'))) {
81
+ const file = path.join(fixtureDir, name), source = fs.readFileSync(file, 'utf8');
82
+ const declared = source.match(/^\/\/ (?:(?:Local )?[Ff]ixture payload sha256|Extracted payload sha256|Extracted payload SHA256)(?: \([^)]*\))?: ([a-f0-9]{64})$/m)?.[1];
83
+ assert.ok(declared, `${name} declares payload SHA256`);
84
+ assert.equal(crypto.createHash('sha256').update(payloadOf(source)).digest('hex'), declared, `${name} payload SHA256`);
85
+ const payload = payloadOf(source);
86
+ const mutations = name === 'xm-excerpt.mjs' ? [['Y8=524288', 'Y8=524289']]
87
+ : name === 'km-excerpt.mjs' ? [['function KM(', 'function KN(']]
88
+ : name === 'chunk-8h7qs60z.mjs' ? [['function A2r(', 'function A2s(']]
89
+ : name === 'stubs.mjs' ? [['210000', '210001']] : [];
90
+ assert.ok(mutations.length, `${name} has a payload mutation`);
91
+ for (const [before, after] of mutations) {
92
+ assert.ok(payload.includes(before), `${name} mutation target exists`);
93
+ const mutated = payload.replace(before, after);
94
+ assert.notEqual(crypto.createHash('sha256').update(mutated).digest('hex'), declared, `${name} changed payload fails its declared SHA256`);
95
+ }
96
+ }
97
+ const originalChunk = sourceFromFixture();
98
+ assert.equal(crypto.createHash('sha256').update(originalChunk).digest('hex'), shaExpected);
99
+ const kmPath = path.join(root, 'lib/test-fixtures/upstream-2.1.287/km-excerpt.mjs');
100
+ const kmSrc = fs.readFileSync(kmPath, 'utf8');
101
+ const excerpt = payloadOf(kmSrc);
102
+ assert.equal(crypto.createHash('sha256').update(excerpt).digest('hex'), '363763f3c9f2a7e76aba7f4fc4759337f11f35e2340e8f234e291cf5e911f0cf');
103
+ assert.ok(excerpt.includes('function KM(') && excerpt.includes('function YM()'));
104
+ });
105
+
106
+ test('upstream fixture recheck against extracted files', { skip: process.env.UPSTREAM_EXTRACT_DIR ? false : 'UPSTREAM_EXTRACT_DIR is unset; repository fixture hashes were checked above' }, () => {
107
+ const original = fs.readFileSync(path.join(process.env.UPSTREAM_EXTRACT_DIR, 'chunk-8h7qs60z.js'), 'utf8');
108
+ assert.equal(crypto.createHash('sha256').update(original).digest('hex'), shaExpected);
109
+ });
110
+
111
+ test('shim SHA256 and CRC32 implementations work in every combination', () => {
112
+ for (const [si, sha] of shaFns.entries()) for (const [ci, crc] of crcFns.entries()) {
113
+ globalThis.Bun = bunFor(sha, crc);
114
+ assert.equal(Bun.SHA256.hash('abc', 'base64'), 'ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=');
115
+ assert.equal(Bun.hash.crc32('123456789'), 0xcbf43926, `sha ${si}, crc ${ci}`);
116
+ }
117
+ });
118
+
119
+ test('mode 2 upstream A2r and Fzo gzip blocks round-trip at boundaries and with a dictionary', async () => {
120
+ const { A2r, Fzo } = await import('./test-fixtures/upstream-2.1.287/chunk-8h7qs60z.mjs');
121
+ globalThis.Bun = bunFor(shaFns[0], crcFns[0]);
122
+ const clock = { monotonicNow: () => performance.now(), setTimeout: (fn, ms, opts) => { const t = setTimeout(fn, ms); if (opts?.unref) t.unref(); return () => clearTimeout(t); } };
123
+ for (const [length, boundary] of [[524288, 131072], [524288, 131071], [524288, 131073], [524289, 131072], [655359, 131072], [655360, 131072], [655361, 131072]]) {
124
+ const body = bodyOf(length, boundary), store = { blocks: new Map(), storedBytes: 0, maxStoredBytes: 210000, generation: 0, pooledCompression: Promise.resolve(), cancelIdleDrop: undefined };
125
+ const prepared = A2r({ body: Buffer.from(body), level: 6, store, clock });
126
+ const sizes = prepared.blocks.map(block => block.end - block.start);
127
+ assert.ok(boundary <= 131072 ? sizes.includes(boundary) : sizes.includes(131072) && sizes.includes(1), `128 KiB boundary ${boundary}`);
128
+ assert.ok(prepared.blocks.some(block => block.dictionaryStart < block.start), 'later block uses a preset dictionary');
129
+ const compressed = await Fzo(prepared, store, clock);
130
+ gunzipMatches(compressed, body);
131
+ const changed = body.slice(0, -16) + 'changed-tail-123';
132
+ const next = A2r({ body: Buffer.from(changed), level: 6, store, clock });
133
+ const compressed2 = await Fzo(next, store, clock);
134
+ assert.ok(next.reusedBlockCount > 0, `changed tail reuses blocks at ${length}`);
135
+ gunzipMatches(compressed2, changed);
136
+ }
137
+ });
138
+
139
+ test('mode 1 XM selects runtime first, then sends cached block gzip; mode 2 compresses immediately', async () => {
140
+ const { A2r, Fzo, Ls: blockLs, P2r } = await import('./test-fixtures/upstream-2.1.287/chunk-8h7qs60z.mjs');
141
+ const { XM, YM } = await import('./test-fixtures/upstream-2.1.287/xm-excerpt.mjs');
142
+ const body = bodyOf(600000), store = { blocks: new Map(), storedBytes: 0, maxStoredBytes: 900000, generation: 0, pooledCompression: Promise.resolve(), cancelIdleDrop: undefined };
143
+ const state = { fired: new Set(), once(key) { if (this.fired.has(key)) return false; this.fired.add(key); return true; }, gzipRequestBody: { blockStore: store, blocksSwitchedOff: false, blocksBuildGeneration: undefined, blockGzippedResponses: new WeakSet() } };
144
+ const errors = [], logs = [];
145
+ const clock = { monotonicNow: () => performance.now(), setTimeout: (fn, ms, opts) => { const timer = setTimeout(fn, ms); if (opts?.unref) timer.unref(); return () => clearTimeout(timer); } };
146
+ globalThis.Bun = bunFor(shaFns[1], crcFns[1]); globalThis.a = { CLAUDE_CODE_GZIP_REQUEST_BODY_BLOCKS: 1 }; globalThis.C = () => 0; globalThis.q8 = 'tengu_buzzing_pike';
147
+ globalThis.P2r=P2r; globalThis.A2r=A2r; globalThis.Fzo=Fzo; globalThis.Ls=()=>state; globalThis.LBt=()=>{}; globalThis.Z8=()=>()=>{}; globalThis.QM=(err)=>{state.qmError=String(err)+' '+err?.stack}; globalThis.OXe=class extends Error{}; globalThis.PXe=()=>{}; globalThis.t=(...args)=>logs.push(args); globalThis.p=()=>{}; globalThis.y=()=>{}; globalThis.d=(...args)=>errors.push(args);
148
+ assert.equal(YM(),1);
149
+ const init = { method:'POST', headers:{'content-type':'application/json'}, compress:'gzip', body, url:'https://api.anthropic.com/v1/messages' };
150
+ const first = await XM(init, clock); assert.equal(first.init,init); assert.equal(first.init.headers['Content-Encoding'],undefined);
151
+ assert.equal(state.gzipRequestBody.blocksSwitchedOff,false); assert.equal(typeof first.afterResponse,'function');
152
+ first.afterResponse({ok:true});
153
+ const keepAlive=setInterval(()=>{},50), deadline=performance.now()+10000;
154
+ while(store.blocks.size===0 && performance.now()<deadline) await new Promise(resolve=>setTimeout(resolve,10)); clearInterval(keepAlive);
155
+ assert.ok(store.blocks.size>0,'real timer populated cache');
156
+ const second=await XM(init,clock); assert.equal(typeof second.init.headers.get, 'function', `XM did not select gzip: cached ${store.blocks.size} blocks, switchedOff=${state.gzipRequestBody.blocksSwitchedOff}, error=${state.qmError}`); assert.equal(second.init.headers.get('Content-Encoding'),'gzip');
157
+ assert.deepEqual(zlib.gunzipSync(second.init.body),Buffer.from(body)); assert.equal(state.gzipRequestBody.blocksSwitchedOff,false);
158
+ globalThis.a.CLAUDE_CODE_GZIP_REQUEST_BODY_BLOCKS=2;
159
+ const mode2=await XM(init,clock); assert.equal(mode2.init.headers.get('Content-Encoding'),'gzip'); assert.deepEqual(zlib.gunzipSync(mode2.init.body),Buffer.from(body));
160
+ assert.deepEqual(errors, [], 'normal XM paths did not report unexpected errors');
161
+ assert.deepEqual(logs, [], 'normal XM paths did not log unexpected warnings');
162
+ for (const bun of [{hash:{crc32:crcFns[0]}},{SHA256:{hash:shaFns[0]}}]) {
163
+ globalThis.Bun=bun; state.gzipRequestBody.blocksSwitchedOff=false; state.gzipRequestBody.blockStore={...store,blocks:new Map(),storedBytes:0,generation:0};
164
+ const errorsBefore=errors.length, logsBefore=logs.length;
165
+ const fallback=await XM(init,clock); assert.equal(fallback.init,init); assert.equal(fallback.init.headers['Content-Encoding'],undefined); assert.equal(state.gzipRequestBody.blocksSwitchedOff,'until_next_conversation');
166
+ assert.equal(errors.length, errorsBefore+1, 'mutant failure was reported to the error handler');
167
+ assert.equal(logs.length, logsBefore+1, 'mutant failure was logged by the upstream fallback');
168
+ }
169
+ for(const key of ['a','C','q8','P2r','A2r','Fzo','Ls','LBt','Z8','QM','OXe','PXe','t','p','y','d']) delete globalThis[key];
170
+ });
171
+
172
+ test('mutants without SHA256 or CRC32 fail or take the upstream failure path', async () => {
173
+ const { A2r, Fzo } = await import('./test-fixtures/upstream-2.1.287/chunk-8h7qs60z.mjs');
174
+ const body = Buffer.from(bodyOf(524288));
175
+ globalThis.Bun = { hash: { crc32: crcFns[0] } };
176
+ const store = { blocks: new Map(), storedBytes: 0, maxStoredBytes: 210000, generation: 0, pooledCompression: Promise.resolve(), cancelIdleDrop: undefined };
177
+ assert.throws(() => A2r({ body, level: 6, store, clock: { monotonicNow: () => performance.now(), setTimeout } }), /hash/);
178
+ globalThis.Bun = { SHA256: { hash: shaFns[0] } };
179
+ globalThis.Bun = bunFor(shaFns[0], crcFns[0]);
180
+ const clock = { monotonicNow: () => performance.now(), setTimeout: (fn, ms, options) => { const t = setTimeout(fn, ms); if (options?.unref) t.unref(); return () => clearTimeout(t); } };
181
+ const state = A2r({ body, level: 6, store, clock });
182
+ globalThis.Bun = { SHA256: { hash: shaFns[0] } };
183
+ await assert.rejects(Fzo(state, store, clock), /crc32/);
184
+ });
@@ -311,6 +311,20 @@ stableHash.xxHash64 = function bunHashXxHash64(value, seed) {
311
311
  return (BigInt(hi) << 32n) | BigInt(lo);
312
312
  };
313
313
 
314
+ stableHash.crc32 = function bunHashCrc32(data, seed) {
315
+ let buf;
316
+ if (typeof data === 'string') {
317
+ buf = Buffer.from(data, 'utf8');
318
+ } else if (data instanceof ArrayBuffer) {
319
+ buf = Buffer.from(data);
320
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
321
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
322
+ } else {
323
+ buf = Buffer.from(data);
324
+ }
325
+ return require('node:zlib').crc32(buf, seed === undefined ? 0 : seed >>> 0);
326
+ };
327
+
314
328
  function replaceRequired(source, pattern, replacement, label, expectedCount) {
315
329
  const text = String(source);
316
330
  const matches = text.match(pattern);
@@ -686,6 +700,26 @@ async function esmChunkedMain() {
686
700
  wrapAnsi,
687
701
  stripANSI,
688
702
  hash: stableHash,
703
+ SHA256: {
704
+ hash(data, encoding) {
705
+ let buf;
706
+ if (typeof data === 'string') {
707
+ buf = Buffer.from(data, 'utf8');
708
+ } else if (data instanceof ArrayBuffer) {
709
+ buf = Buffer.from(data);
710
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
711
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
712
+ } else {
713
+ buf = Buffer.from(data);
714
+ }
715
+ const digest = require('node:crypto').createHash('sha256').update(buf).digest();
716
+ if (encoding) {
717
+ return digest.toString(encoding);
718
+ } else {
719
+ return new Uint8Array(digest);
720
+ }
721
+ }
722
+ },
689
723
  which: (cmd) => {
690
724
  try {
691
725
  return require('child_process').execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
@@ -960,6 +994,26 @@ async function legacyCjsMain() {
960
994
  wrapAnsi,
961
995
  stripANSI,
962
996
  hash: stableHash,
997
+ SHA256: {
998
+ hash(data, encoding) {
999
+ let buf;
1000
+ if (typeof data === 'string') {
1001
+ buf = Buffer.from(data, 'utf8');
1002
+ } else if (data instanceof ArrayBuffer) {
1003
+ buf = Buffer.from(data);
1004
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
1005
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
1006
+ } else {
1007
+ buf = Buffer.from(data);
1008
+ }
1009
+ const digest = require('node:crypto').createHash('sha256').update(buf).digest();
1010
+ if (encoding) {
1011
+ return digest.toString(encoding);
1012
+ } else {
1013
+ return new Uint8Array(digest);
1014
+ }
1015
+ }
1016
+ },
963
1017
  which: (cmd) => {
964
1018
  try {
965
1019
  return _realChild.execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
@@ -1373,6 +1427,20 @@ stableHash.xxHash64 = function bunHashXxHash64(value, seed) {
1373
1427
  return (BigInt(hi) << 32n) | BigInt(lo);
1374
1428
  };
1375
1429
 
1430
+ stableHash.crc32 = function bunHashCrc32(data, seed) {
1431
+ let buf;
1432
+ if (typeof data === 'string') {
1433
+ buf = Buffer.from(data, 'utf8');
1434
+ } else if (data instanceof ArrayBuffer) {
1435
+ buf = Buffer.from(data);
1436
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
1437
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
1438
+ } else {
1439
+ buf = Buffer.from(data);
1440
+ }
1441
+ return require('node:zlib').crc32(buf, seed === undefined ? 0 : seed >>> 0);
1442
+ };
1443
+
1376
1444
  function replaceRequired(source, pattern, replacement, label, expectedCount) {
1377
1445
  const text = String(source);
1378
1446
  const matches = text.match(pattern);
@@ -1748,6 +1816,26 @@ async function esmChunkedMain() {
1748
1816
  wrapAnsi,
1749
1817
  stripANSI,
1750
1818
  hash: stableHash,
1819
+ SHA256: {
1820
+ hash(data, encoding) {
1821
+ let buf;
1822
+ if (typeof data === 'string') {
1823
+ buf = Buffer.from(data, 'utf8');
1824
+ } else if (data instanceof ArrayBuffer) {
1825
+ buf = Buffer.from(data);
1826
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
1827
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
1828
+ } else {
1829
+ buf = Buffer.from(data);
1830
+ }
1831
+ const digest = require('node:crypto').createHash('sha256').update(buf).digest();
1832
+ if (encoding) {
1833
+ return digest.toString(encoding);
1834
+ } else {
1835
+ return new Uint8Array(digest);
1836
+ }
1837
+ }
1838
+ },
1751
1839
  which: (cmd) => {
1752
1840
  try {
1753
1841
  return require('child_process').execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
@@ -2024,6 +2112,26 @@ async function legacyCjsMain() {
2024
2112
  wrapAnsi,
2025
2113
  stripANSI,
2026
2114
  hash: stableHash,
2115
+ SHA256: {
2116
+ hash(data, encoding) {
2117
+ let buf;
2118
+ if (typeof data === 'string') {
2119
+ buf = Buffer.from(data, 'utf8');
2120
+ } else if (data instanceof ArrayBuffer) {
2121
+ buf = Buffer.from(data);
2122
+ } else if (data && typeof data === 'object' && data.buffer instanceof ArrayBuffer) {
2123
+ buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
2124
+ } else {
2125
+ buf = Buffer.from(data);
2126
+ }
2127
+ const digest = require('node:crypto').createHash('sha256').update(buf).digest();
2128
+ if (encoding) {
2129
+ return digest.toString(encoding);
2130
+ } else {
2131
+ return new Uint8Array(digest);
2132
+ }
2133
+ }
2134
+ },
2027
2135
  which: (cmd) => {
2028
2136
  try {
2029
2137
  return _realChild.execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
@@ -2242,6 +2242,45 @@ test('stableHash.xxHash64 implementation (G2 v3 implementation)', () => {
2242
2242
  }
2243
2243
  });
2244
2244
 
2245
+ test('stableHash.crc32 and Bun.SHA256 implementation (all shim additions)', () => {
2246
+ const crypto = require('node:crypto');
2247
+ const helperBlock = extractBlock("cat <<'NODE' > \"$_helper\"", '\n export ENABLE_CLAUDEAI_MCP_SERVERS=');
2248
+ const bootstrapBlock = extractBlock("cat <<'NODE' > \"$_bootstrap\"", '\n export ENABLE_CLAUDEAI_MCP_SERVERS=');
2249
+ function balancedObject(text, start) {
2250
+ let depth = 0, quote = '', escaped = false;
2251
+ for (let i = start; i < text.length; i++) { const c = text[i];
2252
+ if (quote) { if (escaped) escaped = false; else if (c === '\\\\') escaped = true; else if (c === quote) quote = ''; continue; }
2253
+ if (c === '"' || c === "'" || c === '`') quote = c; else if (c === '{') depth++; else if (c === '}' && --depth === 0) return text.slice(start, i + 1);
2254
+ } throw new Error('unbalanced object');
2255
+ }
2256
+ const blocks = [helperBlock, bootstrapBlock];
2257
+ const shaSources = blocks.flatMap(block => [...block.matchAll(/SHA256:\s*\{/g)].map(m => balancedObject(block, m.index + m[0].indexOf('{'))));
2258
+ const crcSources = blocks.flatMap(block => [...block.matchAll(/stableHash\.crc32\s*=\s*function\s+bunHashCrc32/g)].map(m => {
2259
+ const start = block.lastIndexOf('function stableHash(value, seed) {', m.index);
2260
+ return block.slice(start, block.indexOf('\n};', start) + 3) + '\n' + block.slice(m.index, block.indexOf('};', m.index) + 2) + '\nmodule.exports=stableHash.crc32;';
2261
+ }));
2262
+ assert.equal(shaSources.length, 4); assert.equal(crcSources.length, 2);
2263
+ const shaFns = shaSources.map(source => { const module = { exports: {} }; vm.runInNewContext(`module.exports=${source}`, { module, require, Buffer, Uint8Array, ArrayBuffer }); return module.exports.hash; });
2264
+ const crcFns = crcSources.map(source => { const module = { exports: {} }; vm.runInNewContext(source, { module, require, Buffer, Uint8Array, ArrayBuffer }); return module.exports; });
2265
+ const digest = value => crypto.createHash('sha256').update(value).digest('hex');
2266
+ const expected = Buffer.from('known-input'), backing = Buffer.from('!known-input?');
2267
+ const u16Backing = new Uint8Array([33,107,110,111,119,110,45,105,110,112,117,116,63]);
2268
+ const u16Input = new Uint16Array(u16Backing.buffer, 2, 5);
2269
+ const u16Digest = digest(Buffer.from(u16Input.buffer, u16Input.byteOffset, u16Input.byteLength));
2270
+ const inputs = [['string','known-input',digest(expected)], ['Buffer',expected,digest(expected)], ['ArrayBuffer',expected.buffer.slice(expected.byteOffset,expected.byteOffset+expected.byteLength),digest(expected)], ['DataView',new DataView(backing.buffer,backing.byteOffset+1,11),digest(expected)], ['Uint8Array',new Uint8Array(expected),digest(expected)], ['offset subarray',backing.subarray(1,12),digest(expected)], ['Uint16Array',u16Input,u16Digest]];
2271
+ for (const [i, sha] of shaFns.entries()) { for (const [name,value,want] of inputs) assert.equal(sha(value,'hex'),want,`SHA256 #${i+1} ${name}`); assert.equal(sha('abc','base64'),'ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0='); const raw=sha('abc'); assert.ok(raw instanceof Uint8Array,`SHA256 #${i+1} default result is Uint8Array`); assert.equal(raw.length,32,`SHA256 #${i+1} default result length`); assert.deepEqual(Buffer.from(raw),crypto.createHash('sha256').update('abc').digest(),`SHA256 #${i+1} default digest`); }
2272
+ for (const [i, crc] of crcFns.entries()) {
2273
+ assert.equal(crc('123456789'),0xcbf43926,`CRC32 #${i+1}`); assert.equal(crc(''),0); assert.equal(crc('test'),crc(Buffer.from('test')));
2274
+ const a=Buffer.from('hello'), b=Buffer.from('world'); assert.equal(crc(b,crc(a)),crc(Buffer.concat([a,b])));
2275
+ assert.equal(crc('123456789',0),0xcbf43926); assert.notEqual(crc('123456789',1),crc('123456789',0));
2276
+ const view=Buffer.from('!test?'); assert.equal(crc(new DataView(view.buffer,view.byteOffset+1,4)),crc('test'));
2277
+ const ab=Buffer.from('!test?'); assert.equal(crc(ab.buffer.slice(ab.byteOffset+1,ab.byteOffset+5)),crc('test'),`CRC32 #${i+1} ArrayBuffer`);
2278
+ const u16=new Uint16Array(new Uint8Array([33,116,101,115,116,63]).buffer,2,2); assert.equal(crc(u16),crc(Buffer.from(u16.buffer,u16.byteOffset,u16.byteLength)),`CRC32 #${i+1} Uint16Array`);
2279
+ assert.equal(crc(new DataView(ab.buffer,ab.byteOffset+1,4)),crc('test'),`CRC32 #${i+1} DataView`);
2280
+ assert.equal(crc(ab.subarray(1,5)),crc('test'),`CRC32 #${i+1} offset subarray`);
2281
+ }
2282
+ });
2283
+
2245
2284
  test('hooksMetadata construction: both helper and bootstrap esmChunkedMain contain same code', () => {
2246
2285
  const fullScript = fs.readFileSync(scriptPath, 'utf8');
2247
2286
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash0816/claude-code",
3
- "version": "2.1.285",
3
+ "version": "2.1.287",
4
4
  "description": "Unofficial Termux-native Claude Code wrapper with audited native replay",
5
5
  "license": "GPL-3.0-only",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "files": [
11
11
  "bin/",
12
12
  "lib/",
13
+ "!lib/test-fixtures/**",
13
14
  "config/",
14
15
  "README.md",
15
16
  "LICENSE"