oh-my-opencode-cohub 1.12.9-beta.4 → 1.12.9-beta.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.
- package/dist/cli/config-io.d.ts +3 -3
- package/dist/cli/config-io.d.ts.map +1 -1
- package/dist/cli/index.js +45 -35
- package/package.json +1 -1
package/dist/cli/config-io.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
29
|
-
export declare function
|
|
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":"
|
|
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.
|
|
3
|
+
var version = "1.12.9-beta.5";
|
|
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
|
-
|
|
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(
|
|
54
|
+
plugins.unshift(pkgSpec);
|
|
50
55
|
config.plugin = plugins;
|
|
51
56
|
writeJSON(configPath, config);
|
|
52
|
-
return { success: true, message: `✓ 已添加 "${
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
|
427
|
+
function installToCacheDir(version2) {
|
|
419
428
|
try {
|
|
420
|
-
const
|
|
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
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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: `✓
|
|
443
|
+
return { success: true, message: `✓ 已安装 ${pkgSpec} 到 ${targetDir}` };
|
|
433
444
|
} catch (e) {
|
|
434
|
-
return { success: false, 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 =
|
|
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);
|