@d3ara1n/pi-hashline-edit 0.5.1 → 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3ara1n/pi-hashline-edit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hashline-style file editing for pi — line-anchored edits verified by content hash, replacing oldText/newText matching",
|
|
6
6
|
"homepage": "https://github.com/d3ara1n/pi-extensions/tree/main/packages/pi-hashline-edit#readme",
|
|
@@ -12,7 +12,7 @@ import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
|
|
|
12
12
|
async function findPathRg(): Promise<string | null> {
|
|
13
13
|
for (const directory of process.env.PATH?.split(delimiter) ?? []) {
|
|
14
14
|
if (!directory) continue;
|
|
15
|
-
const candidate = join(directory, "rg");
|
|
15
|
+
const candidate = join(directory, process.platform === "win32" ? "rg.exe" : "rg");
|
|
16
16
|
try {
|
|
17
17
|
await access(candidate, constants.X_OK);
|
|
18
18
|
return candidate;
|
|
@@ -31,15 +31,16 @@ test("real rg emits anchored matches from a temporary directory", {
|
|
|
31
31
|
const file = join(directory, "fixture.ts");
|
|
32
32
|
await writeFile(file, "needle\nother\n");
|
|
33
33
|
const tool = makeGrepOverrideWithBackend(directory, {
|
|
34
|
-
findRg: async () => rgPath,
|
|
35
34
|
delegate: async () => {
|
|
36
35
|
throw new Error("integration test must not invoke the built-in grep delegate");
|
|
37
36
|
},
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
for (const pattern of ["needle", ["needle"]]) {
|
|
40
|
+
const result: any = await tool.execute("0", { pattern }, undefined, undefined);
|
|
41
|
+
assert.match(result.content[0].text, /fixture\.ts · 1 match/);
|
|
42
|
+
assert.match(result.content[0].text, /1#[0-9A-Z]+│needle/);
|
|
43
|
+
}
|
|
43
44
|
} finally {
|
|
44
45
|
await rm(directory, { recursive: true, force: true });
|
|
45
46
|
}
|
package/src/pi/grep-tool.ts
CHANGED
|
@@ -55,15 +55,16 @@ const GREP_MAX_LINE_LENGTH = 500;
|
|
|
55
55
|
|
|
56
56
|
/** Locate ripgrep: pi's bundled bin first, then PATH. Returns null if not found. */
|
|
57
57
|
async function findRg(): Promise<string | null> {
|
|
58
|
+
const executable = process.platform === "win32" ? "rg.exe" : "rg";
|
|
58
59
|
const agentDir = getAgentDir();
|
|
59
|
-
const piRg = join(agentDir, "bin",
|
|
60
|
+
const piRg = join(agentDir, "bin", executable);
|
|
60
61
|
try {
|
|
61
62
|
await access(piRg, constants.X_OK);
|
|
62
63
|
return piRg;
|
|
63
64
|
} catch {}
|
|
64
65
|
for (const dir of process.env.PATH?.split(delimiter) ?? []) {
|
|
65
66
|
if (!dir) continue;
|
|
66
|
-
const p = join(dir,
|
|
67
|
+
const p = join(dir, executable);
|
|
67
68
|
try {
|
|
68
69
|
await access(p, constants.X_OK);
|
|
69
70
|
return p;
|
package/src/pi/pi.test.ts
CHANGED
|
@@ -2,15 +2,18 @@ import { test } from "node:test";
|
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { canonicalPath } from "./read-tool.ts";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
5
6
|
|
|
6
7
|
test("canonicalPath resolves relative and absolute", () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
assert.equal(canonicalPath(
|
|
8
|
+
const cwd = resolve("/cwd");
|
|
9
|
+
const absolute = resolve("/abs/x.ts");
|
|
10
|
+
assert.equal(canonicalPath(cwd, "foo.ts"), join(cwd, "foo.ts"));
|
|
11
|
+
assert.equal(canonicalPath(cwd, "./foo.ts"), join(cwd, "foo.ts"));
|
|
12
|
+
assert.equal(canonicalPath(cwd, absolute), absolute);
|
|
10
13
|
});
|
|
11
14
|
|
|
12
15
|
test("canonicalPath expands ~ to home directory", () => {
|
|
13
16
|
const home = homedir();
|
|
14
17
|
assert.equal(canonicalPath("/cwd", "~"), home);
|
|
15
|
-
assert.equal(canonicalPath("/cwd", "~/foo.ts"),
|
|
18
|
+
assert.equal(canonicalPath("/cwd", "~/foo.ts"), join(home, "foo.ts"));
|
|
16
19
|
});
|