dsh-triage 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -15,17 +15,20 @@
15
15
  * C5 copy goes through ctx.locale.register + bind, side effects through ctx.effect
16
16
  * C6 a READ-ONLY tab is an accepted shape upstream, so we do not compete for a slot
17
17
  *
18
- * WHAT THIS TAB DELIBERATELY DOES NOT DO: it renders no verdicts. Judgement ("go / blocked /
19
- * unknown") is computed by the CLI and by the local `serve` panel from recorded evidence; a
20
- * settings tab cannot read `data/results` and must not invent a conclusion from what little the
21
- * browser can see (铁律 1: no evidence → no claim). So the tab shows (a) how to get the answer,
22
- * and (b) one honest fact it *can* verify: how many rows the Host reports (row count only,
23
- * labelled as a fact, never as a verdict).
18
+ * R51 — WHAT CHANGED, AND WHY: until R50 this tab showed a row count, a verdict tally and the
19
+ * sentence "run `dsh-triage audit` in a terminal". The rule it respected was real (the browser
20
+ * cannot compute a verdict), but the conclusion had become reachable by then: R33 opened a
21
+ * read-only route, so the answer could be *computed on the host, by the CLI's own engine*, and
22
+ * merely *displayed* here. The tab now asks `/compat-triage/summary` for
23
+ * `buildProfileSummary()`'s output — the same projection `dsh-triage status` and `serve` print —
24
+ * and renders it. It still decides nothing: every number and every sentence below comes from the
25
+ * payload, and when the payload is missing it says so instead of rendering zeros.
24
26
  *
25
27
  * DEGRADATION IS THE DEFAULT: every registration is wrapped, and the tab is only registered
26
28
  * when the whole contract is present (slots.inject, slots.register, locale.register, a renderer).
27
29
  * A missing piece means ZERO registrations — no half-rendered tab, no error page.
28
30
  */
31
+
29
32
  window.__ModuleLoader__.load({
30
33
  id: 'dsh-triage',
31
34
  factory: (require) => {
@@ -33,38 +36,409 @@ window.__ModuleLoader__.load({
33
36
  const NS = 'compat-triage'
34
37
  /** Services this tab needs; the loader only exposes these to `require`/ctx (C4). */
35
38
  const inject = ['slots', 'locale', 'modules']
39
+ /** The read-only route built in R51. One place, so a rename cannot drift between halves. */
40
+ const SUMMARY_URL = '/compat-triage/summary'
41
+ /** T-818: the on-demand four-bucket answer, selected by a query on the route that works. */
42
+ const UPGRADE_URL = '/compat-triage/summary?upgrade=1'
43
+ /** How many issues a settings tab may show before it stops being a settings tab. */
44
+ const ISSUES_SHOWN = 3
45
+ /** T-818: the four buckets and the count field each one reads. */
46
+ const UPGRADE_COUNT_KEY = {
47
+ 'would-be-denied': 'would_be_denied',
48
+ 'cannot-tell': 'cannot_tell',
49
+ improved: 'improved',
50
+ 'likely-fine': 'likely_fine',
51
+ }
52
+ /**
53
+ * The pure views, kept so the vm test can render them without a React runtime (see
54
+ * `views()` at the bottom). They are NOT part of the Host contract: the Host only calls
55
+ * `apply`, and everything else here is for our own assertions.
56
+ */
57
+ let lastViews = null
36
58
 
37
59
  const zh = {
38
60
  tab: '分诊台',
39
- title: '分诊台 · 装之前判断,坏之后定位',
40
- hint: '结论由命令行的同一个引擎给出(同一份证据、同一条 messageId)。这里只显示宿主事实与入口。',
41
- command: 'dsh-triage audit',
42
- commandHint: '在本机终端运行;加 --json 可拿到逐行结论。',
43
- rows: '宿主报告 {count} 行插件',
44
- rowsUnknown: '没拿到宿主插件清单(只读路由不可用)',
45
- rowsFact: '行数是事实,不是结论。',
46
- verdicts: 'CLI 同一引擎的结论:{go} go · {blocked} blocked · {unknown} unknown',
47
- verdictsUnknown: '没拿到结论(只读路由不回答)',
48
- source: '数据来自宿主只读路由 /compat-triage/audit,与 dsh-triage audit --json 同源。',
61
+ title: '插件分诊台 · 本地兼容性诊断',
62
+ hint: '由本地诊断引擎提供分析结果,与终端 CLI 输出保持同源。',
63
+ counts: '配置项 {rows} · 已分析 {judged} · 正常 {go} · 存在异常 {denied} · 未明确 {unknown}',
64
+ /** Count table (R55): one row per number, so a reader compares values instead of parsing a sentence. */
65
+ countColumns: ['诊断项', '数量', '说明'],
66
+ countLabels: {
67
+ rows: '配置项总数',
68
+ judged: '已分析',
69
+ go: '正常',
70
+ denied: '存在异常',
71
+ unknown: '未明确',
72
+ collisions: '标识冲突',
73
+ duplicates: '多版本重复',
74
+ },
75
+ countMeanings: {
76
+ rows: '已在 Profile 中声明的插件配置条目',
77
+ judged: '具备依赖声明并已完成推演的条目',
78
+ go: '版本规则匹配正常,可正常加载',
79
+ denied: '依赖版本不满足,启动加载时将被拦截',
80
+ unknown: '未显式声明依赖区间(不作盲目推断)',
81
+ collisions: '多个插件争抢同一 Entry ID',
82
+ duplicates: '同一插件检测到多个不同版本副本',
83
+ },
84
+ issueColumns: ['#', '插件', '结论', '修复'],
85
+ nextColumns: ['操作项', '执行命令'],
86
+ none: '—',
87
+ issues: '待处理问题',
88
+ noIssues: '未检测到兼容性异常或冲突。',
89
+ reason: '原因',
90
+ unknownSuffix: '注:未显式声明依赖区间的插件按规则归入“未明确”,不盲目推定为兼容。',
91
+ more: '另有 {n} 项未在当前摘要中显示。',
92
+ next: '下一步建议',
93
+ source: '数据来源于本地只读接口 /compat-triage/summary,与 `dsh-triage status` 同源。',
49
94
  reload: '刷新',
95
+ copy: '复制',
50
96
  failed: '读取失败',
51
- panel: '也可以开本地面板:dsh-triage serve',
97
+ pending: '正在加载诊断数据…',
98
+ unreachable: '未能获取诊断结果(本地接口无响应),请检查服务状态。',
99
+ noWeb: '当前环境未启用 Web 模块,请在终端执行 `dsh-triage status`。',
100
+ empty: '未检测到已安装插件,通常是主目录或 Profile 路径指定有误。',
101
+ errorEmpty: '诊断接口未返回 summary 数据,暂无法展示指标。',
102
+ upgradeButton: '升级预检',
103
+ upgradeTitle: '升级预检 · 目标 {version}',
104
+ upgradeHint: '点击后才读取 npm 的 next 标签;只判声明层,不是运行期实测。',
105
+ upgradePending: '正在读取 npm 并推演…',
106
+ upgradeOffline: '读取 npm 失败(离线或网络不可用)——不显示任何桶,避免把“读不到”当成“不会坏”。',
107
+ upgradeBucketColumns: ['桶', '数量', '意思'],
108
+ upgradeBucketLabels: {
109
+ 'would-be-denied': '会被拒',
110
+ 'cannot-tell': '判不了',
111
+ improved: '会变好',
112
+ 'likely-fine': '像没事',
113
+ },
114
+ upgradeBucketMeanings: {
115
+ 'would-be-denied': '目标版本的准入规则会拒绝这一行/包',
116
+ 'cannot-tell': '声明不足或目标还没发布,证据不够',
117
+ improved: '今天被拒、目标放行——目标版本会放行它',
118
+ 'likely-fine': '声明上不冲突——不等于升级后能跑',
119
+ },
120
+ upgradeMore: '另有 {n} 个单元未列出。',
121
+ upgradeBoundary: '只判声明层;不是运行期实测,也不改你的 profile。',
122
+ upgradeSource: '数据来源于本地只读接口 /compat-triage/upgrade(点击后读取 npm next)。',
123
+ upgradeBack: '返回现状',
52
124
  }
53
125
  const en = {
54
126
  tab: 'Triage',
55
- title: 'Triage · judge before install, attribute after breakage',
56
- hint: 'Verdicts come from the same engine as the CLI (same evidence, same messageId). This tab shows host facts and entry points only.',
57
- command: 'dsh-triage audit',
58
- commandHint: 'Run it in a local terminal; add --json for per-row verdicts.',
59
- rows: 'The host reports {count} plugin rows',
60
- rowsUnknown: 'Host plugin inventory unavailable (read-only route not answering)',
61
- rowsFact: 'A row count is a fact, not a verdict.',
62
- verdicts: 'Conclusions from the CLI engine: {go} go · {blocked} blocked · {unknown} unknown',
63
- verdictsUnknown: 'No conclusions (the read-only route did not answer)',
64
- source: 'Read from the host route /compat-triage/audit, the same payload as dsh-triage audit --json.',
127
+ title: 'Triage · will this setup break?',
128
+ hint: 'The conclusion is computed on the host by the same engine as the CLI; this tab only displays it.',
129
+ counts: 'rows {rows} · judged {judged} · fine {go} · will break {denied} · cannot tell {unknown}',
130
+ countColumns: ['Item', 'Count', 'Meaning'],
131
+ countLabels: {
132
+ rows: 'rows',
133
+ judged: 'judged',
134
+ go: 'fine',
135
+ denied: 'will break',
136
+ unknown: 'cannot tell',
137
+ collisions: 'collisions',
138
+ duplicates: 'duplicates',
139
+ },
140
+ countMeanings: {
141
+ rows: 'declared',
142
+ judged: 'judged',
143
+ go: 'admitted',
144
+ denied: 'dropped at start-up',
145
+ unknown: 'not a pass',
146
+ collisions: 'two plugins claim one row id',
147
+ duplicates: 'the same package installed twice',
148
+ },
149
+ issueColumns: ['#', 'Plugin', 'Conclusion', 'Fix'],
150
+ nextColumns: ['If you want', 'Run'],
151
+ none: '—',
152
+ issues: 'What needs you',
153
+ noIssues: 'Nothing here needs your hands.',
154
+ reason: 'reason',
155
+ unknownSuffix: 'Rows that declare no version range are not a pass — they are "cannot tell".',
156
+ more: '{n} more not listed here.',
157
+ next: 'Next step',
158
+ source: 'Read from the host route /compat-triage/summary, the same projection `dsh-triage status` prints.',
65
159
  reload: 'Refresh',
160
+ copy: 'Copy',
66
161
  failed: 'Read failed',
67
- panel: 'Local panel: dsh-triage serve',
162
+ pending: 'Reading the host…',
163
+ unreachable: 'No conclusion (the read-only route did not answer) — that is not "all good".',
164
+ noWeb: 'This profile serves no web surface, so the route does not exist. Use `dsh-triage status` in a terminal.',
165
+ empty: 'This home/profile yields zero plugin rows — usually --dsh-home / --profile points somewhere else.',
166
+ errorEmpty: 'The route returned no summary field, so no numbers are shown.',
167
+ upgradeButton: 'Upgrade check',
168
+ upgradeTitle: 'Upgrade check · target {version}',
169
+ upgradeHint: 'The npm next tag is read only after you click; this judges the declaration layer, not a runtime measurement.',
170
+ upgradePending: 'Reading npm and judging the target…',
171
+ upgradeOffline: 'The npm read failed (offline or unreachable). No buckets are shown: "could not read" is not "nothing will break".',
172
+ upgradeBucketColumns: ['Bucket', 'Count', 'Meaning'],
173
+ upgradeBucketLabels: {
174
+ 'would-be-denied': 'will be denied',
175
+ 'cannot-tell': 'cannot tell',
176
+ improved: 'improved',
177
+ 'likely-fine': 'likely fine',
178
+ },
179
+ upgradeBucketMeanings: {
180
+ 'would-be-denied': 'the target runtime would deny this row/package',
181
+ 'cannot-tell': 'not enough declaration or the target is unpublished',
182
+ improved: 'denied today, admitted at the target — the target would let it through',
183
+ 'likely-fine': 'no declaration conflict — not a promise that it runs',
184
+ },
185
+ upgradeMore: '{n} more units not listed.',
186
+ upgradeBoundary: 'Declaration layer only; not a runtime measurement, and it does not touch your profile.',
187
+ upgradeSource: 'Read from /compat-triage/upgrade after a click; the host reads the npm next tag.',
188
+ upgradeBack: 'Back to status',
189
+ }
190
+
191
+ /** Fill `{name}` placeholders. A missing value becomes `?`, never `0`. */
192
+ function fill(template, values) {
193
+ return String(template).replace(/\{(\w+)\}/g, (whole, key) =>
194
+ Object.prototype.hasOwnProperty.call(values, key) ? String(values[key]) : '?',
195
+ )
196
+ }
197
+
198
+ /** A clipboard we do not have is a no-op, not a fake "copied". */
199
+ function copyText(text) {
200
+ const report = (ok, error) => {
201
+ try {
202
+ if (typeof window === 'object' && window !== null) {
203
+ window.__dshTriage = { ...(window.__dshTriage || {}), clipboard: { ok, error: error ?? null } }
204
+ }
205
+ } catch {
206
+ // Recording the outcome is a nicety; the button still works without it.
207
+ }
208
+ }
209
+ try {
210
+ if (typeof navigator === 'object' && navigator !== null && navigator.clipboard) {
211
+ navigator.clipboard.writeText(String(text)).then(
212
+ () => report(true, null),
213
+ // The failure is published, not swallowed: a button that cannot copy must be visible as
214
+ // such to the probe (R51 user test), not merely unhelpful to the person clicking it.
215
+ (error) => report(false, String((error && error.message) || error)),
216
+ )
217
+ return
218
+ }
219
+ report(false, 'navigator.clipboard is unavailable')
220
+ } catch (error) {
221
+ report(false, String((error && error.message) || error))
222
+ }
223
+ }
224
+
225
+ /**
226
+ * The two pure views. Everything they print comes from `copy` (the Host's localization) and
227
+ * `summary` (the Host's projection); nothing here counts, ranks or fills a missing field.
228
+ */
229
+ function makeViews(jsxRuntime) {
230
+ const jsx = jsxRuntime.jsx
231
+ const jsxs = jsxRuntime.jsxs
232
+
233
+ /**
234
+ * ONE TABLE PRIMITIVE (R55). The Host's stylesheet does not style our markup, and a borderless
235
+ * table with no padding renders as run-together columns, so a minimal amount of layout is
236
+ * inlined here. Inline styles are presentation only: if the page's CSP drops them, the table
237
+ * is still a table (thead/tbody/tr/th/td) and every number is still in its own cell.
238
+ */
239
+ const CELL = { padding: '4px 10px 4px 0', textAlign: 'left', verticalAlign: 'top' }
240
+ const HEAD = { ...CELL, fontWeight: 600, whiteSpace: 'nowrap', borderBottom: '1px solid rgba(127,127,127,0.35)' }
241
+
242
+ function matrix(headers, rows, attrs) {
243
+ return jsxs('table', {
244
+ ...(attrs || {}),
245
+ style: { borderCollapse: 'collapse', margin: '4px 0 10px', width: '100%' },
246
+ children: [
247
+ jsx('thead', {
248
+ children: jsx('tr', {
249
+ children: headers.map((label, column) =>
250
+ jsx('th', { 'data-col': String(column), style: HEAD, children: String(label) }),
251
+ ),
252
+ }),
253
+ }),
254
+ jsx('tbody', {
255
+ children: rows.map((cells, index) =>
256
+ jsx('tr', {
257
+ 'data-row': String(index),
258
+ children: cells.map((cell, column) => jsx('td', { 'data-col': String(column), style: CELL, children: cell })),
259
+ }),
260
+ ),
261
+ }),
262
+ ],
263
+ })
264
+ }
265
+
266
+ /**
267
+ * Counts as three columns. `data-count-label` / `data-count-value` let the recorder read the
268
+ * numbers back as pairs instead of scraping a sentence.
269
+ *
270
+ * COLLISIONS AND DUPLICATES ONLY APPEAR WHEN THEY EXIST (R55): the headline counts them as
271
+ * "things that will go wrong" ("有 2 个东西会出问题"), so a table that only showed `会坏 1`
272
+ * contradicted the sentence above it — found by looking at the mixed demo, not by a test.
273
+ */
274
+ function countsTable(counts, copy) {
275
+ const order = [
276
+ ['rows', counts.rows],
277
+ ['judged', counts.judged],
278
+ ['go', counts.go],
279
+ ['denied', counts.denied],
280
+ ['unknown', counts.unknown],
281
+ ['collisions', counts.collisions],
282
+ ['duplicates', counts.duplicateCopies],
283
+ ].filter(([, value]) => typeof value === 'number')
284
+ const rows = order
285
+ .filter(([key, value]) => (key === 'collisions' || key === 'duplicates') ? Number(value) > 0 : true)
286
+ .map(([key, value]) => [
287
+ jsx('span', { 'data-count-label': key, children: copy.countLabels[key] }),
288
+ jsx('strong', { 'data-count-value': key, children: String(value) }),
289
+ jsx('span', { 'data-count-meaning': key, children: copy.countMeanings[key] }),
290
+ ])
291
+ return matrix(copy.countColumns, rows, { 'data-triage-counts': '1' })
292
+ }
293
+
294
+ /**
295
+ * One row per issue: what it is, then the engine's own reason on a second line inside the same
296
+ * cell. Five columns did not fit a settings dialog; the reason belongs under the conclusion it
297
+ * explains, not in a column of its own.
298
+ */
299
+ function issuesTable(issues, copy) {
300
+ const rows = issues.map((issue, index) => [
301
+ String(index + 1),
302
+ jsx('code', { children: String(issue.id) }),
303
+ jsxs('span', {
304
+ 'data-issue-kind': String(issue.kind),
305
+ children: [
306
+ jsx('span', { children: String(issue.plain) }),
307
+ typeof issue.line === 'string' && issue.line !== ''
308
+ ? jsx('span', {
309
+ style: { display: 'block', opacity: 0.75, fontSize: '0.9em' },
310
+ children: `${copy.reason}: ${issue.line}`,
311
+ })
312
+ : null,
313
+ ].filter((node) => node !== null),
314
+ }),
315
+ typeof issue.fix === 'string' && issue.fix !== ''
316
+ ? jsx('button', {
317
+ type: 'button',
318
+ 'data-copy-fix': String(issue.id),
319
+ style: { whiteSpace: 'nowrap' },
320
+ onClick: () => copyText(issue.fix),
321
+ children: copy.copy,
322
+ })
323
+ : copy.none,
324
+ ])
325
+ return matrix(copy.issueColumns, rows, { 'data-triage-issues': String(issues.length) })
326
+ }
327
+
328
+ /** Two columns: what you want to do, and the command. No prose in between. */
329
+ function nextTable(steps, copy) {
330
+ const rows = steps.map((step) => [String(step.label), jsx('code', { children: String(step.command) })])
331
+ return matrix(copy.nextColumns, rows)
332
+ }
333
+
334
+ function summaryView(summary, copy, onRefresh, onUpgrade) {
335
+ const counts = summary && summary.counts ? summary.counts : null
336
+ const children = [jsx('h3', { children: copy.title }), jsx('p', { children: copy.hint })]
337
+ children.push(
338
+ jsx('p', {
339
+ 'data-triage-tone': String(summary && summary.tone ? summary.tone : 'unknown'),
340
+ children: jsx('strong', { children: String((summary && summary.plain) || (summary && summary.headline) || '') }),
341
+ }),
342
+ )
343
+ if (counts !== null) {
344
+ children.push(countsTable(counts, copy))
345
+ // Zero rows is not a clean profile: it is usually the wrong home. Say so (R49's lesson).
346
+ if (counts.rows === 0) children.push(jsx('p', { children: copy.empty }))
347
+ }
348
+ const issues = summary && Array.isArray(summary.issues) ? summary.issues.slice(0, ISSUES_SHOWN) : []
349
+ if (issues.length === 0) children.push(jsx('p', { children: copy.noIssues }))
350
+ else {
351
+ children.push(jsx('h4', { children: copy.issues }))
352
+ children.push(issuesTable(issues, copy))
353
+ if (summary.more > 0) children.push(jsx('p', { children: fill(copy.more, { n: summary.more }) }))
354
+ }
355
+ if (counts !== null && counts.unknown > 0) children.push(jsx('p', { children: copy.unknownSuffix }))
356
+ if (summary && Array.isArray(summary.next) && summary.next.length > 0) {
357
+ children.push(jsx('h4', { children: copy.next }))
358
+ children.push(nextTable(summary.next, copy))
359
+ }
360
+ children.push(jsx('p', { children: copy.source }))
361
+ // T-818: the second screen is on demand. This button is the only thing that reads npm.
362
+ children.push(
363
+ jsx('button', {
364
+ type: 'button',
365
+ 'data-triage-action': 'upgrade',
366
+ onClick: onUpgrade,
367
+ children: copy.upgradeButton,
368
+ }),
369
+ )
370
+ children.push(jsx('button', { type: 'button', onClick: onRefresh, children: copy.reload }))
371
+ return jsxs('div', { 'data-triage-tab': 'summary', children })
372
+ }
373
+
374
+ /**
375
+ * FOUR FAILURES, FOUR SENTENCES. "No route" is a profile shape, "unreadable" is a profile
376
+ * state, "no summary field" is a version skew, "thrown" is a dead process — and none of them
377
+ * is "no problems", which is what a zero-filled table would say.
378
+ */
379
+ function failureView(result, copy, onRefresh) {
380
+ const kind = result === null ? 'pending' : result.kind
381
+ const children = [jsx('h3', { children: copy.title }), jsx('p', { children: copy.hint })]
382
+ if (kind === 'route-missing') children.push(jsx('p', { children: copy.noWeb }))
383
+ else if (kind === 'no-summary') children.push(jsx('p', { children: copy.errorEmpty }))
384
+ else if (kind === 'pending') children.push(jsx('p', { children: copy.pending }))
385
+ else children.push(jsx('p', { children: copy.unreachable }))
386
+ if (result !== null && result.detail) {
387
+ children.push(jsx('p', { children: `${copy.failed}: ${String(result.detail)}` }))
388
+ }
389
+ children.push(jsx('button', { type: 'button', onClick: onRefresh, children: copy.reload }))
390
+ return jsxs('div', { 'data-triage-tab': 'error', 'data-triage-kind': String(kind), children })
391
+ }
392
+
393
+ /**
394
+ * T-818: four buckets, each with `data-upgrade-bucket` / `data-upgrade-count` so the recorder
395
+ * can read them as pairs. The words come from the Host's copy; nothing is counted here.
396
+ */
397
+ function upgradeView(result, copy, onBack) {
398
+ const upgrade = result && result.upgrade ? result.upgrade : null
399
+ const target = upgrade && upgrade.target && upgrade.target.version ? String(upgrade.target.version) : '?'
400
+ const children = [jsx('h3', { children: fill(copy.upgradeTitle, { version: target }) }), jsx('p', { children: copy.upgradeHint })]
401
+ if (upgrade && upgrade.counts) {
402
+ const rows = ['would-be-denied', 'cannot-tell', 'improved', 'likely-fine'].map((bucket) => {
403
+ const count = upgrade.counts[UPGRADE_COUNT_KEY[bucket]] ?? 0
404
+ return [
405
+ jsx('span', { 'data-upgrade-label': bucket, children: copy.upgradeBucketLabels[bucket] }),
406
+ jsx('strong', { 'data-upgrade-bucket': bucket, 'data-upgrade-count': String(count), children: String(count) }),
407
+ jsx('span', { children: copy.upgradeBucketMeanings[bucket] }),
408
+ ]
409
+ })
410
+ children.push(matrix(copy.upgradeBucketColumns, rows, { 'data-triage-upgrade': '1' }))
411
+ if (upgrade.more > 0) children.push(jsx('p', { children: fill(copy.upgradeMore, { n: upgrade.more }) }))
412
+ }
413
+ children.push(jsx('p', { children: copy.upgradeBoundary }))
414
+ children.push(jsx('p', { children: copy.upgradeSource }))
415
+ children.push(jsx('button', { type: 'button', onClick: onBack, children: copy.upgradeBack }))
416
+ return jsxs('div', { 'data-triage-tab': 'upgrade', children })
417
+ }
418
+
419
+ /** Offline / unreadable is its own sentence, never a zero-filled bucket table. */
420
+ function upgradeFailureView(status, result, copy, onBack) {
421
+ const loading = status === 'loading'
422
+ const children = [jsx('h3', { children: copy.upgradeButton }), jsx('p', { children: copy.upgradeHint })]
423
+ if (loading) children.push(jsx('p', { children: copy.upgradePending }))
424
+ else children.push(jsx('p', { children: copy.upgradeOffline }))
425
+ if (result && result.detail) children.push(jsx('p', { children: `${copy.failed}: ${String(result.detail)}` }))
426
+ children.push(jsx('button', { type: 'button', onClick: onBack, children: copy.upgradeBack }))
427
+ /*
428
+ * R62: "still reading the registry" and "the read failed" used to share one mark
429
+ * (`data-triage-tab="upgrade-error"`), so any observer that asked "is there an error view?"
430
+ * answered yes while the answer was still on the wire — the R61 harness did exactly that and
431
+ * reported a hung fetch. Two states, two marks. The kind attribute keeps `loading` as well,
432
+ * so a probe that only reads `data-triage-kind` still cannot mistake it for a verdict.
433
+ */
434
+ return jsxs('div', {
435
+ 'data-triage-tab': loading ? 'upgrade-loading' : 'upgrade-error',
436
+ 'data-triage-kind': String(result && result.kind ? result.kind : status),
437
+ children,
438
+ })
439
+ }
440
+
441
+ return { summaryView, failureView, upgradeView, upgradeFailureView }
68
442
  }
69
443
 
70
444
  /**
@@ -74,66 +448,67 @@ window.__ModuleLoader__.load({
74
448
  function makeTab(react, jsxRuntime) {
75
449
  if (react === null || jsxRuntime === null) return null
76
450
  const { useState, useEffect, useCallback } = react
77
- const jsx = jsxRuntime.jsx
78
- const jsxs = jsxRuntime.jsxs
451
+ const views = makeViews(jsxRuntime)
452
+ lastViews = views
79
453
  return function CompatTriageTab(props) {
80
454
  const copy = props.copy
81
- const [state, setState] = useState({ status: 'idle', count: null, verdicts: null, detail: null })
455
+ const [state, setState] = useState({ status: 'idle', result: null })
456
+ const [screen, setScreen] = useState('summary')
457
+ const [upgrade, setUpgrade] = useState({ status: 'idle', result: null })
82
458
  const load = useCallback(() => {
83
459
  let cancelled = false
84
460
  setState((previous) => ({ ...previous, status: 'loading' }))
85
461
  Promise.resolve()
86
462
  .then(() => props.load())
87
463
  .then((result) => {
464
+ if (cancelled) return
465
+ setState({ status: result && result.ok ? 'ready' : 'failed', result })
466
+ })
467
+ .catch((error) => {
88
468
  if (cancelled) return
89
469
  setState({
90
- status: result.ok ? 'ready' : 'failed',
91
- count: result.count ?? null,
92
- verdicts: result.verdicts ?? null,
93
- detail: result.detail ?? null,
470
+ status: 'failed',
471
+ result: { ok: false, kind: 'thrown', detail: String((error && error.message) || error) },
94
472
  })
95
473
  })
474
+ return () => {
475
+ cancelled = true
476
+ }
477
+ }, [props])
478
+ /*
479
+ * T-818: the upgrade screen is opened by the button, never by mount. Calling this function is
480
+ * the only thing in the tab that causes an npm read.
481
+ */
482
+ const loadUpgrade = useCallback(() => {
483
+ let cancelled = false
484
+ setScreen('upgrade')
485
+ setUpgrade({ status: 'loading', result: null })
486
+ Promise.resolve()
487
+ .then(() => props.loadUpgrade())
488
+ .then((result) => {
489
+ if (cancelled) return
490
+ setUpgrade({ status: result && result.ok ? 'ready' : 'failed', result })
491
+ })
96
492
  .catch((error) => {
97
493
  if (cancelled) return
98
- setState({ status: 'failed', count: null, verdicts: null, detail: String((error && error.message) || error) })
494
+ setUpgrade({ status: 'failed', result: { ok: false, kind: 'thrown', detail: String((error && error.message) || error) } })
99
495
  })
100
496
  return () => {
101
497
  cancelled = true
102
498
  }
103
499
  }, [props])
104
500
  useEffect(() => load(), [load])
105
- const rowsText =
106
- state.count === null
107
- ? copy.rowsUnknown
108
- : copy.rows.replace('{count}', String(state.count))
109
- const verdictsText =
110
- state.verdicts === null
111
- ? copy.verdictsUnknown
112
- : copy.verdicts
113
- .replace('{go}', String(state.verdicts.go))
114
- .replace('{blocked}', String(state.verdicts.blocked))
115
- .replace('{unknown}', String(state.verdicts.unknown))
116
- return jsxs('div', {
117
- children: [
118
- jsx('h3', { children: copy.title }),
119
- jsx('p', { children: copy.hint }),
120
- jsx('p', { children: rowsText }),
121
- jsx('p', { children: verdictsText }),
122
- jsx('p', { children: copy.source }),
123
- jsx('p', { children: copy.rowsFact }),
124
- jsx('p', {
125
- children: [
126
- jsx('code', { children: copy.command }),
127
- jsx('span', { children: ` — ${copy.commandHint}` }),
128
- ],
129
- }),
130
- jsx('p', { children: copy.panel }),
131
- state.status === 'failed' && state.detail !== null
132
- ? jsx('p', { children: `${copy.failed}: ${state.detail}` })
133
- : null,
134
- jsx('button', { type: 'button', onClick: load, children: copy.reload }),
135
- ],
136
- })
501
+ if (screen === 'upgrade') {
502
+ if (upgrade.status !== 'ready' || upgrade.result === null || upgrade.result.ok !== true || !upgrade.result.upgrade) {
503
+ return views.upgradeFailureView(upgrade.status, upgrade.result, copy, () => setScreen('summary'))
504
+ }
505
+ return views.upgradeView(upgrade.result, copy, () => setScreen('summary'))
506
+ }
507
+ const result = state.result
508
+ if (state.status !== 'ready' || result === null || result.ok !== true || result.summary === null) {
509
+ return views.failureView(state.status === 'idle' ? null : result, copy, load)
510
+ }
511
+ return views.summaryView(result.summary, copy, load, loadUpgrade)
137
512
  }
138
513
  }
139
514
 
@@ -185,35 +560,81 @@ window.__ModuleLoader__.load({
185
560
  if (effect !== null) effect(registerDictionaries, 'compat-triage:dictionaries')
186
561
  else registerDictionaries()
187
562
  const t = locale.bind(NS)
563
+ /*
564
+ * WHICH LOCALE THE PAYLOAD SHOULD BE READ IN: ask the Host's own binding, do not sniff the
565
+ * browser. `t('tab')` resolving to the zh dictionary means this page is being shown in
566
+ * Chinese, so the Chinese sentences are the correct ones; anything else (a third locale, or
567
+ * a test double) falls back to English, which is also what `summary.en` is for.
568
+ */
569
+ const activeLocale = t('tab') === zh.tab ? 'zh' : 'en'
570
+ /*
571
+ * STRUCTURED COPY COMES FROM THE DICTIONARY, NOT FROM `t()` (R55): `t()` is the Host's string
572
+ * binding — feeding it arrays and objects to get column labels back would be relying on
573
+ * behaviour nobody promised. Tables need labels, so they are read from the dictionary this
574
+ * plugin registered, for the same locale `t()` just reported.
575
+ */
576
+ const dict = activeLocale === 'zh' ? zh : en
188
577
  const injected = () => ({
578
+ locale: activeLocale,
189
579
  copy: {
190
580
  tab: t('tab'),
191
581
  title: t('title'),
192
582
  hint: t('hint'),
193
- command: t('command'),
194
- commandHint: t('commandHint'),
195
- rows: t('rows'),
196
- rowsUnknown: t('rowsUnknown'),
197
- rowsFact: t('rowsFact'),
198
- verdicts: t('verdicts'),
199
- verdictsUnknown: t('verdictsUnknown'),
583
+ counts: t('counts'),
584
+ countColumns: dict.countColumns,
585
+ countLabels: dict.countLabels,
586
+ countMeanings: dict.countMeanings,
587
+ issueColumns: dict.issueColumns,
588
+ nextColumns: dict.nextColumns,
589
+ none: dict.none,
590
+ issues: t('issues'),
591
+ noIssues: t('noIssues'),
592
+ reason: t('reason'),
593
+ unknownSuffix: t('unknownSuffix'),
594
+ more: t('more'),
595
+ next: t('next'),
200
596
  source: t('source'),
201
597
  reload: t('reload'),
598
+ copy: t('copy'),
202
599
  failed: t('failed'),
203
- panel: t('panel'),
600
+ pending: t('pending'),
601
+ unreachable: t('unreachable'),
602
+ noWeb: t('noWeb'),
603
+ empty: t('empty'),
604
+ errorEmpty: t('errorEmpty'),
605
+ upgradeButton: t('upgradeButton'),
606
+ upgradeTitle: t('upgradeTitle'),
607
+ upgradeHint: t('upgradeHint'),
608
+ upgradePending: t('upgradePending'),
609
+ upgradeOffline: t('upgradeOffline'),
610
+ upgradeBucketColumns: dict.upgradeBucketColumns,
611
+ upgradeBucketLabels: dict.upgradeBucketLabels,
612
+ upgradeBucketMeanings: dict.upgradeBucketMeanings,
613
+ upgradeMore: t('upgradeMore'),
614
+ upgradeBoundary: t('upgradeBoundary'),
615
+ upgradeSource: t('upgradeSource'),
616
+ upgradeBack: t('upgradeBack'),
204
617
  },
205
618
  /*
206
- * FACTS FROM THE HOST, NOT JUDGEMENTS MADE HERE (铁律 1). Since R33 the tab reads the Host's
207
- * read-only route, which answers with the exact payload `dsh-triage audit --json` prints —
208
- * built by the same `loadAuditData()`/`auditJsonPayload()` the CLI uses. The tab only counts
209
- * what the payload says; it never decides a conclusion and never guesses a missing field.
619
+ * FACTS FROM THE HOST, NOT JUDGEMENTS MADE HERE (铁律 1). The route answers with the
620
+ * projection `dsh-triage status` prints, built by `buildProfileSummary()` from the same
621
+ * `loadAuditData()` the CLI calls. This function only picks a locale and forwards the
622
+ * failure: it counts nothing and never fills a missing field with a plausible value.
210
623
  */
211
624
  load: async () => {
212
625
  /** Publish what the tab just showed, so a real page can be asked for it (R33 same-source). */
213
626
  const publishData = (result) => {
214
627
  try {
215
628
  if (typeof window === 'object' && window !== null) {
216
- window.__dshTriage = { ...(window.__dshTriage || {}), data: { ok: result.ok, rows: result.count, verdicts: result.verdicts, detail: result.detail ?? null } }
629
+ window.__dshTriage = {
630
+ ...(window.__dshTriage || {}),
631
+ data: {
632
+ ok: result.ok,
633
+ kind: result.kind ?? null,
634
+ tone: result.summary && result.summary.tone ? result.summary.tone : null,
635
+ counts: result.summary && result.summary.counts ? result.summary.counts : null,
636
+ },
637
+ }
217
638
  }
218
639
  } catch {
219
640
  // A frozen window only costs the diagnostic marker, never the tab.
@@ -222,15 +643,17 @@ window.__ModuleLoader__.load({
222
643
  }
223
644
  let response
224
645
  try {
225
- response = await fetch('/compat-triage/audit', {
646
+ response = await fetch(SUMMARY_URL, {
226
647
  credentials: 'include',
227
648
  headers: { accept: 'application/json' },
228
649
  })
229
650
  } catch (error) {
230
651
  // A dead route is a fact to report, not an exception to render: `load` never throws.
231
- return publishData({ ok: false, count: null, verdicts: null, detail: String((error && error.message) || error) })
652
+ return publishData({ ok: false, kind: 'thrown', summary: null, detail: String((error && error.message) || error) })
232
653
  }
233
654
  if (!response.ok) {
655
+ // 404 is the one failure with its own meaning: this profile serves no web surface.
656
+ const kind = response.status === 404 ? 'route-missing' : 'http'
234
657
  let detail = `HTTP ${response.status}`
235
658
  try {
236
659
  const body = await response.json()
@@ -238,21 +661,63 @@ window.__ModuleLoader__.load({
238
661
  } catch {
239
662
  // A non-JSON error body is still an error; the status is the fact we have.
240
663
  }
241
- return publishData({ ok: false, count: null, verdicts: null, detail })
664
+ return publishData({ ok: false, kind, summary: null, detail })
242
665
  }
243
666
  const payload = await response.json()
244
- const rows = Array.isArray(payload?.rows) ? payload.rows.length : null
245
- const verdicts = Array.isArray(payload?.row_verdicts) ? payload.row_verdicts : null
246
- const tally = verdicts === null ? null : { go: 0, blocked: 0, unknown: 0 }
247
- if (verdicts !== null) {
248
- for (const verdict of verdicts) {
249
- const conclusion = verdict && verdict.conclusion
250
- if (conclusion === 'go') tally.go += 1
251
- else if (conclusion === 'blocked') tally.blocked += 1
252
- else tally.unknown += 1
667
+ const summary = payload && payload.summary ? payload.summary[activeLocale] || payload.summary.en || null : null
668
+ if (summary === null) {
669
+ return publishData({ ok: false, kind: 'no-summary', summary: null, detail: null })
670
+ }
671
+ return publishData({ ok: true, kind: null, summary, detail: null })
672
+ },
673
+ /*
674
+ * T-818: fetched only when the person clicks "升级预检". A route that is missing (404) or a
675
+ * registry that cannot be read (502/504) produces a sentence, never a zero-filled bucket table.
676
+ */
677
+ loadUpgrade: async () => {
678
+ const publishUpgrade = (result) => {
679
+ try {
680
+ if (typeof window === 'object' && window !== null) {
681
+ window.__dshTriage = {
682
+ ...(window.__dshTriage || {}),
683
+ upgrade: {
684
+ ok: result.ok,
685
+ kind: result.kind ?? null,
686
+ target: result.upgrade && result.upgrade.target ? result.upgrade.target.version : null,
687
+ counts: result.upgrade && result.upgrade.counts ? result.upgrade.counts : null,
688
+ },
689
+ }
690
+ }
691
+ } catch {
692
+ // The marker is diagnostic only; the screen still works without it.
253
693
  }
694
+ return result
254
695
  }
255
- return publishData({ ok: true, count: rows, verdicts: tally, detail: null })
696
+ let response
697
+ try {
698
+ response = await fetch(UPGRADE_URL, {
699
+ credentials: 'include',
700
+ headers: { accept: 'application/json' },
701
+ })
702
+ } catch (error) {
703
+ return publishUpgrade({ ok: false, kind: 'thrown', upgrade: null, detail: String((error && error.message) || error) })
704
+ }
705
+ if (!response.ok) {
706
+ const kind = response.status === 404 ? 'route-missing' : 'http'
707
+ let detail = `HTTP ${response.status}`
708
+ try {
709
+ const body = await response.json()
710
+ if (body && typeof body.error === 'string') detail = `${response.status}: ${body.error}`
711
+ } catch {
712
+ // A non-JSON error body is still an error; the status is the fact we have.
713
+ }
714
+ return publishUpgrade({ ok: false, kind, upgrade: null, detail })
715
+ }
716
+ const payload = await response.json()
717
+ if (!payload || !payload.counts || !payload.target) {
718
+ return publishUpgrade({ ok: false, kind: 'no-upgrade', upgrade: null, detail: null })
719
+ }
720
+ return publishUpgrade({ ok: true, kind: null, upgrade: payload, detail: null })
256
721
  },
257
722
  })
258
723
  slots.inject('settings.plugins.tab', () =>
@@ -276,7 +741,7 @@ window.__ModuleLoader__.load({
276
741
  const registered = register(ctx, require)
277
742
  publishMarker(
278
743
  registered
279
- ? { registered: true, slot: 'settings.plugins.tab', id: NS }
744
+ ? { registered: true, slot: 'settings.plugins.tab', id: NS, route: SUMMARY_URL, upgrade: UPGRADE_URL }
280
745
  : { registered: false, reason: 'contract-missing', id: NS },
281
746
  )
282
747
  return registered
@@ -288,6 +753,11 @@ window.__ModuleLoader__.load({
288
753
  }
289
754
  }
290
755
 
291
- return { NS, inject, apply, register }
756
+ /** Test seam: the pure views, available after a successful registration. */
757
+ function views() {
758
+ return lastViews
759
+ }
760
+
761
+ return { NS, inject, apply, register, views }
292
762
  },
293
763
  })