@trim21/personal-pi-extensions 0.1.487 → 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.
- package/package.json +1 -1
- package/src/aft/tools.ts +39 -9
package/package.json
CHANGED
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
|
|
|
@@ -290,6 +291,42 @@ const CallgraphParams = Type.Object(
|
|
|
290
291
|
/** 只读导航的合法"否定答案":符号未定义或索引仍在构建——返回文本而非报错。 */
|
|
291
292
|
const CALLGRAPH_SOFT_CODES = new Set(["symbol_not_found", "callgraph_building"]);
|
|
292
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
|
+
|
|
293
330
|
export function registerCallgraphTool(pi: ExtensionAPI, ctx: AftToolContext): void {
|
|
294
331
|
pi.registerTool({
|
|
295
332
|
name: "aft_callgraph",
|
|
@@ -317,14 +354,7 @@ export function registerCallgraphTool(pi: ExtensionAPI, ctx: AftToolContext): vo
|
|
|
317
354
|
includeUnresolved: params.includeUnresolved,
|
|
318
355
|
});
|
|
319
356
|
|
|
320
|
-
const { text, response } = await
|
|
321
|
-
bridgeFor(ctx),
|
|
322
|
-
"callgraph",
|
|
323
|
-
rawArgs,
|
|
324
|
-
extCtx,
|
|
325
|
-
undefined,
|
|
326
|
-
CALLGRAPH_SOFT_CODES,
|
|
327
|
-
);
|
|
357
|
+
const { text, response } = await callCallgraphWithBuildRetry(bridgeFor(ctx), rawArgs, extCtx);
|
|
328
358
|
const out =
|
|
329
359
|
text ||
|
|
330
360
|
formatCallgraphSections(params.op, response, PLAIN_CALLGRAPH_THEME, {
|