pi-hashline-edit-pro 0.9.0 → 0.9.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/package.json +1 -1
- package/src/hashline/apply.ts +7 -1
- package/src/replace-diff.ts +16 -8
- package/src/replace-response.ts +2 -10
package/package.json
CHANGED
package/src/hashline/apply.ts
CHANGED
|
@@ -287,7 +287,7 @@ export function applyHashlineEdits(
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
|
|
290
|
-
const ANCHOR_CONTEXT_LINES =
|
|
290
|
+
const ANCHOR_CONTEXT_LINES = 0;
|
|
291
291
|
const ANCHOR_MAX_OUTPUT_LINES = 12;
|
|
292
292
|
|
|
293
293
|
export function computeAffectedLineRange(params: {
|
|
@@ -309,6 +309,12 @@ export function computeAffectedLineRange(params: {
|
|
|
309
309
|
return null;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
// When contextLines is 0, skip the anchor block entirely.
|
|
313
|
+
// The LLM already knows what it changed and can call read for fresh anchors.
|
|
314
|
+
if (contextLines === 0) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
312
318
|
if (resultLineCount === 0) {
|
|
313
319
|
return null;
|
|
314
320
|
}
|
package/src/replace-diff.ts
CHANGED
|
@@ -44,7 +44,7 @@ function formatDiffPreviewLine(
|
|
|
44
44
|
export function generateDiffString(
|
|
45
45
|
oldContent: string,
|
|
46
46
|
newContent: string,
|
|
47
|
-
contextLines =
|
|
47
|
+
contextLines = 2,
|
|
48
48
|
newContentHashes?: string[],
|
|
49
49
|
): { diff: string; firstChangedLine: number | undefined } {
|
|
50
50
|
const parts = Diff.diffLines(oldContent, newContent);
|
|
@@ -85,12 +85,19 @@ export function generateDiffString(
|
|
|
85
85
|
let linesToShow = raw;
|
|
86
86
|
let skipStart = 0;
|
|
87
87
|
let skipEnd = 0;
|
|
88
|
+
let skipMiddle = 0; // lines skipped between head and tail context
|
|
88
89
|
|
|
89
90
|
if (!lastWasChange) {
|
|
91
|
+
// Before a change: show last contextLines only.
|
|
90
92
|
skipStart = Math.max(0, raw.length - contextLines);
|
|
91
93
|
linesToShow = raw.slice(skipStart);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
+
} else if (nextPartIsChange && raw.length > contextLines * 2) {
|
|
95
|
+
// Between two changes: show first contextLines + last contextLines with ellipsis in between.
|
|
96
|
+
const tail = raw.slice(-contextLines);
|
|
97
|
+
linesToShow = [...raw.slice(0, contextLines), "__ELLIPSIS__", ...tail];
|
|
98
|
+
skipMiddle = raw.length - contextLines * 2;
|
|
99
|
+
} else if (linesToShow.length > contextLines) {
|
|
100
|
+
// After a change with no next change nearby: show first contextLines only.
|
|
94
101
|
skipEnd = linesToShow.length - contextLines;
|
|
95
102
|
linesToShow = linesToShow.slice(0, contextLines);
|
|
96
103
|
}
|
|
@@ -101,17 +108,18 @@ export function generateDiffString(
|
|
|
101
108
|
newLineNum += skipStart;
|
|
102
109
|
}
|
|
103
110
|
for (const line of linesToShow) {
|
|
111
|
+
if (line === "__ELLIPSIS__") {
|
|
112
|
+
output.push(` ...`);
|
|
113
|
+
oldLineNum += skipMiddle;
|
|
114
|
+
newLineNum += skipMiddle;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
104
117
|
const hash = effectiveNewHashes[newLineNum - 1];
|
|
105
118
|
output.push(formatDiffPreviewLine(" ", line, hash));
|
|
106
119
|
|
|
107
120
|
oldLineNum++;
|
|
108
121
|
newLineNum++;
|
|
109
122
|
}
|
|
110
|
-
if (skipEnd > 0) {
|
|
111
|
-
output.push(` ...`);
|
|
112
|
-
oldLineNum += skipEnd;
|
|
113
|
-
newLineNum += skipEnd;
|
|
114
|
-
}
|
|
115
123
|
} else {
|
|
116
124
|
oldLineNum += raw.length;
|
|
117
125
|
newLineNum += raw.length;
|
package/src/replace-response.ts
CHANGED
|
@@ -190,18 +190,10 @@ export function buildChangedResponse(input: SuccessResponseInput): ToolResult {
|
|
|
190
190
|
CHANGED_ANCHOR_TEXT_BUDGET_BYTES
|
|
191
191
|
? block
|
|
192
192
|
: "Anchors omitted; use read for subsequent edits.";
|
|
193
|
-
|
|
193
|
+
})()
|
|
194
194
|
: resultLines.length === 0
|
|
195
195
|
? "File is empty. Use edit to insert content."
|
|
196
|
-
:
|
|
197
|
-
const diffLines = diffResult.diff.split("\n");
|
|
198
|
-
const MAX_DIFF_LINES = 30;
|
|
199
|
-
if (diffLines.length <= MAX_DIFF_LINES) {
|
|
200
|
-
return `Diff preview:\n${diffResult.diff}`;
|
|
201
|
-
}
|
|
202
|
-
const truncated = diffLines.slice(0, MAX_DIFF_LINES).join("\n");
|
|
203
|
-
return `Diff preview (${diffLines.length} lines, showing first ${MAX_DIFF_LINES}):\n${truncated}\n...`;
|
|
204
|
-
})();
|
|
196
|
+
: ""; // No anchor context → show nothing; LLM can call read for fresh anchors
|
|
205
197
|
const text = [anchorsBlock, warningsBlock.trimStart()]
|
|
206
198
|
.filter((section) => section.length > 0)
|
|
207
199
|
.join("\n\n");
|