@zshuangmu/agenthub 0.4.8 → 0.4.10
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/README.md +1 -0
- package/package.json +1 -1
- package/src/cli.js +22 -0
- package/src/commands/uninstall.js +76 -0
- package/src/lib/fs-utils.js +5 -1
package/README.md
CHANGED
|
@@ -148,6 +148,7 @@ agenthub verify code-review-assistant --registry ./.registry --target-workspace
|
|
|
148
148
|
| `info` | 查看 Agent 详情 |
|
|
149
149
|
| `install` | 安装 Agent 到 workspace |
|
|
150
150
|
| `list` | 列出已安装的 Agent |
|
|
151
|
+
| `uninstall` | 卸载已安装的 Agent |
|
|
151
152
|
| `verify` | 校验已安装 Agent 是否完整 |
|
|
152
153
|
| `versions` | 查看 Agent 版本历史 |
|
|
153
154
|
| `update` | 更新 Agent 到最新版 |
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -28,6 +28,7 @@ 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";
|
|
33
34
|
import { setVerbose, debug } from "./lib/debug.js";
|
|
@@ -66,6 +67,7 @@ AgentHub v${VERSION} - AI Agent 打包与分发平台
|
|
|
66
67
|
search 搜索 Registry 中的 Agent
|
|
67
68
|
info 查看 Agent 详情
|
|
68
69
|
list 列出当前目录/指定目录的已安装 Agent
|
|
70
|
+
uninstall 卸载已安装的 Agent
|
|
69
71
|
verify 校验已安装 Agent 是否完整可用
|
|
70
72
|
versions 查看 Agent 版本历史
|
|
71
73
|
update 更新已安装 Agent 到最新版
|
|
@@ -183,6 +185,19 @@ agenthub list - 列出已安装 Agent
|
|
|
183
185
|
agenthub list --target-workspace ./my-workspace
|
|
184
186
|
agenthub list --json
|
|
185
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
|
|
186
201
|
`,
|
|
187
202
|
verify: `
|
|
188
203
|
agenthub verify - 校验已安装 Agent
|
|
@@ -427,6 +442,13 @@ async function main() {
|
|
|
427
442
|
return;
|
|
428
443
|
}
|
|
429
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
|
+
|
|
430
452
|
case "verify": {
|
|
431
453
|
const result = await verifyCommand(rest[0], options);
|
|
432
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/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;
|