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/client.js ADDED
@@ -0,0 +1,2637 @@
1
+ /**
2
+ * GENERATED FILE — do not edit directly.
3
+ * Source: client/*.js · build: node scripts/build-client.mjs
4
+ */
5
+ window.__ModuleLoader__.load({
6
+ id: 'dsh-skill-eval',
7
+ factory(require) {
8
+
9
+ // client/01-runtime.js
10
+ const React = require('react')
11
+ const h = React.createElement
12
+ const { useEffect, useRef, useState, useSyncExternalStore } = React
13
+
14
+ const env = { locale: null }
15
+
16
+ // ---------------------------------------------------------------- store
17
+ function createStore(initial) {
18
+ let state = initial
19
+ const listeners = new Set()
20
+ return {
21
+ get: () => state,
22
+ set(next) {
23
+ state = typeof next === 'function' ? next(state) : next
24
+ for (const listener of [...listeners]) listener()
25
+ },
26
+ subscribe(listener) {
27
+ listeners.add(listener)
28
+ return () => listeners.delete(listener)
29
+ },
30
+ }
31
+ }
32
+
33
+ const store = createStore({ open: false, view: 'skills', loading: false, error: null, data: null, fetchedAt: 0 })
34
+ const useStore = () => useSyncExternalStore(store.subscribe, store.get, store.get)
35
+
36
+ // The in-conversation turn card is the product surface; the popup is an
37
+ // optional extra. Set `window.__SEV_ENABLE_POPUP__ = true` in the page (or
38
+ // flip the default here) to bring the sidebar button and modal back.
39
+ const ENABLE_POPUP = typeof window !== 'undefined' && window.__SEV_ENABLE_POPUP__ === true
40
+
41
+ // client/02-texts.js
42
+ // --------------------------------------------------------------- locale
43
+ const TEXTS = {
44
+ zh: {
45
+ open: '技能评测',
46
+ title: '技能评测',
47
+ subtitle: '每次 skill 加载之后真实发生了什么:加载成败、后续工具报错、用户有没有推翻、花了多少调用。',
48
+ refresh: '刷新',
49
+ close: '关闭',
50
+ copy: '复制给 agent',
51
+ copied: '已复制',
52
+ copyFailed: '复制失败',
53
+ loading: '正在读取遥测…',
54
+ empty: '还没有记录到技能加载。先用一次 skill 让插件收集数据。',
55
+ failed: '读取失败',
56
+ loads: '加载',
57
+ closed: '已结算',
58
+ corr: '纠正率',
59
+ err: '错误率',
60
+ latency: '加载耗时',
61
+ dims: { static: '静态质量', reliability: '可靠性', effectiveness: '有效性', efficiency: '效率' },
62
+ provisional: '样本不足,分数为临时值',
63
+ noAdvice: '没有需要修的问题',
64
+ footerHint: '也可以直接让 agent 调 skill_eval_report',
65
+ auto: '每 5 秒自动刷新',
66
+ turnLabel: '技能评测',
67
+ kpiSkills: '有遥测的技能',
68
+ kpiLoads: '累计加载',
69
+ kpiFixable: '有待修问题',
70
+ kpiAvg: '平均分',
71
+ searchPlaceholder: '搜索技能…',
72
+ onlyActionable: '仅看待修',
73
+ noMatch: '没有匹配的技能',
74
+ chartScoreDist: '分数分布',
75
+ chartValidity: '证据覆盖',
76
+ chartMcp: 'MCP 延迟',
77
+ chartSessions: '会话活动',
78
+ chartAvg: '均值',
79
+ chartTrend: '趋势',
80
+ chartP50: 'p50',
81
+ chartP95: 'p95',
82
+ chartThreshold: '阈值',
83
+ chartWithCI: '有区间',
84
+ chartProvisional: '临时分',
85
+ chartNoEvidence: '无区间',
86
+ chartActionable: '待修',
87
+ chartLoads: '加载',
88
+ chartCalls: '调用',
89
+ chartErrors: '错误',
90
+ chartSessionsUnit: '次会话',
91
+ noChartData: '暂无数据',
92
+ config: '配置',
93
+ updated: '更新',
94
+ turnCalls: '调用',
95
+ turnErrors: '错误',
96
+ turnNext: '下一步 · 可改',
97
+ tokPerLoad: 'tok/次加载',
98
+ devLoads: '次加载',
99
+ devClosed: '已结算',
100
+ devOpen: '未结算',
101
+ skillsWord: '个技能',
102
+ turnHistory: '改动记录',
103
+ detailSkills: '个技能有遥测',
104
+ detailActionable: '个有待修问题',
105
+ rowConfigSummary: '评分权重、阈值、预算与开关',
106
+ settingsLoading: '正在读取配置…',
107
+ settingsFailed: '读取配置失败',
108
+ settingsSave: '保存',
109
+ settingsSaving: '保存中…',
110
+ settingsSaved: '已保存并立即生效',
111
+ settingsOpenWeb: '在网页里打开',
112
+ settingsNeedsRestart: '当前宿主还是旧版本:重启 DeepSeek Harness 后这里会显示原生设置;也可以先打开网页配置页。',
113
+ storeError: '遥测写入失败',
114
+ turnDetail: '本轮详情',
115
+ noTurnAdvice: '本轮无待修问题',
116
+ tabs: { skills: '按技能', steps: '轨迹', runs: '按运行', mcp: 'MCP', dev: '开发者' },
117
+ stepKpiAvg: '步均分',
118
+ stepKpiLatest: '最近回合',
119
+ stepKpiCount: '已记录步数',
120
+ stepRecent: '近几次回合对比',
121
+ stepFilter: '按技能查看',
122
+ stepAll: '全部',
123
+ stepTurn: '回合',
124
+ stepStep: '步',
125
+ stepCalls: '调用',
126
+ stepErrors: '错误',
127
+ stepDuration: '耗时',
128
+ stepTokens: 'token',
129
+ stepNoData: '还没有逐步遥测:完成一个回合并刷新后自动出现。',
130
+ stepDelta: '较上回合',
131
+ stepFormula: '步分 = 100 − 工具错误×20 − 循环错误×35 − 超量调用×3',
132
+ stepTrace: '查看轨迹',
133
+ stepTurnAvg: '回合均分',
134
+ stepWorst: '最低',
135
+ stepBest: '最高',
136
+ stepFiltered: '只看该技能所在步',
137
+ stepNoSkill: '无技能加载',
138
+ runsHead: ['会话', '评分', '加载', '调用', '报错'],
139
+ mcpHead: ['服务器', '健康', '调用', '错误率', 'p50/p95'],
140
+ emptyRuns: '还没有运行记录',
141
+ emptyMcp: '还没有 MCP 调用记录',
142
+ mcpFailing: '出错的工具',
143
+ mcpFix: 'MCP 修复建议',
144
+ staleTitle: '当前 host 运行的是旧一代插件',
145
+ staleHint:
146
+ '数据里没有 scoring / ranking 字段,说明这个进程还在用升级前的模块。请重启 DeepSeek Harness(退出再打开),然后刷新本页。',
147
+ version: '插件版本',
148
+ devLabels: {
149
+ weights: '评分权重',
150
+ thresholds: '等级线',
151
+ minSamples: '最小样本',
152
+ dataDir: '数据目录',
153
+ api: '数据接口',
154
+ module: '模块 / 磁盘',
155
+ routes: '注册路由',
156
+ tools: '工具',
157
+ skew: '需要重启',
158
+ totals: '记录量',
159
+ store: '存储错误',
160
+ },
161
+ },
162
+ en: {
163
+ open: 'Skill eval',
164
+ title: 'Skill eval',
165
+ subtitle:
166
+ 'What really happened after each skill load: load success, follow-up tool errors, user pushback, and cost.',
167
+ refresh: 'Refresh',
168
+ close: 'Close',
169
+ copy: 'Copy for agent',
170
+ copied: 'Copied',
171
+ copyFailed: 'Copy failed',
172
+ loading: 'Reading telemetry…',
173
+ empty: 'No skill loads recorded yet. Load one skill to start collecting.',
174
+ failed: 'Read failed',
175
+ loads: 'loads',
176
+ closed: 'closed',
177
+ corr: 'corr',
178
+ err: 'err',
179
+ latency: 'load',
180
+ dims: { static: 'static', reliability: 'reliability', effectiveness: 'effectiveness', efficiency: 'efficiency' },
181
+ provisional: 'provisional score: not enough loads yet',
182
+ noAdvice: 'nothing to fix from recorded evidence',
183
+ footerHint: 'The agent can read the same report through skill_eval_report',
184
+ auto: 'auto-refresh every 5s',
185
+ turnLabel: 'Skill eval',
186
+ kpiSkills: 'skills with data',
187
+ kpiLoads: 'loads recorded',
188
+ kpiFixable: 'with a fix',
189
+ kpiAvg: 'average score',
190
+ searchPlaceholder: 'filter skills…',
191
+ onlyActionable: 'needs a fix',
192
+ noMatch: 'no skill matches the filter',
193
+ chartScoreDist: 'Score distribution',
194
+ chartValidity: 'Evidence coverage',
195
+ chartMcp: 'MCP latency',
196
+ chartSessions: 'Session activity',
197
+ chartAvg: 'avg',
198
+ chartTrend: 'trend',
199
+ chartP50: 'p50',
200
+ chartP95: 'p95',
201
+ chartThreshold: 'threshold',
202
+ chartWithCI: 'with CI',
203
+ chartProvisional: 'provisional',
204
+ chartNoEvidence: 'no interval',
205
+ chartActionable: 'to fix',
206
+ chartLoads: 'loads',
207
+ chartCalls: 'calls',
208
+ chartErrors: 'errors',
209
+ chartSessionsUnit: 'session(s)',
210
+ noChartData: 'no data yet',
211
+ config: 'Configure',
212
+ updated: 'updated',
213
+ turnCalls: 'calls',
214
+ turnErrors: 'err',
215
+ turnNext: 'next fix',
216
+ tokPerLoad: 'tok/load',
217
+ devLoads: 'loads',
218
+ devClosed: 'closed',
219
+ devOpen: 'open',
220
+ skillsWord: 'skills',
221
+ turnHistory: 'edit history',
222
+ detailSkills: 'skill(s) with telemetry',
223
+ detailActionable: 'with an actionable fix',
224
+ rowConfigSummary: 'Weights, thresholds, budgets and switches',
225
+ settingsLoading: 'loading settings…',
226
+ settingsFailed: 'failed to load settings',
227
+ settingsSave: 'Save',
228
+ settingsSaving: 'saving…',
229
+ settingsSaved: 'saved and applied',
230
+ settingsOpenWeb: 'Open in browser',
231
+ settingsNeedsRestart:
232
+ 'This host still runs an older generation: restart DeepSeek Harness to get the native settings page, or use the web page meanwhile.',
233
+ storeError: 'telemetry write failed',
234
+ turnDetail: 'details',
235
+ noTurnAdvice: 'nothing to fix in this turn',
236
+ tabs: { skills: 'Skills', steps: 'Steps', runs: 'Runs', mcp: 'MCP', dev: 'Dev' },
237
+ stepKpiAvg: 'step average',
238
+ stepKpiLatest: 'latest turn',
239
+ stepKpiCount: 'recorded steps',
240
+ stepRecent: 'Recent turns',
241
+ stepFilter: 'by skill',
242
+ stepAll: 'all',
243
+ stepTurn: 'turn',
244
+ stepStep: 'step',
245
+ stepCalls: 'calls',
246
+ stepErrors: 'errors',
247
+ stepDuration: 'duration',
248
+ stepTokens: 'tokens',
249
+ stepNoData: 'No step telemetry yet: finish a turn and refresh.',
250
+ stepDelta: 'vs previous turn',
251
+ stepFormula: 'step = 100 − tool errors×20 − loop errors×35 − call-volume×3',
252
+ stepTrace: 'view steps',
253
+ stepTurnAvg: 'turn average',
254
+ stepWorst: 'lowest',
255
+ stepBest: 'highest',
256
+ stepFiltered: 'steps that loaded this skill',
257
+ stepNoSkill: 'no skill loaded',
258
+ runsHead: ['session', 'score', 'loads', 'calls', 'errors'],
259
+ mcpHead: ['server', 'health', 'calls', 'errors', 'p50/p95'],
260
+ emptyRuns: 'no runs recorded yet',
261
+ emptyMcp: 'no MCP calls recorded yet',
262
+ mcpFailing: 'failing tools',
263
+ mcpFix: 'MCP fixes',
264
+ staleTitle: 'The running host serves an older plugin generation',
265
+ staleHint:
266
+ 'The payload has no scoring/ranking fields, so this process still runs the pre-upgrade module. Quit and reopen DeepSeek Harness, then reload this page.',
267
+ version: 'plugin version',
268
+ devLabels: {
269
+ weights: 'weights',
270
+ thresholds: 'grade bands',
271
+ minSamples: 'min samples',
272
+ dataDir: 'data dir',
273
+ api: 'data api',
274
+ module: 'module / disk',
275
+ routes: 'routes',
276
+ tools: 'tools',
277
+ skew: 'restart',
278
+ totals: 'records',
279
+ store: 'store error',
280
+ },
281
+ },
282
+ }
283
+
284
+ // Stable identities: a new subscribe function on every render makes
285
+ // useSyncExternalStore resubscribe each time (one pair per card before this).
286
+ const localeSubscribe = (onChange) =>
287
+ env.locale && typeof env.locale.subscribe === 'function' ? env.locale.subscribe(onChange) : () => {}
288
+ const localeSnapshot = () =>
289
+ env.locale && typeof env.locale.getSnapshot === 'function' ? env.locale.getSnapshot() : null
290
+ const localeServerSnapshot = () => null
291
+
292
+ function useLang() {
293
+ const snapshot = useSyncExternalStore(localeSubscribe, localeSnapshot, localeServerSnapshot)
294
+ const active = snapshot && snapshot.active ? String(snapshot.active) : 'zh'
295
+ const lang = active.toLowerCase().startsWith('zh') ? 'zh' : 'en'
296
+ return { lang, t: TEXTS[lang] }
297
+ }
298
+
299
+ // client/03-data.js
300
+ // ---------------------------------------------------------------- utils
301
+ // Keep in sync with package.json `version` (a test enforces it). The host
302
+ // registers this exact path per release, so a plugin that was hot-reloaded
303
+ // without reclaiming the canonical route still answers here.
304
+ const DATA_VERSION = '1.20.2'
305
+ const DATA_URL = '/skill-eval/data/' + DATA_VERSION
306
+ const DATA_URL_FALLBACK = '/skill-eval/data'
307
+ const SETTINGS_URL = '/skill-eval/settings/' + DATA_VERSION
308
+ const SETTINGS_URL_FALLBACK = '/skill-eval/settings'
309
+
310
+ function fmt(value, digits) {
311
+ return typeof value === 'number' && Number.isFinite(value) ? value.toFixed(digits === undefined ? 1 : digits) : '—'
312
+ }
313
+
314
+ function pct(value) {
315
+ return typeof value === 'number' && Number.isFinite(value) ? Math.round(value * 100) + '%' : '—'
316
+ }
317
+
318
+ function scoreColor(value) {
319
+ if (typeof value !== 'number' || !Number.isFinite(value)) return 'var(--dsw-alias-state-idle-primary, #a1a1aa)'
320
+ if (value >= 90) return 'var(--dsw-alias-state-success-primary, #2f9e44)'
321
+ if (value >= 70) return 'var(--dsw-alias-state-warn-primary, #d97706)'
322
+ return 'var(--dsw-alias-state-error-primary, #c92a2a)'
323
+ }
324
+
325
+ function severityColor(severity) {
326
+ if (severity === 'critical') return 'var(--dsw-alias-state-error-primary, #c92a2a)'
327
+ if (severity === 'warning') return 'var(--dsw-alias-state-warn-primary, #d97706)'
328
+ return 'var(--dsw-alias-brand-primary, #4d6bfe)'
329
+ }
330
+
331
+ async function fetchReport(url) {
332
+ const response = await fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store' })
333
+ if (!response.ok) {
334
+ const error = new Error('HTTP ' + response.status)
335
+ error.status = response.status
336
+ throw error
337
+ }
338
+ return response.json()
339
+ }
340
+
341
+ let loadInFlight = false
342
+ let loadGeneration = 0
343
+
344
+ function load() {
345
+ // Refresh can be clicked repeatedly and the popup polls; only one
346
+ // request may update the store, and only the newest request wins.
347
+ if (loadInFlight) return
348
+ loadInFlight = true
349
+ const generation = (loadGeneration += 1)
350
+ const finish = (patch) => {
351
+ if (generation !== loadGeneration) return
352
+ store.set((state) => ({ ...state, ...patch }))
353
+ }
354
+ store.set((state) => ({ ...state, loading: true, error: null }))
355
+ fetchReport(DATA_URL)
356
+ .catch((error) => {
357
+ // a host that predates the versioned alias (or a hot reload that kept
358
+ // the canonical route) still answers on the unversioned path
359
+ if (error && error.status === 404) return fetchReport(DATA_URL_FALLBACK)
360
+ throw error
361
+ })
362
+ .then((data) => {
363
+ finish({ loading: false, data, error: null, fetchedAt: Date.now() })
364
+ })
365
+ .catch((error) => {
366
+ finish({ loading: false, error: error && error.message ? error.message : String(error) })
367
+ })
368
+ .finally(() => {
369
+ if (generation === loadGeneration) loadInFlight = false
370
+ })
371
+ }
372
+
373
+ const REFRESH_MS = 5000
374
+
375
+ function ensureReport() {
376
+ const state = store.get()
377
+ if (state.loading) return
378
+ if (state.data && Date.now() - state.fetchedAt < 10000) return
379
+ load()
380
+ }
381
+
382
+ // Versioned aliases survive hot reloads where the canonical route is still
383
+ // owned by an older generation; both land on the same board.
384
+ const BOARD_URL = '/skill-eval/board/' + DATA_VERSION
385
+ const CONFIG_URL = BOARD_URL + '/config'
386
+
387
+ function boardUrl() {
388
+ try {
389
+ return window.location.origin + BOARD_URL
390
+ } catch {
391
+ return BOARD_URL
392
+ }
393
+ }
394
+
395
+ function openBoard() {
396
+ try {
397
+ window.open(boardUrl(), '_blank', 'noopener')
398
+ } catch {
399
+ // opening a tab is best effort; the link in the tooltip still works
400
+ }
401
+ }
402
+
403
+ function openReport() {
404
+ if (!ENABLE_POPUP) {
405
+ openBoard()
406
+ return
407
+ }
408
+ store.set((state) => ({ ...state, open: true }))
409
+ load()
410
+ }
411
+
412
+ function setView(view) {
413
+ store.set((state) => ({ ...state, view }))
414
+ }
415
+
416
+ function closeReport() {
417
+ store.set((state) => ({ ...state, open: false }))
418
+ }
419
+
420
+ function buildMarkdown(data) {
421
+ if (!data || !Array.isArray(data.skills) || data.skills.length === 0) return '# skill eval: no data'
422
+ const lines = ['# Skill eval report', '']
423
+ for (const skill of data.skills) {
424
+ const score = skill.score || {}
425
+ const dims = score.dimensions || {}
426
+ lines.push('## ' + skill.skill + ' — ' + fmt(score.total) + '/100 (' + (score.grade || '?') + ')')
427
+ lines.push(
428
+ '- static ' +
429
+ fmt(dims.static) +
430
+ ' · reliability ' +
431
+ fmt(dims.reliability) +
432
+ ' · effectiveness ' +
433
+ fmt(dims.effectiveness) +
434
+ ' · efficiency ' +
435
+ fmt(dims.efficiency),
436
+ )
437
+ const stats = skill.stats || {}
438
+ lines.push(
439
+ '- loads ' +
440
+ (stats.loads || 0) +
441
+ ' · closed ' +
442
+ (stats.closed || 0) +
443
+ ' · corrections ' +
444
+ pct(stats.correctionRate) +
445
+ ' · tool errors ' +
446
+ pct(stats.errRate) +
447
+ ' · load ' +
448
+ fmt(stats.p50LoadMs, 0) +
449
+ 'ms',
450
+ )
451
+ for (const item of (skill.advice || []).slice(0, 4)) {
452
+ lines.push('- [' + item.severity + '] ' + item.title + ' — ' + item.evidence)
453
+ lines.push(' fix: ' + item.fix)
454
+ }
455
+ lines.push('')
456
+ }
457
+ return lines.join('\n')
458
+ }
459
+
460
+ // client/04-components.js
461
+ // ------------------------------------------------------------- components
462
+ function GaugeIcon(props) {
463
+ const size = props?.size || 16
464
+ return h(
465
+ 'svg',
466
+ { viewBox: '0 0 24 24', width: size, height: size, fill: 'none', 'aria-hidden': true, style: { display: 'block' } },
467
+ h('path', {
468
+ d: 'M4 17a8 8 0 0 1 16 0',
469
+ stroke: 'currentColor',
470
+ strokeWidth: 2,
471
+ strokeLinecap: 'round',
472
+ }),
473
+ h('path', { d: 'M12 17l4.5-5.5', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }),
474
+ h('circle', { cx: 12, cy: 17, r: 1.6, fill: 'currentColor' }),
475
+ )
476
+ }
477
+
478
+ // client/05-settings.js
479
+ // ------------------------------------------------------------ settings
480
+ // Units ship in English from the settings API; the Chinese form localizes them.
481
+ const UNIT_ZH = { loads: '次加载', tokens: 'token', edits: '次修改' }
482
+ const unitLabel = (unit, lang) => (!unit ? '' : lang === 'zh' ? UNIT_ZH[unit] || unit : unit)
483
+
484
+ const settingsStore = createStore({ loading: false, saving: false, data: null, error: null, savedAt: 0 })
485
+ const useSettings = () => useSyncExternalStore(settingsStore.subscribe, settingsStore.get, settingsStore.get)
486
+
487
+ async function fetchSettings() {
488
+ settingsStore.set((state) => ({ ...state, loading: true, error: null }))
489
+ let response = await fetch(SETTINGS_URL, { headers: { accept: 'application/json' } })
490
+ if (response.status === 404)
491
+ response = await fetch(SETTINGS_URL_FALLBACK, { headers: { accept: 'application/json' } })
492
+ if (!response.ok) throw new Error('HTTP ' + response.status)
493
+ const type =
494
+ (response.headers && typeof response.headers.get === 'function' && response.headers.get('content-type')) || ''
495
+ if (type.indexOf('json') === -1) {
496
+ // The dashboard's stale prefix route answers HTML when this host still
497
+ // runs a generation from before the settings API existed.
498
+ throw new Error('host-too-old')
499
+ }
500
+ const data = await response.json()
501
+ settingsStore.set((state) => ({ ...state, loading: false, data }))
502
+ return data
503
+ }
504
+
505
+ async function saveSettings(values) {
506
+ settingsStore.set((state) => ({ ...state, saving: true, error: null }))
507
+ try {
508
+ const post = (url) =>
509
+ fetch(url, {
510
+ method: 'POST',
511
+ headers: { 'content-type': 'application/json', accept: 'application/json', 'x-skill-eval-config': '1' },
512
+ body: JSON.stringify(values),
513
+ })
514
+ let response = await post(SETTINGS_URL)
515
+ if (response.status === 404) response = await post(SETTINGS_URL_FALLBACK)
516
+ const payload = await response.json()
517
+ if (!response.ok || payload.saved !== true) {
518
+ settingsStore.set((state) => ({
519
+ ...state,
520
+ saving: false,
521
+ error: payload.errors?.[0]?.message ?? 'HTTP ' + response.status,
522
+ }))
523
+ return false
524
+ }
525
+ settingsStore.set((state) => ({
526
+ ...state,
527
+ saving: false,
528
+ data: { ...(state.data ?? {}), values: payload.values },
529
+ savedAt: Date.now(),
530
+ }))
531
+ return true
532
+ } catch (error) {
533
+ settingsStore.set((state) => ({
534
+ ...state,
535
+ saving: false,
536
+ error: error instanceof Error ? error.message : String(error),
537
+ }))
538
+ return false
539
+ }
540
+ }
541
+
542
+ function SettingsForm(props) {
543
+ const { lang, t } = useLang()
544
+ // The web config page is a second surface; inside the desktop shell
545
+ // window.open is denied, so the in-panel dialog hides the link it cannot honour.
546
+ const webOpen = !props || props.webOpen !== false
547
+ const state = useSettings()
548
+ const [draft, setDraft] = useState(null)
549
+ useEffect(() => {
550
+ let alive = true
551
+ fetchSettings().catch((error) => {
552
+ if (alive) settingsStore.set((current) => ({ ...current, loading: false, error: error.message }))
553
+ })
554
+ return () => {
555
+ alive = false
556
+ }
557
+ }, [])
558
+ const data = state.data
559
+ const values = draft ?? (data && data.values) ?? {}
560
+ const groups = data && data.fields ? groupSettingsFields(data.fields, lang) : []
561
+ const set = (key, value) => setDraft({ ...values, [key]: value })
562
+ const save = async () => {
563
+ const ok = await saveSettings(values)
564
+ if (ok) setDraft(null)
565
+ }
566
+ if (state.loading && !data) return h('div', { className: 'sev-settings' }, t.settingsLoading)
567
+ if (state.error && !data) {
568
+ const restart = state.error === 'host-too-old'
569
+ return h(
570
+ 'div',
571
+ { className: 'sev-settings' },
572
+ h('div', null, restart ? t.settingsNeedsRestart : t.settingsFailed + ': ' + state.error),
573
+ webOpen
574
+ ? h(
575
+ 'button',
576
+ {
577
+ type: 'button',
578
+ className: 'sev-btn',
579
+ onClick: () => window.open(window.location.origin + CONFIG_URL, '_blank', 'noopener'),
580
+ },
581
+ t.settingsOpenWeb,
582
+ )
583
+ : null,
584
+ )
585
+ }
586
+ return h(
587
+ 'div',
588
+ { className: 'sev-settings' },
589
+ h('style', { key: 'sev-settings-style' }, STYLES + '\n' + TURN_STYLES),
590
+ h('div', { className: 'sev-settings-heading' }, lang === 'zh' ? '评分配置' : 'Scoring settings'),
591
+ h(
592
+ 'div',
593
+ { className: 'sev-settings-sub' },
594
+ lang === 'zh'
595
+ ? webOpen
596
+ ? '保存后立即生效;网页配置页提供同一组字段。'
597
+ : '保存后立即生效。'
598
+ : webOpen
599
+ ? 'Saved values apply immediately; the web config page exposes the same fields.'
600
+ : 'Saved values apply immediately.',
601
+ ),
602
+ groups.map((group) =>
603
+ h(
604
+ 'div',
605
+ { className: 'sev-settings-group', key: group.title },
606
+ h('h4', null, group.title),
607
+ group.fields.map((field) =>
608
+ h(
609
+ 'div',
610
+ { className: 'sev-settings-row', key: field.key },
611
+ h(
612
+ 'div',
613
+ { className: 'sev-settings-label' },
614
+ h('span', null, lang === 'zh' ? field.labelZh || field.label : field.label),
615
+ (lang === 'zh' ? field.helpZh : field.help)
616
+ ? h('small', null, lang === 'zh' ? field.helpZh : field.help)
617
+ : null,
618
+ ),
619
+ field.type === 'boolean'
620
+ ? h(
621
+ 'label',
622
+ { className: 'sev-switch' },
623
+ h('input', {
624
+ type: 'checkbox',
625
+ checked: values[field.key] === true,
626
+ onChange: (event) => set(field.key, event.currentTarget.checked),
627
+ }),
628
+ h('i', { 'aria-hidden': 'true' }),
629
+ )
630
+ : h(
631
+ 'div',
632
+ { className: 'sev-settings-control' },
633
+ h('input', {
634
+ type: 'number',
635
+ min: field.min,
636
+ max: field.max,
637
+ step: field.step,
638
+ value: values[field.key] ?? '',
639
+ onChange: (event) => set(field.key, event.currentTarget.value),
640
+ }),
641
+ field.unit ? h('em', null, unitLabel(field.unit, lang)) : null,
642
+ ),
643
+ ),
644
+ ),
645
+ ),
646
+ ),
647
+ h(
648
+ 'div',
649
+ { className: 'sev-settings-actions' },
650
+ h(
651
+ 'button',
652
+ { type: 'button', className: 'sev-btn', disabled: state.saving, onClick: save },
653
+ state.saving ? t.settingsSaving : t.settingsSave,
654
+ ),
655
+ webOpen
656
+ ? h(
657
+ 'button',
658
+ {
659
+ type: 'button',
660
+ className: 'sev-btn sev-btn--ghost',
661
+ onClick: () => window.open(window.location.origin + CONFIG_URL, '_blank', 'noopener'),
662
+ },
663
+ t.settingsOpenWeb,
664
+ )
665
+ : null,
666
+ ),
667
+ state.savedAt ? h('div', { className: 'sev-settings-status' }, t.settingsSaved) : null,
668
+ state.error && data ? h('div', { className: 'sev-settings-status sev-error' }, state.error) : null,
669
+ )
670
+ }
671
+
672
+ function groupSettingsFields(fields, lang = 'zh') {
673
+ // The host ships group metadata with every field; the local classifier is
674
+ // only a fallback for an older payload (versioned routes keep old hosts
675
+ // alive after a hot reload).
676
+ const fallbackTitles =
677
+ lang === 'zh'
678
+ ? ['评分权重与阈值', '成本', '建议与生命周期', 'MCP', '输出']
679
+ : ['Scoring', 'Cost', 'Advice & lifecycle', 'MCP', 'Output']
680
+ const fallbackTitle = (field) =>
681
+ field.key.indexOf('weights.') === 0 || field.key.indexOf('thresholds.') === 0
682
+ ? fallbackTitles[0]
683
+ : ['tokenBudgetPerLoad', 'cacheReadWeight', 'countTokens'].includes(field.key)
684
+ ? fallbackTitles[1]
685
+ : ['mcpErrorRatePercent', 'mcpP95Ms'].includes(field.key)
686
+ ? fallbackTitles[3]
687
+ : ['promptHint', 'reportOnTurnEnd'].includes(field.key)
688
+ ? fallbackTitles[4]
689
+ : fallbackTitles[2]
690
+ const groups = new Map()
691
+ for (const field of fields) {
692
+ const title = field.group ? (lang === 'zh' ? field.groupZh || field.group : field.group) : fallbackTitle(field)
693
+ const list = groups.get(title) ?? []
694
+ list.push(field)
695
+ groups.set(title, list)
696
+ }
697
+ return [...groups.entries()].map(([title, list]) => ({ title, fields: list }))
698
+ }
699
+
700
+ /** Native seat: this plugin's row in Settings → Plugins gains a configure page. */
701
+ function RowConfig(props) {
702
+ const { t } = useLang()
703
+ const view = props && props.view
704
+ if (view === 'summary') return h('span', null, t.rowConfigSummary)
705
+ return h(SettingsForm, null)
706
+ }
707
+
708
+ // client/06-advice.js
709
+ // Chinese copy for rule-generated advice (host attaches titleZh/fixZh).
710
+ const adviceView = (item, lang) =>
711
+ item && lang === 'zh' && item.titleZh ? { ...item, title: item.titleZh, fix: item.fixZh || item.fix } : item
712
+
713
+ // Copy JSON/markdown for the agent. The async Clipboard API needs a real
714
+ // user gesture and can be missing on plain-http hosts, so fall back to the
715
+ // hidden-textarea + execCommand path before reporting failure.
716
+ async function copyText(text) {
717
+ try {
718
+ if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
719
+ await navigator.clipboard.writeText(text)
720
+ return true
721
+ }
722
+ } catch {
723
+ // fall through to the execCommand path
724
+ }
725
+ try {
726
+ if (typeof document !== 'undefined' && typeof document.execCommand === 'function') {
727
+ const area = document.createElement('textarea')
728
+ area.value = text
729
+ area.setAttribute('readonly', '')
730
+ area.style.position = 'fixed'
731
+ area.style.top = '-1000px'
732
+ area.style.opacity = '0'
733
+ document.body.appendChild(area)
734
+ try {
735
+ area.select()
736
+ return Boolean(document.execCommand('copy'))
737
+ } finally {
738
+ area.remove()
739
+ }
740
+ }
741
+ } catch {
742
+ // no clipboard available
743
+ }
744
+ return false
745
+ }
746
+
747
+ // client/06b-charts.js
748
+ // Pure-SVG charts for the board panel. No chart library: the bundle stays a
749
+ // single self-contained file, and every chart gets an aria-label with its data.
750
+ const CHART_COLORS = { green: '#2f9e44', yellow: '#d97706', amber: '#c9a227', red: '#c92a2a', blue: '#4d6bfe' }
751
+
752
+ function ChartCard(props) {
753
+ return h(
754
+ 'section',
755
+ { className: props.solo ? 'sev-chart sev-chart--solo' : 'sev-chart' },
756
+ h(
757
+ 'header',
758
+ { className: 'sev-chart-head' },
759
+ h('b', null, props.title),
760
+ props.hint ? h('span', null, props.hint) : null,
761
+ ),
762
+ props.children,
763
+ )
764
+ }
765
+
766
+ function chartEmpty(t) {
767
+ return h('div', { className: 'sev-chart-empty' }, t.noChartData)
768
+ }
769
+
770
+ function ScoreHistogram(props) {
771
+ const { skills, t } = props
772
+ const values = (skills || []).map((entry) => entry.score?.total).filter((value) => Number.isFinite(value))
773
+ if (values.length === 0) return h(ChartCard, { title: t.chartScoreDist }, chartEmpty(t))
774
+ const buckets = [
775
+ { label: '0–59', min: 0, max: 59.999 },
776
+ { label: '60–69', min: 60, max: 69.999 },
777
+ { label: '70–79', min: 70, max: 79.999 },
778
+ { label: '80–89', min: 80, max: 89.999 },
779
+ { label: '90–100', min: 90, max: 100 },
780
+ ]
781
+ const counts = buckets.map((bucket) => values.filter((value) => value >= bucket.min && value <= bucket.max).length)
782
+ const max = Math.max(1, ...counts)
783
+ const average = values.reduce((sum, value) => sum + value, 0) / values.length
784
+ const width = 300
785
+ const height = 124
786
+ const pad = 22
787
+ const barWidth = (width - pad * 2) / buckets.length
788
+ const plotHeight = height - pad - 18
789
+ const averageY = height - pad - (Math.max(0, Math.min(100, average)) / 100) * plotHeight
790
+ return h(
791
+ ChartCard,
792
+ { title: t.chartScoreDist, hint: `${values.length} ${t.skillsWord}` },
793
+ h(
794
+ 'svg',
795
+ {
796
+ className: 'sev-chart-svg',
797
+ viewBox: `0 0 ${width} ${height}`,
798
+ role: 'img',
799
+ 'aria-label': `${t.chartScoreDist}: ${buckets.map((bucket, index) => `${bucket.label} ${counts[index]}`).join(', ')}`,
800
+ },
801
+ counts.map((count, index) => {
802
+ const barHeight = count === 0 ? 0 : Math.max(2, (count / max) * plotHeight)
803
+ const x = pad + index * barWidth + 6
804
+ return h(
805
+ 'g',
806
+ { key: buckets[index].label },
807
+ h('rect', {
808
+ x,
809
+ y: height - pad - barHeight,
810
+ width: Math.max(4, barWidth - 12),
811
+ height: barHeight,
812
+ rx: 3,
813
+ fill: scoreColor(buckets[index].max),
814
+ opacity: count === 0 ? 0.18 : 0.9,
815
+ }),
816
+ count > 0
817
+ ? h(
818
+ 'text',
819
+ {
820
+ x: x + Math.max(4, barWidth - 12) / 2,
821
+ y: height - pad - barHeight - 4,
822
+ textAnchor: 'middle',
823
+ fontSize: 9,
824
+ fill: 'currentColor',
825
+ },
826
+ String(count),
827
+ )
828
+ : null,
829
+ h(
830
+ 'text',
831
+ {
832
+ x: x + Math.max(4, barWidth - 12) / 2,
833
+ y: height - 6,
834
+ textAnchor: 'middle',
835
+ fontSize: 8,
836
+ fill: 'currentColor',
837
+ opacity: 0.65,
838
+ },
839
+ buckets[index].label,
840
+ ),
841
+ )
842
+ }),
843
+ h('line', {
844
+ x1: pad,
845
+ x2: width - pad,
846
+ y1: averageY,
847
+ y2: averageY,
848
+ stroke: CHART_COLORS.blue,
849
+ strokeWidth: 1.5,
850
+ strokeDasharray: '4 3',
851
+ }),
852
+ h(
853
+ 'text',
854
+ { x: width - pad, y: Math.max(10, averageY - 4), textAnchor: 'end', fontSize: 9, fill: CHART_COLORS.blue },
855
+ `${t.chartAvg} ${fmt(average)}`,
856
+ ),
857
+ ),
858
+ )
859
+ }
860
+
861
+ function TrendSparkline(props) {
862
+ const { trend, t } = props
863
+ const points = (trend || []).filter((point) => Number.isFinite(point?.total)).slice(-12)
864
+ if (points.length < 2) return null
865
+ const width = 88
866
+ const height = 24
867
+ const values = points.map((point) => point.total)
868
+ const min = Math.min(...values)
869
+ const max = Math.max(...values)
870
+ const span = Math.max(1, max - min)
871
+ const coords = values.map((value, index) => [
872
+ 2 + (index * (width - 4)) / (values.length - 1),
873
+ height - 3 - ((value - min) / span) * (height - 6),
874
+ ])
875
+ const first = values[0]
876
+ const last = values[values.length - 1]
877
+ const color = last > first + 1 ? CHART_COLORS.green : last < first - 1 ? CHART_COLORS.red : CHART_COLORS.yellow
878
+ return h(
879
+ 'svg',
880
+ {
881
+ className: 'sev-spark',
882
+ viewBox: `0 0 ${width} ${height}`,
883
+ role: 'img',
884
+ 'aria-label': `${t.chartTrend}: ${values.map((value) => Math.round(value)).join(' → ')}`,
885
+ },
886
+ h('polyline', {
887
+ points: coords.map((point) => point.join(',')).join(' '),
888
+ fill: 'none',
889
+ stroke: color,
890
+ strokeWidth: 2,
891
+ strokeLinejoin: 'round',
892
+ strokeLinecap: 'round',
893
+ }),
894
+ h('circle', { cx: coords.at(-1)[0], cy: coords.at(-1)[1], r: 2.5, fill: color }),
895
+ )
896
+ }
897
+
898
+ function ValidityDonut(props) {
899
+ const { validity, t } = props
900
+ const coverage = (validity && validity.coverage) || {}
901
+ const total = Number(coverage.skills) || 0
902
+ if (total === 0) return h(ChartCard, { title: t.chartValidity }, chartEmpty(t))
903
+ const withCI = Math.min(total, Number(coverage.withCI) || 0)
904
+ const provisional = Math.min(total - withCI, Number(coverage.provisional) || 0)
905
+ const rest = Math.max(0, total - withCI - provisional)
906
+ const segments = [
907
+ { value: withCI, color: CHART_COLORS.green, label: t.chartWithCI },
908
+ { value: provisional, color: CHART_COLORS.yellow, label: t.chartProvisional },
909
+ { value: rest, color: 'var(--dsw-alias-border-l2, #d4d4d8)', label: t.chartNoEvidence },
910
+ ].filter((segment) => segment.value > 0)
911
+ const radius = 30
912
+ const circumference = 2 * Math.PI * radius
913
+ let offset = 0
914
+ return h(
915
+ ChartCard,
916
+ { title: t.chartValidity, hint: `${withCI}/${total} ${t.chartWithCI}` },
917
+ h(
918
+ 'div',
919
+ { className: 'sev-donut-wrap' },
920
+ h(
921
+ 'svg',
922
+ {
923
+ className: 'sev-donut',
924
+ viewBox: '0 0 84 84',
925
+ role: 'img',
926
+ 'aria-label': segments.map((segment) => `${segment.label} ${segment.value}`).join(', '),
927
+ },
928
+ h('circle', { cx: 42, cy: 42, r: radius, fill: 'none', stroke: '#e4e4e7', strokeWidth: 9, opacity: 0.45 }),
929
+ segments.map((segment) => {
930
+ const length = (segment.value / total) * circumference
931
+ const circle = h('circle', {
932
+ key: segment.label,
933
+ cx: 42,
934
+ cy: 42,
935
+ r: radius,
936
+ fill: 'none',
937
+ stroke: segment.color,
938
+ strokeWidth: 9,
939
+ strokeDasharray: `${length} ${circumference - length}`,
940
+ strokeDashoffset: -offset,
941
+ transform: 'rotate(-90 42 42)',
942
+ strokeLinecap: 'butt',
943
+ })
944
+ offset += length
945
+ return circle
946
+ }),
947
+ h(
948
+ 'text',
949
+ { x: 42, y: 39, textAnchor: 'middle', fontSize: 15, fontWeight: 700, fill: 'currentColor' },
950
+ String(withCI),
951
+ ),
952
+ h(
953
+ 'text',
954
+ { x: 42, y: 52, textAnchor: 'middle', fontSize: 8, fill: 'currentColor', opacity: 0.65 },
955
+ `${t.chartWithCI}`,
956
+ ),
957
+ ),
958
+ h(
959
+ 'ul',
960
+ { className: 'sev-chart-legend' },
961
+ segments.map((segment) =>
962
+ h(
963
+ 'li',
964
+ { key: segment.label },
965
+ h('i', { style: { background: segment.color } }),
966
+ segment.label,
967
+ h('b', null, ` ${segment.value}`),
968
+ ),
969
+ ),
970
+ h(
971
+ 'li',
972
+ null,
973
+ h('i', { style: { background: CHART_COLORS.blue } }),
974
+ `${t.chartActionable} ${coverage.actionable ?? 0}`,
975
+ ),
976
+ ),
977
+ ),
978
+ )
979
+ }
980
+
981
+ function fmtMs(value) {
982
+ if (typeof value !== 'number' || !Number.isFinite(value)) return '—'
983
+ if (value >= 1000) {
984
+ const seconds = value / 1000
985
+ return (Number.isInteger(seconds) ? String(seconds) : seconds.toFixed(1)) + 's'
986
+ }
987
+ return Math.round(value) + 'ms'
988
+ }
989
+
990
+ function McpLatencyChart(props) {
991
+ const { servers, t, solo } = props
992
+ const rows = (servers || []).filter((row) => (row.calls || 0) > 0).slice(0, 8)
993
+ if (rows.length === 0) return h(ChartCard, { title: t.chartMcp }, chartEmpty(t))
994
+ // The alert line follows the configured MCP p95 threshold; 3000 is only the
995
+ // fallback for an older host payload that predates the `mcp` block.
996
+ const configured = Number(props.thresholdMs)
997
+ const threshold = Number.isFinite(configured) && configured > 0 ? configured : 3000
998
+ const peak = Math.max(threshold, ...rows.map((row) => Math.max(row.p50Ms || 0, row.p95Ms || 0)))
999
+ const scale = peak * 1.05
1000
+ const width = (value) => Math.max(1.5, Math.min(100, ((value || 0) / scale) * 100)) + '%'
1001
+ return h(
1002
+ ChartCard,
1003
+ { title: t.chartMcp, hint: t.chartThreshold + ' ' + fmtMs(threshold), solo },
1004
+ h(
1005
+ 'div',
1006
+ { className: 'sev-lat' },
1007
+ rows.map((row) =>
1008
+ h(
1009
+ 'div',
1010
+ {
1011
+ key: row.server,
1012
+ className: 'sev-lat-row',
1013
+ role: 'img',
1014
+ 'aria-label':
1015
+ row.server +
1016
+ ': ' +
1017
+ t.chartP50 +
1018
+ ' ' +
1019
+ fmtMs(row.p50Ms) +
1020
+ ', ' +
1021
+ t.chartP95 +
1022
+ ' ' +
1023
+ fmtMs(row.p95Ms) +
1024
+ ', ' +
1025
+ t.chartThreshold +
1026
+ ' ' +
1027
+ fmtMs(threshold),
1028
+ },
1029
+ h(
1030
+ 'div',
1031
+ { className: 'sev-lat-head' },
1032
+ h('b', null, row.server),
1033
+ h('span', null, t.chartP50 + ' ' + fmtMs(row.p50Ms) + ' · ' + t.chartP95 + ' ' + fmtMs(row.p95Ms)),
1034
+ ),
1035
+ h(
1036
+ 'div',
1037
+ { className: 'sev-meter' },
1038
+ h('i', { className: 'sev-meter-fill sev-meter-fill--p95', style: { width: width(row.p95Ms) } }),
1039
+ h('i', { className: 'sev-meter-fill sev-meter-fill--p50', style: { width: width(row.p50Ms) } }),
1040
+ h('span', { className: 'sev-meter-threshold', style: { left: width(threshold) } }),
1041
+ ),
1042
+ ),
1043
+ ),
1044
+ h(
1045
+ 'ul',
1046
+ { className: 'sev-chart-legend' },
1047
+ h('li', null, h('i', { style: { background: CHART_COLORS.blue } }), t.chartP50),
1048
+ h('li', null, h('i', { style: { background: CHART_COLORS.yellow } }), t.chartP95),
1049
+ h('li', null, h('i', { style: { background: CHART_COLORS.red } }), t.chartThreshold + ' ' + fmtMs(threshold)),
1050
+ ),
1051
+ ),
1052
+ )
1053
+ }
1054
+
1055
+ function SessionActivityChart(props) {
1056
+ const { runs, t, solo } = props
1057
+ const rows = [...(runs || [])]
1058
+ .filter((run) => Number.isFinite(run.lastAt))
1059
+ .sort((a, b) => a.lastAt - b.lastAt)
1060
+ .slice(-12)
1061
+ if (rows.length === 0) return h(ChartCard, { title: t.chartSessions }, chartEmpty(t))
1062
+ const width = 300
1063
+ const height = 104
1064
+ const pad = 18
1065
+ const plot = height - pad - 14
1066
+ const max = Math.max(1, ...rows.map((run) => (run.toolCalls || 0) + (run.loads || 0)))
1067
+ const barWidth = (width - pad * 2) / rows.length
1068
+ const totals = rows.reduce(
1069
+ (sum, run) => ({
1070
+ loads: sum.loads + (run.loads || 0),
1071
+ calls: sum.calls + (run.toolCalls || 0),
1072
+ errors: sum.errors + (run.errors || 0),
1073
+ }),
1074
+ { loads: 0, calls: 0, errors: 0 },
1075
+ )
1076
+ return h(
1077
+ ChartCard,
1078
+ { title: t.chartSessions, hint: `${rows.length} ${t.chartSessionsUnit}`, solo },
1079
+ h(
1080
+ 'svg',
1081
+ {
1082
+ className: 'sev-chart-svg',
1083
+ viewBox: `0 0 ${width} ${height}`,
1084
+ role: 'img',
1085
+ 'aria-label': rows
1086
+ .map(
1087
+ (run) =>
1088
+ `${new Date(run.lastAt).toLocaleTimeString()}: ${run.loads || 0} ${t.chartLoads}, ${run.errors || 0} ${t.chartErrors}`,
1089
+ )
1090
+ .join('; '),
1091
+ },
1092
+ rows.map((run, index) => {
1093
+ const calls = run.toolCalls || 0
1094
+ const loads = run.loads || 0
1095
+ const errors = run.errors || 0
1096
+ const barHeight = Math.max(2, ((calls + loads) / max) * plot)
1097
+ const x = pad + index * barWidth + 2
1098
+ return h(
1099
+ 'g',
1100
+ { key: `${run.sessionId}-${index}` },
1101
+ h('rect', {
1102
+ x,
1103
+ y: height - pad - barHeight,
1104
+ width: Math.max(3, barWidth - 4),
1105
+ height: barHeight,
1106
+ rx: 2,
1107
+ fill: CHART_COLORS.blue,
1108
+ opacity: 0.8,
1109
+ }),
1110
+ errors > 0
1111
+ ? h('rect', {
1112
+ x,
1113
+ y: height - pad - barHeight,
1114
+ width: Math.max(3, barWidth - 4),
1115
+ height: Math.max(2, Math.min(barHeight, (errors / Math.max(1, calls + loads)) * barHeight)),
1116
+ rx: 2,
1117
+ fill: CHART_COLORS.red,
1118
+ })
1119
+ : null,
1120
+ )
1121
+ }),
1122
+ h(
1123
+ 'text',
1124
+ { x: pad, y: height - 3, fontSize: 8, fill: 'currentColor', opacity: 0.7 },
1125
+ `${totals.loads} ${t.chartLoads} · ${totals.calls} ${t.chartCalls} · ${totals.errors} ${t.chartErrors}`,
1126
+ ),
1127
+ ),
1128
+ )
1129
+ }
1130
+
1131
+ function SkillsCharts(props) {
1132
+ const { data, skills, t } = props
1133
+ return h(
1134
+ 'div',
1135
+ { className: 'sev-charts' },
1136
+ h(ScoreHistogram, { skills, t }),
1137
+ h(ValidityDonut, { validity: data && data.validity, t }),
1138
+ h(McpLatencyChart, { servers: data && data.mcpServers, t, thresholdMs: data && data.mcp && data.mcp.p95Ms }),
1139
+ h(SessionActivityChart, { runs: data && data.runs, t }),
1140
+ )
1141
+ }
1142
+
1143
+ // client/06c-steps.js
1144
+ // Per-turn loop trajectory. The host records one scored row per agent step;
1145
+ // this view shows the overall picture, a skill-filtered drill-down, and the
1146
+ // recent-turn comparison the panel was missing.
1147
+ function stepClock(at) {
1148
+ return Number.isFinite(at) ? new Date(at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '—'
1149
+ }
1150
+
1151
+ function stepDeltaTone(delta) {
1152
+ if (!Number.isFinite(delta) || Math.abs(delta) < 0.05) return 'flat'
1153
+ return delta > 0 ? 'up' : 'down'
1154
+ }
1155
+
1156
+ function StepKpi(props) {
1157
+ return h('div', { className: 'sev-kpi' }, h('b', null, props.value), h('span', null, props.label))
1158
+ }
1159
+
1160
+ function StepRow(props) {
1161
+ const { step, previous, t } = props
1162
+ const score = step.score || {}
1163
+ const delta =
1164
+ previous && Number.isFinite(previous.score?.total)
1165
+ ? Math.round((score.total - previous.score.total) * 10) / 10
1166
+ : null
1167
+ const meta = [
1168
+ `${step.toolCalls} ${t.stepCalls}`,
1169
+ step.errors > 0 ? `${step.errors} ${t.stepErrors}` : null,
1170
+ step.durationMs > 0 ? `${Math.round(step.durationMs / 100) / 10}s` : null,
1171
+ step.tokens?.calls > 0 ? `${step.tokens.input + step.tokens.output} ${t.stepTokens}` : null,
1172
+ ].filter(Boolean)
1173
+ return h(
1174
+ 'li',
1175
+ { className: 'sev-step' },
1176
+ h(
1177
+ 'span',
1178
+ {
1179
+ className: 'sev-step-score',
1180
+ style: { color: scoreColor(score.total), borderColor: scoreColor(score.total) },
1181
+ title: (score.penalties || []).map((item) => `${item.id} −${item.penalty}`).join(', '),
1182
+ },
1183
+ fmt(score.total),
1184
+ ),
1185
+ h(
1186
+ 'div',
1187
+ { className: 'sev-step-main' },
1188
+ h(
1189
+ 'div',
1190
+ { className: 'sev-step-title' },
1191
+ `${t.stepStep} ${step.step ?? '?'} · ${meta.join(' · ')}`,
1192
+ delta !== null
1193
+ ? h(
1194
+ 'span',
1195
+ { className: 'sev-step-delta sev-step-delta--' + stepDeltaTone(delta) },
1196
+ (delta > 0 ? '+' : '') + delta,
1197
+ )
1198
+ : null,
1199
+ ),
1200
+ h(
1201
+ 'div',
1202
+ { className: 'sev-step-sub' },
1203
+ (step.skills || []).length > 0
1204
+ ? step.skills.map((skill) =>
1205
+ h(
1206
+ 'button',
1207
+ {
1208
+ key: skill,
1209
+ type: 'button',
1210
+ className: 'sev-step-skill',
1211
+ onClick: () => props.onFilter(skill),
1212
+ title: t.stepFiltered,
1213
+ },
1214
+ skill,
1215
+ ),
1216
+ )
1217
+ : h('span', { className: 'sev-muted' }, t.stepNoSkill),
1218
+ (step.errorNames || []).length > 0
1219
+ ? h('span', { className: 'sev-step-err' }, step.errorNames.join(', '))
1220
+ : null,
1221
+ ),
1222
+ ),
1223
+ )
1224
+ }
1225
+
1226
+ function StepTurn(props) {
1227
+ const { turn, t, previousAverage, onFilter } = props
1228
+ const delta =
1229
+ Number.isFinite(previousAverage) && Number.isFinite(turn.average) ? turn.average - previousAverage : null
1230
+ const trend = turn.steps.map((step) => ({ total: step.score?.total }))
1231
+ return h(
1232
+ 'section',
1233
+ { className: 'sev-turn' },
1234
+ h(
1235
+ 'header',
1236
+ { className: 'sev-turn-head' },
1237
+ h('b', null, `${t.stepTurn} ${turn.turn ?? '?'} · ${stepClock(turn.lastAt)}`),
1238
+ h(
1239
+ 'span',
1240
+ { className: 'sev-turn-meta' },
1241
+ `${turn.steps.length} ${t.stepStep} · ${turn.skills.join(', ') || '—'}`,
1242
+ ),
1243
+ h(TrendSparkline, { trend, t }),
1244
+ h(
1245
+ 'span',
1246
+ { className: 'sev-turn-avg', style: { color: scoreColor(turn.average) } },
1247
+ `${t.stepTurnAvg} ${fmt(turn.average)}`,
1248
+ ),
1249
+ delta !== null
1250
+ ? h(
1251
+ 'span',
1252
+ { className: 'sev-turn-delta sev-step-delta--' + stepDeltaTone(Math.round(delta * 10) / 10) },
1253
+ `${t.stepDelta} ${delta > 0 ? '+' : ''}${Math.round(delta * 10) / 10}`,
1254
+ )
1255
+ : null,
1256
+ ),
1257
+ h(
1258
+ 'ol',
1259
+ { className: 'sev-steplist' },
1260
+ turn.steps.map((step, index) =>
1261
+ h(StepRow, { key: `${step.step}-${step.at}`, step, previous: turn.steps[index - 1], t, onFilter }),
1262
+ ),
1263
+ ),
1264
+ )
1265
+ }
1266
+
1267
+ function StepsView(props) {
1268
+ const { data, t } = props
1269
+ const filter = props.filter || ''
1270
+ const allSteps = (data && Array.isArray(data.steps) ? data.steps : [])
1271
+ .slice()
1272
+ .sort((a, b) => (a.at ?? 0) - (b.at ?? 0))
1273
+ const filterSkills = [...new Set(allSteps.flatMap((step) => step.skills || []))].sort()
1274
+ const steps = filter ? allSteps.filter((step) => (step.skills || []).includes(filter)) : allSteps
1275
+ const allTurns = data && Array.isArray(data.stepTurns) ? data.stepTurns : []
1276
+ const stepKey = (step) => `${step.sessionId}#${step.turn}#${step.step}#${step.at}`
1277
+ const visibleKeys = new Set(steps.map(stepKey))
1278
+ const turns = allTurns
1279
+ .map((turn) => ({ ...turn, steps: (turn.steps || []).filter((step) => visibleKeys.has(stepKey(step))) }))
1280
+ .filter((turn) => turn.steps.length > 0)
1281
+ const scores = steps.map((step) => step.score?.total).filter((value) => Number.isFinite(value))
1282
+ const average = scores.length > 0 ? scores.reduce((sum, value) => sum + value, 0) / scores.length : null
1283
+ const latest = turns[0] || null
1284
+ const previous = turns[1] || null
1285
+ const delta =
1286
+ latest && previous && Number.isFinite(latest.average) && Number.isFinite(previous.average)
1287
+ ? Math.round((latest.average - previous.average) * 10) / 10
1288
+ : null
1289
+ const recent = turns.slice(0, 5)
1290
+ const maxRecent = Math.max(1, ...recent.map((turn) => turn.average || 0))
1291
+ return h(
1292
+ 'div',
1293
+ { className: 'sev-steps' },
1294
+ steps.length === 0
1295
+ ? h('div', { className: 'sev-empty' }, t.stepNoData)
1296
+ : h(
1297
+ React.Fragment,
1298
+ null,
1299
+ h(
1300
+ 'div',
1301
+ { className: 'sev-steps-kpis' },
1302
+ h(StepKpi, { label: t.stepKpiAvg, value: average === null ? '—' : fmt(average) }),
1303
+ h(StepKpi, {
1304
+ label: t.stepKpiLatest,
1305
+ value:
1306
+ latest && latest.average !== null
1307
+ ? `${t.stepTurn} ${latest.turn ?? '?'} · ${fmt(latest.average)}` +
1308
+ (delta !== null ? ` (${delta > 0 ? '+' : ''}${delta})` : '')
1309
+ : '—',
1310
+ }),
1311
+ h(StepKpi, {
1312
+ label: t.stepKpiCount,
1313
+ value: `${scores.length} ${t.stepStep} / ${allTurns.length} ${t.stepTurn}`,
1314
+ }),
1315
+ ),
1316
+ h(
1317
+ 'div',
1318
+ { className: 'sev-recent' },
1319
+ h('b', null, t.stepRecent),
1320
+ recent.map((turn) =>
1321
+ h(
1322
+ 'div',
1323
+ { key: `${turn.sessionId}-${turn.turn}`, className: 'sev-recent-turn' },
1324
+ h('span', null, `${t.stepTurn} ${turn.turn ?? '?'}`),
1325
+ h('i', {
1326
+ style: {
1327
+ width: `${Math.max(4, ((turn.average || 0) / maxRecent) * 100)}%`,
1328
+ background: scoreColor(turn.average),
1329
+ },
1330
+ }),
1331
+ h('em', null, fmt(turn.average)),
1332
+ ),
1333
+ ),
1334
+ ),
1335
+ h(
1336
+ 'div',
1337
+ { className: 'sev-step-filters' },
1338
+ h('b', null, t.stepFilter),
1339
+ h(
1340
+ 'button',
1341
+ {
1342
+ type: 'button',
1343
+ className: 'sev-chip' + (filter === '' ? ' sev-chip--on' : ''),
1344
+ onClick: () => props.onFilter(''),
1345
+ },
1346
+ t.stepAll,
1347
+ ),
1348
+ filterSkills.map((skill) =>
1349
+ h(
1350
+ 'button',
1351
+ {
1352
+ key: skill,
1353
+ type: 'button',
1354
+ className: 'sev-chip' + (filter === skill ? ' sev-chip--on' : ''),
1355
+ onClick: () => props.onFilter(skill),
1356
+ },
1357
+ skill,
1358
+ ),
1359
+ ),
1360
+ ),
1361
+ h('div', { className: 'sev-step-formula' }, t.stepFormula),
1362
+ turns.length === 0
1363
+ ? h('div', { className: 'sev-empty' }, filter ? t.noMatch : t.stepNoData)
1364
+ : turns.map((turn, index) =>
1365
+ h(StepTurn, {
1366
+ key: `${turn.sessionId}-${turn.turn}`,
1367
+ turn,
1368
+ t,
1369
+ previousAverage: turns[index + 1]?.average ?? null,
1370
+ onFilter: props.onFilter,
1371
+ }),
1372
+ ),
1373
+ ),
1374
+ )
1375
+ }
1376
+
1377
+ // client/07-board.js
1378
+ // ------------------------------------------------------------- main panel
1379
+ // Same placement as the context plugin: a sidebar panel icon + a main panel
1380
+ // keyed by the same id. This is the board's primary home inside DSH.
1381
+ function PanelIcon(props) {
1382
+ const size = props && Number(props.size) > 0 ? Number(props.size) : 18
1383
+ const active = props && props.active === true
1384
+ return h('span', { style: { display: 'inline-flex', opacity: active ? 1 : 0.72 } }, h(GaugeIcon, { size }))
1385
+ }
1386
+
1387
+ function BoardPanel() {
1388
+ const state = useStore()
1389
+ const { lang, t } = useLang()
1390
+ const copyTimer = useRef(null)
1391
+ const mounted = useRef(true)
1392
+ const [configOpen, setConfigOpen] = useState(false)
1393
+ useEffect(() => {
1394
+ ensureReport()
1395
+ return () => {
1396
+ mounted.current = false
1397
+ if (copyTimer.current) clearTimeout(copyTimer.current)
1398
+ }
1399
+ }, [])
1400
+ // Escape closes the in-panel settings dialog; the web config page stays as a
1401
+ // second surface but is unreachable from the desktop shell (window.open is
1402
+ // denied there), so the dialog is the entry point that always works.
1403
+ useEffect(() => {
1404
+ if (!configOpen) return undefined
1405
+ const onKey = (event) => {
1406
+ if (event.key === 'Escape') setConfigOpen(false)
1407
+ }
1408
+ window.addEventListener('keydown', onKey)
1409
+ return () => window.removeEventListener('keydown', onKey)
1410
+ }, [configOpen])
1411
+ const data = state.data
1412
+ const skills = (data && data.skills) || []
1413
+ const [copyState, setCopyState] = useState('idle')
1414
+ const [query, setQuery] = useState('')
1415
+ const [onlyActionable, setOnlyActionable] = useState(false)
1416
+ const copy = async () => {
1417
+ // Before the first load there is nothing to hand over; copying "{}" and
1418
+ // reporting success is worse than a disabled button.
1419
+ if (!data) return
1420
+ const ok = await copyText(JSON.stringify(data, null, 2))
1421
+ if (!mounted.current) return
1422
+ setCopyState(ok ? 'copied' : 'failed')
1423
+ if (copyTimer.current) clearTimeout(copyTimer.current)
1424
+ copyTimer.current = setTimeout(() => setCopyState('idle'), 1600)
1425
+ }
1426
+ // The dialog declares aria-modal, so Tab must not walk into the board behind it.
1427
+ const trapFocus = (event) => {
1428
+ if (event.key !== 'Tab') return
1429
+ const focusable = [
1430
+ ...event.currentTarget.querySelectorAll(
1431
+ 'button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])',
1432
+ ),
1433
+ ].filter((node) => !node.disabled && node.offsetParent !== null)
1434
+ if (focusable.length === 0) return
1435
+ const first = focusable[0]
1436
+ const last = focusable[focusable.length - 1]
1437
+ if (event.shiftKey && document.activeElement === first) {
1438
+ event.preventDefault()
1439
+ last.focus()
1440
+ } else if (!event.shiftKey && document.activeElement === last) {
1441
+ event.preventDefault()
1442
+ first.focus()
1443
+ }
1444
+ }
1445
+ const actionable = (data && data.validity && data.validity.coverage && data.validity.coverage.actionable) || 0
1446
+ const hasFix = (entry) =>
1447
+ (entry.advice || []).some((item) => item.severity === 'critical' || item.severity === 'warning')
1448
+ const fixable = skills.filter(hasFix).length
1449
+ const loads = skills.reduce((total, entry) => total + (entry.stats?.loads || 0), 0)
1450
+ const scored = skills.map((entry) => entry.score?.total).filter((value) => Number.isFinite(value))
1451
+ const average = scored.length > 0 ? scored.reduce((a, b) => a + b, 0) / scored.length : null
1452
+ const needle = query.trim().toLowerCase()
1453
+ const visibleSkills = skills.filter(
1454
+ (entry) =>
1455
+ (!onlyActionable || hasFix(entry)) && (needle.length === 0 || entry.skill.toLowerCase().includes(needle)),
1456
+ )
1457
+ const updated =
1458
+ data && data.generatedAt && Number.isFinite(Date.parse(data.generatedAt))
1459
+ ? new Date(data.generatedAt).toLocaleTimeString()
1460
+ : null
1461
+ const rankingNote =
1462
+ data && data.ranking ? (lang === 'zh' && data.ranking.noteZh ? data.ranking.noteZh : data.ranking.note) : null
1463
+ return h(
1464
+ 'div',
1465
+ { className: 'sev-panel' },
1466
+ h('style', { key: 'sev-panel-style' }, STYLES + '\n' + PANEL_STYLES.join('\n')),
1467
+ h(
1468
+ 'div',
1469
+ { className: 'sev-head', style: { borderBottom: 'none', padding: '0 0 6px' } },
1470
+ h(
1471
+ 'div',
1472
+ { className: 'sev-head-text' },
1473
+ h('div', { className: 'sev-title' }, t.title),
1474
+ h(
1475
+ 'div',
1476
+ { className: 'sev-sub' },
1477
+ skills.length +
1478
+ ' ' +
1479
+ t.detailSkills +
1480
+ ' · ' +
1481
+ actionable +
1482
+ ' ' +
1483
+ t.detailActionable +
1484
+ (updated ? ' · ' + t.updated + ' ' + updated : ''),
1485
+ ),
1486
+ h(
1487
+ 'div',
1488
+ { className: 'sev-tabs', role: 'tablist' },
1489
+ ['skills', 'steps', 'runs', 'mcp', 'dev'].map((view) =>
1490
+ h(
1491
+ 'button',
1492
+ {
1493
+ key: view,
1494
+ type: 'button',
1495
+ role: 'tab',
1496
+ 'aria-selected': state.view === view,
1497
+ className: 'sev-tab' + (state.view === view ? ' sev-tab--on' : ''),
1498
+ onClick: () => setView(view),
1499
+ },
1500
+ t.tabs[view],
1501
+ ),
1502
+ ),
1503
+ ),
1504
+ ),
1505
+ h(
1506
+ 'div',
1507
+ { className: 'sev-head-actions' },
1508
+ h(
1509
+ 'button',
1510
+ {
1511
+ type: 'button',
1512
+ className: 'sev-btn',
1513
+ title: t.rowConfigSummary,
1514
+ onClick: () => setConfigOpen(true),
1515
+ },
1516
+ t.config,
1517
+ ),
1518
+ h('button', { type: 'button', className: 'sev-btn', onClick: load, disabled: state.loading }, t.refresh),
1519
+ h(
1520
+ 'button',
1521
+ { type: 'button', className: 'sev-btn', onClick: copy, disabled: !data },
1522
+ h(
1523
+ 'span',
1524
+ { role: 'status', 'aria-live': 'polite' },
1525
+ copyState === 'copied' ? t.copied : copyState === 'failed' ? t.copyFailed : t.copy,
1526
+ ),
1527
+ ),
1528
+ ),
1529
+ ),
1530
+ h(
1531
+ 'div',
1532
+ { className: 'sev-kpis' },
1533
+ [
1534
+ [t.kpiSkills, skills.length],
1535
+ [t.kpiLoads, loads],
1536
+ [t.kpiFixable, fixable],
1537
+ [t.kpiAvg, average === null ? '—' : fmt(average)],
1538
+ ].map(([label, value]) =>
1539
+ h('div', { className: 'sev-kpi', key: label }, h('b', null, String(value)), h('span', null, label)),
1540
+ ),
1541
+ ),
1542
+ state.loading && !data ? h('div', { className: 'sev-empty' }, t.loading) : null,
1543
+ state.view === 'skills' && data ? h(SkillsCharts, { data, skills, t }) : null,
1544
+ data && !data.scoring
1545
+ ? h('div', { className: 'sev-stale' }, h('b', null, t.staleTitle), h('span', null, t.staleHint))
1546
+ : null,
1547
+ state.error ? h('div', { className: 'sev-error' }, t.failed + ': ' + state.error + ' — ' + DATA_URL) : null,
1548
+ data && data.totals && data.totals.storeError
1549
+ ? h('div', { className: 'sev-error' }, t.storeError + ': ' + data.totals.storeError)
1550
+ : null,
1551
+ state.view === 'skills' && rankingNote ? h('div', { className: 'sev-note' }, rankingNote) : null,
1552
+ state.view === 'skills'
1553
+ ? h(
1554
+ 'div',
1555
+ { className: 'sev-filterbar' },
1556
+ h('input', {
1557
+ type: 'search',
1558
+ className: 'sev-search',
1559
+ value: query,
1560
+ placeholder: t.searchPlaceholder,
1561
+ 'aria-label': t.searchPlaceholder,
1562
+ onChange: (event) => setQuery(event.target.value),
1563
+ }),
1564
+ h(
1565
+ 'button',
1566
+ {
1567
+ type: 'button',
1568
+ className: 'sev-chip' + (onlyActionable ? ' sev-chip--on' : ''),
1569
+ 'aria-pressed': onlyActionable,
1570
+ onClick: () => setOnlyActionable((value) => !value),
1571
+ },
1572
+ t.onlyActionable + ' (' + fixable + ')',
1573
+ ),
1574
+ )
1575
+ : null,
1576
+ state.view === 'skills'
1577
+ ? !state.loading && !state.error && skills.length === 0
1578
+ ? h('div', { className: 'sev-empty' }, t.empty)
1579
+ : visibleSkills.length === 0
1580
+ ? h('div', { className: 'sev-empty' }, t.noMatch)
1581
+ : visibleSkills.map((skill) =>
1582
+ h(SkillCard, {
1583
+ key: skill.skill,
1584
+ skill,
1585
+ t,
1586
+ lang,
1587
+ onTrace: (name) => store.set((current) => ({ ...current, view: 'steps', stepFilter: name })),
1588
+ }),
1589
+ )
1590
+ : state.view === 'steps'
1591
+ ? h(StepsView, {
1592
+ data,
1593
+ t,
1594
+ filter: state.stepFilter || '',
1595
+ onFilter: (name) => store.set((current) => ({ ...current, stepFilter: name })),
1596
+ })
1597
+ : state.view === 'runs'
1598
+ ? h(RunsView, { data, t })
1599
+ : state.view === 'mcp'
1600
+ ? h(McpView, { data, t, lang })
1601
+ : h(DevView, { data, t }),
1602
+ configOpen
1603
+ ? h(
1604
+ 'div',
1605
+ {
1606
+ className: 'sev-backdrop',
1607
+ role: 'presentation',
1608
+ onMouseDown: (event) => {
1609
+ if (event.target === event.currentTarget) setConfigOpen(false)
1610
+ },
1611
+ },
1612
+ h(
1613
+ 'div',
1614
+ {
1615
+ className: 'sev-dialog',
1616
+ role: 'dialog',
1617
+ 'aria-modal': 'true',
1618
+ 'aria-label': t.config,
1619
+ onKeyDown: trapFocus,
1620
+ },
1621
+ h(
1622
+ 'header',
1623
+ { className: 'sev-head' },
1624
+ h(
1625
+ 'div',
1626
+ { className: 'sev-head-text' },
1627
+ h('div', { className: 'sev-title' }, t.config),
1628
+ h('div', { className: 'sev-sub' }, t.rowConfigSummary),
1629
+ ),
1630
+ h(
1631
+ 'div',
1632
+ { className: 'sev-head-actions' },
1633
+ h(
1634
+ 'button',
1635
+ {
1636
+ type: 'button',
1637
+ className: 'sev-btn sev-btn--icon',
1638
+ onClick: () => setConfigOpen(false),
1639
+ 'aria-label': t.close,
1640
+ title: t.close,
1641
+ autoFocus: true,
1642
+ },
1643
+ '✕',
1644
+ ),
1645
+ ),
1646
+ ),
1647
+ h('div', { className: 'sev-body' }, h(SettingsForm, { webOpen: false })),
1648
+ ),
1649
+ )
1650
+ : null,
1651
+ )
1652
+ }
1653
+
1654
+ const PANEL_STYLES = [
1655
+ '.sev-panel{height:100%;overflow:auto;box-sizing:border-box;padding:22px 26px 32px;display:flex;flex-direction:column;gap:14px;color:var(--dsw-alias-label-primary, #18181b);font-size:13px;line-height:1.5;background:var(--dsw-alias-bg-layer-1, transparent)}',
1656
+ '.sev-panel .sev-head{display:flex;align-items:flex-start;gap:12px}',
1657
+ '.sev-kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px}',
1658
+ '.sev-kpi{display:flex;flex-direction:column;gap:2px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:10px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
1659
+ '.sev-kpi b{font-size:18px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary, #18181b)}',
1660
+ '.sev-kpi span{font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
1661
+ '.sev-filterbar{display:flex;align-items:center;gap:10px}',
1662
+ '.sev-search{flex:1;min-width:0;padding:6px 10px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:8px;background:var(--dsw-alias-bg-layer-1, #fff);color:inherit;font:inherit}',
1663
+ '.sev-search:focus-visible{outline:2px solid var(--dsw-alias-brand-primary, #4d6bfe);outline-offset:1px}',
1664
+ '.sev-chip{padding:6px 10px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:999px;background:transparent;color:var(--dsw-alias-label-secondary, #71717a);font:inherit;cursor:pointer;white-space:nowrap}',
1665
+ '.sev-chip--on{border-color:var(--dsw-alias-brand-primary, #4d6bfe);color:var(--dsw-alias-brand-primary, #4d6bfe);background:var(--dsw-alias-bg-layer-2, #f4f4f5);font-weight:600}',
1666
+ ]
1667
+
1668
+ function FooterAction(props) {
1669
+ const { t } = useLang()
1670
+ const wide = props && props.wide !== false
1671
+ return h(
1672
+ 'button',
1673
+ {
1674
+ type: 'button',
1675
+ className: wide ? 'sev-btn' : 'sev-btn sev-btn--icon',
1676
+ title: t.open,
1677
+ 'aria-label': t.open,
1678
+ onClick: openReport,
1679
+ },
1680
+ h(GaugeIcon, { size: 16 }),
1681
+ wide ? h('span', null, t.open) : null,
1682
+ )
1683
+ }
1684
+
1685
+ function DimensionBar(props) {
1686
+ const value = props.value
1687
+ const width = typeof value === 'number' && Number.isFinite(value) ? Math.max(0, Math.min(100, value)) : 0
1688
+ return h(
1689
+ 'div',
1690
+ { className: 'sev-dim' },
1691
+ h('span', { className: 'sev-dim-label' }, props.label),
1692
+ h('span', { className: 'sev-dim-track' }, h('i', { style: { width: width + '%', background: scoreColor(value) } })),
1693
+ h('b', null, fmt(value)),
1694
+ )
1695
+ }
1696
+
1697
+ const SkillCard = React.memo(function SkillCard(props) {
1698
+ const skill = props.skill
1699
+ const t = props.t
1700
+ const lang = props.lang || 'zh'
1701
+ const score = skill.score || {}
1702
+ const dims = score.dimensions || {}
1703
+ const stats = skill.stats || {}
1704
+ const advice = (skill.topAdvice && skill.topAdvice.length ? skill.topAdvice : skill.advice || []).slice(0, 3)
1705
+ return h(
1706
+ 'article',
1707
+ { className: 'sev-card' },
1708
+ h(
1709
+ 'div',
1710
+ { className: 'sev-card-head' },
1711
+ h('div', { className: 'sev-name' }, skill.skill),
1712
+ h(TrendSparkline, { trend: skill.trend, t }),
1713
+ h('div', { className: 'sev-grade', style: { color: scoreColor(score.total) } }, score.grade || '?'),
1714
+ h('div', { className: 'sev-total', style: { color: scoreColor(score.total) } }, fmt(score.total)),
1715
+ h(
1716
+ 'button',
1717
+ {
1718
+ type: 'button',
1719
+ className: 'sev-trace',
1720
+ title: t.stepTrace,
1721
+ 'aria-label': t.stepTrace + ': ' + skill.skill,
1722
+ onClick: () => props.onTrace && props.onTrace(skill.skill),
1723
+ },
1724
+ t.stepTrace,
1725
+ ),
1726
+ ),
1727
+ score.provisional ? h('div', { className: 'sev-provisional' }, t.provisional) : null,
1728
+ score.ci
1729
+ ? h(
1730
+ 'div',
1731
+ { className: 'sev-ci' },
1732
+ '95% CI ' + fmt(score.ci.low) + ' – ' + fmt(score.ci.high) + ' · n=' + (score.samples || 0),
1733
+ )
1734
+ : null,
1735
+ h(
1736
+ 'div',
1737
+ { className: 'sev-dims' },
1738
+ h(DimensionBar, { label: t.dims.static, value: dims.static }),
1739
+ h(DimensionBar, { label: t.dims.reliability, value: dims.reliability }),
1740
+ h(DimensionBar, { label: t.dims.effectiveness, value: dims.effectiveness }),
1741
+ h(DimensionBar, { label: t.dims.efficiency, value: dims.efficiency }),
1742
+ ),
1743
+ h(
1744
+ 'div',
1745
+ { className: 'sev-meta' },
1746
+ (stats.loads || 0) +
1747
+ ' ' +
1748
+ t.loads +
1749
+ ' · ' +
1750
+ (stats.closed || 0) +
1751
+ ' ' +
1752
+ t.closed +
1753
+ ' · ' +
1754
+ t.corr +
1755
+ ' ' +
1756
+ pct(stats.correctionRate) +
1757
+ ' · ' +
1758
+ t.err +
1759
+ ' ' +
1760
+ pct(stats.errRate) +
1761
+ ' · ' +
1762
+ t.latency +
1763
+ ' ' +
1764
+ fmt(stats.p50LoadMs, 0) +
1765
+ 'ms' +
1766
+ (typeof stats.tokensPerLoad === 'number'
1767
+ ? ' · ≈' + stats.tokensPerLoad.toLocaleString() + ' ' + t.tokPerLoad
1768
+ : ''),
1769
+ ),
1770
+ advice.length
1771
+ ? h(
1772
+ 'ul',
1773
+ { className: 'sev-advice' },
1774
+ advice.map((raw, index) => {
1775
+ const item = adviceView(raw, lang)
1776
+ return h(
1777
+ 'li',
1778
+ { key: item.id || String(index), style: { borderLeftColor: severityColor(item.severity) } },
1779
+ h(
1780
+ 'b',
1781
+ null,
1782
+ (item.severity === 'critical' ? '🛑 ' : item.severity === 'warning' ? '⚠️ ' : 'ℹ️ ') + item.title,
1783
+ ),
1784
+ h('span', null, item.evidence),
1785
+ h('em', null, '↳ ' + item.fix),
1786
+ )
1787
+ }),
1788
+ )
1789
+ : h('div', { className: 'sev-meta' }, t.noAdvice),
1790
+ )
1791
+ })
1792
+
1793
+ function DataTable(props) {
1794
+ const { head, rows, empty, variant } = props
1795
+ if (rows.length === 0) return h('div', { className: 'sev-empty' }, empty)
1796
+ return h(
1797
+ 'div',
1798
+ { className: 'sev-table' + (variant ? ' sev-table--' + variant : '') },
1799
+ h(
1800
+ 'div',
1801
+ { className: 'sev-tr sev-th' },
1802
+ head.map((label) => h('span', { key: label }, label)),
1803
+ ),
1804
+ rows.map((cells, index) =>
1805
+ h(
1806
+ 'div',
1807
+ { className: 'sev-tr', key: String(index) },
1808
+ cells.map((cell, cellIndex) =>
1809
+ h('span', { key: String(cellIndex), className: cellIndex === 0 ? 'sev-strong' : undefined }, cell),
1810
+ ),
1811
+ ),
1812
+ ),
1813
+ )
1814
+ }
1815
+
1816
+ function RunsView(props) {
1817
+ const t = props.t
1818
+ const runs = props.data && Array.isArray(props.data.runs) ? props.data.runs : []
1819
+ return h(
1820
+ React.Fragment,
1821
+ null,
1822
+ h(SessionActivityChart, { runs, t, solo: true }),
1823
+ h(DataTable, {
1824
+ head: t.runsHead,
1825
+ empty: t.emptyRuns,
1826
+ rows: runs
1827
+ .slice(0, 12)
1828
+ .map((run) => [
1829
+ String(run.sessionId || '').slice(-8),
1830
+ h(
1831
+ 'b',
1832
+ { style: { color: scoreColor(run.score && run.score.total) } },
1833
+ fmt(run.score && run.score.total) +
1834
+ ' ' +
1835
+ ((run.score && run.score.grade) || '') +
1836
+ (run.score && run.score.ci ? ' [' + fmt(run.score.ci.low) + '–' + fmt(run.score.ci.high) + ']' : ''),
1837
+ ),
1838
+ String(run.loads || 0),
1839
+ String(run.toolCalls || 0),
1840
+ String(run.errors || 0),
1841
+ ]),
1842
+ }),
1843
+ )
1844
+ }
1845
+
1846
+ function McpView(props) {
1847
+ const t = props.t
1848
+ const lang = props.lang || 'zh'
1849
+ const data = props.data || {}
1850
+ const servers = Array.isArray(data.mcpServers) ? data.mcpServers : []
1851
+ const advice = (Array.isArray(data.mcpAdvice) ? data.mcpAdvice : []).slice(0, 6)
1852
+ const failing = []
1853
+ for (const row of servers) {
1854
+ for (const tool of row.tools || []) {
1855
+ if ((tool.errors || 0) > 0) failing.push({ server: row.server, ...tool })
1856
+ }
1857
+ }
1858
+ const calls = servers.reduce((total, row) => total + (row.calls || 0), 0)
1859
+ const errors = servers.reduce((total, row) => total + (row.errors || 0), 0)
1860
+ // With nothing recorded, a chart card plus an empty table card reads as two
1861
+ // broken panels; one honest empty card is the whole state.
1862
+ if (servers.length === 0 || calls === 0) {
1863
+ return h(
1864
+ 'div',
1865
+ { className: 'sev-card' },
1866
+ h('header', { className: 'sev-card-head' }, h('b', null, t.tabs.mcp)),
1867
+ h('div', { className: 'sev-empty' }, t.emptyMcp),
1868
+ )
1869
+ }
1870
+ const latency = (row) =>
1871
+ row.p50Ms === null || row.p50Ms === undefined
1872
+ ? '—'
1873
+ : fmtMs(row.p50Ms) + ' / ' + (row.p95Ms === null || row.p95Ms === undefined ? '—' : fmtMs(row.p95Ms))
1874
+ return h(
1875
+ React.Fragment,
1876
+ null,
1877
+ // No `solo` here: the chart card must line up with the table card below it,
1878
+ // and `.sev-chart--solo` caps the width at 560px.
1879
+ h(McpLatencyChart, {
1880
+ servers,
1881
+ t,
1882
+ thresholdMs: data.mcp && data.mcp.p95Ms,
1883
+ }),
1884
+ h(
1885
+ 'div',
1886
+ { className: 'sev-card' },
1887
+ h(
1888
+ 'header',
1889
+ { className: 'sev-card-head' },
1890
+ h('b', null, t.mcpHead[0]),
1891
+ h('span', null, servers.length + ' · ' + calls + ' ' + t.chartCalls + ' · ' + errors + ' ' + t.chartErrors),
1892
+ ),
1893
+ h(DataTable, {
1894
+ variant: 'mcp',
1895
+ head: t.mcpHead,
1896
+ empty: t.emptyMcp,
1897
+ rows: servers.map((row) => [
1898
+ row.server,
1899
+ h(
1900
+ 'span',
1901
+ { className: 'sev-health' },
1902
+ h('i', { className: 'sev-grade', style: { color: scoreColor(row.health) } }, row.grade || '—'),
1903
+ fmt(row.health),
1904
+ ),
1905
+ String(row.calls || 0),
1906
+ pct(row.errorRate),
1907
+ latency(row),
1908
+ ]),
1909
+ }),
1910
+ ),
1911
+ advice.length > 0
1912
+ ? h(
1913
+ 'div',
1914
+ { className: 'sev-card' },
1915
+ h('header', { className: 'sev-card-head' }, h('b', null, t.mcpFix)),
1916
+ h(
1917
+ 'div',
1918
+ { className: 'sev-advice-list' },
1919
+ advice.map((raw, index) => {
1920
+ const item = adviceView(raw, lang)
1921
+ return h(
1922
+ 'div',
1923
+ { className: 'sev-advice-row', key: item.id + '-' + index },
1924
+ h(
1925
+ 'b',
1926
+ { style: { color: severityColor(item.severity) } },
1927
+ (item.severity === 'critical' ? '🛑 ' : item.severity === 'warning' ? '⚠️ ' : 'ℹ️ ') + item.title,
1928
+ ),
1929
+ h('em', null, '↳ ' + item.fix),
1930
+ )
1931
+ }),
1932
+ ),
1933
+ )
1934
+ : null,
1935
+ failing.length > 0
1936
+ ? h(
1937
+ 'div',
1938
+ { className: 'sev-card' },
1939
+ h('header', { className: 'sev-card-head' }, h('b', null, t.mcpFailing)),
1940
+ h(
1941
+ 'div',
1942
+ { className: 'sev-advice-list' },
1943
+ failing.slice(0, 8).map((tool) =>
1944
+ h(
1945
+ 'div',
1946
+ { className: 'sev-sub-row', key: tool.server + '/' + tool.tool },
1947
+ h('span', null, tool.server + '/' + tool.tool),
1948
+ h('b', null, (tool.errors || 0) + '/' + (tool.calls || 0)),
1949
+ ),
1950
+ ),
1951
+ ),
1952
+ )
1953
+ : null,
1954
+ )
1955
+ }
1956
+
1957
+ function DevView(props) {
1958
+ const t = props.t
1959
+ const data = props.data || {}
1960
+ const scoring = data.scoring || {}
1961
+ const totals = data.totals || {}
1962
+ const weights = scoring.weightsPercent || {}
1963
+ const th = scoring.thresholds || {}
1964
+ const dev = data.dev || {}
1965
+ const rows = [
1966
+ [
1967
+ t.devLabels.weights,
1968
+ ['static', 'reliability', 'effectiveness', 'efficiency']
1969
+ .map((key) => key + ' ' + (weights[key] ?? '—'))
1970
+ .join(' · '),
1971
+ ],
1972
+ [
1973
+ t.devLabels.thresholds,
1974
+ 'A≥' + (th.excellent ?? '—') + ' · B≥' + (th.good ?? '—') + ' · C≥' + (th.pass ?? '—') + ' · D≥60',
1975
+ ],
1976
+ [t.devLabels.minSamples, String(scoring.minSamples ?? '—')],
1977
+ [
1978
+ t.devLabels.totals,
1979
+ (totals.invocations ?? 0) +
1980
+ ' ' +
1981
+ t.devLoads +
1982
+ ' · ' +
1983
+ (totals.closed ?? 0) +
1984
+ ' ' +
1985
+ t.devClosed +
1986
+ ' · ' +
1987
+ (totals.open ?? 0) +
1988
+ ' ' +
1989
+ t.devOpen,
1990
+ ],
1991
+ [t.devLabels.dataDir, data.dataDir || '—'],
1992
+ [t.devLabels.api, DATA_URL],
1993
+ [
1994
+ t.devLabels.module,
1995
+ (dev.moduleVersion ?? '—') +
1996
+ ' / ' +
1997
+ (dev.diskVersion ?? '—') +
1998
+ (dev.skew ? ' ⚠ ' + t.devLabels.skew : ''),
1999
+ ],
2000
+ [t.devLabels.routes, String(dev.routes ?? '—') + ' · ' + t.devLabels.tools + ' ' + String(dev.tools ?? '—')],
2001
+ [t.devLabels.store, totals.storeError ? String(totals.storeError) : 'ok'],
2002
+ [t.version, DATA_VERSION],
2003
+ ]
2004
+ return h(
2005
+ 'div',
2006
+ { className: 'sev-kv' },
2007
+ rows.map(([label, value]) =>
2008
+ h('div', { className: 'sev-kv-row', key: label }, h('span', null, label), h('b', null, String(value))),
2009
+ ),
2010
+ )
2011
+ }
2012
+
2013
+ // client/08-turn.js
2014
+ function scoreOf(data, skill) {
2015
+ const entry = ((data && data.skills) || []).find((item) => item.skill === skill)
2016
+ return entry ? entry.score || {} : null
2017
+ }
2018
+
2019
+ /**
2020
+ * The completed-turn strip: it reads the durable per-turn skill loads from
2021
+ * the report and renders only under turns that actually loaded a skill.
2022
+ */
2023
+ // The slot owner supplies `useChat` as a prop. Split it into two wrapper
2024
+ // components so the hook is never called conditionally: React compares the
2025
+ // returned element type, so a host that stops passing the hook remounts the
2026
+ // plain wrapper instead of changing this component's hook count.
2027
+ function TurnSkillCard(props) {
2028
+ return typeof props.useChat === 'function' ? h(TurnSkillCardWithChat, props) : h(TurnSkillCardPlain, { ...props })
2029
+ }
2030
+
2031
+ function TurnSkillCardWithChat(props) {
2032
+ const nodesSnapshot = props.useChat((snapshot) => snapshot.nodes)
2033
+ return h(TurnSkillCardBody, { ...props, nodesSnapshot })
2034
+ }
2035
+
2036
+ function TurnSkillCardPlain(props) {
2037
+ return h(TurnSkillCardBody, props)
2038
+ }
2039
+
2040
+ function TurnSkillCardBody(props) {
2041
+ const { sessionId, turn, nodesSnapshot } = props
2042
+ const { lang, t } = useLang()
2043
+ const state = useStore()
2044
+
2045
+ useEffect(() => {
2046
+ ensureReport()
2047
+ }, [sessionId, turn && turn.turn])
2048
+
2049
+ if (!turn) return null
2050
+ // `status` is 'closed' on current hosts; older/other builds may omit it or
2051
+ // use a different word, so only a clearly in-flight turn is skipped.
2052
+ const status = typeof turn.status === 'string' ? turn.status.toLowerCase() : ''
2053
+ if (status && /run|stream|pending|activ|progress/.test(status)) return null
2054
+ const turnNumber =
2055
+ typeof turn.turn === 'number'
2056
+ ? turn.turn
2057
+ : typeof turn.number === 'number'
2058
+ ? turn.number
2059
+ : typeof turn.index === 'number'
2060
+ ? turn.index
2061
+ : null
2062
+ if (turnNumber === null) return null
2063
+ const data = state.data
2064
+ const rows = ((data && data.turnLoads) || []).filter((row) => row.sessionId === sessionId && row.turn === turnNumber)
2065
+ if (rows.length === 0) return null
2066
+
2067
+ let toolCalls = null
2068
+ let errors = null
2069
+ if (nodesSnapshot && typeof nodesSnapshot.values === 'function') {
2070
+ const inTurn = [...nodesSnapshot.values()].filter(
2071
+ (node) => node && node.location && node.location.turn && node.location.turn.turn === turnNumber,
2072
+ )
2073
+ toolCalls = inTurn.filter((node) => node.kind === 'tool-call').length
2074
+ errors = inTurn.filter(
2075
+ (node) =>
2076
+ node.kind === 'tool-call' &&
2077
+ node.data &&
2078
+ (node.data.isError === true || (node.data.result && node.data.result.isError === true)),
2079
+ ).length
2080
+ }
2081
+
2082
+ const skills = [...new Set(rows.flatMap((row) => row.skills))]
2083
+ const skillEntries = ((data && data.skills) || []).filter((entry) => skills.includes(entry.skill))
2084
+ // One next fix per loaded skill: a turn can load several skills, and the
2085
+ // strip should surface each skill's own next move instead of a single
2086
+ // global winner. Cap at three so the strip stays readable.
2087
+ const nextSteps = skillEntries
2088
+ .map((entry) => {
2089
+ const first = (entry.advice || [])
2090
+ .filter((item) => item.severity === 'critical' || item.severity === 'warning')
2091
+ .sort((a, b) => (a.severity === 'critical' ? 0 : 1) - (b.severity === 'critical' ? 0 : 1))[0]
2092
+ return first ? { ...adviceView(first, lang), skill: entry.skill } : null
2093
+ })
2094
+ .filter(Boolean)
2095
+ .slice(0, 3)
2096
+ return h(
2097
+ React.Fragment,
2098
+ null,
2099
+ h('style', { key: 'sev-turn-style' }, TURN_STYLES),
2100
+ h(
2101
+ 'div',
2102
+ { className: 'sev-turn' },
2103
+ h('span', { className: 'sev-turn-label' }, t.turnLabel),
2104
+ ...skills.map((skill) => {
2105
+ const score = scoreOf(data, skill)
2106
+ return h(
2107
+ 'span',
2108
+ { className: 'sev-turn-chip', key: skill },
2109
+ h('b', null, skill),
2110
+ score && typeof score.total === 'number'
2111
+ ? h('i', { style: { color: scoreColor(score.total) } }, fmt(score.total) + ' ' + (score.grade || ''))
2112
+ : null,
2113
+ )
2114
+ }),
2115
+ toolCalls !== null
2116
+ ? h(
2117
+ 'span',
2118
+ { className: 'sev-turn-meta' },
2119
+ toolCalls + ' ' + t.turnCalls + (errors ? ' · ' + errors + ' ' + t.turnErrors : ''),
2120
+ )
2121
+ : null,
2122
+ ...nextSteps.map((nextStep) =>
2123
+ h(
2124
+ 'span',
2125
+ { className: 'sev-turn-next', key: 'next-' + nextStep.skill },
2126
+ t.turnNext + ' ',
2127
+ h('b', null, nextStep.skill),
2128
+ ' · ' + (t.dims[nextStep.dimension] || nextStep.dimension || 'static') + ' · ' + nextStep.title,
2129
+ ),
2130
+ ),
2131
+ h(
2132
+ 'details',
2133
+ { className: 'sev-turn-detail' },
2134
+ h('summary', null, t.turnDetail),
2135
+ ...skills.map((skill) => {
2136
+ const entry = ((data && data.skills) || []).find((item) => item.skill === skill)
2137
+ const advice = ((entry && entry.advice) || []).slice(0, 3)
2138
+ const history = ((data && data.edits) || []).filter((edit) => edit.skill === skill).slice(0, 3)
2139
+ return h(
2140
+ 'div',
2141
+ { className: 'sev-turn-advice', key: 'advice-' + skill },
2142
+ h('b', null, skill),
2143
+ advice.length === 0
2144
+ ? h('span', null, t.noTurnAdvice)
2145
+ : advice.map((raw, index) => {
2146
+ const item = adviceView(raw, lang)
2147
+ return h(
2148
+ 'span',
2149
+ { key: item.id || String(index) },
2150
+ (item.severity === 'critical' ? '🛑 ' : item.severity === 'warning' ? '⚠️ ' : 'ℹ️ ') + item.title,
2151
+ )
2152
+ }),
2153
+ history.length > 0
2154
+ ? h(
2155
+ 'div',
2156
+ { className: 'sev-turn-history', key: 'history-' + skill },
2157
+ h('span', null, t.turnHistory + ' '),
2158
+ ...history.map((edit, index) =>
2159
+ h(
2160
+ 'span',
2161
+ { key: (edit.at || '') + '-' + index },
2162
+ (edit.verdict === 'accept' ? '✅ ' : edit.verdict === 'reject' ? '🚫 ' : '⚠️ ') +
2163
+ (edit.dimension || 'static') +
2164
+ (edit.hypothesis ? ' · ' + edit.hypothesis.slice(0, 60) : ''),
2165
+ ),
2166
+ ),
2167
+ )
2168
+ : null,
2169
+ )
2170
+ }),
2171
+ ),
2172
+ ),
2173
+ )
2174
+ }
2175
+
2176
+ const TURN_STYLES = [
2177
+ '.sev-turn{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:8px 0 2px;padding:7px 10px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:10px;background:var(--dsw-alias-bg-layer-1, #ffffff);font-size:11.5px;color:var(--dsw-alias-label-secondary, #71717a)}',
2178
+ '.sev-turn-label{font-weight:600;color:var(--dsw-alias-label-primary, #18181b)}',
2179
+ '.sev-turn-chip{display:inline-flex;align-items:center;gap:5px;padding:2px 8px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:999px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2180
+ '.sev-turn-chip b{font-weight:600;color:var(--dsw-alias-label-primary, #18181b)}',
2181
+ '.sev-turn-chip i{font-style:normal;font-variant-numeric:tabular-nums}',
2182
+ '.sev-turn-meta{font-variant-numeric:tabular-nums}',
2183
+ '.sev-turn-next{display:inline-flex;align-items:center;gap:4px;padding:2px 7px;border-radius:999px;background:var(--dsw-alias-bg-layer-2, #f4f4f5);color:var(--dsw-alias-label-secondary, #52525b);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
2184
+ '.sev-turn-next b{font-weight:600;color:var(--dsw-alias-label-primary, #18181b)}',
2185
+ '.sev-turn-history{display:flex;flex-direction:column;gap:2px;margin-top:4px;padding-top:4px;border-top:1px dashed var(--dsw-alias-border-l1, #e4e4e7)}',
2186
+ '.sev-turn-history span{opacity:.85}',
2187
+ '.sev-settings{display:flex;flex-direction:column;gap:14px;padding:4px 0;font-size:12px;max-width:760px}',
2188
+ '.sev-settings-group h4{margin:12px 0 2px;font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary, #71717a)}',
2189
+ '.sev-settings-row{display:grid;grid-template-columns:minmax(220px,1fr) auto;align-items:center;gap:14px;padding:9px 0;border-bottom:1px solid var(--dsw-alias-border-l1, #f0f0f2)}',
2190
+ '.sev-settings-label{display:flex;flex-direction:column;gap:2px}',
2191
+ '.sev-settings-label small{font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2192
+ '.sev-settings-control{display:flex;align-items:center;gap:6px;justify-content:flex-end}',
2193
+ '.sev-settings-control em{font-style:normal;font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2194
+ '.sev-settings-row input[type=number]{width:120px;padding:5px 8px;border:1px solid var(--dsw-alias-border-l1, #d4d4d8);border-radius:7px;font:inherit;background:transparent;color:inherit;text-align:right}',
2195
+ '.sev-switch{position:relative;display:inline-flex;align-items:center;cursor:pointer}',
2196
+ '.sev-switch input{position:absolute;opacity:0;width:1px;height:1px}',
2197
+ '.sev-switch i{display:block;width:34px;height:20px;border-radius:999px;background:var(--dsw-alias-border-l2, #d4d4d8);transition:background .15s}',
2198
+ '.sev-switch i::after{content:"";display:block;width:16px;height:16px;margin:2px;border-radius:50%;background:#fff;transition:transform .15s}',
2199
+ '.sev-switch input:checked + i{background:var(--dsw-alias-brand-primary, #4d6bfe)}',
2200
+ '.sev-switch input:checked + i::after{transform:translateX(14px)}',
2201
+ '.sev-switch input:focus-visible + i{outline:2px solid var(--dsw-alias-brand-primary, #4d6bfe);outline-offset:2px}',
2202
+ '.sev-settings-actions{display:flex;gap:8px}',
2203
+ '.sev-settings-status{color:#16a34a;font-size:11.5px}',
2204
+ '.sev-settings-status.sev-error{color:#c92a2a}',
2205
+ '.sev-settings-heading{font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary, #18181b);margin-bottom:2px}',
2206
+ '.sev-turn-detail{flex-basis:100%;width:100%;margin:6px 0 0;padding-top:6px;border-top:1px dashed var(--dsw-alias-border-l1, #e4e4e7)}',
2207
+ '.sev-turn-detail summary{cursor:pointer;color:var(--dsw-alias-brand-primary, #4d6bfe);font-weight:500}',
2208
+ '.sev-turn-detail[open] summary{margin-bottom:4px}',
2209
+ '.sev-turn-advice{display:grid;gap:3px;margin:6px 0 0;padding:6px 9px;border-left:2px solid var(--dsw-alias-border-l2, #d4d4d8);border-radius:0 8px 8px 0;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2210
+ '.sev-turn-advice + .sev-turn-advice{margin-top:8px}',
2211
+ '.sev-turn-advice b{display:block;margin-bottom:2px;color:var(--dsw-alias-label-primary, #18181b)}',
2212
+ ].join('\n')
2213
+
2214
+ // client/09-overlay.js
2215
+ function ReportOverlay() {
2216
+ const state = useStore()
2217
+ const { lang, t } = useLang()
2218
+ const [copyState, setCopyState] = useState('idle')
2219
+ const copyTimer = useRef(null)
2220
+ const mounted = useRef(true)
2221
+ const dialogRef = useRef(null)
2222
+ const openerRef = useRef(null)
2223
+
2224
+ // Restore keyboard focus to whatever opened the popup, and keep Tab inside
2225
+ // the dialog while it is open (it declares aria-modal, so focus must not
2226
+ // wander behind the backdrop).
2227
+ useEffect(() => {
2228
+ if (!state.open) return undefined
2229
+ openerRef.current = typeof document !== 'undefined' ? document.activeElement : null
2230
+ return () => {
2231
+ const opener = openerRef.current
2232
+ openerRef.current = null
2233
+ if (opener && typeof opener.focus === 'function') {
2234
+ try {
2235
+ opener.focus()
2236
+ } catch {
2237
+ // the opener may have unmounted
2238
+ }
2239
+ }
2240
+ }
2241
+ }, [state.open])
2242
+
2243
+ const trapTab = (event) => {
2244
+ if (event.key !== 'Tab') return
2245
+ const root = dialogRef.current
2246
+ if (!root) return
2247
+ const nodes = [
2248
+ ...root.querySelectorAll('button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])'),
2249
+ ].filter((node) => !node.disabled && node.offsetParent !== null)
2250
+ if (nodes.length === 0) return
2251
+ const first = nodes[0]
2252
+ const last = nodes[nodes.length - 1]
2253
+ if (event.shiftKey && document.activeElement === first) {
2254
+ event.preventDefault()
2255
+ last.focus()
2256
+ } else if (!event.shiftKey && document.activeElement === last) {
2257
+ event.preventDefault()
2258
+ first.focus()
2259
+ }
2260
+ }
2261
+
2262
+ useEffect(() => {
2263
+ if (!state.open) return undefined
2264
+ const onKey = (event) => {
2265
+ if (event.key === 'Escape') closeReport()
2266
+ }
2267
+ window.addEventListener('keydown', onKey)
2268
+ // Keep the numbers moving while a run is in progress. Windows only land
2269
+ // at turn end, so a live view shows new loads immediately and their
2270
+ // statistics right after the turn settles.
2271
+ const timer = setInterval(() => {
2272
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
2273
+ load()
2274
+ }, REFRESH_MS)
2275
+ return () => {
2276
+ window.removeEventListener('keydown', onKey)
2277
+ clearInterval(timer)
2278
+ }
2279
+ }, [state.open])
2280
+
2281
+ useEffect(
2282
+ () => () => {
2283
+ mounted.current = false
2284
+ if (copyTimer.current) clearTimeout(copyTimer.current)
2285
+ },
2286
+ [],
2287
+ )
2288
+
2289
+ const copy = async () => {
2290
+ const text = buildMarkdown(state.data)
2291
+ const ok = await copyText(text)
2292
+ if (!mounted.current) return
2293
+ setCopyState(ok ? 'copied' : 'failed')
2294
+ if (copyTimer.current) clearTimeout(copyTimer.current)
2295
+ copyTimer.current = setTimeout(() => setCopyState('idle'), 1500)
2296
+ }
2297
+
2298
+ const data = state.data
2299
+ const skills = data && Array.isArray(data.skills) ? data.skills : []
2300
+ const totals = (data && data.totals) || {}
2301
+
2302
+ return h(
2303
+ React.Fragment,
2304
+ null,
2305
+ h('style', { key: 'sev-style' }, STYLES),
2306
+ state.open
2307
+ ? h(
2308
+ 'div',
2309
+ {
2310
+ className: 'sev-backdrop',
2311
+ role: 'presentation',
2312
+ onMouseDown: (event) => {
2313
+ if (event.target === event.currentTarget) closeReport()
2314
+ },
2315
+ },
2316
+ h(
2317
+ 'div',
2318
+ {
2319
+ className: 'sev-dialog',
2320
+ role: 'dialog',
2321
+ 'aria-modal': 'true',
2322
+ 'aria-label': t.title,
2323
+ ref: dialogRef,
2324
+ onKeyDown: trapTab,
2325
+ },
2326
+ h(
2327
+ 'header',
2328
+ { className: 'sev-head' },
2329
+ h(
2330
+ 'div',
2331
+ { className: 'sev-head-text' },
2332
+ h('div', { className: 'sev-title' }, t.title),
2333
+ h('div', { className: 'sev-sub' }, t.subtitle),
2334
+ h(
2335
+ 'div',
2336
+ { className: 'sev-tabs', role: 'tablist' },
2337
+ ['skills', 'steps', 'runs', 'mcp', 'dev'].map((view) =>
2338
+ h(
2339
+ 'button',
2340
+ {
2341
+ key: view,
2342
+ type: 'button',
2343
+ role: 'tab',
2344
+ 'aria-selected': state.view === view,
2345
+ className: 'sev-tab' + (state.view === view ? ' sev-tab--on' : ''),
2346
+ onClick: () => setView(view),
2347
+ },
2348
+ t.tabs[view],
2349
+ ),
2350
+ ),
2351
+ ),
2352
+ ),
2353
+ h(
2354
+ 'div',
2355
+ { className: 'sev-head-actions' },
2356
+ h(
2357
+ 'button',
2358
+ { type: 'button', className: 'sev-btn', onClick: load, disabled: state.loading },
2359
+ t.refresh,
2360
+ ),
2361
+ h(
2362
+ 'button',
2363
+ { type: 'button', className: 'sev-btn', onClick: copy },
2364
+ h(
2365
+ 'span',
2366
+ { role: 'status', 'aria-live': 'polite' },
2367
+ copyState === 'copied' ? t.copied : copyState === 'failed' ? t.copyFailed : t.copy,
2368
+ ),
2369
+ ),
2370
+ h(
2371
+ 'button',
2372
+ {
2373
+ type: 'button',
2374
+ className: 'sev-btn sev-btn--icon',
2375
+ onClick: closeReport,
2376
+ 'aria-label': t.close,
2377
+ title: t.close,
2378
+ autoFocus: true,
2379
+ },
2380
+ '✕',
2381
+ ),
2382
+ ),
2383
+ ),
2384
+ h(
2385
+ 'div',
2386
+ { className: 'sev-body' },
2387
+ state.loading && !data ? h('div', { className: 'sev-empty' }, t.loading) : null,
2388
+ data && !data.scoring
2389
+ ? h('div', { className: 'sev-stale' }, h('b', null, t.staleTitle), h('span', null, t.staleHint))
2390
+ : null,
2391
+ state.error
2392
+ ? h('div', { className: 'sev-error' }, t.failed + ': ' + state.error + ' — ' + DATA_URL)
2393
+ : null,
2394
+ state.view === 'skills'
2395
+ ? data && data.ranking
2396
+ ? h(
2397
+ 'div',
2398
+ { className: 'sev-note' },
2399
+ lang === 'zh' && data.ranking.noteZh ? data.ranking.noteZh : data.ranking.note,
2400
+ )
2401
+ : null
2402
+ : null,
2403
+ state.view === 'skills'
2404
+ ? !state.loading && !state.error && skills.length === 0
2405
+ ? h('div', { className: 'sev-empty' }, t.empty)
2406
+ : skills.map((skill) =>
2407
+ h(SkillCard, {
2408
+ key: skill.skill,
2409
+ skill,
2410
+ t,
2411
+ lang,
2412
+ onTrace: (name) => store.set((current) => ({ ...current, view: 'steps', stepFilter: name })),
2413
+ }),
2414
+ )
2415
+ : state.view === 'steps'
2416
+ ? h(StepsView, {
2417
+ data,
2418
+ t,
2419
+ filter: state.stepFilter || '',
2420
+ onFilter: (name) => store.set((current) => ({ ...current, stepFilter: name })),
2421
+ })
2422
+ : state.view === 'runs'
2423
+ ? h(RunsView, { data, t })
2424
+ : state.view === 'mcp'
2425
+ ? h(McpView, { data, t, lang })
2426
+ : h(DevView, { data, t }),
2427
+ ),
2428
+ h(
2429
+ 'footer',
2430
+ { className: 'sev-foot' },
2431
+ h(
2432
+ 'span',
2433
+ null,
2434
+ (totals.invocations || 0) + ' ' + t.loads + ' · ' + (totals.skills || 0) + ' ' + t.skillsWord,
2435
+ ),
2436
+ h(
2437
+ 'span',
2438
+ { className: 'sev-foot-hint' },
2439
+ (data && data.scoring
2440
+ ? Object.entries(data.scoring.weightsPercent || {})
2441
+ .map(([key, value]) => key + ' ' + value)
2442
+ .join('/') +
2443
+ ' · A≥' +
2444
+ ((data.scoring.thresholds || {}).excellent ?? 90) +
2445
+ ' — '
2446
+ : '') +
2447
+ t.footerHint +
2448
+ ' · ' +
2449
+ t.auto,
2450
+ ),
2451
+ h('span', { className: 'sev-foot-dir' }, (data && data.dataDir) || ''),
2452
+ ),
2453
+ ),
2454
+ )
2455
+ : null,
2456
+ )
2457
+ }
2458
+
2459
+ // client/10-styles.js
2460
+ const STYLES = [
2461
+ '.sev-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:9px;background:var(--dsw-alias-bg-layer-1, #ffffff);color:var(--dsw-alias-label-secondary, #71717a);font-size:12px;line-height:1;cursor:pointer;white-space:nowrap;font-family:inherit}',
2462
+ '.sev-btn:hover{color:var(--dsw-alias-label-primary, #18181b);border-color:var(--dsw-alias-border-l2, #d4d4d8)}',
2463
+ '.sev-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary, #4d6bfe);outline-offset:1px}',
2464
+ '.sev-btn--icon{width:30px;padding:0}',
2465
+ '.sev-btn--ghost{background:transparent}',
2466
+ '.sev-backdrop{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:28px;background:rgba(9,9,11,.44);pointer-events:auto}',
2467
+ '.sev-dialog{display:flex;flex-direction:column;width:min(780px,94vw);max-height:84vh;overflow:hidden;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:16px;background:var(--dsw-alias-bg-overlay, #ffffff);color:var(--dsw-alias-label-primary, #18181b);box-shadow:0 26px 70px rgba(0,0,0,.34);font-size:13px;line-height:1.5}',
2468
+ '.sev-head{display:flex;align-items:flex-start;gap:12px;padding:16px 18px 12px;border-bottom:1px solid var(--dsw-alias-border-l1, #e4e4e7)}',
2469
+ '.sev-head-text{flex:1;min-width:0}',
2470
+ '.sev-title{font-size:15px;font-weight:600}',
2471
+ '.sev-sub{margin-top:3px;color:var(--dsw-alias-label-secondary, #71717a);font-size:11.5px;line-height:1.45}',
2472
+ '.sev-head-actions{display:flex;gap:6px;flex:none}',
2473
+ '.sev-body{flex:1;overflow:auto;padding:14px 18px 18px;display:flex;flex-direction:column;gap:12px}',
2474
+ '.sev-empty{padding:26px 0;text-align:center;color:var(--dsw-alias-label-secondary, #71717a)}',
2475
+ '.sev-error{margin:0;padding:10px 12px;border-radius:10px;border:1px solid var(--dsw-alias-state-error-primary, #c92a2a);color:var(--dsw-alias-state-error-primary, #c92a2a);font-size:12px;word-break:break-all}',
2476
+ '.sev-card{border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:12px;background:var(--dsw-alias-bg-layer-1, #ffffff);padding:12px 14px}',
2477
+ '.sev-card-head{display:flex;align-items:baseline;gap:10px}',
2478
+ '.sev-name{flex:1;font-weight:600;font-size:13.5px;word-break:break-word}',
2479
+ '.sev-grade{font-weight:700;font-size:17px;font-variant-numeric:tabular-nums}',
2480
+ '.sev-total{font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}',
2481
+ '.sev-provisional{margin-top:2px;font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2482
+ '.sev-ci{margin-top:2px;font-size:11px;color:var(--dsw-alias-label-secondary, #71717a);font-variant-numeric:tabular-nums}',
2483
+ '.sev-note{margin-bottom:10px;padding:8px 10px;border-radius:9px;border:1px solid var(--dsw-alias-state-warn-primary, #d97706);color:var(--dsw-alias-label-primary, #18181b);font-size:11.5px;line-height:1.45}',
2484
+ '.sev-stale{display:grid;gap:3px;margin-bottom:10px;padding:10px 12px;border-radius:10px;border:1px solid var(--dsw-alias-state-error-primary, #c92a2a);background:var(--dsw-alias-bg-layer-1, #ffffff);font-size:11.5px;line-height:1.5}',
2485
+ '.sev-stale b{color:var(--dsw-alias-state-error-primary, #c92a2a);font-size:12px}',
2486
+ '.sev-stale span{color:var(--dsw-alias-label-secondary, #71717a)}',
2487
+ '.sev-dims{display:grid;gap:4px;margin:9px 0 8px}',
2488
+ '.sev-dim{display:grid;grid-template-columns:96px 1fr 40px;align-items:center;gap:8px}',
2489
+ '.sev-dim-label{font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2490
+ '.sev-dim-track{display:block;height:6px;border-radius:4px;background:var(--dsw-alias-bg-layer-2, #f4f4f5);overflow:hidden}',
2491
+ '.sev-dim-track i{display:block;height:100%;border-radius:4px;min-width:2px}',
2492
+ '.sev-dim b{font-size:11px;font-weight:600;text-align:right;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary, #71717a)}',
2493
+ '.sev-meta{font-size:11px;color:var(--dsw-alias-label-secondary, #71717a);font-variant-numeric:tabular-nums}',
2494
+ '.sev-advice{list-style:none;margin:9px 0 0;padding:0;display:grid;gap:7px}',
2495
+ '.sev-advice li{border-left:3px solid var(--dsw-alias-border-l2, #d4d4d8);padding-left:9px}',
2496
+ '.sev-advice b{display:block;font-size:12px;font-weight:600}',
2497
+ '.sev-advice span{display:block;font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2498
+ '.sev-advice em{display:block;margin-top:2px;font-size:11px;font-style:normal;color:var(--dsw-alias-label-primary, #18181b);opacity:.86}',
2499
+ '.sev-tabs{display:flex;gap:4px;margin-top:8px}',
2500
+ '.sev-tab{border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary, #71717a);font-size:12px;padding:3px 9px;border-radius:7px;cursor:pointer;font-family:inherit}',
2501
+ '.sev-tab:hover{color:var(--dsw-alias-label-primary, #18181b);background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2502
+ '.sev-tab--on{color:var(--dsw-alias-label-primary, #18181b);background:var(--dsw-alias-bg-layer-2, #f4f4f5);font-weight:600}',
2503
+ '.sev-table{display:grid;gap:2px;font-size:12px}',
2504
+ '.sev-kv{display:grid;gap:6px;font-size:12px}',
2505
+ // NOTE: '.sev-sub' belongs to the panel subtitle; the advice container used to
2506
+ // reuse that class and silently restyled the header. It is now its own class.
2507
+ '.sev-advice-list{display:grid;gap:4px;margin-top:8px;font-size:12px}',
2508
+ '.sev-sub-row{display:flex;justify-content:space-between;gap:10px;padding:4px 8px;border-radius:7px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2509
+ '.sev-sub-row b{font-variant-numeric:tabular-nums;color:var(--dsw-alias-state-error-primary, #c92a2a)}',
2510
+ '.sev-advice-row{display:grid;gap:2px;padding:6px 8px;border-radius:7px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2511
+ '.sev-card{border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:12px;padding:10px 12px;background:var(--dsw-alias-bg-layer-1, #fff);min-width:0}',
2512
+ '.sev-card-head{display:flex;align-items:baseline;justify-content:space-between;gap:8px;margin-bottom:4px;font-size:12px}',
2513
+ '.sev-card-head b{font-weight:600}',
2514
+ '.sev-card-head span{color:var(--dsw-alias-label-secondary, #71717a);font-size:10.5px;font-variant-numeric:tabular-nums}',
2515
+ '.sev-table--mcp .sev-tr{grid-template-columns:1.5fr .8fr .5fr .6fr 1fr}',
2516
+ '.sev-health{display:inline-flex;align-items:center;gap:5px;font-variant-numeric:tabular-nums}',
2517
+ '.sev-grade{display:inline-flex;align-items:center;justify-content:center;min-width:16px;height:16px;padding:0 4px;border-radius:5px;font-style:normal;font-size:10px;font-weight:700;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2518
+ '.sev-lat{display:grid;gap:10px;padding:4px 0 2px}',
2519
+ '.sev-lat-row{display:grid;gap:4px}',
2520
+ '.sev-lat-head{display:flex;justify-content:space-between;gap:10px;font-size:11.5px}',
2521
+ '.sev-lat-head b{font-weight:600}',
2522
+ '.sev-lat-head span{color:var(--dsw-alias-label-secondary, #71717a);font-variant-numeric:tabular-nums}',
2523
+ '.sev-meter{position:relative;height:8px;border-radius:999px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2524
+ '.sev-meter-fill{position:absolute;left:0;top:0;height:100%;border-radius:999px}',
2525
+ '.sev-meter-fill--p95{background:var(--dsw-alias-state-warn-primary, #d97706);opacity:.35}',
2526
+ '.sev-meter-fill--p50{background:var(--dsw-alias-brand-primary, #4d6bfe)}',
2527
+ '.sev-meter-threshold{position:absolute;top:-4px;bottom:-4px;width:0;border-left:1px dashed var(--dsw-alias-state-error-primary, #c92a2a);opacity:.75}',
2528
+ '.sev-advice-row b{font-size:12px;font-weight:600}',
2529
+ '.sev-advice-row em{font-style:normal;font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2530
+ '.sev-kv-row{display:grid;grid-template-columns:120px 1fr;gap:10px;padding:5px 8px;border-radius:7px;background:var(--dsw-alias-bg-layer-1, #ffffff)}',
2531
+ '.sev-kv-row span{color:var(--dsw-alias-label-secondary, #71717a);font-size:11px}',
2532
+ '.sev-kv-row b{font-weight:500;word-break:break-all;font-variant-numeric:tabular-nums}',
2533
+ '.sev-tr{display:grid;grid-template-columns:1.4fr .6fr .6fr .6fr .6fr;gap:8px;padding:6px 8px;border-radius:7px}',
2534
+ '.sev-tr:nth-child(odd){background:var(--dsw-alias-bg-layer-1, #ffffff)}',
2535
+ '.sev-th{color:var(--dsw-alias-label-secondary, #71717a);font-size:11px;text-transform:none}',
2536
+ '.sev-tr span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-variant-numeric:tabular-nums}',
2537
+ '.sev-strong{font-weight:600}',
2538
+ '.sev-foot{display:flex;align-items:center;gap:10px;padding:9px 18px;border-top:1px solid var(--dsw-alias-border-l1, #e4e4e7);font-size:11px;color:var(--dsw-alias-label-secondary, #71717a)}',
2539
+ '.sev-foot-hint{flex:1;text-align:center}',
2540
+ '.sev-foot-dir{max-width:36%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl}',
2541
+ '.sev-trace{padding:2px 7px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:999px;background:transparent;color:var(--dsw-alias-label-secondary, #71717a);font:inherit;font-size:10.5px;cursor:pointer;white-space:nowrap}',
2542
+ '.sev-trace:hover{color:var(--dsw-alias-brand-primary, #4d6bfe);border-color:var(--dsw-alias-brand-primary, #4d6bfe)}',
2543
+ '.sev-steps{display:flex;flex-direction:column;gap:12px}',
2544
+ '.sev-steps-kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px}',
2545
+ '.sev-recent{display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:8px 12px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:10px;font-size:11px}',
2546
+ '.sev-recent b{font-weight:600}',
2547
+ '.sev-recent-turn{display:flex;flex-direction:column;gap:3px;min-width:92px;font-size:10px;color:var(--dsw-alias-label-secondary, #71717a)}',
2548
+ '.sev-recent-turn i{display:block;height:5px;border-radius:3px;background:var(--dsw-alias-brand-primary, #4d6bfe)}',
2549
+ '.sev-recent-turn em{font-style:normal;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary, #18181b)}',
2550
+ '.sev-step-filters{display:flex;align-items:center;gap:6px;flex-wrap:wrap;font-size:11px}',
2551
+ '.sev-step-formula{font-size:10.5px;color:var(--dsw-alias-label-secondary, #71717a)}',
2552
+ '.sev-turn{border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:12px;overflow:hidden;background:var(--dsw-alias-bg-layer-1, #fff)}',
2553
+ '.sev-turn-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 12px;border-bottom:1px solid var(--dsw-alias-border-l1, #e4e4e7);font-size:11.5px;background:var(--dsw-alias-bg-layer-2, #f4f4f5)}',
2554
+ '.sev-turn-meta{flex:1;min-width:120px;font-size:10.5px;color:var(--dsw-alias-label-secondary, #71717a)}',
2555
+ '.sev-turn-avg{font-weight:600;font-variant-numeric:tabular-nums}',
2556
+ '.sev-turn-delta,.sev-step-delta{font-size:10.5px;font-variant-numeric:tabular-nums}',
2557
+ '.sev-step-delta--up{color:#2f9e44}',
2558
+ '.sev-step-delta--down{color:#c92a2a}',
2559
+ '.sev-step-delta--flat{color:var(--dsw-alias-label-secondary, #71717a)}',
2560
+ '.sev-steplist{list-style:none;margin:0;padding:2px 0;display:grid}',
2561
+ '.sev-step{display:flex;align-items:center;gap:10px;padding:5px 12px}',
2562
+ '.sev-step:nth-child(odd){background:color-mix(in srgb, var(--dsw-alias-bg-layer-2, #f4f4f5) 55%, transparent)}',
2563
+ '.sev-step-score{flex:none;width:44px;height:26px;display:inline-flex;align-items:center;justify-content:center;border:1px solid;border-radius:7px;font-weight:700;font-size:12px;font-variant-numeric:tabular-nums}',
2564
+ '.sev-step-main{flex:1;min-width:0}',
2565
+ '.sev-step-title{display:flex;align-items:center;gap:8px;font-size:11.5px;flex-wrap:wrap}',
2566
+ '.sev-step-sub{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-top:1px;font-size:10px;color:var(--dsw-alias-label-secondary, #71717a)}',
2567
+ '.sev-step-skill{padding:0 6px;border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:999px;background:transparent;color:inherit;font:inherit;font-size:9.5px;cursor:pointer}',
2568
+ '.sev-step-skill:hover{color:var(--dsw-alias-brand-primary, #4d6bfe);border-color:var(--dsw-alias-brand-primary, #4d6bfe)}',
2569
+ '.sev-step-err{color:#c92a2a}',
2570
+ '.sev-muted{color:var(--dsw-alias-label-secondary, #71717a)}',
2571
+ '.sev-charts{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:12px}',
2572
+ '.sev-chart{border:1px solid var(--dsw-alias-border-l1, #e4e4e7);border-radius:12px;padding:10px 12px;background:var(--dsw-alias-bg-layer-1, #fff);min-width:0}',
2573
+ '.sev-chart-head{display:flex;align-items:baseline;justify-content:space-between;gap:8px;margin-bottom:6px;font-size:12px}',
2574
+ '.sev-chart-head b{font-weight:600}',
2575
+ '.sev-chart-head span{color:var(--dsw-alias-label-secondary, #71717a);font-size:10.5px;font-variant-numeric:tabular-nums}',
2576
+ '.sev-chart-svg{display:block;width:100%;height:auto;color:var(--dsw-alias-label-secondary, #71717a);overflow:visible}',
2577
+ '.sev-chart-empty{padding:22px 0;text-align:center;color:var(--dsw-alias-label-secondary, #71717a);font-size:11px}',
2578
+ '.sev-chart--solo{max-width:560px}',
2579
+ '.sev-chart-legend{list-style:none;margin:0;padding:0;display:grid;gap:3px;font-size:10.5px;color:var(--dsw-alias-label-secondary, #71717a)}',
2580
+ '.sev-chart-legend li{display:flex;align-items:center;gap:5px}',
2581
+ '.sev-chart-legend i{width:8px;height:8px;border-radius:2px;display:inline-block;flex:none}',
2582
+ '.sev-chart-legend b{color:var(--dsw-alias-label-primary, #18181b);font-variant-numeric:tabular-nums}',
2583
+ '.sev-donut-wrap{display:flex;align-items:center;gap:12px}',
2584
+ '.sev-donut{width:84px;height:84px;flex:none}',
2585
+ '.sev-spark{width:64px;height:18px;flex:none;opacity:0.9}',
2586
+ '@media(max-width:720px){.sev-charts{grid-template-columns:1fr}}',
2587
+ ].join('\n')
2588
+
2589
+ // client/11-apply.js
2590
+ return {
2591
+ inject: ['slots', 'locale'],
2592
+ apply(ctx) {
2593
+ env.locale = ctx.locale
2594
+ ctx.slots.inject('conversation.chat.turnTail', () =>
2595
+ ctx.slots.register({ name: 'conversation.chat.turnTail', id: 'skill-eval-turn', order: 30 }, TurnSkillCard),
2596
+ )
2597
+ // Board: sidebar panel icon + the main panel it addresses (same pattern
2598
+ // as the context plugin). The icon label follows the page language.
2599
+ const panelLabel = () => {
2600
+ let active
2601
+ try {
2602
+ const snapshot = ctx.locale && typeof ctx.locale.getSnapshot === 'function' ? ctx.locale.getSnapshot() : null
2603
+ active = snapshot && snapshot.active ? String(snapshot.active) : ''
2604
+ } catch {
2605
+ // fall back to the browser language below
2606
+ }
2607
+ if (!active && typeof navigator !== 'undefined') active = String(navigator.language || '')
2608
+ return /^zh/i.test(active) ? '技能评测' : 'Skill eval'
2609
+ }
2610
+ ctx.slots.inject('sidebar.panellist', () =>
2611
+ ctx.slots.register({ name: 'sidebar.panellist', id: 'skill-eval', order: 40, label: panelLabel }, PanelIcon),
2612
+ )
2613
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'skill-eval' }, BoardPanel))
2614
+ // Two human entry points by design: the in-conversation strip (below)
2615
+ // and one board row in the session header's More menu. Settings live in
2616
+ // the plugin's own row config page, not a separate section.
2617
+ if (ENABLE_POPUP) {
2618
+ ctx.slots.inject('sidebar.footer.action', () =>
2619
+ ctx.slots.register(
2620
+ { name: 'sidebar.footer.action', id: 'skill-eval-open', order: 30, label: panelLabel },
2621
+ FooterAction,
2622
+ ),
2623
+ )
2624
+ ctx.slots.inject('shell.overlay', () =>
2625
+ ctx.slots.register({ name: 'shell.overlay', id: 'skill-eval-modal', order: 900 }, ReportOverlay),
2626
+ )
2627
+ }
2628
+ // Settings: the bundle's own config page (Settings → Plugins → this
2629
+ // bundle), keyed by the package name — the same seat the context plugin
2630
+ // uses for its settings.
2631
+ ctx.slots.inject('plugins.bundle.config', () =>
2632
+ ctx.slots.register({ name: 'plugins.bundle.config', key: 'dsh-skill-eval' }, RowConfig),
2633
+ )
2634
+ },
2635
+ }
2636
+ },
2637
+ })