@trim21/personal-pi-extensions 0.0.305 → 0.0.308
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/aft/ast-edit.ts +35 -1
- package/src/system-prompt/prompt.md +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trim21/personal-pi-extensions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.308",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
|
|
6
6
|
"keywords": [
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
"web-tree-sitter": "^0.26.12"
|
|
94
94
|
},
|
|
95
95
|
"optionalDependencies": {
|
|
96
|
-
"@cortexkit/aft-linux-x64": "0.51.
|
|
96
|
+
"@cortexkit/aft-linux-x64": "0.51.2"
|
|
97
97
|
}
|
|
98
98
|
}
|
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",
|
|
@@ -17,6 +17,7 @@ In addition to the tools above, you may have access to other custom tools depend
|
|
|
17
17
|
|
|
18
18
|
## Doing tasks
|
|
19
19
|
|
|
20
|
+
- When investigating a codebase, first use the AFT tools (aft_outline / aft_zoom / aft_callgraph / aft_search) to map the structure, inspect named symbols, and trace call relationships before falling back to grep or full-file reads — they are cheaper and purpose-built for this.
|
|
20
21
|
- The user will primarily request you to perform software engineering tasks. These may include solving bugs, adding new functionality, refactoring code, explaining code, and more. When given an unclear or generic instruction, consider it in the context of these software engineering tasks and the current working directory. For example, if the user asks you to change "methodName" to snake case, do not reply with just "method_name", instead find the method in the code and modify the code.
|
|
21
22
|
- You are highly capable and often allow users to complete ambitious tasks that would otherwise be too complex or take too long. You should defer to user judgement about whether a task is too large to attempt.
|
|
22
23
|
- For exploratory questions ("what could we do about X?", "how should we approach this?", "what do you think?"), respond in 2-3 sentences with a recommendation and the main tradeoff. Present it as something the user can redirect, not a decided plan. Don't implement until the user agrees.
|