@aiti-ai/ext-shared 0.0.0-stage → 0.1.8
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/LICENSE +21 -0
- package/agent-accounts.test.mjs +227 -0
- package/agent-accounts.ts +324 -0
- package/agent-capability-contract.test.mjs +129 -0
- package/agent-interaction.test.mjs +194 -0
- package/agent-interaction.ts +340 -0
- package/agent-launch.test.mjs +262 -0
- package/agent-spawn-env.test.mjs +169 -0
- package/agent-spawn-env.ts +548 -0
- package/aiti-editor-inject.mjs +49 -0
- package/backend-queue.test.mjs +336 -0
- package/backend-queue.ts +469 -0
- package/blob-save-route.ts +128 -0
- package/cbc-model-catalog.ts +86 -0
- package/check-client.mjs +273 -0
- package/check-ext-globals.mjs +144 -0
- package/controlled-login-dialog.mjs +270 -0
- package/controlled-login.mjs +398 -0
- package/controlled-login.test.mjs +466 -0
- package/convert-saveas.test.mjs +39 -0
- package/convert-saveas.ts +170 -0
- package/copy-client-bundle.mjs +39 -0
- package/cursor-cli-store.ts +377 -0
- package/dedupe-fetch.test.mjs +71 -0
- package/dedupe-fetch.ts +58 -0
- package/deploy-commit.mjs +52 -0
- package/dev-pack.mjs +246 -0
- package/dock-icons.ts +127 -0
- package/esbuild-bin.test.mjs +53 -0
- package/esbuild-bin.ts +66 -0
- package/exec-async.test.mjs +86 -0
- package/exec-async.ts +179 -0
- package/ext-display-names.ts +91 -0
- package/ext-entry-contracts.test.mjs +131 -0
- package/ext-float-dock-core.test.mjs +348 -0
- package/ext-float-dock-core.ts +783 -0
- package/ext-float-dock-lite.ts +52 -0
- package/ext-float-dock.test.mjs +286 -0
- package/ext-float-dock.ts +740 -0
- package/ext-icons-deploy.mjs +24 -0
- package/ext-lazy.test.mjs +186 -0
- package/ext-lazy.tsx +183 -0
- package/ext-model-state.test.mjs +272 -0
- package/ext-model-state.ts +324 -0
- package/ext-protocol.mjs +113 -0
- package/ext-protocol.test.mjs +88 -0
- package/ext-session-usage.test.mjs +219 -0
- package/ext-session-usage.ts +507 -0
- package/external-cli-governance.ts +153 -0
- package/git-ops-client/api.mjs +56 -0
- package/git-ops-client/branch-panel.tsx +987 -0
- package/git-ops-client/i18n.mjs +328 -0
- package/host-tools-allow.test.mjs +46 -0
- package/host-tools-allow.ts +84 -0
- package/icons/alert.svg +1 -0
- package/icons/bookmark.svg +1 -0
- package/icons/bot.svg +1 -0
- package/icons/chart-column.svg +1 -0
- package/icons/check-circle.svg +1 -0
- package/icons/clipboard-list.svg +1 -0
- package/icons/clock.svg +1 -0
- package/icons/coffee.svg +1 -0
- package/icons/edit.svg +1 -0
- package/icons/eye.svg +1 -0
- package/icons/git-branch.svg +1 -0
- package/icons/git-commit-horizontal.svg +1 -0
- package/icons/globe.svg +1 -0
- package/icons/history.svg +1 -0
- package/icons/import.svg +1 -0
- package/icons/inbox.svg +1 -0
- package/icons/key-round.svg +1 -0
- package/icons/layout-grid.svg +1 -0
- package/icons/mail.svg +1 -0
- package/icons/message-circle.svg +1 -0
- package/icons/message-square.svg +1 -0
- package/icons/meter-vertical.svg +1 -0
- package/icons/mic.svg +1 -0
- package/icons/monitor.svg +1 -0
- package/icons/pen-line.svg +1 -0
- package/icons/plug.svg +1 -0
- package/icons/radio-dot.svg +1 -0
- package/icons/radio.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/rocket.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/shield.svg +1 -0
- package/icons/sparkles.svg +1 -0
- package/icons/square-kanban.svg +1 -0
- package/icons/terminal.svg +1 -0
- package/icons/users.svg +1 -0
- package/icons/volume-2.svg +1 -0
- package/icons/wand.svg +1 -0
- package/icons/wrench.svg +1 -0
- package/icons/x-circle.svg +1 -0
- package/icons/x.svg +1 -0
- package/ignore-semantics.ts +76 -0
- package/lazy-loading-metrics.mjs +61 -0
- package/new-session-cwd.test.mjs +389 -0
- package/new-session-cwd.ts +253 -0
- package/open-viewer-window.ts +65 -0
- package/overlay-back-client.test.mjs +123 -0
- package/overlay-back-client.ts +87 -0
- package/package.json +65 -4
- package/pi-fork-rpc/README.md +12 -0
- package/pi-fork-rpc/cli-resolve.test.mjs +42 -0
- package/pi-fork-rpc/cli-resolve.ts +79 -0
- package/pi-fork-rpc/remote-queue.test.mjs +100 -0
- package/pi-fork-rpc/remote-queue.ts +140 -0
- package/pi-fork-rpc/spec.ts +106 -0
- package/pi-fork-rpc/wire.test.mjs +260 -0
- package/pi-fork-rpc/wire.ts +367 -0
- package/popup-anchor.ts +45 -0
- package/provider-priority-contract.test.mjs +55 -0
- package/reconcile-deps.mjs +41 -0
- package/reload-instances.mjs +60 -0
- package/seed-tool.test.mjs +95 -0
- package/seed-tool.ts +88 -0
- package/session-recycle.ts +109 -0
- package/shared-copy-sync.test.mjs +115 -0
- package/soffice-locate.ts +171 -0
- package/soffice-panel.ts +239 -0
- package/sync-dir.mjs +91 -0
- package/sync-dir.test.mjs +101 -0
- package/sync-gate.test.mjs +93 -0
- package/sync-mirror.test.mjs +85 -0
- package/task-list.test.mjs +91 -0
- package/task-list.ts +118 -0
- package/test-rm-rf.mjs +33 -0
- package/ui-dialogs.test.mjs +198 -0
- package/ui-dialogs.ts +310 -0
- package/README.md +0 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { execFileAsync, queueRepo } from "./exec-async.ts";
|
|
4
|
+
|
|
5
|
+
test("execFileAsync resolves stdout", async () => {
|
|
6
|
+
const out = await execFileAsync("echo", ["hello"]);
|
|
7
|
+
assert.equal(out, "hello\n");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("execFileAsync error carries stdout/stderr/status (execFileSync 形态)", async () => {
|
|
11
|
+
try {
|
|
12
|
+
await execFileAsync("sh", ["-c", "echo out; echo err >&2; exit 3"]);
|
|
13
|
+
assert.fail("should throw");
|
|
14
|
+
} catch (e) {
|
|
15
|
+
assert.equal(e.status, 3);
|
|
16
|
+
assert.equal(e.stdout, "out\n");
|
|
17
|
+
assert.equal(e.stderr, "err");
|
|
18
|
+
assert.match(e.message, /exit status 3/);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("execFileAsync timeout kills and reports timed out", async () => {
|
|
23
|
+
try {
|
|
24
|
+
await execFileAsync("sleep", ["5"], { timeoutMs: 200 });
|
|
25
|
+
assert.fail("should throw");
|
|
26
|
+
} catch (e) {
|
|
27
|
+
assert.ok(e.killed === true);
|
|
28
|
+
assert.match(e.message, /timed out/);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("execFileAsync input writes to stdin", async () => {
|
|
33
|
+
const out = await execFileAsync("cat", [], { input: "from-stdin" });
|
|
34
|
+
assert.equal(out, "from-stdin");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("execFileAsync maxBuffer overflow fails with exceed message", async () => {
|
|
38
|
+
try {
|
|
39
|
+
await execFileAsync("sh", ["-c", "yes x | head -c 1000000"], { maxBuffer: 1024 });
|
|
40
|
+
assert.fail("should throw");
|
|
41
|
+
} catch (e) {
|
|
42
|
+
assert.match(e.message, /maxBuffer/);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("execFileAsync missing binary rejects with error message", async () => {
|
|
47
|
+
await assert.rejects(() => execFileAsync("definitely-not-exist-bin-xyz", ["a"]), /definitely-not-exist-bin-xyz/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("queueRepo serializes same-key tasks in order", async () => {
|
|
51
|
+
const order = [];
|
|
52
|
+
const mk = (id, delay) => async () => {
|
|
53
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
54
|
+
order.push(id);
|
|
55
|
+
return id;
|
|
56
|
+
};
|
|
57
|
+
const results = await Promise.all([
|
|
58
|
+
queueRepo("k1", mk("a", 30)),
|
|
59
|
+
queueRepo("k1", mk("b", 5)),
|
|
60
|
+
queueRepo("k1", mk("c", 10)),
|
|
61
|
+
]);
|
|
62
|
+
assert.deepEqual(order, ["a", "b", "c"]);
|
|
63
|
+
assert.deepEqual(results, ["a", "b", "c"]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("queueRepo different keys run concurrently", async () => {
|
|
67
|
+
let inside = 0;
|
|
68
|
+
let overlap = false;
|
|
69
|
+
const fn = async () => {
|
|
70
|
+
inside++;
|
|
71
|
+
if (inside > 1) overlap = true;
|
|
72
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
73
|
+
inside--;
|
|
74
|
+
};
|
|
75
|
+
await Promise.all([
|
|
76
|
+
queueRepo("ka", fn),
|
|
77
|
+
queueRepo("kb", fn),
|
|
78
|
+
]);
|
|
79
|
+
assert.equal(overlap, true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("queueRepo failure does not block subsequent tasks", async () => {
|
|
83
|
+
await assert.rejects(() => queueRepo("k2", async () => { throw new Error("boom"); }), /boom/);
|
|
84
|
+
const out = await queueRepo("k2", async () => "ok");
|
|
85
|
+
assert.equal(out, "ok");
|
|
86
|
+
});
|
package/exec-async.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 共享异步子进程工具(execFileSync → execFile 全仓改造的权威实现)。
|
|
3
|
+
*
|
|
4
|
+
* ⚠ 性能红线(2026-09-12 改造):常驻进程(pi-web 服务端 / pi 扩展)内
|
|
5
|
+
* 禁止 execFileSync/spawnSync/execSync——git/ps/soffice 等子进程跑多久,
|
|
6
|
+
* 整个 HTTP 服务就阻塞多久。凡新代码需要跑子进程,一律 import 本文件。
|
|
7
|
+
* 构建/部署/一次性 CLI 脚本不受此红线约束。
|
|
8
|
+
*
|
|
9
|
+
* 错误形态对齐 execFileSync:失败时抛出的 Error 附着 stdout/stderr/status,
|
|
10
|
+
* 调用侧原有的 `catch (e) { e.stderr }` 读取逻辑不需要改。
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
14
|
+
import { StringDecoder } from "node:string_decoder";
|
|
15
|
+
import { join as pathJoin } from "node:path";
|
|
16
|
+
|
|
17
|
+
export interface ExecAsyncOpts {
|
|
18
|
+
cwd?: string;
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
/** 超时后 kill 子进程(默认 120s;超时错误 code=ETIMEOUT? 见 ETIMEOUT 处理) */
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
maxBuffer?: number;
|
|
23
|
+
/** stdin 写入(如 sqlcipher 解密):传字符串则写完自动 end */
|
|
24
|
+
input?: string;
|
|
25
|
+
/** shell 直通(仅在参数无法数组化时使用,默认 false) */
|
|
26
|
+
shell?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** execFileSync 兼容错误形态:调用侧 catch (e) { e.stderr/e.stdout/e.status } 原样可用 */
|
|
30
|
+
export type ExecAsyncError = Error & {
|
|
31
|
+
stdout: string;
|
|
32
|
+
stderr: string;
|
|
33
|
+
status: number | null;
|
|
34
|
+
signal: NodeJS.Signals | null;
|
|
35
|
+
killed?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const DEFAULT_MAX_BUFFER = 64 * 1024 * 1024;
|
|
39
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Promise 版 execFile:返回 stdout;失败时抛出带 stdout/stderr/status 的错误。
|
|
43
|
+
* 基于 spawn 实现(execFile 不支持 stdin input)。
|
|
44
|
+
*/
|
|
45
|
+
export function execFileAsync(bin: string, args: string[], opts: ExecAsyncOpts = {}): Promise<string> {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const child = spawn(bin, args, {
|
|
48
|
+
...(opts.cwd ? { cwd: opts.cwd } : {}),
|
|
49
|
+
...(opts.env ? { env: opts.env } : {}),
|
|
50
|
+
...(opts.shell ? { shell: true } : {}),
|
|
51
|
+
stdio: [opts.input != null ? "pipe" : "ignore", "pipe", "pipe"],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
let stdout = "";
|
|
55
|
+
let stderr = "";
|
|
56
|
+
let killed = false;
|
|
57
|
+
const maxBuffer = opts.maxBuffer ?? DEFAULT_MAX_BUFFER;
|
|
58
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
59
|
+
|
|
60
|
+
let stdoutLen = 0;
|
|
61
|
+
let stderrLen = 0;
|
|
62
|
+
let overflowed = false;
|
|
63
|
+
|
|
64
|
+
const timer = setTimeout(() => {
|
|
65
|
+
killed = true;
|
|
66
|
+
child.kill("SIGTERM");
|
|
67
|
+
// 宽限 5s 后升级 SIGKILL(子进程忽略 SIGTERM 时)
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
if (!child.killed || child.exitCode === null) {
|
|
70
|
+
try { child.kill("SIGKILL"); } catch { /* 已退出 */ }
|
|
71
|
+
}
|
|
72
|
+
}, 5_000).unref?.();
|
|
73
|
+
}, timeoutMs);
|
|
74
|
+
timer.unref?.();
|
|
75
|
+
|
|
76
|
+
if (opts.input != null && child.stdin) {
|
|
77
|
+
child.stdin.on("error", () => { /* EPIPE:子进程提前退出属正常 */ });
|
|
78
|
+
child.stdin.end(opts.input);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// StringDecoder 跨 chunk 安全解码(加固 A1):逐 chunk toString 会把跨 chunk
|
|
82
|
+
// 的多字节字符(中文)解码成 U+FFFD,损坏输出文本
|
|
83
|
+
const stdoutDec = new StringDecoder("utf8");
|
|
84
|
+
const stderrDec = new StringDecoder("utf8");
|
|
85
|
+
child.stdout?.on("data", (chunk: Buffer) => {
|
|
86
|
+
stdoutLen += chunk.length;
|
|
87
|
+
if (stdoutLen > maxBuffer) {
|
|
88
|
+
overflowed = true;
|
|
89
|
+
killed = true;
|
|
90
|
+
try { child.kill("SIGTERM"); } catch { /* 已退出 */ }
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
stdout += stdoutDec.write(chunk);
|
|
94
|
+
});
|
|
95
|
+
child.stderr?.on("data", (chunk: Buffer) => {
|
|
96
|
+
stderrLen += chunk.length;
|
|
97
|
+
if (stderrLen > maxBuffer) {
|
|
98
|
+
overflowed = true;
|
|
99
|
+
killed = true;
|
|
100
|
+
try { child.kill("SIGTERM"); } catch { /* 已退出 */ }
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
stderr += stderrDec.write(chunk);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const fail = (code: number | null, signal: NodeJS.Signals | null, message: string) => {
|
|
107
|
+
const e = new Error(`Command failed: ${bin} ${args.join(" ")}: ${message}\n${stderr.trim()}`) as ExecAsyncError;
|
|
108
|
+
e.stdout = stdout;
|
|
109
|
+
e.stderr = stderr.trim();
|
|
110
|
+
e.status = code;
|
|
111
|
+
e.signal = signal;
|
|
112
|
+
e.killed = killed;
|
|
113
|
+
reject(e);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
child.on("error", (err) => fail(null, null, err.message));
|
|
117
|
+
|
|
118
|
+
child.on("close", (code, signal) => {
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
if (overflowed) {
|
|
121
|
+
fail(code, signal, `output exceeded maxBuffer (${maxBuffer} bytes)`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (killed && code === null && signal === "SIGTERM") {
|
|
125
|
+
fail(code, signal, "timed out");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (code === 0 && signal === null) {
|
|
129
|
+
resolve(stdout);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
fail(code, signal, signal ? `killed by signal ${signal}` : `exit status ${code}`);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* per-key 串行队列:同一资源(如同一 gitDir)的「读-改-写」序列原子化。
|
|
139
|
+
*
|
|
140
|
+
* 异步化后同仓提交序列(rev-parse → add → write-tree → commit-tree →
|
|
141
|
+
* update-ref)可能被并发事件交错;队列保证同 key 序列一个接一个跑。
|
|
142
|
+
* 失败消化:单次失败不阻断后续(链条吞掉 rejection)。
|
|
143
|
+
*/
|
|
144
|
+
const queues = new Map<string, Promise<unknown>>();
|
|
145
|
+
|
|
146
|
+
export function queueRepo<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
147
|
+
const prev = queues.get(key) ?? Promise.resolve();
|
|
148
|
+
const run = prev.then(fn, fn);
|
|
149
|
+
queues.set(key, run.catch(() => {}));
|
|
150
|
+
return run;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 同步 PATH 探测(纯 fs,零 spawn):命中返回绝对路径,未命中返回 null。
|
|
155
|
+
* 语义同 `which <bin>`,但只读文件系统(毫秒级)——探针类调用严禁 execFileSync("which")。
|
|
156
|
+
* 候选必须 isFile(目录 X_OK 恒真,qoder 同名目录误报教训)。
|
|
157
|
+
*/
|
|
158
|
+
export function whichBin(bin: string): string | null {
|
|
159
|
+
const isExecFile = (p: string): boolean => {
|
|
160
|
+
try {
|
|
161
|
+
if (!statSync(p).isFile()) return false;
|
|
162
|
+
} catch { return false; }
|
|
163
|
+
try { accessSync(p, constants.X_OK); return true; } catch { return false; }
|
|
164
|
+
};
|
|
165
|
+
if (bin.includes("/") || bin.includes("\\")) {
|
|
166
|
+
return isExecFile(bin) ? bin : null;
|
|
167
|
+
}
|
|
168
|
+
const dirs = (process.env.PATH || "").split(process.platform === "win32" ? ";" : ":").filter(Boolean);
|
|
169
|
+
const exts = process.platform === "win32"
|
|
170
|
+
? ["", ".exe", ".cmd", ".bat", ...(process.env.PATHEXT || "").split(";").filter(Boolean).map((e) => e.toLowerCase())]
|
|
171
|
+
: [""];
|
|
172
|
+
for (const dir of dirs) {
|
|
173
|
+
for (const ext of exts) {
|
|
174
|
+
const p = pathJoin(dir, bin + ext);
|
|
175
|
+
if (isExecFile(p)) return p;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 扩展展示名(id → 双语友好名)——唯一权威来源。
|
|
3
|
+
*
|
|
4
|
+
* 用途:扩展技术 id(如 aiti-cmd / aiti-git-review)对用户不友好,各扩展 client
|
|
5
|
+
* (aiti-extman / aiti-helper …)展示扩展分组/列表时用它显示中文/英文友好名,
|
|
6
|
+
* 表内缺失的扩展回退到 server name / id。
|
|
7
|
+
*
|
|
8
|
+
* 约定:新增扩展时在此补一行(en + zh)。此表只放「展示名」,不做逻辑。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const EXT_DISPLAY_NAMES: Record<string, { en: string; zh: string }> = {
|
|
12
|
+
"aiti-acp-agent": { en: "ACP Session Backend", zh: "ACP 会话后端" },
|
|
13
|
+
"aiti-ai-input": { en: "AI Input Enhancer", zh: "AI 输入增强" },
|
|
14
|
+
"aiti-ai-schedule": { en: "AI Schedule", zh: "AI 定时任务" },
|
|
15
|
+
"aiti-ai-speek": { en: "AI Voice Reading", zh: "AI 语音朗读" },
|
|
16
|
+
"aiti-ai-usage": { en: "AI Usage", zh: "AI 用量统计" },
|
|
17
|
+
"aiti-append-system": { en: "Append System Prompt", zh: "追加系统提示词" },
|
|
18
|
+
"aiti-attach-agent": { en: "Attach Session Backend", zh: "附着会话后端" },
|
|
19
|
+
"aiti-channels": { en: "IM Channels", zh: "IM 渠道" },
|
|
20
|
+
"aiti-claude-code-agent": { en: "Claude Code Session Backend", zh: "Claude Code 会话后端" },
|
|
21
|
+
"aiti-cmd": { en: "Command Palette", zh: "命令面板" },
|
|
22
|
+
"aiti-codex-agent": { en: "Codex Session Backend", zh: "Codex 会话后端" },
|
|
23
|
+
"aiti-configs": { en: "Config Versioning & Self-check", zh: "配置版本化 + 崩溃自检" },
|
|
24
|
+
"aiti-cpu-meter": { en: "CPU Meter", zh: "CPU 流畅度仪表" },
|
|
25
|
+
"aiti-crash-fatal": { en: "Crash Drill (dev)", zh: "崩溃演习(开发)" },
|
|
26
|
+
"aiti-cursor-agent": { en: "Cursor Session Backend", zh: "Cursor 会话后端" },
|
|
27
|
+
"aiti-debug-inject": { en: "Remote Debug Inject", zh: "远程调试注入" },
|
|
28
|
+
"aiti-devtools": { en: "Page DevTools", zh: "页面 AI 调试工具" },
|
|
29
|
+
"aiti-devtools-vite": { en: "DevTools Vite Plugin", zh: "DevTools Vite 插件" },
|
|
30
|
+
"aiti-devtools-vue": { en: "DevTools Vue Plugin", zh: "DevTools Vue 插件" },
|
|
31
|
+
"aiti-doc-center": { en: "Doc Center", zh: "文档中心" },
|
|
32
|
+
"aiti-draft-keeper": { en: "Draft Keeper", zh: "草稿保管员" },
|
|
33
|
+
"aiti-echo-agent": { en: "Echo Session Backend", zh: "Echo 会话后端" },
|
|
34
|
+
"aiti-editor": { en: "File Editor", zh: "文件编辑器" },
|
|
35
|
+
"aiti-event-bus": { en: "Page Event Bus", zh: "页面事件总线" },
|
|
36
|
+
"aiti-extman": { en: "Extension Manager", zh: "扩展管理器" },
|
|
37
|
+
"aiti-float": { en: "Dialog Float Enhancer", zh: "弹窗浮动增强器" },
|
|
38
|
+
"aiti-folder": { en: "Folder Browser", zh: "文件夹浏览器" },
|
|
39
|
+
"aiti-git-review": { en: "Git Review", zh: "Git 代码审核" },
|
|
40
|
+
"aiti-git-trace": { en: "AI Change Trace", zh: "AI 变更追踪" },
|
|
41
|
+
"aiti-helper": { en: "AI Helper", zh: "AI 助手入口" },
|
|
42
|
+
"aiti-inject": { en: "Debug Inject FAB", zh: "调试注入按钮" },
|
|
43
|
+
"aiti-mcp-bridge": { en: "MCP Bridge", zh: "MCP 桥" },
|
|
44
|
+
"aiti-model-check": { en: "Model Availability", zh: "模型可用性管理" },
|
|
45
|
+
"aiti-model-wizard": { en: "Model Wizard", zh: "模型添加向导" },
|
|
46
|
+
"aiti-msg-anchor": { en: "Message Anchor Banner", zh: "消息锚点横幅" },
|
|
47
|
+
"aiti-msg-nav": { en: "Message Scroll Nav", zh: "消息滚动导航" },
|
|
48
|
+
"aiti-msg-smart": { en: "Message Intelligence", zh: "消息智能" },
|
|
49
|
+
"aiti-onlyoffice": { en: "OnlyOffice Editor", zh: "OnlyOffice 编辑" },
|
|
50
|
+
"aiti-pi-agent": { en: "pi Session Backend", zh: "pi 会话后端" },
|
|
51
|
+
"aiti-plan-first": { en: "Plan-First Reminder", zh: "方案先行" },
|
|
52
|
+
"aiti-plan-review": { en: "Plan Review", zh: "方案评审" },
|
|
53
|
+
"aiti-prompts": { en: "Prompt Snippets", zh: "Prompt 片段收藏库" },
|
|
54
|
+
"aiti-qoder-agent": { en: "Qoder Session Backend", zh: "Qoder 会话后端" },
|
|
55
|
+
"aiti-queue-keeper": { en: "Queue Keeper", zh: "队列管家" },
|
|
56
|
+
"aiti-sheet-univer": { en: "Excel Editor", zh: "Excel 编辑器" },
|
|
57
|
+
"aiti-subagents": { en: "Subagents", zh: "子代理" },
|
|
58
|
+
"aiti-testagent": { en: "TestAgent · Java Debugging", zh: "TestAgent · Java 后端调试" },
|
|
59
|
+
"aiti-ui-env": { en: "UI Environment", zh: "UI 环境(桌面/无头虚拟屏)" },
|
|
60
|
+
"aiti-word-docx-preview": { en: "Word Preview", zh: "Word 预览" },
|
|
61
|
+
"aiti-word-superdoc": { en: "Word Editor", zh: "Word 编辑" },
|
|
62
|
+
"aiti-zcode-agent": { en: "ZCode Session Backend", zh: "ZCode 会话后端" },
|
|
63
|
+
"demo": { en: "Demo Extension", zh: "示例扩展" },
|
|
64
|
+
"demo-lazy": { en: "Demo Extension (Lazy)", zh: "示例扩展(懒加载)" },
|
|
65
|
+
"devtools-vscode": { en: "VS Code Plugin", zh: "VS Code 插件" },
|
|
66
|
+
"devtools-idea": { en: "IDEA Plugin", zh: "IDEA 插件" },
|
|
67
|
+
"ext-jsx-client": { en: "JSX Client Template", zh: "扩展 JSX 客户端模板" },
|
|
68
|
+
"service-tunnels": { en: "Service Tunnels", zh: "服务隧道" },
|
|
69
|
+
"session-manager": { en: "Session Manager", zh: "会话管理器" },
|
|
70
|
+
"sm-demo-source": { en: "Demo Session Source", zh: "第三方会话源示例" },
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const CJK_RE = /[\u3400-\u4dbf\u4e00-\u9fff]/;
|
|
74
|
+
|
|
75
|
+
/** 当前界面语言(localStorage pi-locale,与宿主 useI18n 同源;缺省 en)。 */
|
|
76
|
+
export function currentUiLocale(): "zh-CN" | "en" {
|
|
77
|
+
try {
|
|
78
|
+
const v = window.localStorage.getItem("pi-locale");
|
|
79
|
+
if (v === "zh-CN" || v === "en") return v;
|
|
80
|
+
} catch { /* 存储不可用时用缺省 */ }
|
|
81
|
+
return "en";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 按界面语言解析扩展展示名:zh → 双语表 zh / server name / id;
|
|
85
|
+
* en → 双语表 en / 无 CJK 的 server name / id。 */
|
|
86
|
+
export function extDisplayName(id: string, fallbackName?: string | null): string {
|
|
87
|
+
const entry = EXT_DISPLAY_NAMES[id];
|
|
88
|
+
if (currentUiLocale() === "zh-CN") return (entry && entry.zh) || fallbackName || id;
|
|
89
|
+
if (entry) return entry.en;
|
|
90
|
+
return fallbackName && !CJK_RE.test(fallbackName) ? fallbackName : id;
|
|
91
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ext-entry-contracts.test.mjs —— 全量扩展入口契约巡检(覆盖所有官方扩展)。
|
|
3
|
+
*
|
|
4
|
+
* E2E 实测沉淀的回归闸门(2026-11-06):
|
|
5
|
+
* 1. package.json 必须声明 aitiExtProtocol(协议红线,全仓校验的仓库内等价断言);
|
|
6
|
+
* 2. registerItems/registerItems?. 调用的插槽名必须是宿主 ExtSlotName 联合的合法成员
|
|
7
|
+
* (拼错插槽 = 条目永远不渲染 = 死入口);
|
|
8
|
+
* 3. registerItems 引用的 feature 必须在扩展 features 声明里存在(引用不存在的
|
|
9
|
+
* feature id = 条目被永远隐藏的死卡——aiti-app-center feature-gate 过滤按此口径);
|
|
10
|
+
* 4. index.ts 静态 ui 声明的插槽键同样是合法插槽名;
|
|
11
|
+
* 5. 镜像脚本排除契约:__pycache__/*.pyc 必须在 sync 脚本排除集内
|
|
12
|
+
* (文件系统拷贝绕过 gitignore 的泄露回归,见 sync 脚本 fix c6e38ac0)。
|
|
13
|
+
*
|
|
14
|
+
* Run: node --test pi-web-ext/_shared/ext-entry-contracts.test.mjs
|
|
15
|
+
*/
|
|
16
|
+
import { readdirSync, readFileSync, statSync, existsSync } from "node:fs";
|
|
17
|
+
import { join, dirname } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import test from "node:test";
|
|
20
|
+
import assert from "node:assert/strict";
|
|
21
|
+
|
|
22
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const extRoot = join(here, "..");
|
|
24
|
+
const workRoot = join(extRoot, "..");
|
|
25
|
+
|
|
26
|
+
/** 宿主 ExtSlotName 联合镜像(pi-web lib/ext/types.ts;扩宿主插槽时同步此处)。 */
|
|
27
|
+
const VALID_SLOTS = new Set([
|
|
28
|
+
"toolbar", "sidebar", "sidebarFooter", "sessionTopbar", "sessionRowActions",
|
|
29
|
+
"sessionRowLeading", "sessionRowMeta", "sidebarProjects", "sidebarContent",
|
|
30
|
+
"dialogs", "banners", "pages", "chatInputTop", "chatOverlay",
|
|
31
|
+
"userMessageActions", "assistantMessageActions", "assistantMessageFooter",
|
|
32
|
+
"fileViewer", "pathPicker", "newSessionBackendOptions", "sessionStats",
|
|
33
|
+
"composerTools", "queuePanel", "recoveryDialog", "workspacePickerActions",
|
|
34
|
+
"newSessionContextTrailing", "modelSelector", "modelSelectorFooter",
|
|
35
|
+
"settingsModels", "settingsAgentsFeature", "settingsAgents", "terminalDock",
|
|
36
|
+
"sidebarExplorerDock", "rightFileDock", "sidebarTasks", "composerAffix",
|
|
37
|
+
"modelInfoLead", "compactLead", "sessionRequestCard", "newSessionSelectors",
|
|
38
|
+
"newSessionPreparers", "newSessionWidgets",
|
|
39
|
+
"noWorkspaceGuide", // v3 新增:fresh 首屏整页引导替换槽(AppShell 消费;aiti-quickstart 首用)
|
|
40
|
+
// 跨 bundle 生态槽:宿主 ExtSlotName 类型联合未收录(types 缺口,运行时字符串键注册表不受影响),
|
|
41
|
+
// 消费方 = aiti-model-wizard 的会话信息聚合(getExtUiItems 跨 bundle 读)。见 aiti-provider-usage。
|
|
42
|
+
"sessionInfoPanel",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
function listExts() {
|
|
46
|
+
// 并发套件里 sync-mirror 测试会临时创建/删除夹具扩展目录——ENOENT 视为已消失,跳过
|
|
47
|
+
const dirs = readdirSync(extRoot, { withFileTypes: true })
|
|
48
|
+
.filter((e) => e.isDirectory() && e.name !== "_shared" && e.name !== "node_modules")
|
|
49
|
+
.map((e) => e.name);
|
|
50
|
+
return dirs.filter((n) => {
|
|
51
|
+
try { return existsSync(join(extRoot, n, "package.json")); } catch { return false; }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function* clientFiles(dir) {
|
|
56
|
+
let entries;
|
|
57
|
+
try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
58
|
+
for (const e of entries) {
|
|
59
|
+
const p = join(dir, e.name);
|
|
60
|
+
if (e.isDirectory()) {
|
|
61
|
+
// assets/ + chunk-*.mjs = vite 构建产物(vendor 库内部 feature: 字符串会
|
|
62
|
+
// 造成契约扫描假阳性)——契约检查只看手写源码
|
|
63
|
+
if (e.name === "node_modules" || e.name === "dist" || e.name === "vendor" || e.name === "assets") continue;
|
|
64
|
+
yield* clientFiles(p);
|
|
65
|
+
} else if (/\.(tsx?|js|mjs)$/.test(e.name) && !/\.test\.(mjs|js)$/.test(e.name) && !/\.min\.(js|mjs)$/.test(e.name) && !/-chunk-[A-Za-z0-9_-]+\.mjs$/.test(e.name)) {
|
|
66
|
+
// -chunk-<hash>.mjs = vite 构建产物(vendor 库内部的 feature: 字符串会造成
|
|
67
|
+
// 契约扫描假阳性)——契约检查只看手写源码
|
|
68
|
+
yield p;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
test("每个官方扩展的 package.json 声明 aitiExtProtocol", () => {
|
|
74
|
+
const bad = [];
|
|
75
|
+
for (const name of listExts()) {
|
|
76
|
+
const pkg = JSON.parse(readFileSync(join(extRoot, name, "package.json"), "utf8"));
|
|
77
|
+
if (!/^1\.\d+$/.test(String(pkg.aitiExtProtocol ?? ""))) bad.push(`${name}: ${pkg.aitiExtProtocol ?? "缺失"}`);
|
|
78
|
+
}
|
|
79
|
+
assert.deepEqual(bad, [], "缺少/非法 aitiExtProtocol 的扩展");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("registerItems 插槽名全部合法(拼错 = 死入口)", () => {
|
|
83
|
+
const bad = [];
|
|
84
|
+
for (const name of listExts()) {
|
|
85
|
+
const dir = join(extRoot, name);
|
|
86
|
+
for (const f of clientFiles(dir)) {
|
|
87
|
+
const src = readFileSync(f, "utf8");
|
|
88
|
+
for (const m of src.matchAll(/\bregisterItems\b[\s\S]{0,40}?\(\s*["'`]([a-zA-Z]+)["'`]/g)) {
|
|
89
|
+
if (!VALID_SLOTS.has(m[1])) bad.push(`${name} (${f.split("pi-web-ext/")[1]}): "${m[1]}"`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
assert.deepEqual(bad, [], "引用了不存在插槽的 registerItems 调用");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("registerItems 引用的 feature 必须在 features 声明里存在", () => {
|
|
97
|
+
const bad = [];
|
|
98
|
+
for (const name of listExts()) {
|
|
99
|
+
const dir = join(extRoot, name);
|
|
100
|
+
const indexSrc = existsSync(join(dir, "index.ts")) ? readFileSync(join(dir, "index.ts"), "utf8") : "";
|
|
101
|
+
const declared = new Set([...indexSrc.matchAll(/\{\s*id:\s*["'`]([a-zA-Z0-9._-]+)["'`]/g)].map((m) => m[1]));
|
|
102
|
+
for (const f of clientFiles(dir)) {
|
|
103
|
+
const src = readFileSync(f, "utf8");
|
|
104
|
+
for (const m of src.matchAll(/\bfeature:\s*["'`]([a-zA-Z0-9._-]+)["'`]/g)) {
|
|
105
|
+
if (!declared.has(m[1])) bad.push(`${name}: feature "${m[1]}"(${f.split("pi-web-ext/")[1]})不在 features 声明`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
assert.deepEqual(bad, [], "引用了未声明 feature 的条目");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("index.ts 静态 ui 声明的插槽键全部合法", () => {
|
|
113
|
+
const bad = [];
|
|
114
|
+
for (const name of listExts()) {
|
|
115
|
+
const indexSrc = existsSync(join(extRoot, name, "index.ts")) ? readFileSync(join(extRoot, name, "index.ts"), "utf8") : null;
|
|
116
|
+
if (!indexSrc) continue;
|
|
117
|
+
// ui 块里的非插槽元数据键(宿主 registerDeclaredSlots 会多声明但无消费方;ai-helper 聚合读):
|
|
118
|
+
// i18n/provides/clientDependsOn/clientImmediately 是宿主过滤的白名单,helpers 是 aiti-helper 的聚合元数据
|
|
119
|
+
const UI_META_KEYS = new Set(["i18n", "provides", "clientDependsOn", "clientImmediately", "helpers"]);
|
|
120
|
+
for (const m of indexSrc.matchAll(/^\s{4}([a-zA-Z]+):\s*\[$/gm)) {
|
|
121
|
+
if (!VALID_SLOTS.has(m[1]) && !UI_META_KEYS.has(m[1])) bad.push(`${name}: ui.${m[1]}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
assert.deepEqual(bad, [], "静态 ui 声明使用了未知插槽键");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("镜像脚本排除契约:__pycache__/.pyc 在 sync 排除集内", () => {
|
|
128
|
+
const src = readFileSync(join(workRoot, "scripts", "sync-extensions-to-aiti-ai.mjs"), "utf8");
|
|
129
|
+
assert.match(src, /EXCLUDE_NAMES = new Set\([^\)]*__pycache__/, "EXCLUDE_NAMES 缺 __pycache__");
|
|
130
|
+
assert.match(src, /EXCLUDE_SUFFIX = \[[^\]]*"\.pyc"/, "EXCLUDE_SUFFIX 缺 .pyc");
|
|
131
|
+
});
|