agentdock-cli 1.0.1 → 1.2.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 +47 -2
- package/dist/package.json +2 -1
- package/dist/src/cli.js +42 -1
- package/dist/src/commands/diff.js +71 -0
- package/dist/src/commands/doctor.js +1 -0
- package/dist/src/commands/history.js +107 -0
- package/dist/src/commands/recover.js +180 -0
- package/dist/src/commands/restore.js +103 -0
- package/dist/src/commands/snapshot.js +154 -0
- package/dist/src/constants/command-error-codes.js +4 -0
- package/dist/src/core/attest.js +5 -92
- package/dist/src/core/doctor.js +281 -0
- package/dist/src/core/report-html.js +72 -0
- package/dist/src/core/snapshot-diff.js +122 -0
- package/dist/src/core/snapshot.js +535 -0
- package/dist/src/core/supply-chain.js +114 -0
- package/dist/src/i18n/index.js +96 -4
- package/package.json +2 -1
|
@@ -123,6 +123,62 @@ function renderShareCard(report) {
|
|
|
123
123
|
<p class="share-card-note">仅含评分与数量,不含路径、变量名与配置内容。由 AgentDock 生成。</p>
|
|
124
124
|
</section>`;
|
|
125
125
|
}
|
|
126
|
+
function renderNextSteps(report) {
|
|
127
|
+
// 按体检模式给出可复制的下一步命令:live → 先 scan 再打包;scan → 打包;
|
|
128
|
+
// package → 审计 + 安装。全部本地执行,不联网、不上传。
|
|
129
|
+
const steps = [];
|
|
130
|
+
if (report.mode === 'package') {
|
|
131
|
+
steps.push({
|
|
132
|
+
title: '审计安装包',
|
|
133
|
+
detail: '检查完整性、签名与供应链风险,确认无泄露后再安装。',
|
|
134
|
+
command: `agentdock verify ${'<包目录>'} --strict`,
|
|
135
|
+
}, {
|
|
136
|
+
title: '安装到目标机',
|
|
137
|
+
detail: '按 .env.example 填好真实值后安装;冲突项默认跳过。',
|
|
138
|
+
command: `agentdock install ${'<包目录>'} ${'<目标目录>'}`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (report.mode === 'scan') {
|
|
142
|
+
steps.push({
|
|
143
|
+
title: '生成可分发安装包',
|
|
144
|
+
detail: '令牌自动打码为占位符,真实值留在本机 .env。',
|
|
145
|
+
command: `agentdock pack --from-scan ${'<扫描目录>/agentdock.scan.yml'} --out ${'<包目录>'} --zip`,
|
|
146
|
+
}, {
|
|
147
|
+
title: '审计安装包',
|
|
148
|
+
detail: '确认没有明文令牌、完整性校验通过。',
|
|
149
|
+
command: `agentdock doctor --package ${'<包目录>'}`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
steps.push({
|
|
154
|
+
title: '扫描当前环境',
|
|
155
|
+
detail: '生成迁移清单,并隔离配置中的密钥。',
|
|
156
|
+
command: 'agentdock scan --agent all --out ./agentdock-scan',
|
|
157
|
+
}, {
|
|
158
|
+
title: '打包并打码',
|
|
159
|
+
detail: '把 scan 产物打成安装包,令牌替换为占位符。',
|
|
160
|
+
command: `agentdock pack --from-scan ./agentdock-scan/agentdock.scan.yml --out ./agentdock-package --zip`,
|
|
161
|
+
}, {
|
|
162
|
+
title: '在目标机还原',
|
|
163
|
+
detail: '先填 .env,再安装;可加 --dry-run 预览。',
|
|
164
|
+
command: `agentdock install ./agentdock-package ${'<目标目录>'}`,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const items = steps
|
|
168
|
+
.map((step, index) => `
|
|
169
|
+
<li class="step">
|
|
170
|
+
<div class="step-head"><span class="step-index">${index + 1}</span><span class="step-title">${escapeHtml(step.title)}</span></div>
|
|
171
|
+
<p class="step-detail">${escapeHtml(step.detail)}</p>
|
|
172
|
+
<code class="step-command">${escapeHtml(step.command)}</code>
|
|
173
|
+
</li>`)
|
|
174
|
+
.join('');
|
|
175
|
+
return `
|
|
176
|
+
<section class="card">
|
|
177
|
+
<h2>下一步</h2>
|
|
178
|
+
<ol class="steps">${items}</ol>
|
|
179
|
+
<p class="muted">所有命令均在本机执行,不联网、不上传配置。完整用法见 <code>agentdock --help</code>。</p>
|
|
180
|
+
</section>`;
|
|
181
|
+
}
|
|
126
182
|
const STYLES = `
|
|
127
183
|
:root {
|
|
128
184
|
color-scheme: light;
|
|
@@ -243,6 +299,20 @@ const STYLES = `
|
|
|
243
299
|
.share-stat-label { font-size: 12px; color: var(--muted); }
|
|
244
300
|
.share-card-note { margin: 18px 0 0; font-size: 12px; color: var(--muted); }
|
|
245
301
|
.muted { color: var(--muted); font-size: 14px; }
|
|
302
|
+
.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
|
|
303
|
+
.step { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: #fafbff; }
|
|
304
|
+
.step-head { display: flex; align-items: center; gap: 10px; }
|
|
305
|
+
.step-index {
|
|
306
|
+
width: 22px; height: 22px; border-radius: 999px; background: var(--accent); color: #fff;
|
|
307
|
+
display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
|
|
308
|
+
}
|
|
309
|
+
.step-title { font-weight: 600; font-size: 14px; }
|
|
310
|
+
.step-detail { margin: 6px 0 8px; color: var(--muted); font-size: 13px; }
|
|
311
|
+
.step-command {
|
|
312
|
+
display: block; background: #101828; color: #e6e9f0; border-radius: 8px;
|
|
313
|
+
padding: 9px 12px; font-size: 12px; word-break: break-all;
|
|
314
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
315
|
+
}
|
|
246
316
|
@media (max-width: 640px) {
|
|
247
317
|
.hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
|
|
248
318
|
.stat-line { justify-content: center; }
|
|
@@ -303,6 +373,8 @@ function renderReportHtml(report) {
|
|
|
303
373
|
${renderRemediation(report)}
|
|
304
374
|
</section>
|
|
305
375
|
|
|
376
|
+
${renderNextSteps(report)}
|
|
377
|
+
|
|
306
378
|
${renderShareCard(report)}
|
|
307
379
|
</div>
|
|
308
380
|
</body>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseConfigObject = parseConfigObject;
|
|
4
|
+
exports.buildSnapshotDiff = buildSnapshotDiff;
|
|
5
|
+
const smol_toml_1 = require("smol-toml");
|
|
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
|
+
try {
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
function flatten(value, prefix, out) {
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
if (value.length === 0) {
|
|
31
|
+
out.set(prefix, []);
|
|
32
|
+
}
|
|
33
|
+
value.forEach((item, index) => flatten(item, `${prefix}[${index}]`, out));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (value !== null && typeof value === 'object') {
|
|
37
|
+
const keys = Object.keys(value);
|
|
38
|
+
if (keys.length === 0) {
|
|
39
|
+
out.set(prefix, {});
|
|
40
|
+
}
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
const child = value[key];
|
|
43
|
+
flatten(child, prefix ? `${prefix}.${key}` : key, out);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
out.set(prefix, value);
|
|
48
|
+
}
|
|
49
|
+
function mask(text) {
|
|
50
|
+
if (text.length <= 8) {
|
|
51
|
+
return '****';
|
|
52
|
+
}
|
|
53
|
+
return `${text.slice(0, 4)}****${text.slice(-4)}`;
|
|
54
|
+
}
|
|
55
|
+
function renderValue(pathKey, value) {
|
|
56
|
+
const text = typeof value === 'string' ? value : (JSON.stringify(value) ?? String(value));
|
|
57
|
+
if (SENSITIVE_PATH.test(pathKey)) {
|
|
58
|
+
return mask(text);
|
|
59
|
+
}
|
|
60
|
+
return text.length > MAX_VALUE_LENGTH ? `${text.slice(0, MAX_VALUE_LENGTH - 3)}...` : text;
|
|
61
|
+
}
|
|
62
|
+
function buildSnapshotDiff(params) {
|
|
63
|
+
const changes = [];
|
|
64
|
+
for (const relPath of [...params.files].sort()) {
|
|
65
|
+
const beforeText = params.before.get(relPath)?.toString('utf8');
|
|
66
|
+
const afterText = params.after.get(relPath)?.toString('utf8');
|
|
67
|
+
const beforeObj = beforeText === undefined ? undefined : parseConfigObject(relPath, beforeText);
|
|
68
|
+
const afterObj = afterText === undefined ? undefined : parseConfigObject(relPath, afterText);
|
|
69
|
+
if ((beforeText !== undefined && beforeObj === null) || (afterText !== undefined && afterObj === null)) {
|
|
70
|
+
if (beforeText !== afterText) {
|
|
71
|
+
changes.push({
|
|
72
|
+
path: relPath,
|
|
73
|
+
change: beforeText === undefined ? 'added' : afterText === undefined ? 'removed' : 'modified',
|
|
74
|
+
note: '配置解析失败,按整文件比较',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const flatBefore = new Map();
|
|
80
|
+
const flatAfter = new Map();
|
|
81
|
+
if (beforeObj !== undefined) {
|
|
82
|
+
flatten(beforeObj, '', flatBefore);
|
|
83
|
+
}
|
|
84
|
+
if (afterObj !== undefined) {
|
|
85
|
+
flatten(afterObj, '', flatAfter);
|
|
86
|
+
}
|
|
87
|
+
const keys = [...new Set([...flatBefore.keys(), ...flatAfter.keys()])].sort();
|
|
88
|
+
for (const key of keys) {
|
|
89
|
+
const hasBefore = flatBefore.has(key);
|
|
90
|
+
const hasAfter = flatAfter.has(key);
|
|
91
|
+
const pathKey = key ? `${relPath}#${key}` : relPath;
|
|
92
|
+
if (hasBefore && !hasAfter) {
|
|
93
|
+
changes.push({ path: pathKey, change: 'removed', before: renderValue(key, flatBefore.get(key)) });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!hasBefore && hasAfter) {
|
|
97
|
+
changes.push({ path: pathKey, change: 'added', after: renderValue(key, flatAfter.get(key)) });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const beforeValue = flatBefore.get(key);
|
|
101
|
+
const afterValue = flatAfter.get(key);
|
|
102
|
+
if (JSON.stringify(beforeValue) !== JSON.stringify(afterValue)) {
|
|
103
|
+
changes.push({
|
|
104
|
+
path: pathKey,
|
|
105
|
+
change: 'modified',
|
|
106
|
+
before: renderValue(key, beforeValue),
|
|
107
|
+
after: renderValue(key, afterValue),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const added = changes.filter((item) => item.change === 'added').length;
|
|
113
|
+
const removed = changes.filter((item) => item.change === 'removed').length;
|
|
114
|
+
const modified = changes.filter((item) => item.change === 'modified').length;
|
|
115
|
+
return {
|
|
116
|
+
from: params.from,
|
|
117
|
+
to: params.to,
|
|
118
|
+
files: [...params.files].sort(),
|
|
119
|
+
changes,
|
|
120
|
+
summary: `${added} 新增 / ${removed} 删除 / ${modified} 修改`,
|
|
121
|
+
};
|
|
122
|
+
}
|