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
|
@@ -3,10 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.planInstall = planInstall;
|
|
6
7
|
exports.installPackage = installPackage;
|
|
7
8
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const smol_toml_1 = require("smol-toml");
|
|
9
11
|
const fs_1 = require("../utils/fs");
|
|
12
|
+
/** Parse a data file by its extension (TOML or JSON). */
|
|
13
|
+
function parseByExt(filePath, content) {
|
|
14
|
+
return node_path_1.default.extname(filePath).toLowerCase() === '.toml' ? (0, smol_toml_1.parse)(content) : JSON.parse(content);
|
|
15
|
+
}
|
|
10
16
|
async function isIdenticalFile(targetPath, sourcePath) {
|
|
11
17
|
try {
|
|
12
18
|
const [targetBuf, sourceBuf] = await Promise.all([
|
|
@@ -72,21 +78,67 @@ function deepMerge(target, source) {
|
|
|
72
78
|
}
|
|
73
79
|
return out;
|
|
74
80
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
/** Deep-merge only `keys` from `source` into `target`; other target keys are left untouched. */
|
|
82
|
+
function mergeOnlyKeys(target, source, keys) {
|
|
83
|
+
const out = { ...target };
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
out[key] = deepMerge(out[key], source[key]);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Deep-merge a package payload into a target file, preserving the target's
|
|
91
|
+
* own file format (JSON or TOML). Used so a merged `.claude.json` (JSON) or
|
|
92
|
+
* Codex `.codex/config.toml` (TOML) keeps the target's other keys while the
|
|
93
|
+
* package's keys win. Never clobbers the target file format.
|
|
94
|
+
*
|
|
95
|
+
* When `mergeKeys` is given, only those top-level keys are merged (the rest
|
|
96
|
+
* of the target is preserved). On a *fresh* target (file absent) the whole
|
|
97
|
+
* payload is restored regardless, so a first install still carries the full
|
|
98
|
+
* configuration.
|
|
99
|
+
*/
|
|
100
|
+
async function mergeDataFile(from, to, mergeKeys) {
|
|
101
|
+
let source = {};
|
|
102
|
+
try {
|
|
103
|
+
source = parseByExt(from, await promises_1.default.readFile(from, 'utf8'));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
source = {};
|
|
107
|
+
}
|
|
108
|
+
// Fresh target: restore the entire payload (in the target's format).
|
|
109
|
+
if (!(await (0, fs_1.pathExists)(to))) {
|
|
110
|
+
if (node_path_1.default.extname(to).toLowerCase() === '.toml') {
|
|
111
|
+
await (0, fs_1.writeTextFile)(to, (0, smol_toml_1.stringify)(source));
|
|
81
112
|
}
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
else {
|
|
114
|
+
await (0, fs_1.writeJsonFile)(to, source);
|
|
84
115
|
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
let target = {};
|
|
119
|
+
try {
|
|
120
|
+
target = parseByExt(to, await promises_1.default.readFile(to, 'utf8'));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
target = {};
|
|
124
|
+
}
|
|
125
|
+
const merged = mergeKeys && mergeKeys.length > 0
|
|
126
|
+
? mergeOnlyKeys(target, source, mergeKeys)
|
|
127
|
+
: deepMerge(target, source);
|
|
128
|
+
if (node_path_1.default.extname(to).toLowerCase() === '.toml') {
|
|
129
|
+
await (0, fs_1.writeTextFile)(to, (0, smol_toml_1.stringify)(merged));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
await (0, fs_1.writeJsonFile)(to, merged);
|
|
85
133
|
}
|
|
86
|
-
const merged = deepMerge(target, source);
|
|
87
|
-
await (0, fs_1.writeJsonFile)(to, merged);
|
|
88
134
|
}
|
|
89
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Produce a read-only preview of what `install` would do for a package
|
|
137
|
+
* against a target path — without writing anything. Boundary checks
|
|
138
|
+
* (`safeResolveWithin`) still run so path-traversal issues surface here.
|
|
139
|
+
* Shared by `install --dry-run` and the `diff` command.
|
|
140
|
+
*/
|
|
141
|
+
async function planInstall(packagePath, explicitTargetPath, overwrite = false) {
|
|
90
142
|
const packageRoot = node_path_1.default.resolve(packagePath);
|
|
91
143
|
const manifestSnapshotPath = node_path_1.default.join(packageRoot, 'manifest.resolved.json');
|
|
92
144
|
const installPlanPath = node_path_1.default.join(packageRoot, 'meta', 'install-plan.json');
|
|
@@ -98,60 +150,115 @@ async function installPackage(packagePath, explicitTargetPath, overwrite = false
|
|
|
98
150
|
}
|
|
99
151
|
const installPlan = await (0, fs_1.readJsonFile)(installPlanPath);
|
|
100
152
|
const effectiveOverwrite = overwrite || installPlan.overwrite === true;
|
|
101
|
-
// The target may live anywhere the user chooses (e.g. ~/.claude); only individual
|
|
102
|
-
// entries must stay within it. No boundary check against packageRoot here.
|
|
103
153
|
const targetRoot = node_path_1.default.resolve(explicitTargetPath ?? installPlan.targetPath ?? './installed');
|
|
104
|
-
|
|
105
|
-
// both the destination `to` and the source `from` fields of a malicious package).
|
|
106
|
-
const entries = [
|
|
154
|
+
const rawEntries = [
|
|
107
155
|
...installPlan.sources.map((source) => ({
|
|
108
156
|
from: (0, fs_1.safeResolveWithin)(packageRoot, source.from, 'source.from'),
|
|
109
157
|
to: (0, fs_1.safeResolveWithin)(targetRoot, source.to, 'source.to'),
|
|
110
158
|
kind: source.kind,
|
|
111
159
|
merge: source.merge ?? false,
|
|
160
|
+
mergeKeys: source.mergeKeys,
|
|
112
161
|
})),
|
|
113
162
|
...installPlan.templates.map((template) => ({
|
|
114
163
|
from: (0, fs_1.safeResolveWithin)(packageRoot, template.from, 'template.from'),
|
|
115
164
|
to: (0, fs_1.safeResolveWithin)(targetRoot, template.to, 'template.to'),
|
|
116
165
|
kind: 'template',
|
|
166
|
+
merge: false,
|
|
117
167
|
})),
|
|
118
168
|
];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
169
|
+
const entries = [];
|
|
170
|
+
for (const entry of rawEntries) {
|
|
171
|
+
const exists = await (0, fs_1.pathExists)(entry.to);
|
|
172
|
+
let identical = false;
|
|
173
|
+
if (exists) {
|
|
174
|
+
identical = entry.kind === 'directory'
|
|
175
|
+
? await isIdenticalDirectory(entry.to, entry.from)
|
|
176
|
+
: await isIdenticalFile(entry.to, entry.from);
|
|
177
|
+
}
|
|
178
|
+
let action;
|
|
179
|
+
let note;
|
|
180
|
+
if (entry.merge) {
|
|
181
|
+
action = 'merge';
|
|
182
|
+
note = exists ? await describeMerge(entry.from, entry.to, entry.mergeKeys) : 'merge: target missing (will create)';
|
|
183
|
+
}
|
|
184
|
+
else if (!exists) {
|
|
185
|
+
action = 'create';
|
|
186
|
+
}
|
|
187
|
+
else if (identical) {
|
|
188
|
+
action = 'skip';
|
|
189
|
+
}
|
|
190
|
+
else if (effectiveOverwrite) {
|
|
191
|
+
action = 'overwrite';
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
action = 'conflict';
|
|
195
|
+
}
|
|
196
|
+
entries.push({ ...entry, merge: entry.merge ?? false, mergeKeys: entry.mergeKeys, exists, identical, action, note });
|
|
197
|
+
}
|
|
198
|
+
const conflicts = entries.filter((entry) => entry.action === 'conflict');
|
|
199
|
+
return { targetPath: targetRoot, entries, conflicts };
|
|
200
|
+
}
|
|
201
|
+
/** Human-readable summary of what a merge entry would add to the target file. */
|
|
202
|
+
async function describeMerge(sourcePath, targetPath, mergeKeys) {
|
|
123
203
|
try {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
204
|
+
const source = parseByExt(sourcePath, await promises_1.default.readFile(sourcePath, 'utf8'));
|
|
205
|
+
const targetExists = await (0, fs_1.pathExists)(targetPath);
|
|
206
|
+
const target = targetExists
|
|
207
|
+
? parseByExt(targetPath, await promises_1.default.readFile(targetPath, 'utf8'))
|
|
208
|
+
: {};
|
|
209
|
+
// TOML config.toml uses `mcp_servers`; JSON .claude.json uses `mcpServers`.
|
|
210
|
+
const mcpKey = node_path_1.default.extname(sourcePath).toLowerCase() === '.toml' ? 'mcp_servers' : 'mcpServers';
|
|
211
|
+
const focusKey = mergeKeys && mergeKeys.length > 0
|
|
212
|
+
? (mergeKeys.find((k) => k === mcpKey) ?? mergeKeys[0])
|
|
213
|
+
: mcpKey;
|
|
214
|
+
const sourceServers = source[focusKey];
|
|
215
|
+
const targetServers = target[focusKey];
|
|
216
|
+
if (sourceServers && targetServers && typeof sourceServers === 'object') {
|
|
217
|
+
const added = Object.keys(sourceServers).filter((key) => !(key in targetServers));
|
|
218
|
+
if (added.length > 0) {
|
|
219
|
+
return `merge: adds ${focusKey} [${added.join(', ')}]`;
|
|
141
220
|
}
|
|
142
|
-
|
|
143
|
-
|
|
221
|
+
}
|
|
222
|
+
if (mergeKeys && mergeKeys.length > 0) {
|
|
223
|
+
const addedKeys = mergeKeys.filter((key) => !(key in target));
|
|
224
|
+
if (addedKeys.length > 0) {
|
|
225
|
+
return `merge: adds keys [${addedKeys.join(', ')}]`;
|
|
144
226
|
}
|
|
145
|
-
|
|
227
|
+
return `merge: no new keys in [${mergeKeys.join(', ')}]`;
|
|
146
228
|
}
|
|
147
|
-
|
|
148
|
-
|
|
229
|
+
const addedKeys = Object.keys(source).filter((key) => !(key in target));
|
|
230
|
+
if (addedKeys.length > 0) {
|
|
231
|
+
return `merge: adds keys [${addedKeys.join(', ')}]`;
|
|
149
232
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
233
|
+
return 'merge: no new top-level keys';
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return 'merge: deep-merge into existing';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function installPackage(packagePath, explicitTargetPath, overwrite = false, dryRun = false) {
|
|
240
|
+
const plan = await planInstall(packagePath, explicitTargetPath, overwrite);
|
|
241
|
+
// Dry-run: validate + preview only, never touch the target.
|
|
242
|
+
if (dryRun) {
|
|
243
|
+
return { targetPath: plan.targetPath, plan };
|
|
244
|
+
}
|
|
245
|
+
// Create the target root up front so the lock file parent exists.
|
|
246
|
+
await (0, fs_1.ensureDirectory)(plan.targetPath);
|
|
247
|
+
const lockPath = node_path_1.default.join(plan.targetPath, '.agentdock.lock');
|
|
248
|
+
const lockHandle = await (0, fs_1.acquireLock)(lockPath);
|
|
249
|
+
try {
|
|
250
|
+
if (plan.conflicts.length > 0) {
|
|
251
|
+
throw new Error(`Install conflict detected:\n${plan.conflicts.map((entry) => entry.to).join('\n')}`);
|
|
252
|
+
}
|
|
253
|
+
for (const entry of plan.entries) {
|
|
254
|
+
// Idempotent no-op: an existing entry identical to the source is skipped.
|
|
255
|
+
if (entry.action === 'skip') {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (entry.action === 'merge') {
|
|
259
|
+
// Deep-merge the payload into the existing target (preserving other
|
|
260
|
+
// top-level keys / other mcpServers or mcp_servers). Never clobbers it.
|
|
261
|
+
await mergeDataFile(entry.from, entry.to, entry.mergeKeys);
|
|
155
262
|
continue;
|
|
156
263
|
}
|
|
157
264
|
if (entry.kind === 'directory') {
|
|
@@ -161,7 +268,7 @@ async function installPackage(packagePath, explicitTargetPath, overwrite = false
|
|
|
161
268
|
await (0, fs_1.copyFileSafe)(entry.from, entry.to);
|
|
162
269
|
}
|
|
163
270
|
}
|
|
164
|
-
return { targetPath:
|
|
271
|
+
return { targetPath: plan.targetPath, plan };
|
|
165
272
|
}
|
|
166
273
|
finally {
|
|
167
274
|
await (0, fs_1.releaseLock)(lockHandle, lockPath);
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderReportHtml = renderReportHtml;
|
|
4
|
+
function escapeHtml(value) {
|
|
5
|
+
return value
|
|
6
|
+
.replace(/&/g, '&')
|
|
7
|
+
.replace(/</g, '<')
|
|
8
|
+
.replace(/>/g, '>')
|
|
9
|
+
.replace(/"/g, '"')
|
|
10
|
+
.replace(/'/g, ''');
|
|
11
|
+
}
|
|
12
|
+
function statusLabel(status) {
|
|
13
|
+
return status === 'pass' ? 'PASS' : status === 'warn' ? 'WARN' : 'FAIL';
|
|
14
|
+
}
|
|
15
|
+
function statusColor(status) {
|
|
16
|
+
return status === 'pass' ? '#12b76a' : status === 'warn' ? '#f79009' : '#f04438';
|
|
17
|
+
}
|
|
18
|
+
function gradeClass(grade) {
|
|
19
|
+
return `grade-${grade.toLowerCase()}`;
|
|
20
|
+
}
|
|
21
|
+
function renderGauge(report) {
|
|
22
|
+
const radius = 58;
|
|
23
|
+
const circumference = 2 * Math.PI * radius;
|
|
24
|
+
const offset = circumference * (1 - report.score / 100);
|
|
25
|
+
return `
|
|
26
|
+
<div class="gauge">
|
|
27
|
+
<svg viewBox="0 0 140 140" class="gauge-svg" role="img" aria-label="环境健康度 ${report.score} 分">
|
|
28
|
+
<circle class="gauge-track" cx="70" cy="70" r="${radius}" />
|
|
29
|
+
<circle class="gauge-value ${gradeClass(report.grade)}" cx="70" cy="70" r="${radius}"
|
|
30
|
+
stroke-dasharray="${circumference.toFixed(2)}" stroke-dashoffset="${offset.toFixed(2)}" />
|
|
31
|
+
</svg>
|
|
32
|
+
<div class="gauge-center">
|
|
33
|
+
<span class="gauge-score">${report.score}</span>
|
|
34
|
+
<span class="gauge-unit">/ 100</span>
|
|
35
|
+
</div>
|
|
36
|
+
</div>`;
|
|
37
|
+
}
|
|
38
|
+
function renderInventory(report) {
|
|
39
|
+
if (report.inventory.agents.length === 0) {
|
|
40
|
+
return '<p class="muted">未捕获到可迁移定义。</p>';
|
|
41
|
+
}
|
|
42
|
+
const rows = report.inventory.agents
|
|
43
|
+
.map((item) => `
|
|
44
|
+
<tr>
|
|
45
|
+
<td><strong>${item.agent === 'claude' ? 'Claude Code' : 'Codex'}</strong></td>
|
|
46
|
+
<td>${item.mcp}</td>
|
|
47
|
+
<td>${item.skills}</td>
|
|
48
|
+
<td>${item.agents}</td>
|
|
49
|
+
<td>${item.plugins}</td>
|
|
50
|
+
<td>${item.hooks}</td>
|
|
51
|
+
<td>${item.memory}</td>
|
|
52
|
+
<td>${item.settings}</td>
|
|
53
|
+
<td><strong>${item.total}</strong></td>
|
|
54
|
+
</tr>`)
|
|
55
|
+
.join('');
|
|
56
|
+
return `
|
|
57
|
+
<table class="inventory">
|
|
58
|
+
<thead>
|
|
59
|
+
<tr>
|
|
60
|
+
<th>助手</th><th>MCP</th><th>Skill</th><th>Agent</th><th>Plugin</th>
|
|
61
|
+
<th>Hook</th><th>记忆</th><th>Settings</th><th>合计</th>
|
|
62
|
+
</tr>
|
|
63
|
+
</thead>
|
|
64
|
+
<tbody>${rows}</tbody>
|
|
65
|
+
</table>
|
|
66
|
+
<p class="inventory-total">共 <strong>${report.inventory.totalEntries}</strong> 项可迁移定义,隔离 <strong>${report.inventory.secretsCount}</strong> 个机密。</p>`;
|
|
67
|
+
}
|
|
68
|
+
function renderFinding(check, finding) {
|
|
69
|
+
const path = finding.path ? ` <code>${escapeHtml(finding.path)}</code>` : '';
|
|
70
|
+
return `<li class="finding finding--${finding.severity}"><span class="dot" style="background:${statusColor(check.status)}"></span>${escapeHtml(finding.message)}${path}</li>`;
|
|
71
|
+
}
|
|
72
|
+
function renderCheck(check) {
|
|
73
|
+
const findings = check.findings.length
|
|
74
|
+
? `<ul class="findings">${check.findings.map((finding) => renderFinding(check, finding)).join('')}</ul>`
|
|
75
|
+
: '';
|
|
76
|
+
const remediation = check.remediation && check.status !== 'pass'
|
|
77
|
+
? `<div class="remediation"><span class="remediation-label">建议</span>${escapeHtml(check.remediation)}</div>`
|
|
78
|
+
: '';
|
|
79
|
+
return `
|
|
80
|
+
<article class="check check--${check.status}">
|
|
81
|
+
<div class="check-head">
|
|
82
|
+
<span class="badge badge--${check.status}">${statusLabel(check.status)}</span>
|
|
83
|
+
<h3>${escapeHtml(check.label)}</h3>
|
|
84
|
+
</div>
|
|
85
|
+
<p class="check-detail">${escapeHtml(check.detail)}</p>
|
|
86
|
+
${findings}
|
|
87
|
+
${remediation}
|
|
88
|
+
</article>`;
|
|
89
|
+
}
|
|
90
|
+
function renderRemediation(report) {
|
|
91
|
+
const actionable = report.checks.filter((check) => check.remediation && check.status !== 'pass');
|
|
92
|
+
if (actionable.length === 0) {
|
|
93
|
+
return '<p class="muted">未发现需要处理的问题。</p>';
|
|
94
|
+
}
|
|
95
|
+
const items = actionable
|
|
96
|
+
.map((check) => `
|
|
97
|
+
<li>
|
|
98
|
+
<div class="todo-head"><span class="badge badge--${check.status}">${statusLabel(check.status)}</span> ${escapeHtml(check.label)}</div>
|
|
99
|
+
<p>${escapeHtml(check.remediation)}</p>
|
|
100
|
+
</li>`)
|
|
101
|
+
.join('');
|
|
102
|
+
return `<ol class="todo-list">${items}</ol>`;
|
|
103
|
+
}
|
|
104
|
+
function renderShareCard(report) {
|
|
105
|
+
const pass = report.checks.filter((check) => check.status === 'pass').length;
|
|
106
|
+
const warn = report.checks.filter((check) => check.status === 'warn').length;
|
|
107
|
+
const fail = report.checks.filter((check) => check.status === 'fail').length;
|
|
108
|
+
return `
|
|
109
|
+
<section class="share-card">
|
|
110
|
+
<div class="share-card-head">
|
|
111
|
+
<div>
|
|
112
|
+
<div class="share-card-kicker">可安全分享的摘要 · 已脱敏</div>
|
|
113
|
+
<div class="share-card-title">AgentDock 环境健康度</div>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="share-grade ${gradeClass(report.grade)}">${report.grade}</div>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="share-score">${report.score}<span> / 100</span></div>
|
|
118
|
+
<div class="share-stats">
|
|
119
|
+
<div class="share-stat"><span class="share-stat-value">${report.inventory.totalEntries}</span><span class="share-stat-label">可迁移定义</span></div>
|
|
120
|
+
<div class="share-stat"><span class="share-stat-value">${report.inventory.secretsCount}</span><span class="share-stat-label">隔离机密</span></div>
|
|
121
|
+
<div class="share-stat"><span class="share-stat-value">${pass} / ${warn} / ${fail}</span><span class="share-stat-label">通过 / 警告 / 失败</span></div>
|
|
122
|
+
</div>
|
|
123
|
+
<p class="share-card-note">仅含评分与数量,不含路径、变量名与配置内容。由 AgentDock 生成。</p>
|
|
124
|
+
</section>`;
|
|
125
|
+
}
|
|
126
|
+
const STYLES = `
|
|
127
|
+
:root {
|
|
128
|
+
color-scheme: light;
|
|
129
|
+
--bg: #f4f6fb;
|
|
130
|
+
--card: #ffffff;
|
|
131
|
+
--ink: #101828;
|
|
132
|
+
--muted: #667085;
|
|
133
|
+
--border: #e6e9f0;
|
|
134
|
+
--accent: #4f46e5;
|
|
135
|
+
--pass: #12b76a;
|
|
136
|
+
--warn: #f79009;
|
|
137
|
+
--fail: #f04438;
|
|
138
|
+
}
|
|
139
|
+
* { box-sizing: border-box; }
|
|
140
|
+
body {
|
|
141
|
+
margin: 0;
|
|
142
|
+
background: var(--bg);
|
|
143
|
+
color: var(--ink);
|
|
144
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
|
145
|
+
line-height: 1.6;
|
|
146
|
+
}
|
|
147
|
+
.page { max-width: 980px; margin: 0 auto; padding: 40px 20px 64px; }
|
|
148
|
+
header { margin-bottom: 24px; }
|
|
149
|
+
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
|
|
150
|
+
.brand-mark {
|
|
151
|
+
width: 30px; height: 30px; border-radius: 9px;
|
|
152
|
+
background: linear-gradient(135deg, #6366f1, #22d3ee);
|
|
153
|
+
}
|
|
154
|
+
.meta { color: var(--muted); font-size: 13px; margin-top: 8px; word-break: break-all; }
|
|
155
|
+
.profile-note {
|
|
156
|
+
margin-top: 12px; padding: 12px 14px; border-radius: 10px;
|
|
157
|
+
background: #fffaeb; border: 1px solid #fedf89; color: #93370d; font-size: 13px;
|
|
158
|
+
}
|
|
159
|
+
.card {
|
|
160
|
+
background: var(--card); border: 1px solid var(--border); border-radius: 16px;
|
|
161
|
+
padding: 24px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
|
|
162
|
+
}
|
|
163
|
+
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 16px; }
|
|
164
|
+
.hero { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: center; }
|
|
165
|
+
.gauge { position: relative; width: 180px; height: 180px; }
|
|
166
|
+
.gauge-svg { width: 180px; height: 180px; transform: rotate(-90deg); }
|
|
167
|
+
.gauge-track { fill: none; stroke: #eef1f7; stroke-width: 13; }
|
|
168
|
+
.gauge-value { fill: none; stroke: var(--accent); stroke-width: 13; stroke-linecap: round; }
|
|
169
|
+
.gauge-value.grade-a { stroke: var(--pass); }
|
|
170
|
+
.gauge-value.grade-b { stroke: #2e90fa; }
|
|
171
|
+
.gauge-value.grade-c { stroke: var(--warn); }
|
|
172
|
+
.gauge-value.grade-d { stroke: var(--fail); }
|
|
173
|
+
.gauge-center {
|
|
174
|
+
position: absolute; inset: 0; display: flex; flex-direction: column;
|
|
175
|
+
align-items: center; justify-content: center;
|
|
176
|
+
}
|
|
177
|
+
.gauge-score { font-size: 44px; font-weight: 800; line-height: 1; }
|
|
178
|
+
.gauge-unit { color: var(--muted); font-size: 13px; margin-top: 4px; }
|
|
179
|
+
.hero-grade { display: inline-flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
|
|
180
|
+
.grade-chip {
|
|
181
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
182
|
+
width: 40px; height: 40px; border-radius: 12px; color: #fff; font-weight: 800;
|
|
183
|
+
}
|
|
184
|
+
.grade-chip.grade-a, .share-grade.grade-a { background: var(--pass); }
|
|
185
|
+
.grade-chip.grade-b, .share-grade.grade-b { background: #2e90fa; }
|
|
186
|
+
.grade-chip.grade-c, .share-grade.grade-c { background: var(--warn); }
|
|
187
|
+
.grade-chip.grade-d, .share-grade.grade-d { background: var(--fail); }
|
|
188
|
+
.hero-summary { color: var(--muted); margin: 10px 0 0; }
|
|
189
|
+
.stat-line { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
|
|
190
|
+
.pill {
|
|
191
|
+
border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px;
|
|
192
|
+
font-size: 12px; color: var(--muted); background: #fafbff;
|
|
193
|
+
}
|
|
194
|
+
.inventory { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
195
|
+
.inventory th, .inventory td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--border); }
|
|
196
|
+
.inventory th:first-child, .inventory td:first-child { text-align: left; }
|
|
197
|
+
.inventory th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
|
|
198
|
+
.inventory tbody tr:last-child td { border-bottom: none; }
|
|
199
|
+
.inventory-total { margin: 14px 0 0; color: var(--muted); font-size: 14px; }
|
|
200
|
+
.check { border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }
|
|
201
|
+
.check--pass { border-left-color: var(--pass); }
|
|
202
|
+
.check--warn { border-left-color: var(--warn); background: #fffcf5; }
|
|
203
|
+
.check--fail { border-left-color: var(--fail); background: #fff5f4; }
|
|
204
|
+
.check-head { display: flex; align-items: center; gap: 10px; }
|
|
205
|
+
.check-head h3 { margin: 0; font-size: 15px; }
|
|
206
|
+
.check-detail { margin: 8px 0 0; color: #344054; font-size: 14px; }
|
|
207
|
+
.badge {
|
|
208
|
+
display: inline-block; padding: 2px 8px; border-radius: 999px;
|
|
209
|
+
font-size: 11px; font-weight: 700; letter-spacing: .04em;
|
|
210
|
+
}
|
|
211
|
+
.badge--pass { background: #ecfdf3; color: #027a48; }
|
|
212
|
+
.badge--warn { background: #fffaeb; color: #b54708; }
|
|
213
|
+
.badge--fail { background: #fef3f2; color: #b42318; }
|
|
214
|
+
.findings { margin: 10px 0 0; padding: 0; list-style: none; }
|
|
215
|
+
.finding { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: #475467; margin: 4px 0; }
|
|
216
|
+
.finding .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto; }
|
|
217
|
+
.finding code { background: #f2f4f7; border-radius: 5px; padding: 1px 5px; font-size: 12px; word-break: break-all; }
|
|
218
|
+
.remediation {
|
|
219
|
+
margin-top: 10px; padding: 10px 12px; border-radius: 9px;
|
|
220
|
+
background: #eef2ff; color: #3538cd; font-size: 13px;
|
|
221
|
+
}
|
|
222
|
+
.remediation-label { font-weight: 700; margin-right: 8px; }
|
|
223
|
+
.todo-list { margin: 0; padding-left: 20px; }
|
|
224
|
+
.todo-list li { margin-bottom: 14px; }
|
|
225
|
+
.todo-list p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
|
|
226
|
+
.todo-head { font-weight: 600; font-size: 14px; }
|
|
227
|
+
.share-card {
|
|
228
|
+
border: 1px dashed #c7d2fe; border-radius: 16px; padding: 24px;
|
|
229
|
+
background: linear-gradient(135deg, #ffffff 0%, #f5f7ff 100%);
|
|
230
|
+
}
|
|
231
|
+
.share-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
|
|
232
|
+
.share-card-kicker { font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .04em; }
|
|
233
|
+
.share-card-title { font-size: 20px; font-weight: 700; margin-top: 4px; }
|
|
234
|
+
.share-grade {
|
|
235
|
+
width: 52px; height: 52px; border-radius: 14px; color: #fff;
|
|
236
|
+
display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800;
|
|
237
|
+
}
|
|
238
|
+
.share-score { font-size: 52px; font-weight: 800; margin: 18px 0 6px; }
|
|
239
|
+
.share-score span { font-size: 18px; color: var(--muted); font-weight: 600; }
|
|
240
|
+
.share-stats { display: flex; flex-wrap: wrap; gap: 28px; margin-top: 10px; }
|
|
241
|
+
.share-stat { display: flex; flex-direction: column; }
|
|
242
|
+
.share-stat-value { font-size: 22px; font-weight: 700; }
|
|
243
|
+
.share-stat-label { font-size: 12px; color: var(--muted); }
|
|
244
|
+
.share-card-note { margin: 18px 0 0; font-size: 12px; color: var(--muted); }
|
|
245
|
+
.muted { color: var(--muted); font-size: 14px; }
|
|
246
|
+
@media (max-width: 640px) {
|
|
247
|
+
.hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
|
|
248
|
+
.stat-line { justify-content: center; }
|
|
249
|
+
.page { padding: 24px 14px 48px; }
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
function renderReportHtml(report) {
|
|
253
|
+
const profileNote = report.profile === 'xinchuang'
|
|
254
|
+
? '<div class="profile-note">信创适配评估为启发式检查,结果需人工确认,不构成“已适配”结论。</div>'
|
|
255
|
+
: '';
|
|
256
|
+
const agentMeta = report.agent ? ` · agent=${escapeHtml(report.agent)}` : '';
|
|
257
|
+
const target = escapeHtml(report.target || '—');
|
|
258
|
+
const generatedAt = new Date().toLocaleString('zh-CN');
|
|
259
|
+
return `<!doctype html>
|
|
260
|
+
<html lang="zh-CN">
|
|
261
|
+
<head>
|
|
262
|
+
<meta charset="utf-8">
|
|
263
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
264
|
+
<title>AgentDock Report</title>
|
|
265
|
+
<style>${STYLES}</style>
|
|
266
|
+
</head>
|
|
267
|
+
<body>
|
|
268
|
+
<div class="page">
|
|
269
|
+
<header>
|
|
270
|
+
<div class="brand"><span class="brand-mark"></span>AgentDock Report</div>
|
|
271
|
+
<div class="meta">模式 ${escapeHtml(report.mode)}${agentMeta} · 目标 ${target} · 生成于 ${escapeHtml(generatedAt)}</div>
|
|
272
|
+
${profileNote}
|
|
273
|
+
</header>
|
|
274
|
+
|
|
275
|
+
<section class="card hero">
|
|
276
|
+
${renderGauge(report)}
|
|
277
|
+
<div>
|
|
278
|
+
<div class="hero-grade">
|
|
279
|
+
<span class="grade-chip ${gradeClass(report.grade)}">${report.grade}</span>
|
|
280
|
+
环境健康度 ${report.score} / 100
|
|
281
|
+
</div>
|
|
282
|
+
<p class="hero-summary">${escapeHtml(report.summary)}</p>
|
|
283
|
+
<div class="stat-line">
|
|
284
|
+
<span class="pill">可迁移定义 ${report.inventory.totalEntries}</span>
|
|
285
|
+
<span class="pill">隔离机密 ${report.inventory.secretsCount}</span>
|
|
286
|
+
<span class="pill">检查 ${report.checks.length} 项</span>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
</section>
|
|
290
|
+
|
|
291
|
+
<section class="card">
|
|
292
|
+
<h2>环境清单</h2>
|
|
293
|
+
${renderInventory(report)}
|
|
294
|
+
</section>
|
|
295
|
+
|
|
296
|
+
<section class="card">
|
|
297
|
+
<h2>检查明细</h2>
|
|
298
|
+
${report.checks.map((check) => renderCheck(check)).join('')}
|
|
299
|
+
</section>
|
|
300
|
+
|
|
301
|
+
<section class="card">
|
|
302
|
+
<h2>修复建议</h2>
|
|
303
|
+
${renderRemediation(report)}
|
|
304
|
+
</section>
|
|
305
|
+
|
|
306
|
+
${renderShareCard(report)}
|
|
307
|
+
</div>
|
|
308
|
+
</body>
|
|
309
|
+
</html>
|
|
310
|
+
`;
|
|
311
|
+
}
|