agentdock-cli 0.4.3 → 0.6.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 +9 -2
- package/dist/package.json +1 -1
- package/dist/src/cli.js +12 -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/scan.js +6 -2
- package/dist/src/commands/uninstall.js +81 -0
- package/dist/src/core/config.js +83 -0
- package/dist/src/core/doctor.js +4 -4
- package/dist/src/core/installer.js +179 -28
- package/dist/src/core/scan-export.js +95 -9
- package/dist/src/core/uninstall.js +159 -0
- package/dist/src/i18n/index.js +108 -0
- package/dist/src/scanners/sensitive.js +49 -0
- package/dist/src/utils/plan-render.js +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,15 +127,22 @@ restore/
|
|
|
127
127
|
|---|---|---|
|
|
128
128
|
| `scan` | 发现并提取 AI 助手环境,隔离敏感信息,产出 v3 manifest | `agentdock scan --agent all --root ~ --out ./out` |
|
|
129
129
|
| `export` | 把扫描产物打包成可迁移包(默认打码,`--env` 回注) | `agentdock export --from-scan ./out/agentdock.scan.yml --out ./pkg` |
|
|
130
|
-
| `install` | 从包安全还原到目标机(越界校验 / 锁 / 原子写 /
|
|
130
|
+
| `install` | 从包安全还原到目标机(越界校验 / 锁 / 原子写 / 幂等);`--dry-run` 只预览不落盘 | `agentdock install ./pkg ~` |
|
|
131
131
|
| `validate` | 校验 manifest 合法性 | `agentdock validate ./pkg/manifest.resolved.json` |
|
|
132
132
|
| `doctor` | 体检环境 / 包:配置健康度、可迁移性、是否泄密(每项附**修复建议**) | `agentdock doctor --agent all --root ~` |
|
|
133
|
+
| `list` | 列出已捕获的 MCP / Skill / Agent 等定义清单 | `agentdock list --package ./pkg` |
|
|
134
|
+
| `diff` | 对比「包内容」与「目标机现状」:哪些新增 / 相同 / 变更 / 需合并 / 会冲突(不落盘) | `agentdock diff ./pkg ~` |
|
|
135
|
+
| `config` | 管理 AgentDock 自身配置(`agent` / `out` / `env` 默认值),存于 `~/.agentdock/config.json` | `agentdock config set agent codex` |
|
|
136
|
+
| `uninstall` | 反向卸载:移除包安装的文件/目录,按「与包内容是否一致」安全删除,merge 条目精确摘回包贡献的键(不动用户改动) | `agentdock uninstall ./pkg ~` |
|
|
133
137
|
|
|
134
138
|
`doctor` 退出码已量化,便于 CI / 自动化区分严重度:**0** = 全通过、**1** = 仅有警告(可迁移但有隐患)、**2** = 存在失败(需处理)。加 `--json` 可机读,remediation 字段随报告一同返回。
|
|
135
|
-
| `list` | 列出已捕获的 MCP / Skill / Agent 等定义清单 | `agentdock list --package ./pkg` |
|
|
136
139
|
|
|
137
140
|
支持的双助手:**Claude Code**(JSON:`settings.json` + `.claude.json`)与 **Codex**(TOML:`config.toml` + `AGENTS.md`)。
|
|
138
141
|
|
|
142
|
+
**Codex 配置合并(与 Claude 同权)**:`config.toml` 以 `merge` 方式安装——目标机若已存在 `config.toml`,只深度合并包内的 `mcp_servers`,**保留其原有的 `model` / `provider` 等设置**,绝不整体覆盖;全新目标机则整文件还原。卸载时同样只精确摘回包贡献的 `mcp_servers`,不动用户既有配置。这与 Claude `.claude.json` 仅合并 `mcpServers` 的语义完全对齐。
|
|
143
|
+
|
|
144
|
+
**多语言输出(i18n)**:人类可读的命令行输出支持 `en`(默认)与 `zh-CN`,通过环境变量 `AGENTDOCK_LANG` 或 `agentdock config set lang <en|zh-CN>` 切换。`--json` 输出始终为英文(机器按 key 解析,不本地化)。
|
|
145
|
+
|
|
139
146
|
## 安全承诺
|
|
140
147
|
|
|
141
148
|
- **敏感三层隔离**:字段名 + 值形态双重识别,命中即替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}`,原值进 `.env.example`,绝不下盘。
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
package/dist/src/cli.js
CHANGED
|
@@ -8,6 +8,10 @@ const scan_1 = require("./commands/scan");
|
|
|
8
8
|
const doctor_1 = require("./commands/doctor");
|
|
9
9
|
const list_1 = require("./commands/list");
|
|
10
10
|
const validate_1 = require("./commands/validate");
|
|
11
|
+
const diff_1 = require("./commands/diff");
|
|
12
|
+
const config_1 = require("./commands/config");
|
|
13
|
+
const uninstall_1 = require("./commands/uninstall");
|
|
14
|
+
const i18n_1 = require("./i18n");
|
|
11
15
|
function parseCliOptions(args) {
|
|
12
16
|
const positionals = [];
|
|
13
17
|
const options = {};
|
|
@@ -85,6 +89,7 @@ function parseCliOptions(args) {
|
|
|
85
89
|
return { positionals, options };
|
|
86
90
|
}
|
|
87
91
|
async function runCli(args) {
|
|
92
|
+
await (0, i18n_1.initI18n)();
|
|
88
93
|
const [command, ...rest] = args;
|
|
89
94
|
const { positionals, options } = parseCliOptions(rest);
|
|
90
95
|
switch (command) {
|
|
@@ -100,11 +105,17 @@ async function runCli(args) {
|
|
|
100
105
|
return (0, doctor_1.runDoctorCommand)(options);
|
|
101
106
|
case 'list':
|
|
102
107
|
return (0, list_1.runListCommand)(options);
|
|
108
|
+
case 'diff':
|
|
109
|
+
return (0, diff_1.runDiffCommand)(positionals[0], positionals[1], options);
|
|
110
|
+
case 'config':
|
|
111
|
+
return (0, config_1.runConfigCommand)(positionals, options);
|
|
112
|
+
case 'uninstall':
|
|
113
|
+
return (0, uninstall_1.runUninstallCommand)(positionals[0], positionals[1], options);
|
|
103
114
|
default:
|
|
104
115
|
return {
|
|
105
116
|
exitCode: 1,
|
|
106
117
|
stdout: [],
|
|
107
|
-
stderr: [
|
|
118
|
+
stderr: [(0, i18n_1.t)('cli.usage')],
|
|
108
119
|
};
|
|
109
120
|
}
|
|
110
121
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
+
}
|
package/dist/src/core/doctor.js
CHANGED
|
@@ -220,7 +220,7 @@ async function doctorLiveClaude(root) {
|
|
|
220
220
|
if (leaks.length) {
|
|
221
221
|
leakFindings.push({
|
|
222
222
|
severity: 'error',
|
|
223
|
-
message: `在"原文复制"
|
|
223
|
+
message: `在"原文复制"文件(skills/agents/memory/hooks/plugins)中发现 ${leaks.length} 处疑似真实令牌;scan 不在扫描期打码,但 \`export --from-scan\` 会自动打码(安全),不会随包泄露`,
|
|
224
224
|
path: entry.path,
|
|
225
225
|
});
|
|
226
226
|
}
|
|
@@ -244,7 +244,7 @@ async function doctorLiveClaude(root) {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露', '
|
|
247
|
+
checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露', '免费文本中的明文令牌,`scan` 不在扫描期打码,但 `export --from-scan` 会自动打码(安全),不会随包泄露;若 `doctor --package` 仍报泄露,说明该文件未被正确打码,可手动将明文替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}` 占位符。'));
|
|
248
248
|
// 4. 运行态隔离
|
|
249
249
|
const runState = await walkForRunState(claudeDir);
|
|
250
250
|
const runStateFindings = runState.map((p) => ({
|
|
@@ -332,7 +332,7 @@ async function doctorLiveCodex(root) {
|
|
|
332
332
|
if (leaks.length) {
|
|
333
333
|
leakFindings.push({
|
|
334
334
|
severity: 'error',
|
|
335
|
-
message: `在"原文复制"
|
|
335
|
+
message: `在"原文复制"文件(skills/agents/memory/hooks/plugins)中发现 ${leaks.length} 处疑似真实令牌;scan 不在扫描期打码,但 \`export --from-scan\` 会自动打码(安全),不会随包泄露`,
|
|
336
336
|
path: entry.path,
|
|
337
337
|
});
|
|
338
338
|
}
|
|
@@ -354,7 +354,7 @@ async function doctorLiveCodex(root) {
|
|
|
354
354
|
// ignore
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露', '
|
|
357
|
+
checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露', '免费文本中的明文令牌,`scan` 不在扫描期打码,但 `export --from-scan` 会自动打码(安全),不会随包泄露;若 `doctor --package` 仍报泄露,说明该文件未被正确打码,可手动将明文替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}` 占位符。'));
|
|
358
358
|
// 4. 运行态隔离
|
|
359
359
|
const runState = await walkForRunState(codexDir);
|
|
360
360
|
const runStateFindings = runState.map((p) => ({
|
|
@@ -3,10 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.planInstall = planInstall;
|
|
6
7
|
exports.installPackage = installPackage;
|
|
7
8
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const smol_toml_1 = require("smol-toml");
|
|
9
11
|
const fs_1 = require("../utils/fs");
|
|
12
|
+
/** Parse a data file by its extension (TOML or JSON). */
|
|
13
|
+
function parseByExt(filePath, content) {
|
|
14
|
+
return node_path_1.default.extname(filePath).toLowerCase() === '.toml' ? (0, smol_toml_1.parse)(content) : JSON.parse(content);
|
|
15
|
+
}
|
|
10
16
|
async function isIdenticalFile(targetPath, sourcePath) {
|
|
11
17
|
try {
|
|
12
18
|
const [targetBuf, sourceBuf] = await Promise.all([
|
|
@@ -53,7 +59,86 @@ async function isIdenticalDirectory(targetPath, sourcePath) {
|
|
|
53
59
|
}
|
|
54
60
|
return true;
|
|
55
61
|
}
|
|
56
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Recursively merge `source` into `target`. Objects merge key-by-key
|
|
64
|
+
* (source wins on name conflict); arrays / primitives are replaced by source.
|
|
65
|
+
* Used so a merged `.claude.json` keeps the target's other top-level
|
|
66
|
+
* keys and its existing mcpServers while the package's servers win.
|
|
67
|
+
*/
|
|
68
|
+
function deepMerge(target, source) {
|
|
69
|
+
if (typeof source !== 'object' || source === null || Array.isArray(source)) {
|
|
70
|
+
return source;
|
|
71
|
+
}
|
|
72
|
+
if (typeof target !== 'object' || target === null || Array.isArray(target)) {
|
|
73
|
+
return source;
|
|
74
|
+
}
|
|
75
|
+
const out = { ...target };
|
|
76
|
+
for (const [key, value] of Object.entries(source)) {
|
|
77
|
+
out[key] = deepMerge(target[key], value);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** Deep-merge only `keys` from `source` into `target`; other target keys are left untouched. */
|
|
82
|
+
function mergeOnlyKeys(target, source, keys) {
|
|
83
|
+
const out = { ...target };
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
out[key] = deepMerge(out[key], source[key]);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Deep-merge a package payload into a target file, preserving the target's
|
|
91
|
+
* own file format (JSON or TOML). Used so a merged `.claude.json` (JSON) or
|
|
92
|
+
* Codex `.codex/config.toml` (TOML) keeps the target's other keys while the
|
|
93
|
+
* package's keys win. Never clobbers the target file format.
|
|
94
|
+
*
|
|
95
|
+
* When `mergeKeys` is given, only those top-level keys are merged (the rest
|
|
96
|
+
* of the target is preserved). On a *fresh* target (file absent) the whole
|
|
97
|
+
* payload is restored regardless, so a first install still carries the full
|
|
98
|
+
* configuration.
|
|
99
|
+
*/
|
|
100
|
+
async function mergeDataFile(from, to, mergeKeys) {
|
|
101
|
+
let source = {};
|
|
102
|
+
try {
|
|
103
|
+
source = parseByExt(from, await promises_1.default.readFile(from, 'utf8'));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
source = {};
|
|
107
|
+
}
|
|
108
|
+
// Fresh target: restore the entire payload (in the target's format).
|
|
109
|
+
if (!(await (0, fs_1.pathExists)(to))) {
|
|
110
|
+
if (node_path_1.default.extname(to).toLowerCase() === '.toml') {
|
|
111
|
+
await (0, fs_1.writeTextFile)(to, (0, smol_toml_1.stringify)(source));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
await (0, fs_1.writeJsonFile)(to, source);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
let target = {};
|
|
119
|
+
try {
|
|
120
|
+
target = parseByExt(to, await promises_1.default.readFile(to, 'utf8'));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
target = {};
|
|
124
|
+
}
|
|
125
|
+
const merged = mergeKeys && mergeKeys.length > 0
|
|
126
|
+
? mergeOnlyKeys(target, source, mergeKeys)
|
|
127
|
+
: deepMerge(target, source);
|
|
128
|
+
if (node_path_1.default.extname(to).toLowerCase() === '.toml') {
|
|
129
|
+
await (0, fs_1.writeTextFile)(to, (0, smol_toml_1.stringify)(merged));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
await (0, fs_1.writeJsonFile)(to, merged);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Produce a read-only preview of what `install` would do for a package
|
|
137
|
+
* against a target path — without writing anything. Boundary checks
|
|
138
|
+
* (`safeResolveWithin`) still run so path-traversal issues surface here.
|
|
139
|
+
* Shared by `install --dry-run` and the `diff` command.
|
|
140
|
+
*/
|
|
141
|
+
async function planInstall(packagePath, explicitTargetPath, overwrite = false) {
|
|
57
142
|
const packageRoot = node_path_1.default.resolve(packagePath);
|
|
58
143
|
const manifestSnapshotPath = node_path_1.default.join(packageRoot, 'manifest.resolved.json');
|
|
59
144
|
const installPlanPath = node_path_1.default.join(packageRoot, 'meta', 'install-plan.json');
|
|
@@ -65,51 +150,117 @@ async function installPackage(packagePath, explicitTargetPath, overwrite = false
|
|
|
65
150
|
}
|
|
66
151
|
const installPlan = await (0, fs_1.readJsonFile)(installPlanPath);
|
|
67
152
|
const effectiveOverwrite = overwrite || installPlan.overwrite === true;
|
|
68
|
-
// The target may live anywhere the user chooses (e.g. ~/.claude); only individual
|
|
69
|
-
// entries must stay within it. No boundary check against packageRoot here.
|
|
70
153
|
const targetRoot = node_path_1.default.resolve(explicitTargetPath ?? installPlan.targetPath ?? './installed');
|
|
71
|
-
|
|
72
|
-
// both the destination `to` and the source `from` fields of a malicious package).
|
|
73
|
-
const entries = [
|
|
154
|
+
const rawEntries = [
|
|
74
155
|
...installPlan.sources.map((source) => ({
|
|
75
156
|
from: (0, fs_1.safeResolveWithin)(packageRoot, source.from, 'source.from'),
|
|
76
157
|
to: (0, fs_1.safeResolveWithin)(targetRoot, source.to, 'source.to'),
|
|
77
158
|
kind: source.kind,
|
|
159
|
+
merge: source.merge ?? false,
|
|
160
|
+
mergeKeys: source.mergeKeys,
|
|
78
161
|
})),
|
|
79
162
|
...installPlan.templates.map((template) => ({
|
|
80
163
|
from: (0, fs_1.safeResolveWithin)(packageRoot, template.from, 'template.from'),
|
|
81
164
|
to: (0, fs_1.safeResolveWithin)(targetRoot, template.to, 'template.to'),
|
|
82
165
|
kind: 'template',
|
|
166
|
+
merge: false,
|
|
83
167
|
})),
|
|
84
168
|
];
|
|
169
|
+
const entries = [];
|
|
170
|
+
for (const entry of rawEntries) {
|
|
171
|
+
const exists = await (0, fs_1.pathExists)(entry.to);
|
|
172
|
+
let identical = false;
|
|
173
|
+
if (exists) {
|
|
174
|
+
identical = entry.kind === 'directory'
|
|
175
|
+
? await isIdenticalDirectory(entry.to, entry.from)
|
|
176
|
+
: await isIdenticalFile(entry.to, entry.from);
|
|
177
|
+
}
|
|
178
|
+
let action;
|
|
179
|
+
let note;
|
|
180
|
+
if (entry.merge) {
|
|
181
|
+
action = 'merge';
|
|
182
|
+
note = exists ? await describeMerge(entry.from, entry.to, entry.mergeKeys) : 'merge: target missing (will create)';
|
|
183
|
+
}
|
|
184
|
+
else if (!exists) {
|
|
185
|
+
action = 'create';
|
|
186
|
+
}
|
|
187
|
+
else if (identical) {
|
|
188
|
+
action = 'skip';
|
|
189
|
+
}
|
|
190
|
+
else if (effectiveOverwrite) {
|
|
191
|
+
action = 'overwrite';
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
action = 'conflict';
|
|
195
|
+
}
|
|
196
|
+
entries.push({ ...entry, merge: entry.merge ?? false, mergeKeys: entry.mergeKeys, exists, identical, action, note });
|
|
197
|
+
}
|
|
198
|
+
const conflicts = entries.filter((entry) => entry.action === 'conflict');
|
|
199
|
+
return { targetPath: targetRoot, entries, conflicts };
|
|
200
|
+
}
|
|
201
|
+
/** Human-readable summary of what a merge entry would add to the target file. */
|
|
202
|
+
async function describeMerge(sourcePath, targetPath, mergeKeys) {
|
|
203
|
+
try {
|
|
204
|
+
const source = parseByExt(sourcePath, await promises_1.default.readFile(sourcePath, 'utf8'));
|
|
205
|
+
const targetExists = await (0, fs_1.pathExists)(targetPath);
|
|
206
|
+
const target = targetExists
|
|
207
|
+
? parseByExt(targetPath, await promises_1.default.readFile(targetPath, 'utf8'))
|
|
208
|
+
: {};
|
|
209
|
+
// TOML config.toml uses `mcp_servers`; JSON .claude.json uses `mcpServers`.
|
|
210
|
+
const mcpKey = node_path_1.default.extname(sourcePath).toLowerCase() === '.toml' ? 'mcp_servers' : 'mcpServers';
|
|
211
|
+
const focusKey = mergeKeys && mergeKeys.length > 0
|
|
212
|
+
? (mergeKeys.find((k) => k === mcpKey) ?? mergeKeys[0])
|
|
213
|
+
: mcpKey;
|
|
214
|
+
const sourceServers = source[focusKey];
|
|
215
|
+
const targetServers = target[focusKey];
|
|
216
|
+
if (sourceServers && targetServers && typeof sourceServers === 'object') {
|
|
217
|
+
const added = Object.keys(sourceServers).filter((key) => !(key in targetServers));
|
|
218
|
+
if (added.length > 0) {
|
|
219
|
+
return `merge: adds ${focusKey} [${added.join(', ')}]`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (mergeKeys && mergeKeys.length > 0) {
|
|
223
|
+
const addedKeys = mergeKeys.filter((key) => !(key in target));
|
|
224
|
+
if (addedKeys.length > 0) {
|
|
225
|
+
return `merge: adds keys [${addedKeys.join(', ')}]`;
|
|
226
|
+
}
|
|
227
|
+
return `merge: no new keys in [${mergeKeys.join(', ')}]`;
|
|
228
|
+
}
|
|
229
|
+
const addedKeys = Object.keys(source).filter((key) => !(key in target));
|
|
230
|
+
if (addedKeys.length > 0) {
|
|
231
|
+
return `merge: adds keys [${addedKeys.join(', ')}]`;
|
|
232
|
+
}
|
|
233
|
+
return 'merge: no new top-level keys';
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return 'merge: deep-merge into existing';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function installPackage(packagePath, explicitTargetPath, overwrite = false, dryRun = false) {
|
|
240
|
+
const plan = await planInstall(packagePath, explicitTargetPath, overwrite);
|
|
241
|
+
// Dry-run: validate + preview only, never touch the target.
|
|
242
|
+
if (dryRun) {
|
|
243
|
+
return { targetPath: plan.targetPath, plan };
|
|
244
|
+
}
|
|
85
245
|
// Create the target root up front so the lock file parent exists.
|
|
86
|
-
await (0, fs_1.ensureDirectory)(
|
|
87
|
-
const lockPath = node_path_1.default.join(
|
|
246
|
+
await (0, fs_1.ensureDirectory)(plan.targetPath);
|
|
247
|
+
const lockPath = node_path_1.default.join(plan.targetPath, '.agentdock.lock');
|
|
88
248
|
const lockHandle = await (0, fs_1.acquireLock)(lockPath);
|
|
89
249
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
250
|
+
if (plan.conflicts.length > 0) {
|
|
251
|
+
throw new Error(`Install conflict detected:\n${plan.conflicts.map((entry) => entry.to).join('\n')}`);
|
|
252
|
+
}
|
|
253
|
+
for (const entry of plan.entries) {
|
|
254
|
+
// Idempotent no-op: an existing entry identical to the source is skipped.
|
|
255
|
+
if (entry.action === 'skip') {
|
|
96
256
|
continue;
|
|
97
257
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (await isIdenticalFile(entry.to, entry.from)) {
|
|
258
|
+
if (entry.action === 'merge') {
|
|
259
|
+
// Deep-merge the payload into the existing target (preserving other
|
|
260
|
+
// top-level keys / other mcpServers or mcp_servers). Never clobbers it.
|
|
261
|
+
await mergeDataFile(entry.from, entry.to, entry.mergeKeys);
|
|
105
262
|
continue;
|
|
106
263
|
}
|
|
107
|
-
conflicts.push(entry.to);
|
|
108
|
-
}
|
|
109
|
-
if (conflicts.length > 0) {
|
|
110
|
-
throw new Error(`Install conflict detected:\n${conflicts.join('\n')}`);
|
|
111
|
-
}
|
|
112
|
-
for (const entry of entries) {
|
|
113
264
|
if (entry.kind === 'directory') {
|
|
114
265
|
await (0, fs_1.copyDirectorySafe)(entry.from, entry.to);
|
|
115
266
|
}
|
|
@@ -117,7 +268,7 @@ async function installPackage(packagePath, explicitTargetPath, overwrite = false
|
|
|
117
268
|
await (0, fs_1.copyFileSafe)(entry.from, entry.to);
|
|
118
269
|
}
|
|
119
270
|
}
|
|
120
|
-
return { targetPath:
|
|
271
|
+
return { targetPath: plan.targetPath, plan };
|
|
121
272
|
}
|
|
122
273
|
finally {
|
|
123
274
|
await (0, fs_1.releaseLock)(lockHandle, lockPath);
|
|
@@ -95,7 +95,45 @@ async function exportFromScan(options) {
|
|
|
95
95
|
const payloadSourcesRoot = node_path_1.default.join(outputPath, 'payload', 'sources');
|
|
96
96
|
await (0, fs_1.ensureDirectory)(payloadSourcesRoot);
|
|
97
97
|
const sources = [];
|
|
98
|
+
const freeTextSecrets = [];
|
|
98
99
|
const toFrom = (diskRel) => `payload/sources/${diskRel}`;
|
|
100
|
+
/**
|
|
101
|
+
* Walk a copied directory and mask (or re-inject, when `env` is set)
|
|
102
|
+
* leaked secret tokens in every text file. Skips files with no leak and
|
|
103
|
+
* no placeholder so binaries / clean files are never rewritten.
|
|
104
|
+
*/
|
|
105
|
+
async function processDirectoryTexts(dir, agent) {
|
|
106
|
+
let entries;
|
|
107
|
+
try {
|
|
108
|
+
entries = await promises_1.default.readdir(dir, { withFileTypes: true });
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
const full = node_path_1.default.join(dir, entry.name);
|
|
115
|
+
if (entry.isDirectory()) {
|
|
116
|
+
await processDirectoryTexts(full, agent);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
let content;
|
|
120
|
+
try {
|
|
121
|
+
content = await promises_1.default.readFile(full, 'utf8');
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
continue; // unreadable / binary — leave untouched
|
|
125
|
+
}
|
|
126
|
+
const hasLeak = (0, sensitive_1.findSecretLeaks)(content).length > 0;
|
|
127
|
+
const hasPlaceholder = env ? /\{\{AGENTDOCK_[A-Z0-9_]+\}\}/.test(content) : false;
|
|
128
|
+
if (!hasLeak && !hasPlaceholder) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const out = env
|
|
132
|
+
? (0, sensitive_1.injectSecretsInText)((0, sensitive_1.maskSecretsInText)(content, agent, freeTextSecrets), env)
|
|
133
|
+
: (0, sensitive_1.maskSecretsInText)(content, agent, freeTextSecrets);
|
|
134
|
+
await (0, fs_1.writeTextFile)(full, out);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
99
137
|
for (const [agentName, domain] of Object.entries(manifest.agents)) {
|
|
100
138
|
if (!domain) {
|
|
101
139
|
continue;
|
|
@@ -125,7 +163,11 @@ async function exportFromScan(options) {
|
|
|
125
163
|
const diskRel = '.agentdock-mcp.json';
|
|
126
164
|
const content = JSON.stringify(merged, null, 2);
|
|
127
165
|
await (0, fs_1.writeTextFile)(node_path_1.default.join(payloadSourcesRoot, diskRel), content);
|
|
128
|
-
|
|
166
|
+
// `merge: true` → installer deep-merges this JSON into the target's
|
|
167
|
+
// existing file (preserving other top-level keys / other mcpServers)
|
|
168
|
+
// instead of overwriting it. Makes `install` safe on a machine
|
|
169
|
+
// that already has a `.claude.json`.
|
|
170
|
+
sources.push({ id: `${agent}-mcp-merged`, kind: 'file', from: toFrom(diskRel), to: '.claude.json', merge: true });
|
|
129
171
|
}
|
|
130
172
|
// --- Everything else ---
|
|
131
173
|
for (const entry of iterEntries(domain)) {
|
|
@@ -140,8 +182,10 @@ async function exportFromScan(options) {
|
|
|
140
182
|
const kind = stat.isDirectory() ? 'directory' : 'file';
|
|
141
183
|
const targetDisk = node_path_1.default.join(payloadSourcesRoot, rel);
|
|
142
184
|
if (kind === 'directory') {
|
|
143
|
-
//
|
|
185
|
+
// recursive copy (skill dirs), then mask/inject any leaked
|
|
186
|
+
// tokens inside the copied text files (prevents plaintext riding into the package)
|
|
144
187
|
await (0, fs_1.copyDirectorySafe)(entry.path, targetDisk);
|
|
188
|
+
await processDirectoryTexts(targetDisk, agent);
|
|
145
189
|
}
|
|
146
190
|
else if (entry.kind === 'settings') {
|
|
147
191
|
if (node_path_1.default.extname(entry.path) === '.toml') {
|
|
@@ -175,13 +219,38 @@ async function exportFromScan(options) {
|
|
|
175
219
|
}
|
|
176
220
|
else {
|
|
177
221
|
// skill .md / agent .md / plugin json / hook script / memory md:
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
222
|
+
// mask (or re-inject when `env` is set) any leaked secret tokens
|
|
223
|
+
// so plaintext never rides into the package. Clean files (no leak,
|
|
224
|
+
// no placeholder) are copied verbatim.
|
|
225
|
+
let content;
|
|
226
|
+
try {
|
|
227
|
+
content = await promises_1.default.readFile(entry.path, 'utf8');
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
await (0, fs_1.copyFileSafe)(entry.path, targetDisk);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const hasLeak = (0, sensitive_1.findSecretLeaks)(content).length > 0;
|
|
234
|
+
const hasPlaceholder = env ? /\{\{AGENTDOCK_[A-Z0-9_]+\}\}/.test(content) : false;
|
|
235
|
+
if (!hasLeak && !hasPlaceholder) {
|
|
236
|
+
await (0, fs_1.copyFileSafe)(entry.path, targetDisk);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
const out = env
|
|
240
|
+
? (0, sensitive_1.injectSecretsInText)((0, sensitive_1.maskSecretsInText)(content, agent, freeTextSecrets), env)
|
|
241
|
+
: (0, sensitive_1.maskSecretsInText)(content, agent, freeTextSecrets);
|
|
242
|
+
await (0, fs_1.writeTextFile)(targetDisk, out);
|
|
243
|
+
}
|
|
183
244
|
}
|
|
184
|
-
|
|
245
|
+
// Codex `config.toml` (and any TOML settings entry) is merged rather
|
|
246
|
+
// than overwritten, so installing onto a machine that already has a
|
|
247
|
+
// config.toml keeps its own model/provider settings and only adds the
|
|
248
|
+
// package's `mcp_servers` — mirroring the Claude `.claude.json` merge
|
|
249
|
+
// behavior (which scopes to `mcpServers`) and closing the Codex parity
|
|
250
|
+
// gap. On a fresh target the whole file is restored.
|
|
251
|
+
const merge = entry.kind === 'settings' && node_path_1.default.extname(entry.path) === '.toml' ? true : undefined;
|
|
252
|
+
const mergeKeys = merge ? ['mcp_servers'] : undefined;
|
|
253
|
+
sources.push({ id: entry.id, kind, from: toFrom(rel), to: rel, merge, mergeKeys });
|
|
185
254
|
}
|
|
186
255
|
}
|
|
187
256
|
const installPlan = {
|
|
@@ -192,7 +261,23 @@ async function exportFromScan(options) {
|
|
|
192
261
|
const snapshotPath = node_path_1.default.join(outputPath, 'manifest.resolved.json');
|
|
193
262
|
const installPlanPath = node_path_1.default.join(outputPath, 'meta', 'install-plan.json');
|
|
194
263
|
const packageMetadataPath = node_path_1.default.join(outputPath, 'package.json');
|
|
195
|
-
|
|
264
|
+
const envExamplePath = node_path_1.default.join(outputPath, '.env.example');
|
|
265
|
+
// Free-text secrets discovered during export are folded into the resolved
|
|
266
|
+
// manifest + the package's own `.env.example` so `--env` re-injection
|
|
267
|
+
// and `doctor --package` stay consistent end-to-end.
|
|
268
|
+
const augmentedSecrets = [
|
|
269
|
+
...manifest.secrets,
|
|
270
|
+
...freeTextSecrets.map((secret) => ({
|
|
271
|
+
key: secret.key,
|
|
272
|
+
source: secret.source,
|
|
273
|
+
sample: secret.sample,
|
|
274
|
+
})),
|
|
275
|
+
];
|
|
276
|
+
const resolvedManifest = {
|
|
277
|
+
...manifest,
|
|
278
|
+
secrets: augmentedSecrets,
|
|
279
|
+
};
|
|
280
|
+
await (0, fs_1.writeJsonFile)(snapshotPath, resolvedManifest);
|
|
196
281
|
await (0, fs_1.writeJsonFile)(installPlanPath, installPlan);
|
|
197
282
|
await (0, fs_1.writeJsonFile)(packageMetadataPath, {
|
|
198
283
|
name: 'agentdock-scan-package',
|
|
@@ -200,6 +285,7 @@ async function exportFromScan(options) {
|
|
|
200
285
|
project: manifest.project.name,
|
|
201
286
|
manifestVersion: 3,
|
|
202
287
|
});
|
|
288
|
+
await (0, fs_1.writeTextFile)(envExamplePath, (0, sensitive_1.renderEnvExample)(augmentedSecrets));
|
|
203
289
|
return { outputPath, snapshotPath, installPlanPath };
|
|
204
290
|
}
|
|
205
291
|
finally {
|
|
@@ -0,0 +1,159 @@
|
|
|
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.uninstallPackage = uninstallPackage;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const smol_toml_1 = require("smol-toml");
|
|
10
|
+
const installer_1 = require("./installer");
|
|
11
|
+
const fs_1 = require("../utils/fs");
|
|
12
|
+
function deepEqual(a, b) {
|
|
13
|
+
if (a === b)
|
|
14
|
+
return true;
|
|
15
|
+
if (typeof a !== typeof b)
|
|
16
|
+
return false;
|
|
17
|
+
if (a === null || b === null)
|
|
18
|
+
return a === b;
|
|
19
|
+
if (typeof a !== 'object')
|
|
20
|
+
return false;
|
|
21
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
22
|
+
return false;
|
|
23
|
+
const ka = Object.keys(a);
|
|
24
|
+
const kb = Object.keys(b);
|
|
25
|
+
if (ka.length !== kb.length)
|
|
26
|
+
return false;
|
|
27
|
+
return ka.every((k) => deepEqual(a[k], b[k]));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reverse a merge: remove from the target file exactly the keys whose current
|
|
31
|
+
* value still equals the package's contributed value. User-edited values
|
|
32
|
+
* (which now differ) are left untouched. Format-aware (JSON or TOML) so the
|
|
33
|
+
* Codex `.codex/config.toml` unmerge behaves like the JSON `.claude.json`
|
|
34
|
+
* unmerge. Returns the keys that were removed.
|
|
35
|
+
*/
|
|
36
|
+
async function unmergeDataFile(sourcePath, toPath, mergeKeys) {
|
|
37
|
+
const parse = (filePath, content) => node_path_1.default.extname(filePath).toLowerCase() === '.toml'
|
|
38
|
+
? (0, smol_toml_1.parse)(content)
|
|
39
|
+
: JSON.parse(content);
|
|
40
|
+
let source;
|
|
41
|
+
try {
|
|
42
|
+
source = parse(sourcePath, await promises_1.default.readFile(sourcePath, 'utf8'));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
if (!(await (0, fs_1.pathExists)(toPath))) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
let target;
|
|
51
|
+
try {
|
|
52
|
+
target = parse(toPath, await promises_1.default.readFile(toPath, 'utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const removed = [];
|
|
58
|
+
// TOML config.toml uses `mcp_servers`; JSON .claude.json uses `mcpServers`.
|
|
59
|
+
const mcpKey = node_path_1.default.extname(sourcePath).toLowerCase() === '.toml' ? 'mcp_servers' : 'mcpServers';
|
|
60
|
+
const sourceServers = source[mcpKey];
|
|
61
|
+
const targetServers = target[mcpKey];
|
|
62
|
+
// If the merge was scoped to specific keys, only unmerge those (preserve the
|
|
63
|
+
// target's other keys, e.g. its own model/provider on a Codex config.toml).
|
|
64
|
+
const scopedKeys = mergeKeys && mergeKeys.length > 0 ? mergeKeys : undefined;
|
|
65
|
+
for (const key of Object.keys(source)) {
|
|
66
|
+
if (scopedKeys && !scopedKeys.includes(key))
|
|
67
|
+
continue;
|
|
68
|
+
if (key === mcpKey)
|
|
69
|
+
continue;
|
|
70
|
+
if (deepEqual(target[key], source[key])) {
|
|
71
|
+
delete target[key];
|
|
72
|
+
removed.push(key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (sourceServers && targetServers) {
|
|
76
|
+
for (const server of Object.keys(sourceServers)) {
|
|
77
|
+
if (deepEqual(targetServers[server], sourceServers[server])) {
|
|
78
|
+
delete targetServers[server];
|
|
79
|
+
removed.push(`${mcpKey}.${server}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (removed.length > 0) {
|
|
84
|
+
if (node_path_1.default.extname(toPath).toLowerCase() === '.toml') {
|
|
85
|
+
await (0, fs_1.writeTextFile)(toPath, (0, smol_toml_1.stringify)(target));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await (0, fs_1.writeJsonFile)(toPath, target);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return removed;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reverse an install. Files/directories are removed only when they still
|
|
95
|
+
* match the package (safe); modified ones are skipped unless `--force`.
|
|
96
|
+
* Merge entries are reversed key-by-key so user-edited values survive.
|
|
97
|
+
* Reuses `planInstall` so no install-time bookkeeping is required — the
|
|
98
|
+
* package itself is the source of truth for what to undo.
|
|
99
|
+
*/
|
|
100
|
+
async function uninstallPackage(packagePath, explicitTargetPath, dryRun = false, force = false) {
|
|
101
|
+
const plan = await (0, installer_1.planInstall)(packagePath, explicitTargetPath);
|
|
102
|
+
const removed = [];
|
|
103
|
+
const skipped = [];
|
|
104
|
+
const decide = (entry) => {
|
|
105
|
+
if (entry.merge)
|
|
106
|
+
return 'unmerge';
|
|
107
|
+
if (!entry.exists)
|
|
108
|
+
return 'skip-missing';
|
|
109
|
+
if (entry.identical)
|
|
110
|
+
return entry.kind === 'directory' ? 'remove-dir' : 'remove-file';
|
|
111
|
+
return force ? (entry.kind === 'directory' ? 'remove-dir' : 'remove-file') : 'skip-modified';
|
|
112
|
+
};
|
|
113
|
+
if (dryRun) {
|
|
114
|
+
for (const entry of plan.entries) {
|
|
115
|
+
const action = decide(entry);
|
|
116
|
+
const note = action === 'skip-modified' ? 'modified — use --force' : undefined;
|
|
117
|
+
(action === 'skip-missing' || action === 'skip-modified' ? skipped : removed).push({
|
|
118
|
+
to: entry.to,
|
|
119
|
+
kind: entry.kind,
|
|
120
|
+
action,
|
|
121
|
+
note,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return { targetPath: plan.targetPath, removed, skipped, dryRun: true };
|
|
125
|
+
}
|
|
126
|
+
await (0, fs_1.ensureDirectory)(plan.targetPath);
|
|
127
|
+
const lockPath = node_path_1.default.join(plan.targetPath, '.agentdock.lock');
|
|
128
|
+
const lockHandle = await (0, fs_1.acquireLock)(lockPath);
|
|
129
|
+
try {
|
|
130
|
+
for (const entry of plan.entries) {
|
|
131
|
+
const action = decide(entry);
|
|
132
|
+
if (action === 'skip-missing') {
|
|
133
|
+
skipped.push({ to: entry.to, kind: entry.kind, action });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (action === 'skip-modified') {
|
|
137
|
+
skipped.push({ to: entry.to, kind: entry.kind, action, note: 'modified — use --force' });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (action === 'unmerge') {
|
|
141
|
+
const removedKeys = await unmergeDataFile(entry.from, entry.to, entry.mergeKeys);
|
|
142
|
+
removed.push({
|
|
143
|
+
to: entry.to,
|
|
144
|
+
kind: entry.kind,
|
|
145
|
+
action,
|
|
146
|
+
note: removedKeys.length > 0 ? `removed ${removedKeys.join(', ')}` : 'nothing to remove',
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// remove-file / remove-dir
|
|
151
|
+
await promises_1.default.rm(entry.to, { recursive: true, force: action === 'remove-dir' && force });
|
|
152
|
+
removed.push({ to: entry.to, kind: entry.kind, action });
|
|
153
|
+
}
|
|
154
|
+
return { targetPath: plan.targetPath, removed, skipped, dryRun: false };
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await (0, fs_1.releaseLock)(lockHandle, lockPath);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeLang = normalizeLang;
|
|
4
|
+
exports.getLang = getLang;
|
|
5
|
+
exports.initI18n = initI18n;
|
|
6
|
+
exports.t = t;
|
|
7
|
+
exports.setLangForTest = setLangForTest;
|
|
8
|
+
const config_1 = require("../core/config");
|
|
9
|
+
const FALLBACK = 'en';
|
|
10
|
+
/** User-facing strings. Machines read `--json` output, which is never localized. */
|
|
11
|
+
const DICTIONARIES = {
|
|
12
|
+
en: {
|
|
13
|
+
'cli.usage': 'Usage: agentdock <scan|export|install|validate|doctor|list|diff|config|uninstall> [path]',
|
|
14
|
+
'install.complete': 'Install completed: {path}',
|
|
15
|
+
'uninstall.complete': 'Uninstall complete: {path}',
|
|
16
|
+
'uninstall.dryRunHeader': 'Uninstall plan (dry-run — no changes made): {path}',
|
|
17
|
+
'dryrun.header': 'Install plan (dry-run — no changes written):',
|
|
18
|
+
'diff.header': 'Diff vs current target:',
|
|
19
|
+
'plan.summaryDryRun': '{total} entries, {conflicts} conflict(s){hint}',
|
|
20
|
+
'plan.summaryDiff': '{total} entries, {conflicts} would conflict{hint}',
|
|
21
|
+
'plan.forceHint': ' — use --overwrite to force',
|
|
22
|
+
'plan.conflictHint': ' (install would refuse without --overwrite)',
|
|
23
|
+
'config.title': 'Configuration:',
|
|
24
|
+
'config.set': 'set {key} = {value}',
|
|
25
|
+
'config.unknownKey': 'Unknown config key: {key} (valid: {valid})',
|
|
26
|
+
'config.invalidValue': 'Invalid value for {key}: {reason}',
|
|
27
|
+
'config.usage': 'Usage: agentdock config <list|get|set> [key] [value]',
|
|
28
|
+
'config.unset': 'unset {key}',
|
|
29
|
+
'config.file': 'config file: {path}',
|
|
30
|
+
'config.noSettings': '(no settings — command defaults apply)',
|
|
31
|
+
'config.unsetValue': '(unset)',
|
|
32
|
+
},
|
|
33
|
+
'zh-CN': {
|
|
34
|
+
'cli.usage': '用法:agentdock <scan|export|install|validate|doctor|list|diff|config|uninstall> [path]',
|
|
35
|
+
'install.complete': '安装完成:{path}',
|
|
36
|
+
'uninstall.complete': '卸载完成:{path}',
|
|
37
|
+
'uninstall.dryRunHeader': '卸载计划(dry-run — 未做任何改动):{path}',
|
|
38
|
+
'dryrun.header': '安装计划(dry-run — 未写入任何文件):',
|
|
39
|
+
'diff.header': '与当前目标机的差异:',
|
|
40
|
+
'plan.summaryDryRun': '{total} 项,{conflicts} 处冲突{hint}',
|
|
41
|
+
'plan.summaryDiff': '{total} 项,{conflicts} 处会冲突{hint}',
|
|
42
|
+
'plan.forceHint': ' — 使用 --overwrite 强制覆盖',
|
|
43
|
+
'plan.conflictHint': '(不使用 --overwrite 安装会拒绝)',
|
|
44
|
+
'config.title': '当前配置:',
|
|
45
|
+
'config.set': '已设置 {key} = {value}',
|
|
46
|
+
'config.unknownKey': '未知配置项:{key}(合法值:{valid})',
|
|
47
|
+
'config.invalidValue': '配置项 {key} 的值无效:{reason}',
|
|
48
|
+
'config.usage': '用法:agentdock config <list|get|set> [key] [value]',
|
|
49
|
+
'config.unset': '已清除 {key}',
|
|
50
|
+
'config.file': '配置文件:{path}',
|
|
51
|
+
'config.noSettings': '(暂无设置 — 使用命令默认值)',
|
|
52
|
+
'config.unsetValue': '(未设置)',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/** Normalize a raw locale string to a supported Lang, or null if unsupported. */
|
|
56
|
+
function normalizeLang(value) {
|
|
57
|
+
if (!value)
|
|
58
|
+
return null;
|
|
59
|
+
const v = value.toLowerCase();
|
|
60
|
+
if (v === 'en' || v === 'english')
|
|
61
|
+
return 'en';
|
|
62
|
+
if (v === 'zh' || v === 'zh-cn' || v === 'zh_cn' || v === 'cn' || v === 'chinese')
|
|
63
|
+
return 'zh-CN';
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function langFromEnv() {
|
|
67
|
+
return normalizeLang(typeof process !== 'undefined' ? process.env.AGENTDOCK_LANG : undefined);
|
|
68
|
+
}
|
|
69
|
+
let currentLang = langFromEnv() ?? FALLBACK;
|
|
70
|
+
function getLang() {
|
|
71
|
+
return currentLang;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolve the active language. Precedence: `AGENTDOCK_LANG` env > `lang` in
|
|
75
|
+
* AgentDock config > English fallback. Call once at CLI startup.
|
|
76
|
+
*/
|
|
77
|
+
async function initI18n() {
|
|
78
|
+
const envLang = langFromEnv();
|
|
79
|
+
if (envLang) {
|
|
80
|
+
currentLang = envLang;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const cfg = await (0, config_1.loadConfig)();
|
|
85
|
+
const cfgLang = normalizeLang(cfg.lang);
|
|
86
|
+
if (cfgLang) {
|
|
87
|
+
currentLang = cfgLang;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// keep env/default
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Translate a key with optional `{var}` interpolation. Falls back to English, then the key itself. */
|
|
95
|
+
function t(key, vars) {
|
|
96
|
+
const dict = DICTIONARIES[currentLang] ?? DICTIONARIES[FALLBACK];
|
|
97
|
+
let str = dict[key] ?? DICTIONARIES[FALLBACK][key] ?? key;
|
|
98
|
+
if (vars) {
|
|
99
|
+
for (const [name, value] of Object.entries(vars)) {
|
|
100
|
+
str = str.replace(new RegExp(`\\{${name}\\}`, 'g'), String(value));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return str;
|
|
104
|
+
}
|
|
105
|
+
/** Test-only: force a language. Pass `undefined` to reset to env/default. */
|
|
106
|
+
function setLangForTest(lang) {
|
|
107
|
+
currentLang = lang ?? langFromEnv() ?? FALLBACK;
|
|
108
|
+
}
|
|
@@ -16,6 +16,8 @@ exports.maskSecret = maskSecret;
|
|
|
16
16
|
exports.collectSecrets = collectSecrets;
|
|
17
17
|
exports.secretKeyName = secretKeyName;
|
|
18
18
|
exports.maskSecretsInPlace = maskSecretsInPlace;
|
|
19
|
+
exports.maskSecretsInText = maskSecretsInText;
|
|
20
|
+
exports.injectSecretsInText = injectSecretsInText;
|
|
19
21
|
exports.renderEnvExample = renderEnvExample;
|
|
20
22
|
const SECRET_KEY_PATTERN = /(token|api[_-]?key|secret|password|passwd|auth|private[_-]?key|credential|access[_-]?key)/i;
|
|
21
23
|
const SECRET_VALUE_PATTERNS = [
|
|
@@ -156,6 +158,53 @@ function maskSecretsInPlace(node, basePath, agent, secretsEnv, seen = new WeakSe
|
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Stable short hash so the same token maps to the same placeholder key across
|
|
163
|
+
* files (keeps `.env.example` / re-injection deduped and deterministic).
|
|
164
|
+
*/
|
|
165
|
+
function stableHash(input) {
|
|
166
|
+
let h = 0x811c9dc5;
|
|
167
|
+
for (let i = 0; i < input.length; i++) {
|
|
168
|
+
h ^= input.charCodeAt(i);
|
|
169
|
+
h = Math.imul(h, 0x01000193);
|
|
170
|
+
}
|
|
171
|
+
return (h >>> 0).toString(36).toUpperCase().padStart(7, '0').slice(0, 7);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Mask every secret token found in free text (skills/agents/memory/hooks `.md`,
|
|
175
|
+
* etc.) with a stable `{{AGENTDOCK_<AGENT>_FREETEXT_<HASH>}}` placeholder,
|
|
176
|
+
* and record each as a secret so `.env.example` + `--env` re-injection stay
|
|
177
|
+
* consistent. Replaces the previous verbatim copy that let real tokens ride
|
|
178
|
+
* into the package. Detection uses the same value patterns as `looksLikeSecret`
|
|
179
|
+
* / `findSecretLeaks`.
|
|
180
|
+
*/
|
|
181
|
+
function maskSecretsInText(text, agent, accumulator) {
|
|
182
|
+
const tokens = [...new Set(findSecretLeaks(text))];
|
|
183
|
+
if (tokens.length === 0) {
|
|
184
|
+
return text;
|
|
185
|
+
}
|
|
186
|
+
// Longest tokens first so a prefix token can't swallow a longer one.
|
|
187
|
+
tokens.sort((a, b) => b.length - a.length);
|
|
188
|
+
let out = text;
|
|
189
|
+
for (const token of tokens) {
|
|
190
|
+
const key = `AGENTDOCK_${agent.toUpperCase()}_FREETEXT_${stableHash(token)}`;
|
|
191
|
+
const placeholder = `{{${key}}}`;
|
|
192
|
+
if (out.includes(placeholder)) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
out = out.split(token).join(placeholder);
|
|
196
|
+
accumulator.push({ key, sample: maskSecret(token), source: 'freetext' });
|
|
197
|
+
}
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Re-inject real values into free text for an `--env` export. Placeholders use
|
|
202
|
+
* the same `{{AGENTDOCK_*_FREETEXT_*}}` names emitted by `maskSecretsInText`,
|
|
203
|
+
* keyed by the env file's `AGENTDOCK_*` keys.
|
|
204
|
+
*/
|
|
205
|
+
function injectSecretsInText(text, secretsEnv) {
|
|
206
|
+
return text.replace(/\{\{(AGENTDOCK_[A-Z0-9_]+)\}\}/g, (match, key) => secretsEnv[key] !== undefined ? secretsEnv[key] : match);
|
|
207
|
+
}
|
|
159
208
|
/**
|
|
160
209
|
* Render a `.env.example` from isolated secrets. Only placeholder keys are
|
|
161
210
|
* written — never the real values, which stay on the source machine.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderPlan = renderPlan;
|
|
4
|
+
const i18n_1 = require("../i18n");
|
|
5
|
+
const DRY_RUN_LABEL = {
|
|
6
|
+
create: 'CREATE ',
|
|
7
|
+
overwrite: 'OVERWRITE',
|
|
8
|
+
merge: 'MERGE ',
|
|
9
|
+
skip: 'SKIP ',
|
|
10
|
+
conflict: 'CONFLICT ',
|
|
11
|
+
};
|
|
12
|
+
const DIFF_LABEL = {
|
|
13
|
+
create: 'NEW ',
|
|
14
|
+
overwrite: 'CHANGED ',
|
|
15
|
+
merge: 'MERGE ',
|
|
16
|
+
skip: 'SAME ',
|
|
17
|
+
conflict: 'CONFLICT ',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Render an install plan preview as text lines.
|
|
21
|
+
* `mode: 'dry-run'` shows intended actions; `mode: 'diff'` shows the gap
|
|
22
|
+
* between the package and the current target machine.
|
|
23
|
+
*/
|
|
24
|
+
function renderPlan(plan, mode, title) {
|
|
25
|
+
const labels = mode === 'dry-run' ? DRY_RUN_LABEL : DIFF_LABEL;
|
|
26
|
+
const heading = title
|
|
27
|
+
?? (mode === 'dry-run' ? (0, i18n_1.t)('dryrun.header') : (0, i18n_1.t)('diff.header'));
|
|
28
|
+
const lines = [heading, ` target: ${plan.targetPath}`];
|
|
29
|
+
for (const entry of plan.entries) {
|
|
30
|
+
const note = entry.note ? ` (${entry.note})` : '';
|
|
31
|
+
lines.push(` ${labels[entry.action]} ${entry.to}${note}`);
|
|
32
|
+
}
|
|
33
|
+
const conflicts = plan.conflicts.length;
|
|
34
|
+
const hint = conflicts > 0
|
|
35
|
+
? (mode === 'dry-run' ? (0, i18n_1.t)('plan.forceHint') : (0, i18n_1.t)('plan.conflictHint'))
|
|
36
|
+
: '';
|
|
37
|
+
const summary = mode === 'dry-run'
|
|
38
|
+
? (0, i18n_1.t)('plan.summaryDryRun', { total: plan.entries.length, conflicts, hint })
|
|
39
|
+
: (0, i18n_1.t)('plan.summaryDiff', { total: plan.entries.length, conflicts, hint });
|
|
40
|
+
lines.push(` ${summary}`);
|
|
41
|
+
return lines;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|