dsh-hashline-edit 0.5.0 → 0.5.2
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 +84 -7
- package/cordis.patch.yml +20 -2
- package/lib/client.js +13 -3
- package/lib/index.js +2643 -78
- package/lib/types/dsh/codegraph/cli.d.ts +61 -0
- package/lib/types/dsh/codegraph/project.d.ts +27 -0
- package/lib/types/dsh/codegraph/tools.d.ts +36 -0
- package/lib/types/dsh/codegraph/view.d.ts +25 -0
- package/lib/types/dsh/diagnostics/cli.d.ts +76 -0
- package/lib/types/dsh/diagnostics/messages.d.ts +37 -0
- package/lib/types/dsh/diagnostics/parse.d.ts +39 -0
- package/lib/types/dsh/diagnostics/tools.d.ts +20 -0
- package/lib/types/dsh/diagnostics/view.d.ts +31 -0
- package/lib/types/dsh/guidance.d.ts +10 -4
- package/lib/types/dsh/hide.d.ts +6 -0
- package/lib/types/dsh/index.d.ts +51 -3
- 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 +47 -0
- package/lib/types/dsh/rg/view.d.ts +81 -0
- package/lib/types/dsh/shell-view.d.ts +2 -2
- package/lib/types/dsh/tools/edit.d.ts +15 -1
- package/lib/types/dsh/tools/read-folded.d.ts +85 -0
- package/lib/types/src/domain-errors.d.ts +12 -1
- package/lib/types/src/edit-tool.d.ts +9 -1
- package/lib/types/src/mutation-engine/edit-expand.d.ts +36 -0
- package/lib/types/src/mutation-engine/edit-indent.d.ts +49 -0
- package/lib/types/src/mutation-engine/edit-request.d.ts +4 -0
- package/lib/types/src/mutation-engine/types.d.ts +57 -0
- package/lib/types/src/payload-contract.d.ts +4 -0
- package/lib/types/src/read-expansion/fold-skeleton.d.ts +32 -0
- package/lib/types/src/read-expansion/span-expansion.d.ts +26 -0
- package/package.json +1 -1
- package/prompts/codegraph-guidelines.md +8 -0
- package/prompts/diagnostics-guidelines.md +8 -0
- package/prompts/edit-guidelines.md +3 -1
- package/prompts/edit.md +3 -1
- package/prompts/read-description.md +1 -1
- package/prompts/read-guidelines.md +3 -1
- package/prompts/rg-guidelines.md +8 -0
- package/src/domain-errors.ts +52 -1
- package/src/edit-tool.ts +12 -1
- package/src/mutation-engine/edit-expand.ts +328 -0
- package/src/mutation-engine/edit-indent.ts +121 -0
- package/src/mutation-engine/edit-request.ts +4 -0
- package/src/mutation-engine/pipeline.ts +134 -48
- package/src/mutation-engine/types.ts +54 -0
- package/src/payload-contract.ts +74 -4
- package/src/read-expansion/ast-provider.ts +32 -0
- package/src/read-expansion/fold-skeleton.ts +56 -0
- package/src/read-expansion/qualified-names.ts +7 -0
- package/src/read-expansion/read-provider.ts +9 -0
- package/src/read-expansion/span-expansion.ts +26 -0
package/lib/index.js
CHANGED
|
@@ -112,6 +112,19 @@ function unsupportedFormat(payload) {
|
|
|
112
112
|
}
|
|
113
113
|
return `Path is a binary file: ${payload.path} (${payload.description ?? "binary"}).`;
|
|
114
114
|
}
|
|
115
|
+
function expandUnavailableFormat(payload) {
|
|
116
|
+
const where = `line ${payload.line} of ${payload.path}`;
|
|
117
|
+
if (payload.reason === "non-code") {
|
|
118
|
+
return `"expand": "item" is unavailable at ${where}: the shipped syntax grammars serve rust, typescript, tsx, vue, python, go and java files only. Nothing was written.`;
|
|
119
|
+
}
|
|
120
|
+
if (payload.reason === "grammar-unavailable") {
|
|
121
|
+
return `"expand": "item" is unavailable at ${where}: this host has no syntax grammar for the file. Nothing was written.`;
|
|
122
|
+
}
|
|
123
|
+
if (payload.reason === "stale-content") {
|
|
124
|
+
return `"expand": "item" is unavailable at ${where}: the resolved syntax item no longer contains the anchor line. Nothing was written.`;
|
|
125
|
+
}
|
|
126
|
+
return `"expand": "item" is unavailable at ${where}: no single syntax item contains that line \u2014 it sits outside every item (imports, file header) or the syntax tree could not resolve one. Nothing was written.`;
|
|
127
|
+
}
|
|
115
128
|
function accessFormat(payload) {
|
|
116
129
|
if (payload.kind === "symlink-loop") {
|
|
117
130
|
return `Too many symbolic links while resolving: ${payload.path}.`;
|
|
@@ -345,6 +358,10 @@ ${servedBlock}`
|
|
|
345
358
|
E_UNIQUE_MATCH: {
|
|
346
359
|
audience: "MODEL",
|
|
347
360
|
format: ({ message }) => message
|
|
361
|
+
},
|
|
362
|
+
E_EXPAND_UNAVAILABLE: {
|
|
363
|
+
audience: "MODEL",
|
|
364
|
+
format: expandUnavailableFormat
|
|
348
365
|
}
|
|
349
366
|
};
|
|
350
367
|
function neverServedShapeFormat(payload) {
|
|
@@ -791,12 +808,12 @@ async function resolveTarget(path) {
|
|
|
791
808
|
if (remainingParts.length === 0) {
|
|
792
809
|
return currentPath;
|
|
793
810
|
}
|
|
794
|
-
const [nextPart, ...
|
|
811
|
+
const [nextPart, ...tail2] = remainingParts;
|
|
795
812
|
const candidatePath = join4(currentPath, nextPart);
|
|
796
813
|
try {
|
|
797
814
|
const candidateStats = await lstat(candidatePath);
|
|
798
815
|
if (!candidateStats.isSymbolicLink()) {
|
|
799
|
-
return resParts(candidatePath,
|
|
816
|
+
return resParts(candidatePath, tail2);
|
|
800
817
|
}
|
|
801
818
|
if (visitedSymlinks.has(candidatePath)) {
|
|
802
819
|
const error = new Error(
|
|
@@ -808,10 +825,10 @@ async function resolveTarget(path) {
|
|
|
808
825
|
visitedSymlinks.add(candidatePath);
|
|
809
826
|
const linkTargetPath = resolve(dirname2(candidatePath), await readlink(candidatePath));
|
|
810
827
|
const targetParts = linkTargetPath.slice(parse(linkTargetPath).root.length).split(sep).filter((part) => part.length > 0);
|
|
811
|
-
return resParts(parse(linkTargetPath).root, [...targetParts, ...
|
|
828
|
+
return resParts(parse(linkTargetPath).root, [...targetParts, ...tail2]);
|
|
812
829
|
} catch (error) {
|
|
813
830
|
if (errCode(error) === "ENOENT") {
|
|
814
|
-
return join4(candidatePath, ...
|
|
831
|
+
return join4(candidatePath, ...tail2);
|
|
815
832
|
}
|
|
816
833
|
throw error;
|
|
817
834
|
}
|
|
@@ -1581,7 +1598,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
|
|
|
1581
1598
|
});
|
|
1582
1599
|
if (disposeAssemble !== void 0) disposers.push(disposeAssemble);
|
|
1583
1600
|
const disposeGuard = tools?.guard?.(
|
|
1584
|
-
(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
|
|
1585
1602
|
);
|
|
1586
1603
|
if (disposeGuard !== void 0) disposers.push(disposeGuard);
|
|
1587
1604
|
return () => {
|
|
@@ -1948,6 +1965,23 @@ var GUIDANCE_SECTIONS = [
|
|
|
1948
1965
|
orderName: "TOOL_READ",
|
|
1949
1966
|
renderDefault: () => guidanceText("", loadGuide("../prompts/read-guidelines.md"))
|
|
1950
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
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
name: "tool:codegraph",
|
|
1977
|
+
defaultOrder: 1200,
|
|
1978
|
+
renderDefault: () => guidanceText("", loadGuide("../prompts/codegraph-guidelines.md"))
|
|
1979
|
+
},
|
|
1980
|
+
{
|
|
1981
|
+
name: "tool:diagnostics",
|
|
1982
|
+
defaultOrder: 1250,
|
|
1983
|
+
renderDefault: () => guidanceText("", loadGuide("../prompts/diagnostics-guidelines.md"))
|
|
1984
|
+
},
|
|
1951
1985
|
{
|
|
1952
1986
|
name: "tool:write",
|
|
1953
1987
|
defaultOrder: 1300,
|
|
@@ -1993,9 +2027,12 @@ function orderResolver(registry) {
|
|
|
1993
2027
|
function sectionEnabled(name2, toggles) {
|
|
1994
2028
|
if (toggles === void 0) return true;
|
|
1995
2029
|
if (name2 === "tool:read") return toggles.read;
|
|
2030
|
+
if (name2 === "tool:rg") return toggles.rg === true;
|
|
1996
2031
|
if (name2 === "tool:write") return toggles.applyPatch || toggles.edit;
|
|
1997
2032
|
if (name2 === "tool:apply_patch") return toggles.applyPatch;
|
|
1998
2033
|
if (name2 === "tool:edit") return toggles.edit;
|
|
2034
|
+
if (name2 === "tool:codegraph") return toggles.codegraph === true;
|
|
2035
|
+
if (name2 === "tool:diagnostics") return toggles.diagnostics === true;
|
|
1999
2036
|
return true;
|
|
2000
2037
|
}
|
|
2001
2038
|
function toolVisible(agentCtx, name2) {
|
|
@@ -3843,8 +3880,8 @@ function contextLinesToShow(displayLines, lastWasChange, nextPartIsChange, conte
|
|
|
3843
3880
|
skipStart = Math.max(0, displayLines.length - contextLines);
|
|
3844
3881
|
linesToShow = displayLines.slice(skipStart);
|
|
3845
3882
|
} else if (nextPartIsChange && displayLines.length > contextLines * 2) {
|
|
3846
|
-
const
|
|
3847
|
-
linesToShow = [...displayLines.slice(0, contextLines), UNTOUCHED_MARKER, ...
|
|
3883
|
+
const tail2 = contextLines === 0 ? [] : displayLines.slice(-contextLines);
|
|
3884
|
+
linesToShow = [...displayLines.slice(0, contextLines), UNTOUCHED_MARKER, ...tail2];
|
|
3848
3885
|
skipMiddle = displayLines.length - contextLines * 2;
|
|
3849
3886
|
} else if (!nextPartIsChange && linesToShow.length > contextLines) {
|
|
3850
3887
|
linesToShow = linesToShow.slice(0, contextLines);
|
|
@@ -5996,9 +6033,9 @@ function buildRangeServeBlock(startLine, endLine, fileHashes, fileLines) {
|
|
|
5996
6033
|
const last = Math.max(first, Math.min(endLine, Math.max(len, first)));
|
|
5997
6034
|
const servedRows = buildRangeServeRows(first, last, fileHashes);
|
|
5998
6035
|
const totalLen = endLine - startLine + 1;
|
|
5999
|
-
const
|
|
6036
|
+
const tail2 = first === startLine && servedRows.length < totalLen ? `
|
|
6000
6037
|
${paginationHint(startLine + servedRows.length, totalLen - servedRows.length)}` : "";
|
|
6001
|
-
return { servedRows, rendered: fmtServedRows(servedRows, fileLines) +
|
|
6038
|
+
return { servedRows, rendered: fmtServedRows(servedRows, fileLines) + tail2 };
|
|
6002
6039
|
}
|
|
6003
6040
|
function assembleRejectAndServe(args) {
|
|
6004
6041
|
const { servedRows, rendered } = buildRangeServeBlock(
|
|
@@ -8376,6 +8413,24 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
|
|
|
8376
8413
|
return best ?? null;
|
|
8377
8414
|
}
|
|
8378
8415
|
|
|
8416
|
+
// src/read-expansion/fold-skeleton.ts
|
|
8417
|
+
function collectSkeletonItems(root, kinds, decorate) {
|
|
8418
|
+
const items = [];
|
|
8419
|
+
const visit = (node, depth) => {
|
|
8420
|
+
for (const child of node.namedChildren) {
|
|
8421
|
+
if (!Object.hasOwn(kinds, child.type)) {
|
|
8422
|
+
visit(child, depth);
|
|
8423
|
+
continue;
|
|
8424
|
+
}
|
|
8425
|
+
const decorated = decorate(child);
|
|
8426
|
+
items.push({ startLine: decorated.startLine, endLine: decorated.endLine, depth });
|
|
8427
|
+
visit(child, depth + 1);
|
|
8428
|
+
}
|
|
8429
|
+
};
|
|
8430
|
+
visit(root, 1);
|
|
8431
|
+
return items;
|
|
8432
|
+
}
|
|
8433
|
+
|
|
8379
8434
|
// src/read-expansion/grammar-cache.ts
|
|
8380
8435
|
import { createHash } from "node:crypto";
|
|
8381
8436
|
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -8993,6 +9048,35 @@ function createAstSpanProvider(options = {}) {
|
|
|
8993
9048
|
return runtimeAbsent;
|
|
8994
9049
|
},
|
|
8995
9050
|
prefetch,
|
|
9051
|
+
/**
|
|
9052
|
+
* The whole file's structural skeleton: every item the language's kind table owns, at its
|
|
9053
|
+
* nesting depth. WHY it reuses the boundary policy: the same handle cache, the same decline
|
|
9054
|
+
* vocabulary and the same decoration tables mean a folded read and a widened read can never
|
|
9055
|
+
* disagree about what an item is.
|
|
9056
|
+
*/
|
|
9057
|
+
async skeleton(file) {
|
|
9058
|
+
const language = grammarLanguageForFile(file);
|
|
9059
|
+
if (language === void 0) return decline("no_provider");
|
|
9060
|
+
const languageScope = LANGUAGES[language];
|
|
9061
|
+
if (languageScope === void 0) return decline("no_provider", language);
|
|
9062
|
+
const source = await readText2(file);
|
|
9063
|
+
if (source === void 0) return decline("provider_declined", language);
|
|
9064
|
+
const outcome = await handleFor(language);
|
|
9065
|
+
if (outcome.kind === "decline") return outcome.decline;
|
|
9066
|
+
const tree = outcome.handle.parse(source);
|
|
9067
|
+
if (tree === null) return decline("grammar_unavailable", language);
|
|
9068
|
+
try {
|
|
9069
|
+
if (tree.rootNode.hasError) return decline("provider_declined", language);
|
|
9070
|
+
return {
|
|
9071
|
+
items: collectSkeletonItems(tree.rootNode, languageScope.kinds, languageScope.decorate)
|
|
9072
|
+
};
|
|
9073
|
+
} catch {
|
|
9074
|
+
outcome.handle.onFailure?.();
|
|
9075
|
+
return decline("provider_declined", language);
|
|
9076
|
+
} finally {
|
|
9077
|
+
tree.delete?.();
|
|
9078
|
+
}
|
|
9079
|
+
},
|
|
8996
9080
|
async enclosingSpan(file, window) {
|
|
8997
9081
|
if (!isOffsetWindow(window)) return decline("provider_declined");
|
|
8998
9082
|
const language = grammarLanguageForFile(file);
|
|
@@ -9404,6 +9488,12 @@ function withQualifiedNames(provider, resolver, timeoutMs = DEFAULT_QUALIFIED_NA
|
|
|
9404
9488
|
} catch {
|
|
9405
9489
|
}
|
|
9406
9490
|
return span;
|
|
9491
|
+
},
|
|
9492
|
+
// WHY: a name resolver has nothing to say about an item list, so the skeleton is forwarded
|
|
9493
|
+
// WHY: untouched instead of being dropped with the other members.
|
|
9494
|
+
skeleton(file) {
|
|
9495
|
+
const derive = provider.skeleton;
|
|
9496
|
+
return derive === void 0 ? { refusal: "no_provider" } : derive(file);
|
|
9407
9497
|
}
|
|
9408
9498
|
};
|
|
9409
9499
|
}
|
|
@@ -9433,6 +9523,13 @@ function createReadSpanProvider(options = {}) {
|
|
|
9433
9523
|
if (isPlainTextPath(file)) return paragraph.enclosingSpan(file, window);
|
|
9434
9524
|
if (isShellPath(file)) return bash.enclosingSpan(file, window);
|
|
9435
9525
|
return ast.enclosingSpan(file, window);
|
|
9526
|
+
},
|
|
9527
|
+
skeleton(file) {
|
|
9528
|
+
if (isMarkdownPath(file) || isDataPath(file) || isPlainTextPath(file) || isShellPath(file)) {
|
|
9529
|
+
return { refusal: "no_provider" };
|
|
9530
|
+
}
|
|
9531
|
+
const derive = ast.skeleton;
|
|
9532
|
+
return derive === void 0 ? { refusal: "no_provider" } : derive(file);
|
|
9436
9533
|
}
|
|
9437
9534
|
};
|
|
9438
9535
|
return withQualifiedNames(
|
|
@@ -9999,10 +10096,127 @@ async function publishPluginWrites(deps, requestPaths, ctx, exec) {
|
|
|
9999
10096
|
}
|
|
10000
10097
|
}
|
|
10001
10098
|
|
|
10099
|
+
// dsh/tools/read-folded.ts
|
|
10100
|
+
var DEFAULT_FOLD_DEPTH = 1;
|
|
10101
|
+
var MAX_FOLD_DEPTH = 3;
|
|
10102
|
+
var FOLDED_VIEW_LABEL = "Folded view";
|
|
10103
|
+
function badPayload2(message) {
|
|
10104
|
+
return new DomainError("E_BAD_PAYLOAD", { message });
|
|
10105
|
+
}
|
|
10106
|
+
function admitFoldedRequest(params) {
|
|
10107
|
+
if (params.mode !== "folded") {
|
|
10108
|
+
if (params.foldDepth === void 0) return void 0;
|
|
10109
|
+
throw badPayload2(
|
|
10110
|
+
'Read request field "foldDepth" is only valid together with "mode": "folded".'
|
|
10111
|
+
);
|
|
10112
|
+
}
|
|
10113
|
+
const foldDepth = admitFoldDepth(params.foldDepth);
|
|
10114
|
+
const rest = {};
|
|
10115
|
+
for (const [key, value] of Object.entries(params)) {
|
|
10116
|
+
if (key === "mode" || key === "foldDepth") continue;
|
|
10117
|
+
rest[key] = value;
|
|
10118
|
+
}
|
|
10119
|
+
const request = admitReadRequest(rest);
|
|
10120
|
+
if (request.windows !== void 0) {
|
|
10121
|
+
throw badPayload2(
|
|
10122
|
+
'A "mode": "folded" read always covers the whole file; drop "offset", "limit" and "windows".'
|
|
10123
|
+
);
|
|
10124
|
+
}
|
|
10125
|
+
return { request, foldDepth };
|
|
10126
|
+
}
|
|
10127
|
+
function admitFoldDepth(value) {
|
|
10128
|
+
if (value === void 0) return DEFAULT_FOLD_DEPTH;
|
|
10129
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > MAX_FOLD_DEPTH) {
|
|
10130
|
+
throw badPayload2(
|
|
10131
|
+
`Read request field "foldDepth" must be an integer from 1 to ${MAX_FOLD_DEPTH}; it sets how deeply a folded read reveals nested items.`
|
|
10132
|
+
);
|
|
10133
|
+
}
|
|
10134
|
+
return value;
|
|
10135
|
+
}
|
|
10136
|
+
function foldSegments(items, totalLines, foldDepth) {
|
|
10137
|
+
const kept = items.filter(
|
|
10138
|
+
(item) => item.depth <= foldDepth && item.startLine >= 1 && item.endLine <= totalLines && item.startLine <= item.endLine
|
|
10139
|
+
).sort((left, right) => left.startLine - right.startLine || right.endLine - left.endLine);
|
|
10140
|
+
const segments = [];
|
|
10141
|
+
let next = 1;
|
|
10142
|
+
for (const item of kept) {
|
|
10143
|
+
if (item.startLine > next) {
|
|
10144
|
+
segments.push({ kind: "gap", startLine: next, endLine: item.startLine - 1 });
|
|
10145
|
+
}
|
|
10146
|
+
segments.push({ kind: "item", startLine: item.startLine, endLine: item.endLine });
|
|
10147
|
+
next = Math.max(next, item.endLine + 1);
|
|
10148
|
+
}
|
|
10149
|
+
if (next <= totalLines) segments.push({ kind: "gap", startLine: next, endLine: totalLines });
|
|
10150
|
+
return segments;
|
|
10151
|
+
}
|
|
10152
|
+
function foldedLineNumbers(segments) {
|
|
10153
|
+
const lines = [];
|
|
10154
|
+
for (const segment of segments) {
|
|
10155
|
+
lines.push(segment.startLine);
|
|
10156
|
+
if (segment.endLine !== segment.startLine) lines.push(segment.endLine);
|
|
10157
|
+
}
|
|
10158
|
+
return lines;
|
|
10159
|
+
}
|
|
10160
|
+
function gapContent(count) {
|
|
10161
|
+
return `\u2026 (${count} ${count === 1 ? "line" : "lines"}) \u2026`;
|
|
10162
|
+
}
|
|
10163
|
+
function foldedLabel(itemCount, elided) {
|
|
10164
|
+
const items = `${itemCount} ${itemCount === 1 ? "item" : "items"}`;
|
|
10165
|
+
const lines = `${elided} ${elided === 1 ? "line" : "lines"} elided`;
|
|
10166
|
+
return `${FOLDED_VIEW_LABEL}, ${items}, ${lines}`;
|
|
10167
|
+
}
|
|
10168
|
+
async function renderFoldedPage(input) {
|
|
10169
|
+
const segments = foldSegments(input.items, input.totalLines, input.foldDepth);
|
|
10170
|
+
const served = await input.serve(foldedLineNumbers(segments));
|
|
10171
|
+
const byLine = /* @__PURE__ */ new Map();
|
|
10172
|
+
for (const row of served) byLine.set(row.line, row);
|
|
10173
|
+
const rows = [];
|
|
10174
|
+
let itemCount = 0;
|
|
10175
|
+
for (const segment of segments) {
|
|
10176
|
+
const first = byLine.get(segment.startLine);
|
|
10177
|
+
const last = segment.endLine === segment.startLine ? first : byLine.get(segment.endLine);
|
|
10178
|
+
if (first === void 0 || last === void 0) return void 0;
|
|
10179
|
+
if (segment.kind === "item") {
|
|
10180
|
+
itemCount += 1;
|
|
10181
|
+
rows.push(
|
|
10182
|
+
segment.endLine === segment.startLine ? `${first.hash}${HASH_SEP}${first.text}` : `${first.hash}..${last.hash}${HASH_SEP}${first.text}`
|
|
10183
|
+
);
|
|
10184
|
+
continue;
|
|
10185
|
+
}
|
|
10186
|
+
const count = segment.endLine - segment.startLine + 1;
|
|
10187
|
+
rows.push(
|
|
10188
|
+
segment.endLine === segment.startLine ? `${first.hash}${HASH_SEP}${gapContent(count)}` : `${first.hash}..${last.hash}${HASH_SEP}${gapContent(count)}`
|
|
10189
|
+
);
|
|
10190
|
+
}
|
|
10191
|
+
const header = formatPageHeader({
|
|
10192
|
+
label: foldedLabel(itemCount, input.totalLines - itemCount),
|
|
10193
|
+
file: input.file,
|
|
10194
|
+
totalLines: input.totalLines
|
|
10195
|
+
});
|
|
10196
|
+
return { text: [header, ...rows].join("\n") };
|
|
10197
|
+
}
|
|
10198
|
+
var UNAVAILABLE_REASONS = {
|
|
10199
|
+
no_provider: "this file has no supported grammar",
|
|
10200
|
+
grammar_unavailable: "its grammar is unavailable",
|
|
10201
|
+
cold_grammar: "its grammar is still loading",
|
|
10202
|
+
runtime_absent: "the grammar runtime is unavailable",
|
|
10203
|
+
provider_declined: "the parser declined this file",
|
|
10204
|
+
provider_error: "the parser failed on it",
|
|
10205
|
+
boundary_crossing: "no item encloses this file",
|
|
10206
|
+
invalid_answer: "the parser gave no usable item",
|
|
10207
|
+
not_superset: "the parser gave no usable item",
|
|
10208
|
+
unanchored: "its items could not be anchored",
|
|
10209
|
+
empty_file: "the file has no lines"
|
|
10210
|
+
};
|
|
10211
|
+
function foldedUnavailableNote(reason) {
|
|
10212
|
+
const detail = UNAVAILABLE_REASONS[reason] ?? "its structure could not be derived";
|
|
10213
|
+
return `[Folded view unavailable: ${detail}. Showing the served page instead.]`;
|
|
10214
|
+
}
|
|
10215
|
+
|
|
10002
10216
|
// dsh/tools/read.ts
|
|
10003
10217
|
var READ_TOOL_NAME = "read";
|
|
10004
10218
|
var READ_DESCRIPTION = loadP("../prompts/read-description.md");
|
|
10005
|
-
var
|
|
10219
|
+
var READ_MODES = ["served", "verbatim", "folded"];
|
|
10006
10220
|
function createDefaultReadSpanProvider(io) {
|
|
10007
10221
|
const readTextFile = io === void 0 ? void 0 : async (path) => {
|
|
10008
10222
|
try {
|
|
@@ -10015,16 +10229,16 @@ function createDefaultReadSpanProvider(io) {
|
|
|
10015
10229
|
};
|
|
10016
10230
|
return createReadSpanProvider(readTextFile === void 0 ? {} : { readTextFile });
|
|
10017
10231
|
}
|
|
10018
|
-
async function loadGovernedText(deps, absolutePath,
|
|
10232
|
+
async function loadGovernedText(deps, absolutePath, displayPath2, signal) {
|
|
10019
10233
|
const loaded = await loadFileKindAndText(absolutePath, {
|
|
10020
|
-
displayPath,
|
|
10234
|
+
displayPath: displayPath2,
|
|
10021
10235
|
...deps.coreIo === void 0 ? {} : { io: deps.coreIo },
|
|
10022
10236
|
...signal === void 0 ? {} : { signal }
|
|
10023
10237
|
});
|
|
10024
|
-
if (loaded.kind !== "text") throw unsupportedLoaded(
|
|
10238
|
+
if (loaded.kind !== "text") throw unsupportedLoaded(displayPath2, loaded);
|
|
10025
10239
|
const decoded = decodeUtf8Strict(
|
|
10026
10240
|
deps.coreIo === void 0 ? await deps.io.read(absolutePath, signal) : await deps.coreIo.readFile(await deps.coreIo.resolve(absolutePath), signal),
|
|
10027
|
-
|
|
10241
|
+
displayPath2
|
|
10028
10242
|
);
|
|
10029
10243
|
const stats = loaded.stats;
|
|
10030
10244
|
return {
|
|
@@ -10304,7 +10518,8 @@ async function serveFileLines(deps, request) {
|
|
|
10304
10518
|
async function readAndServe(deps, rawArgs, exec, spanProvider) {
|
|
10305
10519
|
const ctx = resolveToolContext(exec);
|
|
10306
10520
|
const raw = rawArgs;
|
|
10307
|
-
const
|
|
10521
|
+
const folded = admitFoldedRequest(raw);
|
|
10522
|
+
const request = folded === void 0 ? admitReadRequest(raw) : folded.request;
|
|
10308
10523
|
const mode = request.mode;
|
|
10309
10524
|
const absolutePath = toCwd(request.file, ctx.cwd);
|
|
10310
10525
|
ctx.signal?.throwIfAborted();
|
|
@@ -10330,6 +10545,18 @@ async function readAndServe(deps, rawArgs, exec, spanProvider) {
|
|
|
10330
10545
|
})();
|
|
10331
10546
|
return resolvedText;
|
|
10332
10547
|
};
|
|
10548
|
+
if (folded !== void 0) {
|
|
10549
|
+
return foldedReadPage({
|
|
10550
|
+
deps,
|
|
10551
|
+
exec,
|
|
10552
|
+
ctx,
|
|
10553
|
+
request,
|
|
10554
|
+
absolutePath,
|
|
10555
|
+
normalized,
|
|
10556
|
+
spanProvider,
|
|
10557
|
+
foldDepth: folded.foldDepth
|
|
10558
|
+
});
|
|
10559
|
+
}
|
|
10333
10560
|
const wantsAnchor = request.windows?.some((window) => window.kind === "anchor") === true;
|
|
10334
10561
|
const store = mode === "served" || wantsAnchor ? await loadHashStore() : void 0;
|
|
10335
10562
|
const anchorText = wantsAnchor ? await normalized() : void 0;
|
|
@@ -10388,6 +10615,49 @@ async function readAndServe(deps, rawArgs, exec, spanProvider) {
|
|
|
10388
10615
|
...presentation === void 0 ? {} : { presentation }
|
|
10389
10616
|
};
|
|
10390
10617
|
}
|
|
10618
|
+
async function foldedReadPage(input) {
|
|
10619
|
+
const { deps, exec, ctx, request, absolutePath, spanProvider } = input;
|
|
10620
|
+
const fallback = async (reason) => {
|
|
10621
|
+
const served = await readAndServe(
|
|
10622
|
+
deps,
|
|
10623
|
+
{ path: request.file, mode: "served" },
|
|
10624
|
+
exec,
|
|
10625
|
+
spanProvider
|
|
10626
|
+
);
|
|
10627
|
+
return { ...served, text: `${foldedUnavailableNote(reason)}
|
|
10628
|
+
|
|
10629
|
+
${served.text}` };
|
|
10630
|
+
};
|
|
10631
|
+
const provider = spanProvider;
|
|
10632
|
+
if (provider === void 0 || provider.skeleton === void 0) return fallback("no_provider");
|
|
10633
|
+
let answer;
|
|
10634
|
+
try {
|
|
10635
|
+
answer = await provider.skeleton(absolutePath);
|
|
10636
|
+
} catch {
|
|
10637
|
+
answer = { refusal: "provider_error" };
|
|
10638
|
+
}
|
|
10639
|
+
if ("refusal" in answer) return fallback(answer.refusal);
|
|
10640
|
+
const text = await input.normalized();
|
|
10641
|
+
if (text === void 0) return fallback("not_text");
|
|
10642
|
+
const totalLines = visibleLineTotal(text.normalized, walkLines(text.normalized).total);
|
|
10643
|
+
if (totalLines === 0) return fallback("empty_file");
|
|
10644
|
+
const page = await renderFoldedPage({
|
|
10645
|
+
file: request.file,
|
|
10646
|
+
totalLines,
|
|
10647
|
+
foldDepth: input.foldDepth,
|
|
10648
|
+
items: answer.items,
|
|
10649
|
+
serve: (lineNumbers) => serveFileLines(deps, {
|
|
10650
|
+
path: request.file,
|
|
10651
|
+
cwd: ctx.cwd,
|
|
10652
|
+
sessionKey: ctx.sessionKey,
|
|
10653
|
+
signal: ctx.signal,
|
|
10654
|
+
lineNumbers
|
|
10655
|
+
})
|
|
10656
|
+
});
|
|
10657
|
+
if (page === void 0) return fallback("unanchored");
|
|
10658
|
+
await deps.observations?.publish(absolutePath, exec, { signal: ctx.signal });
|
|
10659
|
+
return { text: page.text };
|
|
10660
|
+
}
|
|
10391
10661
|
var MAX_PRESENTATION_LINES = 400;
|
|
10392
10662
|
var MAX_PRESENTATION_LINE_CHARS = 2048;
|
|
10393
10663
|
function capPresentationLine(text) {
|
|
@@ -10498,8 +10768,12 @@ function buildReadTool(deps, options = {}) {
|
|
|
10498
10768
|
},
|
|
10499
10769
|
mode: {
|
|
10500
10770
|
type: "string",
|
|
10501
|
-
enum:
|
|
10502
|
-
description: "`served` (default) returns `HASH\u2502content` rows and records them as served; `verbatim` returns plain text with no anchors."
|
|
10771
|
+
enum: READ_MODES,
|
|
10772
|
+
description: "`served` (default) returns `HASH\u2502content` rows and records them as served; `verbatim` returns plain text with no anchors; `folded` returns the file's structural skeleton \u2014 one anchored row per syntax item \u2014 and always covers the whole file."
|
|
10773
|
+
},
|
|
10774
|
+
foldDepth: {
|
|
10775
|
+
type: "number",
|
|
10776
|
+
description: "Folded mode only: how deeply the skeleton nests, 1-3 (default 1). 1 keeps top-level items and each value reaches one level deeper. Refused unless `mode` is `folded`."
|
|
10503
10777
|
}
|
|
10504
10778
|
},
|
|
10505
10779
|
output: {
|
|
@@ -10981,6 +11255,8 @@ async function plan(deps, request) {
|
|
|
10981
11255
|
}
|
|
10982
11256
|
}
|
|
10983
11257
|
var GREP_TOOL_NAME = "grep";
|
|
11258
|
+
var RG_TOOL_NAME = "rg";
|
|
11259
|
+
var GREP_TOOL_NAMES = [GREP_TOOL_NAME, RG_TOOL_NAME];
|
|
10984
11260
|
var GREP_INLINE_MAX_MATCHES = 250;
|
|
10985
11261
|
var GREP_VIEW_MAX_INLINE_TOKENS = 12500;
|
|
10986
11262
|
var TOKEN_CHARS_PER_UNIT = 4;
|
|
@@ -11185,7 +11461,7 @@ function createShellHooks(deps) {
|
|
|
11185
11461
|
async postExecute(exec, result, next) {
|
|
11186
11462
|
const elapsed = deps.metrics === void 0 ? void 0 : stopwatch();
|
|
11187
11463
|
const decision = await next();
|
|
11188
|
-
if (exec.name
|
|
11464
|
+
if (GREP_TOOL_NAMES.includes(exec.name))
|
|
11189
11465
|
return grepPostExecute(deps, exec, result, decision, elapsed);
|
|
11190
11466
|
if (!SHELL_TOOL_NAMES.includes(exec.name)) return decision;
|
|
11191
11467
|
if (result.isError || decision.kind !== "accept") return decision;
|
|
@@ -12109,8 +12385,8 @@ function resolveRequestPath(path, cwd) {
|
|
|
12109
12385
|
}
|
|
12110
12386
|
const cwdAbsolute = resolvePath2(cwd);
|
|
12111
12387
|
const absolutePath = isAbsolute6(path) ? resolvePath2(path) : resolvePath2(cwdAbsolute, path);
|
|
12112
|
-
const
|
|
12113
|
-
if (
|
|
12388
|
+
const relative3 = relativePath(cwdAbsolute, absolutePath);
|
|
12389
|
+
if (relative3.startsWith("..") || isAbsolute6(relative3)) {
|
|
12114
12390
|
return { ok: false, message: "path must stay inside the workspace" };
|
|
12115
12391
|
}
|
|
12116
12392
|
return { ok: true, value: { path, absolutePath } };
|
|
@@ -13187,6 +13463,251 @@ async function repairCutIntents(store) {
|
|
|
13187
13463
|
}
|
|
13188
13464
|
}
|
|
13189
13465
|
|
|
13466
|
+
// src/mutation-engine/edit-indent.ts
|
|
13467
|
+
function leadingWhitespaceOf(line) {
|
|
13468
|
+
let end = 0;
|
|
13469
|
+
while (end < line.length && (line[end] === " " || line[end] === " ")) end += 1;
|
|
13470
|
+
return line.slice(0, end);
|
|
13471
|
+
}
|
|
13472
|
+
function isBlankLine(line) {
|
|
13473
|
+
return line.trim() === "";
|
|
13474
|
+
}
|
|
13475
|
+
function commonIndentPrefix(lines) {
|
|
13476
|
+
let prefix;
|
|
13477
|
+
for (const line of lines) {
|
|
13478
|
+
if (isBlankLine(line)) continue;
|
|
13479
|
+
const indent = leadingWhitespaceOf(line);
|
|
13480
|
+
if (prefix === void 0) {
|
|
13481
|
+
prefix = indent;
|
|
13482
|
+
if (prefix === "") return "";
|
|
13483
|
+
continue;
|
|
13484
|
+
}
|
|
13485
|
+
let shared = 0;
|
|
13486
|
+
while (shared < prefix.length && shared < indent.length && prefix[shared] === indent[shared]) {
|
|
13487
|
+
shared += 1;
|
|
13488
|
+
}
|
|
13489
|
+
prefix = prefix.slice(0, shared);
|
|
13490
|
+
if (prefix === "") return "";
|
|
13491
|
+
}
|
|
13492
|
+
return prefix ?? "";
|
|
13493
|
+
}
|
|
13494
|
+
function applyAutoIndent(text, baseIndent) {
|
|
13495
|
+
const lines = text.split("\n");
|
|
13496
|
+
const strippedPrefix = commonIndentPrefix(lines);
|
|
13497
|
+
let changedLines = 0;
|
|
13498
|
+
const rebased = lines.map((line) => {
|
|
13499
|
+
if (isBlankLine(line)) return line;
|
|
13500
|
+
const next = `${baseIndent}${line.slice(strippedPrefix.length)}`;
|
|
13501
|
+
if (next !== line) changedLines += 1;
|
|
13502
|
+
return next;
|
|
13503
|
+
});
|
|
13504
|
+
const nextText = rebased.join("\n");
|
|
13505
|
+
return {
|
|
13506
|
+
text: nextText,
|
|
13507
|
+
changed: nextText !== text,
|
|
13508
|
+
changedLines,
|
|
13509
|
+
strippedPrefix
|
|
13510
|
+
};
|
|
13511
|
+
}
|
|
13512
|
+
function describeIndent(indent) {
|
|
13513
|
+
if (indent === "") return "no indentation";
|
|
13514
|
+
if (/^ +$/.test(indent)) {
|
|
13515
|
+
return indent.length === 1 ? "1 space" : `${indent.length} spaces`;
|
|
13516
|
+
}
|
|
13517
|
+
if (/^\t+$/.test(indent)) {
|
|
13518
|
+
return indent.length === 1 ? "1 tab" : `${indent.length} tabs`;
|
|
13519
|
+
}
|
|
13520
|
+
return `the exact prefix ${JSON.stringify(indent)}`;
|
|
13521
|
+
}
|
|
13522
|
+
function buildIndentNote(args) {
|
|
13523
|
+
const { ref, summary } = args;
|
|
13524
|
+
const stripped = summary.strippedPrefix === "" ? "" : `; a shared ${describeIndent(summary.strippedPrefix)} prefix was dropped from the payload`;
|
|
13525
|
+
return `${ref}: "indent": "auto" re-indented ${summary.changedLines} line(s) to the anchor line's ${describeIndent(summary.baseIndent)}${stripped}.`;
|
|
13526
|
+
}
|
|
13527
|
+
|
|
13528
|
+
// src/mutation-engine/edit-expand.ts
|
|
13529
|
+
var sharedProvider;
|
|
13530
|
+
function defaultExpandProvider() {
|
|
13531
|
+
if (sharedProvider === void 0) sharedProvider = createAstSpanProvider();
|
|
13532
|
+
return sharedProvider;
|
|
13533
|
+
}
|
|
13534
|
+
function refusalReasonOf(answer) {
|
|
13535
|
+
if (answer === null) return "no-enclosing-item";
|
|
13536
|
+
if (!("refusal" in answer)) return "no-enclosing-item";
|
|
13537
|
+
switch (answer.refusal) {
|
|
13538
|
+
case "no_provider":
|
|
13539
|
+
case "not_text":
|
|
13540
|
+
case "toggle_off":
|
|
13541
|
+
return "non-code";
|
|
13542
|
+
case "grammar_unavailable":
|
|
13543
|
+
case "cold_grammar":
|
|
13544
|
+
case "runtime_absent":
|
|
13545
|
+
return "grammar-unavailable";
|
|
13546
|
+
default:
|
|
13547
|
+
return "no-enclosing-item";
|
|
13548
|
+
}
|
|
13549
|
+
}
|
|
13550
|
+
function expandUnavailable(args) {
|
|
13551
|
+
return new DomainError("E_EXPAND_UNAVAILABLE", {
|
|
13552
|
+
path: args.path,
|
|
13553
|
+
line: args.line,
|
|
13554
|
+
reason: args.reason
|
|
13555
|
+
});
|
|
13556
|
+
}
|
|
13557
|
+
async function resolveEnclosingItem(args) {
|
|
13558
|
+
const answer = await args.provider.enclosingSpan(args.absolutePath, {
|
|
13559
|
+
offset: args.anchorLine,
|
|
13560
|
+
limit: 1
|
|
13561
|
+
});
|
|
13562
|
+
if (answer === null || "refusal" in answer) {
|
|
13563
|
+
throw expandUnavailable({
|
|
13564
|
+
path: args.filePath,
|
|
13565
|
+
line: args.anchorLine,
|
|
13566
|
+
reason: refusalReasonOf(answer)
|
|
13567
|
+
});
|
|
13568
|
+
}
|
|
13569
|
+
const startLine = answer.start;
|
|
13570
|
+
const endLine = answer.end;
|
|
13571
|
+
if (!Number.isInteger(startLine) || !Number.isInteger(endLine) || startLine < 1 || endLine < startLine || startLine > args.anchorLine || endLine < args.anchorLine || endLine > args.totalLines) {
|
|
13572
|
+
throw expandUnavailable({
|
|
13573
|
+
path: args.filePath,
|
|
13574
|
+
line: args.anchorLine,
|
|
13575
|
+
reason: "stale-content"
|
|
13576
|
+
});
|
|
13577
|
+
}
|
|
13578
|
+
return { startLine, endLine };
|
|
13579
|
+
}
|
|
13580
|
+
function replaceItemSpan(content, startLine, endLine, lines) {
|
|
13581
|
+
const fileLines = splitLines(content);
|
|
13582
|
+
const out = [...fileLines.slice(0, startLine - 1), ...lines, ...fileLines.slice(endLine)];
|
|
13583
|
+
return serializeLineList(content, fileLines, void 0, out);
|
|
13584
|
+
}
|
|
13585
|
+
async function applyExpandedItem(input) {
|
|
13586
|
+
abortIf(input.signal);
|
|
13587
|
+
const lines = splitLines(input.content);
|
|
13588
|
+
const leased = resolveLeasedEdit({
|
|
13589
|
+
edit: {
|
|
13590
|
+
content_lines: [],
|
|
13591
|
+
hash_bounds: [input.edit.hash_bounds[0], input.edit.hash_bounds[0]]
|
|
13592
|
+
},
|
|
13593
|
+
snapshot: {
|
|
13594
|
+
fileHashes: input.hashes,
|
|
13595
|
+
fileLines: lines,
|
|
13596
|
+
filePath: input.absolutePath
|
|
13597
|
+
},
|
|
13598
|
+
served: input.served,
|
|
13599
|
+
source: input.identity
|
|
13600
|
+
});
|
|
13601
|
+
const anchorLine = leased.resolved.hash_bounds[0].line;
|
|
13602
|
+
const provider = input.provider ?? defaultExpandProvider();
|
|
13603
|
+
const item = await resolveEnclosingItem({
|
|
13604
|
+
provider,
|
|
13605
|
+
absolutePath: input.absolutePath,
|
|
13606
|
+
filePath: input.filePath,
|
|
13607
|
+
anchorLine,
|
|
13608
|
+
totalLines: input.hashes.length
|
|
13609
|
+
});
|
|
13610
|
+
let replacement = input.edit.content_lines;
|
|
13611
|
+
let indent;
|
|
13612
|
+
if (input.indent === "auto" && replacement.length > 0) {
|
|
13613
|
+
const anchorText = lines[anchorLine - 1] ?? "";
|
|
13614
|
+
const rebased = applyAutoIndent(replacement.join("\n"), leadingWhitespaceOf(anchorText));
|
|
13615
|
+
if (rebased.changed) {
|
|
13616
|
+
replacement = rebased.text.split("\n");
|
|
13617
|
+
indent = {
|
|
13618
|
+
baseIndent: leadingWhitespaceOf(anchorText),
|
|
13619
|
+
strippedPrefix: rebased.strippedPrefix,
|
|
13620
|
+
changedLines: rebased.changedLines
|
|
13621
|
+
};
|
|
13622
|
+
}
|
|
13623
|
+
}
|
|
13624
|
+
const nextContent = replaceItemSpan(input.content, item.startLine, item.endLine, replacement);
|
|
13625
|
+
const range = {
|
|
13626
|
+
startLine: item.startLine,
|
|
13627
|
+
endLine: item.endLine,
|
|
13628
|
+
startHash: input.hashes[item.startLine - 1],
|
|
13629
|
+
endHash: input.hashes[item.endLine - 1],
|
|
13630
|
+
delta: replacement.length - (item.endLine - item.startLine + 1)
|
|
13631
|
+
};
|
|
13632
|
+
const warnings = [];
|
|
13633
|
+
const echo = findServedHashEcho(replacement, input.served, input.canonDigests, 1);
|
|
13634
|
+
let literalBypass = false;
|
|
13635
|
+
if (echo !== void 0) {
|
|
13636
|
+
if (input.mode === "literal") {
|
|
13637
|
+
literalBypass = true;
|
|
13638
|
+
warnings.push(LITERAL_BYPASS_NOTICE);
|
|
13639
|
+
} else {
|
|
13640
|
+
const count = trackServedEditRefusal(
|
|
13641
|
+
input.sessionKey,
|
|
13642
|
+
input.absolutePath,
|
|
13643
|
+
input.edit.hash_bounds[0].hash,
|
|
13644
|
+
input.edit.hash_bounds[1].hash,
|
|
13645
|
+
replacement[echo.k - 1] ?? ""
|
|
13646
|
+
);
|
|
13647
|
+
throw new DomainError("E_SUSPICIOUS_TEXT", {
|
|
13648
|
+
target: "edit",
|
|
13649
|
+
path: input.filePath,
|
|
13650
|
+
line: echo.k,
|
|
13651
|
+
hash: echo.hash,
|
|
13652
|
+
servedLine: echo.servedLine,
|
|
13653
|
+
count
|
|
13654
|
+
});
|
|
13655
|
+
}
|
|
13656
|
+
}
|
|
13657
|
+
const payloadEdit = { ...input.edit, content_lines: replacement };
|
|
13658
|
+
warnUnicodeEsc(payloadEdit, warnings);
|
|
13659
|
+
const neverServedCount = findNeverServedAnchorShapes(replacement, input.served, 1).length;
|
|
13660
|
+
if (nextContent === input.content) {
|
|
13661
|
+
return {
|
|
13662
|
+
kind: "noop",
|
|
13663
|
+
range,
|
|
13664
|
+
noopEdit: {
|
|
13665
|
+
loc: input.edit.hash_bounds[0].hash,
|
|
13666
|
+
currentContent: lines.slice(item.startLine - 1, item.endLine).join("\n")
|
|
13667
|
+
},
|
|
13668
|
+
anchorWarnings: warnings.length > 0 ? warnings : void 0,
|
|
13669
|
+
literalBypass,
|
|
13670
|
+
neverServedCount,
|
|
13671
|
+
...indent !== void 0 ? { indent } : {}
|
|
13672
|
+
};
|
|
13673
|
+
}
|
|
13674
|
+
if (input.content !== "" && nextContent === "") {
|
|
13675
|
+
throw new DomainError("E_EMPTY_RANGE", {});
|
|
13676
|
+
}
|
|
13677
|
+
const removedHashes = new Set(input.hashes.slice(item.startLine - 1, item.endLine));
|
|
13678
|
+
const nextHashes = await defaultHashIdentity.hashesFor(nextContent, {
|
|
13679
|
+
path: input.absolutePath,
|
|
13680
|
+
prior: { content: input.content, hashes: input.hashes, removedHashes },
|
|
13681
|
+
persist: false,
|
|
13682
|
+
snapshotIO: snapshotIOFor(input.store),
|
|
13683
|
+
// SAFETY: the options object is typed by HashIdentity's internal parameter shape, which the caller
|
|
13684
|
+
// SAFETY: never sees; every field above is already typed, so the cast widens nothing.
|
|
13685
|
+
blockedHashes: input.blockedHashes
|
|
13686
|
+
});
|
|
13687
|
+
const changed = changedRange(input.content, nextContent);
|
|
13688
|
+
return {
|
|
13689
|
+
kind: "applied",
|
|
13690
|
+
content: nextContent,
|
|
13691
|
+
hashes: nextHashes,
|
|
13692
|
+
removedHashes,
|
|
13693
|
+
range,
|
|
13694
|
+
firstChangedLine: changed?.firstChangedLine,
|
|
13695
|
+
lastChangedLine: changed?.lastChangedLine,
|
|
13696
|
+
anchorWarnings: warnings.length > 0 ? warnings : void 0,
|
|
13697
|
+
literalBypass,
|
|
13698
|
+
neverServedCount,
|
|
13699
|
+
sourceRange: void 0,
|
|
13700
|
+
mutationSpans: void 0,
|
|
13701
|
+
// WHY: the loop's fallback counts the item's own target span, which for an expansion is the one
|
|
13702
|
+
// WHY: anchor line rather than the whole item; the expansion reports its honest counts instead.
|
|
13703
|
+
mutationStats: {
|
|
13704
|
+
addedLines: replacement.length,
|
|
13705
|
+
removedLines: item.endLine - item.startLine + 1
|
|
13706
|
+
},
|
|
13707
|
+
...indent !== void 0 ? { indent } : {}
|
|
13708
|
+
};
|
|
13709
|
+
}
|
|
13710
|
+
|
|
13190
13711
|
// src/mutation-engine/pipeline.ts
|
|
13191
13712
|
function collectRemovedHashes(edit, originalHashes) {
|
|
13192
13713
|
const removedHashes = /* @__PURE__ */ new Set();
|
|
@@ -13223,6 +13744,31 @@ function countLineChanges(edit, originalHashes, isNoop) {
|
|
|
13223
13744
|
totalRemovedLines
|
|
13224
13745
|
};
|
|
13225
13746
|
}
|
|
13747
|
+
function autoIndentedEdit(input, identity) {
|
|
13748
|
+
if (input.edit.content_lines.length === 0) return { edit: input.edit };
|
|
13749
|
+
const fileLines = splitLines(input.content);
|
|
13750
|
+
const leased = resolveLeasedEdit({
|
|
13751
|
+
edit: {
|
|
13752
|
+
content_lines: [],
|
|
13753
|
+
hash_bounds: [input.edit.hash_bounds[0], input.edit.hash_bounds[0]]
|
|
13754
|
+
},
|
|
13755
|
+
snapshot: { fileHashes: input.hashes, fileLines, filePath: input.absolutePath },
|
|
13756
|
+
served: input.served,
|
|
13757
|
+
source: identity
|
|
13758
|
+
});
|
|
13759
|
+
const anchorLine = leased.resolved.hash_bounds[0].line;
|
|
13760
|
+
const baseIndent = leadingWhitespaceOf(fileLines[anchorLine - 1] ?? "");
|
|
13761
|
+
const rebased = applyAutoIndent(input.edit.content_lines.join("\n"), baseIndent);
|
|
13762
|
+
if (!rebased.changed) return { edit: input.edit };
|
|
13763
|
+
return {
|
|
13764
|
+
edit: { ...input.edit, content_lines: rebased.text.split("\n") },
|
|
13765
|
+
indent: {
|
|
13766
|
+
baseIndent,
|
|
13767
|
+
strippedPrefix: rebased.strippedPrefix,
|
|
13768
|
+
changedLines: rebased.changedLines
|
|
13769
|
+
}
|
|
13770
|
+
};
|
|
13771
|
+
}
|
|
13226
13772
|
async function applyOneEdit(input) {
|
|
13227
13773
|
abortIf(input.signal);
|
|
13228
13774
|
const identity = leaseSpanSource({
|
|
@@ -13232,9 +13778,12 @@ async function applyOneEdit(input) {
|
|
|
13232
13778
|
content: input.content,
|
|
13233
13779
|
...input.currentIds !== void 0 ? { currentIds: input.currentIds } : {}
|
|
13234
13780
|
});
|
|
13781
|
+
let indent;
|
|
13235
13782
|
let anchorResult;
|
|
13236
13783
|
try {
|
|
13237
|
-
|
|
13784
|
+
const prepared = input.indent === "auto" ? autoIndentedEdit(input, identity) : { edit: input.edit };
|
|
13785
|
+
indent = prepared.indent;
|
|
13786
|
+
anchorResult = applyEdit(input.content, prepared.edit, input.signal, input.hashes, {
|
|
13238
13787
|
// WHY: read/write agreement — the verify path is literally the same
|
|
13239
13788
|
// WHY: canonical absolute path the `hashesFor` call below uses (one field).
|
|
13240
13789
|
filePath: input.absolutePath,
|
|
@@ -13270,7 +13819,8 @@ async function applyOneEdit(input) {
|
|
|
13270
13819
|
noopEdit: anchorResult.noopEdit,
|
|
13271
13820
|
anchorWarnings,
|
|
13272
13821
|
literalBypass,
|
|
13273
|
-
neverServedCount
|
|
13822
|
+
neverServedCount,
|
|
13823
|
+
...indent !== void 0 ? { indent } : {}
|
|
13274
13824
|
};
|
|
13275
13825
|
}
|
|
13276
13826
|
if (!input.hashes || input.hashes.length === 0)
|
|
@@ -13305,7 +13855,8 @@ async function applyOneEdit(input) {
|
|
|
13305
13855
|
neverServedCount,
|
|
13306
13856
|
sourceRange: anchorResult.sourceRange,
|
|
13307
13857
|
mutationSpans: anchorResult.mutationSpans,
|
|
13308
|
-
mutationStats: anchorResult.mutationStats
|
|
13858
|
+
mutationStats: anchorResult.mutationStats,
|
|
13859
|
+
...indent !== void 0 ? { indent } : {}
|
|
13309
13860
|
};
|
|
13310
13861
|
}
|
|
13311
13862
|
async function recordRejectionServe(args) {
|
|
@@ -13602,7 +14153,8 @@ async function runMutations(request, cwd, options, itemNumbers) {
|
|
|
13602
14153
|
fileHashes: originalHashes,
|
|
13603
14154
|
hadUtf8DecodeErrors,
|
|
13604
14155
|
absolutePath,
|
|
13605
|
-
served
|
|
14156
|
+
served,
|
|
14157
|
+
canonDigests
|
|
13606
14158
|
} = await loadEditFile({
|
|
13607
14159
|
path,
|
|
13608
14160
|
cwd,
|
|
@@ -13691,28 +14243,73 @@ async function runMutations(request, cwd, options, itemNumbers) {
|
|
|
13691
14243
|
continue;
|
|
13692
14244
|
}
|
|
13693
14245
|
const edit = parsedItem.edit;
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13698
|
-
|
|
13699
|
-
|
|
13700
|
-
|
|
13701
|
-
|
|
13702
|
-
|
|
13703
|
-
|
|
13704
|
-
|
|
13705
|
-
|
|
13706
|
-
|
|
13707
|
-
|
|
13708
|
-
|
|
13709
|
-
|
|
13710
|
-
|
|
13711
|
-
|
|
14246
|
+
let outcome;
|
|
14247
|
+
if (item.expand === "item") {
|
|
14248
|
+
try {
|
|
14249
|
+
outcome = await applyExpandedItem({
|
|
14250
|
+
edit,
|
|
14251
|
+
...item.indent !== void 0 ? { indent: item.indent } : {},
|
|
14252
|
+
content: currentContent,
|
|
14253
|
+
hashes: currentHashes,
|
|
14254
|
+
served,
|
|
14255
|
+
canonDigests,
|
|
14256
|
+
identity: leaseSpanSource({
|
|
14257
|
+
store: hashStore,
|
|
14258
|
+
sessionKey,
|
|
14259
|
+
absolutePath,
|
|
14260
|
+
content: currentContent,
|
|
14261
|
+
...isPreview ? {} : { currentIds }
|
|
14262
|
+
}),
|
|
14263
|
+
absolutePath,
|
|
14264
|
+
filePath: path,
|
|
14265
|
+
mode,
|
|
14266
|
+
sessionKey,
|
|
14267
|
+
store: hashStore,
|
|
14268
|
+
blockedHashes: batchBlockedHashes,
|
|
14269
|
+
provider: options?.spanProvider,
|
|
14270
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {}
|
|
14271
|
+
});
|
|
14272
|
+
} catch (error) {
|
|
14273
|
+
if (!(error instanceof DomainError)) throw error;
|
|
14274
|
+
await recordRejectionServe({
|
|
14275
|
+
error,
|
|
14276
|
+
sessionKey,
|
|
14277
|
+
absolutePath,
|
|
14278
|
+
isPreview,
|
|
14279
|
+
lineCount: currentHashes.length,
|
|
14280
|
+
contentHash: isPreview ? void 0 : snapshotHashFor(currentContent)
|
|
14281
|
+
});
|
|
13712
14282
|
if (items.length === 1) throw error;
|
|
13713
14283
|
throw batchAbortFor({ error, index: number, path });
|
|
13714
14284
|
}
|
|
13715
|
-
}
|
|
14285
|
+
} else {
|
|
14286
|
+
outcome = await applyOneEdit({
|
|
14287
|
+
content: currentContent,
|
|
14288
|
+
hashes: currentHashes,
|
|
14289
|
+
edit,
|
|
14290
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
14291
|
+
served,
|
|
14292
|
+
blockedHashes: batchBlockedHashes,
|
|
14293
|
+
canonDigests: baseCanonDigests,
|
|
14294
|
+
sessionKey,
|
|
14295
|
+
absolutePath,
|
|
14296
|
+
store: hashStore,
|
|
14297
|
+
isPreview,
|
|
14298
|
+
mode,
|
|
14299
|
+
...item.indent !== void 0 ? { indent: item.indent } : {},
|
|
14300
|
+
// WHY: the intermediate buffer is in-memory only, so its identities come from the buffer map
|
|
14301
|
+
// WHY: (`null` lines are the batch's own creations) — a re-diff of it against S_latest cannot
|
|
14302
|
+
// WHY: tell which of two byte-identical lines carries a leased line_id.
|
|
14303
|
+
...isPreview ? {} : { currentIds },
|
|
14304
|
+
onRejected: async (error) => {
|
|
14305
|
+
if (items.length === 1) throw error;
|
|
14306
|
+
throw batchAbortFor({ error, index: number, path });
|
|
14307
|
+
}
|
|
14308
|
+
});
|
|
14309
|
+
}
|
|
14310
|
+
if (outcome.kind === "applied" && outcome.indent !== void 0) {
|
|
14311
|
+
warnings.push(buildIndentNote({ ref: `edit[${number}] (${path})`, summary: outcome.indent }));
|
|
14312
|
+
}
|
|
13716
14313
|
const range = outcome.range;
|
|
13717
14314
|
const coveredRanges = outcome.kind === "applied" && outcome.sourceRange ? [range, outcome.sourceRange] : [range];
|
|
13718
14315
|
editedIntervals.push(...coveredRanges);
|
|
@@ -15150,8 +15747,8 @@ function isRec(value) {
|
|
|
15150
15747
|
function isNormalizedEdit(input) {
|
|
15151
15748
|
return isRec(input) && input[normalizedEdit] === true;
|
|
15152
15749
|
}
|
|
15153
|
-
var ITEM_SHAPE =
|
|
15154
|
-
var EDIT_PAYLOAD_HINT = `Edit must be called with exactly one payload per item, and each call edits ONE file. Use the canonical payload {"file": file, "edits": [{ "anchor_from": anchor_from, "anchor_to": anchor_to, "text": text }, ...], "mode"?: "general" | "literal"}: "file" is the text file to edit (a non-empty string, never a directory); each item names the bare-${HASH_LEN}-char anchor "anchor_from" (the first line of the range, and the whole range of a single-line edit), an optional second bare anchor "anchor_to" (the last line of a multi-line range; omit it to edit "anchor_from" alone) and exactly one payload \u2014 "text" (bare replacement content; an empty string deletes the range), "text_ref" ({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } \u2014 the served span's bytes, whose two bounds are always required, and whose "file" may name another served file as the copy/cut source), or an insertion slot "after"/"before" (the exact lines to insert below/above the single anchor line, which is never restated); optional "at" is "in-place" (default), "before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced served rows are refused) or "literal" (declared literal content).`;
|
|
15750
|
+
var ITEM_SHAPE = 'an item is one payload over its anchor pair \u2014 `text` (optionally with `indent: "auto"` and, alone, `expand: "item"`), `text_ref`, or one insertion slot `after`/`before` (optionally with `indent: "auto"`) \u2014 plus optional `at`';
|
|
15751
|
+
var EDIT_PAYLOAD_HINT = `Edit must be called with exactly one payload per item, and each call edits ONE file. Use the canonical payload {"file": file, "edits": [{ "anchor_from": anchor_from, "anchor_to": anchor_to, "text": text }, ...], "mode"?: "general" | "literal"}: "file" is the text file to edit (a non-empty string, never a directory); each item names the bare-${HASH_LEN}-char anchor "anchor_from" (the first line of the range, and the whole range of a single-line edit), an optional second bare anchor "anchor_to" (the last line of a multi-line range; omit it to edit "anchor_from" alone) and exactly one payload \u2014 "text" (bare replacement content; an empty string deletes the range), "text_ref" ({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } \u2014 the served span's bytes, whose two bounds are always required, and whose "file" may name another served file as the copy/cut source), or an insertion slot "after"/"before" (the exact lines to insert below/above the single anchor line, which is never restated); optional "at" is "in-place" (default), "before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced served rows are refused) or "literal" (declared literal content); optional "indent": "auto" re-bases a "text"/"after"/"before" payload on the leading whitespace of the line "anchor_from" names, and optional "expand": "item" replaces the whole syntax item around "anchor_from" (in-place "text" only: "anchor_to" is refused because the AST decides the end).`;
|
|
15155
15752
|
function describeReceived(input) {
|
|
15156
15753
|
if (input === void 0) return "Received no arguments.";
|
|
15157
15754
|
if (input === null) return "Received null.";
|
|
@@ -15226,7 +15823,16 @@ function isAbsentValue(value) {
|
|
|
15226
15823
|
}
|
|
15227
15824
|
function foldAbsentSlots(item) {
|
|
15228
15825
|
const folded = { ...item };
|
|
15229
|
-
for (const key of [
|
|
15826
|
+
for (const key of [
|
|
15827
|
+
"text",
|
|
15828
|
+
"text_ref",
|
|
15829
|
+
"at",
|
|
15830
|
+
"anchor_to",
|
|
15831
|
+
"after",
|
|
15832
|
+
"before",
|
|
15833
|
+
"indent",
|
|
15834
|
+
"expand"
|
|
15835
|
+
]) {
|
|
15230
15836
|
if (isAbsentValue(folded[key])) delete folded[key];
|
|
15231
15837
|
}
|
|
15232
15838
|
if (isRec(folded.text_ref)) {
|
|
@@ -15240,7 +15846,8 @@ function analyzeItem(value, index) {
|
|
|
15240
15846
|
if (!isRec(value)) {
|
|
15241
15847
|
return `edit[${index}] must be an object: ${ITEM_SHAPE}.`;
|
|
15242
15848
|
}
|
|
15243
|
-
const
|
|
15849
|
+
const modifierKeys = /* @__PURE__ */ new Set(["indent", "expand"]);
|
|
15850
|
+
const keys = new Set(Object.keys(value).filter((key) => !modifierKeys.has(key)));
|
|
15244
15851
|
const hasText = keys.has("text");
|
|
15245
15852
|
const hasRef = keys.has("text_ref");
|
|
15246
15853
|
const hasAfter = keys.has("after");
|
|
@@ -15295,6 +15902,28 @@ function analyzeItem(value, index) {
|
|
|
15295
15902
|
return `edit[${index}] "at" must be "in-place", "before" or "after" when present.`;
|
|
15296
15903
|
}
|
|
15297
15904
|
}
|
|
15905
|
+
const indentValue = value.indent;
|
|
15906
|
+
if (indentValue !== void 0 && indentValue !== "auto") {
|
|
15907
|
+
return `edit[${index}] "indent" must be "auto" when present ("as-is" is the default and may be omitted).`;
|
|
15908
|
+
}
|
|
15909
|
+
const expandValue = value.expand;
|
|
15910
|
+
if (expandValue !== void 0 && expandValue !== "item") {
|
|
15911
|
+
return `edit[${index}] "expand" must be "item" when present: it replaces the whole syntax item that contains "anchor_from".`;
|
|
15912
|
+
}
|
|
15913
|
+
const wantsAutoIndent = indentValue === "auto";
|
|
15914
|
+
const wantsExpand = expandValue === "item";
|
|
15915
|
+
if (wantsExpand && anchor_to !== void 0) {
|
|
15916
|
+
return `edit[${index}] "expand": "item" takes only "anchor_from": the syntax item's own span decides the end, so delete "anchor_to" from the item.`;
|
|
15917
|
+
}
|
|
15918
|
+
if (wantsExpand && (hasRef || hasInsert || at !== void 0 && at !== "in-place")) {
|
|
15919
|
+
return `edit[${index}] "expand": "item" replaces the whole syntax item with "text", so it takes no "text_ref", "after", "before" or "at": keep "text" and delete the other payload and placement fields.`;
|
|
15920
|
+
}
|
|
15921
|
+
if (wantsAutoIndent && hasRef) {
|
|
15922
|
+
return `edit[${index}] "indent" does not apply to "text_ref": the referenced served bytes are copied verbatim. Delete "indent" from the item, or send the lines as "text" to have them re-indented.`;
|
|
15923
|
+
}
|
|
15924
|
+
if (wantsAutoIndent && hasText && text === "") {
|
|
15925
|
+
return `edit[${index}] "indent" has no lines to indent: "text": "" is the deletion payload. Delete "indent" from the item.`;
|
|
15926
|
+
}
|
|
15298
15927
|
if (hasInsert) {
|
|
15299
15928
|
if (hasAfter && hasBefore) {
|
|
15300
15929
|
return `edit[${index}] carries both "after" and "before": an insertion picks one side. Keep "after" to add lines below "anchor_from", or "before" to add them above, and delete the other.`;
|
|
@@ -15402,6 +16031,11 @@ function analyzeRequest(input) {
|
|
|
15402
16031
|
}
|
|
15403
16032
|
edited.push(item);
|
|
15404
16033
|
}
|
|
16034
|
+
if (items.length > 1 && edited.some((item) => item.expand === "item")) {
|
|
16035
|
+
failures.push(
|
|
16036
|
+
`Edit request carries "expand": "item" in a call with ${items.length} items: an expanded item must be the only item in the call \u2014 send one expand edit per call.`
|
|
16037
|
+
);
|
|
16038
|
+
}
|
|
15405
16039
|
if (failures.length > 0) {
|
|
15406
16040
|
return { ok: false, message: `${failures.join(" ")} ${describeReceived(input)}` };
|
|
15407
16041
|
}
|
|
@@ -15418,7 +16052,9 @@ function normalizedItemFrom(item) {
|
|
|
15418
16052
|
return {
|
|
15419
16053
|
target,
|
|
15420
16054
|
at,
|
|
15421
|
-
payload
|
|
16055
|
+
payload,
|
|
16056
|
+
...item.indent === "auto" ? { indent: item.indent } : {},
|
|
16057
|
+
...item.expand === "item" ? { expand: item.expand } : {}
|
|
15422
16058
|
};
|
|
15423
16059
|
}
|
|
15424
16060
|
function normReq(input) {
|
|
@@ -15446,6 +16082,8 @@ function isPlacementValue(value) {
|
|
|
15446
16082
|
}
|
|
15447
16083
|
function isNormalizedEditItem(value) {
|
|
15448
16084
|
if (!isRec(value)) return false;
|
|
16085
|
+
if (value.indent !== void 0 && value.indent !== "auto") return false;
|
|
16086
|
+
if (value.expand !== void 0 && value.expand !== "item") return false;
|
|
15449
16087
|
const { target, at, payload } = value;
|
|
15450
16088
|
if (!isRec(target)) return false;
|
|
15451
16089
|
if (typeof target.anchor_from !== "string" || typeof target.anchor_to !== "string") return false;
|
|
@@ -15608,7 +16246,7 @@ function isMutationSuccess(r) {
|
|
|
15608
16246
|
}
|
|
15609
16247
|
|
|
15610
16248
|
// src/edit-tool.ts
|
|
15611
|
-
function createEditTool() {
|
|
16249
|
+
function createEditTool(options = {}) {
|
|
15612
16250
|
return {
|
|
15613
16251
|
async execute(params, signal, ctx) {
|
|
15614
16252
|
const canonical = normReq(params);
|
|
@@ -15620,7 +16258,8 @@ function createEditTool() {
|
|
|
15620
16258
|
accessMode: constants7.R_OK | constants7.W_OK,
|
|
15621
16259
|
// SAFETY: signal is AbortSignal | undefined at pi boundary — runtime check via engine's abortIf
|
|
15622
16260
|
...signal !== void 0 ? { signal } : {},
|
|
15623
|
-
sessionKey
|
|
16261
|
+
sessionKey,
|
|
16262
|
+
...options.spanProvider !== void 0 ? { spanProvider: options.spanProvider } : {}
|
|
15624
16263
|
});
|
|
15625
16264
|
if (isMutationSuccess(result)) {
|
|
15626
16265
|
return result.toolResult;
|
|
@@ -15643,7 +16282,8 @@ function createEditTool() {
|
|
|
15643
16282
|
assertReq(normalized);
|
|
15644
16283
|
const result = await preview(normalized, cwd, {
|
|
15645
16284
|
accessMode: constants7.R_OK,
|
|
15646
|
-
sessionKey: sessionKeyFor(ctx)
|
|
16285
|
+
sessionKey: sessionKeyFor(ctx),
|
|
16286
|
+
...options.spanProvider !== void 0 ? { spanProvider: options.spanProvider } : {}
|
|
15647
16287
|
});
|
|
15648
16288
|
if (!isMutationSuccess(result)) {
|
|
15649
16289
|
return { error: result.message };
|
|
@@ -15870,6 +16510,26 @@ var EDIT_PARAMETERS = {
|
|
|
15870
16510
|
},
|
|
15871
16511
|
{ type: "null" }
|
|
15872
16512
|
]
|
|
16513
|
+
},
|
|
16514
|
+
indent: {
|
|
16515
|
+
oneOf: [
|
|
16516
|
+
{
|
|
16517
|
+
type: "string",
|
|
16518
|
+
enum: ["as-is", "auto"],
|
|
16519
|
+
description: '"auto" re-bases the payload on the leading whitespace of the anchor_from line; "as-is" (the default) writes it verbatim'
|
|
16520
|
+
},
|
|
16521
|
+
{ type: "null" }
|
|
16522
|
+
]
|
|
16523
|
+
},
|
|
16524
|
+
expand: {
|
|
16525
|
+
oneOf: [
|
|
16526
|
+
{
|
|
16527
|
+
type: "string",
|
|
16528
|
+
enum: ["item"],
|
|
16529
|
+
description: '"item" replaces the whole syntax item that contains anchor_from (leading doc comment through closing brace); takes only anchor_from and text'
|
|
16530
|
+
},
|
|
16531
|
+
{ type: "null" }
|
|
16532
|
+
]
|
|
15873
16533
|
}
|
|
15874
16534
|
}
|
|
15875
16535
|
}
|
|
@@ -15903,8 +16563,10 @@ function writtenMemberFiles(admitted) {
|
|
|
15903
16563
|
return files;
|
|
15904
16564
|
}
|
|
15905
16565
|
var EDIT_TOOL_DESCRIPTION = loadP("../prompts/edit.md");
|
|
15906
|
-
function buildEditTool(deps) {
|
|
15907
|
-
const tool = createEditTool(
|
|
16566
|
+
function buildEditTool(deps, options = {}) {
|
|
16567
|
+
const tool = createEditTool(
|
|
16568
|
+
options.spanProvider === void 0 ? {} : { spanProvider: options.spanProvider }
|
|
16569
|
+
);
|
|
15908
16570
|
const sandboxFields = deps.sandbox.escalationModes.length > 0 ? deps.sandbox.schemaFields() : {};
|
|
15909
16571
|
return defineTool3({
|
|
15910
16572
|
name: EDIT_TOOL_NAME,
|
|
@@ -16026,25 +16688,1826 @@ function admit2(args) {
|
|
|
16026
16688
|
}
|
|
16027
16689
|
}
|
|
16028
16690
|
|
|
16029
|
-
// dsh/
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16033
|
-
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16691
|
+
// dsh/codegraph/cli.ts
|
|
16692
|
+
import { spawn } from "node:child_process";
|
|
16693
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
16694
|
+
import { dirname as dirname10, extname, join as join10 } from "node:path";
|
|
16695
|
+
var PACKAGE_SCRIPT = join10(
|
|
16696
|
+
"node_modules",
|
|
16697
|
+
"@colbymchenry",
|
|
16698
|
+
"codegraph",
|
|
16699
|
+
"dist",
|
|
16700
|
+
"bin",
|
|
16701
|
+
"codegraph.js"
|
|
16702
|
+
);
|
|
16703
|
+
var BUNDLED_SCRIPT = join10("lib", "dist", "bin", "codegraph.js");
|
|
16704
|
+
var WINDOWS_SHIM_NAMES = [
|
|
16705
|
+
"codegraph.cmd",
|
|
16706
|
+
"codegraph.exe",
|
|
16707
|
+
"codegraph.bat",
|
|
16708
|
+
"codegraph"
|
|
16709
|
+
];
|
|
16710
|
+
var POSIX_SHIM_NAMES = ["codegraph"];
|
|
16711
|
+
function isScript(entry) {
|
|
16712
|
+
const ext = extname(entry).toLowerCase();
|
|
16713
|
+
return ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
16714
|
+
}
|
|
16715
|
+
function isCommandShim(entry) {
|
|
16716
|
+
const lower = entry.toLowerCase();
|
|
16717
|
+
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
16718
|
+
}
|
|
16719
|
+
function invocationOf(entry, platform, exists) {
|
|
16720
|
+
if (isScript(entry)) return { command: process.execPath, prefixArgs: [entry], source: entry };
|
|
16721
|
+
if (!isCommandShim(entry)) {
|
|
16722
|
+
if (platform === "win32" && !entry.toLowerCase().endsWith(".exe")) return void 0;
|
|
16723
|
+
return { command: entry, prefixArgs: [], source: entry };
|
|
16724
|
+
}
|
|
16725
|
+
const binDir = dirname10(entry);
|
|
16726
|
+
const installRoot = dirname10(binDir);
|
|
16727
|
+
const candidates = [
|
|
16728
|
+
{ command: join10(installRoot, "node.exe"), script: join10(installRoot, BUNDLED_SCRIPT) },
|
|
16729
|
+
{ command: process.execPath, script: join10(binDir, PACKAGE_SCRIPT) },
|
|
16730
|
+
{ command: process.execPath, script: join10(installRoot, PACKAGE_SCRIPT) }
|
|
16731
|
+
];
|
|
16732
|
+
for (const candidate of candidates) {
|
|
16733
|
+
if (!exists(candidate.script)) continue;
|
|
16734
|
+
if (candidate.command !== process.execPath && !exists(candidate.command)) continue;
|
|
16735
|
+
return { command: candidate.command, prefixArgs: [candidate.script], source: entry };
|
|
16736
|
+
}
|
|
16737
|
+
return void 0;
|
|
16040
16738
|
}
|
|
16041
|
-
function
|
|
16042
|
-
const
|
|
16043
|
-
const
|
|
16044
|
-
const
|
|
16045
|
-
|
|
16046
|
-
|
|
16047
|
-
|
|
16739
|
+
function resolveCodegraphInvocation(options = {}) {
|
|
16740
|
+
const platform = options.platform ?? process.platform;
|
|
16741
|
+
const exists = options.exists ?? existsSync5;
|
|
16742
|
+
const explicit = options.explicitPath?.trim() ?? "";
|
|
16743
|
+
if (explicit !== "") {
|
|
16744
|
+
if (!exists(explicit)) {
|
|
16745
|
+
return { ok: false, problem: `codegraphPath points at "${explicit}", which does not exist` };
|
|
16746
|
+
}
|
|
16747
|
+
const invocation = invocationOf(explicit, platform, exists);
|
|
16748
|
+
if (invocation === void 0) {
|
|
16749
|
+
return {
|
|
16750
|
+
ok: false,
|
|
16751
|
+
problem: `codegraphPath "${explicit}" is not a runnable codegraph entry point`
|
|
16752
|
+
};
|
|
16753
|
+
}
|
|
16754
|
+
return { ok: true, invocation };
|
|
16755
|
+
}
|
|
16756
|
+
const pathValue = options.pathValue ?? process.env.PATH ?? "";
|
|
16757
|
+
const separator = platform === "win32" ? ";" : ":";
|
|
16758
|
+
const names = platform === "win32" ? WINDOWS_SHIM_NAMES : POSIX_SHIM_NAMES;
|
|
16759
|
+
for (const directory of pathValue.split(separator)) {
|
|
16760
|
+
if (directory === "") continue;
|
|
16761
|
+
for (const name2 of names) {
|
|
16762
|
+
const entry = join10(directory, name2);
|
|
16763
|
+
if (!exists(entry)) continue;
|
|
16764
|
+
const invocation = invocationOf(entry, platform, exists);
|
|
16765
|
+
if (invocation !== void 0) return { ok: true, invocation };
|
|
16766
|
+
}
|
|
16767
|
+
}
|
|
16768
|
+
return { ok: false, problem: "no codegraph executable was found on PATH" };
|
|
16769
|
+
}
|
|
16770
|
+
var CODEGRAPH_TIMEOUT_MS = 12e4;
|
|
16771
|
+
var MAX_CAPTURE_CHARS = 2e6;
|
|
16772
|
+
function runCodegraph(invocation, args, options) {
|
|
16773
|
+
options.signal?.throwIfAborted();
|
|
16774
|
+
const timeoutMs = options.timeoutMs ?? CODEGRAPH_TIMEOUT_MS;
|
|
16775
|
+
const env = {
|
|
16776
|
+
...process.env,
|
|
16777
|
+
// WHY: the CLI is a machine surface here; ANSI color would corrupt anchored rows.
|
|
16778
|
+
NO_COLOR: "1",
|
|
16779
|
+
FORCE_COLOR: "0",
|
|
16780
|
+
...options.env
|
|
16781
|
+
};
|
|
16782
|
+
return new Promise((resolve6, reject) => {
|
|
16783
|
+
const child = spawn(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
16784
|
+
cwd: options.cwd,
|
|
16785
|
+
env,
|
|
16786
|
+
windowsHide: true,
|
|
16787
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
16788
|
+
});
|
|
16789
|
+
let stdout = "";
|
|
16790
|
+
let stderr = "";
|
|
16791
|
+
let timedOut = false;
|
|
16792
|
+
let settled = false;
|
|
16793
|
+
const capture = (current, chunk) => current.length >= MAX_CAPTURE_CHARS ? current : (current + chunk).slice(0, MAX_CAPTURE_CHARS);
|
|
16794
|
+
const stop = () => {
|
|
16795
|
+
if (settled) return;
|
|
16796
|
+
settled = true;
|
|
16797
|
+
clearTimeout(timer);
|
|
16798
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
16799
|
+
};
|
|
16800
|
+
const onAbort = () => {
|
|
16801
|
+
child.kill();
|
|
16802
|
+
stop();
|
|
16803
|
+
reject(options.signal?.reason ?? new Error("codegraph call aborted"));
|
|
16804
|
+
};
|
|
16805
|
+
const timer = setTimeout(() => {
|
|
16806
|
+
timedOut = true;
|
|
16807
|
+
child.kill();
|
|
16808
|
+
}, timeoutMs);
|
|
16809
|
+
child.stdout?.setEncoding("utf8");
|
|
16810
|
+
child.stderr?.setEncoding("utf8");
|
|
16811
|
+
child.stdout?.on("data", (chunk) => {
|
|
16812
|
+
stdout = capture(stdout, chunk);
|
|
16813
|
+
});
|
|
16814
|
+
child.stderr?.on("data", (chunk) => {
|
|
16815
|
+
stderr = capture(stderr, chunk);
|
|
16816
|
+
});
|
|
16817
|
+
child.on("error", (error) => {
|
|
16818
|
+
stop();
|
|
16819
|
+
reject(error);
|
|
16820
|
+
});
|
|
16821
|
+
child.on("close", (code) => {
|
|
16822
|
+
if (settled) return;
|
|
16823
|
+
stop();
|
|
16824
|
+
resolve6({ stdout, stderr, code, timedOut });
|
|
16825
|
+
});
|
|
16826
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
16827
|
+
});
|
|
16828
|
+
}
|
|
16829
|
+
|
|
16830
|
+
// dsh/rg/cli.ts
|
|
16831
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
16832
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
16833
|
+
import { join as join11 } from "node:path";
|
|
16834
|
+
var WINDOWS_RG_NAMES = ["rg.exe", "rg", "rg.cmd", "rg.bat"];
|
|
16835
|
+
var POSIX_RG_NAMES = ["rg"];
|
|
16836
|
+
function isCommandShim2(entry) {
|
|
16837
|
+
const lower = entry.toLowerCase();
|
|
16838
|
+
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
16839
|
+
}
|
|
16840
|
+
function resolveRgInvocation(options = {}) {
|
|
16841
|
+
const platform = options.platform ?? process.platform;
|
|
16842
|
+
const exists = options.exists ?? existsSync6;
|
|
16843
|
+
const explicit = options.explicitPath?.trim() ?? "";
|
|
16844
|
+
if (explicit !== "") {
|
|
16845
|
+
if (!exists(explicit)) {
|
|
16846
|
+
return { ok: false, problem: `rgPath points at "${explicit}", which does not exist` };
|
|
16847
|
+
}
|
|
16848
|
+
if (isCommandShim2(explicit)) {
|
|
16849
|
+
return {
|
|
16850
|
+
ok: false,
|
|
16851
|
+
problem: `rgPath "${explicit}" is a shell shim; point it at rg.exe instead`
|
|
16852
|
+
};
|
|
16853
|
+
}
|
|
16854
|
+
return { ok: true, invocation: { command: explicit, prefixArgs: [], source: explicit } };
|
|
16855
|
+
}
|
|
16856
|
+
const pathValue = options.pathValue ?? process.env.PATH ?? "";
|
|
16857
|
+
const separator = platform === "win32" ? ";" : ":";
|
|
16858
|
+
const names = platform === "win32" ? WINDOWS_RG_NAMES : POSIX_RG_NAMES;
|
|
16859
|
+
let shim;
|
|
16860
|
+
for (const directory of pathValue.split(separator)) {
|
|
16861
|
+
if (directory === "") continue;
|
|
16862
|
+
for (const name2 of names) {
|
|
16863
|
+
const entry = join11(directory, name2);
|
|
16864
|
+
if (!exists(entry)) continue;
|
|
16865
|
+
if (isCommandShim2(entry)) {
|
|
16866
|
+
shim ??= entry;
|
|
16867
|
+
continue;
|
|
16868
|
+
}
|
|
16869
|
+
return { ok: true, invocation: { command: entry, prefixArgs: [], source: entry } };
|
|
16870
|
+
}
|
|
16871
|
+
}
|
|
16872
|
+
if (shim !== void 0) {
|
|
16873
|
+
return {
|
|
16874
|
+
ok: false,
|
|
16875
|
+
problem: `only a shell shim was found at "${shim}"; put the real rg.exe on PATH`
|
|
16876
|
+
};
|
|
16877
|
+
}
|
|
16878
|
+
return { ok: false, problem: "no rg executable was found on PATH" };
|
|
16879
|
+
}
|
|
16880
|
+
var RG_TIMEOUT_MS = 3e4;
|
|
16881
|
+
var MAX_CAPTURE_CHARS2 = 8e6;
|
|
16882
|
+
function runRg(invocation, args, options) {
|
|
16883
|
+
options.signal?.throwIfAborted();
|
|
16884
|
+
const timeoutMs = options.timeoutMs ?? RG_TIMEOUT_MS;
|
|
16885
|
+
const env = {
|
|
16886
|
+
...process.env,
|
|
16887
|
+
// WHY: the transport is machine-read JSON; a colour escape would corrupt a parsed line.
|
|
16888
|
+
NO_COLOR: "1",
|
|
16889
|
+
FORCE_COLOR: "0",
|
|
16890
|
+
...options.env
|
|
16891
|
+
};
|
|
16892
|
+
return new Promise((resolve6, reject) => {
|
|
16893
|
+
const child = spawn2(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
16894
|
+
cwd: options.cwd,
|
|
16895
|
+
env,
|
|
16896
|
+
windowsHide: true,
|
|
16897
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
16898
|
+
});
|
|
16899
|
+
let stdout = "";
|
|
16900
|
+
let stderr = "";
|
|
16901
|
+
let timedOut = false;
|
|
16902
|
+
let overflow = false;
|
|
16903
|
+
let settled = false;
|
|
16904
|
+
const capture = (current, chunk) => {
|
|
16905
|
+
if (current.length >= MAX_CAPTURE_CHARS2) {
|
|
16906
|
+
overflow = true;
|
|
16907
|
+
return current;
|
|
16908
|
+
}
|
|
16909
|
+
const next = current + chunk;
|
|
16910
|
+
if (next.length > MAX_CAPTURE_CHARS2) {
|
|
16911
|
+
overflow = true;
|
|
16912
|
+
return next.slice(0, MAX_CAPTURE_CHARS2);
|
|
16913
|
+
}
|
|
16914
|
+
return next;
|
|
16915
|
+
};
|
|
16916
|
+
const stop = () => {
|
|
16917
|
+
if (settled) return;
|
|
16918
|
+
settled = true;
|
|
16919
|
+
clearTimeout(timer);
|
|
16920
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
16921
|
+
};
|
|
16922
|
+
const onAbort = () => {
|
|
16923
|
+
child.kill();
|
|
16924
|
+
stop();
|
|
16925
|
+
reject(options.signal?.reason ?? new Error("grep run aborted"));
|
|
16926
|
+
};
|
|
16927
|
+
const timer = setTimeout(() => {
|
|
16928
|
+
timedOut = true;
|
|
16929
|
+
child.kill();
|
|
16930
|
+
}, timeoutMs);
|
|
16931
|
+
child.stdout?.setEncoding("utf8");
|
|
16932
|
+
child.stderr?.setEncoding("utf8");
|
|
16933
|
+
child.stdout?.on("data", (chunk) => {
|
|
16934
|
+
stdout = capture(stdout, chunk);
|
|
16935
|
+
});
|
|
16936
|
+
child.stderr?.on("data", (chunk) => {
|
|
16937
|
+
stderr = capture(stderr, chunk);
|
|
16938
|
+
});
|
|
16939
|
+
child.on("error", (error) => {
|
|
16940
|
+
stop();
|
|
16941
|
+
reject(error);
|
|
16942
|
+
});
|
|
16943
|
+
child.on("close", (code) => {
|
|
16944
|
+
if (settled) return;
|
|
16945
|
+
stop();
|
|
16946
|
+
resolve6({ stdout, stderr, code, timedOut, overflow });
|
|
16947
|
+
});
|
|
16948
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
16949
|
+
});
|
|
16950
|
+
}
|
|
16951
|
+
|
|
16952
|
+
// dsh/codegraph/tools.ts
|
|
16953
|
+
import {
|
|
16954
|
+
defineTool as defineTool4
|
|
16955
|
+
} from "@deepseek-ai/dsh-tools";
|
|
16956
|
+
|
|
16957
|
+
// dsh/codegraph/project.ts
|
|
16958
|
+
import { dirname as dirname11, join as join12 } from "node:path";
|
|
16959
|
+
var CODEGRAPH_DIR = ".codegraph";
|
|
16960
|
+
var REPOSITORY_MARKER = ".git";
|
|
16961
|
+
async function resolveProjectPath(io, request) {
|
|
16962
|
+
const start = toCwd(request.requested ?? ".", request.cwd);
|
|
16963
|
+
let directory = start;
|
|
16964
|
+
let distance = 0;
|
|
16965
|
+
for (; ; ) {
|
|
16966
|
+
request.signal?.throwIfAborted();
|
|
16967
|
+
const index = await io.stat(join12(directory, CODEGRAPH_DIR), request.signal);
|
|
16968
|
+
const repository = await io.stat(join12(directory, REPOSITORY_MARKER), request.signal);
|
|
16969
|
+
const isRepository = repository !== void 0;
|
|
16970
|
+
if (index?.isDirectory === true && (distance === 0 || isRepository)) {
|
|
16971
|
+
return { ok: true, projectPath: directory, distance };
|
|
16972
|
+
}
|
|
16973
|
+
if (isRepository) return { ok: false, searchedFrom: start };
|
|
16974
|
+
const parent = dirname11(directory);
|
|
16975
|
+
if (parent === directory) return { ok: false, searchedFrom: start };
|
|
16976
|
+
directory = parent;
|
|
16977
|
+
distance += 1;
|
|
16978
|
+
}
|
|
16979
|
+
}
|
|
16980
|
+
|
|
16981
|
+
// dsh/codegraph/view.ts
|
|
16982
|
+
var FILE_HEADER = /^\*\*`(.+?)`\*\* — /u;
|
|
16983
|
+
var FILE_SUMMARY = /^\*\*(.+)\*\* — /u;
|
|
16984
|
+
var LOCATION = /^\*\*Location:\*\* (.+):(\d+)\b/u;
|
|
16985
|
+
var CONTEXT_HEADER = /^#### .+ \((.+):(\d+)\)$/u;
|
|
16986
|
+
var DRIFT_NOTICE = /^> .*?`([^`]+)` changed on disk/u;
|
|
16987
|
+
var NUMBERED_ROW = /^(\d+)\t(.*)$/u;
|
|
16988
|
+
var FENCE = /^```/u;
|
|
16989
|
+
function contextOf2(line) {
|
|
16990
|
+
const header = FILE_HEADER.exec(line);
|
|
16991
|
+
if (header !== null) return { file: header[1] ?? "", startLine: void 0 };
|
|
16992
|
+
const location = LOCATION.exec(line);
|
|
16993
|
+
if (location !== null) return { file: location[1] ?? "", startLine: void 0 };
|
|
16994
|
+
const summary = FILE_SUMMARY.exec(line);
|
|
16995
|
+
if (summary !== null) return { file: summary[1] ?? "", startLine: void 0 };
|
|
16996
|
+
const section = CONTEXT_HEADER.exec(line);
|
|
16997
|
+
if (section !== null) return { file: section[1] ?? "", startLine: Number(section[2] ?? 0) };
|
|
16998
|
+
const drift = DRIFT_NOTICE.exec(line);
|
|
16999
|
+
if (drift !== null) return { file: drift[1] ?? "", startLine: void 0 };
|
|
17000
|
+
return void 0;
|
|
17001
|
+
}
|
|
17002
|
+
function decodeOnce(state, file) {
|
|
17003
|
+
const cached = state.decoded.get(file);
|
|
17004
|
+
if (cached !== void 0) return cached;
|
|
17005
|
+
const pending = (async () => {
|
|
17006
|
+
try {
|
|
17007
|
+
return await decodeFileLines(state.deps, {
|
|
17008
|
+
path: file,
|
|
17009
|
+
cwd: state.projectPath,
|
|
17010
|
+
signal: state.signal
|
|
17011
|
+
});
|
|
17012
|
+
} catch {
|
|
17013
|
+
return void 0;
|
|
17014
|
+
}
|
|
17015
|
+
})();
|
|
17016
|
+
state.decoded.set(file, pending);
|
|
17017
|
+
return pending;
|
|
17018
|
+
}
|
|
17019
|
+
async function serveVerifiedRows(state, file, lineNumbers, texts) {
|
|
17020
|
+
if (lineNumbers.length === 0 || lineNumbers.length !== texts.length) return void 0;
|
|
17021
|
+
const disk = await decodeOnce(state, file);
|
|
17022
|
+
if (disk === void 0) return void 0;
|
|
17023
|
+
for (let index = 0; index < lineNumbers.length; index += 1) {
|
|
17024
|
+
const line = lineNumbers[index] ?? 0;
|
|
17025
|
+
if (line < 1 || line > disk.length) return void 0;
|
|
17026
|
+
if (disk[line - 1] !== (texts[index] ?? "")) return void 0;
|
|
17027
|
+
}
|
|
17028
|
+
const absolutePath = toCwd(file, state.projectPath);
|
|
17029
|
+
try {
|
|
17030
|
+
const served = await serveFileLines(state.deps, {
|
|
17031
|
+
path: absolutePath,
|
|
17032
|
+
cwd: state.projectPath,
|
|
17033
|
+
sessionKey: state.sessionKey,
|
|
17034
|
+
signal: state.signal,
|
|
17035
|
+
lineNumbers
|
|
17036
|
+
});
|
|
17037
|
+
if (served.length !== lineNumbers.length) return void 0;
|
|
17038
|
+
const hashes = new Map(served.map((row) => [row.line, row.hash]));
|
|
17039
|
+
const rows = [];
|
|
17040
|
+
for (let index = 0; index < lineNumbers.length; index += 1) {
|
|
17041
|
+
const hash = hashes.get(lineNumbers[index] ?? 0);
|
|
17042
|
+
if (hash === void 0) return void 0;
|
|
17043
|
+
rows.push(`${hash}${HASH_SEP}${texts[index] ?? ""}`);
|
|
17044
|
+
}
|
|
17045
|
+
state.served.add(absolutePath);
|
|
17046
|
+
return rows;
|
|
17047
|
+
} catch (error) {
|
|
17048
|
+
reportDiagnostic(
|
|
17049
|
+
"codegraph-view",
|
|
17050
|
+
`Could not serve ${file}; leaving the block as printed:`,
|
|
17051
|
+
error
|
|
17052
|
+
);
|
|
17053
|
+
return void 0;
|
|
17054
|
+
}
|
|
17055
|
+
}
|
|
17056
|
+
async function anchorRun(state, context, rows) {
|
|
17057
|
+
const file = context.file;
|
|
17058
|
+
if (file === void 0 || file === "" || rows.length === 0) return [...rows];
|
|
17059
|
+
const matches = rows.map((row) => NUMBERED_ROW.exec(row));
|
|
17060
|
+
if (matches.every((match) => match !== null)) {
|
|
17061
|
+
const lineNumbers = matches.map((match) => Number(match?.[1] ?? 0));
|
|
17062
|
+
const texts = matches.map((match) => match?.[2] ?? "");
|
|
17063
|
+
return await serveVerifiedRows(state, file, lineNumbers, texts) ?? [...rows];
|
|
17064
|
+
}
|
|
17065
|
+
if (matches.every((match) => match === null) && context.startLine !== void 0) {
|
|
17066
|
+
const startLine = context.startLine;
|
|
17067
|
+
const lineNumbers = rows.map((_row, index) => startLine + index);
|
|
17068
|
+
return await serveVerifiedRows(state, file, lineNumbers, [...rows]) ?? [...rows];
|
|
17069
|
+
}
|
|
17070
|
+
return [...rows];
|
|
17071
|
+
}
|
|
17072
|
+
async function anchorFencedBody(state, context, rows) {
|
|
17073
|
+
const numbered = rows.some((row) => NUMBERED_ROW.test(row));
|
|
17074
|
+
if (!numbered) return anchorRun(state, context, rows);
|
|
17075
|
+
const out = [];
|
|
17076
|
+
let index = 0;
|
|
17077
|
+
while (index < rows.length) {
|
|
17078
|
+
const row = rows[index] ?? "";
|
|
17079
|
+
if (!NUMBERED_ROW.test(row)) {
|
|
17080
|
+
out.push(row);
|
|
17081
|
+
index += 1;
|
|
17082
|
+
continue;
|
|
17083
|
+
}
|
|
17084
|
+
let end = index;
|
|
17085
|
+
while (end < rows.length && NUMBERED_ROW.test(rows[end] ?? "")) end += 1;
|
|
17086
|
+
out.push(...await anchorRun(state, context, rows.slice(index, end)));
|
|
17087
|
+
index = end;
|
|
17088
|
+
}
|
|
17089
|
+
return out;
|
|
17090
|
+
}
|
|
17091
|
+
async function anchorCodegraphView(deps, request) {
|
|
17092
|
+
const state = {
|
|
17093
|
+
deps,
|
|
17094
|
+
projectPath: request.projectPath,
|
|
17095
|
+
sessionKey: request.sessionKey,
|
|
17096
|
+
signal: request.signal,
|
|
17097
|
+
decoded: /* @__PURE__ */ new Map(),
|
|
17098
|
+
served: /* @__PURE__ */ new Set()
|
|
17099
|
+
};
|
|
17100
|
+
const lines = request.text.replace(/\r\n/gu, "\n").split("\n");
|
|
17101
|
+
const out = [];
|
|
17102
|
+
let context = { file: void 0, startLine: void 0 };
|
|
17103
|
+
let index = 0;
|
|
17104
|
+
while (index < lines.length) {
|
|
17105
|
+
const line = lines[index] ?? "";
|
|
17106
|
+
if (FENCE.test(line)) {
|
|
17107
|
+
let close = index + 1;
|
|
17108
|
+
while (close < lines.length && !FENCE.test(lines[close] ?? "")) close += 1;
|
|
17109
|
+
const body = lines.slice(index + 1, close);
|
|
17110
|
+
out.push(line, ...await anchorFencedBody(state, context, body));
|
|
17111
|
+
if (close < lines.length) {
|
|
17112
|
+
out.push(lines[close] ?? "");
|
|
17113
|
+
index = close + 1;
|
|
17114
|
+
} else {
|
|
17115
|
+
index = close;
|
|
17116
|
+
}
|
|
17117
|
+
continue;
|
|
17118
|
+
}
|
|
17119
|
+
const introduced = contextOf2(line);
|
|
17120
|
+
if (introduced !== void 0) {
|
|
17121
|
+
context = introduced;
|
|
17122
|
+
out.push(line);
|
|
17123
|
+
index += 1;
|
|
17124
|
+
continue;
|
|
17125
|
+
}
|
|
17126
|
+
if (context.file !== void 0 && NUMBERED_ROW.test(line)) {
|
|
17127
|
+
let end = index;
|
|
17128
|
+
while (end < lines.length && NUMBERED_ROW.test(lines[end] ?? "")) end += 1;
|
|
17129
|
+
out.push(...await anchorRun(state, context, lines.slice(index, end)));
|
|
17130
|
+
index = end;
|
|
17131
|
+
continue;
|
|
17132
|
+
}
|
|
17133
|
+
out.push(line);
|
|
17134
|
+
index += 1;
|
|
17135
|
+
}
|
|
17136
|
+
for (const absolutePath of state.served) {
|
|
17137
|
+
await deps.observations?.publish(
|
|
17138
|
+
absolutePath,
|
|
17139
|
+
request.exec,
|
|
17140
|
+
request.signal === void 0 ? void 0 : { signal: request.signal }
|
|
17141
|
+
);
|
|
17142
|
+
}
|
|
17143
|
+
return { text: out.join("\n"), servedFiles: [...state.served].sort() };
|
|
17144
|
+
}
|
|
17145
|
+
|
|
17146
|
+
// dsh/codegraph/tools.ts
|
|
17147
|
+
var OUTCOME_SCHEMA = {
|
|
17148
|
+
type: "object",
|
|
17149
|
+
properties: {
|
|
17150
|
+
text: { type: "string", required: true },
|
|
17151
|
+
projectPath: { type: "string" }
|
|
17152
|
+
},
|
|
17153
|
+
additionalProperties: false
|
|
17154
|
+
};
|
|
17155
|
+
var PROJECT_PATH_PARAMETER = {
|
|
17156
|
+
type: "string",
|
|
17157
|
+
description: "Project path whose `.codegraph` index to query. Defaults to the nearest index at or above the session working directory."
|
|
17158
|
+
};
|
|
17159
|
+
function stringArg(args, key) {
|
|
17160
|
+
const value = args[key];
|
|
17161
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
17162
|
+
}
|
|
17163
|
+
function numberArg(args, key) {
|
|
17164
|
+
const value = args[key];
|
|
17165
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
17166
|
+
}
|
|
17167
|
+
function booleanArg(args, key) {
|
|
17168
|
+
return args[key] === true;
|
|
17169
|
+
}
|
|
17170
|
+
function pushValue(argv, flag, value) {
|
|
17171
|
+
if (value === void 0) return;
|
|
17172
|
+
argv.push(flag, String(value));
|
|
17173
|
+
}
|
|
17174
|
+
function missingCliText(problem) {
|
|
17175
|
+
return [
|
|
17176
|
+
`codegraph is unavailable for this call: ${problem}.`,
|
|
17177
|
+
"Install codegraph 1.6.4 or newer, or point this plugin's `codegraphPath` config at its executable; indexing a repository stays the user's decision (`codegraph init`)."
|
|
17178
|
+
].join("\n\n");
|
|
17179
|
+
}
|
|
17180
|
+
function missingIndexText(searchedFrom) {
|
|
17181
|
+
return [
|
|
17182
|
+
`No \`.codegraph\` index was found at or above ${searchedFrom}. Nothing is indexed for this workspace, so the codegraph tools cannot answer.`,
|
|
17183
|
+
"Indexing is the user's decision: ask before running `codegraph init` in the repository root."
|
|
17184
|
+
].join("\n\n");
|
|
17185
|
+
}
|
|
17186
|
+
function timeoutText(subcommand, timeoutMs) {
|
|
17187
|
+
return `codegraph ${subcommand} did not finish within ${timeoutMs} ms and was stopped. Retry a narrower query, or use the built-in search tools for this call.`;
|
|
17188
|
+
}
|
|
17189
|
+
function failureText(subcommand, result) {
|
|
17190
|
+
const detail = result.stderr.trim() === "" ? result.stdout.trim() : result.stderr.trim();
|
|
17191
|
+
return [
|
|
17192
|
+
`codegraph ${subcommand} failed (exit ${result.code === null ? "signal" : result.code}).`,
|
|
17193
|
+
detail === "" ? "It printed no error text." : detail
|
|
17194
|
+
].join("\n\n");
|
|
17195
|
+
}
|
|
17196
|
+
function emptyText(subcommand) {
|
|
17197
|
+
return [
|
|
17198
|
+
`codegraph ${subcommand} returned no output. That usually means the query matched nothing in the index, or the index is stale.`,
|
|
17199
|
+
"Run `codegraph sync` in the project root to refresh an index that lags the working tree."
|
|
17200
|
+
].join("\n\n");
|
|
17201
|
+
}
|
|
17202
|
+
function launchFailureText(error) {
|
|
17203
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17204
|
+
return `codegraph could not be started: ${message}. Check the plugin's \`codegraphPath\` config and that the executable can run.`;
|
|
17205
|
+
}
|
|
17206
|
+
function withProjectNote(text, project) {
|
|
17207
|
+
if (project.distance === 0) return text;
|
|
17208
|
+
return `${text}
|
|
17209
|
+
|
|
17210
|
+
_(codegraph index: ${project.projectPath})_`;
|
|
17211
|
+
}
|
|
17212
|
+
async function executeQuery(deps, options, exec, query, rawArgs) {
|
|
17213
|
+
const args = typeof rawArgs === "object" && rawArgs !== null ? rawArgs : {};
|
|
17214
|
+
const planned = query.command(args);
|
|
17215
|
+
if (planned.problem !== void 0) return { text: planned.problem };
|
|
17216
|
+
const ctx = resolveToolContext(exec);
|
|
17217
|
+
const project = await resolveProjectPath(deps.io, {
|
|
17218
|
+
requested: stringArg(args, "projectPath"),
|
|
17219
|
+
cwd: ctx.cwd,
|
|
17220
|
+
signal: ctx.signal
|
|
17221
|
+
});
|
|
17222
|
+
if (!project.ok) return { text: missingIndexText(project.searchedFrom) };
|
|
17223
|
+
if (!options.resolution.ok) return { text: missingCliText(options.resolution.problem) };
|
|
17224
|
+
const timeoutMs = options.timeoutMs ?? CODEGRAPH_TIMEOUT_MS;
|
|
17225
|
+
let result;
|
|
17226
|
+
try {
|
|
17227
|
+
result = await runCodegraph(
|
|
17228
|
+
options.resolution.invocation,
|
|
17229
|
+
[...planned.args, "-p", project.projectPath],
|
|
17230
|
+
{ cwd: ctx.cwd, signal: ctx.signal, timeoutMs }
|
|
17231
|
+
);
|
|
17232
|
+
} catch (error) {
|
|
17233
|
+
ctx.signal?.throwIfAborted();
|
|
17234
|
+
return { text: launchFailureText(error) };
|
|
17235
|
+
}
|
|
17236
|
+
if (result.timedOut) return { text: timeoutText(query.subcommand, timeoutMs) };
|
|
17237
|
+
if (result.code !== 0) return { text: failureText(query.subcommand, result) };
|
|
17238
|
+
const printed = result.stdout.replace(/\r\n/gu, "\n").trimEnd();
|
|
17239
|
+
if (printed === "") return { text: emptyText(query.subcommand) };
|
|
17240
|
+
if (!query.anchors) return { text: withProjectNote(printed, project) };
|
|
17241
|
+
const view = await anchorCodegraphView(deps, {
|
|
17242
|
+
text: printed,
|
|
17243
|
+
projectPath: project.projectPath,
|
|
17244
|
+
sessionKey: ctx.sessionKey,
|
|
17245
|
+
signal: ctx.signal,
|
|
17246
|
+
exec
|
|
17247
|
+
});
|
|
17248
|
+
return { text: withProjectNote(view.text, project), projectPath: project.projectPath };
|
|
17249
|
+
}
|
|
17250
|
+
var SOURCE_NOTE = "The source is served as `HASH\u2502content` rows, so treat these files as already read and edit them by their anchors instead of reading them again.";
|
|
17251
|
+
var QUERIES = [
|
|
17252
|
+
{
|
|
17253
|
+
name: "codegraph_explore",
|
|
17254
|
+
subcommand: "explore",
|
|
17255
|
+
anchors: true,
|
|
17256
|
+
description: `Explore an area: the verbatim current source of the relevant symbols grouped by file, plus the call paths among them and what depends on them. ${SOURCE_NOTE} Prefer this over grep/find for architecture, flow, "where is X" and "what would changing X break" questions whenever the workspace has a \`.codegraph\` index.`,
|
|
17257
|
+
parameters: {
|
|
17258
|
+
query: {
|
|
17259
|
+
type: "string",
|
|
17260
|
+
required: true,
|
|
17261
|
+
description: 'Symbol names, file names or a short natural-language question (e.g. "AuthService loginUser session-manager"). For a flow question, name the symbols spanning the flow.'
|
|
17262
|
+
},
|
|
17263
|
+
maxFiles: {
|
|
17264
|
+
type: "number",
|
|
17265
|
+
description: "Maximum number of files to include source from."
|
|
17266
|
+
},
|
|
17267
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17268
|
+
},
|
|
17269
|
+
command: (args) => {
|
|
17270
|
+
const query = stringArg(args, "query") ?? "";
|
|
17271
|
+
const argv = ["explore", query];
|
|
17272
|
+
pushValue(argv, "--max-files", numberArg(args, "maxFiles"));
|
|
17273
|
+
return { args: argv };
|
|
17274
|
+
}
|
|
17275
|
+
},
|
|
17276
|
+
{
|
|
17277
|
+
name: "codegraph_node",
|
|
17278
|
+
subcommand: "node",
|
|
17279
|
+
anchors: true,
|
|
17280
|
+
description: `One symbol's source plus the functions it calls and the functions that call it \u2014 or, in file mode, a line window of one file with its dependents. ${SOURCE_NOTE}`,
|
|
17281
|
+
parameters: {
|
|
17282
|
+
symbol: {
|
|
17283
|
+
type: "string",
|
|
17284
|
+
description: "Symbol name to inspect (function, method, class, interface, type)."
|
|
17285
|
+
},
|
|
17286
|
+
file: {
|
|
17287
|
+
type: "string",
|
|
17288
|
+
description: "File mode: read this file's line window with its dependents; also disambiguates same-named symbols."
|
|
17289
|
+
},
|
|
17290
|
+
offset: { type: "number", description: "File mode: 1-based first line." },
|
|
17291
|
+
limit: { type: "number", description: "File mode: maximum lines." },
|
|
17292
|
+
symbolsOnly: {
|
|
17293
|
+
type: "boolean",
|
|
17294
|
+
description: "File mode: return only the file's symbol map and dependents."
|
|
17295
|
+
},
|
|
17296
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17297
|
+
},
|
|
17298
|
+
command: (args) => {
|
|
17299
|
+
const symbol = stringArg(args, "symbol");
|
|
17300
|
+
const file = stringArg(args, "file");
|
|
17301
|
+
if (symbol === void 0 && file === void 0) {
|
|
17302
|
+
return { args: [], problem: "codegraph_node needs `symbol` or `file`." };
|
|
17303
|
+
}
|
|
17304
|
+
const argv = ["node"];
|
|
17305
|
+
if (symbol !== void 0) argv.push(symbol);
|
|
17306
|
+
if (file !== void 0) argv.push("-f", file);
|
|
17307
|
+
pushValue(argv, "--offset", numberArg(args, "offset"));
|
|
17308
|
+
pushValue(argv, "--limit", numberArg(args, "limit"));
|
|
17309
|
+
if (booleanArg(args, "symbolsOnly")) argv.push("--symbols-only");
|
|
17310
|
+
return { args: argv };
|
|
17311
|
+
}
|
|
17312
|
+
},
|
|
17313
|
+
{
|
|
17314
|
+
name: "codegraph_context",
|
|
17315
|
+
subcommand: "context",
|
|
17316
|
+
anchors: true,
|
|
17317
|
+
description: `Build context for a task: entry points, related symbols, their relationships and their code blocks. ${SOURCE_NOTE}`,
|
|
17318
|
+
parameters: {
|
|
17319
|
+
task: {
|
|
17320
|
+
type: "string",
|
|
17321
|
+
required: true,
|
|
17322
|
+
description: 'The task or question to gather context for (e.g. "add a retry to the upload path").'
|
|
17323
|
+
},
|
|
17324
|
+
maxNodes: { type: "number", description: "Maximum number of symbols to include." },
|
|
17325
|
+
noCode: { type: "boolean", description: "Omit code blocks and return structure only." },
|
|
17326
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17327
|
+
},
|
|
17328
|
+
command: (args) => {
|
|
17329
|
+
const argv = ["context", stringArg(args, "task") ?? ""];
|
|
17330
|
+
pushValue(argv, "-n", numberArg(args, "maxNodes"));
|
|
17331
|
+
if (booleanArg(args, "noCode")) argv.push("--no-code");
|
|
17332
|
+
return { args: argv };
|
|
17333
|
+
}
|
|
17334
|
+
},
|
|
17335
|
+
{
|
|
17336
|
+
name: "codegraph_search",
|
|
17337
|
+
subcommand: "query",
|
|
17338
|
+
anchors: false,
|
|
17339
|
+
description: "Quick symbol search by name. Returns locations only (no source): use codegraph_explore to understand an area, or codegraph_node for one symbol's served source.",
|
|
17340
|
+
parameters: {
|
|
17341
|
+
query: {
|
|
17342
|
+
type: "string",
|
|
17343
|
+
required: true,
|
|
17344
|
+
description: 'Symbol name or partial name (e.g. "auth", "signIn", "UserService").'
|
|
17345
|
+
},
|
|
17346
|
+
kind: {
|
|
17347
|
+
type: "string",
|
|
17348
|
+
enum: [
|
|
17349
|
+
"function",
|
|
17350
|
+
"method",
|
|
17351
|
+
"class",
|
|
17352
|
+
"interface",
|
|
17353
|
+
"type",
|
|
17354
|
+
"variable",
|
|
17355
|
+
"route",
|
|
17356
|
+
"component"
|
|
17357
|
+
],
|
|
17358
|
+
description: "Filter by node kind."
|
|
17359
|
+
},
|
|
17360
|
+
limit: { type: "number", description: "Maximum results (default: 10)." },
|
|
17361
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17362
|
+
},
|
|
17363
|
+
command: (args) => {
|
|
17364
|
+
const argv = ["query", stringArg(args, "query") ?? ""];
|
|
17365
|
+
const kind = stringArg(args, "kind");
|
|
17366
|
+
if (kind !== void 0) argv.push("-k", kind);
|
|
17367
|
+
pushValue(argv, "-l", numberArg(args, "limit"));
|
|
17368
|
+
return { args: argv };
|
|
17369
|
+
}
|
|
17370
|
+
},
|
|
17371
|
+
{
|
|
17372
|
+
name: "codegraph_callers",
|
|
17373
|
+
subcommand: "callers",
|
|
17374
|
+
anchors: false,
|
|
17375
|
+
description: "List the functions that call a symbol, including callback registrations a text search cannot follow. Returns locations; call codegraph_node or codegraph_explore when the source is needed.",
|
|
17376
|
+
parameters: {
|
|
17377
|
+
symbol: {
|
|
17378
|
+
type: "string",
|
|
17379
|
+
required: true,
|
|
17380
|
+
description: "Function, method or class to find callers for."
|
|
17381
|
+
},
|
|
17382
|
+
file: {
|
|
17383
|
+
type: "string",
|
|
17384
|
+
description: "Narrow to the definition in this file (path or suffix) when several same-named symbols exist."
|
|
17385
|
+
},
|
|
17386
|
+
limit: { type: "number", description: "Maximum number of callers (default: 20)." },
|
|
17387
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17388
|
+
},
|
|
17389
|
+
command: (args) => {
|
|
17390
|
+
const argv = ["callers", stringArg(args, "symbol") ?? ""];
|
|
17391
|
+
const file = stringArg(args, "file");
|
|
17392
|
+
if (file !== void 0) argv.push("-f", file);
|
|
17393
|
+
pushValue(argv, "-l", numberArg(args, "limit"));
|
|
17394
|
+
return { args: argv };
|
|
17395
|
+
}
|
|
17396
|
+
},
|
|
17397
|
+
{
|
|
17398
|
+
name: "codegraph_callees",
|
|
17399
|
+
subcommand: "callees",
|
|
17400
|
+
anchors: false,
|
|
17401
|
+
description: "List the functions a symbol calls. Returns locations; call codegraph_node or codegraph_explore when the source is needed.",
|
|
17402
|
+
parameters: {
|
|
17403
|
+
symbol: {
|
|
17404
|
+
type: "string",
|
|
17405
|
+
required: true,
|
|
17406
|
+
description: "Function, method or class to find callees for."
|
|
17407
|
+
},
|
|
17408
|
+
file: {
|
|
17409
|
+
type: "string",
|
|
17410
|
+
description: "Narrow to the definition in this file (path or suffix) when several same-named symbols exist."
|
|
17411
|
+
},
|
|
17412
|
+
limit: { type: "number", description: "Maximum number of callees (default: 20)." },
|
|
17413
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17414
|
+
},
|
|
17415
|
+
command: (args) => {
|
|
17416
|
+
const argv = ["callees", stringArg(args, "symbol") ?? ""];
|
|
17417
|
+
const file = stringArg(args, "file");
|
|
17418
|
+
if (file !== void 0) argv.push("-f", file);
|
|
17419
|
+
pushValue(argv, "-l", numberArg(args, "limit"));
|
|
17420
|
+
return { args: argv };
|
|
17421
|
+
}
|
|
17422
|
+
},
|
|
17423
|
+
{
|
|
17424
|
+
name: "codegraph_impact",
|
|
17425
|
+
subcommand: "impact",
|
|
17426
|
+
anchors: false,
|
|
17427
|
+
description: "Analyze what is affected by changing a symbol: the dependents reachable from it within a traversal depth. Returns locations; fetch bodies with codegraph_node.",
|
|
17428
|
+
parameters: {
|
|
17429
|
+
symbol: { type: "string", required: true, description: "Symbol to analyze." },
|
|
17430
|
+
file: {
|
|
17431
|
+
type: "string",
|
|
17432
|
+
description: "Narrow to the definition in this file (path or suffix) when several same-named symbols exist."
|
|
17433
|
+
},
|
|
17434
|
+
depth: { type: "number", description: "Traversal depth (default: 2)." },
|
|
17435
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17436
|
+
},
|
|
17437
|
+
command: (args) => {
|
|
17438
|
+
const argv = ["impact", stringArg(args, "symbol") ?? ""];
|
|
17439
|
+
const file = stringArg(args, "file");
|
|
17440
|
+
if (file !== void 0) argv.push("-f", file);
|
|
17441
|
+
pushValue(argv, "-d", numberArg(args, "depth"));
|
|
17442
|
+
return { args: argv };
|
|
17443
|
+
}
|
|
17444
|
+
},
|
|
17445
|
+
{
|
|
17446
|
+
name: "codegraph_implementations",
|
|
17447
|
+
subcommand: "implementations",
|
|
17448
|
+
anchors: false,
|
|
17449
|
+
description: "List the types that implement or extend a trait, interface or class, down to a subtype depth. Returns locations; fetch bodies with codegraph_node.",
|
|
17450
|
+
parameters: {
|
|
17451
|
+
symbol: {
|
|
17452
|
+
type: "string",
|
|
17453
|
+
required: true,
|
|
17454
|
+
description: "Trait, interface or class to find implementors of."
|
|
17455
|
+
},
|
|
17456
|
+
file: {
|
|
17457
|
+
type: "string",
|
|
17458
|
+
description: "Narrow to the definition in this file (path or suffix) when several same-named symbols exist."
|
|
17459
|
+
},
|
|
17460
|
+
depth: { type: "number", description: "Levels of subtypes to list, 1-6 (default: 1)." },
|
|
17461
|
+
projectPath: PROJECT_PATH_PARAMETER
|
|
17462
|
+
},
|
|
17463
|
+
command: (args) => {
|
|
17464
|
+
const argv = ["implementations", stringArg(args, "symbol") ?? ""];
|
|
17465
|
+
const file = stringArg(args, "file");
|
|
17466
|
+
if (file !== void 0) argv.push("-f", file);
|
|
17467
|
+
pushValue(argv, "-d", numberArg(args, "depth"));
|
|
17468
|
+
return { args: argv };
|
|
17469
|
+
}
|
|
17470
|
+
}
|
|
17471
|
+
];
|
|
17472
|
+
function buildTool(deps, options, query) {
|
|
17473
|
+
return defineTool4({
|
|
17474
|
+
name: query.name,
|
|
17475
|
+
description: query.description,
|
|
17476
|
+
parameters: query.parameters,
|
|
17477
|
+
output: {
|
|
17478
|
+
schema: OUTCOME_SCHEMA,
|
|
17479
|
+
render: (_args, value) => [{ type: "text", text: value.text }]
|
|
17480
|
+
},
|
|
17481
|
+
async execute(args, exec) {
|
|
17482
|
+
const outcome = await executeQuery(deps, options, exec, query, args);
|
|
17483
|
+
return outcome.projectPath === void 0 ? { text: outcome.text } : { text: outcome.text, projectPath: outcome.projectPath };
|
|
17484
|
+
}
|
|
17485
|
+
});
|
|
17486
|
+
}
|
|
17487
|
+
function buildCodegraphTools(deps, options) {
|
|
17488
|
+
return QUERIES.map((query) => buildTool(deps, options, query));
|
|
17489
|
+
}
|
|
17490
|
+
|
|
17491
|
+
// dsh/diagnostics/tools.ts
|
|
17492
|
+
import { dirname as dirname14, join as join14 } from "node:path";
|
|
17493
|
+
import {
|
|
17494
|
+
defineTool as defineTool5
|
|
17495
|
+
} from "@deepseek-ai/dsh-tools";
|
|
17496
|
+
|
|
17497
|
+
// dsh/diagnostics/cli.ts
|
|
17498
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
17499
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
17500
|
+
import { dirname as dirname12, extname as extname2, join as join13 } from "node:path";
|
|
17501
|
+
var DIAGNOSTICS_TOOL_NAMES = ["cargo-check", "cargo-clippy", "tsc"];
|
|
17502
|
+
var TSC_SCRIPT = join13("node_modules", "typescript", "bin", "tsc");
|
|
17503
|
+
var WINDOWS_CARGO_NAMES = ["cargo.exe", "cargo.cmd", "cargo.bat", "cargo"];
|
|
17504
|
+
var POSIX_CARGO_NAMES = ["cargo"];
|
|
17505
|
+
var WINDOWS_TSC_NAMES = ["tsc.cmd", "tsc.exe", "tsc.bat", "tsc"];
|
|
17506
|
+
var POSIX_TSC_NAMES = ["tsc"];
|
|
17507
|
+
function isDiagnosticsTool(value) {
|
|
17508
|
+
return typeof value === "string" && DIAGNOSTICS_TOOL_NAMES.includes(value);
|
|
17509
|
+
}
|
|
17510
|
+
var PLANNED_ARGS = {
|
|
17511
|
+
"cargo-check": ["check", "--message-format=json", "--quiet"],
|
|
17512
|
+
"cargo-clippy": ["clippy", "--message-format=json", "--quiet"],
|
|
17513
|
+
tsc: ["--noEmit", "--pretty", "false"]
|
|
17514
|
+
};
|
|
17515
|
+
function planDiagnosticsArgs(tool) {
|
|
17516
|
+
return PLANNED_ARGS[tool];
|
|
17517
|
+
}
|
|
17518
|
+
function isScript2(entry) {
|
|
17519
|
+
const ext = extname2(entry).toLowerCase();
|
|
17520
|
+
return ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
17521
|
+
}
|
|
17522
|
+
function isCommandShim3(entry) {
|
|
17523
|
+
const lower = entry.toLowerCase();
|
|
17524
|
+
return lower.endsWith(".cmd") || lower.endsWith(".bat");
|
|
17525
|
+
}
|
|
17526
|
+
function pathDirectories(pathValue, platform) {
|
|
17527
|
+
const separator = platform === "win32" ? ";" : ":";
|
|
17528
|
+
return pathValue.split(separator).filter((directory) => directory !== "");
|
|
17529
|
+
}
|
|
17530
|
+
function runnableEntry(entry, platform) {
|
|
17531
|
+
if (isScript2(entry)) return { command: process.execPath, prefixArgs: [entry], source: entry };
|
|
17532
|
+
if (isCommandShim3(entry)) return void 0;
|
|
17533
|
+
const ext = extname2(entry).toLowerCase();
|
|
17534
|
+
if (ext === "" && platform === "win32") return void 0;
|
|
17535
|
+
return { command: entry, prefixArgs: [], source: entry };
|
|
17536
|
+
}
|
|
17537
|
+
function findUpward(start, candidate, exists) {
|
|
17538
|
+
let directory = start;
|
|
17539
|
+
for (; ; ) {
|
|
17540
|
+
const entry = candidate(directory);
|
|
17541
|
+
if (exists(entry)) return entry;
|
|
17542
|
+
const parent = dirname12(directory);
|
|
17543
|
+
if (parent === directory) return void 0;
|
|
17544
|
+
directory = parent;
|
|
17545
|
+
}
|
|
17546
|
+
}
|
|
17547
|
+
function resolveCargoInvocation(options = {}) {
|
|
17548
|
+
const platform = options.platform ?? process.platform;
|
|
17549
|
+
const exists = options.exists ?? existsSync7;
|
|
17550
|
+
const names = platform === "win32" ? WINDOWS_CARGO_NAMES : POSIX_CARGO_NAMES;
|
|
17551
|
+
let shim;
|
|
17552
|
+
for (const directory of pathDirectories(options.pathValue ?? process.env.PATH ?? "", platform)) {
|
|
17553
|
+
for (const name2 of names) {
|
|
17554
|
+
const entry = join13(directory, name2);
|
|
17555
|
+
if (!exists(entry)) continue;
|
|
17556
|
+
if (isCommandShim3(entry)) {
|
|
17557
|
+
const sibling = join13(directory, "cargo.exe");
|
|
17558
|
+
if (!exists(sibling)) {
|
|
17559
|
+
shim ??= entry;
|
|
17560
|
+
continue;
|
|
17561
|
+
}
|
|
17562
|
+
return { ok: true, invocation: { command: sibling, prefixArgs: [], source: sibling } };
|
|
17563
|
+
}
|
|
17564
|
+
const invocation = runnableEntry(entry, platform);
|
|
17565
|
+
if (invocation !== void 0) return { ok: true, invocation };
|
|
17566
|
+
}
|
|
17567
|
+
}
|
|
17568
|
+
if (shim !== void 0) {
|
|
17569
|
+
return {
|
|
17570
|
+
ok: false,
|
|
17571
|
+
problem: `only a shell shim was found at "${shim}", which cannot run without a shell; put the real cargo.exe on PATH`
|
|
17572
|
+
};
|
|
17573
|
+
}
|
|
17574
|
+
return { ok: false, problem: "no cargo executable was found on PATH" };
|
|
17575
|
+
}
|
|
17576
|
+
function resolveTscInvocation(cwd, options = {}) {
|
|
17577
|
+
const platform = options.platform ?? process.platform;
|
|
17578
|
+
const exists = options.exists ?? existsSync7;
|
|
17579
|
+
const local = findUpward(cwd, (directory) => join13(directory, TSC_SCRIPT), exists);
|
|
17580
|
+
if (local !== void 0) {
|
|
17581
|
+
return {
|
|
17582
|
+
ok: true,
|
|
17583
|
+
invocation: { command: process.execPath, prefixArgs: [local], source: local }
|
|
17584
|
+
};
|
|
17585
|
+
}
|
|
17586
|
+
const names = platform === "win32" ? WINDOWS_TSC_NAMES : POSIX_TSC_NAMES;
|
|
17587
|
+
let shim;
|
|
17588
|
+
for (const directory of pathDirectories(options.pathValue ?? process.env.PATH ?? "", platform)) {
|
|
17589
|
+
for (const name2 of names) {
|
|
17590
|
+
const entry = join13(directory, name2);
|
|
17591
|
+
if (!exists(entry)) continue;
|
|
17592
|
+
if (isCommandShim3(entry)) {
|
|
17593
|
+
const binDir = dirname12(entry);
|
|
17594
|
+
for (const root of [binDir, dirname12(binDir)]) {
|
|
17595
|
+
const script = join13(root, TSC_SCRIPT);
|
|
17596
|
+
if (!exists(script)) continue;
|
|
17597
|
+
return {
|
|
17598
|
+
ok: true,
|
|
17599
|
+
invocation: { command: process.execPath, prefixArgs: [script], source: script }
|
|
17600
|
+
};
|
|
17601
|
+
}
|
|
17602
|
+
shim ??= entry;
|
|
17603
|
+
continue;
|
|
17604
|
+
}
|
|
17605
|
+
const invocation = runnableEntry(entry, platform);
|
|
17606
|
+
if (invocation !== void 0) return { ok: true, invocation };
|
|
17607
|
+
}
|
|
17608
|
+
}
|
|
17609
|
+
if (shim !== void 0) {
|
|
17610
|
+
return {
|
|
17611
|
+
ok: false,
|
|
17612
|
+
problem: `only a shell shim was found at "${shim}", which cannot run without a shell; put the real tsc script on PATH`
|
|
17613
|
+
};
|
|
17614
|
+
}
|
|
17615
|
+
return {
|
|
17616
|
+
ok: false,
|
|
17617
|
+
problem: `no TypeScript compiler was found: ${cwd} has no ${TSC_SCRIPT} at or above it, and no tsc is on PATH`
|
|
17618
|
+
};
|
|
17619
|
+
}
|
|
17620
|
+
var DIAGNOSTICS_TIMEOUT_MS = 12e4;
|
|
17621
|
+
var MAX_CAPTURE_CHARS3 = 2e6;
|
|
17622
|
+
function runDiagnosticsCommand(invocation, args, options) {
|
|
17623
|
+
options.signal?.throwIfAborted();
|
|
17624
|
+
const timeoutMs = options.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS;
|
|
17625
|
+
const env = {
|
|
17626
|
+
...process.env,
|
|
17627
|
+
// WHY: the diagnostics are a machine surface; a colour escape would corrupt the parsed
|
|
17628
|
+
// WHY: text and the anchored rows served from it.
|
|
17629
|
+
NO_COLOR: "1",
|
|
17630
|
+
FORCE_COLOR: "0",
|
|
17631
|
+
CARGO_TERM_COLOR: "never",
|
|
17632
|
+
...options.env
|
|
17633
|
+
};
|
|
17634
|
+
return new Promise((resolve6, reject) => {
|
|
17635
|
+
const child = spawn3(invocation.command, [...invocation.prefixArgs, ...args], {
|
|
17636
|
+
cwd: options.cwd,
|
|
17637
|
+
env,
|
|
17638
|
+
windowsHide: true,
|
|
17639
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
17640
|
+
});
|
|
17641
|
+
let stdout = "";
|
|
17642
|
+
let stderr = "";
|
|
17643
|
+
let timedOut = false;
|
|
17644
|
+
let settled = false;
|
|
17645
|
+
const capture = (current, chunk) => current.length >= MAX_CAPTURE_CHARS3 ? current : (current + chunk).slice(0, MAX_CAPTURE_CHARS3);
|
|
17646
|
+
const stop = () => {
|
|
17647
|
+
if (settled) return;
|
|
17648
|
+
settled = true;
|
|
17649
|
+
clearTimeout(timer);
|
|
17650
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
17651
|
+
};
|
|
17652
|
+
const onAbort = () => {
|
|
17653
|
+
child.kill();
|
|
17654
|
+
stop();
|
|
17655
|
+
reject(options.signal?.reason ?? new Error("diagnostics run aborted"));
|
|
17656
|
+
};
|
|
17657
|
+
const timer = setTimeout(() => {
|
|
17658
|
+
timedOut = true;
|
|
17659
|
+
child.kill();
|
|
17660
|
+
}, timeoutMs);
|
|
17661
|
+
child.stdout?.setEncoding("utf8");
|
|
17662
|
+
child.stderr?.setEncoding("utf8");
|
|
17663
|
+
child.stdout?.on("data", (chunk) => {
|
|
17664
|
+
stdout = capture(stdout, chunk);
|
|
17665
|
+
});
|
|
17666
|
+
child.stderr?.on("data", (chunk) => {
|
|
17667
|
+
stderr = capture(stderr, chunk);
|
|
17668
|
+
});
|
|
17669
|
+
child.on("error", (error) => {
|
|
17670
|
+
stop();
|
|
17671
|
+
reject(error);
|
|
17672
|
+
});
|
|
17673
|
+
child.on("close", (code) => {
|
|
17674
|
+
if (settled) return;
|
|
17675
|
+
stop();
|
|
17676
|
+
resolve6({ stdout, stderr, code, timedOut });
|
|
17677
|
+
});
|
|
17678
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
17679
|
+
});
|
|
17680
|
+
}
|
|
17681
|
+
|
|
17682
|
+
// dsh/diagnostics/messages.ts
|
|
17683
|
+
var TAIL_LINES = 40;
|
|
17684
|
+
function plural(count, noun) {
|
|
17685
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
17686
|
+
}
|
|
17687
|
+
function tailLines(text, max) {
|
|
17688
|
+
if (text.trim() === "") return "";
|
|
17689
|
+
const lines = text.replace(/\r\n/gu, "\n").replace(/\n+$/u, "").split("\n");
|
|
17690
|
+
return lines.slice(-max).join("\n");
|
|
17691
|
+
}
|
|
17692
|
+
function summaryLine(tool, cwd, counts) {
|
|
17693
|
+
return `${plural(counts.total, "diagnostic")} (${plural(counts.errors, "error")}, ${plural(
|
|
17694
|
+
counts.warnings,
|
|
17695
|
+
"warning"
|
|
17696
|
+
)}) from ${tool} in ${cwd}`;
|
|
17697
|
+
}
|
|
17698
|
+
function showingNote(total, shown) {
|
|
17699
|
+
return `_Showing the first ${shown} of ${plural(total, "diagnostic")}; raise \`maxDiagnostics\` for the rest._`;
|
|
17700
|
+
}
|
|
17701
|
+
function skippedNote(skipped) {
|
|
17702
|
+
return `_${plural(skipped, "diagnostic")} skipped: the file could not be served as rows (unreadable, not UTF-8, binary, or the reported line is outside the file)._`;
|
|
17703
|
+
}
|
|
17704
|
+
function cleanText(tool, cwd) {
|
|
17705
|
+
return `${tool} reported no diagnostics in ${cwd}.`;
|
|
17706
|
+
}
|
|
17707
|
+
function missingToolchainText(tool, problem) {
|
|
17708
|
+
const hint = tool === "tsc" ? "Install the project's TypeScript dependency so `node_modules/typescript/bin/tsc` resolves (for this repository: `pnpm install`), or put a `tsc` on PATH." : "Install the Rust toolchain (rustup) so `cargo` is on PATH, then retry from the project that holds `Cargo.toml`.";
|
|
17709
|
+
return [`${tool} is unavailable for this call: ${problem}.`, hint].join("\n\n");
|
|
17710
|
+
}
|
|
17711
|
+
function missingTsconfigText(cwd) {
|
|
17712
|
+
return [
|
|
17713
|
+
`No tsconfig.json or jsconfig.json was found at or above ${cwd}, so \`tsc\` would have no project to check.`,
|
|
17714
|
+
"Run this from (or pass `cwd`) the directory that holds the project's tsconfig.json."
|
|
17715
|
+
].join("\n\n");
|
|
17716
|
+
}
|
|
17717
|
+
function unusableCwdText(cwd) {
|
|
17718
|
+
return [
|
|
17719
|
+
`${cwd} is not a readable directory, so no toolchain could run there.`,
|
|
17720
|
+
"Pass `cwd` as the project root that holds Cargo.toml or tsconfig.json, or omit it to use the session working directory."
|
|
17721
|
+
].join("\n\n");
|
|
17722
|
+
}
|
|
17723
|
+
function timeoutText2(tool, timeoutMs) {
|
|
17724
|
+
return `${tool} did not finish within ${timeoutMs} ms and was stopped. Retry with a narrower \`cwd\` (one crate or package), or run the project's own check script instead.`;
|
|
17725
|
+
}
|
|
17726
|
+
function rawOutputText(tool, result) {
|
|
17727
|
+
const exit = result.code === null ? "stopped on a signal" : `exited with code ${result.code}`;
|
|
17728
|
+
const sections = [
|
|
17729
|
+
`${tool} ${exit} and printed no diagnostics this tool could parse.`,
|
|
17730
|
+
"That usually means the invocation does not match the project (run it from the project root, or pass `cwd`), or the toolchain printed a different output format."
|
|
17731
|
+
];
|
|
17732
|
+
const stdout = tailLines(result.stdout, TAIL_LINES);
|
|
17733
|
+
const stderr = tailLines(result.stderr, TAIL_LINES);
|
|
17734
|
+
if (stdout !== "") sections.push(`Last lines of stdout:
|
|
17735
|
+
|
|
17736
|
+
${stdout}`);
|
|
17737
|
+
if (stderr !== "") sections.push(`Last lines of stderr:
|
|
17738
|
+
|
|
17739
|
+
${stderr}`);
|
|
17740
|
+
if (stdout === "" && stderr === "") sections.push("It printed nothing at all.");
|
|
17741
|
+
return sections.join("\n\n");
|
|
17742
|
+
}
|
|
17743
|
+
function launchFailureText2(tool, error) {
|
|
17744
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17745
|
+
return `${tool} could not be started: ${message}. Check that the toolchain executable can run in this session.`;
|
|
17746
|
+
}
|
|
17747
|
+
|
|
17748
|
+
// dsh/diagnostics/parse.ts
|
|
17749
|
+
function recordOf(value) {
|
|
17750
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
17751
|
+
}
|
|
17752
|
+
function textOf(value) {
|
|
17753
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
17754
|
+
}
|
|
17755
|
+
function positionOf(value) {
|
|
17756
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1 ? value : void 0;
|
|
17757
|
+
}
|
|
17758
|
+
function primarySpanOf(message) {
|
|
17759
|
+
const spans = message.spans;
|
|
17760
|
+
if (!Array.isArray(spans)) return void 0;
|
|
17761
|
+
for (const candidate of spans) {
|
|
17762
|
+
const span = recordOf(candidate);
|
|
17763
|
+
if (span === void 0 || span.is_primary !== true) continue;
|
|
17764
|
+
const file = textOf(span.file_name);
|
|
17765
|
+
const line = positionOf(span.line_start);
|
|
17766
|
+
if (file === void 0 || line === void 0) continue;
|
|
17767
|
+
return {
|
|
17768
|
+
file,
|
|
17769
|
+
line,
|
|
17770
|
+
column: positionOf(span.column_start) ?? 1,
|
|
17771
|
+
label: textOf(span.label)
|
|
17772
|
+
};
|
|
17773
|
+
}
|
|
17774
|
+
return void 0;
|
|
17775
|
+
}
|
|
17776
|
+
function parseCargoLine(line) {
|
|
17777
|
+
if (!line.startsWith("{")) return void 0;
|
|
17778
|
+
let parsed;
|
|
17779
|
+
try {
|
|
17780
|
+
parsed = JSON.parse(line);
|
|
17781
|
+
} catch {
|
|
17782
|
+
return void 0;
|
|
17783
|
+
}
|
|
17784
|
+
const record = recordOf(parsed);
|
|
17785
|
+
if (record === void 0 || record.reason !== "compiler-message") return void 0;
|
|
17786
|
+
const message = recordOf(record.message);
|
|
17787
|
+
if (message === void 0) return void 0;
|
|
17788
|
+
const level = textOf(message.level);
|
|
17789
|
+
const headline = textOf(message.message);
|
|
17790
|
+
if (level === void 0 || headline === void 0) return void 0;
|
|
17791
|
+
const span = primarySpanOf(message);
|
|
17792
|
+
if (span === void 0) return void 0;
|
|
17793
|
+
const code = textOf(recordOf(message.code)?.code);
|
|
17794
|
+
return {
|
|
17795
|
+
level,
|
|
17796
|
+
...code === void 0 ? {} : { code },
|
|
17797
|
+
message: headline,
|
|
17798
|
+
file: span.file,
|
|
17799
|
+
line: span.line,
|
|
17800
|
+
column: span.column,
|
|
17801
|
+
...span.label === void 0 ? {} : { label: span.label }
|
|
17802
|
+
};
|
|
17803
|
+
}
|
|
17804
|
+
var TSC_DIAGNOSTIC = /^(.+?)\((\d+),(\d+)\): (error|warning) (TS\d+): (.*)$/u;
|
|
17805
|
+
var TSC_CONTINUATION = /^\s+\S/u;
|
|
17806
|
+
function parseCargoOutput(stdout) {
|
|
17807
|
+
const diagnostics = [];
|
|
17808
|
+
for (const line of stdout.replace(/\r\n/gu, "\n").split("\n")) {
|
|
17809
|
+
const diagnostic = parseCargoLine(line);
|
|
17810
|
+
if (diagnostic !== void 0) diagnostics.push(diagnostic);
|
|
17811
|
+
}
|
|
17812
|
+
return diagnostics;
|
|
17813
|
+
}
|
|
17814
|
+
function parseTscOutput(stdout) {
|
|
17815
|
+
const lines = stdout.replace(/\r\n/gu, "\n").split("\n");
|
|
17816
|
+
const diagnostics = [];
|
|
17817
|
+
let index = 0;
|
|
17818
|
+
while (index < lines.length) {
|
|
17819
|
+
const line = lines[index] ?? "";
|
|
17820
|
+
const match = TSC_DIAGNOSTIC.exec(line);
|
|
17821
|
+
if (match === null) {
|
|
17822
|
+
index += 1;
|
|
17823
|
+
continue;
|
|
17824
|
+
}
|
|
17825
|
+
const file = textOf(match[1]);
|
|
17826
|
+
const lineNumber = positionOf(Number(match[2]));
|
|
17827
|
+
const level = textOf(match[4]);
|
|
17828
|
+
const message = textOf(match[6]);
|
|
17829
|
+
if (file === void 0 || lineNumber === void 0 || level === void 0 || message === void 0) {
|
|
17830
|
+
index += 1;
|
|
17831
|
+
continue;
|
|
17832
|
+
}
|
|
17833
|
+
const detail = [];
|
|
17834
|
+
let next = index + 1;
|
|
17835
|
+
while (next < lines.length && TSC_CONTINUATION.test(lines[next] ?? "")) {
|
|
17836
|
+
detail.push((lines[next] ?? "").trimEnd());
|
|
17837
|
+
next += 1;
|
|
17838
|
+
}
|
|
17839
|
+
const column = positionOf(Number(match[3])) ?? 1;
|
|
17840
|
+
diagnostics.push({
|
|
17841
|
+
level,
|
|
17842
|
+
code: match[5] ?? "TS0000",
|
|
17843
|
+
message,
|
|
17844
|
+
file,
|
|
17845
|
+
line: lineNumber,
|
|
17846
|
+
column,
|
|
17847
|
+
...detail.length === 0 ? {} : { detail }
|
|
17848
|
+
});
|
|
17849
|
+
index = next;
|
|
17850
|
+
}
|
|
17851
|
+
return diagnostics;
|
|
17852
|
+
}
|
|
17853
|
+
function parseDiagnostics(tool, stdout) {
|
|
17854
|
+
return tool === "tsc" ? parseTscOutput(stdout) : parseCargoOutput(stdout);
|
|
17855
|
+
}
|
|
17856
|
+
|
|
17857
|
+
// dsh/diagnostics/view.ts
|
|
17858
|
+
import { dirname as dirname13, isAbsolute as isAbsolute7 } from "node:path";
|
|
17859
|
+
function headerOf(diagnostic) {
|
|
17860
|
+
const code = diagnostic.code === void 0 ? "" : `[${diagnostic.code}]`;
|
|
17861
|
+
return `${diagnostic.level}${code} ${diagnostic.message} \u2014 ${diagnostic.file}:${diagnostic.line}:${diagnostic.column}`;
|
|
17862
|
+
}
|
|
17863
|
+
function detailOf(diagnostic) {
|
|
17864
|
+
const lines = [];
|
|
17865
|
+
if (diagnostic.label !== void 0) lines.push(` ${diagnostic.label}`);
|
|
17866
|
+
for (const line of diagnostic.detail ?? []) lines.push(` ${line.trim()}`);
|
|
17867
|
+
return lines;
|
|
17868
|
+
}
|
|
17869
|
+
async function statOnce(state, candidate) {
|
|
17870
|
+
try {
|
|
17871
|
+
const info = await state.deps.io.stat(candidate, state.signal);
|
|
17872
|
+
return info?.isFile === true;
|
|
17873
|
+
} catch {
|
|
17874
|
+
return false;
|
|
17875
|
+
}
|
|
17876
|
+
}
|
|
17877
|
+
function resolveOnce(state, printed) {
|
|
17878
|
+
const cached = state.resolved.get(printed);
|
|
17879
|
+
if (cached !== void 0) return cached;
|
|
17880
|
+
const pending = (async () => {
|
|
17881
|
+
if (isAbsolute7(printed)) return await statOnce(state, printed) ? printed : void 0;
|
|
17882
|
+
let directory = state.cwd;
|
|
17883
|
+
for (; ; ) {
|
|
17884
|
+
state.signal?.throwIfAborted();
|
|
17885
|
+
const candidate = toCwd(printed, directory);
|
|
17886
|
+
if (await statOnce(state, candidate)) return candidate;
|
|
17887
|
+
const parent = dirname13(directory);
|
|
17888
|
+
if (parent === directory) return void 0;
|
|
17889
|
+
directory = parent;
|
|
17890
|
+
}
|
|
17891
|
+
})();
|
|
17892
|
+
state.resolved.set(printed, pending);
|
|
17893
|
+
return pending;
|
|
17894
|
+
}
|
|
17895
|
+
function decodeOnce2(state, file) {
|
|
17896
|
+
const cached = state.decoded.get(file);
|
|
17897
|
+
if (cached !== void 0) return cached;
|
|
17898
|
+
const pending = (async () => {
|
|
17899
|
+
try {
|
|
17900
|
+
return await decodeFileLines(state.deps, {
|
|
17901
|
+
path: file,
|
|
17902
|
+
cwd: state.cwd,
|
|
17903
|
+
signal: state.signal
|
|
17904
|
+
});
|
|
17905
|
+
} catch {
|
|
17906
|
+
return void 0;
|
|
17907
|
+
}
|
|
17908
|
+
})();
|
|
17909
|
+
state.decoded.set(file, pending);
|
|
17910
|
+
return pending;
|
|
17911
|
+
}
|
|
17912
|
+
function windowOf(start, end) {
|
|
17913
|
+
const lines = [];
|
|
17914
|
+
for (let line = start; line <= end; line += 1) lines.push(line);
|
|
17915
|
+
return lines;
|
|
17916
|
+
}
|
|
17917
|
+
async function rowsOf(state, diagnostic) {
|
|
17918
|
+
const absolutePath = await resolveOnce(state, diagnostic.file);
|
|
17919
|
+
if (absolutePath === void 0) return void 0;
|
|
17920
|
+
const disk = await decodeOnce2(state, absolutePath);
|
|
17921
|
+
if (disk === void 0 || disk.length === 0) return void 0;
|
|
17922
|
+
if (diagnostic.line < 1 || diagnostic.line > disk.length) return void 0;
|
|
17923
|
+
const start = Math.max(1, diagnostic.line - state.contextLines);
|
|
17924
|
+
const end = Math.min(disk.length, diagnostic.line + state.contextLines);
|
|
17925
|
+
const lineNumbers = windowOf(start, end);
|
|
17926
|
+
try {
|
|
17927
|
+
const served = await serveFileLines(state.deps, {
|
|
17928
|
+
path: absolutePath,
|
|
17929
|
+
cwd: state.cwd,
|
|
17930
|
+
sessionKey: state.sessionKey,
|
|
17931
|
+
signal: state.signal,
|
|
17932
|
+
lineNumbers
|
|
17933
|
+
});
|
|
17934
|
+
if (served.length !== lineNumbers.length) return void 0;
|
|
17935
|
+
const rows = [];
|
|
17936
|
+
for (const row of served) {
|
|
17937
|
+
if (disk[row.line - 1] !== row.text) return void 0;
|
|
17938
|
+
rows.push(`${row.hash}${HASH_SEP}${row.text}`);
|
|
17939
|
+
}
|
|
17940
|
+
state.served.add(absolutePath);
|
|
17941
|
+
return rows;
|
|
17942
|
+
} catch (error) {
|
|
17943
|
+
reportDiagnostic(
|
|
17944
|
+
"diagnostics-view",
|
|
17945
|
+
`Could not serve ${diagnostic.file}; skipping that diagnostic:`,
|
|
17946
|
+
error
|
|
17947
|
+
);
|
|
17948
|
+
return void 0;
|
|
17949
|
+
}
|
|
17950
|
+
}
|
|
17951
|
+
async function anchorDiagnosticsView(deps, request) {
|
|
17952
|
+
const state = {
|
|
17953
|
+
deps,
|
|
17954
|
+
cwd: request.cwd,
|
|
17955
|
+
contextLines: request.contextLines,
|
|
17956
|
+
sessionKey: request.sessionKey,
|
|
17957
|
+
signal: request.signal,
|
|
17958
|
+
resolved: /* @__PURE__ */ new Map(),
|
|
17959
|
+
decoded: /* @__PURE__ */ new Map(),
|
|
17960
|
+
served: /* @__PURE__ */ new Set()
|
|
17961
|
+
};
|
|
17962
|
+
const blocks = [];
|
|
17963
|
+
let skipped = 0;
|
|
17964
|
+
for (const diagnostic of request.diagnostics) {
|
|
17965
|
+
request.signal?.throwIfAborted();
|
|
17966
|
+
const rows = await rowsOf(state, diagnostic);
|
|
17967
|
+
if (rows === void 0) {
|
|
17968
|
+
skipped += 1;
|
|
17969
|
+
continue;
|
|
17970
|
+
}
|
|
17971
|
+
blocks.push([headerOf(diagnostic), ...detailOf(diagnostic), ...rows].join("\n"));
|
|
17972
|
+
}
|
|
17973
|
+
for (const absolutePath of state.served) {
|
|
17974
|
+
await deps.observations?.publish(
|
|
17975
|
+
absolutePath,
|
|
17976
|
+
request.exec,
|
|
17977
|
+
request.signal === void 0 ? void 0 : { signal: request.signal }
|
|
17978
|
+
);
|
|
17979
|
+
}
|
|
17980
|
+
return { blocks, skipped, servedFiles: [...state.served].sort() };
|
|
17981
|
+
}
|
|
17982
|
+
|
|
17983
|
+
// dsh/diagnostics/tools.ts
|
|
17984
|
+
var DIAGNOSTICS_TOOL_NAME = "diagnostics";
|
|
17985
|
+
var DEFAULT_CONTEXT_LINES = 2;
|
|
17986
|
+
var DEFAULT_MAX_DIAGNOSTICS = 20;
|
|
17987
|
+
var MIN_CONTEXT_LINES = 1;
|
|
17988
|
+
var MAX_CONTEXT_LINES = 10;
|
|
17989
|
+
var MIN_MAX_DIAGNOSTICS = 1;
|
|
17990
|
+
var MAX_MAX_DIAGNOSTICS = 100;
|
|
17991
|
+
var TSCONFIG_NAMES = ["tsconfig.json", "jsconfig.json"];
|
|
17992
|
+
var OUTCOME_SCHEMA2 = {
|
|
17993
|
+
type: "object",
|
|
17994
|
+
properties: {
|
|
17995
|
+
text: { type: "string", required: true }
|
|
17996
|
+
},
|
|
17997
|
+
additionalProperties: false
|
|
17998
|
+
};
|
|
17999
|
+
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`.";
|
|
18000
|
+
var DESCRIPTION = [
|
|
18001
|
+
"Run a compiler or linter over a project and return its errors and warnings as anchored, editable rows.",
|
|
18002
|
+
"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.",
|
|
18003
|
+
"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."
|
|
18004
|
+
].join("\n\n");
|
|
18005
|
+
var PARAMETERS = {
|
|
18006
|
+
tool: {
|
|
18007
|
+
type: "string",
|
|
18008
|
+
required: true,
|
|
18009
|
+
enum: [...DIAGNOSTICS_TOOL_NAMES],
|
|
18010
|
+
description: "Toolchain to run: `cargo-check` (`cargo check`), `cargo-clippy` (`cargo clippy`) or `tsc` (`--noEmit`)."
|
|
18011
|
+
},
|
|
18012
|
+
cwd: {
|
|
18013
|
+
type: "string",
|
|
18014
|
+
description: "Project directory the toolchain runs in. Defaults to the session working directory; the cargo workspace root or the directory holding tsconfig.json is the right choice."
|
|
18015
|
+
},
|
|
18016
|
+
contextLines: {
|
|
18017
|
+
type: "number",
|
|
18018
|
+
description: "Served lines above and below each diagnostic's own line, 1-10 (default 2). Out-of-range values are clamped, not refused."
|
|
18019
|
+
},
|
|
18020
|
+
maxDiagnostics: {
|
|
18021
|
+
type: "number",
|
|
18022
|
+
description: "Maximum diagnostics to serve, 1-100 (default 20). Out-of-range values are clamped, not refused; the header still counts everything the toolchain reported."
|
|
18023
|
+
}
|
|
18024
|
+
};
|
|
18025
|
+
function stringArg2(args, key) {
|
|
18026
|
+
const value = args[key];
|
|
18027
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
18028
|
+
}
|
|
18029
|
+
function clampedArg(value, min, max, fallback) {
|
|
18030
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
18031
|
+
return Math.min(max, Math.max(min, Math.round(value)));
|
|
18032
|
+
}
|
|
18033
|
+
function defaultResolve(tool, cwd) {
|
|
18034
|
+
return tool === "tsc" ? resolveTscInvocation(cwd) : resolveCargoInvocation();
|
|
18035
|
+
}
|
|
18036
|
+
async function hasProjectConfig(deps, cwd, signal) {
|
|
18037
|
+
let directory = cwd;
|
|
18038
|
+
for (; ; ) {
|
|
18039
|
+
for (const name2 of TSCONFIG_NAMES) {
|
|
18040
|
+
const info = await deps.io.stat(join14(directory, name2), signal).catch(() => void 0);
|
|
18041
|
+
if (info?.isFile === true) return true;
|
|
18042
|
+
}
|
|
18043
|
+
const parent = dirname14(directory);
|
|
18044
|
+
if (parent === directory) return false;
|
|
18045
|
+
directory = parent;
|
|
18046
|
+
}
|
|
18047
|
+
}
|
|
18048
|
+
function countsOf(parsed) {
|
|
18049
|
+
let errors = 0;
|
|
18050
|
+
let warnings = 0;
|
|
18051
|
+
for (const diagnostic of parsed) {
|
|
18052
|
+
if (diagnostic.level === "error") errors += 1;
|
|
18053
|
+
else if (diagnostic.level === "warning") warnings += 1;
|
|
18054
|
+
}
|
|
18055
|
+
return { total: parsed.length, errors, warnings };
|
|
18056
|
+
}
|
|
18057
|
+
function composeText(tool, cwd, parsed, selected, blocks, skipped) {
|
|
18058
|
+
const sections = [summaryLine(tool, cwd, countsOf(parsed))];
|
|
18059
|
+
sections.push(...blocks);
|
|
18060
|
+
if (selected < parsed.length) sections.push(showingNote(parsed.length, selected));
|
|
18061
|
+
if (skipped > 0) sections.push(skippedNote(skipped));
|
|
18062
|
+
return sections.join("\n\n");
|
|
18063
|
+
}
|
|
18064
|
+
async function executeDiagnostics(deps, options, exec, rawArgs) {
|
|
18065
|
+
const args = typeof rawArgs === "object" && rawArgs !== null ? rawArgs : {};
|
|
18066
|
+
const ctx = resolveToolContext(exec);
|
|
18067
|
+
const tool = args.tool;
|
|
18068
|
+
if (!isDiagnosticsTool(tool)) {
|
|
18069
|
+
return `diagnostics needs \`tool\`: one of ${DIAGNOSTICS_TOOL_NAMES.map((name2) => `\`${name2}\``).join(", ")}.`;
|
|
18070
|
+
}
|
|
18071
|
+
const cwd = toCwd(stringArg2(args, "cwd") ?? ".", ctx.cwd);
|
|
18072
|
+
const directory = await deps.io.stat(cwd, ctx.signal).catch(() => void 0);
|
|
18073
|
+
if (directory?.isDirectory !== true) return unusableCwdText(cwd);
|
|
18074
|
+
const contextLines = clampedArg(
|
|
18075
|
+
args.contextLines,
|
|
18076
|
+
MIN_CONTEXT_LINES,
|
|
18077
|
+
MAX_CONTEXT_LINES,
|
|
18078
|
+
DEFAULT_CONTEXT_LINES
|
|
18079
|
+
);
|
|
18080
|
+
const maxDiagnostics = clampedArg(
|
|
18081
|
+
args.maxDiagnostics,
|
|
18082
|
+
MIN_MAX_DIAGNOSTICS,
|
|
18083
|
+
MAX_MAX_DIAGNOSTICS,
|
|
18084
|
+
DEFAULT_MAX_DIAGNOSTICS
|
|
18085
|
+
);
|
|
18086
|
+
const locate = options.resolve ?? defaultResolve;
|
|
18087
|
+
const resolution = locate(tool, cwd);
|
|
18088
|
+
if (!resolution.ok) return missingToolchainText(tool, resolution.problem);
|
|
18089
|
+
if (tool === "tsc" && !await hasProjectConfig(deps, cwd, ctx.signal)) {
|
|
18090
|
+
return missingTsconfigText(cwd);
|
|
18091
|
+
}
|
|
18092
|
+
const timeoutMs = options.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS;
|
|
18093
|
+
let result;
|
|
18094
|
+
try {
|
|
18095
|
+
result = await runDiagnosticsCommand(resolution.invocation, planDiagnosticsArgs(tool), {
|
|
18096
|
+
cwd,
|
|
18097
|
+
signal: ctx.signal,
|
|
18098
|
+
timeoutMs
|
|
18099
|
+
});
|
|
18100
|
+
} catch (error) {
|
|
18101
|
+
ctx.signal?.throwIfAborted();
|
|
18102
|
+
return launchFailureText2(tool, error);
|
|
18103
|
+
}
|
|
18104
|
+
if (result.timedOut) return timeoutText2(tool, timeoutMs);
|
|
18105
|
+
const parsed = parseDiagnostics(tool, result.stdout);
|
|
18106
|
+
if (parsed.length === 0) {
|
|
18107
|
+
const quiet = `${result.stdout}${result.stderr}`.trim() === "" && result.code === 0;
|
|
18108
|
+
return quiet ? cleanText(tool, cwd) : rawOutputText(tool, result);
|
|
18109
|
+
}
|
|
18110
|
+
const selected = parsed.slice(0, maxDiagnostics);
|
|
18111
|
+
const view = await anchorDiagnosticsView(deps, {
|
|
18112
|
+
diagnostics: selected,
|
|
18113
|
+
cwd,
|
|
18114
|
+
contextLines,
|
|
18115
|
+
sessionKey: ctx.sessionKey,
|
|
18116
|
+
signal: ctx.signal,
|
|
18117
|
+
exec
|
|
18118
|
+
});
|
|
18119
|
+
return composeText(tool, cwd, parsed, selected.length, view.blocks, view.skipped);
|
|
18120
|
+
}
|
|
18121
|
+
function buildDiagnosticsTool(deps, options) {
|
|
18122
|
+
return defineTool5({
|
|
18123
|
+
name: DIAGNOSTICS_TOOL_NAME,
|
|
18124
|
+
description: DESCRIPTION,
|
|
18125
|
+
parameters: PARAMETERS,
|
|
18126
|
+
output: {
|
|
18127
|
+
schema: OUTCOME_SCHEMA2,
|
|
18128
|
+
render: (_args, value) => [{ type: "text", text: value.text }]
|
|
18129
|
+
},
|
|
18130
|
+
async execute(args, exec) {
|
|
18131
|
+
return { text: await executeDiagnostics(deps, options, exec, args) };
|
|
18132
|
+
}
|
|
18133
|
+
});
|
|
18134
|
+
}
|
|
18135
|
+
function buildDiagnosticsTools(deps, options = {}) {
|
|
18136
|
+
return [buildDiagnosticsTool(deps, options)];
|
|
18137
|
+
}
|
|
18138
|
+
|
|
18139
|
+
// dsh/rg/tools.ts
|
|
18140
|
+
import {
|
|
18141
|
+
defineTool as defineTool6
|
|
18142
|
+
} from "@deepseek-ai/dsh-tools";
|
|
18143
|
+
|
|
18144
|
+
// dsh/rg/command.ts
|
|
18145
|
+
import { isAbsolute as isAbsolute8, relative as relative2 } from "node:path";
|
|
18146
|
+
function validateInclude(include) {
|
|
18147
|
+
if (include.trim().length === 0) throw new Error("include must be a non-empty glob when given");
|
|
18148
|
+
if (include.startsWith("!"))
|
|
18149
|
+
throw new Error(
|
|
18150
|
+
'include must be a positive glob filter; negated patterns ("!\u2026") are not supported'
|
|
18151
|
+
);
|
|
18152
|
+
let braceDepth = 0;
|
|
18153
|
+
for (const character of include) {
|
|
18154
|
+
if (character === "{") braceDepth += 1;
|
|
18155
|
+
else if (character === "}") braceDepth = Math.max(0, braceDepth - 1);
|
|
18156
|
+
else if (character === "," && braceDepth === 0) {
|
|
18157
|
+
throw new Error(
|
|
18158
|
+
"include must be one glob, not a comma-separated list (use {a,b} alternation instead)"
|
|
18159
|
+
);
|
|
18160
|
+
}
|
|
18161
|
+
}
|
|
18162
|
+
}
|
|
18163
|
+
function booleanArg2(record, key) {
|
|
18164
|
+
const value = record[key];
|
|
18165
|
+
if (value === void 0) return void 0;
|
|
18166
|
+
if (typeof value !== "boolean") throw new Error(`${key} must be a boolean when given`);
|
|
18167
|
+
return value;
|
|
18168
|
+
}
|
|
18169
|
+
function parseRgArgs(raw) {
|
|
18170
|
+
const record = typeof raw === "object" && raw !== null ? raw : {};
|
|
18171
|
+
const pattern = record.pattern;
|
|
18172
|
+
if (typeof pattern !== "string" || pattern.length === 0)
|
|
18173
|
+
throw new Error("pattern must be a non-empty string");
|
|
18174
|
+
const path = record.path;
|
|
18175
|
+
if (path !== void 0 && (typeof path !== "string" || path.trim().length === 0)) {
|
|
18176
|
+
throw new Error("path must be a non-empty string when given");
|
|
18177
|
+
}
|
|
18178
|
+
const rawInclude = record.include;
|
|
18179
|
+
if (rawInclude !== void 0 && typeof rawInclude !== "string")
|
|
18180
|
+
throw new Error("include must be a string when given");
|
|
18181
|
+
const include = rawInclude === "" ? void 0 : rawInclude;
|
|
18182
|
+
if (include !== void 0) validateInclude(include);
|
|
18183
|
+
return {
|
|
18184
|
+
pattern,
|
|
18185
|
+
...path === void 0 ? {} : { path },
|
|
18186
|
+
...include === void 0 ? {} : { include },
|
|
18187
|
+
...booleanArg2(record, "ignoreCase") === true ? { ignoreCase: true } : {},
|
|
18188
|
+
...booleanArg2(record, "fixedStrings") === true ? { fixedStrings: true } : {},
|
|
18189
|
+
...booleanArg2(record, "wordMatch") === true ? { wordMatch: true } : {},
|
|
18190
|
+
...booleanArg2(record, "hidden") === true ? { hidden: true } : {},
|
|
18191
|
+
...booleanArg2(record, "noIgnore") === true ? { noIgnore: true } : {}
|
|
18192
|
+
};
|
|
18193
|
+
}
|
|
18194
|
+
function buildRgCommand(input) {
|
|
18195
|
+
const parts = ["--json", `--regexp=${input.pattern}`];
|
|
18196
|
+
if (input.include !== void 0) parts.push(`--glob=${input.include}`);
|
|
18197
|
+
if (input.ignoreCase === true) parts.push("--ignore-case");
|
|
18198
|
+
if (input.fixedStrings === true) parts.push("--fixed-strings");
|
|
18199
|
+
if (input.wordMatch === true) parts.push("--word-regexp");
|
|
18200
|
+
if (input.hidden === true) parts.push("--hidden");
|
|
18201
|
+
if (input.noIgnore === true) parts.push("--no-ignore");
|
|
18202
|
+
if (input.path !== void 0) parts.push("--", input.path);
|
|
18203
|
+
return parts;
|
|
18204
|
+
}
|
|
18205
|
+
function malformedRecord(detail) {
|
|
18206
|
+
return new Error(`rg received malformed --json output (${detail})`);
|
|
18207
|
+
}
|
|
18208
|
+
function parseRecord(line) {
|
|
18209
|
+
let parsed;
|
|
18210
|
+
try {
|
|
18211
|
+
parsed = JSON.parse(line);
|
|
18212
|
+
} catch {
|
|
18213
|
+
throw malformedRecord("a line is not JSON");
|
|
18214
|
+
}
|
|
18215
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
18216
|
+
throw malformedRecord("a record is not an object");
|
|
18217
|
+
const record = parsed;
|
|
18218
|
+
if (record.type !== "match") return void 0;
|
|
18219
|
+
if (typeof record.data !== "object" || record.data === null)
|
|
18220
|
+
throw malformedRecord("a match record has no data");
|
|
18221
|
+
const data = record.data;
|
|
18222
|
+
const pathText = typeof data.path === "object" && data.path !== null ? data.path.text : void 0;
|
|
18223
|
+
if (typeof pathText !== "string") throw malformedRecord("a match record has no path text");
|
|
18224
|
+
if (typeof data.line_number !== "number")
|
|
18225
|
+
throw malformedRecord("a match record has no line number");
|
|
18226
|
+
if (typeof data.lines !== "object" || data.lines === null)
|
|
18227
|
+
throw malformedRecord("a match record has no line content");
|
|
18228
|
+
const lines = data.lines;
|
|
18229
|
+
if (typeof lines.text === "string") {
|
|
18230
|
+
return { path: pathText, lineNumber: data.line_number, line: lines.text.replace(/\r?\n$/, "") };
|
|
18231
|
+
}
|
|
18232
|
+
if (typeof lines.bytes === "string") {
|
|
18233
|
+
return { path: pathText, lineNumber: data.line_number, line: "(line is not valid UTF-8)" };
|
|
18234
|
+
}
|
|
18235
|
+
throw malformedRecord("a match record has neither line text nor bytes");
|
|
18236
|
+
}
|
|
18237
|
+
function parseRgOutput(stdout) {
|
|
18238
|
+
const matches = [];
|
|
18239
|
+
for (const line of stdout.split("\n")) {
|
|
18240
|
+
if (line.length === 0) continue;
|
|
18241
|
+
const match = parseRecord(line);
|
|
18242
|
+
if (match !== void 0) matches.push(match);
|
|
18243
|
+
}
|
|
18244
|
+
return matches;
|
|
18245
|
+
}
|
|
18246
|
+
function displayPath(rawPath, cwd) {
|
|
18247
|
+
const stripped = rawPath.startsWith("./") ? rawPath.slice(2) : rawPath;
|
|
18248
|
+
if (!isAbsolute8(stripped)) return stripped;
|
|
18249
|
+
const relativePath2 = relative2(cwd, stripped);
|
|
18250
|
+
if (relativePath2 === "" || isAbsolute8(relativePath2) || relativePath2.startsWith(".."))
|
|
18251
|
+
return stripped;
|
|
18252
|
+
return relativePath2;
|
|
18253
|
+
}
|
|
18254
|
+
|
|
18255
|
+
// dsh/rg/view.ts
|
|
18256
|
+
var GREP_MAX_LINE_BYTES = 2e3;
|
|
18257
|
+
var GREP_META_MAX_BYTES = 65536;
|
|
18258
|
+
function matchNoun(count) {
|
|
18259
|
+
return count === 1 ? "match" : "matches";
|
|
18260
|
+
}
|
|
18261
|
+
function previewLine(line, maxBytes = GREP_MAX_LINE_BYTES) {
|
|
18262
|
+
if (Buffer.byteLength(line, "utf8") <= maxBytes) return line;
|
|
18263
|
+
let used = 0;
|
|
18264
|
+
let cut = "";
|
|
18265
|
+
for (const character of line) {
|
|
18266
|
+
const size = Buffer.byteLength(character, "utf8");
|
|
18267
|
+
if (used + size > maxBytes) break;
|
|
18268
|
+
used += size;
|
|
18269
|
+
cut += character;
|
|
18270
|
+
}
|
|
18271
|
+
return cut + "\u2026";
|
|
18272
|
+
}
|
|
18273
|
+
function retainMatches(matches, maxMatches = GREP_INLINE_MAX_MATCHES) {
|
|
18274
|
+
const items = matches.slice(0, maxMatches);
|
|
18275
|
+
return { items, seen: matches.length, truncated: matches.length > items.length };
|
|
18276
|
+
}
|
|
18277
|
+
function groupByFile(matches) {
|
|
18278
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
18279
|
+
for (const match of matches) {
|
|
18280
|
+
const entry = { lineNumber: match.lineNumber, line: previewLine(match.line) };
|
|
18281
|
+
const group = byFile.get(match.path);
|
|
18282
|
+
if (group !== void 0) group.push(entry);
|
|
18283
|
+
else byFile.set(match.path, [entry]);
|
|
18284
|
+
}
|
|
18285
|
+
return Array.from(byFile, ([path, fileMatches]) => ({ path, matches: fileMatches }));
|
|
18286
|
+
}
|
|
18287
|
+
function formatRgText(matches) {
|
|
18288
|
+
const retained = retainMatches(matches);
|
|
18289
|
+
if (retained.seen === 0) return "No matches found";
|
|
18290
|
+
const header = retained.truncated ? "Found " + retained.items.length + " of " + retained.seen + " matches" : "Found " + retained.seen + " " + matchNoun(retained.seen);
|
|
18291
|
+
const blocks = groupByFile(retained.items).map(
|
|
18292
|
+
(group) => [
|
|
18293
|
+
group.path,
|
|
18294
|
+
group.matches.map((match) => "Line " + match.lineNumber + ": " + match.line).join("\n")
|
|
18295
|
+
].join("\n")
|
|
18296
|
+
);
|
|
18297
|
+
const omitted = retained.seen - retained.items.length;
|
|
18298
|
+
const footer = omitted === 0 ? "" : "\n\n(" + omitted + " more " + matchNoun(omitted) + (omitted === 1 ? " was" : " were") + " not shown; narrow the pattern, path, or include.)";
|
|
18299
|
+
return header + "\n\n" + blocks.join("\n\n") + footer;
|
|
18300
|
+
}
|
|
18301
|
+
function metaBytes(meta) {
|
|
18302
|
+
return Buffer.byteLength(JSON.stringify(meta), "utf8");
|
|
18303
|
+
}
|
|
18304
|
+
function capMetaBytes(meta, maxMetaBytes) {
|
|
18305
|
+
if (metaBytes(meta) <= maxMetaBytes) return meta;
|
|
18306
|
+
const files = [...meta.files];
|
|
18307
|
+
while (files.length > 1 && metaBytes({ ...meta, files, truncated: true }) > maxMetaBytes)
|
|
18308
|
+
files.pop();
|
|
18309
|
+
return { ...meta, files, truncated: true };
|
|
18310
|
+
}
|
|
18311
|
+
function rgMeta(matches, failed = false) {
|
|
18312
|
+
const retained = retainMatches(matches);
|
|
18313
|
+
const meta = {
|
|
18314
|
+
shape: "matches",
|
|
18315
|
+
files: groupByFile(retained.items),
|
|
18316
|
+
truncated: retained.truncated,
|
|
18317
|
+
total: retained.seen,
|
|
18318
|
+
...failed ? { failed: true } : {}
|
|
18319
|
+
};
|
|
18320
|
+
return capMetaBytes(meta, GREP_META_MAX_BYTES);
|
|
18321
|
+
}
|
|
18322
|
+
function isFileMatches(value) {
|
|
18323
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
18324
|
+
const { path, matches } = value;
|
|
18325
|
+
if (typeof path !== "string" || !Array.isArray(matches)) return false;
|
|
18326
|
+
return matches.every((match) => {
|
|
18327
|
+
if (typeof match !== "object" || match === null || Array.isArray(match)) return false;
|
|
18328
|
+
const { lineNumber, line } = match;
|
|
18329
|
+
return typeof lineNumber === "number" && typeof line === "string";
|
|
18330
|
+
});
|
|
18331
|
+
}
|
|
18332
|
+
function searchViewFromMeta(meta) {
|
|
18333
|
+
if (typeof meta !== "object" || meta === null || Array.isArray(meta)) return void 0;
|
|
18334
|
+
const record = meta;
|
|
18335
|
+
if (record.shape !== "matches" || record.failed === true) return void 0;
|
|
18336
|
+
const { files, truncated, total } = record;
|
|
18337
|
+
if (!Array.isArray(files) || !files.every(isFileMatches)) return void 0;
|
|
18338
|
+
if (typeof truncated !== "boolean" || typeof total !== "number") return void 0;
|
|
18339
|
+
return { card: "search", shape: "matches", files, truncated, total };
|
|
18340
|
+
}
|
|
18341
|
+
|
|
18342
|
+
// dsh/rg/tools.ts
|
|
18343
|
+
var RG_TOOL_NAME2 = "rg";
|
|
18344
|
+
var CALL_TIMEOUT_MARGIN_MS = 5e3;
|
|
18345
|
+
var CAPTURE_BUDGET_MB = 8;
|
|
18346
|
+
var DESCRIPTION2 = [
|
|
18347
|
+
"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.",
|
|
18348
|
+
"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.",
|
|
18349
|
+
"When the `read` switch is on, every matched line is served as `HASH\u2502content` rows, so the following `edit` or `apply_patch` needs no separate `read`.",
|
|
18350
|
+
"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."
|
|
18351
|
+
].join("\n\n");
|
|
18352
|
+
var PARAMETERS2 = {
|
|
18353
|
+
pattern: {
|
|
18354
|
+
type: "string",
|
|
18355
|
+
required: true,
|
|
18356
|
+
description: "Regular expression to search for (ripgrep syntax)."
|
|
18357
|
+
},
|
|
18358
|
+
path: {
|
|
18359
|
+
type: "string",
|
|
18360
|
+
description: "File or directory to search. Defaults to the session working directory; a relative path resolves against it."
|
|
18361
|
+
},
|
|
18362
|
+
include: {
|
|
18363
|
+
type: "string",
|
|
18364
|
+
description: 'One glob filter for which files to search (e.g. "*.ts", "*.{js,jsx}"). Not a list; negation is not supported.'
|
|
18365
|
+
},
|
|
18366
|
+
ignoreCase: {
|
|
18367
|
+
type: "boolean",
|
|
18368
|
+
description: "Search case-insensitively (`-i`). Default keeps ripgrep's smart case: insensitive only when the pattern has no uppercase letter."
|
|
18369
|
+
},
|
|
18370
|
+
fixedStrings: {
|
|
18371
|
+
type: "boolean",
|
|
18372
|
+
description: "Treat `pattern` as literal text (`-F`) instead of a regular expression."
|
|
18373
|
+
},
|
|
18374
|
+
wordMatch: {
|
|
18375
|
+
type: "boolean",
|
|
18376
|
+
description: "Only match whole words (`-w`)."
|
|
18377
|
+
},
|
|
18378
|
+
hidden: {
|
|
18379
|
+
type: "boolean",
|
|
18380
|
+
description: "Also search hidden files and directories (`--hidden`)."
|
|
18381
|
+
},
|
|
18382
|
+
noIgnore: {
|
|
18383
|
+
type: "boolean",
|
|
18384
|
+
description: "Ignore `.gitignore`/`.ignore` rules and search every file (`--no-ignore`)."
|
|
18385
|
+
}
|
|
18386
|
+
};
|
|
18387
|
+
var OUTCOME_SCHEMA3 = {
|
|
18388
|
+
type: "object",
|
|
18389
|
+
properties: {
|
|
18390
|
+
matches: {
|
|
18391
|
+
type: "array",
|
|
18392
|
+
required: true,
|
|
18393
|
+
items: {
|
|
18394
|
+
type: "object",
|
|
18395
|
+
additionalProperties: false,
|
|
18396
|
+
properties: {
|
|
18397
|
+
path: { type: "string", required: true },
|
|
18398
|
+
lineNumber: { type: "integer", required: true },
|
|
18399
|
+
line: { type: "string", required: true }
|
|
18400
|
+
}
|
|
18401
|
+
}
|
|
18402
|
+
},
|
|
18403
|
+
note: { type: "string" }
|
|
18404
|
+
},
|
|
18405
|
+
additionalProperties: false
|
|
18406
|
+
};
|
|
18407
|
+
function missingRgText(problem) {
|
|
18408
|
+
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.";
|
|
18409
|
+
}
|
|
18410
|
+
function tail(text, maxLines = 20) {
|
|
18411
|
+
const lines = text.trimEnd().split("\n");
|
|
18412
|
+
return lines.slice(Math.max(0, lines.length - maxLines)).join("\n");
|
|
18413
|
+
}
|
|
18414
|
+
function outcomeFor(run, cwd, timeoutMs) {
|
|
18415
|
+
if (run.timedOut) {
|
|
18416
|
+
return {
|
|
18417
|
+
matches: [],
|
|
18418
|
+
note: "rg stopped after " + timeoutMs + " ms without finishing. Narrow the pattern, path, or include."
|
|
18419
|
+
};
|
|
18420
|
+
}
|
|
18421
|
+
if (run.overflow) {
|
|
18422
|
+
return {
|
|
18423
|
+
matches: [],
|
|
18424
|
+
note: "rg produced more output than the " + CAPTURE_BUDGET_MB + " MB capture budget and was not parsed. Narrow the pattern, path, or include."
|
|
18425
|
+
};
|
|
18426
|
+
}
|
|
18427
|
+
if (run.code === 1) return { matches: [] };
|
|
18428
|
+
if (run.code !== 0) {
|
|
18429
|
+
const diagnostics = tail(run.stderr);
|
|
18430
|
+
const detail = diagnostics === "" ? " (no stderr output)" : "\n" + diagnostics;
|
|
18431
|
+
return { matches: [], note: "rg exited with code " + String(run.code) + ":" + detail };
|
|
18432
|
+
}
|
|
18433
|
+
return {
|
|
18434
|
+
matches: parseRgOutput(run.stdout).map((match) => ({
|
|
18435
|
+
...match,
|
|
18436
|
+
path: displayPath(match.path, cwd)
|
|
18437
|
+
}))
|
|
18438
|
+
};
|
|
18439
|
+
}
|
|
18440
|
+
function presentCall(args) {
|
|
18441
|
+
const where = args.path !== void 0 ? " in " + args.path : "";
|
|
18442
|
+
const filter = args.include !== void 0 && args.include !== "" ? " (" + args.include + ")" : "";
|
|
18443
|
+
return {
|
|
18444
|
+
card: "generic",
|
|
18445
|
+
title: "Rg " + args.pattern + where + filter,
|
|
18446
|
+
kind: "search",
|
|
18447
|
+
rawInput: args.pattern
|
|
18448
|
+
};
|
|
18449
|
+
}
|
|
18450
|
+
function buildRgTool(options = {}) {
|
|
18451
|
+
const timeoutMs = options.timeoutMs ?? RG_TIMEOUT_MS;
|
|
18452
|
+
return defineTool6({
|
|
18453
|
+
name: RG_TOOL_NAME2,
|
|
18454
|
+
description: DESCRIPTION2,
|
|
18455
|
+
parameters: PARAMETERS2,
|
|
18456
|
+
// WHY: the spawn timer reports its own timeout as guidance, so the cooperative budget must
|
|
18457
|
+
// WHY: never preempt that message — it only backstops a run that never settles.
|
|
18458
|
+
timeoutMs: timeoutMs + CALL_TIMEOUT_MARGIN_MS,
|
|
18459
|
+
output: {
|
|
18460
|
+
schema: OUTCOME_SCHEMA3,
|
|
18461
|
+
render: (_args, value) => [{ type: "text", text: value.note ?? formatRgText(value.matches) }],
|
|
18462
|
+
presentationMeta: (_args, value) => rgMeta(value.matches, value.note !== void 0)
|
|
18463
|
+
},
|
|
18464
|
+
async execute(args, exec) {
|
|
18465
|
+
const input = parseRgArgs(args);
|
|
18466
|
+
const ctx = resolveToolContext(exec);
|
|
18467
|
+
const locate = options.resolveRg ?? (() => resolveRgInvocation());
|
|
18468
|
+
const resolution = locate();
|
|
18469
|
+
if (!resolution.ok) return { matches: [], note: missingRgText(resolution.problem) };
|
|
18470
|
+
const runner = options.run ?? runRg;
|
|
18471
|
+
let run;
|
|
18472
|
+
try {
|
|
18473
|
+
run = await runner(resolution.invocation, buildRgCommand(input), {
|
|
18474
|
+
cwd: ctx.cwd,
|
|
18475
|
+
signal: ctx.signal,
|
|
18476
|
+
timeoutMs
|
|
18477
|
+
});
|
|
18478
|
+
} catch (error) {
|
|
18479
|
+
ctx.signal?.throwIfAborted();
|
|
18480
|
+
return {
|
|
18481
|
+
matches: [],
|
|
18482
|
+
note: "rg could not start: " + (error instanceof Error ? error.message : String(error))
|
|
18483
|
+
};
|
|
18484
|
+
}
|
|
18485
|
+
return outcomeFor(run, ctx.cwd, timeoutMs);
|
|
18486
|
+
},
|
|
18487
|
+
presentCall,
|
|
18488
|
+
presentResult: (_args, result) => result.isError ? void 0 : searchViewFromMeta(result.meta)
|
|
18489
|
+
});
|
|
18490
|
+
}
|
|
18491
|
+
|
|
18492
|
+
// dsh/write-hook.ts
|
|
18493
|
+
var AUTO_READ_HEADING = "--- Auto-read (hashline anchors) ---";
|
|
18494
|
+
function errorMessage3(error) {
|
|
18495
|
+
return error instanceof Error ? error.message : String(error);
|
|
18496
|
+
}
|
|
18497
|
+
function writeRequest(exec) {
|
|
18498
|
+
const args = exec.arguments;
|
|
18499
|
+
const rawPath = args?.file_path ?? args?.path;
|
|
18500
|
+
const content = args?.content;
|
|
18501
|
+
if (typeof rawPath !== "string" || typeof content !== "string") return void 0;
|
|
18502
|
+
return { rawPath, content };
|
|
18503
|
+
}
|
|
18504
|
+
function execContext2(exec) {
|
|
18505
|
+
const agent = exec.agent;
|
|
18506
|
+
const session = agent?.session;
|
|
18507
|
+
const get = agent?.ctx?.get;
|
|
18508
|
+
const workingDirectory = typeof get === "function" && agent?.ctx !== void 0 ? get.call(agent.ctx, "workingDirectory") : void 0;
|
|
18509
|
+
const cwd = session !== void 0 && workingDirectory !== void 0 && typeof workingDirectory.get === "function" ? workingDirectory.get(session) : session?.header?.cwd ?? process.cwd();
|
|
18510
|
+
const sessionKey = session?.id !== void 0 && session.id.length > 0 ? session.id : void 0;
|
|
16048
18511
|
return { cwd, sessionKey };
|
|
16049
18512
|
}
|
|
16050
18513
|
async function servedHashEchoReason(deps, rawPath, content, cwd, sessionKey, signal) {
|
|
@@ -16215,7 +18678,12 @@ var inject = ["agents", "tools", "systemPrompt"];
|
|
|
16215
18678
|
var Config = Schema.object({
|
|
16216
18679
|
read: Schema.boolean().default(true).volatile(),
|
|
16217
18680
|
applyPatch: Schema.boolean().default(true).volatile(),
|
|
16218
|
-
edit: Schema.boolean().default(false).volatile()
|
|
18681
|
+
edit: Schema.boolean().default(false).volatile(),
|
|
18682
|
+
codegraph: Schema.boolean().default(false).volatile(),
|
|
18683
|
+
codegraphPath: Schema.string().default("").volatile(),
|
|
18684
|
+
diagnostics: Schema.boolean().default(false).volatile(),
|
|
18685
|
+
rg: Schema.boolean().default(true).volatile(),
|
|
18686
|
+
rgPath: Schema.string().default("").volatile()
|
|
16219
18687
|
});
|
|
16220
18688
|
function switchValue(value, fallback) {
|
|
16221
18689
|
if (typeof value === "boolean") return value;
|
|
@@ -16229,12 +18697,29 @@ function switchValue(value, fallback) {
|
|
|
16229
18697
|
}
|
|
16230
18698
|
return fallback;
|
|
16231
18699
|
}
|
|
18700
|
+
function stringValue(value, fallback) {
|
|
18701
|
+
if (typeof value === "string") return value;
|
|
18702
|
+
if (value !== null && typeof value === "object" && typeof value.get === "function") {
|
|
18703
|
+
try {
|
|
18704
|
+
const inner = value.get();
|
|
18705
|
+
return typeof inner === "string" ? inner : fallback;
|
|
18706
|
+
} catch {
|
|
18707
|
+
return fallback;
|
|
18708
|
+
}
|
|
18709
|
+
}
|
|
18710
|
+
return fallback;
|
|
18711
|
+
}
|
|
16232
18712
|
function resolveSwitches(config = {}) {
|
|
16233
18713
|
const fields = config;
|
|
16234
18714
|
return {
|
|
16235
18715
|
read: switchValue(fields.read, true),
|
|
16236
18716
|
applyPatch: switchValue(fields.applyPatch, true),
|
|
16237
|
-
edit: switchValue(fields.edit, false)
|
|
18717
|
+
edit: switchValue(fields.edit, false),
|
|
18718
|
+
codegraph: switchValue(fields.codegraph, false),
|
|
18719
|
+
codegraphPath: stringValue(fields.codegraphPath, ""),
|
|
18720
|
+
diagnostics: switchValue(fields.diagnostics, false),
|
|
18721
|
+
rg: switchValue(fields.rg, true),
|
|
18722
|
+
rgPath: stringValue(fields.rgPath, "")
|
|
16238
18723
|
};
|
|
16239
18724
|
}
|
|
16240
18725
|
function toolsOfAgent(agent) {
|
|
@@ -16291,14 +18776,41 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
|
|
|
16291
18776
|
disposers.push(edit.dispose);
|
|
16292
18777
|
}
|
|
16293
18778
|
}
|
|
16294
|
-
if (
|
|
18779
|
+
if (switches.codegraph) {
|
|
18780
|
+
const codegraph = {
|
|
18781
|
+
resolution: resolveCodegraphInvocation({ explicitPath: switches.codegraphPath })
|
|
18782
|
+
};
|
|
18783
|
+
for (const definition of buildCodegraphTools(deps, codegraph)) {
|
|
18784
|
+
const dispose = registerToolQuietly(rootCtx, agent, definition, "codegraph");
|
|
18785
|
+
if (dispose !== void 0) disposers.push(dispose);
|
|
18786
|
+
}
|
|
18787
|
+
}
|
|
18788
|
+
if (switches.diagnostics) {
|
|
18789
|
+
for (const definition of buildDiagnosticsTools(deps)) {
|
|
18790
|
+
const dispose = registerToolQuietly(rootCtx, agent, definition, "diagnostics");
|
|
18791
|
+
if (dispose !== void 0) disposers.push(dispose);
|
|
18792
|
+
}
|
|
18793
|
+
}
|
|
18794
|
+
if (switches.rg) {
|
|
18795
|
+
const rg = buildRgTool({
|
|
18796
|
+
resolveRg: () => resolveRgInvocation({ explicitPath: switches.rgPath })
|
|
18797
|
+
});
|
|
18798
|
+
const dispose = registerToolQuietly(rootCtx, agent, rg, "rg");
|
|
18799
|
+
if (dispose !== void 0) disposers.push(dispose);
|
|
18800
|
+
}
|
|
18801
|
+
if (registered.length > 0 || switches.rg) {
|
|
16295
18802
|
disposers.push(
|
|
16296
18803
|
registerNativeToolHiding(rootCtx, agent.ctx, {
|
|
16297
18804
|
toolNames: registered,
|
|
16298
|
-
// WHY:
|
|
16299
|
-
// WHY:
|
|
16300
|
-
|
|
16301
|
-
|
|
18805
|
+
// WHY: the `rg` lane replaces the native search tool under a different name, which
|
|
18806
|
+
// WHY: no same-name probe can mask.
|
|
18807
|
+
hiddenToolNames: switches.rg ? ["grep"] : [],
|
|
18808
|
+
// WHY: the native `grep` brief describes a tool this profile no longer has; the
|
|
18809
|
+
// WHY: replacement carries its own `tool:rg` brief.
|
|
18810
|
+
guidanceToClear: switches.rg ? ["tool:grep"] : [],
|
|
18811
|
+
...switches.rg ? {
|
|
18812
|
+
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
|
|
18813
|
+
} : {},
|
|
16302
18814
|
scope: agent
|
|
16303
18815
|
})
|
|
16304
18816
|
);
|
|
@@ -16334,6 +18846,19 @@ function registerMutationTool(rootCtx, agent, deps, build) {
|
|
|
16334
18846
|
return null;
|
|
16335
18847
|
}
|
|
16336
18848
|
}
|
|
18849
|
+
function registerToolQuietly(rootCtx, agent, definition, lane) {
|
|
18850
|
+
try {
|
|
18851
|
+
const agentTools = toolsOfAgent(agent);
|
|
18852
|
+
if (agentTools === void 0) throw new Error("agent tools registry is unavailable");
|
|
18853
|
+
return agentTools.register(definition);
|
|
18854
|
+
} catch (error) {
|
|
18855
|
+
warnVia3(
|
|
18856
|
+
rootCtx,
|
|
18857
|
+
`${lane} tool registration failed for agent ${agent.id} (${definition.name}): ${error instanceof Error ? error.message : String(error)}; that tool stays off for this agent`
|
|
18858
|
+
);
|
|
18859
|
+
return void 0;
|
|
18860
|
+
}
|
|
18861
|
+
}
|
|
16337
18862
|
function disposeReverse(disposers) {
|
|
16338
18863
|
while (disposers.length > 0) {
|
|
16339
18864
|
const dispose = disposers.pop();
|
|
@@ -16393,6 +18918,46 @@ function apply2(rootCtx, config = {}) {
|
|
|
16393
18918
|
if (switches.edit) {
|
|
16394
18919
|
disposers.push(rootCtx.tools.register(buildEditTool(rootDeps)));
|
|
16395
18920
|
}
|
|
18921
|
+
if (switches.codegraph) {
|
|
18922
|
+
const codegraph = {
|
|
18923
|
+
resolution: resolveCodegraphInvocation({ explicitPath: switches.codegraphPath })
|
|
18924
|
+
};
|
|
18925
|
+
for (const definition of buildCodegraphTools(rootDeps, codegraph)) {
|
|
18926
|
+
try {
|
|
18927
|
+
disposers.push(rootCtx.tools.register(definition));
|
|
18928
|
+
} catch (error) {
|
|
18929
|
+
rootCtx.logger.warn(
|
|
18930
|
+
`dsh-hashline-edit: root codegraph tool registration failed for ${definition.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
18931
|
+
);
|
|
18932
|
+
}
|
|
18933
|
+
}
|
|
18934
|
+
}
|
|
18935
|
+
if (switches.diagnostics) {
|
|
18936
|
+
for (const definition of buildDiagnosticsTools(rootDeps)) {
|
|
18937
|
+
try {
|
|
18938
|
+
disposers.push(rootCtx.tools.register(definition));
|
|
18939
|
+
} catch (error) {
|
|
18940
|
+
rootCtx.logger.warn(
|
|
18941
|
+
`dsh-hashline-edit: root diagnostics tool registration failed for ${definition.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
18942
|
+
);
|
|
18943
|
+
}
|
|
18944
|
+
}
|
|
18945
|
+
}
|
|
18946
|
+
if (switches.rg) {
|
|
18947
|
+
try {
|
|
18948
|
+
disposers.push(
|
|
18949
|
+
rootCtx.tools.register(
|
|
18950
|
+
buildRgTool({
|
|
18951
|
+
resolveRg: () => resolveRgInvocation({ explicitPath: switches.rgPath })
|
|
18952
|
+
})
|
|
18953
|
+
)
|
|
18954
|
+
);
|
|
18955
|
+
} catch (error) {
|
|
18956
|
+
rootCtx.logger.warn(
|
|
18957
|
+
`dsh-hashline-edit: root rg tool registration failed: ${error instanceof Error ? error.message : String(error)}`
|
|
18958
|
+
);
|
|
18959
|
+
}
|
|
18960
|
+
}
|
|
16396
18961
|
} catch (error) {
|
|
16397
18962
|
disposeReverse(disposers);
|
|
16398
18963
|
rootCtx.logger.warn(
|