agentdock-cli 1.1.0 → 1.4.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 +106 -4
- package/dist/package.json +2 -2
- package/dist/src/agents/registry.js +551 -0
- package/dist/src/agents/semantic.js +208 -0
- package/dist/src/cli.js +45 -1
- package/dist/src/commands/agents.js +84 -0
- package/dist/src/commands/diff.js +73 -0
- package/dist/src/commands/doctor.js +1 -0
- package/dist/src/commands/history.js +109 -0
- package/dist/src/commands/list.js +2 -1
- package/dist/src/commands/recover.js +185 -0
- package/dist/src/commands/restore.js +103 -0
- package/dist/src/commands/snapshot.js +155 -0
- package/dist/src/commands/sync.js +5 -1
- package/dist/src/constants/command-error-codes.js +4 -0
- package/dist/src/core/doctor.js +319 -6
- package/dist/src/core/installer.js +18 -15
- package/dist/src/core/list.js +6 -0
- package/dist/src/core/report.js +29 -8
- package/dist/src/core/scan-export.js +31 -30
- package/dist/src/core/scan.js +59 -34
- package/dist/src/core/snapshot-diff.js +111 -0
- package/dist/src/core/snapshot.js +535 -0
- package/dist/src/core/uninstall.js +12 -7
- package/dist/src/i18n/index.js +112 -4
- package/dist/src/scanners/semantic-scanner.js +272 -0
- package/dist/src/utils/config-format.js +168 -0
- package/package.json +2 -2
package/dist/src/i18n/index.js
CHANGED
|
@@ -10,8 +10,8 @@ const FALLBACK = 'en';
|
|
|
10
10
|
/** User-facing strings. Machines read `--json` output, which is never localized. */
|
|
11
11
|
const DICTIONARIES = {
|
|
12
12
|
en: {
|
|
13
|
-
'cli.usage': 'Usage: agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync> [path]',
|
|
14
|
-
'cli.help.commands': 'Commands: scan, export, pack, install, verify, attest, keygen, sign, validate, doctor, report, list, diff, config, uninstall, sync',
|
|
13
|
+
'cli.usage': 'Usage: agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync|snapshot|history|recover|restore|agents> [path]',
|
|
14
|
+
'cli.help.commands': 'Commands: scan, export, pack, install, verify, attest, keygen, sign, validate, doctor, report, list, diff, config, uninstall, sync, snapshot, history, recover, restore, agents',
|
|
15
15
|
'cli.help.docs': 'Docs: https://github.com/spsz831/AgentDock#readme',
|
|
16
16
|
'cli.version': 'agentdock {version}',
|
|
17
17
|
'pack.usage': 'Usage: agentdock pack --from-scan <scan.yml> --out <dir> [--zip] [--env <file>] [--overwrite]',
|
|
@@ -47,6 +47,60 @@ const DICTIONARIES = {
|
|
|
47
47
|
'sync.statusLocalOnly': 'local only ({count}):',
|
|
48
48
|
'sync.statusRemoteOnly': 'bundle only ({count}):',
|
|
49
49
|
'sync.undoSkipped': 'modified since sync — left untouched',
|
|
50
|
+
'snapshot.usage': 'Usage: agentdock snapshot [create|list] [--agent <id|all>] [--root <dir>] [--redact] [--if-changed]\n agentdock snapshot push <target-dir> [--snapshot <id>] [--force]\n agentdock snapshot pull <source-dir> [--force]',
|
|
51
|
+
'snapshot.pushUsage': 'Usage: agentdock snapshot push <target-dir> [--snapshot <id>] [--force]',
|
|
52
|
+
'snapshot.pullUsage': 'Usage: agentdock snapshot pull <source-dir> [--force]',
|
|
53
|
+
'snapshot.pushed': 'Snapshot {id} exported to {dest}',
|
|
54
|
+
'snapshot.pulled': 'Imported {count} snapshot(s): {ids}',
|
|
55
|
+
'snapshot.pullSkipped': ' skipped (already exists, use --force to overwrite): {ids}',
|
|
56
|
+
'snapshot.pullNone': 'No snapshots imported',
|
|
57
|
+
'snapshot.created': 'Snapshot created: {id}',
|
|
58
|
+
'snapshot.location': ' location: {path}',
|
|
59
|
+
'snapshot.files': ' files ({count}): {files}',
|
|
60
|
+
'snapshot.counts': ' top-level keys: {top} / env keys: {env} / MCP: {mcp}',
|
|
61
|
+
'snapshot.redacted': ' secrets: redacted',
|
|
62
|
+
'snapshot.plaintext': ' secrets: stored in plaintext (local only — do not commit)',
|
|
63
|
+
'snapshot.empty': 'No snapshots yet — run `agentdock snapshot` to create a baseline',
|
|
64
|
+
'snapshot.unchanged': 'Configuration unchanged since snapshot {id} — skipped',
|
|
65
|
+
'snapshot.listHeader': 'Snapshots ({count}) in {dir}:',
|
|
66
|
+
'snapshot.listItem': ' {id} {agent} {files} file(s){redacted}',
|
|
67
|
+
'history.usage': 'Usage: agentdock history [--agent <id|all>] [--root <dir>]',
|
|
68
|
+
'agents.usage': 'Usage: agentdock agents [--root <dir>] [--json]',
|
|
69
|
+
'agents.header': 'Supported AI coding tools: {supported}; detected on this machine: {installed} (root: {root})',
|
|
70
|
+
'agents.item': ' {id} {name} {status} {files} config file(s)',
|
|
71
|
+
'agents.installed': '[installed]',
|
|
72
|
+
'agents.notInstalled': '[not found]',
|
|
73
|
+
'agents.experimental': 'experimental path — may need verification',
|
|
74
|
+
'agents.note': ' {note}',
|
|
75
|
+
'agents.hint': 'Use `agentdock snapshot --agent <id>` / `agentdock doctor --agent <id>` for any tool above.',
|
|
76
|
+
'history.header': 'Snapshot history ({count}) in {dir}:',
|
|
77
|
+
'history.entry': ' {id} {agent} {files} file(s) {summary}',
|
|
78
|
+
'history.baseline': 'baseline',
|
|
79
|
+
'history.changes': '{added} added / {removed} removed / {modified} modified',
|
|
80
|
+
'history.highlight': ' {path}',
|
|
81
|
+
'history.empty': 'No snapshots yet — run `agentdock snapshot` to create a baseline',
|
|
82
|
+
'recover.usage': 'Usage: agentdock recover [--snapshot <id>] [--apply] [--undo] [--root <dir>]',
|
|
83
|
+
'recover.header': 'Recovery candidates ({count}) in {dir} (highest score first):',
|
|
84
|
+
'recover.candidate': ' {score}/100 {id} {agent} {files} file(s){redacted}',
|
|
85
|
+
'recover.missing': ' missing: {files}',
|
|
86
|
+
'recover.recommended': ' recommended: {id}',
|
|
87
|
+
'recover.hint': 'Run `agentdock recover --apply` to restore the recommended snapshot, or `agentdock recover --snapshot <id> --apply` to choose another.',
|
|
88
|
+
'recover.empty': 'No snapshots to recover from — run `agentdock snapshot` first',
|
|
89
|
+
'recover.planLine': 'Recovery plan from snapshot {id} ({score}/100, {mode}):',
|
|
90
|
+
'recover.applied': 'Recovered {count} file(s) from snapshot {id}',
|
|
91
|
+
'recover.backup': ' pre-recovery snapshot: {id} (rollback: agentdock recover --undo --apply)',
|
|
92
|
+
'recover.undone': 'Undo complete: restored {count} file(s) from snapshot {id}',
|
|
93
|
+
'diff.snapshotHeader': 'Config diff: snapshot {from} → {to}',
|
|
94
|
+
'diff.noSnapshot': 'No snapshot found — run `agentdock snapshot` first',
|
|
95
|
+
'diff.noChanges': 'No configuration changes',
|
|
96
|
+
'restore.usage': 'Usage: agentdock restore --snapshot <id> [--apply]; rollback: agentdock restore --undo [--apply]',
|
|
97
|
+
'restore.planHeader': 'Restore plan from snapshot {id} ({mode}):',
|
|
98
|
+
'restore.undoPlanHeader': 'Undo plan — restore pre-restore snapshot {id} ({mode}):',
|
|
99
|
+
'restore.modeDryRun': 'dry-run — no changes written, use --apply to execute',
|
|
100
|
+
'restore.modeApply': 'applied',
|
|
101
|
+
'restore.applied': 'Restored {count} file(s) from snapshot {id}',
|
|
102
|
+
'restore.backup': ' pre-restore snapshot: {id} (rollback: agentdock restore --undo --apply)',
|
|
103
|
+
'restore.undone': 'Undo complete: restored {count} file(s) from snapshot {id}',
|
|
50
104
|
'install.complete': 'Install completed: {path}',
|
|
51
105
|
'uninstall.complete': 'Uninstall complete: {path}',
|
|
52
106
|
'uninstall.dryRunHeader': 'Uninstall plan (dry-run — no changes made): {path}',
|
|
@@ -67,8 +121,8 @@ const DICTIONARIES = {
|
|
|
67
121
|
'config.unsetValue': '(unset)',
|
|
68
122
|
},
|
|
69
123
|
'zh-CN': {
|
|
70
|
-
'cli.usage': '用法:agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync> [path]',
|
|
71
|
-
'cli.help.commands': '命令:scan、export、pack、install、verify、attest、keygen、sign、validate、doctor、report、list、diff、config、uninstall、sync',
|
|
124
|
+
'cli.usage': '用法:agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync|snapshot|history|recover|restore|agents> [path]',
|
|
125
|
+
'cli.help.commands': '命令:scan、export、pack、install、verify、attest、keygen、sign、validate、doctor、report、list、diff、config、uninstall、sync、snapshot、history、recover、restore、agents',
|
|
72
126
|
'cli.help.docs': '文档:https://github.com/spsz831/AgentDock#readme',
|
|
73
127
|
'cli.version': 'agentdock {version}',
|
|
74
128
|
'pack.usage': '用法:agentdock pack --from-scan <scan.yml> --out <目录> [--zip] [--env <文件>] [--overwrite]',
|
|
@@ -104,6 +158,60 @@ const DICTIONARIES = {
|
|
|
104
158
|
'sync.statusLocalOnly': '仅本机有({count}):',
|
|
105
159
|
'sync.statusRemoteOnly': '仅 bundle 有({count}):',
|
|
106
160
|
'sync.undoSkipped': '同步后被修改过,保持不动',
|
|
161
|
+
'snapshot.usage': '用法:agentdock snapshot [create|list] [--agent <工具id|all>] [--root <目录>] [--redact] [--if-changed]\n agentdock snapshot push <目标目录> [--snapshot <id>] [--force]\n agentdock snapshot pull <来源目录> [--force]',
|
|
162
|
+
'snapshot.pushUsage': '用法:agentdock snapshot push <目标目录> [--snapshot <id>] [--force]',
|
|
163
|
+
'snapshot.pullUsage': '用法:agentdock snapshot pull <来源目录> [--force]',
|
|
164
|
+
'snapshot.pushed': '快照 {id} 已导出到 {dest}',
|
|
165
|
+
'snapshot.pulled': '已导入 {count} 份快照:{ids}',
|
|
166
|
+
'snapshot.pullSkipped': ' 已跳过(本地已存在,--force 可覆盖):{ids}',
|
|
167
|
+
'snapshot.pullNone': '没有导入任何快照',
|
|
168
|
+
'snapshot.created': '快照已创建:{id}',
|
|
169
|
+
'snapshot.location': ' 位置:{path}',
|
|
170
|
+
'snapshot.files': ' 文件({count}):{files}',
|
|
171
|
+
'snapshot.counts': ' 顶层键:{top} / env 键:{env} / MCP:{mcp}',
|
|
172
|
+
'snapshot.redacted': ' 敏感值:已打码',
|
|
173
|
+
'snapshot.plaintext': ' 敏感值:明文保存(仅本机,请勿提交)',
|
|
174
|
+
'snapshot.empty': '尚无快照 —— 先运行 `agentdock snapshot` 建立基线',
|
|
175
|
+
'snapshot.unchanged': '配置自快照 {id} 以来没有变化 —— 已跳过',
|
|
176
|
+
'snapshot.listHeader': '快照({count})位于 {dir}:',
|
|
177
|
+
'snapshot.listItem': ' {id} {agent} {files} 个文件{redacted}',
|
|
178
|
+
'history.usage': '用法:agentdock history [--agent <工具id|all>] [--root <目录>]',
|
|
179
|
+
'agents.usage': '用法:agentdock agents [--root <目录>] [--json]',
|
|
180
|
+
'agents.header': '支持 {supported} 个 AI 编程工具;本机检测到 {installed} 个(root:{root})',
|
|
181
|
+
'agents.item': ' {id} {name} {status} {files} 个配置文件',
|
|
182
|
+
'agents.installed': '[已安装]',
|
|
183
|
+
'agents.notInstalled': '[未找到]',
|
|
184
|
+
'agents.experimental': '实验性路径 —— 可能需实测确认',
|
|
185
|
+
'agents.note': ' {note}',
|
|
186
|
+
'agents.hint': '对以上任意工具可用 `agentdock snapshot --agent <工具id>` / `agentdock doctor --agent <工具id>`。',
|
|
187
|
+
'history.header': '快照时间线({count})位于 {dir}:',
|
|
188
|
+
'history.entry': ' {id} {agent} {files} 个文件 {summary}',
|
|
189
|
+
'history.baseline': '基线',
|
|
190
|
+
'history.changes': '{added} 新增 / {removed} 删除 / {modified} 修改',
|
|
191
|
+
'history.highlight': ' {path}',
|
|
192
|
+
'history.empty': '尚无快照 —— 先运行 `agentdock snapshot` 建立基线',
|
|
193
|
+
'recover.usage': '用法:agentdock recover [--snapshot <id>] [--apply] [--undo] [--root <目录>]',
|
|
194
|
+
'recover.header': '恢复候选({count})位于 {dir}(按完整度评分排序):',
|
|
195
|
+
'recover.candidate': ' {score}/100 {id} {agent} {files} 个文件{redacted}',
|
|
196
|
+
'recover.missing': ' 缺失:{files}',
|
|
197
|
+
'recover.recommended': ' 推荐:{id}',
|
|
198
|
+
'recover.hint': '运行 `agentdock recover --apply` 恢复推荐快照,或 `agentdock recover --snapshot <id> --apply` 选择其他快照。',
|
|
199
|
+
'recover.empty': '没有可恢复的快照 —— 先运行 `agentdock snapshot` 建立基线',
|
|
200
|
+
'recover.planLine': '恢复计划(快照 {id},评分 {score}/100,{mode}):',
|
|
201
|
+
'recover.applied': '已从快照 {id} 恢复 {count} 个文件',
|
|
202
|
+
'recover.backup': ' 写前快照:{id}(回滚:agentdock recover --undo --apply)',
|
|
203
|
+
'recover.undone': '撤销完成:已从快照 {id} 恢复 {count} 个文件',
|
|
204
|
+
'diff.snapshotHeader': '配置差异:快照 {from} → {to}',
|
|
205
|
+
'diff.noSnapshot': '尚未找到快照 —— 先运行 `agentdock snapshot`',
|
|
206
|
+
'diff.noChanges': '配置没有变化',
|
|
207
|
+
'restore.usage': '用法:agentdock restore --snapshot <id> [--apply];回滚:agentdock restore --undo [--apply]',
|
|
208
|
+
'restore.planHeader': '恢复计划(快照 {id},{mode}):',
|
|
209
|
+
'restore.undoPlanHeader': '撤销计划 —— 还原写前快照 {id}({mode}):',
|
|
210
|
+
'restore.modeDryRun': 'dry-run — 未写入任何改动,--apply 才会执行',
|
|
211
|
+
'restore.modeApply': '已执行',
|
|
212
|
+
'restore.applied': '已从快照 {id} 恢复 {count} 个文件',
|
|
213
|
+
'restore.backup': ' 写前快照:{id}(回滚:agentdock restore --undo --apply)',
|
|
214
|
+
'restore.undone': '撤销完成:已从快照 {id} 恢复 {count} 个文件',
|
|
107
215
|
'install.complete': '安装完成:{path}',
|
|
108
216
|
'uninstall.complete': '卸载完成:{path}',
|
|
109
217
|
'uninstall.dryRunHeader': '卸载计划(dry-run — 未做任何改动):{path}',
|
|
@@ -0,0 +1,272 @@
|
|
|
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.scanAgentSemantic = scanAgentSemantic;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const sensitive_1 = require("./sensitive");
|
|
10
|
+
const config_format_1 = require("../utils/config-format");
|
|
11
|
+
/**
|
|
12
|
+
* 通用语义扫描器:按 `AgentSemanticProfile` 采集 MCP、全局指令、规则、
|
|
13
|
+
* 技能与子代理。Claude / Codex 仍走各自的专用扫描器(保留既有语义),
|
|
14
|
+
* 其余工具统一走这里。
|
|
15
|
+
*/
|
|
16
|
+
async function exists(targetPath) {
|
|
17
|
+
try {
|
|
18
|
+
await promises_1.default.access(targetPath);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function abs(root, relPath) {
|
|
26
|
+
return node_path_1.default.join(root, ...relPath.split('/'));
|
|
27
|
+
}
|
|
28
|
+
function slug(value) {
|
|
29
|
+
return value
|
|
30
|
+
.replace(/[\\/.:]+/g, '-')
|
|
31
|
+
.replace(/-+/g, '-')
|
|
32
|
+
.replace(/^-|-$/g, '')
|
|
33
|
+
.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function recordSecrets(node, basePath, agent, secrets) {
|
|
36
|
+
const found = [];
|
|
37
|
+
(0, sensitive_1.collectSecrets)(node, basePath, found);
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
for (const item of found) {
|
|
40
|
+
if (seen.has(item.jsonPath)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
seen.add(item.jsonPath);
|
|
44
|
+
secrets.push({
|
|
45
|
+
key: (0, sensitive_1.secretKeyName)(agent, item.jsonPath),
|
|
46
|
+
source: item.jsonPath,
|
|
47
|
+
sample: (0, sensitive_1.maskSecret)(item.value),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** 递归收集目录下的结构化配置文件(最多 `depth` 层)。 */
|
|
52
|
+
async function collectStructuredFiles(dir, depth, out) {
|
|
53
|
+
let entries;
|
|
54
|
+
try {
|
|
55
|
+
entries = await promises_1.default.readdir(dir, { withFileTypes: true });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const full = node_path_1.default.join(dir, entry.name);
|
|
62
|
+
if (entry.isDirectory()) {
|
|
63
|
+
if (depth > 0) {
|
|
64
|
+
await collectStructuredFiles(full, depth - 1, out);
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if ((0, config_format_1.kindFromPath)(entry.name) !== 'text') {
|
|
69
|
+
out.push(full);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** 收集目录下指定扩展名的文件(单层)。 */
|
|
74
|
+
async function collectFilesByExt(dir, extensions) {
|
|
75
|
+
try {
|
|
76
|
+
const entries = await promises_1.default.readdir(dir, { withFileTypes: true });
|
|
77
|
+
return entries
|
|
78
|
+
.filter((entry) => entry.isFile() && extensions.some((ext) => entry.name.toLowerCase().endsWith(ext)))
|
|
79
|
+
.map((entry) => node_path_1.default.join(dir, entry.name))
|
|
80
|
+
.sort();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function scanAgentSemantic(root, profile, agentId) {
|
|
87
|
+
const domain = {
|
|
88
|
+
mcp: [],
|
|
89
|
+
skills: [],
|
|
90
|
+
agents: [],
|
|
91
|
+
plugins: [],
|
|
92
|
+
hooks: [],
|
|
93
|
+
memory: [],
|
|
94
|
+
settings: [],
|
|
95
|
+
};
|
|
96
|
+
const secrets = [];
|
|
97
|
+
const skipped = [];
|
|
98
|
+
const notes = [];
|
|
99
|
+
const settingsSeen = new Set();
|
|
100
|
+
const memorySeen = new Set();
|
|
101
|
+
const skillSeen = new Set();
|
|
102
|
+
/** 把一个结构化配置文件登记为 settings,并顺带提取其中的机密。 */
|
|
103
|
+
async function addSettings(relPath, kind) {
|
|
104
|
+
const full = abs(root, relPath);
|
|
105
|
+
if (settingsSeen.has(relPath) || !(await exists(full))) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
settingsSeen.add(relPath);
|
|
109
|
+
domain.settings.push({
|
|
110
|
+
id: `${agentId}-settings-${slug(relPath)}`,
|
|
111
|
+
kind: 'settings',
|
|
112
|
+
path: full,
|
|
113
|
+
ref: relPath,
|
|
114
|
+
});
|
|
115
|
+
if (kind === 'text') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const parsed = (0, config_format_1.parseStructured)(kind, await promises_1.default.readFile(full, 'utf8'));
|
|
120
|
+
recordSecrets(parsed, full, agentId, secrets);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
notes.push(`${relPath} 解析失败(${kind}),仅记录路径`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** 指令 / 规则文件 → memory。 */
|
|
127
|
+
async function addMemory(full, ref) {
|
|
128
|
+
if (memorySeen.has(full)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
memorySeen.add(full);
|
|
132
|
+
domain.memory.push({
|
|
133
|
+
id: `${agentId}-memory-${slug(ref)}`,
|
|
134
|
+
kind: 'memory',
|
|
135
|
+
path: full,
|
|
136
|
+
ref,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// --- MCP(同时把承载它的配置文件登记为 settings,导出时整文件合并) ---
|
|
140
|
+
for (const source of profile.mcp ?? []) {
|
|
141
|
+
const full = abs(root, source.relPath);
|
|
142
|
+
if (!(await exists(full))) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
await addSettings(source.relPath, source.kind);
|
|
146
|
+
let parsed;
|
|
147
|
+
try {
|
|
148
|
+
parsed = (0, config_format_1.parseStructured)(source.kind, await promises_1.default.readFile(full, 'utf8'));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
notes.push(`${source.relPath} 解析失败,跳过 MCP 提取`);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const container = parsed?.[source.key];
|
|
155
|
+
if (!container || typeof container !== 'object' || Array.isArray(container)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
for (const name of Object.keys(container)) {
|
|
159
|
+
domain.mcp.push({
|
|
160
|
+
id: `mcp-${name}`,
|
|
161
|
+
kind: 'mcp',
|
|
162
|
+
path: full,
|
|
163
|
+
ref: `${source.relPath}#${source.key}.${name}`,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const count = Object.keys(container).length;
|
|
167
|
+
if (count === 0) {
|
|
168
|
+
notes.push(`${source.relPath} 中未定义 MCP server`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// --- 普通配置(整文件迁移) ---
|
|
172
|
+
for (const config of profile.configs ?? []) {
|
|
173
|
+
await addSettings(config.relPath, config.kind);
|
|
174
|
+
}
|
|
175
|
+
// --- 目录型配置(profile / 补丁) ---
|
|
176
|
+
for (const dirRel of profile.configDirs ?? []) {
|
|
177
|
+
const dirFull = abs(root, dirRel);
|
|
178
|
+
const files = [];
|
|
179
|
+
await collectStructuredFiles(dirFull, 2, files);
|
|
180
|
+
for (const full of files) {
|
|
181
|
+
const rel = node_path_1.default.relative(root, full).split(node_path_1.default.sep).join('/');
|
|
182
|
+
await addSettings(rel, (0, config_format_1.kindFromPath)(full));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// --- 全局指令 ---
|
|
186
|
+
for (const instruction of profile.instructions ?? []) {
|
|
187
|
+
const full = abs(root, instruction.relPath);
|
|
188
|
+
if (await exists(full)) {
|
|
189
|
+
await addMemory(full, instruction.relPath);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// --- 规则目录(md / mdc / txt → memory) ---
|
|
193
|
+
for (const dirRel of profile.ruleDirs ?? []) {
|
|
194
|
+
const dirFull = abs(root, dirRel);
|
|
195
|
+
const files = await collectFilesByExt(dirFull, ['.md', '.mdc', '.txt']);
|
|
196
|
+
for (const full of files) {
|
|
197
|
+
const rel = node_path_1.default.relative(root, full).split(node_path_1.default.sep).join('/');
|
|
198
|
+
await addMemory(full, rel);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// --- 技能目录(每个子目录一个技能) ---
|
|
202
|
+
for (const dirRel of profile.skillDirs ?? []) {
|
|
203
|
+
const dirFull = abs(root, dirRel);
|
|
204
|
+
let entries;
|
|
205
|
+
try {
|
|
206
|
+
entries = await promises_1.default.readdir(dirFull, { withFileTypes: true });
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
for (const entry of entries) {
|
|
212
|
+
if (!entry.isDirectory()) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const full = node_path_1.default.join(dirFull, entry.name);
|
|
216
|
+
if (skillSeen.has(full)) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
skillSeen.add(full);
|
|
220
|
+
domain.skills.push({
|
|
221
|
+
id: `skill-${entry.name}`,
|
|
222
|
+
kind: 'skill',
|
|
223
|
+
path: full,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// --- 子代理(md / json) ---
|
|
228
|
+
for (const dirRel of profile.agentDirs ?? []) {
|
|
229
|
+
const files = await collectFilesByExt(abs(root, dirRel), ['.md']);
|
|
230
|
+
for (const full of files) {
|
|
231
|
+
domain.agents.push({
|
|
232
|
+
id: `agent-${node_path_1.default.basename(full).replace(/\.md$/i, '')}`,
|
|
233
|
+
kind: 'agent',
|
|
234
|
+
path: full,
|
|
235
|
+
ref: node_path_1.default.relative(root, full).split(node_path_1.default.sep).join('/'),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (const dirRel of profile.agentJsonDirs ?? []) {
|
|
240
|
+
const files = await collectFilesByExt(abs(root, dirRel), ['.json']);
|
|
241
|
+
for (const full of files) {
|
|
242
|
+
domain.agents.push({
|
|
243
|
+
id: `agent-${node_path_1.default.basename(full).replace(/\.json$/i, '')}`,
|
|
244
|
+
kind: 'agent',
|
|
245
|
+
path: full,
|
|
246
|
+
ref: node_path_1.default.relative(root, full).split(node_path_1.default.sep).join('/'),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const total = Object.values(domain).reduce((sum, entries) => sum + entries.length, 0);
|
|
251
|
+
if (total === 0) {
|
|
252
|
+
notes.push(`未找到 ${agentId} 的语义配置(可先用 snapshot 做文件级备份)`);
|
|
253
|
+
}
|
|
254
|
+
// 去重:同一 MCP server 出现在多个候选文件时按 path + ref 保留一条。
|
|
255
|
+
const dedup = (entries) => {
|
|
256
|
+
const seen = new Set();
|
|
257
|
+
return entries.filter((entry) => {
|
|
258
|
+
const key = `${entry.kind}:${entry.path}:${entry.ref ?? ''}`;
|
|
259
|
+
if (seen.has(key)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
seen.add(key);
|
|
263
|
+
return true;
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
domain.mcp = dedup(domain.mcp);
|
|
267
|
+
domain.settings = dedup(domain.settings);
|
|
268
|
+
domain.memory = dedup(domain.memory);
|
|
269
|
+
domain.skills = dedup(domain.skills);
|
|
270
|
+
domain.agents = dedup(domain.agents);
|
|
271
|
+
return { domain, secrets, skipped, notes };
|
|
272
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 结构化配置格式的统一解析 / 序列化(v1.4)。
|
|
4
|
+
*
|
|
5
|
+
* 语义化迁移需要同时处理 JSON、JSONC、YAML、TOML 四种格式:
|
|
6
|
+
* - `scan` 按工具声明的格式读取 MCP / settings;
|
|
7
|
+
* - `export` 脱敏后按原格式重新序列化;
|
|
8
|
+
* - `install` 合并到目标文件时也按目标扩展名保留格式。
|
|
9
|
+
*
|
|
10
|
+
* JSONC 只支持读取(写回为标准 JSON),避免发明注释保留逻辑。
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.stripJsonc = stripJsonc;
|
|
17
|
+
exports.kindFromPath = kindFromPath;
|
|
18
|
+
exports.parseStructured = parseStructured;
|
|
19
|
+
exports.stringifyStructured = stringifyStructured;
|
|
20
|
+
exports.parseConfigObjectSafe = parseConfigObjectSafe;
|
|
21
|
+
const smol_toml_1 = require("smol-toml");
|
|
22
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
23
|
+
/** 去掉 JSONC 注释与尾随逗号,且不破坏字符串内容。 */
|
|
24
|
+
function stripJsonc(text) {
|
|
25
|
+
let out = '';
|
|
26
|
+
let inString = false;
|
|
27
|
+
let escaped = false;
|
|
28
|
+
let lineComment = false;
|
|
29
|
+
let blockComment = false;
|
|
30
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
31
|
+
const char = text[index];
|
|
32
|
+
const next = text[index + 1];
|
|
33
|
+
if (lineComment) {
|
|
34
|
+
if (char === '\n') {
|
|
35
|
+
lineComment = false;
|
|
36
|
+
out += char;
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (blockComment) {
|
|
41
|
+
if (char === '*' && next === '/') {
|
|
42
|
+
blockComment = false;
|
|
43
|
+
index += 1;
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (inString) {
|
|
48
|
+
out += char;
|
|
49
|
+
if (escaped) {
|
|
50
|
+
escaped = false;
|
|
51
|
+
}
|
|
52
|
+
else if (char === '\\') {
|
|
53
|
+
escaped = true;
|
|
54
|
+
}
|
|
55
|
+
else if (char === '"') {
|
|
56
|
+
inString = false;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === '"') {
|
|
61
|
+
inString = true;
|
|
62
|
+
out += char;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (char === '/' && next === '/') {
|
|
66
|
+
lineComment = true;
|
|
67
|
+
index += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (char === '/' && next === '*') {
|
|
71
|
+
blockComment = true;
|
|
72
|
+
index += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
out += char;
|
|
76
|
+
}
|
|
77
|
+
// 去尾随逗号(同样跳过字符串)
|
|
78
|
+
let cleaned = '';
|
|
79
|
+
inString = false;
|
|
80
|
+
escaped = false;
|
|
81
|
+
for (let index = 0; index < out.length; index += 1) {
|
|
82
|
+
const char = out[index];
|
|
83
|
+
if (inString) {
|
|
84
|
+
cleaned += char;
|
|
85
|
+
if (escaped) {
|
|
86
|
+
escaped = false;
|
|
87
|
+
}
|
|
88
|
+
else if (char === '\\') {
|
|
89
|
+
escaped = true;
|
|
90
|
+
}
|
|
91
|
+
else if (char === '"') {
|
|
92
|
+
inString = false;
|
|
93
|
+
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (char === '"') {
|
|
97
|
+
inString = true;
|
|
98
|
+
cleaned += char;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (char === ',') {
|
|
102
|
+
let lookahead = index + 1;
|
|
103
|
+
while (lookahead < out.length && /\s/.test(out[lookahead])) {
|
|
104
|
+
lookahead += 1;
|
|
105
|
+
}
|
|
106
|
+
if (out[lookahead] === '}' || out[lookahead] === ']') {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
cleaned += char;
|
|
111
|
+
}
|
|
112
|
+
return cleaned;
|
|
113
|
+
}
|
|
114
|
+
/** 按文件扩展名推断配置格式;未知扩展名视为纯文本。 */
|
|
115
|
+
function kindFromPath(filePath) {
|
|
116
|
+
const lower = filePath.toLowerCase();
|
|
117
|
+
if (lower.endsWith('.jsonc'))
|
|
118
|
+
return 'jsonc';
|
|
119
|
+
if (lower.endsWith('.json'))
|
|
120
|
+
return 'json';
|
|
121
|
+
if (lower.endsWith('.toml'))
|
|
122
|
+
return 'toml';
|
|
123
|
+
if (lower.endsWith('.yml') || lower.endsWith('.yaml'))
|
|
124
|
+
return 'yaml';
|
|
125
|
+
return 'text';
|
|
126
|
+
}
|
|
127
|
+
/** 按格式解析文本;解析失败时抛出原始错误,由调用方决定如何处理。 */
|
|
128
|
+
function parseStructured(kind, text) {
|
|
129
|
+
switch (kind) {
|
|
130
|
+
case 'json':
|
|
131
|
+
return JSON.parse(text);
|
|
132
|
+
case 'jsonc':
|
|
133
|
+
return JSON.parse(stripJsonc(text));
|
|
134
|
+
case 'toml':
|
|
135
|
+
return (0, smol_toml_1.parse)(text);
|
|
136
|
+
case 'yaml':
|
|
137
|
+
return yaml_1.default.parse(text);
|
|
138
|
+
default:
|
|
139
|
+
throw new Error(`CONFIG_FORMAT_UNSUPPORTED: ${kind}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** 按格式序列化;JSONC 统一写回标准 JSON(不保留注释)。 */
|
|
143
|
+
function stringifyStructured(kind, data) {
|
|
144
|
+
switch (kind) {
|
|
145
|
+
case 'toml':
|
|
146
|
+
return (0, smol_toml_1.stringify)(data);
|
|
147
|
+
case 'yaml':
|
|
148
|
+
return yaml_1.default.stringify(data);
|
|
149
|
+
case 'json':
|
|
150
|
+
case 'jsonc':
|
|
151
|
+
return `${JSON.stringify(data, null, 2)}\n`;
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`CONFIG_FORMAT_UNSUPPORTED: ${kind}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** 解析失败返回 null(供快照 / 差异这类“尽力而为”场景使用)。 */
|
|
157
|
+
function parseConfigObjectSafe(relPath, text) {
|
|
158
|
+
const kind = kindFromPath(relPath);
|
|
159
|
+
if (kind === 'text') {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
return parseStructured(kind, text);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Diagnose, migrate, and back up your AI coding
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Diagnose, migrate, and back up your AI coding environment — Claude Code, Codex, Gemini CLI, TRAE, Cursor/Grok Build, Cline, Windsurf, Copilot, OpenCode and more — with config snapshots, restore, and secret isolation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
7
7
|
"codex",
|