oh-my-opencode-cohub 1.12.9-beta.4 → 1.12.9-beta.6

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.
@@ -1,5 +1,5 @@
1
1
  /** 添加 CoHub 到 opencode.json 的 plugin 数组 */
2
- export declare function addPluginToOpenCodeConfig(): {
2
+ export declare function addPluginToOpenCodeConfig(version: string): {
3
3
  success: boolean;
4
4
  message: string;
5
5
  };
@@ -25,8 +25,8 @@ export declare function uninstallCoHub(): {
25
25
  success: boolean;
26
26
  messages: string[];
27
27
  };
28
- /** 复制 dist 文件到 ~/.config/opencode/plugins/oh-my-opencode-cohub/dist/ */
29
- export declare function copyPluginFiles(cliDir: string): {
28
+ /** 将 cohub 安装到 ~/.cache/opencode/packages/oh-my-opencode-cohub/(含完整 node_modules) */
29
+ export declare function installToCacheDir(version: string): {
30
30
  success: boolean;
31
31
  message: string;
32
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config-io.d.ts","sourceRoot":"","sources":["../../src/cli/config-io.ts"],"names":[],"mappings":"AAkCA,2CAA2C;AAC3C,wBAAgB,yBAAyB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAajF;AAED,sCAAsC;AACtC,wBAAgB,oBAAoB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAa5E;AAOD;;wDAEwD;AACxD,wBAAgB,mBAAmB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAuF3E;AA8ED,4DAA4D;AAC5D,wBAAgB,kBAAkB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA2G1E;AAED,8BAA8B;AAC9B,wBAAgB,cAAc,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CA6GzE;AAgBD,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAsBrF"}
1
+ {"version":3,"file":"config-io.d.ts","sourceRoot":"","sources":["../../src/cli/config-io.ts"],"names":[],"mappings":"AAmCA,2CAA2C;AAC3C,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAwBhG;AAED,sCAAsC;AACtC,wBAAgB,oBAAoB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAa5E;AAOD;;wDAEwD;AACxD,wBAAgB,mBAAmB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAuF3E;AA+ED,4DAA4D;AAC5D,wBAAgB,kBAAkB,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA2G1E;AAED,8BAA8B;AAC9B,wBAAgB,cAAc,IAAI;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAgIzE;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA6BxF"}
package/dist/cli/index.js CHANGED
@@ -1,15 +1,12 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/cli/index.ts
4
- import { fileURLToPath } from "node:url";
5
- import * as path2 from "node:path";
6
2
  // package.json
7
- var version = "1.12.9-beta.4";
3
+ var version = "1.12.9-beta.6";
8
4
 
9
5
  // src/cli/config-io.ts
10
6
  import * as fs from "node:fs";
11
7
  import * as path from "node:path";
12
8
  import * as os from "node:os";
9
+ import { execSync } from "node:child_process";
13
10
  var PACKAGE_NAME = "oh-my-opencode-cohub";
14
11
  function getOpencodeConfigPath() {
15
12
  return path.join(os.homedir(), ".config", "opencode", "opencode.json");
@@ -39,17 +36,25 @@ function writeJSON(filePath, data) {
39
36
  `;
40
37
  fs.writeFileSync(filePath, content, "utf-8");
41
38
  }
42
- function addPluginToOpenCodeConfig() {
39
+ function addPluginToOpenCodeConfig(version2) {
43
40
  const configPath = getOpencodeConfigPath();
44
41
  let config = readJSON(configPath) ?? {};
45
42
  const plugins = Array.isArray(config.plugin) ? [...config.plugin] : [];
43
+ const pkgSpec = `${PACKAGE_NAME}@${version2}`;
46
44
  if (plugins.some((p) => p.includes(PACKAGE_NAME))) {
47
- return { success: true, message: "CoHub 已在 opencode.json 的 plugin 数组中,跳过" };
45
+ for (let i = 0;i < plugins.length; i++) {
46
+ if (plugins[i].includes(PACKAGE_NAME)) {
47
+ plugins[i] = pkgSpec;
48
+ }
49
+ }
50
+ config.plugin = plugins;
51
+ writeJSON(configPath, config);
52
+ return { success: true, message: `✓ 已更新 "${pkgSpec}" 到 opencode.json 的 plugin 数组` };
48
53
  }
49
- plugins.unshift(PACKAGE_NAME);
54
+ plugins.unshift(pkgSpec);
50
55
  config.plugin = plugins;
51
56
  writeJSON(configPath, config);
52
- return { success: true, message: `✓ 已添加 "${PACKAGE_NAME}" 到 opencode.json 的 plugin 数组` };
57
+ return { success: true, message: `✓ 已添加 "${pkgSpec}" 到 opencode.json 的 plugin 数组` };
53
58
  }
54
59
  function addPluginToTuiConfig() {
55
60
  const configPath = getTuiConfigPath();
@@ -145,6 +150,7 @@ function registerCoHubAgents() {
145
150
  return { success: true, message: `✓ ${msgParts.join(",")}` };
146
151
  }
147
152
  var COHUB_CONFIG_PATH = path.join(os.homedir(), ".config", "opencode", "oh-my-opencode-cohub.json");
153
+ var PACKAGES_CACHE = path.join(os.homedir(), ".cache", "opencode", "packages", PACKAGE_NAME);
148
154
  var HEAVY_KEYWORDS = ["pro", "preview", "opus", "max", "sonnet", "gpt-5.6"];
149
155
  var LIGHT_KEYWORDS = ["flash", "mini", "haiku", "gpt-5.4", "gpt-5.3"];
150
156
  var DESIGN_KEYWORDS = ["minimax", "m3", "sonnet", "claude"];
@@ -400,52 +406,56 @@ function uninstallCoHub() {
400
406
  }
401
407
  }
402
408
  }
403
- messages.push("✅ CoHub 卸载完成。完全关闭 OpenCode 后重新打开即可。");
404
- return { success: true, messages };
405
- }
406
- function copyRecursive(src, dest) {
407
- fs.mkdirSync(dest, { recursive: true });
408
- for (const entry of fs.readdirSync(src)) {
409
- const srcPath = path.join(src, entry);
410
- const destPath = path.join(dest, entry);
411
- if (fs.statSync(srcPath).isDirectory()) {
412
- copyRecursive(srcPath, destPath);
413
- } else {
414
- fs.copyFileSync(srcPath, destPath);
409
+ if (fs.existsSync(PACKAGES_CACHE)) {
410
+ try {
411
+ fs.rmSync(PACKAGES_CACHE, { recursive: true, force: true });
412
+ messages.push("✓ 已清理缓存目录");
413
+ } catch {
414
+ messages.push("⚠ 清理缓存目录失败,请手动删除: " + PACKAGES_CACHE);
415
415
  }
416
416
  }
417
+ const legacyPluginsDir = path.join(os.homedir(), ".config", "opencode", "plugins", PACKAGE_NAME);
418
+ if (fs.existsSync(legacyPluginsDir)) {
419
+ try {
420
+ fs.rmSync(legacyPluginsDir, { recursive: true, force: true });
421
+ messages.push("✓ 已清理旧 plugins 目录");
422
+ } catch {}
423
+ }
424
+ messages.push("✅ CoHub 卸载完成。完全关闭 OpenCode 后重新打开即可。");
425
+ return { success: true, messages };
417
426
  }
418
- function copyPluginFiles(cliDir) {
427
+ function installToCacheDir(version2) {
419
428
  try {
420
- const distDir = path.resolve(cliDir, "..");
421
- const pluginDir = path.join(os.homedir(), ".config", "opencode", "plugins", PACKAGE_NAME);
422
- const targetDir = path.join(pluginDir, "dist");
429
+ const targetDir = PACKAGES_CACHE;
423
430
  if (fs.existsSync(targetDir)) {
424
431
  fs.rmSync(targetDir, { recursive: true, force: true });
425
432
  }
426
- copyRecursive(distDir, targetDir);
427
- const pkgSrc = path.resolve(distDir, "..", "package.json");
428
- const pkgDest = path.join(pluginDir, "package.json");
429
- if (fs.existsSync(pkgSrc)) {
430
- fs.copyFileSync(pkgSrc, pkgDest);
433
+ fs.mkdirSync(targetDir, { recursive: true });
434
+ const pkgJson = { private: true };
435
+ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify(pkgJson, null, 2), "utf-8");
436
+ const pkgSpec = `${PACKAGE_NAME}@${version2}`;
437
+ const cmd = `npm install "${pkgSpec}" --save --legacy-peer-deps`;
438
+ execSync(cmd, { cwd: targetDir, stdio: "pipe", timeout: 120000 });
439
+ const entryPath = path.join(targetDir, "node_modules", PACKAGE_NAME, "dist", "index.js");
440
+ if (!fs.existsSync(entryPath)) {
441
+ return { success: false, message: `⚠ npm install 成功但入口文件缺失: ${entryPath}` };
431
442
  }
432
- return { success: true, message: `✓ 已复制 dist 文件到 ${targetDir}` };
443
+ return { success: true, message: `✓ 已安装 ${pkgSpec} 到 ${targetDir}` };
433
444
  } catch (e) {
434
- return { success: false, message: `⚠ 复制 dist 失败: ${e.message}` };
445
+ return { success: false, message: `⚠ 安装失败: ${e.message}` };
435
446
  }
436
447
  }
437
448
 
438
449
  // src/cli/index.ts
439
- var __dirname2 = path2.dirname(fileURLToPath(import.meta.url));
440
450
  async function main() {
441
451
  const args = process.argv.slice(2);
442
452
  const command = args[0];
443
453
  if (command === "install") {
444
454
  console.log(`\uD83D\uDE80 oh-my-opencode-cohub v${version} 安装中...
445
455
  `);
446
- const r0 = copyPluginFiles(__dirname2);
456
+ const r0 = installToCacheDir(version);
447
457
  console.log(r0.message);
448
- const r1 = addPluginToOpenCodeConfig();
458
+ const r1 = addPluginToOpenCodeConfig(version);
449
459
  console.log(r1.message);
450
460
  const r2 = addPluginToTuiConfig();
451
461
  console.log(r2.message);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAyHlD,QAAA,MAAM,WAAW,EAAE,MAkiBlB,CAAC;AAEF,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAyHlD,QAAA,MAAM,WAAW,EAAE,MA6gBlB,CAAC;AAEF,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAe,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -2066,29 +2066,6 @@ ${ORCHESTRATOR_PROMPT}
2066
2066
  appendLog("messages.transform", `⚠️ 注入后 content 为空,已设空格占位 (session=${sessionID?.slice(0, 20) ?? "?"})`);
2067
2067
  }
2068
2068
  }
2069
- for (let i = 0;i < output.messages.length; i++) {
2070
- const msg = output.messages[i];
2071
- const parts = msg.parts ?? [];
2072
- let totalText = "";
2073
- for (const p of parts) {
2074
- if (p.type === "text" && p.text)
2075
- totalText += p.text;
2076
- }
2077
- if (!totalText.trim() && parts.length > 0) {
2078
- let found = false;
2079
- for (const p of parts) {
2080
- if (p.type === "text") {
2081
- p.text = " ";
2082
- found = true;
2083
- break;
2084
- }
2085
- }
2086
- if (!found) {
2087
- parts.push({ type: "text", text: " " });
2088
- }
2089
- appendLog("messages.transform", `⚠️ 消息[${i}] role=${msg.info?.role ?? "?"} content为空,已设占位 (session=${sessionID?.slice(0, 20) ?? "?"})`);
2090
- }
2091
- }
2092
2069
  } catch (err) {
2093
2070
  appendLog("messages.transform", "hook 失败", err);
2094
2071
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-opencode-cohub",
3
- "version": "1.12.9-beta.4",
3
+ "version": "1.12.9-beta.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Mr-cjf/oh-my-opencode-cohub.git"