@hangox/mg-cli 1.3.3 → 1.5.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/bin/mg-native-host.js +2 -0
- package/dist/cli.js +1039 -90
- package/dist/cli.js.map +1 -1
- package/dist/daemon-runner.js +12 -1
- package/dist/daemon-runner.js.map +1 -1
- package/dist/{index-AVsoGQ0e.d.ts → index-DuCpsEXk.d.ts} +341 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/dist/native-host.js +349 -0
- package/dist/native-host.js.map +1 -0
- package/dist/postinstall.js +132 -0
- package/dist/postinstall.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +12 -1
- package/dist/server.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
|
|
4
|
+
// src/scripts/register-utils.ts
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import os from "os";
|
|
8
|
+
import { execSync } from "child_process";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var HOST_NAME = "com.hangox.mgplugin";
|
|
11
|
+
var EXTENSION_ID = "ddhihanlpcdneicohnglnaliefnkaeja";
|
|
12
|
+
var DESCRIPTION = "MasterGo Plugin Native Messaging Host";
|
|
13
|
+
function getBrowserPaths(browser) {
|
|
14
|
+
const home = os.homedir();
|
|
15
|
+
const platform = os.platform();
|
|
16
|
+
const browserDirs = {
|
|
17
|
+
chrome: {
|
|
18
|
+
darwin: path.join(home, "Library/Application Support/Google/Chrome/NativeMessagingHosts"),
|
|
19
|
+
linux: path.join(home, ".config/google-chrome/NativeMessagingHosts"),
|
|
20
|
+
win32: path.join(
|
|
21
|
+
process.env.APPDATA || path.join(home, "AppData/Roaming"),
|
|
22
|
+
"Google/Chrome/NativeMessagingHosts"
|
|
23
|
+
)
|
|
24
|
+
},
|
|
25
|
+
chromium: {
|
|
26
|
+
darwin: path.join(home, "Library/Application Support/Chromium/NativeMessagingHosts"),
|
|
27
|
+
linux: path.join(home, ".config/chromium/NativeMessagingHosts"),
|
|
28
|
+
win32: path.join(
|
|
29
|
+
process.env.APPDATA || path.join(home, "AppData/Roaming"),
|
|
30
|
+
"Chromium/NativeMessagingHosts"
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
edge: {
|
|
34
|
+
darwin: path.join(
|
|
35
|
+
home,
|
|
36
|
+
"Library/Application Support/Microsoft Edge/NativeMessagingHosts"
|
|
37
|
+
),
|
|
38
|
+
linux: path.join(home, ".config/microsoft-edge/NativeMessagingHosts"),
|
|
39
|
+
win32: path.join(
|
|
40
|
+
process.env.APPDATA || path.join(home, "AppData/Roaming"),
|
|
41
|
+
"Microsoft/Edge/NativeMessagingHosts"
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const registryKeys = {
|
|
46
|
+
chrome: `HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\${HOST_NAME}`,
|
|
47
|
+
chromium: `HKCU\\Software\\Chromium\\NativeMessagingHosts\\${HOST_NAME}`,
|
|
48
|
+
edge: `HKCU\\Software\\Microsoft\\Edge\\NativeMessagingHosts\\${HOST_NAME}`
|
|
49
|
+
};
|
|
50
|
+
const manifestDir = browserDirs[browser][platform];
|
|
51
|
+
if (!manifestDir) {
|
|
52
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684\u5E73\u53F0: ${platform}`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
manifestDir,
|
|
56
|
+
registryKey: platform === "win32" ? registryKeys[browser] : void 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getNativeHostPath() {
|
|
60
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
61
|
+
const distDir = path.dirname(currentFile);
|
|
62
|
+
return path.join(distDir, "native-host.js");
|
|
63
|
+
}
|
|
64
|
+
function createManifest() {
|
|
65
|
+
return {
|
|
66
|
+
name: HOST_NAME,
|
|
67
|
+
description: DESCRIPTION,
|
|
68
|
+
path: getNativeHostPath(),
|
|
69
|
+
type: "stdio",
|
|
70
|
+
allowed_origins: [`chrome-extension://${EXTENSION_ID}/`]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function register(browser = "chrome") {
|
|
74
|
+
const config = getBrowserPaths(browser);
|
|
75
|
+
const manifestPath = path.join(config.manifestDir, `${HOST_NAME}.json`);
|
|
76
|
+
const manifest = createManifest();
|
|
77
|
+
console.log("\u6B63\u5728\u6CE8\u518C Native Messaging Host...");
|
|
78
|
+
console.log(` Host Name: ${HOST_NAME}`);
|
|
79
|
+
console.log(` Extension ID: ${EXTENSION_ID}`);
|
|
80
|
+
console.log(` Browser: ${browser}`);
|
|
81
|
+
console.log(` Native Host: ${manifest.path}`);
|
|
82
|
+
console.log(` Manifest: ${manifestPath}`);
|
|
83
|
+
fs.mkdirSync(config.manifestDir, { recursive: true });
|
|
84
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
85
|
+
if (os.platform() !== "win32") {
|
|
86
|
+
try {
|
|
87
|
+
fs.chmodSync(manifest.path, "755");
|
|
88
|
+
} catch {
|
|
89
|
+
console.warn(" \u26A0\uFE0F \u65E0\u6CD5\u8BBE\u7F6E\u6267\u884C\u6743\u9650\uFF0C\u53EF\u80FD\u9700\u8981\u624B\u52A8\u8BBE\u7F6E");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (config.registryKey) {
|
|
93
|
+
try {
|
|
94
|
+
execSync(`reg add "${config.registryKey}" /ve /t REG_SZ /d "${manifestPath}" /f`, {
|
|
95
|
+
stdio: "pipe"
|
|
96
|
+
});
|
|
97
|
+
console.log(" \u2713 Windows \u6CE8\u518C\u8868\u5DF2\u66F4\u65B0");
|
|
98
|
+
} catch {
|
|
99
|
+
console.warn(" \u26A0\uFE0F \u6CE8\u518C\u8868\u5199\u5165\u5931\u8D25\uFF0C\u53EF\u80FD\u9700\u8981\u7BA1\u7406\u5458\u6743\u9650");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
console.log("\u2713 Native Messaging Host \u6CE8\u518C\u6210\u529F");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/scripts/postinstall.ts
|
|
106
|
+
function isGlobalInstall() {
|
|
107
|
+
if (process.env.npm_config_global === "true") return true;
|
|
108
|
+
const pnpmPatterns = ["/pnpm/global/", "/.local/share/pnpm/", "/pnpm-global/"];
|
|
109
|
+
if (pnpmPatterns.some((p) => __dirname.includes(p))) return true;
|
|
110
|
+
const yarnPatterns = ["/.config/yarn/global/", "/yarn/global/"];
|
|
111
|
+
if (yarnPatterns.some((p) => __dirname.includes(p))) return true;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
function main() {
|
|
115
|
+
if (!isGlobalInstall()) {
|
|
116
|
+
console.log("[mg-cli] \u672C\u5730\u5B89\u88C5\uFF0C\u8DF3\u8FC7 Native Host \u6CE8\u518C");
|
|
117
|
+
console.log("[mg-cli] \u5982\u9700\u6CE8\u518C\uFF0C\u8BF7\u8FD0\u884C: npx @hangox/mg-cli register");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
console.log("[mg-cli] \u68C0\u6D4B\u5230\u5168\u5C40\u5B89\u88C5\uFF0C\u5F00\u59CB\u6CE8\u518C Native Messaging Host...");
|
|
121
|
+
console.log(`[mg-cli] Host Name: ${HOST_NAME}`);
|
|
122
|
+
console.log(`[mg-cli] Extension ID: ${EXTENSION_ID}`);
|
|
123
|
+
try {
|
|
124
|
+
register("chrome");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error("[mg-cli] Native Host \u6CE8\u518C\u5931\u8D25:", error);
|
|
127
|
+
console.log("\n[mg-cli] \u8BF7\u624B\u52A8\u8FD0\u884C: npx @hangox/mg-cli register");
|
|
128
|
+
process.exitCode = 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
main();
|
|
132
|
+
//# sourceMappingURL=postinstall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scripts/register-utils.ts","../src/scripts/postinstall.ts"],"sourcesContent":["/**\n * Native Messaging Host 注册辅助函数\n * 支持 macOS, Linux, Windows\n */\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport os from 'node:os'\nimport { execSync } from 'node:child_process'\nimport { fileURLToPath } from 'node:url'\n\n// ==================== 配置常量 ====================\n\nexport const HOST_NAME = 'com.hangox.mgplugin'\nexport const EXTENSION_ID = 'ddhihanlpcdneicohnglnaliefnkaeja'\nconst DESCRIPTION = 'MasterGo Plugin Native Messaging Host'\n\n// ==================== 平台适配 ====================\n\ntype BrowserType = 'chrome' | 'chromium' | 'edge'\n\ninterface PlatformConfig {\n manifestDir: string\n registryKey?: string // Windows only\n}\n\nfunction getBrowserPaths(browser: BrowserType): PlatformConfig {\n const home = os.homedir()\n const platform = os.platform()\n\n const browserDirs: Record<BrowserType, Record<string, string>> = {\n chrome: {\n darwin: path.join(home, 'Library/Application Support/Google/Chrome/NativeMessagingHosts'),\n linux: path.join(home, '.config/google-chrome/NativeMessagingHosts'),\n win32: path.join(\n process.env.APPDATA || path.join(home, 'AppData/Roaming'),\n 'Google/Chrome/NativeMessagingHosts'\n ),\n },\n chromium: {\n darwin: path.join(home, 'Library/Application Support/Chromium/NativeMessagingHosts'),\n linux: path.join(home, '.config/chromium/NativeMessagingHosts'),\n win32: path.join(\n process.env.APPDATA || path.join(home, 'AppData/Roaming'),\n 'Chromium/NativeMessagingHosts'\n ),\n },\n edge: {\n darwin: path.join(\n home,\n 'Library/Application Support/Microsoft Edge/NativeMessagingHosts'\n ),\n linux: path.join(home, '.config/microsoft-edge/NativeMessagingHosts'),\n win32: path.join(\n process.env.APPDATA || path.join(home, 'AppData/Roaming'),\n 'Microsoft/Edge/NativeMessagingHosts'\n ),\n },\n }\n\n const registryKeys: Record<BrowserType, string> = {\n chrome: `HKCU\\\\Software\\\\Google\\\\Chrome\\\\NativeMessagingHosts\\\\${HOST_NAME}`,\n chromium: `HKCU\\\\Software\\\\Chromium\\\\NativeMessagingHosts\\\\${HOST_NAME}`,\n edge: `HKCU\\\\Software\\\\Microsoft\\\\Edge\\\\NativeMessagingHosts\\\\${HOST_NAME}`,\n }\n\n const manifestDir = browserDirs[browser][platform]\n if (!manifestDir) {\n throw new Error(`不支持的平台: ${platform}`)\n }\n\n return {\n manifestDir,\n registryKey: platform === 'win32' ? registryKeys[browser] : undefined,\n }\n}\n\n// ==================== Manifest 生成 ====================\n\nfunction getNativeHostPath(): string {\n // 获取当前文件位置,推算 native-host 入口\n const currentFile = fileURLToPath(import.meta.url)\n const distDir = path.dirname(currentFile)\n return path.join(distDir, 'native-host.js')\n}\n\nfunction createManifest(): { name: string; description: string; path: string; type: string; allowed_origins: string[] } {\n return {\n name: HOST_NAME,\n description: DESCRIPTION,\n path: getNativeHostPath(),\n type: 'stdio',\n allowed_origins: [`chrome-extension://${EXTENSION_ID}/`],\n }\n}\n\n// ==================== 注册逻辑 ====================\n\nexport function register(browser: BrowserType = 'chrome'): void {\n const config = getBrowserPaths(browser)\n const manifestPath = path.join(config.manifestDir, `${HOST_NAME}.json`)\n const manifest = createManifest()\n\n console.log('正在注册 Native Messaging Host...')\n console.log(` Host Name: ${HOST_NAME}`)\n console.log(` Extension ID: ${EXTENSION_ID}`)\n console.log(` Browser: ${browser}`)\n console.log(` Native Host: ${manifest.path}`)\n console.log(` Manifest: ${manifestPath}`)\n\n // 1. 确保目录存在\n fs.mkdirSync(config.manifestDir, { recursive: true })\n\n // 2. 写入 manifest\n fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))\n\n // 3. 设置执行权限 (Unix)\n if (os.platform() !== 'win32') {\n try {\n fs.chmodSync(manifest.path, '755')\n } catch {\n console.warn(' ⚠️ 无法设置执行权限,可能需要手动设置')\n }\n }\n\n // 4. Windows: 写入注册表\n if (config.registryKey) {\n try {\n execSync(`reg add \"${config.registryKey}\" /ve /t REG_SZ /d \"${manifestPath}\" /f`, {\n stdio: 'pipe',\n })\n console.log(' ✓ Windows 注册表已更新')\n } catch {\n console.warn(' ⚠️ 注册表写入失败,可能需要管理员权限')\n }\n }\n\n console.log('✓ Native Messaging Host 注册成功')\n}\n\nexport function unregister(browser: BrowserType = 'chrome'): void {\n const config = getBrowserPaths(browser)\n const manifestPath = path.join(config.manifestDir, `${HOST_NAME}.json`)\n\n // 删除 manifest 文件\n if (fs.existsSync(manifestPath)) {\n fs.unlinkSync(manifestPath)\n console.log(` 已删除: ${manifestPath}`)\n }\n\n // Windows: 删除注册表项\n if (config.registryKey) {\n try {\n execSync(`reg delete \"${config.registryKey}\" /f`, { stdio: 'pipe' })\n console.log(' ✓ Windows 注册表项已删除')\n } catch {\n // 忽略不存在的情况\n }\n }\n}\n\nexport function checkRegistration(browser: BrowserType = 'chrome'): {\n registered: boolean\n manifestPath?: string\n manifest?: unknown\n} {\n const config = getBrowserPaths(browser)\n const manifestPath = path.join(config.manifestDir, `${HOST_NAME}.json`)\n\n if (!fs.existsSync(manifestPath)) {\n return { registered: false }\n }\n\n try {\n const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))\n return {\n registered: true,\n manifestPath,\n manifest,\n }\n } catch {\n return { registered: false, manifestPath }\n }\n}\n","#!/usr/bin/env node\n/**\n * npm postinstall 脚本\n * 全局安装时自动注册 Native Messaging Host\n */\n\nimport { register, HOST_NAME, EXTENSION_ID } from './register-utils.js'\n\n// ==================== 入口 ====================\n\nfunction isGlobalInstall(): boolean {\n // npm 全局安装\n if (process.env.npm_config_global === 'true') return true\n\n // pnpm 全局安装检测\n const pnpmPatterns = ['/pnpm/global/', '/.local/share/pnpm/', '/pnpm-global/']\n if (pnpmPatterns.some((p) => __dirname.includes(p))) return true\n\n // yarn 全局安装检测\n const yarnPatterns = ['/.config/yarn/global/', '/yarn/global/']\n if (yarnPatterns.some((p) => __dirname.includes(p))) return true\n\n return false\n}\n\nfunction main(): void {\n // 仅全局安装时执行\n if (!isGlobalInstall()) {\n console.log('[mg-cli] 本地安装,跳过 Native Host 注册')\n console.log('[mg-cli] 如需注册,请运行: npx @hangox/mg-cli register')\n return\n }\n\n console.log('[mg-cli] 检测到全局安装,开始注册 Native Messaging Host...')\n console.log(`[mg-cli] Host Name: ${HOST_NAME}`)\n console.log(`[mg-cli] Extension ID: ${EXTENSION_ID}`)\n\n try {\n register('chrome')\n } catch (error) {\n console.error('[mg-cli] Native Host 注册失败:', error)\n console.log('\\n[mg-cli] 请手动运行: npx @hangox/mg-cli register')\n // 不要让 postinstall 失败阻止安装\n process.exitCode = 0\n }\n}\n\nmain()\n"],"mappings":";;;;AAKA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAIvB,IAAM,YAAY;AAClB,IAAM,eAAe;AAC5B,IAAM,cAAc;AAWpB,SAAS,gBAAgB,SAAsC;AAC7D,QAAM,OAAO,GAAG,QAAQ;AACxB,QAAM,WAAW,GAAG,SAAS;AAE7B,QAAM,cAA2D;AAAA,IAC/D,QAAQ;AAAA,MACN,QAAQ,KAAK,KAAK,MAAM,gEAAgE;AAAA,MACxF,OAAO,KAAK,KAAK,MAAM,4CAA4C;AAAA,MACnE,OAAO,KAAK;AAAA,QACV,QAAQ,IAAI,WAAW,KAAK,KAAK,MAAM,iBAAiB;AAAA,QACxD;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,QAAQ,KAAK,KAAK,MAAM,2DAA2D;AAAA,MACnF,OAAO,KAAK,KAAK,MAAM,uCAAuC;AAAA,MAC9D,OAAO,KAAK;AAAA,QACV,QAAQ,IAAI,WAAW,KAAK,KAAK,MAAM,iBAAiB;AAAA,QACxD;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,QAAQ,KAAK;AA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;AACF;AAEA,KAAK;","names":[]}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ay as ConnectionManager, aD as LogLevel, aB as Logger, aE as LoggerOptions, av as MGServer, az as ManagedWebSocket, aA as RequestHandler, ax as ServerOptions, aC as createLogger, aw as createServer } from './index-DuCpsEXk.js';
|
|
2
2
|
import 'ws';
|
package/dist/server.js
CHANGED
|
@@ -21,6 +21,7 @@ var SERVER_LOG_FILE = join(LOG_DIR, "server.log");
|
|
|
21
21
|
var HEARTBEAT_INTERVAL = 3e4;
|
|
22
22
|
var HEARTBEAT_TIMEOUT = 9e4;
|
|
23
23
|
var REQUEST_TIMEOUT = 3e4;
|
|
24
|
+
var MAX_REQUEST_TIMEOUT = 6e5;
|
|
24
25
|
|
|
25
26
|
// src/shared/errors.ts
|
|
26
27
|
var ErrorNames = {
|
|
@@ -42,6 +43,8 @@ var ErrorNames = {
|
|
|
42
43
|
["E016" /* SERVER_ALREADY_RUNNING */]: "SERVER_ALREADY_RUNNING",
|
|
43
44
|
["E017" /* CONNECTION_LOST */]: "CONNECTION_LOST",
|
|
44
45
|
["E018" /* NO_EXTENSION_CONNECTED */]: "NO_EXTENSION_CONNECTED",
|
|
46
|
+
["E019" /* EDIT_NOT_ALLOWED */]: "EDIT_NOT_ALLOWED",
|
|
47
|
+
["E020" /* CREATE_NODE_FAILED */]: "CREATE_NODE_FAILED",
|
|
45
48
|
["E099" /* UNKNOWN_ERROR */]: "UNKNOWN_ERROR"
|
|
46
49
|
};
|
|
47
50
|
var ErrorMessages = {
|
|
@@ -63,6 +66,8 @@ var ErrorMessages = {
|
|
|
63
66
|
["E016" /* SERVER_ALREADY_RUNNING */]: "Server \u5DF2\u5728\u8FD0\u884C\u4E2D",
|
|
64
67
|
["E017" /* CONNECTION_LOST */]: "\u8FDE\u63A5\u65AD\u5F00",
|
|
65
68
|
["E018" /* NO_EXTENSION_CONNECTED */]: "\u6CA1\u6709 Chrome \u6269\u5C55\u8FDE\u63A5\u5230 Server\u3002\u8BF7\u786E\u4FDD\u6D4F\u89C8\u5668\u5DF2\u6253\u5F00\u5E76\u5B89\u88C5\u4E86 MG Plugin",
|
|
69
|
+
["E019" /* EDIT_NOT_ALLOWED */]: "\u9875\u9762\u53EA\u8BFB\u6216\u65E0\u7F16\u8F91\u6743\u9650\uFF0C\u65E0\u6CD5\u6267\u884C\u5199\u64CD\u4F5C",
|
|
70
|
+
["E020" /* CREATE_NODE_FAILED */]: "\u521B\u5EFA\u8282\u70B9\u5931\u8D25\uFF08\u6839\u8282\u70B9\u65E0\u6CD5\u521B\u5EFA\uFF09",
|
|
66
71
|
["E099" /* UNKNOWN_ERROR */]: "\u672A\u77E5\u9519\u8BEF"
|
|
67
72
|
};
|
|
68
73
|
var MGError = class extends Error {
|
|
@@ -445,6 +450,12 @@ var ConnectionManager = class {
|
|
|
445
450
|
};
|
|
446
451
|
|
|
447
452
|
// src/server/request-handler.ts
|
|
453
|
+
function resolveRequestTimeout(timeoutMs) {
|
|
454
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
455
|
+
return REQUEST_TIMEOUT;
|
|
456
|
+
}
|
|
457
|
+
return Math.min(timeoutMs, MAX_REQUEST_TIMEOUT);
|
|
458
|
+
}
|
|
448
459
|
var RequestHandler = class {
|
|
449
460
|
logger;
|
|
450
461
|
connectionManager;
|
|
@@ -477,7 +488,7 @@ var RequestHandler = class {
|
|
|
477
488
|
}
|
|
478
489
|
const timer = setTimeout(() => {
|
|
479
490
|
this.handleTimeout(requestId);
|
|
480
|
-
},
|
|
491
|
+
}, resolveRequestTimeout(message.timeoutMs));
|
|
481
492
|
this.pendingRequests.set(requestId, {
|
|
482
493
|
id: requestId,
|
|
483
494
|
consumer,
|