@xynogen/pix-edit 0.1.15 → 0.1.17
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 +3 -3
- package/src/edit.test.ts +6 -4
- package/src/edit.ts +19 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-edit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Pi tool — precise text replacement edit with diff rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@xynogen/pix-pretty": "^1.7.
|
|
38
|
-
"@xynogen/pix-data": "^0.3.
|
|
37
|
+
"@xynogen/pix-pretty": "^1.7.22",
|
|
38
|
+
"@xynogen/pix-data": "^0.3.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/edit.test.ts
CHANGED
|
@@ -19,11 +19,11 @@ class MockTextComponent {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
describe("registerEditTool", () => {
|
|
22
|
-
it("registers a
|
|
23
|
-
const tools: string
|
|
22
|
+
it("registers a self-rendered edit tool", () => {
|
|
23
|
+
const tools: Array<{ name: string; renderShell?: string }> = [];
|
|
24
24
|
const mockPi: PiPrettyApi = {
|
|
25
25
|
registerTool(t: unknown) {
|
|
26
|
-
tools.push(
|
|
26
|
+
tools.push(t as { name: string; renderShell?: string });
|
|
27
27
|
},
|
|
28
28
|
registerCommand() {},
|
|
29
29
|
on() {},
|
|
@@ -49,7 +49,9 @@ describe("registerEditTool", () => {
|
|
|
49
49
|
},
|
|
50
50
|
(_id: string, _inv: () => void) => {},
|
|
51
51
|
);
|
|
52
|
-
expect(tools).
|
|
52
|
+
expect(tools).toHaveLength(1);
|
|
53
|
+
expect(tools[0]?.name).toBe("edit");
|
|
54
|
+
expect(tools[0]?.renderShell).toBe("self");
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
it("restores the bounded diff when an elapsed card is expanded", () => {
|
package/src/edit.ts
CHANGED
|
@@ -7,11 +7,13 @@ import type {
|
|
|
7
7
|
} from "@earendil-works/pi-coding-agent";
|
|
8
8
|
|
|
9
9
|
import { type CollapseState, tickCollapse } from "@xynogen/pix-data/collapse";
|
|
10
|
+
import { resolveBaseBackground } from "@xynogen/pix-pretty/ansi";
|
|
10
11
|
import { MAX_RENDER_LINES } from "@xynogen/pix-pretty/config";
|
|
11
12
|
import type { ToolContext } from "@xynogen/pix-pretty/context";
|
|
12
13
|
import { parseDiff } from "@xynogen/pix-pretty/diff";
|
|
13
14
|
import {
|
|
14
15
|
diffThemeCacheKey,
|
|
16
|
+
renderDiffSummary,
|
|
15
17
|
renderSplit,
|
|
16
18
|
resolveDiffColors,
|
|
17
19
|
summarize,
|
|
@@ -114,6 +116,7 @@ export function registerEditTool(
|
|
|
114
116
|
pi.registerTool({
|
|
115
117
|
...origEdit,
|
|
116
118
|
name: "edit",
|
|
119
|
+
renderShell: "self",
|
|
117
120
|
|
|
118
121
|
async execute(
|
|
119
122
|
tid: string,
|
|
@@ -170,6 +173,7 @@ export function registerEditTool(
|
|
|
170
173
|
},
|
|
171
174
|
|
|
172
175
|
renderCall(args: EditParams, theme: ThemeLike, renderCtx: RenderContextLike<EditRenderState>) {
|
|
176
|
+
resolveBaseBackground(theme);
|
|
173
177
|
const fp = args?.path ?? args?.file_path ?? "";
|
|
174
178
|
const operations = getEditOperations(args);
|
|
175
179
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
@@ -187,8 +191,12 @@ export function registerEditTool(
|
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
const { summary } = summarizeEditOperations(operations);
|
|
190
|
-
const
|
|
191
|
-
|
|
194
|
+
const coloredSummary = renderDiffSummary(summary, theme);
|
|
195
|
+
const suffix =
|
|
196
|
+
operations.length === 1
|
|
197
|
+
? coloredSummary
|
|
198
|
+
: `${theme.fg("muted", `${operations.length} edits`)} ${coloredSummary}`;
|
|
199
|
+
text.setText(fillToolBackground(`${hdr} ${suffix}`));
|
|
192
200
|
return text;
|
|
193
201
|
},
|
|
194
202
|
|
|
@@ -198,6 +206,7 @@ export function registerEditTool(
|
|
|
198
206
|
theme: ThemeLike,
|
|
199
207
|
renderCtx: RenderContextLike<EditRenderState>,
|
|
200
208
|
) {
|
|
209
|
+
resolveBaseBackground(theme);
|
|
201
210
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
202
211
|
const d = result.details as Record<string, unknown> | undefined;
|
|
203
212
|
const isPartial = _opt?.isPartial === true;
|
|
@@ -248,7 +257,8 @@ export function registerEditTool(
|
|
|
248
257
|
renderCtx.state._edk = key;
|
|
249
258
|
const loc =
|
|
250
259
|
(d.editLine as number) > 0 ? ` ${theme.fg("muted", `at line ${d.editLine}`)}` : "";
|
|
251
|
-
|
|
260
|
+
const summary = renderDiffSummary(String(d.summary), theme);
|
|
261
|
+
renderCtx.state._edt = ` ${summary}${loc}\n${theme.fg("muted", " rendering diff…")}`;
|
|
252
262
|
const dc = resolveDiffColors(theme);
|
|
253
263
|
const diff = parseDiff(
|
|
254
264
|
d.oldContent as string,
|
|
@@ -261,7 +271,8 @@ export function registerEditTool(
|
|
|
261
271
|
if (renderCtx.state._edk !== key) return;
|
|
262
272
|
const loc2 =
|
|
263
273
|
(d.editLine as number) > 0 ? ` ${theme.fg("muted", `at line ${d.editLine}`)}` : "";
|
|
264
|
-
|
|
274
|
+
const summary = renderDiffSummary(String(d.summary), theme);
|
|
275
|
+
renderCtx.state._edt = ` ${summary}${loc2}\n${rendered}`;
|
|
265
276
|
renderCtx.invalidate();
|
|
266
277
|
})
|
|
267
278
|
.catch(() => {
|
|
@@ -280,7 +291,8 @@ export function registerEditTool(
|
|
|
280
291
|
if (renderCtx.toolCallId) trackInvalidator(renderCtx.toolCallId, renderCtx.invalidate);
|
|
281
292
|
if (renderCtx.state._edk !== key) {
|
|
282
293
|
renderCtx.state._edk = key;
|
|
283
|
-
|
|
294
|
+
const summary = renderDiffSummary(String(d.summary), theme);
|
|
295
|
+
renderCtx.state._edt = ` ${theme.fg("muted", `${d.editCount} edits`)} ${summary}\n${theme.fg("muted", " rendering diff…")}`;
|
|
284
296
|
const dc = resolveDiffColors(theme);
|
|
285
297
|
Promise.all(
|
|
286
298
|
(
|
|
@@ -298,7 +310,8 @@ export function registerEditTool(
|
|
|
298
310
|
.then((rendered) => {
|
|
299
311
|
if (renderCtx.state._edk !== key) return;
|
|
300
312
|
const body = rendered.join(`\n${theme.fg("muted", " ···")}\n`);
|
|
301
|
-
|
|
313
|
+
const summary = renderDiffSummary(String(d.summary), theme);
|
|
314
|
+
renderCtx.state._edt = ` ${theme.fg("muted", `${d.editCount} edits`)} ${summary}\n${body}`;
|
|
302
315
|
renderCtx.invalidate();
|
|
303
316
|
})
|
|
304
317
|
.catch(() => {
|