@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.
- package/README.md +4 -1
- package/config/claude-native-audited-versions.json +249 -1
- package/config/claude-termux-release-manifest.json +3 -3
- package/lib/bun-cellsegmenter-shim.js +569 -0
- package/lib/bunfs-esm-loader.mjs +156 -0
- package/lib/bunfs-esm-loader.test.js +885 -0
- package/lib/bunfs-extract.js +10 -1
- package/lib/bunfs-extract.test.js +36 -3
- package/lib/hooks-standalone-pattern.js +7 -0
- package/lib/hooks-standalone-pattern.test.js +115 -0
- package/lib/termux-run-claude-native.sh +52 -0
- package/lib/termux-run-claude-native.test.js +467 -0
- package/lib/test-support/vendor-cellsegmenter-harness.js +142 -0
- package/package.json +1 -1
package/lib/bunfs-esm-loader.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createRequire, syncBuiltinESMExports } from 'node:module';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
|
+
const { countQleMatches, applyQlePatch } = require('./hooks-standalone-pattern.js');
|
|
7
8
|
|
|
8
9
|
let PROCESS_OWNED_DIR = null;
|
|
9
10
|
let SOURCE_BIN = null;
|
|
@@ -13,6 +14,10 @@ let WS_STUB_PATH = null;
|
|
|
13
14
|
|
|
14
15
|
let CYCLE_HOISTS = [];
|
|
15
16
|
|
|
17
|
+
let HOOKS_METADATA = { status: 'field-absent', patches: [] };
|
|
18
|
+
let hooksLayerState = null;
|
|
19
|
+
let hooksFallbackWarned = false;
|
|
20
|
+
|
|
16
21
|
let REEXTRACT = null;
|
|
17
22
|
let reExtractConsecFailures = 0;
|
|
18
23
|
let lastReExtractMs = 0;
|
|
@@ -52,6 +57,31 @@ function resolveBunfsPath(id) {
|
|
|
52
57
|
return real;
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
function normalizeHooksMetadata(m) {
|
|
61
|
+
if (!m || typeof m !== 'object') {
|
|
62
|
+
return { status: 'field-absent', patches: [] };
|
|
63
|
+
}
|
|
64
|
+
let status = m.status;
|
|
65
|
+
if (!['ok', 'field-absent', 'entry-missing', 'read-failed'].includes(status)) {
|
|
66
|
+
status = 'read-failed';
|
|
67
|
+
}
|
|
68
|
+
let patches = m.patches;
|
|
69
|
+
if (!Array.isArray(patches)) {
|
|
70
|
+
if (status === 'ok') {
|
|
71
|
+
return { status: 'field-absent', patches: [] };
|
|
72
|
+
}
|
|
73
|
+
patches = [];
|
|
74
|
+
}
|
|
75
|
+
return { status, patches };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function warnOnce(message) {
|
|
79
|
+
if (!hooksFallbackWarned) {
|
|
80
|
+
console.error('[claude-code] ' + message);
|
|
81
|
+
hooksFallbackWarned = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
55
85
|
export function initialize(data) {
|
|
56
86
|
PROCESS_OWNED_DIR = data.processOwnedDir;
|
|
57
87
|
SOURCE_BIN = data.sourceBin;
|
|
@@ -60,6 +90,9 @@ export function initialize(data) {
|
|
|
60
90
|
WS_STUB_PATH = data.wsStubPath;
|
|
61
91
|
CYCLE_HOISTS = Array.isArray(data.cycleHoists) ? data.cycleHoists : [];
|
|
62
92
|
REEXTRACT = typeof data.reExtract === 'function' ? data.reExtract : null;
|
|
93
|
+
HOOKS_METADATA = normalizeHooksMetadata(data.hooksMetadata);
|
|
94
|
+
hooksLayerState = null;
|
|
95
|
+
hooksFallbackWarned = false;
|
|
63
96
|
globalThis.__bunfsRecoverMissing = recoverMissing;
|
|
64
97
|
globalThis.__bunfsResolvePath = resolveBunfsPath;
|
|
65
98
|
// 回復状態のリセット (テスト隔離・再 initialize 対応)
|
|
@@ -67,6 +100,116 @@ export function initialize(data) {
|
|
|
67
100
|
lastReExtractMs = 0;
|
|
68
101
|
}
|
|
69
102
|
|
|
103
|
+
function ensureHooksLayerState() {
|
|
104
|
+
if (hooksLayerState !== null) {
|
|
105
|
+
return hooksLayerState;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const layer1 = new Map();
|
|
109
|
+
let layer2 = true;
|
|
110
|
+
const { status, patches } = HOOKS_METADATA;
|
|
111
|
+
|
|
112
|
+
if (status === 'ok' && Array.isArray(patches) && patches.length > 0) {
|
|
113
|
+
// 全記録について「成立」判定を先読み+各失敗箇所で理由を設定
|
|
114
|
+
let allValid = true;
|
|
115
|
+
let failReason = 'unknown reason';
|
|
116
|
+
const seenFiles = new Set();
|
|
117
|
+
|
|
118
|
+
for (const record of patches) {
|
|
119
|
+
// (a) オブジェクト、file が空でない文字列、.. を含まない、絶対パスでない、PROCESS_OWNED_DIR 配下
|
|
120
|
+
if (!record || typeof record !== 'object') {
|
|
121
|
+
failReason = 'invalid record';
|
|
122
|
+
allValid = false;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (typeof record.file !== 'string' || !record.file) {
|
|
126
|
+
failReason = 'invalid file field';
|
|
127
|
+
allValid = false;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (record.file.includes('..')) {
|
|
131
|
+
failReason = 'file contains ..';
|
|
132
|
+
allValid = false;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
if (path.isAbsolute(record.file)) {
|
|
136
|
+
failReason = 'file is absolute path';
|
|
137
|
+
allValid = false;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
const real = path.resolve(PROCESS_OWNED_DIR, record.file);
|
|
141
|
+
if (path.relative(PROCESS_OWNED_DIR, real).startsWith('..')) {
|
|
142
|
+
failReason = 'path escapes owned dir';
|
|
143
|
+
allValid = false;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// (b) expectedOccurrences が 1 以上の整数
|
|
148
|
+
if (!Number.isInteger(record.expectedOccurrences) || record.expectedOccurrences < 1) {
|
|
149
|
+
failReason = 'invalid expectedOccurrences';
|
|
150
|
+
allValid = false;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// (c) file が他の記録と重複していない
|
|
155
|
+
if (seenFiles.has(record.file)) {
|
|
156
|
+
failReason = 'duplicate file';
|
|
157
|
+
allValid = false;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
seenFiles.add(record.file);
|
|
161
|
+
|
|
162
|
+
// (d) 対象ファイルを読める
|
|
163
|
+
let fileSource;
|
|
164
|
+
if (!existsSync(real)) {
|
|
165
|
+
if (!recoverMissing(real)) {
|
|
166
|
+
failReason = 'file not found or recovery failed';
|
|
167
|
+
allValid = false;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
fileSource = readFileSync(real, 'utf8');
|
|
173
|
+
} catch {
|
|
174
|
+
failReason = 'file read failed';
|
|
175
|
+
allValid = false;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// (e) countQleMatches が expectedOccurrences と一致
|
|
180
|
+
if (countQleMatches(fileSource) !== record.expectedOccurrences) {
|
|
181
|
+
const actual = countQleMatches(fileSource);
|
|
182
|
+
failReason = `occurrence count mismatch (expected ${record.expectedOccurrences}, found ${actual})`;
|
|
183
|
+
allValid = false;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (allValid) {
|
|
189
|
+
// 全件成立: layer1 に記録を詰める
|
|
190
|
+
for (const record of patches) {
|
|
191
|
+
layer1.set(record.file, record.expectedOccurrences);
|
|
192
|
+
}
|
|
193
|
+
layer2 = false;
|
|
194
|
+
} else {
|
|
195
|
+
// 1件でも不成立: layer1 空, layer2=true, 警告1回
|
|
196
|
+
warnOnce(`hooks standalone patch not applied (${failReason}); falling back to import.meta.dir shim (built-in plugin hooks degraded)`);
|
|
197
|
+
}
|
|
198
|
+
} else if (status === 'field-absent') {
|
|
199
|
+
// layer2=true, 警告は前置が実際に行われたときのみ
|
|
200
|
+
layer2 = true;
|
|
201
|
+
} else if (status === 'entry-missing') {
|
|
202
|
+
layer2 = true;
|
|
203
|
+
warnOnce('audited metadata entry missing for this version; built-in plugin hooks may be degraded');
|
|
204
|
+
} else if (status === 'read-failed') {
|
|
205
|
+
layer2 = true;
|
|
206
|
+
warnOnce('audited metadata could not be read; built-in plugin hooks may be degraded');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
hooksLayerState = { layer1, layer2 };
|
|
210
|
+
return hooksLayerState;
|
|
211
|
+
}
|
|
212
|
+
|
|
70
213
|
function tryHoistCycleBreakingImports(filePath, source) {
|
|
71
214
|
const rel = path.relative(PROCESS_OWNED_DIR, filePath);
|
|
72
215
|
const records = CYCLE_HOISTS.filter((r) => r.file === rel);
|
|
@@ -215,6 +358,19 @@ export function load(url, context, nextLoad) {
|
|
|
215
358
|
}
|
|
216
359
|
}
|
|
217
360
|
|
|
361
|
+
// 層1・層2処理
|
|
362
|
+
const rel = path.relative(PROCESS_OWNED_DIR, filePath);
|
|
363
|
+
const st = ensureHooksLayerState();
|
|
364
|
+
if (st.layer1.has(rel)) {
|
|
365
|
+
source = applyQlePatch(source);
|
|
366
|
+
}
|
|
367
|
+
if (st.layer2 && /\bimport\.meta\.dir\b/.test(source)) {
|
|
368
|
+
source = 'import.meta.dir ??= import.meta.dirname;\n' + source;
|
|
369
|
+
if (HOOKS_METADATA.status === 'field-absent') {
|
|
370
|
+
warnOnce('no hooks_standalone_patches record for this version but Bun-only import.meta.dir found in ' + rel + '; using import.meta.dir shim (built-in plugin hooks degraded)');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
218
374
|
let hoistedImportLine = '';
|
|
219
375
|
const hoistResult = tryHoistCycleBreakingImports(filePath, source);
|
|
220
376
|
if (hoistResult) {
|