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
@@ -48,12 +48,43 @@ ACC.addI18n = function addI18n(dictionary) {
48
48
  }
49
49
  }
50
50
 
51
+ /** @returns {'zh' | 'en'} the dictionary matching the document language */
52
+ ACC.lang = function lang() {
53
+ let tag = ''
54
+ try {
55
+ tag = String(document.documentElement.lang || '').toLowerCase()
56
+ } catch {
57
+ // no document (build-time probe): assume English so the fallback keys stay ASCII
58
+ }
59
+ if (tag.startsWith('zh')) return 'zh'
60
+ return 'en'
61
+ }
62
+
63
+ /**
64
+ * Translate a shared key without the host `t` binder. Only for text an
65
+ * ingredient component must render on its own (button labels, default state
66
+ * titles); page copy still goes through the host-bound `t`.
67
+ * @param {string} key
68
+ * @param {string} [fallback] used when neither dictionary has the key
69
+ * @returns {string}
70
+ */
71
+ ACC.t = function translate(key, fallback) {
72
+ const language = ACC.lang()
73
+ const value = ACC.i18n[language][key]
74
+ if (typeof value === 'string') return value
75
+ const other = language === 'en' ? ACC.i18n.zh[key] : ACC.i18n.en[key]
76
+ if (typeof other === 'string') return other
77
+ return fallback === undefined ? key : fallback
78
+ }
79
+
51
80
  /**
52
81
  * @param {{
53
82
  * id: string,
54
83
  * titleKey: string,
84
+ * group?: 'edit' | 'insight' | 'maintain',
55
85
  * order?: number,
56
86
  * descriptionKey?: string,
87
+ * icon?: string,
57
88
  * render: (props: { t: (key: string, values?: Record<string, string | number>) => string }) => unknown,
58
89
  * }} definition
59
90
  */
@@ -66,7 +97,9 @@ ACC.registerPage = function registerPage(definition) {
66
97
  ACC.pages.push({
67
98
  id: definition.id,
68
99
  titleKey: definition.titleKey,
100
+ group: typeof definition.group === 'string' ? definition.group : undefined,
69
101
  descriptionKey: definition.descriptionKey,
102
+ icon: typeof definition.icon === 'string' ? definition.icon : undefined,
70
103
  order: typeof definition.order === 'number' ? definition.order : 100,
71
104
  render: definition.render,
72
105
  })
@@ -97,17 +130,17 @@ ACC.api = async function api(method, params, options) {
97
130
  })
98
131
  } catch (error) {
99
132
  if (error && error.name === 'AbortError') throw error
100
- throw new ACC.ApiError('network', '无法连接宿主', { hint: String((error && error.message) || error) })
133
+ throw new ACC.ApiError('network', ACC.t('common.networkError'), { hint: String((error && error.message) || error) })
101
134
  }
102
135
  let payload = null
103
136
  try {
104
137
  payload = await response.json()
105
138
  } catch {
106
- throw new ACC.ApiError('protocol', `宿主返回了无法解析的响应(HTTP ${response.status})`, { status: response.status })
139
+ throw new ACC.ApiError('protocol', ACC.t('common.protocolError').replace('{status}', String(response.status)), { status: response.status })
107
140
  }
108
141
  if (payload !== null && typeof payload === 'object' && payload.ok === true) return payload.value
109
142
  const detail = (payload && payload.error) || {}
110
- throw new ACC.ApiError(detail.code || 'internal', detail.message || `请求失败(HTTP ${response.status})`, {
143
+ throw new ACC.ApiError(detail.code || 'internal', detail.message || ACC.t('common.httpFailed').replace('{status}', String(response.status)), {
111
144
  hint: detail.hint,
112
145
  status: response.status,
113
146
  })
@@ -118,7 +151,7 @@ ACC.health = async function health(options) {
118
151
  const url = new URL(ACC.healthPath, document.baseURI)
119
152
  const response = await fetch(url, { credentials: 'same-origin', headers: { Accept: 'application/json' }, signal: options && options.signal })
120
153
  const payload = await response.json()
121
- if (!payload || payload.ok !== true) throw new ACC.ApiError('protocol', `健康检查失败(HTTP ${response.status})`, { status: response.status })
154
+ if (!payload || payload.ok !== true) throw new ACC.ApiError('protocol', ACC.t('common.protocolError').replace('{status}', String(response.status)), { status: response.status })
122
155
  return payload.value
123
156
  }
124
157
 
@@ -166,6 +199,83 @@ ACC.useAsync = function useAsync(loader, deps) {
166
199
  return { ...state, reload: useCallback(() => setNonce((value) => value + 1), []) }
167
200
  }
168
201
 
202
+ /* -------------------------------------------------------------------------- */
203
+ /* Icons */
204
+ /* -------------------------------------------------------------------------- */
205
+
206
+ /**
207
+ * 16px stroke icons (`stroke=currentColor`), the same weight as the host
208
+ * settings sidebar. Each entry is a list of `[tag, attributes]` pairs.
209
+ * @type {Record<string, Array<[string, Record<string, unknown>]>>}
210
+ */
211
+ const ACC_ICONS = {
212
+ overview: [
213
+ ['rect', { x: 2.25, y: 2.25, width: 4.6, height: 4.6, rx: 1 }],
214
+ ['rect', { x: 9.15, y: 2.25, width: 4.6, height: 4.6, rx: 1 }],
215
+ ['rect', { x: 2.25, y: 9.15, width: 4.6, height: 4.6, rx: 1 }],
216
+ ['rect', { x: 9.15, y: 9.15, width: 4.6, height: 4.6, rx: 1 }],
217
+ ],
218
+ agents: [
219
+ ['path', { d: 'M3.9 1.9h4.85L12.1 5.25v8.85H3.9z' }],
220
+ ['path', { d: 'M8.6 2.1v3.4h3.4' }],
221
+ ['path', { d: 'M5.9 8.4h4.2M5.9 10.9h4.2' }],
222
+ ],
223
+ tools: [
224
+ ['path', { d: 'M9.85 4.35a3.9 3.9 0 0 0-4.7 4.86L1.9 12.46a1.35 1.35 0 0 0 1.91 1.91l3.25-3.25a3.9 3.9 0 0 0 4.86-4.7l-2.2 2.2-1.7-.4-.4-1.7z' }],
225
+ ],
226
+ sessions: [
227
+ ['path', { d: 'M3.9 2.9h8.2a1.25 1.25 0 0 1 1.25 1.25v5.4a1.25 1.25 0 0 1-1.25 1.25H8.55l-2.8 2.45V10.8H3.9a1.25 1.25 0 0 1-1.25-1.25v-5.4A1.25 1.25 0 0 1 3.9 2.9Z' }],
228
+ ['path', { d: 'M5.9 6.15h4.2M5.9 8.35h2.8' }],
229
+ ],
230
+ meta: [
231
+ ['circle', { cx: 8, cy: 8, r: 6.15 }],
232
+ ['path', { d: 'M8 7.2v4.1' }],
233
+ ['circle', { cx: 8, cy: 4.85, r: 0.72, fill: 'currentColor', stroke: 'none' }],
234
+ ],
235
+ usage: [
236
+ ['path', { d: 'M2.6 13.1h10.8' }],
237
+ ['path', { d: 'M4.6 13.1V9.5' }],
238
+ ['path', { d: 'M8 13.1V5.2' }],
239
+ ['path', { d: 'M11.4 13.1V7.6' }],
240
+ ],
241
+ diagnostics: [['path', { d: 'M1.8 8h3.05l1.5-3.5L8.6 11.5l1.45-3.5h3.15' }]],
242
+ templates: [
243
+ ['rect', { x: 5.3, y: 5.3, width: 8, height: 8, rx: 1.5 }],
244
+ ['path', { d: 'M3.4 10.6V4.15A1.35 1.35 0 0 1 4.75 2.8h6.2' }],
245
+ ],
246
+ recovery: [
247
+ ['path', { d: 'M13.3 8a5.3 5.3 0 1 1-1.55-3.75' }],
248
+ ['path', { d: 'M13.35 2.85v3.95h-3.95' }],
249
+ ],
250
+ inbox: [
251
+ ['path', { d: 'M2.05 9.4h3.1l.95 1.65h3.8l.95-1.65h3.1' }],
252
+ ['path', { d: 'M2.05 9.4 3.75 3.5a1.2 1.2 0 0 1 1.15-.85h6.2a1.2 1.2 0 0 1 1.15.85l1.7 5.9v3.15H2.05z' }],
253
+ ],
254
+ alert: [
255
+ ['path', { d: 'M8 2.55 14.3 13.45H1.7z' }],
256
+ ['path', { d: 'M8 6.35v3.15' }],
257
+ ['circle', { cx: 8, cy: 11.45, r: 0.68, fill: 'currentColor', stroke: 'none' }],
258
+ ],
259
+ retry: [
260
+ ['path', { d: 'M13.3 8a5.3 5.3 0 1 1-1.55-3.75' }],
261
+ ['path', { d: 'M13.35 2.85v3.95h-3.95' }],
262
+ ],
263
+ close: [['path', { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' }]],
264
+ // Pages added in 0.3.0 (instruction preview, session export).
265
+ 'file-text': [
266
+ ['path', { d: 'M3.9 1.9h4.85L12.1 5.25v8.85H3.9z' }],
267
+ ['path', { d: 'M8.6 2.1v3.4h3.4' }],
268
+ ['path', { d: 'M5.9 7.5h4.2M5.9 10h4.2' }],
269
+ ],
270
+ download: [
271
+ ['path', { d: 'M8 2.2v7.1' }],
272
+ ['path', { d: 'M5.1 6.6 8 9.5l2.9-2.9' }],
273
+ ['path', { d: 'M2.9 11.2v1.35a1.2 1.2 0 0 0 1.2 1.2h7.8a1.2 1.2 0 0 0 1.2-1.2v-1.35' }],
274
+ ],
275
+ check: [['path', { d: 'M3.3 8.4 6.3 11.4 12.7 5.1' }]],
276
+ dot: [['circle', { cx: 8, cy: 8, r: 2.4 }]],
277
+ }
278
+
169
279
  /* -------------------------------------------------------------------------- */
170
280
  /* Shared components */
171
281
  /* -------------------------------------------------------------------------- */
@@ -185,16 +295,48 @@ const PRIMITIVES = (() => {
185
295
  }
186
296
  })()
187
297
 
298
+ /**
299
+ * Inline SVG icon. Names cover the built-in page navigation plus the state
300
+ * glyphs the shared components draw; unknown names fall back to a dot.
301
+ * @param {{ name?: string, size?: number, className?: string }} props
302
+ */
303
+ C.Icon = function Icon(props) {
304
+ const glyph = ACC_ICONS[props.name] || ACC_ICONS.dot
305
+ const size = typeof props.size === 'number' ? props.size : 16
306
+ return h(
307
+ 'svg',
308
+ {
309
+ className: `acc-icon${props.className ? ` ${props.className}` : ''}`,
310
+ width: size,
311
+ height: size,
312
+ viewBox: '0 0 16 16',
313
+ fill: 'none',
314
+ stroke: 'currentColor',
315
+ strokeWidth: 1.5,
316
+ strokeLinecap: 'round',
317
+ strokeLinejoin: 'round',
318
+ 'aria-hidden': 'true',
319
+ focusable: 'false',
320
+ },
321
+ glyph.map(([tag, attributes], index) => h(tag, { key: String(index), ...attributes })),
322
+ )
323
+ }
324
+
188
325
  /** @param {{ title?: unknown, subtitle?: unknown, actions?: unknown, children?: unknown, className?: string }} props */
189
326
  C.Card = function Card(props) {
190
327
  return h(
191
328
  'section',
192
329
  { className: `acc-card${props.className ? ` ${props.className}` : ''}` },
193
- (props.title || props.actions)
330
+ (props.title || props.actions || props.subtitle)
194
331
  ? h(
195
332
  'header',
196
333
  { className: 'acc-card-head' },
197
- h('div', { className: 'acc-card-heading' }, props.title ? h('h3', { className: 'acc-card-title' }, props.title) : null, props.subtitle ? h('p', { className: 'acc-card-subtitle' }, props.subtitle) : null),
334
+ h(
335
+ 'div',
336
+ { className: 'acc-card-heading' },
337
+ props.title ? h('h3', { className: 'acc-card-title' }, props.title) : null,
338
+ props.subtitle ? h('p', { className: 'acc-card-subtitle' }, props.subtitle) : null,
339
+ ),
198
340
  props.actions ? h('div', { className: 'acc-card-actions' }, props.actions) : null,
199
341
  )
200
342
  : null,
@@ -204,10 +346,15 @@ C.Card = function Card(props) {
204
346
 
205
347
  /** @param {{ children?: unknown, className?: string, label?: unknown }} props */
206
348
  C.Toolbar = function Toolbar(props) {
207
- return h('div', { className: `acc-toolbar${props.className ? ` ${props.className}` : ''}` }, props.children)
349
+ return h('div', { className: `acc-toolbar${props.className ? ` ${props.className}` : ''}`, role: 'group' }, props.children)
208
350
  }
209
351
 
210
- /** @param {{ children?: unknown, onClick?: Function, tone?: 'default' | 'primary' | 'danger' | 'ghost', disabled?: boolean, title?: string, type?: string }} props */
352
+ /**
353
+ * A labelled button. `ariaLabel` gives icon-only or repeated controls a unique
354
+ * accessible name; when no `title` is given the label doubles as the tooltip so
355
+ * sighted hover and assistive tech agree.
356
+ * @param {{ children?: unknown, onClick?: Function, tone?: 'default' | 'primary' | 'danger' | 'ghost', disabled?: boolean, title?: string, type?: string, icon?: string, ariaLabel?: string }} props
357
+ */
211
358
  C.Btn = function Btn(props) {
212
359
  const tone = props.tone || 'default'
213
360
  return h(
@@ -217,8 +364,10 @@ C.Btn = function Btn(props) {
217
364
  className: `acc-btn acc-btn-${tone}`,
218
365
  onClick: props.onClick,
219
366
  disabled: props.disabled === true,
220
- title: props.title,
367
+ title: props.title === undefined ? props.ariaLabel : props.title,
368
+ 'aria-label': props.ariaLabel,
221
369
  },
370
+ props.icon ? h(C.Icon, { name: props.icon, className: 'acc-btn-icon' }) : null,
222
371
  props.children,
223
372
  )
224
373
  }
@@ -228,12 +377,13 @@ C.Badge = function Badge(props) {
228
377
  return h('span', { className: `acc-badge acc-badge-${props.tone || 'neutral'}`, title: props.title }, props.children)
229
378
  }
230
379
 
231
- /** @param {{ title?: unknown, hint?: unknown, action?: unknown }} props */
380
+ /** @param {{ title?: unknown, hint?: unknown, action?: unknown, icon?: string }} props */
232
381
  C.Empty = function Empty(props) {
233
382
  return h(
234
383
  'div',
235
- { className: 'acc-state' },
236
- h('div', { className: 'acc-state-title' }, props.title),
384
+ { className: 'acc-state acc-state-empty' },
385
+ h('div', { className: 'acc-state-icon' }, h(C.Icon, { name: props.icon || 'inbox', size: 22 })),
386
+ props.title ? h('div', { className: 'acc-state-title' }, props.title) : null,
237
387
  props.hint ? h('div', { className: 'acc-state-hint' }, props.hint) : null,
238
388
  props.action ? h('div', { className: 'acc-state-action' }, props.action) : null,
239
389
  )
@@ -241,24 +391,49 @@ C.Empty = function Empty(props) {
241
391
 
242
392
  /** @param {{ label?: unknown }} props */
243
393
  C.Loading = function Loading(props) {
244
- return h('div', { className: 'acc-state acc-state-loading' }, h('span', { className: 'acc-spinner', 'aria-hidden': 'true' }), h('span', null, props.label))
394
+ return h(
395
+ 'div',
396
+ { className: 'acc-state acc-state-loading', role: 'status', 'aria-live': 'polite', 'aria-busy': 'true' },
397
+ h(
398
+ 'div',
399
+ { className: 'acc-loading-head' },
400
+ h('span', { className: 'acc-spinner', 'aria-hidden': 'true' }),
401
+ h('span', { className: 'acc-loading-label' }, props.label || ACC.t('common.loading')),
402
+ ),
403
+ h(
404
+ 'div',
405
+ { className: 'acc-skeleton-stack', 'aria-hidden': 'true' },
406
+ h('span', { className: 'acc-skeleton' }),
407
+ h('span', { className: 'acc-skeleton', style: { width: '78%' } }),
408
+ h('span', { className: 'acc-skeleton', style: { width: '58%' } }),
409
+ ),
410
+ )
245
411
  }
246
412
 
247
413
  /**
248
414
  * Error state. Shows the machine code, the message and the optional hint so a
249
415
  * user can tell "host lacks this capability" (501/503) from a real failure.
250
- * @param {{ error: Error, onRetry?: Function, label?: unknown }} props
416
+ * @param {{ error: Error, onRetry?: Function, label?: unknown, retryLabel?: unknown }} props
251
417
  */
252
418
  C.ErrorBox = function ErrorBox(props) {
253
419
  const error = props.error || {}
420
+ const code = String(error.code || error.name || 'error')
421
+ const message = String(error.message || error)
254
422
  return h(
255
423
  'div',
256
424
  { className: 'acc-state acc-state-error', role: 'alert' },
257
- h('div', { className: 'acc-state-title' }, props.label || '加载失败'),
258
- h('div', { className: 'acc-state-code' }, String(error.code || error.name || 'error')),
259
- h('div', { className: 'acc-state-message' }, String(error.message || error)),
425
+ h('div', { className: 'acc-state-icon' }, h(C.Icon, { name: 'alert', size: 20 })),
426
+ h('div', { className: 'acc-state-title' }, props.label || ACC.t('common.loadFailed')),
427
+ h('div', { className: 'acc-state-code', title: code }, code),
428
+ h('div', { className: 'acc-state-message' }, message),
260
429
  error.hint ? h('div', { className: 'acc-state-hint' }, String(error.hint)) : null,
261
- props.onRetry ? h('div', { className: 'acc-state-action' }, h(C.Btn, { onClick: props.onRetry }, '重试')) : null,
430
+ props.onRetry
431
+ ? h(
432
+ 'div',
433
+ { className: 'acc-state-action' },
434
+ h(C.Btn, { tone: 'default', icon: 'retry', onClick: props.onRetry }, props.retryLabel || ACC.t('common.retry')),
435
+ )
436
+ : null,
262
437
  )
263
438
  }
264
439
 
@@ -272,7 +447,7 @@ C.Notice = function Notice(props) {
272
447
  * document.body, Esc closes only the top layer, Tab is trapped, focus is
273
448
  * restored) and falls back to an inline fixed-position dialog on hosts that do
274
449
  * not ship the primitive.
275
- * @param {{ children?: unknown, onClose?: Function, title?: unknown, footer?: unknown, tone?: 'warning', closeLabel?: string, open?: boolean }} props
450
+ * @param {{ children?: unknown, onClose?: Function, title?: unknown, description?: unknown, footer?: unknown, tone?: 'warning', closeLabel?: string, open?: boolean }} props
276
451
  */
277
452
  C.Modal = function Modal(props) {
278
453
  const HostModal = PRIMITIVES === undefined ? undefined : PRIMITIVES.Modal
@@ -283,7 +458,8 @@ C.Modal = function Modal(props) {
283
458
  open: props.open !== false,
284
459
  onClose: props.onClose,
285
460
  title: props.title,
286
- closeLabel: props.closeLabel,
461
+ description: props.description,
462
+ closeLabel: props.closeLabel || ACC.t('common.close'),
287
463
  tone: props.tone,
288
464
  footer: props.footer,
289
465
  },
@@ -296,6 +472,8 @@ C.Modal = function Modal(props) {
296
472
  /** Fallback dialog used only when the host primitive is unavailable. */
297
473
  function InlineModal(props) {
298
474
  const ref = useRef(null)
475
+ const titleIdRef = useRef(null)
476
+ if (titleIdRef.current === null) titleIdRef.current = `acc-modal-title-${String(Math.floor(Math.random() * 1e6))}`
299
477
  useEffect(() => {
300
478
  const onKey = (event) => {
301
479
  if (event.key === 'Escape') {
@@ -304,6 +482,8 @@ function InlineModal(props) {
304
482
  }
305
483
  }
306
484
  document.addEventListener('keydown', onKey)
485
+ const first = ref.current && ref.current.firstElementChild
486
+ if (first && typeof first.focus === 'function') first.focus()
307
487
  return () => document.removeEventListener('keydown', onKey)
308
488
  }, [props.onClose])
309
489
  if (props.open === false) return null
@@ -318,59 +498,120 @@ function InlineModal(props) {
318
498
  },
319
499
  h(
320
500
  'div',
321
- { className: 'acc-modal', role: 'dialog', 'aria-modal': 'true', ref },
501
+ { className: 'acc-modal', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': titleIdRef.current, ref },
322
502
  h(
323
503
  'header',
324
504
  { className: 'acc-modal-head' },
325
- h('h3', { className: 'acc-modal-title' }, props.title),
326
- h(C.Btn, { tone: 'ghost', onClick: props.onClose, title: 'Esc' }, props.closeLabel || '关闭'),
505
+ h('h3', { className: 'acc-modal-title', id: titleIdRef.current }, props.title),
506
+ h(C.Btn, { tone: 'ghost', icon: 'close', onClick: props.onClose, ariaLabel: props.closeLabel || ACC.t('common.close'), title: 'Esc' }),
327
507
  ),
328
508
  h('div', { className: 'acc-modal-body' }, props.children),
329
- props.footer === undefined ? null : h('div', { className: 'acc-modal-body' }, props.footer),
509
+ props.footer === undefined ? null : h('div', { className: 'acc-modal-footer' }, props.footer),
330
510
  ),
331
511
  )
332
512
  }
333
513
 
334
514
  /**
335
515
  * Minimal table. `columns` is `[{ key, label, align?, render? }]`; `rows` are
336
- * plain objects addressed by column key.
337
- * @param {{ columns: Array<{ key: string, label: unknown, align?: string, render?: Function }>, rows: readonly any[], empty?: unknown, rowKey?: string }} props
516
+ * plain objects addressed by column key. Optional `rowProps(row, index)` and
517
+ * `rowClassName(row, index)` let a page make rows focusable/selectable without
518
+ * forking the grid.
519
+ * `truncate` (table-wide) or a column's own `truncate` clips the cell to one
520
+ * line with an ellipsis and exposes the full value as the `title`; string
521
+ * returns from a custom `render` are clipped the same way.
522
+ * @param {{
523
+ * columns: Array<{ key: string, label: unknown, align?: string, render?: Function, truncate?: boolean }>,
524
+ * rows: readonly any[],
525
+ * empty?: unknown,
526
+ * rowKey?: string,
527
+ * truncate?: boolean,
528
+ * rowProps?: (row: any, index: number) => Record<string, unknown>,
529
+ * rowClassName?: (row: any, index: number) => string,
530
+ * }} props
338
531
  */
339
532
  C.Table = function Table(props) {
340
533
  if (props.rows.length === 0 && props.empty !== undefined) {
341
534
  return props.empty
342
535
  }
343
536
  const rowKey = props.rowKey || 'id'
537
+ // A long table scrolls inside its own frame so the sticky header stays
538
+ // useful; short tables keep growing with the page.
539
+ const tall = props.rows.length >= 14
344
540
  return h(
345
541
  'div',
346
- { className: 'acc-table-wrap' },
542
+ { className: tall ? 'acc-table-wrap is-tall' : 'acc-table-wrap' },
347
543
  h(
348
544
  'table',
349
545
  { className: 'acc-table' },
350
- h('thead', null, h('tr', null, props.columns.map((column) => h('th', { key: column.key, className: column.align ? `acc-align-${column.align}` : undefined }, column.label)))),
546
+ h(
547
+ 'thead',
548
+ null,
549
+ h(
550
+ 'tr',
551
+ null,
552
+ props.columns.map((column) =>
553
+ h('th', { key: column.key, scope: 'col', className: column.align ? `acc-align-${column.align}` : undefined }, column.label),
554
+ ),
555
+ ),
556
+ ),
351
557
  h(
352
558
  'tbody',
353
559
  null,
354
- props.rows.map((row, index) =>
355
- h(
560
+ props.rows.map((row, index) => {
561
+ const extra = props.rowProps ? props.rowProps(row, index) : undefined
562
+ const rowClass = props.rowClassName ? props.rowClassName(row, index) : undefined
563
+ const attributes = { ...(extra || {}), key: row[rowKey] === undefined ? String(index) : String(row[rowKey]) }
564
+ if (rowClass) attributes.className = rowClass
565
+ return h(
356
566
  'tr',
357
- { key: row[rowKey] === undefined ? String(index) : String(row[rowKey]) },
567
+ attributes,
358
568
  props.columns.map((column) =>
359
- h('td', { key: column.key, className: column.align ? `acc-align-${column.align}` : undefined }, column.render ? column.render(row, index) : renderCell(row[column.key])),
569
+ h('td', { key: column.key, className: column.align ? `acc-align-${column.align}` : undefined }, renderCellContent(column, row, index, props.truncate === true)),
360
570
  ),
361
- ),
362
- ),
571
+ )
572
+ }),
363
573
  ),
364
574
  ),
365
575
  )
366
576
  }
367
577
 
368
- /** @param {unknown} value @returns {unknown} */
369
- function renderCell(value) {
370
- if (value === null || value === undefined) return '—'
371
- if (typeof value === 'string' || typeof value === 'number') return String(value)
372
- if (Array.isArray(value)) return value.map((item) => (typeof item === 'string' ? item : JSON.stringify(item))).join(', ')
373
- return JSON.stringify(value)
578
+ /** Long default cells keep one line and expose the full text through `title`. */
579
+ const ACC_CELL_ELLIPSIS_AT = 44
580
+
581
+ /** @param {unknown} value @returns {string} */
582
+ function cellText(value) {
583
+ return typeof value === 'string' ? value : typeof value === 'number' ? String(value) : Array.isArray(value) ? value.map((item) => (typeof item === 'string' ? item : JSON.stringify(item))).join(', ') : JSON.stringify(value)
584
+ }
585
+
586
+ /**
587
+ * Resolve one cell. Clipping is opt-in per table or per column, so pages that
588
+ * already render structured cells keep full control.
589
+ * @param {{ render?: Function, truncate?: boolean, key: string }} column
590
+ * @param {Record<string, unknown>} row
591
+ * @param {number} index
592
+ * @param {boolean} truncateAll
593
+ * @returns {unknown}
594
+ */
595
+ function renderCellContent(column, row, index, truncateAll) {
596
+ const clip = truncateAll || column.truncate === true
597
+ if (column.render) {
598
+ const rendered = column.render(row, index)
599
+ if (clip && (typeof rendered === 'string' || typeof rendered === 'number')) {
600
+ const text = String(rendered)
601
+ return h('span', { className: 'acc-cell-text is-clip', title: text }, text)
602
+ }
603
+ return rendered
604
+ }
605
+ return renderCell(row[column.key], clip)
606
+ }
607
+
608
+ /** @param {unknown} value @param {boolean} clip @returns {unknown} */
609
+ function renderCell(value, clip) {
610
+ if (value === null || value === undefined) return h('span', { className: 'acc-cell-empty' }, '—')
611
+ const text = cellText(value)
612
+ if (clip) return h('span', { className: 'acc-cell-text is-clip', title: text }, text)
613
+ const long = text.length > ACC_CELL_ELLIPSIS_AT
614
+ return h('span', { className: long ? 'acc-cell-text is-long' : 'acc-cell-text', title: long ? text : undefined }, text)
374
615
  }
375
616
 
376
617
  /** @param {{ items: Array<{ label: unknown, value: unknown }> }} props */
@@ -384,6 +625,18 @@ C.KeyValues = function KeyValues(props) {
384
625
  )
385
626
  }
386
627
 
628
+ /**
629
+ * One-line monospace value (id, path, hash). Long values elide and expose the
630
+ * full string through `title`, so a table or card never grows sideways.
631
+ * @param {{ text?: unknown, children?: unknown, title?: string, className?: string }} props
632
+ */
633
+ C.Mono = function Mono(props) {
634
+ const content = props.text === undefined ? props.children : props.text
635
+ const own = typeof content === 'string' || typeof content === 'number' ? String(content) : null
636
+ const title = props.title === undefined ? (own !== null && own.length > 12 ? own : undefined) : props.title
637
+ return h('span', { className: `acc-mono${props.className ? ` ${props.className}` : ''}`, title }, content)
638
+ }
639
+
387
640
  /** @param {{ text: string }} props — monospace block used for diffs / previews */
388
641
  C.Code = function Code(props) {
389
642
  return h('pre', { className: 'acc-code' }, props.text)
@@ -445,7 +698,41 @@ ACC.fmt = {
445
698
  },
446
699
  }
447
700
 
701
+ /**
702
+ * Give every clipped one-line value a native tooltip. Pages render ids and
703
+ * paths as plain `.acc-mono` spans, so the shell annotates whatever the current
704
+ * page produced (and re-annotates after data-driven DOM updates) instead of
705
+ * asking nine pages to repeat the same `title` logic. Returns a disposer.
706
+ * @param {Element | null} container
707
+ * @returns {() => void}
708
+ */
709
+ ACC.annotateTruncation = function annotateTruncation(container) {
710
+ if (container === null || container === undefined || typeof MutationObserver !== 'function') return () => {}
711
+ let frame = 0
712
+ const annotate = () => {
713
+ frame = 0
714
+ for (const element of container.querySelectorAll('.acc-mono, .acc-cell-text')) {
715
+ if (element.hasAttribute('title')) continue
716
+ const text = element.textContent === null ? '' : String(element.textContent)
717
+ if (text.length < 8) continue
718
+ if (element.scrollWidth > element.clientWidth + 1) element.setAttribute('title', text)
719
+ }
720
+ }
721
+ const schedule = () => {
722
+ if (frame !== 0) return
723
+ frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(annotate) : setTimeout(annotate, 60)
724
+ }
725
+ const observer = new MutationObserver(schedule)
726
+ observer.observe(container, { childList: true, subtree: true })
727
+ schedule()
728
+ return () => {
729
+ observer.disconnect()
730
+ if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
731
+ }
732
+ }
733
+
448
734
  ACC.components = C
735
+ ACC.icons = ACC_ICONS
449
736
  ACC.useState = useState
450
737
  ACC.useEffect = useEffect
451
738
  ACC.useMemo = useMemo