oh-my-opencode 0.1.22 → 0.1.24
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/index.js
CHANGED
|
@@ -1571,6 +1571,9 @@ var SEVERITY_MAP = {
|
|
|
1571
1571
|
3: "information",
|
|
1572
1572
|
4: "hint"
|
|
1573
1573
|
};
|
|
1574
|
+
var DEFAULT_MAX_REFERENCES = 200;
|
|
1575
|
+
var DEFAULT_MAX_SYMBOLS = 200;
|
|
1576
|
+
var DEFAULT_MAX_DIAGNOSTICS = 200;
|
|
1574
1577
|
var BUILTIN_SERVERS = {
|
|
1575
1578
|
typescript: {
|
|
1576
1579
|
command: ["typescript-language-server", "--stdio"],
|
|
@@ -15025,7 +15028,14 @@ var lsp_find_references = tool({
|
|
|
15025
15028
|
const output2 = "No references found";
|
|
15026
15029
|
return output2;
|
|
15027
15030
|
}
|
|
15028
|
-
const
|
|
15031
|
+
const total = result.length;
|
|
15032
|
+
const truncated = total > DEFAULT_MAX_REFERENCES;
|
|
15033
|
+
const limited = truncated ? result.slice(0, DEFAULT_MAX_REFERENCES) : result;
|
|
15034
|
+
const lines = limited.map(formatLocation);
|
|
15035
|
+
if (truncated) {
|
|
15036
|
+
lines.unshift(`Found ${total} references (showing first ${DEFAULT_MAX_REFERENCES}):`);
|
|
15037
|
+
}
|
|
15038
|
+
const output = lines.join(`
|
|
15029
15039
|
`);
|
|
15030
15040
|
return output;
|
|
15031
15041
|
} catch (e) {
|
|
@@ -15045,18 +15055,23 @@ var lsp_document_symbols = tool({
|
|
|
15045
15055
|
return await client.documentSymbols(args.filePath);
|
|
15046
15056
|
});
|
|
15047
15057
|
if (!result || result.length === 0) {
|
|
15048
|
-
const
|
|
15049
|
-
return
|
|
15058
|
+
const output = "No symbols found";
|
|
15059
|
+
return output;
|
|
15050
15060
|
}
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15061
|
+
const total = result.length;
|
|
15062
|
+
const truncated = total > DEFAULT_MAX_SYMBOLS;
|
|
15063
|
+
const limited = truncated ? result.slice(0, DEFAULT_MAX_SYMBOLS) : result;
|
|
15064
|
+
const lines = [];
|
|
15065
|
+
if (truncated) {
|
|
15066
|
+
lines.push(`Found ${total} symbols (showing first ${DEFAULT_MAX_SYMBOLS}):`);
|
|
15067
|
+
}
|
|
15068
|
+
if ("range" in limited[0]) {
|
|
15069
|
+
lines.push(...limited.map((s) => formatDocumentSymbol(s)));
|
|
15055
15070
|
} else {
|
|
15056
|
-
|
|
15057
|
-
`);
|
|
15071
|
+
lines.push(...limited.map(formatSymbolInfo));
|
|
15058
15072
|
}
|
|
15059
|
-
return
|
|
15073
|
+
return lines.join(`
|
|
15074
|
+
`);
|
|
15060
15075
|
} catch (e) {
|
|
15061
15076
|
const output = `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
15062
15077
|
return output;
|
|
@@ -15079,8 +15094,15 @@ var lsp_workspace_symbols = tool({
|
|
|
15079
15094
|
const output2 = "No symbols found";
|
|
15080
15095
|
return output2;
|
|
15081
15096
|
}
|
|
15082
|
-
const
|
|
15083
|
-
const
|
|
15097
|
+
const total = result.length;
|
|
15098
|
+
const limit = Math.min(args.limit ?? DEFAULT_MAX_SYMBOLS, DEFAULT_MAX_SYMBOLS);
|
|
15099
|
+
const truncated = total > limit;
|
|
15100
|
+
const limited = result.slice(0, limit);
|
|
15101
|
+
const lines = limited.map(formatSymbolInfo);
|
|
15102
|
+
if (truncated) {
|
|
15103
|
+
lines.unshift(`Found ${total} symbols (showing first ${limit}):`);
|
|
15104
|
+
}
|
|
15105
|
+
const output = lines.join(`
|
|
15084
15106
|
`);
|
|
15085
15107
|
return output;
|
|
15086
15108
|
} catch (e) {
|
|
@@ -15113,7 +15135,14 @@ var lsp_diagnostics = tool({
|
|
|
15113
15135
|
const output2 = "No diagnostics found";
|
|
15114
15136
|
return output2;
|
|
15115
15137
|
}
|
|
15116
|
-
const
|
|
15138
|
+
const total = diagnostics.length;
|
|
15139
|
+
const truncated = total > DEFAULT_MAX_DIAGNOSTICS;
|
|
15140
|
+
const limited = truncated ? diagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS) : diagnostics;
|
|
15141
|
+
const lines = limited.map(formatDiagnostic);
|
|
15142
|
+
if (truncated) {
|
|
15143
|
+
lines.unshift(`Found ${total} diagnostics (showing first ${DEFAULT_MAX_DIAGNOSTICS}):`);
|
|
15144
|
+
}
|
|
15145
|
+
const output = lines.join(`
|
|
15117
15146
|
`);
|
|
15118
15147
|
return output;
|
|
15119
15148
|
} catch (e) {
|
|
@@ -15258,6 +15287,8 @@ var lsp_code_action_resolve = tool({
|
|
|
15258
15287
|
}
|
|
15259
15288
|
});
|
|
15260
15289
|
// src/tools/ast-grep/constants.ts
|
|
15290
|
+
import { createRequire as createRequire4 } from "module";
|
|
15291
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
15261
15292
|
import { existsSync as existsSync7, statSync } from "fs";
|
|
15262
15293
|
|
|
15263
15294
|
// src/tools/ast-grep/downloader.ts
|
|
@@ -15377,11 +15408,56 @@ function isValidBinary(filePath) {
|
|
|
15377
15408
|
return false;
|
|
15378
15409
|
}
|
|
15379
15410
|
}
|
|
15411
|
+
function getPlatformPackageName2() {
|
|
15412
|
+
const platform = process.platform;
|
|
15413
|
+
const arch = process.arch;
|
|
15414
|
+
const platformMap = {
|
|
15415
|
+
"darwin-arm64": "@ast-grep/cli-darwin-arm64",
|
|
15416
|
+
"darwin-x64": "@ast-grep/cli-darwin-x64",
|
|
15417
|
+
"linux-arm64": "@ast-grep/cli-linux-arm64-gnu",
|
|
15418
|
+
"linux-x64": "@ast-grep/cli-linux-x64-gnu",
|
|
15419
|
+
"win32-x64": "@ast-grep/cli-win32-x64-msvc",
|
|
15420
|
+
"win32-arm64": "@ast-grep/cli-win32-arm64-msvc",
|
|
15421
|
+
"win32-ia32": "@ast-grep/cli-win32-ia32-msvc"
|
|
15422
|
+
};
|
|
15423
|
+
return platformMap[`${platform}-${arch}`] ?? null;
|
|
15424
|
+
}
|
|
15380
15425
|
function findSgCliPathSync() {
|
|
15426
|
+
const binaryName = process.platform === "win32" ? "sg.exe" : "sg";
|
|
15381
15427
|
const cachedPath = getCachedBinaryPath2();
|
|
15382
15428
|
if (cachedPath && isValidBinary(cachedPath)) {
|
|
15383
15429
|
return cachedPath;
|
|
15384
15430
|
}
|
|
15431
|
+
try {
|
|
15432
|
+
const require2 = createRequire4(import.meta.url);
|
|
15433
|
+
const cliPkgPath = require2.resolve("@ast-grep/cli/package.json");
|
|
15434
|
+
const cliDir = dirname2(cliPkgPath);
|
|
15435
|
+
const sgPath = join5(cliDir, binaryName);
|
|
15436
|
+
if (existsSync7(sgPath) && isValidBinary(sgPath)) {
|
|
15437
|
+
return sgPath;
|
|
15438
|
+
}
|
|
15439
|
+
} catch {}
|
|
15440
|
+
const platformPkg = getPlatformPackageName2();
|
|
15441
|
+
if (platformPkg) {
|
|
15442
|
+
try {
|
|
15443
|
+
const require2 = createRequire4(import.meta.url);
|
|
15444
|
+
const pkgPath = require2.resolve(`${platformPkg}/package.json`);
|
|
15445
|
+
const pkgDir = dirname2(pkgPath);
|
|
15446
|
+
const astGrepName = process.platform === "win32" ? "ast-grep.exe" : "ast-grep";
|
|
15447
|
+
const binaryPath = join5(pkgDir, astGrepName);
|
|
15448
|
+
if (existsSync7(binaryPath) && isValidBinary(binaryPath)) {
|
|
15449
|
+
return binaryPath;
|
|
15450
|
+
}
|
|
15451
|
+
} catch {}
|
|
15452
|
+
}
|
|
15453
|
+
if (process.platform === "darwin") {
|
|
15454
|
+
const homebrewPaths = ["/opt/homebrew/bin/sg", "/usr/local/bin/sg"];
|
|
15455
|
+
for (const path of homebrewPaths) {
|
|
15456
|
+
if (existsSync7(path) && isValidBinary(path)) {
|
|
15457
|
+
return path;
|
|
15458
|
+
}
|
|
15459
|
+
}
|
|
15460
|
+
}
|
|
15385
15461
|
return null;
|
|
15386
15462
|
}
|
|
15387
15463
|
var resolvedCliPath2 = null;
|
|
@@ -15428,6 +15504,9 @@ var CLI_LANGUAGES = [
|
|
|
15428
15504
|
"yaml"
|
|
15429
15505
|
];
|
|
15430
15506
|
var NAPI_LANGUAGES = ["html", "javascript", "tsx", "css", "typescript"];
|
|
15507
|
+
var DEFAULT_TIMEOUT_MS = 300000;
|
|
15508
|
+
var DEFAULT_MAX_OUTPUT_BYTES = 1 * 1024 * 1024;
|
|
15509
|
+
var DEFAULT_MAX_MATCHES = 500;
|
|
15431
15510
|
var LANG_EXTENSIONS = {
|
|
15432
15511
|
bash: [".bash", ".sh", ".zsh", ".bats"],
|
|
15433
15512
|
c: [".c", ".h"],
|
|
@@ -15485,16 +15564,6 @@ async function getAstGrepPath() {
|
|
|
15485
15564
|
})();
|
|
15486
15565
|
return initPromise2;
|
|
15487
15566
|
}
|
|
15488
|
-
async function spawnSg(cliPath, args) {
|
|
15489
|
-
const proc = spawn5([cliPath, ...args], {
|
|
15490
|
-
stdout: "pipe",
|
|
15491
|
-
stderr: "pipe"
|
|
15492
|
-
});
|
|
15493
|
-
const stdout = await new Response(proc.stdout).text();
|
|
15494
|
-
const stderr = await new Response(proc.stderr).text();
|
|
15495
|
-
const exitCode = await proc.exited;
|
|
15496
|
-
return { stdout, stderr, exitCode };
|
|
15497
|
-
}
|
|
15498
15567
|
async function runSg(options) {
|
|
15499
15568
|
const args = ["run", "-p", options.pattern, "--lang", options.lang, "--json=compact"];
|
|
15500
15569
|
if (options.rewrite) {
|
|
@@ -15520,47 +15589,114 @@ async function runSg(options) {
|
|
|
15520
15589
|
cliPath = downloadedPath;
|
|
15521
15590
|
}
|
|
15522
15591
|
}
|
|
15523
|
-
|
|
15592
|
+
const timeout = DEFAULT_TIMEOUT_MS;
|
|
15593
|
+
const proc = spawn5([cliPath, ...args], {
|
|
15594
|
+
stdout: "pipe",
|
|
15595
|
+
stderr: "pipe"
|
|
15596
|
+
});
|
|
15597
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
15598
|
+
const id = setTimeout(() => {
|
|
15599
|
+
proc.kill();
|
|
15600
|
+
reject(new Error(`Search timeout after ${timeout}ms`));
|
|
15601
|
+
}, timeout);
|
|
15602
|
+
proc.exited.then(() => clearTimeout(id));
|
|
15603
|
+
});
|
|
15604
|
+
let stdout;
|
|
15605
|
+
let stderr;
|
|
15606
|
+
let exitCode;
|
|
15524
15607
|
try {
|
|
15525
|
-
|
|
15608
|
+
stdout = await Promise.race([new Response(proc.stdout).text(), timeoutPromise]);
|
|
15609
|
+
stderr = await new Response(proc.stderr).text();
|
|
15610
|
+
exitCode = await proc.exited;
|
|
15526
15611
|
} catch (e) {
|
|
15527
15612
|
const error45 = e;
|
|
15528
|
-
if (error45.
|
|
15613
|
+
if (error45.message?.includes("timeout")) {
|
|
15614
|
+
return {
|
|
15615
|
+
matches: [],
|
|
15616
|
+
totalMatches: 0,
|
|
15617
|
+
truncated: true,
|
|
15618
|
+
truncatedReason: "timeout",
|
|
15619
|
+
error: error45.message
|
|
15620
|
+
};
|
|
15621
|
+
}
|
|
15622
|
+
const nodeError = e;
|
|
15623
|
+
if (nodeError.code === "ENOENT" || nodeError.message?.includes("ENOENT") || nodeError.message?.includes("not found")) {
|
|
15529
15624
|
const downloadedPath = await ensureAstGrepBinary();
|
|
15530
15625
|
if (downloadedPath) {
|
|
15531
15626
|
resolvedCliPath3 = downloadedPath;
|
|
15532
15627
|
setSgCliPath(downloadedPath);
|
|
15533
|
-
|
|
15628
|
+
return runSg(options);
|
|
15534
15629
|
} else {
|
|
15535
|
-
|
|
15630
|
+
return {
|
|
15631
|
+
matches: [],
|
|
15632
|
+
totalMatches: 0,
|
|
15633
|
+
truncated: false,
|
|
15634
|
+
error: `ast-grep CLI binary not found.
|
|
15536
15635
|
|
|
15537
15636
|
` + `Auto-download failed. Manual install options:
|
|
15538
15637
|
` + ` bun add -D @ast-grep/cli
|
|
15539
15638
|
` + ` cargo install ast-grep --locked
|
|
15540
|
-
` + ` brew install ast-grep`
|
|
15639
|
+
` + ` brew install ast-grep`
|
|
15640
|
+
};
|
|
15541
15641
|
}
|
|
15542
|
-
} else {
|
|
15543
|
-
throw new Error(`Failed to spawn ast-grep: ${error45.message}`);
|
|
15544
15642
|
}
|
|
15643
|
+
return {
|
|
15644
|
+
matches: [],
|
|
15645
|
+
totalMatches: 0,
|
|
15646
|
+
truncated: false,
|
|
15647
|
+
error: `Failed to spawn ast-grep: ${error45.message}`
|
|
15648
|
+
};
|
|
15545
15649
|
}
|
|
15546
|
-
const { stdout, stderr, exitCode } = result;
|
|
15547
15650
|
if (exitCode !== 0 && stdout.trim() === "") {
|
|
15548
15651
|
if (stderr.includes("No files found")) {
|
|
15549
|
-
return [];
|
|
15652
|
+
return { matches: [], totalMatches: 0, truncated: false };
|
|
15550
15653
|
}
|
|
15551
15654
|
if (stderr.trim()) {
|
|
15552
|
-
|
|
15655
|
+
return { matches: [], totalMatches: 0, truncated: false, error: stderr.trim() };
|
|
15553
15656
|
}
|
|
15554
|
-
return [];
|
|
15657
|
+
return { matches: [], totalMatches: 0, truncated: false };
|
|
15555
15658
|
}
|
|
15556
15659
|
if (!stdout.trim()) {
|
|
15557
|
-
return [];
|
|
15660
|
+
return { matches: [], totalMatches: 0, truncated: false };
|
|
15558
15661
|
}
|
|
15662
|
+
const outputTruncated = stdout.length >= DEFAULT_MAX_OUTPUT_BYTES;
|
|
15663
|
+
const outputToProcess = outputTruncated ? stdout.substring(0, DEFAULT_MAX_OUTPUT_BYTES) : stdout;
|
|
15664
|
+
let matches = [];
|
|
15559
15665
|
try {
|
|
15560
|
-
|
|
15666
|
+
matches = JSON.parse(outputToProcess);
|
|
15561
15667
|
} catch {
|
|
15562
|
-
|
|
15668
|
+
if (outputTruncated) {
|
|
15669
|
+
try {
|
|
15670
|
+
const lastValidIndex = outputToProcess.lastIndexOf("}");
|
|
15671
|
+
if (lastValidIndex > 0) {
|
|
15672
|
+
const bracketIndex = outputToProcess.lastIndexOf("},", lastValidIndex);
|
|
15673
|
+
if (bracketIndex > 0) {
|
|
15674
|
+
const truncatedJson = outputToProcess.substring(0, bracketIndex + 1) + "]";
|
|
15675
|
+
matches = JSON.parse(truncatedJson);
|
|
15676
|
+
}
|
|
15677
|
+
}
|
|
15678
|
+
} catch {
|
|
15679
|
+
return {
|
|
15680
|
+
matches: [],
|
|
15681
|
+
totalMatches: 0,
|
|
15682
|
+
truncated: true,
|
|
15683
|
+
truncatedReason: "max_output_bytes",
|
|
15684
|
+
error: "Output too large and could not be parsed"
|
|
15685
|
+
};
|
|
15686
|
+
}
|
|
15687
|
+
} else {
|
|
15688
|
+
return { matches: [], totalMatches: 0, truncated: false };
|
|
15689
|
+
}
|
|
15563
15690
|
}
|
|
15691
|
+
const totalMatches = matches.length;
|
|
15692
|
+
const matchesTruncated = totalMatches > DEFAULT_MAX_MATCHES;
|
|
15693
|
+
const finalMatches = matchesTruncated ? matches.slice(0, DEFAULT_MAX_MATCHES) : matches;
|
|
15694
|
+
return {
|
|
15695
|
+
matches: finalMatches,
|
|
15696
|
+
totalMatches,
|
|
15697
|
+
truncated: outputTruncated || matchesTruncated,
|
|
15698
|
+
truncatedReason: outputTruncated ? "max_output_bytes" : matchesTruncated ? "max_matches" : undefined
|
|
15699
|
+
};
|
|
15564
15700
|
}
|
|
15565
15701
|
|
|
15566
15702
|
// src/tools/ast-grep/napi.ts
|
|
@@ -15649,13 +15785,22 @@ function getRootInfo(code, lang) {
|
|
|
15649
15785
|
}
|
|
15650
15786
|
|
|
15651
15787
|
// src/tools/ast-grep/utils.ts
|
|
15652
|
-
function formatSearchResult(
|
|
15653
|
-
if (
|
|
15788
|
+
function formatSearchResult(result) {
|
|
15789
|
+
if (result.error) {
|
|
15790
|
+
return `Error: ${result.error}`;
|
|
15791
|
+
}
|
|
15792
|
+
if (result.matches.length === 0) {
|
|
15654
15793
|
return "No matches found";
|
|
15655
15794
|
}
|
|
15656
|
-
const lines = [
|
|
15657
|
-
|
|
15658
|
-
|
|
15795
|
+
const lines = [];
|
|
15796
|
+
if (result.truncated) {
|
|
15797
|
+
const reason = result.truncatedReason === "max_matches" ? `showing first ${result.matches.length} of ${result.totalMatches}` : result.truncatedReason === "max_output_bytes" ? "output exceeded 1MB limit" : "search timed out";
|
|
15798
|
+
lines.push(`\u26A0\uFE0F Results truncated (${reason})
|
|
15799
|
+
`);
|
|
15800
|
+
}
|
|
15801
|
+
lines.push(`Found ${result.matches.length} match(es)${result.truncated ? ` (truncated from ${result.totalMatches})` : ""}:
|
|
15802
|
+
`);
|
|
15803
|
+
for (const match of result.matches) {
|
|
15659
15804
|
const loc = `${match.file}:${match.range.start.line + 1}:${match.range.start.column + 1}`;
|
|
15660
15805
|
lines.push(`${loc}`);
|
|
15661
15806
|
lines.push(` ${match.lines.trim()}`);
|
|
@@ -15664,14 +15809,23 @@ function formatSearchResult(matches) {
|
|
|
15664
15809
|
return lines.join(`
|
|
15665
15810
|
`);
|
|
15666
15811
|
}
|
|
15667
|
-
function formatReplaceResult(
|
|
15668
|
-
if (
|
|
15812
|
+
function formatReplaceResult(result, isDryRun) {
|
|
15813
|
+
if (result.error) {
|
|
15814
|
+
return `Error: ${result.error}`;
|
|
15815
|
+
}
|
|
15816
|
+
if (result.matches.length === 0) {
|
|
15669
15817
|
return "No matches found to replace";
|
|
15670
15818
|
}
|
|
15671
15819
|
const prefix = isDryRun ? "[DRY RUN] " : "";
|
|
15672
|
-
const lines = [
|
|
15673
|
-
|
|
15674
|
-
|
|
15820
|
+
const lines = [];
|
|
15821
|
+
if (result.truncated) {
|
|
15822
|
+
const reason = result.truncatedReason === "max_matches" ? `showing first ${result.matches.length} of ${result.totalMatches}` : result.truncatedReason === "max_output_bytes" ? "output exceeded 1MB limit" : "search timed out";
|
|
15823
|
+
lines.push(`\u26A0\uFE0F Results truncated (${reason})
|
|
15824
|
+
`);
|
|
15825
|
+
}
|
|
15826
|
+
lines.push(`${prefix}${result.matches.length} replacement(s):
|
|
15827
|
+
`);
|
|
15828
|
+
for (const match of result.matches) {
|
|
15675
15829
|
const loc = `${match.file}:${match.range.start.line + 1}:${match.range.start.column + 1}`;
|
|
15676
15830
|
lines.push(`${loc}`);
|
|
15677
15831
|
lines.push(` ${match.text}`);
|
|
@@ -15749,15 +15903,15 @@ var ast_grep_search = tool({
|
|
|
15749
15903
|
},
|
|
15750
15904
|
execute: async (args, context) => {
|
|
15751
15905
|
try {
|
|
15752
|
-
const
|
|
15906
|
+
const result = await runSg({
|
|
15753
15907
|
pattern: args.pattern,
|
|
15754
15908
|
lang: args.lang,
|
|
15755
15909
|
paths: args.paths,
|
|
15756
15910
|
globs: args.globs,
|
|
15757
15911
|
context: args.context
|
|
15758
15912
|
});
|
|
15759
|
-
let output = formatSearchResult(
|
|
15760
|
-
if (matches.length === 0) {
|
|
15913
|
+
let output = formatSearchResult(result);
|
|
15914
|
+
if (result.matches.length === 0 && !result.error) {
|
|
15761
15915
|
const hint = getEmptyResultHint(args.pattern, args.lang);
|
|
15762
15916
|
if (hint) {
|
|
15763
15917
|
output += `
|
|
@@ -15786,7 +15940,7 @@ var ast_grep_replace = tool({
|
|
|
15786
15940
|
},
|
|
15787
15941
|
execute: async (args, context) => {
|
|
15788
15942
|
try {
|
|
15789
|
-
const
|
|
15943
|
+
const result = await runSg({
|
|
15790
15944
|
pattern: args.pattern,
|
|
15791
15945
|
rewrite: args.rewrite,
|
|
15792
15946
|
lang: args.lang,
|
|
@@ -15794,7 +15948,7 @@ var ast_grep_replace = tool({
|
|
|
15794
15948
|
globs: args.globs,
|
|
15795
15949
|
updateAll: args.dryRun === false
|
|
15796
15950
|
});
|
|
15797
|
-
const output = formatReplaceResult(
|
|
15951
|
+
const output = formatReplaceResult(result, args.dryRun !== false);
|
|
15798
15952
|
showOutputToUser(context, output);
|
|
15799
15953
|
return output;
|
|
15800
15954
|
} catch (e) {
|
|
@@ -15875,7 +16029,7 @@ var {spawn: spawn6 } = globalThis.Bun;
|
|
|
15875
16029
|
|
|
15876
16030
|
// src/tools/safe-grep/constants.ts
|
|
15877
16031
|
import { existsSync as existsSync9 } from "fs";
|
|
15878
|
-
import { join as
|
|
16032
|
+
import { join as join6, dirname as dirname3 } from "path";
|
|
15879
16033
|
import { spawnSync } from "child_process";
|
|
15880
16034
|
var cachedCli = null;
|
|
15881
16035
|
function findExecutable(name) {
|
|
@@ -15892,14 +16046,14 @@ function findExecutable(name) {
|
|
|
15892
16046
|
}
|
|
15893
16047
|
function getOpenCodeBundledRg() {
|
|
15894
16048
|
const execPath = process.execPath;
|
|
15895
|
-
const execDir =
|
|
16049
|
+
const execDir = dirname3(execPath);
|
|
15896
16050
|
const isWindows = process.platform === "win32";
|
|
15897
16051
|
const rgName = isWindows ? "rg.exe" : "rg";
|
|
15898
16052
|
const candidates = [
|
|
15899
|
-
|
|
15900
|
-
|
|
15901
|
-
|
|
15902
|
-
|
|
16053
|
+
join6(execDir, rgName),
|
|
16054
|
+
join6(execDir, "bin", rgName),
|
|
16055
|
+
join6(execDir, "..", "bin", rgName),
|
|
16056
|
+
join6(execDir, "..", "libexec", rgName)
|
|
15903
16057
|
];
|
|
15904
16058
|
for (const candidate of candidates) {
|
|
15905
16059
|
if (existsSync9(candidate)) {
|
|
@@ -15933,8 +16087,8 @@ var DEFAULT_MAX_DEPTH = 20;
|
|
|
15933
16087
|
var DEFAULT_MAX_FILESIZE = "10M";
|
|
15934
16088
|
var DEFAULT_MAX_COUNT = 500;
|
|
15935
16089
|
var DEFAULT_MAX_COLUMNS = 1000;
|
|
15936
|
-
var
|
|
15937
|
-
var
|
|
16090
|
+
var DEFAULT_TIMEOUT_MS2 = 300000;
|
|
16091
|
+
var DEFAULT_MAX_OUTPUT_BYTES2 = 10 * 1024 * 1024;
|
|
15938
16092
|
var RG_SAFETY_FLAGS = [
|
|
15939
16093
|
"--no-follow",
|
|
15940
16094
|
"--color=never",
|
|
@@ -16035,7 +16189,7 @@ function parseOutput(output) {
|
|
|
16035
16189
|
async function runRg(options) {
|
|
16036
16190
|
const cli = resolveGrepCli();
|
|
16037
16191
|
const args = buildArgs(options, cli.backend);
|
|
16038
|
-
const timeout = Math.min(options.timeout ??
|
|
16192
|
+
const timeout = Math.min(options.timeout ?? DEFAULT_TIMEOUT_MS2, DEFAULT_TIMEOUT_MS2);
|
|
16039
16193
|
if (cli.backend === "rg") {
|
|
16040
16194
|
args.push("--", options.pattern);
|
|
16041
16195
|
} else {
|
|
@@ -16058,8 +16212,8 @@ async function runRg(options) {
|
|
|
16058
16212
|
const stdout = await Promise.race([new Response(proc.stdout).text(), timeoutPromise]);
|
|
16059
16213
|
const stderr = await new Response(proc.stderr).text();
|
|
16060
16214
|
const exitCode = await proc.exited;
|
|
16061
|
-
const truncated = stdout.length >=
|
|
16062
|
-
const outputToProcess = truncated ? stdout.substring(0,
|
|
16215
|
+
const truncated = stdout.length >= DEFAULT_MAX_OUTPUT_BYTES2;
|
|
16216
|
+
const outputToProcess = truncated ? stdout.substring(0, DEFAULT_MAX_OUTPUT_BYTES2) : stdout;
|
|
16063
16217
|
if (exitCode > 1 && stderr.trim()) {
|
|
16064
16218
|
return {
|
|
16065
16219
|
matches: [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CliLanguage, SgResult } from "./types";
|
|
2
2
|
export interface RunOptions {
|
|
3
3
|
pattern: string;
|
|
4
4
|
lang: CliLanguage;
|
|
@@ -10,6 +10,6 @@ export interface RunOptions {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function getAstGrepPath(): Promise<string | null>;
|
|
12
12
|
export declare function startBackgroundInit(): void;
|
|
13
|
-
export declare function runSg(options: RunOptions): Promise<
|
|
13
|
+
export declare function runSg(options: RunOptions): Promise<SgResult>;
|
|
14
14
|
export declare function isCliAvailable(): boolean;
|
|
15
15
|
export declare function ensureCliAvailable(): Promise<boolean>;
|
|
@@ -4,6 +4,9 @@ export declare function setSgCliPath(path: string): void;
|
|
|
4
4
|
export declare const SG_CLI_PATH: string;
|
|
5
5
|
export declare const CLI_LANGUAGES: readonly ["bash", "c", "cpp", "csharp", "css", "elixir", "go", "haskell", "html", "java", "javascript", "json", "kotlin", "lua", "nix", "php", "python", "ruby", "rust", "scala", "solidity", "swift", "typescript", "tsx", "yaml"];
|
|
6
6
|
export declare const NAPI_LANGUAGES: readonly ["html", "javascript", "tsx", "css", "typescript"];
|
|
7
|
+
export declare const DEFAULT_TIMEOUT_MS = 300000;
|
|
8
|
+
export declare const DEFAULT_MAX_OUTPUT_BYTES: number;
|
|
9
|
+
export declare const DEFAULT_MAX_MATCHES = 500;
|
|
7
10
|
export declare const LANG_EXTENSIONS: Record<string, string[]>;
|
|
8
11
|
export interface EnvironmentCheckResult {
|
|
9
12
|
cli: {
|
|
@@ -49,3 +49,10 @@ export interface TransformResult {
|
|
|
49
49
|
transformed: string;
|
|
50
50
|
editCount: number;
|
|
51
51
|
}
|
|
52
|
+
export interface SgResult {
|
|
53
|
+
matches: CliMatch[];
|
|
54
|
+
totalMatches: number;
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
truncatedReason?: "max_matches" | "max_output_bytes" | "timeout";
|
|
57
|
+
error?: string;
|
|
58
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function formatSearchResult(
|
|
3
|
-
export declare function formatReplaceResult(
|
|
1
|
+
import type { AnalyzeResult, SgResult } from "./types";
|
|
2
|
+
export declare function formatSearchResult(result: SgResult): string;
|
|
3
|
+
export declare function formatReplaceResult(result: SgResult, isDryRun: boolean): string;
|
|
4
4
|
export declare function formatAnalyzeResult(results: AnalyzeResult[], extractedMetaVars: boolean): string;
|
|
5
5
|
export declare function formatTransformResult(original: string, transformed: string, editCount: number): string;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { LSPServerConfig } from "./types";
|
|
2
2
|
export declare const SYMBOL_KIND_MAP: Record<number, string>;
|
|
3
3
|
export declare const SEVERITY_MAP: Record<number, string>;
|
|
4
|
+
export declare const DEFAULT_MAX_REFERENCES = 200;
|
|
5
|
+
export declare const DEFAULT_MAX_SYMBOLS = 200;
|
|
6
|
+
export declare const DEFAULT_MAX_DIAGNOSTICS = 200;
|
|
4
7
|
export declare const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">>;
|
|
5
8
|
export declare const EXT_TO_LANG: Record<string, string>;
|