dsh-hashline-edit 0.5.1 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -8
- package/cordis.patch.yml +14 -1
- package/lib/index.js +805 -108
- package/lib/types/dsh/guidance.d.ts +5 -3
- package/lib/types/dsh/hide.d.ts +6 -0
- package/lib/types/dsh/index.d.ts +30 -1
- package/lib/types/dsh/rg/cli.d.ts +67 -0
- package/lib/types/dsh/rg/command.d.ts +70 -0
- package/lib/types/dsh/rg/tools.d.ts +49 -0
- package/lib/types/dsh/rg/view.d.ts +81 -0
- package/lib/types/dsh/shell-view.d.ts +27 -3
- package/lib/types/dsh/write-hook.d.ts +16 -2
- package/package.json +22 -19
- package/prompts/rg-guidelines.md +8 -0
- package/prompts/write-guidelines.md +1 -0
- package/CHANGELOG.md +0 -345
package/lib/index.js
CHANGED
|
@@ -808,12 +808,12 @@ async function resolveTarget(path) {
|
|
|
808
808
|
if (remainingParts.length === 0) {
|
|
809
809
|
return currentPath;
|
|
810
810
|
}
|
|
811
|
-
const [nextPart, ...
|
|
811
|
+
const [nextPart, ...tail2] = remainingParts;
|
|
812
812
|
const candidatePath = join4(currentPath, nextPart);
|
|
813
813
|
try {
|
|
814
814
|
const candidateStats = await lstat(candidatePath);
|
|
815
815
|
if (!candidateStats.isSymbolicLink()) {
|
|
816
|
-
return resParts(candidatePath,
|
|
816
|
+
return resParts(candidatePath, tail2);
|
|
817
817
|
}
|
|
818
818
|
if (visitedSymlinks.has(candidatePath)) {
|
|
819
819
|
const error = new Error(
|
|
@@ -825,10 +825,10 @@ async function resolveTarget(path) {
|
|
|
825
825
|
visitedSymlinks.add(candidatePath);
|
|
826
826
|
const linkTargetPath = resolve(dirname2(candidatePath), await readlink(candidatePath));
|
|
827
827
|
const targetParts = linkTargetPath.slice(parse(linkTargetPath).root.length).split(sep).filter((part) => part.length > 0);
|
|
828
|
-
return resParts(parse(linkTargetPath).root, [...targetParts, ...
|
|
828
|
+
return resParts(parse(linkTargetPath).root, [...targetParts, ...tail2]);
|
|
829
829
|
} catch (error) {
|
|
830
830
|
if (errCode(error) === "ENOENT") {
|
|
831
|
-
return join4(candidatePath, ...
|
|
831
|
+
return join4(candidatePath, ...tail2);
|
|
832
832
|
}
|
|
833
833
|
throw error;
|
|
834
834
|
}
|
|
@@ -1598,7 +1598,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
|
|
|
1598
1598
|
});
|
|
1599
1599
|
if (disposeAssemble !== void 0) disposers.push(disposeAssemble);
|
|
1600
1600
|
const disposeGuard = tools?.guard?.(
|
|
1601
|
-
(execution) => hidden.has(execution.name) ? nativeEditorDenial(config.toolNames, execution.name) : void 0
|
|
1601
|
+
(execution) => hidden.has(execution.name) ? config.denialText?.(execution.name) ?? nativeEditorDenial(config.toolNames, execution.name) : void 0
|
|
1602
1602
|
);
|
|
1603
1603
|
if (disposeGuard !== void 0) disposers.push(disposeGuard);
|
|
1604
1604
|
return () => {
|
|
@@ -1965,6 +1965,13 @@ var GUIDANCE_SECTIONS = [
|
|
|
1965
1965
|
orderName: "TOOL_READ",
|
|
1966
1966
|
renderDefault: () => guidanceText("", loadGuide("../prompts/read-guidelines.md"))
|
|
1967
1967
|
},
|
|
1968
|
+
{
|
|
1969
|
+
name: "tool:rg",
|
|
1970
|
+
// WHY: this tool replaces the native grep, so its brief belongs in that tool's prompt slot.
|
|
1971
|
+
defaultOrder: 1500,
|
|
1972
|
+
orderName: "TOOL_GREP",
|
|
1973
|
+
renderDefault: () => guidanceText("", loadGuide("../prompts/rg-guidelines.md"))
|
|
1974
|
+
},
|
|
1968
1975
|
{
|
|
1969
1976
|
name: "tool:codegraph",
|
|
1970
1977
|
defaultOrder: 1200,
|
|
@@ -2020,6 +2027,7 @@ function orderResolver(registry) {
|
|
|
2020
2027
|
function sectionEnabled(name2, toggles) {
|
|
2021
2028
|
if (toggles === void 0) return true;
|
|
2022
2029
|
if (name2 === "tool:read") return toggles.read;
|
|
2030
|
+
if (name2 === "tool:rg") return toggles.rg === true;
|
|
2023
2031
|
if (name2 === "tool:write") return toggles.applyPatch || toggles.edit;
|
|
2024
2032
|
if (name2 === "tool:apply_patch") return toggles.applyPatch;
|
|
2025
2033
|
if (name2 === "tool:edit") return toggles.edit;
|
|
@@ -3872,8 +3880,8 @@ function contextLinesToShow(displayLines, lastWasChange, nextPartIsChange, conte
|
|
|
3872
3880
|
skipStart = Math.max(0, displayLines.length - contextLines);
|
|
3873
3881
|
linesToShow = displayLines.slice(skipStart);
|
|
3874
3882
|
} else if (nextPartIsChange && displayLines.length > contextLines * 2) {
|
|
3875
|
-
const
|
|
3876
|
-
linesToShow = [...displayLines.slice(0, contextLines), UNTOUCHED_MARKER, ...
|
|
3883
|
+
const tail2 = contextLines === 0 ? [] : displayLines.slice(-contextLines);
|
|
3884
|
+
linesToShow = [...displayLines.slice(0, contextLines), UNTOUCHED_MARKER, ...tail2];
|
|
3877
3885
|
skipMiddle = displayLines.length - contextLines * 2;
|
|
3878
3886
|
} else if (!nextPartIsChange && linesToShow.length > contextLines) {
|
|
3879
3887
|
linesToShow = linesToShow.slice(0, contextLines);
|
|
@@ -6025,9 +6033,9 @@ function buildRangeServeBlock(startLine, endLine, fileHashes, fileLines) {
|
|
|
6025
6033
|
const last = Math.max(first, Math.min(endLine, Math.max(len, first)));
|
|
6026
6034
|
const servedRows = buildRangeServeRows(first, last, fileHashes);
|
|
6027
6035
|
const totalLen = endLine - startLine + 1;
|
|
6028
|
-
const
|
|
6036
|
+
const tail2 = first === startLine && servedRows.length < totalLen ? `
|
|
6029
6037
|
${paginationHint(startLine + servedRows.length, totalLen - servedRows.length)}` : "";
|
|
6030
|
-
return { servedRows, rendered: fmtServedRows(servedRows, fileLines) +
|
|
6038
|
+
return { servedRows, rendered: fmtServedRows(servedRows, fileLines) + tail2 };
|
|
6031
6039
|
}
|
|
6032
6040
|
function assembleRejectAndServe(args) {
|
|
6033
6041
|
const { servedRows, rendered } = buildRangeServeBlock(
|
|
@@ -10221,16 +10229,16 @@ function createDefaultReadSpanProvider(io) {
|
|
|
10221
10229
|
};
|
|
10222
10230
|
return createReadSpanProvider(readTextFile === void 0 ? {} : { readTextFile });
|
|
10223
10231
|
}
|
|
10224
|
-
async function loadGovernedText(deps, absolutePath,
|
|
10232
|
+
async function loadGovernedText(deps, absolutePath, displayPath2, signal) {
|
|
10225
10233
|
const loaded = await loadFileKindAndText(absolutePath, {
|
|
10226
|
-
displayPath,
|
|
10234
|
+
displayPath: displayPath2,
|
|
10227
10235
|
...deps.coreIo === void 0 ? {} : { io: deps.coreIo },
|
|
10228
10236
|
...signal === void 0 ? {} : { signal }
|
|
10229
10237
|
});
|
|
10230
|
-
if (loaded.kind !== "text") throw unsupportedLoaded(
|
|
10238
|
+
if (loaded.kind !== "text") throw unsupportedLoaded(displayPath2, loaded);
|
|
10231
10239
|
const decoded = decodeUtf8Strict(
|
|
10232
10240
|
deps.coreIo === void 0 ? await deps.io.read(absolutePath, signal) : await deps.coreIo.readFile(await deps.coreIo.resolve(absolutePath), signal),
|
|
10233
|
-
|
|
10241
|
+
displayPath2
|
|
10234
10242
|
);
|
|
10235
10243
|
const stats = loaded.stats;
|
|
10236
10244
|
return {
|
|
@@ -11006,15 +11014,117 @@ function selectStringPath(stage) {
|
|
|
11006
11014
|
if (patternSeen) return positionals.length === 1 ? usablePath(positionals[0]) : void 0;
|
|
11007
11015
|
return positionals.length === 2 ? usablePath(positionals[1]) : void 0;
|
|
11008
11016
|
}
|
|
11017
|
+
var RG_SAFE_LONG = /* @__PURE__ */ new Set([
|
|
11018
|
+
"ignore-case",
|
|
11019
|
+
"fixed-strings",
|
|
11020
|
+
"word-regexp",
|
|
11021
|
+
"smart-case",
|
|
11022
|
+
"line-number"
|
|
11023
|
+
]);
|
|
11024
|
+
var RG_SAFE_SHORT = /* @__PURE__ */ new Set(["i", "F", "w", "S", "n"]);
|
|
11009
11025
|
function rgPath(stage) {
|
|
11010
11026
|
if (stage[0] === void 0 || !eq(stage[0], "rg")) return void 0;
|
|
11011
11027
|
const positionals = [];
|
|
11012
11028
|
for (const token of stage.slice(1)) {
|
|
11013
|
-
if (token.startsWith("
|
|
11029
|
+
if (token.startsWith("--")) {
|
|
11030
|
+
const name2 = token.slice(2);
|
|
11031
|
+
if (name2.includes("=") || !RG_SAFE_LONG.has(name2)) return void 0;
|
|
11032
|
+
continue;
|
|
11033
|
+
}
|
|
11034
|
+
if (token.startsWith("-") && token.length > 1) {
|
|
11035
|
+
for (const flag of token.slice(1)) if (!RG_SAFE_SHORT.has(flag)) return void 0;
|
|
11036
|
+
continue;
|
|
11037
|
+
}
|
|
11014
11038
|
positionals.push(token);
|
|
11015
11039
|
}
|
|
11016
11040
|
return positionals.length === 2 ? usablePath(positionals[1]) : void 0;
|
|
11017
11041
|
}
|
|
11042
|
+
var GREP_SAFE_LONG = /* @__PURE__ */ new Set([
|
|
11043
|
+
"line-number",
|
|
11044
|
+
"ignore-case",
|
|
11045
|
+
"fixed-strings",
|
|
11046
|
+
"word-regexp",
|
|
11047
|
+
"extended-regexp",
|
|
11048
|
+
"basic-regexp",
|
|
11049
|
+
"no-messages",
|
|
11050
|
+
"no-color"
|
|
11051
|
+
]);
|
|
11052
|
+
var GREP_SAFE_SHORT = /* @__PURE__ */ new Set(["n", "i", "F", "w", "E", "G", "s"]);
|
|
11053
|
+
function grepView(stage) {
|
|
11054
|
+
if (stage[0] === void 0 || !eq(stage[0], "grep")) return void 0;
|
|
11055
|
+
const positionals = [];
|
|
11056
|
+
let numbered = false;
|
|
11057
|
+
let optionsDone = false;
|
|
11058
|
+
for (const token of stage.slice(1)) {
|
|
11059
|
+
if (!optionsDone && token === "--") {
|
|
11060
|
+
optionsDone = true;
|
|
11061
|
+
continue;
|
|
11062
|
+
}
|
|
11063
|
+
if (!optionsDone && token.startsWith("--")) {
|
|
11064
|
+
const name2 = token.slice(2);
|
|
11065
|
+
if (name2.includes("=") || !GREP_SAFE_LONG.has(name2)) return void 0;
|
|
11066
|
+
if (name2 === "line-number") numbered = true;
|
|
11067
|
+
continue;
|
|
11068
|
+
}
|
|
11069
|
+
if (!optionsDone && token.startsWith("-") && token.length > 1) {
|
|
11070
|
+
for (const flag of token.slice(1)) {
|
|
11071
|
+
if (!GREP_SAFE_SHORT.has(flag)) return void 0;
|
|
11072
|
+
if (flag === "n") numbered = true;
|
|
11073
|
+
}
|
|
11074
|
+
continue;
|
|
11075
|
+
}
|
|
11076
|
+
positionals.push(token);
|
|
11077
|
+
}
|
|
11078
|
+
if (positionals.length !== 2) return void 0;
|
|
11079
|
+
const path = usablePath(positionals[1]);
|
|
11080
|
+
return path === void 0 ? void 0 : { path, numbered };
|
|
11081
|
+
}
|
|
11082
|
+
function headTailView(stage) {
|
|
11083
|
+
const head = stage[0];
|
|
11084
|
+
if (head === void 0) return void 0;
|
|
11085
|
+
const kind = eq(head, "head") ? "first" : eq(head, "tail") ? "last" : void 0;
|
|
11086
|
+
if (kind === void 0) return void 0;
|
|
11087
|
+
let count;
|
|
11088
|
+
const positionals = [];
|
|
11089
|
+
for (let index = 1; index < stage.length; index += 1) {
|
|
11090
|
+
const token = stage[index];
|
|
11091
|
+
if (token === void 0) return void 0;
|
|
11092
|
+
if (token.startsWith("--lines=")) {
|
|
11093
|
+
const raw = token.slice("--lines=".length);
|
|
11094
|
+
if (!/^\d+$/u.test(raw)) return void 0;
|
|
11095
|
+
count = Number(raw);
|
|
11096
|
+
continue;
|
|
11097
|
+
}
|
|
11098
|
+
if (token === "--lines") {
|
|
11099
|
+
const raw = stage[index + 1];
|
|
11100
|
+
index += 1;
|
|
11101
|
+
if (raw === void 0 || !/^\d+$/u.test(raw)) return void 0;
|
|
11102
|
+
count = Number(raw);
|
|
11103
|
+
continue;
|
|
11104
|
+
}
|
|
11105
|
+
if (token.startsWith("-") && token.length > 1) {
|
|
11106
|
+
const flag = token.slice(1);
|
|
11107
|
+
if (flag === "n") {
|
|
11108
|
+
const raw = stage[index + 1];
|
|
11109
|
+
index += 1;
|
|
11110
|
+
if (raw === void 0 || !/^\d+$/u.test(raw)) return void 0;
|
|
11111
|
+
count = Number(raw);
|
|
11112
|
+
continue;
|
|
11113
|
+
}
|
|
11114
|
+
if (/^\d+$/u.test(flag)) {
|
|
11115
|
+
count = Number(flag);
|
|
11116
|
+
continue;
|
|
11117
|
+
}
|
|
11118
|
+
return void 0;
|
|
11119
|
+
}
|
|
11120
|
+
if (token.startsWith("+")) return void 0;
|
|
11121
|
+
positionals.push(token);
|
|
11122
|
+
}
|
|
11123
|
+
if (positionals.length !== 1) return void 0;
|
|
11124
|
+
const path = usablePath(positionals[0]);
|
|
11125
|
+
if (path === void 0) return void 0;
|
|
11126
|
+
return { kind, path, count: count ?? 10 };
|
|
11127
|
+
}
|
|
11018
11128
|
function parse3(command) {
|
|
11019
11129
|
const tokens = tokenize(command);
|
|
11020
11130
|
if (tokens === void 0) return void 0;
|
|
@@ -11050,6 +11160,12 @@ function parse3(command) {
|
|
|
11050
11160
|
const path2 = rgPath(first);
|
|
11051
11161
|
return path2 === void 0 ? void 0 : { kind: "search", path: path2 };
|
|
11052
11162
|
}
|
|
11163
|
+
if (eq(head, "grep")) {
|
|
11164
|
+
const view = grepView(first);
|
|
11165
|
+
if (view === void 0) return void 0;
|
|
11166
|
+
return { kind: view.numbered ? "search" : "bare", path: view.path };
|
|
11167
|
+
}
|
|
11168
|
+
if (eq(head, "head") || eq(head, "tail")) return headTailView(first);
|
|
11053
11169
|
return void 0;
|
|
11054
11170
|
}
|
|
11055
11171
|
const second = stages[1];
|
|
@@ -11186,7 +11302,7 @@ function alignTransform(command, fileLines, stdoutLines) {
|
|
|
11186
11302
|
if (command.kind === "full") {
|
|
11187
11303
|
return stdoutLines.length === total ? aligned : void 0;
|
|
11188
11304
|
}
|
|
11189
|
-
if (command.kind === "search") return aligned;
|
|
11305
|
+
if (command.kind === "search" || command.kind === "bare") return aligned;
|
|
11190
11306
|
if (command.kind === "window") {
|
|
11191
11307
|
const window = Math.min(command.count, Math.max(0, total - command.skip));
|
|
11192
11308
|
if (stdoutLines.length !== window) return void 0;
|
|
@@ -11247,6 +11363,8 @@ async function plan(deps, request) {
|
|
|
11247
11363
|
}
|
|
11248
11364
|
}
|
|
11249
11365
|
var GREP_TOOL_NAME = "grep";
|
|
11366
|
+
var RG_TOOL_NAME = "rg";
|
|
11367
|
+
var GREP_TOOL_NAMES = [GREP_TOOL_NAME, RG_TOOL_NAME];
|
|
11250
11368
|
var GREP_INLINE_MAX_MATCHES = 250;
|
|
11251
11369
|
var GREP_VIEW_MAX_INLINE_TOKENS = 12500;
|
|
11252
11370
|
var TOKEN_CHARS_PER_UNIT = 4;
|
|
@@ -11254,12 +11372,19 @@ var TOKEN_BLOCK_OVERHEAD = 4;
|
|
|
11254
11372
|
function estimateTextTokens(text) {
|
|
11255
11373
|
return Math.ceil(text.length / TOKEN_CHARS_PER_UNIT) + TOKEN_BLOCK_OVERHEAD;
|
|
11256
11374
|
}
|
|
11257
|
-
function
|
|
11258
|
-
const
|
|
11259
|
-
|
|
11375
|
+
function grepRowsPage(rows) {
|
|
11376
|
+
const groups = /* @__PURE__ */ new Map();
|
|
11377
|
+
for (const row of rows) {
|
|
11378
|
+
const group = groups.get(row.path);
|
|
11379
|
+
if (group === void 0) groups.set(row.path, [row]);
|
|
11380
|
+
else group.push(row);
|
|
11381
|
+
}
|
|
11382
|
+
const blocks = [...groups].map(([path, group]) => {
|
|
11383
|
+
const count = group.length;
|
|
11260
11384
|
const noun = count === 1 ? "match" : "matches";
|
|
11261
|
-
|
|
11262
|
-
${
|
|
11385
|
+
const lines = group.map((row) => `${row.hash}${HASH_SEP}${row.text}`).join("\n");
|
|
11386
|
+
return `[${path} (${count} ${noun})]
|
|
11387
|
+
${lines}`;
|
|
11263
11388
|
});
|
|
11264
11389
|
return `${bashBanner("search")}
|
|
11265
11390
|
${blocks.join("\n")}`;
|
|
@@ -11304,15 +11429,22 @@ async function planGrepView(deps, request) {
|
|
|
11304
11429
|
}
|
|
11305
11430
|
linesByPath.set(path, texts);
|
|
11306
11431
|
}
|
|
11307
|
-
const
|
|
11308
|
-
|
|
11309
|
-
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
|
|
11432
|
+
const previewRows = [];
|
|
11433
|
+
for (const [path, lineNumbers] of lineNumbersByPath) {
|
|
11434
|
+
const texts = linesByPath.get(path) ?? [];
|
|
11435
|
+
for (let index = 0; index < lineNumbers.length; index += 1) {
|
|
11436
|
+
previewRows.push({
|
|
11437
|
+
path,
|
|
11438
|
+
lineNumber: lineNumbers[index] ?? 0,
|
|
11439
|
+
hash: "0000",
|
|
11440
|
+
text: texts[index] ?? ""
|
|
11441
|
+
});
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
if (estimateTextTokens(grepRowsPage(previewRows)) > GREP_VIEW_MAX_INLINE_TOKENS) {
|
|
11313
11445
|
return void 0;
|
|
11314
11446
|
}
|
|
11315
|
-
const
|
|
11447
|
+
const servedRows = [];
|
|
11316
11448
|
let servedLines = 0;
|
|
11317
11449
|
for (const [path, lineNumbers] of lineNumbersByPath) {
|
|
11318
11450
|
const served = await serveFileLines(deps, {
|
|
@@ -11323,22 +11455,520 @@ async function planGrepView(deps, request) {
|
|
|
11323
11455
|
lineNumbers
|
|
11324
11456
|
});
|
|
11325
11457
|
if (served.length !== lineNumbers.length) return void 0;
|
|
11326
|
-
const rows = [];
|
|
11327
11458
|
for (let index = 0; index < lineNumbers.length; index += 1) {
|
|
11328
11459
|
const row = served[index];
|
|
11329
11460
|
if (row === void 0 || row.line !== lineNumbers[index]) return void 0;
|
|
11330
|
-
|
|
11461
|
+
servedRows.push({ path, lineNumber: row.line, hash: row.hash, text: row.text });
|
|
11331
11462
|
}
|
|
11332
|
-
servedLines +=
|
|
11333
|
-
servedGroups.push({ path, lineNumbers: [...lineNumbers], rows });
|
|
11463
|
+
servedLines += lineNumbers.length;
|
|
11334
11464
|
}
|
|
11335
|
-
return {
|
|
11465
|
+
return {
|
|
11466
|
+
text: grepRowsPage(servedRows),
|
|
11467
|
+
rows: servedRows,
|
|
11468
|
+
servedLines,
|
|
11469
|
+
paths: [...lineNumbersByPath.keys()]
|
|
11470
|
+
};
|
|
11336
11471
|
} catch (error) {
|
|
11337
11472
|
reportDiagnostic("grep-view", "Could not serve the grep view; passing through:", error);
|
|
11338
11473
|
return void 0;
|
|
11339
11474
|
}
|
|
11340
11475
|
}
|
|
11341
11476
|
|
|
11477
|
+
// dsh/rg/tools.ts
|
|
11478
|
+
import {
|
|
11479
|
+
defineTool as defineTool2
|
|
11480
|
+
} from "@deepseek-ai/dsh-tools";
|
|
11481
|
+
|
|
11482
|
+
// dsh/rg/command.ts
|
|
11483
|
+
import { isAbsolute as isAbsolute6, relative as relative2 } from "node:path";
|
|
11484
|
+
function validateInclude(include) {
|
|
11485
|
+
if (include.trim().length === 0) throw new Error("include must be a non-empty glob when given");
|
|
11486
|
+
if (include.startsWith("!"))
|
|
11487
|
+
throw new Error(
|
|
11488
|
+
'include must be a positive glob filter; negated patterns ("!\u2026") are not supported'
|
|
11489
|
+
);
|
|
11490
|
+
let braceDepth = 0;
|
|
11491
|
+
for (const character of include) {
|
|
11492
|
+
if (character === "{") braceDepth += 1;
|
|
11493
|
+
else if (character === "}") braceDepth = Math.max(0, braceDepth - 1);
|
|
11494
|
+
else if (character === "," && braceDepth === 0) {
|
|
11495
|
+
throw new Error(
|
|
11496
|
+
"include must be one glob, not a comma-separated list (use {a,b} alternation instead)"
|
|
11497
|
+
);
|
|
11498
|
+
}
|
|
11499
|
+
}
|
|
11500
|
+
}
|
|
11501
|
+
function booleanArg(record, key) {
|
|
11502
|
+
const value = record[key];
|
|
11503
|
+
if (value === void 0) return void 0;
|
|
11504
|
+
if (typeof value !== "boolean") throw new Error(`${key} must be a boolean when given`);
|
|
11505
|
+
return value;
|
|
11506
|
+
}
|
|
11507
|
+
function parseRgArgs(raw) {
|
|
11508
|
+
const record = typeof raw === "object" && raw !== null ? raw : {};
|
|
11509
|
+
const pattern = record.pattern;
|
|
11510
|
+
if (typeof pattern !== "string" || pattern.length === 0)
|
|
11511
|
+
throw new Error("pattern must be a non-empty string");
|
|
11512
|
+
const path = record.path;
|
|
11513
|
+
if (path !== void 0 && (typeof path !== "string" || path.trim().length === 0)) {
|
|
11514
|
+
throw new Error("path must be a non-empty string when given");
|
|
11515
|
+
}
|
|
11516
|
+
const rawInclude = record.include;
|
|
11517
|
+
if (rawInclude !== void 0 && typeof rawInclude !== "string")
|
|
11518
|
+
throw new Error("include must be a string when given");
|
|
11519
|
+
const include = rawInclude === "" ? void 0 : rawInclude;
|
|
11520
|
+
if (include !== void 0) validateInclude(include);
|
|
11521
|
+
return {
|
|
11522
|
+
pattern,
|
|
11523
|
+
...path === void 0 ? {} : { path },
|
|
11524
|
+
...include === void 0 ? {} : { include },
|
|
11525
|
+
...booleanArg(record, "ignoreCase") === true ? { ignoreCase: true } : {},
|
|
11526
|
+
...booleanArg(record, "fixedStrings") === true ? { fixedStrings: true } : {},
|
|
11527
|
+
...booleanArg(record, "wordMatch") === true ? { wordMatch: true } : {},
|
|
11528
|
+
...booleanArg(record, "hidden") === true ? { hidden: true } : {},
|
|
11529
|
+
...booleanArg(record, "noIgnore") === true ? { noIgnore: true } : {}
|
|
11530
|
+
};
|
|
11531
|
+
}
|
|
11532
|
+
function buildRgCommand(input) {
|
|
11533
|
+
const parts = ["--json", `--regexp=${input.pattern}`];
|
|
11534
|
+
if (input.include !== void 0) parts.push(`--glob=${input.include}`);
|
|
11535
|
+
if (input.ignoreCase === true) parts.push("--ignore-case");
|
|
11536
|
+
if (input.fixedStrings === true) parts.push("--fixed-strings");
|
|
11537
|
+
if (input.wordMatch === true) parts.push("--word-regexp");
|
|
11538
|
+
if (input.hidden === true) parts.push("--hidden");
|
|
11539
|
+
if (input.noIgnore === true) parts.push("--no-ignore");
|
|
11540
|
+
if (input.path !== void 0) parts.push("--", input.path);
|
|
11541
|
+
return parts;
|
|
11542
|
+
}
|
|
11543
|
+
function malformedRecord(detail) {
|
|
11544
|
+
return new Error(`rg received malformed --json output (${detail})`);
|
|
11545
|
+
}
|
|
11546
|
+
function parseRecord(line) {
|
|
11547
|
+
let parsed;
|
|
11548
|
+
try {
|
|
11549
|
+
parsed = JSON.parse(line);
|
|
11550
|
+
} catch {
|
|
11551
|
+
throw malformedRecord("a line is not JSON");
|
|
11552
|
+
}
|
|
11553
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
11554
|
+
throw malformedRecord("a record is not an object");
|
|
11555
|
+
const record = parsed;
|
|
11556
|
+
if (record.type !== "match") return void 0;
|
|
11557
|
+
if (typeof record.data !== "object" || record.data === null)
|
|
11558
|
+
throw malformedRecord("a match record has no data");
|
|
11559
|
+
const data = record.data;
|
|
11560
|
+
const pathText = typeof data.path === "object" && data.path !== null ? data.path.text : void 0;
|
|
11561
|
+
if (typeof pathText !== "string") throw malformedRecord("a match record has no path text");
|
|
11562
|
+
if (typeof data.line_number !== "number")
|
|
11563
|
+
throw malformedRecord("a match record has no line number");
|
|
11564
|
+
if (typeof data.lines !== "object" || data.lines === null)
|
|
11565
|
+
throw malformedRecord("a match record has no line content");
|
|
11566
|
+
const lines = data.lines;
|
|
11567
|
+
if (typeof lines.text === "string") {
|
|
11568
|
+
return { path: pathText, lineNumber: data.line_number, line: lines.text.replace(/\r?\n$/, "") };
|
|
11569
|
+
}
|
|
11570
|
+
if (typeof lines.bytes === "string") {
|
|
11571
|
+
return { path: pathText, lineNumber: data.line_number, line: "(line is not valid UTF-8)" };
|
|
11572
|
+
}
|
|
11573
|
+
throw malformedRecord("a match record has neither line text nor bytes");
|
|
11574
|
+
}
|
|
11575
|
+
function parseRgOutput(stdout) {
|
|
11576
|
+
const matches = [];
|
|
11577
|
+
for (const line of stdout.split("\n")) {
|
|
11578
|
+
if (line.length === 0) continue;
|
|
11579
|
+
const match = parseRecord(line);
|
|
11580
|
+
if (match !== void 0) matches.push(match);
|
|
11581
|
+
}
|
|
11582
|
+
return matches;
|
|
11583
|
+
}
|
|
11584
|
+
function displayPath(rawPath, cwd) {
|
|
11585
|
+
const stripped = rawPath.startsWith("./") ? rawPath.slice(2) : rawPath;
|
|
11586
|
+
if (!isAbsolute6(stripped)) return stripped;
|
|
11587
|
+
const relativePath2 = relative2(cwd, stripped);
|
|
11588
|
+
if (relativePath2 === "" || isAbsolute6(relativePath2) || relativePath2.startsWith(".."))
|
|
11589
|
+
return stripped;
|
|
11590
|
+
return relativePath2;
|
|
11591
|
+
}
|
|
11592
|
+
|
|
11593
|
+
// dsh/rg/cli.ts
|
|
11594
|
+
import { spawn } from "node:child_process";
|
|
11595
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
11596
|
+
import { join as join10 } from "node:path";
|
|
11597
|
+
var WINDOWS_RG_NAMES = ["rg.exe", "rg", "rg.cmd", "rg.bat"];
|
|
11598
|
+
var POSIX_RG_NAMES = ["rg"];
|
|
11599
|
+
function isCommandShim(entry) {
|
|
11600
|
+
const lower = entry.toLowerCase();
|
|
11601
|
+
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
11602
|
+
}
|
|
11603
|
+
function resolveRgInvocation(options = {}) {
|
|
11604
|
+
const platform = options.platform ?? process.platform;
|
|
11605
|
+
const exists = options.exists ?? existsSync5;
|
|
11606
|
+
const explicit = options.explicitPath?.trim() ?? "";
|
|
11607
|
+
if (explicit !== "") {
|
|
11608
|
+
if (!exists(explicit)) {
|
|
11609
|
+
return { ok: false, problem: `rgPath points at "${explicit}", which does not exist` };
|
|
11610
|
+
}
|
|
11611
|
+
if (isCommandShim(explicit)) {
|
|
11612
|
+
return {
|
|
11613
|
+
ok: false,
|
|
11614
|
+
problem: `rgPath "${explicit}" is a shell shim; point it at rg.exe instead`
|
|
11615
|
+
};
|
|
11616
|
+
}
|
|
11617
|
+
return { ok: true, invocation: { command: explicit, prefixArgs: [], source: explicit } };
|
|
11618
|
+
}
|
|
11619
|
+
const pathValue = options.pathValue ?? process.env.PATH ?? "";
|
|
11620
|
+
const separator = platform === "win32" ? ";" : ":";
|
|
11621
|
+
const names = platform === "win32" ? WINDOWS_RG_NAMES : POSIX_RG_NAMES;
|
|
11622
|
+
let shim;
|
|
11623
|
+
for (const directory of pathValue.split(separator)) {
|
|
11624
|
+
if (directory === "") continue;
|
|
11625
|
+
for (const name2 of names) {
|
|
11626
|
+
const entry = join10(directory, name2);
|
|
11627
|
+
if (!exists(entry)) continue;
|
|
11628
|
+
if (isCommandShim(entry)) {
|
|
11629
|
+
shim ??= entry;
|
|
11630
|
+
continue;
|
|
11631
|
+
}
|
|
11632
|
+
return { ok: true, invocation: { command: entry, prefixArgs: [], source: entry } };
|
|
11633
|
+
}
|
|
11634
|
+
}
|
|
11635
|
+
if (shim !== void 0) {
|
|
11636
|
+
return {
|
|
11637
|
+
ok: false,
|
|
11638
|
+
problem: `only a shell shim was found at "${shim}"; put the real rg.exe on PATH`
|
|
11639
|
+
};
|
|
11640
|
+
}
|
|
11641
|
+
return { ok: false, problem: "no rg executable was found on PATH" };
|
|
11642
|
+
}
|
|
11643
|
+
var RG_TIMEOUT_MS = 3e4;
|
|
11644
|
+
var MAX_CAPTURE_CHARS = 8e6;
|
|
11645
|
+
function runRg(invocation, args, options) {
|
|
11646
|
+
options.signal?.throwIfAborted();
|
|
11647
|
+
const timeoutMs = options.timeoutMs ?? RG_TIMEOUT_MS;
|
|
11648
|
+
const env = {
|
|
11649
|
+
...process.env,
|
|
11650
|
+
// WHY: the transport is machine-read JSON; a colour escape would corrupt a parsed line.
|
|
11651
|
+
NO_COLOR: "1",
|
|
11652
|
+
FORCE_COLOR: "0",
|
|
11653
|
+
...options.env
|
|
11654
|
+
};
|
|
11655
|
+
return new Promise((resolve6, reject) => {
|
|
11656
|
+
const child = spawn(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
11657
|
+
cwd: options.cwd,
|
|
11658
|
+
env,
|
|
11659
|
+
windowsHide: true,
|
|
11660
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
11661
|
+
});
|
|
11662
|
+
let stdout = "";
|
|
11663
|
+
let stderr = "";
|
|
11664
|
+
let timedOut = false;
|
|
11665
|
+
let overflow = false;
|
|
11666
|
+
let settled = false;
|
|
11667
|
+
const capture = (current, chunk) => {
|
|
11668
|
+
if (current.length >= MAX_CAPTURE_CHARS) {
|
|
11669
|
+
overflow = true;
|
|
11670
|
+
return current;
|
|
11671
|
+
}
|
|
11672
|
+
const next = current + chunk;
|
|
11673
|
+
if (next.length > MAX_CAPTURE_CHARS) {
|
|
11674
|
+
overflow = true;
|
|
11675
|
+
return next.slice(0, MAX_CAPTURE_CHARS);
|
|
11676
|
+
}
|
|
11677
|
+
return next;
|
|
11678
|
+
};
|
|
11679
|
+
const stop = () => {
|
|
11680
|
+
if (settled) return;
|
|
11681
|
+
settled = true;
|
|
11682
|
+
clearTimeout(timer);
|
|
11683
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
11684
|
+
};
|
|
11685
|
+
const onAbort = () => {
|
|
11686
|
+
child.kill();
|
|
11687
|
+
stop();
|
|
11688
|
+
reject(options.signal?.reason ?? new Error("grep run aborted"));
|
|
11689
|
+
};
|
|
11690
|
+
const timer = setTimeout(() => {
|
|
11691
|
+
timedOut = true;
|
|
11692
|
+
child.kill();
|
|
11693
|
+
}, timeoutMs);
|
|
11694
|
+
child.stdout?.setEncoding("utf8");
|
|
11695
|
+
child.stderr?.setEncoding("utf8");
|
|
11696
|
+
child.stdout?.on("data", (chunk) => {
|
|
11697
|
+
stdout = capture(stdout, chunk);
|
|
11698
|
+
});
|
|
11699
|
+
child.stderr?.on("data", (chunk) => {
|
|
11700
|
+
stderr = capture(stderr, chunk);
|
|
11701
|
+
});
|
|
11702
|
+
child.on("error", (error) => {
|
|
11703
|
+
stop();
|
|
11704
|
+
reject(error);
|
|
11705
|
+
});
|
|
11706
|
+
child.on("close", (code) => {
|
|
11707
|
+
if (settled) return;
|
|
11708
|
+
stop();
|
|
11709
|
+
resolve6({ stdout, stderr, code, timedOut, overflow });
|
|
11710
|
+
});
|
|
11711
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
11712
|
+
});
|
|
11713
|
+
}
|
|
11714
|
+
|
|
11715
|
+
// dsh/rg/view.ts
|
|
11716
|
+
var GREP_MAX_LINE_BYTES = 2e3;
|
|
11717
|
+
var GREP_META_MAX_BYTES = 65536;
|
|
11718
|
+
function matchNoun(count) {
|
|
11719
|
+
return count === 1 ? "match" : "matches";
|
|
11720
|
+
}
|
|
11721
|
+
function previewLine(line, maxBytes = GREP_MAX_LINE_BYTES) {
|
|
11722
|
+
if (Buffer.byteLength(line, "utf8") <= maxBytes) return line;
|
|
11723
|
+
let used = 0;
|
|
11724
|
+
let cut = "";
|
|
11725
|
+
for (const character of line) {
|
|
11726
|
+
const size = Buffer.byteLength(character, "utf8");
|
|
11727
|
+
if (used + size > maxBytes) break;
|
|
11728
|
+
used += size;
|
|
11729
|
+
cut += character;
|
|
11730
|
+
}
|
|
11731
|
+
return cut + "\u2026";
|
|
11732
|
+
}
|
|
11733
|
+
function retainMatches(matches, maxMatches = GREP_INLINE_MAX_MATCHES) {
|
|
11734
|
+
const items = matches.slice(0, maxMatches);
|
|
11735
|
+
return { items, seen: matches.length, truncated: matches.length > items.length };
|
|
11736
|
+
}
|
|
11737
|
+
function groupByFile(matches) {
|
|
11738
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
11739
|
+
for (const match of matches) {
|
|
11740
|
+
const entry = { lineNumber: match.lineNumber, line: previewLine(match.line) };
|
|
11741
|
+
const group = byFile.get(match.path);
|
|
11742
|
+
if (group !== void 0) group.push(entry);
|
|
11743
|
+
else byFile.set(match.path, [entry]);
|
|
11744
|
+
}
|
|
11745
|
+
return Array.from(byFile, ([path, fileMatches]) => ({ path, matches: fileMatches }));
|
|
11746
|
+
}
|
|
11747
|
+
function formatRgText(matches) {
|
|
11748
|
+
const retained = retainMatches(matches);
|
|
11749
|
+
if (retained.seen === 0) return "No matches found";
|
|
11750
|
+
const header = retained.truncated ? "Found " + retained.items.length + " of " + retained.seen + " matches" : "Found " + retained.seen + " " + matchNoun(retained.seen);
|
|
11751
|
+
const blocks = groupByFile(retained.items).map(
|
|
11752
|
+
(group) => [
|
|
11753
|
+
group.path,
|
|
11754
|
+
group.matches.map((match) => "Line " + match.lineNumber + ": " + match.line).join("\n")
|
|
11755
|
+
].join("\n")
|
|
11756
|
+
);
|
|
11757
|
+
const omitted = retained.seen - retained.items.length;
|
|
11758
|
+
const footer = omitted === 0 ? "" : "\n\n(" + omitted + " more " + matchNoun(omitted) + (omitted === 1 ? " was" : " were") + " not shown; narrow the pattern, path, or include.)";
|
|
11759
|
+
return header + "\n\n" + blocks.join("\n\n") + footer;
|
|
11760
|
+
}
|
|
11761
|
+
function metaBytes(meta) {
|
|
11762
|
+
return Buffer.byteLength(JSON.stringify(meta), "utf8");
|
|
11763
|
+
}
|
|
11764
|
+
function capMetaBytes(meta, maxMetaBytes) {
|
|
11765
|
+
if (metaBytes(meta) <= maxMetaBytes) return meta;
|
|
11766
|
+
const files = [...meta.files];
|
|
11767
|
+
while (files.length > 1 && metaBytes({ ...meta, files, truncated: true }) > maxMetaBytes)
|
|
11768
|
+
files.pop();
|
|
11769
|
+
return { ...meta, files, truncated: true };
|
|
11770
|
+
}
|
|
11771
|
+
function rgMeta(matches, failed = false) {
|
|
11772
|
+
const retained = retainMatches(matches);
|
|
11773
|
+
const meta = {
|
|
11774
|
+
shape: "matches",
|
|
11775
|
+
files: groupByFile(retained.items),
|
|
11776
|
+
truncated: retained.truncated,
|
|
11777
|
+
total: retained.seen,
|
|
11778
|
+
...failed ? { failed: true } : {}
|
|
11779
|
+
};
|
|
11780
|
+
return capMetaBytes(meta, GREP_META_MAX_BYTES);
|
|
11781
|
+
}
|
|
11782
|
+
function isFileMatches(value) {
|
|
11783
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
11784
|
+
const { path, matches } = value;
|
|
11785
|
+
if (typeof path !== "string" || !Array.isArray(matches)) return false;
|
|
11786
|
+
return matches.every((match) => {
|
|
11787
|
+
if (typeof match !== "object" || match === null || Array.isArray(match)) return false;
|
|
11788
|
+
const { lineNumber, line } = match;
|
|
11789
|
+
return typeof lineNumber === "number" && typeof line === "string";
|
|
11790
|
+
});
|
|
11791
|
+
}
|
|
11792
|
+
function searchViewFromMeta(meta) {
|
|
11793
|
+
if (typeof meta !== "object" || meta === null || Array.isArray(meta)) return void 0;
|
|
11794
|
+
const record = meta;
|
|
11795
|
+
if (record.shape !== "matches" || record.failed === true) return void 0;
|
|
11796
|
+
const { files, truncated, total } = record;
|
|
11797
|
+
if (!Array.isArray(files) || !files.every(isFileMatches)) return void 0;
|
|
11798
|
+
if (typeof truncated !== "boolean" || typeof total !== "number") return void 0;
|
|
11799
|
+
return { card: "search", shape: "matches", files, truncated, total };
|
|
11800
|
+
}
|
|
11801
|
+
|
|
11802
|
+
// dsh/rg/tools.ts
|
|
11803
|
+
var RG_TOOL_NAME2 = "rg";
|
|
11804
|
+
var CALL_TIMEOUT_MARGIN_MS = 5e3;
|
|
11805
|
+
var CAPTURE_BUDGET_MB = 8;
|
|
11806
|
+
var DESCRIPTION = [
|
|
11807
|
+
"Search file contents with a ripgrep regular expression, executed by the `rg` on PATH (ripgrep's own config and ignore rules apply). Returns matching lines with line numbers, grouped by file.",
|
|
11808
|
+
"This tool is `rg`: use it \u2014 not a shell `grep` or `rg` command \u2014 for file-content search. Matching defaults to ripgrep's smart case; `ignoreCase`, `fixedStrings` and `wordMatch` change how the pattern matches, and `hidden`/`noIgnore` widen which files are searched.",
|
|
11809
|
+
"When the `read` switch is on, every matched line is served and leased: a direct call returns the shared `HASH\u2502content` search page, and inside `run_code` each match carries its anchor in `hash`, so the following `edit` or `apply_patch` needs no separate `read`.",
|
|
11810
|
+
"Expected states \u2014 no `rg` on PATH, a rejected pattern, an unreadable target, the 30 s budget \u2014 come back as text guidance, not as an error."
|
|
11811
|
+
].join("\n\n");
|
|
11812
|
+
var PARAMETERS = {
|
|
11813
|
+
pattern: {
|
|
11814
|
+
type: "string",
|
|
11815
|
+
required: true,
|
|
11816
|
+
description: "Regular expression to search for (ripgrep syntax)."
|
|
11817
|
+
},
|
|
11818
|
+
path: {
|
|
11819
|
+
type: "string",
|
|
11820
|
+
description: "File or directory to search. Defaults to the session working directory; a relative path resolves against it."
|
|
11821
|
+
},
|
|
11822
|
+
include: {
|
|
11823
|
+
type: "string",
|
|
11824
|
+
description: 'One glob filter for which files to search (e.g. "*.ts", "*.{js,jsx}"). Not a list; negation is not supported.'
|
|
11825
|
+
},
|
|
11826
|
+
ignoreCase: {
|
|
11827
|
+
type: "boolean",
|
|
11828
|
+
description: "Search case-insensitively (`-i`). Default keeps ripgrep's smart case: insensitive only when the pattern has no uppercase letter."
|
|
11829
|
+
},
|
|
11830
|
+
fixedStrings: {
|
|
11831
|
+
type: "boolean",
|
|
11832
|
+
description: "Treat `pattern` as literal text (`-F`) instead of a regular expression."
|
|
11833
|
+
},
|
|
11834
|
+
wordMatch: {
|
|
11835
|
+
type: "boolean",
|
|
11836
|
+
description: "Only match whole words (`-w`)."
|
|
11837
|
+
},
|
|
11838
|
+
hidden: {
|
|
11839
|
+
type: "boolean",
|
|
11840
|
+
description: "Also search hidden files and directories (`--hidden`)."
|
|
11841
|
+
},
|
|
11842
|
+
noIgnore: {
|
|
11843
|
+
type: "boolean",
|
|
11844
|
+
description: "Ignore `.gitignore`/`.ignore` rules and search every file (`--no-ignore`)."
|
|
11845
|
+
}
|
|
11846
|
+
};
|
|
11847
|
+
var OUTCOME_SCHEMA = {
|
|
11848
|
+
type: "object",
|
|
11849
|
+
properties: {
|
|
11850
|
+
matches: {
|
|
11851
|
+
type: "array",
|
|
11852
|
+
required: true,
|
|
11853
|
+
items: {
|
|
11854
|
+
type: "object",
|
|
11855
|
+
additionalProperties: false,
|
|
11856
|
+
properties: {
|
|
11857
|
+
path: { type: "string", required: true },
|
|
11858
|
+
lineNumber: { type: "integer", required: true },
|
|
11859
|
+
line: { type: "string", required: true },
|
|
11860
|
+
hash: { type: "string" }
|
|
11861
|
+
}
|
|
11862
|
+
}
|
|
11863
|
+
},
|
|
11864
|
+
note: { type: "string" }
|
|
11865
|
+
},
|
|
11866
|
+
additionalProperties: false
|
|
11867
|
+
};
|
|
11868
|
+
function missingRgText(problem) {
|
|
11869
|
+
return "rg could not run: " + problem + ". Install ripgrep (https://github.com/BurntSushi/ripgrep) and put `rg` on PATH, or set this plugin's `rgPath` config to the executable.";
|
|
11870
|
+
}
|
|
11871
|
+
function tail(text, maxLines = 20) {
|
|
11872
|
+
const lines = text.trimEnd().split("\n");
|
|
11873
|
+
return lines.slice(Math.max(0, lines.length - maxLines)).join("\n");
|
|
11874
|
+
}
|
|
11875
|
+
function outcomeFor(run, cwd, timeoutMs) {
|
|
11876
|
+
if (run.timedOut) {
|
|
11877
|
+
return {
|
|
11878
|
+
matches: [],
|
|
11879
|
+
note: "rg stopped after " + timeoutMs + " ms without finishing. Narrow the pattern, path, or include."
|
|
11880
|
+
};
|
|
11881
|
+
}
|
|
11882
|
+
if (run.overflow) {
|
|
11883
|
+
return {
|
|
11884
|
+
matches: [],
|
|
11885
|
+
note: "rg produced more output than the " + CAPTURE_BUDGET_MB + " MB capture budget and was not parsed. Narrow the pattern, path, or include."
|
|
11886
|
+
};
|
|
11887
|
+
}
|
|
11888
|
+
if (run.code === 1) return { matches: [] };
|
|
11889
|
+
if (run.code !== 0) {
|
|
11890
|
+
const diagnostics = tail(run.stderr);
|
|
11891
|
+
const detail = diagnostics === "" ? " (no stderr output)" : "\n" + diagnostics;
|
|
11892
|
+
return { matches: [], note: "rg exited with code " + String(run.code) + ":" + detail };
|
|
11893
|
+
}
|
|
11894
|
+
return {
|
|
11895
|
+
matches: parseRgOutput(run.stdout).map((match) => ({
|
|
11896
|
+
...match,
|
|
11897
|
+
path: displayPath(match.path, cwd)
|
|
11898
|
+
}))
|
|
11899
|
+
};
|
|
11900
|
+
}
|
|
11901
|
+
function rgText(value) {
|
|
11902
|
+
if (value.note !== void 0) return value.note;
|
|
11903
|
+
const rows = anchoredRows(value.matches);
|
|
11904
|
+
return rows === void 0 ? formatRgText(value.matches) : grepRowsPage(rows);
|
|
11905
|
+
}
|
|
11906
|
+
function anchoredRows(matches) {
|
|
11907
|
+
if (matches.length === 0) return void 0;
|
|
11908
|
+
const rows = [];
|
|
11909
|
+
for (const match of matches) {
|
|
11910
|
+
if (match.hash === void 0) return void 0;
|
|
11911
|
+
rows.push({
|
|
11912
|
+
path: match.path,
|
|
11913
|
+
lineNumber: match.lineNumber,
|
|
11914
|
+
hash: match.hash,
|
|
11915
|
+
text: match.line
|
|
11916
|
+
});
|
|
11917
|
+
}
|
|
11918
|
+
return rows;
|
|
11919
|
+
}
|
|
11920
|
+
function presentCall(args) {
|
|
11921
|
+
const where = args.path !== void 0 ? " in " + args.path : "";
|
|
11922
|
+
const filter = args.include !== void 0 && args.include !== "" ? " (" + args.include + ")" : "";
|
|
11923
|
+
return {
|
|
11924
|
+
card: "generic",
|
|
11925
|
+
title: "Rg " + args.pattern + where + filter,
|
|
11926
|
+
kind: "search",
|
|
11927
|
+
rawInput: args.pattern
|
|
11928
|
+
};
|
|
11929
|
+
}
|
|
11930
|
+
function buildRgTool(options = {}) {
|
|
11931
|
+
const timeoutMs = options.timeoutMs ?? RG_TIMEOUT_MS;
|
|
11932
|
+
return defineTool2({
|
|
11933
|
+
name: RG_TOOL_NAME2,
|
|
11934
|
+
description: DESCRIPTION,
|
|
11935
|
+
parameters: PARAMETERS,
|
|
11936
|
+
// WHY: the spawn timer reports its own timeout as guidance, so the cooperative budget must
|
|
11937
|
+
// WHY: never preempt that message — it only backstops a run that never settles.
|
|
11938
|
+
timeoutMs: timeoutMs + CALL_TIMEOUT_MARGIN_MS,
|
|
11939
|
+
output: {
|
|
11940
|
+
schema: OUTCOME_SCHEMA,
|
|
11941
|
+
render: (_args, value) => [{ type: "text", text: rgText(value) }],
|
|
11942
|
+
presentationMeta: (_args, value) => rgMeta(value.matches, value.note !== void 0)
|
|
11943
|
+
},
|
|
11944
|
+
async execute(args, exec) {
|
|
11945
|
+
const input = parseRgArgs(args);
|
|
11946
|
+
const ctx = resolveToolContext(exec);
|
|
11947
|
+
const locate = options.resolveRg ?? (() => resolveRgInvocation());
|
|
11948
|
+
const resolution = locate();
|
|
11949
|
+
if (!resolution.ok) return { matches: [], note: missingRgText(resolution.problem) };
|
|
11950
|
+
const runner = options.run ?? runRg;
|
|
11951
|
+
let run;
|
|
11952
|
+
try {
|
|
11953
|
+
run = await runner(resolution.invocation, buildRgCommand(input), {
|
|
11954
|
+
cwd: ctx.cwd,
|
|
11955
|
+
signal: ctx.signal,
|
|
11956
|
+
timeoutMs
|
|
11957
|
+
});
|
|
11958
|
+
} catch (error) {
|
|
11959
|
+
ctx.signal?.throwIfAborted();
|
|
11960
|
+
return {
|
|
11961
|
+
matches: [],
|
|
11962
|
+
note: "rg could not start: " + (error instanceof Error ? error.message : String(error))
|
|
11963
|
+
};
|
|
11964
|
+
}
|
|
11965
|
+
return outcomeFor(run, ctx.cwd, timeoutMs);
|
|
11966
|
+
},
|
|
11967
|
+
presentCall,
|
|
11968
|
+
presentResult: (_args, result) => result.isError ? void 0 : searchViewFromMeta(result.meta)
|
|
11969
|
+
});
|
|
11970
|
+
}
|
|
11971
|
+
|
|
11342
11972
|
// dsh/shell-hook.ts
|
|
11343
11973
|
var SHELL_TOOL_NAMES = ["pwsh", "bash"];
|
|
11344
11974
|
function grepMatchesOf(value) {
|
|
@@ -11356,6 +11986,25 @@ function grepMatchesOf(value) {
|
|
|
11356
11986
|
}
|
|
11357
11987
|
return matches;
|
|
11358
11988
|
}
|
|
11989
|
+
function withAnchorHashes(value, rows) {
|
|
11990
|
+
const record = asRecord(value);
|
|
11991
|
+
const raw = record?.matches;
|
|
11992
|
+
if (record === void 0 || !Array.isArray(raw) || raw.length !== rows.length) return void 0;
|
|
11993
|
+
const hashOf = new Map(
|
|
11994
|
+
rows.map((row) => [`${row.path}\0${row.lineNumber}`, row.hash])
|
|
11995
|
+
);
|
|
11996
|
+
const matches = [];
|
|
11997
|
+
for (const item of raw) {
|
|
11998
|
+
const match = asRecord(item);
|
|
11999
|
+
if (match === void 0) return void 0;
|
|
12000
|
+
const { path, lineNumber } = match;
|
|
12001
|
+
if (typeof path !== "string" || typeof lineNumber !== "number") return void 0;
|
|
12002
|
+
const hash = hashOf.get(`${path}\0${lineNumber}`);
|
|
12003
|
+
if (hash === void 0) return void 0;
|
|
12004
|
+
matches.push({ ...match, hash });
|
|
12005
|
+
}
|
|
12006
|
+
return { ...record, matches };
|
|
12007
|
+
}
|
|
11359
12008
|
function errorMessage2(error) {
|
|
11360
12009
|
return error instanceof Error ? error.message : String(error);
|
|
11361
12010
|
}
|
|
@@ -11413,7 +12062,7 @@ function execContext(exec) {
|
|
|
11413
12062
|
async function grepPostExecute(deps, exec, result, decision, elapsed) {
|
|
11414
12063
|
if (result.isError || decision.kind !== "accept") return decision;
|
|
11415
12064
|
if (Object.hasOwn(decision, "content") || Object.hasOwn(decision, "value")) return decision;
|
|
11416
|
-
if (exec.parent !== void 0) return decision;
|
|
12065
|
+
if (exec.parent !== void 0 && exec.name !== RG_TOOL_NAME2) return decision;
|
|
11417
12066
|
const matches = grepMatchesOf(result.value);
|
|
11418
12067
|
if (matches === void 0 || matches.length === 0) return decision;
|
|
11419
12068
|
const { cwd, sessionKey } = execContext(exec);
|
|
@@ -11440,6 +12089,15 @@ async function grepPostExecute(deps, exec, result, decision, elapsed) {
|
|
|
11440
12089
|
servedLines: planned.servedLines,
|
|
11441
12090
|
...planned.paths.length === 1 && planned.paths[0] !== void 0 ? { path: planned.paths[0] } : {}
|
|
11442
12091
|
});
|
|
12092
|
+
if (exec.name === RG_TOOL_NAME2) {
|
|
12093
|
+
const anchored = withAnchorHashes(result.value, planned.rows);
|
|
12094
|
+
if (anchored === void 0) return decision;
|
|
12095
|
+
return {
|
|
12096
|
+
kind: "accept",
|
|
12097
|
+
value: anchored,
|
|
12098
|
+
...decision.additionalContexts === void 0 ? {} : { additionalContexts: decision.additionalContexts }
|
|
12099
|
+
};
|
|
12100
|
+
}
|
|
11443
12101
|
return {
|
|
11444
12102
|
kind: "accept",
|
|
11445
12103
|
content: [{ type: "text", text: planned.text }],
|
|
@@ -11451,7 +12109,7 @@ function createShellHooks(deps) {
|
|
|
11451
12109
|
async postExecute(exec, result, next) {
|
|
11452
12110
|
const elapsed = deps.metrics === void 0 ? void 0 : stopwatch();
|
|
11453
12111
|
const decision = await next();
|
|
11454
|
-
if (exec.name
|
|
12112
|
+
if (GREP_TOOL_NAMES.includes(exec.name))
|
|
11455
12113
|
return grepPostExecute(deps, exec, result, decision, elapsed);
|
|
11456
12114
|
if (!SHELL_TOOL_NAMES.includes(exec.name)) return decision;
|
|
11457
12115
|
if (result.isError || decision.kind !== "accept") return decision;
|
|
@@ -11528,7 +12186,7 @@ function registerShellHook(rootCtx, agentCtx, deps) {
|
|
|
11528
12186
|
}
|
|
11529
12187
|
|
|
11530
12188
|
// dsh/tools/apply-patch.ts
|
|
11531
|
-
import { defineTool as
|
|
12189
|
+
import { defineTool as defineTool3 } from "@deepseek-ai/dsh-tools";
|
|
11532
12190
|
|
|
11533
12191
|
// src/apply-patch/grammar.ts
|
|
11534
12192
|
var PATCH_MAX_BYTES = 512 * 1024;
|
|
@@ -12045,7 +12703,7 @@ var PatchParser = class {
|
|
|
12045
12703
|
|
|
12046
12704
|
// src/apply-patch/plan.ts
|
|
12047
12705
|
import { stat as stat3 } from "node:fs/promises";
|
|
12048
|
-
import { dirname as dirname9, isAbsolute as
|
|
12706
|
+
import { dirname as dirname9, isAbsolute as isAbsolute7, relative as relativePath, resolve as resolvePath2 } from "node:path";
|
|
12049
12707
|
|
|
12050
12708
|
// src/apply-patch/resolve.ts
|
|
12051
12709
|
function baselineLinesOf(baseline) {
|
|
@@ -12374,9 +13032,9 @@ function resolveRequestPath(path, cwd) {
|
|
|
12374
13032
|
return { ok: false, message: "path may not name a .git entry" };
|
|
12375
13033
|
}
|
|
12376
13034
|
const cwdAbsolute = resolvePath2(cwd);
|
|
12377
|
-
const absolutePath =
|
|
12378
|
-
const
|
|
12379
|
-
if (
|
|
13035
|
+
const absolutePath = isAbsolute7(path) ? resolvePath2(path) : resolvePath2(cwdAbsolute, path);
|
|
13036
|
+
const relative3 = relativePath(cwdAbsolute, absolutePath);
|
|
13037
|
+
if (relative3.startsWith("..") || isAbsolute7(relative3)) {
|
|
12380
13038
|
return { ok: false, message: "path must stay inside the workspace" };
|
|
12381
13039
|
}
|
|
12382
13040
|
return { ok: true, value: { path, absolutePath } };
|
|
@@ -15579,7 +16237,7 @@ function buildApplyPatchTool(deps, options = {}) {
|
|
|
15579
16237
|
tool ??= options.create?.() ?? createApplyPatchTool();
|
|
15580
16238
|
return tool;
|
|
15581
16239
|
};
|
|
15582
|
-
return
|
|
16240
|
+
return defineTool3({
|
|
15583
16241
|
name: APPLY_PATCH_TOOL_NAME,
|
|
15584
16242
|
description: APPLY_PATCH_DESCRIPTION,
|
|
15585
16243
|
parameters: { ...APPLY_PATCH_PARAMETERS, ...sandboxFields },
|
|
@@ -15724,7 +16382,7 @@ function changedLineCount(result) {
|
|
|
15724
16382
|
}
|
|
15725
16383
|
|
|
15726
16384
|
// dsh/tools/edit.ts
|
|
15727
|
-
import { defineTool as
|
|
16385
|
+
import { defineTool as defineTool4 } from "@deepseek-ai/dsh-tools";
|
|
15728
16386
|
|
|
15729
16387
|
// src/edit-tool.ts
|
|
15730
16388
|
import { constants as constants7 } from "node:fs";
|
|
@@ -16558,7 +17216,7 @@ function buildEditTool(deps, options = {}) {
|
|
|
16558
17216
|
options.spanProvider === void 0 ? {} : { spanProvider: options.spanProvider }
|
|
16559
17217
|
);
|
|
16560
17218
|
const sandboxFields = deps.sandbox.escalationModes.length > 0 ? deps.sandbox.schemaFields() : {};
|
|
16561
|
-
return
|
|
17219
|
+
return defineTool4({
|
|
16562
17220
|
name: EDIT_TOOL_NAME,
|
|
16563
17221
|
description: EDIT_TOOL_DESCRIPTION,
|
|
16564
17222
|
parameters: { ...EDIT_PARAMETERS, ...sandboxFields },
|
|
@@ -16679,10 +17337,10 @@ function admit2(args) {
|
|
|
16679
17337
|
}
|
|
16680
17338
|
|
|
16681
17339
|
// dsh/codegraph/cli.ts
|
|
16682
|
-
import { spawn } from "node:child_process";
|
|
16683
|
-
import { existsSync as
|
|
16684
|
-
import { dirname as dirname10, extname, join as
|
|
16685
|
-
var PACKAGE_SCRIPT =
|
|
17340
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
17341
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
17342
|
+
import { dirname as dirname10, extname, join as join11 } from "node:path";
|
|
17343
|
+
var PACKAGE_SCRIPT = join11(
|
|
16686
17344
|
"node_modules",
|
|
16687
17345
|
"@colbymchenry",
|
|
16688
17346
|
"codegraph",
|
|
@@ -16690,7 +17348,7 @@ var PACKAGE_SCRIPT = join10(
|
|
|
16690
17348
|
"bin",
|
|
16691
17349
|
"codegraph.js"
|
|
16692
17350
|
);
|
|
16693
|
-
var BUNDLED_SCRIPT =
|
|
17351
|
+
var BUNDLED_SCRIPT = join11("lib", "dist", "bin", "codegraph.js");
|
|
16694
17352
|
var WINDOWS_SHIM_NAMES = [
|
|
16695
17353
|
"codegraph.cmd",
|
|
16696
17354
|
"codegraph.exe",
|
|
@@ -16702,22 +17360,22 @@ function isScript(entry) {
|
|
|
16702
17360
|
const ext = extname(entry).toLowerCase();
|
|
16703
17361
|
return ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
16704
17362
|
}
|
|
16705
|
-
function
|
|
17363
|
+
function isCommandShim2(entry) {
|
|
16706
17364
|
const lower = entry.toLowerCase();
|
|
16707
17365
|
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
16708
17366
|
}
|
|
16709
17367
|
function invocationOf(entry, platform, exists) {
|
|
16710
17368
|
if (isScript(entry)) return { command: process.execPath, prefixArgs: [entry], source: entry };
|
|
16711
|
-
if (!
|
|
17369
|
+
if (!isCommandShim2(entry)) {
|
|
16712
17370
|
if (platform === "win32" && !entry.toLowerCase().endsWith(".exe")) return void 0;
|
|
16713
17371
|
return { command: entry, prefixArgs: [], source: entry };
|
|
16714
17372
|
}
|
|
16715
17373
|
const binDir = dirname10(entry);
|
|
16716
17374
|
const installRoot = dirname10(binDir);
|
|
16717
17375
|
const candidates = [
|
|
16718
|
-
{ command:
|
|
16719
|
-
{ command: process.execPath, script:
|
|
16720
|
-
{ command: process.execPath, script:
|
|
17376
|
+
{ command: join11(installRoot, "node.exe"), script: join11(installRoot, BUNDLED_SCRIPT) },
|
|
17377
|
+
{ command: process.execPath, script: join11(binDir, PACKAGE_SCRIPT) },
|
|
17378
|
+
{ command: process.execPath, script: join11(installRoot, PACKAGE_SCRIPT) }
|
|
16721
17379
|
];
|
|
16722
17380
|
for (const candidate of candidates) {
|
|
16723
17381
|
if (!exists(candidate.script)) continue;
|
|
@@ -16728,7 +17386,7 @@ function invocationOf(entry, platform, exists) {
|
|
|
16728
17386
|
}
|
|
16729
17387
|
function resolveCodegraphInvocation(options = {}) {
|
|
16730
17388
|
const platform = options.platform ?? process.platform;
|
|
16731
|
-
const exists = options.exists ??
|
|
17389
|
+
const exists = options.exists ?? existsSync6;
|
|
16732
17390
|
const explicit = options.explicitPath?.trim() ?? "";
|
|
16733
17391
|
if (explicit !== "") {
|
|
16734
17392
|
if (!exists(explicit)) {
|
|
@@ -16749,7 +17407,7 @@ function resolveCodegraphInvocation(options = {}) {
|
|
|
16749
17407
|
for (const directory of pathValue.split(separator)) {
|
|
16750
17408
|
if (directory === "") continue;
|
|
16751
17409
|
for (const name2 of names) {
|
|
16752
|
-
const entry =
|
|
17410
|
+
const entry = join11(directory, name2);
|
|
16753
17411
|
if (!exists(entry)) continue;
|
|
16754
17412
|
const invocation = invocationOf(entry, platform, exists);
|
|
16755
17413
|
if (invocation !== void 0) return { ok: true, invocation };
|
|
@@ -16758,7 +17416,7 @@ function resolveCodegraphInvocation(options = {}) {
|
|
|
16758
17416
|
return { ok: false, problem: "no codegraph executable was found on PATH" };
|
|
16759
17417
|
}
|
|
16760
17418
|
var CODEGRAPH_TIMEOUT_MS = 12e4;
|
|
16761
|
-
var
|
|
17419
|
+
var MAX_CAPTURE_CHARS2 = 2e6;
|
|
16762
17420
|
function runCodegraph(invocation, args, options) {
|
|
16763
17421
|
options.signal?.throwIfAborted();
|
|
16764
17422
|
const timeoutMs = options.timeoutMs ?? CODEGRAPH_TIMEOUT_MS;
|
|
@@ -16770,7 +17428,7 @@ function runCodegraph(invocation, args, options) {
|
|
|
16770
17428
|
...options.env
|
|
16771
17429
|
};
|
|
16772
17430
|
return new Promise((resolve6, reject) => {
|
|
16773
|
-
const child =
|
|
17431
|
+
const child = spawn2(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
16774
17432
|
cwd: options.cwd,
|
|
16775
17433
|
env,
|
|
16776
17434
|
windowsHide: true,
|
|
@@ -16780,7 +17438,7 @@ function runCodegraph(invocation, args, options) {
|
|
|
16780
17438
|
let stderr = "";
|
|
16781
17439
|
let timedOut = false;
|
|
16782
17440
|
let settled = false;
|
|
16783
|
-
const capture = (current, chunk) => current.length >=
|
|
17441
|
+
const capture = (current, chunk) => current.length >= MAX_CAPTURE_CHARS2 ? current : (current + chunk).slice(0, MAX_CAPTURE_CHARS2);
|
|
16784
17442
|
const stop = () => {
|
|
16785
17443
|
if (settled) return;
|
|
16786
17444
|
settled = true;
|
|
@@ -16819,11 +17477,11 @@ function runCodegraph(invocation, args, options) {
|
|
|
16819
17477
|
|
|
16820
17478
|
// dsh/codegraph/tools.ts
|
|
16821
17479
|
import {
|
|
16822
|
-
defineTool as
|
|
17480
|
+
defineTool as defineTool5
|
|
16823
17481
|
} from "@deepseek-ai/dsh-tools";
|
|
16824
17482
|
|
|
16825
17483
|
// dsh/codegraph/project.ts
|
|
16826
|
-
import { dirname as dirname11, join as
|
|
17484
|
+
import { dirname as dirname11, join as join12 } from "node:path";
|
|
16827
17485
|
var CODEGRAPH_DIR = ".codegraph";
|
|
16828
17486
|
var REPOSITORY_MARKER = ".git";
|
|
16829
17487
|
async function resolveProjectPath(io, request) {
|
|
@@ -16832,8 +17490,8 @@ async function resolveProjectPath(io, request) {
|
|
|
16832
17490
|
let distance = 0;
|
|
16833
17491
|
for (; ; ) {
|
|
16834
17492
|
request.signal?.throwIfAborted();
|
|
16835
|
-
const index = await io.stat(
|
|
16836
|
-
const repository = await io.stat(
|
|
17493
|
+
const index = await io.stat(join12(directory, CODEGRAPH_DIR), request.signal);
|
|
17494
|
+
const repository = await io.stat(join12(directory, REPOSITORY_MARKER), request.signal);
|
|
16837
17495
|
const isRepository = repository !== void 0;
|
|
16838
17496
|
if (index?.isDirectory === true && (distance === 0 || isRepository)) {
|
|
16839
17497
|
return { ok: true, projectPath: directory, distance };
|
|
@@ -17012,7 +17670,7 @@ async function anchorCodegraphView(deps, request) {
|
|
|
17012
17670
|
}
|
|
17013
17671
|
|
|
17014
17672
|
// dsh/codegraph/tools.ts
|
|
17015
|
-
var
|
|
17673
|
+
var OUTCOME_SCHEMA2 = {
|
|
17016
17674
|
type: "object",
|
|
17017
17675
|
properties: {
|
|
17018
17676
|
text: { type: "string", required: true },
|
|
@@ -17032,7 +17690,7 @@ function numberArg(args, key) {
|
|
|
17032
17690
|
const value = args[key];
|
|
17033
17691
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
17034
17692
|
}
|
|
17035
|
-
function
|
|
17693
|
+
function booleanArg2(args, key) {
|
|
17036
17694
|
return args[key] === true;
|
|
17037
17695
|
}
|
|
17038
17696
|
function pushValue(argv, flag, value) {
|
|
@@ -17174,7 +17832,7 @@ var QUERIES = [
|
|
|
17174
17832
|
if (file !== void 0) argv.push("-f", file);
|
|
17175
17833
|
pushValue(argv, "--offset", numberArg(args, "offset"));
|
|
17176
17834
|
pushValue(argv, "--limit", numberArg(args, "limit"));
|
|
17177
|
-
if (
|
|
17835
|
+
if (booleanArg2(args, "symbolsOnly")) argv.push("--symbols-only");
|
|
17178
17836
|
return { args: argv };
|
|
17179
17837
|
}
|
|
17180
17838
|
},
|
|
@@ -17196,7 +17854,7 @@ var QUERIES = [
|
|
|
17196
17854
|
command: (args) => {
|
|
17197
17855
|
const argv = ["context", stringArg(args, "task") ?? ""];
|
|
17198
17856
|
pushValue(argv, "-n", numberArg(args, "maxNodes"));
|
|
17199
|
-
if (
|
|
17857
|
+
if (booleanArg2(args, "noCode")) argv.push("--no-code");
|
|
17200
17858
|
return { args: argv };
|
|
17201
17859
|
}
|
|
17202
17860
|
},
|
|
@@ -17338,12 +17996,12 @@ var QUERIES = [
|
|
|
17338
17996
|
}
|
|
17339
17997
|
];
|
|
17340
17998
|
function buildTool(deps, options, query) {
|
|
17341
|
-
return
|
|
17999
|
+
return defineTool5({
|
|
17342
18000
|
name: query.name,
|
|
17343
18001
|
description: query.description,
|
|
17344
18002
|
parameters: query.parameters,
|
|
17345
18003
|
output: {
|
|
17346
|
-
schema:
|
|
18004
|
+
schema: OUTCOME_SCHEMA2,
|
|
17347
18005
|
render: (_args, value) => [{ type: "text", text: value.text }]
|
|
17348
18006
|
},
|
|
17349
18007
|
async execute(args, exec) {
|
|
@@ -17357,17 +18015,17 @@ function buildCodegraphTools(deps, options) {
|
|
|
17357
18015
|
}
|
|
17358
18016
|
|
|
17359
18017
|
// dsh/diagnostics/tools.ts
|
|
17360
|
-
import { dirname as dirname14, join as
|
|
18018
|
+
import { dirname as dirname14, join as join14 } from "node:path";
|
|
17361
18019
|
import {
|
|
17362
|
-
defineTool as
|
|
18020
|
+
defineTool as defineTool6
|
|
17363
18021
|
} from "@deepseek-ai/dsh-tools";
|
|
17364
18022
|
|
|
17365
18023
|
// dsh/diagnostics/cli.ts
|
|
17366
|
-
import { spawn as
|
|
17367
|
-
import { existsSync as
|
|
17368
|
-
import { dirname as dirname12, extname as extname2, join as
|
|
18024
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
18025
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
18026
|
+
import { dirname as dirname12, extname as extname2, join as join13 } from "node:path";
|
|
17369
18027
|
var DIAGNOSTICS_TOOL_NAMES = ["cargo-check", "cargo-clippy", "tsc"];
|
|
17370
|
-
var TSC_SCRIPT =
|
|
18028
|
+
var TSC_SCRIPT = join13("node_modules", "typescript", "bin", "tsc");
|
|
17371
18029
|
var WINDOWS_CARGO_NAMES = ["cargo.exe", "cargo.cmd", "cargo.bat", "cargo"];
|
|
17372
18030
|
var POSIX_CARGO_NAMES = ["cargo"];
|
|
17373
18031
|
var WINDOWS_TSC_NAMES = ["tsc.cmd", "tsc.exe", "tsc.bat", "tsc"];
|
|
@@ -17387,7 +18045,7 @@ function isScript2(entry) {
|
|
|
17387
18045
|
const ext = extname2(entry).toLowerCase();
|
|
17388
18046
|
return ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
17389
18047
|
}
|
|
17390
|
-
function
|
|
18048
|
+
function isCommandShim3(entry) {
|
|
17391
18049
|
const lower = entry.toLowerCase();
|
|
17392
18050
|
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
17393
18051
|
}
|
|
@@ -17397,7 +18055,7 @@ function pathDirectories(pathValue, platform) {
|
|
|
17397
18055
|
}
|
|
17398
18056
|
function runnableEntry(entry, platform) {
|
|
17399
18057
|
if (isScript2(entry)) return { command: process.execPath, prefixArgs: [entry], source: entry };
|
|
17400
|
-
if (
|
|
18058
|
+
if (isCommandShim3(entry)) return void 0;
|
|
17401
18059
|
const ext = extname2(entry).toLowerCase();
|
|
17402
18060
|
if (ext === "" && platform === "win32") return void 0;
|
|
17403
18061
|
return { command: entry, prefixArgs: [], source: entry };
|
|
@@ -17414,15 +18072,15 @@ function findUpward(start, candidate, exists) {
|
|
|
17414
18072
|
}
|
|
17415
18073
|
function resolveCargoInvocation(options = {}) {
|
|
17416
18074
|
const platform = options.platform ?? process.platform;
|
|
17417
|
-
const exists = options.exists ??
|
|
18075
|
+
const exists = options.exists ?? existsSync7;
|
|
17418
18076
|
const names = platform === "win32" ? WINDOWS_CARGO_NAMES : POSIX_CARGO_NAMES;
|
|
17419
18077
|
let shim;
|
|
17420
18078
|
for (const directory of pathDirectories(options.pathValue ?? process.env.PATH ?? "", platform)) {
|
|
17421
18079
|
for (const name2 of names) {
|
|
17422
|
-
const entry =
|
|
18080
|
+
const entry = join13(directory, name2);
|
|
17423
18081
|
if (!exists(entry)) continue;
|
|
17424
|
-
if (
|
|
17425
|
-
const sibling =
|
|
18082
|
+
if (isCommandShim3(entry)) {
|
|
18083
|
+
const sibling = join13(directory, "cargo.exe");
|
|
17426
18084
|
if (!exists(sibling)) {
|
|
17427
18085
|
shim ??= entry;
|
|
17428
18086
|
continue;
|
|
@@ -17443,8 +18101,8 @@ function resolveCargoInvocation(options = {}) {
|
|
|
17443
18101
|
}
|
|
17444
18102
|
function resolveTscInvocation(cwd, options = {}) {
|
|
17445
18103
|
const platform = options.platform ?? process.platform;
|
|
17446
|
-
const exists = options.exists ??
|
|
17447
|
-
const local = findUpward(cwd, (directory) =>
|
|
18104
|
+
const exists = options.exists ?? existsSync7;
|
|
18105
|
+
const local = findUpward(cwd, (directory) => join13(directory, TSC_SCRIPT), exists);
|
|
17448
18106
|
if (local !== void 0) {
|
|
17449
18107
|
return {
|
|
17450
18108
|
ok: true,
|
|
@@ -17455,12 +18113,12 @@ function resolveTscInvocation(cwd, options = {}) {
|
|
|
17455
18113
|
let shim;
|
|
17456
18114
|
for (const directory of pathDirectories(options.pathValue ?? process.env.PATH ?? "", platform)) {
|
|
17457
18115
|
for (const name2 of names) {
|
|
17458
|
-
const entry =
|
|
18116
|
+
const entry = join13(directory, name2);
|
|
17459
18117
|
if (!exists(entry)) continue;
|
|
17460
|
-
if (
|
|
18118
|
+
if (isCommandShim3(entry)) {
|
|
17461
18119
|
const binDir = dirname12(entry);
|
|
17462
18120
|
for (const root of [binDir, dirname12(binDir)]) {
|
|
17463
|
-
const script =
|
|
18121
|
+
const script = join13(root, TSC_SCRIPT);
|
|
17464
18122
|
if (!exists(script)) continue;
|
|
17465
18123
|
return {
|
|
17466
18124
|
ok: true,
|
|
@@ -17486,7 +18144,7 @@ function resolveTscInvocation(cwd, options = {}) {
|
|
|
17486
18144
|
};
|
|
17487
18145
|
}
|
|
17488
18146
|
var DIAGNOSTICS_TIMEOUT_MS = 12e4;
|
|
17489
|
-
var
|
|
18147
|
+
var MAX_CAPTURE_CHARS3 = 2e6;
|
|
17490
18148
|
function runDiagnosticsCommand(invocation, args, options) {
|
|
17491
18149
|
options.signal?.throwIfAborted();
|
|
17492
18150
|
const timeoutMs = options.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS;
|
|
@@ -17500,7 +18158,7 @@ function runDiagnosticsCommand(invocation, args, options) {
|
|
|
17500
18158
|
...options.env
|
|
17501
18159
|
};
|
|
17502
18160
|
return new Promise((resolve6, reject) => {
|
|
17503
|
-
const child =
|
|
18161
|
+
const child = spawn3(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
17504
18162
|
cwd: options.cwd,
|
|
17505
18163
|
env,
|
|
17506
18164
|
windowsHide: true,
|
|
@@ -17510,7 +18168,7 @@ function runDiagnosticsCommand(invocation, args, options) {
|
|
|
17510
18168
|
let stderr = "";
|
|
17511
18169
|
let timedOut = false;
|
|
17512
18170
|
let settled = false;
|
|
17513
|
-
const capture = (current, chunk) => current.length >=
|
|
18171
|
+
const capture = (current, chunk) => current.length >= MAX_CAPTURE_CHARS3 ? current : (current + chunk).slice(0, MAX_CAPTURE_CHARS3);
|
|
17514
18172
|
const stop = () => {
|
|
17515
18173
|
if (settled) return;
|
|
17516
18174
|
settled = true;
|
|
@@ -17723,7 +18381,7 @@ function parseDiagnostics(tool, stdout) {
|
|
|
17723
18381
|
}
|
|
17724
18382
|
|
|
17725
18383
|
// dsh/diagnostics/view.ts
|
|
17726
|
-
import { dirname as dirname13, isAbsolute as
|
|
18384
|
+
import { dirname as dirname13, isAbsolute as isAbsolute8 } from "node:path";
|
|
17727
18385
|
function headerOf(diagnostic) {
|
|
17728
18386
|
const code = diagnostic.code === void 0 ? "" : `[${diagnostic.code}]`;
|
|
17729
18387
|
return `${diagnostic.level}${code} ${diagnostic.message} \u2014 ${diagnostic.file}:${diagnostic.line}:${diagnostic.column}`;
|
|
@@ -17746,7 +18404,7 @@ function resolveOnce(state, printed) {
|
|
|
17746
18404
|
const cached = state.resolved.get(printed);
|
|
17747
18405
|
if (cached !== void 0) return cached;
|
|
17748
18406
|
const pending = (async () => {
|
|
17749
|
-
if (
|
|
18407
|
+
if (isAbsolute8(printed)) return await statOnce(state, printed) ? printed : void 0;
|
|
17750
18408
|
let directory = state.cwd;
|
|
17751
18409
|
for (; ; ) {
|
|
17752
18410
|
state.signal?.throwIfAborted();
|
|
@@ -17857,7 +18515,7 @@ var MAX_CONTEXT_LINES = 10;
|
|
|
17857
18515
|
var MIN_MAX_DIAGNOSTICS = 1;
|
|
17858
18516
|
var MAX_MAX_DIAGNOSTICS = 100;
|
|
17859
18517
|
var TSCONFIG_NAMES = ["tsconfig.json", "jsconfig.json"];
|
|
17860
|
-
var
|
|
18518
|
+
var OUTCOME_SCHEMA3 = {
|
|
17861
18519
|
type: "object",
|
|
17862
18520
|
properties: {
|
|
17863
18521
|
text: { type: "string", required: true }
|
|
@@ -17865,12 +18523,12 @@ var OUTCOME_SCHEMA2 = {
|
|
|
17865
18523
|
additionalProperties: false
|
|
17866
18524
|
};
|
|
17867
18525
|
var SOURCE_NOTE2 = "Every diagnostic's file is served as `HASH\u2502content` rows around the reported line, so the following `apply_patch` or `edit` needs no separate `read`.";
|
|
17868
|
-
var
|
|
18526
|
+
var DESCRIPTION2 = [
|
|
17869
18527
|
"Run a compiler or linter over a project and return its errors and warnings as anchored, editable rows.",
|
|
17870
18528
|
"Supported `tool` values: `cargo-check`, `cargo-clippy` (the Rust `cargo` CLI) and `tsc` (the project's `node_modules/typescript`, else a `tsc` on PATH). " + SOURCE_NOTE2 + " The `\u2014 path:line:col` header above each block names the line its diagnostic points at, and the rows themselves stay byte-identical to a `read` page.",
|
|
17871
18529
|
"Expected states \u2014 no toolchain, no tsconfig, a timeout, output that carries no parseable diagnostic \u2014 come back as text guidance, not as an error."
|
|
17872
18530
|
].join("\n\n");
|
|
17873
|
-
var
|
|
18531
|
+
var PARAMETERS2 = {
|
|
17874
18532
|
tool: {
|
|
17875
18533
|
type: "string",
|
|
17876
18534
|
required: true,
|
|
@@ -17905,7 +18563,7 @@ async function hasProjectConfig(deps, cwd, signal) {
|
|
|
17905
18563
|
let directory = cwd;
|
|
17906
18564
|
for (; ; ) {
|
|
17907
18565
|
for (const name2 of TSCONFIG_NAMES) {
|
|
17908
|
-
const info = await deps.io.stat(
|
|
18566
|
+
const info = await deps.io.stat(join14(directory, name2), signal).catch(() => void 0);
|
|
17909
18567
|
if (info?.isFile === true) return true;
|
|
17910
18568
|
}
|
|
17911
18569
|
const parent = dirname14(directory);
|
|
@@ -17987,12 +18645,12 @@ async function executeDiagnostics(deps, options, exec, rawArgs) {
|
|
|
17987
18645
|
return composeText(tool, cwd, parsed, selected.length, view.blocks, view.skipped);
|
|
17988
18646
|
}
|
|
17989
18647
|
function buildDiagnosticsTool(deps, options) {
|
|
17990
|
-
return
|
|
18648
|
+
return defineTool6({
|
|
17991
18649
|
name: DIAGNOSTICS_TOOL_NAME,
|
|
17992
|
-
description:
|
|
17993
|
-
parameters:
|
|
18650
|
+
description: DESCRIPTION2,
|
|
18651
|
+
parameters: PARAMETERS2,
|
|
17994
18652
|
output: {
|
|
17995
|
-
schema:
|
|
18653
|
+
schema: OUTCOME_SCHEMA3,
|
|
17996
18654
|
render: (_args, value) => [{ type: "text", text: value.text }]
|
|
17997
18655
|
},
|
|
17998
18656
|
async execute(args, exec) {
|
|
@@ -18072,6 +18730,7 @@ function createWriteHooks(deps) {
|
|
|
18072
18730
|
const decision = await next();
|
|
18073
18731
|
if (exec.name !== "write" || result.isError || decision.kind !== "accept") return decision;
|
|
18074
18732
|
if ("value" in decision) return decision;
|
|
18733
|
+
if (deps.autoReadEnabled !== true) return decision;
|
|
18075
18734
|
const request = writeRequest(exec);
|
|
18076
18735
|
if (request === void 0) return decision;
|
|
18077
18736
|
const { cwd, sessionKey } = execContext2(exec);
|
|
@@ -18140,7 +18799,7 @@ async function defaultAutoRead(io, rawPath, cwd, sessionKey, signal) {
|
|
|
18140
18799
|
clearServedRefusals(sessionKey, prepared.absolutePath);
|
|
18141
18800
|
return prepared.preview;
|
|
18142
18801
|
}
|
|
18143
|
-
function defaultWriteHookDeps(warn3, io, observations) {
|
|
18802
|
+
function defaultWriteHookDeps(warn3, io, observations, options = {}) {
|
|
18144
18803
|
return {
|
|
18145
18804
|
async resolvePath(rawPath, cwd, signal) {
|
|
18146
18805
|
signal?.throwIfAborted();
|
|
@@ -18162,6 +18821,7 @@ function defaultWriteHookDeps(warn3, io, observations) {
|
|
|
18162
18821
|
return defaultAutoRead(io, rawPath, cwd, sessionKey, signal);
|
|
18163
18822
|
},
|
|
18164
18823
|
...observations === void 0 ? {} : { observations },
|
|
18824
|
+
...options.autoReadEnabled === true ? { autoReadEnabled: true } : {},
|
|
18165
18825
|
warn: warn3
|
|
18166
18826
|
};
|
|
18167
18827
|
}
|
|
@@ -18169,9 +18829,9 @@ function warnVia2(rootCtx, message) {
|
|
|
18169
18829
|
const logger = rootCtx.logger;
|
|
18170
18830
|
if (typeof logger?.warn === "function") logger.warn(`dsh-hashline-edit: ${message}`);
|
|
18171
18831
|
}
|
|
18172
|
-
function registerWriteHook(rootCtx, agentCtx, io, observations) {
|
|
18832
|
+
function registerWriteHook(rootCtx, agentCtx, io, observations, options = {}) {
|
|
18173
18833
|
const hooks = createWriteHooks(
|
|
18174
|
-
defaultWriteHookDeps((message) => warnVia2(rootCtx, message), io, observations)
|
|
18834
|
+
defaultWriteHookDeps((message) => warnVia2(rootCtx, message), io, observations, options)
|
|
18175
18835
|
);
|
|
18176
18836
|
const disposeGuard = agentCtx.on(
|
|
18177
18837
|
"tools/pre-execute",
|
|
@@ -18196,7 +18856,10 @@ var Config = Schema.object({
|
|
|
18196
18856
|
edit: Schema.boolean().default(false).volatile(),
|
|
18197
18857
|
codegraph: Schema.boolean().default(false).volatile(),
|
|
18198
18858
|
codegraphPath: Schema.string().default("").volatile(),
|
|
18199
|
-
diagnostics: Schema.boolean().default(false).volatile()
|
|
18859
|
+
diagnostics: Schema.boolean().default(false).volatile(),
|
|
18860
|
+
rg: Schema.boolean().default(true).volatile(),
|
|
18861
|
+
rgPath: Schema.string().default("").volatile(),
|
|
18862
|
+
writeAutoRead: Schema.boolean().default(false).volatile()
|
|
18200
18863
|
});
|
|
18201
18864
|
function switchValue(value, fallback) {
|
|
18202
18865
|
if (typeof value === "boolean") return value;
|
|
@@ -18230,7 +18893,10 @@ function resolveSwitches(config = {}) {
|
|
|
18230
18893
|
edit: switchValue(fields.edit, false),
|
|
18231
18894
|
codegraph: switchValue(fields.codegraph, false),
|
|
18232
18895
|
codegraphPath: stringValue(fields.codegraphPath, ""),
|
|
18233
|
-
diagnostics: switchValue(fields.diagnostics, false)
|
|
18896
|
+
diagnostics: switchValue(fields.diagnostics, false),
|
|
18897
|
+
rg: switchValue(fields.rg, true),
|
|
18898
|
+
rgPath: stringValue(fields.rgPath, ""),
|
|
18899
|
+
writeAutoRead: switchValue(fields.writeAutoRead, false)
|
|
18234
18900
|
};
|
|
18235
18901
|
}
|
|
18236
18902
|
function toolsOfAgent(agent) {
|
|
@@ -18302,21 +18968,37 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
|
18302
18968
|
if (dispose !== void 0) disposers.push(dispose);
|
|
18303
18969
|
}
|
|
18304
18970
|
}
|
|
18305
|
-
if (
|
|
18971
|
+
if (switches.rg) {
|
|
18972
|
+
const rg = buildRgTool({
|
|
18973
|
+
resolveRg: () => resolveRgInvocation({ explicitPath: switches.rgPath })
|
|
18974
|
+
});
|
|
18975
|
+
const dispose = registerToolQuietly(rootCtx, agent, rg, "rg");
|
|
18976
|
+
if (dispose !== void 0) disposers.push(dispose);
|
|
18977
|
+
}
|
|
18978
|
+
if (registered.length > 0 || switches.rg) {
|
|
18306
18979
|
disposers.push(
|
|
18307
18980
|
registerNativeToolHiding(rootCtx, agent.ctx, {
|
|
18308
18981
|
toolNames: registered,
|
|
18309
|
-
// WHY:
|
|
18310
|
-
// WHY:
|
|
18311
|
-
|
|
18312
|
-
|
|
18982
|
+
// WHY: the `rg` lane replaces the native search tool under a different name, which
|
|
18983
|
+
// WHY: no same-name probe can mask.
|
|
18984
|
+
hiddenToolNames: switches.rg ? ["grep"] : [],
|
|
18985
|
+
// WHY: the native `grep` brief describes a tool this profile no longer has; the
|
|
18986
|
+
// WHY: replacement carries its own `tool:rg` brief.
|
|
18987
|
+
guidanceToClear: switches.rg ? ["tool:grep"] : [],
|
|
18988
|
+
...switches.rg ? {
|
|
18989
|
+
denialText: (name2) => name2 === "grep" ? "`grep` is disabled in this profile: file-content search goes through the `rg` tool. Call `rg` \u2014 not a shell `grep` or `rg` command." : void 0
|
|
18990
|
+
} : {},
|
|
18313
18991
|
scope: agent
|
|
18314
18992
|
})
|
|
18315
18993
|
);
|
|
18316
18994
|
}
|
|
18317
18995
|
disposers.push(registerGuidanceSections(rootCtx, agent.ctx, switches));
|
|
18318
18996
|
if (switches.read || switches.applyPatch || switches.edit) {
|
|
18319
|
-
disposers.push(
|
|
18997
|
+
disposers.push(
|
|
18998
|
+
registerWriteHook(rootCtx, agent.ctx, io, bridge?.observations, {
|
|
18999
|
+
autoReadEnabled: switches.writeAutoRead
|
|
19000
|
+
})
|
|
19001
|
+
);
|
|
18320
19002
|
}
|
|
18321
19003
|
if (switches.read) {
|
|
18322
19004
|
disposers.push(registerShellHook(rootCtx, agent.ctx, deps));
|
|
@@ -18442,6 +19124,21 @@ function apply2(rootCtx, config = {}) {
|
|
|
18442
19124
|
}
|
|
18443
19125
|
}
|
|
18444
19126
|
}
|
|
19127
|
+
if (switches.rg) {
|
|
19128
|
+
try {
|
|
19129
|
+
disposers.push(
|
|
19130
|
+
rootCtx.tools.register(
|
|
19131
|
+
buildRgTool({
|
|
19132
|
+
resolveRg: () => resolveRgInvocation({ explicitPath: switches.rgPath })
|
|
19133
|
+
})
|
|
19134
|
+
)
|
|
19135
|
+
);
|
|
19136
|
+
} catch (error) {
|
|
19137
|
+
rootCtx.logger.warn(
|
|
19138
|
+
`dsh-hashline-edit: root rg tool registration failed: ${error instanceof Error ? error.message : String(error)}`
|
|
19139
|
+
);
|
|
19140
|
+
}
|
|
19141
|
+
}
|
|
18445
19142
|
} catch (error) {
|
|
18446
19143
|
disposeReverse(disposers);
|
|
18447
19144
|
rootCtx.logger.warn(
|