@xynogen/pix-edit 0.1.12 → 0.1.13
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 +1 -1
- package/src/edit.test.ts +2 -8
- package/src/edit.ts +11 -41
- package/src/extension.ts +2 -9
package/package.json
CHANGED
package/src/edit.test.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
2
|
import type { CursorStore, FffState } from "@xynogen/pix-pretty/fff";
|
|
3
3
|
import type { PiPrettyApi, TextComponentCtor } from "@xynogen/pix-pretty/types";
|
|
4
|
-
import {
|
|
5
|
-
getEditOperations,
|
|
6
|
-
registerEditTool,
|
|
7
|
-
summarizeEditOperations,
|
|
8
|
-
} from "./edit";
|
|
4
|
+
import { getEditOperations, registerEditTool, summarizeEditOperations } from "./edit";
|
|
9
5
|
|
|
10
6
|
class MockTextComponent {
|
|
11
7
|
private text = "";
|
|
@@ -72,9 +68,7 @@ describe("getEditOperations", () => {
|
|
|
72
68
|
|
|
73
69
|
describe("summarizeEditOperations", () => {
|
|
74
70
|
it("returns a summary string", () => {
|
|
75
|
-
const { summary } = summarizeEditOperations([
|
|
76
|
-
{ oldText: "a\nb", newText: "c\nd\ne" },
|
|
77
|
-
]);
|
|
71
|
+
const { summary } = summarizeEditOperations([{ oldText: "a\nb", newText: "c\nd\ne" }]);
|
|
78
72
|
expect(typeof summary).toBe("string");
|
|
79
73
|
expect(summary.length).toBeGreaterThan(0);
|
|
80
74
|
});
|
package/src/edit.ts
CHANGED
|
@@ -167,11 +167,7 @@ export function registerEditTool(
|
|
|
167
167
|
return result;
|
|
168
168
|
},
|
|
169
169
|
|
|
170
|
-
renderCall(
|
|
171
|
-
args: EditParams,
|
|
172
|
-
theme: ThemeLike,
|
|
173
|
-
renderCtx: RenderContextLike<EditRenderState>,
|
|
174
|
-
) {
|
|
170
|
+
renderCall(args: EditParams, theme: ThemeLike, renderCtx: RenderContextLike<EditRenderState>) {
|
|
175
171
|
const fp = args?.path ?? args?.file_path ?? "";
|
|
176
172
|
const operations = getEditOperations(args);
|
|
177
173
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
@@ -183,10 +179,7 @@ export function registerEditTool(
|
|
|
183
179
|
}
|
|
184
180
|
|
|
185
181
|
const { summary } = summarizeEditOperations(operations);
|
|
186
|
-
const suffix =
|
|
187
|
-
operations.length === 1
|
|
188
|
-
? summary
|
|
189
|
-
: `${operations.length} edits ${summary}`;
|
|
182
|
+
const suffix = operations.length === 1 ? summary : `${operations.length} edits ${summary}`;
|
|
190
183
|
text.setText(fillToolBackground(`${hdr} ${theme.fg("muted", suffix)}`));
|
|
191
184
|
return text;
|
|
192
185
|
},
|
|
@@ -220,14 +213,11 @@ export function registerEditTool(
|
|
|
220
213
|
// Single edit — full split diff
|
|
221
214
|
if (d?._type === "editInfo") {
|
|
222
215
|
const key = `ed:${diffThemeCacheKey(theme)}:${termW()}:${d.summary}:${(d.oldContent as string).length}:${(d.newContent as string).length}:${d.language ?? ""}`;
|
|
223
|
-
if (renderCtx.toolCallId)
|
|
224
|
-
trackInvalidator(renderCtx.toolCallId, renderCtx.invalidate);
|
|
216
|
+
if (renderCtx.toolCallId) trackInvalidator(renderCtx.toolCallId, renderCtx.invalidate);
|
|
225
217
|
if (renderCtx.state._edk !== key) {
|
|
226
218
|
renderCtx.state._edk = key;
|
|
227
219
|
const loc =
|
|
228
|
-
(d.editLine as number) > 0
|
|
229
|
-
? ` ${theme.fg("muted", `at line ${d.editLine}`)}`
|
|
230
|
-
: "";
|
|
220
|
+
(d.editLine as number) > 0 ? ` ${theme.fg("muted", `at line ${d.editLine}`)}` : "";
|
|
231
221
|
renderCtx.state._edt = ` ${d.summary}${loc}\n${theme.fg("muted", " rendering diff…")}`;
|
|
232
222
|
const dc = resolveDiffColors(theme);
|
|
233
223
|
const diff = parseDiff(
|
|
@@ -236,18 +226,11 @@ export function registerEditTool(
|
|
|
236
226
|
3,
|
|
237
227
|
d.editLine as number,
|
|
238
228
|
);
|
|
239
|
-
renderSplit(
|
|
240
|
-
diff,
|
|
241
|
-
d.language as string | undefined,
|
|
242
|
-
MAX_RENDER_LINES,
|
|
243
|
-
dc,
|
|
244
|
-
)
|
|
229
|
+
renderSplit(diff, d.language as string | undefined, MAX_RENDER_LINES, dc)
|
|
245
230
|
.then((rendered) => {
|
|
246
231
|
if (renderCtx.state._edk !== key) return;
|
|
247
232
|
const loc2 =
|
|
248
|
-
(d.editLine as number) > 0
|
|
249
|
-
? ` ${theme.fg("muted", `at line ${d.editLine}`)}`
|
|
250
|
-
: "";
|
|
233
|
+
(d.editLine as number) > 0 ? ` ${theme.fg("muted", `at line ${d.editLine}`)}` : "";
|
|
251
234
|
renderCtx.state._edt = ` ${d.summary}${loc2}\n${rendered}`;
|
|
252
235
|
renderCtx.invalidate();
|
|
253
236
|
})
|
|
@@ -264,8 +247,7 @@ export function registerEditTool(
|
|
|
264
247
|
// Multi-edit — stacked diffs
|
|
265
248
|
if (d?._type === "multiEditInfo") {
|
|
266
249
|
const key = `med:${diffThemeCacheKey(theme)}:${termW()}:${d.summary}:${d.editCount}:${d.diffLineCount}`;
|
|
267
|
-
if (renderCtx.toolCallId)
|
|
268
|
-
trackInvalidator(renderCtx.toolCallId, renderCtx.invalidate);
|
|
250
|
+
if (renderCtx.toolCallId) trackInvalidator(renderCtx.toolCallId, renderCtx.invalidate);
|
|
269
251
|
if (renderCtx.state._edk !== key) {
|
|
270
252
|
renderCtx.state._edk = key;
|
|
271
253
|
renderCtx.state._edt = ` ${d.editCount} edits ${d.summary}\n${theme.fg("muted", " rendering diff…")}`;
|
|
@@ -279,12 +261,7 @@ export function registerEditTool(
|
|
|
279
261
|
editLine?: number;
|
|
280
262
|
}>
|
|
281
263
|
).map((op) => {
|
|
282
|
-
const diff = parseDiff(
|
|
283
|
-
op.oldContent,
|
|
284
|
-
op.newContent,
|
|
285
|
-
3,
|
|
286
|
-
op.editLine ?? 0,
|
|
287
|
-
);
|
|
264
|
+
const diff = parseDiff(op.oldContent, op.newContent, 3, op.editLine ?? 0);
|
|
288
265
|
return renderSplit(diff, op.language, MAX_RENDER_LINES, dc);
|
|
289
266
|
}),
|
|
290
267
|
)
|
|
@@ -300,20 +277,13 @@ export function registerEditTool(
|
|
|
300
277
|
renderCtx.invalidate();
|
|
301
278
|
});
|
|
302
279
|
}
|
|
303
|
-
text.setText(
|
|
304
|
-
renderCtx.state._edt ?? ` ${d.editCount} edits ${d.summary}`,
|
|
305
|
-
);
|
|
280
|
+
text.setText(renderCtx.state._edt ?? ` ${d.editCount} edits ${d.summary}`);
|
|
306
281
|
return text;
|
|
307
282
|
}
|
|
308
283
|
|
|
309
284
|
const fallback = result.content?.[0];
|
|
310
|
-
const fallbackText =
|
|
311
|
-
|
|
312
|
-
text.setText(
|
|
313
|
-
fillToolBackground(
|
|
314
|
-
` ${theme.fg("dim", String(fallbackText).slice(0, 120))}`,
|
|
315
|
-
),
|
|
316
|
-
);
|
|
285
|
+
const fallbackText = fallback && isTextContent(fallback) ? fallback.text : "edited";
|
|
286
|
+
text.setText(fillToolBackground(` ${theme.fg("dim", String(fallbackText).slice(0, 120))}`));
|
|
317
287
|
return text;
|
|
318
288
|
},
|
|
319
289
|
});
|
package/src/extension.ts
CHANGED
|
@@ -4,15 +4,8 @@ import {
|
|
|
4
4
|
type EditToolInput,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { CursorStore, fffState } from "@xynogen/pix-pretty/fff";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
trackInvalidator,
|
|
10
|
-
} from "@xynogen/pix-pretty/resize";
|
|
11
|
-
import type {
|
|
12
|
-
PiPrettyApi,
|
|
13
|
-
TextComponentCtor,
|
|
14
|
-
ToolFactory,
|
|
15
|
-
} from "@xynogen/pix-pretty/types";
|
|
7
|
+
import { attachResizeListener, trackInvalidator } from "@xynogen/pix-pretty/resize";
|
|
8
|
+
import type { PiPrettyApi, TextComponentCtor, ToolFactory } from "@xynogen/pix-pretty/types";
|
|
16
9
|
import { shortPath } from "@xynogen/pix-pretty/utils";
|
|
17
10
|
import { registerEditTool } from "./edit.js";
|
|
18
11
|
import { once } from "./once.ts";
|