@bash0816/claude-code 2.1.270 → 2.1.276

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.
@@ -1567,6 +1567,9 @@ function loadBunShim(source) {
1567
1567
  wrapAnsi: value => value,
1568
1568
  stripANSI: value => value,
1569
1569
  stableHash: () => 0,
1570
+ sliceAnsi: (s) => s,
1571
+ sleepSync: () => {},
1572
+ CellSegmenter: class {},
1570
1573
  __claudeYaml: {},
1571
1574
  Buffer,
1572
1575
  require,
@@ -1595,6 +1598,9 @@ function loadEsmBunShim(source) {
1595
1598
  wrapAnsi: value => value,
1596
1599
  stripANSI: value => value,
1597
1600
  stableHash: () => 0,
1601
+ sliceAnsi: (s) => s,
1602
+ sleepSync: () => {},
1603
+ CellSegmenter: class {},
1598
1604
  process: { versions: {} },
1599
1605
  Buffer,
1600
1606
  require,
@@ -1856,3 +1862,382 @@ test('termux-run-claude-native.sh maintains compatibility with new zstd fields',
1856
1862
  const blocks = (script.match(/globalThis\.Bun\s*=\s*{/g) || []);
1857
1863
  assert.ok(blocks.length >= 2, 'should have at least 2 Bun initializations for helper and bootstrap');
1858
1864
  });
1865
+
1866
+ test('ESM and legacy Bun shims include new CellSegmenter exports', () => {
1867
+ for (const blockMarker of ['cat <<\'NODE\' > "$_helper"', 'cat <<\'NODE\' > "$_bootstrap"']) {
1868
+ const block = extractBlock(blockMarker, '\n export ENABLE_CLAUDEAI_MCP_SERVERS=');
1869
+ const BunEsm = loadEsmBunShim(extractEsmShimSource(block));
1870
+ const BunLegacy = loadBunShim(extractShimSource(block));
1871
+
1872
+ // Verify sliceAnsi is present
1873
+ assert.equal(typeof BunEsm.sliceAnsi, 'function', `${blockMarker}: ESM sliceAnsi should be a function`);
1874
+ assert.equal(typeof BunLegacy.sliceAnsi, 'function', `${blockMarker}: legacy sliceAnsi should be a function`);
1875
+
1876
+ // Verify sleepSync is present
1877
+ assert.equal(typeof BunEsm.sleepSync, 'function', `${blockMarker}: ESM sleepSync should be a function`);
1878
+ assert.equal(typeof BunLegacy.sleepSync, 'function', `${blockMarker}: legacy sleepSync should be a function`);
1879
+
1880
+
1881
+ // Verify CellSegmenter is present
1882
+ assert.equal(typeof BunEsm.ant.CellSegmenter, 'function', `${blockMarker}: ESM ant.CellSegmenter should be a function`);
1883
+ assert.equal(typeof BunLegacy.ant.CellSegmenter, 'function', `${blockMarker}: legacy ant.CellSegmenter should be a function`);
1884
+ }
1885
+ });
1886
+
1887
+ // ============================================================
1888
+ // CellSegmenter integration tests with vendor harness (G3 v2 revision)
1889
+ // ============================================================
1890
+
1891
+ test('CellSegmenter: run monotonicity and style non-contamination (BL-3)', () => {
1892
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
1893
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => 1);
1894
+ const { D, Pool } = h;
1895
+
1896
+ const stylePool = new Pool();
1897
+ const charPool = new Pool([' ', 'S']);
1898
+ const hyperPool = new Pool(['']);
1899
+
1900
+ // Test case: style repeats after gap (BL-3 regression)
1901
+ const d1 = new D(stylePool, charPool);
1902
+ d1.segment('aa\x1b[34mBLUE\x1b[39m', false);
1903
+ d1.paint(h.mkScreen(40, 1).cells, 40, 0, 0, hyperPool);
1904
+
1905
+ const d2 = new D(stylePool, charPool);
1906
+ const n = d2.segment('ok \x1b[1mERR\x1b[22m done', false);
1907
+
1908
+ // Verify run indices are monotonic
1909
+ const runIndices = [];
1910
+ for (let i = 0; i < n; i++) {
1911
+ runIndices.push(d2.cells[2*i+1] >>> 10);
1912
+ }
1913
+ for (let i = 1; i < runIndices.length; i++) {
1914
+ assert.ok(runIndices[i] >= runIndices[i-1], `run ${i} should be >= run ${i-1}`);
1915
+ }
1916
+
1917
+ // Paint and verify style isolation (find the bold run, not run 0)
1918
+ d2.paint(h.mkScreen(40, 1).cells, 40, 0, 0, hyperPool);
1919
+ const boldRunIdx = runIndices.find(r => r > 0) || 0; // Skip run 0 (unstyled)
1920
+ const boldStyleId = d2.styleId(d2.runs[2*boldRunIdx]);
1921
+ const blueStyleId = stylePool.arr.findIndex(s => s.includes('34'));
1922
+ assert.ok(boldStyleId !== blueStyleId || blueStyleId === -1, 'style should not contaminate between segments');
1923
+ });
1924
+
1925
+ test('CellSegmenter: foreground color exclusivity (BL-6)', () => {
1926
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
1927
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => 1);
1928
+ const { D, Pool } = h;
1929
+
1930
+ const stylePool = new Pool();
1931
+ const charPool = new Pool([' ', 'S']);
1932
+ const d = new D(stylePool, charPool);
1933
+
1934
+ const text = '\x1b[31mRED\x1b[32mGREEN\x1b[0m';
1935
+ d.segment(text, false);
1936
+
1937
+ // Extract runIndices for RED and GREEN
1938
+ const reds = [];
1939
+ const greens = [];
1940
+ for (let i = 0; i < d.count; i++) {
1941
+ const runIdx = d.cells[2*i+1] >>> 10;
1942
+ if (d.graphemes[d.cells[2*i]] === 'R') reds.push(runIdx);
1943
+ if (d.graphemes[d.cells[2*i]] === 'G') greens.push(runIdx);
1944
+ }
1945
+
1946
+ const redStyleId = reds.length > 0 ? d.styleId(d.runs[2*reds[0]]) : -1;
1947
+ const greenStyleId = greens.length > 0 ? d.styleId(d.runs[2*greens[0]]) : -1;
1948
+ assert.notEqual(redStyleId, greenStyleId, 'RED and GREEN should have distinct styleIds');
1949
+
1950
+ // Direct validation: GREEN run should NOT contain red (31) code - verifying exclusivity
1951
+ if (greens.length > 0) {
1952
+ const greenRunIdx = greens[0];
1953
+ const greenSgrIdx = d.runs[2*greenRunIdx];
1954
+ const greenCodes = d.ansiCodes(greenSgrIdx);
1955
+ const hasBothColors = greenCodes.some(c => c.code.includes('31')) && greenCodes.some(c => c.code.includes('32'));
1956
+ assert.ok(!hasBothColors, 'GREEN run should not contain red (31) code - colors must be exclusive');
1957
+ }
1958
+ });
1959
+
1960
+ test('CellSegmenter: sgrCloseKeys derivation (§9-5)', () => {
1961
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
1962
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => 1);
1963
+ const { D, Pool, mC } = h;
1964
+
1965
+ const stylePool = new Pool();
1966
+ const charPool = new Pool([' ', 'S']);
1967
+ const d = new D(stylePool, charPool);
1968
+
1969
+ const text = '\x1b[1;31mX';
1970
+ d.segment(text, false);
1971
+
1972
+ // Check that sgrKeys[1] contains open codes and sgrCloseKeys[1] contains matching close codes
1973
+ const keys = d.sgrKeys[1];
1974
+ const closeKeys = d.sgrCloseKeys[1];
1975
+ const keyList = keys.split('\x00').filter(k => k);
1976
+ const closeList = closeKeys.split('\x00').filter(k => k);
1977
+
1978
+ assert.equal(keyList.length, closeList.length, 'open and close codes should have same count');
1979
+ assert.ok(keyList.some(k => k.includes('1')), 'should have bold (1)');
1980
+ assert.ok(keyList.some(k => k.includes('31')), 'should have fg-red (31)');
1981
+ assert.ok(closeList.some(c => c.includes('22')), 'should have bold-close (22)');
1982
+ assert.ok(closeList.some(c => c.includes('39')), 'should have fg-close (39)');
1983
+ });
1984
+
1985
+ test('CellSegmenter: URI indexing and OSC8 handling (BL-4, BL-5)', () => {
1986
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
1987
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => 1);
1988
+ const { D, Pool, mkScreen, readCell } = h;
1989
+
1990
+ const stylePool = new Pool();
1991
+ const charPool = new Pool([' ', 'S']);
1992
+ const hyperPool = new Pool(['']);
1993
+ const d = new D(stylePool, charPool);
1994
+
1995
+ // Test OSC8 with BEL terminator
1996
+ const text1 = 'A\x1b]8;;http://x\x07B\x1b]8;;\x07C';
1997
+ d.segment(text1, false);
1998
+ const screen1 = mkScreen(40, 1);
1999
+ d.paint(screen1.cells, 40, 0, 0, hyperPool);
2000
+
2001
+ const cellA = readCell(screen1, charPool, hyperPool, 0, 0);
2002
+ const cellB = readCell(screen1, charPool, hyperPool, 1, 0);
2003
+ const cellC = readCell(screen1, charPool, hyperPool, 2, 0);
2004
+
2005
+ assert.equal(cellA.hyperlink, undefined, 'A should have no hyperlink');
2006
+ assert.equal(cellB.hyperlink, 'http://x', 'B should link to http://x');
2007
+ assert.equal(cellC.hyperlink, undefined, 'C should have no hyperlink');
2008
+
2009
+ // Test OSC8 with ST terminator (ESC backslash)
2010
+ stylePool.arr = [];
2011
+ stylePool.map.clear();
2012
+ const d2 = new D(stylePool, charPool);
2013
+ const text2 = '\x1b]8;;http://st\x1b\\ST\x1b]8;;\x1b\\';
2014
+ d2.segment(text2, false);
2015
+
2016
+ // Verify no ESC byte mixed into text
2017
+ const textReconstructed = d2.graphemes.slice(0, d2.count).join('');
2018
+ assert.equal(textReconstructed, 'ST', 'ST terminator should not include ESC bytes');
2019
+
2020
+ // BL-5: Verify uris array has clean URLs without ESC bytes
2021
+ const uriWithoutEsc = d2.uris[1]; // Index 1 because 0 is reserved
2022
+ assert.ok(uriWithoutEsc, 'should have URI at index 1');
2023
+ assert.equal(uriWithoutEsc, 'http://st', 'URI should be clean without ESC bytes');
2024
+ });
2025
+
2026
+ test('CellSegmenter: no infinite loops on malformed escapes (BL-1, BL-2)', function() {
2027
+ const createShim = require('./bun-cellsegmenter-shim.js');
2028
+ const { CellSegmenter, sliceAnsi } = createShim({
2029
+ stringWidth: (s) => s.replace(/\x1b\[[0-9;]*m/g, '').length,
2030
+ graphemeWidth: (s) => 1
2031
+ });
2032
+
2033
+ const cases = {
2034
+ 'osc-title': '\x1b]0;my title\x07hello',
2035
+ 'osc9': '\x1b]9;notify\x07hi',
2036
+ 'osc8-badprefix': '\x1b]8x;;http://a\x07hi',
2037
+ 'esc-alone': 'abc\x1b',
2038
+ 'esc-paren': 'abc\x1bcdef',
2039
+ 'esc-dcs': '\x1bPsomething\x1b\\text',
2040
+ 'esc-st': 'a\x1b\\b',
2041
+ 'esc-charset': '\x1b(Bhello',
2042
+ 'esc-esc': 'a\x1b\x1bb',
2043
+ 'sgr-unterm': 'abc\x1b[31',
2044
+ 'osc8-unterm': 'abc\x1b]8;;http://x',
2045
+ 'csi-K': '\x1b[Khello, my friend',
2046
+ 'csi-cursor': '\x1b[2J\x1b[Hmenu item',
2047
+ };
2048
+
2049
+ const seg = new CellSegmenter({
2050
+ ambiguousIsNarrow: true,
2051
+ substitute: [],
2052
+ screen: { widthMask: 3, narrow: 0, wide: 1, spacerTail: 2, spacerHead: 3, emptyCharIndex: 0, spacerCharIndex: 1, emptyWord: 0, tabWidth: 8 }
2053
+ });
2054
+
2055
+ for (const [label, text] of Object.entries(cases)) {
2056
+ // Test segment() with timeout
2057
+ const startSeg = Date.now();
2058
+ const n = seg.segment(text, new Int32Array(1024), new Int32Array(1024), false);
2059
+ const segTime = Date.now() - startSeg;
2060
+ assert.ok(segTime < 500, `segment(${label}) took ${segTime}ms (>500ms suggests hang)`);
2061
+ assert.ok(n >= 0 || n === -1, `segment(${label}) returned invalid result ${n}`);
2062
+
2063
+ // Test sliceAnsi() with timeout
2064
+ const startSlice = Date.now();
2065
+ const result = sliceAnsi(text, 0, 100);
2066
+ const sliceTime = Date.now() - startSlice;
2067
+ assert.ok(sliceTime < 500, `sliceAnsi(${label}) took ${sliceTime}ms (>500ms suggests hang)`);
2068
+
2069
+ // Verify CSI sequences are consumed (not in output text)
2070
+ if (label === 'csi-K') {
2071
+ assert.equal(result, 'hello, my friend', 'CSI-K should consume and not appear in output');
2072
+ }
2073
+ if (label === 'csi-cursor') {
2074
+ assert.equal(result, 'menu item', 'CSI-2J and CSI-H should not appear in output');
2075
+ }
2076
+ }
2077
+ });
2078
+
2079
+ test('CellSegmenter: grapheme boundary correctness (BL-8 regression prevention)', () => {
2080
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
2081
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => {
2082
+ // Proper grapheme width calculation
2083
+ const symbols = Array.from(String(s || ''));
2084
+ const codePoints = symbols.map(sym => sym.codePointAt(0)).filter(cp => Number.isFinite(cp));
2085
+ if (codePoints.length === 0) return 0;
2086
+ if (codePoints.length > 1 && codePoints.every(cp => cp >= 0x1f1e6 && cp <= 0x1f1ff)) return 2; // Flag pairs
2087
+ if (codePoints.includes(0x200d) || codePoints.includes(0x20e3) || codePoints.includes(0xfe0f)) return 2; // ZWJ, VS16
2088
+ if (codePoints.some(cp => (cp >= 0x1f300 && cp <= 0x1f6ff) || (cp >= 0x1f900 && cp <= 0x1f9ff))) return 2; // Emoji
2089
+ return 1;
2090
+ });
2091
+ const { D, Pool } = h;
2092
+
2093
+ const stylePool = new Pool();
2094
+ const charPool = new Pool([' ', 'S']);
2095
+
2096
+ // Test 1: ZWJ family emoji (👨‍👩‍👧) should be 1 grapheme, not split
2097
+ const d1 = new D(stylePool, charPool);
2098
+ const family = '👨‍👩‍👧';
2099
+ const n1 = d1.segment(family, false);
2100
+ assert.equal(n1, 1, `Family emoji ${JSON.stringify(family)} should be 1 grapheme cluster`);
2101
+
2102
+ // Test 2: Flag emoji (🇯🇵) should be 1 grapheme (surrogate pair combined)
2103
+ const d2 = new D(stylePool, charPool);
2104
+ const jpFlag = '🇯🇵';
2105
+ const n2 = d2.segment(jpFlag, false);
2106
+ assert.equal(n2, 1, `Flag emoji ${JSON.stringify(jpFlag)} should be 1 grapheme cluster`);
2107
+
2108
+ // Test 3: sliceAnsi() should not produce isolated surrogates
2109
+ const { sliceAnsi } = h;
2110
+ const sliceResult = sliceAnsi('a👍b', 0, 2);
2111
+ // Check for isolated surrogates (UTF-16 range 0xD800-0xDFFF)
2112
+ const isSurrogatePair = /[\ud800-\udfff]/.test(sliceResult);
2113
+ assert.ok(!isSurrogatePair, `sliceAnsi('a👍b', 0, 2) should not have orphaned surrogates: ${JSON.stringify(sliceResult)}`);
2114
+
2115
+ // Test 4: Warning symbol with VS16 (⚠️) should have correct width
2116
+ const d4 = new D(stylePool, charPool);
2117
+ const warning = '⚠️ warn';
2118
+ const n4 = d4.segment(warning, false);
2119
+ // Intl.Segmenter splits as: '⚠️' (1 grapheme) + ' ' (1) + 'w' (1) + 'a' (1) + 'r' (1) + 'n' (1) = 6 graphemes
2120
+ assert.equal(n4, 6, `Warning symbol with VS16 should produce 6 graphemes: got ${n4}`);
2121
+ });
2122
+
2123
+ test('CellSegmenter: fresh instance pool initialization (NB-2)', () => {
2124
+ const createHarness = require('./test-support/vendor-cellsegmenter-harness.js');
2125
+ const h = createHarness((s) => s.replace(/\x1b\[[0-9;]*m/g, '').length, (s) => {
2126
+ // Simple width calculator
2127
+ const codePoints = Array.from(String(s || '')).map(sym => sym.codePointAt(0)).filter(cp => Number.isFinite(cp));
2128
+ if (codePoints.length === 0) return 0;
2129
+ if (codePoints.length > 1 && codePoints.every(cp => cp >= 0x1f1e6 && cp <= 0x1f1ff)) return 2; // Flag pairs
2130
+ if (codePoints.includes(0x200d) || codePoints.includes(0x20e3) || codePoints.includes(0xfe0f)) return 2; // ZWJ, VS16
2131
+ return 1;
2132
+ });
2133
+ const { D, Pool } = h;
2134
+
2135
+ // Test 1: New instance pool initialization
2136
+ const stylePool = new Pool();
2137
+ const charPool = new Pool([' ', 'a', 'b', 'c']);
2138
+ const d = new D(stylePool, charPool);
2139
+
2140
+ // Verify initial pool state: sgrKeys should have [''] (index 0 only)
2141
+ assert.equal(d.sgrKeys.length, 1, 'sgrKeys should start with length 1 (index 0 only)');
2142
+ assert.equal(d.sgrKeys[0], '', 'sgrKeys[0] should be empty string');
2143
+
2144
+ // Verify initial pool state: uris should have [''] (index 0 only)
2145
+ assert.equal(d.uris.length, 1, 'uris should start with length 1 (index 0 only)');
2146
+ assert.equal(d.uris[0], '', 'uris[0] should be empty string');
2147
+
2148
+ // Test 2: Multiple segments work correctly without reset
2149
+ d.segment('hello world', false);
2150
+ d.segment('test string', false);
2151
+ assert.ok(d.sgrKeys.length >= 1, 'sgrKeys should grow or stay at 1 (unstyled input)');
2152
+ assert.ok(d.graphemes.length >= 20, 'graphemes should accumulate');
2153
+
2154
+ // Test 3: Fresh instance has clean pools
2155
+ const d2 = new D(stylePool, charPool);
2156
+ assert.equal(d2.sgrKeys.length, 1, 'new instance sgrKeys should be at length 1');
2157
+ assert.equal(d2.sgrKeys[0], '', 'new instance sgrKeys[0] should be empty string');
2158
+ assert.equal(d2.uris.length, 1, 'new instance uris should be at length 1');
2159
+ assert.equal(d2.uris[0], '', 'new instance uris[0] should be empty string');
2160
+
2161
+ // Test 4: Fresh instance can segment immediately
2162
+ const count2 = d2.segment('fresh test', false);
2163
+ assert.ok(count2 > 0, 'should successfully segment after reset');
2164
+ assert.equal(d2.graphemes.length, count2, 'grapheme count should match segment result');
2165
+ });
2166
+
2167
+ test('stableHash.xxHash64 implementation (G2 v3 implementation)', () => {
2168
+ const api = loadHelperApi();
2169
+ const { stableHash } = api;
2170
+
2171
+ // Test 1: Base64 representation of xxHash64 result is valid (1-13 chars in base36)
2172
+ const result1 = stableHash.xxHash64('x').toString(36);
2173
+ assert.match(result1, /^[0-9a-z]{1,13}$/, `xxHash64('x').toString(36) should match [0-9a-z]{1,13}, got: ${result1}`);
2174
+
2175
+ // Test 2: seedless mode with fixed literal values - hi !== lo
2176
+ const fixedLiterals = ['a', 'hello', 'thinking:1562789', 'thinking:1779192', '', 'x'.repeat(100)];
2177
+ for (const val of fixedLiterals) {
2178
+ const h = stableHash.xxHash64(val);
2179
+ const hi = h >> 32n;
2180
+ const lo = h & 0xffffffffn;
2181
+ assert.ok(hi !== lo, `xxHash64('${val.slice(0, 20)}${val.length > 20 ? '...' : ''}') should have hi !== lo (got hi=${hi}, lo=${lo})`);
2182
+ }
2183
+
2184
+ // Test 3: seed specified mode - hi !== lo
2185
+ const seededPairs = [
2186
+ ['x', 42],
2187
+ ['hello', 1234],
2188
+ ['test', 9999],
2189
+ ];
2190
+ for (const [val, seed] of seededPairs) {
2191
+ const h = stableHash.xxHash64(val, seed);
2192
+ const hi = h >> 32n;
2193
+ const lo = h & 0xffffffffn;
2194
+ assert.ok(hi !== lo, `xxHash64('${val}', ${seed}) should have hi !== lo (got hi=${hi}, lo=${lo})`);
2195
+ }
2196
+
2197
+ // Test 4: Deterministic (repeated calls return same result)
2198
+ const val = 'determinism-test';
2199
+ const r1 = stableHash.xxHash64(val);
2200
+ const r2 = stableHash.xxHash64(val);
2201
+ const r3 = stableHash.xxHash64(val);
2202
+ assert.equal(r1, r2, `xxHash64 should be deterministic (1st vs 2nd call)`);
2203
+ assert.equal(r2, r3, `xxHash64 should be deterministic (2nd vs 3rd call)`);
2204
+
2205
+ // Test 5: Return type is bigint
2206
+ const result5 = stableHash.xxHash64('x');
2207
+ assert.equal(typeof result5, 'bigint', `xxHash64 should return bigint, got: ${typeof result5}`);
2208
+
2209
+ // Test 6: Verify .xxHash64 is accessible in ESM shim context
2210
+ // Use the same logic as the "実行モード網羅" section of the design doc
2211
+ function extractEsmShimSource(block) {
2212
+ const sm = '\n globalThis.Bun = {';
2213
+ const em = '\n globalThis.__claudeBun = globalThis.Bun;';
2214
+ const s = block.indexOf(sm);
2215
+ const e = block.indexOf(em, s);
2216
+ return block.slice(s + 1, e + em.length);
2217
+ }
2218
+
2219
+ // Verify for both _helper and _bootstrap heredocs
2220
+ for (const markerKey of ['cat <<\'NODE\' > "$_helper"', 'cat <<\'NODE\' > "$_bootstrap"']) {
2221
+ const helperBlock = extractBlock(markerKey, '\n export ENABLE_CLAUDEAI_MCP_SERVERS=');
2222
+ const stableHashSource = extractFunction(
2223
+ helperBlock,
2224
+ 'function stableHash(value, seed) {',
2225
+ '\n\nfunction replaceRequired(source, pattern, replacement, label, expectedCount) {',
2226
+ );
2227
+ const context = vm.createContext({
2228
+ stringWidth: () => 0, wrapAnsi: v => v, stripANSI: v => v,
2229
+ sliceAnsi: s => s, sleepSync: () => {}, CellSegmenter: class {},
2230
+ process: { versions: {} }, Buffer, require,
2231
+ });
2232
+ context.module = { exports: {} };
2233
+ vm.runInContext(
2234
+ `${stableHashSource}\n${extractEsmShimSource(helperBlock)}\nmodule.exports = { Bun: globalThis.Bun, stableHash };`,
2235
+ context,
2236
+ );
2237
+ const { Bun, stableHash: contextStableHash } = context.module.exports;
2238
+ assert.equal(Bun.hash, contextStableHash, `Bun.hash should be identical to stableHash in ${markerKey}`);
2239
+ assert.equal(typeof Bun.hash.xxHash64, 'function', `Bun.hash.xxHash64 should be a function in ${markerKey}`);
2240
+ const testResult = Bun.hash.xxHash64('x').toString(36);
2241
+ assert.match(testResult, /^[0-9a-z]{1,13}$/, `Bun.hash.xxHash64('x').toString(36) should match pattern in ${markerKey}, got: ${testResult}`);
2242
+ }
2243
+ });
@@ -0,0 +1,142 @@
1
+ // Faithful re-implementation of the vendor-side consumer (class _d) from
2
+ // cellsegmenter-extracted-functions.js, so we can exercise the shim exactly
3
+ // the way claude-code 2.1.272 does.
4
+ const createShim = require('../bun-cellsegmenter-shim.js');
5
+
6
+ // Create shim factory that accepts stringWidth and graphemeWidth
7
+ function createHarness(stringWidth, graphemeWidth) {
8
+ const { CellSegmenter, sliceAnsi, sleepSync } = createShim({
9
+ stringWidth,
10
+ graphemeWidth,
11
+ });
12
+
13
+ const fl = 17, Fo = 2, kr = 32767, pn = 3, Ub = 10, fC = 255, dC = 256, Eut = 8;
14
+ const aXe = [[1564, 1564], [8234, 8238], [8294, 8297]];
15
+ function qn(n, s, u) { return n << fl | s << Fo | u; }
16
+ function Ys(n, s, u) {
17
+ if (n.length >= s) return n;
18
+ let f = new Int32Array(Math.max(s, 2 * n.length));
19
+ if (u > 0) f.set(n.subarray(0, Math.min(u, n.length)));
20
+ return f;
21
+ }
22
+ class Pool {
23
+ constructor(seed) { this.arr = seed ? seed.slice() : []; this.map = new Map(); this.arr.forEach((v, i) => this.map.set(v, i)); }
24
+ intern(v) { if (this.map.has(v)) return this.map.get(v); const i = this.arr.length; this.arr.push(v); this.map.set(v, i); return i; }
25
+ get(i) { return this.arr[i]; }
26
+ }
27
+ function As() {
28
+ return new CellSegmenter({
29
+ ambiguousIsNarrow: true,
30
+ substitute: aXe,
31
+ screen: { widthMask: pn, narrow: 0, wide: 1, spacerTail: 2, spacerHead: 3, emptyCharIndex: 0, spacerCharIndex: 1, emptyWord: qn(0, 0, 0), tabWidth: Eut },
32
+ });
33
+ }
34
+ // class _d
35
+ class D {
36
+ constructor(stylePool, charPool) {
37
+ this.stylePool = stylePool; this.charPool = charPool;
38
+ this.native = As();
39
+ this.cells = new Int32Array(512); this.runs = new Int32Array(512);
40
+ this.count = 0; this.reordered = false;
41
+ this.graphemes = this.native.graphemes;
42
+ this.sgrKeys = this.native.sgrKeys;
43
+ this.sgrCloseKeys = this.native.sgrCloseKeys;
44
+ this.uris = this.native.uris;
45
+ this.charMap = new Int32Array(256); this.charMapLength = 0;
46
+ this.styleIds = new Int32Array(64);
47
+ this.linkIds = new Int32Array(16);
48
+ this.words = new Int32Array(64);
49
+ this.retries = 0;
50
+ }
51
+ segment(n, s) {
52
+ let u = this.native.segment(n, this.cells, this.runs, s);
53
+ if (u < 0) {
54
+ this.retries++;
55
+ let f = Math.max(-u, this.cells.length);
56
+ this.cells = new Int32Array(2 * f); this.runs = new Int32Array(2 * f);
57
+ u = this.native.segment(n, this.cells, this.runs, s);
58
+ }
59
+ this.count = u; this.reordered = s; return u;
60
+ }
61
+ width(n, s, u) {
62
+ let f = this.segment(n, u), p = s;
63
+ for (let y = 0; y < f; y++) {
64
+ let S = this.cells[2 * y + 1];
65
+ p += (S & dC) !== 0 ? Eut - p % Eut : S & fC;
66
+ }
67
+ return p - s;
68
+ }
69
+ charIndices() {
70
+ let n = this.graphemes;
71
+ if (this.charMapLength < n.length) {
72
+ this.charMap = Ys(this.charMap, n.length, this.charMapLength);
73
+ for (let s = this.charMapLength; s < n.length; s++) this.charMap[s] = this.charPool.intern(n[s]);
74
+ this.charMapLength = n.length;
75
+ }
76
+ return this.charMap;
77
+ }
78
+ // verbatim from vendor bundle
79
+ runWords(n) {
80
+ let s = this.count;
81
+ if (s === 0) return this.words;
82
+ if (this.hyperlinkPool !== n) { this.hyperlinkPool = n; this.linkIds.fill(0); }
83
+ let u = this.cells[2 * s - 1] >>> Ub;
84
+ if (this.reordered) for (let p = 0; p < s; p++) u = Math.max(u, this.cells[2 * p + 1] >>> Ub);
85
+ let f = u + 1;
86
+ this.words = Ys(this.words, f, 0);
87
+ this.runCount = f;
88
+ for (let p = 0; p < f; p++) {
89
+ let y = this.runs[2 * p + 1], S = 0;
90
+ if (y !== 0) {
91
+ if (this.linkIds = Ys(this.linkIds, y + 1, this.linkIds.length), S = this.linkIds[y], S === 0)
92
+ S = n.intern(this.uris[y]) + 1, this.linkIds[y] = S;
93
+ S -= 1;
94
+ }
95
+ this.words[p] = qn(this.styleId(this.runs[2 * p]), S, 0);
96
+ }
97
+ return this.words;
98
+ }
99
+ paint(n, s, u, f, p) {
100
+ return this.native.paint(n, s, u, f, this.cells, this.count, void 0, this.charIndices(), this.runWords(p));
101
+ }
102
+ // ansiCodes / styleId per vendor bundle
103
+ ansiCodes(n) {
104
+ if (n === 0) return [];
105
+ let s = this.sgrKeys[n].split('\x00'), u = this.sgrCloseKeys[n].split('\x00'), f = [];
106
+ for (let p = 0; p < s.length; p++) {
107
+ let y = s[p];
108
+ if (mC.test(y)) f.push({ type: 'ansi', code: y, endCode: u[p] });
109
+ }
110
+ return f;
111
+ }
112
+ styleId(n) {
113
+ this.styleIds = Ys(this.styleIds, n + 1, this.styleIds.length);
114
+ let s = this.styleIds[n];
115
+ if (s === 0) { s = this.stylePool.intern(JSON.stringify(this.ansiCodes(n))) + 1; this.styleIds[n] = s; }
116
+ return s - 1;
117
+ }
118
+ }
119
+ const mC = /^\x1b\[(?:\d{1,3})(?:;5;\d{1,3}|;2;\d{1,3};\d{1,3};\d{1,3})?m$/;
120
+
121
+ // Y0 damage decode
122
+ function Y0(u) {
123
+ let f = Math.floor(u / 1048576) % 65536;
124
+ let p = Math.floor(u / 68719476736);
125
+ if (f >= p) return null;
126
+ return { x: f, width: p - f };
127
+ }
128
+
129
+ function mkScreen(width, height) {
130
+ return { width, height, cells: new Int32Array(width * height * 2) };
131
+ }
132
+ function readCell(screen, charPool, hyperPool, x, y) {
133
+ const i = (y * screen.width + x) << 1;
134
+ const p = screen.cells[i + 1];
135
+ const h = p >>> Fo & kr;
136
+ return { char: charPool.get(screen.cells[i]), styleId: p >>> fl, width: p & pn, hyperlink: h === 0 ? undefined : hyperPool.get(h) };
137
+ }
138
+
139
+ return { CellSegmenter, sliceAnsi, sleepSync, D, Pool, As, qn, Y0, mkScreen, readCell, mC, fl, Fo, kr, pn, Ub, fC, dC };
140
+ }
141
+
142
+ module.exports = createHarness;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash0816/claude-code",
3
- "version": "2.1.270",
3
+ "version": "2.1.276",
4
4
  "description": "Unofficial Termux-native Claude Code wrapper with audited native replay",
5
5
  "license": "GPL-3.0-only",
6
6
  "bin": {