@liang-hz/agent-in-chrome 0.55.0
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/.ext-id.txt +4 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/PRIVACY.md +86 -0
- package/README.en.md +419 -0
- package/README.md +406 -0
- package/bin/agent-in-chrome.mjs +97 -0
- package/commands/agent-in-chrome.md +18 -0
- package/commands/install-agent-in-chrome.md +22 -0
- package/docs/AGENTS.md +94 -0
- package/docs/CLI.md +297 -0
- package/docs/client-compat.json +23 -0
- package/extension/about-toc.js +25 -0
- package/extension/about.html +240 -0
- package/extension/about.js +44 -0
- package/extension/agent-window.html +100 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-24.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/icons/icon-64.png +0 -0
- package/extension/icons/icon-attention-128.png +0 -0
- package/extension/icons/icon-attention-16.png +0 -0
- package/extension/icons/icon-attention-24.png +0 -0
- package/extension/icons/icon-attention-32.png +0 -0
- package/extension/icons/icon-attention-48.png +0 -0
- package/extension/icons/icon-attention-64.png +0 -0
- package/extension/icons/icon-attention.svg +18 -0
- package/extension/icons/icon-failed-128.png +0 -0
- package/extension/icons/icon-failed-16.png +0 -0
- package/extension/icons/icon-failed-24.png +0 -0
- package/extension/icons/icon-failed-32.png +0 -0
- package/extension/icons/icon-failed-48.png +0 -0
- package/extension/icons/icon-failed-64.png +0 -0
- package/extension/icons/icon-failed.svg +18 -0
- package/extension/icons/icon-idle-128.png +0 -0
- package/extension/icons/icon-idle-16.png +0 -0
- package/extension/icons/icon-idle-24.png +0 -0
- package/extension/icons/icon-idle-32.png +0 -0
- package/extension/icons/icon-idle-48.png +0 -0
- package/extension/icons/icon-idle-64.png +0 -0
- package/extension/icons/icon-idle.svg +18 -0
- package/extension/icons/icon-mark.svg +10 -0
- package/extension/icons/icon-running-128.png +0 -0
- package/extension/icons/icon-running-16.png +0 -0
- package/extension/icons/icon-running-24.png +0 -0
- package/extension/icons/icon-running-32.png +0 -0
- package/extension/icons/icon-running-48.png +0 -0
- package/extension/icons/icon-running-64.png +0 -0
- package/extension/icons/icon-running.svg +18 -0
- package/extension/icons/icon.svg +18 -0
- package/extension/manifest.json +44 -0
- package/extension/popup-ui.js +38 -0
- package/extension/popup.html +350 -0
- package/extension/popup.js +741 -0
- package/extension/sw.js +11127 -0
- package/extension/update-check.js +66 -0
- package/extension/welcome.html +110 -0
- package/extension/welcome.js +18 -0
- package/mcp/agent-identity.mjs +1007 -0
- package/mcp/cdp/bridge.mjs +239 -0
- package/mcp/cdp/browser-launch.mjs +1127 -0
- package/mcp/cdp/chrome-shim.mjs +1124 -0
- package/mcp/cdp/client.mjs +443 -0
- package/mcp/cli-invocation.mjs +67 -0
- package/mcp/config.mjs +191 -0
- package/mcp/foreground-guard.mjs +295 -0
- package/mcp/proc-win.mjs +112 -0
- package/mcp/secret-shape.mjs +155 -0
- package/mcp/server.mjs +3437 -0
- package/mcp/session-id.mjs +281 -0
- package/mcp/token.mjs +260 -0
- package/mcp/tool-tiers.mjs +84 -0
- package/mcp/trace.mjs +528 -0
- package/mcp/update-cli.mjs +163 -0
- package/mcp/update-notice.mjs +194 -0
- package/native-host/host.mjs +356 -0
- package/native-host/mac-foreground/aic-fg.swift +114 -0
- package/native-host/mac-foreground/build.mjs +43 -0
- package/package.json +46 -0
- package/scripts/agents.mjs +921 -0
- package/scripts/borrow-login.mjs +935 -0
- package/scripts/cli-browser.mjs +148 -0
- package/scripts/e2e-sweep.mjs +192 -0
- package/scripts/e2e.mjs +3911 -0
- package/scripts/fixture-server.mjs +1419 -0
- package/scripts/guard-publish.mjs +175 -0
- package/scripts/install.mjs +1383 -0
- package/scripts/launcher-provenance.mjs +74 -0
- package/scripts/pack-crx.mjs +82 -0
- package/scripts/pick.mjs +114 -0
- package/scripts/test-agents.mjs +968 -0
- package/scripts/test-borrow.mjs +289 -0
- package/scripts/test-config.mjs +618 -0
- package/scripts/test-e2e-sweep.mjs +251 -0
- package/scripts/test-foreground-guard.mjs +383 -0
- package/scripts/test-identity.mjs +1141 -0
- package/scripts/test-install-skill.mjs +378 -0
- package/scripts/test-protocol.mjs +712 -0
- package/scripts/test-security.mjs +1360 -0
- package/scripts/test-sw.mjs +14526 -0
- package/scripts/test-update.mjs +301 -0
- package/skills/agent-in-chrome/SKILL.md +60 -0
- package/skills/agent-in-chrome/references/actions-and-waits.md +136 -0
- package/skills/agent-in-chrome/references/amap-dir-dropdown.md +66 -0
- package/skills/agent-in-chrome/references/geetest-click-captcha.md +55 -0
- package/skills/agent-in-chrome/references/network-debugging.md +20 -0
- package/skills/agent-in-chrome/references/reading-pages.md +30 -0
- package/skills/agent-in-chrome/references/recovery.md +25 -0
- package/skills/agent-in-chrome/references/tabs-and-sessions.md +34 -0
- package/skills/install-agent-in-chrome/SKILL.md +252 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
import * as install from "./install.mjs";
|
|
10
|
+
import { buildAgents } from "./agents.mjs";
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
13
|
+
const INSTALLER = path.join(ROOT, "scripts", "install.mjs");
|
|
14
|
+
const BIN = path.join(ROOT, "bin", "agent-in-chrome.mjs");
|
|
15
|
+
const SKILL_DIR = path.join(ROOT, "skills", "install-agent-in-chrome");
|
|
16
|
+
const SKILL = path.join(SKILL_DIR, "SKILL.md");
|
|
17
|
+
const COMMAND = path.join(ROOT, "commands", "install-agent-in-chrome.md");
|
|
18
|
+
const FAKE_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "aic-skill-home-"));
|
|
19
|
+
fs.mkdirSync(
|
|
20
|
+
process.platform === "darwin"
|
|
21
|
+
? path.join(FAKE_HOME, "Library", "Application Support", "Google", "Chrome")
|
|
22
|
+
: process.platform === "win32"
|
|
23
|
+
? path.join(FAKE_HOME, "AppData", "Local", "Google", "Chrome", "User Data")
|
|
24
|
+
: path.join(FAKE_HOME, ".config", "google-chrome"),
|
|
25
|
+
{ recursive: true },
|
|
26
|
+
);
|
|
27
|
+
process.on("exit", () => fs.rmSync(FAKE_HOME, { recursive: true, force: true }));
|
|
28
|
+
|
|
29
|
+
const RUNTIME_DIR = path.join(FAKE_HOME, ".agent-in-chrome", "agent-in-chrome");
|
|
30
|
+
|
|
31
|
+
let passed = 0;
|
|
32
|
+
let failed = 0;
|
|
33
|
+
const check = (name, cond, extra = "") => {
|
|
34
|
+
if (cond) {
|
|
35
|
+
console.log(` \x1b[32m✓\x1b[0m ${name}`);
|
|
36
|
+
passed++;
|
|
37
|
+
} else {
|
|
38
|
+
console.log(` \x1b[31m✗\x1b[0m ${name}${extra ? ` — ${extra}` : ""}`);
|
|
39
|
+
failed++;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const runInstaller = (args) =>
|
|
44
|
+
spawnSync(process.execPath, [INSTALLER, ...args], {
|
|
45
|
+
encoding: "utf8",
|
|
46
|
+
timeout: 60000,
|
|
47
|
+
env: { ...process.env, HOME: FAKE_HOME, USERPROFILE: FAKE_HOME },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const skillText = fs.readFileSync(SKILL, "utf8");
|
|
51
|
+
const commandText = fs.readFileSync(COMMAND, "utf8");
|
|
52
|
+
|
|
53
|
+
console.log("\n\x1b[1m--print-config:三种格式都得是能直接用的东西\x1b[0m");
|
|
54
|
+
|
|
55
|
+
const jsonRun = runInstaller(["--check", "--print-config"]);
|
|
56
|
+
check("json:退出码 0", jsonRun.status === 0, `status=${jsonRun.status} stderr=${(jsonRun.stderr || "").slice(0, 200)}`);
|
|
57
|
+
|
|
58
|
+
let facts = null;
|
|
59
|
+
try {
|
|
60
|
+
facts = JSON.parse(jsonRun.stdout);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
check("json:stdout 整份都能 JSON.parse(不许掺一个字的杂音)", false, String(e.message).slice(0, 160));
|
|
63
|
+
}
|
|
64
|
+
if (facts) {
|
|
65
|
+
check("json:stdout 整份都能 JSON.parse(不许掺一个字的杂音)", true);
|
|
66
|
+
check("默认格式就是 json(不带 =xxx 时)", typeof facts === "object" && !!facts.mcp);
|
|
67
|
+
check("有版本号,且和 package.json 一致", facts.version === JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")).version, facts.version);
|
|
68
|
+
check("runtimeDir / serverPath 都是绝对路径", path.isAbsolute(facts.runtimeDir || "") && path.isAbsolute(facts.serverPath || ""), `${facts.runtimeDir} / ${facts.serverPath}`);
|
|
69
|
+
check("server 名字就是 agent-in-chrome(配置里那个键)", facts.mcp.name === "agent-in-chrome", facts.mcp.name);
|
|
70
|
+
|
|
71
|
+
for (const [k, e] of Object.entries({ launcher: facts.mcp.launcher, npx: facts.mcp.npx })) {
|
|
72
|
+
check(
|
|
73
|
+
`mcp.${k} 是 {command,args,env} 三件套且 command 非空`,
|
|
74
|
+
!!e && typeof e.command === "string" && e.command.length > 0 && Array.isArray(e.args) && !!e.env && typeof e.env === "object",
|
|
75
|
+
JSON.stringify(e)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
check(
|
|
79
|
+
"mcp.npx 用的是 package.json 的包名(带 scope),不是配置里那个键",
|
|
80
|
+
`${facts.mcp.npx.command} ${facts.mcp.npx.args.join(" ")}` === `npx -y ${JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")).name} serve`,
|
|
81
|
+
JSON.stringify(facts.mcp.npx)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
check("extension.dir 是绝对路径", path.isAbsolute(facts.extension?.dir || ""), facts.extension?.dir);
|
|
85
|
+
check("extension.id 是 32 位扩展 ID", /^[a-p]{32}$/.test(facts.extension?.id || ""), facts.extension?.id);
|
|
86
|
+
check("extension.ids 至少含开发版那个(host 清单按它逐个枚举)", Array.isArray(facts.extension?.ids) && facts.extension.ids[0] === facts.extension.id);
|
|
87
|
+
check("storeUrl 要么是 null 要么是商店链接(不许是空串这种半吊子)", facts.extension?.storeUrl === null || /^https:\/\//.test(facts.extension?.storeUrl || ""), String(facts.extension?.storeUrl));
|
|
88
|
+
|
|
89
|
+
check("nativeHost.name 是 host 清单里那个名字", facts.nativeHost?.name === "org.liangai.agent_in_chrome", facts.nativeHost?.name);
|
|
90
|
+
const manifestPaths = Object.values(facts.nativeHost?.manifestPaths || {});
|
|
91
|
+
check("nativeHost.manifestPaths 至少一个浏览器,且都是绝对路径", manifestPaths.length > 0 && manifestPaths.every((p) => path.isAbsolute(p)), JSON.stringify(facts.nativeHost?.manifestPaths));
|
|
92
|
+
|
|
93
|
+
check("agents 是数组且不为空", Array.isArray(facts.agents) && facts.agents.length > 0, String(facts.agents?.length));
|
|
94
|
+
const badAgent = (facts.agents || []).find(
|
|
95
|
+
(a) => typeof a.id !== "string" || typeof a.name !== "string" || typeof a.detected !== "boolean" || typeof a.configPath !== "string" || typeof a.registered !== "boolean"
|
|
96
|
+
);
|
|
97
|
+
check("agents 每一项都是 {id,name,detected,configPath,registered}", !badAgent, JSON.stringify(badAgent));
|
|
98
|
+
const realIds = buildAgents({ serverPath: facts.serverPath, mcpLauncher: facts.mcp.launcher.command }).map((a) => a.id);
|
|
99
|
+
check(
|
|
100
|
+
"agents 的 id 清单和 buildAgents 完全一致(不是另编的一份)",
|
|
101
|
+
JSON.stringify(facts.agents.map((a) => a.id)) === JSON.stringify(realIds),
|
|
102
|
+
JSON.stringify(facts.agents.map((a) => a.id))
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const tomlRun = runInstaller(["--check", "--print-config=toml"]);
|
|
107
|
+
check("toml:退出码 0", tomlRun.status === 0, `status=${tomlRun.status}`);
|
|
108
|
+
{
|
|
109
|
+
const lines = tomlRun.stdout.split("\n");
|
|
110
|
+
const live = lines.filter((l) => l.trim() && !l.trim().startsWith("#"));
|
|
111
|
+
check("toml:有 [mcp_servers.agent-in-chrome] 这张表", live.some((l) => l.trim() === "[mcp_servers.agent-in-chrome]"), JSON.stringify(live.slice(0, 3)));
|
|
112
|
+
check("toml:有一行 command =", live.some((l) => /^command\s*=\s*".+"$/.test(l.trim())), JSON.stringify(live));
|
|
113
|
+
check("toml:有一行 args =", live.some((l) => /^args\s*=\s*\[/.test(l.trim())));
|
|
114
|
+
check("toml:只有一张活着的同名表(另一种启动方式是注释)", live.filter((l) => l.trim().startsWith("[mcp_servers.")).length === 1);
|
|
115
|
+
check("toml:注释里给了 npx 那条启动方式", tomlRun.stdout.includes("# command = \"npx\""), tomlRun.stdout.slice(-200));
|
|
116
|
+
check("toml:没有非注释的杂音行(每一行不是注释就得是配置)", live.every((l) => /^\[|^\w+\s*=/.test(l.trim())), JSON.stringify(live));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const cliRun = runInstaller(["--check", "--print-config=claude-cli"]);
|
|
120
|
+
check("claude-cli:退出码 0", cliRun.status === 0, `status=${cliRun.status}`);
|
|
121
|
+
check("claude-cli:stdout 第一行就是 claude mcp add", cliRun.stdout.startsWith("claude mcp add"), JSON.stringify(cliRun.stdout.split("\n")[0]));
|
|
122
|
+
check("claude-cli:命令里带 server 名", cliRun.stdout.split("\n")[0].includes("agent-in-chrome"));
|
|
123
|
+
check("claude-cli:命令里带 --scope user(不写就落进项目级,换个目录就没了)", cliRun.stdout.split("\n")[0].includes("--scope user"));
|
|
124
|
+
check(
|
|
125
|
+
"claude-cli:除了那条命令,其余行要么空要么是 # 注释",
|
|
126
|
+
cliRun.stdout.split("\n").slice(1).every((l) => !l.trim() || l.trim().startsWith("#")),
|
|
127
|
+
JSON.stringify(cliRun.stdout.split("\n").slice(1))
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
console.log("\n\x1b[1mstdout 归配置,别的都走 stderr\x1b[0m");
|
|
131
|
+
for (const [fmt, r] of [["json", jsonRun], ["toml", tomlRun], ["claude-cli", cliRun]]) {
|
|
132
|
+
check(`${fmt}:提示确实打在 stderr 上(不是没打)`, (r.stderr || "").includes("--print-config"), JSON.stringify((r.stderr || "").slice(0, 120)));
|
|
133
|
+
check(`${fmt}:stdout 里没有安装器那套 ✓/✗/· 输出`, !/[✓✗·!]\s/.test(r.stdout), JSON.stringify(r.stdout.slice(0, 160)));
|
|
134
|
+
check(`${fmt}:stdout 里没有 ANSI 颜色码(管道里那是垃圾字符)`, !r.stdout.includes("\x1b["));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
console.log("\n\x1b[1m--print-config 不写任何文件\x1b[0m");
|
|
138
|
+
{
|
|
139
|
+
const snapshot = (dir) => {
|
|
140
|
+
const out = [];
|
|
141
|
+
const walk = (p, rel) => {
|
|
142
|
+
let ents;
|
|
143
|
+
try {
|
|
144
|
+
ents = fs.readdirSync(p, { withFileTypes: true });
|
|
145
|
+
} catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
for (const e of ents.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
149
|
+
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
150
|
+
if (childRel === "cli-profile") continue;
|
|
151
|
+
const child = path.join(p, e.name);
|
|
152
|
+
if (e.isDirectory()) {
|
|
153
|
+
walk(child, childRel);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
let st;
|
|
157
|
+
try {
|
|
158
|
+
st = fs.statSync(child);
|
|
159
|
+
} catch {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
out.push(`${childRel}\t${st.size}\t${st.mtimeMs}`);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
walk(dir, "");
|
|
166
|
+
return out.join("\n");
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const exists = fs.existsSync(RUNTIME_DIR);
|
|
170
|
+
const before = exists ? snapshot(RUNTIME_DIR) : "";
|
|
171
|
+
runInstaller(["--check", "--print-config"]);
|
|
172
|
+
runInstaller(["--check", "--print-config=toml"]);
|
|
173
|
+
const misuse = runInstaller(["--print-config"]);
|
|
174
|
+
const after = exists ? snapshot(RUNTIME_DIR) : "";
|
|
175
|
+
check("运行时目录里的文件、大小、mtime 全都没变", before === after, `目录=${RUNTIME_DIR}`);
|
|
176
|
+
check(
|
|
177
|
+
"运行时目录本来就不存在时也没被凭空建出来",
|
|
178
|
+
exists || !fs.existsSync(RUNTIME_DIR),
|
|
179
|
+
"这台机器上没装过,而 --print-config 把目录建出来了"
|
|
180
|
+
);
|
|
181
|
+
check("误用成 install 时也只是打印(退出码 0)", misuse.status === 0, `status=${misuse.status}`);
|
|
182
|
+
let misuseJson = null;
|
|
183
|
+
try {
|
|
184
|
+
misuseJson = JSON.parse(misuse.stdout);
|
|
185
|
+
} catch {}
|
|
186
|
+
check("误用成 install 时 stdout 仍是干净的 JSON", !!misuseJson && misuseJson.mcp?.name === "agent-in-chrome");
|
|
187
|
+
check("并且在 stderr 上说清楚了「什么都没装」", (misuse.stderr || "").includes("什么都没装"), JSON.stringify((misuse.stderr || "").slice(0, 200)));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
console.log("\n\x1b[1m旗标解析\x1b[0m");
|
|
191
|
+
{
|
|
192
|
+
check("--print-config 不带值 = json", install.parseFlags(["--check", "--print-config"]).printConfig === "json");
|
|
193
|
+
check("--print-config=toml 认得", install.parseFlags(["--print-config=toml"]).printConfig === "toml");
|
|
194
|
+
check("不带这个旗标时是 null(不能恒真)", install.parseFlags(["--check"]).printConfig === null);
|
|
195
|
+
check("--print-config 不会被当成「不认识的旗标」", install.parseFlags(["--check", "--print-config=json"]).unknown.length === 0, JSON.stringify(install.parseFlags(["--check", "--print-config=json"]).unknown));
|
|
196
|
+
check("走的是 check 那条路(mode 仍按旗标算)", install.parseFlags(["--check", "--print-config"]).mode === "check");
|
|
197
|
+
|
|
198
|
+
const badFmt = runInstaller(["--check", "--print-config=yaml"]);
|
|
199
|
+
check("认不出的格式:退出码 2(和「不认识的旗标」同级)", badFmt.status === 2, `status=${badFmt.status}`);
|
|
200
|
+
check("认不出的格式:stdout 一个字都不出(别让管道拿到半份配置)", badFmt.stdout === "", JSON.stringify(badFmt.stdout));
|
|
201
|
+
check("认不出的格式:stderr 说清楚认哪几种", /json/.test(badFmt.stderr) && /toml/.test(badFmt.stderr) && /claude-cli/.test(badFmt.stderr), JSON.stringify(badFmt.stderr.slice(0, 160)));
|
|
202
|
+
check("PRINT_FORMATS 就是这三种", JSON.stringify(install.PRINT_FORMATS) === JSON.stringify(["json", "toml", "claude-cli"]));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
console.log("\n\x1b[1mlauncher 条目的形状:print-config 与 agents.mjs 是同一份\x1b[0m");
|
|
206
|
+
{
|
|
207
|
+
const trae = buildAgents({ serverPath: facts.serverPath, mcpLauncher: facts.mcp.launcher.command }).find((a) => a.id === "trae");
|
|
208
|
+
const entry = JSON.parse(trae.preview.join("\n")).mcpServers["agent-in-chrome"];
|
|
209
|
+
check(
|
|
210
|
+
"print-config 的 mcp.launcher 和 agents.mjs 写给 GUI 客户端的条目一致",
|
|
211
|
+
entry.command === facts.mcp.launcher.command && JSON.stringify(entry.args || []) === JSON.stringify(facts.mcp.launcher.args),
|
|
212
|
+
`agents.mjs=${JSON.stringify(entry)} print-config=${JSON.stringify(facts.mcp.launcher)}`
|
|
213
|
+
);
|
|
214
|
+
check(
|
|
215
|
+
"launcher 指的就是运行时目录里那个启动器",
|
|
216
|
+
facts.mcp.launcher.command === path.join(facts.runtimeDir, process.platform === "win32" ? "mcp-launcher.bat" : "mcp-launcher.sh") ||
|
|
217
|
+
(process.platform === "win32" && facts.mcp.launcher.args.includes(path.join(facts.runtimeDir, "mcp-launcher.bat"))),
|
|
218
|
+
JSON.stringify(facts.mcp.launcher)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
console.log("\n\x1b[1m文档漂移:skill 里的每条命令都得存在\x1b[0m");
|
|
223
|
+
{
|
|
224
|
+
const binSrc = fs.readFileSync(BIN, "utf8");
|
|
225
|
+
const installerSrc = fs.readFileSync(INSTALLER, "utf8");
|
|
226
|
+
|
|
227
|
+
const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")).name;
|
|
228
|
+
const PKG_RE = PKG.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
229
|
+
const commandsIn = (text) => {
|
|
230
|
+
const out = [];
|
|
231
|
+
for (const m of text.matchAll(new RegExp(`npx ${PKG_RE}(?:@latest)?([^\\n\`|]*)`, "g"))) {
|
|
232
|
+
const toks = m[1].split(/\s+/).filter(Boolean);
|
|
233
|
+
const sub = toks.find((t) => !t.startsWith("-")) || null;
|
|
234
|
+
const flags = toks.filter((t) => t.startsWith("--")).map((t) => (t.includes("=") ? t.slice(0, t.indexOf("=") + 1) : t));
|
|
235
|
+
out.push({ sub, flags, raw: `npx ${PKG}${m[1]}`.trim() });
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const calls = [...commandsIn(skillText), ...commandsIn(commandText)];
|
|
241
|
+
check("skill 里确实写了 npx 命令(没有的话这组测试就白守了)", calls.length >= 4, String(calls.length));
|
|
242
|
+
|
|
243
|
+
const badSub = calls.filter((c) => c.sub && !binSrc.includes(`"${c.sub}"`));
|
|
244
|
+
check("每条命令的子命令 bin/agent-in-chrome.mjs 里都认得", badSub.length === 0, badSub.map((c) => c.raw).join(" / "));
|
|
245
|
+
|
|
246
|
+
const allFlags = [...new Set(calls.flatMap((c) => c.flags))];
|
|
247
|
+
const badFlags = allFlags.filter((f) => !installerSrc.includes(f));
|
|
248
|
+
check(`每个旗标 scripts/install.mjs 里都认得(${allFlags.join(" ")})`, badFlags.length === 0, badFlags.join(" "));
|
|
249
|
+
|
|
250
|
+
check("上面那条判据不是恒真(编一个不存在的旗标必须落空)", !installerSrc.includes("--totally-not-a-flag="));
|
|
251
|
+
|
|
252
|
+
const idsInSkill = [...skillText.matchAll(/--agents=([a-z0-9,-]+)/g)].flatMap((m) => m[1].split(","));
|
|
253
|
+
const knownIds = new Set(buildAgents({ serverPath: facts.serverPath, mcpLauncher: facts.mcp.launcher.command }).map((a) => a.id));
|
|
254
|
+
const badIds = idsInSkill.filter((id) => !knownIds.has(id));
|
|
255
|
+
check("skill 里举例用的 agent id 都是真的", badIds.length === 0, badIds.join("、"));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
console.log("\n\x1b[1m文档漂移:README / docs 里的 npx 子命令都得存在\x1b[0m");
|
|
259
|
+
{
|
|
260
|
+
const binSrc = fs.readFileSync(BIN, "utf8");
|
|
261
|
+
const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")).name;
|
|
262
|
+
const PKG_RE = PKG.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
263
|
+
const DOCS = ["README.md", "README.en.md", "docs/CLI.md"];
|
|
264
|
+
const subs = new Set();
|
|
265
|
+
for (const rel of DOCS) {
|
|
266
|
+
const text = fs.readFileSync(path.join(ROOT, rel), "utf8");
|
|
267
|
+
for (const m of text.matchAll(new RegExp(`npx ${PKG_RE}(?:@latest)?([^\\n\`|]*)`, "g"))) {
|
|
268
|
+
const sub = m[1].split(/\s+/).filter(Boolean).find((t) => !t.startsWith("-"));
|
|
269
|
+
if (sub) subs.add(sub);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
check(`文档里确实写了 npx 子命令(收到 ${[...subs].join(" ")})`, subs.size >= 3, [...subs].join(" "));
|
|
273
|
+
const bad = [...subs].filter((sub) => !binSrc.includes(`"${sub}"`));
|
|
274
|
+
check("每个子命令 bin/agent-in-chrome.mjs 里都认得", bad.length === 0, bad.join(" / "));
|
|
275
|
+
check("上面那条判据不是恒真(编一个不存在的子命令必须落空)", !binSrc.includes(`"frobnicate"`));
|
|
276
|
+
|
|
277
|
+
const cli = fs.readFileSync(path.join(ROOT, "docs", "CLI.md"), "utf8");
|
|
278
|
+
for (const sub of ["borrow-login", "cli-browser"]) {
|
|
279
|
+
check(`docs/CLI.md 给了 ${sub} 的 npx 敲法`, cli.includes(`npx ${PKG} ${sub}`));
|
|
280
|
+
check(`docs/CLI.md 也留着 ${sub} 的 git 检出敲法`, cli.includes(`node scripts/${sub}.mjs`));
|
|
281
|
+
check(`bin 认得 ${sub} 子命令`, binSrc.includes(`cmd === "${sub}"`));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
console.log("\n\x1b[1mskill 与 command 的形状\x1b[0m");
|
|
286
|
+
{
|
|
287
|
+
const frontmatter = (text) => {
|
|
288
|
+
const lines = text.split("\n");
|
|
289
|
+
if (lines[0].trim() !== "---") return null;
|
|
290
|
+
const end = lines.indexOf("---", 1);
|
|
291
|
+
if (end === -1) return null;
|
|
292
|
+
const fm = {};
|
|
293
|
+
for (const l of lines.slice(1, end)) {
|
|
294
|
+
const m = /^([A-Za-z_][\w-]*):\s*(.*)$/.exec(l);
|
|
295
|
+
if (m) fm[m[1]] = m[2].trim();
|
|
296
|
+
}
|
|
297
|
+
return fm;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const sfm = frontmatter(skillText);
|
|
301
|
+
check("SKILL.md 有合法的 frontmatter", !!sfm);
|
|
302
|
+
check("skill 的 name 和目录名一致(不一致时客户端按目录名找,name 就成了摆设)", sfm?.name === path.basename(SKILL_DIR), sfm?.name);
|
|
303
|
+
check("skill 有 description", (sfm?.description || "").length > 40, String(sfm?.description?.length));
|
|
304
|
+
for (const kw of ["安装", "装不上", "配置", "自检", "install", "connect"])
|
|
305
|
+
check(`description 里有触发词「${kw}」`, (sfm?.description || "").includes(kw));
|
|
306
|
+
check("description 中英文都写了(英文触发词那半在)", /[a-z]{4,}/.test(sfm?.description || "") && /[一-龥]/.test(sfm?.description || ""));
|
|
307
|
+
|
|
308
|
+
const cfm = frontmatter(commandText);
|
|
309
|
+
check("command 有合法的 frontmatter", !!cfm);
|
|
310
|
+
check("command 有 description", (cfm?.description || "").length > 5, String(cfm?.description));
|
|
311
|
+
check("command 指向这个 skill", commandText.includes("install-agent-in-chrome"));
|
|
312
|
+
|
|
313
|
+
const PRIVATE_DOCS = ["docs/" + "DESIGN" + ".md", "docs/" + "RUNBOOK" + ".md", "docs/" + "internal/"];
|
|
314
|
+
for (const doc of PRIVATE_DOCS) check(`skill 里没有引用不公开的 ${doc}`, !skillText.includes(doc));
|
|
315
|
+
const SCAN_RE = new RegExp("docs\\/internal|(?<![\\w-])(DE" + "SIGN|RUN" + "BOOK)\\.md");
|
|
316
|
+
check("拼出来的就是隐私扫描认的那三个名字", PRIVATE_DOCS.length === 3 && PRIVATE_DOCS.every((d) => SCAN_RE.test(d)), PRIVATE_DOCS.join(" "));
|
|
317
|
+
check("上面那条判据不是恒真(换个无关名字必须落空)", !SCAN_RE.test("docs/CLI.md"));
|
|
318
|
+
|
|
319
|
+
const links = [...skillText.matchAll(/\]\((\.\.\/[^)#]+)(?:#[^)]*)?\)/g)].map((m) => m[1]);
|
|
320
|
+
const deadLinks = links.filter((l) => !fs.existsSync(path.resolve(SKILL_DIR, l)));
|
|
321
|
+
check(`skill 里的相对链接都指得到(${links.length} 条)`, deadLinks.length === 0, deadLinks.join("、"));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
console.log("\n\x1b[1m安装器登记了这份 skill\x1b[0m");
|
|
325
|
+
{
|
|
326
|
+
const assets = install.ASSETS || [];
|
|
327
|
+
const skillAsset = assets.find((a) => a.from === SKILL_DIR);
|
|
328
|
+
const cmdAsset = assets.find((a) => a.from === COMMAND);
|
|
329
|
+
check("ASSETS 里有安装 skill", !!skillAsset, JSON.stringify(assets.map((a) => a.label)));
|
|
330
|
+
check("ASSETS 里有 /install-agent-in-chrome 命令", !!cmdAsset);
|
|
331
|
+
check("skill 资产指的是整个目录", !!skillAsset && fs.statSync(skillAsset.from).isDirectory());
|
|
332
|
+
check("卸载时它有对应的移除路径(不然会留在用户盘上)", !!skillAsset?.removeWith);
|
|
333
|
+
|
|
334
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aic-install-skill-"));
|
|
335
|
+
try {
|
|
336
|
+
install.copyAsset(skillAsset.from, path.join(tmp, "install-agent-in-chrome"));
|
|
337
|
+
install.copyAsset(cmdAsset.from, path.join(tmp, "commands", "install-agent-in-chrome.md"));
|
|
338
|
+
check("装完 SKILL.md 在", fs.existsSync(path.join(tmp, "install-agent-in-chrome", "SKILL.md")));
|
|
339
|
+
check("装完命令文件在", fs.existsSync(path.join(tmp, "commands", "install-agent-in-chrome.md")));
|
|
340
|
+
} finally {
|
|
341
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
console.log("\n\x1b[1mregistered 字段真的在读文件\x1b[0m");
|
|
346
|
+
{
|
|
347
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "aic-reg-"));
|
|
348
|
+
const jsonFile = path.join(tmp, "mcp.json");
|
|
349
|
+
fs.writeFileSync(jsonFile, JSON.stringify({ mcpServers: { "agent-in-chrome": { command: "node" } } }));
|
|
350
|
+
check("JSON 配置里有我们的键 → true", install.configHasOurEntry(jsonFile) === true);
|
|
351
|
+
|
|
352
|
+
fs.writeFileSync(jsonFile, JSON.stringify({ mcpServers: { "some-other": { command: "node" } } }));
|
|
353
|
+
check("换成别人的键 → false(不是恒真)", install.configHasOurEntry(jsonFile) === false);
|
|
354
|
+
|
|
355
|
+
fs.writeFileSync(jsonFile, JSON.stringify({ mcpServers: { "my-agent-in-chrome-2": { command: "node" } } }));
|
|
356
|
+
check("JSON 里含而不等的键名不算我们的", install.configHasOurEntry(jsonFile) === false);
|
|
357
|
+
|
|
358
|
+
const tomlFile = path.join(tmp, "config.toml");
|
|
359
|
+
fs.writeFileSync(tomlFile, `[mcp_servers.agent-in-chrome]\ncommand = "node"\n`);
|
|
360
|
+
check("TOML(没有零依赖解析器)走全文匹配 → true", install.configHasOurEntry(tomlFile) === true);
|
|
361
|
+
fs.writeFileSync(tomlFile, `[mcp_servers.other]\ncommand = "node"\n`);
|
|
362
|
+
check("TOML 里没有我们 → false", install.configHasOurEntry(tomlFile) === false);
|
|
363
|
+
|
|
364
|
+
check("文件不存在 → false(不抛)", install.configHasOurEntry(path.join(tmp, "nope.json")) === false);
|
|
365
|
+
|
|
366
|
+
check(
|
|
367
|
+
"configPathsOf 拆得开多 profile",
|
|
368
|
+
JSON.stringify(install.configPathsOf("/a/x.yml、/b/y.yml")) === JSON.stringify(["/a/x.yml", "/b/y.yml"])
|
|
369
|
+
);
|
|
370
|
+
check(
|
|
371
|
+
"configPathsOf 剥得掉「(经 claude mcp add,scope: user)」这类说明",
|
|
372
|
+
JSON.stringify(install.configPathsOf("/u/.claude.json(经 claude mcp add,scope: user)")) === JSON.stringify(["/u/.claude.json"])
|
|
373
|
+
);
|
|
374
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
console.log(`\n${failed ? "\x1b[31m" : "\x1b[32m"}${passed} 通过,${failed} 失败\x1b[0m\n`);
|
|
378
|
+
process.exit(failed ? 1 : 0);
|