@trim21/personal-pi-extensions 0.1.486 → 0.1.488

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/aft/tools.ts +39 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.486",
3
+ "version": "0.1.488",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
package/src/aft/tools.ts CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { readFileSync } from "node:fs";
9
9
  import { stat } from "node:fs/promises";
10
+ import { setTimeout as sleep } from "node:timers/promises";
10
11
  import { fileURLToPath } from "node:url";
11
12
 
12
13
  import {
@@ -18,7 +19,7 @@ import {
18
19
  PLAIN_CALLGRAPH_THEME,
19
20
  type StatusSnapshot,
20
21
  } from "@cortexkit/aft-bridge";
21
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
22
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
22
23
  import { type Static, Type } from "typebox";
23
24
  import { Value } from "typebox/value";
24
25
 
@@ -152,7 +153,6 @@ export function registerOutlineTool(pi: ExtensionAPI, ctx: AftToolContext): void
152
153
  truncated,
153
154
  params,
154
155
  pendant: {
155
- title: "aft_outline",
156
156
  subtitle,
157
157
  } satisfies ToolPendant,
158
158
  },
@@ -224,7 +224,6 @@ export function registerZoomTool(pi: ExtensionAPI, ctx: AftToolContext): void {
224
224
  truncated,
225
225
  params,
226
226
  pendant: {
227
- title: "aft_zoom",
228
227
  subtitle,
229
228
  markdown: buildPendantMarkdown({
230
229
  title: "aft_zoom",
@@ -292,6 +291,42 @@ const CallgraphParams = Type.Object(
292
291
  /** 只读导航的合法"否定答案":符号未定义或索引仍在构建——返回文本而非报错。 */
293
292
  const CALLGRAPH_SOFT_CODES = new Set(["symbol_not_found", "callgraph_building"]);
294
293
 
294
+ /**
295
+ * callgraph 查询的 building 重试总预算与间隔。Rust 侧内联等待窗口
296
+ * (AFT_CALLGRAPH_BUILD_WAIT_MS)覆盖不到的场景会秒回 callgraph_building:
297
+ * 语义索引冷种子 gate 激活期间 callgraph 冷构建被 defer(大仓库可持续数分钟),
298
+ * 以及冷构建本身超过内联窗口。这里在扩展侧重试,预算耗尽才把 building
299
+ * 文本交给模型。
300
+ */
301
+ export const CALLGRAPH_BUILD_RETRY_BUDGET_MS = 90_000;
302
+ const CALLGRAPH_BUILD_RETRY_INTERVAL_MS = 3_000;
303
+
304
+ export async function callCallgraphWithBuildRetry(
305
+ bridge: AftProjectTransport,
306
+ rawArgs: Record<string, unknown>,
307
+ extCtx: ExtensionContext,
308
+ timing?: { budgetMs: number; intervalMs: number },
309
+ ): Promise<{ text: string; response: Record<string, unknown> }> {
310
+ const budgetMs = timing?.budgetMs ?? CALLGRAPH_BUILD_RETRY_BUDGET_MS;
311
+ const intervalMs = timing?.intervalMs ?? CALLGRAPH_BUILD_RETRY_INTERVAL_MS;
312
+ const deadline = Date.now() + budgetMs;
313
+ for (;;) {
314
+ const { text, response } = await callAftTool(
315
+ bridge,
316
+ "callgraph",
317
+ rawArgs,
318
+ extCtx,
319
+ undefined,
320
+ CALLGRAPH_SOFT_CODES,
321
+ );
322
+ const code = typeof response.code === "string" ? response.code : "";
323
+ if (code !== "callgraph_building" || Date.now() >= deadline) {
324
+ return { text, response };
325
+ }
326
+ await sleep(intervalMs);
327
+ }
328
+ }
329
+
295
330
  export function registerCallgraphTool(pi: ExtensionAPI, ctx: AftToolContext): void {
296
331
  pi.registerTool({
297
332
  name: "aft_callgraph",
@@ -319,14 +354,7 @@ export function registerCallgraphTool(pi: ExtensionAPI, ctx: AftToolContext): vo
319
354
  includeUnresolved: params.includeUnresolved,
320
355
  });
321
356
 
322
- const { text, response } = await callAftTool(
323
- bridgeFor(ctx),
324
- "callgraph",
325
- rawArgs,
326
- extCtx,
327
- undefined,
328
- CALLGRAPH_SOFT_CODES,
329
- );
357
+ const { text, response } = await callCallgraphWithBuildRetry(bridgeFor(ctx), rawArgs, extCtx);
330
358
  const out =
331
359
  text ||
332
360
  formatCallgraphSections(params.op, response, PLAIN_CALLGRAPH_THEME, {