@trim21/personal-pi-extensions 0.1.516 → 0.1.518
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/bridge.ts +9 -22
- package/src/aft/index.ts +33 -21
- package/src/gh-readonly.ts +18 -75
package/package.json
CHANGED
package/src/aft/bridge.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFT bridge 管理:二进制解析、transport pool 生命周期、工具调用封装。
|
|
3
3
|
*
|
|
4
|
-
* 依赖 @cortexkit/aft-bridge(官方协议的 JS
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 依赖 @cortexkit/aft-bridge(官方协议的 JS 客户端):二进制解析由入口在
|
|
5
|
+
* session_start 用 findBinary 完成(缓存 → npm 平台包 → PATH → cargo →
|
|
6
|
+
* GitHub release 兜底),本模块只接收解析结果;内网部署只要保证平台包版本与
|
|
7
7
|
* aft-bridge 锁一致就不会走到最后的网络下载。
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
type AftTransportPool,
|
|
13
13
|
type BridgeRequestOptions,
|
|
14
14
|
createAftTransportPool,
|
|
15
|
-
findBinary,
|
|
16
15
|
inlineUserConfigTier,
|
|
17
16
|
readConfigTiers,
|
|
18
17
|
resolveCortexKitConfigPaths,
|
|
@@ -25,6 +24,8 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
25
24
|
import type { SemanticRemote } from "./config.js";
|
|
26
25
|
import { type AftLogger, createAftLogger } from "./logger.js";
|
|
27
26
|
|
|
27
|
+
export { findBinary } from "@cortexkit/aft-bridge";
|
|
28
|
+
|
|
28
29
|
/** Pi 会话 ID:Rust 侧用它做 session 作用域(undo/checkpoint),感知工具可留空。 */
|
|
29
30
|
export function resolveSessionId(extCtx: ExtensionContext): string | undefined {
|
|
30
31
|
const manager = (extCtx as unknown as { sessionManager?: { getSessionId?: () => string } })
|
|
@@ -33,22 +34,6 @@ export function resolveSessionId(extCtx: ExtensionContext): string | undefined {
|
|
|
33
34
|
return typeof id === "string" && id.length > 0 ? id : undefined;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
/**
|
|
37
|
-
* 解析 aft 二进制;失败时抛出(调用方决定是否降级不注册工具)。
|
|
38
|
-
* 不带版本参数:findBinary 内部用 @cortexkit/aft-bridge 自身版本作为匹配基准,
|
|
39
|
-
* 与 npm 平台包(@cortexkit/aft-<platform>)精确对齐,避免手动读 package.json
|
|
40
|
-
* (其 exports 不暴露 ./package.json)。
|
|
41
|
-
*/
|
|
42
|
-
export async function resolveAftBinary(): Promise<string> {
|
|
43
|
-
const path = await findBinary();
|
|
44
|
-
if (!path) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
"AFT binary not found. Install via npm platform package (@cortexkit/aft-<platform>), cargo install agent-file-tools, or place `aft` on PATH.",
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return path;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
37
|
export interface AftPool {
|
|
53
38
|
pool: AftTransportPool;
|
|
54
39
|
/** 当前项目根(process.cwd),供 bridge 查询。 */
|
|
@@ -65,10 +50,11 @@ export interface AftState {
|
|
|
65
50
|
export async function createAftState(
|
|
66
51
|
cwd: string,
|
|
67
52
|
sessionId: string | undefined,
|
|
53
|
+
binaryPath: string,
|
|
68
54
|
semantic?: SemanticRemote,
|
|
69
55
|
): Promise<AftState> {
|
|
70
56
|
const logger = createAftLogger(sessionId);
|
|
71
|
-
const pool = await createAftPool(cwd, logger, semantic);
|
|
57
|
+
const pool = await createAftPool(cwd, logger, binaryPath, semantic);
|
|
72
58
|
return { logger, pool };
|
|
73
59
|
}
|
|
74
60
|
|
|
@@ -91,6 +77,7 @@ export const SEMANTIC_API_KEY_ENV = "AFT_SEMANTIC_API_KEY";
|
|
|
91
77
|
|
|
92
78
|
/**
|
|
93
79
|
* 创建 transport pool。每个项目根一个常驻 aft 进程,跨 session 共享。
|
|
80
|
+
* `binaryPath` 由入口在 session_start 解析好传入(含 auto-download 兜底)。
|
|
94
81
|
*
|
|
95
82
|
* `semantic` 决定 embedding 密钥如何送达子进程:aft 只从配置里读 `api_key_env`
|
|
96
83
|
* 这个「变量名」,再自己 `env::var` 取值,所以提供值时必须连带把名字告诉它。
|
|
@@ -99,12 +86,12 @@ export const SEMANTIC_API_KEY_ENV = "AFT_SEMANTIC_API_KEY";
|
|
|
99
86
|
export async function createAftPool(
|
|
100
87
|
cwd: string,
|
|
101
88
|
logger: AftLogger,
|
|
89
|
+
binaryPath: string,
|
|
102
90
|
semantic?: SemanticRemote,
|
|
103
91
|
): Promise<AftPool> {
|
|
104
92
|
// 必须在任何 bridge 代码运行前注册:不设 logger 时 aft-bridge 会把 child
|
|
105
93
|
// stderr / 生命周期日志 fallback 到 console.error,raw 输出打进 pi 的 stderr 破坏 TUI。
|
|
106
94
|
setActiveLogger(logger);
|
|
107
|
-
const binaryPath = await resolveAftBinary();
|
|
108
95
|
const paths = resolveCortexKitConfigPaths(cwd);
|
|
109
96
|
const childEnv: Record<string, string> = {
|
|
110
97
|
// Rust 侧 semantic_search 在索引 Building 时阻塞等待构建完成
|
package/src/aft/index.ts
CHANGED
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
* fastembed 后端不使用。
|
|
10
10
|
*
|
|
11
11
|
* bridge 状态(日志 + 常驻 aft 子进程)的生命周期跟 session 走:session_start
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* 时先解析 aft 二进制(含 GitHub release auto-download 兜底)——找不到就
|
|
13
|
+
* notify warning 且不注册任何 aft 工具,避免模型看到只会抛 "not initialized"
|
|
14
|
+
* 的死工具;找到则注册工具并创建 bridge 状态(日志落在
|
|
15
|
+
* tmp/{sessionId}/aft-plugin.log),session_shutdown / 进程退出时释放。
|
|
16
|
+
* 工具实现经 getState() 取状态。
|
|
15
17
|
*
|
|
16
18
|
* Usage:
|
|
17
19
|
* pi -e ./aft/index.ts
|
|
@@ -20,7 +22,7 @@
|
|
|
20
22
|
import { resolveCortexKitConfigPaths } from "@cortexkit/aft-bridge";
|
|
21
23
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
22
24
|
|
|
23
|
-
import { createAftState, resolveSessionId, shutdownAftPool } from "./bridge.js";
|
|
25
|
+
import { createAftState, findBinary, resolveSessionId, shutdownAftPool } from "./bridge.js";
|
|
24
26
|
import { loadAftConfig } from "./config.js";
|
|
25
27
|
import {
|
|
26
28
|
registerCallgraphTool,
|
|
@@ -37,12 +39,6 @@ export default function aftReadTools(pi: ExtensionAPI): void {
|
|
|
37
39
|
// bridge 状态跟 session 生命周期走,作用域就是本工厂闭包,不落到模块级。
|
|
38
40
|
let state: Awaited<ReturnType<typeof createAftState>> | null = null;
|
|
39
41
|
|
|
40
|
-
// 预热:提前解析二进制并拉起 bridge 子进程;失败直接抛给 pi(runner 捕获
|
|
41
|
-
// 后上报 ExtensionError),工具调用侧经 getState() 抛未初始化错误。
|
|
42
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
43
|
-
state = await createAftState(cwd, resolveSessionId(ctx), cfg.semanticRemote);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
42
|
const getState = (): Awaited<ReturnType<typeof createAftState>> => {
|
|
47
43
|
if (!state) {
|
|
48
44
|
throw new Error(
|
|
@@ -53,22 +49,38 @@ export default function aftReadTools(pi: ExtensionAPI): void {
|
|
|
53
49
|
};
|
|
54
50
|
|
|
55
51
|
const toolCtx = { cwd, getState };
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
|
|
53
|
+
// 工具注册延迟到 session_start:先确认二进制可用再决定注册面。pi 允许在
|
|
54
|
+
// session_start 里 registerTool(工具表按 name 覆盖,跨 session 重复注册幂等)。
|
|
55
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
56
|
+
const binaryPath = await findBinary();
|
|
57
|
+
if (!binaryPath) {
|
|
58
|
+
ctx.ui.notify(
|
|
59
|
+
"AFT binary not found: aft_outline / aft_zoom / aft_callgraph are not registered. " +
|
|
60
|
+
"Install the npm platform package (@cortexkit/aft-<platform>), run `cargo install agent-file-tools`, " +
|
|
61
|
+
"or place `aft` on PATH, then restart pi.",
|
|
62
|
+
"warning",
|
|
63
|
+
);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
registerOutlineTool(pi, toolCtx);
|
|
68
|
+
registerZoomTool(pi, toolCtx);
|
|
69
|
+
registerCallgraphTool(pi, toolCtx);
|
|
70
|
+
if (cfg.semanticSearch) {
|
|
71
|
+
if (cfg.semanticRemote) {
|
|
72
|
+
registerSearchTool(pi, toolCtx);
|
|
73
|
+
} else {
|
|
74
|
+
// 只开了开关、没配外部 embedding 后端:与其静默不注册,不如说明缺什么。
|
|
65
75
|
ctx.ui.notify(
|
|
66
76
|
"aft_search is not registered: semantic_search needs an external embedding backend (aft.jsonc semantic.backend = openai_compatible | ollama, plus base_url). The local ONNX fastembed default is not used here.",
|
|
67
77
|
"warning",
|
|
68
78
|
);
|
|
69
|
-
}
|
|
79
|
+
}
|
|
70
80
|
}
|
|
71
|
-
|
|
81
|
+
|
|
82
|
+
state = await createAftState(cwd, resolveSessionId(ctx), binaryPath, cfg.semanticRemote);
|
|
83
|
+
});
|
|
72
84
|
|
|
73
85
|
// 释放当前 session 的 bridge 状态。session_shutdown 是 pi 的正常生命周期;
|
|
74
86
|
// beforeExit 兜底进程自然退出(不能注册 SIGINT/SIGTERM——那会吞掉 pi 主进程
|
package/src/gh-readonly.ts
CHANGED
|
@@ -1134,86 +1134,30 @@ const PR_CHECKS_JSON_FIELDS = "name,state,bucket,startedAt,completedAt,link,work
|
|
|
1134
1134
|
const CHECKS_POLL_INTERVAL_MS = 30_000;
|
|
1135
1135
|
const CHECKS_WATCH_DEADLINE_MS = 600_000;
|
|
1136
1136
|
|
|
1137
|
-
function bucketIcon(bucket: string): string {
|
|
1138
|
-
switch (bucket) {
|
|
1139
|
-
case "pass": {
|
|
1140
|
-
return "✅";
|
|
1141
|
-
}
|
|
1142
|
-
case "fail": {
|
|
1143
|
-
return "❌";
|
|
1144
|
-
}
|
|
1145
|
-
case "skipping": {
|
|
1146
|
-
return "⏭️";
|
|
1147
|
-
}
|
|
1148
|
-
case "cancel": {
|
|
1149
|
-
return "🚫";
|
|
1150
|
-
}
|
|
1151
|
-
default: {
|
|
1152
|
-
return "🔄";
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
function formatClock(ms: number): string {
|
|
1158
|
-
const date = new Date(ms);
|
|
1159
|
-
return [date.getHours(), date.getMinutes(), date.getSeconds()]
|
|
1160
|
-
.map((n) => String(n).padStart(2, "0"))
|
|
1161
|
-
.join(":");
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
function pad2(n: number): string {
|
|
1165
|
-
return String(n).padStart(2, "0");
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
function formatDuration(totalSeconds: number): string {
|
|
1169
|
-
const seconds = Math.floor(totalSeconds);
|
|
1170
|
-
const h = Math.floor(seconds / 3600);
|
|
1171
|
-
const m = Math.floor((seconds % 3600) / 60);
|
|
1172
|
-
const s = seconds % 60;
|
|
1173
|
-
if (h > 0) return `${h}h${pad2(m)}m${pad2(s)}s`;
|
|
1174
|
-
if (m > 0) return `${m}m${pad2(s)}s`;
|
|
1175
|
-
return `${s}s`;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
1137
|
/**
|
|
1179
|
-
* Render one polling round of `gh pr checks`
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1138
|
+
* Render one polling round of `gh pr checks` as a compact bullet list of the
|
|
1139
|
+
* checks still in flight: running ones first (`- [>]`), queued ones after
|
|
1140
|
+
* (`- [ ]`). Completed checks are hidden — the header already reports the
|
|
1141
|
+
* completion count. Pure — no network.
|
|
1182
1142
|
*/
|
|
1183
|
-
export function
|
|
1143
|
+
export function renderPrChecksList(options: {
|
|
1184
1144
|
prNumber: number | string;
|
|
1185
1145
|
round: number;
|
|
1186
1146
|
checks: readonly PrCheck[];
|
|
1187
|
-
now: number;
|
|
1188
1147
|
}): string {
|
|
1189
|
-
const { prNumber, round, checks
|
|
1148
|
+
const { prNumber, round, checks } = options;
|
|
1190
1149
|
const completed = checks.filter((c) => c.bucket !== "pending").length;
|
|
1191
1150
|
|
|
1192
|
-
const
|
|
1151
|
+
const pending = checks.filter((c) => c.bucket === "pending");
|
|
1152
|
+
const ordered = [...pending.filter((c) => c.startedAt), ...pending.filter((c) => !c.startedAt)];
|
|
1153
|
+
const lines = ordered.map((check) => {
|
|
1193
1154
|
const name = check.link ? `[${check.name}](${check.link})` : check.name;
|
|
1194
|
-
|
|
1195
|
-
if (check.startedAt) {
|
|
1196
|
-
const startMs = Date.parse(check.startedAt);
|
|
1197
|
-
const endMs = check.completedAt ? Date.parse(check.completedAt) : now;
|
|
1198
|
-
elapsed = formatDuration(Math.max(0, (endMs - startMs) / 1000));
|
|
1199
|
-
}
|
|
1200
|
-
const cells = [
|
|
1201
|
-
`${bucketIcon(check.bucket)} ${name}`,
|
|
1202
|
-
check.workflow ?? "—",
|
|
1203
|
-
check.bucket,
|
|
1204
|
-
check.startedAt ? formatClock(Date.parse(check.startedAt)) : "—",
|
|
1205
|
-
elapsed,
|
|
1206
|
-
];
|
|
1207
|
-
return `| ${cells.join(" | ")} |`;
|
|
1155
|
+
return `- [${check.startedAt ? ">" : " "}] ${name}`;
|
|
1208
1156
|
});
|
|
1209
|
-
const body =
|
|
1157
|
+
const body =
|
|
1158
|
+
checks.length === 0 ? "- _no checks reported_" : lines.length > 0 ? lines.join("\n") : "";
|
|
1210
1159
|
|
|
1211
|
-
return
|
|
1212
|
-
`### PR #${prNumber} checks — round ${round}: ${completed}/${checks.length} complete\n\n` +
|
|
1213
|
-
`| Check | Workflow | Status | Started | Elapsed |\n` +
|
|
1214
|
-
`|---|---|---|---|---|\n` +
|
|
1215
|
-
body
|
|
1216
|
-
);
|
|
1160
|
+
return `### PR #${prNumber} checks — round ${round}: ${completed}/${checks.length} complete${body ? `\n\n${body}` : ""}`;
|
|
1217
1161
|
}
|
|
1218
1162
|
|
|
1219
1163
|
function sleepInterruptibly(ms: number, signal: AbortSignal | undefined): Promise<void> {
|
|
@@ -1248,8 +1192,9 @@ export interface PollPrChecksOptions {
|
|
|
1248
1192
|
|
|
1249
1193
|
/**
|
|
1250
1194
|
* Poll `gh pr checks --json` until no check is pending (or a fail-fast
|
|
1251
|
-
* failure, or the deadline), emitting a
|
|
1252
|
-
* each round. In JSON mode gh exits 0 whenever it could fetch the
|
|
1195
|
+
* failure, or the deadline), emitting a compact list of in-flight checks via
|
|
1196
|
+
* `onUpdate` each round. In JSON mode gh exits 0 whenever it could fetch the
|
|
1197
|
+
* checks —
|
|
1253
1198
|
* completion is judged from the `bucket` field, not the exit code. A non-zero
|
|
1254
1199
|
* exit (no checks reported, auth, network) is not fatal here: the caller
|
|
1255
1200
|
* proceeds to the Actions API verification, which either produces the final
|
|
@@ -1282,9 +1227,7 @@ export async function pollPrChecks(options: PollPrChecksOptions): Promise<void>
|
|
|
1282
1227
|
const checks: PrCheck[] = Value.Parse(Type.Array(prCheckSchema), JSON.parse(result.stdout));
|
|
1283
1228
|
|
|
1284
1229
|
onUpdate?.({
|
|
1285
|
-
content: [
|
|
1286
|
-
{ type: "text", text: renderPrChecksTable({ prNumber, round, checks, now: Date.now() }) },
|
|
1287
|
-
],
|
|
1230
|
+
content: [{ type: "text", text: renderPrChecksList({ prNumber, round, checks }) }],
|
|
1288
1231
|
details: {},
|
|
1289
1232
|
});
|
|
1290
1233
|
|
|
@@ -1852,7 +1795,7 @@ export default function ghReadonlyTools(pi: ExtensionAPI) {
|
|
|
1852
1795
|
label: "Watch GitHub PR Checks",
|
|
1853
1796
|
description:
|
|
1854
1797
|
"Watch CI status checks for a PR until they complete. Blocks until all checks finish or one fails. " +
|
|
1855
|
-
"Each polling round streams a
|
|
1798
|
+
"Each polling round streams a compact bullet list of the checks still in flight via onUpdate. " +
|
|
1856
1799
|
"Use this when you need to wait for CI to complete and see the final result.",
|
|
1857
1800
|
promptSnippet: "Watch and wait for GitHub PR CI checks to complete",
|
|
1858
1801
|
parameters: Type.Object({
|