galaxy-opc 0.5.2 → 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 +89 -9
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -111,10 +111,54 @@ 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
  }
117
153
 
154
+ function findPackedTarball(dir, pkgPrefix) {
155
+ if (!fs.existsSync(dir)) return null;
156
+ const files = fs.readdirSync(dir).filter((f) => f.startsWith(pkgPrefix) && f.endsWith(".tgz"));
157
+ if (files.length === 0) return null;
158
+ files.sort();
159
+ return path.join(dir, files[files.length - 1]);
160
+ }
161
+
118
162
  function getOpenclawVersion() {
119
163
  try {
120
164
  const out = execSync("openclaw --version 2>&1", { encoding: "utf8" }).trim();
@@ -184,6 +228,28 @@ ${bold(cyan(" ╚════════════════════
184
228
  process.exit(1);
185
229
  }
186
230
  console.log(green(" ✓ git 已就绪"));
231
+ } else if (process.platform === "win32") {
232
+ console.log(yellow("\n ! git 未安装,正在尝试通过 winget 自动安装...\n"));
233
+ if (!checkTool("winget")) {
234
+ console.error(red(" ✗ 未检测到 winget,无法自动安装 git"));
235
+ console.error(gray(" 请先安装 Git: https://git-scm.com/downloads\n"));
236
+ process.exit(1);
237
+ }
238
+ try {
239
+ await runCommand("winget", [
240
+ "install", "--id", "Git.Git", "-e",
241
+ "--accept-package-agreements", "--accept-source-agreements",
242
+ ]);
243
+ } catch {
244
+ console.error(red(" ✗ git 自动安装失败"));
245
+ console.error(gray(" 请手动安装 Git 后重试: https://git-scm.com/downloads\n"));
246
+ process.exit(1);
247
+ }
248
+ if (!checkTool("git")) {
249
+ console.error(red(" ✗ git 安装后仍不可用,请重开终端再试"));
250
+ process.exit(1);
251
+ }
252
+ console.log(green(" ✓ git 已安装"));
187
253
  } else {
188
254
  console.error(red("\n ✗ git 未安装,请先安装 git:"));
189
255
  console.error(gray(" https://git-scm.com/downloads\n"));
@@ -202,7 +268,7 @@ ${bold(cyan(" ╚════════════════════
202
268
  if (ocVersion) {
203
269
  console.log(green(` ✓ OpenClaw 已安装 (${ocVersion})`));
204
270
  } else {
205
- console.log(dim(" 正在安装 OpenClaw(首次安装约 80MB+,使用国内镜像加速)...\n"));
271
+ console.log(dim(" 正在安装 OpenClaw(优先官方源,失败自动切换镜像)...\n"));
206
272
  // 临时覆盖 git url rewrite(强制 SSH 协议转 HTTPS,覆盖两种格式)
207
273
  const gitRewrites = [
208
274
  ["url.https://github.com/.insteadOf", "git@github.com:"],
@@ -217,14 +283,12 @@ ${bold(cyan(" ╚════════════════════
217
283
  }
218
284
 
219
285
  try {
220
- await runCommand("npm", [
221
- "install", "-g", "openclaw@latest",
222
- "--registry", "https://registry.npmmirror.com",
223
- ]);
286
+ await installOpenclawWithFallback();
224
287
  console.log(green("\n ✓ OpenClaw 安装完成"));
225
288
  } catch {
226
289
  console.error(red("\n ✗ OpenClaw 安装失败,请手动运行:"));
227
- 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"));
228
292
  process.exit(1);
229
293
  } finally {
230
294
  // 还原 git 配置
@@ -286,9 +350,25 @@ async function installPlugin() {
286
350
  await runCommand("openclaw", ["plugins", "install", "galaxy-opc-plugin"]);
287
351
  console.log(green("\n ✓ 插件安装完成"));
288
352
  } catch (e) {
289
- console.error(red(`\n 插件安装失败: ${e.message}`));
290
- console.error(gray(" 请手动运行: openclaw plugins install galaxy-opc-plugin\n"));
291
- process.exit(1);
353
+ console.log(yellow(`\n ! npm spec 安装失败: ${e.message}`));
354
+ console.log(dim(" 正在尝试 fallback:先 npm pack,再安装本地 tgz...\n"));
355
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "galaxy-opc-plugin-"));
356
+ try {
357
+ await runCommand("npm", ["pack", "galaxy-opc-plugin@latest", "--silent"], { cwd: tmpDir });
358
+ const archive = findPackedTarball(tmpDir, "galaxy-opc-plugin-");
359
+ if (!archive) throw new Error("未找到打包产物 *.tgz");
360
+ await runCommand("openclaw", ["plugins", "install", archive]);
361
+ console.log(green("\n ✓ 插件安装完成(fallback)"));
362
+ } catch (fallbackErr) {
363
+ console.error(red(`\n ✗ fallback 安装也失败: ${fallbackErr.message}`));
364
+ console.error(gray(" 请依次手动执行:"));
365
+ console.error(gray(" 1) openclaw doctor --fix"));
366
+ console.error(gray(" 2) npm pack galaxy-opc-plugin@latest --silent"));
367
+ console.error(gray(" 3) openclaw plugins install .\\galaxy-opc-plugin-<version>.tgz\n"));
368
+ process.exit(1);
369
+ } finally {
370
+ try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch { /* ignore */ }
371
+ }
292
372
  }
293
373
 
294
374
  // better-sqlite3 是 native 模块,需要针对当前 Node.js 版本编译
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc",
3
- "version": "0.5.2",
3
+ "version": "0.5.5",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 AI 员工系统",
5
5
  "keywords": [
6
6
  "ai",