dsh-skill-eval 0.0.0-stage → 1.20.2

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +675 -0
  2. package/LICENSE +21 -0
  3. package/README.md +200 -2
  4. package/README.zh.md +157 -0
  5. package/client.js +2637 -0
  6. package/cordis.patch.yml +9 -0
  7. package/docs/ACCEPTANCE.md +71 -0
  8. package/docs/AUDIT.md +64 -0
  9. package/docs/CODE-REVIEW.md +49 -0
  10. package/docs/COMPARISON.md +33 -0
  11. package/docs/DETAIL.md +463 -0
  12. package/docs/DEV-RELOAD.md +114 -0
  13. package/docs/ENTRYPOINTS.md +65 -0
  14. package/docs/RELEASE.md +44 -0
  15. package/docs/RRSI-NOTES.md +129 -0
  16. package/docs/SCENARIOS.md +91 -0
  17. package/docs/UI-REVIEW.md +115 -0
  18. package/docs/WORKFLOW.md +108 -0
  19. package/icon.svg +9 -0
  20. package/index.js +1111 -0
  21. package/lib/accept.js +350 -0
  22. package/lib/advice.js +547 -0
  23. package/lib/critic.js +101 -0
  24. package/lib/dev.js +148 -0
  25. package/lib/history.js +140 -0
  26. package/lib/html.js +8 -0
  27. package/lib/inspect.js +142 -0
  28. package/lib/integrity.js +46 -0
  29. package/lib/loop.js +195 -0
  30. package/lib/random.js +29 -0
  31. package/lib/recorder.js +634 -0
  32. package/lib/render.js +582 -0
  33. package/lib/report.js +646 -0
  34. package/lib/score.js +525 -0
  35. package/lib/settings.js +396 -0
  36. package/lib/snapshot.js +166 -0
  37. package/lib/steps.js +141 -0
  38. package/lib/store.js +186 -0
  39. package/lib/validity.js +115 -0
  40. package/locale/en.json +6 -0
  41. package/locale/zh.json +6 -0
  42. package/package.json +96 -4
  43. package/scripts/accept.mjs +226 -0
  44. package/scripts/build-client.mjs +59 -0
  45. package/scripts/build.mjs +81 -0
  46. package/scripts/doctor.mjs +199 -0
  47. package/scripts/lib.mjs +52 -0
  48. package/scripts/verify-live.mjs +168 -0
package/lib/render.js ADDED
@@ -0,0 +1,582 @@
1
+ /** Rendering helpers: markdown for the agent-facing tool, HTML for the web dashboard. */
2
+
3
+ import { localizeReport } from './advice.js'
4
+ import { buildLoopPlans } from './loop.js'
5
+ import { escapeHtml as esc } from './html.js'
6
+
7
+ function bar(value, width = 10) {
8
+ if (!Number.isFinite(value)) return '·'.repeat(width)
9
+ const filled = Math.round((Math.max(0, Math.min(100, value)) / 100) * width)
10
+ return '█'.repeat(filled) + '░'.repeat(width - filled)
11
+ }
12
+
13
+ function fmt(x, digits = 1) {
14
+ return x === null || x === undefined || !Number.isFinite(x) ? '—' : Number(x).toFixed(digits)
15
+ }
16
+
17
+ function pct(x) {
18
+ return x === null || x === undefined ? '—' : `${Math.round(x * 100)}%`
19
+ }
20
+
21
+ const SEV_ICON = { critical: '🛑', warning: '⚠️', info: 'ℹ️' }
22
+
23
+ export function renderMcpMarkdown(report) {
24
+ const rows = report.mcpServers ?? []
25
+ const lines = ['## MCP servers', '']
26
+ if (rows.length === 0) {
27
+ lines.push('No MCP calls recorded yet. MCP tools reach the model as `mcp__<server>__<tool>`.')
28
+ return lines.join('\n')
29
+ }
30
+ lines.push('| server | health | grade | calls | errors | error rate | p50 | p95 |')
31
+ lines.push('|---|---|---|---|---|---|---|---|')
32
+ for (const row of rows) {
33
+ lines.push(
34
+ `| \`${row.server}\` | ${fmt(row.health)} | **${row.grade}** | ${row.calls} | ${row.errors} | ${pct(row.errorRate)} | ${
35
+ row.p50Ms === null ? '—' : `${row.p50Ms}ms`
36
+ } | ${row.p95Ms === null ? '—' : `${row.p95Ms}ms`} |`,
37
+ )
38
+ }
39
+ const advice = report.mcpAdvice ?? []
40
+ if (advice.length > 0) {
41
+ lines.push('')
42
+ lines.push('### MCP fixes')
43
+ lines.push('')
44
+ for (const item of advice.slice(0, 6)) {
45
+ lines.push(`${SEV_ICON[item.severity] ?? '•'} **${item.title}** — ${item.evidence}`)
46
+ lines.push(` ↳ fix: ${item.fix}`)
47
+ }
48
+ }
49
+
50
+ const failing = rows.flatMap((row) =>
51
+ row.tools.filter((tool) => tool.errors > 0).map((tool) => ({ server: row.server, ...tool })),
52
+ )
53
+ if (failing.length > 0) {
54
+ lines.push('')
55
+ lines.push('### Tools with errors')
56
+ lines.push('')
57
+ for (const tool of failing.slice(0, 8)) {
58
+ lines.push(
59
+ `- \`${tool.server}/${tool.tool}\` — ${tool.errors}/${tool.calls} failed (${pct(tool.errorRate)}) · p95 ${
60
+ tool.p95Ms === null || tool.p95Ms === undefined ? '—' : `${tool.p95Ms}ms`
61
+ }`,
62
+ )
63
+ }
64
+ }
65
+ const slow = rows
66
+ .flatMap((row) =>
67
+ row.tools
68
+ .filter((tool) => typeof tool.p95Ms === 'number' && tool.p95Ms > 3000)
69
+ .map((tool) => ({ server: row.server, ...tool })),
70
+ )
71
+ .sort((a, b) => b.p95Ms - a.p95Ms)
72
+ if (slow.length > 0) {
73
+ lines.push('')
74
+ lines.push('### Slowest tools (p95)')
75
+ lines.push('')
76
+ for (const tool of slow.slice(0, 8)) {
77
+ lines.push(
78
+ `- \`${tool.server}/${tool.tool}\` — p50 ${tool.p50Ms ?? '—'}ms · p95 ${tool.p95Ms}ms · ${tool.calls} call(s)`,
79
+ )
80
+ }
81
+ }
82
+ return lines.join('\n')
83
+ }
84
+
85
+ export function renderRunsMarkdown(report) {
86
+ const rows = report.runs ?? []
87
+ const lines = ['## Recent runs', '']
88
+ if (rows.length === 0) {
89
+ lines.push('No runs recorded yet.')
90
+ return lines.join('\n')
91
+ }
92
+ lines.push('| session | score | grade | confidence | loads | calls | errors | corrections | mcp | skills |')
93
+ lines.push('|---|---|---|---|---|---|---|---|---|---|')
94
+ for (const run of rows.slice(0, 12)) {
95
+ lines.push(
96
+ `| \`${run.sessionId.slice(-8)}\` | ${fmt(run.score?.total)}${
97
+ run.score?.ci ? ` (${fmt(run.score.ci.low, 0)}–${fmt(run.score.ci.high, 0)})` : ''
98
+ } | **${run.score?.grade ?? '—'}** | ${
99
+ run.score?.confidence ?? '—'
100
+ } | ${run.loads} | ${run.toolCalls} | ${run.errors} | ${run.corrections} | ${run.mcpCalls}/${run.mcpErrors} | ${run.skills
101
+ .slice(0, 3)
102
+ .map((s) => `\`${s}\``)
103
+ .join(', ')} |`,
104
+ )
105
+ }
106
+ return lines.join('\n')
107
+ }
108
+
109
+ export function renderStandardMarkdown(report) {
110
+ const scoring = report.scoring ?? {}
111
+ const weights = scoring.weightsPercent ?? {}
112
+ const th = scoring.thresholds ?? {}
113
+ return [
114
+ '## Grading standard',
115
+ '',
116
+ `- weights: static ${weights.static ?? '—'} · reliability ${weights.reliability ?? '—'} · effectiveness ${
117
+ weights.effectiveness ?? '—'
118
+ } · efficiency ${weights.efficiency ?? '—'} (normalised to 100%)`,
119
+ `- grade floors: A≥${th.excellent ?? 90} · B≥${th.good ?? 80} · C≥${th.pass ?? 70} · D≥60 · F<60`,
120
+ `- minimum samples before a score stops being provisional: ${scoring.minSamples ?? '—'}`,
121
+ '',
122
+ 'Change them in the plugin config; a weight of 0 drops that dimension.',
123
+ '',
124
+ '```yaml',
125
+ 'config:',
126
+ ` weights: {static: ${weights.static ?? 30}, reliability: ${weights.reliability ?? 25}, effectiveness: ${
127
+ weights.effectiveness ?? 30
128
+ }, efficiency: ${weights.efficiency ?? 15}}`,
129
+ ` thresholds: {excellent: ${th.excellent ?? 90}, good: ${th.good ?? 80}, pass: ${th.pass ?? 70}}`,
130
+ ` minSamples: ${scoring.minSamples ?? 3}`,
131
+ '```',
132
+ '',
133
+ 'Paste that block into the profile entry for `dsh-skill-eval` (Plugins → Skill eval → config),',
134
+ 'or add it under the matching `id` in the profile `cordis.patch.yml`.',
135
+ ].join('\n')
136
+ }
137
+
138
+ export function renderSummaryMarkdown(report) {
139
+ const lines = []
140
+ lines.push('## Skill execution report')
141
+ lines.push('')
142
+ lines.push(
143
+ `recorded **${report.totals.invocations}** skill load(s) across **${report.totals.skills}** skill(s) · ${report.totals.closed} closed window(s) · data: \`${report.dataDir}\``,
144
+ )
145
+ lines.push('')
146
+ if (report.skills.length === 0) {
147
+ lines.push('No skill loads recorded yet. The plugin only sees loads that go through the `skill` tool.')
148
+ return lines.join('\n')
149
+ }
150
+ lines.push('| skill | score | grade | static | reliab. | effect. | effic. | loads | corr. | abandon |')
151
+ lines.push('|---|---|---|---|---|---|---|---|---|---|')
152
+ for (const s of report.skills) {
153
+ lines.push(
154
+ `| \`${s.skill}\` | ${fmt(s.score.total)}${s.score.provisional ? '*' : ''}${
155
+ s.score.ci ? ` (${fmt(s.score.ci.low, 0)}–${fmt(s.score.ci.high, 0)})` : ''
156
+ } | **${s.score.grade}** | ${fmt(
157
+ s.score.dimensions.static,
158
+ )} | ${fmt(s.score.dimensions.reliability)} | ${fmt(s.score.dimensions.effectiveness)} | ${fmt(
159
+ s.score.dimensions.efficiency,
160
+ )} | ${s.stats.loads} | ${pct(s.stats.correctionRate)} | ${pct(s.stats.abandonRate)} |`,
161
+ )
162
+ }
163
+ lines.push('')
164
+ if (report.scoring) {
165
+ const pctWeights = report.scoring.weightsPercent || {}
166
+ const th = report.scoring.thresholds || {}
167
+ lines.push(
168
+ `scoring: static ${pctWeights.static ?? '—'} · reliability ${pctWeights.reliability ?? '—'} · effectiveness ${
169
+ pctWeights.effectiveness ?? '—'
170
+ } · efficiency ${pctWeights.efficiency ?? '—'} | A≥${th.excellent ?? 90} B≥${th.good ?? 80} C≥${th.pass ?? 70}`,
171
+ )
172
+ lines.push('')
173
+ }
174
+ lines.push('`*` = provisional (fewer loads than the configured minimum).')
175
+ if (report.ranking && report.ranking.note) {
176
+ lines.push('')
177
+ lines.push(`> ${report.ranking.note}`)
178
+ }
179
+ lines.push('')
180
+ if ((report.mcpServers ?? []).length > 0) {
181
+ lines.push('### MCP servers')
182
+ lines.push('')
183
+ lines.push('| server | health | grade | calls | errors | p50 | p95 |')
184
+ lines.push('|---|---|---|---|---|---|---|')
185
+ for (const row of report.mcpServers) {
186
+ lines.push(
187
+ `| \`${row.server}\` | ${fmt(row.health)} | **${row.grade}** | ${row.calls} | ${pct(row.errorRate)} | ${
188
+ row.p50Ms === null ? '—' : `${row.p50Ms}ms`
189
+ } | ${row.p95Ms === null ? '—' : `${row.p95Ms}ms`} |`,
190
+ )
191
+ }
192
+ for (const item of (report.mcpAdvice ?? []).slice(0, 4)) {
193
+ lines.push(`${SEV_ICON[item.severity] ?? '•'} ${item.title} — ${item.evidence}`)
194
+ }
195
+ lines.push('')
196
+ }
197
+
198
+ if ((report.runs ?? []).length > 0) {
199
+ lines.push('### Recent runs')
200
+ lines.push('')
201
+ lines.push('| session | score | grade | loads | calls | errors | corrections | skills |')
202
+ lines.push('|---|---|---|---|---|---|---|---|')
203
+ for (const run of report.runs.slice(0, 8)) {
204
+ lines.push(
205
+ `| \`${run.sessionId.slice(-8)}\` | ${fmt(run.score?.total)} | **${run.score?.grade ?? '—'}** | ${run.loads} | ${
206
+ run.toolCalls
207
+ } | ${run.errors} | ${run.corrections} | ${run.skills
208
+ .slice(0, 3)
209
+ .map((s) => `\`${s}\``)
210
+ .join(', ')} |`,
211
+ )
212
+ }
213
+ lines.push('')
214
+ }
215
+
216
+ const flagged = report.skills.filter((s) => s.topAdvice.length > 0).slice(0, 5)
217
+ if (flagged.length > 0) {
218
+ lines.push('### Highest-value fixes')
219
+ lines.push('')
220
+ for (const s of flagged) {
221
+ lines.push(`**\`${s.skill}\`** — ${fmt(s.score.total)}/100 (${s.score.grade})`)
222
+ if (typeof s.adviceBudget === 'number') {
223
+ lines.push(`_edit budget: ${s.adviceBudget} concurrent change(s) this round_`)
224
+ }
225
+ if (s.exploration) {
226
+ lines.push(`_exploration: ${s.exploration.reason} → next change should target \`${s.exploration.suggestion}\`_`)
227
+ }
228
+ for (const a of s.topAdvice) {
229
+ lines.push(`${SEV_ICON[a.severity] ?? '•'} **${a.title}** — ${a.evidence}`)
230
+ lines.push(` ↳ fix: ${a.fix}`)
231
+ }
232
+ lines.push('')
233
+ }
234
+ }
235
+ return lines.join('\n')
236
+ }
237
+
238
+ export function renderSkillMarkdown(entry) {
239
+ const lines = []
240
+ lines.push(`## \`${entry.skill}\` — ${fmt(entry.score.total)}/100 (${entry.score.grade})`)
241
+ lines.push('')
242
+ if (entry.score.ci) {
243
+ lines.push(
244
+ `95% confidence interval: **${fmt(entry.score.ci.low)} – ${fmt(entry.score.ci.high)}** (${entry.score.ci.resamples} bootstrap resamples over ${entry.score.samples} load(s))`,
245
+ )
246
+ }
247
+ if (entry.score.provisional) lines.push('> provisional score: not enough recorded loads yet')
248
+ lines.push('')
249
+ lines.push(`static quality ${bar(entry.score.dimensions.static)} ${fmt(entry.score.dimensions.static)}`)
250
+ lines.push(`reliability ${bar(entry.score.dimensions.reliability)} ${fmt(entry.score.dimensions.reliability)}`)
251
+ lines.push(
252
+ `effectiveness ${bar(entry.score.dimensions.effectiveness)} ${fmt(entry.score.dimensions.effectiveness)}`,
253
+ )
254
+ lines.push(`efficiency ${bar(entry.score.dimensions.efficiency)} ${fmt(entry.score.dimensions.efficiency)}`)
255
+ lines.push('')
256
+ lines.push('### measured')
257
+ lines.push('')
258
+ lines.push(`- loads: ${entry.stats.loads} (${entry.stats.closed} closed window(s), ${entry.stats.open} open)`)
259
+ lines.push(`- load success: ${pct(entry.stats.loadOkRate)}`)
260
+ lines.push(`- tool calls in window: ${entry.stats.toolCalls} total, avg ${fmt(entry.stats.avgCalls)}`)
261
+ lines.push(`- post-load tool error rate: ${pct(entry.stats.errRate)}`)
262
+ lines.push(`- user correction rate: ${pct(entry.stats.correctionRate)}`)
263
+ lines.push(`- ignored-after-load rate: ${pct(entry.stats.abandonRate)}`)
264
+ lines.push(`- sibling skill loaded in same window: ${pct(entry.stats.siblingRate)}`)
265
+ lines.push(`- median load time: ${fmt(entry.stats.p50LoadMs, 0)} ms`)
266
+ if (entry.staticQuality) {
267
+ lines.push('')
268
+ lines.push(
269
+ `### authoring (static ${fmt(entry.staticQuality.score)}/100, ${entry.staticQuality.bodyLines} body lines, ${entry.staticQuality.source ?? 'unknown source'})`,
270
+ )
271
+ for (const c of entry.staticQuality.checks ?? []) {
272
+ if (c.fraction >= 1) continue
273
+ lines.push(`- ✗ ${c.label} (${c.points}/${c.weight})`)
274
+ }
275
+ }
276
+ lines.push('')
277
+ lines.push('### advice')
278
+ lines.push('')
279
+ if (entry.advice.length === 0) lines.push('Nothing to fix from the recorded evidence.')
280
+ for (const a of entry.advice) {
281
+ lines.push(`${SEV_ICON[a.severity] ?? '•'} **[${a.severity}] ${a.title}** (${a.dimension})`)
282
+ lines.push(` evidence: ${a.evidence}`)
283
+ lines.push(` fix: ${a.fix}`)
284
+ }
285
+ return lines.join('\n')
286
+ }
287
+
288
+ // ---------------------------------------------------------------------------
289
+ // HTML dashboard
290
+ // ---------------------------------------------------------------------------
291
+
292
+ function scoreColor(v) {
293
+ if (!Number.isFinite(v)) return '#666'
294
+ if (v >= 90) return '#2f9e44'
295
+ if (v >= 80) return '#5c9e2f'
296
+ if (v >= 70) return '#c9a227'
297
+ if (v >= 60) return '#d97706'
298
+ return '#c92a2a'
299
+ }
300
+
301
+ function adviceBlock(title, items) {
302
+ const list = Array.isArray(items) ? items : []
303
+ if (list.length === 0) return ''
304
+ const rows = list
305
+ .slice(0, 6)
306
+ .map(
307
+ (item) =>
308
+ `<li style="border-left:3px solid ${item.severity === 'critical' ? 'var(--dsw-alias-state-error-primary, #c92a2a)' : 'var(--dsw-alias-state-warn-primary, #d97706)'};padding-left:9px;margin-bottom:8px"><b>${esc(
309
+ item.title,
310
+ )}</b><div class="sub">${esc(item.evidence)}</div><div>↳ ${esc(item.fix)}</div></li>`,
311
+ )
312
+ .join('')
313
+ return `<section class="block"><h2>${esc(title)}</h2><ul style="list-style:none;padding:0;margin:0;font-size:12px">${rows}</ul></section>`
314
+ }
315
+
316
+ function tableSection(title, headers, rows) {
317
+ if (rows.length === 0) return ''
318
+ const head = headers.map((h) => `<th>${esc(h)}</th>`).join('')
319
+ const body = rows
320
+ .map(
321
+ (cells) =>
322
+ `<tr>${cells.map((cell, index) => `<td${index === 0 ? ' class="first"' : ''}>${cell}</td>`).join('')}</tr>`,
323
+ )
324
+ .join('')
325
+ return `<section class="block"><h2>${esc(title)}</h2><table><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table></section>`
326
+ }
327
+
328
+ /** Pick a language from an explicit ?lang=, then Accept-Language, defaulting to English. */
329
+ export function resolveLang(acceptLanguage, explicit) {
330
+ const explicitLang = typeof explicit === 'string' ? explicit.toLowerCase() : ''
331
+ if (explicitLang.startsWith('zh')) return 'zh'
332
+ if (explicitLang.startsWith('en')) return 'en'
333
+ const header = typeof acceptLanguage === 'string' ? acceptLanguage.toLowerCase() : ''
334
+ if (header.includes('zh')) return 'zh'
335
+ if (header.includes('en')) return 'en'
336
+ return 'en'
337
+ }
338
+
339
+ const BOARD = {
340
+ en: {
341
+ lang: 'en',
342
+ title: 'Skill execution report',
343
+ config: '⚙ Settings',
344
+ scoring: 'scoring',
345
+ loadsLine: (r) =>
346
+ `${r.totals.invocations} load(s) · ${r.totals.skills} skill(s) · ${r.totals.closed} closed window(s) · generated ${r.generatedAt}`,
347
+ noSkills: 'No skill loads recorded yet.',
348
+ dims: { static: 'static', reliability: 'reliability', effectiveness: 'effectiveness', efficiency: 'efficiency' },
349
+ meta: (s) =>
350
+ `${s.stats.loads} load(s) · corr ${pct(s.stats.correctionRate)} · abandon ${pct(s.stats.abandonRate)} · err ${pct(
351
+ s.stats.errRate,
352
+ )} · ${fmt(s.stats.p50LoadMs, 0)}ms`,
353
+ noIssues: 'no issues from recorded evidence',
354
+ nextTitle: 'Next steps (ranked by expected gain / effort)',
355
+ priority: 'priority',
356
+ budget: 'budget',
357
+ nextEmpty: 'No skill currently has an actionable fix within budget.',
358
+ evidenceTitle: 'What the evidence supports',
359
+ coverage: (v) =>
360
+ `coverage: ${v.coverage.skills} skill(s) · ${v.coverage.withCI} with 95% intervals · ${v.coverage.provisional} provisional · ranking ${
361
+ v.ranking.significant ? 'significant' : 'not significant'
362
+ }`,
363
+ canSay: 'Can say',
364
+ cannotSay: 'Cannot say yet',
365
+ ledgerTitle: 'Screened edits',
366
+ ledgerHead: ['at', 'skill', 'dimension', 'verdict', 'hypothesis'],
367
+ mcpTitle: 'MCP servers',
368
+ mcpHead: ['server', 'health', 'grade', 'calls', 'errors', 'p50', 'p95'],
369
+ mcpFixes: 'MCP fixes',
370
+ runsTitle: 'Recent runs',
371
+ runsHead: ['session', 'score', 'grade', 'loads', 'calls', 'errors', 'corrections', 'skills'],
372
+ toggle: (other, label) => `<a href="?lang=${other}">${label}</a>`,
373
+ },
374
+ zh: {
375
+ lang: 'zh',
376
+ title: '技能执行报告',
377
+ config: '⚙ 配置',
378
+ scoring: '评分',
379
+ loadsLine: (r) =>
380
+ `${r.totals.invocations} 次加载 · ${r.totals.skills} 个技能 · ${r.totals.closed} 个已结算窗口 · 生成于 ${r.generatedAt}`,
381
+ noSkills: '还没有记录到技能加载。',
382
+ dims: { static: '静态质量', reliability: '可靠性', effectiveness: '有效性', efficiency: '效率' },
383
+ meta: (s) =>
384
+ `${s.stats.loads} 次加载 · 纠正 ${pct(s.stats.correctionRate)} · 忽略 ${pct(s.stats.abandonRate)} · 报错 ${pct(
385
+ s.stats.errRate,
386
+ )} · ${fmt(s.stats.p50LoadMs, 0)}ms`,
387
+ noIssues: '按现有证据没有需要修的问题',
388
+ nextTitle: '下一步(按预期收益 / 成本排序)',
389
+ priority: '优先级',
390
+ budget: '预算',
391
+ nextEmpty: '当前没有在预算内有可行动修复的技能。',
392
+ evidenceTitle: '证据能支持什么',
393
+ coverage: (v) =>
394
+ `覆盖:${v.coverage.skills} 个技能 · ${v.coverage.withCI} 个有 95% 区间 · ${v.coverage.provisional} 个临时分 · 排名${
395
+ v.ranking.significant ? '显著' : '不显著'
396
+ }`,
397
+ canSay: '可以断言',
398
+ cannotSay: '还不能断言',
399
+ ledgerTitle: '已审查的改动',
400
+ ledgerHead: ['时间', '技能', '维度', '裁决', '假设'],
401
+ mcpTitle: 'MCP 服务器',
402
+ mcpHead: ['服务器', '健康度', '等级', '调用', '错误', 'p50', 'p95'],
403
+ mcpFixes: 'MCP 修复建议',
404
+ runsTitle: '最近运行',
405
+ runsHead: ['会话', '评分', '等级', '加载', '调用', '错误', '纠正', '技能'],
406
+ toggle: (other, label) => `<a href="?lang=${other}">${label}</a>`,
407
+ },
408
+ }
409
+
410
+ export function renderHtml(input, options = {}) {
411
+ const lang = options.lang === 'zh' ? 'zh' : 'en'
412
+ const report = localizeReport(input, lang)
413
+ const t = BOARD[lang]
414
+ const rows = report.skills
415
+ .map((s) => {
416
+ const d = s.score.dimensions
417
+ const cells = [
418
+ ['static', d.static],
419
+ ['reliability', d.reliability],
420
+ ['effectiveness', d.effectiveness],
421
+ ['efficiency', d.efficiency],
422
+ ]
423
+ .map(
424
+ ([label, v]) =>
425
+ `<div class="dim"><span>${esc(t.dims[label] ?? label)}</span><i style="width:${Number.isFinite(v) ? Math.max(0, Math.min(100, v)) : 0}%;background:${scoreColor(v)}"></i><b>${fmt(v)}</b></div>`,
426
+ )
427
+ .join('')
428
+ const advice = s.advice
429
+ .slice(0, 4)
430
+ .map(
431
+ (a) =>
432
+ `<li class="sev-${esc(a.severity)}"><b>${esc(a.title)}</b><span>${esc(a.evidence)}</span><em>${esc(a.fix)}</em></li>`,
433
+ )
434
+ .join('')
435
+ return `<article class="card">
436
+ <header>
437
+ <div class="name">${esc(s.skill)}</div>
438
+ <div class="grade" style="color:${scoreColor(s.score.total)}">${esc(s.score.grade)}</div>
439
+ <div class="total" style="color:${scoreColor(s.score.total)}">${fmt(s.score.total)}${s.score.provisional ? '<sup>*</sup>' : ''}</div>
440
+ </header>
441
+ <div class="dims">${cells}</div>
442
+ <div class="meta">${esc(t.meta(s))}</div>
443
+ ${advice ? `<ul class="advice">${advice}</ul>` : `<div class="meta">${esc(t.noIssues)}</div>`}
444
+ </article>`
445
+ })
446
+ .join('\n')
447
+
448
+ const validity = report.validity ?? null
449
+ const plans = buildLoopPlans(report, { editBudgetMax: report.scoring?.editBudgetMax ?? 4 }).slice(0, 3)
450
+ const nextSteps = plans.length
451
+ ? `<div class="block"><h2>${esc(t.nextTitle)}</h2><ol class="steps">${plans
452
+ .map(
453
+ (plan) =>
454
+ `<li><b>${esc(plan.skill)}</b> — ${esc(t.priority)} ${plan.priority?.score ?? '—'} · ${esc(t.budget)} ${plan.budget}<br><span>${esc(
455
+ plan.chosen[0]?.title ?? '',
456
+ )}</span> <em>${esc(plan.chosen[0]?.fix ?? '')}</em></li>`,
457
+ )
458
+ .join('')}</ol></div>`
459
+ : `<div class="block"><h2>${esc(t.nextTitle)}</h2><div class="sub">${esc(t.nextEmpty)}</div></div>`
460
+ const evidence = validity
461
+ ? `<div class="block"><h2>${esc(t.evidenceTitle)}</h2>
462
+ <div class="sub">${esc(t.coverage(validity))}</div>
463
+ <ul class="evidence"><li><b>${esc(t.canSay)}</b><ul>${validity.canSay.map((line) => `<li>${esc(line)}</li>`).join('')}</ul></li>
464
+ <li><b>${esc(t.cannotSay)}</b><ul>${validity.cannotSay.map((line) => `<li>${esc(line)}</li>`).join('')}</ul></li></ul></div>`
465
+ : ''
466
+ const editRows = (report.edits ?? [])
467
+ .slice(0, 8)
468
+ .map((edit) => [
469
+ esc(
470
+ Number.isFinite(Number(edit.at)) ? new Date(Number(edit.at)).toISOString().replace('T', ' ').slice(0, 19) : '—',
471
+ ),
472
+ esc(edit.skill ?? ''),
473
+ esc(edit.dimension ?? '—'),
474
+ `<b>${esc(edit.verdict ?? '')}</b>`,
475
+ esc((edit.hypothesis ?? '').slice(0, 70)),
476
+ ])
477
+ const ledgerBlock = tableSection(t.ledgerTitle, t.ledgerHead, editRows)
478
+ const otherLang = lang === 'zh' ? 'en' : 'zh'
479
+ const toggle = options.base
480
+ ? `<div class="sub">${t.config ? `<a href="${esc(options.base)}/config">${esc(t.config)}</a> · ` : ''}${t.toggle(
481
+ otherLang,
482
+ otherLang === 'zh' ? '中文' : 'English',
483
+ )}</div>`
484
+ : ''
485
+ const scoringLine = report.scoring
486
+ ? `${t.scoring}: ${Object.entries(report.scoring.weightsPercent || {})
487
+ .map(([k, v]) => `${k} ${v}`)
488
+ .join(' · ')} | A≥${report.scoring.thresholds?.excellent ?? 90} B≥${report.scoring.thresholds?.good ?? 80} C≥${
489
+ report.scoring.thresholds?.pass ?? 70
490
+ }`
491
+ : ''
492
+
493
+ return `<!doctype html>
494
+ <html lang="${t.lang}"><head><meta charset="utf-8">
495
+ <meta name="viewport" content="width=device-width,initial-scale=1">
496
+ <title>Skill eval</title>
497
+ <style>
498
+ :root{color-scheme:light dark}
499
+ body{margin:0;padding:28px;font:14px/1.55 ui-sans-serif,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;background:#fafafa;color:#18181b}
500
+ @media (prefers-color-scheme:dark){body{background:#111113;color:#e7e7ea}.card{background:#1a1a1e!important;border-color:#2a2a30!important}.meta{color:#8f8f9a}}
501
+ h1{font-size:19px;margin:0 0 4px}
502
+ .sub{color:#71717a;margin-bottom:22px;font-size:12px}
503
+ .grid{display:grid;gap:14px;grid-template-columns:repeat(auto-fill,minmax(360px,1fr))}
504
+ .card{background:#fff;border:1px solid #e5e5e9;border-radius:12px;padding:16px}
505
+ header{display:flex;align-items:center;gap:10px;margin-bottom:10px}
506
+ .name{font-weight:600;font-size:15px;flex:1;word-break:break-all}
507
+ .grade{font-weight:700;font-size:18px}
508
+ .total{font-variant-numeric:tabular-nums;font-weight:600}
509
+ .dims{display:grid;gap:5px;margin-bottom:10px}
510
+ .dim{display:grid;grid-template-columns:98px 1fr 38px;align-items:center;gap:8px;font-size:11px;color:#71717a}
511
+ .dim i{display:block;height:6px;border-radius:3px;background:#ddd;min-width:2px}
512
+ .dim b{text-align:right;font-variant-numeric:tabular-nums;color:#3f3f46}
513
+ @media (prefers-color-scheme:dark){.dim b{color:#c9c9d1}}
514
+ .meta{font-size:11px;color:#8f8f9a;margin-bottom:8px}
515
+ .advice{list-style:none;padding:0;margin:0;display:grid;gap:7px}
516
+ .advice li{font-size:12px;padding-left:9px;border-left:3px solid #d4d4d8}
517
+ .advice li b{display:block}
518
+ .advice li span{display:block;color:#71717a;font-size:11px}
519
+ .advice li em{display:block;font-style:normal;font-size:11px;color:#3f3f46;margin-top:2px}
520
+ .advice .sev-critical{border-color:#c92a2a}
521
+ .advice .sev-warning{border-color:#d97706}
522
+ .advice .sev-info{border-color:#3b82f6}
523
+ @media (prefers-color-scheme:dark){.advice li em{color:#c9c9d1}}
524
+ .block{margin-top:26px}
525
+ .block h2{font-size:14px;margin:0 0 8px}
526
+ .block table{border-collapse:collapse;width:100%;font-size:12px}
527
+ .block th{text-align:left;font-weight:600;color:#71717a;border-bottom:1px solid #e5e5e9;padding:6px 8px}
528
+ .block td{border-bottom:1px solid #f0f0f2;padding:6px 8px;font-variant-numeric:tabular-nums}
529
+ .block td.first{font-weight:600}
530
+ .steps{margin:0;padding-left:20px;display:grid;gap:10px;font-size:12px}
531
+ .steps b{font-weight:600}
532
+ .steps span{color:#3f3f46}
533
+ .steps em{font-style:normal;color:#71717a;font-size:11px;display:block;margin-top:2px}
534
+ .evidence{list-style:none;padding:0;margin:0;display:grid;gap:10px;font-size:12px}
535
+ .evidence > li > b{display:block;margin-bottom:3px}
536
+ .evidence ul{margin:0;padding-left:18px;color:#52525b;font-size:11.5px}
537
+ @media (prefers-color-scheme:dark){.steps span,.evidence ul{color:#c9c9d1}}
538
+ @media (prefers-color-scheme:dark){.block th{border-color:#2a2a30}.block td{border-color:#232329}}
539
+ </style></head>
540
+ <body>
541
+ <h1>${esc(t.title)}</h1>
542
+ ${toggle}
543
+ <div class="sub">${esc(scoringLine)}</div>
544
+ <div class="sub">${esc(t.loadsLine(report))} · <code>${esc(report.dataDir)}</code></div>
545
+ <div class="grid">
546
+ ${rows || `<div class="sub">${esc(t.noSkills)}</div>`}
547
+ </div>
548
+ ${nextSteps}
549
+ ${evidence}
550
+ ${ledgerBlock}
551
+ ${tableSection(
552
+ t.mcpTitle,
553
+ t.mcpHead,
554
+ (report.mcpServers ?? []).map((row) => [
555
+ esc(row.server),
556
+ fmt(row.health),
557
+ `<b style="color:${scoreColor(row.health)}">${esc(row.grade)}</b>`,
558
+ String(row.calls),
559
+ pct(row.errorRate),
560
+ row.p50Ms === null ? '—' : `${row.p50Ms}ms`,
561
+ row.p95Ms === null ? '—' : `${row.p95Ms}ms`,
562
+ ]),
563
+ )}
564
+ ${adviceBlock(t.mcpFixes, report.mcpAdvice)}
565
+ ${tableSection(
566
+ t.runsTitle,
567
+ t.runsHead,
568
+ (report.runs ?? [])
569
+ .slice(0, 12)
570
+ .map((run) => [
571
+ esc(run.sessionId.slice(-8)),
572
+ fmt(run.score?.total),
573
+ `<b style="color:${scoreColor(run.score?.total)}">${esc(run.score?.grade ?? '—')}</b>`,
574
+ String(run.loads),
575
+ String(run.toolCalls),
576
+ String(run.errors),
577
+ String(run.corrections),
578
+ esc(run.skills.slice(0, 3).join(', ')),
579
+ ]),
580
+ )}
581
+ </body></html>`
582
+ }