galaxy-opc 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/bin/cli.mjs +16 -71
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -14,10 +14,6 @@ import readline from "node:readline";
14
14
  import { execSync, spawn } from "node:child_process";
15
15
  import crypto from "node:crypto";
16
16
 
17
- const PLUGIN_REPO_GITHUB = "https://github.com/P3ngSaM/galaxy-opc.git";
18
- const PLUGIN_REPO_GITEE = "https://gitee.com/peng-sam/galaxy-opc.git";
19
- const PLUGIN_DIR_NAME = "opc-platform";
20
-
21
17
  // ─── 颜色工具 ───────────────────────────────────────────────────────────────
22
18
  const c = {
23
19
  reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m",
@@ -127,25 +123,13 @@ function getOpenclawVersion() {
127
123
  }
128
124
  }
129
125
 
130
- // 检测国内网络,自动选择 Gitee 或 GitHub
131
- async function detectRepoUrl() {
132
- return new Promise((resolve) => {
133
- const req = spawn("git", ["ls-remote", "--exit-code", "--heads", PLUGIN_REPO_GITHUB, "main"], {
134
- stdio: "ignore", timeout: 5000,
135
- });
136
- const timer = setTimeout(() => { req.kill(); resolve(PLUGIN_REPO_GITEE); }, 5000);
137
- req.on("close", (code) => { clearTimeout(timer); resolve(code === 0 ? PLUGIN_REPO_GITHUB : PLUGIN_REPO_GITEE); });
138
- req.on("error", () => { clearTimeout(timer); resolve(PLUGIN_REPO_GITEE); });
139
- });
140
- }
141
-
142
126
  // ─── 路径常量 ───────────────────────────────────────────────────────────────
143
- const HOME = os.homedir();
144
- const STATE_DIR = path.join(HOME, ".openclaw");
127
+ const HOME = os.homedir();
128
+ const STATE_DIR = path.join(HOME, ".openclaw");
145
129
  const CONFIG_PATH = path.join(STATE_DIR, "openclaw.json");
146
- const ENV_PATH = path.join(STATE_DIR, ".env");
147
- // 插件存放在 ~/.openclaw/extensions/opc-platform
148
- const PLUGIN_INSTALL_DIR = path.join(STATE_DIR, "extensions", PLUGIN_DIR_NAME);
130
+ const ENV_PATH = path.join(STATE_DIR, ".env");
131
+ // 插件由 openclaw plugins install 写入 ~/.openclaw/extensions/opc-platform
132
+ const PLUGIN_INSTALL_DIR = path.join(STATE_DIR, "extensions", "opc-platform");
149
133
 
150
134
  // ─── 命令路由 ───────────────────────────────────────────────────────────────
151
135
  const args = process.argv.slice(2);
@@ -183,12 +167,6 @@ ${bold(cyan(" ╚════════════════════
183
167
  }
184
168
  console.log(green(` ✓ Node.js v${process.versions.node}`));
185
169
 
186
- if (!checkTool("git")) {
187
- console.error(red("\n ✗ 未检测到 git,请先安装: https://git-scm.com/\n"));
188
- process.exit(1);
189
- }
190
- console.log(green(" ✓ git 已安装"));
191
-
192
170
  // ── 步骤 2:安装 openclaw ────────────────────────────────────────────────
193
171
  separator();
194
172
  console.log(bold(" 步骤 2 / 4 安装 OpenClaw 核心"));
@@ -198,13 +176,13 @@ ${bold(cyan(" ╚════════════════════
198
176
  if (ocVersion) {
199
177
  console.log(green(` ✓ OpenClaw 已安装 (${ocVersion})`));
200
178
  } else {
201
- console.log(dim(" 正在安装 OpenClaw(官方核心,约 10MB)...\n"));
179
+ console.log(dim(" 正在安装 OpenClaw(首次安装约 80MB+,使用国内镜像加速)...\n"));
202
180
  try {
203
- await runCommand("npm", ["install", "-g", "openclaw@latest"]);
181
+ await runCommand("npm", ["install", "-g", "openclaw@latest", "--registry", "https://registry.npmmirror.com"]);
204
182
  console.log(green("\n ✓ OpenClaw 安装完成"));
205
183
  } catch {
206
184
  console.error(red("\n ✗ OpenClaw 安装失败,请手动运行:"));
207
- console.error(gray(" npm install -g openclaw@latest\n"));
185
+ console.error(gray(" npm install -g openclaw@latest --registry https://registry.npmmirror.com\n"));
208
186
  process.exit(1);
209
187
  }
210
188
  }
@@ -220,59 +198,26 @@ ${bold(cyan(" ╚════════════════════
220
198
  if (!update) {
221
199
  console.log(green(" ✓ 跳过,使用现有版本"));
222
200
  } else {
223
- await downloadPlugin();
201
+ await installPlugin();
224
202
  }
225
203
  } else {
226
- await downloadPlugin();
227
- }
228
-
229
- // 安装插件依赖
230
- console.log(dim("\n 安装插件依赖...\n"));
231
- try {
232
- await runCommand("npm", ["install", "--prefix", PLUGIN_INSTALL_DIR, "--omit=dev"]);
233
- console.log(green(" ✓ 插件依赖安装完成"));
234
- } catch {
235
- console.log(yellow(" ! 插件依赖安装失败,部分功能可能受影响"));
204
+ await installPlugin();
236
205
  }
237
206
 
238
207
  // ── 步骤 4:配置模型 ────────────────────────────────────────────────────
239
208
  await cmdSetup();
240
209
  }
241
210
 
242
- async function downloadPlugin() {
243
- const tmpDir = path.join(os.tmpdir(), `galaxy-opc-${Date.now()}`);
244
-
245
- console.log(dim(" 检测网络,选择最快下载源..."));
246
- const repoUrl = await detectRepoUrl();
247
- const source = repoUrl.includes("gitee") ? "Gitee(国内加速)" : "GitHub";
248
- console.log(green(` ✓ 使用 ${source}`));
249
- console.log(dim(" 正在下载插件...\n"));
250
-
211
+ async function installPlugin() {
212
+ console.log(dim(" 正在通过 OpenClaw 安装插件...\n"));
251
213
  try {
252
- await runCommand("git", ["clone", "--depth", "1", repoUrl, tmpDir]);
214
+ await runCommand("openclaw", ["plugins", "install", "galaxy-opc-plugin"]);
215
+ console.log(green("\n ✓ 插件安装完成"));
253
216
  } catch (e) {
254
- console.error(red(`\n ✗ 下载失败: ${e.message}`));
255
- process.exit(1);
256
- }
257
-
258
- // 把 extensions/opc-platform 复制到 ~/.openclaw/extensions/opc-platform
259
- const srcPlugin = path.join(tmpDir, "extensions", PLUGIN_DIR_NAME);
260
- if (!fs.existsSync(srcPlugin)) {
261
- console.error(red(`\n ✗ 插件目录不存在: ${srcPlugin}`));
217
+ console.error(red(`\n ✗ 插件安装失败: ${e.message}`));
218
+ console.error(gray(" 请手动运行: openclaw plugins install galaxy-opc-plugin\n"));
262
219
  process.exit(1);
263
220
  }
264
-
265
- ensureDir(path.join(STATE_DIR, "extensions"));
266
- if (fs.existsSync(PLUGIN_INSTALL_DIR)) {
267
- fs.rmSync(PLUGIN_INSTALL_DIR, { recursive: true, force: true });
268
- }
269
- fs.cpSync(srcPlugin, PLUGIN_INSTALL_DIR, { recursive: true,
270
- filter: (src) => !src.includes("node_modules") && !src.includes(".git"),
271
- });
272
-
273
- // 清理临时目录
274
- fs.rmSync(tmpDir, { recursive: true, force: true });
275
- console.log(green(` ✓ 插件已安装到 ${PLUGIN_INSTALL_DIR}`));
276
221
  }
277
222
 
278
223
  // ─── setup:配置 AI 模型 + 写入 openclaw.json ───────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 AI 员工系统",
5
5
  "keywords": [
6
6
  "ai",