@caupulican/pi-adaptative 0.84.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
- package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +4 -2
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +3 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +6 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +28 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +46 -11
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/doctor.d.ts +1 -1
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +5 -4
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +6 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
- package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/session-task-profile-store.js +138 -0
- package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
- package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
- package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
- package/dist/core/orchestration/task-profile-writer.js +165 -0
- package/dist/core/orchestration/task-profile-writer.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +3 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +14 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +4 -6
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -0
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +21 -23
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.js +1 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -6
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +2 -26
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.js +4 -4
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +32 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +137 -69
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +22 -7
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +128 -55
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-intent.d.ts +70 -0
- package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-intent.js +325 -0
- package/dist/core/tools/file-mutation-intent.js.map +1 -0
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +41 -18
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +3 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +31 -8
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +33 -0
- package/dist/core/tools/profile-writer.d.ts.map +1 -0
- package/dist/core/tools/profile-writer.js +67 -0
- package/dist/core/tools/profile-writer.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +6 -11
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +2 -0
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +16 -2
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/write.d.ts +24 -7
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +182 -107
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jscpd-cli.d.ts +3 -0
- package/dist/jscpd-cli.d.ts.map +1 -0
- package/dist/jscpd-cli.js +22 -0
- package/dist/jscpd-cli.js.map +1 -0
- package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +85 -3
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/bundled-jscpd.d.ts +20 -0
- package/dist/utils/bundled-jscpd.d.ts.map +1 -0
- package/dist/utils/bundled-jscpd.js +154 -0
- package/dist/utils/bundled-jscpd.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +11 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +22 -0
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/index.md +3 -0
- package/docs/managed-data-tools.md +15 -0
- package/docs/quickstart.md +2 -2
- package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
- package/docs/tool-repair.md +1 -1
- package/docs/worker-profiles.md +16 -0
- package/examples/extensions/built-in-tool-renderer.ts +12 -5
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +8 -7
- package/examples/extensions/prompt-customizer.ts +4 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/ssh.ts +113 -24
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +112 -12
- package/package.json +7 -5
|
@@ -28,6 +28,26 @@ export interface FuzzyMatchResult {
|
|
|
28
28
|
export interface Edit {
|
|
29
29
|
oldText: string;
|
|
30
30
|
newText: string;
|
|
31
|
+
/** Inclusive 1-based line bounds from the read that supplied oldText. */
|
|
32
|
+
range?: EditRange;
|
|
33
|
+
}
|
|
34
|
+
export interface EditRange {
|
|
35
|
+
startLine: number;
|
|
36
|
+
endLine: number;
|
|
37
|
+
}
|
|
38
|
+
interface PlannedEdit {
|
|
39
|
+
editIndex: number;
|
|
40
|
+
matchIndex: number;
|
|
41
|
+
matchLength: number;
|
|
42
|
+
newText: string;
|
|
43
|
+
expectedText: string;
|
|
44
|
+
}
|
|
45
|
+
export interface EditMatchPlan {
|
|
46
|
+
/** Length of the LF-normalized source against which this plan was validated. */
|
|
47
|
+
baseLength: number;
|
|
48
|
+
editCount: number;
|
|
49
|
+
/** Compact, source-ordered replacement spans; the source body is not retained. */
|
|
50
|
+
edits: readonly PlannedEdit[];
|
|
31
51
|
}
|
|
32
52
|
export interface AppliedEditsResult {
|
|
33
53
|
baseContent: string;
|
|
@@ -45,13 +65,15 @@ export declare function stripBom(content: string): {
|
|
|
45
65
|
text: string;
|
|
46
66
|
};
|
|
47
67
|
/**
|
|
48
|
-
*
|
|
68
|
+
* Match and validate one or more replacements against LF-normalized content.
|
|
49
69
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* into the original content.
|
|
70
|
+
* The returned plan retains only the validated spans and their replacement
|
|
71
|
+
* text. Exact matching uses native substring search, bounded by optional line
|
|
72
|
+
* ranges, while uniqueness is still proven across the whole source.
|
|
54
73
|
*/
|
|
74
|
+
export declare function planEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): EditMatchPlan;
|
|
75
|
+
/** Apply a validated match plan to the same LF-normalized source in one linear join. */
|
|
76
|
+
export declare function applyEditMatchPlan(normalizedContent: string, plan: EditMatchPlan, path: string): AppliedEditsResult;
|
|
55
77
|
export declare function applyEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): AppliedEditsResult;
|
|
56
78
|
/** Generate a standard unified patch. */
|
|
57
79
|
export declare function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines?: number): string;
|
|
@@ -70,14 +92,19 @@ export interface EditDiffResult {
|
|
|
70
92
|
export interface EditDiffError {
|
|
71
93
|
error: string;
|
|
72
94
|
}
|
|
95
|
+
export interface EditPlannedDiffResult extends EditDiffResult {
|
|
96
|
+
plan: EditMatchPlan;
|
|
97
|
+
}
|
|
73
98
|
/**
|
|
74
99
|
* Compute the diff for one or more edit operations without applying them.
|
|
75
100
|
* Used for preview rendering in the TUI before the tool executes.
|
|
76
101
|
*/
|
|
102
|
+
export declare function computeEditsPlannedDiff(path: string, edits: Edit[], cwd: string): Promise<EditPlannedDiffResult | EditDiffError>;
|
|
77
103
|
export declare function computeEditsDiff(path: string, edits: Edit[], cwd: string): Promise<EditDiffResult | EditDiffError>;
|
|
78
104
|
/**
|
|
79
105
|
* Compute the diff for a single edit operation without applying it.
|
|
80
106
|
* Kept as a convenience wrapper for single-edit callers.
|
|
81
107
|
*/
|
|
82
108
|
export declare function computeEditDiff(path: string, oldText: string, newText: string, cwd: string): Promise<EditDiffResult | EditDiffError>;
|
|
109
|
+
export {};
|
|
83
110
|
//# sourceMappingURL=edit-diff.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM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AI,EAAE,EACb,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,qBAAqB,GAAG,aAAa,CAAC,CA0BhD;AAED,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,IAAI,EAAE,EACb,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAIzC;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAEzC"}
|
|
@@ -29,12 +29,11 @@ export function restoreLineEndings(text, ending) {
|
|
|
29
29
|
* - Normalize special Unicode spaces to regular space
|
|
30
30
|
*/
|
|
31
31
|
export function normalizeForFuzzyMatch(text) {
|
|
32
|
+
return normalizeFuzzyCharacters(text).replace(/[^\S\n]+(?=\n|$)/gu, "");
|
|
33
|
+
}
|
|
34
|
+
function normalizeFuzzyCharacters(text) {
|
|
32
35
|
return (text
|
|
33
36
|
.normalize("NFKC")
|
|
34
|
-
// Strip trailing whitespace per line
|
|
35
|
-
.split("\n")
|
|
36
|
-
.map((line) => line.trimEnd())
|
|
37
|
-
.join("\n")
|
|
38
37
|
// Smart single quotes → '
|
|
39
38
|
.replace(/[\u2018\u2019\u201A\u201B]/g, "'")
|
|
40
39
|
// Smart double quotes → "
|
|
@@ -91,12 +90,18 @@ export function stripBom(content) {
|
|
|
91
90
|
return content.startsWith("\uFEFF") ? { bom: "\uFEFF", text: content.slice(1) } : { bom: "", text: content };
|
|
92
91
|
}
|
|
93
92
|
function countExactOccurrences(content, oldText) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
if (oldText.length === 0)
|
|
94
|
+
return 0;
|
|
95
|
+
let count = 0;
|
|
96
|
+
let searchFrom = 0;
|
|
97
|
+
while (searchFrom <= content.length - oldText.length) {
|
|
98
|
+
const index = content.indexOf(oldText, searchFrom);
|
|
99
|
+
if (index === -1)
|
|
100
|
+
break;
|
|
101
|
+
count++;
|
|
102
|
+
searchFrom = index + 1;
|
|
103
|
+
}
|
|
104
|
+
return count;
|
|
100
105
|
}
|
|
101
106
|
function getLineStarts(content) {
|
|
102
107
|
const starts = [0];
|
|
@@ -128,19 +133,24 @@ function lineTextAt(content, lineStarts, lineIndex) {
|
|
|
128
133
|
function normalizedColumnToOriginalColumn(line, normalizedColumn) {
|
|
129
134
|
if (normalizedColumn <= 0)
|
|
130
135
|
return 0;
|
|
131
|
-
|
|
132
|
-
for (
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
originalColumn = nextColumn;
|
|
136
|
+
const boundaries = [0];
|
|
137
|
+
for (let index = 0; index < line.length;) {
|
|
138
|
+
const codePoint = line.codePointAt(index);
|
|
139
|
+
index += codePoint !== undefined && codePoint > 0xffff ? 2 : 1;
|
|
140
|
+
boundaries.push(index);
|
|
137
141
|
}
|
|
138
|
-
|
|
142
|
+
let low = 1;
|
|
143
|
+
let high = boundaries.length - 1;
|
|
144
|
+
while (low < high) {
|
|
145
|
+
const mid = Math.floor((low + high) / 2);
|
|
146
|
+
if (normalizeForFuzzyMatch(line.slice(0, boundaries[mid])).length >= normalizedColumn)
|
|
147
|
+
high = mid;
|
|
148
|
+
else
|
|
149
|
+
low = mid + 1;
|
|
150
|
+
}
|
|
151
|
+
return boundaries[low] ?? line.length;
|
|
139
152
|
}
|
|
140
|
-
function mapFuzzySpanToOriginal(originalContent, normalizedIndex, normalizedLength) {
|
|
141
|
-
const fuzzyContent = normalizeForFuzzyMatch(originalContent);
|
|
142
|
-
const fuzzyLineStarts = getLineStarts(fuzzyContent);
|
|
143
|
-
const originalLineStarts = getLineStarts(originalContent);
|
|
153
|
+
function mapFuzzySpanToOriginal(originalContent, originalLineStarts, fuzzyLineStarts, normalizedIndex, normalizedLength) {
|
|
144
154
|
const start = lineColumnAt(fuzzyLineStarts, normalizedIndex);
|
|
145
155
|
const end = lineColumnAt(fuzzyLineStarts, normalizedIndex + normalizedLength);
|
|
146
156
|
const startLine = lineTextAt(originalContent, originalLineStarts, start.lineIndex);
|
|
@@ -149,11 +159,12 @@ function mapFuzzySpanToOriginal(originalContent, normalizedIndex, normalizedLeng
|
|
|
149
159
|
const originalEnd = originalLineStarts[end.lineIndex] + normalizedColumnToOriginalColumn(endLine, end.column);
|
|
150
160
|
return { index: originalStart, length: originalEnd - originalStart };
|
|
151
161
|
}
|
|
152
|
-
function getNotFoundError(path, editIndex, totalEdits) {
|
|
162
|
+
function getNotFoundError(path, editIndex, totalEdits, range) {
|
|
163
|
+
const rangeSuffix = range ? ` within lines ${range.startLine}-${range.endLine}` : "";
|
|
153
164
|
if (totalEdits === 1) {
|
|
154
|
-
return new Error(`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`);
|
|
165
|
+
return new Error(`Could not find the exact text in ${path}${rangeSuffix}. The old text must match exactly including all whitespace and newlines.`);
|
|
155
166
|
}
|
|
156
|
-
return new Error(`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`);
|
|
167
|
+
return new Error(`Could not find edits[${editIndex}] in ${path}${rangeSuffix}. The oldText must match exactly including all whitespace and newlines.`);
|
|
157
168
|
}
|
|
158
169
|
function getDuplicateError(path, editIndex, totalEdits, occurrences) {
|
|
159
170
|
if (totalEdits === 1) {
|
|
@@ -173,68 +184,118 @@ function getNoChangeError(path, totalEdits) {
|
|
|
173
184
|
}
|
|
174
185
|
return new Error(`No changes made to ${path}. The replacements produced identical content.`);
|
|
175
186
|
}
|
|
187
|
+
function validateRange(range, lineStarts, contentLength, path, editIndex, totalEdits) {
|
|
188
|
+
if (!range)
|
|
189
|
+
return { start: 0, end: contentLength };
|
|
190
|
+
const label = totalEdits === 1 ? "range" : `edits[${editIndex}].range`;
|
|
191
|
+
if (!Number.isSafeInteger(range.startLine) ||
|
|
192
|
+
!Number.isSafeInteger(range.endLine) ||
|
|
193
|
+
range.startLine < 1 ||
|
|
194
|
+
range.endLine < range.startLine) {
|
|
195
|
+
throw new Error(`${label} in ${path} must contain inclusive positive line numbers with startLine <= endLine.`);
|
|
196
|
+
}
|
|
197
|
+
if (!lineStarts || range.endLine > lineStarts.length) {
|
|
198
|
+
throw new Error(`${label} in ${path} exceeds the file's ${lineStarts?.length ?? 0} lines.`);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
start: lineStarts[range.startLine - 1],
|
|
202
|
+
end: lineStarts[range.endLine] ?? contentLength,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function findWithin(content, oldText, window) {
|
|
206
|
+
if (oldText.length === 0 || oldText.length > window.end - window.start)
|
|
207
|
+
return -1;
|
|
208
|
+
const index = content.indexOf(oldText, window.start);
|
|
209
|
+
return index !== -1 && index + oldText.length <= window.end ? index : -1;
|
|
210
|
+
}
|
|
211
|
+
function rangesOverlap(previous, current) {
|
|
212
|
+
return previous.matchIndex + previous.matchLength > current.matchIndex;
|
|
213
|
+
}
|
|
176
214
|
/**
|
|
177
|
-
*
|
|
215
|
+
* Match and validate one or more replacements against LF-normalized content.
|
|
178
216
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* into the original content.
|
|
217
|
+
* The returned plan retains only the validated spans and their replacement
|
|
218
|
+
* text. Exact matching uses native substring search, bounded by optional line
|
|
219
|
+
* ranges, while uniqueness is still proven across the whole source.
|
|
183
220
|
*/
|
|
184
|
-
export function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
throw getEmptyOldTextError(path, i, normalizedEdits.length);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const baseContent = normalizedContent;
|
|
221
|
+
export function planEditsToNormalizedContent(normalizedContent, edits, path) {
|
|
222
|
+
let originalLineStarts;
|
|
223
|
+
let fuzzyContent;
|
|
224
|
+
let fuzzyLineStarts;
|
|
225
|
+
const needsLineStarts = edits.some((edit) => edit.range !== undefined);
|
|
226
|
+
if (needsLineStarts)
|
|
227
|
+
originalLineStarts = getLineStarts(normalizedContent);
|
|
195
228
|
const matchedEdits = [];
|
|
196
|
-
for (let i = 0; i <
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
for (let i = 0; i < edits.length; i++) {
|
|
230
|
+
const sourceEdit = edits[i];
|
|
231
|
+
const oldText = normalizeToLF(sourceEdit.oldText);
|
|
232
|
+
const newText = normalizeToLF(sourceEdit.newText);
|
|
233
|
+
if (oldText.length === 0)
|
|
234
|
+
throw getEmptyOldTextError(path, i, edits.length);
|
|
235
|
+
const exactWindow = validateRange(sourceEdit.range, originalLineStarts, normalizedContent.length, path, i, edits.length);
|
|
236
|
+
let matchIndex = findWithin(normalizedContent, oldText, exactWindow);
|
|
237
|
+
let matchLength = oldText.length;
|
|
238
|
+
let occurrences;
|
|
239
|
+
if (matchIndex !== -1) {
|
|
240
|
+
occurrences = countExactOccurrences(normalizedContent, oldText);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
fuzzyContent ??= normalizeForFuzzyMatch(normalizedContent);
|
|
244
|
+
fuzzyLineStarts ??= getLineStarts(fuzzyContent);
|
|
245
|
+
originalLineStarts ??= getLineStarts(normalizedContent);
|
|
246
|
+
const fuzzyOldText = normalizeForFuzzyMatch(oldText);
|
|
247
|
+
const fuzzyWindow = validateRange(sourceEdit.range, fuzzyLineStarts, fuzzyContent.length, path, i, edits.length);
|
|
248
|
+
const fuzzyIndex = findWithin(fuzzyContent, fuzzyOldText, fuzzyWindow);
|
|
249
|
+
if (fuzzyIndex === -1)
|
|
250
|
+
throw getNotFoundError(path, i, edits.length, sourceEdit.range);
|
|
251
|
+
occurrences = countExactOccurrences(fuzzyContent, fuzzyOldText);
|
|
252
|
+
const replacementSpan = mapFuzzySpanToOriginal(normalizedContent, originalLineStarts, fuzzyLineStarts, fuzzyIndex, fuzzyOldText.length);
|
|
253
|
+
matchIndex = replacementSpan.index;
|
|
254
|
+
matchLength = replacementSpan.length;
|
|
201
255
|
}
|
|
202
|
-
const occurrences = matchResult.usedFuzzyMatch
|
|
203
|
-
? countFuzzyOccurrences(baseContent, edit.oldText)
|
|
204
|
-
: countExactOccurrences(baseContent, edit.oldText);
|
|
205
256
|
if (occurrences > 1) {
|
|
206
|
-
throw getDuplicateError(path, i,
|
|
257
|
+
throw getDuplicateError(path, i, edits.length, occurrences);
|
|
207
258
|
}
|
|
208
|
-
const replacementSpan = matchResult.usedFuzzyMatch
|
|
209
|
-
? mapFuzzySpanToOriginal(baseContent, matchResult.index, matchResult.matchLength)
|
|
210
|
-
: { index: matchResult.index, length: matchResult.matchLength };
|
|
211
259
|
matchedEdits.push({
|
|
212
260
|
editIndex: i,
|
|
213
|
-
matchIndex
|
|
214
|
-
matchLength
|
|
215
|
-
newText
|
|
261
|
+
matchIndex,
|
|
262
|
+
matchLength,
|
|
263
|
+
newText,
|
|
264
|
+
expectedText: normalizedContent.slice(matchIndex, matchIndex + matchLength),
|
|
216
265
|
});
|
|
217
266
|
}
|
|
218
267
|
matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
|
|
219
268
|
for (let i = 1; i < matchedEdits.length; i++) {
|
|
220
269
|
const previous = matchedEdits[i - 1];
|
|
221
270
|
const current = matchedEdits[i];
|
|
222
|
-
if (previous
|
|
271
|
+
if (rangesOverlap(previous, current)) {
|
|
223
272
|
throw new Error(`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`);
|
|
224
273
|
}
|
|
225
274
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
newContent.substring(edit.matchIndex + edit.matchLength);
|
|
275
|
+
return { baseLength: normalizedContent.length, editCount: edits.length, edits: matchedEdits };
|
|
276
|
+
}
|
|
277
|
+
/** Apply a validated match plan to the same LF-normalized source in one linear join. */
|
|
278
|
+
export function applyEditMatchPlan(normalizedContent, plan, path) {
|
|
279
|
+
if (normalizedContent.length !== plan.baseLength) {
|
|
280
|
+
throw new Error(`The validated edit plan for ${path} is stale because the source length changed.`);
|
|
233
281
|
}
|
|
234
|
-
|
|
235
|
-
|
|
282
|
+
const parts = [];
|
|
283
|
+
let sourceIndex = 0;
|
|
284
|
+
for (const edit of plan.edits) {
|
|
285
|
+
if (!normalizedContent.startsWith(edit.expectedText, edit.matchIndex)) {
|
|
286
|
+
throw new Error(`The validated edit plan for ${path} is stale at edits[${edit.editIndex}].`);
|
|
287
|
+
}
|
|
288
|
+
parts.push(normalizedContent.slice(sourceIndex, edit.matchIndex), edit.newText);
|
|
289
|
+
sourceIndex = edit.matchIndex + edit.matchLength;
|
|
236
290
|
}
|
|
237
|
-
|
|
291
|
+
parts.push(normalizedContent.slice(sourceIndex));
|
|
292
|
+
const newContent = parts.join("");
|
|
293
|
+
if (normalizedContent === newContent)
|
|
294
|
+
throw getNoChangeError(path, plan.editCount);
|
|
295
|
+
return { baseContent: normalizedContent, newContent };
|
|
296
|
+
}
|
|
297
|
+
export function applyEditsToNormalizedContent(normalizedContent, edits, path) {
|
|
298
|
+
return applyEditMatchPlan(normalizedContent, planEditsToNormalizedContent(normalizedContent, edits, path), path);
|
|
238
299
|
}
|
|
239
300
|
/** Generate a standard unified patch. */
|
|
240
301
|
export function generateUnifiedPatch(path, oldContent, newContent, contextLines = 4) {
|
|
@@ -363,7 +424,7 @@ export function generateDiffString(oldContent, newContent, contextLines = 4) {
|
|
|
363
424
|
* Compute the diff for one or more edit operations without applying them.
|
|
364
425
|
* Used for preview rendering in the TUI before the tool executes.
|
|
365
426
|
*/
|
|
366
|
-
export async function
|
|
427
|
+
export async function computeEditsPlannedDiff(path, edits, cwd) {
|
|
367
428
|
const absolutePath = resolveToCwd(path, cwd);
|
|
368
429
|
try {
|
|
369
430
|
// Check if file exists and is readable
|
|
@@ -379,14 +440,21 @@ export async function computeEditsDiff(path, edits, cwd) {
|
|
|
379
440
|
// Strip BOM before matching (LLM won't include invisible BOM in oldText)
|
|
380
441
|
const { text: content } = stripBom(rawContent);
|
|
381
442
|
const normalizedContent = normalizeToLF(content);
|
|
382
|
-
const
|
|
443
|
+
const plan = planEditsToNormalizedContent(normalizedContent, edits, path);
|
|
444
|
+
const { baseContent, newContent } = applyEditMatchPlan(normalizedContent, plan, path);
|
|
383
445
|
// Generate the diff
|
|
384
|
-
return generateDiffString(baseContent, newContent);
|
|
446
|
+
return { ...generateDiffString(baseContent, newContent), plan };
|
|
385
447
|
}
|
|
386
448
|
catch (err) {
|
|
387
449
|
return { error: err instanceof Error ? err.message : String(err) };
|
|
388
450
|
}
|
|
389
451
|
}
|
|
452
|
+
export async function computeEditsDiff(path, edits, cwd) {
|
|
453
|
+
const result = await computeEditsPlannedDiff(path, edits, cwd);
|
|
454
|
+
if ("error" in result)
|
|
455
|
+
return result;
|
|
456
|
+
return { diff: result.diff, firstChangedLine: result.firstChangedLine };
|
|
457
|
+
}
|
|
390
458
|
/**
|
|
391
459
|
* Compute the diff for a single edit operation without applying it.
|
|
392
460
|
* Kept as a convenience wrapper for single-edit callers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,M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CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAElG,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,IAAY,EACZ,OAAe,EACf,OAAe,EACf,GAAW;IAEX,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n */\n\nimport * as Diff from \"diff\";\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/** The original content replacements should be applied to. */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * Fuzzy matching searches normalized text, but returned spans still refer to\n * the original content so replacement does not normalize unrelated text.\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: content,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\nfunction countExactOccurrences(content: string, oldText: string): number {\n\treturn content.split(oldText).length - 1;\n}\n\nfunction countFuzzyOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getLineStarts(content: string): number[] {\n\tconst starts = [0];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tif (content[i] === \"\\n\") starts.push(i + 1);\n\t}\n\treturn starts;\n}\n\nfunction lineColumnAt(lineStarts: number[], index: number): { lineIndex: number; column: number } {\n\tlet low = 0;\n\tlet high = lineStarts.length - 1;\n\twhile (low <= high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\t\tif (lineStarts[mid] <= index) low = mid + 1;\n\t\telse high = mid - 1;\n\t}\n\tconst lineIndex = Math.max(0, high);\n\treturn { lineIndex, column: index - lineStarts[lineIndex] };\n}\n\nfunction lineTextAt(content: string, lineStarts: number[], lineIndex: number): string {\n\tconst start = lineStarts[lineIndex];\n\tconst nextStart = lineStarts[lineIndex + 1] ?? content.length;\n\tconst end = nextStart > start && content[nextStart - 1] === \"\\n\" ? nextStart - 1 : nextStart;\n\treturn content.slice(start, end);\n}\n\nfunction normalizedColumnToOriginalColumn(line: string, normalizedColumn: number): number {\n\tif (normalizedColumn <= 0) return 0;\n\tlet originalColumn = 0;\n\tfor (const char of line) {\n\t\tconst nextColumn = originalColumn + char.length;\n\t\tif (normalizeForFuzzyMatch(line.slice(0, nextColumn)).length >= normalizedColumn) return nextColumn;\n\t\toriginalColumn = nextColumn;\n\t}\n\treturn line.length;\n}\n\nfunction mapFuzzySpanToOriginal(\n\toriginalContent: string,\n\tnormalizedIndex: number,\n\tnormalizedLength: number,\n): { index: number; length: number } {\n\tconst fuzzyContent = normalizeForFuzzyMatch(originalContent);\n\tconst fuzzyLineStarts = getLineStarts(fuzzyContent);\n\tconst originalLineStarts = getLineStarts(originalContent);\n\tconst start = lineColumnAt(fuzzyLineStarts, normalizedIndex);\n\tconst end = lineColumnAt(fuzzyLineStarts, normalizedIndex + normalizedLength);\n\tconst startLine = lineTextAt(originalContent, originalLineStarts, start.lineIndex);\n\tconst endLine = lineTextAt(originalContent, originalLineStarts, end.lineIndex);\n\tconst originalStart =\n\t\toriginalLineStarts[start.lineIndex] + normalizedColumnToOriginalColumn(startLine, start.column);\n\tconst originalEnd = originalLineStarts[end.lineIndex] + normalizedColumnToOriginalColumn(endLine, end.column);\n\treturn { index: originalStart, length: originalEnd - originalStart };\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. Fuzzy matching uses\n * normalized text only for finding the span; the final splice is always made\n * into the original content.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst baseContent = normalizedContent;\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(baseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = matchResult.usedFuzzyMatch\n\t\t\t? countFuzzyOccurrences(baseContent, edit.oldText)\n\t\t\t: countExactOccurrences(baseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tconst replacementSpan = matchResult.usedFuzzyMatch\n\t\t\t? mapFuzzySpanToOriginal(baseContent, matchResult.index, matchResult.matchLength)\n\t\t\t: { index: matchResult.index, length: matchResult.matchLength };\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: replacementSpan.index,\n\t\t\tmatchLength: replacementSpan.length,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tlet newContent = baseContent;\n\tfor (let i = matchedEdits.length - 1; i >= 0; i--) {\n\t\tconst edit = matchedEdits[i];\n\t\tnewContent =\n\t\t\tnewContent.substring(0, edit.matchIndex) +\n\t\t\tedit.newText +\n\t\t\tnewContent.substring(edit.matchIndex + edit.matchLength);\n\t}\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], cwd);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,OAAO,KAAK,CAAC,CAAC;QAAE,OAA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,GAAG,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC;IACjE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,IAAY,EACZ,KAAa,EACb,GAAW;IAEX,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,IAAI,OAAO,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IACrC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,IAAY,EACZ,OAAe,EACf,OAAe,EACf,GAAW;IAEX,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n */\n\nimport * as Diff from \"diff\";\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn normalizeFuzzyCharacters(text).replace(/[^\\S\\n]+(?=\\n|$)/gu, \"\");\n}\n\nfunction normalizeFuzzyCharacters(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/** The original content replacements should be applied to. */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n\t/** Inclusive 1-based line bounds from the read that supplied oldText. */\n\trange?: EditRange;\n}\n\nexport interface EditRange {\n\tstartLine: number;\n\tendLine: number;\n}\n\ninterface PlannedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n\texpectedText: string;\n}\n\nexport interface EditMatchPlan {\n\t/** Length of the LF-normalized source against which this plan was validated. */\n\tbaseLength: number;\n\teditCount: number;\n\t/** Compact, source-ordered replacement spans; the source body is not retained. */\n\tedits: readonly PlannedEdit[];\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * Fuzzy matching searches normalized text, but returned spans still refer to\n * the original content so replacement does not normalize unrelated text.\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: content,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\nfunction countExactOccurrences(content: string, oldText: string): number {\n\tif (oldText.length === 0) return 0;\n\tlet count = 0;\n\tlet searchFrom = 0;\n\twhile (searchFrom <= content.length - oldText.length) {\n\t\tconst index = content.indexOf(oldText, searchFrom);\n\t\tif (index === -1) break;\n\t\tcount++;\n\t\tsearchFrom = index + 1;\n\t}\n\treturn count;\n}\n\nfunction getLineStarts(content: string): number[] {\n\tconst starts = [0];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tif (content[i] === \"\\n\") starts.push(i + 1);\n\t}\n\treturn starts;\n}\n\nfunction lineColumnAt(lineStarts: number[], index: number): { lineIndex: number; column: number } {\n\tlet low = 0;\n\tlet high = lineStarts.length - 1;\n\twhile (low <= high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\t\tif (lineStarts[mid] <= index) low = mid + 1;\n\t\telse high = mid - 1;\n\t}\n\tconst lineIndex = Math.max(0, high);\n\treturn { lineIndex, column: index - lineStarts[lineIndex] };\n}\n\nfunction lineTextAt(content: string, lineStarts: number[], lineIndex: number): string {\n\tconst start = lineStarts[lineIndex];\n\tconst nextStart = lineStarts[lineIndex + 1] ?? content.length;\n\tconst end = nextStart > start && content[nextStart - 1] === \"\\n\" ? nextStart - 1 : nextStart;\n\treturn content.slice(start, end);\n}\n\nfunction normalizedColumnToOriginalColumn(line: string, normalizedColumn: number): number {\n\tif (normalizedColumn <= 0) return 0;\n\tconst boundaries = [0];\n\tfor (let index = 0; index < line.length; ) {\n\t\tconst codePoint = line.codePointAt(index);\n\t\tindex += codePoint !== undefined && codePoint > 0xffff ? 2 : 1;\n\t\tboundaries.push(index);\n\t}\n\n\tlet low = 1;\n\tlet high = boundaries.length - 1;\n\twhile (low < high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\t\tif (normalizeForFuzzyMatch(line.slice(0, boundaries[mid])).length >= normalizedColumn) high = mid;\n\t\telse low = mid + 1;\n\t}\n\treturn boundaries[low] ?? line.length;\n}\n\nfunction mapFuzzySpanToOriginal(\n\toriginalContent: string,\n\toriginalLineStarts: number[],\n\tfuzzyLineStarts: number[],\n\tnormalizedIndex: number,\n\tnormalizedLength: number,\n): { index: number; length: number } {\n\tconst start = lineColumnAt(fuzzyLineStarts, normalizedIndex);\n\tconst end = lineColumnAt(fuzzyLineStarts, normalizedIndex + normalizedLength);\n\tconst startLine = lineTextAt(originalContent, originalLineStarts, start.lineIndex);\n\tconst endLine = lineTextAt(originalContent, originalLineStarts, end.lineIndex);\n\tconst originalStart =\n\t\toriginalLineStarts[start.lineIndex] + normalizedColumnToOriginalColumn(startLine, start.column);\n\tconst originalEnd = originalLineStarts[end.lineIndex] + normalizedColumnToOriginalColumn(endLine, end.column);\n\treturn { index: originalStart, length: originalEnd - originalStart };\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number, range?: EditRange): Error {\n\tconst rangeSuffix = range ? ` within lines ${range.startLine}-${range.endLine}` : \"\";\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}${rangeSuffix}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}${rangeSuffix}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\ninterface MatchWindow {\n\tstart: number;\n\tend: number;\n}\n\nfunction validateRange(\n\trange: EditRange | undefined,\n\tlineStarts: number[] | undefined,\n\tcontentLength: number,\n\tpath: string,\n\teditIndex: number,\n\ttotalEdits: number,\n): MatchWindow {\n\tif (!range) return { start: 0, end: contentLength };\n\tconst label = totalEdits === 1 ? \"range\" : `edits[${editIndex}].range`;\n\tif (\n\t\t!Number.isSafeInteger(range.startLine) ||\n\t\t!Number.isSafeInteger(range.endLine) ||\n\t\trange.startLine < 1 ||\n\t\trange.endLine < range.startLine\n\t) {\n\t\tthrow new Error(`${label} in ${path} must contain inclusive positive line numbers with startLine <= endLine.`);\n\t}\n\tif (!lineStarts || range.endLine > lineStarts.length) {\n\t\tthrow new Error(`${label} in ${path} exceeds the file's ${lineStarts?.length ?? 0} lines.`);\n\t}\n\treturn {\n\t\tstart: lineStarts[range.startLine - 1],\n\t\tend: lineStarts[range.endLine] ?? contentLength,\n\t};\n}\n\nfunction findWithin(content: string, oldText: string, window: MatchWindow): number {\n\tif (oldText.length === 0 || oldText.length > window.end - window.start) return -1;\n\tconst index = content.indexOf(oldText, window.start);\n\treturn index !== -1 && index + oldText.length <= window.end ? index : -1;\n}\n\nfunction rangesOverlap(previous: PlannedEdit, current: PlannedEdit): boolean {\n\treturn previous.matchIndex + previous.matchLength > current.matchIndex;\n}\n\n/**\n * Match and validate one or more replacements against LF-normalized content.\n *\n * The returned plan retains only the validated spans and their replacement\n * text. Exact matching uses native substring search, bounded by optional line\n * ranges, while uniqueness is still proven across the whole source.\n */\nexport function planEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): EditMatchPlan {\n\tlet originalLineStarts: number[] | undefined;\n\tlet fuzzyContent: string | undefined;\n\tlet fuzzyLineStarts: number[] | undefined;\n\tconst needsLineStarts = edits.some((edit) => edit.range !== undefined);\n\tif (needsLineStarts) originalLineStarts = getLineStarts(normalizedContent);\n\n\tconst matchedEdits: PlannedEdit[] = [];\n\tfor (let i = 0; i < edits.length; i++) {\n\t\tconst sourceEdit = edits[i];\n\t\tconst oldText = normalizeToLF(sourceEdit.oldText);\n\t\tconst newText = normalizeToLF(sourceEdit.newText);\n\t\tif (oldText.length === 0) throw getEmptyOldTextError(path, i, edits.length);\n\n\t\tconst exactWindow = validateRange(\n\t\t\tsourceEdit.range,\n\t\t\toriginalLineStarts,\n\t\t\tnormalizedContent.length,\n\t\t\tpath,\n\t\t\ti,\n\t\t\tedits.length,\n\t\t);\n\t\tlet matchIndex = findWithin(normalizedContent, oldText, exactWindow);\n\t\tlet matchLength = oldText.length;\n\t\tlet occurrences: number;\n\n\t\tif (matchIndex !== -1) {\n\t\t\toccurrences = countExactOccurrences(normalizedContent, oldText);\n\t\t} else {\n\t\t\tfuzzyContent ??= normalizeForFuzzyMatch(normalizedContent);\n\t\t\tfuzzyLineStarts ??= getLineStarts(fuzzyContent);\n\t\t\toriginalLineStarts ??= getLineStarts(normalizedContent);\n\t\t\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\t\t\tconst fuzzyWindow = validateRange(\n\t\t\t\tsourceEdit.range,\n\t\t\t\tfuzzyLineStarts,\n\t\t\t\tfuzzyContent.length,\n\t\t\t\tpath,\n\t\t\t\ti,\n\t\t\t\tedits.length,\n\t\t\t);\n\t\t\tconst fuzzyIndex = findWithin(fuzzyContent, fuzzyOldText, fuzzyWindow);\n\t\t\tif (fuzzyIndex === -1) throw getNotFoundError(path, i, edits.length, sourceEdit.range);\n\t\t\toccurrences = countExactOccurrences(fuzzyContent, fuzzyOldText);\n\t\t\tconst replacementSpan = mapFuzzySpanToOriginal(\n\t\t\t\tnormalizedContent,\n\t\t\t\toriginalLineStarts,\n\t\t\t\tfuzzyLineStarts,\n\t\t\t\tfuzzyIndex,\n\t\t\t\tfuzzyOldText.length,\n\t\t\t);\n\t\t\tmatchIndex = replacementSpan.index;\n\t\t\tmatchLength = replacementSpan.length;\n\t\t}\n\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, edits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex,\n\t\t\tmatchLength,\n\t\t\tnewText,\n\t\t\texpectedText: normalizedContent.slice(matchIndex, matchIndex + matchLength),\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (rangesOverlap(previous, current)) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn { baseLength: normalizedContent.length, editCount: edits.length, edits: matchedEdits };\n}\n\n/** Apply a validated match plan to the same LF-normalized source in one linear join. */\nexport function applyEditMatchPlan(normalizedContent: string, plan: EditMatchPlan, path: string): AppliedEditsResult {\n\tif (normalizedContent.length !== plan.baseLength) {\n\t\tthrow new Error(`The validated edit plan for ${path} is stale because the source length changed.`);\n\t}\n\n\tconst parts: string[] = [];\n\tlet sourceIndex = 0;\n\tfor (const edit of plan.edits) {\n\t\tif (!normalizedContent.startsWith(edit.expectedText, edit.matchIndex)) {\n\t\t\tthrow new Error(`The validated edit plan for ${path} is stale at edits[${edit.editIndex}].`);\n\t\t}\n\t\tparts.push(normalizedContent.slice(sourceIndex, edit.matchIndex), edit.newText);\n\t\tsourceIndex = edit.matchIndex + edit.matchLength;\n\t}\n\tparts.push(normalizedContent.slice(sourceIndex));\n\tconst newContent = parts.join(\"\");\n\n\tif (normalizedContent === newContent) throw getNoChangeError(path, plan.editCount);\n\treturn { baseContent: normalizedContent, newContent };\n}\n\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\treturn applyEditMatchPlan(normalizedContent, planEditsToNormalizedContent(normalizedContent, edits, path), path);\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\nexport interface EditPlannedDiffResult extends EditDiffResult {\n\tplan: EditMatchPlan;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsPlannedDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditPlannedDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst plan = planEditsToNormalizedContent(normalizedContent, edits, path);\n\t\tconst { baseContent, newContent } = applyEditMatchPlan(normalizedContent, plan, path);\n\n\t\t// Generate the diff\n\t\treturn { ...generateDiffString(baseContent, newContent), plan };\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst result = await computeEditsPlannedDiff(path, edits, cwd);\n\tif (\"error\" in result) return result;\n\treturn { diff: result.diff, firstChangedLine: result.firstChangedLine };\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], cwd);\n}\n"]}
|
|
@@ -3,25 +3,40 @@ import { Box } from "@caupulican/pi-tui";
|
|
|
3
3
|
import { type Static, Type } from "typebox";
|
|
4
4
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
5
5
|
import { type EditDiffError, type EditDiffResult } from "./edit-diff.ts";
|
|
6
|
+
import { FileMutationIntentController } from "./file-mutation-intent.ts";
|
|
6
7
|
type EditPreview = EditDiffResult | EditDiffError;
|
|
7
8
|
type EditRenderState = {
|
|
8
9
|
callComponent?: EditCallRenderComponent;
|
|
9
10
|
};
|
|
10
|
-
declare const editSchema: Type.TObject<{
|
|
11
|
+
declare const editSchema: Type.TUnion<[Type.TObject<{
|
|
12
|
+
action: Type.TLiteral<"prepare">;
|
|
11
13
|
path: Type.TString;
|
|
14
|
+
}>, Type.TObject<{
|
|
15
|
+
action: Type.TLiteral<"commit">;
|
|
16
|
+
path: Type.TString;
|
|
17
|
+
intentId: Type.TString;
|
|
12
18
|
edits: Type.TArray<Type.TObject<{
|
|
13
19
|
oldText: Type.TString;
|
|
14
20
|
newText: Type.TString;
|
|
21
|
+
range: Type.TOptional<Type.TObject<{
|
|
22
|
+
startLine: Type.TInteger;
|
|
23
|
+
endLine: Type.TInteger;
|
|
24
|
+
}>>;
|
|
15
25
|
}>>;
|
|
16
|
-
}>;
|
|
26
|
+
}>]>;
|
|
17
27
|
export type EditToolInput = Static<typeof editSchema>;
|
|
18
28
|
export interface EditToolDetails {
|
|
29
|
+
phase: "prepared" | "committed";
|
|
30
|
+
intentId?: string;
|
|
31
|
+
contentRef?: string;
|
|
19
32
|
/** Display-oriented diff of the changes made */
|
|
20
|
-
diff
|
|
33
|
+
diff?: string;
|
|
21
34
|
/** Standard unified patch of the changes made */
|
|
22
|
-
patch
|
|
35
|
+
patch?: string;
|
|
23
36
|
/** Line number of the first change in the new file (for editor navigation) */
|
|
24
37
|
firstChangedLine?: number;
|
|
38
|
+
/** True when execution reused the match plan already validated for the call preview. */
|
|
39
|
+
matchPlanReused?: boolean;
|
|
25
40
|
}
|
|
26
41
|
/**
|
|
27
42
|
* Pluggable operations for the edit tool.
|
|
@@ -32,16 +47,16 @@ export interface EditOperations {
|
|
|
32
47
|
readFile: (absolutePath: string) => Promise<Buffer>;
|
|
33
48
|
/** Write content to a file */
|
|
34
49
|
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
35
|
-
/** Check if file is readable and writable (throw if not) */
|
|
36
|
-
access: (absolutePath: string) => Promise<void>;
|
|
37
50
|
}
|
|
38
51
|
export interface EditToolOptions {
|
|
39
52
|
/** Custom operations for file editing. Default: local filesystem */
|
|
40
53
|
operations?: EditOperations;
|
|
54
|
+
/** Session-owned two-phase intent and exact-content-reference authority. */
|
|
55
|
+
intentController?: FileMutationIntentController;
|
|
41
56
|
}
|
|
42
57
|
type EditCallRenderComponent = Box & {
|
|
43
58
|
preview?: EditPreview;
|
|
44
|
-
|
|
59
|
+
previewRequestId: number;
|
|
45
60
|
previewPending?: boolean;
|
|
46
61
|
settledError?: boolean;
|
|
47
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAA2B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAA2B,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAMN,KAAK,aAAa,EAClB,KAAK,cAAc,EAOnB,MAAM,gBAAgB,CAAC;AAExB,OAAO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