@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,175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* `prepublishOnly` 闸:防止在**私有源检出**里手滑 `npm publish`。
|
|
4
|
+
*
|
|
5
|
+
* 三条判据(任何一条命中就拒绝发布,退出码 1,问题打在 stderr):
|
|
6
|
+
* 1. 仓库根有 `.private-source` 标记,或者树里有 `scripts/release/`(发布流水线本身,
|
|
7
|
+
* 公开快照里被整个排除)→ 这是私有源,拒绝。
|
|
8
|
+
* 2. 随机抽 5 个 .js/.mjs,找**未还原的公开标记**(行首 `//!` 或 `/*!`),找到就拒绝。
|
|
9
|
+
* 3. 树里有**私有层**测试(live 层 `e2e-browser` / `e2e-concurrency` / `e2e-mcp-sdk`、
|
|
10
|
+
* 手动验证脚本 `verify-*.mjs`、只被 live 层引用的 `png-diff` / `read-page-bench`、
|
|
11
|
+
* 发布工具自己的 `test-release-*`、官网的 `test-site`)→ 拒绝。
|
|
12
|
+
* 公开层测试(不需要浏览器的那一层)**随包发布,这里放行**。
|
|
13
|
+
* 判据只看文件名,失败方向是「像私有层就拒」。
|
|
14
|
+
*
|
|
15
|
+
* 判据一律收窄到**行首**(去掉前导空白之后):这个文件跟着公开包一起发,
|
|
16
|
+
* 不能 import 剥离器,只能自带判据,宁可漏报也不误报。
|
|
17
|
+
*
|
|
18
|
+
* 失败方向:认不出就当成「没剥过」拒绝,不是放行。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import fs from "node:fs";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
|
|
25
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
26
|
+
|
|
27
|
+
/* 保守判据:整行去掉前导空白之后以未还原的公开标记 `//!` 或 `/*!` 开头 */
|
|
28
|
+
export function unrestoredMarkerLines(text) {
|
|
29
|
+
const out = [];
|
|
30
|
+
const lines = text.split("\n");
|
|
31
|
+
for (let i = 0; i < lines.length; i++) {
|
|
32
|
+
const t = lines[i].trimStart();
|
|
33
|
+
if (t.startsWith("//!") || t.startsWith("/*!")) out.push({ line: i + 1, text: lines[i].trim().slice(0, 100) });
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const SKIP_DIRS = new Set([".git", "node_modules", "dist"]);
|
|
39
|
+
|
|
40
|
+
// 「这是测试文件」的判据:TEST_FILE_RE 是正则表,isTestFile(rel) 拿相对路径问一次,
|
|
41
|
+
// 正则锚在 basename 开头,命中即视为测试文件。
|
|
42
|
+
export const PRIVATE_TEST_FILE_RE = [
|
|
43
|
+
/(^|\/)e2e-(browser|concurrency|mcp-sdk)\.mjs$/,
|
|
44
|
+
/(^|\/)verify-[^/]+\.(mjs|cjs|js)$/,
|
|
45
|
+
/(^|\/)png-diff\.mjs$/,
|
|
46
|
+
/(^|\/)read-page-bench\.mjs$/,
|
|
47
|
+
/(^|\/)test-release-[^/]+\.(mjs|cjs|js)$/,
|
|
48
|
+
/(^|\/)test-site\.mjs$/,
|
|
49
|
+
/(^|\/)pack-store\.mjs$/,
|
|
50
|
+
/(^|\/)scripts\/probe(\/|$)/,
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
export function isPrivateTestFile(rel) {
|
|
54
|
+
const p = String(rel).split(path.sep).join("/");
|
|
55
|
+
return PRIVATE_TEST_FILE_RE.some((re) => re.test(p));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* 全树列文件(不只是 js——CI 工作流也要看得见):返回相对 root 的路径数组,跳过 .git / node_modules / dist */
|
|
59
|
+
export function listAllFiles(dir, acc = [], root = dir) {
|
|
60
|
+
let ents;
|
|
61
|
+
try {
|
|
62
|
+
ents = fs.readdirSync(dir, { withFileTypes: true });
|
|
63
|
+
} catch {
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
for (const e of ents) {
|
|
67
|
+
if (SKIP_DIRS.has(e.name)) continue;
|
|
68
|
+
const p = path.join(dir, e.name);
|
|
69
|
+
if (e.isDirectory()) listAllFiles(p, acc, root);
|
|
70
|
+
else if (e.isFile()) acc.push(path.relative(root, p).split(path.sep).join("/"));
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function listJs(dir, acc = [], root = dir) {
|
|
76
|
+
let ents;
|
|
77
|
+
try {
|
|
78
|
+
ents = fs.readdirSync(dir, { withFileTypes: true });
|
|
79
|
+
} catch {
|
|
80
|
+
return acc;
|
|
81
|
+
}
|
|
82
|
+
for (const e of ents) {
|
|
83
|
+
if (SKIP_DIRS.has(e.name)) continue;
|
|
84
|
+
const p = path.join(dir, e.name);
|
|
85
|
+
if (e.isDirectory()) listJs(p, acc, root);
|
|
86
|
+
else if (e.isFile() && /\.(mjs|cjs|js)$/.test(e.name)) acc.push(p);
|
|
87
|
+
}
|
|
88
|
+
return acc;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* 抽样。默认真随机——每次 publish 抽不同的 5 个,长期下来覆盖面比固定 5 个大得多。
|
|
93
|
+
* 传 rng 便于单测钉死抽样。
|
|
94
|
+
*/
|
|
95
|
+
export function pickSample(files, n = 5, rng = Math.random) {
|
|
96
|
+
const a = files.slice();
|
|
97
|
+
for (let i = a.length - 1; i > 0; i--) {
|
|
98
|
+
const j = Math.floor(rng() * (i + 1));
|
|
99
|
+
[a[i], a[j]] = [a[j], a[i]];
|
|
100
|
+
}
|
|
101
|
+
return a.slice(0, n);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// guard(root, { rng, sampleSize }):跑一遍三条判据,返回问题描述字符串数组;
|
|
105
|
+
// 空数组 = 放行。只读不写,不碰进程退出码,退出码由调用方决定。
|
|
106
|
+
export function guard(root = ROOT, { rng = Math.random, sampleSize = 5 } = {}) {
|
|
107
|
+
const problems = [];
|
|
108
|
+
|
|
109
|
+
const privateSigns = [".private-source", "scripts/release/strip-comments.mjs"].filter((p) =>
|
|
110
|
+
fs.existsSync(path.join(root, p)),
|
|
111
|
+
);
|
|
112
|
+
if (privateSigns.length) {
|
|
113
|
+
problems.push(
|
|
114
|
+
`这是**私有源检出**(${privateSigns.join(" / ")} 都只在私有树里有),不许从这里发 npm。\n` +
|
|
115
|
+
" npm 只能从剥好注释的公开检出发:\n" +
|
|
116
|
+
" node scripts/release/publish.mjs --publish",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tests = listAllFiles(root).filter(isPrivateTestFile);
|
|
121
|
+
if (tests.length) {
|
|
122
|
+
problems.push(
|
|
123
|
+
`这棵树里有**私有层**测试(${tests.length} 个,例如 ${tests.slice(0, 3).join("、")})——` +
|
|
124
|
+
`live 层 / 发布工具自测 / 官网测试都不随公开包发布,不许发。\n` +
|
|
125
|
+
` 公开层测试(不需要浏览器的那一层)是允许的,这里放行的就是那一层。\n` +
|
|
126
|
+
` 正常的公开检出由 scripts/release/publish.mjs 生成,它一支私有层测试都不会放进来。`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const files = listJs(root);
|
|
131
|
+
if (files.length === 0) {
|
|
132
|
+
problems.push("一个 .js/.mjs 都找不到:包的内容不对,先查快照是怎么打的。");
|
|
133
|
+
} else {
|
|
134
|
+
const sample = pickSample(files, sampleSize, rng);
|
|
135
|
+
for (const f of sample) {
|
|
136
|
+
let text;
|
|
137
|
+
try {
|
|
138
|
+
text = fs.readFileSync(f, "utf8");
|
|
139
|
+
} catch (e) {
|
|
140
|
+
problems.push(`读不了 ${path.relative(root, f)}:${e.message}`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const hits = unrestoredMarkerLines(text);
|
|
144
|
+
if (hits.length) {
|
|
145
|
+
problems.push(
|
|
146
|
+
`${path.relative(root, f)} 里还有未还原的公开标记(抽样命中 ${hits.length} 行,` +
|
|
147
|
+
`例如第 ${hits[0].line} 行:${hits[0].text})——这棵树没剥过注释,不许发。`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return problems;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function main() {
|
|
156
|
+
const problems = guard();
|
|
157
|
+
if (problems.length === 0) {
|
|
158
|
+
process.stderr.write("prepublishOnly 闸通过:不是私有源、树里没有私有层测试、抽样未见未还原的公开标记。\n");
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
process.stderr.write("拒绝发布:\n" + problems.map((p) => ` - ${p}`).join("\n") + "\n");
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function isMainModule(metaUrl) {
|
|
166
|
+
const entry = process.argv[1];
|
|
167
|
+
if (!entry) return false;
|
|
168
|
+
try {
|
|
169
|
+
return fs.realpathSync(entry) === fs.realpathSync(fileURLToPath(metaUrl));
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (isMainModule(import.meta.url)) process.exit(main());
|