pi-hashline-edit-pro 0.9.5 → 0.9.7
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/LICENSE +1 -1
- package/index.ts +2 -1
- package/package.json +1 -1
- package/prompts/replace-guidelines.md +2 -2
- package/src/constants.ts +2 -1
- package/src/file-kind.ts +7 -1
- package/src/hashline/resolve.ts +2 -2
- package/src/replace-response.ts +3 -4
- package/src/replace.ts +2 -2
package/LICENSE
CHANGED
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import { join, isAbsolute } from "path";
|
|
4
|
-
import { computeLineHashes, formatHashlineRegion } from "./src/hashline";
|
|
4
|
+
import { computeLineHashes, ensureHasherReady, formatHashlineRegion } from "./src/hashline";
|
|
5
5
|
import { registerReplaceTool } from "./src/replace";
|
|
6
6
|
import { registerReadTool } from "./src/read";
|
|
7
7
|
import { normalizeToLF } from "./src/replace-diff";
|
|
@@ -15,6 +15,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
15
15
|
pi.on("session_start", async (_event, ctx) => {
|
|
16
16
|
const active = pi.getActiveTools();
|
|
17
17
|
pi.setActiveTools(active.filter((t) => t !== "edit"));
|
|
18
|
+
await ensureHasherReady();
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
const autoReadValue = process.env.PI_HASHLINE_AUTO_READ;
|
package/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
- Use `replace` with HASH anchors for all file changes; batch every change to one file into a single `replace` call.
|
|
2
|
-
- After a successful `replace`, the
|
|
3
|
-
- On `[E_STALE_ANCHOR]`,
|
|
2
|
+
- After a successful `replace`, the response text is empty (warnings only). Call `read` to get fresh anchors for follow-up edits.
|
|
3
|
+
- On `[E_STALE_ANCHOR]`, call `read` to get fresh anchors, copy the 3-character HASH from each line into `old_range`, and retry.
|
package/src/constants.ts
CHANGED
|
@@ -2,4 +2,5 @@ export const AUTO_READ_MAX_LINES = 2000;
|
|
|
2
2
|
export const CHANGED_ANCHOR_TEXT_BUDGET_BYTES = 50 * 1024;
|
|
3
3
|
export const ANCHOR_CONTEXT_LINES = 0;
|
|
4
4
|
export const ANCHOR_MAX_OUTPUT_LINES = 12;
|
|
5
|
-
export const FILE_TYPE_SNIFF_BYTES = 8192;
|
|
5
|
+
export const FILE_TYPE_SNIFF_BYTES = 8192;
|
|
6
|
+
export const MAX_FILE_BYTES = 100 * 1024 * 1024;
|
package/src/file-kind.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { open as fsOpen, stat as fsStat } from "fs/promises";
|
|
2
2
|
import { fileTypeFromBuffer } from "file-type";
|
|
3
|
-
import { FILE_TYPE_SNIFF_BYTES } from "./constants";
|
|
3
|
+
import { FILE_TYPE_SNIFF_BYTES, MAX_FILE_BYTES } from "./constants";
|
|
4
4
|
|
|
5
5
|
const IMAGE_MIME_TYPES = new Set<string>([
|
|
6
6
|
"image/jpeg",
|
|
@@ -48,6 +48,12 @@ export async function loadFileKindAndText(
|
|
|
48
48
|
description: "unsupported file type",
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
if (pathStat.size > MAX_FILE_BYTES) {
|
|
52
|
+
return {
|
|
53
|
+
kind: "binary",
|
|
54
|
+
description: `file exceeds ${MAX_FILE_BYTES} byte limit`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
51
57
|
|
|
52
58
|
const fileHandle = await fsOpen(filePath, "r");
|
|
53
59
|
try {
|
package/src/hashline/resolve.ts
CHANGED
|
@@ -134,7 +134,7 @@ function assertEditItem(edit: Record<string, unknown>, index: number): void {
|
|
|
134
134
|
const unknownKeys = Object.keys(edit).filter((key) => !ITEM_KEYS.has(key));
|
|
135
135
|
if (unknownKeys.length > 0) {
|
|
136
136
|
throw new Error(
|
|
137
|
-
`[E_BAD_SHAPE] Edit ${index} contains unknown or unsupported fields: ${unknownKeys.join(", ")}.`,
|
|
137
|
+
`[E_BAD_SHAPE] Edit ${index} contains unknown or unsupported fields: ${unknownKeys.join(", ")}. Each edit takes only { old_range, new_lines }.`,
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -144,7 +144,7 @@ function assertEditItem(edit: Record<string, unknown>, index: number): void {
|
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
if (!("new_lines" in edit)) {
|
|
147
|
-
throw new Error(`[E_BAD_SHAPE] Edit ${index} requires a "new_lines" field.`);
|
|
147
|
+
throw new Error(`[E_BAD_SHAPE] Edit ${index} requires a "new_lines" field. Provide the replacement lines (use [] to delete).`);
|
|
148
148
|
}
|
|
149
149
|
if ("new_lines" in edit && !isStringArray(edit.new_lines)) {
|
|
150
150
|
throw new Error(`[E_BAD_SHAPE] Edit ${index} field "new_lines" must be a string array.`);
|
package/src/replace-response.ts
CHANGED
|
@@ -156,13 +156,12 @@ export function buildNoopResponse(input: NoopResponseInput): ToolResult {
|
|
|
156
156
|
export function buildChangedResponse(input: SuccessResponseInput): ToolResult {
|
|
157
157
|
const { result, warnings, snapshotId, originalNormalized, editMeta } = input;
|
|
158
158
|
|
|
159
|
-
const
|
|
159
|
+
const resultLines = getVisibleLines(result);
|
|
160
|
+
const resultHashes = input.resultHashes ?? computeLineHashes(result);
|
|
161
|
+
const diffResult = generateDiffString(originalNormalized, result, 2, resultHashes);
|
|
160
162
|
const addedLines = countDiffLines(diffResult.diff, "+");
|
|
161
163
|
const removedLines = countDiffLines(diffResult.diff, "-");
|
|
162
164
|
const warningsBlock = warningsBlockOf(warnings);
|
|
163
|
-
|
|
164
|
-
const resultLines = getVisibleLines(result);
|
|
165
|
-
const resultHashes = input.resultHashes ?? computeLineHashes(result);
|
|
166
165
|
const anchorRange = computeAffectedLineRange({
|
|
167
166
|
firstChangedLine: editMeta.firstChangedLine,
|
|
168
167
|
lastChangedLine: editMeta.lastChangedLine,
|
package/src/replace.ts
CHANGED
|
@@ -118,7 +118,7 @@ export function assertReplaceRequest(
|
|
|
118
118
|
);
|
|
119
119
|
if (unknownRootKeys.length > 0) {
|
|
120
120
|
throw new Error(
|
|
121
|
-
`[E_BAD_SHAPE] Edit request contains unknown or unsupported fields: ${unknownRootKeys.join(", ")}.`,
|
|
121
|
+
`[E_BAD_SHAPE] Edit request contains unknown or unsupported fields: ${unknownRootKeys.join(", ")}. Use only { path, edits }; each edit is { old_range: ["<START>", "<END>"], new_lines: [...] }.`,
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -127,7 +127,7 @@ export function assertReplaceRequest(
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (hasOwn(request, "edits") && !Array.isArray(request.edits)) {
|
|
130
|
-
throw new Error('[E_BAD_SHAPE] Edit request requires an "edits" array when provided.');
|
|
130
|
+
throw new Error('[E_BAD_SHAPE] Edit request requires an "edits" array when provided. Each edit is { old_range: ["<START>", "<END>"], new_lines: [...] }.');
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
}
|