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,7 +1,21 @@
1
- /* Overview page — the reference implementation every other page copies.
2
- * It shows environment facts, one number per data source with an explicit
3
- * "unavailable + reason" state, and shortcut cards that navigate internally. */
1
+ /* Overview page — the front door of the console.
2
+ *
3
+ * Information hierarchy, top to bottom:
4
+ * 1. "Needs attention" strip (only when a module reports a real problem).
5
+ * 2. Environment facts (identity of the running host).
6
+ * 3. Key counts — each card is a button that opens the owning page; a count
7
+ * that cannot be read shows the reason, never a fabricated 0.
8
+ * 4. Module status table — one row per module, with the exact detail and a
9
+ * button that opens that module's page.
10
+ *
11
+ * Layout only lives here: the settings column already scrolls, so the page
12
+ * never claims height/overflow. */
4
13
  (function overviewPage() {
14
+ /** Root rhythm: vertical only (the host owns padding and scrolling). */
15
+ const PAGE_STYLE = { display: 'flex', flexDirection: 'column', gap: '16px', padding: '8px 0' }
16
+ const STAT_HINT_STYLE = { color: 'var(--dsw-alias-label-tertiary)', font: '12px/16px var(--dsw-font-family, sans-serif)' }
17
+ const CLAMP_STYLE = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '100%' }
18
+
5
19
  /**
6
20
  * @param {unknown} source
7
21
  * @param {(key: string, values?: Record<string, string | number>) => string} t
@@ -14,80 +28,284 @@
14
28
  return String(t('common.unavailable'))
15
29
  }
16
30
 
31
+ /** @param {string} state @param {Function} t */
32
+ function stateLabel(state, t) {
33
+ const key =
34
+ state === 'FULL' ? 'common.stateFull'
35
+ : state === 'PARTIAL' ? 'common.statePartial'
36
+ : state === 'ALTERNATIVE' ? 'common.stateAlternative'
37
+ : state === 'BLOCKED' ? 'common.stateBlocked'
38
+ : state === 'DEFERRED' ? 'common.stateDeferred'
39
+ : 'common.stateUnknown'
40
+ return `${String(state)} · ${t(key)}`
41
+ }
42
+
43
+ /** @param {string} state */
44
+ function stateTone(state) {
45
+ if (state === 'FULL') return 'success'
46
+ if (state === 'BLOCKED') return 'danger'
47
+ if (state === 'PARTIAL' || state === 'ALTERNATIVE' || state === 'DEFERRED') return 'warn'
48
+ return 'neutral'
49
+ }
50
+
17
51
  /**
18
- * @param {{ label: string, source: unknown, onOpen?: Function, t: Function }} props
52
+ * One clickable number. Unavailable sources show the reason instead of 0 and
53
+ * the button still opens the owning page (which shows the full explanation).
54
+ * @param {{ label: string, source: unknown, page?: string, pageTitle?: string, onOpen: Function, t: Function }} props
19
55
  */
20
56
  function StatCard(props) {
21
57
  const source = /** @type {Record<string, unknown> | null} */ (props.source)
22
- const available = source !== null && source.available === true
58
+ const available = source !== null && typeof source === 'object' && source.available === true
59
+ const reason = source !== null && typeof source === 'object' ? String(source.reason || '') : ''
60
+ const hint = source !== null && typeof source === 'object' ? String(source.hint || '') : ''
61
+ const value = countText(source, props.t)
62
+ const openLabel = props.pageTitle ? props.t('overview.openPage', { page: props.pageTitle }) : undefined
23
63
  return h(
24
64
  'button',
25
65
  {
26
66
  type: 'button',
27
67
  className: `acc-card acc-stat${available ? '' : ' acc-stat-unavailable'}`,
28
68
  onClick: props.onOpen,
29
- title: available ? undefined : String((source && (source.hint || source.reason)) || ''),
69
+ title: available ? openLabel : `${reason}${hint ? ` · ${hint}` : ''}`,
70
+ 'aria-label': `${props.label}: ${value}${available ? '' : ` (${props.t('common.unavailable')}: ${reason})`}${openLabel ? ` - ${openLabel}` : ''}`,
30
71
  },
31
72
  h('span', { className: 'acc-stat-label' }, props.label),
32
- h('span', { className: 'acc-stat-value' }, countText(source, props.t)),
33
- available ? null : h('span', { className: 'acc-stat-reason' }, String((source && source.reason) || props.t('common.unavailable'))),
73
+ h('span', { className: 'acc-stat-value' }, value),
74
+ available
75
+ ? h('span', { style: STAT_HINT_STYLE }, openLabel || '')
76
+ : h('span', { className: 'acc-stat-reason', title: reason }, reason || props.t('common.unavailable')),
34
77
  )
35
78
  }
36
79
 
37
- /** @param {{ summary: any, t: Function, navigate: Function }} props */
38
- function OverviewBody(props) {
80
+ /** Small badge row used for the state distribution. @param {{ counts: Record<string, number>, t: Function }} props */
81
+ function StateSummary(props) {
82
+ const order = ['FULL', 'PARTIAL', 'ALTERNATIVE', 'DEFERRED', 'BLOCKED', 'UNKNOWN']
83
+ const entries = order.filter((state) => (props.counts[state] || 0) > 0)
84
+ if (entries.length === 0) return null
85
+ return h(
86
+ 'div',
87
+ { className: 'acc-row', 'aria-label': props.t('overview.modulesSummary') },
88
+ entries.map((state) =>
89
+ h(C.Badge, { key: state, tone: stateTone(state), title: stateLabel(state, props.t) }, `${state} × ${props.counts[state]}`),
90
+ ),
91
+ )
92
+ }
93
+
94
+ /**
95
+ * "Needs attention" row: diagnostics errors/warnings and instruction-file
96
+ * issues, each linking to the page that owns the fix. Renders nothing when
97
+ * everything is clean, so the strip never becomes decoration.
98
+ * @param {{ summary: any, t: Function, navigate: Function }} props
99
+ */
100
+ function AttentionStrip(props) {
39
101
  const { summary, t, navigate } = props
102
+ const diagnostics = summary.diagnostics && summary.diagnostics.available === true ? summary.diagnostics : null
103
+ const agents = summary.agents && summary.agents.available === true ? summary.agents : null
104
+ const usage = summary.usageToday && summary.usageToday.available === true ? summary.usageToday : null
105
+ const problems = []
106
+ if (diagnostics !== null && (diagnostics.error > 0 || diagnostics.warn > 0)) {
107
+ problems.push(
108
+ h(
109
+ 'div',
110
+ { key: 'diag', className: 'acc-row' },
111
+ h(C.Badge, { tone: diagnostics.error > 0 ? 'danger' : 'warn' }, t('overview.attentionDiagnostics', { errors: diagnostics.error, warnings: diagnostics.warn })),
112
+ h(C.Btn, { tone: 'ghost', onClick: () => navigate('diagnostics'), ariaLabel: t('overview.attentionDiagnosticsCta') }, t('overview.viewDiagnostics')),
113
+ ),
114
+ )
115
+ }
116
+ const issueErrors = agents !== null && agents.issues ? agents.issues.error : 0
117
+ const issueWarnings = agents !== null && agents.issues ? agents.issues.warn : 0
118
+ if (issueErrors > 0 || issueWarnings > 0) {
119
+ problems.push(
120
+ h(
121
+ 'div',
122
+ { key: 'agents', className: 'acc-row' },
123
+ h(C.Badge, { tone: issueErrors > 0 ? 'danger' : 'warn' }, t('overview.attentionAgents', { errors: issueErrors, warnings: issueWarnings })),
124
+ h(C.Btn, { tone: 'ghost', onClick: () => navigate('agents') }, t('overview.viewAgents')),
125
+ ),
126
+ )
127
+ }
128
+ if (usage !== null && usage.enabled === false) {
129
+ problems.push(
130
+ h(
131
+ 'div',
132
+ { key: 'usage', className: 'acc-row' },
133
+ h(C.Badge, { tone: 'warn' }, t('overview.attentionUsageOff')),
134
+ h(C.Btn, { tone: 'ghost', onClick: () => navigate('usage') }, t('overview.viewUsage')),
135
+ ),
136
+ )
137
+ }
138
+ if (problems.length === 0) return null
139
+ return h(C.Notice, { tone: 'warn' }, h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px' } }, problems))
140
+ }
141
+
142
+ /** @param {{ summary: any, t: Function, navigate: Function, reload: Function }} props */
143
+ function OverviewBody(props) {
144
+ const { summary, t, navigate, reload } = props
40
145
  const environment = summary.environment || {}
41
146
  const counts = summary.counts || {}
42
147
  const usage = summary.usageToday || {}
148
+ const agents = summary.agents && summary.agents.available === true ? summary.agents : null
43
149
  const modules = Array.isArray(summary.modules) ? summary.modules : []
44
150
  const capabilities = summary.capabilities || { present: 0, total: 0, missing: [] }
151
+ const missing = Array.isArray(capabilities.missing) ? capabilities.missing : []
152
+ const stateCounts = {}
153
+ for (const entry of modules) stateCounts[entry.state] = (stateCounts[entry.state] || 0) + 1
154
+ const capabilityRatio = capabilities.total > 0 ? capabilities.present / capabilities.total : 0
155
+ const instructions = agents === null
156
+ ? { available: false, reason: /** @type {any} */ (summary.agents || {}).reason }
157
+ : { available: true, value: agents.files ? agents.files.total : 0 }
158
+ const generatedAt = summary.generatedAt ? ACC.fmt.dateTime(summary.generatedAt) : ''
159
+
160
+ const statCards = [
161
+ { key: 'sessions', label: t('overview.sessions'), source: counts.sessions, page: 'sessions' },
162
+ { key: 'tools', label: t('overview.tools'), source: counts.tools, page: 'tools' },
163
+ { key: 'presets', label: t('overview.presets'), source: counts.presets, page: 'meta' },
164
+ {
165
+ key: 'calls',
166
+ label: t('overview.todayCalls'),
167
+ source: usage && usage.available === true ? { available: true, value: usage.calls } : usage,
168
+ page: 'usage',
169
+ },
170
+ { key: 'backups', label: t('overview.backups'), source: summary.counters && summary.counters.backups, page: 'agents' },
171
+ { key: 'instructions', label: t('overview.instructions'), source: instructions, page: 'agents' },
172
+ ]
45
173
 
46
174
  return h(
47
175
  'div',
48
- { className: 'acc-content-inner' },
176
+ { style: PAGE_STYLE },
177
+ h(AttentionStrip, { summary, t, navigate }),
49
178
  h(
50
179
  C.Card,
51
- { title: t('overview.environment') },
180
+ {
181
+ title: t('overview.environment'),
182
+ subtitle: `${String(environment.platform || '')} · Node ${String(environment.node || '')}`,
183
+ actions: [
184
+ generatedAt ? h('span', { key: 'at', className: 'acc-muted' }, t('overview.generatedAt', { time: generatedAt })) : null,
185
+ h(C.Btn, { key: 'refresh', onClick: reload, title: t('overview.refreshAll'), ariaLabel: t('overview.refreshAll') }, t('common.refresh')),
186
+ ],
187
+ },
52
188
  h(C.KeyValues, {
53
189
  items: [
54
190
  { label: t('overview.pluginVersion'), value: String(summary.pluginVersion || '') },
55
- { label: t('overview.dshVersion'), value: environment.dshVersion ? String(environment.dshVersion) : String(environment.dshVersionReason || t('common.unknown')) },
191
+ {
192
+ label: t('overview.dshVersion'),
193
+ value: environment.dshVersion
194
+ ? String(environment.dshVersion)
195
+ : h('span', { title: String(environment.dshVersionReason || '') }, String(t('common.unknown'))),
196
+ },
56
197
  { label: t('overview.node'), value: String(environment.node || '') },
57
198
  { label: t('overview.platform'), value: String(environment.platform || '') },
58
199
  { label: t('overview.profile'), value: environment.profile ? String(environment.profile) : t('common.unknown') },
59
200
  { label: t('overview.cwd'), value: h('span', { className: 'acc-mono' }, String(environment.cwd || '')) },
60
201
  { label: t('overview.storage'), value: h('span', { className: 'acc-mono' }, String(environment.storageRoot || '')) },
61
- { label: t('overview.capabilities'), value: `${capabilities.present}/${capabilities.total}${capabilities.missing.length > 0 ? `(${t('overview.missing')}: ${capabilities.missing.join(', ')})` : ''}` },
202
+ {
203
+ label: t('overview.capabilities'),
204
+ value: h(
205
+ 'div',
206
+ { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
207
+ h(
208
+ 'span',
209
+ { title: missing.length > 0 ? `${t('overview.missing')}: ${missing.join(', ')}` : t('common.none') },
210
+ t('overview.capabilitiesValue', { present: capabilities.present, total: capabilities.total }),
211
+ ),
212
+ h(
213
+ 'div',
214
+ {
215
+ className: 'acc-bar',
216
+ role: 'img',
217
+ 'aria-label': t('overview.capabilitiesValue', { present: capabilities.present, total: capabilities.total }),
218
+ style: { maxWidth: '240px' },
219
+ },
220
+ h('div', { className: 'acc-bar-fill', style: { width: `${Math.round(capabilityRatio * 100)}%` } }),
221
+ ),
222
+ ),
223
+ },
224
+ {
225
+ label: t('overview.missing'),
226
+ value: missing.length === 0 ? t('common.none') : h('span', { className: 'acc-mono', title: missing.join(', ') }, missing.join(', ')),
227
+ },
62
228
  ],
63
229
  }),
64
230
  ),
65
231
  h(
66
- 'div',
67
- { className: 'acc-stat-grid' },
68
- h(StatCard, { label: t('overview.sessions'), source: counts.sessions, onOpen: () => navigate('sessions'), t }),
69
- h(StatCard, { label: t('overview.tools'), source: counts.tools, onOpen: () => navigate('tools'), t }),
70
- h(StatCard, { label: t('overview.presets'), source: counts.presets, onOpen: () => navigate('meta'), t }),
71
- h(StatCard, {
72
- label: t('overview.todayCalls'),
73
- source: usage && usage.available === true ? { available: true, value: usage.calls } : usage,
74
- onOpen: () => navigate('usage'),
75
- t,
76
- }),
77
- h(StatCard, { label: t('overview.backups'), source: summary.counters && summary.counters.backups, onOpen: () => navigate('agents'), t }),
232
+ 'section',
233
+ { style: { display: 'flex', flexDirection: 'column', gap: '8px' }, 'aria-label': t('overview.countsGroup') },
234
+ h(
235
+ 'div',
236
+ { className: 'acc-row', style: { justifyContent: 'space-between' } },
237
+ h('h3', { className: 'acc-section-title' }, t('overview.countsGroup')),
238
+ h('span', { className: 'acc-muted' }, t('overview.countsHint')),
239
+ ),
240
+ h(
241
+ 'div',
242
+ { className: 'acc-stat-grid' },
243
+ statCards.map((card) =>
244
+ h(StatCard, {
245
+ key: card.key,
246
+ label: card.label,
247
+ source: card.source,
248
+ pageTitle: t(`nav.${card.page}`),
249
+ onOpen: () => navigate(card.page),
250
+ t,
251
+ }),
252
+ ),
253
+ ),
78
254
  ),
79
255
  h(
80
256
  C.Card,
81
- { title: t('overview.modules'), subtitle: t('overview.modulesHint') },
257
+ {
258
+ title: t('overview.modules'),
259
+ subtitle: t('overview.modulesHint'),
260
+ actions: h(StateSummary, { counts: stateCounts, t }),
261
+ },
262
+ /* Three columns only: the settings column is ~360px wide, so the method
263
+ * count and the state detail ride along as a second line instead of
264
+ * forcing a horizontal scrollbar. */
82
265
  h(C.Table, {
83
266
  columns: [
84
- { key: 'id', label: t('overview.module'), render: (row) => t(row.titleKey) },
85
- { key: 'state', label: t('overview.state'), render: (row) => h(C.Badge, { tone: row.state === 'FULL' ? 'success' : row.state === 'BLOCKED' ? 'danger' : 'warn', title: row.detail }, row.state) },
86
- { key: 'methods', label: t('overview.methods'), align: 'right', render: (row) => String(row.methodCount) },
87
- { key: 'detail', label: t('common.detail'), render: (row) => (row.detail ? String(row.detail) : '—') },
267
+ {
268
+ key: 'id',
269
+ label: t('overview.module'),
270
+ render: (row) =>
271
+ h(
272
+ 'div',
273
+ { style: { display: 'flex', flexDirection: 'column', gap: '1px', minWidth: 0 } },
274
+ h('span', null, t(row.titleKey)),
275
+ h(
276
+ 'span',
277
+ { className: 'acc-muted', style: { fontSize: '11px', ...CLAMP_STYLE, maxWidth: '180px' }, title: String(row.detail || '') },
278
+ t('overview.methodsValue', { count: row.methodCount }),
279
+ ),
280
+ row.detail ? h('span', { style: { fontSize: '11px', color: 'var(--dsw-alias-label-tertiary, #81858c)' } }, ACC.l10n.host(`overview.moduleDetail.${row.id}`, row.detail)) : null,
281
+ row.detail ? ACC.l10n.raw(t('overview.rawHostText'), row.detail) : null,
282
+ ),
283
+ },
284
+ {
285
+ key: 'state',
286
+ label: t('overview.state'),
287
+ render: (row) => h(C.Badge, { tone: stateTone(row.state), title: String(row.detail || '') }, stateLabel(row.state, t)),
288
+ },
289
+ {
290
+ key: 'open',
291
+ label: '',
292
+ align: 'right',
293
+ render: (row) =>
294
+ h(
295
+ C.Btn,
296
+ {
297
+ tone: 'ghost',
298
+ onClick: () => navigate(row.id),
299
+ title: t('overview.openPage', { page: t(row.titleKey) }),
300
+ ariaLabel: t('overview.openPage', { page: t(row.titleKey) }),
301
+ },
302
+ t('overview.open'),
303
+ ),
304
+ },
88
305
  ],
89
306
  rows: modules,
90
- empty: h(C.Empty, { title: t('nav.empty'), hint: t('nav.emptyHint') }),
307
+ rowKey: 'id',
308
+ empty: h(C.Empty, { title: t('nav.empty'), hint: t('nav.emptyHint'), action: h(C.Btn, { onClick: reload }, t('common.refresh')) }),
91
309
  }),
92
310
  ),
93
311
  usage && usage.available === false
@@ -100,14 +318,17 @@
100
318
  function OverviewPage(props) {
101
319
  const summary = ACC.useAsync((context) => ACC.api('overview.summary', {}, context), [])
102
320
  if (summary.status === 'loading') return h(C.Loading, { label: props.t('common.loading') })
103
- if (summary.status === 'error') return h(C.ErrorBox, { error: /** @type {Error} */ (summary.error), onRetry: summary.reload, label: props.t('overview.failed') })
104
- return h(OverviewBody, { summary: summary.data, t: props.t, navigate: props.navigate })
321
+ if (summary.status === 'error') {
322
+ return h(C.ErrorBox, { error: /** @type {Error} */ (summary.error), onRetry: summary.reload, label: props.t('overview.failed') })
323
+ }
324
+ return h(OverviewBody, { summary: summary.data, t: props.t, navigate: props.navigate, reload: summary.reload })
105
325
  }
106
326
 
107
327
  ACC.registerPage({
108
328
  id: 'overview',
109
329
  titleKey: 'nav.overview',
110
330
  order: 10,
331
+ group: 'insight',
111
332
  render: (props) => h(OverviewPage, props),
112
333
  })
113
334
  })()