galaxy-opc 0.5.3 → 0.5.5

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.
Files changed (2) hide show
  1. package/bin/cli.mjs +40 -6
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -111,6 +111,42 @@ function runCommand(cmd, args, options = {}) {
111
111
  });
112
112
  }
113
113
 
114
+ function buildOpenclawInstallEnv() {
115
+ // On some Windows machines node-llama-cpp postinstall fails while cloning llama.cpp.
116
+ // OpenClaw works with hosted providers; skip local llama.cpp download to improve install success.
117
+ if (process.platform === "win32") {
118
+ return { ...process.env, NODE_LLAMA_CPP_SKIP_DOWNLOAD: "true" };
119
+ }
120
+ return process.env;
121
+ }
122
+
123
+ async function installOpenclawWithFallback() {
124
+ const env = buildOpenclawInstallEnv();
125
+ const attempts = [
126
+ {
127
+ label: "官方源(原生)",
128
+ args: ["install", "-g", "openclaw@latest"],
129
+ },
130
+ {
131
+ label: "国内镜像(fallback)",
132
+ args: ["install", "-g", "openclaw@latest", "--registry", "https://registry.npmmirror.com"],
133
+ },
134
+ ];
135
+
136
+ let lastErr = null;
137
+ for (const attempt of attempts) {
138
+ console.log(dim(` 尝试 ${attempt.label} 安装 OpenClaw...\n`));
139
+ try {
140
+ await runCommand("npm", attempt.args, { env });
141
+ return;
142
+ } catch (e) {
143
+ lastErr = e;
144
+ console.log(yellow(` ! ${attempt.label} 失败: ${e.message}\n`));
145
+ }
146
+ }
147
+ throw lastErr || new Error("OpenClaw 安装失败");
148
+ }
149
+
114
150
  function checkTool(cmd) {
115
151
  try { execSync(`${cmd} --version`, { stdio: "ignore" }); return true; } catch { return false; }
116
152
  }
@@ -232,7 +268,7 @@ ${bold(cyan(" ╚════════════════════
232
268
  if (ocVersion) {
233
269
  console.log(green(` ✓ OpenClaw 已安装 (${ocVersion})`));
234
270
  } else {
235
- console.log(dim(" 正在安装 OpenClaw(首次安装约 80MB+,使用国内镜像加速)...\n"));
271
+ console.log(dim(" 正在安装 OpenClaw(优先官方源,失败自动切换镜像)...\n"));
236
272
  // 临时覆盖 git url rewrite(强制 SSH 协议转 HTTPS,覆盖两种格式)
237
273
  const gitRewrites = [
238
274
  ["url.https://github.com/.insteadOf", "git@github.com:"],
@@ -247,14 +283,12 @@ ${bold(cyan(" ╚════════════════════
247
283
  }
248
284
 
249
285
  try {
250
- await runCommand("npm", [
251
- "install", "-g", "openclaw@latest",
252
- "--registry", "https://registry.npmmirror.com",
253
- ]);
286
+ await installOpenclawWithFallback();
254
287
  console.log(green("\n ✓ OpenClaw 安装完成"));
255
288
  } catch {
256
289
  console.error(red("\n ✗ OpenClaw 安装失败,请手动运行:"));
257
- console.error(gray(" npm install -g openclaw@latest --registry https://registry.npmmirror.com\n"));
290
+ console.error(gray(" npm install -g openclaw@latest"));
291
+ console.error(gray(" 或 npm install -g openclaw@latest --registry https://registry.npmmirror.com\n"));
258
292
  process.exit(1);
259
293
  } finally {
260
294
  // 还原 git 配置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 AI 员工系统",
5
5
  "keywords": [
6
6
  "ai",