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,19 +1,37 @@
1
- /* Agent information page — two read-only views (Agents / Presets) plus the
2
- * redacted configuration export and the import pipeline. Host configuration
3
- * writes are not possible here: every host-config section is labelled BLOCKED
4
- * from the host response, never faked locally. */
1
+ /* Agent information page — Agent/preset views, redacted configuration export
2
+ * and the import pipeline.
3
+ *
4
+ * UX rules kept here:
5
+ * - Four tabs (Agent / Presets / Export / Import) with real tab semantics and
6
+ * Left/Right arrow navigation.
7
+ * - Presets open a detail dialog; host configuration writes are never faked —
8
+ * every unavailable target is labelled BLOCKED *with the host's reason*.
9
+ * - Export states the redaction promise before generating and reports the
10
+ * result inline (counts, bytes, time) with download/copy feedback.
11
+ * - Import preview is a field-level two-column diff (current vs target), plus
12
+ * a collapsed raw unified diff for copy/paste. */
5
13
  (function metaPage() {
6
14
  /* Layout only: the host scrolls the content column, so pages never take over
7
15
  * height/overflow. Colors/typography come from the shared acc-* classes. */
8
16
  const PAGE_STYLE = { display: 'flex', flexDirection: 'column', gap: '12px', padding: '8px 0' }
9
17
  const STACK_STYLE = { display: 'flex', flexDirection: 'column', gap: '12px' }
10
- const TEXTAREA_STYLE = { width: '100%', minHeight: '160px', resize: 'vertical' }
11
18
  const TABS = [
12
19
  { id: 'agents', key: 'meta.tabAgents' },
13
20
  { id: 'presets', key: 'meta.tabPresets' },
14
21
  { id: 'export', key: 'meta.tabExport' },
15
22
  { id: 'import', key: 'meta.tabImport' },
16
23
  ]
24
+ const DIFF_PANEL_STYLE = {
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ gap: '4px',
28
+ minWidth: 0,
29
+ padding: '8px',
30
+ border: '.5px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))',
31
+ borderRadius: 'var(--dsw-radius-sm, 8px)',
32
+ background: 'var(--dsw-alias-interactive-bg-hover, rgba(38,49,72,.06))',
33
+ }
34
+ const CLAMP_STYLE = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '100%' }
17
35
 
18
36
  /** @param {any} block @param {{ value?: string, fallback?: string }} [options] */
19
37
  function blockValue(block, options) {
@@ -45,21 +63,6 @@
45
63
  return `${String(value.provider || '?')}/${String(value.model || '?')}${value.reasoningEffort ? ` · ${String(value.reasoningEffort)}` : ''}`
46
64
  }
47
65
 
48
- /** @param {string} text @param {string} name */
49
- function downloadText(text, name) {
50
- try {
51
- const blob = new Blob([text], { type: 'application/json' })
52
- const url = URL.createObjectURL(blob)
53
- const anchor = document.createElement('a')
54
- anchor.href = url
55
- anchor.download = name
56
- anchor.click()
57
- setTimeout(() => URL.revokeObjectURL(url), 1000)
58
- } catch {
59
- // Download is a convenience only; the JSON stays visible in the modal.
60
- }
61
- }
62
-
63
66
  /** @param {string} text @returns {number} UTF-8 byte length without Node buffers */
64
67
  function utf8Bytes(value) {
65
68
  try {
@@ -69,8 +72,71 @@
69
72
  }
70
73
  }
71
74
 
72
- /** @param {any} preview @param {Function} t */
73
- function unifiedDiffText(preview, t) {
75
+ /** Download helper with URL cleanup on unmount (no leaked revoke timers). */
76
+ function useDownload() {
77
+ const timers = ACC.useRef([])
78
+ ACC.useEffect(() => () => {
79
+ for (const timer of timers.current) clearTimeout(timer)
80
+ timers.current = []
81
+ }, [])
82
+ return ACC.useCallback((input) => {
83
+ const blob = new Blob([input.text], { type: input.mime || 'application/json' })
84
+ const url = URL.createObjectURL(blob)
85
+ const anchor = document.createElement('a')
86
+ anchor.href = url
87
+ anchor.download = input.filename
88
+ anchor.click()
89
+ const timer = setTimeout(() => URL.revokeObjectURL(url), 1000)
90
+ timers.current.push(timer)
91
+ }, [])
92
+ }
93
+
94
+ /** Inline copy feedback (the host has no toast service). */
95
+ function CopyButton(props) {
96
+ const [state, setState] = ACC.useState('idle')
97
+ const copy = ACC.useCallback(() => {
98
+ const text = String(props.text || '')
99
+ if (text.length === 0) {
100
+ setState('failed')
101
+ return
102
+ }
103
+ if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
104
+ navigator.clipboard.writeText(text).then(() => setState('done'), () => setState('failed'))
105
+ return
106
+ }
107
+ setState('failed')
108
+ }, [props.text])
109
+ ACC.useEffect(() => {
110
+ if (state === 'idle') return undefined
111
+ const timer = setTimeout(() => setState('idle'), 1800)
112
+ return () => clearTimeout(timer)
113
+ }, [state])
114
+ const label = state === 'done' ? props.t('meta.copied') : state === 'failed' ? props.t('meta.copyFailed') : props.label || props.t('meta.copy')
115
+ return h(C.Btn, { tone: 'ghost', onClick: copy, title: label, ariaLabel: props.ariaLabel || label, style: { padding: '0 6px' } }, label)
116
+ }
117
+
118
+ /** Collapsible block with a real button header. */
119
+ function Disclosure(props) {
120
+ return h(
121
+ 'div',
122
+ { style: { display: 'flex', flexDirection: 'column', gap: '6px' } },
123
+ h(
124
+ 'button',
125
+ {
126
+ type: 'button',
127
+ onClick: props.onToggle,
128
+ 'aria-expanded': props.open,
129
+ style: { display: 'flex', alignItems: 'center', gap: '6px', padding: 0, border: 0, background: 'transparent', color: 'inherit', font: 'inherit', cursor: 'pointer', textAlign: 'left' },
130
+ },
131
+ h('span', { 'aria-hidden': 'true' }, props.open ? '▾' : '▸'),
132
+ h('span', { className: 'acc-muted' }, props.label),
133
+ ),
134
+ props.open ? props.children : null,
135
+ )
136
+ }
137
+
138
+ /** @param {string} text @param {string} name */
139
+ function rawDiffLines(preview, t) {
74
140
  const lines = []
75
141
  const show = (value) => (value === null || value === undefined || value === '' ? '∅' : String(value))
76
142
  const diff = preview.diff || {}
@@ -84,28 +150,20 @@
84
150
  lines.push(`- ${field.field}: ${show(field.current)}`)
85
151
  lines.push(`+ ${field.field}: ${show(field.target)}`)
86
152
  }
87
- const composition = entry.composition
88
- if (composition && composition.changed === true) {
89
- for (const line of composition.removed || []) lines.push(`- ${line.line}: ${line.text}`)
90
- for (const line of composition.added || []) lines.push(`+ ${line.line}: ${line.text}`)
91
- if (composition.truncated) lines.push(`… ${t('meta.importDiffTruncated')}`)
92
- }
93
153
  }
94
154
  const models = diff.models || { changed: false, fields: [] }
95
155
  if (models.changed) {
96
- lines.push(`--- ${t('meta.importModels')} ${t('meta.importCurrent')}`)
97
- lines.push(`+++ ${t('meta.importModels')} ${t('meta.importTarget')}`)
98
156
  for (const field of models.fields || []) {
99
157
  if (!field.changed) continue
100
- lines.push(`- ${field.field}: ${show(field.current)}`)
101
- lines.push(`+ ${field.field}: ${show(field.target)}`)
158
+ lines.push(`- ${t('meta.importModels')} ${field.field}: ${show(field.current)}`)
159
+ lines.push(`+ ${t('meta.importModels')} ${field.field}: ${show(field.target)}`)
102
160
  }
103
161
  }
104
162
  if (lines.length === 0) lines.push(t('meta.importDiffEmpty'))
105
163
  return lines.join('\n')
106
164
  }
107
165
 
108
- /** @param {any} writeability @param {Function} t */
166
+ /** One write target as a plain row (BLOCKED keeps the host's reason). */
109
167
  function writeabilityRows(writeability, t) {
110
168
  if (writeability === null || writeability === undefined || typeof writeability !== 'object') return []
111
169
  const labels = {
@@ -121,11 +179,8 @@
121
179
  rows.push({
122
180
  key,
123
181
  target: labels[key],
124
- status: entry.available === true
125
- ? h(C.Badge, { tone: 'success' }, t('meta.importWritable'))
126
- : entry.code === 'not_applied'
127
- ? h(C.Badge, { tone: 'warn' }, t('meta.importNotApplied'))
128
- : h(C.Badge, { tone: 'danger' }, t('meta.importBlocked')),
182
+ available: entry.available === true,
183
+ code: String(entry.code || ''),
129
184
  reason: String(entry.reason || ''),
130
185
  hint: String(entry.hint || ''),
131
186
  })
@@ -133,6 +188,65 @@
133
188
  return rows
134
189
  }
135
190
 
191
+ /** A field row inside one diff column. */
192
+ function diffField(label, value, t) {
193
+ const text = value === null || value === undefined || value === '' ? '∅' : String(value)
194
+ return h(
195
+ 'div',
196
+ { key: label, style: { display: 'flex', gap: '6px', minWidth: 0, fontSize: '11px', lineHeight: '16px' } },
197
+ h('span', { className: 'acc-muted', style: { flex: '0 0 auto' } }, `${label}:`),
198
+ h('span', { className: 'acc-mono', style: { ...CLAMP_STYLE, wordBreak: 'break-word', overflowWrap: 'anywhere' }, title: text }, text),
199
+ )
200
+ }
201
+
202
+ /** Field-level two-column diff for one changed preset. */
203
+ function PresetDiff(props) {
204
+ const { entry, t } = props
205
+ const fields = Array.isArray(entry.fields) ? entry.fields : []
206
+ const composition = entry.composition && entry.composition.changed === true ? entry.composition : null
207
+ return h(
208
+ 'div',
209
+ { style: { display: 'flex', flexDirection: 'column', gap: '6px', paddingTop: '6px' } },
210
+ h(
211
+ 'div',
212
+ { className: 'acc-row', style: { gap: '6px' } },
213
+ h('strong', { className: 'acc-mono', style: { fontSize: '12px' } }, String(entry.id)),
214
+ entry.name ? h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, String(entry.name)) : null,
215
+ ),
216
+ h(
217
+ 'div',
218
+ { className: 'acc-grid-2' },
219
+ h(
220
+ 'div',
221
+ { style: DIFF_PANEL_STYLE },
222
+ h('div', { className: 'acc-section-title' }, t('meta.diffCurrent')),
223
+ fields.length === 0 ? h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, t('common.none')) : fields.map((field) => diffField(field.field, field.current, t)),
224
+ composition && Array.isArray(composition.removed) && composition.removed.length > 0
225
+ ? h(
226
+ 'div',
227
+ { style: { display: 'flex', flexDirection: 'column', gap: '1px', marginTop: '4px' } },
228
+ composition.removed.map((line) => h('span', { key: String(line.line), className: 'acc-mono', style: { fontSize: '11px', color: 'var(--acc-danger-text, #b42318)' } }, `- ${line.text}`)),
229
+ )
230
+ : null,
231
+ ),
232
+ h(
233
+ 'div',
234
+ { style: DIFF_PANEL_STYLE },
235
+ h('div', { className: 'acc-section-title' }, t('meta.diffTarget')),
236
+ fields.length === 0 ? h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, t('common.none')) : fields.map((field) => diffField(field.field, field.target, t)),
237
+ composition && Array.isArray(composition.added) && composition.added.length > 0
238
+ ? h(
239
+ 'div',
240
+ { style: { display: 'flex', flexDirection: 'column', gap: '1px', marginTop: '4px' } },
241
+ composition.added.map((line) => h('span', { key: String(line.line), className: 'acc-mono', style: { fontSize: '11px', color: 'var(--acc-success-text, #15803d)' } }, `+ ${line.text}`)),
242
+ )
243
+ : null,
244
+ ),
245
+ ),
246
+ composition && composition.truncated ? h('div', { className: 'acc-muted', style: { fontSize: '11px' } }, t('meta.importDiffTruncated')) : null,
247
+ )
248
+ }
249
+
136
250
  /** @param {{ t: Function }} props */
137
251
  function AgentsView(props) {
138
252
  const t = props.t
@@ -140,7 +254,9 @@
140
254
  if (state.status === 'loading') return h(C.Loading, { label: t('common.loading') })
141
255
  if (state.status === 'error') return h(C.ErrorBox, { error: state.error, onRetry: state.reload, label: t('meta.loadFailed') })
142
256
  const data = state.data
143
- if (data.available === false) return h(C.Empty, { title: t('meta.agentsUnavailable'), hint: String(data.reason || '') })
257
+ if (data.available === false) {
258
+ return h(C.Empty, { title: t('meta.agentsUnavailable'), hint: String(data.reason || ''), action: h(C.Btn, { onClick: state.reload }, t('common.retry')) })
259
+ }
144
260
  const agents = data.agents && data.agents.available === true ? data.agents.items : []
145
261
  const md = data.agentsMd || {}
146
262
  const models = data.models || {}
@@ -150,36 +266,77 @@
150
266
  { style: STACK_STYLE },
151
267
  h(
152
268
  C.Card,
153
- { title: t('meta.agentsTitle'), subtitle: t('meta.agentsHint'), actions: h(C.Btn, { onClick: state.reload }, t('common.refresh')) },
269
+ {
270
+ title: t('meta.agentsTitle'),
271
+ subtitle: t('meta.agentsHint'),
272
+ actions: h(
273
+ 'div',
274
+ { className: 'acc-row' },
275
+ h(C.Badge, { tone: 'neutral' }, t('meta.agentCount', { count: agents.length })),
276
+ h(C.Btn, { tone: 'ghost', onClick: state.reload, icon: 'retry', ariaLabel: t('meta.refreshAgents') }, t('common.refresh')),
277
+ ),
278
+ },
154
279
  agents.length === 0
155
- ? h(C.Empty, { title: t('meta.noAgents'), hint: t('meta.noAgentsHint') })
156
- : h(C.Table, {
157
- columns: [
158
- { key: 'name', label: t('meta.agentName'), render: (row) => (row.name && row.name.available === true && row.name.value ? String(row.name.value) : h('span', { className: 'acc-mono' }, String(row.id))) },
159
- { key: 'id', label: t('meta.agentId'), render: (row) => h('span', { className: 'acc-mono' }, String(row.id)) },
160
- { key: 'preset', label: t('meta.agentPreset'), render: (row) => (row.preset && row.preset.available === true ? String(row.preset.value) : h(C.Badge, { tone: 'warn', title: unavailableReason(row.preset, t) }, t('common.unavailable'))) },
161
- { key: 'model', label: t('meta.agentModel'), render: (row) => modelText(row.model, t) },
162
- { key: 'status', label: t('meta.agentStatus'), render: (row) => h(C.Badge, { tone: row.status === 'running' ? 'info' : 'neutral' }, row.status === 'running' ? t('meta.running') : row.status === 'idle' ? t('meta.idle') : String(row.status || t('common.unknown'))) },
163
- { key: 'sessions', label: t('meta.agentSessions'), align: 'right', render: (row) => String(blockValue(row.sessions)) },
164
- { key: 'tools', label: t('meta.agentTools'), align: 'right', render: (row) => String(blockValue(row.toolCount)) },
165
- {
166
- key: 'agentsMd',
167
- label: t('meta.agentAgentsMd'),
168
- render: (row) => {
169
- const state_ = row.agentsMd || {}
170
- if (state_.available === false) return h(C.Badge, { tone: 'warn', title: String(state_.reason || '') }, t('common.unavailable'))
171
- return h('span', { className: 'acc-row' }, h(C.Badge, { tone: state_.present === true ? 'success' : 'neutral' }, `${t('meta.agentsMdPresent')}: ${state_.present === true ? t('meta.yes') : t('meta.no')}`), h(C.Badge, { tone: state_.inChain === true ? 'success' : state_.inChain === false ? 'neutral' : 'warn' }, `${t('meta.agentsMdInChain')}: ${state_.inChain === true ? t('meta.yes') : state_.inChain === false ? t('meta.no') : t('common.unknown')}`))
172
- },
173
- },
174
- ],
175
- rows: agents,
176
- rowKey: 'id',
177
- }),
178
- Array.isArray(data.notes) && data.notes.length > 0 ? h('ul', { className: 'acc-muted' }, data.notes.map((note, index) => h('li', { key: String(index) }, String(note)))) : null,
280
+ ? h(C.Empty, { title: t('meta.noAgents'), hint: t('meta.noAgentsHint'), icon: 'inbox' })
281
+ : h(
282
+ 'div',
283
+ { className: 'acc-list' },
284
+ agents.map((row) =>
285
+ h(
286
+ 'div',
287
+ { key: String(row.id), className: 'acc-list-item', style: { flexDirection: 'column', alignItems: 'stretch', gap: '4px', cursor: 'default' } },
288
+ h(
289
+ 'div',
290
+ { className: 'acc-row', style: { gap: '6px' } },
291
+ h(
292
+ 'strong',
293
+ { style: { minWidth: 0, ...CLAMP_STYLE } },
294
+ row.name && row.name.available === true && row.name.value ? String(row.name.value) : String(row.id),
295
+ ),
296
+ h(C.Badge, { tone: row.status === 'running' ? 'info' : 'neutral' }, row.status === 'running' ? t('meta.running') : row.status === 'idle' ? t('meta.idle') : String(row.status || t('common.unknown'))),
297
+ h('span', { className: 'acc-grow' }),
298
+ h('span', { className: 'acc-mono', style: { fontSize: '11px', ...CLAMP_STYLE, maxWidth: '120px' }, title: String(row.id) }, String(row.id)),
299
+ ),
300
+ h(
301
+ 'div',
302
+ { className: 'acc-row', style: { gap: '6px', fontSize: '11px' } },
303
+ h(
304
+ 'span',
305
+ { className: 'acc-muted' },
306
+ `${t('meta.agentPreset')} ${row.preset && row.preset.available === true ? String(row.preset.value) : t('common.unavailable')}`,
307
+ ),
308
+ h('span', { className: 'acc-muted', style: { ...CLAMP_STYLE } }, `${t('meta.agentModel')} ${modelText(row.model, t)}`),
309
+ h('span', { className: 'acc-muted' }, `${t('meta.agentSessions')} ${String(blockValue(row.sessions))} · ${t('meta.agentTools')} ${String(blockValue(row.toolCount))}`),
310
+ ),
311
+ (() => {
312
+ const agentsMd = row.agentsMd || {}
313
+ if (agentsMd.available === false) return h(C.Badge, { tone: 'warn', title: String(agentsMd.reason || '') }, t('common.unavailable'))
314
+ return h(
315
+ 'div',
316
+ { className: 'acc-row', style: { gap: '6px' } },
317
+ h(C.Badge, { tone: agentsMd.present === true ? 'success' : 'neutral' }, `${t('meta.agentsMdPresent')}: ${agentsMd.present === true ? t('meta.yes') : t('meta.no')}`),
318
+ h(
319
+ C.Badge,
320
+ { tone: agentsMd.inChain === true ? 'success' : agentsMd.inChain === false ? 'neutral' : 'warn' },
321
+ `${t('meta.agentsMdInChain')}: ${agentsMd.inChain === true ? t('meta.yes') : agentsMd.inChain === false ? t('meta.no') : t('common.unknown')}`,
322
+ ),
323
+ )
324
+ })(),
325
+ ),
326
+ ),
327
+ ),
328
+ Array.isArray(data.notes) && data.notes.length > 0
329
+ ? h(
330
+ 'div',
331
+ { className: 'acc-muted', style: { fontSize: '11px', display: 'flex', flexDirection: 'column', gap: '2px' } },
332
+ h('span', null, t('meta.hostNotesFold')),
333
+ ACC.l10n.raw(t('meta.rawHostText'), data.notes.join('\n')),
334
+ )
335
+ : null,
179
336
  ),
180
337
  h(
181
338
  C.Card,
182
- { title: t('meta.agentsMdTitle') },
339
+ { title: t('meta.agentsMdTitle'), subtitle: t('meta.agentsMdHint') },
183
340
  md.available === false
184
341
  ? h(C.Notice, { tone: 'warn' }, `${t('meta.agentsMdUnavailable')} ${String(md.reason || '')}`)
185
342
  : h(
@@ -191,16 +348,31 @@
191
348
  { label: t('meta.agentsMdInChain'), value: yesNoBadge(md.inChain, t) },
192
349
  { label: t('meta.agentsMdFiles'), value: String(md.fileCount === undefined ? '—' : md.fileCount) },
193
350
  { label: t('meta.source'), value: String(md.source || '') },
194
- { label: t('meta.basis'), value: String(md.basis || '') },
351
+ {
352
+ label: t('meta.basis'),
353
+ value: h(
354
+ 'div',
355
+ { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
356
+ h('span', null, ACC.l10n.host('meta.basisAgentsList', md.basis)),
357
+ ACC.l10n.raw(t('meta.rawHostText'), md.basis),
358
+ ),
359
+ },
195
360
  ],
196
361
  }),
197
362
  Array.isArray(md.files) && md.files.length > 0
198
363
  ? h(C.Table, {
199
364
  columns: [
200
- { key: 'path', label: t('common.path'), render: (row) => h('span', { className: 'acc-mono' }, String(row.path)) },
201
- { key: 'scope', label: t('meta.scope'), render: (row) => String(row.scope || '—') },
202
- { key: 'exists', label: t('meta.exists'), render: (row) => yesNoBadge(row.exists === true, t) },
203
- { key: 'inChain', label: t('meta.agentsMdInChain'), render: (row) => yesNoBadge(row.inChain, t) },
365
+ {
366
+ key: 'path',
367
+ label: t('common.path'),
368
+ render: (row) =>
369
+ h(
370
+ 'div',
371
+ { style: { display: 'flex', flexDirection: 'column', gap: '1px' } },
372
+ h('span', { className: 'acc-mono', style: { fontSize: '11px', ...CLAMP_STYLE, maxWidth: '190px' }, title: String(row.path) }, String(row.path)),
373
+ h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, `${String(row.scope || '—')} · ${t('meta.exists')} ${row.exists === true ? t('meta.yes') : t('meta.no')} · ${t('meta.agentsMdInChain')} ${row.inChain === true ? t('meta.yes') : row.inChain === false ? t('meta.no') : t('common.unknown')}`),
374
+ ),
375
+ },
204
376
  ],
205
377
  rows: md.files,
206
378
  rowKey: 'path',
@@ -217,7 +389,14 @@
217
389
  { label: t('meta.sessionsTotal'), value: sessions.available === true ? String(sessions.total) : String(t('common.unavailable')) },
218
390
  ],
219
391
  }),
220
- models.default && models.default.available === true && models.default.basis ? h(C.Notice, { tone: 'info' }, String(models.default.basis)) : null,
392
+ models.default && models.default.available === true && models.default.basis
393
+ ? h(
394
+ C.Notice,
395
+ { tone: 'info' },
396
+ ACC.l10n.host('meta.modelBasisGeneric', models.default.basis),
397
+ ACC.l10n.raw(t('meta.rawHostText'), models.default.basis),
398
+ )
399
+ : null,
221
400
  ),
222
401
  )
223
402
  }
@@ -232,7 +411,7 @@
232
411
  state.status === 'loading'
233
412
  ? h(C.Loading, { label: t('common.loading') })
234
413
  : state.status === 'error'
235
- ? h(C.ErrorBox, { error: state.error, label: t('meta.loadFailed') })
414
+ ? h(C.ErrorBox, { error: state.error, label: t('meta.loadFailed'), onRetry: state.reload })
236
415
  : state.data.available === false
237
416
  ? h(C.Notice, { tone: 'warn' }, String(state.data.reason || t('common.unavailable')))
238
417
  : h(
@@ -249,7 +428,7 @@
249
428
  ],
250
429
  }),
251
430
  h(C.Notice, { tone: 'info' }, t('meta.presetReadonly')),
252
- h('h4', { className: 'acc-card-title' }, t('meta.presetComposition')),
431
+ h('h4', { className: 'acc-section-title' }, t('meta.presetComposition')),
253
432
  state.data.preset.composition && state.data.preset.composition.available === true
254
433
  ? h(C.Table, {
255
434
  columns: [
@@ -263,7 +442,7 @@
263
442
  })
264
443
  : h(C.Notice, { tone: 'warn' }, String((state.data.preset.composition && state.data.preset.composition.reason) || t('common.unavailable'))),
265
444
  h(C.Truncated, { truncated: state.data.preset.composition && state.data.preset.composition.truncated === true, label: t('meta.compositionTruncated') }),
266
- h('h4', { className: 'acc-card-title' }, t('meta.presetDocument')),
445
+ h('h4', { className: 'acc-section-title' }, t('meta.presetDocument')),
267
446
  state.data.document && state.data.document.available === true
268
447
  ? h(C.Code, { text: String(state.data.document.content || '') })
269
448
  : h(C.Notice, { tone: 'warn' }, String((state.data.document && state.data.document.reason) || t('meta.presetNoDocument'))),
@@ -280,32 +459,82 @@
280
459
  if (state.status === 'loading') return h(C.Loading, { label: t('common.loading') })
281
460
  if (state.status === 'error') return h(C.ErrorBox, { error: state.error, onRetry: state.reload, label: t('meta.loadFailed') })
282
461
  const data = state.data
283
- if (data.available === false) return h(C.Empty, { title: t('meta.presetsUnavailable'), hint: String(data.reason || '') })
462
+ if (data.available === false) {
463
+ return h(C.Empty, { title: t('meta.presetsUnavailable'), hint: String(data.reason || ''), action: h(C.Btn, { onClick: state.reload }, t('common.retry')) })
464
+ }
284
465
  const items = Array.isArray(data.items) ? data.items : []
285
466
  return h(
286
467
  'div',
287
468
  { style: STACK_STYLE },
288
469
  h(
289
470
  C.Card,
290
- { title: t('meta.presetsTitle'), subtitle: t('meta.presetsHint'), actions: h(C.Btn, { onClick: state.reload }, t('common.refresh')) },
471
+ {
472
+ title: t('meta.presetsTitle'),
473
+ subtitle: t('meta.presetsHint'),
474
+ actions: h(
475
+ 'div',
476
+ { className: 'acc-row' },
477
+ h(C.Badge, { tone: 'neutral' }, t('meta.presetCount', { count: items.length })),
478
+ h(C.Btn, { tone: 'ghost', onClick: state.reload, icon: 'retry', ariaLabel: t('meta.refreshPresets') }, t('common.refresh')),
479
+ ),
480
+ },
291
481
  items.length === 0
292
- ? h(C.Empty, { title: t('meta.noPresets'), hint: t('meta.noPresetsHint') })
293
- : h(C.Table, {
294
- columns: [
295
- { key: 'name', label: t('meta.presetName'), render: (row) => h('button', { type: 'button', className: 'acc-btn acc-btn-ghost', onClick: () => setSelected(String(row.id)) }, String(row.name || row.id)) },
296
- { key: 'id', label: t('meta.presetId'), render: (row) => h('span', { className: 'acc-mono' }, String(row.id)) },
297
- { key: 'default', label: t('meta.presetDefault'), render: (row) => (row.isDefault === true ? h(C.Badge, { tone: 'info' }, t('meta.yes')) : '—') },
298
- { key: 'source', label: t('meta.presetSource'), render: (row) => (row.composition && row.composition.available === true ? `${row.composition.rowCount} ${t('meta.rowsUnit')}` : String((row.composition && row.composition.reason) || t('common.unavailable'))) },
299
- { key: 'model', label: t('meta.presetModel'), render: (row) => modelText(row.model, t) },
300
- { key: 'tools', label: t('meta.presetTools'), render: (row) => (row.tools && row.tools.available === true ? `${t('meta.presetToolsVisible')} ${row.tools.visible}${row.tools.conditional === null ? '' : ` · ${t('meta.presetToolsConditional')} ${row.tools.conditional}`}` : String(t('common.unavailable'))) },
301
- { key: 'sessions', label: t('meta.presetSessions'), align: 'right', render: (row) => String(blockValue(row.sessions)) },
302
- { key: 'broken', label: t('meta.presetBroken'), render: (row) => (row.broken ? h(C.Badge, { tone: 'danger', title: String(row.broken) }, t('meta.broken')) : '—') },
303
- ],
304
- rows: items,
305
- rowKey: 'id',
306
- }),
482
+ ? h(C.Empty, { title: t('meta.noPresets'), hint: t('meta.noPresetsHint'), icon: 'inbox', action: h(C.Btn, { onClick: state.reload }, t('common.retry')) })
483
+ : h(
484
+ 'div',
485
+ { className: 'acc-list' },
486
+ items.map((row) =>
487
+ h(
488
+ 'button',
489
+ {
490
+ key: String(row.id),
491
+ type: 'button',
492
+ className: 'acc-list-item',
493
+ 'aria-haspopup': 'dialog',
494
+ 'aria-label': `${t('meta.openPreset')}: ${String(row.name || row.id)}`,
495
+ title: t('meta.openPreset'),
496
+ onClick: () => setSelected(String(row.id)),
497
+ style: { flexDirection: 'column', alignItems: 'stretch', gap: '4px' },
498
+ },
499
+ h(
500
+ 'div',
501
+ { className: 'acc-row', style: { gap: '6px' } },
502
+ h('span', { 'aria-hidden': 'true' }, '▸'),
503
+ h('strong', { style: { minWidth: 0, ...CLAMP_STYLE } }, String(row.name || row.id)),
504
+ row.isDefault === true ? h(C.Badge, { tone: 'info' }, t('meta.defaultBadge')) : null,
505
+ row.broken ? h(C.Badge, { tone: 'danger', title: String(row.broken) }, t('meta.broken')) : null,
506
+ h('span', { className: 'acc-grow' }),
507
+ h('span', { className: 'acc-mono', style: { fontSize: '11px', ...CLAMP_STYLE, maxWidth: '110px' }, title: String(row.id) }, String(row.id)),
508
+ ),
509
+ h(
510
+ 'div',
511
+ { className: 'acc-row', style: { gap: '6px', fontSize: '11px' } },
512
+ h(
513
+ 'span',
514
+ { className: 'acc-muted' },
515
+ row.composition && row.composition.available === true
516
+ ? `${t('meta.presetSource')} ${row.composition.rowCount} ${t('meta.rowsUnit')}`
517
+ : `${t('meta.presetSource')} ${t('common.unavailable')}`,
518
+ ),
519
+ h('span', { className: 'acc-muted', style: { ...CLAMP_STYLE } }, `${t('meta.presetModel')} ${modelText(row.model, t)}`),
520
+ h(
521
+ 'span',
522
+ { className: 'acc-muted' },
523
+ `${t('meta.presetTools')} ${row.tools && row.tools.available === true ? String(row.tools.visible) : t('common.unavailable')} · ${t('meta.presetSessions')} ${String(blockValue(row.sessions))}`,
524
+ ),
525
+ ),
526
+ ),
527
+ ),
528
+ ),
307
529
  h(C.Truncated, { truncated: data.truncated === true, label: `${t('meta.presetsTruncated')} ${data.total}` }),
308
- Array.isArray(data.notes) && data.notes.length > 0 ? h('ul', { className: 'acc-muted' }, data.notes.map((note, index) => h('li', { key: String(index) }, String(note)))) : null,
530
+ Array.isArray(data.notes) && data.notes.length > 0
531
+ ? h(
532
+ 'div',
533
+ { className: 'acc-muted', style: { fontSize: '11px', display: 'flex', flexDirection: 'column', gap: '2px' } },
534
+ h('span', null, t('meta.hostNotesFold')),
535
+ ACC.l10n.raw(t('meta.rawHostText'), data.notes.join('\n')),
536
+ )
537
+ : null,
309
538
  ),
310
539
  selected.length > 0 ? h(PresetDetailModal, { t, presetId: selected, onClose: () => setSelected('') }) : null,
311
540
  )
@@ -317,63 +546,65 @@
317
546
  const [exported, setExported] = ACC.useState(null)
318
547
  const [error, setError] = ACC.useState(null)
319
548
  const [busy, setBusy] = ACC.useState(false)
320
- const [open, setOpen] = ACC.useState(false)
549
+ const [openRaw, setOpenRaw] = ACC.useState(false)
550
+ const [downloaded, setDownloaded] = ACC.useState(false)
551
+ const download = useDownload()
321
552
 
322
553
  const generate = () => {
323
554
  setBusy(true)
324
555
  setError(null)
325
556
  ACC.api('meta.export', {})
326
- .then((value) => {
327
- setExported(value)
328
- setOpen(true)
329
- })
557
+ .then((value) => setExported(value))
330
558
  .catch((failure) => setError(failure))
331
559
  .finally(() => setBusy(false))
332
560
  }
333
561
 
334
562
  const text = exported === null ? '' : JSON.stringify(exported, null, 2)
563
+ const presetCount = exported !== null && Array.isArray(exported.presets) ? exported.presets.length : 0
564
+ const agentCount = exported !== null && Array.isArray(exported.agents) ? exported.agents.length : 0
335
565
  return h(
336
566
  'div',
337
567
  { style: STACK_STYLE },
338
568
  h(
339
569
  C.Card,
340
570
  { title: t('meta.exportTitle'), subtitle: t('meta.exportHint') },
571
+ /* Stated before the button is pressed, not after. */
341
572
  h(C.Notice, { tone: 'info' }, t('meta.exportRedaction')),
342
573
  h(
343
574
  C.Toolbar,
344
575
  null,
345
- h(C.Btn, { tone: 'primary', onClick: generate, disabled: busy }, busy ? t('common.loading') : t('meta.exportGenerate')),
346
- exported === null ? null : h(C.Btn, { onClick: () => setOpen(true) }, t('meta.exportReopen')),
347
- exported === null ? null : h(C.Btn, { onClick: () => downloadText(text, 'dcc-config-export.json') }, t('meta.exportDownload')),
576
+ h(C.Btn, { tone: 'primary', onClick: generate, disabled: busy, icon: 'check' }, busy ? t('meta.exportGenerating') : t('meta.exportGenerate')),
577
+ exported === null ? null : h(C.Btn, { onClick: () => { download({ filename: 'dcc-config-export.json', text }); setDownloaded(true) }, icon: 'check' }, downloaded ? t('meta.downloaded') : t('meta.exportDownload')),
578
+ exported === null ? null : h(CopyButton, { text, t, label: t('meta.exportCopy') }),
579
+ exported === null ? null : h(C.Btn, { tone: 'ghost', onClick: generate, disabled: busy }, t('common.refresh')),
348
580
  ),
349
- error === null ? null : h(C.ErrorBox, { error, label: t('meta.exportFailed') }),
350
- exported === null ? h(C.Empty, { title: t('meta.exportEmpty'), hint: t('meta.exportEmptyHint') }) : null,
351
- ),
352
- open && exported !== null
353
- ? h(
354
- C.Modal,
355
- { title: t('meta.exportTitle'), onClose: () => setOpen(false) },
356
- h(C.Notice, { tone: 'info' }, t('meta.exportRedaction')),
357
- Array.isArray(exported.warnings) && exported.warnings.length > 0 ? h(C.Notice, { tone: 'warn' }, exported.warnings.join(' · ')) : null,
358
- exported.truncated === true ? h(C.Notice, { tone: 'warn' }, String(exported.truncationReason || t('meta.exportTruncated'))) : null,
359
- h(C.KeyValues, {
360
- items: [
361
- { label: t('meta.exportSchemaVersion'), value: String(exported.schemaVersion) },
362
- { label: t('meta.exportedAt'), value: String(exported.exportedAt) },
363
- { label: t('meta.exportBytes'), value: ACC.fmt.bytes(utf8Bytes(text)) },
364
- { label: t('meta.exportPresets'), value: Array.isArray(exported.presets) ? String(exported.presets.length) : '0' },
365
- { label: t('meta.exportAgents'), value: Array.isArray(exported.agents) ? String(exported.agents.length) : '0' },
366
- ],
367
- }),
368
- h(C.Code, { text }),
369
- h(
370
- C.Toolbar,
371
- null,
372
- h(C.Btn, { onClick: () => downloadText(text, 'dcc-config-export.json') }, t('meta.exportDownload')),
373
- h(C.Btn, { tone: 'ghost', onClick: () => setOpen(false) }, t('common.close')),
581
+ error === null ? null : h(C.ErrorBox, { error, label: t('meta.exportFailed'), onRetry: generate }),
582
+ exported === null
583
+ ? h(C.Empty, { title: t('meta.exportEmpty'), hint: t('meta.exportEmptyHint'), icon: 'check', action: h(C.Btn, { tone: 'primary', onClick: generate }, t('meta.exportGenerate')) })
584
+ : h(
585
+ 'div',
586
+ { style: STACK_STYLE, 'aria-live': 'polite' },
587
+ h(C.Notice, { tone: 'success' }, t('meta.exportGenerated', { presets: presetCount, agents: agentCount, bytes: ACC.fmt.bytes(utf8Bytes(text)) })),
588
+ Array.isArray(exported.warnings) && exported.warnings.length > 0
589
+ ? h(C.Notice, { tone: 'warn' }, t('meta.exportWarningsFold'), ACC.l10n.raw(t('meta.rawHostText'), exported.warnings.join('\n')))
590
+ : null,
591
+ exported.truncated === true ? h(C.Notice, { tone: 'warn' }, String(exported.truncationReason || t('meta.exportTruncated'))) : null,
592
+ h(C.KeyValues, {
593
+ items: [
594
+ { label: t('meta.exportSchemaVersion'), value: String(exported.schemaVersion) },
595
+ { label: t('meta.exportedAt'), value: ACC.l10n.dateTime(exported.exportedAt, t) },
596
+ { label: t('meta.exportBytes'), value: ACC.fmt.bytes(utf8Bytes(text)) },
597
+ { label: t('meta.exportPresets'), value: String(presetCount) },
598
+ { label: t('meta.exportAgents'), value: String(agentCount) },
599
+ ],
600
+ }),
601
+ h(
602
+ Disclosure,
603
+ { open: openRaw, onToggle: () => setOpenRaw((value) => !value), label: t('meta.exportShowJson') },
604
+ h(C.Code, { text }),
605
+ ),
374
606
  ),
375
- )
376
- : null,
607
+ ),
377
608
  )
378
609
  }
379
610
 
@@ -386,20 +617,28 @@
386
617
  const [busy, setBusy] = ACC.useState(false)
387
618
  const [confirmOpen, setConfirmOpen] = ACC.useState(false)
388
619
  const [applied, setApplied] = ACC.useState(null)
620
+ const [openRaw, setOpenRaw] = ACC.useState(false)
621
+ const textRef = ACC.useRef(null)
622
+
623
+ const parse = () => {
624
+ try {
625
+ return { document: JSON.parse(text) }
626
+ } catch (parseError) {
627
+ return { error: Object.assign(new Error(String(parseError.message || parseError)), { code: 'invalid_json' }) }
628
+ }
629
+ }
389
630
 
390
631
  const runPreview = () => {
391
632
  setError(null)
392
633
  setApplied(null)
393
- let parsed
394
- try {
395
- parsed = JSON.parse(text)
396
- } catch (parseError) {
634
+ const parsed = parse()
635
+ if (parsed.error) {
397
636
  setPreview(null)
398
- setError(Object.assign(new Error(String(parseError.message || parseError)), { code: 'invalid_json' }))
637
+ setError(parsed.error)
399
638
  return
400
639
  }
401
640
  setBusy(true)
402
- ACC.api('meta.importPreview', { document: parsed })
641
+ ACC.api('meta.importPreview', { document: parsed.document })
403
642
  .then((value) => setPreview(value))
404
643
  .catch((failure) => {
405
644
  setPreview(null)
@@ -412,20 +651,27 @@
412
651
  setConfirmOpen(false)
413
652
  setBusy(true)
414
653
  setError(null)
415
- let parsed
416
- try {
417
- parsed = JSON.parse(text)
418
- } catch (parseError) {
654
+ const parsed = parse()
655
+ if (parsed.error) {
419
656
  setBusy(false)
420
- setError(Object.assign(new Error(String(parseError.message || parseError)), { code: 'invalid_json' }))
657
+ setError(parsed.error)
421
658
  return
422
659
  }
423
- ACC.api('meta.importApply', { document: parsed, confirm: true })
660
+ ACC.api('meta.importApply', { document: parsed.document, confirm: true })
424
661
  .then((value) => setApplied(value))
425
662
  .catch((failure) => setError(failure))
426
663
  .finally(() => setBusy(false))
427
664
  }
428
665
 
666
+ const writeRows = preview === null ? [] : writeabilityRows(preview.writeability, t)
667
+ const blocked = writeRows.filter((row) => !row.available)
668
+ const canApply = preview !== null && preview.applySupported && preview.applySupported.pluginState === true
669
+ const diff = preview === null ? {} : preview.diff || {}
670
+ const changedPresets = diff.presets && Array.isArray(diff.presets.modified) ? diff.presets.modified : []
671
+ const addedPresets = diff.presets && Array.isArray(diff.presets.added) ? diff.presets.added : []
672
+ const removedPresets = diff.presets && Array.isArray(diff.presets.removed) ? diff.presets.removed : []
673
+ const models = diff.models && diff.models.changed === true ? diff.models : null
674
+
429
675
  return h(
430
676
  'div',
431
677
  { style: STACK_STYLE },
@@ -433,56 +679,122 @@
433
679
  C.Card,
434
680
  { title: t('meta.importTitle'), subtitle: t('meta.importHint') },
435
681
  h(C.Notice, { tone: 'warn' }, t('meta.importLimits')),
436
- h('textarea', {
437
- className: 'acc-code',
438
- style: TEXTAREA_STYLE,
439
- value: text,
440
- placeholder: t('meta.importPlaceholder'),
441
- onChange: (event) => setText(event.target.value),
442
- 'aria-label': t('meta.importDocument'),
443
- }),
682
+ h(
683
+ 'div',
684
+ { className: 'acc-field' },
685
+ h('label', { className: 'acc-label', htmlFor: 'acc-meta-import' }, t('meta.importDocument')),
686
+ h('textarea', {
687
+ id: 'acc-meta-import',
688
+ ref: textRef,
689
+ className: 'acc-textarea',
690
+ value: text,
691
+ placeholder: t('meta.importPlaceholder'),
692
+ onChange: (event) => setText(event.target.value),
693
+ 'aria-invalid': error !== null && error.code === 'invalid_json' ? 'true' : undefined,
694
+ 'aria-describedby': 'acc-meta-import-hint',
695
+ spellCheck: false,
696
+ }),
697
+ h('span', { id: 'acc-meta-import-hint', className: 'acc-muted', style: { fontSize: '11px' } }, t('meta.importBytesHint', { bytes: ACC.fmt.bytes(utf8Bytes(text)) })),
698
+ ),
444
699
  h(
445
700
  C.Toolbar,
446
701
  null,
447
- h(C.Btn, { tone: 'primary', onClick: runPreview, disabled: busy || text.trim().length === 0 }, busy ? t('common.loading') : t('meta.importPreview')),
448
- text.length === 0 ? null : h(C.Btn, { tone: 'ghost', onClick: () => { setText(''); setPreview(null); setError(null); setApplied(null) } }, t('meta.importClear')),
702
+ h(C.Btn, { tone: 'primary', onClick: runPreview, disabled: busy || text.trim().length === 0, icon: 'check' }, busy ? t('common.loading') : t('meta.importPreview')),
703
+ text.length === 0
704
+ ? null
705
+ : h(C.Btn, { tone: 'ghost', onClick: () => { setText(''); setPreview(null); setError(null); setApplied(null) } }, t('meta.importClear')),
449
706
  ),
450
- error === null ? null : h(C.ErrorBox, { error, label: t('meta.importParseFailed') }),
707
+ error === null ? null : h(C.ErrorBox, { error, label: error.code === 'invalid_json' ? t('meta.importParseFailed') : t('meta.loadFailed'), onRetry: error.code === 'invalid_json' ? undefined : runPreview }),
451
708
  ),
452
709
  preview === null
453
710
  ? null
454
711
  : h(
455
712
  C.Card,
456
- { title: t('meta.importDiffTitle') },
713
+ { title: t('meta.importDiffTitle'), subtitle: t('meta.importDiffHint') },
457
714
  h(C.KeyValues, {
458
715
  items: [
459
- { label: t('meta.exportSchemaVersion'), value: String(preview.documentSummary ? preview.documentSummary.schemaVersion : '') },
460
- { label: t('meta.exportedAt'), value: String((preview.documentSummary && preview.documentSummary.exportedAt) || '—') },
461
- { label: t('meta.exportPresets'), value: String(preview.documentSummary ? preview.documentSummary.presetCount : 0) },
462
- { label: t('meta.exportAgents'), value: String(preview.documentSummary ? preview.documentSummary.agentCount : 0) },
463
- { label: t('meta.importUnchanged'), value: String(preview.diff && preview.diff.presets ? preview.diff.presets.unchanged : '—') },
464
- ],
465
- }),
466
- h(C.Notice, { tone: 'info' }, t('meta.importDiffHint')),
467
- h(C.Code, { text: unifiedDiffText(preview, t) }),
468
- h('h4', { className: 'acc-card-title' }, t('meta.importWriteability')),
469
- h(C.Table, {
470
- columns: [
471
- { key: 'target', label: t('meta.importTargetSection') },
472
- { key: 'status', label: t('meta.importStatus') },
473
- { key: 'reason', label: t('common.reason') },
474
- { key: 'hint', label: t('common.detail') },
716
+ {
717
+ label: t('meta.importSummary'),
718
+ value: t('meta.importSummaryValue', {
719
+ added: addedPresets.length,
720
+ removed: removedPresets.length,
721
+ changed: changedPresets.length,
722
+ unchanged: String(diff.presets && diff.presets.unchanged !== undefined ? diff.presets.unchanged : '—'),
723
+ }),
724
+ },
725
+ { label: t('meta.exportSchemaVersion'), value: String(preview.documentSummary ? preview.documentSummary.schemaVersion : '—') },
726
+ { label: t('meta.exportedAt'), value: preview.documentSummary && preview.documentSummary.exportedAt ? ACC.l10n.dateTime(preview.documentSummary.exportedAt, t) : '—' },
727
+ { label: t('meta.importModels'), value: models === null ? t('meta.importUnchangedValue') : t('meta.importChangedValue') },
475
728
  ],
476
- rows: writeabilityRows(preview.writeability, t),
477
- rowKey: 'key',
478
729
  }),
479
- preview.writeability && preview.writeability.hostPresets && preview.writeability.hostPresets.available === false
480
- ? h(C.Notice, { tone: 'danger' }, `${t('meta.importBlockedNotice')} ${String(preview.writeability.hostPresets.reason || '')}`)
730
+ addedPresets.length > 0
731
+ ? h(
732
+ 'div',
733
+ { className: 'acc-row', style: { gap: '6px' } },
734
+ h(C.Badge, { tone: 'success' }, t('meta.importAdded')),
735
+ addedPresets.map((entry) => h(C.Badge, { key: String(entry.id), tone: 'success', title: String(entry.id) }, String(entry.name || entry.id))),
736
+ )
737
+ : null,
738
+ removedPresets.length > 0
739
+ ? h(
740
+ 'div',
741
+ { className: 'acc-row', style: { gap: '6px' } },
742
+ h(C.Badge, { tone: 'danger' }, t('meta.importRemoved')),
743
+ removedPresets.map((entry) => h(C.Badge, { key: String(entry.id), tone: 'danger', title: String(entry.id) }, String(entry.name || entry.id))),
744
+ )
745
+ : null,
746
+ changedPresets.length === 0 && models === null && addedPresets.length === 0 && removedPresets.length === 0
747
+ ? h(C.Notice, { tone: 'success' }, t('meta.importDiffEmpty'))
748
+ : h(
749
+ 'div',
750
+ { style: STACK_STYLE },
751
+ changedPresets.length > 0 ? h('h4', { className: 'acc-section-title' }, t('meta.importModifiedTitle', { count: changedPresets.length })) : null,
752
+ changedPresets.map((entry) => h(PresetDiff, { key: String(entry.id), entry, t })),
753
+ models === null
754
+ ? null
755
+ : h(
756
+ 'div',
757
+ { style: STACK_STYLE },
758
+ h('h4', { className: 'acc-section-title' }, t('meta.importModels')),
759
+ h(
760
+ 'div',
761
+ { className: 'acc-grid-2' },
762
+ h('div', { style: DIFF_PANEL_STYLE }, h('div', { className: 'acc-section-title' }, t('meta.diffCurrent')), (models.fields || []).filter((field) => field.changed).map((field) => diffField(field.field, field.current, t))),
763
+ h('div', { style: DIFF_PANEL_STYLE }, h('div', { className: 'acc-section-title' }, t('meta.diffTarget')), (models.fields || []).filter((field) => field.changed).map((field) => diffField(field.field, field.target, t))),
764
+ ),
765
+ ),
766
+ ),
767
+ h(
768
+ Disclosure,
769
+ { open: openRaw, onToggle: () => setOpenRaw((value) => !value), label: t('meta.importRawDiffToggle') },
770
+ h(C.Code, { text: rawDiffLines(preview, t) }),
771
+ ),
772
+ h('h4', { className: 'acc-section-title' }, t('meta.importWriteability')),
773
+ blocked.length > 0
774
+ ? h(C.Notice, { tone: 'danger' }, h('div', null, h('strong', null, t('meta.blockedTitle'))), h('div', null, t('meta.blockedBody')))
481
775
  : null,
776
+ h(
777
+ 'div',
778
+ { className: 'acc-list' },
779
+ writeRows.map((row) =>
780
+ h(
781
+ 'div',
782
+ { key: row.key, className: 'acc-list-item', style: { flexDirection: 'column', alignItems: 'stretch', gap: '2px', cursor: 'default' } },
783
+ h(
784
+ 'div',
785
+ { className: 'acc-row', style: { gap: '6px' } },
786
+ h('strong', { style: { fontSize: '12px' } }, row.target),
787
+ h(C.Badge, { tone: row.available ? 'success' : row.code === 'not_applied' ? 'warn' : 'danger' }, row.available ? t('meta.importWritable') : row.code === 'not_applied' ? t('meta.importNotApplied') : t('meta.importBlocked')),
788
+ ),
789
+ row.reason ? h('span', { className: 'acc-muted', style: { fontSize: '11px', wordBreak: 'break-word' } }, row.reason) : null,
790
+ row.hint ? h('span', { className: 'acc-muted', style: { fontSize: '11px', wordBreak: 'break-word' } }, row.hint) : null,
791
+ ),
792
+ ),
793
+ ),
482
794
  h(
483
795
  C.Toolbar,
484
796
  null,
485
- h(C.Btn, { tone: 'primary', onClick: () => setConfirmOpen(true), disabled: busy || !(preview.applySupported && preview.applySupported.pluginState === true) }, t('meta.importApply')),
797
+ h(C.Btn, { tone: 'primary', onClick: () => setConfirmOpen(true), disabled: busy || !canApply, icon: 'check' }, t('meta.importApply')),
486
798
  ),
487
799
  h(C.Notice, { tone: 'info' }, t('meta.importApplyHint')),
488
800
  ),
@@ -498,7 +810,15 @@
498
810
  { label: t('meta.importHash'), value: h('span', { className: 'acc-mono' }, String(applied.pluginState ? applied.pluginState.hash : '')) },
499
811
  { label: t('meta.importHostPresets'), value: applied.hostConfig && applied.hostConfig.available === false ? h(C.Badge, { tone: 'danger' }, t('meta.importBlocked')) : h(C.Badge, { tone: 'success' }, t('meta.importWritable')) },
500
812
  { label: t('meta.importHostModels'), value: applied.models && applied.models.available === false ? h(C.Badge, { tone: 'warn' }, t('meta.importNotApplied')) : h(C.Badge, { tone: 'success' }, t('meta.importWritable')) },
501
- { label: t('meta.importRollback'), value: String(applied.rollback ? applied.rollback.reason : '') },
813
+ {
814
+ label: t('meta.importRollback'),
815
+ value: h(
816
+ 'div',
817
+ { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
818
+ h('span', null, ACC.l10n.host('meta.rollbackGeneric', applied.rollback ? applied.rollback.reason : '')),
819
+ ACC.l10n.raw(t('meta.rawHostText'), applied.rollback ? applied.rollback.reason : ''),
820
+ ),
821
+ },
502
822
  ],
503
823
  }),
504
824
  applied.hostConfig && applied.hostConfig.available === false ? h(C.Notice, { tone: 'danger' }, `${t('meta.importBlockedNotice')} ${String(applied.hostConfig.reason || '')}`) : null,
@@ -508,46 +828,86 @@
508
828
  confirmOpen
509
829
  ? h(
510
830
  C.Modal,
511
- { title: t('meta.importConfirmTitle'), onClose: () => setConfirmOpen(false) },
831
+ {
832
+ title: t('meta.importConfirmTitle'),
833
+ onClose: () => setConfirmOpen(false),
834
+ footer: h(
835
+ 'div',
836
+ { className: 'acc-row', style: { justifyContent: 'flex-end' } },
837
+ h(C.Btn, { tone: 'ghost', onClick: () => setConfirmOpen(false) }, t('common.cancel')),
838
+ h(C.Btn, { tone: 'primary', onClick: runApply }, t('meta.importApplyCta')),
839
+ ),
840
+ },
512
841
  h(C.Notice, { tone: 'warn' }, t('meta.importConfirmBody')),
513
- h(C.Notice, { tone: 'danger' }, t('meta.importBlockedNotice')),
514
- h(
515
- C.Toolbar,
516
- null,
517
- h(C.Btn, { tone: 'primary', onClick: runApply }, t('common.confirm')),
518
- h(C.Btn, { tone: 'ghost', onClick: () => setConfirmOpen(false) }, t('common.cancel')),
519
- ),
842
+ h(C.Notice, { tone: 'danger' }, h('div', null, h('strong', null, t('meta.blockedTitle')), h('div', null, t('meta.blockedBody')))),
843
+ h(C.Notice, { tone: 'info' }, t('meta.importRollbackHint')),
520
844
  )
521
845
  : null,
522
846
  )
523
847
  }
524
848
 
525
- /** @param {{ t: Function }} props */
849
+ /** @param {{ t: Function, navigate: Function }} props */
526
850
  function MetaPage(props) {
527
851
  const t = props.t
528
852
  const [tab, setTab] = ACC.useState('agents')
853
+ const tabRefs = ACC.useRef({})
854
+ const move = (delta) => {
855
+ const index = TABS.findIndex((entry) => entry.id === tab)
856
+ const next = TABS[(index + delta + TABS.length) % TABS.length]
857
+ setTab(next.id)
858
+ const node = tabRefs.current[next.id]
859
+ if (node && typeof node.focus === 'function') node.focus()
860
+ }
529
861
  return h(
530
862
  'div',
531
863
  { style: PAGE_STYLE },
532
864
  h(
533
- C.Toolbar,
534
- null,
535
- TABS.map((entry) => h(C.Btn, { key: entry.id, tone: tab === entry.id ? 'primary' : 'default', onClick: () => setTab(entry.id) }, t(entry.key))),
865
+ 'div',
866
+ { className: 'acc-tabs', role: 'tablist', 'aria-label': t('meta.tabsLabel') },
867
+ TABS.map((entry) =>
868
+ h(
869
+ 'button',
870
+ {
871
+ key: entry.id,
872
+ ref: (node) => { tabRefs.current[entry.id] = node },
873
+ type: 'button',
874
+ role: 'tab',
875
+ id: `acc-meta-tab-${entry.id}`,
876
+ 'aria-selected': tab === entry.id,
877
+ 'aria-controls': `acc-meta-panel-${entry.id}`,
878
+ tabIndex: tab === entry.id ? 0 : -1,
879
+ className: `acc-tab${tab === entry.id ? ' is-active' : ''}`,
880
+ onClick: () => setTab(entry.id),
881
+ onKeyDown: (event) => {
882
+ if (event.key === 'ArrowRight') { event.preventDefault(); move(1) }
883
+ else if (event.key === 'ArrowLeft') { event.preventDefault(); move(-1) }
884
+ else if (event.key === 'Home') { event.preventDefault(); setTab(TABS[0].id) }
885
+ else if (event.key === 'End') { event.preventDefault(); setTab(TABS[TABS.length - 1].id) }
886
+ },
887
+ },
888
+ t(entry.key),
889
+ ),
890
+ ),
891
+ ),
892
+ h(
893
+ 'div',
894
+ { role: 'tabpanel', id: `acc-meta-panel-${tab}`, 'aria-labelledby': `acc-meta-tab-${tab}` },
895
+ tab === 'agents'
896
+ ? h(AgentsView, { t })
897
+ : tab === 'presets'
898
+ ? h(PresetsView, { t })
899
+ : tab === 'export'
900
+ ? h(ExportView, { t })
901
+ : h(ImportView, { t }),
536
902
  ),
537
- tab === 'agents'
538
- ? h(AgentsView, { t })
539
- : tab === 'presets'
540
- ? h(PresetsView, { t })
541
- : tab === 'export'
542
- ? h(ExportView, { t })
543
- : h(ImportView, { t }),
544
903
  )
545
904
  }
546
905
 
547
906
  ACC.registerPage({
548
907
  id: 'meta',
549
908
  titleKey: 'nav.meta',
550
- order: 50,
909
+ order: 60,
910
+ group: 'insight',
551
911
  render: (props) => h(MetaPage, props),
552
912
  })
553
913
  })()