galaxy-opc 0.5.16 → 0.5.17

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 +90 -5
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -2,11 +2,12 @@
2
2
  /**
3
3
  * 星环 Galaxy OPC — CLI 入口
4
4
  * 用法:
5
- * npx galaxy-opc # 安装并初始化(首次使用)
6
- * npx galaxy-opc setup # 重新配置 AI 模型
7
- * npx galaxy-opc start # 启动服务
8
- * npx galaxy-opc update # 更新插件并重新编译原生模块
9
- * npx galaxy-opc doctor # 诊断安装状态
5
+ * npx galaxy-opc # 安装并初始化(首次使用)
6
+ * npx galaxy-opc setup # 重新配置 AI 模型
7
+ * npx galaxy-opc start # 启动服务
8
+ * npx galaxy-opc update # 更新插件并重新编译原生模块
9
+ * npx galaxy-opc uninstall # 卸载插件(可选保留数据)
10
+ * npx galaxy-opc doctor # 诊断安装状态
10
11
  */
11
12
 
12
13
  import fs from "node:fs";
@@ -240,6 +241,8 @@ if (command === "start") {
240
241
  await cmdUpdate();
241
242
  } else if (command === "setup") {
242
243
  await cmdSetup();
244
+ } else if (command === "uninstall") {
245
+ await cmdUninstall();
243
246
  } else if (command === "doctor") {
244
247
  await cmdDoctor();
245
248
  } else {
@@ -493,6 +496,88 @@ async function cmdUpdate() {
493
496
  console.log(cyan(" npx galaxy-opc start\n"));
494
497
  }
495
498
 
499
+ // ─── uninstall:卸载插件(可选保留数据 / 卸载 openclaw)────────────────────
500
+ async function cmdUninstall() {
501
+ separator();
502
+ console.log(bold(" galaxy-opc uninstall — 卸载 OPC Platform 插件"));
503
+ separator();
504
+
505
+ console.log(red("\n 警告:此操作将移除 OPC Platform 插件及其配置。\n"));
506
+
507
+ const confirm = await askYesNo(" 确认继续卸载?", false);
508
+ if (!confirm) {
509
+ console.log(gray("\n 已取消。\n"));
510
+ return;
511
+ }
512
+
513
+ // ── 1. 询问是否保留业务数据(SQLite 数据库)──────────────────────────────
514
+ const keepData = await askYesNo(
515
+ ` 保留业务数据(公司/财务/合同等数据库 ${path.join(STATE_DIR, "opc-platform")})?`,
516
+ true,
517
+ );
518
+
519
+ // ── 2. 移除插件目录 ───────────────────────────────────────────────────────
520
+ const pluginDir = path.join(STATE_DIR, "extensions", "galaxy-opc-plugin");
521
+ if (fs.existsSync(pluginDir)) {
522
+ console.log(dim(`\n 移除插件目录: ${pluginDir}`));
523
+ try {
524
+ fs.rmSync(pluginDir, { recursive: true, force: true });
525
+ console.log(green(" ✓ 插件目录已移除"));
526
+ } catch (e) {
527
+ console.log(yellow(` ! 无法移除插件目录: ${e.message}`));
528
+ }
529
+ } else {
530
+ console.log(gray(" 插件目录不存在,跳过"));
531
+ }
532
+
533
+ // ── 3. 从 openclaw.json 中清除插件注册信息 ───────────────────────────────
534
+ const cfg = readJson(CONFIG_PATH);
535
+ let cfgChanged = false;
536
+ if (cfg.plugins?.["galaxy-opc-plugin"]) {
537
+ delete cfg.plugins["galaxy-opc-plugin"];
538
+ cfgChanged = true;
539
+ }
540
+ if (cfg.plugins?.load) {
541
+ delete cfg.plugins.load;
542
+ cfgChanged = true;
543
+ }
544
+ if (cfgChanged) {
545
+ writeJson(CONFIG_PATH, cfg);
546
+ console.log(green(" ✓ 已从 openclaw.json 清除插件配置"));
547
+ }
548
+
549
+ // ── 4. 可选删除业务数据 ───────────────────────────────────────────────────
550
+ if (!keepData) {
551
+ const dataDir = path.join(STATE_DIR, "opc-platform");
552
+ if (fs.existsSync(dataDir)) {
553
+ try {
554
+ fs.rmSync(dataDir, { recursive: true, force: true });
555
+ console.log(green(" ✓ 业务数据已删除"));
556
+ } catch (e) {
557
+ console.log(yellow(` ! 无法删除数据目录: ${e.message}`));
558
+ }
559
+ }
560
+ } else {
561
+ console.log(dim(` 数据已保留: ${path.join(STATE_DIR, "opc-platform")}`));
562
+ }
563
+
564
+ // ── 5. 询问是否同时卸载 openclaw ────────────────────────────────────────
565
+ const removeOc = await askYesNo("\n 同时卸载 OpenClaw(npm uninstall -g openclaw)?", false);
566
+ if (removeOc) {
567
+ console.log(dim("\n 卸载 openclaw...\n"));
568
+ try {
569
+ await runCommand("npm", ["uninstall", "-g", "openclaw"]);
570
+ console.log(green(" ✓ openclaw 已卸载"));
571
+ } catch (e) {
572
+ console.log(yellow(` ! openclaw 卸载失败: ${e.message}`));
573
+ console.log(gray(" 请手动执行: npm uninstall -g openclaw"));
574
+ }
575
+ }
576
+
577
+ separator();
578
+ console.log(green("\n ✓ 卸载完成。\n"));
579
+ }
580
+
496
581
  // ─── setup:配置 AI 模型 + 写入 openclaw.json ───────────────────────────────
497
582
  async function cmdSetup() {
498
583
  separator();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc",
3
- "version": "0.5.16",
3
+ "version": "0.5.17",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 AI 员工系统",
5
5
  "keywords": [
6
6
  "ai",