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
|
@@ -0,0 +1,243 @@
|
|
|
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.computeReportScore = computeReportScore;
|
|
7
|
+
exports.gradeForScore = gradeForScore;
|
|
8
|
+
exports.runReport = runReport;
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
13
|
+
const doctor_1 = require("./doctor");
|
|
14
|
+
const report_html_1 = require("./report-html");
|
|
15
|
+
const claude_scanner_1 = require("../scanners/claude-scanner");
|
|
16
|
+
const codex_scanner_1 = require("../scanners/codex-scanner");
|
|
17
|
+
const fs_1 = require("../utils/fs");
|
|
18
|
+
// ===== inventory =====
|
|
19
|
+
function countDomain(agent, domain) {
|
|
20
|
+
const mcp = domain.mcp.length;
|
|
21
|
+
const skills = domain.skills.length;
|
|
22
|
+
const agents = domain.agents.length;
|
|
23
|
+
const plugins = domain.plugins.length;
|
|
24
|
+
const hooks = domain.hooks.length;
|
|
25
|
+
const memory = domain.memory.length;
|
|
26
|
+
const settings = domain.settings.length;
|
|
27
|
+
return {
|
|
28
|
+
agent,
|
|
29
|
+
mcp,
|
|
30
|
+
skills,
|
|
31
|
+
agents,
|
|
32
|
+
plugins,
|
|
33
|
+
hooks,
|
|
34
|
+
memory,
|
|
35
|
+
settings,
|
|
36
|
+
total: mcp + skills + agents + plugins + hooks + memory + settings,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function makeInventory(agents, secretsCount) {
|
|
40
|
+
return {
|
|
41
|
+
agents,
|
|
42
|
+
totalEntries: agents.reduce((sum, item) => sum + item.total, 0),
|
|
43
|
+
secretsCount,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function inventoryLive(agentFilter, root) {
|
|
47
|
+
const agents = [];
|
|
48
|
+
let secretsCount = 0;
|
|
49
|
+
if (agentFilter === 'claude' || agentFilter === 'all') {
|
|
50
|
+
const scan = await (0, claude_scanner_1.scanClaude)(root);
|
|
51
|
+
agents.push(countDomain('claude', scan.domain));
|
|
52
|
+
secretsCount += scan.secrets.length;
|
|
53
|
+
}
|
|
54
|
+
if (agentFilter === 'codex' || agentFilter === 'all') {
|
|
55
|
+
const scan = await (0, codex_scanner_1.scanCodex)(root);
|
|
56
|
+
agents.push(countDomain('codex', scan.domain));
|
|
57
|
+
secretsCount += scan.secrets.length;
|
|
58
|
+
}
|
|
59
|
+
return makeInventory(agents, secretsCount);
|
|
60
|
+
}
|
|
61
|
+
function inventoryFromManifest(manifest, agentFilter) {
|
|
62
|
+
const agents = [];
|
|
63
|
+
const entries = Object.entries(manifest.agents ?? {});
|
|
64
|
+
for (const [name, domain] of entries) {
|
|
65
|
+
if (!domain) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (agentFilter !== 'all' && agentFilter !== name) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
agents.push(countDomain(name, domain));
|
|
72
|
+
}
|
|
73
|
+
return makeInventory(agents, manifest.secrets?.length ?? 0);
|
|
74
|
+
}
|
|
75
|
+
async function inventoryFromScan(scanPath, agentFilter) {
|
|
76
|
+
const manifestPath = node_path_1.default.resolve(scanPath);
|
|
77
|
+
if (!(await (0, fs_1.pathExists)(manifestPath))) {
|
|
78
|
+
return makeInventory([], 0);
|
|
79
|
+
}
|
|
80
|
+
const manifest = yaml_1.default.parse(await promises_1.default.readFile(manifestPath, 'utf8'));
|
|
81
|
+
return inventoryFromManifest(manifest, agentFilter);
|
|
82
|
+
}
|
|
83
|
+
async function inventoryFromPackage(pkgDir, agentFilter) {
|
|
84
|
+
const manifestPath = node_path_1.default.join(node_path_1.default.resolve(pkgDir), 'manifest.resolved.json');
|
|
85
|
+
if (!(await (0, fs_1.pathExists)(manifestPath))) {
|
|
86
|
+
return makeInventory([], 0);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const manifest = JSON.parse(await promises_1.default.readFile(manifestPath, 'utf8'));
|
|
90
|
+
return inventoryFromManifest(manifest, agentFilter);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return makeInventory([], 0);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// ===== scoring =====
|
|
97
|
+
function computeReportScore(checks) {
|
|
98
|
+
let score = 100;
|
|
99
|
+
for (const check of checks) {
|
|
100
|
+
if (check.status === 'fail') {
|
|
101
|
+
score -= 20;
|
|
102
|
+
}
|
|
103
|
+
else if (check.status === 'warn') {
|
|
104
|
+
score -= 8;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return Math.max(0, Math.min(100, score));
|
|
108
|
+
}
|
|
109
|
+
function gradeForScore(score) {
|
|
110
|
+
if (score >= 90)
|
|
111
|
+
return 'A';
|
|
112
|
+
if (score >= 75)
|
|
113
|
+
return 'B';
|
|
114
|
+
if (score >= 60)
|
|
115
|
+
return 'C';
|
|
116
|
+
return 'D';
|
|
117
|
+
}
|
|
118
|
+
// ===== xinchuang heuristics =====
|
|
119
|
+
const ABSOLUTE_PATH_PATTERN = /[A-Za-z]:[\\/]|\/(?:home|Users|root|opt|usr\/local)\//g;
|
|
120
|
+
const RUNTIME_COMMAND_PATTERN = /"command"\s*:\s*"(?:npx|uvx|docker|bunx|pnpm)"|command\s*=\s*"(?:npx|uvx|docker|bunx|pnpm)"/g;
|
|
121
|
+
const EXTERNAL_ENDPOINT_PATTERN = /https?:\/\/[^\s"'`]+/g;
|
|
122
|
+
async function readConfigTexts(root) {
|
|
123
|
+
const candidates = [
|
|
124
|
+
node_path_1.default.join(root, '.claude', 'settings.json'),
|
|
125
|
+
node_path_1.default.join(root, '.claude.json'),
|
|
126
|
+
node_path_1.default.join(root, '.codex', 'config.toml'),
|
|
127
|
+
];
|
|
128
|
+
const texts = [];
|
|
129
|
+
for (const file of candidates) {
|
|
130
|
+
try {
|
|
131
|
+
texts.push({ file, text: await promises_1.default.readFile(file, 'utf8') });
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// missing / unreadable config is already reported by the doctor checks
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return texts;
|
|
138
|
+
}
|
|
139
|
+
function collectHits(texts, pattern, sampleLimit = 3) {
|
|
140
|
+
const findings = [];
|
|
141
|
+
for (const { file, text } of texts) {
|
|
142
|
+
const matches = text.match(pattern);
|
|
143
|
+
if (!matches || matches.length === 0) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const samples = [...new Set(matches)].slice(0, sampleLimit);
|
|
147
|
+
findings.push({
|
|
148
|
+
severity: 'warn',
|
|
149
|
+
message: `发现 ${matches.length} 处${samples.length ? `(示例:${samples.join(', ')})` : ''}`,
|
|
150
|
+
path: file,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return findings;
|
|
154
|
+
}
|
|
155
|
+
function heuristicCheck(id, label, findings, cleanDetail, remediation) {
|
|
156
|
+
const status = findings.length > 0 ? 'warn' : 'pass';
|
|
157
|
+
return {
|
|
158
|
+
id,
|
|
159
|
+
label,
|
|
160
|
+
status,
|
|
161
|
+
detail: status === 'pass' ? `${cleanDetail}(启发式检查,仍需人工确认)` : `需人工确认:发现 ${findings.length} 个可疑项`,
|
|
162
|
+
findings,
|
|
163
|
+
...(status === 'pass' ? {} : { remediation }),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async function xinchuangChecks(root) {
|
|
167
|
+
const texts = await readConfigTexts(root);
|
|
168
|
+
const platform = {
|
|
169
|
+
id: 'xinchuang-platform',
|
|
170
|
+
label: '信创 · 平台 / 运行时(需人工确认)',
|
|
171
|
+
status: 'warn',
|
|
172
|
+
detail: `需人工确认:当前为 ${process.platform}/${process.arch},Node ${process.version};请核对目标信创环境(如麒麟 V10 / 统信 UOS、LoongArch / 鲲鹏 ARM)的操作系统、CPU 架构与运行时版本`,
|
|
173
|
+
findings: [],
|
|
174
|
+
remediation: '信创适配无法仅凭本机静态信息判定。请在目标机上运行 `agentdock report --profile xinchuang`,人工验证 Node 运行时、依赖与 MCP 服务可用性。',
|
|
175
|
+
};
|
|
176
|
+
const pathCheck = heuristicCheck('xinchuang-paths', '信创 · 绝对路径(需人工确认)', collectHits(texts, ABSOLUTE_PATH_PATTERN), '配置中未发现平台相关的绝对路径引用', '跨机器 / 跨国产化系统时,固定路径(如 C:\\Users\\...、/home/...)通常不可用。建议改为相对路径或环境变量,并在目标机重新验证。');
|
|
177
|
+
const runtimeCheck = heuristicCheck('xinchuang-runtime', '信创 · MCP 运行时依赖(需人工确认)', collectHits(texts, RUNTIME_COMMAND_PATTERN), '配置中未发现 npx / uvx / docker 等运行时拉取命令', 'npx / uvx / docker 等运行时会在目标机联网拉取依赖;信创内网环境需提前离线安装,或改为本地可执行文件。');
|
|
178
|
+
const endpointCheck = heuristicCheck('xinchuang-endpoints', '信创 · 外网端点(需人工确认)', collectHits(texts, EXTERNAL_ENDPOINT_PATTERN), '配置中未发现外网 http(s) 端点', '外网 http(s) 端点在信创内网可能不可达,需提前确认网络策略或改用内网镜像 / 代理。');
|
|
179
|
+
return [platform, pathCheck, runtimeCheck, endpointCheck];
|
|
180
|
+
}
|
|
181
|
+
function xinchuangManualCheck(mode) {
|
|
182
|
+
return {
|
|
183
|
+
id: 'xinchuang-manual',
|
|
184
|
+
label: '信创 · 需人工确认',
|
|
185
|
+
status: 'warn',
|
|
186
|
+
detail: `需人工确认:${mode} 模式仅审计产物,不评估信创环境适配`,
|
|
187
|
+
findings: [],
|
|
188
|
+
remediation: '请在目标机上运行 `agentdock report --profile xinchuang`,人工验证运行时、依赖、绝对路径与外网端点。',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// ===== entry =====
|
|
192
|
+
async function runReport(options) {
|
|
193
|
+
const agent = options.agent ?? 'all';
|
|
194
|
+
const profile = options.profile ?? 'default';
|
|
195
|
+
let base;
|
|
196
|
+
let inventory;
|
|
197
|
+
let extraChecks = [];
|
|
198
|
+
if (options.fromScan) {
|
|
199
|
+
base = await (0, doctor_1.runDoctor)({ agent, fromScan: options.fromScan });
|
|
200
|
+
inventory = await inventoryFromScan(options.fromScan, agent);
|
|
201
|
+
if (profile === 'xinchuang') {
|
|
202
|
+
extraChecks = [xinchuangManualCheck('scan')];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (options.package) {
|
|
206
|
+
base = await (0, doctor_1.runDoctor)({ agent, package: options.package });
|
|
207
|
+
inventory = await inventoryFromPackage(options.package, agent);
|
|
208
|
+
if (profile === 'xinchuang') {
|
|
209
|
+
extraChecks = [xinchuangManualCheck('package')];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const root = options.root ?? node_os_1.default.homedir();
|
|
214
|
+
base = await (0, doctor_1.runDoctor)({ agent, root });
|
|
215
|
+
inventory = await inventoryLive(agent, root);
|
|
216
|
+
if (profile === 'xinchuang') {
|
|
217
|
+
extraChecks = await xinchuangChecks(root);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const checks = [...base.checks, ...extraChecks];
|
|
221
|
+
const score = computeReportScore(checks);
|
|
222
|
+
const grade = gradeForScore(score);
|
|
223
|
+
const summary = profile === 'xinchuang'
|
|
224
|
+
? `${base.summary}(信创适配为启发式检查,需人工确认)`
|
|
225
|
+
: base.summary;
|
|
226
|
+
const report = {
|
|
227
|
+
...base,
|
|
228
|
+
checks,
|
|
229
|
+
summary,
|
|
230
|
+
profile,
|
|
231
|
+
score,
|
|
232
|
+
grade,
|
|
233
|
+
inventory,
|
|
234
|
+
};
|
|
235
|
+
if (options.out) {
|
|
236
|
+
await (0, fs_1.ensureDirectory)(options.out);
|
|
237
|
+
report.htmlPath = node_path_1.default.join(options.out, 'agentdock-report.html');
|
|
238
|
+
report.jsonPath = node_path_1.default.join(options.out, 'agentdock-report.json');
|
|
239
|
+
await (0, fs_1.writeJsonFile)(report.jsonPath, report);
|
|
240
|
+
await (0, fs_1.writeTextFile)(report.htmlPath, (0, report_html_1.renderReportHtml)(report));
|
|
241
|
+
}
|
|
242
|
+
return report;
|
|
243
|
+
}
|
|
@@ -242,7 +242,15 @@ async function exportFromScan(options) {
|
|
|
242
242
|
await (0, fs_1.writeTextFile)(targetDisk, out);
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
|
|
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 });
|
|
246
254
|
}
|
|
247
255
|
}
|
|
248
256
|
const installPlan = {
|
|
@@ -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|report|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|report|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
|
+
}
|
package/dist/src/utils/fs.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.readJsonFile = readJsonFile;
|
|
|
17
17
|
exports.writeJsonFile = writeJsonFile;
|
|
18
18
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
19
19
|
const node_path_1 = __importDefault(require("node:path"));
|
|
20
|
-
const
|
|
20
|
+
const picomatch_1 = __importDefault(require("picomatch"));
|
|
21
21
|
function resolveFrom(baseDir, targetPath) {
|
|
22
22
|
return node_path_1.default.resolve(baseDir, targetPath);
|
|
23
23
|
}
|
|
@@ -126,9 +126,11 @@ async function copyDirectoryFiltered(sourcePath, targetPath, include, exclude, f
|
|
|
126
126
|
const files = await walkDirectoryWithSymlinkPolicy(sourcePath, '', followSymlinks);
|
|
127
127
|
const includePatterns = include?.length ? include : ['**/*'];
|
|
128
128
|
const excludePatterns = exclude ?? [];
|
|
129
|
+
const includeMatchers = includePatterns.map((pattern) => (0, picomatch_1.default)(pattern, { dot: true }));
|
|
130
|
+
const excludeMatchers = excludePatterns.map((pattern) => (0, picomatch_1.default)(pattern, { dot: true }));
|
|
129
131
|
for (const file of files) {
|
|
130
|
-
const isIncluded =
|
|
131
|
-
const isExcluded =
|
|
132
|
+
const isIncluded = includeMatchers.some((matches) => matches(file.relativePath));
|
|
133
|
+
const isExcluded = excludeMatchers.some((matches) => matches(file.relativePath));
|
|
132
134
|
if (!isIncluded || isExcluded) {
|
|
133
135
|
continue;
|
|
134
136
|
}
|
|
@@ -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,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",
|