@trim21/personal-pi-extensions 0.0.303 → 0.0.304

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.303",
3
+ "version": "0.0.304",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -16,9 +16,10 @@ import { Type } from "typebox";
16
16
  import { Value } from "typebox/value";
17
17
 
18
18
  import { requireAbsolutePath } from "../claude-code/common.js";
19
+ import { type ToolPendant } from "../lib/pendant.js";
19
20
  import { guardWriteAccess } from "../lib/write-guard.js";
20
21
  import { callAftTool } from "./bridge.js";
21
- import { type AftToolContext, bridgeFor } from "./tools.js";
22
+ import { type AftToolContext, bridgeFor, buildPendantMarkdown } from "./tools.js";
22
23
 
23
24
  // ── 纯函数(可测) ──────────────────────────────────────────────────────────
24
25
 
@@ -256,9 +257,20 @@ export function registerAstEditTool(pi: ExtensionAPI, ctx: AftToolContext): void
256
257
 
257
258
  // 第三步:AFT 原子写盘(备份 + 格式化 + undo),结果由 Rust 格式化返回。
258
259
  const { text } = await callAftTool(bridgeFor(ctx), "edit", rawArgs, extCtx);
260
+ const files = previewFiles.map((f) => f.file || filePath);
259
261
  return {
260
262
  content: [{ type: "text", text }],
261
- details: { input: params, files: previewFiles.map((f) => f.file || filePath) },
263
+ details: {
264
+ files,
265
+ pendant: {
266
+ markdown: buildPendantMarkdown({
267
+ title: "ast_edit",
268
+ input: params,
269
+ output: text,
270
+ }),
271
+ expanded: true,
272
+ } satisfies ToolPendant,
273
+ },
262
274
  };
263
275
  },
264
276
  });
package/src/aft/tools.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
21
21
  import { Type } from "typebox";
22
22
 
23
+ import { type ToolPendant } from "../lib/pendant.js";
23
24
  import { callAftTool, SEMANTIC_INDEX_WAIT_TIMEOUT_MS } from "./bridge.js";
24
25
 
25
26
  /** 解析 `~` 前缀与相对路径(相对 session cwd)。URL 与绝对路径原样返回。 */
@@ -40,6 +41,32 @@ export function bridgeFor(ctx: AftToolContext): AftProjectTransport {
40
41
  return ctx.pool.getBridge(ctx.cwd);
41
42
  }
42
43
 
44
+ /** 人类视角的调用记录:input params + 与 LLM 相同的输出结果。 */
45
+ export function buildPendantMarkdown(params: {
46
+ title: string;
47
+ input: unknown;
48
+ output: string;
49
+ truncated?: boolean;
50
+ }): string {
51
+ const lines = [
52
+ `## ${params.title}`,
53
+ "",
54
+ "**Input**",
55
+ "",
56
+ "```json",
57
+ JSON.stringify(params.input, null, 2),
58
+ "```",
59
+ "",
60
+ "**Output**",
61
+ "",
62
+ params.output,
63
+ ];
64
+ if (params.truncated) {
65
+ lines.push("", "_输出已截断_");
66
+ }
67
+ return lines.join("\n").trim();
68
+ }
69
+
43
70
  const OutlineParams = Type.Object(
44
71
  {
45
72
  target: Type.String({
@@ -88,9 +115,21 @@ export function registerOutlineTool(pi: ExtensionAPI, ctx: AftToolContext): void
88
115
  if (params.includeTests !== undefined) rawArgs.includeTests = params.includeTests;
89
116
 
90
117
  const { text, response } = await callAftTool(bridgeFor(ctx), "outline", rawArgs, extCtx);
118
+ const truncated = response.truncated === true;
91
119
  return {
92
120
  content: [{ type: "text", text }],
93
- details: { input: params, truncated: response.truncated === true },
121
+ details: {
122
+ truncated,
123
+ pendant: {
124
+ markdown: buildPendantMarkdown({
125
+ title: "aft_outline",
126
+ input: params,
127
+ output: text,
128
+ truncated,
129
+ }),
130
+ expanded: true,
131
+ } satisfies ToolPendant,
132
+ },
94
133
  };
95
134
  },
96
135
  });
@@ -193,9 +232,21 @@ export function registerZoomTool(pi: ExtensionAPI, ctx: AftToolContext): void {
193
232
  if (coerceBoolean(params.callgraph)) rawArgs.callgraph = true;
194
233
 
195
234
  const { text, response } = await callAftTool(bridgeFor(ctx), "zoom", rawArgs, extCtx);
235
+ const truncated = response.truncated === true;
196
236
  return {
197
237
  content: [{ type: "text", text }],
198
- details: { input: params, truncated: response.truncated === true },
238
+ details: {
239
+ truncated,
240
+ pendant: {
241
+ markdown: buildPendantMarkdown({
242
+ title: "aft_zoom",
243
+ input: params,
244
+ output: text,
245
+ truncated,
246
+ }),
247
+ expanded: true,
248
+ } satisfies ToolPendant,
249
+ },
199
250
  };
200
251
  },
201
252
  });
@@ -291,9 +342,21 @@ export function registerCallgraphTool(pi: ExtensionAPI, ctx: AftToolContext): vo
291
342
  formatCallgraphSections(params.op, response, PLAIN_CALLGRAPH_THEME, {
292
343
  includeUnresolved: coerceBoolean(params.includeUnresolved),
293
344
  }).join("\n");
345
+ const truncated = response.truncated === true;
294
346
  return {
295
347
  content: [{ type: "text", text: out }],
296
- details: { input: params, truncated: response.truncated === true },
348
+ details: {
349
+ truncated,
350
+ pendant: {
351
+ markdown: buildPendantMarkdown({
352
+ title: "aft_callgraph",
353
+ input: params,
354
+ output: out,
355
+ truncated,
356
+ }),
357
+ expanded: true,
358
+ } satisfies ToolPendant,
359
+ },
297
360
  };
298
361
  },
299
362
  });
@@ -354,9 +417,21 @@ export function registerSearchTool(pi: ExtensionAPI, ctx: AftToolContext): void
354
417
  transportTimeoutMs: SEMANTIC_INDEX_WAIT_TIMEOUT_MS + 60_000,
355
418
  keepBridgeOnTimeout: true,
356
419
  });
420
+ const truncated = response.truncated === true;
357
421
  return {
358
422
  content: [{ type: "text", text }],
359
- details: { input: params, truncated: response.truncated === true },
423
+ details: {
424
+ truncated,
425
+ pendant: {
426
+ markdown: buildPendantMarkdown({
427
+ title: "aft_search",
428
+ input: params,
429
+ output: text,
430
+ truncated,
431
+ }),
432
+ expanded: true,
433
+ } satisfies ToolPendant,
434
+ },
360
435
  };
361
436
  },
362
437
  });