@trim21/personal-pi-extensions 0.0.305 → 0.0.306
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/aft/ast-edit.ts +35 -1
package/package.json
CHANGED
package/src/aft/ast-edit.ts
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
* 防呆不同,ast_edit 不要求先读)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import
|
|
14
|
+
import {
|
|
15
|
+
type ExtensionAPI,
|
|
16
|
+
generateDiffString,
|
|
17
|
+
generateUnifiedPatch,
|
|
18
|
+
} from "@earendil-works/pi-coding-agent";
|
|
15
19
|
import { Type } from "typebox";
|
|
16
20
|
import { Value } from "typebox/value";
|
|
17
21
|
|
|
@@ -114,6 +118,35 @@ export function mapEditItems(
|
|
|
114
118
|
});
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
/**
|
|
122
|
+
* 参照 Edit 工具的结果输出:把 preview 的 before/after 转成行号 diff、
|
|
123
|
+
* unified patch 与首个变更行。多文件(glob 批量)时逐文件拼接 diff/patch,
|
|
124
|
+
* firstChangedLine 取首个文件的。
|
|
125
|
+
*/
|
|
126
|
+
export function buildEditDiffDetails(
|
|
127
|
+
previewFiles: PreviewFile[],
|
|
128
|
+
fallbackFile: string,
|
|
129
|
+
): { diff: string; patch: string; firstChangedLine: number | undefined } {
|
|
130
|
+
const parts = previewFiles.map((f) => {
|
|
131
|
+
const file = f.file || fallbackFile;
|
|
132
|
+
const diff = generateDiffString(f.before, f.after);
|
|
133
|
+
return {
|
|
134
|
+
file,
|
|
135
|
+
diff: diff.diff,
|
|
136
|
+
patch: generateUnifiedPatch(file, f.before, f.after),
|
|
137
|
+
firstChangedLine: diff.firstChangedLine,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
if (parts.length === 0) {
|
|
141
|
+
return { diff: "", patch: "", firstChangedLine: undefined };
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
diff: parts.map((p) => `--- ${p.file}\n${p.diff}`).join("\n"),
|
|
145
|
+
patch: parts.map((p) => `--- ${p.file}\n${p.patch}`).join("\n"),
|
|
146
|
+
firstChangedLine: parts[0]?.firstChangedLine,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
117
150
|
// ── 工具 ────────────────────────────────────────────────────────────────────
|
|
118
151
|
|
|
119
152
|
const EditItemParams = Type.Object({
|
|
@@ -262,6 +295,7 @@ export function registerAstEditTool(pi: ExtensionAPI, ctx: AftToolContext): void
|
|
|
262
295
|
content: [{ type: "text", text }],
|
|
263
296
|
details: {
|
|
264
297
|
files,
|
|
298
|
+
...buildEditDiffDetails(previewFiles, filePath),
|
|
265
299
|
pendant: {
|
|
266
300
|
markdown: buildPendantMarkdown({
|
|
267
301
|
title: "ast_edit",
|