agentdock-cli 1.2.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 +59 -2
- 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 +3 -0
- package/dist/src/commands/agents.js +84 -0
- package/dist/src/commands/diff.js +3 -1
- package/dist/src/commands/history.js +3 -1
- package/dist/src/commands/list.js +2 -1
- package/dist/src/commands/recover.js +10 -5
- package/dist/src/commands/snapshot.js +2 -1
- package/dist/src/commands/sync.js +5 -1
- package/dist/src/core/doctor.js +151 -50
- 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 +2 -13
- package/dist/src/core/snapshot.js +14 -14
- package/dist/src/core/uninstall.js +12 -7
- package/dist/src/i18n/index.js +24 -8
- 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/core/scan.js
CHANGED
|
@@ -10,7 +10,10 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
10
10
|
const yaml_1 = __importDefault(require("yaml"));
|
|
11
11
|
const claude_scanner_1 = require("../scanners/claude-scanner");
|
|
12
12
|
const codex_scanner_1 = require("../scanners/codex-scanner");
|
|
13
|
+
const semantic_scanner_1 = require("../scanners/semantic-scanner");
|
|
13
14
|
const sensitive_1 = require("../scanners/sensitive");
|
|
15
|
+
const registry_1 = require("../agents/registry");
|
|
16
|
+
const semantic_1 = require("../agents/semantic");
|
|
14
17
|
const fs_1 = require("../utils/fs");
|
|
15
18
|
function countDomain(domain) {
|
|
16
19
|
return {
|
|
@@ -23,33 +26,41 @@ function countDomain(domain) {
|
|
|
23
26
|
settings: domain.settings.length,
|
|
24
27
|
};
|
|
25
28
|
}
|
|
29
|
+
function domainTotal(domain) {
|
|
30
|
+
return Object.values(domain).reduce((sum, entries) => sum + entries.length, 0);
|
|
31
|
+
}
|
|
32
|
+
function emptyDomain() {
|
|
33
|
+
return {
|
|
34
|
+
mcp: [],
|
|
35
|
+
skills: [],
|
|
36
|
+
agents: [],
|
|
37
|
+
plugins: [],
|
|
38
|
+
hooks: [],
|
|
39
|
+
memory: [],
|
|
40
|
+
settings: [],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
26
43
|
function renderReport(manifest, reportData) {
|
|
27
44
|
const lines = ['# AgentDock Scan Report', ''];
|
|
28
45
|
lines.push(`- Agent: \`${reportData.agent}\``);
|
|
29
46
|
lines.push(`- Secrets isolated: **${reportData.secretsCount}**`);
|
|
30
47
|
lines.push('');
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
lines.push(
|
|
37
|
-
lines.push(`-
|
|
38
|
-
lines.push(`-
|
|
39
|
-
lines.push(`-
|
|
40
|
-
lines.push(`-
|
|
41
|
-
lines.push(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
lines.push(`- Skills: ${codex.skills.length}`);
|
|
48
|
-
lines.push(`- Agents: ${codex.agents.length}`);
|
|
49
|
-
lines.push(`- Plugins: ${codex.plugins.length}`);
|
|
50
|
-
lines.push(`- Hooks: ${codex.hooks.length}`);
|
|
51
|
-
lines.push(`- Memory files: ${codex.memory.length}`);
|
|
52
|
-
lines.push(`- config.toml: ${codex.settings.length ? 'yes' : 'no'}`);
|
|
48
|
+
for (const [agentId, domain] of Object.entries(manifest.agents)) {
|
|
49
|
+
if (!domain) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const adapter = (0, registry_1.resolveAgentAdapter)(agentId);
|
|
53
|
+
lines.push(`## ${adapter?.displayName ?? agentId} (\`${agentId}\`)`, '');
|
|
54
|
+
lines.push(`- MCP servers: ${domain.mcp.length}`);
|
|
55
|
+
lines.push(`- Skills: ${domain.skills.length}`);
|
|
56
|
+
lines.push(`- Agents: ${domain.agents.length}`);
|
|
57
|
+
lines.push(`- Plugins: ${domain.plugins.length}`);
|
|
58
|
+
lines.push(`- Hooks: ${domain.hooks.length}`);
|
|
59
|
+
lines.push(`- Memory / instructions: ${domain.memory.length}`);
|
|
60
|
+
lines.push(`- Config files: ${domain.settings.length}`);
|
|
61
|
+
if (adapter?.experimental) {
|
|
62
|
+
lines.push('- 状态:实验性路径(未完全实测)');
|
|
63
|
+
}
|
|
53
64
|
lines.push('');
|
|
54
65
|
}
|
|
55
66
|
if (reportData.secretsCount > 0) {
|
|
@@ -77,32 +88,46 @@ function renderReport(manifest, reportData) {
|
|
|
77
88
|
}
|
|
78
89
|
return lines.join('\n');
|
|
79
90
|
}
|
|
91
|
+
async function scanOne(agentId, root) {
|
|
92
|
+
if (agentId === 'claude') {
|
|
93
|
+
return (0, claude_scanner_1.scanClaude)(root);
|
|
94
|
+
}
|
|
95
|
+
if (agentId === 'codex') {
|
|
96
|
+
return (0, codex_scanner_1.scanCodex)(root);
|
|
97
|
+
}
|
|
98
|
+
const profile = (0, semantic_1.agentSemanticProfile)(agentId);
|
|
99
|
+
if (!profile) {
|
|
100
|
+
return { domain: emptyDomain(), secrets: [], skipped: [], notes: [`${agentId} 暂无语义化配置`] };
|
|
101
|
+
}
|
|
102
|
+
return (0, semantic_scanner_1.scanAgentSemantic)(root, profile, agentId);
|
|
103
|
+
}
|
|
80
104
|
async function runScan(options) {
|
|
81
105
|
const agents = {};
|
|
82
106
|
const secrets = [];
|
|
83
107
|
const skipped = [];
|
|
84
108
|
const notes = [];
|
|
85
109
|
const counts = {};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
agents
|
|
110
|
+
const agentIds = options.agent === 'all'
|
|
111
|
+
? registry_1.AGENT_ADAPTERS.map((adapter) => adapter.id)
|
|
112
|
+
: [(0, registry_1.normalizeAgentId)(options.agent, false)];
|
|
113
|
+
for (const agentId of agentIds) {
|
|
114
|
+
const result = await scanOne(agentId, options.root);
|
|
115
|
+
const total = domainTotal(result.domain);
|
|
116
|
+
// `all` 模式下跳过本机未安装 / 无定义的工具,避免产出 30 多个空域。
|
|
117
|
+
if (options.agent === 'all' && total === 0) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
agents[agentId] = result.domain;
|
|
97
121
|
secrets.push(...result.secrets);
|
|
98
122
|
skipped.push(...result.skipped);
|
|
99
123
|
notes.push(...result.notes);
|
|
100
|
-
counts
|
|
124
|
+
counts[agentId] = countDomain(result.domain);
|
|
101
125
|
}
|
|
102
126
|
const manifest = {
|
|
103
127
|
version: 3,
|
|
104
128
|
project: { name: `${node_path_1.default.basename(options.root) || 'local'}-ai-env` },
|
|
105
129
|
agents,
|
|
130
|
+
scanRoot: options.root,
|
|
106
131
|
secrets,
|
|
107
132
|
outputs: { type: 'directory', path: options.out },
|
|
108
133
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseConfigObject = parseConfigObject;
|
|
4
4
|
exports.buildSnapshotDiff = buildSnapshotDiff;
|
|
5
|
-
const
|
|
5
|
+
const config_format_1 = require("../utils/config-format");
|
|
6
6
|
/**
|
|
7
7
|
* 快照比对(v1.2)。
|
|
8
8
|
* 按 JSON / TOML 路径展开后逐键比较,值统一脱敏且截断,
|
|
@@ -12,18 +12,7 @@ const SENSITIVE_PATH = /(token|secret|passw|api[_-]?key|auth|credential|cookie)/
|
|
|
12
12
|
const MAX_VALUE_LENGTH = 120;
|
|
13
13
|
/** 解析配置文件为对象;解析失败或非结构化格式返回 null。 */
|
|
14
14
|
function parseConfigObject(relPath, text) {
|
|
15
|
-
|
|
16
|
-
if (relPath.endsWith('.json')) {
|
|
17
|
-
return JSON.parse(text);
|
|
18
|
-
}
|
|
19
|
-
if (relPath.endsWith('.toml')) {
|
|
20
|
-
return (0, smol_toml_1.parse)(text);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
15
|
+
return (0, config_format_1.parseConfigObjectSafe)(relPath, text);
|
|
27
16
|
}
|
|
28
17
|
function flatten(value, prefix, out) {
|
|
29
18
|
if (Array.isArray(value)) {
|
|
@@ -25,6 +25,7 @@ const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
|
25
25
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
26
26
|
const node_path_1 = __importDefault(require("node:path"));
|
|
27
27
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
28
|
+
const registry_1 = require("../agents/registry");
|
|
28
29
|
const snapshot_diff_1 = require("./snapshot-diff");
|
|
29
30
|
const fs_1 = require("../utils/fs");
|
|
30
31
|
/**
|
|
@@ -32,21 +33,13 @@ const fs_1 = require("../utils/fs");
|
|
|
32
33
|
* 只采集关键配置文件(不复制 skills / memory 全量),默认明文保存,
|
|
33
34
|
* `--redact` 时对疑似令牌值打码。所有写入都限制在 `<root>/.agentdock` 内。
|
|
34
35
|
*/
|
|
35
|
-
/** 每个 agent 需要纳入快照的配置文件(相对用户主目录)。 */
|
|
36
|
-
const CONFIG_FILES = {
|
|
37
|
-
claude: ['.claude.json', '.claude/settings.json', '.claude/settings.local.json'],
|
|
38
|
-
codex: ['.codex/config.toml'],
|
|
39
|
-
};
|
|
40
36
|
const SECRET_KEY_PATTERN = /(token|secret|passw|api[_-]?key|auth|credential|cookie)/i;
|
|
41
37
|
const REDACTED = '***REDACTED***';
|
|
42
38
|
/** 只保留最近这么多个快照的索引条目,避免 index.json 无限增长。 */
|
|
43
39
|
const MAX_INDEX_ENTRIES = 200;
|
|
40
|
+
/** 该工具(或 `all`)需要纳入快照的配置文件,来自适配器注册表。 */
|
|
44
41
|
function configFilesFor(agent) {
|
|
45
|
-
|
|
46
|
-
return [...CONFIG_FILES.claude];
|
|
47
|
-
if (agent === 'codex')
|
|
48
|
-
return [...CONFIG_FILES.codex];
|
|
49
|
-
return [...CONFIG_FILES.claude, ...CONFIG_FILES.codex];
|
|
42
|
+
return (0, registry_1.agentConfigFiles)(agent).map((file) => file.relPath);
|
|
50
43
|
}
|
|
51
44
|
function snapshotsDir(root) {
|
|
52
45
|
return node_path_1.default.join(root, '.agentdock', 'snapshots');
|
|
@@ -61,17 +54,22 @@ function hashBuffer(data) {
|
|
|
61
54
|
return node_crypto_1.default.createHash('sha256').update(data).digest('hex');
|
|
62
55
|
}
|
|
63
56
|
function fileKind(relPath) {
|
|
57
|
+
if (relPath.endsWith('.jsonc'))
|
|
58
|
+
return 'jsonc';
|
|
64
59
|
if (relPath.endsWith('.json'))
|
|
65
60
|
return 'json';
|
|
66
61
|
if (relPath.endsWith('.toml'))
|
|
67
62
|
return 'toml';
|
|
63
|
+
if (relPath.endsWith('.yml') || relPath.endsWith('.yaml'))
|
|
64
|
+
return 'yaml';
|
|
68
65
|
return 'text';
|
|
69
66
|
}
|
|
67
|
+
/** 按行脱敏:兼容 `a = b`(TOML/INI)、`"a": "b"`(JSON/JSONC)与 `a: b`(YAML)。 */
|
|
70
68
|
function redactTextByLine(text) {
|
|
71
69
|
return text
|
|
72
70
|
.split(/\r?\n/)
|
|
73
71
|
.map((line) => {
|
|
74
|
-
const match = /^(\s*[A-Za-z0-9_.-]*(?:token|secret|passw|api[_-]?key|auth|credential)[A-Za-z0-9_.-]
|
|
72
|
+
const match = /^(\s*"?[A-Za-z0-9_.-]*(?:token|secret|passw|api[_-]?key|auth|credential)[A-Za-z0-9_.-]*"?\s*[:=]\s*).*$/i.exec(line);
|
|
75
73
|
return match ? `${match[1]}"${REDACTED}"` : line;
|
|
76
74
|
})
|
|
77
75
|
.join('\n');
|
|
@@ -118,9 +116,11 @@ function computeCounts(files) {
|
|
|
118
116
|
envKeys += Object.keys(env).length;
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
for (const key of ['mcpServers', 'mcp_servers', 'mcp']) {
|
|
120
|
+
const mcp = obj[key];
|
|
121
|
+
if (mcp && typeof mcp === 'object' && !Array.isArray(mcp)) {
|
|
122
|
+
mcpCount += Object.keys(mcp).length;
|
|
123
|
+
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
return { topLevelKeys, envKeys, mcpCount };
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.uninstallPackage = uninstallPackage;
|
|
7
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
9
|
+
const config_format_1 = require("../utils/config-format");
|
|
10
10
|
const installer_1 = require("./installer");
|
|
11
11
|
const fs_1 = require("../utils/fs");
|
|
12
12
|
function deepEqual(a, b) {
|
|
@@ -34,9 +34,13 @@ function deepEqual(a, b) {
|
|
|
34
34
|
* unmerge. Returns the keys that were removed.
|
|
35
35
|
*/
|
|
36
36
|
async function unmergeDataFile(sourcePath, toPath, mergeKeys) {
|
|
37
|
-
const parse = (filePath, content) =>
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const parse = (filePath, content) => {
|
|
38
|
+
const kind = (0, config_format_1.kindFromPath)(filePath);
|
|
39
|
+
if (kind === 'text') {
|
|
40
|
+
throw new Error(`CONFIG_FORMAT_UNSUPPORTED: ${filePath}`);
|
|
41
|
+
}
|
|
42
|
+
return (0, config_format_1.parseStructured)(kind, content);
|
|
43
|
+
};
|
|
40
44
|
let source;
|
|
41
45
|
try {
|
|
42
46
|
source = parse(sourcePath, await promises_1.default.readFile(sourcePath, 'utf8'));
|
|
@@ -81,11 +85,12 @@ async function unmergeDataFile(sourcePath, toPath, mergeKeys) {
|
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
if (removed.length > 0) {
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
const kind = (0, config_format_1.kindFromPath)(toPath);
|
|
89
|
+
if (kind === 'json' || kind === 'text') {
|
|
90
|
+
await (0, fs_1.writeJsonFile)(toPath, target);
|
|
86
91
|
}
|
|
87
92
|
else {
|
|
88
|
-
await (0, fs_1.
|
|
93
|
+
await (0, fs_1.writeTextFile)(toPath, (0, config_format_1.stringifyStructured)(kind, target));
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
return removed;
|
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|snapshot|history|recover|restore> [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',
|
|
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,7 +47,7 @@ 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
|
|
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
51
|
'snapshot.pushUsage': 'Usage: agentdock snapshot push <target-dir> [--snapshot <id>] [--force]',
|
|
52
52
|
'snapshot.pullUsage': 'Usage: agentdock snapshot pull <source-dir> [--force]',
|
|
53
53
|
'snapshot.pushed': 'Snapshot {id} exported to {dest}',
|
|
@@ -64,7 +64,15 @@ const DICTIONARIES = {
|
|
|
64
64
|
'snapshot.unchanged': 'Configuration unchanged since snapshot {id} — skipped',
|
|
65
65
|
'snapshot.listHeader': 'Snapshots ({count}) in {dir}:',
|
|
66
66
|
'snapshot.listItem': ' {id} {agent} {files} file(s){redacted}',
|
|
67
|
-
'history.usage': 'Usage: agentdock history [--agent
|
|
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.',
|
|
68
76
|
'history.header': 'Snapshot history ({count}) in {dir}:',
|
|
69
77
|
'history.entry': ' {id} {agent} {files} file(s) {summary}',
|
|
70
78
|
'history.baseline': 'baseline',
|
|
@@ -113,8 +121,8 @@ const DICTIONARIES = {
|
|
|
113
121
|
'config.unsetValue': '(unset)',
|
|
114
122
|
},
|
|
115
123
|
'zh-CN': {
|
|
116
|
-
'cli.usage': '用法:agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync|snapshot|history|recover|restore> [path]',
|
|
117
|
-
'cli.help.commands': '命令:scan、export、pack、install、verify、attest、keygen、sign、validate、doctor、report、list、diff、config、uninstall、sync、snapshot、history、recover、restore',
|
|
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',
|
|
118
126
|
'cli.help.docs': '文档:https://github.com/spsz831/AgentDock#readme',
|
|
119
127
|
'cli.version': 'agentdock {version}',
|
|
120
128
|
'pack.usage': '用法:agentdock pack --from-scan <scan.yml> --out <目录> [--zip] [--env <文件>] [--overwrite]',
|
|
@@ -150,7 +158,7 @@ const DICTIONARIES = {
|
|
|
150
158
|
'sync.statusLocalOnly': '仅本机有({count}):',
|
|
151
159
|
'sync.statusRemoteOnly': '仅 bundle 有({count}):',
|
|
152
160
|
'sync.undoSkipped': '同步后被修改过,保持不动',
|
|
153
|
-
'snapshot.usage': '用法:agentdock snapshot [create|list] [--agent
|
|
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]',
|
|
154
162
|
'snapshot.pushUsage': '用法:agentdock snapshot push <目标目录> [--snapshot <id>] [--force]',
|
|
155
163
|
'snapshot.pullUsage': '用法:agentdock snapshot pull <来源目录> [--force]',
|
|
156
164
|
'snapshot.pushed': '快照 {id} 已导出到 {dest}',
|
|
@@ -167,7 +175,15 @@ const DICTIONARIES = {
|
|
|
167
175
|
'snapshot.unchanged': '配置自快照 {id} 以来没有变化 —— 已跳过',
|
|
168
176
|
'snapshot.listHeader': '快照({count})位于 {dir}:',
|
|
169
177
|
'snapshot.listItem': ' {id} {agent} {files} 个文件{redacted}',
|
|
170
|
-
'history.usage': '用法:agentdock history [--agent
|
|
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>`。',
|
|
171
187
|
'history.header': '快照时间线({count})位于 {dir}:',
|
|
172
188
|
'history.entry': ' {id} {agent} {files} 个文件 {summary}',
|
|
173
189
|
'history.baseline': '基线',
|
|
@@ -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
|
+
}
|