agentdock-cli 0.6.0 → 0.7.1

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.
@@ -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, '&lt;')
8
+ .replace(/>/g, '&gt;')
9
+ .replace(/"/g, '&quot;')
10
+ .replace(/'/g, '&#39;');
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
+ }
@@ -0,0 +1,243 @@
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.computeReportScore = computeReportScore;
7
+ exports.gradeForScore = gradeForScore;
8
+ exports.runReport = runReport;
9
+ const node_os_1 = __importDefault(require("node:os"));
10
+ const promises_1 = __importDefault(require("node:fs/promises"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const yaml_1 = __importDefault(require("yaml"));
13
+ const doctor_1 = require("./doctor");
14
+ const report_html_1 = require("./report-html");
15
+ const claude_scanner_1 = require("../scanners/claude-scanner");
16
+ const codex_scanner_1 = require("../scanners/codex-scanner");
17
+ const fs_1 = require("../utils/fs");
18
+ // ===== inventory =====
19
+ function countDomain(agent, domain) {
20
+ const mcp = domain.mcp.length;
21
+ const skills = domain.skills.length;
22
+ const agents = domain.agents.length;
23
+ const plugins = domain.plugins.length;
24
+ const hooks = domain.hooks.length;
25
+ const memory = domain.memory.length;
26
+ const settings = domain.settings.length;
27
+ return {
28
+ agent,
29
+ mcp,
30
+ skills,
31
+ agents,
32
+ plugins,
33
+ hooks,
34
+ memory,
35
+ settings,
36
+ total: mcp + skills + agents + plugins + hooks + memory + settings,
37
+ };
38
+ }
39
+ function makeInventory(agents, secretsCount) {
40
+ return {
41
+ agents,
42
+ totalEntries: agents.reduce((sum, item) => sum + item.total, 0),
43
+ secretsCount,
44
+ };
45
+ }
46
+ async function inventoryLive(agentFilter, root) {
47
+ const agents = [];
48
+ let secretsCount = 0;
49
+ if (agentFilter === 'claude' || agentFilter === 'all') {
50
+ const scan = await (0, claude_scanner_1.scanClaude)(root);
51
+ agents.push(countDomain('claude', scan.domain));
52
+ secretsCount += scan.secrets.length;
53
+ }
54
+ if (agentFilter === 'codex' || agentFilter === 'all') {
55
+ const scan = await (0, codex_scanner_1.scanCodex)(root);
56
+ agents.push(countDomain('codex', scan.domain));
57
+ secretsCount += scan.secrets.length;
58
+ }
59
+ return makeInventory(agents, secretsCount);
60
+ }
61
+ function inventoryFromManifest(manifest, agentFilter) {
62
+ const agents = [];
63
+ const entries = Object.entries(manifest.agents ?? {});
64
+ for (const [name, domain] of entries) {
65
+ if (!domain) {
66
+ continue;
67
+ }
68
+ if (agentFilter !== 'all' && agentFilter !== name) {
69
+ continue;
70
+ }
71
+ agents.push(countDomain(name, domain));
72
+ }
73
+ return makeInventory(agents, manifest.secrets?.length ?? 0);
74
+ }
75
+ async function inventoryFromScan(scanPath, agentFilter) {
76
+ const manifestPath = node_path_1.default.resolve(scanPath);
77
+ if (!(await (0, fs_1.pathExists)(manifestPath))) {
78
+ return makeInventory([], 0);
79
+ }
80
+ const manifest = yaml_1.default.parse(await promises_1.default.readFile(manifestPath, 'utf8'));
81
+ return inventoryFromManifest(manifest, agentFilter);
82
+ }
83
+ async function inventoryFromPackage(pkgDir, agentFilter) {
84
+ const manifestPath = node_path_1.default.join(node_path_1.default.resolve(pkgDir), 'manifest.resolved.json');
85
+ if (!(await (0, fs_1.pathExists)(manifestPath))) {
86
+ return makeInventory([], 0);
87
+ }
88
+ try {
89
+ const manifest = JSON.parse(await promises_1.default.readFile(manifestPath, 'utf8'));
90
+ return inventoryFromManifest(manifest, agentFilter);
91
+ }
92
+ catch {
93
+ return makeInventory([], 0);
94
+ }
95
+ }
96
+ // ===== scoring =====
97
+ function computeReportScore(checks) {
98
+ let score = 100;
99
+ for (const check of checks) {
100
+ if (check.status === 'fail') {
101
+ score -= 20;
102
+ }
103
+ else if (check.status === 'warn') {
104
+ score -= 8;
105
+ }
106
+ }
107
+ return Math.max(0, Math.min(100, score));
108
+ }
109
+ function gradeForScore(score) {
110
+ if (score >= 90)
111
+ return 'A';
112
+ if (score >= 75)
113
+ return 'B';
114
+ if (score >= 60)
115
+ return 'C';
116
+ return 'D';
117
+ }
118
+ // ===== xinchuang heuristics =====
119
+ const ABSOLUTE_PATH_PATTERN = /[A-Za-z]:[\\/]|\/(?:home|Users|root|opt|usr\/local)\//g;
120
+ const RUNTIME_COMMAND_PATTERN = /"command"\s*:\s*"(?:npx|uvx|docker|bunx|pnpm)"|command\s*=\s*"(?:npx|uvx|docker|bunx|pnpm)"/g;
121
+ const EXTERNAL_ENDPOINT_PATTERN = /https?:\/\/[^\s"'`]+/g;
122
+ async function readConfigTexts(root) {
123
+ const candidates = [
124
+ node_path_1.default.join(root, '.claude', 'settings.json'),
125
+ node_path_1.default.join(root, '.claude.json'),
126
+ node_path_1.default.join(root, '.codex', 'config.toml'),
127
+ ];
128
+ const texts = [];
129
+ for (const file of candidates) {
130
+ try {
131
+ texts.push({ file, text: await promises_1.default.readFile(file, 'utf8') });
132
+ }
133
+ catch {
134
+ // missing / unreadable config is already reported by the doctor checks
135
+ }
136
+ }
137
+ return texts;
138
+ }
139
+ function collectHits(texts, pattern, sampleLimit = 3) {
140
+ const findings = [];
141
+ for (const { file, text } of texts) {
142
+ const matches = text.match(pattern);
143
+ if (!matches || matches.length === 0) {
144
+ continue;
145
+ }
146
+ const samples = [...new Set(matches)].slice(0, sampleLimit);
147
+ findings.push({
148
+ severity: 'warn',
149
+ message: `发现 ${matches.length} 处${samples.length ? `(示例:${samples.join(', ')})` : ''}`,
150
+ path: file,
151
+ });
152
+ }
153
+ return findings;
154
+ }
155
+ function heuristicCheck(id, label, findings, cleanDetail, remediation) {
156
+ const status = findings.length > 0 ? 'warn' : 'pass';
157
+ return {
158
+ id,
159
+ label,
160
+ status,
161
+ detail: status === 'pass' ? `${cleanDetail}(启发式检查,仍需人工确认)` : `需人工确认:发现 ${findings.length} 个可疑项`,
162
+ findings,
163
+ ...(status === 'pass' ? {} : { remediation }),
164
+ };
165
+ }
166
+ async function xinchuangChecks(root) {
167
+ const texts = await readConfigTexts(root);
168
+ const platform = {
169
+ id: 'xinchuang-platform',
170
+ label: '信创 · 平台 / 运行时(需人工确认)',
171
+ status: 'warn',
172
+ detail: `需人工确认:当前为 ${process.platform}/${process.arch},Node ${process.version};请核对目标信创环境(如麒麟 V10 / 统信 UOS、LoongArch / 鲲鹏 ARM)的操作系统、CPU 架构与运行时版本`,
173
+ findings: [],
174
+ remediation: '信创适配无法仅凭本机静态信息判定。请在目标机上运行 `agentdock report --profile xinchuang`,人工验证 Node 运行时、依赖与 MCP 服务可用性。',
175
+ };
176
+ const pathCheck = heuristicCheck('xinchuang-paths', '信创 · 绝对路径(需人工确认)', collectHits(texts, ABSOLUTE_PATH_PATTERN), '配置中未发现平台相关的绝对路径引用', '跨机器 / 跨国产化系统时,固定路径(如 C:\\Users\\...、/home/...)通常不可用。建议改为相对路径或环境变量,并在目标机重新验证。');
177
+ const runtimeCheck = heuristicCheck('xinchuang-runtime', '信创 · MCP 运行时依赖(需人工确认)', collectHits(texts, RUNTIME_COMMAND_PATTERN), '配置中未发现 npx / uvx / docker 等运行时拉取命令', 'npx / uvx / docker 等运行时会在目标机联网拉取依赖;信创内网环境需提前离线安装,或改为本地可执行文件。');
178
+ const endpointCheck = heuristicCheck('xinchuang-endpoints', '信创 · 外网端点(需人工确认)', collectHits(texts, EXTERNAL_ENDPOINT_PATTERN), '配置中未发现外网 http(s) 端点', '外网 http(s) 端点在信创内网可能不可达,需提前确认网络策略或改用内网镜像 / 代理。');
179
+ return [platform, pathCheck, runtimeCheck, endpointCheck];
180
+ }
181
+ function xinchuangManualCheck(mode) {
182
+ return {
183
+ id: 'xinchuang-manual',
184
+ label: '信创 · 需人工确认',
185
+ status: 'warn',
186
+ detail: `需人工确认:${mode} 模式仅审计产物,不评估信创环境适配`,
187
+ findings: [],
188
+ remediation: '请在目标机上运行 `agentdock report --profile xinchuang`,人工验证运行时、依赖、绝对路径与外网端点。',
189
+ };
190
+ }
191
+ // ===== entry =====
192
+ async function runReport(options) {
193
+ const agent = options.agent ?? 'all';
194
+ const profile = options.profile ?? 'default';
195
+ let base;
196
+ let inventory;
197
+ let extraChecks = [];
198
+ if (options.fromScan) {
199
+ base = await (0, doctor_1.runDoctor)({ agent, fromScan: options.fromScan });
200
+ inventory = await inventoryFromScan(options.fromScan, agent);
201
+ if (profile === 'xinchuang') {
202
+ extraChecks = [xinchuangManualCheck('scan')];
203
+ }
204
+ }
205
+ else if (options.package) {
206
+ base = await (0, doctor_1.runDoctor)({ agent, package: options.package });
207
+ inventory = await inventoryFromPackage(options.package, agent);
208
+ if (profile === 'xinchuang') {
209
+ extraChecks = [xinchuangManualCheck('package')];
210
+ }
211
+ }
212
+ else {
213
+ const root = options.root ?? node_os_1.default.homedir();
214
+ base = await (0, doctor_1.runDoctor)({ agent, root });
215
+ inventory = await inventoryLive(agent, root);
216
+ if (profile === 'xinchuang') {
217
+ extraChecks = await xinchuangChecks(root);
218
+ }
219
+ }
220
+ const checks = [...base.checks, ...extraChecks];
221
+ const score = computeReportScore(checks);
222
+ const grade = gradeForScore(score);
223
+ const summary = profile === 'xinchuang'
224
+ ? `${base.summary}(信创适配为启发式检查,需人工确认)`
225
+ : base.summary;
226
+ const report = {
227
+ ...base,
228
+ checks,
229
+ summary,
230
+ profile,
231
+ score,
232
+ grade,
233
+ inventory,
234
+ };
235
+ if (options.out) {
236
+ await (0, fs_1.ensureDirectory)(options.out);
237
+ report.htmlPath = node_path_1.default.join(options.out, 'agentdock-report.html');
238
+ report.jsonPath = node_path_1.default.join(options.out, 'agentdock-report.json');
239
+ await (0, fs_1.writeJsonFile)(report.jsonPath, report);
240
+ await (0, fs_1.writeTextFile)(report.htmlPath, (0, report_html_1.renderReportHtml)(report));
241
+ }
242
+ return report;
243
+ }
@@ -10,7 +10,7 @@ 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|install|validate|doctor|list|diff|config|uninstall> [path]',
13
+ 'cli.usage': 'Usage: agentdock <scan|export|install|validate|doctor|report|list|diff|config|uninstall> [path]',
14
14
  'install.complete': 'Install completed: {path}',
15
15
  'uninstall.complete': 'Uninstall complete: {path}',
16
16
  'uninstall.dryRunHeader': 'Uninstall plan (dry-run — no changes made): {path}',
@@ -31,7 +31,7 @@ const DICTIONARIES = {
31
31
  'config.unsetValue': '(unset)',
32
32
  },
33
33
  'zh-CN': {
34
- 'cli.usage': '用法:agentdock <scan|export|install|validate|doctor|list|diff|config|uninstall> [path]',
34
+ 'cli.usage': '用法:agentdock <scan|export|install|validate|doctor|report|list|diff|config|uninstall> [path]',
35
35
  'install.complete': '安装完成:{path}',
36
36
  'uninstall.complete': '卸载完成:{path}',
37
37
  'uninstall.dryRunHeader': '卸载计划(dry-run — 未做任何改动):{path}',
@@ -17,7 +17,7 @@ exports.readJsonFile = readJsonFile;
17
17
  exports.writeJsonFile = writeJsonFile;
18
18
  const promises_1 = __importDefault(require("node:fs/promises"));
19
19
  const node_path_1 = __importDefault(require("node:path"));
20
- const minimatch_1 = require("minimatch");
20
+ const picomatch_1 = __importDefault(require("picomatch"));
21
21
  function resolveFrom(baseDir, targetPath) {
22
22
  return node_path_1.default.resolve(baseDir, targetPath);
23
23
  }
@@ -126,9 +126,11 @@ async function copyDirectoryFiltered(sourcePath, targetPath, include, exclude, f
126
126
  const files = await walkDirectoryWithSymlinkPolicy(sourcePath, '', followSymlinks);
127
127
  const includePatterns = include?.length ? include : ['**/*'];
128
128
  const excludePatterns = exclude ?? [];
129
+ const includeMatchers = includePatterns.map((pattern) => (0, picomatch_1.default)(pattern, { dot: true }));
130
+ const excludeMatchers = excludePatterns.map((pattern) => (0, picomatch_1.default)(pattern, { dot: true }));
129
131
  for (const file of files) {
130
- const isIncluded = includePatterns.some((pattern) => (0, minimatch_1.minimatch)(file.relativePath, pattern, { dot: true }));
131
- const isExcluded = excludePatterns.some((pattern) => (0, minimatch_1.minimatch)(file.relativePath, pattern, { dot: true }));
132
+ const isIncluded = includeMatchers.some((matches) => matches(file.relativePath));
133
+ const isExcluded = excludeMatchers.some((matches) => matches(file.relativePath));
132
134
  if (!isIncluded || isExcluded) {
133
135
  continue;
134
136
  }