@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,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export function listMjs(dir, { readdir = fs.readdirSync } = {}) {
|
|
6
|
+
const out = [];
|
|
7
|
+
const walk = (d, rel) => {
|
|
8
|
+
let ents;
|
|
9
|
+
try {
|
|
10
|
+
ents = readdir(d, { withFileTypes: true });
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
for (const e of ents) {
|
|
15
|
+
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
16
|
+
if (e.isDirectory()) walk(path.join(d, e.name), childRel);
|
|
17
|
+
else if (e.isFile() && e.name.endsWith(".mjs")) out.push(childRel);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
walk(dir, "");
|
|
21
|
+
return out.sort();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function hashFile(p, { read = fs.readFileSync } = {}) {
|
|
25
|
+
try {
|
|
26
|
+
return crypto.createHash("sha256").update(read(p)).digest("hex");
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function compareInstalledMcp(workspaceMcpDir, runtimeDir, io = {}) {
|
|
33
|
+
const files = listMjs(workspaceMcpDir, io);
|
|
34
|
+
const differ = [];
|
|
35
|
+
const missing = [];
|
|
36
|
+
for (const rel of files) {
|
|
37
|
+
const a = hashFile(path.join(workspaceMcpDir, rel), io);
|
|
38
|
+
const b = hashFile(path.join(runtimeDir, rel), io);
|
|
39
|
+
if (b === null) missing.push(rel);
|
|
40
|
+
else if (a !== b) differ.push(rel);
|
|
41
|
+
}
|
|
42
|
+
return { ok: differ.length === 0 && missing.length === 0, differ, missing, checked: files.length };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function versionOf(serverFile, { read = fs.readFileSync } = {}) {
|
|
46
|
+
try {
|
|
47
|
+
const m = /VERSION\s*=\s*["']([^"']+)["']/.exec(String(read(serverFile, "utf8")).slice(0, 20000));
|
|
48
|
+
return m ? m[1] : null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function provenanceReport({ launcher, custom, workspaceMcpDir, runtimeDir, io = {} }) {
|
|
55
|
+
const serverFile = custom ? null : path.join(runtimeDir, "server.mjs");
|
|
56
|
+
const ver = versionOf(serverFile || path.join(workspaceMcpDir, "server.mjs"), io);
|
|
57
|
+
if (custom) {
|
|
58
|
+
return {
|
|
59
|
+
line: `server 来源 ${launcher}(自定义启动器,不比对;版本以它实际拉起的那份为准)`,
|
|
60
|
+
fatal: null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const cmp = compareInstalledMcp(workspaceMcpDir, runtimeDir, io);
|
|
64
|
+
const line = `server 来源 ${serverFile}(已安装副本 ${ver || "版本未知"},mcp/ 比对 ${cmp.checked} 个模块)`;
|
|
65
|
+
if (cmp.ok) return { line, fatal: null };
|
|
66
|
+
const bad = [...cmp.differ.map((f) => `${f}(内容不同)`), ...cmp.missing.map((f) => `${f}(没装过去)`)];
|
|
67
|
+
return {
|
|
68
|
+
line,
|
|
69
|
+
fatal:
|
|
70
|
+
`已安装的 server 与工作区不一致,这一轮测的不是你改的代码:\n` +
|
|
71
|
+
bad.map((b) => ` - ${b}`).join("\n") +
|
|
72
|
+
`\n 先 \`node scripts/install.mjs\` 把改动装上,或者用 AGENT_IN_CHROME_E2E_LAUNCHER 指一个跑工作区代码的启动器。`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 用 ext-key.pem 把 extension/ 打成签名的 CRX3。
|
|
3
|
+
// node scripts/pack-crx.mjs → dist/agent-in-chrome.crx
|
|
4
|
+
// 私钥缺失(仓库根目录没有 ext-key.pem)直接退出码 1,不产出半成品。
|
|
5
|
+
// CRX3 结构:
|
|
6
|
+
// "Cr24" | uint32le(3) | uint32le(headerLen) | CrxFileHeader(protobuf) | zip
|
|
7
|
+
// 签名覆盖的字节是:
|
|
8
|
+
// "CRX3 SignedData\0" | uint32le(len(signedHeaderData)) | signedHeaderData | zip
|
|
9
|
+
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
|
|
16
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
17
|
+
const EXT_DIR = path.join(ROOT, "extension");
|
|
18
|
+
const KEY = path.join(ROOT, "ext-key.pem");
|
|
19
|
+
const OUT_DIR = path.join(ROOT, "dist");
|
|
20
|
+
const OUT = path.join(OUT_DIR, "agent-in-chrome.crx");
|
|
21
|
+
|
|
22
|
+
function varint(n) {
|
|
23
|
+
const out = [];
|
|
24
|
+
while (n > 0x7f) {
|
|
25
|
+
out.push((n & 0x7f) | 0x80);
|
|
26
|
+
n >>>= 7;
|
|
27
|
+
}
|
|
28
|
+
out.push(n);
|
|
29
|
+
return Buffer.from(out);
|
|
30
|
+
}
|
|
31
|
+
function field(num, payload) {
|
|
32
|
+
return Buffer.concat([varint((num << 3) | 2), varint(payload.length), payload]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!fs.existsSync(KEY)) {
|
|
36
|
+
console.error(`找不到私钥 ${KEY}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
fs.mkdirSync(OUT_DIR, { recursive: true });
|
|
40
|
+
|
|
41
|
+
const version = JSON.parse(fs.readFileSync(path.join(EXT_DIR, "manifest.json"), "utf8")).version;
|
|
42
|
+
|
|
43
|
+
const zipPath = path.join(OUT_DIR, "extension.zip");
|
|
44
|
+
fs.rmSync(zipPath, { force: true });
|
|
45
|
+
execFileSync("/usr/bin/zip", ["-r", "-X", "-q", zipPath, "."], { cwd: EXT_DIR });
|
|
46
|
+
const zip = fs.readFileSync(zipPath);
|
|
47
|
+
|
|
48
|
+
const pubDer = crypto.createPublicKey(fs.readFileSync(KEY)).export({ type: "spki", format: "der" });
|
|
49
|
+
const digest = crypto.createHash("sha256").update(pubDer).digest();
|
|
50
|
+
const crxId = digest.subarray(0, 16);
|
|
51
|
+
const extId = [...crxId]
|
|
52
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
53
|
+
.join("")
|
|
54
|
+
.split("")
|
|
55
|
+
.map((c) => String.fromCharCode(c.charCodeAt(0) + (c >= "0" && c <= "9" ? 49 : 10)))
|
|
56
|
+
.join("");
|
|
57
|
+
|
|
58
|
+
const signedHeaderData = field(1, crxId);
|
|
59
|
+
|
|
60
|
+
const lenLE = Buffer.alloc(4);
|
|
61
|
+
lenLE.writeUInt32LE(signedHeaderData.length, 0);
|
|
62
|
+
const payload = Buffer.concat([Buffer.from("CRX3 SignedData\0", "binary"), lenLE, signedHeaderData, zip]);
|
|
63
|
+
const signature = crypto.sign("sha256", payload, {
|
|
64
|
+
key: fs.readFileSync(KEY),
|
|
65
|
+
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const proof = Buffer.concat([field(1, pubDer), field(2, signature)]);
|
|
69
|
+
const header = Buffer.concat([field(2, proof), field(10000, signedHeaderData)]);
|
|
70
|
+
|
|
71
|
+
const magic = Buffer.from("Cr24", "binary");
|
|
72
|
+
const ver = Buffer.alloc(4);
|
|
73
|
+
ver.writeUInt32LE(3, 0);
|
|
74
|
+
const hlen = Buffer.alloc(4);
|
|
75
|
+
hlen.writeUInt32LE(header.length, 0);
|
|
76
|
+
fs.writeFileSync(OUT, Buffer.concat([magic, ver, hlen, header, zip]));
|
|
77
|
+
fs.rmSync(zipPath, { force: true });
|
|
78
|
+
|
|
79
|
+
console.log(`打包完成 ${OUT}`);
|
|
80
|
+
console.log(` 版本 ${version}`);
|
|
81
|
+
console.log(` 扩展 ID ${extId}`);
|
|
82
|
+
console.log(` 大小 ${(fs.statSync(OUT).size / 1024).toFixed(1)} KB`);
|
package/scripts/pick.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Agent in Chrome — 终端多选清单(零依赖)
|
|
2
|
+
// 交互约定:
|
|
3
|
+
// ↑↓ / kj 移动 空格 勾选/取消 a 全选/全不选
|
|
4
|
+
// 回车 确认 Ctrl-C / Esc / q 取消(返回 null,调用方据此中止,不是当成全不选)
|
|
5
|
+
// 铁律:非 TTY 一律不进这里。agent 代跑、CI、管道输入时挂在 stdin 上等按键,
|
|
6
|
+
// 表现是安装命令永远不返回——比少问一句严重得多。调用方负责判断,这里再兜一层底。
|
|
7
|
+
|
|
8
|
+
import readline from "node:readline";
|
|
9
|
+
|
|
10
|
+
function glyphs(platform) {
|
|
11
|
+
return platform === "win32" ? { on: "[x]", off: "[ ]", cur: ">", pad: " " } : { on: "◉", off: "◯", cur: "❯", pad: " " };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ESC = "\x1b";
|
|
15
|
+
const DIM = `${ESC}[2m`;
|
|
16
|
+
const BOLD = `${ESC}[1m`;
|
|
17
|
+
const CYAN = `${ESC}[36m`;
|
|
18
|
+
const RESET = `${ESC}[0m`;
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* items: [{ label, note }],note 是右侧的灰色补充(这里放要改的配置文件路径)
|
|
22
|
+
* 返回被选中项的下标数组;用户主动取消时返回 null。
|
|
23
|
+
*/
|
|
24
|
+
export async function pickMulti(items, opts = {}) {
|
|
25
|
+
const {
|
|
26
|
+
title = "",
|
|
27
|
+
hint = "↑↓ 移动 空格 选/不选 a 全选 回车 确认",
|
|
28
|
+
input = process.stdin,
|
|
29
|
+
output = process.stdout,
|
|
30
|
+
platform = process.platform,
|
|
31
|
+
selected = items.map(() => true),
|
|
32
|
+
} = opts;
|
|
33
|
+
|
|
34
|
+
if (!items.length) return [];
|
|
35
|
+
if (!input.isTTY || typeof input.setRawMode !== "function") {
|
|
36
|
+
return items.map((_, i) => i).filter((i) => selected[i]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const g = glyphs(platform);
|
|
40
|
+
const width = (s) => [...s].reduce((n, c) => n + (/[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/.test(c) ? 2 : 1), 0);
|
|
41
|
+
const labelW = Math.max(...items.map((it) => width(it.label)));
|
|
42
|
+
const padLabel = (s) => s + " ".repeat(Math.max(0, labelW - width(s)));
|
|
43
|
+
const marks = selected.slice();
|
|
44
|
+
let cur = 0;
|
|
45
|
+
let drawn = 0;
|
|
46
|
+
|
|
47
|
+
const render = () => {
|
|
48
|
+
const lines = [];
|
|
49
|
+
if (title) lines.push(title);
|
|
50
|
+
for (let i = 0; i < items.length; i++) {
|
|
51
|
+
const pointer = i === cur ? `${CYAN}${g.cur}${RESET}` : g.pad;
|
|
52
|
+
const box = marks[i] ? `${CYAN}${g.on}${RESET}` : `${DIM}${g.off}${RESET}`;
|
|
53
|
+
const text = items[i].note ? padLabel(items[i].label) : items[i].label;
|
|
54
|
+
const label = i === cur ? `${BOLD}${text}${RESET}` : text;
|
|
55
|
+
const note = items[i].note ? ` ${DIM}${items[i].note}${RESET}` : "";
|
|
56
|
+
lines.push(` ${pointer} ${box} ${label}${note}`);
|
|
57
|
+
}
|
|
58
|
+
lines.push(` ${DIM}${hint}${RESET}`);
|
|
59
|
+
|
|
60
|
+
let out = "";
|
|
61
|
+
if (drawn) out += `${ESC}[${drawn}A`;
|
|
62
|
+
for (const l of lines) out += `${ESC}[2K${l}\n`;
|
|
63
|
+
output.write(out);
|
|
64
|
+
drawn = lines.length;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
readline.emitKeypressEvents(input);
|
|
68
|
+
const wasRaw = input.isRaw;
|
|
69
|
+
input.setRawMode(true);
|
|
70
|
+
output.write(`${ESC}[?25l`);
|
|
71
|
+
const wasPaused = input.isPaused();
|
|
72
|
+
input.resume();
|
|
73
|
+
|
|
74
|
+
const cleanup = () => {
|
|
75
|
+
input.removeListener("keypress", onKey);
|
|
76
|
+
try {
|
|
77
|
+
input.setRawMode(!!wasRaw);
|
|
78
|
+
} catch {}
|
|
79
|
+
if (wasPaused) input.pause();
|
|
80
|
+
output.write(`${ESC}[?25h`);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
let done;
|
|
84
|
+
const result = new Promise((r) => (done = r));
|
|
85
|
+
|
|
86
|
+
function onKey(str, key = {}) {
|
|
87
|
+
const name = key.name || "";
|
|
88
|
+
if ((key.ctrl && name === "c") || name === "escape" || name === "q") {
|
|
89
|
+
render();
|
|
90
|
+
cleanup();
|
|
91
|
+
done(null);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (name === "up" || name === "k") cur = (cur - 1 + items.length) % items.length;
|
|
95
|
+
else if (name === "down" || name === "j") cur = (cur + 1) % items.length;
|
|
96
|
+
else if (name === "space") marks[cur] = !marks[cur];
|
|
97
|
+
else if (name === "a") {
|
|
98
|
+
const allOn = marks.every(Boolean);
|
|
99
|
+
for (let i = 0; i < marks.length; i++) marks[i] = !allOn;
|
|
100
|
+
} else if (name === "return" || name === "enter") {
|
|
101
|
+
render();
|
|
102
|
+
cleanup();
|
|
103
|
+
done(marks.map((m, i) => (m ? i : -1)).filter((i) => i >= 0));
|
|
104
|
+
return;
|
|
105
|
+
} else if (str === " ") {
|
|
106
|
+
marks[cur] = !marks[cur];
|
|
107
|
+
} else return;
|
|
108
|
+
render();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
input.on("keypress", onKey);
|
|
112
|
+
render();
|
|
113
|
+
return result;
|
|
114
|
+
}
|