@42ailab/42plugin 0.2.30 → 0.2.31

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/42plugin CHANGED
@@ -3,12 +3,13 @@
3
3
  /**
4
4
  * 42plugin CLI 启动脚本
5
5
  * 参考 @biomejs/biome 实现
6
+ * 增强 Windows 支持和错误处理
6
7
  */
7
8
 
8
- const { platform, arch, env, version } = process;
9
+ const { platform, arch, env, version, argv } = process;
9
10
  const { spawnSync } = require("child_process");
10
11
  const { existsSync } = require("fs");
11
- const { join } = require("path");
12
+ const { join, dirname } = require("path");
12
13
 
13
14
  const PLATFORMS = {
14
15
  win32: {
@@ -24,36 +25,170 @@ const PLATFORMS = {
24
25
  },
25
26
  };
26
27
 
28
+ // 检测包管理器
29
+ function detectPackageManager() {
30
+ if (env.npm_config_user_agent) {
31
+ if (env.npm_config_user_agent.includes("bun")) return "bun";
32
+ if (env.npm_config_user_agent.includes("yarn")) return "yarn";
33
+ if (env.npm_config_user_agent.includes("pnpm")) return "pnpm";
34
+ if (env.npm_config_user_agent.includes("npm")) return "npm";
35
+ }
36
+ if (env.npm_execpath) {
37
+ if (env.npm_execpath.includes("bun")) return "bun";
38
+ if (env.npm_execpath.includes("yarn")) return "yarn";
39
+ if (env.npm_execpath.includes("pnpm")) return "pnpm";
40
+ }
41
+ return "unknown";
42
+ }
43
+
44
+ // 诊断模式
45
+ if (argv.includes("--diagnose") || argv.includes("--debug")) {
46
+ console.log("42plugin 诊断信息:");
47
+ console.log("==================");
48
+ console.log(`平台: ${platform}`);
49
+ console.log(`架构: ${arch}`);
50
+ console.log(`Node 版本: ${version}`);
51
+ console.log(`包管理器: ${detectPackageManager()}`);
52
+ console.log(`脚本路径: ${__filename}`);
53
+ console.log(`工作目录: ${process.cwd()}`);
54
+ console.log("");
55
+
56
+ // 显示关键环境变量
57
+ console.log("环境变量:");
58
+ console.log(` npm_config_global: ${env.npm_config_global || "(未设置)"}`);
59
+ console.log(` BUN_INSTALL: ${env.BUN_INSTALL || "(未设置)"}`);
60
+ console.log(` HOME: ${env.HOME || "(未设置)"}`);
61
+ if (platform === "win32") {
62
+ console.log(` APPDATA: ${env.APPDATA || "(未设置)"}`);
63
+ console.log(` USERPROFILE: ${env.USERPROFILE || "(未设置)"}`);
64
+ }
65
+ console.log("");
66
+
67
+ // 如果只是诊断模式,显示路径检查后退出
68
+ if (argv.length === 3) {
69
+ // 只有 --diagnose 参数,进行完整诊断后退出
70
+ const binPath = env.PLUGIN_BINARY || PLATFORMS?.[platform]?.[arch];
71
+ if (binPath) {
72
+ console.log("二进制文件查找:");
73
+ console.log(` 目标包: ${binPath.split("/")[0]}/${binPath.split("/")[1]}`);
74
+ }
75
+ process.exit(0);
76
+ }
77
+ }
78
+
27
79
  const binPath = env.PLUGIN_BINARY || PLATFORMS?.[platform]?.[arch];
28
80
 
29
81
  if (binPath) {
30
82
  let resolvedPath;
83
+ const attemptedPaths = [];
31
84
 
32
85
  // 1. 优先使用 require.resolve(本地安装时有效)
33
86
  try {
34
87
  resolvedPath = require.resolve(binPath);
35
- } catch {
36
- // 2. Fallback: 查找嵌套的 node_modules(全局安装时有效)
37
- // npm/bun 全局安装时,optionalDependencies 会被安装到主包内部的 node_modules
88
+ attemptedPaths.push({ path: "require.resolve", result: resolvedPath });
89
+ } catch (e) {
90
+ attemptedPaths.push({ path: "require.resolve", result: `失败: ${e.message}` });
91
+ }
92
+
93
+ // 2. 查找嵌套的 node_modules(全局安装时有效)
94
+ if (!resolvedPath) {
38
95
  const nestedPath = join(__dirname, "..", "node_modules", binPath);
96
+ attemptedPaths.push({ path: nestedPath, result: existsSync(nestedPath) ? "存在" : "不存在" });
39
97
  if (existsSync(nestedPath)) {
40
98
  resolvedPath = nestedPath;
41
99
  }
42
100
  }
43
101
 
102
+ // 3. Windows 特殊处理:检查多个可能的全局安装路径
103
+ if (!resolvedPath && platform === "win32") {
104
+ // 解析 scoped 包名: @42ailab/42plugin-win32-x64/bin/42plugin.exe
105
+ // 正确提取包名部分 (@42ailab/42plugin-win32-x64)
106
+ const pathParts = binPath.split("/");
107
+ const scopedPackage = pathParts[0].startsWith("@") ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0];
108
+ const binaryFile = pathParts[pathParts.length - 1];
109
+
110
+ const possiblePaths = [
111
+ // npm 全局路径
112
+ env.APPDATA && join(env.APPDATA, "npm", "node_modules", "@42ailab", "42plugin", "node_modules", binPath),
113
+ // bun 全局路径
114
+ env.USERPROFILE && join(env.USERPROFILE, ".bun", "install", "global", "node_modules", "@42ailab", "42plugin", "node_modules", binPath),
115
+ // 相对于当前脚本的路径(正确处理 scoped 包名)
116
+ join(dirname(dirname(__dirname)), scopedPackage, "bin", binaryFile),
117
+ // 兄弟包路径(hoisted 场景)
118
+ join(__dirname, "..", "..", scopedPackage, "bin", binaryFile),
119
+ ].filter(Boolean);
120
+
121
+ for (const path of possiblePaths) {
122
+ attemptedPaths.push({ path, result: existsSync(path) ? "存在" : "不存在" });
123
+ if (existsSync(path)) {
124
+ resolvedPath = path;
125
+ break;
126
+ }
127
+ }
128
+ }
129
+
130
+ // 4. Unix 系统额外检查路径
131
+ if (!resolvedPath && (platform === "darwin" || platform === "linux")) {
132
+ const possiblePaths = [
133
+ // npm 全局路径
134
+ "/usr/local/lib/node_modules/@42ailab/42plugin/node_modules/" + binPath,
135
+ join(env.HOME || "", ".npm-global/lib/node_modules/@42ailab/42plugin/node_modules", binPath),
136
+ // bun 全局路径
137
+ join(env.HOME || "", ".bun/install/global/node_modules/@42ailab/42plugin/node_modules", binPath),
138
+ ];
139
+
140
+ for (const path of possiblePaths) {
141
+ attemptedPaths.push({ path, result: existsSync(path) ? "存在" : "不存在" });
142
+ if (existsSync(path)) {
143
+ resolvedPath = path;
144
+ break;
145
+ }
146
+ }
147
+ }
148
+
44
149
  if (!resolvedPath) {
45
150
  console.error(`错误: 找不到平台二进制包 ${binPath.split("/")[0]}`);
46
151
  console.error("");
152
+
153
+ if (argv.includes("--diagnose") || argv.includes("--debug")) {
154
+ console.error("尝试的路径:");
155
+ attemptedPaths.forEach(({ path, result }) => {
156
+ console.error(` - ${path}: ${result}`);
157
+ });
158
+ console.error("");
159
+ }
160
+
47
161
  console.error("可能原因:");
48
162
  console.error(" - 包管理器未正确安装 optionalDependencies");
49
163
  console.error(" - 版本不匹配 (主包和二进制包版本不一致)");
164
+ if (platform === "win32") {
165
+ console.error(" - Windows 防病毒软件可能阻止了二进制文件下载");
166
+ console.error(" - npm/bun 缓存损坏");
167
+ }
50
168
  console.error("");
51
169
  console.error("解决方案:");
52
- console.error(" # 完全重新安装");
53
- console.error(" bun remove -g @42ailab/42plugin && bun add -g @42ailab/42plugin");
170
+
171
+ if (platform === "win32") {
172
+ console.error(" # 方法 1: 清理缓存并重新安装");
173
+ console.error(" npm cache clean --force");
174
+ console.error(" npm install -g @42ailab/42plugin --force");
175
+ console.error("");
176
+ console.error(" # 方法 2: 使用 bun (如果已安装)");
177
+ console.error(" bun remove -g @42ailab/42plugin");
178
+ console.error(" bun add -g @42ailab/42plugin");
179
+ console.error("");
180
+ console.error(" # 方法 3: 手动下载二进制文件");
181
+ console.error(" 访问 https://github.com/42ailab/42plugin/releases 下载对应版本");
182
+ } else {
183
+ console.error(" # 完全重新安装");
184
+ console.error(" bun remove -g @42ailab/42plugin && bun add -g @42ailab/42plugin");
185
+ console.error("");
186
+ console.error(" # 或使用 Homebrew (macOS 推荐)");
187
+ console.error(" brew install 42ailab/42plugin/42plugin");
188
+ }
189
+
54
190
  console.error("");
55
- console.error(" # 或使用 Homebrew (推荐)");
56
- console.error(" brew install 42ailab/42plugin/42plugin");
191
+ console.error("运行 '42plugin --diagnose' 获取详细诊断信息");
57
192
  process.exit(1);
58
193
  }
59
194
 
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 42plugin 自动修复脚本
5
+ * 用于修复常见的安装问题,特别是 Windows 平台
6
+ */
7
+
8
+ const { platform, arch, env } = process;
9
+ const { execSync } = require("child_process");
10
+ const { existsSync, rmSync, writeFileSync } = require("fs");
11
+ const { join, isAbsolute } = require("path");
12
+
13
+ // 颜色输出
14
+ const colors = {
15
+ reset: "\x1b[0m",
16
+ red: "\x1b[31m",
17
+ green: "\x1b[32m",
18
+ yellow: "\x1b[33m",
19
+ blue: "\x1b[34m",
20
+ cyan: "\x1b[36m",
21
+ };
22
+
23
+ function log(message, color = "reset") {
24
+ console.log(`${colors[color]}${message}${colors.reset}`);
25
+ }
26
+
27
+ function detectPackageManager() {
28
+ // 优先检查运行时环境变量(最准确反映用户实际使用的包管理器)
29
+ if (env.npm_config_user_agent) {
30
+ if (env.npm_config_user_agent.includes("bun")) return "bun";
31
+ if (env.npm_config_user_agent.includes("yarn")) return "yarn";
32
+ if (env.npm_config_user_agent.includes("pnpm")) return "pnpm";
33
+ if (env.npm_config_user_agent.includes("npm")) return "npm";
34
+ }
35
+
36
+ if (env.npm_execpath) {
37
+ if (env.npm_execpath.includes("bun")) return "bun";
38
+ if (env.npm_execpath.includes("yarn")) return "yarn";
39
+ if (env.npm_execpath.includes("pnpm")) return "pnpm";
40
+ if (env.npm_execpath.includes("npm")) return "npm";
41
+ }
42
+
43
+ // 检查命令可用性(回退方案,默认 npm 优先)
44
+ try {
45
+ execSync("npm --version", { stdio: "ignore" });
46
+ return "npm";
47
+ } catch {}
48
+
49
+ try {
50
+ execSync("bun --version", { stdio: "ignore" });
51
+ return "bun";
52
+ } catch {}
53
+
54
+ try {
55
+ execSync("pnpm --version", { stdio: "ignore" });
56
+ return "pnpm";
57
+ } catch {}
58
+
59
+ try {
60
+ execSync("yarn --version", { stdio: "ignore" });
61
+ return "yarn";
62
+ } catch {}
63
+
64
+ return "npm";
65
+ }
66
+
67
+ async function repair() {
68
+ log("\n🔧 42plugin 自动修复工具", "cyan");
69
+ log("=" .repeat(40), "cyan");
70
+
71
+ const packageManager = detectPackageManager();
72
+ log(`\n检测到包管理器: ${packageManager}`, "blue");
73
+ log(`平台: ${platform}-${arch}`, "blue");
74
+
75
+ // Step 1: 清理缓存
76
+ log("\n步骤 1: 清理包管理器缓存...", "yellow");
77
+ try {
78
+ switch (packageManager) {
79
+ case "npm":
80
+ execSync("npm cache clean --force", { stdio: "inherit" });
81
+ break;
82
+ case "bun":
83
+ // Bun 缓存清理
84
+ const bunCacheDir = join(env.HOME || env.USERPROFILE || "", ".bun", "install", "cache");
85
+ if (existsSync(bunCacheDir)) {
86
+ log(" 清理 Bun 缓存目录...", "blue");
87
+ rmSync(bunCacheDir, { recursive: true, force: true });
88
+ }
89
+ break;
90
+ case "yarn":
91
+ execSync("yarn cache clean", { stdio: "inherit" });
92
+ break;
93
+ case "pnpm":
94
+ execSync("pnpm store prune", { stdio: "inherit" });
95
+ break;
96
+ }
97
+ log(" ✅ 缓存清理完成", "green");
98
+ } catch (error) {
99
+ log(` ⚠️ 缓存清理失败: ${error.message}`, "yellow");
100
+ }
101
+
102
+ // Step 2: 卸载旧版本
103
+ log("\n步骤 2: 卸载旧版本...", "yellow");
104
+ try {
105
+ switch (packageManager) {
106
+ case "npm":
107
+ execSync("npm uninstall -g @42ailab/42plugin", { stdio: "inherit" });
108
+ break;
109
+ case "bun":
110
+ execSync("bun remove -g @42ailab/42plugin", { stdio: "inherit" });
111
+ break;
112
+ case "yarn":
113
+ execSync("yarn global remove @42ailab/42plugin", { stdio: "inherit" });
114
+ break;
115
+ case "pnpm":
116
+ execSync("pnpm remove -g @42ailab/42plugin", { stdio: "inherit" });
117
+ break;
118
+ }
119
+ log(" ✅ 旧版本卸载完成", "green");
120
+ } catch (error) {
121
+ log(" ⚠️ 未找到已安装的版本", "yellow");
122
+ }
123
+
124
+ // Step 3: Windows 特殊处理
125
+ if (platform === "win32") {
126
+ log("\n步骤 3: Windows 特殊处理...", "yellow");
127
+
128
+ // 清理可能损坏的全局 node_modules(仅清理 42plugin 相关目录)
129
+ const globalPaths = [];
130
+
131
+ // 安全地构建路径,确保环境变量存在且路径为绝对路径
132
+ if (env.APPDATA && isAbsolute(env.APPDATA)) {
133
+ globalPaths.push(join(env.APPDATA, "npm", "node_modules", "@42ailab", "42plugin"));
134
+ globalPaths.push(join(env.APPDATA, "npm", "node_modules", "@42ailab", "42plugin-win32-x64"));
135
+ }
136
+ if (env.USERPROFILE && isAbsolute(env.USERPROFILE)) {
137
+ globalPaths.push(join(env.USERPROFILE, ".bun", "install", "global", "node_modules", "@42ailab", "42plugin"));
138
+ globalPaths.push(join(env.USERPROFILE, ".bun", "install", "global", "node_modules", "@42ailab", "42plugin-win32-x64"));
139
+ }
140
+
141
+ for (const cleanPath of globalPaths) {
142
+ // 额外安全检查:确保路径是绝对路径且包含预期的目录结构
143
+ if (!isAbsolute(cleanPath) || !cleanPath.includes("node_modules")) {
144
+ log(` ⚠️ 跳过可疑路径: ${cleanPath}`, "yellow");
145
+ continue;
146
+ }
147
+
148
+ if (existsSync(cleanPath)) {
149
+ log(` 清理 ${cleanPath}...`, "blue");
150
+ try {
151
+ rmSync(cleanPath, { recursive: true, force: true });
152
+ log(` ✅ 清理完成`, "green");
153
+ } catch (error) {
154
+ log(` ⚠️ 清理失败: ${error.message}`, "yellow");
155
+ }
156
+ }
157
+ }
158
+
159
+ // 检查并关闭可能占用文件的防病毒软件提示
160
+ log("\n 💡 提示: 如果安装仍然失败,请尝试:", "yellow");
161
+ log(" 1. 暂时禁用 Windows Defender 或其他防病毒软件", "yellow");
162
+ log(" 2. 以管理员身份运行命令提示符", "yellow");
163
+ log(" 3. 检查代理设置: npm config get proxy", "yellow");
164
+ }
165
+
166
+ // Step 4: 重新安装
167
+ log("\n步骤 4: 重新安装 42plugin...", "yellow");
168
+ try {
169
+ let installCommand;
170
+ switch (packageManager) {
171
+ case "npm":
172
+ installCommand = "npm install -g @42ailab/42plugin@latest --force";
173
+ break;
174
+ case "bun":
175
+ installCommand = "bun add -g @42ailab/42plugin@latest";
176
+ break;
177
+ case "yarn":
178
+ installCommand = "yarn global add @42ailab/42plugin@latest";
179
+ break;
180
+ case "pnpm":
181
+ installCommand = "pnpm add -g @42ailab/42plugin@latest";
182
+ break;
183
+ }
184
+
185
+ log(` 执行: ${installCommand}`, "blue");
186
+ execSync(installCommand, { stdio: "inherit" });
187
+ log("\n ✅ 安装完成", "green");
188
+ } catch (error) {
189
+ log(`\n ❌ 安装失败: ${error.message}`, "red");
190
+
191
+ // 提供备选方案
192
+ log("\n📝 备选解决方案:", "yellow");
193
+
194
+ if (platform === "win32") {
195
+ log("\n方法 1: 使用不同的包管理器", "cyan");
196
+ if (packageManager !== "bun") {
197
+ log(" curl -fsSL https://bun.sh/install | bash", "blue");
198
+ log(" bun add -g @42ailab/42plugin", "blue");
199
+ } else {
200
+ log(" npm install -g @42ailab/42plugin --force", "blue");
201
+ }
202
+
203
+ log("\n方法 2: 手动安装", "cyan");
204
+ log(" 1. 访问 https://github.com/42ailab/42plugin/releases", "blue");
205
+ log(" 2. 下载 42plugin-win32-x64.exe", "blue");
206
+ log(" 3. 将文件放置到以下路径:", "blue");
207
+ log(` ${env.APPDATA}\\npm\\node_modules\\@42ailab\\42plugin-win32-x64\\bin\\`, "blue");
208
+
209
+ log("\n方法 3: 使用 WSL (Windows Subsystem for Linux)", "cyan");
210
+ log(" 在 WSL 中安装可以避免 Windows 特定问题", "blue");
211
+ } else if (platform === "darwin") {
212
+ log("\n推荐: 使用 Homebrew", "cyan");
213
+ log(" brew install 42ailab/42plugin/42plugin", "blue");
214
+ }
215
+
216
+ process.exit(1);
217
+ }
218
+
219
+ // Step 5: 验证安装
220
+ log("\n步骤 5: 验证安装...", "yellow");
221
+ try {
222
+ const version = execSync("42plugin --version", { encoding: "utf-8" }).trim();
223
+ log(`\n✅ 修复成功! 42plugin ${version} 已安装`, "green");
224
+ log("\n现在可以运行: 42plugin --help", "blue");
225
+ } catch (error) {
226
+ log("\n⚠️ 安装似乎完成,但验证失败", "yellow");
227
+ log(" 可能需要重新打开终端或刷新环境变量", "yellow");
228
+
229
+ if (platform === "win32") {
230
+ log("\n Windows 用户请:", "yellow");
231
+ log(" 1. 关闭并重新打开命令提示符/PowerShell", "yellow");
232
+ log(" 2. 运行: refreshenv (如果可用)", "yellow");
233
+ log(" 3. 或重启计算机以确保 PATH 更新", "yellow");
234
+ } else {
235
+ log("\n 请运行: source ~/.bashrc 或 source ~/.zshrc", "yellow");
236
+ }
237
+ }
238
+
239
+ // 创建修复日志
240
+ const logFile = join(env.HOME || env.USERPROFILE || "", ".42plugin-repair.log");
241
+ try {
242
+ const logContent = {
243
+ timestamp: new Date().toISOString(),
244
+ platform: `${platform}-${arch}`,
245
+ packageManager,
246
+ success: true,
247
+ };
248
+ writeFileSync(logFile, JSON.stringify(logContent, null, 2));
249
+ } catch {}
250
+ }
251
+
252
+ // 运行修复
253
+ repair().catch((error) => {
254
+ log(`\n❌ 修复过程出错: ${error.message}`, "red");
255
+ log("\n请访问 https://github.com/42ailab/42plugin/issues 报告问题", "yellow");
256
+ process.exit(1);
257
+ });
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "description": "42plugin CLI - AI 插件管理工具",
5
5
  "bin": {
6
- "42plugin": "bin/42plugin"
6
+ "42plugin": "bin/42plugin",
7
+ "42plugin-repair": "bin/42plugin-repair"
7
8
  },
8
9
  "files": [
9
- "bin"
10
+ "bin",
11
+ "postinstall.js"
10
12
  ],
13
+ "scripts": {
14
+ "postinstall": "node postinstall.js"
15
+ },
11
16
  "keywords": [
12
17
  "claude",
13
18
  "claude-code",
@@ -26,10 +31,10 @@
26
31
  "node": ">=18.0.0"
27
32
  },
28
33
  "optionalDependencies": {
29
- "@42ailab/42plugin-darwin-arm64": "0.2.30",
30
- "@42ailab/42plugin-darwin-x64": "0.2.30",
31
- "@42ailab/42plugin-linux-arm64": "0.2.30",
32
- "@42ailab/42plugin-linux-x64": "0.2.30",
33
- "@42ailab/42plugin-win32-x64": "0.2.30"
34
+ "@42ailab/42plugin-darwin-arm64": "0.2.31",
35
+ "@42ailab/42plugin-darwin-x64": "0.2.31",
36
+ "@42ailab/42plugin-linux-arm64": "0.2.31",
37
+ "@42ailab/42plugin-linux-x64": "0.2.31",
38
+ "@42ailab/42plugin-win32-x64": "0.2.31"
34
39
  }
35
40
  }
package/postinstall.js ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 42plugin 安装后验证脚本
5
+ * 确保平台特定的二进制文件正确安装
6
+ */
7
+
8
+ const { platform, arch, env } = process;
9
+ const { existsSync, writeFileSync } = require("fs");
10
+ const { join, dirname, isAbsolute } = require("path");
11
+
12
+ // 颜色输出
13
+ const colors = {
14
+ reset: "\x1b[0m",
15
+ red: "\x1b[31m",
16
+ green: "\x1b[32m",
17
+ yellow: "\x1b[33m",
18
+ blue: "\x1b[34m",
19
+ };
20
+
21
+ function log(message, color = "reset") {
22
+ console.log(`${colors[color]}${message}${colors.reset}`);
23
+ }
24
+
25
+ function isGlobalInstall() {
26
+ // npm 全局安装检测
27
+ if (env.npm_config_global === "true") {
28
+ return true;
29
+ }
30
+
31
+ // Bun 全局安装检测:检查安装路径是否在 Bun 全局目录下
32
+ if (env.BUN_INSTALL) {
33
+ const scriptPath = __dirname;
34
+ const bunGlobalPath = join(env.BUN_INSTALL, "install", "global");
35
+ if (scriptPath.includes(bunGlobalPath) || scriptPath.includes(".bun/install/global")) {
36
+ return true;
37
+ }
38
+ }
39
+
40
+ return false;
41
+ }
42
+
43
+ function verifyInstallation() {
44
+ // 只在全局安装时运行
45
+ if (!isGlobalInstall()) {
46
+ return;
47
+ }
48
+
49
+ log("\n🔍 验证 42plugin 安装...", "blue");
50
+
51
+ const platformKey = `${platform}-${arch}`;
52
+ const packageName = `@42ailab/42plugin-${platformKey}`;
53
+
54
+ // 特殊处理 Windows 包名
55
+ const actualPackageName = platform === "win32"
56
+ ? `@42ailab/42plugin-win32-x64`
57
+ : packageName;
58
+
59
+ log(` 平台: ${platformKey}`, "blue");
60
+ log(` 包名: ${actualPackageName}`, "blue");
61
+
62
+ // 检查支持的平台
63
+ const supportedPlatforms = [
64
+ "darwin-x64",
65
+ "darwin-arm64",
66
+ "linux-x64",
67
+ "linux-arm64",
68
+ "win32-x64",
69
+ ];
70
+
71
+ if (!supportedPlatforms.includes(platformKey)) {
72
+ log(`\n⚠️ 警告: 平台 ${platformKey} 暂不支持`, "yellow");
73
+ log(" 支持的平台: " + supportedPlatforms.join(", "), "yellow");
74
+ return;
75
+ }
76
+
77
+ // 检查二进制文件是否存在
78
+ const binaryName = platform === "win32" ? "42plugin.exe" : "42plugin";
79
+ const possiblePaths = [
80
+ // 嵌套在主包内的 node_modules
81
+ join(__dirname, "..", "node_modules", actualPackageName, "bin", binaryName),
82
+ // 同级的兄弟包 (hoisted)
83
+ join(__dirname, "..", "..", actualPackageName, "bin", binaryName),
84
+ // 上级 node_modules (全局安装)
85
+ join(dirname(dirname(__dirname)), actualPackageName, "bin", binaryName),
86
+ // @42ailab/42plugin 内嵌套的依赖
87
+ join(__dirname, "node_modules", actualPackageName, "bin", binaryName),
88
+ ];
89
+
90
+ let binaryFound = false;
91
+ let binaryPath = null;
92
+
93
+ for (const path of possiblePaths) {
94
+ if (existsSync(path)) {
95
+ binaryFound = true;
96
+ binaryPath = path;
97
+ break;
98
+ }
99
+ }
100
+
101
+ if (binaryFound) {
102
+ log(`\n✅ 安装验证成功!`, "green");
103
+ log(` 二进制文件位置: ${binaryPath}`, "green");
104
+ } else {
105
+ log(`\n⚠️ 警告: 未找到平台二进制文件`, "yellow");
106
+ log(` 期望的包: ${actualPackageName}`, "yellow");
107
+
108
+ // 提供修复指导(不执行网络请求,避免供应链风险)
109
+ log("\n📝 请尝试以下解决方案:", "yellow");
110
+
111
+ if (platform === "win32") {
112
+ log("\n 方法 1: 运行自动修复工具", "cyan");
113
+ log(" npx @42ailab/42plugin-repair", "blue");
114
+ log("\n 方法 2: 手动清理并重新安装", "cyan");
115
+ log(" npm cache clean --force", "blue");
116
+ log(" npm install -g @42ailab/42plugin --force", "blue");
117
+ log("\n 方法 3: 使用 bun (推荐)", "cyan");
118
+ log(" bun add -g @42ailab/42plugin", "blue");
119
+ log("\n 方法 4: 手动下载", "cyan");
120
+ log(" 访问 https://github.com/42ailab/42plugin/releases", "blue");
121
+ } else {
122
+ log(" 1. 运行修复工具: npx @42ailab/42plugin-repair", "yellow");
123
+ log(" 2. 重新安装: npm install -g @42ailab/42plugin --force", "yellow");
124
+ log(" 3. 使用 bun: bun add -g @42ailab/42plugin", "yellow");
125
+ if (platform === "darwin") {
126
+ log(" 4. 使用 Homebrew: brew install 42ailab/42plugin/42plugin", "yellow");
127
+ }
128
+ }
129
+ }
130
+
131
+ // 创建标记文件记录安装状态
132
+ const statusFile = join(__dirname, "..", ".install-verified");
133
+ try {
134
+ writeFileSync(statusFile, JSON.stringify({
135
+ platform: platformKey,
136
+ binaryFound,
137
+ binaryPath,
138
+ timestamp: new Date().toISOString(),
139
+ version: require("../package.json").version,
140
+ }, null, 2));
141
+ } catch (e) {
142
+ // 忽略写入错误
143
+ }
144
+ }
145
+
146
+ // 处理错误,避免阻塞安装
147
+ try {
148
+ verifyInstallation();
149
+ } catch (error) {
150
+ log(`\n⚠️ 安装验证出错: ${error.message}`, "yellow");
151
+ log(" 42plugin 可能无法正常工作,请参考上述解决方案", "yellow");
152
+ }