@zshuangmu/agenthub 0.4.7 → 0.4.9
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/package.json +1 -1
- package/src/cli.js +30 -0
- package/src/commands/uninstall.js +76 -0
- package/src/lib/debug.js +21 -1
- package/src/lib/fs-utils.js +5 -1
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -28,8 +28,10 @@ import {
|
|
|
28
28
|
formatVersionsOutput,
|
|
29
29
|
doctorCommand,
|
|
30
30
|
} from "./index.js";
|
|
31
|
+
import { uninstallCommand, formatUninstallOutput } from "./commands/uninstall.js";
|
|
31
32
|
|
|
32
33
|
import { success, error, warning, info as infoColor, highlight, muted, symbols } from "./lib/colors.js";
|
|
34
|
+
import { setVerbose, debug } from "./lib/debug.js";
|
|
33
35
|
|
|
34
36
|
import { createRequire } from "node:module";
|
|
35
37
|
const require = createRequire(import.meta.url);
|
|
@@ -65,6 +67,7 @@ AgentHub v${VERSION} - AI Agent 打包与分发平台
|
|
|
65
67
|
search 搜索 Registry 中的 Agent
|
|
66
68
|
info 查看 Agent 详情
|
|
67
69
|
list 列出当前目录/指定目录的已安装 Agent
|
|
70
|
+
uninstall 卸载已安装的 Agent
|
|
68
71
|
verify 校验已安装 Agent 是否完整可用
|
|
69
72
|
versions 查看 Agent 版本历史
|
|
70
73
|
update 更新已安装 Agent 到最新版
|
|
@@ -76,6 +79,7 @@ AgentHub v${VERSION} - AI Agent 打包与分发平台
|
|
|
76
79
|
选项:
|
|
77
80
|
--help, -h 显示帮助信息
|
|
78
81
|
--version, -v 显示版本号
|
|
82
|
+
--verbose 显示详细日志信息
|
|
79
83
|
|
|
80
84
|
详细帮助:
|
|
81
85
|
agenthub <command> --help
|
|
@@ -181,6 +185,19 @@ agenthub list - 列出已安装 Agent
|
|
|
181
185
|
agenthub list --target-workspace ./my-workspace
|
|
182
186
|
agenthub list --json
|
|
183
187
|
agenthub list --target-workspace ./my-workspace
|
|
188
|
+
`,
|
|
189
|
+
uninstall: `
|
|
190
|
+
agenthub uninstall - 卸载已安装 Agent
|
|
191
|
+
|
|
192
|
+
用法:
|
|
193
|
+
agenthub uninstall <agent-slug> [--target-workspace <dir>]
|
|
194
|
+
|
|
195
|
+
选项:
|
|
196
|
+
--target-workspace <dir> 指定工作区目录(可选)
|
|
197
|
+
|
|
198
|
+
示例:
|
|
199
|
+
agenthub uninstall my-agent
|
|
200
|
+
agenthub uninstall my-agent --target-workspace ./my-workspace
|
|
184
201
|
`,
|
|
185
202
|
verify: `
|
|
186
203
|
agenthub verify - 校验已安装 Agent
|
|
@@ -321,6 +338,12 @@ async function main() {
|
|
|
321
338
|
const { positionals, options } = parseArgs(process.argv.slice(2));
|
|
322
339
|
const [command, ...rest] = positionals;
|
|
323
340
|
|
|
341
|
+
// 设置 verbose 模式
|
|
342
|
+
if (options.verbose) {
|
|
343
|
+
setVerbose(true);
|
|
344
|
+
debug("Verbose mode enabled");
|
|
345
|
+
}
|
|
346
|
+
|
|
324
347
|
// 全局选项 - only show version if --version/-v is a boolean flag, not a string value
|
|
325
348
|
if (options.version === true) {
|
|
326
349
|
console.log(`AgentHub v${VERSION}`);
|
|
@@ -419,6 +442,13 @@ async function main() {
|
|
|
419
442
|
return;
|
|
420
443
|
}
|
|
421
444
|
|
|
445
|
+
case "uninstall": {
|
|
446
|
+
if (!requireArg(rest[0], "错误: 需要指定 agent slug")) return;
|
|
447
|
+
const result = await uninstallCommand(rest[0], options);
|
|
448
|
+
console.log(formatUninstallOutput(result));
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
422
452
|
case "verify": {
|
|
423
453
|
const result = await verifyCommand(rest[0], options);
|
|
424
454
|
console.log(formatVerifyOutput(result));
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uninstall Command
|
|
3
|
+
* 卸载已安装的 Agent
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { pathExists, readJson, writeJson, removeDir } from "../lib/fs-utils.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 卸载已安装的 Agent
|
|
11
|
+
* @param {string} agentSpec - Agent slug 或 slug@version
|
|
12
|
+
* @param {object} options - 选项
|
|
13
|
+
* @returns {Promise<object>} 卸载结果
|
|
14
|
+
*/
|
|
15
|
+
export async function uninstallCommand(agentSpec, options = {}) {
|
|
16
|
+
const { slug } = parseSpec(agentSpec);
|
|
17
|
+
const targetWorkspace = path.resolve(options.targetWorkspace || process.cwd());
|
|
18
|
+
const agenthubDir = path.join(targetWorkspace, ".agenthub");
|
|
19
|
+
const installRecordPath = path.join(agenthubDir, "install.json");
|
|
20
|
+
|
|
21
|
+
// 检查安装记录是否存在
|
|
22
|
+
if (!(await pathExists(installRecordPath))) {
|
|
23
|
+
throw new Error(`未找到安装记录: ${slug}\n 该 Agent 可能未安装或安装记录已损坏`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 读取安装记录
|
|
27
|
+
const installRecord = await readJson(installRecordPath);
|
|
28
|
+
|
|
29
|
+
// 检查是否是该 Agent
|
|
30
|
+
if (installRecord.slug !== slug) {
|
|
31
|
+
throw new Error(`当前工作区安装的是 ${installRecord.slug},而非 ${slug}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 保存卸载信息
|
|
35
|
+
const uninstallInfo = {
|
|
36
|
+
slug: installRecord.slug,
|
|
37
|
+
version: installRecord.version,
|
|
38
|
+
installedAt: installRecord.installedAt,
|
|
39
|
+
uninstalledAt: new Date().toISOString(),
|
|
40
|
+
location: targetWorkspace,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 删除安装记录
|
|
44
|
+
await removeDir(agenthubDir);
|
|
45
|
+
|
|
46
|
+
return uninstallInfo;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 解析 agent spec
|
|
51
|
+
*/
|
|
52
|
+
function parseSpec(spec) {
|
|
53
|
+
const match = spec.match(/^([^@]+)(?:@(.+))?$/);
|
|
54
|
+
if (!match) {
|
|
55
|
+
throw new Error(`无效的 agent spec: ${spec}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
slug: match[1],
|
|
59
|
+
version: match[2] || null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 格式化卸载输出
|
|
65
|
+
*/
|
|
66
|
+
export function formatUninstallOutput(info) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
lines.push("\n🗑️ 卸载成功\n");
|
|
69
|
+
lines.push("─".repeat(50));
|
|
70
|
+
lines.push(` Agent: ${info.slug}@${info.version}`);
|
|
71
|
+
lines.push(` 安装时间: ${info.installedAt || "未知"}`);
|
|
72
|
+
lines.push(` 卸载时间: ${info.uninstalledAt}`);
|
|
73
|
+
lines.push("─".repeat(50));
|
|
74
|
+
lines.push(`\n💡 重新安装: agenthub install ${info.slug}\n`);
|
|
75
|
+
return lines.join("\n");
|
|
76
|
+
}
|
package/src/lib/debug.js
CHANGED
|
@@ -3,7 +3,27 @@
|
|
|
3
3
|
* 性能日志工具,用于调试和性能分析
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
let verboseMode = false;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 设置 verbose 模式
|
|
10
|
+
* @param {boolean} enabled - 是否启用
|
|
11
|
+
*/
|
|
12
|
+
export function setVerbose(enabled) {
|
|
13
|
+
verboseMode = enabled;
|
|
14
|
+
if (enabled) {
|
|
15
|
+
process.env.AGENTHUB_DEBUG = "true";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取是否处于 debug 模式
|
|
21
|
+
*/
|
|
22
|
+
export function isDebug() {
|
|
23
|
+
return verboseMode || process.env.AGENTHUB_DEBUG === "true" || process.env.AGENTHUB_DEBUG === "1";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const DEBUG = isDebug();
|
|
7
27
|
|
|
8
28
|
/**
|
|
9
29
|
* 计时器存储
|
package/src/lib/fs-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cp, mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
1
|
+
import { cp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
export async function ensureDir(dirPath) {
|
|
@@ -28,6 +28,10 @@ export async function pathExists(targetPath) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export async function removeDir(dirPath) {
|
|
32
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
export async function countFiles(dirPath) {
|
|
32
36
|
if (!(await pathExists(dirPath))) {
|
|
33
37
|
return 0;
|