dsh-agent-control-center 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +217 -83
  3. package/README.zh.md +159 -58
  4. package/client.js +7660 -2005
  5. package/cordis.patch.yml +5 -0
  6. package/docs/01-CONTRACT.md +3 -2
  7. package/docs/05-ACCEPTANCE-EVIDENCE.md +81 -0
  8. package/docs/06-UX-OPTIMIZATION.md +57 -0
  9. package/docs/07-GUIDE.md +327 -0
  10. package/docs/08-COMPATIBILITY.md +202 -0
  11. package/docs/09-ARCHITECTURE.md +333 -0
  12. package/docs/ROADMAP.md +448 -0
  13. package/index.js +67 -2
  14. package/lib/core/cache.js +277 -0
  15. package/lib/core/compat.js +877 -0
  16. package/lib/core/errors.js +14 -1
  17. package/lib/core/http.js +22 -0
  18. package/lib/core/index.js +53 -2
  19. package/lib/core/paths.js +6 -0
  20. package/lib/core/registry.js +21 -5
  21. package/lib/core/util.js +4 -1
  22. package/lib/modules/a-agents.js +104 -4
  23. package/lib/modules/b-tools.js +169 -26
  24. package/lib/modules/f-diagnostics.js +109 -17
  25. package/lib/modules/g-templates.js +18 -0
  26. package/lib/modules/i-recovery.js +84 -23
  27. package/lib/modules/j-instruction.js +624 -0
  28. package/lib/modules/k-export.js +540 -0
  29. package/package.json +1 -1
  30. package/scripts/release.mjs +81 -0
  31. package/scripts/verify.mjs +12 -0
  32. package/src/client/app.js +684 -118
  33. package/src/client/i18n/agents.js +96 -0
  34. package/src/client/i18n/common.js +36 -0
  35. package/src/client/i18n/diagnostics.js +52 -0
  36. package/src/client/i18n/export.js +174 -0
  37. package/src/client/i18n/instruction.js +236 -0
  38. package/src/client/i18n/meta.js +72 -0
  39. package/src/client/i18n/overview.js +38 -0
  40. package/src/client/i18n/recovery.js +66 -0
  41. package/src/client/i18n/sessions.js +64 -0
  42. package/src/client/i18n/templates.js +88 -0
  43. package/src/client/i18n/tools.js +96 -0
  44. package/src/client/i18n/usage.js +42 -0
  45. package/src/client/kernel.js +327 -40
  46. package/src/client/pages/agents.js +637 -354
  47. package/src/client/pages/diagnostics.js +526 -177
  48. package/src/client/pages/export.js +664 -0
  49. package/src/client/pages/instruction.js +648 -0
  50. package/src/client/pages/meta.js +553 -193
  51. package/src/client/pages/overview.js +255 -34
  52. package/src/client/pages/recovery.js +332 -131
  53. package/src/client/pages/sessions.js +470 -307
  54. package/src/client/pages/templates.js +691 -381
  55. package/src/client/pages/tools.js +559 -206
  56. package/src/client/pages/usage.js +235 -57
@@ -1,8 +1,18 @@
1
- /* Diagnostics page — grouped check table with status badges, evidence, impact,
2
- * suggested action, one safe fix per fixable row (before/after comparison), and
3
- * Markdown/JSON report export. */
1
+ /* Diagnostics page — grouped, collapsible check report.
2
+ *
3
+ * Shape of the page:
4
+ * 1. Toolbar: run again, export Markdown/JSON, last-run time.
5
+ * 2. Four summary tiles; each tile is also the status filter (aria-pressed).
6
+ * 3. One collapsible section per check group; only groups with visible items
7
+ * are rendered, and the section header keeps the group's own counts.
8
+ * 4. Safe fixes are confirmed in a modal, show before → after, and never
9
+ * touch host data (only the plugin's own storage).
10
+ * 5. Every evidence row can be copied, so a report can quote it verbatim. */
4
11
  (function diagnosticsPage() {
5
12
  const TONES = { ok: 'success', warn: 'warn', error: 'danger', unknown: 'neutral' }
13
+ const PAGE_STYLE = { display: 'flex', flexDirection: 'column', gap: '12px', padding: '8px 0' }
14
+ const STACK_STYLE = { display: 'flex', flexDirection: 'column', gap: '12px' }
15
+ const STATUS_ORDER = ['error', 'warn', 'unknown', 'ok']
6
16
 
7
17
  /** @param {{ status: string, t: Function }} props */
8
18
  function StatusBadge(props) {
@@ -15,171 +25,482 @@
15
25
  return value.length > max ? `${value.slice(0, max)}…` : value
16
26
  }
17
27
 
18
- /** @param {{ label: string, value: number, tone: string, note?: string }} props */
19
- function SummaryCard(props) {
20
- const color = props.tone === 'danger' ? 'var(--dsw-alias-state-error-primary, var(--acc-danger))' : props.tone === 'warn' ? 'var(--dsw-alias-state-warn-primary, var(--acc-warn))' : props.tone === 'success' ? 'var(--dsw-alias-state-success-primary, var(--acc-success))' : 'var(--dsw-alias-label-secondary, var(--acc-fg-weak))'
28
+ /** Inline copy feedback; no toast service is available, so the label changes. */
29
+ function CopyButton(props) {
30
+ const [state, setState] = ACC.useState('idle')
31
+ const copy = ACC.useCallback(() => {
32
+ const text = String(props.text || '')
33
+ const finish = (next) => setState(next)
34
+ if (text.length === 0) {
35
+ finish('failed')
36
+ return
37
+ }
38
+ if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
39
+ navigator.clipboard.writeText(text).then(() => finish('done'), () => finish('failed'))
40
+ return
41
+ }
42
+ finish('failed')
43
+ }, [props.text])
44
+ ACC.useEffect(() => {
45
+ if (state === 'idle') return undefined
46
+ const timer = setTimeout(() => setState('idle'), 1800)
47
+ return () => clearTimeout(timer)
48
+ }, [state])
49
+ const label = state === 'done' ? props.t('diagnostics.copied') : state === 'failed' ? props.t('diagnostics.copyFailed') : props.label || props.t('diagnostics.copy')
50
+ return h(
51
+ C.Btn,
52
+ { tone: 'ghost', onClick: copy, title: props.title || label, ariaLabel: props.ariaLabel, style: { padding: '0 6px' } },
53
+ label,
54
+ )
55
+ }
56
+
57
+ /** Download helper with URL cleanup on unmount (no leaked revoke timers). */
58
+ function useDownload() {
59
+ const timers = ACC.useRef([])
60
+ ACC.useEffect(() => () => {
61
+ for (const timer of timers.current) clearTimeout(timer)
62
+ timers.current = []
63
+ }, [])
64
+ return ACC.useCallback((input) => {
65
+ const blob = new Blob([input.text], { type: input.mime })
66
+ const url = URL.createObjectURL(blob)
67
+ const anchor = document.createElement('a')
68
+ anchor.href = url
69
+ anchor.download = input.filename
70
+ anchor.click()
71
+ const timer = setTimeout(() => URL.revokeObjectURL(url), 1000)
72
+ timers.current.push(timer)
73
+ }, [])
74
+ }
75
+
76
+ /**
77
+ * One collapsible group. The header is a real button with `aria-expanded`, so
78
+ * keyboard and screen-reader users can fold the report without a pointer.
79
+ * @param {{ title: unknown, counts: any, open: boolean, onToggle: Function, children?: unknown }} props
80
+ */
81
+ function GroupSection(props) {
82
+ return h(
83
+ 'section',
84
+ {
85
+ style: {
86
+ border: '.5px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))',
87
+ borderRadius: 'var(--dsw-radius-sm, 8px)',
88
+ overflow: 'hidden',
89
+ },
90
+ },
91
+ h(
92
+ 'button',
93
+ {
94
+ type: 'button',
95
+ onClick: props.onToggle,
96
+ 'aria-expanded': props.open,
97
+ style: {
98
+ display: 'flex',
99
+ width: '100%',
100
+ alignItems: 'center',
101
+ justifyContent: 'space-between',
102
+ gap: '8px',
103
+ padding: '8px 12px',
104
+ border: 0,
105
+ background: props.open ? 'var(--dsw-alias-interactive-bg-hover, rgba(38,49,72,.06))' : 'transparent',
106
+ color: 'inherit',
107
+ font: 'inherit',
108
+ textAlign: 'left',
109
+ cursor: 'pointer',
110
+ },
111
+ },
112
+ h(
113
+ 'span',
114
+ { style: { display: 'flex', alignItems: 'center', gap: '8px', minWidth: 0 } },
115
+ h('span', { 'aria-hidden': 'true' }, props.open ? '▾' : '▸'),
116
+ h('strong', null, props.title),
117
+ h('span', { className: 'acc-muted' }, `(${props.counts.total})`),
118
+ ),
119
+ h(
120
+ 'span',
121
+ { className: 'acc-row' },
122
+ STATUS_ORDER.filter((status) => (props.counts[status] || 0) > 0).map((status) =>
123
+ h(C.Badge, { key: status, tone: TONES[status] }, `${String(status)} ${props.counts[status]}`),
124
+ ),
125
+ ),
126
+ ),
127
+ props.open ? h('div', { style: { padding: '0 12px 12px' } }, props.children) : null,
128
+ )
129
+ }
130
+
131
+ /**
132
+ * Split one host evidence string into machine `key=value` chips plus the parts
133
+ * that are prose (Chinese parentheticals in this build). Chips stay visible;
134
+ * prose is folded into a Raw block so the English UI never prints host Chinese.
135
+ * @param {unknown} text
136
+ * @returns {{ chips: Array<{ key: string, value: string }>, raw: string }}
137
+ */
138
+ function splitEvidence(text) {
139
+ const source = String(text === null || text === undefined ? '' : text)
140
+ const hidden = []
141
+ const visible = source.replace(/[((]([^))]*)[))]/g, (match) => {
142
+ hidden.push(match.trim())
143
+ return ' '
144
+ })
145
+ const chips = []
146
+ for (const token of visible.split(/\s+/)) {
147
+ if (token.length === 0) continue
148
+ if (ACC.l10n.hasCjk(token)) {
149
+ hidden.push(token)
150
+ continue
151
+ }
152
+ const equals = token.indexOf('=')
153
+ if (equals > 0) chips.push({ key: token.slice(0, equals), value: token.slice(equals + 1) })
154
+ else chips.push({ key: '', value: token })
155
+ }
156
+ const raw = hidden.length > 0 ? source : ''
157
+ return { chips, raw }
158
+ }
159
+
160
+ /** Evidence chips for one check row, with the host's prose kept in a Raw fold. */
161
+ function EvidenceCell(props) {
162
+ const { t } = props
163
+ const parsed = splitEvidence(props.text)
21
164
  return h(
22
165
  'div',
23
- { className: 'acc-card acc-stat' },
166
+ { style: { display: 'flex', flexDirection: 'column', gap: '3px', minWidth: 0 } },
167
+ h(
168
+ 'div',
169
+ { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '4px', minWidth: 0 } },
170
+ parsed.chips.length === 0 ? h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, t('diagnostics.evidenceEmpty')) : null,
171
+ parsed.chips.map((chip, index) =>
172
+ h(
173
+ 'span',
174
+ {
175
+ key: `${chip.key}-${index}`,
176
+ className: 'acc-mono',
177
+ title: chip.key.length > 0 ? `${chip.key}=${chip.value}` : chip.value,
178
+ style: {
179
+ display: 'inline-flex',
180
+ alignItems: 'baseline',
181
+ gap: '3px',
182
+ padding: '0 5px',
183
+ border: '0.5px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))',
184
+ borderRadius: '999px',
185
+ fontSize: '11px',
186
+ lineHeight: '16px',
187
+ maxWidth: '100%',
188
+ overflow: 'hidden',
189
+ textOverflow: 'ellipsis',
190
+ whiteSpace: 'nowrap',
191
+ },
192
+ },
193
+ chip.key.length > 0 ? h('span', { style: { color: 'var(--dsw-alias-label-tertiary, #81858c)' } }, `${chip.key}=`) : null,
194
+ h('span', null, chip.value),
195
+ ),
196
+ ),
197
+ props.children,
198
+ ),
199
+ ACC.l10n.raw(t('diagnostics.rawEvidence'), parsed.raw),
200
+ )
201
+ }
202
+
203
+ /** @param {{ label: string, value: number, tone: string, note?: string, onFilter: Function, active: boolean }} props */
204
+ function SummaryTile(props) {
205
+ const color =
206
+ props.tone === 'danger' ? 'var(--dsw-alias-state-error-primary, #ec1313)'
207
+ : props.tone === 'warn' ? 'var(--dsw-alias-state-warn-primary, #f59e0b)'
208
+ : props.tone === 'success' ? 'var(--dsw-alias-state-success-primary, #22c55e)'
209
+ : 'var(--dsw-alias-label-secondary, #61666b)'
210
+ return h(
211
+ 'button',
212
+ {
213
+ type: 'button',
214
+ className: 'acc-card acc-stat',
215
+ onClick: props.onFilter,
216
+ 'aria-pressed': props.active,
217
+ title: props.active ? props.titleOn : props.titleOff,
218
+ style: props.active ? { borderColor: 'var(--dsw-alias-border-selected, var(--dsw-alias-state-business-primary, #4176e6))' } : undefined,
219
+ },
24
220
  h('span', { className: 'acc-stat-label' }, props.label),
25
221
  h('span', { className: 'acc-stat-value', style: { color } }, String(props.value)),
26
- props.note ? h('span', { className: 'acc-stat-reason', style: { color: 'var(--dsw-alias-label-secondary, var(--acc-fg-weak))' } }, props.note) : null,
222
+ props.note ? h('span', { className: 'acc-stat-reason', style: { color: 'var(--dsw-alias-label-secondary, #61666b)' } }, props.note) : null,
27
223
  )
28
224
  }
29
225
 
30
- /** @param {{ filename: string, mime: string, text: string }} input */
31
- function download(input) {
32
- const blob = new Blob([input.text], { type: input.mime })
33
- const url = URL.createObjectURL(blob)
34
- const anchor = document.createElement('a')
35
- anchor.href = url
36
- anchor.download = input.filename
37
- anchor.click()
38
- setTimeout(() => URL.revokeObjectURL(url), 1000)
226
+ /** Export result dialog: keeps the payload, offers download + copy with feedback. */
227
+ function ExportDialog(props) {
228
+ const { t, exported, onClose } = props
229
+ const [copied, setCopied] = ACC.useState('idle')
230
+ const [downloaded, setDownloaded] = ACC.useState('idle')
231
+ const download = useDownload()
232
+ ACC.useEffect(() => {
233
+ if (copied === 'idle' && downloaded === 'idle') return undefined
234
+ const timer = setTimeout(() => {
235
+ setCopied('idle')
236
+ setDownloaded('idle')
237
+ }, 2200)
238
+ return () => clearTimeout(timer)
239
+ }, [copied, downloaded])
240
+ return h(
241
+ C.Modal,
242
+ { title: `${t('diagnostics.exportTitle')} · ${exported.filename}`, onClose, footer: null },
243
+ h('div', { style: STACK_STYLE },
244
+ h(C.Notice, { tone: 'info' }, t('diagnostics.exportRedactionNote')),
245
+ h(C.Code, { text: clip(exported.text, 60000) }),
246
+ h(
247
+ 'div',
248
+ { className: 'acc-row' },
249
+ h(
250
+ C.Btn,
251
+ {
252
+ tone: 'primary',
253
+ onClick: () => {
254
+ download({
255
+ filename: exported.filename,
256
+ mime: exported.format === 'md' ? 'text/markdown;charset=utf-8' : 'application/json;charset=utf-8',
257
+ text: exported.text,
258
+ })
259
+ setDownloaded('done')
260
+ },
261
+ },
262
+ downloaded === 'done' ? t('diagnostics.downloaded') : t('diagnostics.download'),
263
+ ),
264
+ h(CopyButton, { text: exported.text, t, label: t('diagnostics.copy'), title: t('diagnostics.copyReport') }),
265
+ h('span', { className: 'acc-muted', 'aria-live': 'polite' }, copied === 'failed' ? t('diagnostics.copyFailed') : ''),
266
+ h('span', { className: 'acc-grow' }),
267
+ h(C.Btn, { tone: 'ghost', onClick: onClose }, t('common.close')),
268
+ ),
269
+ ),
270
+ )
39
271
  }
40
272
 
41
- /** @param {{ report: any, t: Function, filter: string, onFilter: Function, onFix: Function, fixing: string | null }} props */
273
+ /** @param {{ report: any, t: Function, statusFilter: string, onStatus: Function, openGroups: any, toggleGroup: Function, onFix: Function, fixing: string | null, expanded: Function }} props */
42
274
  function DiagnosticsBody(props) {
43
275
  const { report, t } = props
44
276
  const summary = report.summary || { ok: 0, warn: 0, error: 0, unknown: 0, total: 0, groups: [] }
45
277
  const items = Array.isArray(report.items) ? report.items : []
46
- const groups = Array.isArray(summary.groups) ? summary.groups : []
47
- const visible = props.filter === '' ? items : items.filter((item) => item.group === props.filter)
48
278
  const capabilityItem = items.find((item) => item.id === 'capabilities.summary')
49
279
  const capabilities = capabilityItem && capabilityItem.details && Array.isArray(capabilityItem.details.capabilities)
50
280
  ? capabilityItem.details.capabilities
51
281
  : null
282
+ const visibleItems = props.statusFilter === '' ? items : items.filter((item) => item.status === props.statusFilter)
283
+ const groupOrder = []
284
+ const grouped = new Map()
285
+ for (const item of items) {
286
+ if (!grouped.has(item.group)) {
287
+ grouped.set(item.group, { group: item.group, total: 0, ok: 0, warn: 0, error: 0, unknown: 0, items: [] })
288
+ groupOrder.push(item.group)
289
+ }
290
+ const bucket = grouped.get(item.group)
291
+ bucket.total += 1
292
+ bucket[item.status] = (bucket[item.status] || 0) + 1
293
+ if (props.statusFilter === '' || item.status === props.statusFilter) bucket.items.push(item)
294
+ }
295
+ const sections = groupOrder
296
+ .map((group) => grouped.get(group))
297
+ .filter((bucket) => bucket.items.length > 0)
52
298
 
53
299
  return h(
54
300
  'div',
55
- { className: 'acc-content-inner' },
301
+ { style: PAGE_STYLE },
302
+ h(
303
+ 'div',
304
+ { className: 'acc-stat-grid', role: 'group', 'aria-label': t('diagnostics.filterStatus') },
305
+ h(SummaryTile, {
306
+ label: t('diagnostics.summary.error'), value: summary.error, tone: 'danger',
307
+ onFilter: () => props.onStatus(props.statusFilter === 'error' ? '' : 'error'),
308
+ active: props.statusFilter === 'error',
309
+ titleOn: t('diagnostics.filterClear'), titleOff: t('diagnostics.filterOnly', { status: t('diagnostics.status.error') }),
310
+ }),
311
+ h(SummaryTile, {
312
+ label: t('diagnostics.summary.warn'), value: summary.warn, tone: 'warn',
313
+ onFilter: () => props.onStatus(props.statusFilter === 'warn' ? '' : 'warn'),
314
+ active: props.statusFilter === 'warn',
315
+ titleOn: t('diagnostics.filterClear'), titleOff: t('diagnostics.filterOnly', { status: t('diagnostics.status.warn') }),
316
+ }),
317
+ h(SummaryTile, {
318
+ label: t('diagnostics.summary.unknown'), value: summary.unknown, tone: 'neutral',
319
+ onFilter: () => props.onStatus(props.statusFilter === 'unknown' ? '' : 'unknown'),
320
+ active: props.statusFilter === 'unknown',
321
+ titleOn: t('diagnostics.filterClear'), titleOff: t('diagnostics.filterOnly', { status: t('diagnostics.status.unknown') }),
322
+ }),
323
+ h(SummaryTile, {
324
+ label: t('diagnostics.summary.ok'), value: summary.ok, tone: 'success',
325
+ note: t('diagnostics.summary.total', { total: summary.total }),
326
+ onFilter: () => props.onStatus(props.statusFilter === 'ok' ? '' : 'ok'),
327
+ active: props.statusFilter === 'ok',
328
+ titleOn: t('diagnostics.filterClear'), titleOff: t('diagnostics.filterOnly', { status: t('diagnostics.status.ok') }),
329
+ }),
330
+ ),
56
331
  h(
57
332
  'div',
58
- { className: 'acc-stat-grid' },
59
- h(SummaryCard, { label: t('diagnostics.summary.error'), value: summary.error, tone: 'danger' }),
60
- h(SummaryCard, { label: t('diagnostics.summary.warn'), value: summary.warn, tone: 'warn' }),
61
- h(SummaryCard, { label: t('diagnostics.summary.unknown'), value: summary.unknown, tone: 'neutral' }),
62
- h(SummaryCard, { label: t('diagnostics.summary.ok'), value: summary.ok, tone: 'success', note: t('diagnostics.summary.total', { total: summary.total }) }),
333
+ { className: 'acc-row', style: { justifyContent: 'space-between' } },
334
+ h(
335
+ 'div',
336
+ { className: 'acc-row' },
337
+ h('span', { className: 'acc-muted' }, props.statusFilter === '' ? t('diagnostics.filterAllActive') : t('diagnostics.filterActive', { status: t(`diagnostics.status.${props.statusFilter}`), count: visibleItems.length })),
338
+ props.statusFilter === '' ? null : h(C.Btn, { tone: 'ghost', onClick: () => props.onStatus('') }, t('diagnostics.filterClear')),
339
+ ),
340
+ h(
341
+ 'div',
342
+ { className: 'acc-row' },
343
+ h(C.Btn, { tone: 'ghost', onClick: () => props.expanded(true) }, t('diagnostics.expandAll')),
344
+ h(C.Btn, { tone: 'ghost', onClick: () => props.expanded(false) }, t('diagnostics.collapseAll')),
345
+ ),
63
346
  ),
64
347
  h(
65
348
  C.Notice,
66
349
  { tone: summary.error > 0 ? 'danger' : summary.warn > 0 ? 'warn' : 'success' },
67
350
  summary.worst === null
68
351
  ? t('diagnostics.noneWorst')
69
- : `${t('diagnostics.worst')}:${summary.worst.id}(${t(`diagnostics.status.${summary.worst.status}`)})— ${clip(summary.worst.evidence, 240)}`,
352
+ : h(
353
+ 'div',
354
+ { style: { display: 'flex', flexDirection: 'column', gap: '3px' } },
355
+ h('div', null, h('strong', null, `${t('diagnostics.worst')}: ${t(`diagnostics.check.${summary.worst.id}`)}`), ` (${t(`diagnostics.status.${summary.worst.status}`)})`),
356
+ h('div', { className: 'acc-muted', style: { fontSize: '11px' } }, t(`diagnostics.impact.${summary.worst.id}`)),
357
+ h(EvidenceCell, { text: summary.worst.evidence, t }),
358
+ ),
70
359
  ),
71
- h(
72
- C.Card,
73
- {
74
- title: t('diagnostics.title'),
75
- subtitle: t('diagnostics.subtitle'),
76
- actions: h(
77
- 'div',
78
- { className: 'acc-row' },
360
+ report.note
361
+ ? h(
362
+ C.Notice,
363
+ { tone: 'info' },
364
+ ACC.l10n.host('diagnostics.noteBudgetUnknown', report.note),
365
+ ACC.l10n.raw(t('diagnostics.rawEvidence'), report.note),
366
+ )
367
+ : null,
368
+ sections.length === 0
369
+ ? h(C.Empty, {
370
+ title: t('diagnostics.noMatch'),
371
+ hint: t('diagnostics.noMatchHint'),
372
+ action: h(C.Btn, { onClick: () => props.onStatus('') }, t('diagnostics.filterClear')),
373
+ })
374
+ : sections.map((bucket) =>
79
375
  h(
80
- 'select',
376
+ GroupSection,
81
377
  {
82
- className: 'acc-select',
83
- value: props.filter,
84
- 'aria-label': t('diagnostics.filterLabel'),
85
- onChange: (event) => props.onFilter(event.target.value),
378
+ key: bucket.group,
379
+ title: t(`diagnostics.group.${bucket.group}`),
380
+ counts: bucket,
381
+ open: props.openGroups[bucket.group] !== false,
382
+ onToggle: () => props.toggleGroup(bucket.group),
86
383
  },
87
- h('option', { value: '' }, t('diagnostics.filterAll')),
88
- groups.map((group) => h('option', { key: group.group, value: group.group }, `${t(`diagnostics.group.${group.group}`)} (${group.total})`)),
89
- ),
90
- ),
91
- },
92
- h(C.Table, {
93
- columns: [
94
- {
95
- key: 'title',
96
- label: t('diagnostics.check'),
97
- render: (row) => h(
384
+ h(
98
385
  'div',
99
- null,
100
- h('strong', null, t(`diagnostics.check.${row.id}`)),
101
- h('div', { className: 'acc-muted acc-mono' }, row.id),
386
+ { style: { display: 'flex', flexDirection: 'column' } },
387
+ bucket.items.map((row) =>
388
+ h(
389
+ 'div',
390
+ {
391
+ key: row.id,
392
+ style: {
393
+ display: 'flex',
394
+ flexDirection: 'column',
395
+ gap: '3px',
396
+ padding: '8px 2px',
397
+ borderBottom: '0.5px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))',
398
+ },
399
+ },
400
+ h(
401
+ 'div',
402
+ { style: { display: 'flex', alignItems: 'center', gap: '6px', flexWrap: 'wrap' } },
403
+ h('strong', { style: { fontSize: '12px' } }, t(`diagnostics.check.${row.id}`)),
404
+ h(StatusBadge, { status: row.status, t }),
405
+ h('span', { className: 'acc-grow' }),
406
+ row.fixable === true
407
+ ? h(
408
+ C.Btn,
409
+ {
410
+ tone: row.status === 'error' ? 'danger' : 'default',
411
+ disabled: props.fixing !== null && props.fixing !== undefined,
412
+ onClick: () => props.onFix(row.id),
413
+ title: t('diagnostics.fixConfirm'),
414
+ 'aria-label': `${t('diagnostics.fix')}: ${t(`diagnostics.check.${row.id}`)}`,
415
+ },
416
+ props.fixing === row.id ? t('diagnostics.fixing') : t('diagnostics.fix'),
417
+ )
418
+ : h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, t('diagnostics.notFixable')),
419
+ ),
420
+ h(
421
+ 'div',
422
+ { style: { display: 'flex', alignItems: 'flex-start', gap: '4px', minWidth: 0 } },
423
+ h('span', { className: 'acc-mono', style: { fontSize: '11px', color: 'var(--dsw-alias-label-secondary, #61666b)', flex: '0 0 auto' } }, `#${row.id}`),
424
+ h(EvidenceCell, { text: row.evidence, t }),
425
+ h(CopyButton, {
426
+ text: `${row.id}\t${row.status}\t${String(row.evidence || '')}`,
427
+ t,
428
+ title: t('diagnostics.copyEvidence'),
429
+ ariaLabel: t('diagnostics.copyEvidenceFor', { id: row.id }),
430
+ }),
431
+ ),
432
+ h(
433
+ 'div',
434
+ { className: 'acc-muted', style: { fontSize: '11px', lineHeight: '1.5' } },
435
+ h('div', null, `${t('diagnostics.impact')}: ${t(`diagnostics.impact.${row.id}`)}`),
436
+ h('div', null, `${t('diagnostics.action')}: ${t(`diagnostics.action.${row.id}`)}`),
437
+ ),
438
+ ),
439
+ ),
102
440
  ),
103
- },
104
- {
105
- key: 'status',
106
- label: t('diagnostics.status'),
107
- render: (row) => h(StatusBadge, { status: row.status, t }),
108
- },
109
- {
110
- key: 'evidence',
111
- label: t('diagnostics.evidence'),
112
- render: (row) => h('span', { className: 'acc-mono', title: String(row.evidence || '') }, clip(row.evidence || '—', 120)),
113
- },
114
- {
115
- key: 'impact',
116
- label: t('diagnostics.impact'),
117
- render: (row) => h('span', { style: { maxWidth: '260px', display: 'inline-block' } }, t(`diagnostics.impact.${row.id}`)),
118
- },
119
- {
120
- key: 'action',
121
- label: t('diagnostics.action'),
122
- render: (row) => h('span', { style: { maxWidth: '240px', display: 'inline-block' } }, t(`diagnostics.action.${row.id}`)),
123
- },
124
- {
125
- key: 'fix',
126
- label: t('diagnostics.fixable'),
127
- render: (row) => (row.fixable === true
128
- ? h(
129
- C.Btn,
130
- {
131
- tone: row.status === 'error' ? 'danger' : 'default',
132
- disabled: props.fixing !== null && props.fixing !== undefined,
133
- onClick: () => props.onFix(row.id),
134
- title: t('diagnostics.fixConfirm'),
135
- },
136
- props.fixing === row.id ? t('diagnostics.fixing') : t('diagnostics.fix'),
137
- )
138
- : h('span', { className: 'acc-muted' }, t('diagnostics.notFixable'))),
139
- },
140
- ],
141
- rows: visible,
142
- rowKey: 'id',
143
- empty: h(C.Empty, { title: t('diagnostics.empty'), hint: t('diagnostics.emptyHint') }),
144
- }),
145
- ),
441
+ ),
442
+ ),
146
443
  capabilities === null
147
444
  ? null
148
445
  : h(
149
- C.Card,
150
- { title: t('diagnostics.capabilities'), subtitle: capabilityItem.evidence },
151
- h(C.Table, {
152
- columns: [
153
- { key: 'name', label: t('diagnostics.capabilityName'), render: (row) => h('span', { className: 'acc-mono' }, row.name) },
154
- {
155
- key: 'present',
156
- label: t('diagnostics.status'),
157
- render: (row) => h(C.Badge, { tone: row.present ? 'success' : 'warn' }, row.present ? t('diagnostics.capabilityPresent') : t('diagnostics.capabilityMissing')),
158
- },
159
- { key: 'methods', label: t('diagnostics.capabilityMethods'), render: (row) => h('span', { className: 'acc-mono' }, Array.isArray(row.methods) ? row.methods.join(', ') || '—' : '—') },
160
- { key: 'detail', label: t('diagnostics.capabilityDetail'), render: (row) => row.detail || '—' },
161
- ],
162
- rows: capabilities,
163
- rowKey: 'name',
164
- }),
165
- ),
446
+ C.Card,
447
+ { title: t('diagnostics.capabilities') },
448
+ h(C.Table, {
449
+ columns: [
450
+ {
451
+ key: 'name',
452
+ label: t('diagnostics.capabilityName'),
453
+ render: (row) =>
454
+ h(
455
+ 'div',
456
+ { style: { display: 'flex', flexDirection: 'column', gap: '1px' } },
457
+ h('span', { className: 'acc-mono' }, row.name),
458
+ h(
459
+ 'span',
460
+ { className: 'acc-muted acc-mono', style: { fontSize: '11px', wordBreak: 'break-word' } },
461
+ Array.isArray(row.methods) ? row.methods.join(', ') || '—' : '—',
462
+ ),
463
+ row.detail ? h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, ACC.l10n.host('diagnostics.capabilityDetailGeneric', row.detail)) : null,
464
+ row.detail ? ACC.l10n.raw(t('diagnostics.rawEvidence'), String(row.detail)) : null,
465
+ ),
466
+ },
467
+ {
468
+ key: 'present',
469
+ label: t('diagnostics.status'),
470
+ render: (row) => h(C.Badge, { tone: row.present ? 'success' : 'warn' }, row.present ? t('diagnostics.capabilityPresent') : t('diagnostics.capabilityMissing')),
471
+ },
472
+ ],
473
+ rows: capabilities,
474
+ rowKey: 'name',
475
+ }),
476
+ ),
166
477
  )
167
478
  }
168
479
 
169
480
  /** @param {{ t: Function }} props */
170
481
  function DiagnosticsPage(props) {
171
482
  const { t } = props
172
- const state = ACC.useAsync((context) => ACC.api('diagnostics.run', {}, context), [])
173
- const [filter, setFilter] = useState('')
174
- const [fixing, setFixing] = useState(null)
175
- const [fixReport, setFixReport] = useState(null)
176
- const [fixError, setFixError] = useState(null)
177
- const [exported, setExported] = useState(null)
178
- const [exportError, setExportError] = useState(null)
483
+ // The explicit Run button must not reuse a cached pass.
484
+ const forceRun = ACC.useRef(false)
485
+ const state = ACC.useAsync((context) => {
486
+ const refresh = forceRun.current
487
+ forceRun.current = false
488
+ return ACC.api('diagnostics.run', refresh ? { refresh: true } : {}, context)
489
+ }, [])
490
+ const [statusFilter, setStatusFilter] = ACC.useState('')
491
+ const [closedGroups, setClosedGroups] = ACC.useState({})
492
+ const [fixTarget, setFixTarget] = ACC.useState(null)
493
+ const [fixing, setFixing] = ACC.useState(null)
494
+ const [fixReport, setFixReport] = ACC.useState(null)
495
+ const [fixError, setFixError] = ACC.useState(null)
496
+ const [exporting, setExporting] = ACC.useState(null)
497
+ const [exported, setExported] = ACC.useState(null)
498
+ const [exportError, setExportError] = ACC.useState(null)
179
499
 
180
- const runFix = useCallback(async (id) => {
500
+ const runFix = ACC.useCallback(async (id) => {
181
501
  setFixing(id)
182
502
  setFixError(null)
503
+ setFixReport(null)
183
504
  try {
184
505
  const result = await ACC.api('diagnostics.fix', { id })
185
506
  setFixReport(result)
@@ -188,17 +509,21 @@
188
509
  setFixError(error)
189
510
  } finally {
190
511
  setFixing(null)
512
+ setFixTarget(null)
191
513
  }
192
514
  }, [state.reload])
193
515
 
194
- const runExport = useCallback(async (format) => {
516
+ const runExport = ACC.useCallback(async (format) => {
195
517
  setExportError(null)
518
+ setExporting(format)
196
519
  try {
197
520
  const result = await ACC.api('diagnostics.export', { format })
198
521
  const text = format === 'md' ? result.text : JSON.stringify(result.document, null, 2)
199
522
  setExported({ format, filename: result.filename, text })
200
523
  } catch (error) {
201
524
  setExportError(error)
525
+ } finally {
526
+ setExporting(null)
202
527
  }
203
528
  }, [])
204
529
 
@@ -206,71 +531,94 @@
206
531
  if (state.status === 'error') return h(C.ErrorBox, { error: state.error, onRetry: state.reload, label: t('diagnostics.failed') })
207
532
 
208
533
  const report = state.data || {}
534
+ const filter = statusFilter
535
+ const openGroups = {}
536
+ for (const key of Object.keys(closedGroups)) openGroups[key] = !closedGroups[key]
537
+ const fixTitle = fixTarget === null ? '' : t(`diagnostics.check.${fixTarget}`)
538
+
209
539
  return h(
210
540
  'div',
211
- { className: 'acc-content-inner' },
541
+ { style: PAGE_STYLE },
212
542
  h(
213
- C.Toolbar,
214
- null,
215
- h(C.Btn, { tone: 'primary', onClick: state.reload }, t('diagnostics.run')),
216
- h(C.Btn, { onClick: () => runExport('md') }, t('diagnostics.exportMd')),
217
- h(C.Btn, { onClick: () => runExport('json') }, t('diagnostics.exportJson')),
218
- h('span', { className: 'acc-muted' }, `${t('diagnostics.generatedAt')}:${report.generatedAt || '—'}`),
543
+ C.Card,
544
+ {
545
+ title: t('diagnostics.title'),
546
+ subtitle: t('diagnostics.subtitle'),
547
+ actions: [
548
+ h(C.Btn, { key: 'run', tone: 'primary', onClick: () => { forceRun.current = true; state.reload() } }, t('diagnostics.run')),
549
+ h(C.Btn, { key: 'md', disabled: exporting !== null, onClick: () => runExport('md') }, exporting === 'md' ? t('diagnostics.exporting') : t('diagnostics.exportMd')),
550
+ h(C.Btn, { key: 'json', disabled: exporting !== null, onClick: () => runExport('json') }, exporting === 'json' ? t('diagnostics.exporting') : t('diagnostics.exportJson')),
551
+ ],
552
+ },
553
+ h(
554
+ 'div',
555
+ { className: 'acc-row', style: { justifyContent: 'space-between' } },
556
+ h('span', { className: 'acc-muted' }, `${t('diagnostics.generatedAt')}: ${report.generatedAt ? ACC.l10n.dateTime(report.generatedAt, t) : '—'}`),
557
+ h('span', { className: 'acc-muted' }, report.cached === true ? t('diagnostics.cached') : t('diagnostics.fresh')),
558
+ ),
219
559
  ),
220
560
  exportError ? h(C.ErrorBox, { error: exportError, label: t('diagnostics.exportFailed') }) : null,
221
561
  fixError ? h(C.ErrorBox, { error: fixError, label: t('diagnostics.fixFailed') }) : null,
222
562
  fixReport
223
563
  ? h(
224
- C.Notice,
225
- { tone: fixReport.fixed ? 'success' : 'warn' },
226
- h('div', null, `${t('diagnostics.fixDone')}:${fixReport.id} · ${fixReport.action}${fixReport.detail ? `(${fixReport.detail})` : ''}`),
227
- h('div', { className: 'acc-mono' }, `${t('diagnostics.before')}: ${fixReport.before.status} → ${t('diagnostics.after')}: ${fixReport.after.status}`),
228
- h('div', { className: 'acc-mono' }, clip(fixReport.before.evidence, 200)),
229
- h('div', { className: 'acc-mono' }, clip(fixReport.after.evidence, 200)),
230
- )
231
- : null,
232
- h(DiagnosticsBody, {
233
- report,
234
- t,
235
- filter,
236
- onFilter: setFilter,
237
- onFix: runFix,
238
- fixing,
239
- }),
240
- exported
241
- ? h(
242
- C.Modal,
243
- { title: `${t('diagnostics.exportTitle')} · ${exported.filename}`, onClose: () => setExported(null) },
244
- h(C.Code, { text: clip(exported.text, 60000) }),
245
- h(
246
- 'div',
247
- { className: 'acc-row' },
248
- h(
249
- C.Btn,
250
- {
251
- tone: 'primary',
252
- onClick: () => download({
253
- filename: exported.filename,
254
- mime: exported.format === 'md' ? 'text/markdown;charset=utf-8' : 'application/json;charset=utf-8',
255
- text: exported.text,
256
- }),
257
- },
258
- t('diagnostics.download'),
259
- ),
564
+ C.Notice,
565
+ { tone: fixReport.fixed ? 'success' : 'warn' },
566
+ h('div', null, `${t('diagnostics.fixDone')}: ${t(`diagnostics.check.${fixReport.id}`)}`),
567
+ h('div', { className: 'acc-muted', style: { fontSize: '11px' } }, ACC.l10n.map(fixReport.fixed ? 'diagnostics.fixApplied' : 'diagnostics.fixNoChange')),
568
+ ACC.l10n.raw(t('diagnostics.rawEvidence'), `${String(fixReport.action || '')}\n${String(fixReport.detail || '')}`),
260
569
  h(
261
- C.Btn,
262
- {
263
- onClick: () => {
264
- if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
265
- navigator.clipboard.writeText(exported.text)
266
- }
267
- },
268
- },
269
- t('diagnostics.copy'),
570
+ 'div',
571
+ { className: 'acc-grid-2', style: { marginTop: '6px' } },
572
+ h('div', null, h('div', { className: 'acc-muted' }, `${t('diagnostics.before')} · ${fixReport.before.status}`), h('div', { className: 'acc-mono' }, clip(fixReport.before.evidence, 200))),
573
+ h('div', null, h('div', { className: 'acc-muted' }, `${t('diagnostics.after')} · ${fixReport.after.status}`), h('div', { className: 'acc-mono' }, clip(fixReport.after.evidence, 200))),
270
574
  ),
271
- ),
272
- )
575
+ fixReport.recheckedAt ? h('div', { className: 'acc-muted' }, `${t('diagnostics.rechecked')}: ${ACC.l10n.dateTime(fixReport.recheckedAt, t)}`) : null,
576
+ )
273
577
  : null,
578
+ state.data && state.data.items && state.data.items.length === 0
579
+ ? h(C.Empty, {
580
+ title: t('diagnostics.empty'),
581
+ hint: t('diagnostics.emptyHint'),
582
+ action: h(C.Btn, { tone: 'primary', onClick: state.reload }, t('diagnostics.run')),
583
+ })
584
+ : h(DiagnosticsBody, {
585
+ report,
586
+ t,
587
+ statusFilter: filter,
588
+ onStatus: setStatusFilter,
589
+ openGroups,
590
+ toggleGroup: (group) => setClosedGroups((previous) => ({ ...previous, [group]: !previous[group] })),
591
+ expanded: (open) => {
592
+ if (open) {
593
+ setClosedGroups({})
594
+ return
595
+ }
596
+ const next = {}
597
+ for (const bucket of report.summary && Array.isArray(report.summary.groups) ? report.summary.groups : []) next[bucket.group] = true
598
+ setClosedGroups(next)
599
+ },
600
+ onFix: (id) => setFixTarget(id),
601
+ fixing,
602
+ }),
603
+ exported ? h(ExportDialog, { t, exported, onClose: () => setExported(null) }) : null,
604
+ fixTarget === null
605
+ ? null
606
+ : h(
607
+ C.Modal,
608
+ {
609
+ title: t('diagnostics.fixTitle'),
610
+ onClose: () => setFixTarget(null),
611
+ footer: h(
612
+ 'div',
613
+ { className: 'acc-row', style: { justifyContent: 'flex-end' } },
614
+ h(C.Btn, { tone: 'ghost', onClick: () => setFixTarget(null) }, t('common.cancel')),
615
+ h(C.Btn, { tone: 'primary', onClick: () => runFix(fixTarget) }, t('diagnostics.fixCta')),
616
+ ),
617
+ },
618
+ h('p', { style: { margin: 0 } }, `${t('diagnostics.fixTarget')}: ${fixTitle}`),
619
+ h(C.Notice, { tone: 'warn' }, t('diagnostics.fixConfirm')),
620
+ h(C.Notice, { tone: 'info' }, t('diagnostics.fixScope')),
621
+ ),
274
622
  )
275
623
  }
276
624
 
@@ -278,6 +626,7 @@
278
626
  id: 'diagnostics',
279
627
  titleKey: 'nav.diagnostics',
280
628
  order: 70,
629
+ group: 'maintain',
281
630
  render: (props) => h(DiagnosticsPage, props),
282
631
  })
283
632
  })()