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/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
|
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseConfigObject = parseConfigObject;
|
|
4
|
+
exports.buildSnapshotDiff = buildSnapshotDiff;
|
|
5
|
+
const config_format_1 = require("../utils/config-format");
|
|
6
|
+
/**
|
|
7
|
+
* 快照比对(v1.2)。
|
|
8
|
+
* 按 JSON / TOML 路径展开后逐键比较,值统一脱敏且截断,
|
|
9
|
+
* 避免把令牌原文打印到终端或 CI 日志。
|
|
10
|
+
*/
|
|
11
|
+
const SENSITIVE_PATH = /(token|secret|passw|api[_-]?key|auth|credential|cookie)/i;
|
|
12
|
+
const MAX_VALUE_LENGTH = 120;
|
|
13
|
+
/** 解析配置文件为对象;解析失败或非结构化格式返回 null。 */
|
|
14
|
+
function parseConfigObject(relPath, text) {
|
|
15
|
+
return (0, config_format_1.parseConfigObjectSafe)(relPath, text);
|
|
16
|
+
}
|
|
17
|
+
function flatten(value, prefix, out) {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
if (value.length === 0) {
|
|
20
|
+
out.set(prefix, []);
|
|
21
|
+
}
|
|
22
|
+
value.forEach((item, index) => flatten(item, `${prefix}[${index}]`, out));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (value !== null && typeof value === 'object') {
|
|
26
|
+
const keys = Object.keys(value);
|
|
27
|
+
if (keys.length === 0) {
|
|
28
|
+
out.set(prefix, {});
|
|
29
|
+
}
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
const child = value[key];
|
|
32
|
+
flatten(child, prefix ? `${prefix}.${key}` : key, out);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
out.set(prefix, value);
|
|
37
|
+
}
|
|
38
|
+
function mask(text) {
|
|
39
|
+
if (text.length <= 8) {
|
|
40
|
+
return '****';
|
|
41
|
+
}
|
|
42
|
+
return `${text.slice(0, 4)}****${text.slice(-4)}`;
|
|
43
|
+
}
|
|
44
|
+
function renderValue(pathKey, value) {
|
|
45
|
+
const text = typeof value === 'string' ? value : (JSON.stringify(value) ?? String(value));
|
|
46
|
+
if (SENSITIVE_PATH.test(pathKey)) {
|
|
47
|
+
return mask(text);
|
|
48
|
+
}
|
|
49
|
+
return text.length > MAX_VALUE_LENGTH ? `${text.slice(0, MAX_VALUE_LENGTH - 3)}...` : text;
|
|
50
|
+
}
|
|
51
|
+
function buildSnapshotDiff(params) {
|
|
52
|
+
const changes = [];
|
|
53
|
+
for (const relPath of [...params.files].sort()) {
|
|
54
|
+
const beforeText = params.before.get(relPath)?.toString('utf8');
|
|
55
|
+
const afterText = params.after.get(relPath)?.toString('utf8');
|
|
56
|
+
const beforeObj = beforeText === undefined ? undefined : parseConfigObject(relPath, beforeText);
|
|
57
|
+
const afterObj = afterText === undefined ? undefined : parseConfigObject(relPath, afterText);
|
|
58
|
+
if ((beforeText !== undefined && beforeObj === null) || (afterText !== undefined && afterObj === null)) {
|
|
59
|
+
if (beforeText !== afterText) {
|
|
60
|
+
changes.push({
|
|
61
|
+
path: relPath,
|
|
62
|
+
change: beforeText === undefined ? 'added' : afterText === undefined ? 'removed' : 'modified',
|
|
63
|
+
note: '配置解析失败,按整文件比较',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const flatBefore = new Map();
|
|
69
|
+
const flatAfter = new Map();
|
|
70
|
+
if (beforeObj !== undefined) {
|
|
71
|
+
flatten(beforeObj, '', flatBefore);
|
|
72
|
+
}
|
|
73
|
+
if (afterObj !== undefined) {
|
|
74
|
+
flatten(afterObj, '', flatAfter);
|
|
75
|
+
}
|
|
76
|
+
const keys = [...new Set([...flatBefore.keys(), ...flatAfter.keys()])].sort();
|
|
77
|
+
for (const key of keys) {
|
|
78
|
+
const hasBefore = flatBefore.has(key);
|
|
79
|
+
const hasAfter = flatAfter.has(key);
|
|
80
|
+
const pathKey = key ? `${relPath}#${key}` : relPath;
|
|
81
|
+
if (hasBefore && !hasAfter) {
|
|
82
|
+
changes.push({ path: pathKey, change: 'removed', before: renderValue(key, flatBefore.get(key)) });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!hasBefore && hasAfter) {
|
|
86
|
+
changes.push({ path: pathKey, change: 'added', after: renderValue(key, flatAfter.get(key)) });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const beforeValue = flatBefore.get(key);
|
|
90
|
+
const afterValue = flatAfter.get(key);
|
|
91
|
+
if (JSON.stringify(beforeValue) !== JSON.stringify(afterValue)) {
|
|
92
|
+
changes.push({
|
|
93
|
+
path: pathKey,
|
|
94
|
+
change: 'modified',
|
|
95
|
+
before: renderValue(key, beforeValue),
|
|
96
|
+
after: renderValue(key, afterValue),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const added = changes.filter((item) => item.change === 'added').length;
|
|
102
|
+
const removed = changes.filter((item) => item.change === 'removed').length;
|
|
103
|
+
const modified = changes.filter((item) => item.change === 'modified').length;
|
|
104
|
+
return {
|
|
105
|
+
from: params.from,
|
|
106
|
+
to: params.to,
|
|
107
|
+
files: [...params.files].sort(),
|
|
108
|
+
changes,
|
|
109
|
+
summary: `${added} 新增 / ${removed} 删除 / ${modified} 修改`,
|
|
110
|
+
};
|
|
111
|
+
}
|