@xynogen/pix-edit 0.1.7 → 0.1.10
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 +2 -2
- package/src/edit.test.ts +25 -7
- package/src/edit.ts +5 -3
- package/src/once.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-edit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Pi tool — precise text replacement edit with diff rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@xynogen/pix-pretty": "
|
|
37
|
+
"@xynogen/pix-pretty": "^1.7.9"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/edit.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import type { CursorStore, FffState } from "@xynogen/pix-pretty/fff";
|
|
3
|
+
import type { PiPrettyApi, TextComponentCtor } from "@xynogen/pix-pretty/types";
|
|
2
4
|
import {
|
|
3
5
|
getEditOperations,
|
|
4
6
|
registerEditTool,
|
|
@@ -18,15 +20,31 @@ class MockTextComponent {
|
|
|
18
20
|
describe("registerEditTool", () => {
|
|
19
21
|
it("registers a tool named 'edit'", () => {
|
|
20
22
|
const tools: string[] = [];
|
|
23
|
+
const mockPi: PiPrettyApi = {
|
|
24
|
+
registerTool(t: unknown) {
|
|
25
|
+
tools.push((t as { name: string }).name);
|
|
26
|
+
},
|
|
27
|
+
registerCommand() {},
|
|
28
|
+
on() {},
|
|
29
|
+
};
|
|
30
|
+
|
|
21
31
|
registerEditTool(
|
|
22
|
-
|
|
23
|
-
() => ({ execute: async () => ({ content: [] }) })
|
|
32
|
+
mockPi,
|
|
33
|
+
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
24
34
|
{
|
|
25
35
|
cwd: process.cwd(),
|
|
26
36
|
sp: (p: string) => p,
|
|
27
|
-
TextComponent: MockTextComponent as
|
|
28
|
-
fffState: {
|
|
29
|
-
|
|
37
|
+
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
38
|
+
fffState: {
|
|
39
|
+
module: null,
|
|
40
|
+
finder: null,
|
|
41
|
+
partialIndex: false,
|
|
42
|
+
dbDir: null,
|
|
43
|
+
} satisfies FffState,
|
|
44
|
+
cursorStore: {
|
|
45
|
+
store: () => "",
|
|
46
|
+
get: () => undefined,
|
|
47
|
+
} as unknown as CursorStore,
|
|
30
48
|
},
|
|
31
49
|
(_id: string, _inv: () => void) => {},
|
|
32
50
|
);
|
|
@@ -39,7 +57,7 @@ describe("getEditOperations", () => {
|
|
|
39
57
|
const ops = getEditOperations({
|
|
40
58
|
path: "f.ts",
|
|
41
59
|
edits: [{ oldText: "a", newText: "b" }],
|
|
42
|
-
}
|
|
60
|
+
});
|
|
43
61
|
expect(ops).toEqual([{ oldText: "a", newText: "b" }]);
|
|
44
62
|
});
|
|
45
63
|
|
|
@@ -47,7 +65,7 @@ describe("getEditOperations", () => {
|
|
|
47
65
|
const ops = getEditOperations({
|
|
48
66
|
path: "f.ts",
|
|
49
67
|
edits: [{ oldText: "x", newText: "x" }],
|
|
50
|
-
}
|
|
68
|
+
});
|
|
51
69
|
expect(ops).toHaveLength(0);
|
|
52
70
|
});
|
|
53
71
|
});
|
package/src/edit.ts
CHANGED
|
@@ -136,12 +136,14 @@ export function registerEditTool(
|
|
|
136
136
|
const { diffs, summary } = summarizeEditOperations(operations);
|
|
137
137
|
|
|
138
138
|
if (operations.length === 1) {
|
|
139
|
+
const op0 = operations[0];
|
|
140
|
+
if (!op0) return result;
|
|
139
141
|
setResultDetails(result, {
|
|
140
142
|
_type: "editInfo",
|
|
141
143
|
summary,
|
|
142
|
-
editLine: opEditLine(fp,
|
|
143
|
-
oldContent:
|
|
144
|
-
newContent:
|
|
144
|
+
editLine: opEditLine(fp, op0.newText),
|
|
145
|
+
oldContent: op0.oldText,
|
|
146
|
+
newContent: op0.newText,
|
|
145
147
|
language: fileLang,
|
|
146
148
|
filePath: fp,
|
|
147
149
|
});
|
package/src/once.ts
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export function once(pi: object, key: string, fn: () => void): void {
|
|
16
16
|
const g = globalThis as { __pixOnce?: WeakMap<object, Set<string>> };
|
|
17
|
-
|
|
17
|
+
if (!g.__pixOnce) g.__pixOnce = new WeakMap<object, Set<string>>();
|
|
18
|
+
const registry = g.__pixOnce;
|
|
18
19
|
let loaded = registry.get(pi);
|
|
19
20
|
if (!loaded) {
|
|
20
21
|
loaded = new Set<string>();
|