@wrongstack/tools 0.267.0 → 0.269.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/dist/batch-tool-use.js.map +1 -1
- package/dist/builtin.js +147 -131
- package/dist/builtin.js.map +1 -1
- package/dist/codebase-index/index.js +101 -85
- package/dist/codebase-index/index.js.map +1 -1
- package/dist/codebase-index/worker.js +101 -85
- package/dist/codebase-index/worker.js.map +1 -1
- package/dist/exec.js +63 -12
- package/dist/exec.js.map +1 -1
- package/dist/fetch.js.map +1 -1
- package/dist/index.js +147 -131
- package/dist/index.js.map +1 -1
- package/dist/pack.js +147 -131
- package/dist/pack.js.map +1 -1
- package/dist/search.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -711,13 +711,13 @@ async function globFiles(pattern, base, extraGlob) {
|
|
|
711
711
|
return await globNative(pattern, base, extraGlob);
|
|
712
712
|
}
|
|
713
713
|
function checkRg() {
|
|
714
|
-
return new Promise((
|
|
714
|
+
return new Promise((resolve6) => {
|
|
715
715
|
try {
|
|
716
716
|
const p = spawn("rg", ["--version"], { env: buildChildEnv(), stdio: "ignore", windowsHide: true });
|
|
717
|
-
p.on("error", () =>
|
|
718
|
-
p.on("close", (code) =>
|
|
717
|
+
p.on("error", () => resolve6(false));
|
|
718
|
+
p.on("close", (code) => resolve6(code === 0));
|
|
719
719
|
} catch {
|
|
720
|
-
|
|
720
|
+
resolve6(false);
|
|
721
721
|
}
|
|
722
722
|
});
|
|
723
723
|
}
|
|
@@ -734,10 +734,10 @@ function spawnRgFind(pattern, base) {
|
|
|
734
734
|
buf += chunk.toString();
|
|
735
735
|
});
|
|
736
736
|
return {
|
|
737
|
-
promise: new Promise((
|
|
737
|
+
promise: new Promise((resolve6, reject) => {
|
|
738
738
|
child.on("error", reject);
|
|
739
739
|
child.on("close", () => {
|
|
740
|
-
|
|
740
|
+
resolve6(buf.split("\n").filter(Boolean));
|
|
741
741
|
});
|
|
742
742
|
})
|
|
743
743
|
};
|
|
@@ -943,13 +943,13 @@ var grepTool = {
|
|
|
943
943
|
}
|
|
944
944
|
};
|
|
945
945
|
async function detectRg(signal) {
|
|
946
|
-
return new Promise((
|
|
946
|
+
return new Promise((resolve6) => {
|
|
947
947
|
try {
|
|
948
948
|
const p = spawn("rg", ["--version"], { env: buildChildEnv(), stdio: "ignore", signal, windowsHide: true });
|
|
949
|
-
p.on("error", () =>
|
|
950
|
-
p.on("close", (code) =>
|
|
949
|
+
p.on("error", () => resolve6(false));
|
|
950
|
+
p.on("close", (code) => resolve6(code === 0));
|
|
951
951
|
} catch {
|
|
952
|
-
|
|
952
|
+
resolve6(false);
|
|
953
953
|
}
|
|
954
954
|
});
|
|
955
955
|
}
|
|
@@ -2024,10 +2024,10 @@ var bashTool = {
|
|
|
2024
2024
|
queue.push(c);
|
|
2025
2025
|
}
|
|
2026
2026
|
};
|
|
2027
|
-
const next = () => new Promise((
|
|
2027
|
+
const next = () => new Promise((resolve6) => {
|
|
2028
2028
|
const c = queue.shift();
|
|
2029
|
-
if (c)
|
|
2030
|
-
else resolveNext =
|
|
2029
|
+
if (c) resolve6(c);
|
|
2030
|
+
else resolveNext = resolve6;
|
|
2031
2031
|
});
|
|
2032
2032
|
let lastFlush = Date.now();
|
|
2033
2033
|
const flush = () => {
|
|
@@ -2323,26 +2323,26 @@ var execTool = {
|
|
|
2323
2323
|
allowed: false
|
|
2324
2324
|
};
|
|
2325
2325
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2326
|
+
let cwd;
|
|
2327
|
+
try {
|
|
2328
|
+
cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : await safeResolveReal(ctx.cwd, ctx);
|
|
2329
|
+
} catch {
|
|
2329
2330
|
return {
|
|
2330
2331
|
command: cmd,
|
|
2331
2332
|
args,
|
|
2332
2333
|
stdout: "",
|
|
2333
|
-
stderr: `cwd "${input.cwd}" resolves outside project root`,
|
|
2334
|
+
stderr: `cwd "${input.cwd ?? ctx.cwd}" resolves outside project root`,
|
|
2334
2335
|
exitCode: 1,
|
|
2335
2336
|
truncated: false,
|
|
2336
2337
|
allowed: false
|
|
2337
2338
|
};
|
|
2338
2339
|
}
|
|
2339
|
-
const cwd = requestedCwd;
|
|
2340
2340
|
const signal = opts.signal;
|
|
2341
2341
|
return runCommand(cmd, args, cwd, timeout, signal, ctx.session?.id);
|
|
2342
2342
|
}
|
|
2343
2343
|
};
|
|
2344
2344
|
function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
|
|
2345
|
-
return new Promise((
|
|
2345
|
+
return new Promise((resolve6) => {
|
|
2346
2346
|
let stdout = "";
|
|
2347
2347
|
let stderr = "";
|
|
2348
2348
|
let killed = false;
|
|
@@ -2397,7 +2397,7 @@ function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
|
|
|
2397
2397
|
const exitCode = killed ? 124 : code ?? 1;
|
|
2398
2398
|
registry.afterCall(durationMs, exitCode !== 0);
|
|
2399
2399
|
const spooled = spool.finalize();
|
|
2400
|
-
|
|
2400
|
+
resolve6({
|
|
2401
2401
|
command: cmd,
|
|
2402
2402
|
args,
|
|
2403
2403
|
stdout: normalizeCommandOutput(stdout) + (spooled ? spoolNote(spooled) : ""),
|
|
@@ -2413,7 +2413,7 @@ function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
|
|
|
2413
2413
|
if (typeof pid === "number") registry.unregister(pid);
|
|
2414
2414
|
registry.afterCall(Date.now() - startedAt, true);
|
|
2415
2415
|
spool.finalize();
|
|
2416
|
-
|
|
2416
|
+
resolve6({
|
|
2417
2417
|
command: cmd,
|
|
2418
2418
|
args,
|
|
2419
2419
|
stdout: normalizeCommandOutput(stdout),
|
|
@@ -3499,7 +3499,7 @@ function buildArgs(input) {
|
|
|
3499
3499
|
}
|
|
3500
3500
|
}
|
|
3501
3501
|
function runGit(args, cwd, signal) {
|
|
3502
|
-
return new Promise((
|
|
3502
|
+
return new Promise((resolve6) => {
|
|
3503
3503
|
let stdout = "";
|
|
3504
3504
|
let stderr = "";
|
|
3505
3505
|
const child = spawn("git", args, {
|
|
@@ -3520,7 +3520,7 @@ function runGit(args, cwd, signal) {
|
|
|
3520
3520
|
}
|
|
3521
3521
|
});
|
|
3522
3522
|
child.on("error", (err) => {
|
|
3523
|
-
|
|
3523
|
+
resolve6({
|
|
3524
3524
|
command: args[0],
|
|
3525
3525
|
stdout: normalizeCommandOutput(stdout),
|
|
3526
3526
|
stderr: err.message,
|
|
@@ -3529,7 +3529,7 @@ function runGit(args, cwd, signal) {
|
|
|
3529
3529
|
});
|
|
3530
3530
|
});
|
|
3531
3531
|
child.on("close", (code) => {
|
|
3532
|
-
|
|
3532
|
+
resolve6({
|
|
3533
3533
|
command: args[0],
|
|
3534
3534
|
stdout: normalizeCommandOutput(stdout),
|
|
3535
3535
|
stderr: normalizeCommandOutput(stderr),
|
|
@@ -3629,7 +3629,7 @@ function stripPathComponents(p, strip) {
|
|
|
3629
3629
|
return parts.slice(strip).join("/");
|
|
3630
3630
|
}
|
|
3631
3631
|
function runPatch(args, cwd, signal) {
|
|
3632
|
-
return new Promise((
|
|
3632
|
+
return new Promise((resolve6) => {
|
|
3633
3633
|
let stdout = "";
|
|
3634
3634
|
let stderr = "";
|
|
3635
3635
|
const env = { ...buildChildEnv(), LANG: "C", LC_ALL: "C" };
|
|
@@ -3640,8 +3640,8 @@ function runPatch(args, cwd, signal) {
|
|
|
3640
3640
|
child.stderr?.on("data", (c) => {
|
|
3641
3641
|
stderr += c.toString();
|
|
3642
3642
|
});
|
|
3643
|
-
child.on("close", (code) =>
|
|
3644
|
-
child.on("error", (e) =>
|
|
3643
|
+
child.on("close", (code) => resolve6({ exitCode: code ?? 1, stdout, stderr }));
|
|
3644
|
+
child.on("error", (e) => resolve6({ exitCode: 1, stdout: "", stderr: e.message }));
|
|
3645
3645
|
});
|
|
3646
3646
|
}
|
|
3647
3647
|
function extractPatchedFiles(output) {
|
|
@@ -3727,8 +3727,8 @@ var jsonTool = {
|
|
|
3727
3727
|
};
|
|
3728
3728
|
}
|
|
3729
3729
|
};
|
|
3730
|
-
function query(data,
|
|
3731
|
-
const parts =
|
|
3730
|
+
function query(data, path20) {
|
|
3731
|
+
const parts = path20.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
3732
3732
|
let current = data;
|
|
3733
3733
|
for (const part of parts) {
|
|
3734
3734
|
if (current === null || current === void 0) return void 0;
|
|
@@ -3869,7 +3869,7 @@ function findGitDir2(cwd) {
|
|
|
3869
3869
|
return null;
|
|
3870
3870
|
}
|
|
3871
3871
|
function runGit2(args, cwd, signal) {
|
|
3872
|
-
return new Promise((
|
|
3872
|
+
return new Promise((resolve6) => {
|
|
3873
3873
|
let stdout = "";
|
|
3874
3874
|
let stderr = "";
|
|
3875
3875
|
const child = spawn("git", args, {
|
|
@@ -3885,8 +3885,8 @@ function runGit2(args, cwd, signal) {
|
|
|
3885
3885
|
child.stderr?.on("data", (c) => {
|
|
3886
3886
|
stderr += c.toString();
|
|
3887
3887
|
});
|
|
3888
|
-
child.on("close", (code) =>
|
|
3889
|
-
child.on("error", (e) =>
|
|
3888
|
+
child.on("close", (code) => resolve6({ stdout, stderr, exitCode: code ?? 0 }));
|
|
3889
|
+
child.on("error", (e) => resolve6({ stdout: "", stderr: e.message, exitCode: 1 }));
|
|
3890
3890
|
});
|
|
3891
3891
|
}
|
|
3892
3892
|
async function fileDiff(input, ctx, _signal) {
|
|
@@ -4204,8 +4204,8 @@ async function* spawnStream(opts) {
|
|
|
4204
4204
|
try {
|
|
4205
4205
|
for (; ; ) {
|
|
4206
4206
|
while (queue.length === 0) {
|
|
4207
|
-
await new Promise((
|
|
4208
|
-
waiter =
|
|
4207
|
+
await new Promise((resolve6) => {
|
|
4208
|
+
waiter = resolve6;
|
|
4209
4209
|
});
|
|
4210
4210
|
}
|
|
4211
4211
|
const chunk = queue.shift();
|
|
@@ -4997,7 +4997,7 @@ var outdatedTool = {
|
|
|
4997
4997
|
}
|
|
4998
4998
|
};
|
|
4999
4999
|
function runOutdated(manager, args, cwd, signal) {
|
|
5000
|
-
return new Promise((
|
|
5000
|
+
return new Promise((resolve6) => {
|
|
5001
5001
|
let stdout = "";
|
|
5002
5002
|
let stderr = "";
|
|
5003
5003
|
const MAX = 1e5;
|
|
@@ -5013,10 +5013,10 @@ function runOutdated(manager, args, cwd, signal) {
|
|
|
5013
5013
|
});
|
|
5014
5014
|
child.on("close", (code) => {
|
|
5015
5015
|
const result = parseOutdatedOutput(stdout, code ?? 0);
|
|
5016
|
-
|
|
5016
|
+
resolve6(result);
|
|
5017
5017
|
});
|
|
5018
5018
|
child.on("error", (e) => {
|
|
5019
|
-
|
|
5019
|
+
resolve6({
|
|
5020
5020
|
exit_code: 1,
|
|
5021
5021
|
packages: [],
|
|
5022
5022
|
total: 0,
|
|
@@ -5142,7 +5142,7 @@ async function dockerLogs(service, lines, filterRe, cwd, signal, since) {
|
|
|
5142
5142
|
};
|
|
5143
5143
|
}
|
|
5144
5144
|
args.push("--timestamps", service);
|
|
5145
|
-
return new Promise((
|
|
5145
|
+
return new Promise((resolve6) => {
|
|
5146
5146
|
let stdout = "";
|
|
5147
5147
|
let stderr = "";
|
|
5148
5148
|
const MAX = 2e5;
|
|
@@ -5158,7 +5158,7 @@ async function dockerLogs(service, lines, filterRe, cwd, signal, since) {
|
|
|
5158
5158
|
if (settled) return;
|
|
5159
5159
|
settled = true;
|
|
5160
5160
|
clearTimeout(timer);
|
|
5161
|
-
|
|
5161
|
+
resolve6(result);
|
|
5162
5162
|
};
|
|
5163
5163
|
const child = spawn("docker", args, { cwd, signal, env: buildChildEnv(), stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
5164
5164
|
const timer = setTimeout(() => {
|
|
@@ -5193,7 +5193,7 @@ async function dockerLogs(service, lines, filterRe, cwd, signal, since) {
|
|
|
5193
5193
|
}
|
|
5194
5194
|
var DOCKER_LOGS_TIMEOUT_MS = 3e3;
|
|
5195
5195
|
var MAX_TAIL_LINES = 1e5;
|
|
5196
|
-
async function fileLogs(
|
|
5196
|
+
async function fileLogs(path20, lines, filterRe, stream) {
|
|
5197
5197
|
const { createInterface } = await import('node:readline');
|
|
5198
5198
|
const { createReadStream } = await import('node:fs');
|
|
5199
5199
|
const entries = [];
|
|
@@ -5202,7 +5202,7 @@ async function fileLogs(path21, lines, filterRe, stream) {
|
|
|
5202
5202
|
let writeIdx = 0;
|
|
5203
5203
|
let totalLines = 0;
|
|
5204
5204
|
const rl = createInterface({
|
|
5205
|
-
input: createReadStream(
|
|
5205
|
+
input: createReadStream(path20),
|
|
5206
5206
|
crlfDelay: Number.POSITIVE_INFINITY
|
|
5207
5207
|
});
|
|
5208
5208
|
for await (const line of rl) {
|
|
@@ -5223,7 +5223,7 @@ async function fileLogs(path21, lines, filterRe, stream) {
|
|
|
5223
5223
|
if (parsed) entries.push(parsed);
|
|
5224
5224
|
}
|
|
5225
5225
|
return {
|
|
5226
|
-
source:
|
|
5226
|
+
source: path20,
|
|
5227
5227
|
entries,
|
|
5228
5228
|
total: entries.length,
|
|
5229
5229
|
truncated: totalLines > effLines,
|
|
@@ -6534,7 +6534,7 @@ var IndexStore = class {
|
|
|
6534
6534
|
throw new LockError(`SQLite lock conflict after ${MAX_LOCK_RETRIES} retries: ${msg}`);
|
|
6535
6535
|
}
|
|
6536
6536
|
const delay = Math.min(
|
|
6537
|
-
LOCK_RETRY_BASE_DELAY_MS *
|
|
6537
|
+
LOCK_RETRY_BASE_DELAY_MS * 2 ** attempt,
|
|
6538
6538
|
LOCK_RETRY_MAX_DELAY_MS
|
|
6539
6539
|
);
|
|
6540
6540
|
sleepSync(delay);
|
|
@@ -6827,14 +6827,15 @@ var IndexStore = class {
|
|
|
6827
6827
|
if (!query2.trim()) {
|
|
6828
6828
|
return { results: candidates.slice(0, limit), total: candidates.length };
|
|
6829
6829
|
}
|
|
6830
|
+
const candidateById = new Map(candidates.map((c) => [c.id, c]));
|
|
6830
6831
|
const bm25 = buildBm25Index(
|
|
6831
6832
|
candidates.map((c) => ({ id: c.id, text: buildIndexableText(c.name, c.signature, c.docComment) }))
|
|
6832
6833
|
);
|
|
6833
|
-
const scored = bm25.score(query2, (id) =>
|
|
6834
|
+
const scored = bm25.score(query2, (id) => candidateById.has(id));
|
|
6834
6835
|
scored.sort((a, b) => b.score - a.score);
|
|
6835
6836
|
const qTokens = tokenise(query2);
|
|
6836
6837
|
const results = scored.slice(0, limit).map(({ id, score }) => {
|
|
6837
|
-
const c = expectDefined(
|
|
6838
|
+
const c = expectDefined(candidateById.get(id));
|
|
6838
6839
|
return { ...c, score, snippet: bm25.extractSnippet(id, qTokens) };
|
|
6839
6840
|
});
|
|
6840
6841
|
return { results, total: candidates.length };
|
|
@@ -8251,8 +8252,9 @@ async function loadGitignoreMatcher(projectRoot) {
|
|
|
8251
8252
|
|
|
8252
8253
|
// src/codebase-index/indexer.ts
|
|
8253
8254
|
var YIELD_EVERY_N = 50;
|
|
8255
|
+
var PARALLEL_BATCH = 20;
|
|
8254
8256
|
function yieldEventLoop() {
|
|
8255
|
-
return new Promise((
|
|
8257
|
+
return new Promise((resolve6) => setImmediate(resolve6));
|
|
8256
8258
|
}
|
|
8257
8259
|
function throwIfAborted(signal) {
|
|
8258
8260
|
if (!signal?.aborted) return;
|
|
@@ -8384,97 +8386,111 @@ async function runIndexerWithStore(store, opts) {
|
|
|
8384
8386
|
if (!force) {
|
|
8385
8387
|
for (const meta of store.getAllFileMetas()) existingMeta.set(meta.file, meta);
|
|
8386
8388
|
}
|
|
8387
|
-
for (let
|
|
8388
|
-
const
|
|
8389
|
-
|
|
8390
|
-
|
|
8389
|
+
for (let batchStart = 0; batchStart < files.length; batchStart += PARALLEL_BATCH) {
|
|
8390
|
+
const batchEnd = Math.min(batchStart + PARALLEL_BATCH, files.length);
|
|
8391
|
+
const batchFiles = files.slice(batchStart, batchEnd);
|
|
8392
|
+
opts.onProgress?.(batchEnd, files.length);
|
|
8393
|
+
if (batchStart > 0 && batchStart % YIELD_EVERY_N === 0) {
|
|
8391
8394
|
await yieldEventLoop();
|
|
8392
8395
|
throwIfAborted(signal);
|
|
8393
8396
|
}
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
if (!stat11.isFile()) continue;
|
|
8404
|
-
const lang = detectLang(file);
|
|
8405
|
-
if (!lang) continue;
|
|
8406
|
-
const meta = existingMeta.get(file);
|
|
8407
|
-
if (!force && meta && meta.mtimeMs === Math.floor(stat11.mtimeMs)) {
|
|
8408
|
-
langStats[lang] = (langStats[lang] ?? 0) + meta.symbolCount;
|
|
8409
|
-
symbolsIndexed += meta.symbolCount;
|
|
8410
|
-
filesIndexed++;
|
|
8411
|
-
continue;
|
|
8412
|
-
}
|
|
8413
|
-
store.deleteRefsForFile(file);
|
|
8414
|
-
store.deleteSymbolsForFile(file);
|
|
8415
|
-
let content;
|
|
8416
|
-
try {
|
|
8417
|
-
content = await fs4.readFile(file, { encoding: "utf8", signal });
|
|
8418
|
-
} catch (e) {
|
|
8419
|
-
if (isAbortError(e)) throw e;
|
|
8420
|
-
errors.push(`read error: ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
8421
|
-
continue;
|
|
8422
|
-
}
|
|
8423
|
-
let parsed;
|
|
8424
|
-
try {
|
|
8425
|
-
parsed = await parseFile(file, content, lang);
|
|
8426
|
-
} catch (e) {
|
|
8427
|
-
errors.push(`parse error: ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
8428
|
-
continue;
|
|
8429
|
-
}
|
|
8430
|
-
if (parsed.symbols.length === 0) {
|
|
8431
|
-
store.upsertFile({
|
|
8432
|
-
file,
|
|
8433
|
-
lang,
|
|
8434
|
-
mtimeMs: Math.floor(stat11.mtimeMs),
|
|
8435
|
-
symbolCount: 0,
|
|
8436
|
-
lastIndexed: Date.now()
|
|
8437
|
-
});
|
|
8438
|
-
filesIndexed++;
|
|
8439
|
-
continue;
|
|
8440
|
-
}
|
|
8441
|
-
const nextId = store.getMaxSymbolId() + 1;
|
|
8442
|
-
const symbolsWithIds = parsed.symbols.map((s, i) => ({ ...s, id: nextId + i }));
|
|
8443
|
-
store.insertSymbols(symbolsWithIds, nextId);
|
|
8444
|
-
const count = symbolsWithIds.length;
|
|
8445
|
-
symbolsIndexed += count;
|
|
8446
|
-
langStats[lang] = (langStats[lang] ?? 0) + count;
|
|
8447
|
-
if (parsed.refs && parsed.refs.length > 0) {
|
|
8448
|
-
const refsByLine = /* @__PURE__ */ new Map();
|
|
8449
|
-
for (const r of parsed.refs) {
|
|
8450
|
-
let arr = refsByLine.get(r.line);
|
|
8451
|
-
if (!arr) {
|
|
8452
|
-
arr = [];
|
|
8453
|
-
refsByLine.set(r.line, arr);
|
|
8397
|
+
const statOpts = signal ? { signal } : {};
|
|
8398
|
+
const statReadParse = await Promise.allSettled(
|
|
8399
|
+
batchFiles.map(async (file) => {
|
|
8400
|
+
let stat11;
|
|
8401
|
+
try {
|
|
8402
|
+
stat11 = await fs4.stat(file, statOpts);
|
|
8403
|
+
} catch (e) {
|
|
8404
|
+
if (isAbortError(e)) throw e;
|
|
8405
|
+
return { file, stat: null, lang: "", parsed: null, error: `stat error: ${e instanceof Error ? e.message : String(e)}` };
|
|
8454
8406
|
}
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8407
|
+
if (!stat11.isFile()) return { file, stat: stat11, lang: "", parsed: null };
|
|
8408
|
+
const lang = detectLang(file);
|
|
8409
|
+
if (!lang) return { file, stat: stat11, lang: "", parsed: null };
|
|
8410
|
+
const meta = existingMeta.get(file);
|
|
8411
|
+
if (!force && meta && meta.mtimeMs === Math.floor(stat11.mtimeMs)) {
|
|
8412
|
+
return { file, stat: stat11, lang, parsed: null, skippedMeta: meta };
|
|
8413
|
+
}
|
|
8414
|
+
let content;
|
|
8415
|
+
try {
|
|
8416
|
+
content = await fs4.readFile(file, { encoding: "utf8", signal });
|
|
8417
|
+
} catch (e) {
|
|
8418
|
+
if (isAbortError(e)) throw e;
|
|
8419
|
+
return { file, stat: stat11, lang, parsed: null, error: `read error: ${e instanceof Error ? e.message : String(e)}` };
|
|
8464
8420
|
}
|
|
8421
|
+
let parsed;
|
|
8422
|
+
try {
|
|
8423
|
+
parsed = await parseFile(file, content, lang);
|
|
8424
|
+
} catch (e) {
|
|
8425
|
+
return { file, stat: stat11, lang, parsed: null, error: `parse error: ${e instanceof Error ? e.message : String(e)}` };
|
|
8426
|
+
}
|
|
8427
|
+
return { file, stat: stat11, lang, parsed, content };
|
|
8428
|
+
})
|
|
8429
|
+
);
|
|
8430
|
+
for (let fi = 0; fi < statReadParse.length; fi++) {
|
|
8431
|
+
const settled = statReadParse[fi];
|
|
8432
|
+
const file = expectDefined(batchFiles[fi]);
|
|
8433
|
+
if (settled.status === "rejected") {
|
|
8434
|
+
const err = settled.reason;
|
|
8435
|
+
if (err instanceof Error && isAbortError(err)) throw err;
|
|
8436
|
+
errors.push(`batch error: ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
8437
|
+
continue;
|
|
8438
|
+
}
|
|
8439
|
+
const result = settled.value;
|
|
8440
|
+
if (result.error) {
|
|
8441
|
+
if (result.stat) store.deleteFile(file);
|
|
8442
|
+
if (result.error.includes("error:")) errors.push(result.error);
|
|
8443
|
+
continue;
|
|
8465
8444
|
}
|
|
8466
|
-
|
|
8467
|
-
|
|
8445
|
+
const { stat: stat11, lang, parsed } = result;
|
|
8446
|
+
if (result.skippedMeta) {
|
|
8447
|
+
langStats[lang] = (langStats[lang] ?? 0) + result.skippedMeta.symbolCount;
|
|
8448
|
+
symbolsIndexed += result.skippedMeta.symbolCount;
|
|
8449
|
+
filesIndexed++;
|
|
8450
|
+
continue;
|
|
8468
8451
|
}
|
|
8452
|
+
if (!lang || !parsed) {
|
|
8453
|
+
if (lang) {
|
|
8454
|
+
store.upsertFile({ file, lang, mtimeMs: Math.floor(stat11.mtimeMs), symbolCount: 0, lastIndexed: Date.now() });
|
|
8455
|
+
filesIndexed++;
|
|
8456
|
+
}
|
|
8457
|
+
continue;
|
|
8458
|
+
}
|
|
8459
|
+
store.deleteRefsForFile(file);
|
|
8460
|
+
store.deleteSymbolsForFile(file);
|
|
8461
|
+
if (parsed.symbols.length === 0) {
|
|
8462
|
+
store.upsertFile({ file, lang, mtimeMs: Math.floor(stat11.mtimeMs), symbolCount: 0, lastIndexed: Date.now() });
|
|
8463
|
+
filesIndexed++;
|
|
8464
|
+
continue;
|
|
8465
|
+
}
|
|
8466
|
+
const nextId = store.getMaxSymbolId() + 1;
|
|
8467
|
+
const symbolsWithIds = parsed.symbols.map((s, i) => ({ ...s, id: nextId + i }));
|
|
8468
|
+
store.insertSymbols(symbolsWithIds, nextId);
|
|
8469
|
+
const count = symbolsWithIds.length;
|
|
8470
|
+
symbolsIndexed += count;
|
|
8471
|
+
langStats[lang] = (langStats[lang] ?? 0) + count;
|
|
8472
|
+
if (parsed.refs && parsed.refs.length > 0) {
|
|
8473
|
+
const refsByLine = /* @__PURE__ */ new Map();
|
|
8474
|
+
for (const r of parsed.refs) {
|
|
8475
|
+
let arr = refsByLine.get(r.line);
|
|
8476
|
+
if (!arr) {
|
|
8477
|
+
arr = [];
|
|
8478
|
+
refsByLine.set(r.line, arr);
|
|
8479
|
+
}
|
|
8480
|
+
arr.push(r);
|
|
8481
|
+
}
|
|
8482
|
+
const batch = [];
|
|
8483
|
+
for (const sym of symbolsWithIds) {
|
|
8484
|
+
const symRefs = refsByLine.get(sym.line);
|
|
8485
|
+
if (symRefs) {
|
|
8486
|
+
for (const r of symRefs) batch.push({ ...r, fromId: sym.id });
|
|
8487
|
+
}
|
|
8488
|
+
}
|
|
8489
|
+
if (batch.length > 0) store.insertRefsBatch(batch);
|
|
8490
|
+
}
|
|
8491
|
+
store.upsertFile({ file, lang, mtimeMs: Math.floor(stat11.mtimeMs), symbolCount: count, lastIndexed: Date.now() });
|
|
8492
|
+
filesIndexed++;
|
|
8469
8493
|
}
|
|
8470
|
-
store.upsertFile({
|
|
8471
|
-
file,
|
|
8472
|
-
lang,
|
|
8473
|
-
mtimeMs: Math.floor(stat11.mtimeMs),
|
|
8474
|
-
symbolCount: count,
|
|
8475
|
-
lastIndexed: Date.now()
|
|
8476
|
-
});
|
|
8477
|
-
filesIndexed++;
|
|
8478
8494
|
}
|
|
8479
8495
|
for (const [file_] of existingMeta) {
|
|
8480
8496
|
try {
|
|
@@ -8656,7 +8672,7 @@ function shutdownCodebaseIndexHost() {
|
|
|
8656
8672
|
function callIndexOp(op, args, opts) {
|
|
8657
8673
|
const w = ensureWorker();
|
|
8658
8674
|
if (!w) return callInline(op, args, opts);
|
|
8659
|
-
return new Promise((
|
|
8675
|
+
return new Promise((resolve6, reject) => {
|
|
8660
8676
|
const id = nextRpcId++;
|
|
8661
8677
|
const timer = setTimeout(() => {
|
|
8662
8678
|
pending.delete(id);
|
|
@@ -8679,7 +8695,7 @@ function callIndexOp(op, args, opts) {
|
|
|
8679
8695
|
pending.set(id, {
|
|
8680
8696
|
resolve: (v) => {
|
|
8681
8697
|
cleanup();
|
|
8682
|
-
|
|
8698
|
+
resolve6(v);
|
|
8683
8699
|
},
|
|
8684
8700
|
reject: (e) => {
|
|
8685
8701
|
cleanup();
|