pi-hashline-edit-pro 0.9.6 → 0.9.8
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/index.ts +2 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -1
- package/src/file-kind.ts +7 -1
- package/src/hashline/index.ts +1 -0
- package/src/replace-response.ts +3 -4
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
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/index.ts
CHANGED
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,
|