agentdock-cli 0.5.0 → 0.7.0
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 +15 -4
- package/dist/package.json +15 -9
- package/dist/src/cli.js +26 -1
- package/dist/src/commands/config.js +78 -0
- package/dist/src/commands/diff.js +62 -0
- package/dist/src/commands/export.js +3 -1
- package/dist/src/commands/install.js +26 -2
- package/dist/src/commands/report.js +70 -0
- package/dist/src/commands/scan.js +6 -2
- package/dist/src/commands/uninstall.js +81 -0
- package/dist/src/constants/command-error-codes.js +1 -0
- package/dist/src/core/config.js +83 -0
- package/dist/src/core/installer.js +155 -48
- package/dist/src/core/report-html.js +311 -0
- package/dist/src/core/report.js +243 -0
- package/dist/src/core/scan-export.js +9 -1
- package/dist/src/core/uninstall.js +159 -0
- package/dist/src/i18n/index.js +108 -0
- package/dist/src/utils/fs.js +5 -3
- package/dist/src/utils/plan-render.js +42 -0
- package/package.json +15 -9
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# AgentDock
|
|
2
2
|
|
|
3
|
-
> 你的 AI 编码助手(Claude Code / Codex
|
|
4
|
-
>
|
|
3
|
+
> 你的 AI 编码助手(Claude Code / Codex)的**诊断 · 迁移 · 交付**工具。
|
|
4
|
+
> 一条命令体检环境,生成中文 HTML 报告与修复建议;再把 MCP Server、Skill、Agent、Plugin、Hook、记忆**原样、安全、可复现**地搬到另一台机器 —— **而且绝不把 token 一起带走。**
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/agentdock-cli)
|
|
7
7
|
[](./LICENSE)
|
|
@@ -33,6 +33,9 @@ npx agentdock-cli --help
|
|
|
33
33
|
## 30 秒上手
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
+
# 0. 先体检:生成中文 HTML 报告(健康分 + 检查明细 + 修复建议 + 可分享卡片)
|
|
37
|
+
agentdock report --agent all --out ./report
|
|
38
|
+
|
|
36
39
|
# 1. 扫描当前机器的 AI 助手环境(自动隔离敏感信息)
|
|
37
40
|
agentdock scan --agent all --root ~ --out ./my-env
|
|
38
41
|
|
|
@@ -127,15 +130,23 @@ restore/
|
|
|
127
130
|
|---|---|---|
|
|
128
131
|
| `scan` | 发现并提取 AI 助手环境,隔离敏感信息,产出 v3 manifest | `agentdock scan --agent all --root ~ --out ./out` |
|
|
129
132
|
| `export` | 把扫描产物打包成可迁移包(默认打码,`--env` 回注) | `agentdock export --from-scan ./out/agentdock.scan.yml --out ./pkg` |
|
|
130
|
-
| `install` | 从包安全还原到目标机(越界校验 / 锁 / 原子写 /
|
|
133
|
+
| `install` | 从包安全还原到目标机(越界校验 / 锁 / 原子写 / 幂等);`--dry-run` 只预览不落盘 | `agentdock install ./pkg ~` |
|
|
131
134
|
| `validate` | 校验 manifest 合法性 | `agentdock validate ./pkg/manifest.resolved.json` |
|
|
132
135
|
| `doctor` | 体检环境 / 包:配置健康度、可迁移性、是否泄密(每项附**修复建议**) | `agentdock doctor --agent all --root ~` |
|
|
136
|
+
| `report` | 生成可分享的环境健康报告(评分 / 清单 / 检查 / 修复建议,HTML + JSON);`--profile xinchuang` 追加信创适配启发式检查(需人工确认) | `agentdock report --agent all --out ./report` |
|
|
137
|
+
| `list` | 列出已捕获的 MCP / Skill / Agent 等定义清单 | `agentdock list --package ./pkg` |
|
|
138
|
+
| `diff` | 对比「包内容」与「目标机现状」:哪些新增 / 相同 / 变更 / 需合并 / 会冲突(不落盘) | `agentdock diff ./pkg ~` |
|
|
139
|
+
| `config` | 管理 AgentDock 自身配置(`agent` / `out` / `env` 默认值),存于 `~/.agentdock/config.json` | `agentdock config set agent codex` |
|
|
140
|
+
| `uninstall` | 反向卸载:移除包安装的文件/目录,按「与包内容是否一致」安全删除,merge 条目精确摘回包贡献的键(不动用户改动) | `agentdock uninstall ./pkg ~` |
|
|
133
141
|
|
|
134
142
|
`doctor` 退出码已量化,便于 CI / 自动化区分严重度:**0** = 全通过、**1** = 仅有警告(可迁移但有隐患)、**2** = 存在失败(需处理)。加 `--json` 可机读,remediation 字段随报告一同返回。
|
|
135
|
-
| `list` | 列出已捕获的 MCP / Skill / Agent 等定义清单 | `agentdock list --package ./pkg` |
|
|
136
143
|
|
|
137
144
|
支持的双助手:**Claude Code**(JSON:`settings.json` + `.claude.json`)与 **Codex**(TOML:`config.toml` + `AGENTS.md`)。
|
|
138
145
|
|
|
146
|
+
**Codex 配置合并(与 Claude 同权)**:`config.toml` 以 `merge` 方式安装——目标机若已存在 `config.toml`,只深度合并包内的 `mcp_servers`,**保留其原有的 `model` / `provider` 等设置**,绝不整体覆盖;全新目标机则整文件还原。卸载时同样只精确摘回包贡献的 `mcp_servers`,不动用户既有配置。这与 Claude `.claude.json` 仅合并 `mcpServers` 的语义完全对齐。
|
|
147
|
+
|
|
148
|
+
**多语言输出(i18n)**:人类可读的命令行输出支持 `en`(默认)与 `zh-CN`,通过环境变量 `AGENTDOCK_LANG` 或 `agentdock config set lang <en|zh-CN>` 切换。`--json` 输出始终为英文(机器按 key 解析,不本地化)。
|
|
149
|
+
|
|
139
150
|
## 安全承诺
|
|
140
151
|
|
|
141
152
|
- **敏感三层隔离**:字段名 + 值形态双重识别,命中即替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}`,原值进 `.env.example`,绝不下盘。
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Diagnose, migrate, and back up your AI coding assistant environment (Claude Code / Codex) — Chinese health reports, MCP servers, Skills, Agents, Plugins, Hooks, and memory, with secret isolation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
7
7
|
"codex",
|
|
@@ -12,7 +12,12 @@
|
|
|
12
12
|
"versioning",
|
|
13
13
|
"mcp",
|
|
14
14
|
"skills",
|
|
15
|
-
"cli"
|
|
15
|
+
"cli",
|
|
16
|
+
"report",
|
|
17
|
+
"diagnostics",
|
|
18
|
+
"health-check",
|
|
19
|
+
"audit",
|
|
20
|
+
"air-gapped"
|
|
16
21
|
],
|
|
17
22
|
"type": "commonjs",
|
|
18
23
|
"bin": {
|
|
@@ -35,17 +40,18 @@
|
|
|
35
40
|
"release:commits": "node scripts/generate-commit-groups.js"
|
|
36
41
|
},
|
|
37
42
|
"dependencies": {
|
|
38
|
-
"ajv": "^8.
|
|
43
|
+
"ajv": "^8.20.0",
|
|
39
44
|
"diff": "^8.0.4",
|
|
40
|
-
"
|
|
41
|
-
"smol-toml": "^1.
|
|
45
|
+
"picomatch": "^4.0.7",
|
|
46
|
+
"smol-toml": "^1.9.1",
|
|
42
47
|
"yaml": "^2.8.1"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^24.
|
|
46
|
-
"
|
|
50
|
+
"@types/node": "^24.19.4",
|
|
51
|
+
"@types/picomatch": "^4.0.3",
|
|
52
|
+
"tsx": "^4.23.15",
|
|
47
53
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^
|
|
54
|
+
"vitest": "^4.1.12"
|
|
49
55
|
},
|
|
50
56
|
"author": "spsz831",
|
|
51
57
|
"license": "MIT",
|
package/dist/src/cli.js
CHANGED
|
@@ -6,8 +6,13 @@ const export_1 = require("./commands/export");
|
|
|
6
6
|
const install_1 = require("./commands/install");
|
|
7
7
|
const scan_1 = require("./commands/scan");
|
|
8
8
|
const doctor_1 = require("./commands/doctor");
|
|
9
|
+
const report_1 = require("./commands/report");
|
|
9
10
|
const list_1 = require("./commands/list");
|
|
10
11
|
const validate_1 = require("./commands/validate");
|
|
12
|
+
const diff_1 = require("./commands/diff");
|
|
13
|
+
const config_1 = require("./commands/config");
|
|
14
|
+
const uninstall_1 = require("./commands/uninstall");
|
|
15
|
+
const i18n_1 = require("./i18n");
|
|
11
16
|
function parseCliOptions(args) {
|
|
12
17
|
const positionals = [];
|
|
13
18
|
const options = {};
|
|
@@ -64,6 +69,17 @@ function parseCliOptions(args) {
|
|
|
64
69
|
}
|
|
65
70
|
continue;
|
|
66
71
|
}
|
|
72
|
+
if (arg === '--profile') {
|
|
73
|
+
const nextArg = args[index + 1];
|
|
74
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
75
|
+
options.profile = nextArg === 'xinchuang' ? 'xinchuang' : 'default';
|
|
76
|
+
index += 1;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
positionals.push(arg);
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
67
83
|
if (arg === '--from-scan' || arg === '--env' || arg === '--package') {
|
|
68
84
|
const nextArg = args[index + 1];
|
|
69
85
|
if (nextArg && !nextArg.startsWith('--')) {
|
|
@@ -85,6 +101,7 @@ function parseCliOptions(args) {
|
|
|
85
101
|
return { positionals, options };
|
|
86
102
|
}
|
|
87
103
|
async function runCli(args) {
|
|
104
|
+
await (0, i18n_1.initI18n)();
|
|
88
105
|
const [command, ...rest] = args;
|
|
89
106
|
const { positionals, options } = parseCliOptions(rest);
|
|
90
107
|
switch (command) {
|
|
@@ -98,13 +115,21 @@ async function runCli(args) {
|
|
|
98
115
|
return (0, scan_1.runScanCommand)(options);
|
|
99
116
|
case 'doctor':
|
|
100
117
|
return (0, doctor_1.runDoctorCommand)(options);
|
|
118
|
+
case 'report':
|
|
119
|
+
return (0, report_1.runReportCommand)(options);
|
|
101
120
|
case 'list':
|
|
102
121
|
return (0, list_1.runListCommand)(options);
|
|
122
|
+
case 'diff':
|
|
123
|
+
return (0, diff_1.runDiffCommand)(positionals[0], positionals[1], options);
|
|
124
|
+
case 'config':
|
|
125
|
+
return (0, config_1.runConfigCommand)(positionals, options);
|
|
126
|
+
case 'uninstall':
|
|
127
|
+
return (0, uninstall_1.runUninstallCommand)(positionals[0], positionals[1], options);
|
|
103
128
|
default:
|
|
104
129
|
return {
|
|
105
130
|
exitCode: 1,
|
|
106
131
|
stdout: [],
|
|
107
|
-
stderr: [
|
|
132
|
+
stderr: [(0, i18n_1.t)('cli.usage')],
|
|
108
133
|
};
|
|
109
134
|
}
|
|
110
135
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runConfigCommand = runConfigCommand;
|
|
4
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
5
|
+
const command_json_1 = require("../utils/command-json");
|
|
6
|
+
const i18n_1 = require("../i18n");
|
|
7
|
+
const config_1 = require("../core/config");
|
|
8
|
+
async function runConfigCommand(positionals = [], options = {}) {
|
|
9
|
+
const sub = positionals[0];
|
|
10
|
+
const usage = (message) => {
|
|
11
|
+
if (options.json === true) {
|
|
12
|
+
return {
|
|
13
|
+
exitCode: 1,
|
|
14
|
+
stdout: [(0, command_json_1.toJsonLine)('config', false, { path: (0, config_1.getConfigPath)() }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, message)])],
|
|
15
|
+
stderr: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return { exitCode: 1, stdout: [], stderr: [message] };
|
|
19
|
+
};
|
|
20
|
+
// `config` / `config list` — show all settings.
|
|
21
|
+
if (!sub || sub === 'list') {
|
|
22
|
+
const config = await (0, config_1.loadConfig)();
|
|
23
|
+
if (options.json === true) {
|
|
24
|
+
return {
|
|
25
|
+
exitCode: 0,
|
|
26
|
+
stdout: [(0, command_json_1.toJsonLine)('config', true, { path: (0, config_1.getConfigPath)(), config }, [])],
|
|
27
|
+
stderr: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const lines = [(0, i18n_1.t)('config.file', { path: (0, config_1.getConfigPath)() })];
|
|
31
|
+
if (Object.keys(config).length === 0) {
|
|
32
|
+
lines.push(` ${(0, i18n_1.t)('config.noSettings')}`);
|
|
33
|
+
}
|
|
34
|
+
for (const key of (0, config_1.listConfigKeys)()) {
|
|
35
|
+
const value = config[key];
|
|
36
|
+
lines.push(` ${key} = ${value ?? (0, i18n_1.t)('config.unsetValue')}`);
|
|
37
|
+
}
|
|
38
|
+
return { exitCode: 0, stdout: lines, stderr: [] };
|
|
39
|
+
}
|
|
40
|
+
if (sub === 'get') {
|
|
41
|
+
const key = positionals[1];
|
|
42
|
+
if (!key || !(0, config_1.isConfigKey)(key)) {
|
|
43
|
+
return usage((0, i18n_1.t)('config.usage'));
|
|
44
|
+
}
|
|
45
|
+
const config = await (0, config_1.loadConfig)();
|
|
46
|
+
const value = config[key];
|
|
47
|
+
if (options.json === true) {
|
|
48
|
+
return {
|
|
49
|
+
exitCode: 0,
|
|
50
|
+
stdout: [(0, command_json_1.toJsonLine)('config', true, { path: (0, config_1.getConfigPath)(), key, value: value ?? null }, [])],
|
|
51
|
+
stderr: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { exitCode: 0, stdout: [value ?? (0, i18n_1.t)('config.unsetValue')], stderr: [] };
|
|
55
|
+
}
|
|
56
|
+
if (sub === 'set') {
|
|
57
|
+
const key = positionals[1];
|
|
58
|
+
const value = positionals[2];
|
|
59
|
+
if (!key || !(0, config_1.isConfigKey)(key) || value === undefined) {
|
|
60
|
+
return usage((0, i18n_1.t)('config.usage'));
|
|
61
|
+
}
|
|
62
|
+
const ck = key;
|
|
63
|
+
const err = (0, config_1.validateConfigValue)(ck, value);
|
|
64
|
+
if (err) {
|
|
65
|
+
return usage((0, i18n_1.t)('config.invalidValue', { key: ck, reason: err }));
|
|
66
|
+
}
|
|
67
|
+
const next = await (0, config_1.setConfig)(ck, value);
|
|
68
|
+
if (options.json === true) {
|
|
69
|
+
return {
|
|
70
|
+
exitCode: 0,
|
|
71
|
+
stdout: [(0, command_json_1.toJsonLine)('config', true, { path: (0, config_1.getConfigPath)(), key: ck, value: next[ck] }, [])],
|
|
72
|
+
stderr: [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { exitCode: 0, stdout: [(0, i18n_1.t)('config.set', { key: ck, value: next[ck] ?? '' })], stderr: [] };
|
|
76
|
+
}
|
|
77
|
+
return usage((0, i18n_1.t)('config.usage'));
|
|
78
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDiffCommand = runDiffCommand;
|
|
4
|
+
const installer_1 = require("../core/installer");
|
|
5
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
6
|
+
const command_json_1 = require("../utils/command-json");
|
|
7
|
+
const plan_render_1 = require("../utils/plan-render");
|
|
8
|
+
async function runDiffCommand(packagePath, targetPath, options = {}) {
|
|
9
|
+
if (!packagePath) {
|
|
10
|
+
if (options.json === true) {
|
|
11
|
+
return {
|
|
12
|
+
exitCode: 1,
|
|
13
|
+
stdout: [(0, command_json_1.toJsonLine)('diff', false, { packagePath: null, targetPath: targetPath ?? null, overwrite: options.overwrite === true }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, 'Usage: agentdock diff <packagePath> [targetPath] [--overwrite]')])],
|
|
14
|
+
stderr: [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
exitCode: 1,
|
|
19
|
+
stdout: [],
|
|
20
|
+
stderr: ['Usage: agentdock diff <packagePath> [targetPath] [--overwrite]'],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const plan = await (0, installer_1.planInstall)(packagePath, targetPath, options.overwrite === true);
|
|
25
|
+
if (options.json === true) {
|
|
26
|
+
return {
|
|
27
|
+
exitCode: 0,
|
|
28
|
+
stdout: [(0, command_json_1.toJsonLine)('diff', true, {
|
|
29
|
+
packagePath,
|
|
30
|
+
targetPath: plan.targetPath,
|
|
31
|
+
overwrite: options.overwrite === true,
|
|
32
|
+
entries: plan.entries,
|
|
33
|
+
conflicts: plan.conflicts.length,
|
|
34
|
+
}, [])],
|
|
35
|
+
stderr: [],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
exitCode: 0,
|
|
40
|
+
stdout: (0, plan_render_1.renderPlan)(plan, 'diff'),
|
|
41
|
+
stderr: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
+
if (options.json === true) {
|
|
47
|
+
let code = command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
48
|
+
if (message.includes('Missing package manifest snapshot')) {
|
|
49
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_PACKAGE_MANIFEST;
|
|
50
|
+
}
|
|
51
|
+
else if (message.includes('Missing install plan')) {
|
|
52
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_INSTALL_PLAN;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
exitCode: 1,
|
|
56
|
+
stdout: [(0, command_json_1.toJsonLine)('diff', false, { packagePath, targetPath: targetPath ?? null, overwrite: options.overwrite === true }, [(0, command_json_1.toJsonError)(code, message)])],
|
|
57
|
+
stderr: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { exitCode: 1, stdout: [], stderr: [message] };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -7,11 +7,13 @@ exports.runExportCommand = runExportCommand;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const exporter_1 = require("../core/exporter");
|
|
9
9
|
const scan_export_1 = require("../core/scan-export");
|
|
10
|
+
const config_1 = require("../core/config");
|
|
10
11
|
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
11
12
|
const load_1 = require("../manifest/load");
|
|
12
13
|
const validate_1 = require("../manifest/validate");
|
|
13
14
|
const command_json_1 = require("../utils/command-json");
|
|
14
15
|
async function runExportCommand(manifestPath, options = {}) {
|
|
16
|
+
const config = await (0, config_1.loadConfig)();
|
|
15
17
|
// `scan` → package bridge: build an installable package from a v3 scan manifest.
|
|
16
18
|
if (options.fromScan) {
|
|
17
19
|
const out = options.out
|
|
@@ -21,7 +23,7 @@ async function runExportCommand(manifestPath, options = {}) {
|
|
|
21
23
|
const exportResult = await (0, scan_export_1.exportFromScan)({
|
|
22
24
|
scanManifestPath: options.fromScan,
|
|
23
25
|
out,
|
|
24
|
-
env: options.env ? node_path_1.default.resolve(options.env) : undefined,
|
|
26
|
+
env: options.env ? node_path_1.default.resolve(options.env) : (config.env ? node_path_1.default.resolve(config.env) : undefined),
|
|
25
27
|
overwrite: options.overwrite,
|
|
26
28
|
});
|
|
27
29
|
if (options.json === true) {
|
|
@@ -4,6 +4,8 @@ exports.runInstallCommand = runInstallCommand;
|
|
|
4
4
|
const installer_1 = require("../core/installer");
|
|
5
5
|
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
6
6
|
const command_json_1 = require("../utils/command-json");
|
|
7
|
+
const plan_render_1 = require("../utils/plan-render");
|
|
8
|
+
const i18n_1 = require("../i18n");
|
|
7
9
|
async function runInstallCommand(packagePath, targetPath, options = {}) {
|
|
8
10
|
if (!packagePath) {
|
|
9
11
|
if (options.json === true) {
|
|
@@ -20,7 +22,29 @@ async function runInstallCommand(packagePath, targetPath, options = {}) {
|
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
try {
|
|
23
|
-
const result = await (0, installer_1.installPackage)(packagePath, targetPath, options.overwrite === true);
|
|
25
|
+
const result = await (0, installer_1.installPackage)(packagePath, targetPath, options.overwrite === true, options.dryRun === true);
|
|
26
|
+
if (options.dryRun === true) {
|
|
27
|
+
const plan = result.plan;
|
|
28
|
+
if (options.json === true) {
|
|
29
|
+
return {
|
|
30
|
+
exitCode: 0,
|
|
31
|
+
stdout: [(0, command_json_1.toJsonLine)('install', true, {
|
|
32
|
+
packagePath,
|
|
33
|
+
targetPath: result.targetPath,
|
|
34
|
+
dryRun: true,
|
|
35
|
+
overwrite: options.overwrite === true,
|
|
36
|
+
entries: plan.entries,
|
|
37
|
+
conflicts: plan.conflicts.length,
|
|
38
|
+
}, [])],
|
|
39
|
+
stderr: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
exitCode: 0,
|
|
44
|
+
stdout: (0, plan_render_1.renderPlan)(plan, 'dry-run'),
|
|
45
|
+
stderr: [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
24
48
|
if (options.json === true) {
|
|
25
49
|
return {
|
|
26
50
|
exitCode: 0,
|
|
@@ -34,7 +58,7 @@ async function runInstallCommand(packagePath, targetPath, options = {}) {
|
|
|
34
58
|
}
|
|
35
59
|
return {
|
|
36
60
|
exitCode: 0,
|
|
37
|
-
stdout: [
|
|
61
|
+
stdout: [(0, i18n_1.t)('install.complete', { path: result.targetPath })],
|
|
38
62
|
stderr: [],
|
|
39
63
|
};
|
|
40
64
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runReportCommand = runReportCommand;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const doctor_1 = require("../core/doctor");
|
|
9
|
+
const report_1 = require("../core/report");
|
|
10
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
11
|
+
const command_json_1 = require("../utils/command-json");
|
|
12
|
+
async function runReportCommand(options = {}) {
|
|
13
|
+
const agent = options.agent ?? 'all';
|
|
14
|
+
const out = options.out ? node_path_1.default.resolve(options.out) : node_path_1.default.resolve('agentdock-report');
|
|
15
|
+
const profile = options.profile ?? 'default';
|
|
16
|
+
try {
|
|
17
|
+
const report = await (0, report_1.runReport)({
|
|
18
|
+
agent,
|
|
19
|
+
root: options.root,
|
|
20
|
+
fromScan: options.fromScan,
|
|
21
|
+
package: options.package,
|
|
22
|
+
out,
|
|
23
|
+
profile,
|
|
24
|
+
});
|
|
25
|
+
if (options.json === true) {
|
|
26
|
+
return {
|
|
27
|
+
exitCode: (0, doctor_1.doctorExitCode)(report),
|
|
28
|
+
stdout: [(0, command_json_1.toJsonLine)('report', report.healthy, report, [])],
|
|
29
|
+
stderr: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const lines = [
|
|
33
|
+
`Report (${report.mode})${report.agent ? ` agent=${report.agent}` : ''} — ${report.score}/100 (${report.grade})`,
|
|
34
|
+
report.summary,
|
|
35
|
+
`可迁移定义: ${report.inventory.totalEntries} 项 · 隔离机密: ${report.inventory.secretsCount} 个`,
|
|
36
|
+
...report.checks.flatMap((check) => {
|
|
37
|
+
const checkLines = [` [${check.status.toUpperCase()}] ${check.label} — ${check.detail}`];
|
|
38
|
+
if (check.remediation && check.status !== 'pass') {
|
|
39
|
+
checkLines.push(` → 建议: ${check.remediation}`);
|
|
40
|
+
}
|
|
41
|
+
return checkLines;
|
|
42
|
+
}),
|
|
43
|
+
...(report.htmlPath ? [`html: ${report.htmlPath}`, `json: ${report.jsonPath}`] : []),
|
|
44
|
+
];
|
|
45
|
+
return { exitCode: (0, doctor_1.doctorExitCode)(report), stdout: lines, stderr: [] };
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
49
|
+
if (options.json === true) {
|
|
50
|
+
const data = {
|
|
51
|
+
mode: 'live',
|
|
52
|
+
agent,
|
|
53
|
+
target: '',
|
|
54
|
+
healthy: false,
|
|
55
|
+
checks: [],
|
|
56
|
+
summary: message,
|
|
57
|
+
profile,
|
|
58
|
+
score: 0,
|
|
59
|
+
grade: 'D',
|
|
60
|
+
inventory: { agents: [], totalEntries: 0, secretsCount: 0 },
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
exitCode: 2,
|
|
64
|
+
stdout: [(0, command_json_1.toJsonLine)('report', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.REPORT_FAILED, message)])],
|
|
65
|
+
stderr: [],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { exitCode: 2, stdout: [], stderr: [message] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -6,12 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.runScanCommand = runScanCommand;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const scan_1 = require("../core/scan");
|
|
9
|
+
const config_1 = require("../core/config");
|
|
9
10
|
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
11
|
const command_json_1 = require("../utils/command-json");
|
|
11
12
|
async function runScanCommand(options = {}) {
|
|
12
|
-
const
|
|
13
|
+
const config = await (0, config_1.loadConfig)();
|
|
14
|
+
const agent = options.agent ?? config.agent ?? 'all';
|
|
13
15
|
const root = options.root ?? (0, scan_1.defaultScanRoot)();
|
|
14
|
-
const out = options.out
|
|
16
|
+
const out = options.out
|
|
17
|
+
? node_path_1.default.resolve(options.out)
|
|
18
|
+
: (config.out ? node_path_1.default.resolve(config.out) : node_path_1.default.resolve('agentdock-scan'));
|
|
15
19
|
try {
|
|
16
20
|
const { report } = await (0, scan_1.runScan)({ agent, root, out });
|
|
17
21
|
if (options.json === true) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runUninstallCommand = runUninstallCommand;
|
|
4
|
+
const uninstall_1 = require("../core/uninstall");
|
|
5
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
6
|
+
const command_json_1 = require("../utils/command-json");
|
|
7
|
+
const i18n_1 = require("../i18n");
|
|
8
|
+
const ACTION_LABEL = {
|
|
9
|
+
'remove-file': 'REMOVE ',
|
|
10
|
+
'remove-dir': 'REMOVE ',
|
|
11
|
+
unmerge: 'UNMERGE ',
|
|
12
|
+
'skip-missing': 'SKIP(missing)',
|
|
13
|
+
'skip-modified': 'SKIP(modified)',
|
|
14
|
+
};
|
|
15
|
+
function renderUninstall(targetPath, removed, skipped, dryRun) {
|
|
16
|
+
const lines = [
|
|
17
|
+
dryRun ? (0, i18n_1.t)('uninstall.dryRunHeader', { path: targetPath }) : (0, i18n_1.t)('uninstall.complete', { path: targetPath }),
|
|
18
|
+
];
|
|
19
|
+
for (const entry of [...removed, ...skipped]) {
|
|
20
|
+
const label = ACTION_LABEL[entry.action];
|
|
21
|
+
const note = entry.note ? ` (${entry.note})` : '';
|
|
22
|
+
lines.push(` ${label} ${entry.to}${note}`);
|
|
23
|
+
}
|
|
24
|
+
lines.push(` ${removed.length} removed, ${skipped.length} skipped`);
|
|
25
|
+
return lines;
|
|
26
|
+
}
|
|
27
|
+
async function runUninstallCommand(packagePath, targetPath, options = {}) {
|
|
28
|
+
if (!packagePath) {
|
|
29
|
+
if (options.json === true) {
|
|
30
|
+
return {
|
|
31
|
+
exitCode: 1,
|
|
32
|
+
stdout: [(0, command_json_1.toJsonLine)('uninstall', false, { packagePath: null, targetPath: targetPath ?? null, dryRun: options.dryRun === true, force: options.force === true }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, 'Usage: agentdock uninstall <packagePath> [targetPath] [--force] [--dry-run]')])],
|
|
33
|
+
stderr: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
exitCode: 1,
|
|
38
|
+
stdout: [],
|
|
39
|
+
stderr: ['Usage: agentdock uninstall <packagePath> [targetPath] [--force] [--dry-run]'],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = await (0, uninstall_1.uninstallPackage)(packagePath, targetPath, options.dryRun === true, options.force === true);
|
|
44
|
+
if (options.json === true) {
|
|
45
|
+
return {
|
|
46
|
+
exitCode: 0,
|
|
47
|
+
stdout: [(0, command_json_1.toJsonLine)('uninstall', true, {
|
|
48
|
+
packagePath,
|
|
49
|
+
targetPath: result.targetPath,
|
|
50
|
+
removed: result.removed,
|
|
51
|
+
skipped: result.skipped,
|
|
52
|
+
dryRun: result.dryRun,
|
|
53
|
+
}, [])],
|
|
54
|
+
stderr: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
exitCode: 0,
|
|
59
|
+
stdout: renderUninstall(result.targetPath, result.removed, result.skipped, result.dryRun),
|
|
60
|
+
stderr: [],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
65
|
+
if (options.json === true) {
|
|
66
|
+
let code = command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
67
|
+
if (message.includes('Missing package manifest snapshot')) {
|
|
68
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_PACKAGE_MANIFEST;
|
|
69
|
+
}
|
|
70
|
+
else if (message.includes('Missing install plan')) {
|
|
71
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_INSTALL_PLAN;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
exitCode: 1,
|
|
75
|
+
stdout: [(0, command_json_1.toJsonLine)('uninstall', false, { packagePath, targetPath: targetPath ?? null, dryRun: options.dryRun === true, force: options.force === true }, [(0, command_json_1.toJsonError)(code, message)])],
|
|
76
|
+
stderr: [],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return { exitCode: 1, stdout: [], stderr: [message] };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfigPath = getConfigPath;
|
|
7
|
+
exports.listConfigKeys = listConfigKeys;
|
|
8
|
+
exports.isConfigKey = isConfigKey;
|
|
9
|
+
exports.loadConfig = loadConfig;
|
|
10
|
+
exports.validateConfigValue = validateConfigValue;
|
|
11
|
+
exports.setConfig = setConfig;
|
|
12
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
13
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
14
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const fs_1 = require("../utils/fs");
|
|
16
|
+
const CONFIG_KEYS = ['agent', 'out', 'env', 'lang'];
|
|
17
|
+
const AGENT_VALUES = ['claude', 'codex', 'all'];
|
|
18
|
+
const LANG_VALUES = ['en', 'zh-CN'];
|
|
19
|
+
function configPath() {
|
|
20
|
+
const override = process.env.AGENTDOCK_CONFIG;
|
|
21
|
+
if (override && override.length > 0) {
|
|
22
|
+
return node_path_1.default.resolve(override);
|
|
23
|
+
}
|
|
24
|
+
return node_path_1.default.join(node_os_1.default.homedir(), '.agentdock', 'config.json');
|
|
25
|
+
}
|
|
26
|
+
function configDir() {
|
|
27
|
+
return node_path_1.default.dirname(configPath());
|
|
28
|
+
}
|
|
29
|
+
function getConfigPath() {
|
|
30
|
+
return configPath();
|
|
31
|
+
}
|
|
32
|
+
function listConfigKeys() {
|
|
33
|
+
return [...CONFIG_KEYS];
|
|
34
|
+
}
|
|
35
|
+
function isConfigKey(value) {
|
|
36
|
+
return CONFIG_KEYS.includes(value);
|
|
37
|
+
}
|
|
38
|
+
function sanitizeConfig(parsed) {
|
|
39
|
+
const out = {};
|
|
40
|
+
if (parsed.agent && AGENT_VALUES.includes(parsed.agent)) {
|
|
41
|
+
out.agent = parsed.agent;
|
|
42
|
+
}
|
|
43
|
+
if (typeof parsed.out === 'string' && parsed.out.length > 0) {
|
|
44
|
+
out.out = parsed.out;
|
|
45
|
+
}
|
|
46
|
+
if (typeof parsed.env === 'string' && parsed.env.length > 0) {
|
|
47
|
+
out.env = parsed.env;
|
|
48
|
+
}
|
|
49
|
+
if (typeof parsed.lang === 'string' && LANG_VALUES.includes(parsed.lang)) {
|
|
50
|
+
out.lang = parsed.lang;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** Read AgentDock's own config. Missing/unreadable file → empty object (defaults apply). */
|
|
55
|
+
async function loadConfig() {
|
|
56
|
+
try {
|
|
57
|
+
const raw = await promises_1.default.readFile(configPath(), 'utf8');
|
|
58
|
+
return sanitizeConfig(JSON.parse(raw));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Validate a value for a given key; returns an error message or null if valid. */
|
|
65
|
+
function validateConfigValue(key, value) {
|
|
66
|
+
if (key === 'agent') {
|
|
67
|
+
return AGENT_VALUES.includes(value)
|
|
68
|
+
? null
|
|
69
|
+
: `agent must be one of: ${AGENT_VALUES.join(', ')}`;
|
|
70
|
+
}
|
|
71
|
+
if (key === 'lang') {
|
|
72
|
+
return LANG_VALUES.includes(value) ? null : `lang must be one of: ${LANG_VALUES.join(', ')}`;
|
|
73
|
+
}
|
|
74
|
+
// out / env are filesystem paths — accept any non-empty string.
|
|
75
|
+
return value.length > 0 ? null : `${key} must be a non-empty string`;
|
|
76
|
+
}
|
|
77
|
+
async function setConfig(key, value) {
|
|
78
|
+
const current = await loadConfig();
|
|
79
|
+
const next = { ...current, [key]: value };
|
|
80
|
+
await (0, fs_1.ensureDirectory)(configDir());
|
|
81
|
+
await promises_1.default.writeFile(configPath(), JSON.stringify(next, null, 2), 'utf8');
|
|
82
|
+
return next;
|
|
83
|
+
}
|