shellward 0.6.8 → 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 CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![npm](https://img.shields.io/npm/v/shellward?color=cb0000&label=npm)](https://www.npmjs.com/package/shellward)
10
10
  [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
11
- [![tests](https://img.shields.io/badge/tests-263%20passing-brightgreen)](#performance)
11
+ [![tests](https://img.shields.io/badge/tests-273%20passing-brightgreen)](#performance)
12
12
  [![deps](https://img.shields.io/badge/dependencies-0-brightgreen)](#performance)
13
13
 
14
14
  **🌐 官网: https://jnmetacode.github.io/shellward/**
@@ -39,6 +39,10 @@ npx shellward scan
39
39
 
40
40
  想在浏览器里看?`npx shellward scan --open`(扫完直接打开报告)或 `--serve`(本地 http://localhost 提供报告)——**数据全程不出本机**。
41
41
 
42
+ **Web 扫描器 / 客户端(双模式)**:
43
+ - `shellward web` — 公开仓库 web 扫描器:网页贴「公开仓库 URL」或用 `/scan?repo=URL` 链接体检(可部署,见 `Dockerfile`)。
44
+ - `shellward web --local` — 本地 web GUI(客户端体验):填本地路径扫描,**私有代码不上传、不出本机**,无需命令行。
45
+
42
46
  `--json` 供 CI · `--ci` 发现 critical 时让构建失败 · `--html report.html` 导出可打印成 PDF 的报告(备案/审计存档)· 也可作 [GitHub Action](#github-action-pr-compliance-gate) 接入 PR 门禁。
43
47
 
44
48
  > 检测重点:**境外大模型端点与 SDK 依赖(数据出境——中国独有、英文工具没有的概念)**、硬编码密钥、文件中的中文 PII、`.env` 暴露。扫到境外模型(如 `openai` 依赖)时,**直接给出境内合规替代**(通义千问 / DeepSeek / Kimi / 智谱)及其 OpenAI 兼容 `base_url`——多数迁移只需改一个 `base_url`。
package/dist/cli.js CHANGED
@@ -31,6 +31,13 @@ async function main() {
31
31
  await import('./mcp-server.js');
32
32
  return;
33
33
  }
34
+ if (cmd === 'web') {
35
+ const { startWebServer } = await import('./web/scan-server.js');
36
+ const local = argv.includes('--local');
37
+ const portArg = flagValue(argv, '--port') || argv.slice(1).find(a => /^\d+$/.test(a));
38
+ startWebServer({ port: Number(portArg) || 8080, local });
39
+ return;
40
+ }
34
41
  if (cmd === 'scan') {
35
42
  runScan(argv.slice(1));
36
43
  return;
@@ -178,6 +185,8 @@ Usage:
178
185
  shellward scan --html f Export a self-contained HTML report (print to PDF)
179
186
  shellward scan --open Scan and open the report in your browser (local)
180
187
  shellward scan --serve Scan and serve the report at http://localhost (local)
188
+ shellward web [port] Web scanner for public repo URLs (deploy this)
189
+ shellward web --local Local web GUI: scan a local path (private, no upload)
181
190
  shellward mcp Start MCP server (stdio)
182
191
  shellward --help
183
192
 
@@ -195,6 +204,8 @@ PII in files, .env permissions. Maps to CSL / PIPL / MLPS / cross-border / label
195
204
  shellward scan --html 文件 导出自包含 HTML 报告(浏览器可打印成 PDF)
196
205
  shellward scan --open 扫描并在浏览器打开报告(本地,方便看)
197
206
  shellward scan --serve 扫描并在 http://localhost 提供报告(本地服务)
207
+ shellward web [端口] 公开仓库 web 扫描器(贴 URL 体检,用于部署)
208
+ shellward web --local 本地 web GUI:填本地路径扫描(私有、不上传,客户端体验)
198
209
  shellward mcp 启动 MCP 服务器(stdio)
199
210
  shellward --help
200
211
 
@@ -1,73 +1,96 @@
1
- // src/compliance/html-report.ts — HTML 合规报告(合规包雏形)
1
+ // src/compliance/html-report.ts — HTML 合规报告(合规包)
2
2
  //
3
3
  // 终端输出给开发者看;这份 HTML 给法务/合规/测评机构看 —— 可在浏览器打开、
4
4
  // 打印成 PDF、用于等保/PIPL 备案存档。自包含(内联 CSS、零外部依赖、无需联网)。
5
+ //
6
+ // 设计目标:专业、可信、克制——环形评分仪表、语义化状态药丸、severity 彩色标签、
7
+ // 卡片化分组、品牌色克制使用、清晰层级。
5
8
  import { REGULATION_NAMES } from './regulations.js';
6
9
  import { suggestDomestic } from '../rules/domestic-alternatives.js';
7
10
  const STATUS = {
8
11
  pass: { zh: '合规', en: 'Pass', cls: 'pass' },
9
12
  warn: { zh: '部分', en: 'Partial', cls: 'warn' },
10
13
  fail: { zh: '不合规', en: 'Fail', cls: 'fail' },
11
- manual: { zh: '待确认', en: 'Manual', cls: 'manual' },
14
+ manual: { zh: '待确认', en: 'Review', cls: 'manual' },
12
15
  };
13
16
  const KIND = {
14
- overseas: { zh: '数据出境风险', en: 'Data export risk' },
15
- secret: { zh: '硬编码密钥', en: 'Hardcoded secret' },
16
- pii: { zh: '个人信息暴露', en: 'PII exposure' },
17
- 'env-perm': { zh: '.env 权限', en: '.env permission' },
17
+ overseas: { zh: '数据出境风险', en: 'Data export risk', icon: '🌐' },
18
+ secret: { zh: '硬编码密钥', en: 'Hardcoded secret', icon: '🔑' },
19
+ pii: { zh: '个人信息暴露', en: 'PII exposure', icon: '🪪' },
20
+ 'env-perm': { zh: '.env 权限', en: '.env permission', icon: '📂' },
18
21
  };
19
22
  const KIND_ORDER = ['overseas', 'secret', 'pii', 'env-perm'];
20
23
  const REG_ORDER = ['CSL', 'PIPL', 'MLPS', 'CBDT', 'GENAI'];
21
- const GRADE_COLOR = { A: '#15803d', B: '#65a30d', C: '#d97706', D: '#dc2626' };
24
+ const GRADE = {
25
+ A: { color: '#16a34a', zh: '优秀', en: 'Excellent' },
26
+ B: { color: '#65a30d', zh: '良好', en: 'Good' },
27
+ C: { color: '#d97706', zh: '及格', en: 'Fair' },
28
+ D: { color: '#dc2626', zh: '不及格', en: 'Poor' },
29
+ };
30
+ const SEV = {
31
+ critical: { zh: '严重', en: 'Critical' },
32
+ high: { zh: '高', en: 'High' },
33
+ medium: { zh: '中', en: 'Medium' },
34
+ };
22
35
  /** 生成自包含 HTML 合规报告 */
23
36
  export function renderHtmlReport(report, scan, locale, meta) {
24
37
  const zh = locale === 'zh';
25
38
  const t = (z, e) => (zh ? z : e);
26
- const gradeColor = GRADE_COLOR[report.grade] || '#475569';
39
+ const g = GRADE[report.grade] || { color: '#475569', zh: report.grade, en: report.grade };
27
40
  const when = report.generatedAt.slice(0, 19).replace('T', ' ');
28
- const sections = [];
29
- // ===== 评分卡 =====
30
- sections.push(`
31
- <section class="score-card">
32
- <div class="gauge" style="--c:${gradeColor}">
33
- <div class="score">${report.score}<span>/100</span></div>
34
- <div class="grade" style="color:${gradeColor}">${esc(report.grade)}</div>
41
+ const S = [];
42
+ // ===== 评分 Hero =====
43
+ S.push(`
44
+ <section class="hero">
45
+ <div class="gauge" style="--p:${report.score};--c:${g.color}">
46
+ <div class="gauge-in">
47
+ <div class="gscore">${report.score}<small>/100</small></div>
48
+ <div class="ggrade" style="color:${g.color}">${esc(report.grade)} · ${t(g.zh, g.en)}</div>
49
+ </div>
35
50
  </div>
36
- <div class="summary">
37
- <div class="bar"><div class="fill" style="width:${report.score}%;background:${gradeColor}"></div></div>
38
- <ul class="counts">
39
- <li class="pass">🟢 ${t('合规', 'Pass')} ${report.passed}</li>
40
- <li class="warn">🟡 ${t('部分', 'Partial')} ${report.warned}</li>
41
- <li class="fail">🔴 ${t('不合规', 'Fail')} ${report.failed}</li>
42
- <li class="manual">⚪ ${t('待确认', 'Manual')} ${report.manual}</li>
43
- </ul>
44
- ${report.projectPenalty ? `<p class="penalty">${t('含项目实测风险扣分', 'Includes project-scan penalty')} −${report.projectPenalty}</p>` : ''}
51
+ <div class="hero-side">
52
+ <div class="stat-row">
53
+ ${stat('pass', '🟢', t('合规', 'Pass'), report.passed)}
54
+ ${stat('warn', '🟡', t('部分', 'Partial'), report.warned)}
55
+ ${stat('fail', '🔴', t('不合规', 'Fail'), report.failed)}
56
+ ${stat('manual', '⚪', t('待确认', 'Review'), report.manual)}
57
+ </div>
58
+ ${report.projectPenalty ? `<div class="penalty">⚠ ${t('含项目实测风险扣分', 'Includes project-scan penalty')} <b>−${report.projectPenalty}</b></div>` : ''}
59
+ <p class="hero-note">${t('得分基于本次可静态观测的项目风险。⚪ 待确认项需把 ShellWard 部署为运行时防护或人工核验。', 'Score reflects statically-observable project risk. items need runtime deployment or manual review.')}</p>
45
60
  </div>
46
61
  </section>`);
47
62
  // ===== 项目实测风险 =====
48
- sections.push(`<h2>🔍 ${t('项目实测风险', 'Project Scan Findings')}</h2>`);
49
- sections.push(`<p class="muted">${t('已扫描', 'Scanned')} ${scan.filesScanned} ${t('个文件', 'files')}${scan.truncated ? t('(已达上限)', ' (limit reached)') : ''}</p>`);
63
+ S.push(sectionHead('🔍', t('项目实测风险', 'Project Scan Findings'), t(`已扫描 ${scan.filesScanned} 个文件${scan.truncated ? '(已达上限)' : ''}`, `Scanned ${scan.filesScanned} files${scan.truncated ? ' (limit reached)' : ''}`)));
50
64
  if (scan.findings.length === 0) {
51
- sections.push(`<p class="ok">🟢 ${t('未在项目文件中发现硬编码密钥、个人信息暴露或境外端点。', 'No hardcoded secrets, PII, or overseas endpoints found.')}</p>`);
65
+ S.push(`<div class="empty">🟢 ${t('未在项目文件中发现硬编码密钥、个人信息暴露或境外端点。', 'No hardcoded secrets, PII, or overseas endpoints found in project files.')}</div>`);
52
66
  }
53
67
  else {
68
+ S.push('<div class="chips">');
69
+ for (const k of KIND_ORDER)
70
+ if (scan.counts[k] > 0) {
71
+ S.push(`<span class="chip"><b>${scan.counts[k]}</b> ${KIND[k].icon} ${t(KIND[k].zh, KIND[k].en)}</span>`);
72
+ }
73
+ S.push('</div>');
54
74
  for (const kind of KIND_ORDER) {
55
75
  const items = scan.findings.filter(f => f.kind === kind);
56
76
  if (items.length === 0)
57
77
  continue;
58
- sections.push(`<h3>${t(KIND[kind].zh, KIND[kind].en)} (${items.length})</h3>`);
59
- sections.push('<table class="findings"><thead><tr>'
60
- + `<th>${t('位置', 'Location')}</th><th>${t('说明', 'Detail')}</th><th>${t('严重度', 'Severity')}</th></tr></thead><tbody>`);
78
+ S.push(`<h3 class="sub">${KIND[kind].icon} ${t(KIND[kind].zh, KIND[kind].en)} <span class="n">${items.length}</span></h3>`);
79
+ S.push('<table class="tbl"><tbody>');
61
80
  for (const f of items) {
62
81
  const loc = f.line ? `${f.file}:${f.line}` : f.file;
63
- sections.push(`<tr><td class="loc">${esc(loc)}</td><td>${esc(f.detail)}</td><td class="sev-${f.severity}">${f.severity}</td></tr>`);
82
+ S.push(`<tr>
83
+ <td class="loc"><code>${esc(loc)}</code></td>
84
+ <td>${esc(f.detail)}</td>
85
+ <td class="right">${sevPill(f.severity, zh)}</td></tr>`);
64
86
  }
65
- sections.push('</tbody></table>');
87
+ S.push('</tbody></table>');
66
88
  }
67
89
  }
68
90
  // ===== 境内合规替代建议 =====
69
91
  const overseas = scan.findings.filter(f => f.kind === 'overseas');
70
92
  if (overseas.length > 0) {
93
+ S.push(sectionHead('✅', t('境内合规替代建议', 'Domestic Compliance Alternatives'), t('把数据出境风险变成可执行的迁移路径', 'Turn data-export risk into a migration path')));
71
94
  const seen = new Set();
72
95
  const providers = [];
73
96
  for (const f of overseas) {
@@ -77,42 +100,46 @@ export function renderHtmlReport(report, scan, locale, meta) {
77
100
  seen.add(k);
78
101
  providers.push({ key: f.endpointId || f.provider_en || '', zh: f.provider_zh, en: f.provider_en });
79
102
  }
80
- sections.push(`<h2>✅ ${t('境内合规替代建议', 'Domestic Compliance Alternatives')}</h2>`);
81
- sections.push('<ul class="migrate">');
103
+ S.push('<div class="migrate">');
82
104
  for (const p of providers) {
83
105
  const s = suggestDomestic(p.key, p.zh, p.en);
84
- sections.push(`<li><b>${esc(zh ? s.overseas_zh : s.overseas_en)}</b> → ${esc(zh ? s.difficulty_zh : s.difficulty_en)}</li>`);
106
+ const low = (zh ? s.difficulty_zh : s.difficulty_en).startsWith(zh ? '低' : 'Low');
107
+ S.push(`<div class="mrow"><b>${esc(zh ? s.overseas_zh : s.overseas_en)}</b>
108
+ <span class="mtag ${low ? 'low' : 'mid'}">${t('迁移', 'Migrate')}: ${esc(zh ? s.difficulty_zh : s.difficulty_en)}</span></div>`);
85
109
  }
86
- sections.push('</ul>');
110
+ S.push('</div>');
87
111
  const alts = suggestDomestic(providers[0].key, providers[0].zh, providers[0].en).alternatives;
88
- sections.push('<table class="findings"><thead><tr>'
112
+ S.push('<table class="tbl alts"><thead><tr>'
89
113
  + `<th>${t('境内模型', 'Domestic model')}</th><th>${t('厂商', 'Vendor')}</th><th>${t('OpenAI 兼容 base_url', 'OpenAI-compatible base_url')}</th></tr></thead><tbody>`);
90
114
  for (const m of alts) {
91
- sections.push(`<tr><td>${esc(zh ? m.name_zh : m.name_en)}</td><td>${esc(m.vendor_zh)}</td><td class="loc">${esc(m.baseUrl)}</td></tr>`);
115
+ S.push(`<tr><td><b>${esc(zh ? m.name_zh : m.name_en)}</b></td><td class="muted">${esc(m.vendor_zh)}</td><td class="loc"><code>${esc(m.baseUrl)}</code></td></tr>`);
92
116
  }
93
- sections.push('</tbody></table>');
94
- sections.push(`<p class="muted">${t('对使用 openai SDK 的项目:通常仅需把 base_url 与 api_key 换成上表任一境内模型即可,业务代码无需改动。', 'For openai-SDK projects: usually just swap base_url + api_key — no code change.')}</p>`);
117
+ S.push('</tbody></table>');
118
+ S.push(`<p class="note">💡 ${t('对使用 openai SDK 的项目:通常仅需把 base_url 与 api_key 换成上表任一境内模型即可,业务代码无需改动。', 'For openai-SDK projects: usually just swap base_url + api_key — no code change.')}</p>`);
95
119
  }
96
120
  // ===== 控制项明细 =====
97
- sections.push(`<h2>📋 ${t('合规控制项明细', 'Compliance Controls')}</h2>`);
121
+ S.push(sectionHead('📋', t('合规控制项明细', 'Compliance Controls'), t('按法规分组;⚪ 项为运行时/人工核验', 'By regulation; ⚪ = runtime / manual review')));
98
122
  const grouped = groupBy(report.results);
99
123
  for (const reg of REG_ORDER) {
100
124
  const items = grouped[reg];
101
125
  if (!items || items.length === 0)
102
126
  continue;
103
- sections.push(`<h3>${esc(zh ? REGULATION_NAMES[reg].zh : REGULATION_NAMES[reg].en)}</h3>`);
104
- sections.push('<table class="controls"><thead><tr>'
105
- + `<th>${t('状态', 'Status')}</th><th>${t('控制项', 'Control')}</th><th>${t('条款', 'Article')}</th><th>${t('结论', 'Result')}</th></tr></thead><tbody>`);
127
+ const p = items.filter(r => r.status === 'pass').length;
128
+ const f = items.filter(r => r.status === 'fail').length;
129
+ S.push(`<div class="reg">
130
+ <div class="reg-head"><span>${esc(zh ? REGULATION_NAMES[reg].zh : REGULATION_NAMES[reg].en)}</span>
131
+ <span class="reg-mini">${p ? `<i class="d pass"></i>${p}` : ''}${f ? `<i class="d fail"></i>${f}` : ''}</span></div>
132
+ <table class="tbl ctrl"><tbody>`);
106
133
  for (const r of items) {
107
134
  const st = STATUS[r.status];
108
- sections.push(`<tr><td><span class="badge ${st.cls}">${zh ? st.zh : st.en}</span></td>`
109
- + `<td>${esc(zh ? r.control.title_zh : r.control.title_en)}</td>`
110
- + `<td class="loc">${esc(r.control.article)}</td>`
111
- + `<td>${esc(zh ? r.detail_zh : r.detail_en)}</td></tr>`);
135
+ S.push(`<tr class="${st.cls}">
136
+ <td class="st">${statusPill(r.status, zh)}</td>
137
+ <td class="ttl"><b>${esc(zh ? r.control.title_zh : r.control.title_en)}</b><span class="art">${esc(r.control.article)}</span></td>
138
+ <td class="${r.status === 'manual' ? 'faint' : ''}">${esc(zh ? r.detail_zh : r.detail_en)}</td></tr>`);
112
139
  }
113
- sections.push('</tbody></table>');
140
+ S.push('</tbody></table></div>');
114
141
  }
115
- const disclaimer = t('本报告由 ShellWard 合规网关自动生成,帮助评估并满足合规技术要求,不构成法律意见,亦不替代算法备案/定级备案/PIA 等主体责任。⚪ 待确认项需结合业务人工判定。', 'Generated by ShellWard Compliance Gateway. Assists with technical compliance; not legal advice.');
142
+ const disclaimer = t('本报告由 ShellWard 合规网关自动生成,帮助评估并满足合规技术要求,不构成法律意见,亦不替代算法备案/定级备案/PIA 等主体责任。⚪ 待确认项需结合业务人工判定。', 'Generated by ShellWard Compliance Gateway. Assists with technical compliance; not legal advice. ⚪ items require manual review.');
116
143
  return `<!DOCTYPE html>
117
144
  <html lang="${zh ? 'zh-CN' : 'en'}">
118
145
  <head>
@@ -124,15 +151,31 @@ export function renderHtmlReport(report, scan, locale, meta) {
124
151
  <body>
125
152
  <main>
126
153
  <header>
127
- <h1>🛡️ ${t('AI 应用合规体检报告', 'AI Application Compliance Report')}</h1>
128
- <p class="meta">${t('生成时间', 'Generated')}: ${esc(when)} UTC | ${t('扫描目录', 'Scanned')}: <code>${esc(meta.root)}</code></p>
154
+ <div class="brand">🛡️ Shell<span>Ward</span> <em>${t('合规网关', 'Compliance Gateway')}</em></div>
155
+ <h1>${t('AI 应用合规体检报告', 'AI Application Compliance Report')}</h1>
156
+ <p class="meta">${t('生成', 'Generated')}: ${esc(when)} UTC&nbsp;&nbsp;·&nbsp;&nbsp;${t('扫描目录', 'Path')}: <code>${esc(meta.root)}</code></p>
129
157
  </header>
130
- ${sections.join('\n')}
158
+ ${S.join('\n')}
131
159
  <footer>${esc(disclaimer)}</footer>
132
160
  </main>
133
161
  </body>
134
162
  </html>`;
135
163
  }
164
+ // ===== 小组件 =====
165
+ function stat(cls, icon, label, n) {
166
+ return `<div class="stat ${cls}"><div class="sn">${n}</div><div class="sl">${icon} ${label}</div></div>`;
167
+ }
168
+ function sectionHead(icon, title, sub) {
169
+ return `<div class="shead"><h2>${icon} ${esc(title)}</h2><span>${esc(sub)}</span></div>`;
170
+ }
171
+ function statusPill(s, zh) {
172
+ const st = STATUS[s];
173
+ return `<span class="pill ${st.cls}">${zh ? st.zh : st.en}</span>`;
174
+ }
175
+ function sevPill(sev, zh) {
176
+ const s = SEV[sev] || { zh: sev, en: sev };
177
+ return `<span class="sev ${sev}">${zh ? s.zh : s.en}</span>`;
178
+ }
136
179
  function groupBy(results) {
137
180
  const out = {};
138
181
  for (const r of results)
@@ -149,37 +192,132 @@ function esc(s) {
149
192
  .replace(/'/g, '&#39;');
150
193
  }
151
194
  const CSS = `
152
- :root{--ink:#1e293b;--muted:#64748b;--line:#e2e8f0;--bg:#f8fafc}
195
+ :root{
196
+ --ink:#0f172a;--muted:#64748b;--faint:#94a3b8;--line:#eaeef4;--bg:#eef1f6;--card:#fff;
197
+ --brand:#cb0000;
198
+ --pass:#16a34a;--pass-bg:#dcfce7;--warn:#b45309;--warn-bg:#fef3c7;
199
+ --fail:#dc2626;--fail-bg:#fee2e2;--manual:#64748b;--manual-bg:#eef2f7;
200
+ }
153
201
  *{box-sizing:border-box}
154
- body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif}
155
- main{max-width:920px;margin:0 auto;padding:32px 24px;background:#fff}
156
- header{border-bottom:2px solid var(--line);padding-bottom:16px;margin-bottom:24px}
157
- h1{font-size:24px;margin:0 0 6px}
158
- h2{font-size:19px;margin:32px 0 12px;padding-bottom:6px;border-bottom:1px solid var(--line)}
159
- h3{font-size:15px;margin:20px 0 8px;color:var(--muted)}
202
+ body{margin:0;background:var(--bg);color:var(--ink);
203
+ font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
204
+ -webkit-font-smoothing:antialiased}
205
+ main{max-width:880px;margin:28px auto;background:var(--card);border-radius:16px;
206
+ box-shadow:0 1px 3px rgba(15,23,42,.06),0 12px 32px rgba(15,23,42,.07);overflow:hidden}
207
+ header{padding:30px 36px 22px;background:linear-gradient(180deg,#fafbfd,#fff);border-bottom:1px solid var(--line)}
208
+ .brand{font-size:13px;font-weight:700;color:var(--ink);letter-spacing:.2px}
209
+ .brand span{color:var(--brand)}
210
+ .brand em{font-style:normal;color:var(--faint);font-weight:500;margin-left:4px}
211
+ h1{font-size:25px;margin:10px 0 6px;letter-spacing:-.3px}
160
212
  .meta{color:var(--muted);font-size:13px;margin:0}
161
- code{background:#f1f5f9;padding:1px 5px;border-radius:4px;font-size:13px}
162
- .score-card{display:flex;gap:28px;align-items:center;background:#f1f5f9;border-radius:12px;padding:24px}
163
- .gauge{text-align:center;min-width:120px}
164
- .gauge .score{font-size:44px;font-weight:700;color:var(--c)}
165
- .gauge .score span{font-size:18px;color:var(--muted);font-weight:400}
166
- .gauge .grade{font-size:28px;font-weight:700}
167
- .summary{flex:1}
168
- .bar{height:14px;background:#e2e8f0;border-radius:7px;overflow:hidden;margin-bottom:12px}
169
- .bar .fill{height:100%}
170
- .counts{list-style:none;display:flex;gap:18px;flex-wrap:wrap;padding:0;margin:0;font-size:14px}
171
- .penalty{color:#dc2626;font-size:13px;margin:8px 0 0}
172
- table{width:100%;border-collapse:collapse;margin:8px 0 4px;font-size:13.5px}
173
- th,td{text-align:left;padding:7px 10px;border-bottom:1px solid var(--line);vertical-align:top}
174
- th{background:#f8fafc;font-weight:600;color:var(--muted)}
175
- .loc{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;color:#0f172a;white-space:nowrap}
176
- .sev-critical{color:#dc2626;font-weight:600}.sev-high{color:#ea580c}.sev-medium{color:#d97706}
177
- .badge{display:inline-block;padding:2px 8px;border-radius:999px;font-size:12px;font-weight:600}
178
- .badge.pass{background:#dcfce7;color:#15803d}.badge.warn{background:#fef9c3;color:#a16207}
179
- .badge.fail{background:#fee2e2;color:#b91c1c}.badge.manual{background:#e2e8f0;color:#475569}
180
- .muted{color:var(--muted);font-size:13px}
181
- .ok{color:#15803d;font-weight:600}
182
- .migrate{margin:8px 0}
183
- footer{margin-top:36px;padding-top:16px;border-top:1px solid var(--line);color:var(--muted);font-size:12px}
184
- @media print{body{background:#fff}main{max-width:none;padding:0}h2{break-after:avoid}table{break-inside:auto}tr{break-inside:avoid}}
213
+ .meta code{background:#f1f5f9;padding:1px 6px;border-radius:5px;font-size:12px}
214
+ section,.reg{padding:0 36px}
215
+
216
+ /* Hero 评分 */
217
+ .hero{display:flex;gap:32px;align-items:center;margin:26px 36px;padding:26px 28px;
218
+ background:linear-gradient(135deg,#f8fafc,#f1f5f9);border:1px solid var(--line);border-radius:14px}
219
+ .gauge{--p:0;--c:#475569;flex:none;width:148px;height:148px;border-radius:50%;
220
+ background:conic-gradient(var(--c) calc(var(--p)*1%),#e4e9f1 0);
221
+ display:grid;place-items:center;box-shadow:inset 0 0 0 1px rgba(15,23,42,.04)}
222
+ .gauge-in{width:116px;height:116px;border-radius:50%;background:#fff;display:flex;flex-direction:column;
223
+ align-items:center;justify-content:center;box-shadow:0 2px 8px rgba(15,23,42,.08)}
224
+ .gscore{font-size:42px;font-weight:800;line-height:1;letter-spacing:-1px}
225
+ .gscore small{font-size:15px;font-weight:500;color:var(--faint)}
226
+ .ggrade{font-size:14px;font-weight:700;margin-top:6px}
227
+ .hero-side{flex:1;min-width:0}
228
+ .stat-row{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}
229
+ .stat{background:#fff;border:1px solid var(--line);border-radius:10px;padding:10px 12px;text-align:center}
230
+ .stat .sn{font-size:22px;font-weight:800;line-height:1}
231
+ .stat .sl{font-size:12px;color:var(--muted);margin-top:3px;white-space:nowrap}
232
+ .stat.pass .sn{color:var(--pass)}.stat.warn .sn{color:var(--warn)}
233
+ .stat.fail .sn{color:var(--fail)}.stat.manual .sn{color:var(--manual)}
234
+ .penalty{margin-top:12px;display:inline-block;background:var(--fail-bg);color:var(--fail);
235
+ font-size:12.5px;font-weight:600;padding:5px 12px;border-radius:8px}
236
+ .hero-note{margin:12px 0 0;font-size:12.5px;color:var(--muted);line-height:1.55}
237
+
238
+ /* 段标题 */
239
+ .shead{display:flex;align-items:baseline;gap:12px;margin:34px 36px 14px;
240
+ padding-bottom:10px;border-bottom:2px solid var(--line)}
241
+ .shead h2{font-size:18px;margin:0;font-weight:700}
242
+ .shead span{font-size:12.5px;color:var(--faint)}
243
+ .sub{font-size:14px;font-weight:700;color:var(--ink);margin:18px 36px 8px}
244
+ .sub .n{display:inline-block;background:#eef2f7;color:var(--muted);font-size:12px;
245
+ padding:0 8px;border-radius:999px;margin-left:4px;font-weight:600}
246
+ .empty{margin:8px 36px;padding:16px 18px;background:var(--pass-bg);color:var(--pass);
247
+ border-radius:10px;font-weight:600;font-size:14px}
248
+
249
+ /* chips 概览 */
250
+ .chips{display:flex;flex-wrap:wrap;gap:8px;margin:6px 36px 4px}
251
+ .chip{background:#f1f5f9;border:1px solid var(--line);border-radius:999px;
252
+ padding:5px 13px;font-size:13px;color:var(--muted)}
253
+ .chip b{color:var(--ink);font-size:14px;margin-right:2px}
254
+
255
+ /* 表格 */
256
+ .tbl{width:calc(100% - 72px);margin:4px 36px 6px;border-collapse:separate;border-spacing:0;font-size:13.5px}
257
+ .tbl td,.tbl th{padding:9px 12px;border-bottom:1px solid var(--line);vertical-align:top;text-align:left}
258
+ .tbl th{background:#f8fafc;color:var(--muted);font-weight:600;font-size:12.5px;
259
+ border-bottom:1px solid #e2e8f0}
260
+ .tbl tbody tr:hover{background:#fafbfd}
261
+ .tbl .right{text-align:right;white-space:nowrap}
262
+ .tbl .muted{color:var(--muted)}
263
+ .tbl .faint{color:var(--faint);font-size:13px}
264
+ .loc code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;
265
+ background:#f1f5f9;color:#0f172a;padding:2px 7px;border-radius:5px;white-space:nowrap}
266
+ .alts th:first-child,.alts td:first-child{width:120px}
267
+
268
+ /* severity 标签 */
269
+ .sev{display:inline-block;font-size:11.5px;font-weight:700;padding:2px 9px;border-radius:999px}
270
+ .sev.critical{background:#fee2e2;color:#b91c1c}
271
+ .sev.high{background:#ffedd5;color:#c2410c}
272
+ .sev.medium{background:#fef3c7;color:#b45309}
273
+
274
+ /* 状态药丸 */
275
+ .pill{display:inline-block;font-size:12px;font-weight:700;padding:3px 11px;border-radius:999px;white-space:nowrap}
276
+ .pill.pass{background:var(--pass-bg);color:var(--pass)}
277
+ .pill.warn{background:var(--warn-bg);color:var(--warn)}
278
+ .pill.fail{background:var(--fail-bg);color:var(--fail)}
279
+ .pill.manual{background:var(--manual-bg);color:var(--manual)}
280
+
281
+ /* 境内替代 */
282
+ .migrate{margin:6px 36px 10px;display:flex;flex-direction:column;gap:8px}
283
+ .mrow{display:flex;align-items:center;gap:12px;font-size:14px}
284
+ .mtag{font-size:12px;font-weight:600;padding:3px 10px;border-radius:8px}
285
+ .mtag.low{background:var(--pass-bg);color:var(--pass)}
286
+ .mtag.mid{background:var(--warn-bg);color:var(--warn)}
287
+ .note{margin:8px 36px 4px;font-size:12.5px;color:var(--muted);background:#f8fafc;
288
+ border-left:3px solid var(--brand);padding:10px 14px;border-radius:0 8px 8px 0}
289
+
290
+ /* 法规分组 */
291
+ .reg{margin:14px 36px;padding:0;border:1px solid var(--line);border-radius:12px;overflow:hidden}
292
+ .reg-head{display:flex;justify-content:space-between;align-items:center;
293
+ padding:11px 16px;background:#f8fafc;font-weight:700;font-size:14px;border-bottom:1px solid var(--line)}
294
+ .reg-mini{display:flex;align-items:center;gap:10px;font-size:13px;color:var(--muted);font-weight:600}
295
+ .reg-mini .d{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:4px;vertical-align:middle}
296
+ .reg-mini .d.pass{background:var(--pass)}.reg-mini .d.fail{background:var(--fail)}
297
+ .reg .tbl{width:100%;margin:0}
298
+ .reg .tbl td{padding:10px 16px}
299
+ .reg .tbl tr:last-child td{border-bottom:0}
300
+ .ctrl .st{width:78px}
301
+ .ctrl .ttl{width:210px}
302
+ .ctrl .ttl b{display:block;font-weight:600;font-size:13.5px}
303
+ .ctrl .art{display:block;color:var(--faint);font-size:11.5px;margin-top:2px}
304
+ .ctrl tr.fail{background:#fef6f6}
305
+
306
+ footer{margin-top:30px;padding:20px 36px 30px;border-top:1px solid var(--line);
307
+ color:var(--faint);font-size:11.5px;line-height:1.6;background:#fafbfd}
308
+
309
+ @media(max-width:640px){
310
+ main{margin:0;border-radius:0}
311
+ .hero{flex-direction:column;text-align:center;margin:18px}
312
+ .stat-row{grid-template-columns:repeat(2,1fr)}
313
+ section,.shead,.sub,.chips,.tbl,.migrate,.note,.reg{margin-left:16px;margin-right:16px}
314
+ .tbl{width:calc(100% - 32px)}
315
+ }
316
+ @media print{
317
+ body{background:#fff}
318
+ main{box-shadow:none;margin:0;max-width:none;border-radius:0}
319
+ .hero{background:#f8fafc}
320
+ .reg,.tbl tbody tr{break-inside:avoid}
321
+ h2,.shead{break-after:avoid}
322
+ }
185
323
  `;
@@ -0,0 +1,14 @@
1
+ export interface WebServerOptions {
2
+ port: number;
3
+ /** 本地模式:开放本地路径扫描、仅监听 127.0.0.1 */
4
+ local?: boolean;
5
+ }
6
+ /** 校验仓库 URL:仅允许白名单代码托管域名,拒绝带凭据/异常字符 */
7
+ export declare function validateRepoUrl(input: string): {
8
+ ok: true;
9
+ url: string;
10
+ } | {
11
+ ok: false;
12
+ reason: string;
13
+ };
14
+ export declare function startWebServer(opts: WebServerOptions): void;