jtcrpa-mcp 0.6.1 → 0.6.2
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/bin/cli.mjs +1 -1
- package/dist/codex-setup.js +1 -1
- package/dist/install.js +4 -4
- package/dist/mac-chrome.js +12 -6
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const usage = [
|
|
|
13
13
|
' connect-codex (--chrome-id <扩展ID> | --firefox-id <扩展ID>) --instance <UUID> --setup <UUID>',
|
|
14
14
|
' config (--connection <连接编号> | --instance <UUID>) [--client codex|claude|deepseek]',
|
|
15
15
|
' mcp (--connection <配置中的绑定UUID> | --instance <实例UUID>)',
|
|
16
|
-
' macOS Chrome 的 add 和 connect-codex 可加 --chrome-user-data-dir <用户数据根目录>',
|
|
16
|
+
' macOS 版 Chrome 和 Edge 的 add 和 connect-codex 可加 --chrome-user-data-dir <用户数据根目录>',
|
|
17
17
|
'维护',
|
|
18
18
|
' uninstall 清除当前用户的本机宿主登记',
|
|
19
19
|
' --version 显示桥接器版本',
|
package/dist/codex-setup.js
CHANGED
|
@@ -51,7 +51,7 @@ export async function connectCodex(args) {
|
|
|
51
51
|
const directory = values['chrome-user-data-dir'];
|
|
52
52
|
if (directory !== undefined)
|
|
53
53
|
registration.push('--chrome-user-data-dir', directory);
|
|
54
|
-
await manageHostRegistration('add', registration);
|
|
54
|
+
await manageHostRegistration('add', registration, { fromRunningBrowser: true });
|
|
55
55
|
console.log('正在等待发起接入的浏览器…');
|
|
56
56
|
const setup = await bindCodexBrowser(target, instanceId, ticket);
|
|
57
57
|
console.log(setup.displayName + ' 已就绪。Codex MCP 服务名为 ' + setup.name);
|
package/dist/install.js
CHANGED
|
@@ -28,7 +28,7 @@ function installationPaths() {
|
|
|
28
28
|
const launcher = process.platform === 'darwin' ? 'host.sh' : 'host.cmd';
|
|
29
29
|
return { root, record: path.join(root, 'installation.json'), launcher: path.join(root, launcher) };
|
|
30
30
|
}
|
|
31
|
-
export async function manageHostRegistration(command, args) {
|
|
31
|
+
export async function manageHostRegistration(command, args, { fromRunningBrowser = false } = {}) {
|
|
32
32
|
if (command === 'uninstall' && args.length)
|
|
33
33
|
throw new Error('uninstall does not accept arguments. See jtcrpa-mcp uninstall --help.');
|
|
34
34
|
const paths = installationPaths();
|
|
@@ -36,7 +36,7 @@ export async function manageHostRegistration(command, args) {
|
|
|
36
36
|
if (command === 'uninstall')
|
|
37
37
|
uninstallNativeHost(paths);
|
|
38
38
|
else {
|
|
39
|
-
const { targets, instanceId, chromeDataDir } = parseBrowserTargets(args);
|
|
39
|
+
const { targets, instanceId, chromeDataDir } = parseBrowserTargets(args, fromRunningBrowser);
|
|
40
40
|
addNativeHost(paths, targets, instanceId, chromeDataDir);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
@@ -151,7 +151,7 @@ function uninstallNativeHost(paths) {
|
|
|
151
151
|
removeFileIfPresent(paths.launcher);
|
|
152
152
|
console.log('Native host unregistered.');
|
|
153
153
|
}
|
|
154
|
-
function parseBrowserTargets(args) {
|
|
154
|
+
function parseBrowserTargets(args, fromRunningBrowser) {
|
|
155
155
|
const { values } = parseArgs({ args, options: {
|
|
156
156
|
'chrome-user-data-dir': { type: 'string' }, 'chrome-id': { type: 'string' }, 'firefox-id': { type: 'string' }, instance: { type: 'string' },
|
|
157
157
|
} });
|
|
@@ -174,7 +174,7 @@ function parseBrowserTargets(args) {
|
|
|
174
174
|
if (explicit !== undefined && (!chrome || process.platform !== 'darwin')) {
|
|
175
175
|
throw new Error('--chrome-user-data-dir 仅适用于 macOS 上的 --chrome-id。');
|
|
176
176
|
}
|
|
177
|
-
const chromeDataDir = chrome && process.platform === 'darwin' ? resolveChromeDataDir(chrome, explicit) : undefined;
|
|
177
|
+
const chromeDataDir = chrome && process.platform === 'darwin' ? resolveChromeDataDir(chrome, explicit, fromRunningBrowser) : undefined;
|
|
178
178
|
return { targets, instanceId: values.instance, chromeDataDir };
|
|
179
179
|
}
|
|
180
180
|
function prepareInstallationDirectory(root) {
|
package/dist/mac-chrome.js
CHANGED
|
@@ -6,11 +6,13 @@ export const defaultChromeDataDir = () => path.join(os.homedir(), 'Library/Appli
|
|
|
6
6
|
// ps on macOS flattens argv. Keep spaces inside paths and ignore trailing
|
|
7
7
|
// positional arguments (e.g. a URL) after an existing user data directory.
|
|
8
8
|
function dataDirFromCommand(command) {
|
|
9
|
-
|
|
9
|
+
const browser = /^\/.*\/(Google Chrome|Microsoft Edge)\.app\/Contents\/MacOS\/\1(?:\s|$)/.exec(command)?.[1];
|
|
10
|
+
if (!browser)
|
|
10
11
|
return;
|
|
11
12
|
const flag = /\s--user-data-dir(?:=|\s+)(.+?)(?=\s--|$)/.exec(command);
|
|
12
13
|
if (!flag)
|
|
13
|
-
return
|
|
14
|
+
return browser === 'Microsoft Edge'
|
|
15
|
+
? path.join(os.homedir(), 'Library/Application Support/Microsoft Edge') : defaultChromeDataDir();
|
|
14
16
|
let value = flag[1].trim();
|
|
15
17
|
while (path.isAbsolute(value)) {
|
|
16
18
|
if (fs.statSync(path.join(value, 'Local State'), { throwIfNoEntry: false })?.isFile())
|
|
@@ -22,7 +24,7 @@ function dataDirFromCommand(command) {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
function runningChromeDirs() {
|
|
25
|
-
const found = spawnSync('/usr/bin/pgrep', ['-u', String(process.getuid()), '-x', 'Google Chrome'], { encoding: 'utf8' });
|
|
27
|
+
const found = spawnSync('/usr/bin/pgrep', ['-u', String(process.getuid()), '-x', '(Google Chrome|Microsoft Edge)'], { encoding: 'utf8' });
|
|
26
28
|
const pids = found.stdout?.trim().split(/\s+/);
|
|
27
29
|
if (found.status !== 0 || !pids?.every(pid => /^\d+$/.test(pid)))
|
|
28
30
|
return new Set();
|
|
@@ -61,7 +63,7 @@ function hasExtension(root, extensionId) {
|
|
|
61
63
|
}
|
|
62
64
|
return false;
|
|
63
65
|
}
|
|
64
|
-
export function resolveChromeDataDir(extensionId, explicit) {
|
|
66
|
+
export function resolveChromeDataDir(extensionId, explicit, fromRunningBrowser = false) {
|
|
65
67
|
if (explicit !== undefined) {
|
|
66
68
|
if (!path.isAbsolute(explicit) || !fs.statSync(path.join(explicit, 'Local State'), { throwIfNoEntry: false })?.isFile()) {
|
|
67
69
|
throw new Error('--chrome-user-data-dir 需要现有 Chrome 用户数据根目录的绝对路径(含 Local State)。');
|
|
@@ -69,9 +71,13 @@ export function resolveChromeDataDir(extensionId, explicit) {
|
|
|
69
71
|
return fs.realpathSync(explicit);
|
|
70
72
|
}
|
|
71
73
|
const dirs = runningChromeDirs();
|
|
74
|
+
// connect-codex originates in a live browser. A single root is sufficient
|
|
75
|
+
// even when macOS does not allow enumeration of the profile directory.
|
|
76
|
+
if (fromRunningBrowser && dirs.size === 1)
|
|
77
|
+
return [...dirs][0];
|
|
72
78
|
const matches = [...dirs].filter(dir => hasExtension(dir, extensionId));
|
|
73
|
-
if (matches.length > 1) {
|
|
74
|
-
throw new Error('
|
|
79
|
+
if (matches.length > 1 || (fromRunningBrowser && dirs.size > 1 && !matches.length)) {
|
|
80
|
+
throw new Error('无法唯一确定 Chrome 或 Edge 的用户数据目录,请用 --chrome-user-data-dir 指定目标目录。');
|
|
75
81
|
}
|
|
76
82
|
return matches[0] ?? defaultChromeDataDir();
|
|
77
83
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jtcrpa-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "在 macOS 和 Windows 上用 Codex 等 AI 客户端连接九头虫 Agent,创建和运行网页采集工作流、读取数据集。Connect AI clients to Jiutouchong Agent on macOS and Windows via MCP to create and run web scraping workflows and read datasets.",
|
|
6
6
|
"homepage": "https://jtcrpa.com/",
|