@wrongstack/tools 0.77.0 → 0.84.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/dist/audit.d.ts +4 -4
- package/dist/audit.js +10 -2
- package/dist/audit.js.map +1 -1
- package/dist/{background-indexer-C70RD7LU.d.ts → background-indexer-DYm1FUxK.d.ts} +19 -19
- package/dist/bash.d.ts +4 -4
- package/dist/bash.js +31 -7
- package/dist/bash.js.map +1 -1
- package/dist/batch-tool-use.d.ts +4 -4
- package/dist/batch-tool-use.js.map +1 -1
- package/dist/builtin.js +217 -114
- package/dist/builtin.js.map +1 -1
- package/dist/circuit-breaker.d.ts +6 -6
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/codebase-index/index.d.ts +12 -12
- package/dist/codebase-index/index.js +79 -41
- package/dist/codebase-index/index.js.map +1 -1
- package/dist/diff.d.ts +7 -7
- package/dist/diff.js.map +1 -1
- package/dist/document.d.ts +6 -6
- package/dist/document.js.map +1 -1
- package/dist/edit.d.ts +1 -1
- package/dist/edit.js.map +1 -1
- package/dist/exec.d.ts +3 -3
- package/dist/exec.js +18 -6
- package/dist/exec.js.map +1 -1
- package/dist/fetch.d.ts +1 -1
- package/dist/fetch.js +21 -29
- package/dist/fetch.js.map +1 -1
- package/dist/format.d.ts +4 -4
- package/dist/format.js +18 -4
- package/dist/format.js.map +1 -1
- package/dist/git.d.ts +10 -10
- package/dist/git.js +8 -2
- package/dist/git.js.map +1 -1
- package/dist/glob.d.ts +2 -2
- package/dist/glob.js.map +1 -1
- package/dist/grep.d.ts +6 -6
- package/dist/grep.js +10 -2
- package/dist/grep.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +217 -114
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +5 -5
- package/dist/install.js +18 -4
- package/dist/install.js.map +1 -1
- package/dist/json.d.ts +8 -8
- package/dist/json.js.map +1 -1
- package/dist/lint.d.ts +4 -4
- package/dist/lint.js +18 -4
- package/dist/lint.js.map +1 -1
- package/dist/logs.d.ts +8 -8
- package/dist/logs.js.map +1 -1
- package/dist/memory.d.ts +2 -2
- package/dist/memory.js.map +1 -1
- package/dist/mode.d.ts +3 -3
- package/dist/mode.js.map +1 -1
- package/dist/outdated.d.ts +4 -4
- package/dist/outdated.js.map +1 -1
- package/dist/pack.js +217 -114
- package/dist/pack.js.map +1 -1
- package/dist/patch.d.ts +3 -3
- package/dist/patch.js.map +1 -1
- package/dist/process-registry.d.ts +3 -3
- package/dist/process-registry.js +7 -1
- package/dist/process-registry.js.map +1 -1
- package/dist/read.d.ts +2 -2
- package/dist/read.js.map +1 -1
- package/dist/replace.d.ts +4 -4
- package/dist/replace.js +8 -2
- package/dist/replace.js.map +1 -1
- package/dist/scaffold.d.ts +2 -2
- package/dist/scaffold.js.map +1 -1
- package/dist/search.d.ts +2 -2
- package/dist/search.js +20 -8
- package/dist/search.js.map +1 -1
- package/dist/test.d.ts +7 -7
- package/dist/test.js +18 -4
- package/dist/test.js.map +1 -1
- package/dist/tool-help.d.ts +4 -4
- package/dist/tool-help.js.map +1 -1
- package/dist/tool-search.d.ts +5 -5
- package/dist/tool-search.js.map +1 -1
- package/dist/tool-use.d.ts +2 -2
- package/dist/tool-use.js.map +1 -1
- package/dist/tree.d.ts +7 -7
- package/dist/tree.js +10 -2
- package/dist/tree.js.map +1 -1
- package/dist/typecheck.d.ts +4 -4
- package/dist/typecheck.js +18 -4
- package/dist/typecheck.js.map +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js.map +1 -1
- package/package.json +2 -2
package/dist/pack.js
CHANGED
|
@@ -19,6 +19,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
19
19
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
20
20
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
21
21
|
});
|
|
22
|
+
function expectDefined(value) {
|
|
23
|
+
if (value === null || value === void 0) {
|
|
24
|
+
throw new Error("Expected value to be defined");
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
22
28
|
async function* spawnStream(opts) {
|
|
23
29
|
const max = opts.maxBytes ?? 2e5;
|
|
24
30
|
const flushAt = opts.flushBytes ?? 4 * 1024;
|
|
@@ -70,7 +76,7 @@ async function* spawnStream(opts) {
|
|
|
70
76
|
waiter = resolve7;
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
|
-
const chunk = queue.shift();
|
|
79
|
+
const chunk = expectDefined(queue.shift());
|
|
74
80
|
if (chunk.kind === "close") {
|
|
75
81
|
if (!spawnFailed) exitCode = chunk.code ?? 0;
|
|
76
82
|
break;
|
|
@@ -97,6 +103,12 @@ async function* spawnStream(opts) {
|
|
|
97
103
|
error
|
|
98
104
|
};
|
|
99
105
|
}
|
|
106
|
+
function expectDefined2(value) {
|
|
107
|
+
if (value === null || value === void 0) {
|
|
108
|
+
throw new Error("Expected value to be defined");
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
100
112
|
async function detectPackageManager(cwd) {
|
|
101
113
|
const { stat: stat10 } = await import('node:fs/promises');
|
|
102
114
|
try {
|
|
@@ -186,9 +198,9 @@ function collapseConsecutiveDuplicates(text, minRun = REPEAT_RUN_THRESHOLD) {
|
|
|
186
198
|
while (j < lines.length && lines[j] === lines[i]) j++;
|
|
187
199
|
const run = j - i;
|
|
188
200
|
if (run >= minRun) {
|
|
189
|
-
out.push(lines[i], `\u2026 \u27E8repeated ${run}\xD7\u27E9`);
|
|
201
|
+
out.push(expectDefined2(lines[i]), `\u2026 \u27E8repeated ${run}\xD7\u27E9`);
|
|
190
202
|
} else {
|
|
191
|
-
for (let k = i; k < j; k++) out.push(lines[k]);
|
|
203
|
+
for (let k = i; k < j; k++) out.push(expectDefined2(lines[k]));
|
|
192
204
|
}
|
|
193
205
|
i = j;
|
|
194
206
|
}
|
|
@@ -265,7 +277,9 @@ var auditTool = {
|
|
|
265
277
|
},
|
|
266
278
|
async execute(input, ctx, opts) {
|
|
267
279
|
let final;
|
|
268
|
-
|
|
280
|
+
const executeStream = auditTool.executeStream;
|
|
281
|
+
if (!executeStream) throw new Error("auditTool: stream execution unavailable");
|
|
282
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
269
283
|
if (ev.type === "final") final = ev.output;
|
|
270
284
|
}
|
|
271
285
|
if (!final) throw new Error("audit: stream ended without final event");
|
|
@@ -482,6 +496,12 @@ var CircuitBreaker = class {
|
|
|
482
496
|
};
|
|
483
497
|
|
|
484
498
|
// src/process-registry.ts
|
|
499
|
+
function expectDefined3(value) {
|
|
500
|
+
if (value === null || value === void 0) {
|
|
501
|
+
throw new Error("Expected value to be defined");
|
|
502
|
+
}
|
|
503
|
+
return value;
|
|
504
|
+
}
|
|
485
505
|
var SENSITIVE_FLAG_PATTERNS = [
|
|
486
506
|
// --flag=value or --flag "value" (value captured up to next space or comma)
|
|
487
507
|
/--(?:token|password|passwd|pwd|secret|api[-_]?key|api[-_]?secret|auth|credential|private[-_]?key|access[-_]?key|github[-_]?token|gh[-_]?token|bearer|jwt|oauth|pin|pincode|passphrase|access[-_]?token)(?:[=\s,][^\s]*)?/gi,
|
|
@@ -502,7 +522,7 @@ function redactCommand(cmd) {
|
|
|
502
522
|
const sp = match.search(/\s/);
|
|
503
523
|
const delim = eq !== -1 ? "=" : sp !== -1 ? match[sp] : null;
|
|
504
524
|
if (delim !== null) {
|
|
505
|
-
const flag = match.slice(0, match.indexOf(delim) + 1);
|
|
525
|
+
const flag = match.slice(0, match.indexOf(expectDefined3(delim)) + 1);
|
|
506
526
|
return `${flag}[REDACTED]`;
|
|
507
527
|
}
|
|
508
528
|
const flagEnd = match.match(/^--?[a-zA-Z][a-zA-Z0-9_-]*/)?.[0] ?? match;
|
|
@@ -682,7 +702,7 @@ function getProcessRegistry() {
|
|
|
682
702
|
|
|
683
703
|
// src/bash.ts
|
|
684
704
|
var MAX_OUTPUT = 32768;
|
|
685
|
-
var
|
|
705
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
686
706
|
var STREAM_FLUSH_INTERVAL_MS = 200;
|
|
687
707
|
var STREAM_FLUSH_BYTES = 4 * 1024;
|
|
688
708
|
var bashTool = {
|
|
@@ -721,7 +741,9 @@ var bashTool = {
|
|
|
721
741
|
},
|
|
722
742
|
async execute(input, ctx, opts) {
|
|
723
743
|
let final;
|
|
724
|
-
|
|
744
|
+
const executeStream = bashTool.executeStream;
|
|
745
|
+
if (!executeStream) throw new Error("bashTool: stream execution unavailable");
|
|
746
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
725
747
|
if (ev.type === "final") final = ev.output;
|
|
726
748
|
}
|
|
727
749
|
if (!final) throw new Error("bash: stream ended without final event");
|
|
@@ -743,9 +765,19 @@ var bashTool = {
|
|
|
743
765
|
};
|
|
744
766
|
return;
|
|
745
767
|
}
|
|
746
|
-
const timeoutMs = Math.max(1, Math.min(input.timeout_ms ??
|
|
768
|
+
const timeoutMs = Math.max(1, Math.min(input.timeout_ms ?? DEFAULT_TIMEOUT_MS, 6e5));
|
|
747
769
|
const isWin = os.platform() === "win32";
|
|
748
|
-
const shell =
|
|
770
|
+
const shell = (() => {
|
|
771
|
+
const explicit = process.env[isWin ? "WRONGSTACK_COMSPEC" : "WRONGSTACK_SHELL"];
|
|
772
|
+
if (explicit) return explicit;
|
|
773
|
+
if (isWin) return process.env["COMSPEC"] ?? "cmd.exe";
|
|
774
|
+
const fromEnv = process.env["SHELL"];
|
|
775
|
+
if (fromEnv) {
|
|
776
|
+
const name = fromEnv.split("/").pop() ?? "";
|
|
777
|
+
if (["bash", "zsh", "sh", "dash", "fish"].includes(name)) return fromEnv;
|
|
778
|
+
}
|
|
779
|
+
return "/bin/bash";
|
|
780
|
+
})();
|
|
749
781
|
const args = isWin ? ["/c", input.command] : ["-c", input.command];
|
|
750
782
|
const env = buildChildEnv(ctx.session?.id);
|
|
751
783
|
const detached = isWin ? !!input.background : true;
|
|
@@ -1087,6 +1119,12 @@ function lspKindToInternalKind(k) {
|
|
|
1087
1119
|
}
|
|
1088
1120
|
|
|
1089
1121
|
// src/codebase-index/writer.ts
|
|
1122
|
+
function expectDefined4(value) {
|
|
1123
|
+
if (value === null || value === void 0) {
|
|
1124
|
+
throw new Error("Expected value to be defined");
|
|
1125
|
+
}
|
|
1126
|
+
return value;
|
|
1127
|
+
}
|
|
1090
1128
|
var DB_FILE = "index.db";
|
|
1091
1129
|
function resolveIndexDir(projectRoot, override) {
|
|
1092
1130
|
return override ?? resolveWstackPaths({ projectRoot }).projectCodebaseIndex;
|
|
@@ -1231,7 +1269,7 @@ var IndexStore = class {
|
|
|
1231
1269
|
"SELECT file, lang, mtime_ms, symbol_count, last_indexed FROM files WHERE file = ?"
|
|
1232
1270
|
).all(file);
|
|
1233
1271
|
if (!rows.length) return null;
|
|
1234
|
-
const r = rows[0];
|
|
1272
|
+
const r = expectDefined4(rows[0]);
|
|
1235
1273
|
return { file: r.file, lang: r.lang, mtimeMs: r.mtime_ms, symbolCount: r.symbol_count, lastIndexed: r.last_indexed };
|
|
1236
1274
|
}
|
|
1237
1275
|
getAllFileMetas() {
|
|
@@ -1313,7 +1351,7 @@ var IndexStore = class {
|
|
|
1313
1351
|
const lastRows = this.db.prepare(
|
|
1314
1352
|
"SELECT value FROM metadata WHERE key = 'last_indexed'"
|
|
1315
1353
|
).all();
|
|
1316
|
-
const lastIndexed = lastRows.length ? Number(lastRows[0]
|
|
1354
|
+
const lastIndexed = lastRows.length ? Number(lastRows[0]?.value) : null;
|
|
1317
1355
|
const totalRows = this.db.prepare("SELECT COUNT(*) FROM symbols").all();
|
|
1318
1356
|
const totalSymbols = totalRows[0] ? Number(totalRows[0]["COUNT(*)"]) : 0;
|
|
1319
1357
|
const fileRows = this.db.prepare("SELECT COUNT(*) FROM files").all();
|
|
@@ -1388,8 +1426,9 @@ var IndexStore = class {
|
|
|
1388
1426
|
let resolved = 0;
|
|
1389
1427
|
for (const row of unresolved) {
|
|
1390
1428
|
const target = this.db.prepare("SELECT id FROM symbols WHERE name = ? LIMIT 1").all(row.to_name);
|
|
1391
|
-
|
|
1392
|
-
|
|
1429
|
+
const first = target[0];
|
|
1430
|
+
if (first) {
|
|
1431
|
+
this.db.prepare("UPDATE refs SET to_id = ? WHERE id = ?").run(first.id, row.id);
|
|
1393
1432
|
resolved++;
|
|
1394
1433
|
}
|
|
1395
1434
|
}
|
|
@@ -2143,6 +2182,12 @@ function syncPyParse(filePath, lang) {
|
|
|
2143
2182
|
return { file: filePath, lang, symbols: [], mtimeMs: Date.now() };
|
|
2144
2183
|
}
|
|
2145
2184
|
}
|
|
2185
|
+
function expectDefined5(value) {
|
|
2186
|
+
if (value === null || value === void 0) {
|
|
2187
|
+
throw new Error("Expected value to be defined");
|
|
2188
|
+
}
|
|
2189
|
+
return value;
|
|
2190
|
+
}
|
|
2146
2191
|
function parseSymbols4(opts) {
|
|
2147
2192
|
const { file, content, lang } = opts;
|
|
2148
2193
|
const nativeAvailable = checkNativeParser();
|
|
@@ -2224,14 +2269,14 @@ function regexParse(opts) {
|
|
|
2224
2269
|
const lines = content.split("\n");
|
|
2225
2270
|
const lineOffsets = [0];
|
|
2226
2271
|
for (let i = 0; i < lines.length; i++) {
|
|
2227
|
-
lineOffsets.push(lineOffsets[i] + lines[i]
|
|
2272
|
+
lineOffsets.push((lineOffsets[i] ?? 0) + (lines[i]?.length ?? 0) + 1);
|
|
2228
2273
|
}
|
|
2229
2274
|
function lineFromOffset(offset) {
|
|
2230
2275
|
let lo = 0;
|
|
2231
2276
|
let hi = lineOffsets.length - 1;
|
|
2232
2277
|
while (lo < hi) {
|
|
2233
2278
|
const mid = lo + hi + 1 >>> 1;
|
|
2234
|
-
if (lineOffsets[mid] <= offset) lo = mid;
|
|
2279
|
+
if (expectDefined5(lineOffsets[mid]) <= offset) lo = mid;
|
|
2235
2280
|
else hi = mid - 1;
|
|
2236
2281
|
}
|
|
2237
2282
|
return lo + 1;
|
|
@@ -2243,8 +2288,8 @@ function regexParse(opts) {
|
|
|
2243
2288
|
for (const pattern of RS_PATTERNS) {
|
|
2244
2289
|
pattern.regex.lastIndex = 0;
|
|
2245
2290
|
for (let match = pattern.regex.exec(content); match !== null; match = pattern.regex.exec(content)) {
|
|
2246
|
-
const name = match[1];
|
|
2247
|
-
const offset = match.index;
|
|
2291
|
+
const name = expectDefined5(match[1]);
|
|
2292
|
+
const offset = match.index ?? 0;
|
|
2248
2293
|
const line = lineFromOffset(offset);
|
|
2249
2294
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2250
2295
|
const lineIdx = line - 1;
|
|
@@ -2273,6 +2318,12 @@ function regexParse(opts) {
|
|
|
2273
2318
|
});
|
|
2274
2319
|
return { file, lang, symbols: deduped, mtimeMs: Date.now() };
|
|
2275
2320
|
}
|
|
2321
|
+
function expectDefined6(value) {
|
|
2322
|
+
if (value === null || value === void 0) {
|
|
2323
|
+
throw new Error("Expected value to be defined");
|
|
2324
|
+
}
|
|
2325
|
+
return value;
|
|
2326
|
+
}
|
|
2276
2327
|
function parseSymbols5(opts) {
|
|
2277
2328
|
const { file, content, lang } = opts;
|
|
2278
2329
|
try {
|
|
@@ -2292,21 +2343,21 @@ function regexParse2(opts) {
|
|
|
2292
2343
|
const lines = content.split("\n");
|
|
2293
2344
|
const lineOffsets = [0];
|
|
2294
2345
|
for (let i = 0; i < lines.length; i++) {
|
|
2295
|
-
lineOffsets.push(lineOffsets[i] + lines[i]
|
|
2346
|
+
lineOffsets.push((lineOffsets[i] ?? 0) + (lines[i]?.length ?? 0) + 1);
|
|
2296
2347
|
}
|
|
2297
2348
|
function lineFromOffset(offset) {
|
|
2298
2349
|
let lo = 0;
|
|
2299
2350
|
let hi = lineOffsets.length - 1;
|
|
2300
2351
|
while (lo < hi) {
|
|
2301
2352
|
const mid = lo + hi + 1 >>> 1;
|
|
2302
|
-
if (lineOffsets[mid] <= offset) lo = mid;
|
|
2353
|
+
if (expectDefined6(lineOffsets[mid]) <= offset) lo = mid;
|
|
2303
2354
|
else hi = mid - 1;
|
|
2304
2355
|
}
|
|
2305
2356
|
return lo + 1;
|
|
2306
2357
|
}
|
|
2307
2358
|
const rootMatch = content.match(/^\s*\{/m);
|
|
2308
2359
|
if (rootMatch) {
|
|
2309
|
-
const offset = rootMatch.index;
|
|
2360
|
+
const offset = expectDefined6(rootMatch.index);
|
|
2310
2361
|
const line = lineFromOffset(offset);
|
|
2311
2362
|
symbols.push(
|
|
2312
2363
|
makeSymbol({
|
|
@@ -2322,8 +2373,8 @@ function regexParse2(opts) {
|
|
|
2322
2373
|
}
|
|
2323
2374
|
const topLevelKeyRegex = /^\s*"([^"]+)"\s*:/gm;
|
|
2324
2375
|
for (let match = topLevelKeyRegex.exec(content); match !== null; match = topLevelKeyRegex.exec(content)) {
|
|
2325
|
-
const key = match[1];
|
|
2326
|
-
const offset = match.index;
|
|
2376
|
+
const key = expectDefined6(match[1]);
|
|
2377
|
+
const offset = match.index ?? 0;
|
|
2327
2378
|
const line = lineFromOffset(offset);
|
|
2328
2379
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2329
2380
|
let kind = "property";
|
|
@@ -2369,7 +2420,7 @@ function regexParse2(opts) {
|
|
|
2369
2420
|
const defsRegex = /"\$defs"\s*:|"\$defs"\s*:/g;
|
|
2370
2421
|
const defsMatch = defsRegex.exec(content);
|
|
2371
2422
|
if (defsMatch !== null) {
|
|
2372
|
-
const offset = defsMatch.index;
|
|
2423
|
+
const offset = expectDefined6(defsMatch.index);
|
|
2373
2424
|
const line = lineFromOffset(offset);
|
|
2374
2425
|
symbols.push(
|
|
2375
2426
|
makeSymbol({
|
|
@@ -2392,9 +2443,9 @@ function regexParse2(opts) {
|
|
|
2392
2443
|
for (const pat of defsPatterns) {
|
|
2393
2444
|
pat.lastIndex = 0;
|
|
2394
2445
|
for (let match = pat.exec(content); match !== null; match = pat.exec(content)) {
|
|
2395
|
-
const offset = match.index;
|
|
2446
|
+
const offset = match.index ?? 0;
|
|
2396
2447
|
const line = lineFromOffset(offset);
|
|
2397
|
-
const key = match[0]
|
|
2448
|
+
const key = match[0]?.match(/"([^"]+)"/)?.[1] ?? expectDefined6(match[0]);
|
|
2398
2449
|
symbols.push(
|
|
2399
2450
|
makeSymbol({
|
|
2400
2451
|
name: key,
|
|
@@ -2413,12 +2464,12 @@ function regexParse2(opts) {
|
|
|
2413
2464
|
function extractPackageScripts(content, symbols, file, lang, lineOffsets, lineFromOffset) {
|
|
2414
2465
|
const scriptsBlockRegex = /"scripts"\s*:\s*\{([^}]+)\}/g;
|
|
2415
2466
|
for (let match = scriptsBlockRegex.exec(content); match !== null; match = scriptsBlockRegex.exec(content)) {
|
|
2416
|
-
const blockContent = match[0];
|
|
2417
|
-
const blockOffset = match.index;
|
|
2467
|
+
const blockContent = expectDefined6(match[0]);
|
|
2468
|
+
const blockOffset = match.index ?? 0;
|
|
2418
2469
|
const scriptKeyRegex = /"(\w[\w-]*)"\s*:/g;
|
|
2419
2470
|
for (let scriptMatch = scriptKeyRegex.exec(blockContent); scriptMatch !== null; scriptMatch = scriptKeyRegex.exec(blockContent)) {
|
|
2420
|
-
const key = scriptMatch[1];
|
|
2421
|
-
const keyOffset = blockOffset + scriptMatch.index;
|
|
2471
|
+
const key = expectDefined6(scriptMatch[1]);
|
|
2472
|
+
const keyOffset = blockOffset + expectDefined6(scriptMatch.index);
|
|
2422
2473
|
const line = lineFromOffset(keyOffset);
|
|
2423
2474
|
symbols.push(
|
|
2424
2475
|
makeSymbol({
|
|
@@ -2437,12 +2488,12 @@ function extractPackageScripts(content, symbols, file, lang, lineOffsets, lineFr
|
|
|
2437
2488
|
function extractCompilerOptions(content, symbols, file, lang, lineOffsets, parentLine, lineFromOffset) {
|
|
2438
2489
|
const optsBlockRegex = /"compilerOptions"\s*:\s*\{([^}]+)\}/g;
|
|
2439
2490
|
for (let match = optsBlockRegex.exec(content); match !== null; match = optsBlockRegex.exec(content)) {
|
|
2440
|
-
const blockContent = match[0];
|
|
2441
|
-
const blockOffset = match.index;
|
|
2491
|
+
const blockContent = expectDefined6(match[0]);
|
|
2492
|
+
const blockOffset = match.index ?? 0;
|
|
2442
2493
|
const optKeyRegex = /"(\w[\w]*)"\s*:/g;
|
|
2443
2494
|
for (let optMatch = optKeyRegex.exec(blockContent); optMatch !== null; optMatch = optKeyRegex.exec(blockContent)) {
|
|
2444
|
-
const key = optMatch[1];
|
|
2445
|
-
const keyOffset = blockOffset + optMatch.index;
|
|
2495
|
+
const key = expectDefined6(optMatch[1]);
|
|
2496
|
+
const keyOffset = blockOffset + expectDefined6(optMatch.index);
|
|
2446
2497
|
const line = lineFromOffset(keyOffset);
|
|
2447
2498
|
if (line <= parentLine) continue;
|
|
2448
2499
|
symbols.push(
|
|
@@ -2476,6 +2527,12 @@ function makeSymbol(opts) {
|
|
|
2476
2527
|
}
|
|
2477
2528
|
|
|
2478
2529
|
// src/codebase-index/yaml-parser.ts
|
|
2530
|
+
function expectDefined7(value) {
|
|
2531
|
+
if (value === null || value === void 0) {
|
|
2532
|
+
throw new Error("Expected value to be defined");
|
|
2533
|
+
}
|
|
2534
|
+
return value;
|
|
2535
|
+
}
|
|
2479
2536
|
function parseSymbols6(opts) {
|
|
2480
2537
|
const { file, content, lang } = opts;
|
|
2481
2538
|
try {
|
|
@@ -2490,22 +2547,22 @@ function regexParse3(opts) {
|
|
|
2490
2547
|
const lines = content.split("\n");
|
|
2491
2548
|
const lineOffsets = [0];
|
|
2492
2549
|
for (let i = 0; i < lines.length; i++) {
|
|
2493
|
-
lineOffsets.push(lineOffsets[i] + lines[i]
|
|
2550
|
+
lineOffsets.push((lineOffsets[i] ?? 0) + (lines[i]?.length ?? 0) + 1);
|
|
2494
2551
|
}
|
|
2495
2552
|
function lineFromOffset(offset) {
|
|
2496
2553
|
let lo = 0;
|
|
2497
2554
|
let hi = lineOffsets.length - 1;
|
|
2498
2555
|
while (lo < hi) {
|
|
2499
2556
|
const mid = lo + hi + 1 >>> 1;
|
|
2500
|
-
if (lineOffsets[mid] <= offset) lo = mid;
|
|
2557
|
+
if (expectDefined7(lineOffsets[mid]) <= offset) lo = mid;
|
|
2501
2558
|
else hi = mid - 1;
|
|
2502
2559
|
}
|
|
2503
2560
|
return lo + 1;
|
|
2504
2561
|
}
|
|
2505
2562
|
const anchorRegex = /&(\w[\w-]*)/g;
|
|
2506
2563
|
for (let match = anchorRegex.exec(content); match !== null; match = anchorRegex.exec(content)) {
|
|
2507
|
-
const name = match[1];
|
|
2508
|
-
const offset = match.index;
|
|
2564
|
+
const name = expectDefined7(match[1]);
|
|
2565
|
+
const offset = match.index ?? 0;
|
|
2509
2566
|
const line = lineFromOffset(offset);
|
|
2510
2567
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2511
2568
|
symbols.push(
|
|
@@ -2522,8 +2579,8 @@ function regexParse3(opts) {
|
|
|
2522
2579
|
}
|
|
2523
2580
|
const aliasRegex = /\*(\w[\w-]*)/g;
|
|
2524
2581
|
for (let match = aliasRegex.exec(content); match !== null; match = aliasRegex.exec(content)) {
|
|
2525
|
-
const name = match[1];
|
|
2526
|
-
const offset = match.index;
|
|
2582
|
+
const name = expectDefined7(match[1]);
|
|
2583
|
+
const offset = match.index ?? 0;
|
|
2527
2584
|
const line = lineFromOffset(offset);
|
|
2528
2585
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2529
2586
|
symbols.push(
|
|
@@ -2540,27 +2597,28 @@ function regexParse3(opts) {
|
|
|
2540
2597
|
}
|
|
2541
2598
|
const kvRegex = /^(\s*)([^:#\s][^:#\s]*)\s*:/gm;
|
|
2542
2599
|
for (let match = kvRegex.exec(content); match !== null; match = kvRegex.exec(content)) {
|
|
2543
|
-
const indent = match[1]
|
|
2600
|
+
const indent = match[1]?.length ?? 0;
|
|
2544
2601
|
const key = match[2];
|
|
2545
|
-
|
|
2602
|
+
if (!key) continue;
|
|
2603
|
+
const offset = match.index ?? 0;
|
|
2546
2604
|
const line = lineFromOffset(offset);
|
|
2547
2605
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2548
2606
|
const lineContent = lines[line - 1] ?? "";
|
|
2549
2607
|
if (/^[|&>]/.test(lineContent.trim())) continue;
|
|
2550
2608
|
if (key === "---" || key === "...") continue;
|
|
2551
2609
|
if (indent > 12) continue;
|
|
2552
|
-
const value = extractValue(content, match.index);
|
|
2610
|
+
const value = extractValue(content, match.index ?? 0);
|
|
2553
2611
|
const kind = isScalar(value) ? "literal" : "property";
|
|
2554
2612
|
const signature = `${key}: ${truncate(value, 60)}`;
|
|
2555
2613
|
symbols.push(makeSymbol2({ name: key, kind, line, col, signature, file, lang }));
|
|
2556
2614
|
}
|
|
2557
2615
|
const listItemRegex = /^-(\s+)([^:#\s][^:#\s]*)\s*:/gm;
|
|
2558
2616
|
for (let match = listItemRegex.exec(content); match !== null; match = listItemRegex.exec(content)) {
|
|
2559
|
-
const key = match[2];
|
|
2560
|
-
const offset = match.index;
|
|
2617
|
+
const key = expectDefined7(match[2]);
|
|
2618
|
+
const offset = match.index ?? 0;
|
|
2561
2619
|
const line = lineFromOffset(offset);
|
|
2562
2620
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2563
|
-
const value = extractValue(content, offset + match[0]
|
|
2621
|
+
const value = extractValue(content, offset + match[0]?.length);
|
|
2564
2622
|
const kind = isScalar(value) ? "literal" : "property";
|
|
2565
2623
|
symbols.push(
|
|
2566
2624
|
makeSymbol2({
|
|
@@ -2576,8 +2634,8 @@ function regexParse3(opts) {
|
|
|
2576
2634
|
}
|
|
2577
2635
|
const blockScalarRegex = /^(\s*)([^:#\s][^:#\s]*)\s*:\s*[|>](\s|$)/gm;
|
|
2578
2636
|
for (let match = blockScalarRegex.exec(content); match !== null; match = blockScalarRegex.exec(content)) {
|
|
2579
|
-
const key = match[2];
|
|
2580
|
-
const offset = match.index;
|
|
2637
|
+
const key = expectDefined7(match[2]);
|
|
2638
|
+
const offset = match.index ?? 0;
|
|
2581
2639
|
const line = lineFromOffset(offset);
|
|
2582
2640
|
const col = offset - (lineOffsets[line - 1] ?? 0);
|
|
2583
2641
|
symbols.push(
|
|
@@ -2707,6 +2765,12 @@ function _setIndexProgress(current, total) {
|
|
|
2707
2765
|
Promise.resolve();
|
|
2708
2766
|
|
|
2709
2767
|
// src/codebase-index/indexer.ts
|
|
2768
|
+
function expectDefined8(value) {
|
|
2769
|
+
if (value === null || value === void 0) {
|
|
2770
|
+
throw new Error("Expected value to be defined");
|
|
2771
|
+
}
|
|
2772
|
+
return value;
|
|
2773
|
+
}
|
|
2710
2774
|
var YIELD_EVERY_N = 50;
|
|
2711
2775
|
function yieldEventLoop() {
|
|
2712
2776
|
return new Promise((resolve7) => setImmediate(resolve7));
|
|
@@ -2815,7 +2879,7 @@ async function runIndexer(_ctx, opts) {
|
|
|
2815
2879
|
for (const meta of store.getAllFileMetas()) existingMeta.set(meta.file, meta);
|
|
2816
2880
|
}
|
|
2817
2881
|
for (let fi = 0; fi < files.length; fi++) {
|
|
2818
|
-
const file = files[fi];
|
|
2882
|
+
const file = expectDefined8(files[fi]);
|
|
2819
2883
|
_setIndexProgress(fi + 1, files.length);
|
|
2820
2884
|
if (fi > 0 && fi % YIELD_EVERY_N === 0) {
|
|
2821
2885
|
await yieldEventLoop();
|
|
@@ -2872,7 +2936,7 @@ async function runIndexer(_ctx, opts) {
|
|
|
2872
2936
|
langStats[lang] = (langStats[lang] ?? 0) + count;
|
|
2873
2937
|
if (parsed.refs && parsed.refs.length > 0) {
|
|
2874
2938
|
for (let i = 0; i < symbolsWithIds.length; i++) {
|
|
2875
|
-
const sym = symbolsWithIds[i];
|
|
2939
|
+
const sym = expectDefined8(symbolsWithIds[i]);
|
|
2876
2940
|
const symRefs = parsed.refs.filter((r) => r.line === sym.line);
|
|
2877
2941
|
if (symRefs.length > 0) {
|
|
2878
2942
|
const refsWithFromId = symRefs.map((r) => ({ ...r, fromId: sym.id }));
|
|
@@ -3033,6 +3097,12 @@ var Bm25Index = class {
|
|
|
3033
3097
|
};
|
|
3034
3098
|
|
|
3035
3099
|
// src/codebase-index/codebase-search-tool.ts
|
|
3100
|
+
function expectDefined9(value) {
|
|
3101
|
+
if (value === null || value === void 0) {
|
|
3102
|
+
throw new Error("Expected value to be defined");
|
|
3103
|
+
}
|
|
3104
|
+
return value;
|
|
3105
|
+
}
|
|
3036
3106
|
var codebaseSearchTool = {
|
|
3037
3107
|
name: "codebase-search",
|
|
3038
3108
|
category: "Project",
|
|
@@ -3122,7 +3192,7 @@ var codebaseSearchTool = {
|
|
|
3122
3192
|
const top = scored.slice(0, limit);
|
|
3123
3193
|
const qTokens = tokenise(input.query);
|
|
3124
3194
|
const results = top.map(({ id, score }) => {
|
|
3125
|
-
const c = candidates.find((c2) => c2.id === id);
|
|
3195
|
+
const c = expectDefined9(candidates.find((c2) => c2.id === id));
|
|
3126
3196
|
const snippet = bm25.extractSnippet(id, qTokens);
|
|
3127
3197
|
return {
|
|
3128
3198
|
...c,
|
|
@@ -3657,7 +3727,7 @@ var ALLOWED_COMMANDS = {
|
|
|
3657
3727
|
};
|
|
3658
3728
|
var MAX_ARGS = 20;
|
|
3659
3729
|
var MAX_OUTPUT2 = 2e5;
|
|
3660
|
-
var
|
|
3730
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
3661
3731
|
var BLOCKED_ARG_PATTERNS = {
|
|
3662
3732
|
// python -c/--command executes arbitrary code; python -m runs modules
|
|
3663
3733
|
python: [/-c$/, /^--command$/, /^-m$/, /^--module$/],
|
|
@@ -3720,7 +3790,7 @@ var execTool = {
|
|
|
3720
3790
|
permission: "confirm",
|
|
3721
3791
|
mutating: true,
|
|
3722
3792
|
riskTier: "standard",
|
|
3723
|
-
timeoutMs:
|
|
3793
|
+
timeoutMs: DEFAULT_TIMEOUT_MS2,
|
|
3724
3794
|
capabilities: ["shell.restricted"],
|
|
3725
3795
|
inputSchema: {
|
|
3726
3796
|
type: "object",
|
|
@@ -3781,7 +3851,7 @@ var execTool = {
|
|
|
3781
3851
|
};
|
|
3782
3852
|
}
|
|
3783
3853
|
const args = (input.args ?? []).slice(0, MAX_ARGS);
|
|
3784
|
-
const timeout = Math.max(1, Math.min(input.timeout ??
|
|
3854
|
+
const timeout = Math.max(1, Math.min(input.timeout ?? DEFAULT_TIMEOUT_MS2, DEFAULT_TIMEOUT_MS2));
|
|
3785
3855
|
const argError = validateArgs(cmd, args);
|
|
3786
3856
|
if (argError) {
|
|
3787
3857
|
return {
|
|
@@ -3874,8 +3944,21 @@ function runCommand(cmd, args, cwd, timeout, signal, sessionId) {
|
|
|
3874
3944
|
});
|
|
3875
3945
|
}
|
|
3876
3946
|
var MAX_BYTES = 131072;
|
|
3877
|
-
var
|
|
3947
|
+
var TIMEOUT_MS = 2e4;
|
|
3878
3948
|
var ALLOW_PRIVATE = process.env["WRONGSTACK_FETCH_ALLOW_PRIVATE"] === "1";
|
|
3949
|
+
function combineSignals(signals) {
|
|
3950
|
+
const anyFn = AbortSignal.any;
|
|
3951
|
+
if (typeof anyFn === "function") return anyFn(signals);
|
|
3952
|
+
const ctrl = new AbortController();
|
|
3953
|
+
for (const sig of signals) {
|
|
3954
|
+
if (sig.aborted) {
|
|
3955
|
+
ctrl.abort(sig.reason);
|
|
3956
|
+
return ctrl.signal;
|
|
3957
|
+
}
|
|
3958
|
+
sig.addEventListener("abort", () => ctrl.abort(sig.reason), { once: true });
|
|
3959
|
+
}
|
|
3960
|
+
return ctrl.signal;
|
|
3961
|
+
}
|
|
3879
3962
|
function guardedLookup(hostname, options, callback) {
|
|
3880
3963
|
dns.lookup(hostname, { all: true }).then((records) => {
|
|
3881
3964
|
const family = options?.family;
|
|
@@ -3918,6 +4001,10 @@ function getPinnedDispatcher() {
|
|
|
3918
4001
|
}
|
|
3919
4002
|
return pinnedAgent;
|
|
3920
4003
|
}
|
|
4004
|
+
process.on("beforeExit", () => {
|
|
4005
|
+
pinnedAgent?.destroy();
|
|
4006
|
+
pinnedAgent = void 0;
|
|
4007
|
+
});
|
|
3921
4008
|
async function guardedFetch(url, maxRedirects, signal, headers = {
|
|
3922
4009
|
"user-agent": "WrongStack/1.0 (+https://wrongstack.com)",
|
|
3923
4010
|
accept: "text/html,application/json;q=0.9,text/plain;q=0.8,*/*;q=0.1"
|
|
@@ -3967,7 +4054,7 @@ var fetchTool = {
|
|
|
3967
4054
|
// matching that pattern on any other tool that happens to have a `url`
|
|
3968
4055
|
// input field.
|
|
3969
4056
|
subjectKey: "url",
|
|
3970
|
-
timeoutMs:
|
|
4057
|
+
timeoutMs: TIMEOUT_MS,
|
|
3971
4058
|
maxOutputBytes: MAX_BYTES,
|
|
3972
4059
|
inputSchema: {
|
|
3973
4060
|
type: "object",
|
|
@@ -3986,7 +4073,9 @@ var fetchTool = {
|
|
|
3986
4073
|
},
|
|
3987
4074
|
async execute(input, ctx, opts) {
|
|
3988
4075
|
let final;
|
|
3989
|
-
|
|
4076
|
+
const executeStream = fetchTool.executeStream;
|
|
4077
|
+
if (!executeStream) throw new Error("fetchTool: stream execution unavailable");
|
|
4078
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
3990
4079
|
if (ev.type === "final") final = ev.output;
|
|
3991
4080
|
}
|
|
3992
4081
|
if (!final) throw new Error("fetch: stream ended without final event");
|
|
@@ -4004,8 +4093,8 @@ var fetchTool = {
|
|
|
4004
4093
|
await assertNotPrivate(u.hostname);
|
|
4005
4094
|
yield { type: "log", text: `GET ${input.url}` };
|
|
4006
4095
|
const ctrl = new AbortController();
|
|
4007
|
-
const timer = setTimeout(() => ctrl.abort(new Error("fetch timeout")),
|
|
4008
|
-
const combined = combineSignals(opts.signal, ctrl.signal);
|
|
4096
|
+
const timer = setTimeout(() => ctrl.abort(new Error("fetch timeout")), TIMEOUT_MS);
|
|
4097
|
+
const combined = combineSignals([opts.signal, ctrl.signal]);
|
|
4009
4098
|
try {
|
|
4010
4099
|
const res = await guardedFetch(input.url, 5, combined);
|
|
4011
4100
|
const ct = res.headers.get("content-type") ?? "application/octet-stream";
|
|
@@ -4153,33 +4242,6 @@ function expandIPv6(addr) {
|
|
|
4153
4242
|
if (fill < 0) return null;
|
|
4154
4243
|
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
4155
4244
|
}
|
|
4156
|
-
function combineSignals(...sigs) {
|
|
4157
|
-
const anyFn = AbortSignal.any;
|
|
4158
|
-
if (typeof anyFn === "function") {
|
|
4159
|
-
return anyFn(sigs);
|
|
4160
|
-
}
|
|
4161
|
-
const ctrl = new AbortController();
|
|
4162
|
-
const cleanups = [];
|
|
4163
|
-
const detach = () => {
|
|
4164
|
-
for (const fn of cleanups) fn();
|
|
4165
|
-
cleanups.length = 0;
|
|
4166
|
-
};
|
|
4167
|
-
for (const s of sigs) {
|
|
4168
|
-
if (s.aborted) {
|
|
4169
|
-
detach();
|
|
4170
|
-
ctrl.abort(s.reason);
|
|
4171
|
-
return ctrl.signal;
|
|
4172
|
-
}
|
|
4173
|
-
const onAbort = () => {
|
|
4174
|
-
detach();
|
|
4175
|
-
ctrl.abort(s.reason);
|
|
4176
|
-
};
|
|
4177
|
-
s.addEventListener("abort", onAbort, { once: true });
|
|
4178
|
-
cleanups.push(() => s.removeEventListener("abort", onAbort));
|
|
4179
|
-
}
|
|
4180
|
-
ctrl.signal.addEventListener("abort", detach, { once: true });
|
|
4181
|
-
return ctrl.signal;
|
|
4182
|
-
}
|
|
4183
4245
|
function prettyJson(s) {
|
|
4184
4246
|
try {
|
|
4185
4247
|
return JSON.stringify(JSON.parse(s), null, 2);
|
|
@@ -4245,7 +4307,9 @@ var formatTool = {
|
|
|
4245
4307
|
},
|
|
4246
4308
|
async execute(input, ctx, opts) {
|
|
4247
4309
|
let final;
|
|
4248
|
-
|
|
4310
|
+
const executeStream = formatTool.executeStream;
|
|
4311
|
+
if (!executeStream) throw new Error("formatTool: stream execution unavailable");
|
|
4312
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
4249
4313
|
if (ev.type === "final") final = ev.output;
|
|
4250
4314
|
}
|
|
4251
4315
|
if (!final) throw new Error("format: stream ended without final event");
|
|
@@ -4313,7 +4377,7 @@ async function detectFixer(cwd) {
|
|
|
4313
4377
|
}
|
|
4314
4378
|
}
|
|
4315
4379
|
}
|
|
4316
|
-
var
|
|
4380
|
+
var TIMEOUT_MS2 = 3e4;
|
|
4317
4381
|
var MAX_OUTPUT3 = 1e5;
|
|
4318
4382
|
var gitTool = {
|
|
4319
4383
|
name: "git",
|
|
@@ -4326,7 +4390,7 @@ var gitTool = {
|
|
|
4326
4390
|
// and `MUTATING_SUBCOMMANDS` is consulted at runtime for per-call checks.
|
|
4327
4391
|
mutating: true,
|
|
4328
4392
|
capabilities: ["fs.write", "shell.restricted"],
|
|
4329
|
-
timeoutMs:
|
|
4393
|
+
timeoutMs: TIMEOUT_MS2,
|
|
4330
4394
|
inputSchema: {
|
|
4331
4395
|
type: "object",
|
|
4332
4396
|
properties: {
|
|
@@ -4689,6 +4753,12 @@ function capSubject(line) {
|
|
|
4689
4753
|
}
|
|
4690
4754
|
|
|
4691
4755
|
// src/grep.ts
|
|
4756
|
+
function expectDefined10(value) {
|
|
4757
|
+
if (value === null || value === void 0) {
|
|
4758
|
+
throw new Error("Expected value to be defined");
|
|
4759
|
+
}
|
|
4760
|
+
return value;
|
|
4761
|
+
}
|
|
4692
4762
|
var DEFAULT_IGNORE3 = ["node_modules", ".git", "dist", "build", ".next", "coverage"];
|
|
4693
4763
|
var grepTool = {
|
|
4694
4764
|
name: "grep",
|
|
@@ -4737,7 +4807,9 @@ var grepTool = {
|
|
|
4737
4807
|
},
|
|
4738
4808
|
async execute(input, ctx, opts) {
|
|
4739
4809
|
let final;
|
|
4740
|
-
|
|
4810
|
+
const executeStream = grepTool.executeStream;
|
|
4811
|
+
if (!executeStream) throw new Error("grepTool: stream execution unavailable");
|
|
4812
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
4741
4813
|
if (ev.type === "final") final = ev.output;
|
|
4742
4814
|
}
|
|
4743
4815
|
if (!final) throw new Error("grep: stream ended without final event");
|
|
@@ -4828,7 +4900,7 @@ async function* runRgStream(input, base, mode, limit, signal) {
|
|
|
4828
4900
|
waiter = r;
|
|
4829
4901
|
});
|
|
4830
4902
|
}
|
|
4831
|
-
const c = queue.shift();
|
|
4903
|
+
const c = expectDefined10(queue.shift());
|
|
4832
4904
|
if (c.kind === "error") {
|
|
4833
4905
|
errored = true;
|
|
4834
4906
|
continue;
|
|
@@ -5014,7 +5086,9 @@ var installTool = {
|
|
|
5014
5086
|
},
|
|
5015
5087
|
async execute(input, ctx, opts) {
|
|
5016
5088
|
let final;
|
|
5017
|
-
|
|
5089
|
+
const executeStream = installTool.executeStream;
|
|
5090
|
+
if (!executeStream) throw new Error("installTool: stream execution unavailable");
|
|
5091
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
5018
5092
|
if (ev.type === "final") final = ev.output;
|
|
5019
5093
|
}
|
|
5020
5094
|
if (!final) throw new Error("install: stream ended without final event");
|
|
@@ -5229,7 +5303,9 @@ var lintTool = {
|
|
|
5229
5303
|
},
|
|
5230
5304
|
async execute(input, ctx, opts) {
|
|
5231
5305
|
let final;
|
|
5232
|
-
|
|
5306
|
+
const executeStream = lintTool.executeStream;
|
|
5307
|
+
if (!executeStream) throw new Error("lintTool: stream execution unavailable");
|
|
5308
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
5233
5309
|
if (ev.type === "final") final = ev.output;
|
|
5234
5310
|
}
|
|
5235
5311
|
if (!final) throw new Error("lint: stream ended without final event");
|
|
@@ -5856,14 +5932,15 @@ var planTool = {
|
|
|
5856
5932
|
};
|
|
5857
5933
|
function mkResult(plan, ok, message, todos) {
|
|
5858
5934
|
const open = plan.items.filter((i) => i.status !== "done").length;
|
|
5859
|
-
|
|
5935
|
+
const result = {
|
|
5860
5936
|
ok,
|
|
5861
5937
|
message,
|
|
5862
5938
|
plan: formatPlan(plan),
|
|
5863
5939
|
count: plan.items.length,
|
|
5864
|
-
open
|
|
5865
|
-
todos
|
|
5940
|
+
open
|
|
5866
5941
|
};
|
|
5942
|
+
if (todos !== void 0) result.todos = todos;
|
|
5943
|
+
return result;
|
|
5867
5944
|
}
|
|
5868
5945
|
var MAX_BYTES2 = 5 * 1024 * 1024;
|
|
5869
5946
|
var readTool = {
|
|
@@ -5937,6 +6014,12 @@ var readTool = {
|
|
|
5937
6014
|
};
|
|
5938
6015
|
}
|
|
5939
6016
|
};
|
|
6017
|
+
function expectDefined11(value) {
|
|
6018
|
+
if (value === null || value === void 0) {
|
|
6019
|
+
throw new Error("Expected value to be defined");
|
|
6020
|
+
}
|
|
6021
|
+
return value;
|
|
6022
|
+
}
|
|
5940
6023
|
var DEFAULT_IGNORE4 = ["node_modules", ".git", "dist", "build", ".next", "coverage"];
|
|
5941
6024
|
var replaceTool = {
|
|
5942
6025
|
name: "replace",
|
|
@@ -6016,8 +6099,8 @@ var replaceTool = {
|
|
|
6016
6099
|
const count = matches.length;
|
|
6017
6100
|
let newContentLf = contentLf;
|
|
6018
6101
|
for (let i = matches.length - 1; i >= 0; i--) {
|
|
6019
|
-
const m = matches[i];
|
|
6020
|
-
newContentLf = newContentLf.slice(0, m.index) + input.replacement + newContentLf.slice(m.index + m[0].length);
|
|
6102
|
+
const m = expectDefined11(matches[i]);
|
|
6103
|
+
newContentLf = newContentLf.slice(0, m.index) + input.replacement + newContentLf.slice(expectDefined11(m.index) + m[0].length);
|
|
6021
6104
|
}
|
|
6022
6105
|
re.lastIndex = 0;
|
|
6023
6106
|
totalReplacements += count;
|
|
@@ -6318,9 +6401,15 @@ function substituteVars(content, name, vars) {
|
|
|
6318
6401
|
}
|
|
6319
6402
|
|
|
6320
6403
|
// src/search.ts
|
|
6404
|
+
function expectDefined12(value) {
|
|
6405
|
+
if (value === null || value === void 0) {
|
|
6406
|
+
throw new Error("Expected value to be defined");
|
|
6407
|
+
}
|
|
6408
|
+
return value;
|
|
6409
|
+
}
|
|
6321
6410
|
var DEFAULT_NUM = 10;
|
|
6322
6411
|
var MAX_RESULTS = 50;
|
|
6323
|
-
var
|
|
6412
|
+
var TIMEOUT_MS3 = 15e3;
|
|
6324
6413
|
var searchTool = {
|
|
6325
6414
|
name: "search",
|
|
6326
6415
|
category: "Search",
|
|
@@ -6329,7 +6418,7 @@ var searchTool = {
|
|
|
6329
6418
|
permission: "confirm",
|
|
6330
6419
|
mutating: false,
|
|
6331
6420
|
capabilities: ["net.outbound"],
|
|
6332
|
-
timeoutMs:
|
|
6421
|
+
timeoutMs: TIMEOUT_MS3,
|
|
6333
6422
|
inputSchema: {
|
|
6334
6423
|
type: "object",
|
|
6335
6424
|
properties: {
|
|
@@ -6350,7 +6439,9 @@ var searchTool = {
|
|
|
6350
6439
|
},
|
|
6351
6440
|
async execute(input, ctx, opts) {
|
|
6352
6441
|
let final;
|
|
6353
|
-
|
|
6442
|
+
const executeStream = searchTool.executeStream;
|
|
6443
|
+
if (!executeStream) throw new Error("searchTool: stream execution unavailable");
|
|
6444
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
6354
6445
|
if (ev.type === "final") final = ev.output;
|
|
6355
6446
|
}
|
|
6356
6447
|
if (!final) throw new Error("search: stream ended without final event");
|
|
@@ -6390,7 +6481,7 @@ var searchTool = {
|
|
|
6390
6481
|
async function duckduckgoSearch(query2, num, signal) {
|
|
6391
6482
|
const encoded = encodeURIComponent(query2);
|
|
6392
6483
|
const url = `https://lite.duckduckgo.com/lite/?q=${encoded}&kd=-1&kl=wt-wt`;
|
|
6393
|
-
const results = await fetchWithTimeout(url, signal,
|
|
6484
|
+
const results = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).then((html) => parseDuckDuckGo(html, num)).catch(() => [{ title: "Search unavailable", url: "", snippet: "Could not reach DuckDuckGo" }]);
|
|
6394
6485
|
return {
|
|
6395
6486
|
query: query2,
|
|
6396
6487
|
results,
|
|
@@ -6411,11 +6502,11 @@ function parseDuckDuckGo(html, num) {
|
|
|
6411
6502
|
const snippetRegex = /<a class="result-link"[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>/gi;
|
|
6412
6503
|
const snippet2Regex = /<a class="result-snippet"[^>]*>([^<]+)<\/a>/gi;
|
|
6413
6504
|
const linkMatches = takeFrom(
|
|
6414
|
-
[...html.matchAll(snippetRegex)].filter((m) => m[1] && m[2]).map((m) => ({ url: m[1], title: stripTags2(m[2]) })),
|
|
6505
|
+
[...html.matchAll(snippetRegex)].filter((m) => m[1] && m[2]).map((m) => ({ url: expectDefined12(m[1]), title: stripTags2(expectDefined12(m[2])) })),
|
|
6415
6506
|
num
|
|
6416
6507
|
);
|
|
6417
6508
|
const snippetMatches = takeFrom(
|
|
6418
|
-
[...html.matchAll(snippet2Regex)].filter((m) => m[1]).map((m) => stripTags2(m[1])),
|
|
6509
|
+
[...html.matchAll(snippet2Regex)].filter((m) => m[1]).map((m) => stripTags2(expectDefined12(m[1]))),
|
|
6419
6510
|
num
|
|
6420
6511
|
);
|
|
6421
6512
|
for (let i = 0; i < linkMatches.length && i < num; i++) {
|
|
@@ -6431,7 +6522,7 @@ function parseDuckDuckGo(html, num) {
|
|
|
6431
6522
|
async function googleSearch(query2, num, signal) {
|
|
6432
6523
|
const encoded = encodeURIComponent(query2);
|
|
6433
6524
|
const url = `https://www.google.com/search?q=${encoded}&hl=en`;
|
|
6434
|
-
const html = await fetchWithTimeout(url, signal,
|
|
6525
|
+
const html = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).catch(() => "");
|
|
6435
6526
|
const results = parseGoogleResults(html, num);
|
|
6436
6527
|
return {
|
|
6437
6528
|
query: query2,
|
|
@@ -6446,15 +6537,15 @@ function parseGoogleResults(html, num) {
|
|
|
6446
6537
|
const urlRegex = /<cite[^>]*>([^<]+)<\/cite>/gi;
|
|
6447
6538
|
const snippetRegex = /<span[^>]*class="[^"]*aXCZ0b[^>]*>([^<]+)<\/span>/gi;
|
|
6448
6539
|
const titles = takeFrom(
|
|
6449
|
-
[...html.matchAll(titleRegex)].filter((m) => m[1]).map((m) => stripTags2(m[1])),
|
|
6540
|
+
[...html.matchAll(titleRegex)].filter((m) => m[1]).map((m) => stripTags2(expectDefined12(m[1]))),
|
|
6450
6541
|
num
|
|
6451
6542
|
);
|
|
6452
6543
|
const urls = takeFrom(
|
|
6453
|
-
[...html.matchAll(urlRegex)].filter((m) => m[1]).map((m) => stripTags2(m[1]).replace(/^\*(https?:\/\/[^\s]+).*$/, "$1")).filter((u) => u.startsWith("http")),
|
|
6544
|
+
[...html.matchAll(urlRegex)].filter((m) => m[1]).map((m) => stripTags2(expectDefined12(m[1])).replace(/^\*(https?:\/\/[^\s]+).*$/, "$1")).filter((u) => u.startsWith("http")),
|
|
6454
6545
|
num
|
|
6455
6546
|
);
|
|
6456
6547
|
const snippets = takeFrom(
|
|
6457
|
-
[...html.matchAll(snippetRegex)].filter((m) => m[1]).map((m) => stripTags2(m[1])),
|
|
6548
|
+
[...html.matchAll(snippetRegex)].filter((m) => m[1]).map((m) => stripTags2(expectDefined12(m[1]))),
|
|
6458
6549
|
num
|
|
6459
6550
|
);
|
|
6460
6551
|
for (let i = 0; i < Math.min(titles.length, num); i++) {
|
|
@@ -6469,7 +6560,7 @@ function parseGoogleResults(html, num) {
|
|
|
6469
6560
|
async function bingSearch(query2, num, signal) {
|
|
6470
6561
|
const encoded = encodeURIComponent(query2);
|
|
6471
6562
|
const url = `https://www.bing.com/search?q=${encoded}`;
|
|
6472
|
-
const html = await fetchWithTimeout(url, signal,
|
|
6563
|
+
const html = await fetchWithTimeout(url, signal, TIMEOUT_MS3).then((r) => r.text()).catch(() => "");
|
|
6473
6564
|
const results = parseBingResults(html, num);
|
|
6474
6565
|
return {
|
|
6475
6566
|
query: query2,
|
|
@@ -6483,11 +6574,11 @@ function parseBingResults(html, num) {
|
|
|
6483
6574
|
const titleRegex = /<h2[^>]*>\s*<a[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>\s*<\/h2>/gi;
|
|
6484
6575
|
const snippetRegex = /<p[^>]*class="[^"]*b_paractl[^"]*"[^>]*>([^<]+)<\/p>/gi;
|
|
6485
6576
|
const entries = takeFrom(
|
|
6486
|
-
[...html.matchAll(titleRegex)].filter((m) => m[1] && m[2]).map((m) => ({ url: m[1], title: stripTags2(m[2]) })),
|
|
6577
|
+
[...html.matchAll(titleRegex)].filter((m) => m[1] && m[2]).map((m) => ({ url: expectDefined12(m[1]), title: stripTags2(expectDefined12(m[2])) })),
|
|
6487
6578
|
num
|
|
6488
6579
|
);
|
|
6489
6580
|
const snippets = takeFrom(
|
|
6490
|
-
[...html.matchAll(snippetRegex)].filter((m) => m[1]).map((m) => stripTags2(m[1])),
|
|
6581
|
+
[...html.matchAll(snippetRegex)].filter((m) => m[1]).map((m) => stripTags2(expectDefined12(m[1]))),
|
|
6491
6582
|
num
|
|
6492
6583
|
);
|
|
6493
6584
|
for (let i = 0; i < entries.length; i++) {
|
|
@@ -6557,7 +6648,9 @@ var testTool = {
|
|
|
6557
6648
|
},
|
|
6558
6649
|
async execute(input, ctx, opts) {
|
|
6559
6650
|
let final;
|
|
6560
|
-
|
|
6651
|
+
const executeStream = testTool.executeStream;
|
|
6652
|
+
if (!executeStream) throw new Error("testTool: stream execution unavailable");
|
|
6653
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
6561
6654
|
if (ev.type === "final") final = ev.output;
|
|
6562
6655
|
}
|
|
6563
6656
|
if (!final) throw new Error("test: stream ended without final event");
|
|
@@ -7009,6 +7102,12 @@ var toolUseTool = {
|
|
|
7009
7102
|
}
|
|
7010
7103
|
}
|
|
7011
7104
|
};
|
|
7105
|
+
function expectDefined13(value) {
|
|
7106
|
+
if (value === null || value === void 0) {
|
|
7107
|
+
throw new Error("Expected value to be defined");
|
|
7108
|
+
}
|
|
7109
|
+
return value;
|
|
7110
|
+
}
|
|
7012
7111
|
var DEFAULT_IGNORE5 = [
|
|
7013
7112
|
"node_modules",
|
|
7014
7113
|
".git",
|
|
@@ -7069,7 +7168,9 @@ var treeTool = {
|
|
|
7069
7168
|
},
|
|
7070
7169
|
async execute(input, ctx, opts) {
|
|
7071
7170
|
let final;
|
|
7072
|
-
|
|
7171
|
+
const executeStream = treeTool.executeStream;
|
|
7172
|
+
if (!executeStream) throw new Error("treeTool: stream execution unavailable");
|
|
7173
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
7073
7174
|
if (ev.type === "final") final = ev.output;
|
|
7074
7175
|
}
|
|
7075
7176
|
if (!final) throw new Error("tree: stream ended without final event");
|
|
@@ -7119,7 +7220,7 @@ var treeTool = {
|
|
|
7119
7220
|
});
|
|
7120
7221
|
while (!walkDone || queue.length > 0) {
|
|
7121
7222
|
if (queue.length > 0) {
|
|
7122
|
-
yield queue.shift();
|
|
7223
|
+
yield expectDefined13(queue.shift());
|
|
7123
7224
|
} else {
|
|
7124
7225
|
let pollTimer;
|
|
7125
7226
|
const poll = new Promise((r) => {
|
|
@@ -7209,7 +7310,9 @@ var typecheckTool = {
|
|
|
7209
7310
|
},
|
|
7210
7311
|
async execute(input, ctx, opts) {
|
|
7211
7312
|
let final;
|
|
7212
|
-
|
|
7313
|
+
const executeStream = typecheckTool.executeStream;
|
|
7314
|
+
if (!executeStream) throw new Error("typecheckTool: stream execution unavailable");
|
|
7315
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
7213
7316
|
if (ev.type === "final") final = ev.output;
|
|
7214
7317
|
}
|
|
7215
7318
|
if (!final) throw new Error("typecheck: stream ended without final event");
|