@bash0816/claude-code 2.1.270 → 2.1.276-1

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.
@@ -9,6 +9,13 @@ const MODULE_TABLE_ENTRY_SIZE = 52;
9
9
  const SCAN_CHUNK_SIZE = 1024 * 1024;
10
10
  const NAPI_LOADER = 10;
11
11
 
12
+ class ModuleGraphNotFoundError extends Error {
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = 'ModuleGraphNotFoundError';
16
+ }
17
+ }
18
+
12
19
  function readRange(fd, offset, length) {
13
20
  const buf = Buffer.alloc(length);
14
21
  const bytesRead = readSync(fd, buf, 0, length, offset);
@@ -26,7 +33,7 @@ function findTrailerOffset(fd, fileSize) {
26
33
  const idx = buf.lastIndexOf(TRAILER);
27
34
  if (idx >= 0) return start + idx;
28
35
  }
29
- throw new Error('bunfs-extract: StandaloneModuleGraph trailer not found');
36
+ throw new ModuleGraphNotFoundError('bunfs-extract: StandaloneModuleGraph trailer not found');
30
37
  }
31
38
 
32
39
  function isSafeUint(value) {
@@ -197,6 +204,8 @@ function readEntryContentPrefix(fd, entryModule, maxLength = 256) {
197
204
  }
198
205
 
199
206
  module.exports = {
207
+ TRAILER,
208
+ ModuleGraphNotFoundError,
200
209
  discoverModuleGraph,
201
210
  extractToProcessOwnedDir,
202
211
  cleanupStaleOwnedDirs,
@@ -8,14 +8,14 @@ const path = require('node:path');
8
8
 
9
9
  const {
10
10
  discoverModuleGraph,
11
+ ModuleGraphNotFoundError,
12
+ TRAILER,
11
13
  extractToProcessOwnedDir,
12
14
  cleanupStaleOwnedDirs,
13
15
  prepareProcessOwnedDir,
14
16
  readEntryContentPrefix,
15
17
  } = require('./bunfs-extract.js');
16
18
 
17
- const TRAILER = '\n---- Bun! ----\n';
18
-
19
19
  // StandaloneModuleGraphの最小合成バイナリを構築する。
20
20
  // レイアウト: [preamble padding][module contents][module table][Offsets(32byte)][trailer]
21
21
  function buildSyntheticBinary({ modules, entryPointId, corruptTrailer = false, preamblePadding = 64 }) {
@@ -58,7 +58,7 @@ function buildSyntheticBinary({ modules, entryPointId, corruptTrailer = false, p
58
58
  offsetsBuf.writeUInt32LE(modulesLength, 12);
59
59
  offsetsBuf.writeUInt32LE(entryPointId, 16);
60
60
 
61
- const trailerBuf = Buffer.from(corruptTrailer ? '\n---- NOT BUN ----\n' : TRAILER, 'utf8');
61
+ const trailerBuf = corruptTrailer ? Buffer.from('\n---- NOT BUN ----\n', 'utf8') : TRAILER;
62
62
 
63
63
  return Buffer.concat([
64
64
  Buffer.alloc(preamblePadding),
@@ -114,6 +114,39 @@ test('discoverModuleGraph rejects a binary with a corrupted trailer', () => {
114
114
  }
115
115
  });
116
116
 
117
+ test('discoverModuleGraph throws ModuleGraphNotFoundError when the trailer is absent', () => {
118
+ const file = writeTempBinary(Buffer.from('not a bun standalone module graph'));
119
+ try {
120
+ assert.throws(() => discoverModuleGraph(file), (error) => {
121
+ assert.ok(error instanceof ModuleGraphNotFoundError);
122
+ assert.match(error.message, /trailer not found/);
123
+ return true;
124
+ });
125
+ } finally {
126
+ fs.rmSync(file, { force: true });
127
+ }
128
+ });
129
+
130
+ test('discoverModuleGraph throws plain Error for a malformed graph with a trailer', () => {
131
+ const buf = buildSyntheticBinary({
132
+ modules: [{ name: '/$bunfs/root/cli', content: 'x' }],
133
+ entryPointId: 0,
134
+ });
135
+ const offsetsStart = buf.length - TRAILER.length - 32;
136
+ buf.writeUInt32LE(1, offsetsStart + 12);
137
+ const file = writeTempBinary(buf);
138
+ try {
139
+ assert.throws(() => discoverModuleGraph(file), (error) => {
140
+ assert.ok(error instanceof Error);
141
+ assert.equal(error instanceof ModuleGraphNotFoundError, false);
142
+ assert.match(error.message, /module table length is not a multiple/);
143
+ return true;
144
+ });
145
+ } finally {
146
+ fs.rmSync(file, { force: true });
147
+ }
148
+ });
149
+
117
150
  test('discoverModuleGraph rejects entry_point_id out of range', () => {
118
151
  const buf = buildSyntheticBinary({
119
152
  modules: [{ name: '/$bunfs/root/cli', content: 'x' }],
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ // qle 形: X=(a,b,c)=>FN()?AR(b,c(),a):{module:b,folder:a}
3
+ const QLE_PATTERN_SOURCE = '(\\b[\\w$]+=\\(([\\w$]+),([\\w$]+),([\\w$]+)\\)=>)[\\w$]+\\(\\)\\?([\\w$]+)\\(\\3,\\4\\(\\),\\2\\):\\{module:\\3,folder:\\2\\}';
4
+ const QLE_REPLACEMENT = '$1(!0)?$5($3,$4(),$2):{module:$3,folder:$2}';
5
+ function countQleMatches(source) { return (source.match(new RegExp(QLE_PATTERN_SOURCE, 'g')) || []).length; }
6
+ function applyQlePatch(source) { return source.replace(new RegExp(QLE_PATTERN_SOURCE, 'g'), QLE_REPLACEMENT); }
7
+ module.exports = { QLE_PATTERN_SOURCE, QLE_REPLACEMENT, countQleMatches, applyQlePatch };
@@ -0,0 +1,115 @@
1
+ const test = require('node:test');
2
+ const assert = require('assert/strict');
3
+ const { countQleMatches, applyQlePatch } = require('./hooks-standalone-pattern.js');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ test('countQleMatches finds pattern once in simple example', () => {
8
+ const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
9
+ const count = countQleMatches(source);
10
+ assert.equal(count, 1);
11
+ });
12
+
13
+ test('applyQlePatch replaces uu() with (!0)', () => {
14
+ const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
15
+ const expected = 'var qle=(e,o,r)=>(!0)?ar(o,r(),e):{module:o,folder:e};';
16
+ const result = applyQlePatch(source);
17
+ assert.equal(result, expected);
18
+ });
19
+
20
+ test('applyQlePatch is idempotent', () => {
21
+ const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
22
+ const patched = applyQlePatch(source);
23
+ const repatch = applyQlePatch(patched);
24
+ assert.equal(repatch, patched);
25
+ assert.equal(countQleMatches(patched), 0);
26
+ });
27
+
28
+ test('countQleMatches finds pattern with different minify names', () => {
29
+ const source = 'var vCe=(a,b,c)=>H1()?zz(b,c(),a):{module:b,folder:a};';
30
+ const count = countQleMatches(source);
31
+ assert.equal(count, 1);
32
+ });
33
+
34
+ test('applyQlePatch works with different minify names', () => {
35
+ const source = 'var vCe=(a,b,c)=>H1()?zz(b,c(),a):{module:b,folder:a};';
36
+ const expected = 'var vCe=(a,b,c)=>(!0)?zz(b,c(),a):{module:b,folder:a};';
37
+ const result = applyQlePatch(source);
38
+ assert.equal(result, expected);
39
+ });
40
+
41
+ test('countQleMatches returns 0 for mismatched pattern (wrong field order)', () => {
42
+ const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:e,folder:o};'; // swapped
43
+ const count = countQleMatches(source);
44
+ assert.equal(count, 0);
45
+ });
46
+
47
+ test('countQleMatches returns 0 for import.meta.dirname only', () => {
48
+ const source = 'import.meta.dirname';
49
+ const count = countQleMatches(source);
50
+ assert.equal(count, 0);
51
+ });
52
+
53
+ test('countQleMatches returns 0 for unrelated arrow function', () => {
54
+ const source = 'const f = (a, b, c) => someFunc() ? a : b;';
55
+ const count = countQleMatches(source);
56
+ assert.equal(count, 0);
57
+ });
58
+
59
+ test('countQleMatches finds multiple patterns', () => {
60
+ const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e}; var qle2=(a,b,c)=>uu()?ar(b,c(),a):{module:b,folder:a};';
61
+ const count = countQleMatches(source);
62
+ assert.equal(count, 2);
63
+ });
64
+
65
+ test('real chunk from 2.1.278 (if exists)', () => {
66
+ const versions = [
67
+ path.join(process.env.HOME || '.', '.claude-termux-native-package', 'versions', '2.1.278', 'launcher-workdir'),
68
+ ];
69
+ const testRun = versions.some((vdir) => {
70
+ const chunks = [];
71
+ if (fs.existsSync(vdir)) {
72
+ const esmDir = fs.readdirSync(vdir).find((d) => d.startsWith('esm.'));
73
+ if (esmDir) {
74
+ const chunkDir = path.join(vdir, esmDir);
75
+ const chunkFile = fs.readdirSync(chunkDir).find((f) => f.match(/^chunk-7nckpqfv\.js$/));
76
+ if (chunkFile) {
77
+ const source = fs.readFileSync(path.join(chunkDir, chunkFile), 'utf8');
78
+ const count = countQleMatches(source);
79
+ assert.equal(count, 1, `chunk-7nckpqfv.js should have exactly 1 match, found ${count}`);
80
+ chunks.push({ file: chunkFile, count });
81
+ return true;
82
+ }
83
+ }
84
+ }
85
+ return false;
86
+ });
87
+ if (!testRun) {
88
+ test.skip();
89
+ }
90
+ });
91
+
92
+ test('real chunk from 2.1.276 (if exists)', () => {
93
+ const versions = [
94
+ path.join(process.env.HOME || '.', '.claude-termux-native-package', 'versions', '2.1.276', 'launcher-workdir'),
95
+ ];
96
+ const testRun = versions.some((vdir) => {
97
+ if (fs.existsSync(vdir)) {
98
+ const esmDir = fs.readdirSync(vdir).find((d) => d.startsWith('esm.'));
99
+ if (esmDir) {
100
+ const chunkDir = path.join(vdir, esmDir);
101
+ const chunkFile = fs.readdirSync(chunkDir).find((f) => f.match(/^chunk-0sa9p840\.js$/));
102
+ if (chunkFile) {
103
+ const source = fs.readFileSync(path.join(chunkDir, chunkFile), 'utf8');
104
+ const count = countQleMatches(source);
105
+ assert.equal(count, 1, `chunk-0sa9p840.js should have exactly 1 match, found ${count}`);
106
+ return true;
107
+ }
108
+ }
109
+ }
110
+ return false;
111
+ });
112
+ if (!testRun) {
113
+ test.skip();
114
+ }
115
+ });
@@ -305,6 +305,12 @@ function stableHash(value, seed) {
305
305
  return hash >>> 0;
306
306
  }
307
307
 
308
+ stableHash.xxHash64 = function bunHashXxHash64(value, seed) {
309
+ const lo = stableHash(value, seed);
310
+ const hi = stableHash(value, lo ^ 0x85ebca6b);
311
+ return (BigInt(hi) << 32n) | BigInt(lo);
312
+ };
313
+
308
314
  function replaceRequired(source, pattern, replacement, label, expectedCount) {
309
315
  const text = String(source);
310
316
  const matches = text.match(pattern);
@@ -673,6 +679,7 @@ async function esmChunkedMain() {
673
679
  const libDir = path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib');
674
680
 
675
681
  globalThis.__claudeYaml = createYamlShim();
682
+ const { sliceAnsi, sleepSync, CellSegmenter } = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'bun-cellsegmenter-shim.js'))({ stringWidth, graphemeWidth });
676
683
  globalThis.Bun = {
677
684
  version: '1.1.8',
678
685
  stringWidth,
@@ -692,6 +699,9 @@ async function esmChunkedMain() {
692
699
  unsafe: {
693
700
  setJITPolicy: () => undefined,
694
701
  },
702
+ sliceAnsi,
703
+ sleepSync,
704
+ ant: { CellSegmenter },
695
705
  };
696
706
  Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
697
707
  globalThis.__claudeBunShim = globalThis.Bun;
@@ -708,6 +718,17 @@ async function esmChunkedMain() {
708
718
  // 読み込み失敗時は空配列のまま(fail-closed、既存の同期require経路にフォールバック)
709
719
  }
710
720
 
721
+ let hooksMetadata = { status: 'read-failed', patches: [] };
722
+ try {
723
+ const auditedVersionsForHooks = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'config', 'claude-native-audited-versions.json'));
724
+ const hooksEntry = auditedVersionsForHooks.versions?.[process.env.CURRENT_CLAUDE_VERSION];
725
+ if (!hooksEntry) hooksMetadata = { status: 'entry-missing', patches: [] };
726
+ else if (Array.isArray(hooksEntry.hooks_standalone_patches)) hooksMetadata = { status: 'ok', patches: hooksEntry.hooks_standalone_patches };
727
+ else hooksMetadata = { status: 'field-absent', patches: [] };
728
+ } catch {
729
+ // 既定の read-failed のまま(fail-visible: ローダーが警告する)
730
+ }
731
+
711
732
  const loaderMod = require(path.join(libDir, 'bunfs-esm-loader.mjs'));
712
733
  loaderMod.initialize({
713
734
  processOwnedDir: ownedDir,
@@ -716,6 +737,7 @@ async function esmChunkedMain() {
716
737
  vmGuardPath: path.join(libDir, 'bunfs-vm-guard.mjs'),
717
738
  wsStubPath: path.join(libDir, 'bunfs-ws-stub.mjs'),
718
739
  cycleHoists,
740
+ hooksMetadata,
719
741
  reExtract: (sb, od) => extractToProcessOwnedDir(sb, od),
720
742
  });
721
743
  loaderMod.installFsBunfsInterception();
@@ -930,6 +952,7 @@ async function legacyCjsMain() {
930
952
  process.once('uncaughtException', onAsyncError);
931
953
  process.once('unhandledRejection', onAsyncError);
932
954
  Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
955
+ const { sliceAnsi, sleepSync, CellSegmenter } = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'bun-cellsegmenter-shim.js'))({ stringWidth, graphemeWidth });
933
956
  const _realChild = require('child_process');
934
957
  globalThis.Bun = {
935
958
  version: '1.1.8',
@@ -1016,6 +1039,9 @@ async function legacyCjsMain() {
1016
1039
  unsafe: {
1017
1040
  setJITPolicy: () => undefined,
1018
1041
  },
1042
+ sliceAnsi,
1043
+ sleepSync,
1044
+ ant: { CellSegmenter },
1019
1045
  };
1020
1046
  Object.assign(globalThis.__claudeBunShim, globalThis.Bun);
1021
1047
  if (typeof globalThis.__claudeBunShim.gc !== 'function') {
@@ -1341,6 +1367,12 @@ function stableHash(value, seed) {
1341
1367
  return hash >>> 0;
1342
1368
  }
1343
1369
 
1370
+ stableHash.xxHash64 = function bunHashXxHash64(value, seed) {
1371
+ const lo = stableHash(value, seed);
1372
+ const hi = stableHash(value, lo ^ 0x85ebca6b);
1373
+ return (BigInt(hi) << 32n) | BigInt(lo);
1374
+ };
1375
+
1344
1376
  function replaceRequired(source, pattern, replacement, label, expectedCount) {
1345
1377
  const text = String(source);
1346
1378
  const matches = text.match(pattern);
@@ -1709,6 +1741,7 @@ async function esmChunkedMain() {
1709
1741
  const libDir = path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib');
1710
1742
 
1711
1743
  globalThis.__claudeYaml = createYamlShim();
1744
+ const { sliceAnsi, sleepSync, CellSegmenter } = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'bun-cellsegmenter-shim.js'))({ stringWidth, graphemeWidth });
1712
1745
  globalThis.Bun = {
1713
1746
  version: '1.1.8',
1714
1747
  stringWidth,
@@ -1728,6 +1761,9 @@ async function esmChunkedMain() {
1728
1761
  unsafe: {
1729
1762
  setJITPolicy: () => undefined,
1730
1763
  },
1764
+ sliceAnsi,
1765
+ sleepSync,
1766
+ ant: { CellSegmenter },
1731
1767
  };
1732
1768
  Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
1733
1769
  globalThis.__claudeBunShim = globalThis.Bun;
@@ -1744,6 +1780,17 @@ async function esmChunkedMain() {
1744
1780
  // 読み込み失敗時は空配列のまま(fail-closed、既存の同期require経路にフォールバック)
1745
1781
  }
1746
1782
 
1783
+ let hooksMetadata = { status: 'read-failed', patches: [] };
1784
+ try {
1785
+ const auditedVersionsForHooks = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'config', 'claude-native-audited-versions.json'));
1786
+ const hooksEntry = auditedVersionsForHooks.versions?.[process.env.CURRENT_CLAUDE_VERSION];
1787
+ if (!hooksEntry) hooksMetadata = { status: 'entry-missing', patches: [] };
1788
+ else if (Array.isArray(hooksEntry.hooks_standalone_patches)) hooksMetadata = { status: 'ok', patches: hooksEntry.hooks_standalone_patches };
1789
+ else hooksMetadata = { status: 'field-absent', patches: [] };
1790
+ } catch {
1791
+ // 既定の read-failed のまま(fail-visible: ローダーが警告する)
1792
+ }
1793
+
1747
1794
  const loaderMod = require(path.join(libDir, 'bunfs-esm-loader.mjs'));
1748
1795
  loaderMod.initialize({
1749
1796
  processOwnedDir: ownedDir,
@@ -1752,6 +1799,7 @@ async function esmChunkedMain() {
1752
1799
  vmGuardPath: path.join(libDir, 'bunfs-vm-guard.mjs'),
1753
1800
  wsStubPath: path.join(libDir, 'bunfs-ws-stub.mjs'),
1754
1801
  cycleHoists,
1802
+ hooksMetadata,
1755
1803
  reExtract: (sb, od) => extractToProcessOwnedDir(sb, od),
1756
1804
  });
1757
1805
  loaderMod.installFsBunfsInterception();
@@ -1968,6 +2016,7 @@ async function legacyCjsMain() {
1968
2016
  process.once('uncaughtException', onAsyncError);
1969
2017
  process.once('unhandledRejection', onAsyncError);
1970
2018
  Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
2019
+ const { sliceAnsi, sleepSync, CellSegmenter } = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'bun-cellsegmenter-shim.js'))({ stringWidth, graphemeWidth });
1971
2020
  const _realChild = require('child_process');
1972
2021
  globalThis.Bun = {
1973
2022
  version: '1.1.8',
@@ -2054,6 +2103,9 @@ async function legacyCjsMain() {
2054
2103
  unsafe: {
2055
2104
  setJITPolicy: () => undefined,
2056
2105
  },
2106
+ sliceAnsi,
2107
+ sleepSync,
2108
+ ant: { CellSegmenter },
2057
2109
  };
2058
2110
  Object.assign(globalThis.__claudeBunShim, globalThis.Bun);
2059
2111
  if (typeof globalThis.__claudeBunShim.gc !== 'function') {